summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/Makefile.am5
-rw-r--r--src/Makefile_Eeze.am166
-rw-r--r--src/bin/eeze/eeze_disk_ls.c53
-rw-r--r--src/bin/eeze/eeze_mount.c130
-rw-r--r--src/bin/eeze/eeze_scanner.c453
-rw-r--r--src/bin/eeze/eeze_scanner.h33
-rw-r--r--src/bin/eeze/eeze_sensor_test.c173
-rw-r--r--src/bin/eeze/eeze_udev_test.c238
-rw-r--r--src/bin/eeze/eeze_umount.c113
-rw-r--r--src/lib/eeze/Eeze.h597
-rw-r--r--src/lib/eeze/Eeze_Disk.h571
-rw-r--r--src/lib/eeze/Eeze_Net.h65
-rw-r--r--src/lib/eeze/Eeze_Sensor.h325
-rw-r--r--src/lib/eeze/eeze_disk.c483
-rw-r--r--src/lib/eeze/eeze_disk_libmount.c495
-rw-r--r--src/lib/eeze/eeze_disk_libmount_new.c525
-rw-r--r--src/lib/eeze/eeze_disk_mount.c461
-rw-r--r--src/lib/eeze/eeze_disk_private.h93
-rw-r--r--src/lib/eeze/eeze_disk_udev.c90
-rw-r--r--src/lib/eeze/eeze_main.c123
-rw-r--r--src/lib/eeze/eeze_net.c323
-rw-r--r--src/lib/eeze/eeze_net_private.h53
-rw-r--r--src/lib/eeze/eeze_sensor.c320
-rw-r--r--src/lib/eeze/eeze_sensor_private.h89
-rw-r--r--src/lib/eeze/eeze_udev_find.c384
-rw-r--r--src/lib/eeze/eeze_udev_private.c200
-rw-r--r--src/lib/eeze/eeze_udev_private.h46
-rw-r--r--src/lib/eeze/eeze_udev_syspath.c292
-rw-r--r--src/lib/eeze/eeze_udev_walk.c65
-rw-r--r--src/lib/eeze/eeze_udev_watch.c449
-rw-r--r--src/modules/eeze/eeze_sensor_fake.c191
-rw-r--r--src/modules/eeze/eeze_sensor_tizen.c869
-rw-r--r--src/tests/eeze/eeze_suite.c679
33 files changed, 9152 insertions, 0 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
index 8a90462f1d..3d4b5afd88 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -61,6 +61,9 @@ include Makefile_Embryo.am
61include Makefile_Eio.am 61include Makefile_Eio.am
62include Makefile_EDBus.am 62include Makefile_EDBus.am
63include Makefile_Efreet.am 63include Makefile_Efreet.am
64if HAVE_EEZE
65include Makefile_Eeze.am
66endif
64 67
65.PHONY: benchmark examples 68.PHONY: benchmark examples
66 69
@@ -78,6 +81,7 @@ install-examples:
78clean-local: 81clean-local:
79 rm -rf bin/eet/*.gcno 82 rm -rf bin/eet/*.gcno
80 rm -rf bin/efreet/*.gcno 83 rm -rf bin/efreet/*.gcno
84 rm -rf bin/eeze/*.gcno
81 rm -rf lib/evil/*.gcno 85 rm -rf lib/evil/*.gcno
82 rm -rf lib/eina/*.gcno 86 rm -rf lib/eina/*.gcno
83 rm -rf lib/eo/*.gcno 87 rm -rf lib/eo/*.gcno
@@ -94,6 +98,7 @@ clean-local:
94 rm -rf lib/embryo/*.gcno 98 rm -rf lib/embryo/*.gcno
95 rm -rf lib/edbus/*.gcno 99 rm -rf lib/edbus/*.gcno
96 rm -rf lib/efreet/*.gcno 100 rm -rf lib/efreet/*.gcno
101 rm -rf lib/eeze/*.gcno
97 rm -rf modules/eina/mp/pass_through/*.gcno 102 rm -rf modules/eina/mp/pass_through/*.gcno
98 rm -rf modules/eina/mp/one_big/*.gcno 103 rm -rf modules/eina/mp/one_big/*.gcno
99 rm -rf modules/eina/mp/chained_pool/*.gcno 104 rm -rf modules/eina/mp/chained_pool/*.gcno
diff --git a/src/Makefile_Eeze.am b/src/Makefile_Eeze.am
new file mode 100644
index 0000000000..8e29128a38
--- /dev/null
+++ b/src/Makefile_Eeze.am
@@ -0,0 +1,166 @@
1
2### Library
3
4lib_LTLIBRARIES += \
5lib/eeze/libeeze.la
6
7EEZE_COMMON_CPPFLAGS = \
8-I$(top_srcdir)/src/lib/eina \
9-I$(top_builddir)/src/lib/eina \
10-I$(top_srcdir)/src/lib/eco \
11-I$(top_builddir)/src/lib/eo \
12-I$(top_srcdir)/src/lib/ecore \
13-I$(top_builddir)/src/lib/ecore \
14-I$(top_srcdir)/src/lib/ecore_file \
15-I$(top_builddir)/src/lib/ecore_file \
16-I$(top_srcdir)/src/lib/ecore_con \
17-I$(top_builddir)/src/lib/ecore_con \
18-I$(top_srcdir)/src/lib/eet \
19-I$(top_builddir)/src/lib/eet \
20-I$(top_srcdir)/src/lib/eeze \
21-I$(top_builddir)/src/lib/eeze \
22@EFL_COV_CFLAGS@ \
23@EEZE_CFLAGS@
24
25EEZE_COMMON_LDADD = \
26lib/eina/libeina.la \
27lib/eo/libeo.la \
28lib/ecore/libecore.la \
29@EFL_COV_LIBS@
30
31installed_eezemainheadersdir = $(includedir)/eeze-@VMAJ@
32dist_installed_eezemainheaders_DATA = \
33lib/eeze/Eeze.h \
34lib/eeze/Eeze_Net.h \
35lib/eeze/Eeze_Sensor.h
36
37# libeeze.la
38lib_eeze_libeeze_la_SOURCES = \
39lib/eeze/eeze_main.c \
40lib/eeze/eeze_net.c \
41lib/eeze/eeze_net_private.h \
42lib/eeze/eeze_udev_find.c \
43lib/eeze/eeze_udev_private.h \
44lib/eeze/eeze_udev_private.c \
45lib/eeze/eeze_udev_syspath.c \
46lib/eeze/eeze_udev_walk.c \
47lib/eeze/eeze_udev_watch.c \
48lib/eeze/eeze_sensor_private.h \
49lib/eeze/eeze_sensor.c
50
51if HAVE_EEZE_MOUNT
52dist_installed_eezemainheaders_DATA += lib/eeze/Eeze_Disk.h
53lib_eeze_libeeze_la_SOURCES += \
54lib/eeze/eeze_disk.c \
55lib/eeze/eeze_disk_udev.c \
56lib/eeze/eeze_disk_mount.c \
57lib/eeze/eeze_disk_private.h \
58lib/eeze/eeze_disk_libmount_new.c
59
60EEZE_COMMON_LDADD += \
61lib/ecore_file/libecore_file.la \
62lib/ecore_con/libecore_con.la \
63lib/eet/libeet.la
64endif
65
66EEZE_COMMON_LIBADD = $(EEZE_COMMON_LDADD) @EEZE_LIBS@
67EEZE_COMMON_LDADD += @EEZE_LDFLAGS@
68EEZE_COMMON_USER_LIBADD = $(EEZE_COMMON_LIBADD) lib/eeze/libeeze.la
69EEZE_COMMON_USER_LDADD = $(EEZE_COMMON_LDADD) lib/eeze/libeeze.la
70
71lib_eeze_libeeze_la_CPPFLAGS = \
72$(EEZE_COMMON_CPPFLAGS) \
73-DPACKAGE_BUILD_DIR=\"`pwd`/$(top_builddir)\" \
74-DPACKAGE_LIB_DIR=\"$(libdir)\" \
75-DEFL_EEZE_BUILD
76
77lib_eeze_libeeze_la_LIBADD = $(EEZE_COMMON_LIBADD)
78lib_eeze_libeeze_la_LDFLAGS = @EFL_LTLIBRARY_FLAGS@
79
80eezemodulesensordir = $(libdir)/eeze/sensor
81eezemodulesensor_LTLIBRARIES =
82
83if HAVE_EEZE_TIZEN
84eezemodulesensor_LTLIBRARIES += \
85modules/eeze/eeze-sensor-tizen.la
86modules_eeze_eeze_sensor_tizen_la_SOURCES = \
87modules/eeze/eeze_sensor_tizen.c
88modules_eeze_eeze_sensor_tizen_la_CPPFLAGS = \
89$(EEZE_COMMON_CPPFLAGS) \
90@TIZEN_SENSOR_CFLAGS@
91modules_eeze_eeze_sensor_tizen_la_LIBADD = \
92$(EEZE_COMMON_USER_LIBADD) \
93@TIZEN_SENSOR_LIBS@
94modules_eeze_eeze_sensor_tizen_la_LDFLAGS = -module @EFL_LTMODULE_FLAGS@
95modules_eeze_eeze_sensor_tizen_la_LIBTOOLFLAGS = --tag=disable-static
96else
97
98eezemodulesensor_LTLIBRARIES += \
99modules/eeze/eeze-sensor-fake.la
100modules_eeze_eeze_sensor_fake_la_SOURCES = \
101modules/eeze/eeze_sensor_fake.c
102modules_eeze_eeze_sensor_fake_la_CPPFLAGS = $(EEZE_COMMON_CPPFLAGS)
103modules_eeze_eeze_sensor_fake_la_LIBADD = $(EEZE_COMMON_USER_LIBADD)
104modules_eeze_eeze_sensor_fake_la_LDFLAGS = -module @EFL_LTMODULE_FLAGS@
105modules_eeze_eeze_sensor_fake_la_LIBTOOLFLAGS = --tag=disable-static
106endif
107
108### Binary
109
110noinst_PROGRAMS += \
111bin/eeze/eeze_udev_test \
112bin/eeze/eeze_sensor_test
113
114bin_eeze_eeze_udev_test_SOURCES = bin/eeze/eeze_udev_test.c
115bin_eeze_eeze_udev_test_CPPFLAGS = $(EEZE_COMMON_CPPFLAGS)
116bin_eeze_eeze_udev_test_LDADD = $(EEZE_COMMON_USER_LDADD)
117
118bin_eeze_eeze_sensor_test_SOURCES = bin/eeze/eeze_sensor_test.c
119bin_eeze_eeze_sensor_test_CPPFLAGS = $(EEZE_COMMON_CPPFLAGS)
120bin_eeze_eeze_sensor_test_LDADD = $(EEZE_COMMON_USER_LDADD)
121
122if HAVE_EEZE_MOUNT
123bin_PROGRAMS += \
124bin/eeze/eeze_mount \
125bin/eeze/eeze_umount \
126bin/eeze/eeze_disk_ls \
127bin/eeze/eeze_scanner
128
129bin_eeze_eeze_mount_SOURCES = bin/eeze/eeze_mount.c
130bin_eeze_eeze_mount_CPPFLAGS = $(EEZE_COMMON_CPPFLAGS)
131bin_eeze_eeze_mount_LDADD = $(EEZE_COMMON_USER_LDADD)
132
133bin_eeze_eeze_umount_SOURCES = bin/eeze/eeze_umount.c
134bin_eeze_eeze_umount_CPPFLAGS = $(EEZE_COMMON_CPPFLAGS)
135bin_eeze_eeze_umount_LDADD = $(EEZE_COMMON_USER_LDADD)
136
137bin_eeze_eeze_disk_ls_SOURCES = bin/eeze/eeze_disk_ls.c
138bin_eeze_eeze_disk_ls_CPPFLAGS = $(EEZE_COMMON_CPPFLAGS)
139bin_eeze_eeze_disk_ls_LDADD = $(EEZE_COMMON_USER_LDADD)
140
141bin_eeze_eeze_scanner_SOURCES = \
142bin/eeze/eeze_scanner.c \
143bin/eeze/eeze_scanner.h
144bin_eeze_eeze_scanner_CPPFLAGS = $(EEZE_COMMON_CPPFLAGS)
145bin_eeze_eeze_scanner_LDADD = $(EEZE_COMMON_USER_LDADD)
146endif
147
148setuid_root_mode = a=rx,u+xs
149install-data-hook::
150 @chmod $(setuid_root_mode) $(DESTDIR)$(bindir)/eeze_scanner$(EXEEXT) || true
151
152
153### Unit tests
154
155if EFL_ENABLE_TESTS
156
157check_PROGRAMS += tests/eeze/eeze_suite
158
159tests_eeze_eeze_suite_SOURCES = tests/eeze/eeze_suite.c
160tests_eeze_eeze_suite_CPPFLAGS = \
161-DTESTS_SRC_DIR=\"$(top_srcdir)/src/tests/eeze\" \
162$(EEZE_COMMON_CPPFLAGS) \
163@CHECK_CFLAGS@
164tests_eeze_eeze_suite_LDADD = $(EEZE_COMMON_USER_LDADD) @CHECK_LIBS@
165
166endif
diff --git a/src/bin/eeze/eeze_disk_ls.c b/src/bin/eeze/eeze_disk_ls.c
new file mode 100644
index 0000000000..46c4006ce6
--- /dev/null
+++ b/src/bin/eeze/eeze_disk_ls.c
@@ -0,0 +1,53 @@
1#include <stdio.h>
2#include <Ecore.h>
3#include <Eeze.h>
4#include <Eeze_Disk.h>
5
6/* simple app to print disks and their mount points */
7
8int
9main(void)
10{
11 Eina_List *disks;
12 const char *syspath;
13
14 eeze_init();
15 eeze_disk_function();
16
17 disks = eeze_udev_find_by_type(EEZE_UDEV_TYPE_DRIVE_MOUNTABLE, NULL);
18 printf("Found the following mountable disks:\n");
19 EINA_LIST_FREE(disks, syspath)
20 {
21 Eeze_Disk *disk;
22
23 disk = eeze_disk_new(syspath);
24 printf("\t%s - %s:%s\n", syspath, eeze_disk_devpath_get(disk), eeze_disk_mount_point_get(disk));
25 eeze_disk_free(disk);
26 eina_stringshare_del(syspath);
27 }
28
29 disks = eeze_udev_find_by_type(EEZE_UDEV_TYPE_DRIVE_REMOVABLE, NULL);
30 printf("Found the following removable drives:\n");
31 EINA_LIST_FREE(disks, syspath)
32 {
33 Eeze_Disk *disk;
34
35 disk = eeze_disk_new(syspath);
36 printf("\t%s - %s:%s\n", syspath, eeze_disk_devpath_get(disk), eeze_disk_mount_point_get(disk));
37 eeze_disk_free(disk);
38 eina_stringshare_del(syspath);
39 }
40
41 disks = eeze_udev_find_by_type(EEZE_UDEV_TYPE_DRIVE_INTERNAL, NULL);
42 printf("Found the following internal drives:\n");
43 EINA_LIST_FREE(disks, syspath)
44 {
45 Eeze_Disk *disk;
46
47 disk = eeze_disk_new(syspath);
48 printf("\t%s - %s\n", syspath, eeze_disk_devpath_get(disk));
49 eeze_disk_free(disk);
50 eina_stringshare_del(syspath);
51 }
52 return 0;
53}
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}
diff --git a/src/bin/eeze/eeze_scanner.c b/src/bin/eeze/eeze_scanner.c
new file mode 100644
index 0000000000..d7dda1587c
--- /dev/null
+++ b/src/bin/eeze/eeze_scanner.c
@@ -0,0 +1,453 @@
1#ifdef HAVE_CONFIG_H
2# include "config.h"
3#endif
4
5#include <Eet.h>
6#include <Eeze.h>
7#include <Ecore_Con.h>
8#include <Eeze_Disk.h>
9#include <sys/stat.h>
10#include <sys/types.h>
11#include <errno.h>
12#include <unistd.h>
13#include <fcntl.h>
14
15#include "eeze_scanner.h"
16
17#define DBG(...) EINA_LOG_DOM_DBG(es_log_dom, __VA_ARGS__)
18#define INF(...) EINA_LOG_DOM_INFO(es_log_dom, __VA_ARGS__)
19#define WRN(...) EINA_LOG_DOM_WARN(es_log_dom, __VA_ARGS__)
20#define ERR(...) EINA_LOG_DOM_ERR(es_log_dom, __VA_ARGS__)
21#define CRI(...) EINA_LOG_DOM_CRIT(es_log_dom, __VA_ARGS__)
22
23static int es_log_dom = -1;
24static Ecore_Con_Server *svr = NULL;
25static Eet_Data_Descriptor *es_edd = NULL;
26static Eina_Hash *clients = NULL;
27
28static Eina_List *storage_devices = NULL;
29static Eina_List *storage_cdrom = NULL;
30
31static Eina_List *volume_cdrom = NULL;
32static Eina_List *volume_devices = NULL;
33
34static void
35event_send(const char *device, Eeze_Scanner_Event_Type type, Eina_Bool volume)
36{
37 Eeze_Scanner_Event ev;
38 const Eina_List *l;
39 Ecore_Con_Client *cl;
40
41 ev.device = device;
42 ev.type = type;
43 ev.volume = volume;
44 EINA_LIST_FOREACH(ecore_con_server_clients_get(svr), l, cl)
45 {
46 Eet_Connection *ec;
47
48 ec = eina_hash_find(clients, cl);
49 if (!ec) continue;
50 INF("Serializing event...");
51 eet_connection_send(ec, es_edd, &ev, NULL);
52 }
53}
54
55static Eina_Bool
56event_write(const void *data, size_t size, Ecore_Con_Client *cl)
57{
58 INF("Event sent!");
59 ecore_con_client_send(cl, data, size);
60 return EINA_TRUE;
61}
62
63static Eina_Bool
64disk_mount(void *data EINA_UNUSED, int type EINA_UNUSED, Eeze_Disk *disk)
65{
66 Eina_List *l;
67 Eeze_Scanner_Device *d;
68 if (eeze_disk_type_get(disk) != EEZE_DISK_TYPE_CDROM) return ECORE_CALLBACK_RENEW;
69
70 EINA_LIST_FOREACH(storage_cdrom, l, d)
71 {
72 if (d->device == eeze_disk_syspath_get(disk))
73 {
74 d->mounted = !d->mounted;
75 break;
76 }
77 }
78 return ECORE_CALLBACK_RENEW;
79}
80
81static void
82cl_setup(Ecore_Con_Client *cl EINA_UNUSED, Eet_Connection *ec)
83{
84 Eina_List *l;
85 Eeze_Scanner_Device *dev;
86 Eeze_Scanner_Event ev;
87 const char *sys;
88
89 INF("Sending initial events to new client");
90 EINA_LIST_FOREACH(storage_devices, l, sys)
91 {
92 ev.device = sys;
93 ev.type = EEZE_SCANNER_EVENT_TYPE_ADD;
94 ev.volume = EINA_FALSE;
95 eet_connection_send(ec, es_edd, &ev, NULL);
96 }
97 EINA_LIST_FOREACH(storage_cdrom, l, dev)
98 {
99 ev.device = dev->device;
100 ev.type = EEZE_SCANNER_EVENT_TYPE_ADD;
101 ev.volume = EINA_FALSE;
102 eet_connection_send(ec, es_edd, &ev, NULL);
103 }
104 EINA_LIST_FOREACH(volume_devices, l, sys)
105 {
106 ev.device = sys;
107 ev.type = EEZE_SCANNER_EVENT_TYPE_ADD;
108 ev.volume = EINA_TRUE;
109 eet_connection_send(ec, es_edd, &ev, NULL);
110 }
111 EINA_LIST_FOREACH(volume_cdrom, l, dev)
112 {
113 ev.device = dev->device;
114 ev.type = EEZE_SCANNER_EVENT_TYPE_ADD;
115 ev.volume = EINA_TRUE;
116 eet_connection_send(ec, es_edd, &ev, NULL);
117 }
118}
119
120static Eina_Bool
121es_read(const void *eet_data EINA_UNUSED, size_t size EINA_UNUSED, void *user_data EINA_UNUSED)
122{
123 return EINA_TRUE;
124}
125
126static Eina_Bool
127cl_add(void *data EINA_UNUSED, int type EINA_UNUSED, Ecore_Con_Event_Client_Add *ev)
128{
129 Eet_Connection *ec;
130 INF("Added client");
131
132 ec = eet_connection_new(es_read, (Eet_Write_Cb*)event_write, ev->client);
133 if (!ec)
134 {
135 ERR("Could not create eet serializer! Lost client!");
136 ecore_con_client_del(ev->client);
137 return ECORE_CALLBACK_RENEW;
138 }
139
140 eina_hash_direct_add(clients, ev->client, ec);
141 cl_setup(ev->client, ec);
142 return ECORE_CALLBACK_RENEW;
143}
144
145static Eina_Bool
146cl_del(void *data EINA_UNUSED, int type EINA_UNUSED, Ecore_Con_Event_Client_Del *ev)
147{
148 Eet_Connection *ec;
149 Eina_Bool d;
150 INF("Removed client");
151 ec = eina_hash_find(clients, ev->client);
152 if (ec)
153 {
154 eet_connection_close(ec, &d);
155 eina_hash_del_by_data(clients, ec);
156 }
157
158 return ECORE_CALLBACK_RENEW;
159}
160
161static void
162eet_setup(void)
163{
164 Eet_Data_Descriptor_Class eddc;
165
166 if (!eet_eina_stream_data_descriptor_class_set(&eddc, sizeof(eddc), "eeze_scanner_event", sizeof(Eeze_Scanner_Event)))
167 {
168 CRI("Could not create eet data descriptor!");
169 exit(1);
170 }
171
172 es_edd = eet_data_descriptor_stream_new(&eddc);
173#define DAT(MEMBER, TYPE) EET_DATA_DESCRIPTOR_ADD_BASIC(es_edd, Eeze_Scanner_Event, #MEMBER, MEMBER, EET_T_##TYPE)
174 DAT(device, INLINED_STRING);
175 DAT(type, UINT);
176 DAT(volume, UCHAR);
177#undef DAT
178}
179
180static Eina_Bool
181cdrom_timer(Eeze_Scanner_Device *dev)
182{
183 const char *devpath;
184 int fd;
185
186 /* cdrom already mounted, no need to poll */
187 if (dev->mounted) return EINA_TRUE;
188 devpath = eeze_udev_syspath_get_devpath(dev->device);
189 fd = open(devpath, O_RDONLY);
190 if (fd < 0)
191 {
192 Eina_List *l;
193
194 l = eina_list_data_find_list(volume_cdrom, dev);
195 if (l)
196 {
197 /* disc removed, delete volume */
198 INF("Removed cdrom '%s'", dev->device);
199 volume_cdrom = eina_list_remove_list(volume_cdrom, l);
200 event_send(dev->device, EEZE_SCANNER_EVENT_TYPE_CHANGE, EINA_TRUE);
201 }
202 /* just in case */
203 dev->mounted = EINA_FALSE;
204 }
205 else
206 {
207 if (!eina_list_data_find(volume_cdrom, dev))
208 {
209 INF("Added cdrom '%s'", dev->device);
210 volume_cdrom = eina_list_append(volume_cdrom, dev);
211 event_send(dev->device, EEZE_SCANNER_EVENT_TYPE_CHANGE, EINA_TRUE);
212 }
213 close(fd);
214 }
215 eina_stringshare_del(devpath);
216 return EINA_TRUE;
217}
218
219static void
220storage_setup(void)
221{
222 Eina_List *l, *ll;
223 const char *sys;
224
225 storage_devices = eeze_udev_find_by_type(EEZE_UDEV_TYPE_DRIVE_INTERNAL, NULL);
226 if (!storage_devices)
227 {
228 ERR("No storage devices found! This is not supposed to happen!");
229 exit(1);
230 }
231 EINA_LIST_FOREACH(storage_devices, l, sys)
232 event_send(sys, EEZE_SCANNER_EVENT_TYPE_ADD, EINA_FALSE);
233
234 ll = eeze_udev_find_by_type(EEZE_UDEV_TYPE_DRIVE_REMOVABLE, NULL);
235 EINA_LIST_FREE(ll, sys)
236 {
237 event_send(sys, EEZE_SCANNER_EVENT_TYPE_ADD, EINA_FALSE);
238 storage_devices = eina_list_append(storage_devices, sys);
239 }
240
241 l = eeze_udev_find_by_type(EEZE_UDEV_TYPE_DRIVE_CDROM, NULL);
242 EINA_LIST_FREE(l, sys)
243 {
244 Eeze_Scanner_Device *dev;
245 Eeze_Disk *disk;
246
247 dev = calloc(1, sizeof(Eeze_Scanner_Device));
248 if (!dev)
249 {
250 ERR("Lost cdrom device '%s'!", sys);
251 eina_stringshare_del(sys);
252 continue;
253 }
254 disk = eeze_disk_new(sys);
255 if (!disk)
256 {
257 ERR("Lost cdrom device '%s'!", sys);
258 eina_stringshare_del(sys);
259 free(dev);
260 continue;
261 }
262 dev->device = sys;
263 dev->mounted = eeze_disk_mounted_get(disk);
264 eeze_disk_free(disk);
265 event_send(sys, EEZE_SCANNER_EVENT_TYPE_ADD, EINA_FALSE);
266 dev->poller = ecore_poller_add(ECORE_POLLER_CORE, 32, (Ecore_Task_Cb)cdrom_timer, dev);
267 storage_cdrom = eina_list_append(storage_cdrom, dev);
268 }
269 volume_devices = eeze_udev_find_by_type(EEZE_UDEV_TYPE_DRIVE_MOUNTABLE, NULL);
270 EINA_LIST_FOREACH_SAFE(volume_devices, l, ll, sys)
271 {
272 Eina_List *c;
273 Eeze_Scanner_Device *dev;
274
275 EINA_LIST_FOREACH(storage_cdrom, c, dev)
276 if (sys == dev->device)
277 {
278 eina_stringshare_del(sys);
279 volume_devices = eina_list_remove_list(volume_devices, l);
280 volume_cdrom = eina_list_append(volume_cdrom, dev);
281 event_send(sys, EEZE_SCANNER_EVENT_TYPE_ADD, EINA_TRUE);
282 l = NULL;
283 break;
284 }
285 if (!l) continue;
286 event_send(sys, EEZE_SCANNER_EVENT_TYPE_ADD, EINA_TRUE);
287 }
288}
289
290static void
291cb_vol_chg(const char *device, Eeze_Udev_Event ev, void *data EINA_UNUSED, Eeze_Udev_Watch *watch EINA_UNUSED)
292{
293 Eina_List *l;
294 Eeze_Scanner_Device *dev;
295
296 DBG("device='%s'", device);
297
298 if (ev == EEZE_UDEV_EVENT_ONLINE) ev = EEZE_SCANNER_EVENT_TYPE_ADD;
299 else if (ev == EEZE_UDEV_EVENT_OFFLINE) ev = EEZE_SCANNER_EVENT_TYPE_REMOVE;
300
301 event_send(device, ev, EINA_TRUE);
302 switch (ev)
303 {
304 case EEZE_UDEV_EVENT_ADD:
305 case EEZE_UDEV_EVENT_ONLINE:
306 INF("Added volume '%s'", device);
307 EINA_LIST_FOREACH(storage_cdrom, l, dev)
308 if (device == dev->device)
309 {
310 volume_cdrom = eina_list_append(volume_cdrom, dev);
311 return;
312 }
313 volume_devices = eina_list_append(volume_devices, eina_stringshare_add(device));
314 break;
315 case EEZE_UDEV_EVENT_REMOVE:
316 case EEZE_UDEV_EVENT_OFFLINE:
317 INF("Removed volume '%s'", device);
318 EINA_LIST_FOREACH(volume_cdrom, l, dev)
319 if (device == dev->device)
320 {
321 volume_cdrom = eina_list_remove_list(volume_cdrom, l);
322 return;
323 }
324 volume_devices = eina_list_remove(volume_devices, device);
325 eina_stringshare_del(device);
326 break;
327 default:
328 INF("Changed volume '%s'", device);
329 break;
330 }
331}
332
333static void
334cb_stor_chg(const char *device, Eeze_Udev_Event ev, void *data EINA_UNUSED, Eeze_Udev_Watch *watch EINA_UNUSED)
335{
336 Eina_List *l;
337 Eeze_Scanner_Device *dev = NULL;
338 const char *str;
339
340
341 DBG("device='%s'", device);
342 switch (ev)
343 {
344 case EEZE_UDEV_EVENT_ADD:
345 case EEZE_UDEV_EVENT_ONLINE:
346 INF("Added device '%s'", device);
347 event_send(device, ev, EINA_FALSE);
348 str = eeze_udev_syspath_get_property(device, "ID_CDROM");
349 if (!str)
350 {
351 storage_devices = eina_list_append(storage_devices, eina_stringshare_add(device));
352 return;
353 }
354 eina_stringshare_del(str);
355 dev = calloc(1, sizeof(Eeze_Scanner_Device));
356 dev->device = eina_stringshare_add(device);
357 dev->poller = ecore_poller_add(ECORE_POLLER_CORE, 32,
358 (Ecore_Task_Cb)cdrom_timer, dev);
359 storage_cdrom = eina_list_append(storage_cdrom, dev);
360 break;
361 case EEZE_UDEV_EVENT_REMOVE:
362 case EEZE_UDEV_EVENT_OFFLINE:
363 if (!eina_list_data_find(storage_devices, device))
364 {
365 EINA_LIST_FOREACH(storage_cdrom, l, dev)
366 if (dev->device == device) break;
367 if ((!dev) || (dev->device != device)) return;
368 }
369 INF("Removed device '%s'", device);
370 event_send(device, ev, EINA_FALSE);
371 EINA_LIST_FOREACH(storage_cdrom, l, dev)
372 if (device == dev->device)
373 {
374 if (dev->poller) ecore_poller_del(dev->poller);
375 storage_cdrom = eina_list_remove_list(storage_cdrom, l);
376 eina_stringshare_del(dev->device);
377 free(dev);
378 return;
379 }
380 storage_devices = eina_list_remove(storage_devices, device);
381 eina_stringshare_del(device);
382 break;
383 default:
384 INF("Changed device '%s'", device);
385 break;
386 }
387}
388
389static void
390es_exit(int sig)
391{
392 ecore_con_server_del(svr);
393 exit(sig);
394}
395
396static void
397sigs_setup(void)
398{
399 sigset_t sigs = {{0}};
400 struct sigaction s;
401
402 sigfillset(&sigs);
403 sigdelset(&sigs, SIGSEGV);
404 sigdelset(&sigs, SIGTERM);
405 sigdelset(&sigs, SIGINT);
406 sigdelset(&sigs, SIGQUIT);
407
408 s.sa_handler = es_exit;
409 s.sa_flags = 0;
410 sigaction(SIGTERM, &s, NULL);
411 sigaction(SIGSEGV, &s, NULL);
412 sigaction(SIGINT, &s, NULL);
413}
414
415int
416main(void)
417{
418 eina_init();
419 ecore_init();
420 ecore_con_init();
421 eeze_init();
422 eeze_disk_function();
423 eeze_mount_tabs_watch();
424
425 sigs_setup();
426 es_log_dom = eina_log_domain_register("eeze_scanner", EINA_COLOR_CYAN);
427
428 eet_setup();
429 clients = eina_hash_pointer_new(NULL);
430 EINA_SAFETY_ON_NULL_GOTO(clients, error);
431
432 ecore_event_handler_add(ECORE_CON_EVENT_CLIENT_ADD, (Ecore_Event_Handler_Cb)cl_add, NULL);
433 ecore_event_handler_add(ECORE_CON_EVENT_CLIENT_DEL, (Ecore_Event_Handler_Cb)cl_del, NULL);
434 ecore_event_handler_add(EEZE_EVENT_DISK_UNMOUNT, (Ecore_Event_Handler_Cb)disk_mount, NULL);
435 ecore_event_handler_add(EEZE_EVENT_DISK_MOUNT, (Ecore_Event_Handler_Cb)disk_mount, NULL);
436
437 eeze_udev_watch_add(EEZE_UDEV_TYPE_DRIVE_INTERNAL, EEZE_UDEV_EVENT_NONE, cb_stor_chg, NULL);
438 eeze_udev_watch_add(EEZE_UDEV_TYPE_DRIVE_REMOVABLE, EEZE_UDEV_EVENT_NONE, cb_stor_chg, NULL);
439 eeze_udev_watch_add(EEZE_UDEV_TYPE_DRIVE_CDROM, EEZE_UDEV_EVENT_NONE, cb_stor_chg, NULL);
440 eeze_udev_watch_add(EEZE_UDEV_TYPE_DRIVE_MOUNTABLE, EEZE_UDEV_EVENT_NONE, cb_vol_chg, NULL);
441
442 svr = ecore_con_server_add(ECORE_CON_LOCAL_SYSTEM, "eeze_scanner", 0, NULL);
443 EINA_SAFETY_ON_NULL_GOTO(svr, error);
444
445 storage_setup();
446 ecore_main_loop_begin();
447
448 ecore_con_server_del(svr);
449 return 0;
450error:
451 ERR("Could not start up!");
452 exit(1);
453}
diff --git a/src/bin/eeze/eeze_scanner.h b/src/bin/eeze/eeze_scanner.h
new file mode 100644
index 0000000000..a9757931af
--- /dev/null
+++ b/src/bin/eeze/eeze_scanner.h
@@ -0,0 +1,33 @@
1#ifndef EEZE_SCANNER_H
2#define EEZE_SCANNER_H
3
4#include <Eeze.h>
5
6#define EEZE_SCANNER_EDD_SETUP(edd) \
7 EET_DATA_DESCRIPTOR_ADD_BASIC((edd), Eeze_Scanner_Event, "device", device, EET_T_INLINED_STRING); \
8 EET_DATA_DESCRIPTOR_ADD_BASIC((edd), Eeze_Scanner_Event, "type", type, EET_T_UINT); \
9 EET_DATA_DESCRIPTOR_ADD_BASIC((edd), Eeze_Scanner_Event, "volume", volume, EET_T_UCHAR)
10
11typedef enum
12{
13 EEZE_SCANNER_EVENT_TYPE_NONE,
14 EEZE_SCANNER_EVENT_TYPE_ADD = EEZE_UDEV_EVENT_ADD,
15 EEZE_SCANNER_EVENT_TYPE_REMOVE = EEZE_UDEV_EVENT_REMOVE,
16 EEZE_SCANNER_EVENT_TYPE_CHANGE = EEZE_UDEV_EVENT_CHANGE
17} Eeze_Scanner_Event_Type;
18
19typedef struct
20{
21 const char *device;
22 Eeze_Scanner_Event_Type type;
23 Eina_Bool volume;
24} Eeze_Scanner_Event;
25
26typedef struct
27{
28 Ecore_Poller *poller;
29 const char *device;
30 Eina_Bool mounted;
31} Eeze_Scanner_Device;
32
33#endif
diff --git a/src/bin/eeze/eeze_sensor_test.c b/src/bin/eeze/eeze_sensor_test.c
new file mode 100644
index 0000000000..2c7387691e
--- /dev/null
+++ b/src/bin/eeze/eeze_sensor_test.c
@@ -0,0 +1,173 @@
1#ifdef HAVE_CONFIG_H
2# include <config.h>
3#endif /* ifdef HAVE_CONFIG_H */
4
5#include <Eeze.h>
6#include <Ecore.h>
7#include <stdio.h>
8#include <unistd.h>
9
10#include <Eeze_Sensor.h>
11
12/*
13 TODO
14 if you want a continual flow maybe eeze_sensor_flow_set(sens, EINA_TRUE); (by
15 default they are alll EINA_FALSE - ie dont provide a flow of events).
16*/
17
18static Eina_Bool
19event_cb(void *data EINA_UNUSED, int ev_type, void *event)
20{
21 Eeze_Sensor_Obj *sens = NULL;
22 float x, y, z;
23 int acc;
24 unsigned long long timestamp;
25
26 sens = event;
27 if (!sens) printf("can't find sensor!\n");
28 if (!eeze_sensor_accuracy_get(sens, &acc)) printf("fail get accuracy\n");
29 if (!eeze_sensor_timestamp_get(sens, &timestamp)) printf("fail get timestamp\n");
30
31 if (ev_type == EEZE_SENSOR_EVENT_ACCELEROMETER)
32 {
33 if (!eeze_sensor_xyz_get(sens, &x, &y, &z)) printf("fail get xyz\n");
34 printf("Accelerometer callback: accuracy %i, x %f, y %f, z %f at time: %lli\n", acc, x, y, z, timestamp);
35 }
36 else if (ev_type == EEZE_SENSOR_EVENT_FACEDOWN)
37 printf("Facedown callback at time: %lli\n", timestamp);
38 else if (ev_type == EEZE_SENSOR_EVENT_DOUBLETAP)
39 printf("Doubletap callback at time: %lli\n", timestamp);
40 else if (ev_type == EEZE_SENSOR_EVENT_SHAKE)
41 {
42 if (!eeze_sensor_x_get(sens, &x)) printf("fail get x\n");
43 printf("Shake callback: accuracy %i, x %f at time: %lli\n", acc, x, timestamp);
44 }
45
46 return ECORE_CALLBACK_PASS_ON;
47}
48
49int
50main(void)
51{
52 Eeze_Sensor_Obj *sens;
53 float x, y, z;
54 int acc;
55 unsigned long long timestamp;
56
57 /* Init the subsystems we use to make sure they are ready to use. */
58 ecore_init();
59 eeze_init();
60
61 printf("=== Test sync reads: ===\n");
62 /* Create a new sensor object from the type MAGNETIC. We will operate on this
63 * object to get data out of the sensor */
64 sens = eeze_sensor_new(EEZE_SENSOR_TYPE_MAGNETIC);
65 if (sens)
66 {
67 /* Request the actual sensor data from the object. A magnetic sensor
68 * has three data points so we have to use the xyz function. The data
69 * could be cached from the last read so better also get the timestamp
70 * when the data got read form the physical sensor. */
71 if (!eeze_sensor_xyz_get(sens, &x, &y, &z)) printf("fail get xyz\n");
72 /* Get the accurancy of the reading. Not all sensors support this. */
73 if (!eeze_sensor_accuracy_get(sens, &acc)) printf("fail get accuracy\n");
74 /* Here we read the timestamp the data was read out from the physical
75 * sensor. Can be used to detect how old the readout it.*/
76 if (!eeze_sensor_timestamp_get(sens, &timestamp)) printf("fail get timestamp\n");
77 printf("Magnetic output: accuracy %i, x %f, y %f, z %f at time: %lli\n", acc, x, y, z, timestamp);
78 /* Free the sensor when we do not longer use it. */
79 eeze_sensor_free(sens);
80 }
81 else
82 printf("Could not find a magnetic sensor!\n");
83
84 sens = eeze_sensor_new(EEZE_SENSOR_TYPE_ACCELEROMETER);
85 if (sens)
86 {
87 if (!eeze_sensor_xyz_get(sens, &x, &y, &z)) printf("fail get xyz\n");
88 if (!eeze_sensor_accuracy_get(sens, &acc)) printf("fail get accuracy\n");
89 if (!eeze_sensor_timestamp_get(sens, &timestamp)) printf("fail get timestamp\n");
90 printf("Acceleromter output: accuracy %i, x %f, y %f, z %f at time: %lli\n", acc, x, y, z, timestamp);
91 eeze_sensor_free(sens);
92 }
93 else
94 printf("Could not find an accelerometer sensor!\n");
95
96 sens = eeze_sensor_new(EEZE_SENSOR_TYPE_ORIENTATION);
97 if (sens)
98 {
99 if (!eeze_sensor_xyz_get(sens, &x, &y, &z)) printf("fail get xyz\n");
100 if (!eeze_sensor_accuracy_get(sens, &acc)) printf("fail get accuracy\n");
101 if (!eeze_sensor_timestamp_get(sens, &timestamp)) printf("fail get timestamp\n");
102 printf("Orientation output: accuracy %i, x %f, y %f, z %f at time: %lli\n", acc, x, y, z, timestamp);
103 eeze_sensor_free(sens);
104 }
105 else
106 printf("Could not find an orientation sensor!\n");
107
108 sens = eeze_sensor_new(EEZE_SENSOR_TYPE_GYROSCOPE);
109 if (sens)
110 {
111 if (!eeze_sensor_xyz_get(sens, &x, &y, &z)) printf("fail get xyz\n");
112 if (!eeze_sensor_accuracy_get(sens, &acc)) printf("fail get accuracy\n");
113 if (!eeze_sensor_timestamp_get(sens, &timestamp)) printf("fail get timestamp\n");
114 printf("Gyroscope output: accuracy %i, x %f, y %f, z %f at time: %lli\n", acc, x, y, z, timestamp);
115 eeze_sensor_free(sens);
116 }
117 else
118 printf("Could not find a gyroscope sensor!\n");
119
120 sens = eeze_sensor_new(EEZE_SENSOR_TYPE_PROXIMITY);
121 if (sens)
122 {
123 if (!eeze_sensor_xyz_get(sens, &x, &y, &z)) printf("fail get xyz\n");
124 if (!eeze_sensor_accuracy_get(sens, &acc)) printf("fail get accuracy\n");
125 if (!eeze_sensor_timestamp_get(sens, &timestamp)) printf("fail get timestamp\n");
126 printf("Proximity output: accuracy %i, distance %f at time: %lli\n", acc, x, timestamp);
127 eeze_sensor_free(sens);
128 }
129 else
130 printf("Could not find a proximity sensor!\n");
131
132 sens = eeze_sensor_new(EEZE_SENSOR_TYPE_LIGHT);
133 if (sens)
134 {
135 if (!eeze_sensor_xyz_get(sens, &x, &y, &z)) printf("fail get xyz\n");
136 if (!eeze_sensor_accuracy_get(sens, &acc)) printf("fail get accuracy\n");
137 if (!eeze_sensor_timestamp_get(sens, &timestamp)) printf("fail get timestamp\n");
138 printf("Light output: accuracy %i, lux %f at time: %lli\n", acc, x, timestamp);
139 }
140 else
141 printf("Could not find a light sensor!\n");
142
143 /* Get updated values on a sensor. This readout is synchronous. This way we
144 * can force a read out of the physical sensor instead of using the cached
145 * values. Depending on the hardware this can take a long time. If you don't have special
146 * requirements the cached values should be used. */
147 eeze_sensor_read(sens);
148 if (!sens) printf("can't find an light sensor!\n");
149 if (!eeze_sensor_x_get(sens, &x)) printf("fail get x\n");
150 if (!eeze_sensor_accuracy_get(sens, &acc)) printf("fail get accuracy\n");
151 if (!eeze_sensor_timestamp_get(sens, &timestamp)) printf("fail get timestamp\n");
152 printf("Light output: accuracy %i, lux %f at time: %lli\n", acc, x, timestamp);
153 eeze_sensor_free(sens);
154
155 printf("=== Test async reads / events: ===\n");
156 /* Async read request for sensors. You have to register an event handler for
157 * it first and then request the readout */
158 ecore_event_handler_add(EEZE_SENSOR_EVENT_ACCELEROMETER, event_cb, NULL);
159 sens = eeze_sensor_new(EEZE_SENSOR_TYPE_ACCELEROMETER);
160 eeze_sensor_async_read(sens, NULL);
161
162 /* Set callbacks for motion events coming in */
163 ecore_event_handler_add(EEZE_SENSOR_EVENT_FACEDOWN, event_cb, NULL);
164 ecore_event_handler_add(EEZE_SENSOR_EVENT_DOUBLETAP, event_cb, NULL);
165
166 ecore_main_loop_begin();
167
168 eeze_sensor_free(sens);
169 eeze_shutdown();
170 ecore_shutdown();
171
172 return 0;
173}
diff --git a/src/bin/eeze/eeze_udev_test.c b/src/bin/eeze/eeze_udev_test.c
new file mode 100644
index 0000000000..130771a3c4
--- /dev/null
+++ b/src/bin/eeze/eeze_udev_test.c
@@ -0,0 +1,238 @@
1#include <Eeze.h>
2#include <Ecore.h>
3#include <stdio.h>
4
5/**
6 * This demo program shows how to use some eeze_udev functions. It roughly
7 * 1kb as of now, TODO is to fix this but I'm too lazy now and it's only
8 * a demo.
9 */
10
11typedef struct kbdmouse
12{
13 Eina_List *kbds;
14 Eina_List *mice;
15 Eina_Hash *hash;
16} kbdmouse;
17
18static void
19/* event will always be a syspath starting with /sys */
20catch_events(const char *device,
21 Eeze_Udev_Event event,
22 void *data,
23 Eeze_Udev_Watch *watch)
24{
25 kbdmouse *akbdmouse = data;
26 Eina_List *l;
27 const char *name, *dev, *type;
28
29 /* the device that comes through will be prefixed by "/sys"
30 * but the saved name will not, so we check for the saved name
31 * inside the device name
32 */
33 EINA_LIST_FOREACH(akbdmouse->kbds, l, name)
34 if (!strncmp(device + 5, name, strlen(device + 5) - 8)) goto end;
35 EINA_LIST_FOREACH(akbdmouse->mice, l, name)
36 if (!strncmp(device + 5, name, strlen(device + 5) - 8)) goto end;
37
38 /* check to see if the device was just plugged in */
39 if (eeze_udev_syspath_is_kbd(device) || eeze_udev_syspath_is_mouse(device))
40 goto end;
41 /* if we reach here, the device is neither a keyboard nor a mouse that we saw
42 * previously, so we print a moderately amusing message and bail
43 */
44 printf("Sneaky sneaky! But %s is not a keyboard or a mouse!!\n", device);
45 return;
46
47end:
48 /* we stored the devpaths for all the syspaths previously so that
49 * we can retrieve them now even though the device has been removed and
50 * is inaccessible to udev
51 */
52 if ((event & EEZE_UDEV_EVENT_ADD) == EEZE_UDEV_EVENT_ADD)
53 {
54 dev = eeze_udev_syspath_get_devpath(device);
55 type = "plugged in";
56 }
57 else
58 {
59 dev = eina_hash_find(akbdmouse->hash, name);
60 type = "unplugged";
61 }
62 printf("You %s %s!\n", type, dev);
63 printf("All tests completed, exiting successfully!\n");
64 /* and the hash */
65 eina_hash_free(akbdmouse->hash);
66 /* now we free the lists */
67 eina_list_free(akbdmouse->kbds);
68 eina_list_free(akbdmouse->mice);
69 /* and the random storage struct */
70 free(akbdmouse);
71 /* and delete the watch */
72 eeze_udev_watch_del(watch);
73 /* and shut down eudev */
74 eeze_shutdown();
75 /* and quit the main loop */
76 ecore_main_loop_quit();
77}
78
79static void
80hash_free(void *data)
81{
82 eina_stringshare_del(data);
83}
84
85int
86main()
87{
88 Eina_List *type, *l;
89 const char *name, *check, *check2;
90 kbdmouse *akbdmouse;
91 Eina_Hash *hash;
92
93 ecore_init();
94 eeze_init();
95
96 hash = eina_hash_stringshared_new(hash_free);
97 akbdmouse = malloc(sizeof(kbdmouse));
98 akbdmouse->hash = hash;
99
100 printf("For my first trick, I will find all of your keyboards and return their syspaths.\n");
101 /* find all keyboards using type EEZE_UDEV_TYPE_KEYBOARD */
102 type = eeze_udev_find_by_type(EEZE_UDEV_TYPE_KEYBOARD, NULL);
103 /* add all "link" devices that aren't explicitly found, but are still
104 * part of the device chain
105 */
106 type = eeze_udev_find_unlisted_similar(type);
107 EINA_LIST_FOREACH(type, l, name)
108 {
109 /* add the devpath to the hash for use in the cb later */
110 if ((check = eeze_udev_syspath_get_devpath(name)))
111 eina_hash_direct_add(hash, name, check);
112 printf("Found keyboard: %s\n", name);
113 }
114 /* we save this list for later, because once a device is unplugged it can
115 * no longer be detected by udev, and any related properties are unusable unless
116 * they have been previously stored
117 */
118 akbdmouse->kbds = type;
119
120 printf("\nNext, I will find all of your mice and print the corresponding manufacturer.\n");
121 /* find all mice using type EEZE_UDEV_TYPE_MOUSE */
122 type = eeze_udev_find_by_type(EEZE_UDEV_TYPE_MOUSE, NULL);
123 type = eeze_udev_find_unlisted_similar(type);
124 EINA_LIST_FOREACH(type, l, name)
125 { /* add the devpath to the hash for use in the cb later */
126 if ((check = eeze_udev_syspath_get_devpath(name)))
127 eina_hash_direct_add(hash, name, check); /* get a property using the device's syspath */
128 printf("Found mouse %s with vendor: %s\n", name, eeze_udev_walk_get_sysattr(name, "manufacturer"));
129 }
130 /* we save this list for later, because once a device is unplugged it can
131 * no longer be detected by udev, and any related properties are unusable unless
132 * they have been previously stored
133 */
134 akbdmouse->mice = type;
135
136 printf("\nNow let's try something a little more difficult. Mountable filesystems!\n");
137 /* find all mountable drives using type EEZE_UDEV_TYPE_DRIVE_MOUNTABLE */
138 type = eeze_udev_find_by_type(EEZE_UDEV_TYPE_DRIVE_MOUNTABLE, NULL);
139 type = eeze_udev_find_unlisted_similar(type);
140 EINA_LIST_FREE(type, name)
141 {
142 printf("Found device: %s\n", name); /* get a property using the device's syspath */
143 if ((check = eeze_udev_syspath_get_property(name, "DEVNAME")))
144 {
145 printf("\tYou probably know it better as %s\n", check);
146 eina_stringshare_del(check);
147 }
148 if ((check = eeze_udev_syspath_get_property(name, "ID_FS_TYPE")))
149 {
150 printf("\tIt's formatted as %s", check);
151 eina_stringshare_del(check);
152 check = eeze_udev_syspath_get_property(name, "FSTAB_DIR");
153 if (check)
154 {
155 printf(", and gets mounted at %s", check);
156 eina_stringshare_del(check);
157 }
158 printf("!\n");
159 }
160 eina_stringshare_del(name);
161 }
162
163 printf("\nNetwork devices!\n");
164 type = eeze_udev_find_by_type(EEZE_UDEV_TYPE_NET, NULL);
165 type = eeze_udev_find_unlisted_similar(type);
166 EINA_LIST_FREE(type, name)
167 {
168 printf("Found device: %s\n", name); /* get a property using the device's syspath */
169 if ((check = eeze_udev_syspath_get_property(name, "INTERFACE")))
170 {
171 printf("\tYou probably know it better as %s\n", check);
172 eina_stringshare_del(check);
173 }
174 eina_stringshare_del(name);
175 }
176
177 printf("\nInternal drives, anyone? With serial numbers?\n");
178 /* find all internal drives using type EEZE_UDEV_TYPE_DRIVE_INTERNAL */
179 type = eeze_udev_find_by_type(EEZE_UDEV_TYPE_DRIVE_INTERNAL, NULL);
180 type = eeze_udev_find_unlisted_similar(type);
181 EINA_LIST_FREE(type, name) /* get a property using the device's syspath */
182 {
183 if ((check = eeze_udev_syspath_get_property(name, "ID_SERIAL")))
184 {
185 printf("%s: %s\n", name, check);
186 eina_stringshare_del(check);
187 }
188 eina_stringshare_del(name);
189 }
190
191 printf("\nGot any removables? I'm gonna find em!\n");
192 /* find all removable media using type EEZE_UDEV_TYPE_DRIVE_REMOVABLE */
193 type = eeze_udev_find_by_type(EEZE_UDEV_TYPE_DRIVE_REMOVABLE, NULL);
194 type = eeze_udev_find_unlisted_similar(type);
195 EINA_LIST_FREE(type, name) /* get a property using the device's syspath */
196 {
197 if ((check = eeze_udev_syspath_get_sysattr(name, "model")))
198 {
199 check2 = eeze_udev_syspath_get_subsystem(name);
200 printf("\tOoh, a %s attached to the %s subsytem!\n", check, check2);
201 eina_stringshare_del(check);
202 eina_stringshare_del(check2);
203 }
204 eina_stringshare_del(name);
205 }
206
207 printf("\nGot any v4l device ?\n");
208 /* find all V4L device, may be a webcam or anything that can get a video
209 * stream from the real worl in a numerical form */
210 type = eeze_udev_find_by_type(EEZE_UDEV_TYPE_V4L, NULL);
211 type = eeze_udev_find_unlisted_similar(type);
212 EINA_LIST_FREE(type, name) /* get a device name using the device's syspath */
213 {
214 if ((check = eeze_udev_syspath_get_property(name, "DEVNAME")))
215 {
216 if ((check2 = eeze_udev_syspath_get_sysattr(name, "name")))
217 {
218 printf("%s: '%s' [%s]\n", name, check2, check);
219 eina_stringshare_del(check2);
220 }
221 eina_stringshare_del(check);
222 }
223 eina_stringshare_del(name);
224 }
225
226 /* set a udev watch, grab all events because no EEZE_UDEV_TYPE filter is specified,
227 * set the events to be sent to callback function catch_events(), and attach
228 * kbdmouse to the watch as associated data
229 */
230 eeze_udev_watch_add(EEZE_UDEV_TYPE_NONE, (EEZE_UDEV_EVENT_ADD | EEZE_UDEV_EVENT_REMOVE), catch_events, akbdmouse);
231 printf("\nAnd now for something more complicated. Plug or unplug your keyboard or mouse for me.\n");
232
233 /* main loop must be started to use ecore fd polling */
234 ecore_main_loop_begin();
235
236 return 0;
237}
238
diff --git a/src/bin/eeze/eeze_umount.c b/src/bin/eeze/eeze_umount.c
new file mode 100644
index 0000000000..75d5ebbf31
--- /dev/null
+++ b/src/bin/eeze/eeze_umount.c
@@ -0,0 +1,113 @@
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 unmount. Just don't try anything fancy yet! */
9static const Ecore_Getopt opts =
10{
11 "eeze_unmount",
12 "eeze_unmount /dev/sdb1 /media/disk",
13 "1.0",
14 "(C) 2010 Mike Blumenkrantz",
15 "LGPL",
16 "unmount 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_unmount_cb(void *data, int type, Eeze_Event_Disk_Unmount *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 unmount 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;
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 ((!strncmp(dev, "/sys/", 5)) || (!strncmp(dev, "/dev/", 5)))
89 disk = eeze_disk_new(dev);
90 else if ((args == argc - 1) && (ecore_file_is_dir(dev)))
91 disk = eeze_disk_new_from_mount(dev);
92 else
93 {
94 printf("[Device] must be either a /dev/ path or a /sys/ path!\n");
95 ecore_getopt_help(stderr, &opts);
96 exit(1);
97 }
98 if (!eeze_disk_mounted_get(disk))
99 {
100 printf("[%s] is already unmounted!", dev);
101 exit(1);
102 }
103 ecore_event_handler_add(EEZE_EVENT_DISK_UNMOUNT, (Ecore_Event_Handler_Cb)_unmount_cb, NULL);
104 ecore_event_handler_add(EEZE_EVENT_DISK_ERROR, (Ecore_Event_Handler_Cb)_error_cb, NULL);
105 if (!eeze_disk_unmount(disk))
106 {
107 printf("unmount operation could not be started!\n");
108 exit(1);
109 }
110 ecore_main_loop_begin();
111
112 return 0;
113}
diff --git a/src/lib/eeze/Eeze.h b/src/lib/eeze/Eeze.h
new file mode 100644
index 0000000000..82ef11ae82
--- /dev/null
+++ b/src/lib/eeze/Eeze.h
@@ -0,0 +1,597 @@
1/**
2
3 @brief Eeze Device Library
4
5 @page eeze_main Eeze
6
7 @date 2010 (created)
8
9 @section toc Table of Contents
10
11 @li @ref eeze_main_intro
12 @li @ref eeze_main_compiling
13 @li @ref eeze_main_next_steps
14
15 @section eeze_main_intro Introduction
16
17 Eeze is a library for manipulating devices through udev with a
18 simple and fast api. It interfaces directly with libudev, avoiding
19 such middleman daemons as udisks/upower or hal, to immediately
20 gather device information the instant it becomes known to the
21 system. This can be used to determine such things as:
22
23 @li If a cdrom has a disk inserted
24 @li The temperature of a cpu core
25 @li The remaining power left in a battery
26 @li The current power consumption of various parts
27 @li Monitor in realtime the status of peripheral devices
28
29 Each of the above examples can be performed by using only a single eeze
30 function, as one of the primary focuses of the library is to reduce the
31 complexity of managing devices.
32
33 @section eeze_main_compiling How to compile
34
35 Eeze is a library your application links to. The procedure for this is very
36 simple. You simply have to compile your application with the appropriate
37 compiler flags that the @p pkg-config script outputs. For example:
38
39 Compiling C or C++ files into object files:
40
41 @verbatim
42 gcc -c -o main.o main.c `pkg-config --cflags eeze`
43 @endverbatim
44
45 Linking object files into a binary executable:
46
47 @verbatim
48 gcc -o my_application main.o `pkg-config --libs eeze`
49 @endverbatim
50
51 See @ref pkgconfig
52
53 @section eeze_main_next_steps Next Steps
54
55 After you understood what Eeze is and installed it in your system
56 you should proceed understanding the programming interface. We'd
57 recommend you to take a while to learn @ref Eina and @ref Ecore as
58 they convenient and Eeze provides integration with it.
59
60 Recommended reading:
61
62 @li @link Eeze.h Eeze functions @endlink
63 @li @ref Eeze_Udev UDEV functions
64 @li @ref Eeze_Watch Functions that watch for events
65 @li @ref Eeze_Syspath Functions that accept a device /sys/ path
66 @li @ref Eeze_Find Functions which find types of devices
67 @li @ref Eeze_Disk Disk functions
68 @li @ref Eeze_Net Net functions
69 @li @ref Eeze_Sensor Sensor functions
70
71 */
72#ifndef EEZE_UDEV_H
73#define EEZE_UDEV_H
74
75#include <Eina.h>
76
77#ifdef EAPI
78# undef EAPI
79#endif
80
81#ifdef __GNUC__
82# if __GNUC__ >= 4
83# define EAPI __attribute__ ((visibility("default")))
84# else
85# define EAPI
86# endif
87#else
88# define EAPI
89#endif
90
91/**
92 * @file Eeze.h
93 * @brief Easy device manipulation.
94 *
95 * Eeze is a library for manipulating devices through udev with a simple and fast
96 * api. It interfaces directly with libudev, avoiding such middleman daemons as
97 * udisks/upower or hal, to immediately gather device information the instant it
98 * becomes known to the system. This can be used to determine such things as:
99 * @li If a cdrom has a disk inserted
100 * @li The temperature of a cpu core
101 * @li The remaining power left in a battery
102 * @li The current power consumption of various parts
103 * @li Monitor in realtime the status of peripheral devices
104 * Each of the above examples can be performed by using only a single eeze
105 * function, as one of the primary focuses of the library is to reduce the
106 * complexity of managing devices.
107 *
108 *
109 * For udev functions, see @ref udev.
110 */
111
112/**
113 * @defgroup Eeze_Main main
114 * @ingroup Eeze
115 *
116 * These are general eeze functions which include init and shutdown.
117 */
118
119/**
120 * @defgroup Eeze_Udev udev
121 * @ingroup Eeze_Main
122 *
123 * These are functions which interact directly with udev.
124 */
125
126/**
127 * @addtogroup Eeze_Udev
128 *
129 * These are the device subsystems of udev:
130 * @li ac97
131 * @li acpi
132 * @li bdi
133 * @li block
134 * @li bsg
135 * @li dmi
136 * @li graphics
137 * @li hid
138 * @li hwmon
139 * @li i2c
140 * @li input
141 * @li mem
142 * @li misc
143 * @li net
144 * @li pci
145 * @li pci_bus
146 * @li pci_express
147 * @li platform
148 * @li pnp
149 * @li rtc
150 * @li scsi
151 * @li scsi_device
152 * @li scsi_disk
153 * @li scsi_generic
154 * @li scsi_host
155 * @li serio
156 * @li sound
157 * @li thermal
158 * @li tty
159 * @li usb
160 * @li usb_device
161 * @li vc
162 * @li vtconsole
163 *
164 * These are the devtypes of udev.
165 * @li atapi
166 * @li audio
167 * @li block
168 * @li cd
169 * @li char
170 * @li disk
171 * @li floppy
172 * @li generic
173 * @li hid
174 * @li hub
175 * @li media
176 * @li optical
177 * @li printer
178 * @li rbc
179 * @li scsi
180 * @li storage
181 * @li tape
182 * @li video
183 */
184#ifdef __cplusplus
185extern "C" {
186#endif
187
188/**
189 * @addtogroup Eeze_Udev
190 * @typedef Eeze_Udev_Event
191 * @enum Eeze_Udev_Event
192 * @brief Flags for watch events
193 *
194 * These events are used to specify the events to watch in a
195 * #Eeze_Udev_Watch. They can be ORed together.
196 *@{
197 */
198typedef enum
199{
200 /** - No event specified */
201 EEZE_UDEV_EVENT_NONE = 0xf0,
202 /** - Device added */
203 EEZE_UDEV_EVENT_ADD = (1 << 1),
204 /** - Device removed */
205 EEZE_UDEV_EVENT_REMOVE = (1 << 2),
206 /** - Device changed */
207 EEZE_UDEV_EVENT_CHANGE = (1 << 3),
208 /** - Device has come online */
209 EEZE_UDEV_EVENT_ONLINE = (1 << 4),
210 /** - Device has gone offline */
211 EEZE_UDEV_EVENT_OFFLINE = (1 << 5)
212} Eeze_Udev_Event;
213/** @} */
214
215/**
216 * @addtogroup Eeze_Udev udev
217 * @typedef Eeze_Udev_Type Eeze_Udev_Type
218 * @enum Eeze_Udev_Type
219 * @brief Convenience types to simplify udev access.
220 *
221 * These types allow easy access to certain udev device types. They
222 * may only be used in specified functions.
223 *
224 * @{
225 */
226/*FIXME: these probably need to be bitmasks with categories*/
227typedef enum
228{
229 /** - No type */
230 EEZE_UDEV_TYPE_NONE,
231 /** - Keyboard device */
232 EEZE_UDEV_TYPE_KEYBOARD,
233 /** - Mouse device */
234 EEZE_UDEV_TYPE_MOUSE,
235 /** - Touchpad device */
236 EEZE_UDEV_TYPE_TOUCHPAD,
237 /** - Mountable drive */
238 EEZE_UDEV_TYPE_DRIVE_MOUNTABLE,
239 /** - Internal drive */
240 EEZE_UDEV_TYPE_DRIVE_INTERNAL,
241 /** - Removable drive */
242 EEZE_UDEV_TYPE_DRIVE_REMOVABLE,
243 /** - cd drive */
244 EEZE_UDEV_TYPE_DRIVE_CDROM,
245 /** - AC adapter */
246 EEZE_UDEV_TYPE_POWER_AC,
247 /** - Battery */
248 EEZE_UDEV_TYPE_POWER_BAT,
249 /** - Temperature sensor */
250 EEZE_UDEV_TYPE_IS_IT_HOT_OR_IS_IT_COLD_SENSOR,
251 /** - Network devices */
252 EEZE_UDEV_TYPE_NET,
253 /** - WebCam */
254 EEZE_UDEV_TYPE_V4L,
255 /** - Bluetooth */
256 EEZE_UDEV_TYPE_BLUETOOTH,
257 /** - Joystick
258 * @since 1.7
259 */
260 EEZE_UDEV_TYPE_JOYSTICK
261} Eeze_Udev_Type;
262/**@}*/
263
264struct Eeze_Udev_Watch;
265
266/**
267 * @addtogroup Eeze_Watch
268 * @typedef Eeze_Udev_Watch Eeze_Udev_Watch
269 * @brief Opaque structure to hold data for a udev watch
270 */
271typedef struct Eeze_Udev_Watch Eeze_Udev_Watch;
272
273#define EEZE_VERSION_MAJOR 1
274#define EEZE_VERSION_MINOR 8
275
276 typedef struct _Eeze_Version
277 {
278 int major;
279 int minor;
280 int micro;
281 int revision;
282 } Eeze_Version;
283
284 EAPI extern Eeze_Version *eeze_version;
285
286/**
287 * @addtogroup Eeze_Watch
288 * @typedef Eeze_Udev_Watch_Cb Eeze_Udev_Watch_Cb
289 * @brief Callback type for use with #Eeze_Udev_Watch
290 */
291typedef void(*Eeze_Udev_Watch_Cb)(const char *, Eeze_Udev_Event, void *, Eeze_Udev_Watch *);
292
293
294/**
295 * Initialize the eeze library.
296 * @return The number of times the function has been called, or -1 on failure.
297 *
298 * This function should be called prior to using any eeze functions, and MUST
299 * be called prior to using any udev functions to avoid a segv.
300 *
301 * @ingroup Eeze_Main
302 */
303EAPI int eeze_init(void);
304
305/**
306 * Shut down the eeze library.
307 * @return The number of times the eeze_init has been called, or -1 when
308 * all occurrences of eeze have been shut down.
309 *
310 * This function should be called when no further eeze functions will be called.
311 *
312 * @ingroup Eeze_Main
313 */
314EAPI int eeze_shutdown(void);
315
316 /**
317 * @addtogroup Eeze_Find Find
318 *
319 * These are functions which find/supplement lists of devices.
320 *
321 * @ingroup Eeze_Udev
322 *
323 * @{
324 */
325
326/**
327 * Returns a stringshared list of all syspaths that are (or should be) the same
328 * device as the device pointed at by @p syspath.
329 *
330 * @param syspath The syspath of the device to find matches for
331 * @return All devices which are the same as the one passed
332 */
333EAPI Eina_List *eeze_udev_find_similar_from_syspath(const char *syspath);
334
335/**
336 * Updates a list of all syspaths that are (or should be) the same
337 * device.
338 *
339 * @param list The list of devices to update
340 * @return The updated list
341 *
342 * This function will update @p list to include all devices matching
343 * devices with syspaths currently stored in @p list. All strings are
344 * stringshared.
345 *
346 * @note This is an expensive call, do not use it unless you must.
347 */
348EAPI Eina_List *eeze_udev_find_unlisted_similar(Eina_List *list);
349
350/**
351 * Find a list of devices by a sysattr (and, optionally, a value of that sysattr).
352 *
353 * @param sysattr The attribute to find
354 * @param value Optional: the value that the attribute should have
355 *
356 * @return A stringshared list of the devices found with the attribute
357 *
358 * @ingroup Eeze_Find
359 */
360EAPI Eina_List *eeze_udev_find_by_sysattr(const char *sysattr, const char *value);
361
362/**
363 * Find devices using an #Eeze_Udev_Type and/or a name.
364 *
365 * @param type An #Eeze_Udev_Type or 0
366 * @param name A filter for the device name or @c NULL
367 * @return A stringshared Eina_List of matched devices or @c NULL on failure
368 *
369 * Return a list of syspaths (/sys/$syspath) for matching udev devices.
370 */
371EAPI Eina_List *eeze_udev_find_by_type(Eeze_Udev_Type type, const char *name);
372
373/**
374 * A more advanced find, allows finds using udev properties.
375 *
376 * @param subsystem The udev subsystem to filter by, or @c NULL
377 * @param type "ID_INPUT_KEY", "ID_INPUT_MOUSE", "ID_INPUT_TOUCHPAD", @c NULL, etc
378 * @param name A filter for the device name, or @c NULL
379 * @return A stringshared Eina_List* of matched devices or @c NULL on failure
380 *
381 * Return a list of syspaths (/sys/$syspath) for matching udev devices.
382 * Requires at least one filter.
383 */
384EAPI Eina_List *eeze_udev_find_by_filter(const char *subsystem, const char *type, const char *name);
385 /**
386 * @}
387 */
388
389 /**
390 * @addtogroup Eeze_Syspath Syspath
391 *
392 * These are functions which interact with the syspath (/sys/$PATH) of
393 * a device.
394 *
395 * @ingroup Eeze_Udev
396 *
397 * @{
398 */
399
400/**
401 * Get the syspath of a device from the /dev/ path.
402 *
403 * @param devpath The /dev/ path of the device
404 * @return A stringshared char* which corresponds to the /sys/ path of the device or @c NULL on failure
405 *
406 * Takes "/dev/path" and returns the corresponding /sys/ path (without the "/sys/")
407 */
408EAPI const char *eeze_udev_devpath_get_syspath(const char *devpath);
409
410/**
411 * Find the root device of a device from its syspath.
412 *
413 * @param syspath The syspath of a device, with or without "/sys/"
414 * @return The syspath of the parent device
415 *
416 * Return a stringshared syspath (/sys/$syspath) for the parent device.
417 */
418EAPI const char *eeze_udev_syspath_get_parent(const char *syspath);
419
420/**
421 * Returns a list of all parent device syspaths for @p syspath.
422 *
423 * @param syspath The device to find parents of
424 * @return A stringshared list of the parent devices of @p syspath
425 */
426EAPI Eina_List *eeze_udev_syspath_get_parents(const char *syspath);
427
428/**
429 * Get the /dev/ path from the /sys/ path.
430 *
431 * @param syspath The /sys/ path with or without the /sys/
432 * @return A stringshared char* with the /dev/ path or @c NULL on failure
433 *
434 * Takes /sys/$PATH and turns it into the corresponding "/dev/x/y".
435 */
436EAPI const char *eeze_udev_syspath_get_devpath(const char *syspath);
437
438/**
439 * Get the /dev/ name from the /sys/ path.
440 *
441 * @param syspath The /sys/ path with or without the /sys/
442 * @return A stringshared char* of the device name without the /dev/ path, or @c NULL on failure
443 *
444 * Takes /sys/$PATH and turns it into the corresponding /dev/x/"y".
445 */
446EAPI const char *eeze_udev_syspath_get_devname(const char *syspath);
447
448/**
449 * Get the subsystem of a device from the /sys/ path.
450 *
451 * @param syspath The /sys/ path with or without the /sys/
452 * @return A stringshared char* with the subsystem of the device or @c NULL on failure
453 *
454 * Takes /sys/$PATH and returns the corresponding device subsystem,
455 * such as "input" for keyboards/mice.
456 */
457EAPI const char *eeze_udev_syspath_get_subsystem(const char *syspath);
458
459/**
460 * Get the property value of a device from the /sys/ path.
461 *
462 * @param syspath The /sys/ path with or without the /sys/
463 * @param property The property to get; full list of these is a FIXME
464 * @return A stringshared char* with the property or @c NULL on failure
465 */
466EAPI const char *eeze_udev_syspath_get_property(const char *syspath, const char *property);
467
468/**
469 * Get the sysattr value of a device from the /sys/ path.
470 *
471 * @param syspath The /sys/ path with or without the /sys/
472 * @param sysattr The sysattr to get; full list of these is a FIXME
473 * @return A stringshared char* with the sysattr or @c NULL on failure
474 */
475EAPI const char *eeze_udev_syspath_get_sysattr(const char *syspath, const char *sysattr);
476
477/**
478 * Checks whether the device is a mouse.
479 *
480 * @param syspath The /sys/ path with or without the /sys/
481 * @return If true, the device is a mouse
482 */
483EAPI Eina_Bool eeze_udev_syspath_is_mouse(const char *syspath);
484
485/**
486 * Checks whether the device is a keyboard.
487 *
488 * @param syspath The /sys/ path with or without the /sys/
489 * @return If true, the device is a keyboard
490 */
491EAPI Eina_Bool eeze_udev_syspath_is_kbd(const char *syspath);
492
493/**
494 * Checks whether the device is a touchpad.
495 *
496 * @param syspath The /sys/ path with or without the /sys/
497 * @return If true, the device is a touchpad
498 */
499EAPI Eina_Bool eeze_udev_syspath_is_touchpad(const char *syspath);
500
501/**
502 * Checks whether the device is a joystick.
503 *
504 * @param syspath The /sys/ path with or without the /sys/
505 * @return If true, the device is a joystick
506 * @since 1.7
507 */
508EAPI Eina_Bool eeze_udev_syspath_is_joystick(const char *syspath);
509 /**
510 * @}
511 */
512
513 /**
514 * @addtogroup Eeze_Walks Walks
515 *
516 * These are functions which walk up the device chain.
517 *
518 * @ingroup Eeze_Udev
519 *
520 * @{
521 */
522
523/**
524 * Walks up the device chain starting at @p syspath,
525 * checking each device for @p sysattr with (optional) @p value.
526 *
527 * @param syspath The /sys/ path of the device to start at, with or without the /sys/
528 * @param sysattr The attribute to find
529 * @param value OPTIONAL: The value that @p sysattr should have, or @c NULL
530 *
531 * @return If the sysattr (with value) is found, returns TRUE. Else, false.
532 */
533EAPI Eina_Bool eeze_udev_walk_check_sysattr(const char *syspath, const char *sysattr, const char *value);
534
535/**
536 * Walks up the device chain starting at @p syspath,
537 * checking each device for @p sysattr, and returns the value if found.
538 *
539 * @param syspath The /sys/ path of the device to start at, with or without the /sys/
540 * @param sysattr The attribute to find
541 *
542 * @return The stringshared value of @p sysattr if found, or @c NULL
543 */
544EAPI const char *eeze_udev_walk_get_sysattr(const char *syspath, const char *sysattr);
545 /**
546 * @}
547 */
548
549 /**
550 * @addtogroup Eeze_Watch Watch
551 *
552 * @brief These are functions which monitor udev for events.
553 *
554 * Eeze watches are simple: you specify a type of device to watch (or all devices), some events (or all) to watch for, a callback,
555 * and some data, and then udev watches those device types for events of the type you specified. Your callback is called with a
556 * syspath of the triggering device and the event that happened to the device, along with the data you associated with the watch and
557 * the watch object itself in case you want to stop the watch easily in a callback.
558 *
559 * @ingroup Eeze_Udev
560 *
561 * @{
562 */
563
564/**
565 * Add a watch for a device type
566 *
567 * @param type The #Eeze_Udev_Type to watch
568 * @param event The events to watch; an OR list of #Eeze_Udev_Event (ie (#EEZE_UDEV_EVENT_ADD | #EEZE_UDEV_EVENT_REMOVE)), or 0 for all events
569 * @param cb The function to call when the watch receives data of type #Eeze_Udev_Watch_Cb
570 * @param user_data Data to pass to the callback function
571 *
572 * @return A watch struct for the watch type specified, or @c NULL on failure
573 *
574 * Eeze watches will monitor udev for changes of type(s) @p event to devices of type @p type. When these changes occur, the stringshared
575 * syspath of the device will be sent to function @p func, along with the bitmask of the event type which can be detected through
576 * binary &.
577 */
578EAPI Eeze_Udev_Watch *eeze_udev_watch_add(Eeze_Udev_Type type, int event, Eeze_Udev_Watch_Cb cb, void *user_data);
579
580/**
581 * Deletes a watch.
582 *
583 * @param watch An Eeze_Udev_Watch object
584 * @return The data originally associated with the watch, or @c NULL
585 *
586 * Deletes a watch, closing file descriptors and freeing related udev memory.
587 */
588EAPI void *eeze_udev_watch_del(Eeze_Udev_Watch *watch);
589 /**
590 * @}
591 */
592
593#ifdef __cplusplus
594}
595#endif
596
597#endif
diff --git a/src/lib/eeze/Eeze_Disk.h b/src/lib/eeze/Eeze_Disk.h
new file mode 100644
index 0000000000..ca131d3f51
--- /dev/null
+++ b/src/lib/eeze/Eeze_Disk.h
@@ -0,0 +1,571 @@
1#ifndef EEZE_DISK_H
2#define EEZE_DISK_H
3
4#ifdef EAPI
5# undef EAPI
6#endif
7
8#ifdef __GNUC__
9# if __GNUC__ >= 4
10# define EAPI __attribute__ ((visibility("default")))
11# else
12# define EAPI
13# endif
14#else
15# define EAPI
16#endif
17
18#include <Eina.h>
19#include <Ecore.h>
20
21/**
22 * @file Eeze_Disk.h
23 * @brief Disk manipulation
24 * @since 1.1
25 *
26 * Eeze disk functions allow you to quickly and efficiently manipulate disks
27 * through simple function calls.
28 *
29 * @defgroup Eeze_Disk Disk
30 * Scan and query information about disks. Manipulate them with moun,
31 * unmount and eject.
32 *
33 * @ingroup Eeze
34 * @{
35 */
36
37#ifdef __cplusplus
38extern "C" {
39#endif
40
41/**
42 * @enum Eeze_Disk_Type
43 * @since 1.1
44 *
45 * All disk types known to Eeze.
46 */
47typedef enum
48{
49 EEZE_DISK_TYPE_UNKNOWN = 0, /**< type could not be determined */
50 EEZE_DISK_TYPE_INTERNAL = (1 << 0), /**< internal drive */
51 EEZE_DISK_TYPE_CDROM = (1 << 1), /**< cdrom drive */
52 EEZE_DISK_TYPE_USB = (1 << 2), /**< usb drive */
53 EEZE_DISK_TYPE_FLASH = (1 << 3) /**< flash disk */
54} Eeze_Disk_Type;
55
56/**
57 * @enum Eeze_Mount_Opts
58 * @since 1.1
59 *
60 * All mount options known to Eeze.
61 */
62typedef enum
63{
64#define EEZE_DISK_MOUNTOPT_DEFAULTS (EEZE_DISK_MOUNTOPT_UTF8 | EEZE_DISK_MOUNTOPT_NOEXEC | EEZE_DISK_MOUNTOPT_NOSUID)
65 EEZE_DISK_MOUNTOPT_LOOP = (1 << 1),
66 EEZE_DISK_MOUNTOPT_UTF8 = (1 << 2),
67 EEZE_DISK_MOUNTOPT_NOEXEC = (1 << 3),
68 EEZE_DISK_MOUNTOPT_NOSUID = (1 << 4),
69 EEZE_DISK_MOUNTOPT_REMOUNT = (1 << 5),
70 EEZE_DISK_MOUNTOPT_UID = (1 << 6), /**< use current user's uid */
71 EEZE_DISK_MOUNTOPT_NODEV = (1 << 7) /**< @since 1.7 */
72} Eeze_Mount_Opts;
73
74
75EAPI extern int EEZE_EVENT_DISK_MOUNT;
76EAPI extern int EEZE_EVENT_DISK_UNMOUNT;
77EAPI extern int EEZE_EVENT_DISK_EJECT;
78EAPI extern int EEZE_EVENT_DISK_ERROR;
79
80typedef struct _Eeze_Event_Disk Eeze_Event_Disk_Mount;
81typedef struct _Eeze_Event_Disk Eeze_Event_Disk_Unmount;
82typedef struct _Eeze_Event_Disk Eeze_Event_Disk_Eject;
83
84/**
85 * @typedef Eeze_Disk
86 * @since 1.1
87 *
88 * Handle for an Eeze Disk.
89 */
90typedef struct _Eeze_Disk Eeze_Disk;
91
92struct _Eeze_Event_Disk
93{
94 Eeze_Disk *disk;
95};
96
97/**
98 * @typedef Eeze_Event_Disk_Error
99 * @since 1.1
100 *
101 * Contains the human readable error message.
102 */
103typedef struct _Eeze_Event_Disk_Error Eeze_Event_Disk_Error;
104
105struct _Eeze_Event_Disk_Error
106{
107 Eeze_Disk *disk;
108 const char *message;
109};
110
111/**
112 * @brief Use this function to determine whether your eeze is disk-capable
113 *
114 * Since applications will die if they run/compile against a function that doesn't exist,
115 * if your application successfully runs/compiles with this function then you have eeze_disk.
116 * @since 1.1
117 */
118EAPI void eeze_disk_function(void);
119
120/**
121 * @brief Return whether mount support is available in eeze
122 *
123 * Use this function to determine whether your Eeze library was compiled with a mount
124 * binary available.
125 * @since 1.1
126 */
127EAPI Eina_Bool eeze_disk_can_mount(void);
128
129/**
130 * @brief Return whether unmount support is available in eeze
131 *
132 * Use this function to determine whether your Eeze library was compiled with an unmount
133 * binary available.
134 * @since 1.1
135 */
136EAPI Eina_Bool eeze_disk_can_unmount(void);
137
138/**
139 * @brief Return whether eject support is available in eeze
140 *
141 * Use this function to determine whether your Eeze library was compiled with an eject
142 * binary available.
143 * @since 1.1
144 */
145EAPI Eina_Bool eeze_disk_can_eject(void);
146
147/**
148 * @brief Create a new disk object from a /sys/ path or /dev/ path
149 * @param path The /sys/ or /dev path of the disk; CANNOT be @c NULL.
150 * @return The new disk object
151 *
152 * This function creates a new #Eeze_Disk from @p path. Note that this function
153 * does the minimal amount of work in order to save memory, and udev info about the disk
154 * is not retrieved in this call.
155 * @since 1.1
156 */
157EAPI Eeze_Disk *eeze_disk_new(const char *path);
158
159/**
160 * @brief Create a new disk object from a mount point
161 * @param mount_point The mount point of the disk; CANNOT be @c NULL
162 * @return The new disk object
163 *
164 * This function creates a new #Eeze_Disk from @p mount_point. Note that this function
165 * does the minimal amount of work in order to save memory, and udev info about the disk
166 * is not retrieved in this call. If the disk is not currently mounted, it must have an entry
167 * in /etc/fstab.
168 * @since 1.1
169 */
170EAPI Eeze_Disk *eeze_disk_new_from_mount(const char *mount_point);
171
172/**
173 * @brief Frees a disk object
174 * @param disk The disk object to free
175 *
176 * This call frees an #Eeze_Disk. Once freed, the disk can no longer be used.
177 * @since 1.1
178 */
179EAPI void eeze_disk_free(Eeze_Disk *disk);
180
181/**
182 * @brief Retrieve all disk information
183 * @param disk
184 *
185 * Use this function to retrieve all of a disk's information at once, then use
186 * a "get" function to retrieve the value. Data retrieved in this call is cached,
187 * meaning that subsequent calls will return immediately without performing any work.
188 * @since 1.1
189 */
190EAPI void eeze_disk_scan(Eeze_Disk *disk);
191
192/**
193 * @brief Associate data with a disk
194 * @param disk The disk
195 * @param data The data
196 *
197 * Data can be associated with @p disk with this function.
198 * @see eeze_disk_data_get
199 * @since 1.1
200 */
201EAPI void eeze_disk_data_set(Eeze_Disk *disk, void *data);
202
203/**
204 * @brief Retrieve data previously associated with a disk
205 * @param disk The disk
206 * @return The data
207 *
208 * Data that has been previously associated with @p disk
209 * is returned with this function.
210 * @see eeze_disk_data_set
211 * @since 1.1
212 */
213EAPI void *eeze_disk_data_get(Eeze_Disk *disk);
214
215/**
216 * @brief Return the /sys/ path of a disk
217 * @param disk The disk
218 * @return The /sys/ path
219 *
220 * This retrieves the /sys/ path that udev associates with @p disk.
221 * @since 1.1
222 */
223EAPI const char *eeze_disk_syspath_get(Eeze_Disk *disk);
224
225/**
226 * @brief Return the /dev/ path of a disk
227 * @param disk The disk
228 * @return The /dev/ path
229 *
230 * This retrieves the /dev/ path that udev has created a device node at for @p disk.
231 * @since 1.1
232 */
233EAPI const char *eeze_disk_devpath_get(Eeze_Disk *disk);
234
235/**
236 * @brief Return the filesystem of the disk (if known)
237 * @param disk The disk
238 * @return The filesystem type
239 *
240 * This retrieves the filesystem that the disk is using, or @c NULL if unknown.
241 * @since 1.1
242 */
243EAPI const char *eeze_disk_fstype_get(Eeze_Disk *disk);
244
245/**
246 * @brief Return the manufacturing vendor of the disk
247 * @param disk The disk
248 * @return The vendor
249 *
250 * This retrieves the vendor which manufactured the disk, or @c NULL if unknown.
251 * @since 1.1
252 */
253EAPI const char *eeze_disk_vendor_get(Eeze_Disk *disk);
254
255/**
256 * @brief Return the model of the disk
257 * @param disk The disk
258 * @return The model
259 *
260 * This retrieves the model of the disk, or @c NULL if unknown.
261 * @since 1.1
262 */
263EAPI const char *eeze_disk_model_get(Eeze_Disk *disk);
264
265/**
266 * @brief Return the serial number of the disk
267 * @param disk The disk
268 * @return The serial number
269 *
270 * This retrieves the serial number the disk, or @c NULL if unknown.
271 * @since 1.1
272 */
273EAPI const char *eeze_disk_serial_get(Eeze_Disk *disk);
274
275/**
276 * @brief Return the UUID of the disk
277 * @param disk The disk
278 * @return The UUID
279 *
280 * This retrieves the UUID of the disk, or @c NULL if unknown.
281 * A UUID is a 36 character (hopefully) unique identifier which can
282 * be used to store persistent information about a disk.
283 * @since 1.1
284 */
285EAPI const char *eeze_disk_uuid_get(Eeze_Disk *disk);
286
287/**
288 * @brief Return the label of the disk
289 * @param disk The disk
290 * @return The label
291 *
292 * This retrieves the label (name) of the disk, or @c NULL if unknown.
293 * @since 1.1
294 */
295EAPI const char *eeze_disk_label_get(Eeze_Disk *disk);
296
297/**
298 * @brief Return the #Eeze_Disk_Type of the disk
299 * @param disk The disk
300 * @return The type
301 *
302 * This retrieves the #Eeze_Disk_Type of the disk. This call is useful for determining
303 * the bus that the disk is connected through.
304 * @since 1.1
305 */
306EAPI Eeze_Disk_Type eeze_disk_type_get(Eeze_Disk *disk);
307
308/**
309 * @brief Return whether the disk is removable
310 * @param disk The disk
311 * @return @c EINA_TRUE if removable, @c EINA_FALSE otherwise.
312 * @since 1.1
313 */
314EAPI Eina_Bool eeze_disk_removable_get(Eeze_Disk *disk);
315
316
317/**
318 * @brief Return the mount state of a disk
319 * @param disk The disk
320 * @return The mount state
321 *
322 * This returns the mounted state of the disk. @c EINA_TRUE if mounted,
323 * @c EINA_FALSE otherwise.
324 * @since 1.1
325 */
326EAPI Eina_Bool eeze_disk_mounted_get(Eeze_Disk *disk);
327
328/**
329 * @brief Get the previously set mount wrapper for a disk
330 * @param disk The disk
331 * @return The wrapper, or @c NULL on failure.
332 *
333 * This returns the wrapper previously set with eeze_disk_mount_wrapper_set
334 * @since 1.1
335 */
336EAPI const char *eeze_disk_mount_wrapper_get(Eeze_Disk *disk);
337
338/**
339 * @brief Set a wrapper to run mount commands with
340 * @param disk The disk to wrap mount commands for
341 * @param wrapper The wrapper executable
342 * @return @c EINA_TRUE on success, @c EINA_FALSE otherwise.
343 *
344 * Use this function to set up a wrapper for running mount/umount commands. The wrapper must
345 * NOT use any of the standard mount/umount error code return values, and it must return 0 on success.
346 * Note that this function will call stat() on @p wrapper if not @c NULL to test for existence.
347 * @since 1.1
348 */
349EAPI Eina_Bool eeze_disk_mount_wrapper_set(Eeze_Disk *disk, const char *wrapper);
350
351/**
352 * @brief Begin a mount operation on the disk
353 * @param disk The disk
354 * @return @c EINA_TRUE if the operation was started, @c EINA_FALSE otherwise.
355 *
356 * This call is used to begin a mount operation on @p disk. The operation will
357 * run asynchronously in a pipe, emitting an EEZE_EVENT_DISK_MOUNT event with the disk object
358 * as its event on completion. If any errors are encountered, they will automatically logged
359 * to the eeze_disk domain and an EEZE_EVENT_DISK_ERROR event will be generated with an #Eeze_Event_Disk_Error
360 * struct as its event.
361 *
362 * NOTE: The return value of this function does not in any way reflect the mount state of a disk.
363 * @since 1.1
364 */
365EAPI Eina_Bool eeze_disk_mount(Eeze_Disk *disk);
366
367/**
368 * @brief Begin an unmount operation on the disk
369 * @param disk The disk
370 * @return @c EINA_TRUE if the operation was started, @c EINA_FALSE otherwise.
371 *
372 * This call is used to begin an unmount operation on @p disk. The operation will
373 * run asynchronously in a pipe, emitting an EEZE_EVENT_DISK_UNMOUNT event with the disk object
374 * as its event on completion. If any errors are encountered, they will automatically logged
375 * to the eeze_disk domain and an EEZE_EVENT_DISK_ERROR event will be generated with
376 * an #Eeze_Event_Disk_Error struct as its event.
377 *
378 * NOTE: The return value of this function does not in any way reflect the mount state of a disk.
379 * @since 1.1
380 */
381EAPI Eina_Bool eeze_disk_unmount(Eeze_Disk *disk);
382
383/**
384 * @brief Begin an eject operation on the disk
385 * @param disk The disk
386 * @return @c EINA_TRUE if the operation was started, @c EINA_FALSE otherwise.
387 *
388 * This call is used to begin an eject operation on @p disk. The operation will
389 * run asynchronously in a pipe, emitting an EEZE_EVENT_DISK_EJECT event with the disk object
390 * as its event on completion. If any errors are encountered, they will automatically logged
391 * to the eeze_disk domain and an EEZE_EVENT_DISK_ERROR event will be generated with
392 * an #Eeze_Event_Disk_Error struct as its event.
393 *
394 * NOTE: The return value of this function does not in any way reflect the mount state of a disk.
395 * @since 1.1
396 */
397EAPI Eina_Bool eeze_disk_eject(Eeze_Disk *disk);
398/**
399 * @brief Cancel a pending operation on the disk
400 * @param disk The disk
401 *
402 * This function cancels the current pending operation on @p disk which was previously
403 * started with eeze_disk_mount or eeze_disk_unmount.
404 * @since 1.1
405 */
406EAPI void eeze_disk_cancel(Eeze_Disk *disk);
407
408/**
409 * @brief Return the mount point of a disk
410 * @param disk The disk
411 * @return The mount point
412 *
413 * This function returns the mount point associated with @p disk.
414 * Note that to determine whether the disk is actually mounted, eeze_disk_mounted_get should be used.
415 * @since 1.1
416 */
417EAPI const char *eeze_disk_mount_point_get(Eeze_Disk *disk);
418
419/**
420 * @brief Set the mount point of a disk
421 * @param disk The disk
422 * @param mount_point The mount point
423 * @return @c EINA_TRUE on success, @c EINA_FALSE otherwise.
424 *
425 * This function sets the mount point associated with @p disk.
426 * Note that to determine whether the disk is actually mounted, eeze_disk_mounted_get should be used.
427 * Also note that this function cannot be used while the disk is mounted to avoid losing the current mount point.
428 * @since 1.1
429 */
430EAPI Eina_Bool eeze_disk_mount_point_set(Eeze_Disk *disk, const char *mount_point);
431
432/**
433 * @brief Set the mount options using flags
434 * @param disk The disk
435 * @param opts An ORed set of #Eeze_Mount_Opts
436 * @return @c EINA_TRUE on success, @c EINA_FALSE otherwise.
437 *
438 * This function replaces the current mount opts of a disk with the ones in @p opts.
439 * @since 1.1
440 */
441EAPI Eina_Bool eeze_disk_mountopts_set(Eeze_Disk *disk, unsigned long opts);
442
443/**
444 * @brief Get the flags of a disk's current mount options
445 * @param disk The disk
446 * @return An ORed set of #Eeze_Mount_Opts, 0 on failure
447 *
448 * This function returns the current mount opts of a disk.
449 * @since 1.1
450 */
451EAPI unsigned long eeze_disk_mountopts_get(Eeze_Disk *disk);
452
453
454/**
455 * @brief Begin watching mtab and fstab
456 * @return @c EINA_TRUE if watching was started, @c EINA_FALSE otherwise.
457 *
458 * This function creates inotify watches on /etc/mtab and /etc/fstab and watches
459 * them for changes. This function should be used when expecting a lot of disk
460 * mounting/unmounting while you need disk data since it will automatically update
461 * certain necessary data instead of waiting.
462 * @see eeze_mount_mtab_scan, eeze_mount_fstab_scan
463 * @since 1.1
464 */
465EAPI Eina_Bool eeze_mount_tabs_watch(void);
466
467/**
468 * @brief Stop watching /etc/fstab and /etc/mtab
469 *
470 * This function stops watching fstab and mtab. Data obtained previously will be saved.
471 * @since 1.1
472 */
473EAPI void eeze_mount_tabs_unwatch(void);
474
475/**
476 * @brief Scan /etc/mtab a single time
477 * @return @c EINA_TRUE if mtab could be scanned, @c EINA_FALSE otherwise.
478 *
479 * This function is used to perform a single scan on /etc/mtab. It is used to gather
480 * information about mounted filesystems which can then be used with your #Eeze_Disk objects
481 * where appropriate. These files will automatically be scanned any time a mount point or mount state
482 * is requested unless eeze_mount_tabs_watch has been called previously, in which case data is stored for
483 * use.
484 * If this function is called after eeze_mount_tabs_watch, @c EINA_TRUE will be returned.
485 * @see eeze_mount_tabs_watch, eeze_mount_fstab_scan
486 * @since 1.1
487 */
488EAPI Eina_Bool eeze_mount_mtab_scan(void);
489
490/**
491 * @brief Scan /etc/fstab a single time
492 * @return @c EINA_TRUE if mtab could be scanned, @c EINA_FALSE otherwise.
493 *
494 * This function is used to perform a single scan on /etc/fstab. It is used to gather
495 * information about mounted filesystems which can then be used with your #Eeze_Disk objects
496 * where appropriate. These files will automatically be scanned any time a mount point or mount state
497 * is requested unless eeze_mount_tabs_watch has been called previously, in which case data is stored for
498 * use.
499 * If this function is called after eeze_mount_tabs_watch, @c EINA_TRUE will be returned.
500 * @see eeze_mount_tabs_watch, eeze_mount_mtab_scan
501 * @since 1.1
502 */
503EAPI Eina_Bool eeze_mount_fstab_scan(void);
504
505/**
506 * @brief Get the property value of a disk
507 *
508 * @param disk The disk
509 * @param property The property to get; full list of these is a FIXME
510 * @return A stringshared char* with the property or @c NULL on failure.
511 * @since 1.1
512 */
513
514EAPI const char *eeze_disk_udev_get_property(Eeze_Disk *disk, const char *property);
515
516/**
517 * @brief Get the sysattr value of a disk.
518 *
519 * @param disk The disk
520 * @param sysattr The sysattr to get; full list of these is a FIXME
521 * @return A stringshared char* with the sysattr or @c NULL on failure.
522 * @since 1.1
523 */
524
525EAPI const char *eeze_disk_udev_get_sysattr(Eeze_Disk *disk, const char *sysattr);
526
527/**
528 * Find the root device of a disk.
529 *
530 * @param disk The disk
531 * @return The syspath of the parent device
532 *
533 * Return a stringshared syspath (/sys/$syspath) for the parent device.
534 * @since 1.1
535 */
536EAPI const char *eeze_disk_udev_get_parent(Eeze_Disk *disk);
537
538/**
539 * Walks up the device chain using the device from @p disk,
540 * checking each device for @p sysattr with (optional) @p value.
541 *
542 * @param disk The disk to walk
543 * @param sysattr The attribute to find
544 * @param value OPTIONAL: The value that @p sysattr should have, or @c NULL.
545 *
546 * @return If the sysattr (with value) is found, returns @c EINA_TRUE,
547 * @c EINA_FALSE otherwise.
548 * @since 1.1
549 */
550EAPI Eina_Bool eeze_disk_udev_walk_check_sysattr(Eeze_Disk *disk, const char *sysattr, const char *value);
551
552/**
553 * @brief Walks up the device chain of @p disk
554 * checking each device for @p sysattr and returns the value if found.
555 *
556 * @param disk The disk
557 * @param sysattr The attribute to find
558 *
559 * @return The stringshared value of @p sysattr if found, or @c NULL.
560 * @since 1.1
561 */
562EAPI const char *eeze_disk_udev_walk_get_sysattr(Eeze_Disk *disk, const char *sysattr);
563
564#ifdef __cplusplus
565}
566#endif
567
568/**
569 * @}
570 */
571#endif
diff --git a/src/lib/eeze/Eeze_Net.h b/src/lib/eeze/Eeze_Net.h
new file mode 100644
index 0000000000..aa58deb8d4
--- /dev/null
+++ b/src/lib/eeze/Eeze_Net.h
@@ -0,0 +1,65 @@
1#ifndef EEZE_NET_H
2#define EEZE_NET_H
3
4#ifdef EAPI
5# undef EAPI
6#endif
7
8#ifdef __GNUC__
9# if __GNUC__ >= 4
10# define EAPI __attribute__ ((visibility("default")))
11# else
12# define EAPI
13# endif
14#else
15# define EAPI
16#endif
17
18#include <Eina.h>
19#include <Ecore.h>
20
21/**
22 * @file Eeze_Net.h
23 * @brief Network manipulation
24 *
25 * Eeze net functions allow you to gather information about network objects
26 *
27 * @defgroup Eeze_Net Net
28 * Gather information about network devices.
29 *
30 * @ingroup Eeze
31 * @{
32 */
33
34typedef struct Eeze_Net Eeze_Net;
35
36typedef enum
37{
38 EEZE_NET_ADDR_TYPE_IP,
39 EEZE_NET_ADDR_TYPE_IP6,
40 EEZE_NET_ADDR_TYPE_BROADCAST,
41 EEZE_NET_ADDR_TYPE_BROADCAST6,
42 EEZE_NET_ADDR_TYPE_NETMASK,
43 EEZE_NET_ADDR_TYPE_NETMASK6,
44} Eeze_Net_Addr_Type;
45
46#ifdef __cplusplus
47extern "C" {
48#endif
49
50EAPI Eeze_Net *eeze_net_new(const char *name);
51EAPI void eeze_net_free(Eeze_Net *net);
52EAPI const char *eeze_net_mac_get(Eeze_Net *net);
53EAPI int eeze_net_idx_get(Eeze_Net *net);
54EAPI Eina_Bool eeze_net_scan(Eeze_Net *net);
55EAPI const char *eeze_net_addr_get(Eeze_Net *net, Eeze_Net_Addr_Type type);
56EAPI const char *eeze_net_attribute_get(Eeze_Net *net, const char *attr);
57EAPI const char *eeze_net_syspath_get(Eeze_Net *net);
58EAPI Eina_List *eeze_net_list(void);
59
60#ifdef __cplusplus
61}
62#endif
63/** @} */
64
65#endif
diff --git a/src/lib/eeze/Eeze_Sensor.h b/src/lib/eeze/Eeze_Sensor.h
new file mode 100644
index 0000000000..02a51fe385
--- /dev/null
+++ b/src/lib/eeze/Eeze_Sensor.h
@@ -0,0 +1,325 @@
1#ifndef EEZE_SENSOR_H
2#define EEZE_SENSOR_H
3
4#ifdef EAPI
5# undef EAPI
6#endif
7
8#ifdef __GNUC__
9# if __GNUC__ >= 4
10# define EAPI __attribute__ ((visibility("default")))
11# else
12# define EAPI
13# endif
14#else
15# define EAPI
16#endif
17
18#include <Eina.h>
19
20/**
21 * @file Eeze_Sensor.h
22 * @brief Sensor information subsystem
23 *
24 * Eeze sensor functions allow you to gather sensor information from different
25 * sensor sources available on your hardware. It supports a plugin architecture
26 * to support different hardware platforms and devices. These plugins can be
27 * loaded at runtime.
28 *
29 * Right now we have support for the Tizen sensor framework as well as a simple
30 * fake plugin to be used as a test harness for development. Plugins for other
31 * sensor frameworks or platforms are always welcome.
32 *
33 * Synchronous as well as asynchronous reads are possible. As reading the
34 * physical sensor might be bound to a high latency and thus cost the value of
35 * the last read is cached within Eeze_Sensor together with a timestamp of the
36 * actual read out. This can speed up the value access for application while the
37 * values are still getting updating asynchronously in the background. The
38 * timestamp should be checked if the specific time requirements are needed.
39 *
40 * As an alternative the sensor could be read synchronously. With the
41 * disadvantage that the function call will block until the data is read from
42 * the sensor.
43 *
44 * @since 1.8
45 *
46 * @addtogroup Eeze_Sensor Sensor
47 * Gather sensor information from different sources. Works based on plugins,
48 * with a Tizen plugin being available.
49 *
50 * @ingroup Eeze
51 * @{
52 */
53
54/**
55 * @enum Eeze_Sensor_Type
56 *
57 * All sensor types known by Eeze Sensor. This list of types include real
58 * physical types like proximity or light as well as "aggregated" types like
59 * facedown or doubletap. All types with MOTION in their name can be used as
60 * real events coming from the underlying system. This is not supported on all
61 * systems.
62 *
63 * @since 1.8
64 */
65typedef enum
66{
67 EEZE_SENSOR_TYPE_ACCELEROMETER, /**< Accelerometer sensor */
68 EEZE_SENSOR_TYPE_MAGNETIC, /**< Magnetic sensor */
69 EEZE_SENSOR_TYPE_ORIENTATION, /**< Orientation sensor */
70 EEZE_SENSOR_TYPE_GYROSCOPE, /**< Gyroscope sensor */
71 EEZE_SENSOR_TYPE_LIGHT, /**< Light sensor */
72 EEZE_SENSOR_TYPE_PROXIMITY, /**< Proximity sensor */
73 EEZE_SENSOR_TYPE_MOTION_SNAP, /**< Snap motion sensor */
74 EEZE_SENSOR_TYPE_MOTION_SHAKE, /**< Shake motion sensor */
75 EEZE_SENSOR_TYPE_MOTION_DOUBLETAP, /**< Doubletap motion sensor */
76 EEZE_SENSOR_TYPE_MOTION_PANNING, /**< Panning motion sensor */
77 EEZE_SENSOR_TYPE_MOTION_FACEDOWN, /**< Facedown motion sensor */
78 /* Non-Tizen from here */
79 EEZE_SENSOR_TYPE_BAROMETER, /**< Barometer sensor */
80 EEZE_SENSOR_TYPE_TEMPERATURE, /**< Temperature sensor */
81 EEZE_SENSOR_TYPE_LAST = 0xFF /**< Last item to mark end of enum */
82} Eeze_Sensor_Type;
83
84/**
85 * @defgroup Eeze_Sensor_Events Available eeze sensor events
86 * @brief Sensor events that are emitted from the library as ecore events
87 * @ingroup Eeze
88 *
89 * Event types used to register ecore_event_handler on. These events are used
90 * for #eeze_sensor_async_read to deliver read out data. It is also used for
91 * generated events like facedown or shake. Subscribing to these events in your
92 * application allowsyou to react on these changes in an efficient way without
93 * polling for new updates and wasting power and computing cycles.
94 *
95 * @since 1.8
96 * @{
97 */
98EAPI int EEZE_SENSOR_EVENT_ACCELEROMETER;
99EAPI int EEZE_SENSOR_EVENT_MAGNETIC;
100EAPI int EEZE_SENSOR_EVENT_ORIENTATION;
101EAPI int EEZE_SENSOR_EVENT_GYROSCOPE;
102EAPI int EEZE_SENSOR_EVENT_LIGHT;
103EAPI int EEZE_SENSOR_EVENT_PROXIMITY;
104EAPI int EEZE_SENSOR_EVENT_SNAP;
105EAPI int EEZE_SENSOR_EVENT_SHAKE;
106EAPI int EEZE_SENSOR_EVENT_DOUBLETAP;
107EAPI int EEZE_SENSOR_EVENT_PANNING;
108EAPI int EEZE_SENSOR_EVENT_FACEDOWN;
109EAPI int EEZE_SENSOR_EVENT_BAROMETER;
110EAPI int EEZE_SENSOR_EVENT_TEMPERATURE;
111/**@}*/
112
113/**
114 * @typedef Eeze_Sensor_Obj;
115 *
116 * Object for a sensor type. Keeps information about the type and holds the
117 * data for the accessor functions. As this information gets also updated by
118 * asynchronous reads it might be a good idea to check the timestamp value to
119 * see when the data has been updated. The timestamp is given in microseconds.
120 *
121 * You are not supposed to access the raw data values from here but use the
122 * getter functions for it. Using the raw values from this struct might break
123 * your applications later if the internal structure changes.
124 *
125 * @since 1.8
126 */
127typedef struct _Eeze_Sensor_Obj
128{
129 unsigned int type; /**< Sensor type see #Eeze_Sensor_Type */
130 int accuracy; /**< Accuracy of the sensor value */
131 float data[3]; /**< Sensor data depending on the sensor type */
132 unsigned long long timestamp; /**< Timestamp of data read */
133 Eina_Bool continuous_flow; /**< FUTURE USE: Continuous flow of sensor read out */
134} Eeze_Sensor_Obj;
135
136#ifdef __cplusplus
137extern "C" {
138#endif
139
140/**
141 * @brief Create sensor object to operate on.
142 * @param type Sensor type to create object from.
143 * @return Sensor object for the given type.
144 *
145 * Takes the sensor type and create an object for it to operate on. During this
146 * it also does an initial sensor data read to fill the sensor data into the
147 * object. The #eeze_sensor_free function must be used to destroy the object
148 * and release its memory.
149 *
150 * For every sensor type you want to work with this is the first thing you have
151 * to do. Create the object from the type and everything else the operates on
152 * this object.
153 *
154 * This also takes into account what runtime modules are loaded and handles
155 * them in a given priority to pick up the best sensor source for your sensor
156 * object.
157 *
158 * @since 1.8
159 */
160EAPI Eeze_Sensor_Obj *eeze_sensor_new(Eeze_Sensor_Type type);
161
162/**
163 * @brief Free a sensor object.
164 * @param sens Sensor object to operate on.
165 *
166 * Free an sensor object when it is no longer needed. Always use this function
167 * to cleanup unused sensor objects.
168 *
169 * @since 1.8
170 */
171EAPI void eeze_sensor_free(Eeze_Sensor_Obj *sens);
172
173/**
174 * @brief Get accuracy from sensor object.
175 * @param sens Sensor object to operate on.
176 * @param accuracy Pointer to write accuracy value into.
177 * @return EINA_TRUE for success and EINA_FALSE for failure
178 *
179 * Access function to get the accuracy property from the sensor object. The
180 * accuracy value can have the following values and meaning:
181 * -1 Undefined accuracy
182 * 0 Bad accurancy
183 * 1 Normal accuracy
184 * 2 Good accuracy
185 * 3 Very good accuracy
186 *
187 * @since 1.8
188 */
189EAPI Eina_Bool eeze_sensor_accuracy_get(Eeze_Sensor_Obj *sens, int *accuracy);
190
191/**
192 * @brief Get data from all three data properties
193 * @param sens Sensor object to operate on.
194 * @param x Pointer to write first data property value into.
195 * @param y Pointer to write second data property value into.
196 * @param z Pointer to write third data property value into.
197 * @return EINA_TRUE for success and EINA_FALSE for failure
198 *
199 * Access function to get all three data properties from the sensor object.
200 * This is used for sensor types that offer all three values. Like accelerometer
201 * and magnetic.
202 *
203 * @since 1.8
204 */
205EAPI Eina_Bool eeze_sensor_xyz_get(Eeze_Sensor_Obj *sens, float *x, float *y, float *z);
206
207/**
208 * @brief Get data from first two data properties
209 * @param sens Sensor object to operate on.
210 * @param x Pointer to write first data property value into.
211 * @param y Pointer to write second data property value into.
212 * @return EINA_TRUE for success and EINA_FALSE for failure
213 *
214 * Access function to get the first two data properties from the sensor object.
215 * This is used for sensor types that offer two values. Like panning.
216 *
217 * @since 1.8
218 */
219EAPI Eina_Bool eeze_sensor_xy_get(Eeze_Sensor_Obj *sens, float *x, float *y);
220
221/**
222 * @brief Get the data from first data property
223 * @param sens Sensor object to operate on.
224 * @param x Pointer to write first data property value into.
225 * @return EINA_TRUE for success and EINA_FALSE for failure
226 *
227 * Access function to get the first data property from the sensor object. This
228 * is used for sensor types that only offer one value. Like light or proximity.
229 *
230 * @since 1.8
231 */
232EAPI Eina_Bool eeze_sensor_x_get(Eeze_Sensor_Obj *sens, float *x);
233
234/**
235 * @brief Get timestamp from sensor object.
236 * @param sens Sensor object to operate on.
237 * @param timestamp Pointer to write timestamp value into.
238 * @return EINA_TRUE for success and EINA_FALSE for failure
239 *
240 * Access function to get the timestamp property from the sensor object. It
241 * allows you to determine if the values have been updated since the last time
242 * you requested them.
243 *
244 * @since 1.8
245 */
246EAPI Eina_Bool eeze_sensor_timestamp_get(Eeze_Sensor_Obj *sens, unsigned long long *timestamp);
247
248/**
249 * @brief Read out sensor data
250 * @param sens Sensor object to operate on.
251 * @return EINA_TRUE for success and EINA_FALSE for failure
252 *
253 * This function reads sensor data from the device and fills the sensor object
254 * with the data. This call is synchronous and blocks until the data is read out
255 * and updated in the sensor object. For simple applications this is fine and
256 * the easiest way to use the API. A more efficient way is to use
257 * #eeze_sensor_async_read which allows the sensor readout to happen in the
258 * background and the application would check the timestamp of the data to
259 * determine how recent the data is.
260 *
261 * @since 1.8
262 */
263EAPI Eina_Bool eeze_sensor_read(Eeze_Sensor_Obj *sens);
264
265/**
266 * @brief Asynchronous read out sensor data
267 * @param sens Sensor object to operate on.
268 * @param user_data Data to pass to the callback function.
269 * @return EINA_TRUE for success and EINA_FALSE for failure
270 *
271 * This function reads sensor data from the device and fills the sensor object
272 * with the data. The read is done asynchronously and thus does not block after
273 * calling. Instead the given the application can determine how recent the
274 * values are from the timestamp value that can be accessed through
275 * #eeze_sensor_timestamp_get.
276 *
277 * This function is more efficient but needs a bit more work in the application.
278 * An easier way is to use the synchronous #eeze_sensor_read functions. The
279 * downside of it is that it blocks until the data was read out from the
280 * physical sensor. That might be a long time depending on the hardware and its
281 * interface.
282 *
283 * @since 1.8
284 */
285EAPI Eina_Bool eeze_sensor_async_read(Eeze_Sensor_Obj *sens, void *user_data);
286
287/**
288 * @brief Fetch the sensor object by type from the sensor object list
289 * @param type Sensor type to fetch from the list of sensor objects.
290 * @return The sensor object matching the given type
291 *
292 * @since 1.8
293 */
294EAPI Eeze_Sensor_Obj *eeze_sensor_obj_get(Eeze_Sensor_Type type);
295
296/**
297 * @brief Initialize the Eeze sensor subsystem.
298 * @return EINA_TRUE for success and EINA_FALSE for failure
299 *
300 * This function must be called before using any of the Eeze_Sensor
301 * functionality to make sure the subsystem is setup correctly for usage. If
302 * you already call #eeze_init in your program this is already been take care
303 * of and there is no need to call this to initialize this subsystem manually.
304 *
305 * @since 1.8
306 */
307EAPI Eina_Bool eeze_sensor_init(void);
308
309/**
310 * @brief Clean up and shutdown the Eeze sensor subsystem.
311 *
312 * This function must be called when now longer using Eeze_Sensor to allow the
313 * subsystem to shutdown cleanly. If you already called #eeze_shutdown this is
314 * already been taken care of and there is no need to call this to shutdown this
315 * subsystem manually.
316 *
317 * @since 1.8
318 */
319EAPI void eeze_sensor_shutdown(void);
320
321#ifdef __cplusplus
322}
323#endif
324/** @} */
325#endif
diff --git a/src/lib/eeze/eeze_disk.c b/src/lib/eeze/eeze_disk.c
new file mode 100644
index 0000000000..80b0c31437
--- /dev/null
+++ b/src/lib/eeze/eeze_disk.c
@@ -0,0 +1,483 @@
1#ifdef HAVE_CONFIG_H
2#include "config.h"
3#endif
4
5#include <Ecore.h>
6#include <Eeze.h>
7#include <Eeze_Disk.h>
8#include <unistd.h>
9
10#include "eeze_udev_private.h"
11#include "eeze_disk_private.h"
12
13int _eeze_disk_log_dom = -1;
14Eina_List *_eeze_disks = NULL;
15
16static Eeze_Disk_Type
17_eeze_disk_type_find(Eeze_Disk *disk)
18{
19 const char *test;
20 Eeze_Disk_Type ret;
21 Eina_Bool filesystem = EINA_FALSE; /* this will have no children */
22
23 if (udev_device_get_property_value(disk->device, "ID_CDROM"))
24 return EEZE_DISK_TYPE_CDROM;
25 test = udev_device_get_property_value(disk->device, "ID_FS_USAGE");
26 if ((!test) || strcmp(test, "filesystem"))
27 {
28 test = _walk_children_get_attr(disk->syspath, "ID_CDROM", "block", EINA_TRUE);
29 if (test)
30 {
31 eina_stringshare_del(test);
32 return EEZE_DISK_TYPE_CDROM;
33 }
34 }
35 else
36 filesystem = EINA_TRUE;
37 if (udev_device_get_property_value(disk->device, "ID_ATA"))
38 return EEZE_DISK_TYPE_INTERNAL;
39 if (!filesystem)
40 {
41 test = _walk_children_get_attr(disk->syspath, "ID_ATA", "block", EINA_TRUE);
42 if (test)
43 {
44 eina_stringshare_del(test);
45 return EEZE_DISK_TYPE_INTERNAL;
46 }
47 }
48 test = udev_device_get_property_value(disk->device, "ID_BUS");
49 if (test)
50 {
51 if (!strcmp(test, "ata")) return EEZE_DISK_TYPE_INTERNAL;
52 if (!strcmp(test, "usb")) return EEZE_DISK_TYPE_USB;
53 return EEZE_DISK_TYPE_UNKNOWN; /* FIXME */
54 }
55 if ((!test) && (!filesystem))
56 test = _walk_children_get_attr(disk->syspath, "ID_BUS", "block", EINA_TRUE);
57 if (!test)
58 {
59 _udev_device *dev;
60
61 for (dev = udev_device_get_parent(disk->device); dev; dev = udev_device_get_parent(dev))
62 {
63 test = udev_device_get_subsystem(dev);
64 if (!test) return EEZE_DISK_TYPE_UNKNOWN;
65 if (!strcmp(test, "block")) continue;
66 if (!strcmp(test, "mmc")) return EEZE_DISK_TYPE_FLASH;
67 break;
68 }
69 return EEZE_DISK_TYPE_UNKNOWN; /* FIXME */
70 }
71
72 if (!strcmp(test, "ata")) ret = EEZE_DISK_TYPE_INTERNAL;
73 else if (!strcmp(test, "usb")) ret = EEZE_DISK_TYPE_USB;
74 else ret = EEZE_DISK_TYPE_UNKNOWN; /* FIXME */
75
76 eina_stringshare_del(test);
77
78 return ret;
79}
80
81static _udev_device *
82_eeze_disk_device_from_property(const char *prop, Eina_Bool uuid)
83{
84 _udev_enumerate *en;
85 _udev_list_entry *devs, *cur;
86 _udev_device *device = NULL;
87 const char *devname;
88
89 en = udev_enumerate_new(udev);
90
91 if (!en)
92 return NULL;
93
94 if (uuid)
95 udev_enumerate_add_match_property(en, "ID_FS_UUID", prop);
96 else
97 udev_enumerate_add_match_property(en, "ID_FS_LABEL", prop);
98 udev_enumerate_scan_devices(en);
99 devs = udev_enumerate_get_list_entry(en);
100 udev_list_entry_foreach(cur, devs)
101 {
102 devname = udev_list_entry_get_name(cur);
103 device = udev_device_new_from_syspath(udev, devname);
104 break;
105 }
106 udev_enumerate_unref(en);
107 return device;
108
109}
110
111void
112eeze_disk_shutdown(void)
113{
114 eeze_mount_shutdown();
115 ecore_file_shutdown();
116 eina_log_domain_unregister(_eeze_disk_log_dom);
117 _eeze_disk_log_dom = -1;
118}
119
120Eina_Bool
121eeze_disk_init(void)
122{
123 _eeze_disk_log_dom = eina_log_domain_register("eeze_disk", EINA_COLOR_LIGHTBLUE);
124
125 if (_eeze_disk_log_dom < 0)
126 {
127 EINA_LOG_ERR("Could not register 'eeze_disk' log domain.");
128 goto disk_fail;
129 }
130
131 if (!ecore_file_init())
132 goto disk_fail;
133 if (!eeze_mount_init())
134 goto ecore_file_fail;
135
136 return EINA_TRUE;
137
138ecore_file_fail:
139 ecore_file_shutdown();
140disk_fail:
141 eina_log_domain_unregister(_eeze_disk_log_dom);
142 _eeze_disk_log_dom = -1;
143 return EINA_FALSE;
144}
145
146EAPI void
147eeze_disk_function(void)
148{
149}
150
151EAPI Eeze_Disk *
152eeze_disk_new(const char *path)
153{
154 Eeze_Disk *disk;
155 _udev_device *dev;
156 const char *syspath = NULL;
157 Eina_Bool is_dev = EINA_FALSE;
158
159 EINA_SAFETY_ON_NULL_RETURN_VAL(path, NULL);
160
161 if (!strncmp(path, "/dev/", 5))
162 {
163 is_dev = EINA_TRUE;
164 syspath = eeze_udev_devpath_get_syspath(path);
165 if (!syspath)
166 return NULL;
167
168 if (!(dev = _new_device(syspath)))
169 {
170 eina_stringshare_del(syspath);
171 return NULL;
172 }
173 }
174 else if (!(dev = _new_device(path)))
175 return NULL;
176
177
178 if (!(disk = calloc(1, sizeof(Eeze_Disk))))
179 return NULL;
180
181
182 if (is_dev)
183 {
184 disk->devpath = eina_stringshare_add(path);
185 disk->syspath = syspath;
186 }
187 else
188 disk->syspath = eina_stringshare_add(udev_device_get_syspath(dev));
189
190
191 disk->device = dev;
192 disk->mount_opts = EEZE_DISK_MOUNTOPT_DEFAULTS;
193 disk->mount_cmd_changed = EINA_TRUE;
194 disk->unmount_cmd_changed = EINA_TRUE;
195
196 _eeze_disks = eina_list_append(_eeze_disks, disk);
197
198 return disk;
199}
200
201EAPI Eeze_Disk *
202eeze_disk_new_from_mount(const char *mount_point)
203{
204 Eeze_Disk *disk = NULL;
205 _udev_device *dev = NULL;
206 const char *syspath = NULL, *source, *uuid = NULL, *label = NULL, *devpath = NULL;
207
208 EINA_SAFETY_ON_NULL_RETURN_VAL(mount_point, NULL);
209
210 if (!(source = eeze_disk_libmount_mp_find_source(mount_point)))
211 return NULL;
212
213 if (source[4] == '=')
214 {
215 source += 5;
216 uuid = eina_stringshare_add(source);
217 dev = _eeze_disk_device_from_property(uuid, EINA_TRUE);
218 }
219 else if (source[5] == '=')
220 {
221 source += 6;
222 label = eina_stringshare_add(source);
223 dev = _eeze_disk_device_from_property(label, EINA_FALSE);
224 }
225 else
226 {
227 const char *spath;
228
229 devpath = eina_stringshare_add(source);
230 spath = eeze_udev_devpath_get_syspath(devpath);
231 dev = _new_device(spath);
232 eina_stringshare_del(spath);
233 }
234
235 if (!dev)
236 goto error;
237
238 if (!(disk = calloc(1, sizeof(Eeze_Disk))))
239 goto error;
240
241 disk->syspath = udev_device_get_syspath(dev);
242
243 disk->device = dev;
244 disk->mount_cmd_changed = EINA_TRUE;
245 disk->unmount_cmd_changed = EINA_TRUE;
246 if (uuid)
247 disk->cache.uuid = uuid;
248 else if (label)
249 disk->cache.label = label;
250 else
251 disk->devpath = devpath;
252 disk->mount_point = eina_stringshare_add(mount_point);
253
254 _eeze_disks = eina_list_append(_eeze_disks, disk);
255
256 return disk;
257error:
258 if (uuid)
259 eina_stringshare_del(uuid);
260 else if (label)
261 eina_stringshare_del(label);
262 else if (devpath)
263 eina_stringshare_del(devpath);
264 if (syspath)
265 eina_stringshare_del(syspath);
266 if (dev)
267 udev_device_unref(dev);
268 return NULL;
269}
270
271EAPI void
272eeze_disk_free(Eeze_Disk *disk)
273{
274 extern Eina_List *eeze_events;
275 EINA_SAFETY_ON_NULL_RETURN(disk);
276
277 udev_device_unref(disk->device);
278 if (disk->mount_cmd)
279 eina_strbuf_free(disk->mount_cmd);
280 if (disk->unmount_cmd)
281 eina_strbuf_free(disk->unmount_cmd);
282 if (disk->eject_cmd)
283 eina_strbuf_free(disk->eject_cmd);
284 if (disk->mounter) ecore_exe_kill(disk->mounter);
285 _eeze_disks = eina_list_remove(_eeze_disks, disk);
286 eeze_events = eina_list_remove(eeze_events, disk);
287 free(disk);
288}
289
290EAPI void
291eeze_disk_scan(Eeze_Disk *disk)
292{
293 const char *test;
294 EINA_SAFETY_ON_NULL_RETURN(disk);
295 /* never rescan; if these values change then something is seriously wrong */
296 if (disk->cache.filled) return;
297
298 if (!disk->cache.vendor)
299 disk->cache.vendor = udev_device_get_property_value(disk->device, "ID_VENDOR");
300 if (!disk->cache.vendor)
301 if (!disk->cache.vendor) disk->cache.vendor = udev_device_get_sysattr_value(disk->device, "vendor");
302 if (!disk->cache.model)
303 disk->cache.model = udev_device_get_property_value(disk->device, "ID_MODEL");
304 if (!disk->cache.model)
305 if (!disk->cache.model) disk->cache.model = udev_device_get_sysattr_value(disk->device, "model");
306 if (!disk->cache.serial)
307 disk->cache.serial = udev_device_get_property_value(disk->device, "ID_SERIAL_SHORT");
308 if (!disk->cache.uuid)
309 disk->cache.uuid = udev_device_get_property_value(disk->device, "ID_FS_UUID");
310 if (!disk->cache.type)
311 disk->cache.type = _eeze_disk_type_find(disk);
312 if (!disk->cache.label)
313 disk->cache.label = udev_device_get_property_value(disk->device, "ID_FS_LABEL");
314 test = udev_device_get_sysattr_value(disk->device, "removable");
315 if (test) disk->cache.removable = !!strtol(test, NULL, 10);
316 else
317 test = _walk_children_get_attr(disk->syspath, "removable", "block", EINA_FALSE);
318 if (test)
319 {
320 disk->cache.removable = !!strtol(test, NULL, 10);
321 eina_stringshare_del(test);
322 }
323
324 disk->cache.filled = EINA_TRUE;
325}
326
327EAPI void
328eeze_disk_data_set(Eeze_Disk *disk, void *data)
329{
330 EINA_SAFETY_ON_NULL_RETURN(disk);
331
332 disk->data = data;
333}
334
335EAPI void *
336eeze_disk_data_get(Eeze_Disk *disk)
337{
338 EINA_SAFETY_ON_NULL_RETURN_VAL(disk, NULL);
339
340 return disk->data;
341}
342
343EAPI const char *
344eeze_disk_syspath_get(Eeze_Disk *disk)
345{
346 EINA_SAFETY_ON_NULL_RETURN_VAL(disk, NULL);
347
348 return disk->syspath;
349}
350
351EAPI const char *
352eeze_disk_devpath_get(Eeze_Disk *disk)
353{
354 EINA_SAFETY_ON_NULL_RETURN_VAL(disk, NULL);
355
356 if (disk->devpath)
357 return disk->devpath;
358 disk->devpath = udev_device_get_devnode(disk->device);
359 return disk->devpath;
360}
361
362EAPI const char *
363eeze_disk_fstype_get(Eeze_Disk *disk)
364{
365 EINA_SAFETY_ON_NULL_RETURN_VAL(disk, NULL);
366
367 return disk->fstype;
368}
369
370EAPI const char *
371eeze_disk_vendor_get(Eeze_Disk *disk)
372{
373 EINA_SAFETY_ON_NULL_RETURN_VAL(disk, NULL);
374
375 if (disk->cache.vendor)
376 return disk->cache.vendor;
377
378 disk->cache.vendor = udev_device_get_property_value(disk->device, "ID_VENDOR");
379 if (!disk->cache.vendor) disk->cache.vendor = udev_device_get_sysattr_value(disk->device, "vendor");
380 return disk->cache.vendor;
381}
382
383EAPI const char *
384eeze_disk_model_get(Eeze_Disk *disk)
385{
386 EINA_SAFETY_ON_NULL_RETURN_VAL(disk, NULL);
387
388 if (disk->cache.model)
389 return disk->cache.model;
390
391 disk->cache.model = udev_device_get_property_value(disk->device, "ID_MODEL");
392 if (!disk->cache.model) disk->cache.model = udev_device_get_sysattr_value(disk->device, "model");
393 return disk->cache.model;
394}
395
396EAPI const char *
397eeze_disk_serial_get(Eeze_Disk *disk)
398{
399 EINA_SAFETY_ON_NULL_RETURN_VAL(disk, NULL);
400
401 if (disk->cache.serial)
402 return disk->cache.serial;
403 disk->cache.serial = udev_device_get_property_value(disk->device, "ID_SERIAL_SHORT");
404 return disk->cache.serial;
405}
406
407EAPI const char *
408eeze_disk_uuid_get(Eeze_Disk *disk)
409{
410 EINA_SAFETY_ON_NULL_RETURN_VAL(disk, NULL);
411
412 if (disk->cache.uuid)
413 return disk->cache.uuid;
414 disk->cache.uuid = udev_device_get_property_value(disk->device, "ID_FS_UUID");
415 return disk->cache.uuid;
416}
417
418EAPI const char *
419eeze_disk_label_get(Eeze_Disk *disk)
420{
421 EINA_SAFETY_ON_NULL_RETURN_VAL(disk, NULL);
422
423 if (disk->cache.label)
424 return disk->cache.label;
425 disk->cache.label = udev_device_get_property_value(disk->device, "ID_FS_LABEL");
426 return disk->cache.label;
427}
428
429EAPI Eeze_Disk_Type
430eeze_disk_type_get(Eeze_Disk *disk)
431{
432 EINA_SAFETY_ON_NULL_RETURN_VAL(disk, EEZE_DISK_TYPE_UNKNOWN);
433
434 if (disk->cache.type)
435 return disk->cache.type;
436 disk->cache.type = _eeze_disk_type_find(disk);
437 return disk->cache.type;
438}
439
440EAPI Eina_Bool
441eeze_disk_removable_get(Eeze_Disk *disk)
442{
443 const char *test;
444 EINA_SAFETY_ON_NULL_RETURN_VAL(disk, EINA_FALSE);
445
446 if (disk->cache.filled)
447 return disk->cache.removable;
448
449 test = udev_device_get_sysattr_value(disk->device, "removable");
450 if (test) disk->cache.removable = !!strtol(test, NULL, 10);
451 else
452 test = _walk_children_get_attr(disk->syspath, "removable", "block", EINA_FALSE);
453 if (test)
454 {
455 disk->cache.removable = !!strtol(test, NULL, 10);
456 eina_stringshare_del(test);
457 }
458 return disk->cache.removable;
459}
460
461EAPI Eina_Bool
462eeze_disk_can_mount(void)
463{
464 if (sizeof(EEZE_MOUNT_BIN) == sizeof(""))
465 return EINA_FALSE;
466 return access(EEZE_MOUNT_BIN, X_OK | R_OK) == 0;
467}
468
469EAPI Eina_Bool
470eeze_disk_can_unmount(void)
471{
472 if (sizeof(EEZE_UNMOUNT_BIN) == sizeof(""))
473 return EINA_FALSE;
474 return access(EEZE_UNMOUNT_BIN, X_OK | R_OK) == 0;
475}
476
477EAPI Eina_Bool
478eeze_disk_can_eject(void)
479{
480 if (sizeof(EEZE_EJECT_BIN) == sizeof(""))
481 return EINA_FALSE;
482 return access(EEZE_EJECT_BIN, X_OK | R_OK) == 0;
483}
diff --git a/src/lib/eeze/eeze_disk_libmount.c b/src/lib/eeze/eeze_disk_libmount.c
new file mode 100644
index 0000000000..9cc1980bb2
--- /dev/null
+++ b/src/lib/eeze/eeze_disk_libmount.c
@@ -0,0 +1,495 @@
1#ifdef HAVE_CONFIG_H
2#include "config.h"
3#endif
4
5#ifndef USE_UNSTABLE_LIBMOUNT_API
6# define USE_UNSTABLE_LIBMOUNT_API 1
7#endif
8
9#include <Ecore.h>
10#include <Eeze.h>
11#include <Eeze_Disk.h>
12#include <libmount.h>
13#include <unistd.h>
14
15#include "eeze_udev_private.h"
16#include "eeze_disk_private.h"
17
18/*
19 *
20 * PRIVATE
21 *
22 */
23
24static struct libmnt_optmap eeze_optmap[] =
25{
26 { "loop[=]", EEZE_DISK_MOUNTOPT_LOOP, 0 },
27 { "utf8", EEZE_DISK_MOUNTOPT_UTF8, 0 },
28 { "noexec", EEZE_DISK_MOUNTOPT_NOEXEC, 0 },
29 { "nosuid", EEZE_DISK_MOUNTOPT_NOSUID, 0 },
30 { "remount", EEZE_DISK_MOUNTOPT_REMOUNT, 0 },
31 { "uid[=]", EEZE_DISK_MOUNTOPT_UID, 0 },
32 { "nodev", EEZE_DISK_MOUNTOPT_NODEV, 0 },
33 { NULL, 0, 0 }
34};
35typedef struct libmnt_table libmnt_table;
36typedef struct libmnt_lock libmnt_lock;
37typedef struct libmnt_fs libmnt_fs;
38typedef struct libmnt_cache libmnt_cache;
39static Ecore_File_Monitor *_mtab_mon = NULL;
40static Ecore_File_Monitor *_fstab_mon = NULL;
41static Eina_Bool _watching = EINA_FALSE;
42static Eina_Bool _mtab_scan_active = EINA_FALSE;
43static Eina_Bool _mtab_locked = EINA_FALSE;
44static Eina_Bool _fstab_scan_active = EINA_FALSE;
45static libmnt_cache *_eeze_mount_mtab_cache = NULL;
46static libmnt_cache *_eeze_mount_fstab_cache = NULL;
47static libmnt_table *_eeze_mount_mtab = NULL;
48static libmnt_table *_eeze_mount_fstab = NULL;
49static libmnt_lock *_eeze_mtab_lock = NULL;
50extern Eina_List *_eeze_disks;
51
52static libmnt_table *_eeze_mount_tab_parse(const char *filename);
53static void _eeze_mount_tab_watcher(void *data, Ecore_File_Monitor *mon EINA_UNUSED, Ecore_File_Event event EINA_UNUSED, const char *path);
54
55static Eina_Bool
56_eeze_mount_lock_mtab(void)
57{
58// DBG("Locking mlock: %s", mnt_lock_get_linkfile(_eeze_mtab_lock));
59 if (EINA_LIKELY(access("/etc/mtab", W_OK)))
60 {
61 INF("Insufficient privs for mtab lock, continuing without lock");
62 return EINA_TRUE;
63 }
64 if (mnt_lock_file(_eeze_mtab_lock))
65 {
66 ERR("Couldn't lock mtab!");
67 return EINA_FALSE;
68 }
69 _mtab_locked = EINA_TRUE;
70 return EINA_TRUE;
71}
72
73static void
74_eeze_mount_unlock_mtab(void)
75{
76// DBG("Unlocking mlock: %s", mnt_lock_get_linkfile(_eeze_mtab_lock));
77 if (_mtab_locked) mnt_unlock_file(_eeze_mtab_lock);
78 _mtab_locked = EINA_FALSE;
79}
80
81
82static int
83_eeze_mount_tab_parse_errcb(libmnt_table *tab EINA_UNUSED, const char *filename, int line)
84{
85 ERR("%s:%d: could not parse line!", filename, line); /* most worthless error reporting ever. */
86 return -1;
87}
88
89/*
90 * I could use mnt_new_table_from_file() but this way gives much more detailed output
91 * on failure so why not
92 */
93static libmnt_table *
94_eeze_mount_tab_parse(const char *filename)
95{
96 libmnt_table *tab;
97
98 if (!(tab = mnt_new_table())) return NULL;
99 if (mnt_table_set_parser_errcb(tab, _eeze_mount_tab_parse_errcb))
100 {
101 ERR("Alloc!");
102 mnt_free_table(tab);
103 return NULL;
104 }
105
106 if (!mnt_table_parse_file(tab, filename))
107 return tab;
108
109 mnt_free_table(tab);
110 return NULL;
111}
112
113static void
114_eeze_mount_tab_watcher(void *data, Ecore_File_Monitor *mon EINA_UNUSED, Ecore_File_Event event EINA_UNUSED, const char *path)
115{
116 libmnt_table *bak;
117
118 if (
119 ((_mtab_scan_active) && (data)) || /* mtab has non-null data to avoid needing strcmp */
120 ((_fstab_scan_active) && (!data))
121 )
122 /* prevent scans from triggering a scan */
123 return;
124
125 bak = _eeze_mount_mtab;
126 if (data)
127 if (!_eeze_mount_lock_mtab())
128 { /* FIXME: maybe queue job here? */
129 ERR("Losing events...");
130 return;
131 }
132 _eeze_mount_mtab = _eeze_mount_tab_parse(path);
133 if (data)
134 _eeze_mount_unlock_mtab();
135 if (!_eeze_mount_mtab)
136 {
137 ERR("Could not parse %s! keeping old tab...", path);
138 goto error;
139 }
140 if (data)
141 {
142 Eina_List *l;
143 Eeze_Disk *disk;
144
145 /* catch externally initiated mounts on existing disks by comparing known mount state to current state */
146 EINA_LIST_FOREACH(_eeze_disks, l, disk)
147 {
148 Eina_Bool mounted;
149
150 mounted = disk->mounted;
151
152 if ((eeze_disk_libmount_mounted_get(disk) != mounted) && (!disk->mount_status))
153 {
154 if (!mounted)
155 {
156 Eeze_Event_Disk_Mount *e;
157 e = malloc(sizeof(Eeze_Event_Disk_Mount));
158 if (e)
159 {
160 e->disk = disk;
161 ecore_event_add(EEZE_EVENT_DISK_MOUNT, e, NULL, NULL);
162 }
163 }
164 else
165 {
166 Eeze_Event_Disk_Unmount *e;
167 e = malloc(sizeof(Eeze_Event_Disk_Unmount));
168 if (e)
169 {
170 e->disk = disk;
171 ecore_event_add(EEZE_EVENT_DISK_UNMOUNT, e, NULL, NULL);
172 }
173 }
174 }
175 }
176 }
177
178 mnt_free_table(bak);
179 if (data)
180 {
181 mnt_free_cache(_eeze_mount_mtab_cache);
182 _eeze_mount_mtab_cache = mnt_new_cache();
183 mnt_table_set_cache(_eeze_mount_mtab, _eeze_mount_mtab_cache);
184 }
185 else
186 {
187 mnt_free_cache(_eeze_mount_fstab_cache);
188 _eeze_mount_fstab_cache = mnt_new_cache();
189 mnt_table_set_cache(_eeze_mount_fstab, _eeze_mount_fstab_cache);
190 }
191 return;
192
193error:
194 mnt_free_table(_eeze_mount_mtab);
195 _eeze_mount_mtab = bak;
196}
197
198/*
199 *
200 * INVISIBLE
201 *
202 */
203
204Eina_Bool
205eeze_libmount_init(void)
206{
207 if (_eeze_mtab_lock)
208 return EINA_TRUE;
209 if (!(_eeze_mtab_lock = mnt_new_lock("/etc/mtab", 0)))
210 return EINA_FALSE;
211 return EINA_TRUE;
212}
213
214void
215eeze_libmount_shutdown(void)
216{
217 if (_eeze_mount_fstab)
218 {
219 mnt_free_table(_eeze_mount_fstab);
220 mnt_free_cache(_eeze_mount_fstab_cache);
221 }
222 if (_eeze_mount_mtab)
223 {
224 mnt_free_table(_eeze_mount_mtab);
225 mnt_free_cache(_eeze_mount_mtab_cache);
226 }
227 eeze_mount_tabs_unwatch();
228 if (!_eeze_mtab_lock)
229 return;
230
231 mnt_unlock_file(_eeze_mtab_lock);
232 mnt_free_lock(_eeze_mtab_lock);
233 _eeze_mtab_lock = NULL;
234}
235
236unsigned long
237eeze_disk_libmount_opts_get(Eeze_Disk *disk)
238{
239 libmnt_fs *mnt;
240 const char *opts;
241 unsigned long f = 0;
242
243 if (!eeze_mount_mtab_scan() || !eeze_mount_fstab_scan())
244 return 0;
245
246 mnt = mnt_table_find_tag(_eeze_mount_mtab, "UUID", eeze_disk_uuid_get(disk), MNT_ITER_BACKWARD);
247 if (!mnt)
248 mnt = mnt_table_find_tag(_eeze_mount_fstab, "UUID", eeze_disk_uuid_get(disk), MNT_ITER_BACKWARD);
249
250 if (!mnt) return 0;
251
252 opts = mnt_fs_get_fs_options(mnt);
253 if (!opts) return 0;
254 if (!mnt_optstr_get_flags(opts, &f, eeze_optmap)) return 0;
255 return f;
256}
257
258/*
259 * helper function to return whether a disk is mounted
260 */
261Eina_Bool
262eeze_disk_libmount_mounted_get(Eeze_Disk *disk)
263{
264 libmnt_fs *mnt;
265
266 if (!disk)
267 return EINA_FALSE;
268
269 if (!eeze_mount_mtab_scan() || !eeze_mount_fstab_scan())
270 return EINA_FALSE;
271
272 mnt = mnt_table_find_srcpath(_eeze_mount_mtab, eeze_disk_devpath_get(disk), MNT_ITER_BACKWARD);
273 if (!mnt)
274 {
275 disk->mounted = EINA_FALSE;
276 return EINA_FALSE;
277 }
278
279 eina_stringshare_replace(&disk->mount_point, mnt_fs_get_target(mnt));
280 disk->mounted = EINA_TRUE;
281 return EINA_TRUE;
282}
283
284
285/*
286 * helper function to return the device that is mounted at a mount point
287 */
288const char *
289eeze_disk_libmount_mp_find_source(const char *mount_point)
290{
291 libmnt_fs *mnt;
292
293 if (!mount_point)
294 return NULL;
295
296 if (!eeze_mount_mtab_scan() || !eeze_mount_fstab_scan())
297 return NULL;
298
299 mnt = mnt_table_find_target(_eeze_mount_mtab, mount_point, MNT_ITER_BACKWARD);
300 if (!mnt)
301 mnt = mnt_table_find_target(_eeze_mount_fstab, mount_point, MNT_ITER_BACKWARD);
302
303 if (!mnt)
304 return NULL;
305
306 return mnt_fs_get_source(mnt);
307}
308
309/*
310 * helper function to return a mount point from a uuid
311 */
312const char *
313eeze_disk_libmount_mp_lookup_by_uuid(const char *uuid)
314{
315 libmnt_fs *mnt;
316
317 if (!uuid)
318 return NULL;
319
320 if (!eeze_mount_mtab_scan() || !eeze_mount_fstab_scan())
321 return NULL;
322
323 mnt = mnt_table_find_tag(_eeze_mount_fstab, "UUID", uuid, MNT_ITER_BACKWARD);
324
325 if (!mnt)
326 return NULL;
327
328 return mnt_fs_get_target(mnt);
329}
330
331/*
332 * helper function to return a mount point from a label
333 */
334const char *
335eeze_disk_libmount_mp_lookup_by_label(const char *label)
336{
337 libmnt_fs *mnt;
338
339 if (!label)
340 return NULL;
341
342 if (!eeze_mount_mtab_scan() || !eeze_mount_fstab_scan())
343 return NULL;
344
345 mnt = mnt_table_find_tag(_eeze_mount_fstab, "LABEL", label, MNT_ITER_BACKWARD);
346
347 if (!mnt)
348 return NULL;
349
350 return mnt_fs_get_target(mnt);
351}
352
353/*
354 * helper function to return a mount point from a /dev/ path
355 */
356const char *
357eeze_disk_libmount_mp_lookup_by_devpath(const char *devpath)
358{
359 libmnt_fs *mnt;
360
361 if (!devpath)
362 return NULL;
363
364 if (!eeze_mount_mtab_scan() || !eeze_mount_fstab_scan())
365 return NULL;
366
367 mnt = mnt_table_find_srcpath(_eeze_mount_mtab, devpath, MNT_ITER_BACKWARD);
368 if (!mnt)
369 mnt = mnt_table_find_srcpath(_eeze_mount_fstab, devpath, MNT_ITER_BACKWARD);
370
371 if (!mnt)
372 return NULL;
373
374 return mnt_fs_get_target(mnt);
375}
376
377/*
378 *
379 * API
380 *
381 */
382
383EAPI Eina_Bool
384eeze_mount_tabs_watch(void)
385{
386 libmnt_table *bak;
387
388 if (_watching)
389 return EINA_TRUE;
390
391 if (!_eeze_mount_lock_mtab())
392 return EINA_FALSE;
393
394 bak = _eeze_mount_tab_parse("/etc/mtab");
395 _eeze_mount_unlock_mtab();
396 if (!bak)
397 goto error;
398
399 mnt_free_table(_eeze_mount_mtab);
400 _eeze_mount_mtab = bak;
401 if (!(bak = _eeze_mount_tab_parse("/etc/fstab")))
402 goto error;
403
404 mnt_free_table(_eeze_mount_fstab);
405 _eeze_mount_fstab = bak;
406
407 _eeze_mount_mtab_cache = mnt_new_cache();
408 mnt_table_set_cache(_eeze_mount_mtab, _eeze_mount_mtab_cache);
409
410 _eeze_mount_fstab_cache = mnt_new_cache();
411 mnt_table_set_cache(_eeze_mount_fstab, _eeze_mount_fstab_cache);
412
413 _mtab_mon = ecore_file_monitor_add("/etc/mtab", _eeze_mount_tab_watcher, (void*)1);
414 _fstab_mon = ecore_file_monitor_add("/etc/fstab", _eeze_mount_tab_watcher, NULL);
415 _watching = EINA_TRUE;
416
417 return EINA_TRUE;
418
419error:
420 if (!_eeze_mount_mtab)
421 ERR("Could not parse /etc/mtab!");
422 else
423 {
424 ERR("Could not parse /etc/fstab!")