From 8066ce340d34837b6aff847a6f880582d4a5b5d0 Mon Sep 17 00:00:00 2001 From: Marcel Alexandru Nitan Date: Sun, 30 Jul 2023 18:50:15 +0300 Subject: [PATCH] Add option to switch between configfs and usb_gadget --- README.md | 8 +++++--- src/configfsisomanager.cpp | 2 +- src/main.cpp | 35 +++++++++++++++++++++++++++++++---- 3 files changed, 37 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index a5f0c8a..673a9c2 100644 --- a/README.md +++ b/README.md @@ -17,11 +17,13 @@ ```bash isodrive [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. +Run without any arguments to unmount any mounted files and display this help message. Optional arguments: --rw Mounts the file in read write mode. --cdrom Mounts the file as a cdrom. +-rw Mounts the file in read write mode. +-cdrom Mounts the file as a cdrom. +-configfs Forces the app to use configfs. +-usbgadget Forces the app to use usb_gadget. ``` ### Examples diff --git a/src/configfsisomanager.cpp b/src/configfsisomanager.cpp index 403f07a..40ffb84 100644 --- a/src/configfsisomanager.cpp +++ b/src/configfsisomanager.cpp @@ -65,7 +65,7 @@ void mount_iso(char *iso_path, char *cdrom, char *ro) { char *gadgetRoot = get_gadget_root(); if (gadgetRoot == nullptr) { - printf("No active gadget found\n"); + printf("No active gadget found!\n"); return; } char *configRoot = get_config_root(); diff --git a/src/main.cpp b/src/main.cpp index 5ee4af2..1df735d 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -12,14 +12,23 @@ int print_help() { "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("-rw\t\t Mounts the file in read write mode.\n"); + printf("-cdrom\t\t Mounts the file as a cdrom.\n"); + printf("-configfs\t Forces the app to use configfs.\n"); + printf("-usbgadget\t Forces the app to use usb_gadget.\n\n"); printf("UMOUNT:\n"); return 1; } void configs(char *iso_target, char *cdrom, char *ro) { + printf("Using configfs!\n"); + + if (!supported()) + { + printf("usb_gadget is not supported!\n"); + return; + } if (strcmp(ro, "1") != 0 && strcmp(ro, "0") != 0) { printf("\nFaled to parse -rw argument. Defaulting to ro\n"); printf("Check --help for more usage info\n"); @@ -36,6 +45,12 @@ void configs(char *iso_target, char *cdrom, char *ro) { } void usb(char *iso_target, char *cdrom, char *ro) { + printf("Using usb_gadget!\n"); + if (!usb_supported()) + { + printf("usb_gadget is not supported!\n"); + return; + } if (strcmp(cdrom, "0") != 0 || strcmp(ro, "1") != 0) { printf((char*)"cdrom/ro flags ignored. (this is expected)"); @@ -49,13 +64,19 @@ void usb(char *iso_target, char *cdrom, char *ro) { int main(int argc, char *argv[]) { char *iso_target = (char *)""; char *cdrom = (char *)"0"; - char *ro = (char *)"1"; + char *ro = (char *)"1"; + char *configfs = (char *)"0"; + char *usbgadget = (char *)"0"; 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 if (strcmp(argv[i], "-configfs") == 0) { + configfs = (char *)"1"; + } else if (strcmp(argv[i], "-usbgadget") == 0) { + usbgadget = (char *)"1"; } else if (strcmp(iso_target, "") == 0) { iso_target = argv[i]; } @@ -74,7 +95,13 @@ int main(int argc, char *argv[]) { printf("MOUNT:\n"); } - if (usb_supported()) + if (strcmp(configfs, "1") == 0) + configs(iso_target, cdrom, ro); + else if (strcmp(usbgadget, "1") == 0) + { + usb(iso_target, cdrom, ro); + } + else if (usb_supported()) usb(iso_target, cdrom, ro); else if (supported()) configs(iso_target, cdrom, ro);