Add simple argument parser

This commit is contained in:
Marcel Alexandru Nitan
2023-05-24 11:00:31 +00:00
parent b50b25a1ca
commit 3b472d4928
2 changed files with 53 additions and 24 deletions
+16 -21
View File
@@ -1,5 +1,7 @@
# isodrive (configfs) # isodrive (configfs)
## Building
* `sudo apt install build-essential` * `sudo apt install build-essential`
* `git clone https://github.com/nitanmarcel/isodrive` * `git clone https://github.com/nitanmarcel/isodrive`
@@ -10,36 +12,29 @@
* `sudo make install` (optional) * `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 Optional arguments:
-rw Mounts the file in read write mode.
* `sudo isodrive /full/path/to/file.iso` -cdrom Mounts the file as a cdrom.
```
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`
## Linux ## 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 ## Android
* _On Android you must be compiled in termux, using clang++_ * 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`_ * 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 ## 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 ## Credits
+37 -3
View File
@@ -1,11 +1,45 @@
#include "configfsisomanager.h" #include "configfsisomanager.h"
#include <unistd.h> #include <unistd.h>
#include <stdio.h> #include <stdio.h>
#include <string.h>
int main(int argc, char* argv[]){ int main(int argc, char* argv[]){
char *iso_target = argv[1]; char *iso_target = argv[1];
char *cdrom = (char*)"0"; char *cdrom = (char*)"0";
char *ro = (char*)"1"; 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()) if (!supported())
{ {