mirror of
https://github.com/wichtounet/thor-os.git
synced 2025-09-13 06:29:47 -04:00
Prepare devfs file system
This commit is contained in:
parent
a8770c42bd
commit
fae7afbdb2
40
kernel/include/fs/devfs.hpp
Normal file
40
kernel/include/fs/devfs.hpp
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
//=======================================================================
|
||||||
|
// Copyright Baptiste Wicht 2013-2014.
|
||||||
|
// Distributed under the Boost Software License, Version 1.0.
|
||||||
|
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||||
|
// http://www.boost.org/LICENSE_1_0.txt)
|
||||||
|
//=======================================================================
|
||||||
|
|
||||||
|
#ifndef DEVFS_HPP
|
||||||
|
#define DEVFS_HPP
|
||||||
|
|
||||||
|
#include <vector.hpp>
|
||||||
|
#include <string.hpp>
|
||||||
|
#include <pair.hpp>
|
||||||
|
|
||||||
|
#include "vfs/file_system.hpp"
|
||||||
|
|
||||||
|
namespace devfs {
|
||||||
|
|
||||||
|
struct devfs_file_system : vfs::file_system {
|
||||||
|
private:
|
||||||
|
std::string mount_point;
|
||||||
|
|
||||||
|
public:
|
||||||
|
devfs_file_system(std::string mount_point);
|
||||||
|
~devfs_file_system();
|
||||||
|
|
||||||
|
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 write(const std::vector<std::string>& file_path, const char* buffer, size_t count, size_t offset, size_t& written);
|
||||||
|
size_t truncate(const std::vector<std::string>& file_path, size_t size);
|
||||||
|
size_t get_file(const std::vector<std::string>& file_path, vfs::file& file);
|
||||||
|
size_t ls(const std::vector<std::string>& file_path, std::vector<vfs::file>& contents);
|
||||||
|
size_t touch(const std::vector<std::string>& file_path);
|
||||||
|
size_t mkdir(const std::vector<std::string>& file_path);
|
||||||
|
size_t rm(const std::vector<std::string>& file_path);
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
@ -16,6 +16,7 @@ namespace vfs {
|
|||||||
enum class partition_type {
|
enum class partition_type {
|
||||||
FAT32,
|
FAT32,
|
||||||
SYSFS,
|
SYSFS,
|
||||||
|
DEVFS,
|
||||||
UNKNOWN
|
UNKNOWN
|
||||||
};
|
};
|
||||||
|
|
||||||
|
68
kernel/src/fs/devfs.cpp
Normal file
68
kernel/src/fs/devfs.cpp
Normal file
@ -0,0 +1,68 @@
|
|||||||
|
//=======================================================================
|
||||||
|
// Copyright Baptiste Wicht 2013-2014.
|
||||||
|
// Distributed under the Boost Software License, Version 1.0.
|
||||||
|
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||||
|
// http://www.boost.org/LICENSE_1_0.txt)
|
||||||
|
//=======================================================================
|
||||||
|
|
||||||
|
#include <types.hpp>
|
||||||
|
#include <unique_ptr.hpp>
|
||||||
|
#include <algorithms.hpp>
|
||||||
|
#include <errors.hpp>
|
||||||
|
|
||||||
|
#include "fs/devfs.hpp"
|
||||||
|
|
||||||
|
#include "console.hpp"
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
|
||||||
|
|
||||||
|
} //end of anonymous namespace
|
||||||
|
|
||||||
|
devfs::devfs_file_system::devfs_file_system(std::string mp) : mount_point(mp) {
|
||||||
|
//Nothing to init
|
||||||
|
}
|
||||||
|
|
||||||
|
devfs::devfs_file_system::~devfs_file_system(){
|
||||||
|
//Nothing to delete
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t devfs::devfs_file_system::get_file(const std::vector<std::string>& file_path, vfs::file& f){
|
||||||
|
//TODO
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t devfs::devfs_file_system::read(const std::vector<std::string>& file_path, char* buffer, size_t count, size_t offset, size_t& read){
|
||||||
|
//TODO
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t devfs::devfs_file_system::write(const std::vector<std::string>&, const char*, size_t, size_t, size_t&){
|
||||||
|
//TODO
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t devfs::devfs_file_system::truncate(const std::vector<std::string>& file_path, size_t size){
|
||||||
|
return std::ERROR_PERMISSION_DENIED;
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t devfs::devfs_file_system::ls(const std::vector<std::string>& file_path, std::vector<vfs::file>& contents){
|
||||||
|
//TODO
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t devfs::devfs_file_system::touch(const std::vector<std::string>& ){
|
||||||
|
return std::ERROR_PERMISSION_DENIED;
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t devfs::devfs_file_system::mkdir(const std::vector<std::string>& ){
|
||||||
|
return std::ERROR_PERMISSION_DENIED;
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t devfs::devfs_file_system::rm(const std::vector<std::string>& ){
|
||||||
|
return std::ERROR_PERMISSION_DENIED;
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t devfs::devfs_file_system::statfs(statfs_info& file){
|
||||||
|
file.total_size = 0;
|
||||||
|
file.free_size = 0;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
@ -17,6 +17,7 @@
|
|||||||
|
|
||||||
#include "fs/fat32.hpp"
|
#include "fs/fat32.hpp"
|
||||||
#include "fs/sysfs.hpp"
|
#include "fs/sysfs.hpp"
|
||||||
|
#include "fs/devfs.hpp"
|
||||||
|
|
||||||
#include "scheduler.hpp"
|
#include "scheduler.hpp"
|
||||||
#include "flags.hpp"
|
#include "flags.hpp"
|
||||||
@ -48,6 +49,8 @@ std::string partition_type_to_string(vfs::partition_type type){
|
|||||||
return "FAT32";
|
return "FAT32";
|
||||||
case vfs::partition_type::SYSFS:
|
case vfs::partition_type::SYSFS:
|
||||||
return "sysfs";
|
return "sysfs";
|
||||||
|
case vfs::partition_type::DEVFS:
|
||||||
|
return "devfs";
|
||||||
case vfs::partition_type::UNKNOWN:
|
case vfs::partition_type::UNKNOWN:
|
||||||
return "Unknown";
|
return "Unknown";
|
||||||
default:
|
default:
|
||||||
@ -66,6 +69,10 @@ void mount_sys(){
|
|||||||
mount(vfs::partition_type::SYSFS, "/sys/", "none");
|
mount(vfs::partition_type::SYSFS, "/sys/", "none");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void mount_dev(){
|
||||||
|
mount(vfs::partition_type::DEVFS, "/dev/", "none");
|
||||||
|
}
|
||||||
|
|
||||||
std::vector<std::string> get_path(const char* file_path){
|
std::vector<std::string> get_path(const char* file_path){
|
||||||
std::string file(file_path);
|
std::string file(file_path);
|
||||||
|
|
||||||
@ -132,6 +139,7 @@ std::vector<std::string> get_fs_path(const std::vector<std::string>& path, const
|
|||||||
void vfs::init(){
|
void vfs::init(){
|
||||||
mount_root();
|
mount_root();
|
||||||
mount_sys();
|
mount_sys();
|
||||||
|
mount_dev();
|
||||||
}
|
}
|
||||||
|
|
||||||
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){
|
||||||
@ -148,6 +156,11 @@ int64_t vfs::mount(partition_type type, const char* mount_point, const char* dev
|
|||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case vfs::partition_type::DEVFS:
|
||||||
|
fs = new devfs::devfs_file_system(mount_point);
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return -std::ERROR_INVALID_FILE_SYSTEM;
|
return -std::ERROR_INVALID_FILE_SYSTEM;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user