diff --git a/kernel/include/fs/devfs.hpp b/kernel/include/fs/devfs.hpp new file mode 100644 index 00000000..8778d112 --- /dev/null +++ b/kernel/include/fs/devfs.hpp @@ -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 +#include +#include + +#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& 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); + size_t truncate(const std::vector& file_path, size_t size); + size_t get_file(const std::vector& file_path, vfs::file& file); + size_t ls(const std::vector& file_path, std::vector& contents); + size_t touch(const std::vector& file_path); + size_t mkdir(const std::vector& file_path); + size_t rm(const std::vector& file_path); +}; + +} + +#endif diff --git a/kernel/include/vfs/vfs.hpp b/kernel/include/vfs/vfs.hpp index 50a109ff..76381c8e 100644 --- a/kernel/include/vfs/vfs.hpp +++ b/kernel/include/vfs/vfs.hpp @@ -16,6 +16,7 @@ namespace vfs { enum class partition_type { FAT32, SYSFS, + DEVFS, UNKNOWN }; diff --git a/kernel/src/fs/devfs.cpp b/kernel/src/fs/devfs.cpp new file mode 100644 index 00000000..1c43e217 --- /dev/null +++ b/kernel/src/fs/devfs.cpp @@ -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 +#include +#include +#include + +#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& file_path, vfs::file& f){ + //TODO +} + +size_t devfs::devfs_file_system::read(const std::vector& file_path, char* buffer, size_t count, size_t offset, size_t& read){ + //TODO +} + +size_t devfs::devfs_file_system::write(const std::vector&, const char*, size_t, size_t, size_t&){ + //TODO +} + +size_t devfs::devfs_file_system::truncate(const std::vector& file_path, size_t size){ + return std::ERROR_PERMISSION_DENIED; +} + +size_t devfs::devfs_file_system::ls(const std::vector& file_path, std::vector& contents){ + //TODO +} + +size_t devfs::devfs_file_system::touch(const std::vector& ){ + return std::ERROR_PERMISSION_DENIED; +} + +size_t devfs::devfs_file_system::mkdir(const std::vector& ){ + return std::ERROR_PERMISSION_DENIED; +} + +size_t devfs::devfs_file_system::rm(const std::vector& ){ + 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; +} + diff --git a/kernel/src/vfs/vfs.cpp b/kernel/src/vfs/vfs.cpp index 9cb50ae0..bf4e7729 100644 --- a/kernel/src/vfs/vfs.cpp +++ b/kernel/src/vfs/vfs.cpp @@ -17,6 +17,7 @@ #include "fs/fat32.hpp" #include "fs/sysfs.hpp" +#include "fs/devfs.hpp" #include "scheduler.hpp" #include "flags.hpp" @@ -48,6 +49,8 @@ std::string partition_type_to_string(vfs::partition_type type){ return "FAT32"; case vfs::partition_type::SYSFS: return "sysfs"; + case vfs::partition_type::DEVFS: + return "devfs"; case vfs::partition_type::UNKNOWN: return "Unknown"; default: @@ -66,6 +69,10 @@ void mount_sys(){ mount(vfs::partition_type::SYSFS, "/sys/", "none"); } +void mount_dev(){ + mount(vfs::partition_type::DEVFS, "/dev/", "none"); +} + std::vector get_path(const char* file_path){ std::string file(file_path); @@ -132,6 +139,7 @@ std::vector get_fs_path(const std::vector& path, const void vfs::init(){ mount_root(); mount_sys(); + mount_dev(); } 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; + case vfs::partition_type::DEVFS: + fs = new devfs::devfs_file_system(mount_point); + + break; + default: return -std::ERROR_INVALID_FILE_SYSTEM; }