diff --git a/kernel/include/fs/fat32.hpp b/kernel/include/fs/fat32.hpp index ff423b76..04ced5ab 100644 --- a/kernel/include/fs/fat32.hpp +++ b/kernel/include/fs/fat32.hpp @@ -34,6 +34,8 @@ public: fat32_file_system(std::string mount_point, std::string device, size_t disk, size_t partition); ~fat32_file_system(); + void init(); + size_t statfs(statfs_info& file); size_t read(const std::vector& file_path, char* buffer, size_t count, size_t offset, size_t& read); size_t write(const std::vector& file_path, const char* buffer, size_t count, size_t offset, size_t& written); diff --git a/kernel/include/vfs/file_system.hpp b/kernel/include/vfs/file_system.hpp index 8a7d18c7..797c9b25 100644 --- a/kernel/include/vfs/file_system.hpp +++ b/kernel/include/vfs/file_system.hpp @@ -19,6 +19,8 @@ namespace vfs { struct file_system { virtual ~file_system(){}; + virtual void init(){} + virtual size_t statfs(statfs_info& file) = 0; virtual size_t read(const std::vector& file_path, char* buffer, size_t count, size_t offset, size_t& read) = 0; virtual size_t write(const std::vector& file_path, const char* buffer, size_t count, size_t offset, size_t& written) = 0; diff --git a/kernel/src/ata.cpp b/kernel/src/ata.cpp index 4dd26153..ff878247 100644 --- a/kernel/src/ata.cpp +++ b/kernel/src/ata.cpp @@ -366,8 +366,8 @@ size_t ata::ata_driver::read(void* data, char* destination, size_t count, size_t read = 0; - auto sectors = count % BLOCK_SIZE; - auto start = offset % BLOCK_SIZE; + auto sectors = count / BLOCK_SIZE; + auto start = offset / BLOCK_SIZE; auto descriptor = reinterpret_cast(data); auto disk = reinterpret_cast(descriptor->descriptor); @@ -397,8 +397,8 @@ size_t ata::ata_driver::write(void* data, const char* source, size_t count, size written = 0; - auto sectors = count % BLOCK_SIZE; - auto start = offset % BLOCK_SIZE; + auto sectors = count / BLOCK_SIZE; + auto start = offset / BLOCK_SIZE; auto descriptor = reinterpret_cast(data); auto disk = reinterpret_cast(descriptor->descriptor); @@ -428,8 +428,8 @@ size_t ata::ata_part_driver::read(void* data, char* destination, size_t count, s read = 0; - auto sectors = count % BLOCK_SIZE; - auto start = offset % BLOCK_SIZE; + auto sectors = count / BLOCK_SIZE; + auto start = offset / BLOCK_SIZE; auto part_descriptor = reinterpret_cast(data); auto descriptor = part_descriptor->disk; @@ -462,8 +462,8 @@ size_t ata::ata_part_driver::write(void* data, const char* source, size_t count, written = 0; - auto sectors = count % BLOCK_SIZE; - auto start = offset % BLOCK_SIZE; + auto sectors = count / BLOCK_SIZE; + auto start = offset / BLOCK_SIZE; auto part_descriptor = reinterpret_cast(data); auto descriptor = part_descriptor->disk; diff --git a/kernel/src/fs/fat32.cpp b/kernel/src/fs/fat32.cpp index 740aba0b..19ca263d 100644 --- a/kernel/src/fs/fat32.cpp +++ b/kernel/src/fs/fat32.cpp @@ -171,13 +171,15 @@ void init_file_entry(fat32::cluster_entry* entry_ptr, const char* name, uint32_t } //end of anonymous namespace fat32::fat32_file_system::fat32_file_system(std::string mount_point, std::string device, size_t disk_uuid, size_t partition_uuid) : mount_point(mount_point), device(device), disk(disks::disk_by_uuid(disk_uuid)) { - for(auto& p : partitions(disks::disk_by_uuid(disk_uuid))){ - if(p.uuid == partition_uuid){ - partition = p; - break; - } - } + //Nothing else to init +} +fat32::fat32_file_system::~fat32_file_system(){ + delete fat_bs; + delete fat_is; +} + +void fat32::fat32_file_system::init(){ std::unique_ptr fat_bs_tmp(new fat_bs_t()); if(read_sectors(0, 1, fat_bs_tmp.get())){ @@ -204,11 +206,6 @@ fat32::fat32_file_system::fat32_file_system(std::string mount_point, std::string } } -fat32::fat32_file_system::~fat32_file_system(){ - delete fat_bs; - delete fat_is; -} - size_t fat32::fat32_file_system::get_file(const std::vector& file_path, vfs::file& file){ auto all_files = files(file_path, 1); for(auto& f : all_files){ @@ -1295,11 +1292,11 @@ uint32_t fat32::fat32_file_system::find_free_cluster(){ } bool fat32::fat32_file_system::read_sectors(uint64_t start, uint8_t count, void* destination){ - auto result = vfs::direct_read(device.c_str(), reinterpret_cast(destination), start * 512, count * 512); - return result > 0 && result == count; + auto result = vfs::direct_read(device.c_str(), reinterpret_cast(destination), count * 512, start * 512); + return result > 0 && result == count * 512; } bool fat32::fat32_file_system::write_sectors(uint64_t start, uint8_t count, void* source){ - auto result = vfs::direct_write(device.c_str(), reinterpret_cast(source), start * 512, count * 512); - return result > 0 && result == count; + auto result = vfs::direct_write(device.c_str(), reinterpret_cast(source), count * 512, start * 512); + return result > 0 && result == count * 512; } diff --git a/kernel/src/kernel.cpp b/kernel/src/kernel.cpp index 48d54052..9a0074b1 100644 --- a/kernel/src/kernel.cpp +++ b/kernel/src/kernel.cpp @@ -65,15 +65,6 @@ void kernel_main(){ virtual_allocator::finalize(); kalloc::finalize(); - //Try to init VESA - if(vesa::vesa_enabled && !vesa::init()){ - vesa::vesa_enabled = false; - - //Unfortunately, we are in long mode, we cannot go back - //to text mode for now - suspend_boot(); - } - //Install drivers timer::install(); //acpi::init(); @@ -83,6 +74,15 @@ void kernel_main(){ //Init the virtual file system vfs::init(); + //Try to init VESA + if(vesa::vesa_enabled && !vesa::init()){ + vesa::vesa_enabled = false; + + //Unfortunately, we are in long mode, we cannot go back + //to text mode for now + suspend_boot(); + } + stdio::init_terminals(); //Only install system calls when everything else is ready diff --git a/kernel/src/vfs/vfs.cpp b/kernel/src/vfs/vfs.cpp index 2cb7d80b..d6bdf610 100644 --- a/kernel/src/vfs/vfs.cpp +++ b/kernel/src/vfs/vfs.cpp @@ -140,6 +140,11 @@ void vfs::init(){ mount_root(); mount_sys(); mount_dev(); + + //Finish initilization of the file systems + for(auto& mp : mount_point_list){ + mp.file_system->init(); + } } int64_t vfs::mount(partition_type type, const char* mount_point, const char* device){