diff --git a/kernel/include/disks.hpp b/kernel/include/disks.hpp index 38cd189b..8e9fbe40 100644 --- a/kernel/include/disks.hpp +++ b/kernel/include/disks.hpp @@ -66,6 +66,7 @@ void unmount(); std::vector ls(); uint64_t free_size(); +bool mkdir(const std::string& directory); std::string read_file(const std::string& file); const disk_descriptor* mounted_disk(); diff --git a/kernel/include/fat32.hpp b/kernel/include/fat32.hpp index 15d51000..3a1bbb32 100644 --- a/kernel/include/fat32.hpp +++ b/kernel/include/fat32.hpp @@ -20,6 +20,8 @@ typedef const disks::disk_descriptor& dd; uint64_t free_size(dd disk, const disks::partition_descriptor& partition); std::vector ls(dd disk, const disks::partition_descriptor& partition, const std::vector& path); std::string read_file(dd disk, const disks::partition_descriptor& partition, const std::vector& path, const std::string& file); +bool mkdir(dd disk, const disks::partition_descriptor& partition, const std::vector& path, const std::string& directory); + } diff --git a/kernel/src/disks.cpp b/kernel/src/disks.cpp index 7465eac1..d78911e6 100644 --- a/kernel/src/disks.cpp +++ b/kernel/src/disks.cpp @@ -237,3 +237,11 @@ std::string disks::read_file(const std::string& file){ return fat32::read_file(*_mounted_disk, *_mounted_partition, pwd, file); } + +bool disks::mkdir(const std::string& directory){ + if(!_mounted_disk || !_mounted_partition){ + return false; + } + + return fat32::mkdir(*_mounted_disk, *_mounted_partition, pwd, directory); +} diff --git a/kernel/src/fat32.cpp b/kernel/src/fat32.cpp index c79d8994..9e11bc72 100644 --- a/kernel/src/fat32.cpp +++ b/kernel/src/fat32.cpp @@ -456,3 +456,11 @@ std::string fat32::read_file(dd disk, const disks::partition_descriptor& partiti return std::move(content); } + +bool fat32::mkdir(dd disk, const disks::partition_descriptor& partition, const std::vector& path, const std::string& directory){ + if(!cache_disk_partition(disk, partition)){ + return false; + } + + return false; +} diff --git a/kernel/src/shell.cpp b/kernel/src/shell.cpp index 721e9ee5..08aa5330 100644 --- a/kernel/src/shell.cpp +++ b/kernel/src/shell.cpp @@ -58,6 +58,7 @@ void cd_command(const std::vector& params); void pwd_command(const std::vector& params); void free_command(const std::vector& params); void cat_command(const std::vector& params); +void mkdir_command(const std::vector& params); void shutdown_command(const std::vector& params); struct command_definition { @@ -65,7 +66,7 @@ struct command_definition { void (*function)(const std::vector&); }; -command_definition commands[21] = { +command_definition commands[22] = { {"reboot", reboot_command}, {"help", help_command}, {"uptime", uptime_command}, @@ -86,6 +87,7 @@ command_definition commands[21] = { {"pwd", pwd_command}, {"sysinfo", sysinfo_command}, {"cat", cat_command}, + {"mkdir", mkdir_command}, {"shutdown", shutdown_command}, }; @@ -578,6 +580,29 @@ void cat_command(const std::vector& params){ } } +void mkdir_command(const std::vector& params){ + if(!disks::mounted_partition() || !disks::mounted_disk()){ + k_print_line("Nothing is mounted"); + + return; + } + + if(params.size() == 1){ + k_print_line("No directory provided"); + } else { + auto& directory_name = params[1]; + auto directory = find_file(directory_name); + + if(directory){ + k_printf("mkdir: Cannot create directory '%s': File exists\n", directory_name.c_str()); + } else { + if(!disks::mkdir(directory_name)){ + k_print_line("Directory creation failed"); + } + } + } +} + void shutdown_command(const std::vector&){ if(!acpi::init()){ k_print_line("Unable to init ACPI");