From 3b472d4928601bb78653df8a685635d797bf58cd Mon Sep 17 00:00:00 2001 From: Marcel Alexandru Nitan Date: Wed, 24 May 2023 11:00:31 +0000 Subject: [PATCH] Add simple argument parser --- README.md | 37 ++++++++++++++++--------------------- src/main.cpp | 40 +++++++++++++++++++++++++++++++++++++--- 2 files changed, 53 insertions(+), 24 deletions(-) diff --git a/README.md b/README.md index c984058..0587aa0 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,7 @@ # isodrive (configfs) +## Building + * `sudo apt install build-essential` * `git clone https://github.com/nitanmarcel/isodrive` @@ -10,36 +12,29 @@ * `sudo make install` (optional) -usage: +## Usage -* `isodrive {iso} {cdrom[0/1]} {readonly[1/0]}` +``` +cdrom [FILE]... [OPTION]... +Mounts the given FILE as a bootable device using configfs. +Run without any arguments to unmount any mounted files and to display this help message. -mount - -* `sudo isodrive /full/path/to/file.iso` - -umount - -* `sudo isodrive` - -mount (as cdrom) - -* `sudo isodrive /full/path/to/file.iso 1 1` - -mount (as read write) - -* `sudo isodrive /full/path/to/file.iso 0 0` +Optional arguments: +-rw Mounts the file in read write mode. +-cdrom Mounts the file as a cdrom. +``` ## Linux -* _Has been only tested on Halium based mobile linux, but should work on mainline devices too._ +* Has been only tested on Halium based mobile linux, but should work on mainline devices too. ## Android -* _On Android you must be compiled in termux, using clang++_ -* _On Android you might manually need to mount configfs by running: `mount -t configfs configfs /sys/kernel/config`_ +* On Android can be compiled in termux, using clang++ +* On Android you might manually need to mount configfs by running: `mount -t configfs configfs /sys/kernel/config` +* A magisk module is also available for download [HERE](https://github.com/nitanmarcel/isodrive-magisk/releases/latest) ## Os Support -* _Should support almost every bootable OS images, but for those who don't work or need extra steps, are documented in the [WIKI](https://github.com/nitanmarcel/isodrive/wiki)_ +* Should support almost every bootable OS images, but for those who don't work or need extra steps, are documented in the [WIKI](https://github.com/nitanmarcel/isodrive/wiki) ## Credits diff --git a/src/main.cpp b/src/main.cpp index 81ba960..51b0367 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,11 +1,45 @@ #include "configfsisomanager.h" #include #include +#include int main(int argc, char* argv[]){ - char *iso_target = argv[1]; - char *cdrom = (char*)"0"; - char *ro = (char*)"1"; + char *iso_target = argv[1]; + char *cdrom = (char*)"0"; + char *ro = (char*)"1"; + + for (int i = 1; i < argc; i++) + { + if (strcmp(argv[i], "-rw") == 0) + { + ro = (char*)"0"; + } + else if (strcmp(argv[i], "-cdrom") == 0) + { + cdrom = (char*)"1"; + } + else + { + iso_target = argv[i]; + } + } + + if (argc == 1) + { + printf("Usage:\n"); + printf("cdrom [FILE]... [OPTION]...\n"); + printf("Mounts the given FILE as a bootable device using configfs.\n"); + printf("Run without any arguments to unmount any mounted files and display this help message.\n\n"); + + printf("Optional arguments:\n"); + printf("-rw\t Mounts the file in read write mode.\n"); + printf("-cdrom\t Mounts the file as a cdrom.\n\n"); + printf("UMOUNT:\n"); + } + else + { + printf("MOUNT:\n"); + } if (!supported()) {