From 106f53d9d32cfb5a1f4a3e831f71a3828c9ebc3d Mon Sep 17 00:00:00 2001 From: Baptiste Wicht Date: Sun, 14 Aug 2016 22:12:37 +0200 Subject: [PATCH] Prepare mount for more features --- programs/mount/src/main.cpp | 63 +++++++++++++++++++++++++------------ 1 file changed, 43 insertions(+), 20 deletions(-) diff --git a/programs/mount/src/main.cpp b/programs/mount/src/main.cpp index 8e716ae4..a9f4bdfe 100644 --- a/programs/mount/src/main.cpp +++ b/programs/mount/src/main.cpp @@ -13,36 +13,59 @@ static constexpr const size_t BUFFER_SIZE = 4096; -int main(int, char*[]){ - //TODO Add support to mount new directories +int main(int argc, char* argv[]){ + if(argc == 1){ + auto buffer = new char[BUFFER_SIZE]; - auto buffer = new char[BUFFER_SIZE]; + auto mp_result = mounts(buffer, BUFFER_SIZE); - auto mp_result = mounts(buffer, BUFFER_SIZE); + if(mp_result.valid()){ + size_t position = 0; - if(mp_result.valid()){ - size_t position = 0; + while(true){ + auto entry = reinterpret_cast(buffer + position); - while(true){ - auto entry = reinterpret_cast(buffer + position); + auto mount_point = &entry->name; + auto device = mount_point + entry->length_mp + 1; + auto type = device + entry->length_dev + 1; - auto mount_point = &entry->name; - auto device = mount_point + entry->length_mp + 1; - auto type = device + entry->length_dev + 1; + printf("%s %s %s\n", mount_point, device, type); - printf("%s %s %s\n", mount_point, device, type); + if(!entry->offset_next){ + break; + } - if(!entry->offset_next){ - break; + position += entry->offset_next; } - - position += entry->offset_next; + } else { + printf("mount: error: %s\n", std::error_message(mp_result.error())); } - } else { - printf("mount: error: %s\n", std::error_message(mp_result.error())); + + delete[] buffer; + + exit(0); } - delete[] buffer; + if(argc < 4){ + printf("usage: mount fs device mountpoint\n"); + + exit(1); + } + + auto fs_str = argv[1]; + auto device_str = argv[2]; + auto mount_point_str = argv[3]; + + std::string fs(fs_str); + + if(fs == "fat32"){ + printf("mkfs: Mounting %s fat32 filesystem on %s\n", mount_point_str, device_str); + + //TODO Mount new directory + } else { + printf("mkfs: Unsupported filesystem %s\n", fs_str); + exit(1); + } exit(0); -} \ No newline at end of file +}