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	13 Nov 2012 18:23:41 -0000
@@ -1,8 +1,8 @@
 /*
  * OSBase_CommonFsvol.c
  *
- * (C) Copyright IBM Corp. 2002, 2009
+ * (C) Copyright IBM Corp. 2002, 2012
  *
  * THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE
  * ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE
  * CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT.
@@ -11,8 +11,10 @@
  * http://www.opensource.org/licenses/eclipse-1.0.php
  *
  * Author:       Heidi Neumann <heidineu@de.ibm.com>
  * Contributors: Marcin Gozdalik <gozdal@gozdal.eu.org>
+ *               Henning Sackewitz (shenningz)
+ *               Dave Heller <hellerda@us.ibm.com>
  *               
  * Description:
  * This shared library provides resource access functionality for the class
  * -. 
@@ -20,8 +22,9 @@
 */
 
 /* ---------------------------------------------------------------------------*/
 
+#include <errno.h>
 #include <stdlib.h>
 #include <stdio.h>
 #include <string.h>
 
@@ -174,9 +177,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 +216,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 +242,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 +272,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 +345,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 +361,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;
 }
 
 
