mov eax , cr0
or eax , 0x01
mov cr0 , eax



back to months list

Project : The "Microkernel" Operating System

Journal Entry Date : 2024.02.14

Today I finally finished block device system. Basically, I separated block device driver and storage system. The storage system controls partition devices and file system. Basically, the storage system uses registered partition drivers that detects existing partitions from the device and detects what file system the partitions/the device uses.

I was actually thinking of making a system that has the lists of mounted block devices, but I deprecated the system because I thought it was too overcomplicated design. So, I came up with this "simple" design with only block device driver manager and separated functions(storage_system) that assigns file system and gets partitions.


Overall.. structure I guess

As you can see on the diagram, the BlockDeviceDriverContainer contains all the block device drivers in the kernel system. The driver has a container that has the devices dependent to the driver(= devices that uses the driver.) Upon registering the device, the partition is automatically detected, and the storage system automatically registers logical devices which also contained in the parent physical device.

The PartitionDriver is driver that controls the detection of "partition scheme"(like MBR, GPT ..) The block device driver system(blockdev::) identifies what partition scheme the device is using by calling detect_partition() function. detect_partition() creates logical block devices that has a driver that translates logical sector number to physical sector number.

struct logical_block_device_driver : public blockdev::block_device_driver {
   ...
   bool prepare(void) { debug::out::printf(DEBUG_WARNING , "logical_storage_device_driver::prepare : not allowed\n"); return false; }
   max_t read(blockdev::block_device *device , max_t sector_address , max_t count , void *buffer) override {
       struct blockdev::block_device *physical_super_device = get_physical_super_device(device);
       if(!check(physical_super_device , device)) return 0x00;
       
       sector_address += device->storage_info.partition_info.physical_sector_start;
       
       // Get physical storage pointer of logical storage
       return physical_super_device->device_driver->read(physical_super_device , sector_address , count , buffer);
   }
   ...
}

Basically, the logical driver adds the physical location of that logical device to the logical sector number. Simple yet very effective thing. Now we need to implement the file system driver and some fancy i/o buffer systems. It's going to be (very) hard.. lol