mirror of
https://github.com/wichtounet/thor-os.git
synced 2025-09-13 14:36:37 -04:00
Better use of path
This commit is contained in:
parent
24cb35c843
commit
7773f9c3a8
@ -24,13 +24,13 @@ typedef const disks::disk_descriptor& dd;
|
|||||||
struct fat32_file_system : vfs::file_system {
|
struct fat32_file_system : vfs::file_system {
|
||||||
private:
|
private:
|
||||||
path mount_point;
|
path mount_point;
|
||||||
std::string device;
|
path device;
|
||||||
|
|
||||||
fat_bs_t* fat_bs = nullptr;
|
fat_bs_t* fat_bs = nullptr;
|
||||||
fat_is_t* fat_is = nullptr;
|
fat_is_t* fat_is = nullptr;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
fat32_file_system(path mount_point, std::string device);
|
fat32_file_system(path mount_point, path device);
|
||||||
~fat32_file_system();
|
~fat32_file_system();
|
||||||
|
|
||||||
void init();
|
void init();
|
||||||
|
@ -11,6 +11,8 @@
|
|||||||
#include <stat_info.hpp>
|
#include <stat_info.hpp>
|
||||||
#include <statfs_info.hpp>
|
#include <statfs_info.hpp>
|
||||||
|
|
||||||
|
#include "vfs/path.hpp"
|
||||||
|
|
||||||
namespace vfs {
|
namespace vfs {
|
||||||
|
|
||||||
enum class partition_type {
|
enum class partition_type {
|
||||||
@ -41,11 +43,11 @@ int64_t mount(partition_type type, size_t mp_fd, size_t dev_fd);
|
|||||||
int64_t mount(partition_type type, const char* mount_point, const char* device);
|
int64_t mount(partition_type type, const char* mount_point, const char* device);
|
||||||
|
|
||||||
//Used only inside kernel as a easy way to read a complete file
|
//Used only inside kernel as a easy way to read a complete file
|
||||||
int64_t direct_read(const std::string& file, std::string& content);
|
int64_t direct_read(const path& file, std::string& content);
|
||||||
|
|
||||||
//Use only inside the kernel for FS to access devices
|
//Use only inside the kernel for FS to access devices
|
||||||
int64_t direct_read(const char* file, char* buffer, size_t count, size_t offset = 0);
|
int64_t direct_read(const path& file, char* buffer, size_t count, size_t offset = 0);
|
||||||
int64_t direct_write(const char* file, const char* buffer, size_t count, size_t offset = 0);
|
int64_t direct_write(const path& file, const char* buffer, size_t count, size_t offset = 0);
|
||||||
|
|
||||||
} //end of namespace vfs
|
} //end of namespace vfs
|
||||||
|
|
||||||
|
@ -171,7 +171,7 @@ 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(path mount_point, std::string device) : mount_point(mount_point), device(device) {
|
fat32::fat32_file_system::fat32_file_system(path mount_point, path device) : mount_point(mount_point), device(device) {
|
||||||
//Nothing else to init
|
//Nothing else to init
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1364,11 +1364,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), count * 512, start * 512);
|
auto result = vfs::direct_read(device, reinterpret_cast<char*>(destination), count * 512, start * 512);
|
||||||
return result > 0 && result == count * 512;
|
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), count * 512, start * 512);
|
auto result = vfs::direct_write(device, reinterpret_cast<const char*>(source), count * 512, start * 512);
|
||||||
return result > 0 && result == count * 512;
|
return result > 0 && result == count * 512;
|
||||||
}
|
}
|
||||||
|
@ -614,7 +614,7 @@ int64_t scheduler::exec(const std::string& file, const std::vector<std::string>&
|
|||||||
logging::log(logging::log_level::TRACE, "scheduler:exec: read_file start\n");
|
logging::log(logging::log_level::TRACE, "scheduler:exec: read_file start\n");
|
||||||
|
|
||||||
std::string content;
|
std::string content;
|
||||||
auto result = vfs::direct_read(file, content);
|
auto result = vfs::direct_read(path(file), content);
|
||||||
if(result < 0){
|
if(result < 0){
|
||||||
logging::logf(logging::log_level::DEBUG, "scheduler: direct_read error: %s\n", std::error_message(-result));
|
logging::logf(logging::log_level::DEBUG, "scheduler: direct_read error: %s\n", std::error_message(-result));
|
||||||
|
|
||||||
|
@ -14,7 +14,6 @@
|
|||||||
|
|
||||||
#include "vfs/vfs.hpp"
|
#include "vfs/vfs.hpp"
|
||||||
#include "vfs/file_system.hpp"
|
#include "vfs/file_system.hpp"
|
||||||
#include "vfs/path.hpp"
|
|
||||||
|
|
||||||
#include "fs/fat32.hpp"
|
#include "fs/fat32.hpp"
|
||||||
#include "fs/sysfs.hpp"
|
#include "fs/sysfs.hpp"
|
||||||
@ -32,13 +31,13 @@ namespace {
|
|||||||
|
|
||||||
struct mounted_fs {
|
struct mounted_fs {
|
||||||
vfs::partition_type fs_type;
|
vfs::partition_type fs_type;
|
||||||
std::string device;
|
path device;
|
||||||
path mount_point;
|
path mount_point;
|
||||||
vfs::file_system* file_system;
|
vfs::file_system* file_system;
|
||||||
|
|
||||||
mounted_fs() = default;
|
mounted_fs() = default;
|
||||||
|
|
||||||
mounted_fs(vfs::partition_type type, std::string dev, path mp, vfs::file_system* fs) :
|
mounted_fs(vfs::partition_type type, path dev, path mp, vfs::file_system* fs) :
|
||||||
fs_type(type), device(dev), mount_point(mp), file_system(fs)
|
fs_type(type), device(dev), mount_point(mp), file_system(fs)
|
||||||
{
|
{
|
||||||
// Nothing else to init
|
// Nothing else to init
|
||||||
@ -134,7 +133,7 @@ path get_fs_path(const path& base_path, const mounted_fs& fs){
|
|||||||
return path("/") / base_path.sub_path(fs.mount_point.size());
|
return path("/") / base_path.sub_path(fs.mount_point.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
vfs::file_system* get_new_fs(vfs::partition_type type, const path& mount_point, const std::string& device){
|
vfs::file_system* get_new_fs(vfs::partition_type type, const path& mount_point, const path& device){
|
||||||
switch(type){
|
switch(type){
|
||||||
case vfs::partition_type::FAT32:
|
case vfs::partition_type::FAT32:
|
||||||
return new fat32::fat32_file_system(mount_point, device);
|
return new fat32::fat32_file_system(mount_point, device);
|
||||||
@ -201,14 +200,15 @@ int64_t vfs::mount(partition_type type, size_t mp_fd, size_t dev_fd){
|
|||||||
|
|
||||||
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){
|
||||||
path mp_path(mount_point);
|
path mp_path(mount_point);
|
||||||
|
path dev_path(device);
|
||||||
|
|
||||||
auto fs = get_new_fs(type, mp_path, device);
|
auto fs = get_new_fs(type, mp_path, dev_path);
|
||||||
|
|
||||||
if(!fs){
|
if(!fs){
|
||||||
return -std::ERROR_INVALID_FILE_SYSTEM;
|
return -std::ERROR_INVALID_FILE_SYSTEM;
|
||||||
}
|
}
|
||||||
|
|
||||||
mount_point_list.emplace_back(type, device, mp_path, fs);
|
mount_point_list.emplace_back(type, dev_path, mp_path, fs);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -235,8 +235,6 @@ int64_t vfs::open(const char* file_path, size_t flags){
|
|||||||
auto& fs = get_fs(base_path);
|
auto& fs = get_fs(base_path);
|
||||||
auto fs_path = get_fs_path(base_path, fs);
|
auto fs_path = get_fs_path(base_path, fs);
|
||||||
|
|
||||||
logging::logf(logging::log_level::TRACE, "vfs: open %s:%s \n", base_path.string().c_str(), fs_path.string().c_str());
|
|
||||||
|
|
||||||
//Special handling for opening the root
|
//Special handling for opening the root
|
||||||
if(fs_path.is_root()){
|
if(fs_path.is_root()){
|
||||||
return scheduler::register_new_handle(base_path);
|
return scheduler::register_new_handle(base_path);
|
||||||
@ -379,8 +377,7 @@ int64_t vfs::read(size_t fd, char* buffer, size_t count, size_t offset){
|
|||||||
return read;
|
return read;
|
||||||
}
|
}
|
||||||
|
|
||||||
int64_t vfs::direct_read(const char* file, char* buffer, size_t count, size_t offset){
|
int64_t vfs::direct_read(const path& base_path, char* buffer, size_t count, size_t offset){
|
||||||
auto base_path = get_path(file);
|
|
||||||
auto& fs = get_fs(base_path);
|
auto& fs = get_fs(base_path);
|
||||||
auto fs_path = get_fs_path(base_path, fs);
|
auto fs_path = get_fs_path(base_path, fs);
|
||||||
|
|
||||||
@ -442,8 +439,7 @@ int64_t vfs::clear(size_t fd, size_t count, size_t offset){
|
|||||||
return written;
|
return written;
|
||||||
}
|
}
|
||||||
|
|
||||||
int64_t vfs::direct_write(const char* file, const char* buffer, size_t count, size_t offset){
|
int64_t vfs::direct_write(const path& base_path, const char* buffer, size_t count, size_t offset){
|
||||||
auto base_path = get_path(file);
|
|
||||||
auto& fs = get_fs(base_path);
|
auto& fs = get_fs(base_path);
|
||||||
auto fs_path = get_fs_path(base_path, fs);
|
auto fs_path = get_fs_path(base_path, fs);
|
||||||
|
|
||||||
@ -475,8 +471,7 @@ int64_t vfs::truncate(size_t fd, size_t size){
|
|||||||
return result > 0 ? -result : 0;
|
return result > 0 ? -result : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int64_t vfs::direct_read(const std::string& file_path, std::string& content){
|
int64_t vfs::direct_read(const path& base_path, std::string& content){
|
||||||
auto base_path = get_path(file_path.c_str());
|
|
||||||
auto& fs = get_fs(base_path);
|
auto& fs = get_fs(base_path);
|
||||||
auto fs_path = get_fs_path(base_path, fs);
|
auto fs_path = get_fs_path(base_path, fs);
|
||||||
|
|
||||||
@ -559,7 +554,7 @@ int64_t vfs::mounts(char* buffer, size_t size){
|
|||||||
size_t total_size = 0;
|
size_t total_size = 0;
|
||||||
|
|
||||||
for(auto& mp : mount_point_list){
|
for(auto& mp : mount_point_list){
|
||||||
total_size += 4 * sizeof(size_t) + 3 + mp.device.size() + mp.mount_point.string().size() + partition_type_to_string(mp.fs_type).size();
|
total_size += 4 * sizeof(size_t) + 3 + mp.device.string().size() + mp.mount_point.string().size() + partition_type_to_string(mp.fs_type).size();
|
||||||
}
|
}
|
||||||
|
|
||||||
if(size < total_size){
|
if(size < total_size){
|
||||||
@ -576,11 +571,11 @@ int64_t vfs::mounts(char* buffer, size_t size){
|
|||||||
auto fs_type = partition_type_to_string(mp.fs_type);
|
auto fs_type = partition_type_to_string(mp.fs_type);
|
||||||
|
|
||||||
entry->length_mp = mp.mount_point.string().size();
|
entry->length_mp = mp.mount_point.string().size();
|
||||||
entry->length_dev = mp.device.size();
|
entry->length_dev = mp.device.string().size();
|
||||||
entry->length_type = fs_type.size();
|
entry->length_type = fs_type.size();
|
||||||
|
|
||||||
if(i + 1 < mount_point_list.size()){
|
if(i + 1 < mount_point_list.size()){
|
||||||
entry->offset_next = 4 * sizeof(size_t) + 3 + mp.device.size() + mp.mount_point.string().size() + fs_type.size();
|
entry->offset_next = 4 * sizeof(size_t) + 3 + mp.device.string().size() + mp.mount_point.string().size() + fs_type.size();
|
||||||
position += entry->offset_next;
|
position += entry->offset_next;
|
||||||
} else {
|
} else {
|
||||||
entry->offset_next = 0;
|
entry->offset_next = 0;
|
||||||
@ -594,8 +589,9 @@ int64_t vfs::mounts(char* buffer, size_t size){
|
|||||||
name_buffer[str_pos++] = mount_point[j];
|
name_buffer[str_pos++] = mount_point[j];
|
||||||
}
|
}
|
||||||
name_buffer[str_pos++] = '\0';
|
name_buffer[str_pos++] = '\0';
|
||||||
for(size_t j = 0; j < mp.device.size(); ++j){
|
auto device = mp.device.string();
|
||||||
name_buffer[str_pos++] = mp.device[j];
|
for(size_t j = 0; j < device.size(); ++j){
|
||||||
|
name_buffer[str_pos++] = device[j];
|
||||||
}
|
}
|
||||||
name_buffer[str_pos++] = '\0';
|
name_buffer[str_pos++] = '\0';
|
||||||
for(size_t j = 0; j < fs_type.size(); ++j){
|
for(size_t j = 0; j < fs_type.size(); ++j){
|
||||||
|
Loading…
x
Reference in New Issue
Block a user