summaryrefslogtreecommitdiff
path: root/src/bin/eeze/eeze_mount.c
diff options
context:
space:
mode:
authorGustavo Sverzut Barbieri <barbieri@gmail.com>2013-01-03 20:37:42 +0000
committerGustavo Sverzut Barbieri <barbieri@gmail.com>2013-01-03 20:37:42 +0000
commit68188ac0c89407cb35a0f04f86ad44b0deb95bdb (patch)
tree0ddf76421ab114f162c5a113f65119a6662d6a54 /src/bin/eeze/eeze_mount.c
parentf7cc32f78bf86c804a3f3ae7b8428a408092fbdf (diff)
efl: merge eeze.
Changes also in this commit: * fix missing EAPI in symbols used by modules * removed old libudev and libmount support as agreed by discomfitor/zmike * replaced __UNUSED__ with EINA_UNUSED * fixed docs hierarchy SVN revision: 82100
Diffstat (limited to 'src/bin/eeze/eeze_mount.c')
-rw-r--r--src/bin/eeze/eeze_mount.c130
1 files changed, 130 insertions, 0 deletions
diff --git a/src/bin/eeze/eeze_mount.c b/src/bin/eeze/eeze_mount.c
new file mode 100644
index 0000000000..1f1c561458
--- /dev/null
+++ b/src/bin/eeze/eeze_mount.c
@@ -0,0 +1,130 @@
1#include <Eeze.h>
2#include <Eeze_Disk.h>
3#include <Ecore.h>
4#include <Ecore_File.h>
5#include <Ecore_Getopt.h>
6#include <stdio.h>
7
8/** This app can be used as a "dumb" replacement for mount. Just don't try anything fancy yet! */
9static const Ecore_Getopt opts =
10{
11 "eeze_mount",
12 "eeze_mount /dev/sdb1 /media/disk",
13 "1.0",
14 "(C) 2010 Mike Blumenkrantz",
15 "LGPL",
16 "Mount a disk using either its /sys/ path or its /dev/ path\n\n",
17 1,
18 {
19 ECORE_GETOPT_STORE_TRUE('v', "verbose", "Enable debug output"),
20 ECORE_GETOPT_VERSION('V', "version"),
21 ECORE_GETOPT_COPYRIGHT('R', "copyright"),
22 ECORE_GETOPT_LICENSE('L', "license"),
23 ECORE_GETOPT_HELP('h', "help"),
24 ECORE_GETOPT_SENTINEL
25 }
26};
27
28void
29_mount_cb(void *data, int type, Eeze_Event_Disk_Mount *e)
30{
31 (void)data;
32 (void)type;
33 printf("Success!\n");
34 eeze_disk_free(e->disk);
35 ecore_main_loop_quit();
36}
37
38void
39_error_cb(void *data, int type, Eeze_Event_Disk_Error *de)
40{
41 (void)data;
42 (void)type;
43 printf("Could not mount disk with /dev/ path: %s!\n", eeze_disk_devpath_get(de->disk));
44 eeze_disk_free(de->disk);
45 ecore_main_loop_quit();
46}
47
48int
49main(int argc, char *argv[])
50{
51 int args;
52 const char *dev, *mount_point = NULL;
53 Eina_Bool verbose = EINA_FALSE, exit_option = EINA_FALSE;
54 Eeze_Disk *disk;
55
56 Ecore_Getopt_Value values[] =
57 {
58 ECORE_GETOPT_VALUE_BOOL(verbose),
59 ECORE_GETOPT_VALUE_BOOL(exit_option),
60 ECORE_GETOPT_VALUE_BOOL(exit_option),
61 ECORE_GETOPT_VALUE_BOOL(exit_option),
62 ECORE_GETOPT_VALUE_BOOL(exit_option)
63 };
64
65 if (argc < 2)
66 {
67 printf("Insufficient args specified!\n");
68 ecore_getopt_help(stderr, &opts);
69 exit(1);
70 }
71
72 ecore_init();
73 eeze_init();
74 ecore_app_args_set(argc, (const char **)argv);
75 args = ecore_getopt_parse(&opts, values, argc, argv);
76
77 if (exit_option)
78 return 0;
79
80 if (args < 0)
81 {
82 printf("No args specified!\n");
83 ecore_getopt_help(stderr, &opts);
84 exit(1);
85 }
86 if (verbose) eina_log_domain_level_set("eeze_disk", EINA_LOG_LEVEL_DBG);
87 dev = argv[args];
88 if (args + 1 < argc)
89 mount_point = argv[args + 1];
90 if ((!strncmp(dev, "/sys/", 5)) || (!strncmp(dev, "/dev/", 5)))
91 disk = eeze_disk_new(dev);
92 else if ((args == argc - 1) && (ecore_file_is_dir(dev)))
93 disk = eeze_disk_new_from_mount(dev);
94 else
95 {
96 printf("[Device] must be either a /dev/ path or a /sys/ path!\n");
97 ecore_getopt_help(stderr, &opts);
98 exit(1);
99 }
100 if (eeze_disk_mounted_get(disk))
101 {
102 printf("[%s] is already mounted!", dev);
103 exit(1);
104 }
105 if (argc - args > 1)
106 {
107 eeze_disk_mount_point_set(disk, mount_point);
108 if (eina_str_has_extension(dev, "iso"))
109 {
110 int f;
111 f = eeze_disk_mountopts_get(disk);
112 eeze_disk_mountopts_set(disk, f | EEZE_DISK_MOUNTOPT_LOOP);
113 }
114 }
115 ecore_event_handler_add(EEZE_EVENT_DISK_MOUNT, (Ecore_Event_Handler_Cb)_mount_cb, NULL);
116 ecore_event_handler_add(EEZE_EVENT_DISK_ERROR, (Ecore_Event_Handler_Cb)_error_cb, NULL);
117 eeze_disk_mountopts_get(disk);
118 if (!eeze_disk_mount(disk))
119 {
120 const char *mp;
121
122 mp = eeze_disk_mount_point_get(disk);
123 if (!mp) fprintf(stderr, "No mount point passed!\n");
124 else fprintf(stderr, "Mount operation could not be started!\n");
125 exit(1);
126 }
127 ecore_main_loop_begin();
128
129 return 0;
130}