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



back to months list

Project : The "Microkernel" Operating System

Journal Entry Date : 2024.03.05

Where have I been for 4 days? Yeah, that's right! I made the (nearly whole) FAT16 file system in just three days. Yes. I was in a pain of mindless modification of code that I(from past) wrote. I am in much pain than ever before. Not only because of this inexhaustible amounts of codes and works, but just some.. you know.. nihilistic thought crawling upon your shoulder. Nothing too crazy.

ANYWAYS. Basically, I just changed the majority of this code to make it to work and more beautiful.

And I changed the functions of file system driver from virtual functions to function pointers. For some whatever reason, when I use virtual functions and overRide it, some weird errors about vtable occurs for no logical reason(at least from my knowledge.)

struct file_system_driver {
    bool (*check)(blockdev::block_device *device);
    bool (*get_root_directory)(physical_file_info &file_loc);

    bool (*create)(file_info *new_file , file_info *directory);

    // fill out the structure
    bool (*open)(file_info *file , int option);
    bool (*close)(file_info *file);
    bool (*remove)(file_info *file);

    bool (*rename)(file_info *new_file);
    bool (*move)(file_info *new_file , file_info *new_directory);

    int (*read)(file_info *file , size_t size , void *buffer);
    int (*write)(file_info *file , size_t size , const void *buffer);

    int (*lseek)(file_info *file , max_t cursor , int option);

    int (*read_directory)(file_info *file , max_t cursor);

    char fs_string[32];
};

Also added "get_root_directory" function to get the location of root directory. Since the files will be managed in tree structure, the root of the tree is very important and needs a separate function to find it. Also implemented root ramdisk system to kernel. Basically, the loader passes the location and the size of ramdisk and kernel uses the information to create root ramdisk device. Once the device is made, the device is registered as root device by VFS manager.

void vfs::init(blockdev::block_device *root_device) {
    debug::push_function("vfs::init");
    file_info *root_file = (file_info *)memory::pmem_alloc(sizeof(file_info));
    strcpy(root_file->file_name , "@");
    root_file->is_mounted = true;

    // mount the file
    if(vfs::mount(root_file , root_device) == false) {
        debug::out::printf(DEBUG_WARNING , "Failed mounting root device!\n");
        return;
    }

    debug::out::printf(DEBUG_SPECIAL , "fs_driver : 0x%lx\n" , root_file->mount_loc_info.fs_driver);
    debug::out::printf(DEBUG_SPECIAL , "Device %s%d : File system detected, %s\n" , root_device->device_driver->driver_name , root_device->id , root_file->mount_loc_info.fs_driver->fs_string);
    GLOBAL_OBJECT(VirtualFileSystemCache)->init(root_file);
    debug::pop_function();
}

...

bool vfs::mount(file_info *file , blockdev::block_device *device) {
    fsdev::file_system_driver *fs_driver = fsdev::detect_fs(device);
    if(fs_driver == 0x00) return false;
    file->mount_loc_info.fs_driver = fs_driver;
    file->mount_loc_info.block_device = device;
    if(fs_driver->get_root_directory(file->mount_loc_info) == false) return false; 

    file->is_mounted = true;
    return true;
}

The "@" here is the name of root directory.. it's just an arbitrary character that I thought it looks cool.

Now that some basic stuffs are set, I will implement the actual vfs functions such as open, close, read and write.. probably tomorrow.