00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #ifdef HAVE_CONFIG_H
00027 # include <config.h>
00028 #endif
00029
00030 #include <stdio.h>
00031 #include <stdlib.h>
00032 #include <string.h>
00033 #include <unistd.h>
00034 #include <getopt.h>
00035
00036 #include <glib.h>
00037 #include <dbus/dbus-glib.h>
00038 #include <dbus/dbus-glib-lowlevel.h>
00039
00040 #include <libmnt/libmnt.h>
00041
00042
00043 void main_loop(DBusConnection* dbus_connection, void *user_data);
00044 void volume_mounted(const char* udi, const char* mntpnt, void *user_data);
00045 void volume_unmounted(const char* udi, const char* mntpnt, void *user_data);
00046 void dbus_disconnect(void *user_data);
00047
00048
00050 void main_loop(DBusConnection* dbus_connection, void *user_data)
00051 {
00052 dbus_connection_setup_with_g_main(dbus_connection, NULL);
00053 return;
00054 }
00055
00056
00058 void volume_mounted(const char* udi, const char* mntpnt, void *user_data)
00059 {
00060 printf("volume_mounted('%s', '%s', 0x%p) called\n", udi, mntpnt, user_data);
00061 return;
00062 }
00063
00064
00066 void volume_unmounted(const char* udi, const char* mntpnt, void *user_data)
00067 {
00068 printf("volume_unmounted('%s', '%s', 0x%p) called\n", udi, mntpnt, user_data);
00069 return;
00070 }
00071
00072
00074 void dbus_disconnect(void *user_data)
00075 {
00076 GMainLoop *loop = (GMainLoop *) user_data;
00077
00078 printf("Disconnected from DBUS ! exiting....\n");
00079
00080 g_main_loop_quit(loop);
00081
00082 return;
00083 }
00084
00085
00087 LIBMNTFUNCS mnt_functions = { main_loop,
00088
00089 volume_mounted,
00090 volume_unmounted,
00091 dbus_disconnect};
00092
00093
00094 DBusDispatchStatus gstatus = DBUS_DISPATCH_COMPLETE;
00095
00096 void _dispatch_status(DBusConnection *connection,DBusDispatchStatus new_status,void *data);
00097 void _dispatch_status(
00098 DBusConnection *connection,
00099 DBusDispatchStatus new_status,
00100 void *data)
00101 {
00102 gstatus = new_status;
00103 switch(new_status) {
00104 case DBUS_DISPATCH_DATA_REMAINS:
00105 printf("DBUS_DISPATCH_DATA_REMAINS\n");
00106 break;
00107 case DBUS_DISPATCH_COMPLETE:
00108 printf("DBUS_DISPATCH_COMPLETE\n");
00109 break;
00110 case DBUS_DISPATCH_NEED_MEMORY:
00111 printf("DBUS_DISPATCH_NEED_MEMORY\n");
00112 break;
00113 default:
00114 printf("UNKNOWN\n");
00115 break;
00116 }
00117 }
00118
00119 dbus_bool_t _add_watch(DBusWatch *watch, void *data);
00120 dbus_bool_t _add_watch(DBusWatch *watch, void *data)
00121 {
00122 printf("_add_watch called.\n");
00123 if (!dbus_watch_get_enabled(watch)) {
00124 return TRUE;
00125 }
00126 return TRUE;
00127 }
00128
00129 void _remove_watch(DBusWatch *watch, void *data);
00130 void _remove_watch(DBusWatch *watch, void *data)
00131 {
00132 printf("_remove_watch called.\n");
00133 }
00134
00135 void _toggle_watch(DBusWatch *watch, void *data);
00136 void _toggle_watch(DBusWatch *watch, void *data)
00137 {
00138 printf("_toggle_watch called.\n");
00139 if (dbus_watch_get_enabled(watch)) {
00140 _add_watch(watch, data);
00141 } else {
00142 _remove_watch(watch, data);
00143 }
00144 }
00145
00146 dbus_bool_t _add_timeout(DBusTimeout *timeout, void *data);
00147 dbus_bool_t _add_timeout(DBusTimeout *timeout, void *data)
00148 {
00149 printf("_add_timeout called.\n");
00150 printf("_add_timeout called. %d\n", dbus_timeout_get_interval(timeout));
00151 return TRUE;
00152 }
00153
00154 void _remove_timeout(DBusTimeout *timeout, void *data);
00155 void _remove_timeout(DBusTimeout *timeout, void *data)
00156 {
00157 printf("_remove_timeout called.\n");
00158 }
00159
00160 void _toggle_timeout(DBusTimeout *timeout, void *data);
00161 void _toggle_timeout(DBusTimeout *timeout, void *data)
00162 {
00163 printf("_toggle_timeout called.\n");
00164 if (dbus_timeout_get_enabled (timeout)) {
00165 _add_timeout(timeout, data);
00166 } else {
00167 _remove_timeout(timeout, data);
00168 }
00169 }
00170
00171 void _wakeup_main(void *data);
00172 void _wakeup_main(void *data)
00173 {
00174 printf("_wakeup_main called.\n");
00175 }
00176
00177
00178 gboolean mntcheck(gpointer user_data);
00179 gboolean mntcheck(gpointer user_data)
00180 {
00181 int num_volumes=0;
00182 char **data = NULL;
00183 int i=0;
00184 char *udi = NULL;
00185 char *mntpnt = NULL;
00186
00187
00188 data = mnt_get_all_volumes(&num_volumes);
00189 if (data != NULL) {
00190 for (i=0; i<num_volumes; i++) {
00191 udi = data[i];
00192 if (udi != NULL) {
00193
00194
00195 mntpnt = mnt_get_mntpnt(udi);
00196 if (mntpnt != NULL) {
00197 printf(" -> mntpnt%d = '%s'\n", i, mntpnt);
00198 free(mntpnt);
00199 mntpnt = NULL;
00200 }
00201 free(udi);
00202 udi = NULL;
00203 }
00204 }
00205 free(data);
00206 data = NULL;
00207 num_volumes = 0;
00208 }
00209 return TRUE;
00210 }
00211
00212
00219 int main(int argc, char* argv[])
00220 {
00221 GMainLoop* loop;
00222 int num_volumes=0;
00223 char **data = NULL;
00224 int i=0;
00225 char *udi = NULL;
00226 char *mntpnt = NULL;
00227 int res = -1;
00228
00229
00230
00231 fprintf(stderr, "lsmnt v" PACKAGE_VERSION "\n");
00232
00233
00234 loop = g_main_loop_new (NULL, FALSE);
00235
00236
00237 if (mnt_init(&mnt_functions, loop) == -1) {
00238 fprintf(stderr, "error: mnt_init failed\n");
00239 exit(1);
00240 }
00241
00242
00243
00244
00245
00246
00247
00248
00249
00250
00251
00252
00253 g_timeout_add(1000, mntcheck, NULL);
00254
00255
00256 data = mnt_get_all_volumes(&num_volumes);
00257 if (data != NULL) {
00258 for (i=0; i<num_volumes; i++) {
00259 udi = data[i];
00260 if (udi != NULL) {
00261 printf("volume%d = '%s'\n", i, udi);
00262
00263 res = mnt_remount_rw(udi);
00264 printf("remounting read/write '%s' returns %d\n", udi, res);
00265
00266 res = mnt_remount_rd(udi);
00267 printf("remounting read only '%s' returns %d\n", udi, res);
00268
00269 mntpnt = mnt_get_mntpnt(udi);
00270 if (mntpnt != NULL) {
00271 printf(" -> mntpnt = '%s'\n", mntpnt);
00272 free(mntpnt);
00273 mntpnt = NULL;
00274 }
00275 free(udi);
00276 udi = NULL;
00277 }
00278 }
00279 free(data);
00280 data = NULL;
00281 num_volumes = 0;
00282 }
00283
00284
00285 g_main_loop_run(loop);
00286
00287
00288
00289
00290
00291
00292
00293
00294
00295
00296
00297
00298
00299
00300
00301
00302
00303
00304
00305
00306
00307
00308
00309
00310
00311
00312 mnt_quit();
00313
00314
00315 return 0;
00316 }