added -u, --unmount option to force unmounting the disk after end of operations

This commit is contained in:
Slyvtt 2022-04-20 18:07:58 +02:00
parent 85314f8310
commit 6103d852d5
2 changed files with 12 additions and 2 deletions

View file

@ -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;

View file

@ -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);