Main Page | Modules | Data Structures | File List | Data Fields | Related Pages

lsmnt.c

00001 /***************************************************************************
00002  * CVSID: $Id: lsmnt.c,v 1.15 2004/05/27 20:00:23 stefanb Exp $
00003  *
00004  * lsmnt.c : main() for MNT daemon
00005  *
00006  * Copyright (C) 2004 Stefan Bambach, <stefan@bambach.biz>
00007  *
00008  * Licensed under the GNU General Public License 2.0
00009  *
00010  * This program is free software; you can redistribute it and/or modify
00011  * it under the terms of the GNU General Public License as published by
00012  * the Free Software Foundation; either version 2 of the License, or
00013  * (at your option) any later version.
00014  *
00015  * This program is distributed in the hope that it will be useful,
00016  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00017  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018  * GNU General Public License for more details.
00019  *
00020  * You should have received a copy of the GNU General Public License
00021  * along with this program; if not, write to the Free Software
00022  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
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     // print version info
00089     fprintf(stderr, "lsmnt v" PACKAGE_VERSION "\n");
00090     
00091     // get glib main loop
00092     loop = g_main_loop_new (NULL, FALSE);
00093     
00094     // initialize mnt library
00095     if (mnt_init(&mnt_functions, NULL) == -1) {
00096         fprintf(stderr, "error: mnt_init failed\n");
00097         exit(1);
00098     }
00099 
00100     // get all data
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                 // get the mount point
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     // start program
00124     g_main_loop_run(loop);
00125     
00126     // free libraries resources
00127     mnt_quit();
00128     
00129     // exit
00130     return 0;
00131 }

Generated on Thu May 27 23:27:28 2004 for Mntd by doxygen 1.3.5