.
[gnulib.git] / lib / mountlist.c
index b2ed440..37c3d1b 100644 (file)
@@ -12,8 +12,8 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with this program; if not, write to the Free Software
-   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
+   along with this program; if not, write to the Free Software Foundation,
+   Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
 
 #ifdef HAVE_CONFIG_H
 #include <config.h>
@@ -80,6 +80,10 @@ void error ();
 #include <sys/statfs.h>
 #endif
 
+#ifdef MOUNTED_LISTMNTENT
+#include <mntent.h>
+#endif
+
 #ifdef MOUNTED_GETMNTENT2      /* SVR4.  */
 #include <sys/mnttab.h>
 #endif
@@ -130,10 +134,6 @@ fstype_to_string (t)
 {
   switch (t)
     {
-    case MOUNT_UFS:
-      return "ufs";
-    case MOUNT_NFS:
-      return "nfs";
 #ifdef MOUNT_PC
     case MOUNT_PC:
       return "pc";
@@ -154,6 +154,70 @@ fstype_to_string (t)
     case MOUNT_TMP:
       return "tmp";
 #endif
+#ifdef MOUNT_UFS
+   case MOUNT_UFS:
+     return "ufs" ;
+#endif
+#ifdef MOUNT_NFS
+   case MOUNT_NFS:
+     return "nfs" ;
+#endif
+#ifdef MOUNT_MSDOS
+   case MOUNT_MSDOS:
+     return "msdos" ;
+#endif
+#ifdef MOUNT_LFS
+   case MOUNT_LFS:
+     return "lfs" ;
+#endif
+#ifdef MOUNT_LOFS
+   case MOUNT_LOFS:
+     return "lofs" ;
+#endif
+#ifdef MOUNT_FDESC
+   case MOUNT_FDESC:
+     return "fdesc" ;
+#endif
+#ifdef MOUNT_PORTAL
+   case MOUNT_PORTAL:
+     return "portal" ;
+#endif
+#ifdef MOUNT_NULL
+   case MOUNT_NULL:
+     return "null" ;
+#endif
+#ifdef MOUNT_UMAP
+   case MOUNT_UMAP:
+     return "umap" ;
+#endif
+#ifdef MOUNT_KERNFS
+   case MOUNT_KERNFS:
+     return "kernfs" ;
+#endif
+#ifdef MOUNT_PROCFS
+   case MOUNT_PROCFS:
+     return "procfs" ;
+#endif
+#ifdef MOUNT_AFS
+   case MOUNT_AFS:
+     return "afs" ;
+#endif
+#ifdef MOUNT_CD9660
+   case MOUNT_CD9660:
+     return "cd9660" ;
+#endif
+#ifdef MOUNT_UNION
+   case MOUNT_UNION:
+     return "union" ;
+#endif
+#ifdef MOUNT_DEVFS
+   case MOUNT_DEVFS:
+     return "devfs" ;
+#endif
+#ifdef MOUNT_EXT2FS
+   case MOUNT_EXT2FS:
+     return "ext2fs" ;
+#endif
     default:
       return "?";
     }
@@ -195,6 +259,36 @@ read_filesystem_list (need_fs_type, all_fs)
   me->me_next = NULL;
   mount_list = mtail = me;
 
+#ifdef MOUNTED_LISTMNTENT
+  {
+    struct tabmntent *mntlist, *p;
+    struct mntent *mnt;
+    struct mount_entry *me;
+    
+    /* the third and fourth arguments could be used to filter mounts,
+       but Crays doesn't seem to have any mounts that we want to
+       remove. Specifically, automount create normal NFS mounts.
+       */
+
+    if(listmntent(&mntlist, KMTAB, NULL, NULL) < 0)
+      return NULL;
+    p = mntlist;
+    while(p){
+      mnt = p->ment;
+      me = (struct mount_entry*) xmalloc(sizeof (struct mount_entry));
+      me->me_devname = xstrdup(mnt->mnt_fsname);
+      me->me_mountdir = xstrdup(mnt->mnt_dir);
+      me->me_type = xstrdup(mnt->mnt_type);
+      me->me_dev = -1;
+      me->me_next = NULL;
+      mtail->me_next = me;
+      mtail = me;
+      p = p->next;
+    }
+    freemntlist(mntlist);
+  }
+#endif
+
 #ifdef MOUNTED_GETMNTENT1      /* 4.3BSD, SunOS, HP-UX, Dynix, Irix.  */
   {
     struct mntent *mnt;
@@ -225,7 +319,7 @@ read_filesystem_list (need_fs_type, all_fs)
              me->me_dev = xatoi (devopt + 4);
          }
        else
-         me->me_dev = -1;      /* Magic; means not known yet. */
+         me->me_dev = (dev_t) -1;      /* Magic; means not known yet. */
        me->me_next = NULL;
 
        /* Add to the linked list. */
@@ -256,7 +350,7 @@ read_filesystem_list (need_fs_type, all_fs)
 #else
        me->me_type = fstype_to_string (fsp->f_type);
 #endif
-       me->me_dev = -1;        /* Magic; means not known yet. */
+       me->me_dev = (dev_t) -1;        /* Magic; means not known yet. */
        me->me_next = NULL;
 
        /* Add to the linked list. */
@@ -317,7 +411,7 @@ read_filesystem_list (need_fs_type, all_fs)
        me->me_devname = xstrdup (stats[counter].f_mntfromname);
        me->me_mountdir = xstrdup (stats[counter].f_mntonname);
        me->me_type = mnt_names[stats[counter].f_type];
-       me->me_dev = -1;        /* Magic; means not known yet. */
+       me->me_dev = (dev_t) -1;        /* Magic; means not known yet. */
        me->me_next = NULL;
 
        /* Add to the linked list. */
@@ -350,7 +444,7 @@ read_filesystem_list (need_fs_type, all_fs)
        strcpy (me->me_devname + 5, mnt.mt_dev);
 #endif
        me->me_mountdir = xstrdup (mnt.mt_filsys);
-       me->me_dev = -1;        /* Magic; means not known yet. */
+       me->me_dev = (dev_t) -1;        /* Magic; means not known yet. */
        me->me_type = "";
 #ifdef GETFSTYP                        /* SVR3.  */
        if (need_fs_type)
@@ -384,7 +478,7 @@ read_filesystem_list (need_fs_type, all_fs)
        me->me_devname = xstrdup ( (*ent)->mt_resource);
        me->me_mountdir = xstrdup( (*ent)->mt_directory);
        me->me_type =  xstrdup ((*ent)->mt_fstype);
-       me->me_dev = -1;        /* Magic; means not known yet. */
+       me->me_dev = (dev_t) -1;        /* Magic; means not known yet. */
        me->me_next = NULL;
 
        /* Add to the linked list. */
@@ -412,7 +506,7 @@ read_filesystem_list (need_fs_type, all_fs)
        me->me_devname = xstrdup (mnt.mnt_special);
        me->me_mountdir = xstrdup (mnt.mnt_mountp);
        me->me_type = xstrdup (mnt.mnt_fstype);
-       me->me_dev = -1;        /* Magic; means not known yet. */
+       me->me_dev = (dev_t) -1;        /* Magic; means not known yet. */
        me->me_next = NULL;
 
        /* Add to the linked list. */
@@ -464,7 +558,7 @@ read_filesystem_list (need_fs_type, all_fs)
          }
        me->me_mountdir = xstrdup (thisent + vmp->vmt_data[VMT_STUB].vmt_off);
        me->me_type = xstrdup (fstype_to_string (vmp->vmt_gfstype));
-       me->me_dev = -1;        /* vmt_fsid might be the info we want.  */
+       me->me_dev = (dev_t) -1; /* vmt_fsid might be the info we want.  */
        me->me_next = NULL;
 
        /* Add to the linked list. */