mirror of
https://github.com/wichtounet/thor-os.git
synced 2025-09-10 13:04:53 -04:00
Use VFS inside FAT32
This commit is contained in:
parent
9914c6cfe0
commit
daa9aff9a0
@ -34,6 +34,8 @@ public:
|
|||||||
fat32_file_system(std::string mount_point, std::string device, size_t disk, size_t partition);
|
fat32_file_system(std::string mount_point, std::string device, size_t disk, size_t partition);
|
||||||
~fat32_file_system();
|
~fat32_file_system();
|
||||||
|
|
||||||
|
void init();
|
||||||
|
|
||||||
size_t statfs(statfs_info& file);
|
size_t statfs(statfs_info& file);
|
||||||
size_t read(const std::vector<std::string>& file_path, char* buffer, size_t count, size_t offset, size_t& read);
|
size_t read(const std::vector<std::string>& file_path, char* buffer, size_t count, size_t offset, size_t& read);
|
||||||
size_t write(const std::vector<std::string>& file_path, const char* buffer, size_t count, size_t offset, size_t& written);
|
size_t write(const std::vector<std::string>& file_path, const char* buffer, size_t count, size_t offset, size_t& written);
|
||||||
|
@ -19,6 +19,8 @@ namespace vfs {
|
|||||||
struct file_system {
|
struct file_system {
|
||||||
virtual ~file_system(){};
|
virtual ~file_system(){};
|
||||||
|
|
||||||
|
virtual void init(){}
|
||||||
|
|
||||||
virtual size_t statfs(statfs_info& file) = 0;
|
virtual size_t statfs(statfs_info& file) = 0;
|
||||||
virtual size_t read(const std::vector<std::string>& file_path, char* buffer, size_t count, size_t offset, size_t& read) = 0;
|
virtual size_t read(const std::vector<std::string>& file_path, char* buffer, size_t count, size_t offset, size_t& read) = 0;
|
||||||
virtual size_t write(const std::vector<std::string>& file_path, const char* buffer, size_t count, size_t offset, size_t& written) = 0;
|
virtual size_t write(const std::vector<std::string>& file_path, const char* buffer, size_t count, size_t offset, size_t& written) = 0;
|
||||||
|
@ -366,8 +366,8 @@ size_t ata::ata_driver::read(void* data, char* destination, size_t count, size_t
|
|||||||
|
|
||||||
read = 0;
|
read = 0;
|
||||||
|
|
||||||
auto sectors = count % BLOCK_SIZE;
|
auto sectors = count / BLOCK_SIZE;
|
||||||
auto start = offset % BLOCK_SIZE;
|
auto start = offset / BLOCK_SIZE;
|
||||||
|
|
||||||
auto descriptor = reinterpret_cast<disks::disk_descriptor*>(data);
|
auto descriptor = reinterpret_cast<disks::disk_descriptor*>(data);
|
||||||
auto disk = reinterpret_cast<ata::drive_descriptor*>(descriptor->descriptor);
|
auto disk = reinterpret_cast<ata::drive_descriptor*>(descriptor->descriptor);
|
||||||
@ -397,8 +397,8 @@ size_t ata::ata_driver::write(void* data, const char* source, size_t count, size
|
|||||||
|
|
||||||
written = 0;
|
written = 0;
|
||||||
|
|
||||||
auto sectors = count % BLOCK_SIZE;
|
auto sectors = count / BLOCK_SIZE;
|
||||||
auto start = offset % BLOCK_SIZE;
|
auto start = offset / BLOCK_SIZE;
|
||||||
|
|
||||||
auto descriptor = reinterpret_cast<disks::disk_descriptor*>(data);
|
auto descriptor = reinterpret_cast<disks::disk_descriptor*>(data);
|
||||||
auto disk = reinterpret_cast<ata::drive_descriptor*>(descriptor->descriptor);
|
auto disk = reinterpret_cast<ata::drive_descriptor*>(descriptor->descriptor);
|
||||||
@ -428,8 +428,8 @@ size_t ata::ata_part_driver::read(void* data, char* destination, size_t count, s
|
|||||||
|
|
||||||
read = 0;
|
read = 0;
|
||||||
|
|
||||||
auto sectors = count % BLOCK_SIZE;
|
auto sectors = count / BLOCK_SIZE;
|
||||||
auto start = offset % BLOCK_SIZE;
|
auto start = offset / BLOCK_SIZE;
|
||||||
|
|
||||||
auto part_descriptor = reinterpret_cast<disks::partition_descriptor*>(data);
|
auto part_descriptor = reinterpret_cast<disks::partition_descriptor*>(data);
|
||||||
auto descriptor = part_descriptor->disk;
|
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;
|
written = 0;
|
||||||
|
|
||||||
auto sectors = count % BLOCK_SIZE;
|
auto sectors = count / BLOCK_SIZE;
|
||||||
auto start = offset % BLOCK_SIZE;
|
auto start = offset / BLOCK_SIZE;
|
||||||
|
|
||||||
auto part_descriptor = reinterpret_cast<disks::partition_descriptor*>(data);
|
auto part_descriptor = reinterpret_cast<disks::partition_descriptor*>(data);
|
||||||
auto descriptor = part_descriptor->disk;
|
auto descriptor = part_descriptor->disk;
|
||||||
|
@ -171,13 +171,15 @@ void init_file_entry(fat32::cluster_entry* entry_ptr, const char* name, uint32_t
|
|||||||
} //end of anonymous namespace
|
} //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)) {
|
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))){
|
//Nothing else to init
|
||||||
if(p.uuid == partition_uuid){
|
}
|
||||||
partition = p;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
fat32::fat32_file_system::~fat32_file_system(){
|
||||||
|
delete fat_bs;
|
||||||
|
delete fat_is;
|
||||||
|
}
|
||||||
|
|
||||||
|
void fat32::fat32_file_system::init(){
|
||||||
std::unique_ptr<fat_bs_t> fat_bs_tmp(new fat_bs_t());
|
std::unique_ptr<fat_bs_t> fat_bs_tmp(new fat_bs_t());
|
||||||
|
|
||||||
if(read_sectors(0, 1, fat_bs_tmp.get())){
|
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<std::string>& file_path, vfs::file& file){
|
size_t fat32::fat32_file_system::get_file(const std::vector<std::string>& file_path, vfs::file& file){
|
||||||
auto all_files = files(file_path, 1);
|
auto all_files = files(file_path, 1);
|
||||||
for(auto& f : all_files){
|
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){
|
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<char*>(destination), start * 512, count * 512);
|
auto result = vfs::direct_read(device.c_str(), reinterpret_cast<char*>(destination), count * 512, start * 512);
|
||||||
return result > 0 && result == count;
|
return result > 0 && result == count * 512;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool fat32::fat32_file_system::write_sectors(uint64_t start, uint8_t count, void* source){
|
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<const char*>(source), start * 512, count * 512);
|
auto result = vfs::direct_write(device.c_str(), reinterpret_cast<const char*>(source), count * 512, start * 512);
|
||||||
return result > 0 && result == count;
|
return result > 0 && result == count * 512;
|
||||||
}
|
}
|
||||||
|
@ -65,15 +65,6 @@ void kernel_main(){
|
|||||||
virtual_allocator::finalize();
|
virtual_allocator::finalize();
|
||||||
kalloc::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
|
//Install drivers
|
||||||
timer::install();
|
timer::install();
|
||||||
//acpi::init();
|
//acpi::init();
|
||||||
@ -83,6 +74,15 @@ void kernel_main(){
|
|||||||
//Init the virtual file system
|
//Init the virtual file system
|
||||||
vfs::init();
|
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();
|
stdio::init_terminals();
|
||||||
|
|
||||||
//Only install system calls when everything else is ready
|
//Only install system calls when everything else is ready
|
||||||
|
@ -140,6 +140,11 @@ void vfs::init(){
|
|||||||
mount_root();
|
mount_root();
|
||||||
mount_sys();
|
mount_sys();
|
||||||
mount_dev();
|
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){
|
int64_t vfs::mount(partition_type type, const char* mount_point, const char* device){
|
||||||
|
Loading…
x
Reference in New Issue
Block a user