Index: OSBase_CommonFsvol.c =================================================================== RCS file: /cvsroot/sblim/cmpi-fsvol/OSBase_CommonFsvol.c,v retrieving revision 1.10 diff -a -u -p -U4 -r1.10 OSBase_CommonFsvol.c --- OSBase_CommonFsvol.c 2 Jun 2009 19:42:24 -0000 1.10 +++ OSBase_CommonFsvol.c 26 Oct 2012 15:21:31 -0000 @@ -20,8 +20,9 @@ */ /* ---------------------------------------------------------------------------*/ +#include #include #include #include @@ -174,9 +175,9 @@ struct mntent * _cpy_fs_data( struct mnt struct mntent * md = NULL ; FILE * mtab = NULL ; char * buf = NULL ; - _OSBASE_TRACE(4,("--- _cpy_fs_data() called")); + _OSBASE_TRACE(3,("--- _cpy_fs_data() called")); mer = calloc (1,sizeof (struct mntent)); /* check if root : @@ -213,9 +214,9 @@ struct mntent * _cpy_fs_data( struct mnt mer->mnt_opts = calloc (1, strlen(me->mnt_opts)+1 ); strcpy( mer->mnt_opts, me->mnt_opts); - _OSBASE_TRACE(4,("--- _cpy_fs_data() exited")); + _OSBASE_TRACE(3,("--- _cpy_fs_data() exited")); return mer; } void free_mntlist( struct mntlist * lptr) { @@ -239,25 +240,24 @@ void free_mntent( struct mntent * sptr) if(sptr->mnt_opts) free(sptr->mnt_opts); free(sptr); } - /* ---------------------------------------------------------------------------*/ -// get mount status of a certain file system +// get mount status of a certain file system (from mount command) /* ---------------------------------------------------------------------------*/ /* * 0 ... not mounted * 1 ... mounted */ -unsigned char fs_mount_status( char * fsname ) { +unsigned char fs_mount_status_internal( char * fsname ) { char * cmd = NULL; char ** hdout = NULL; unsigned char vrc = 0; int rc = 0; - _OSBASE_TRACE(4,("--- fs_mount_status() called")); + _OSBASE_TRACE(3,("--- fs_mount_status_internal() called for %s",fsname)); cmd = calloc (1, (14+strlen(fsname))); strcpy( cmd, "mount | grep "); strcat( cmd, fsname ); @@ -270,9 +270,67 @@ unsigned char fs_mount_status( char * fs } if(cmd) free(cmd); freeresultbuf(hdout); - _OSBASE_TRACE(4,("--- fs_mount_status() exited : %s %i",fsname,vrc)); + _OSBASE_TRACE(3,("--- fs_mount_status_internal() exited : %s %i",fsname,vrc)); + return vrc; +} + +/* ---------------------------------------------------------------------------*/ +// get mount status of a certain file system +/* ---------------------------------------------------------------------------*/ + +/* + * 0 ... not mounted + * 1 ... mounted + */ + +unsigned char fs_mount_status( char * fsname ) { + unsigned char vrc = 0; + const char * uuid = "UUID="; + const char * label = "LABEL="; + char * str = NULL; + char pathname_uuid[255] = "/dev/disk/by-uuid/"; + char pathname_label[255] = "/dev/disk/by-label/"; + char * findname = NULL; + char * realname = NULL; + + _OSBASE_TRACE(3,("--- fs_mount_status() called for %s",fsname)); + + if (!(vrc = fs_mount_status_internal(fsname))) { + /* in fstab, some distros use UUIDs, LABELs or device links that don't show + * up in mount */ + if ((str = strstr(fsname, uuid)) != NULL) { + str = str + strlen(uuid); + strcat(pathname_uuid, str); + findname = pathname_uuid; + _OSBASE_TRACE(4,("--- fs_mount_status() %s is %s",fsname,pathname_uuid)); + } + else if ((str = strstr(fsname, label)) != NULL) { + str = str + strlen(label); + strcat(pathname_label, str); + findname = pathname_label; + _OSBASE_TRACE(4,("--- fs_mount_status() %s is %s",fsname,pathname_label)); + } + else { // fsname is some other symlink or device name + findname = fsname; + } + if (!(vrc = fs_mount_status_internal(findname))) { + realname = realpath(findname, NULL); // uses malloc + if (realname != NULL) { + _OSBASE_TRACE(4,("--- fs_mount_status() %s is really %s",findname, + realname)); + vrc = fs_mount_status_internal(realname); + free(realname); + } + else { + _OSBASE_TRACE(1,("--- fs_mount_status() cannot find %s (%s)",findname, + strerror(errno))); + // TODO: should return some error here instead of reporting not mounted + } + } + } + _OSBASE_TRACE(3,("--- fs_mount_status() exited : %s %i",fsname,vrc)); return vrc; } /* @@ -285,9 +343,9 @@ unsigned char fs_default_mount_status( c char ** hdout = NULL; unsigned char vrc = 0; int rc = 0; - _OSBASE_TRACE(4,("--- fs_default_mount_status() called")); + _OSBASE_TRACE(3,("--- fs_default_mount_status() called for %s",fsname)); cmd = calloc (1, (23+strlen(fsname))); strcpy( cmd, "cat /etc/fstab | grep "); strcat( cmd, fsname ); @@ -301,9 +359,9 @@ unsigned char fs_default_mount_status( c } if(cmd) free(cmd); freeresultbuf(hdout); - _OSBASE_TRACE(4,("--- fs_default_mount_status() exited : %s %i",fsname,vrc)); + _OSBASE_TRACE(3,("--- fs_default_mount_status() exited : %s %i",fsname,vrc)); return vrc; }