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
00039 #include <libmnt/libmnt.h>
00040
00041 void main_loop(DBusConnection* dbus_connection, void *user_data);
00042 void volume_mounted(const char* udi, const char* mntpnt, void *user_data);
00043 void volume_unmounted(const char* udi, const char* mntpnt, void *user_data);
00044
00046 void main_loop(DBusConnection* dbus_connection, void *user_data)
00047 {
00048 dbus_connection_setup_with_g_main(dbus_connection, NULL);
00049 return;
00050 }
00051
00052
00054 void volume_mounted(const char* udi, const char* mntpnt, void *user_data)
00055 {
00056 printf("volume_mounted('%s', '%s', 0x%p) called\n", udi, mntpnt, user_data);
00057 return;
00058 }
00059
00060
00062 void volume_unmounted(const char* udi, const char* mntpnt, void *user_data)
00063 {
00064 printf("volume_unmounted('%s', '%s', 0x%p) called\n", udi, mntpnt, user_data);
00065 return;
00066 }
00067
00069 LIBMNTFUNCS mnt_functions = { main_loop,
00070 volume_mounted,
00071 volume_unmounted};
00072
00079 int main(int argc, char* argv[])
00080 {
00081 GMainLoop* loop;
00082 int num_volumes=0;
00083 char **data = NULL;
00084 int i=0;
00085 char *udi = NULL;
00086 char *mntpnt = NULL;
00087
00088
00089 fprintf(stderr, "lsmnt v" PACKAGE_VERSION "\n");
00090
00091
00092 loop = g_main_loop_new (NULL, FALSE);
00093
00094
00095 if (mnt_init(&mnt_functions, NULL) == -1) {
00096 fprintf(stderr, "error: mnt_init failed\n");
00097 exit(1);
00098 }
00099
00100
00101 data = mnt_get_all_volumes(&num_volumes);
00102 if (data != NULL) {
00103 for (i=0; i<num_volumes; i++) {
00104 udi = data[i];
00105 if (udi != NULL) {
00106 printf("volume%d = '%s'\n", i, udi);
00107
00108 mntpnt = mnt_get_mntpnt(udi);
00109 if (mntpnt != NULL) {
00110 printf(" -> mntpnt = '%s'\n", mntpnt);
00111 free(mntpnt);
00112 mntpnt = NULL;
00113 }
00114 free(udi);
00115 udi = NULL;
00116 }
00117 }
00118 free(data);
00119 data = NULL;
00120 num_volumes = 0;
00121 }
00122
00123
00124 g_main_loop_run(loop);
00125
00126
00127 mnt_quit();
00128
00129
00130 return 0;
00131 }