efl
117 строк · 3.0 Кб
1#ifdef HAVE_CONFIG_H2# include <config.h>3#endif4
5#include <Eeze.h>6#include <Eeze_Disk.h>7#include <Ecore.h>8#include <Ecore_File.h>9#include <Ecore_Getopt.h>10#include <stdio.h>11
12/** This app can be used as a "dumb" replacement for unmount. Just don't try anything fancy yet! */
13static const Ecore_Getopt opts =14{
15"eeze_unmount",16"eeze_unmount /dev/sdb1 /media/disk",17"1.0",18"(C) 2010 Mike Blumenkrantz",19"LGPL",20"unmount a disk using either its /sys/ path or its /dev/ path\n\n",211,22{23ECORE_GETOPT_STORE_TRUE('v', "verbose", "Enable debug output"),24ECORE_GETOPT_VERSION('V', "version"),25ECORE_GETOPT_COPYRIGHT('R', "copyright"),26ECORE_GETOPT_LICENSE('L', "license"),27ECORE_GETOPT_HELP('h', "help"),28ECORE_GETOPT_SENTINEL
29}30};31
32static Eina_Bool33_unmount_cb(void *data EINA_UNUSED, int type EINA_UNUSED, void *info)34{
35Eeze_Event_Disk_Unmount *e = info;36printf("Success!\n");37eeze_disk_free(e->disk);38ecore_main_loop_quit();39return EINA_TRUE;40}
41
42static Eina_Bool43_error_cb(void *data EINA_UNUSED, int type EINA_UNUSED, void *info)44{
45Eeze_Event_Disk_Error *de = info;46printf("Could not unmount disk with /dev/ path: %s!\n", eeze_disk_devpath_get(de->disk));47eeze_disk_free(de->disk);48ecore_main_loop_quit();49return EINA_TRUE;50}
51
52int
53main(int argc, char *argv[])54{
55int args;56const char *dev;57Eina_Bool verbose = EINA_FALSE, exit_option = EINA_FALSE;58Eeze_Disk *disk;59
60Ecore_Getopt_Value values[] =61{62ECORE_GETOPT_VALUE_BOOL(verbose),63ECORE_GETOPT_VALUE_BOOL(exit_option),64ECORE_GETOPT_VALUE_BOOL(exit_option),65ECORE_GETOPT_VALUE_BOOL(exit_option),66ECORE_GETOPT_VALUE_BOOL(exit_option)67};68
69if (argc < 2)70{71printf("Insufficient args specified!\n");72ecore_getopt_help(stderr, &opts);73exit(1);74}75
76ecore_init();77eeze_init();78ecore_app_args_set(argc, (const char **)argv);79args = ecore_getopt_parse(&opts, values, argc, argv);80
81if (exit_option)82return 0;83
84if (args < 0)85{86printf("No args specified!\n");87ecore_getopt_help(stderr, &opts);88exit(1);89}90if (verbose) eina_log_domain_level_set("eeze_disk", EINA_LOG_LEVEL_DBG);91dev = argv[args];92if ((!strncmp(dev, "/sys/", 5)) || (!strncmp(dev, "/dev/", 5)))93disk = eeze_disk_new(dev);94else if ((args == argc - 1) && (ecore_file_is_dir(dev)))95disk = eeze_disk_new_from_mount(dev);96else97{98printf("[Device] must be either a /dev/ path or a /sys/ path!\n");99ecore_getopt_help(stderr, &opts);100exit(1);101}102if (!eeze_disk_mounted_get(disk))103{104printf("[%s] is already unmounted!", dev);105exit(1);106}107ecore_event_handler_add(EEZE_EVENT_DISK_UNMOUNT, _unmount_cb, NULL);108ecore_event_handler_add(EEZE_EVENT_DISK_ERROR, _error_cb, NULL);109if (!eeze_disk_unmount(disk))110{111printf("unmount operation could not be started!\n");112exit(1);113}114ecore_main_loop_begin();115
116return 0;117}
118