void main_loop(DBusConnection* dbus_connection, void *user_data) { dbus_connection_setup_with_g_main(dbus_connection, NULL); return; }
void volume_mounted(const char* udi, const char* mntpnt, void *user_data) { printf("volume_mounted('%s', '%s', 0x%p) called\n", udi, mntpnt, user_data); return; }
void volume_unmounted(const char* udi, const char* mntpnt, void *user_data) { printf("volume_unmounted('%s', '%s', 0x%p) called\n", udi, mntpnt, user_data); return; }
LIBMNTFUNCS mnt_functions = { main_loop, volume_mounted, volume_unmounted};
int main(int argc, char* argv[]) { GMainLoop* loop; int num_volumes=0; char **data = NULL; int i=0; char *udi = NULL; char *mntpnt = NULL; // print version info fprintf(stderr, "lsmnt v" PACKAGE_VERSION "\n"); // get glib main loop loop = g_main_loop_new (NULL, FALSE); // initialize mnt library if (mnt_init(&mnt_functions, NULL) == -1) { fprintf(stderr, "error: mnt_init failed\n"); exit(1); } // get all data data = mnt_get_all_volumes(&num_volumes); if (data != NULL) { for (i=0; i<num_volumes; i++) { udi = data[i]; if (udi != NULL) { printf("volume%d = '%s'\n", i, udi); // get the mount point mntpnt = mnt_get_mntpnt(udi); if (mntpnt != NULL) { printf(" -> mntpnt = '%s'\n", mntpnt); free(mntpnt); mntpnt = NULL; } free(udi); udi = NULL; } } free(data); data = NULL; num_volumes = 0; } // start program g_main_loop_run(loop); // free libraries resources mnt_quit(); // exit return 0; }