changeset 1443:13bcee72981f

(read_filesystem_list): If all_fs is negative, omit non-local filesytems. From Paul Eggert.
author Jim Meyering <jim@meyering.net>
date Sat, 25 Jul 1998 14:41:04 +0000
parents 1223381eb847
children 8a70cc03ce0d
files lib/mountlist.c
diffstat 1 files changed, 58 insertions(+), 22 deletions(-) [+]
line wrap: on
line diff
--- a/lib/mountlist.c
+++ b/lib/mountlist.c
@@ -283,8 +283,9 @@
    Add each entry to the tail of the list so that they stay in order.
    If NEED_FS_TYPE is nonzero, ensure that the filesystem type fields in
    the returned list are valid.  Otherwise, they might not be.
-   If ALL_FS is zero, do not return entries for filesystems that
-   are automounter (dummy) entries.  */
+   If ALL_FS is positive, return all entries; if zero, omit entries
+   for filesystems that are automounter (dummy) entries; if negative,
+   also omit non-local filesystems.  */
 
 struct mount_entry *
 read_filesystem_list (int need_fs_type, int all_fs)
@@ -306,9 +307,10 @@
 
     if(listmntent(&mntlist, KMTAB, NULL, NULL) < 0)
       return NULL;
-    p = mntlist;
-    while(p){
+    for (p = mntlist; p; p = p->next) {
       mnt = p->ment;
+      if (all_fs < 0 && REMOTE_FS_TYPE (mnt->mnt_type))
+	continue;
       me = (struct mount_entry*) xmalloc(sizeof (struct mount_entry));
       me->me_devname = xstrdup(mnt->mnt_fsname);
       me->me_mountdir = xstrdup(mnt->mnt_dir);
@@ -316,7 +318,6 @@
       me->me_dev = -1;
       *mtail = me;
       mtail = &me->me_next;
-      p = p->next;
     }
     freemntlist(mntlist);
   }
@@ -335,8 +336,10 @@
 
     while ((mnt = getmntent (fp)))
       {
-	if (!all_fs && (!strcmp (mnt->mnt_type, "ignore")
-			|| !strcmp (mnt->mnt_type, "auto")))
+	if (all_fs <= 0 && (!strcmp (mnt->mnt_type, "ignore")
+			    || !strcmp (mnt->mnt_type, "auto")))
+	  continue;
+	if (all_fs < 0 && REMOTE_FS_TYPE (mnt->mnt_type))
 	  continue;
 
 	me = (struct mount_entry *) xmalloc (sizeof (struct mount_entry));
@@ -372,8 +375,21 @@
     entries = getmntinfo (&fsp, MNT_NOWAIT);
     if (entries < 0)
       return NULL;
-    while (entries-- > 0)
+    for (; entries-- > 0; fsp++)
       {
+	if (all_fs < 0)
+	  {
+# ifdef HAVE_F_FSTYPENAME_IN_STATFS
+	    if (REMOTE_FS_TYPE (fsp->f_fstypename))
+	      continue;
+# else
+#  ifdef MOUNT_NFS
+	    if (REMOTE_FS_TYPE (fstype_to_string (fsp->f_type)))
+	      continue;
+#  endif
+# endif
+	  }
+
 	me = (struct mount_entry *) xmalloc (sizeof (struct mount_entry));
 	me->me_devname = xstrdup (fsp->f_mntfromname);
 	me->me_mountdir = xstrdup (fsp->f_mntonname);
@@ -383,7 +399,6 @@
 	/* Add to the linked list. */
 	*mtail = me;
 	mtail = &me->me_next;
-	fsp++;
       }
   }
 #endif /* MOUNTED_GETMNTINFO */
@@ -398,6 +413,9 @@
 	   0 <= (val = getmnt (&offset, &fsd, sizeof (fsd), NOSTAT_MANY,
 			       (char *) 0)))
       {
+	if (all_fs < 0 && REMOTE_FS_TYPE (gt_names[fsd.fd_req.fstype]))
+	  continue;
+
 	me = (struct mount_entry *) xmalloc (sizeof (struct mount_entry));
 	me->me_devname = xstrdup (fsd.fd_req.devname);
 	me->me_mountdir = xstrdup (fsd.fd_req.path);
@@ -434,6 +452,9 @@
 
     for (counter = 0; counter < numsys; counter++)
       {
+	if (all_fs < 0 && REMOTE_FS_TYPE (mnt_names[stats[counter].f_type]))
+	  continue;
+
 	me = (struct mount_entry *) xmalloc (sizeof (struct mount_entry));
 	me->me_devname = xstrdup (stats[counter].f_mntfromname);
 	me->me_mountdir = xstrdup (stats[counter].f_mntonname);
@@ -461,6 +482,24 @@
 
     while (fread (&mnt, sizeof mnt, 1, fp) > 0)
       {
+	char *fs_type = "";
+
+# ifdef GETFSTYP			/* SVR3.  */
+	if (need_fs_type || all_fs < 0)
+	  {
+	    struct statfs fsd;
+	    char typebuf[FSTYPSZ];
+
+	    if (statfs (mnt.mt_filsys, &fsd, sizeof fsd, 0) != -1
+		&& sysfs (GETFSTYP, fsd.f_fstyp, typebuf) != -1)
+	      {
+		if (all_fs < 0 && REMOTE_FS_TYPE (typebuf))
+		  continue;
+		fs_type = xstrdup (typebuf);
+	      }
+	  }
+# endif
+
 	me = (struct mount_entry *) xmalloc (sizeof (struct mount_entry));
 # ifdef GETFSTYP			/* SVR3.  */
 	me->me_devname = xstrdup (mnt.mt_dev);
@@ -471,18 +510,7 @@
 # endif
 	me->me_mountdir = xstrdup (mnt.mt_filsys);
 	me->me_dev = (dev_t) -1;	/* Magic; means not known yet. */
-	me->me_type = "";
-# ifdef GETFSTYP			/* SVR3.  */
-	if (need_fs_type)
-	  {
-	    struct statfs fsd;
-	    char typebuf[FSTYPSZ];
-
-	    if (statfs (me->me_mountdir, &fsd, sizeof fsd, 0) != -1
-		&& sysfs (GETFSTYP, fsd.f_fstyp, typebuf) != -1)
-	      me->me_type = xstrdup (typebuf);
-	  }
-# endif
+	me->me_type = fs_type;
 
 	/* Add to the linked list. */
 	*mtail = me;
@@ -507,6 +535,9 @@
     struct mntent **mnttbl=getmnttbl(),**ent;
     for (ent=mnttbl;*ent;ent++)
       {
+	if (all_fs < 0 && REMOTE_FS_TYPE ((*ent)->mt_fstype))
+	  continue;
+
 	me = (struct mount_entry *) xmalloc (sizeof (struct mount_entry));
 	me->me_devname = xstrdup ( (*ent)->mt_resource);
 	me->me_mountdir = xstrdup( (*ent)->mt_directory);
@@ -567,7 +598,10 @@
 	while ((ret = getmntent (fp, &mnt)) == 0)
 	  {
 	    /* Don't show automounted filesystems twice on e.g., Solaris.  */
-	    if (!all_fs && MNT_IGNORE (&mnt))
+	    if (all_fs <= 0 && MNT_IGNORE (&mnt))
+	      continue;
+
+	    if (all_fs < 0 && REMOTE_FS_TYPE (mnt.mnt_fstype))
 	      continue;
 
 	    me = (struct mount_entry *) xmalloc (sizeof (struct mount_entry));
@@ -612,6 +646,8 @@
 	 thisent += vmp->vmt_length)
       {
 	vmp = (struct vmount *) thisent;
+	if (all_fs < 0 && vmp->vmt_flags & MNT_REMOTE)
+	  continue;
 	me = (struct mount_entry *) xmalloc (sizeof (struct mount_entry));
 	if (vmp->vmt_flags & MNT_REMOTE)
 	  {