From 6103d852d56e0a8e6a68373c65fea2e6342e5951 Mon Sep 17 00:00:00 2001 From: Slyvtt Date: Wed, 20 Apr 2022 18:07:58 +0200 Subject: [PATCH] added -u, --unmount option to force unmounting the disk after end of operations --- fxlink/main.c | 10 +++++++++- fxlink/ud2.c | 4 +++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/fxlink/main.c b/fxlink/main.c index 1892eda..0c13fad 100644 --- a/fxlink/main.c +++ b/fxlink/main.c @@ -42,6 +42,8 @@ static const char *help_string = " missing, a generic filename will be created.\n" " -q, --quiet Activate quiet mode, i.e. minimum verbosity and very\n" " limited decorations (no extra messages).\n" +" -u, --unmount Force unmount disk at the end of operations, even if\n" +" not mounted here\n" "\n" "Device filters:\n" " A device filter is a comma-separated list of properties that a device has\n" @@ -64,6 +66,7 @@ static const char *help_string = bool silentmode = false; bool loginfile = false; char *userlogfilename = NULL; +bool forceunmount = false; int main(int argc, char **argv) { @@ -86,10 +89,11 @@ int main(int argc, char **argv) { "libusb-log", required_argument, NULL, LIBUSB_LOG }, { "quiet", no_argument, NULL, 'q' }, { "fxlink-log", optional_argument, NULL, LOG_IN_FILE }, + { "unmount", no_argument, NULL, 'u' }, }; while(option >= 0 && option != '?') - switch((option = getopt_long(argc, argv, "hlbsiqf:w::", longs, NULL))) + switch((option = getopt_long(argc, argv, "hlbsiquf:w::", longs, NULL))) { case 'h': fprintf(stderr, help_string, argv[0]); @@ -118,6 +122,10 @@ int main(int argc, char **argv) printf("Enabling quiet mode (i.e. minimum verbosity)\n"); silentmode = true; break; + case 'u': + printf("Force unmount the disk at the end.\n"); + forceunmount = true; + break; case LOG_IN_FILE: printf("Enabling Log in File Mode\n"); loginfile = true; diff --git a/fxlink/ud2.c b/fxlink/ud2.c index 5eae092..765d4e4 100644 --- a/fxlink/ud2.c +++ b/fxlink/ud2.c @@ -16,6 +16,8 @@ // UDisks2 utility functions //--- +extern bool forceunmount; + int ud2_start(UDisksClient **udc_ptr, UDisksManager **udm_ptr) { GError *error = NULL; @@ -358,7 +360,7 @@ int main_send(filter_t *filter, delay_t *delay, char **files) } /* Unmount the filesystem and eject the device if we mounted it */ - if(mounted_here) { + if(mounted_here || forceunmount) { GVariant *args = g_variant_new("a{sv}", NULL); udisks_filesystem_call_unmount_sync(fs, args, NULL, &error); if(error) err("while unmounting %s: %s", dev, error->message);