bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[bug-gnulib] Re: [patch #3741] Added support for Interix within mountlis


From: Jim Meyering
Subject: [bug-gnulib] Re: [patch #3741] Added support for Interix within mountlist.c
Date: Tue, 15 Feb 2005 19:22:59 +0100

Paul Eggert <address@hidden> wrote:
> Jim Meyering <address@hidden> writes:
>
>> +    /* In the unlikely event that opendir and each readdir
>> +       succeed, but all statvfs calls fail, ensure that we
>> +       fail with a valid errno value.  */
>
> If I'm understanding the code correctly, the comment should read "a
> statvfs call fails", not "all statvfs calls fail".
>
>> +    char file_name[9 + NAME_MAX]; /* 8 for /dev/fs/ + 1 for NUL */
>
> A minor point.  The above can be replaced by something like this:
>
>     static char const DEV_FS[] = "/dev/fs/";
>     char file_name[sizeof DEV_FS + NAME_MAX];
>
> and then you can replace later occurrences of "/dev/fs/" with DEV_FS.

Thanks.
Here's an improved patch:

Index: lib/mountlist.c
===================================================================
RCS file: /cvsroot/gnulib/gnulib/lib/mountlist.c,v
retrieving revision 1.48
diff -u -p -r1.48 mountlist.c
--- lib/mountlist.c     1 Feb 2005 23:56:47 -0000       1.48
+++ lib/mountlist.c     15 Feb 2005 18:21:35 -0000
@@ -95,6 +95,11 @@ char *strstr ();
 # include <dirent.h>
 #endif
 
+#ifdef MOUNTED_INTERIX         /* Windows with Interix / Microsoft Services 
For UNIX */
+# include <dirent.h>
+# include <sys/statvfs.h>
+#endif
+
 #ifdef MOUNTED_FREAD           /* SVR2.  */
 # include <mnttab.h>
 #endif
@@ -421,6 +426,98 @@ read_file_system_list (bool need_fs_type
   }
 #endif /* MOUNTED_GETMNT. */
 
+#if defined MOUNTED_INTERIX
+  /* Windows with Interix / Microsoft Services For UNIX */
+  {
+    /* Unlike Cygwin which attempts to implement as many of the UNIX
+       API's as possible, Interix implements a great deal and then depends
+       on developers to port the rest. On Interix, the POSIX implementation
+       prefers to deny that UNIX style file systems exist and therefore
+       does not implement the mount tables for the system.
+
+       This implementation simply scans the mounted file system directory
+       and then reads the statvfs data for each entry to construct the
+       mount list.
+
+       The implementation also chooses to use the reentrant implementation
+       of readdir_r in order to favor a threading friendly system. */
+
+    static char const DEV_FS[] = "/dev/fs";
+    int statvfs_errno = 0;
+    int fail;
+
+    DIR *dirp = opendir (DEV_FS);
+    if (dirp == NULL)
+      {
+       fail = 1;
+      }
+    else
+      {
+       char file_name[sizeof DEV_FS + 1 + NAME_MAX];
+       int saved_errno;
+
+       while (1)
+         {
+           struct statvfs stat_buf;
+           struct dirent entry;
+           struct dirent *result;
+
+           fail = readdir_r (dirp, &entry, &result);
+
+           if (fail || result == NULL)
+             break;
+
+           strcpy (file_name, DEV_FS);
+           strcat (file_name, "/");
+           strcat (file_name, entry.d_name);
+
+           fail = statvfs (file_name, &stat_buf);
+           if (fail == 0)
+             {
+               static char const REMOTE_MOUNT_INDICATOR[]
+                 = "/Device/LanmanRedirector/;",
+               me = xmalloc (sizeof *me);
+               me->me_devname = xstrdup (stat_buf.f_mntfromname);
+               me->me_mountdir = xstrdup (stat_buf.f_mntonname);
+               me->me_type = xstrdup (stat_buf.f_fstypename);
+               me->me_type_malloced = 1;
+               me->me_dummy = 0;
+               me->me_dev = stat_buf.f_fsid;
+               me->me_remote
+                 = strncmp (stat_buf.f_mntfromname,
+                            REMOTE_MOUNT_INDICATOR,
+                            strlen (REMOTE_MOUNT_INDICATOR)) == 0;
+
+               /* Add to the linked list. */
+               *mtail = me;
+               mtail = &me->me_next;
+             }
+           else
+             {
+               statvfs_errno = errno;
+             }
+         }
+
+       saved_errno = errno;
+       closedir (dirp);
+       errno = saved_errno;
+      }
+
+    if (!fail && statvfs_errno)
+      {
+       /* In the unlikely event that opendir and each readdir
+          succeed, but a statvfs call fails, ensure that we
+          fail with a valid errno value.  */
+       fail = 1;
+       errno = statvfs_errno;
+      }
+
+    if (fail)
+      goto free_then_fail;
+
+  }
+#endif
+
 #if defined MOUNTED_FS_STAT_DEV /* BeOS */
   {
     /* The next_dev() and fs_stat_dev() system calls give the list of




reply via email to

[Prev in Thread] Current Thread [Next in Thread]