efl

Форк
0
/
eeze_umount.c 
117 строк · 3.0 Кб
1
#ifdef HAVE_CONFIG_H
2
# include <config.h>
3
#endif
4

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! */
13
static 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",
21
   1,
22
   {
23
      ECORE_GETOPT_STORE_TRUE('v', "verbose", "Enable debug output"),
24
      ECORE_GETOPT_VERSION('V', "version"),
25
      ECORE_GETOPT_COPYRIGHT('R', "copyright"),
26
      ECORE_GETOPT_LICENSE('L', "license"),
27
      ECORE_GETOPT_HELP('h', "help"),
28
      ECORE_GETOPT_SENTINEL
29
   }
30
};
31

32
static Eina_Bool
33
_unmount_cb(void *data EINA_UNUSED, int type EINA_UNUSED, void *info)
34
{
35
   Eeze_Event_Disk_Unmount *e = info;
36
   printf("Success!\n");
37
   eeze_disk_free(e->disk);
38
   ecore_main_loop_quit();
39
   return EINA_TRUE;
40
}
41

42
static Eina_Bool
43
_error_cb(void *data EINA_UNUSED, int type EINA_UNUSED, void *info)
44
{
45
   Eeze_Event_Disk_Error *de = info;
46
   printf("Could not unmount disk with /dev/ path: %s!\n", eeze_disk_devpath_get(de->disk));
47
   eeze_disk_free(de->disk);
48
   ecore_main_loop_quit();
49
   return EINA_TRUE;
50
}
51

52
int
53
main(int argc, char *argv[])
54
{
55
   int args;
56
   const char *dev;
57
   Eina_Bool verbose = EINA_FALSE, exit_option = EINA_FALSE;
58
   Eeze_Disk *disk;
59

60
   Ecore_Getopt_Value values[] =
61
   {
62
      ECORE_GETOPT_VALUE_BOOL(verbose),
63
      ECORE_GETOPT_VALUE_BOOL(exit_option),
64
      ECORE_GETOPT_VALUE_BOOL(exit_option),
65
      ECORE_GETOPT_VALUE_BOOL(exit_option),
66
      ECORE_GETOPT_VALUE_BOOL(exit_option)
67
   };
68

69
   if (argc < 2)
70
     {
71
        printf("Insufficient args specified!\n");
72
        ecore_getopt_help(stderr, &opts);
73
        exit(1);
74
     }
75

76
   ecore_init();
77
   eeze_init();
78
   ecore_app_args_set(argc, (const char **)argv);
79
   args = ecore_getopt_parse(&opts, values, argc, argv);
80

81
   if (exit_option)
82
     return 0;
83

84
   if (args < 0)
85
     {
86
        printf("No args specified!\n");
87
        ecore_getopt_help(stderr, &opts);
88
        exit(1);
89
     }
90
   if (verbose) eina_log_domain_level_set("eeze_disk", EINA_LOG_LEVEL_DBG);
91
   dev = argv[args];
92
   if ((!strncmp(dev, "/sys/", 5)) || (!strncmp(dev, "/dev/", 5)))
93
     disk = eeze_disk_new(dev);
94
   else if ((args == argc - 1) && (ecore_file_is_dir(dev)))
95
     disk = eeze_disk_new_from_mount(dev);
96
   else
97
     {
98
        printf("[Device] must be either a /dev/ path or a /sys/ path!\n");
99
        ecore_getopt_help(stderr, &opts);
100
        exit(1);
101
     }
102
   if (!eeze_disk_mounted_get(disk))
103
     {
104
        printf("[%s] is already unmounted!", dev);
105
        exit(1);
106
     }
107
   ecore_event_handler_add(EEZE_EVENT_DISK_UNMOUNT, _unmount_cb, NULL);
108
   ecore_event_handler_add(EEZE_EVENT_DISK_ERROR, _error_cb, NULL);
109
   if (!eeze_disk_unmount(disk))
110
     {
111
        printf("unmount operation could not be started!\n");
112
        exit(1);
113
     }
114
   ecore_main_loop_begin();
115

116
   return 0;
117
}
118

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.