This is the mail archive of the cygwin-patches mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] implement /proc/filesystems


This patch implements /proc/filesystems:

$ cat /proc/filesystems
        vfat
        ntfs
nodev   smbfs
nodev   nfs
nodev   netapp
        iso9660
        udf
nodev   csc-cache
nodev   sunwnfs
nodev   unixfs
nodev   mvfs
nodev   cifs
nodev   nwfs

(Actual indentation is tabs, not spaces, as on Linux.)

"nodev" is meant to indicate that the filesystem does not represent a
block device[1].  While I tried to base this on Linux as best I could
figure out from web searches, it's very possible that I misjudged some
of these FS types.

I'll follow up with a patch to new-features.sgml later (my pending
CLOCK_MONOTONIC patch currently conflicts with that).


Yaakov

[1]
http://www.redhat.com/docs/manuals/enterprise/RHEL-4-Manual/en-US/Reference_Guide/s2-proc-filesystems.html

2010-08-08  Yaakov Selkowitz  <yselkowitz@users.sourceforge.net>

	* fhandler_proc.cc: Add /proc/filesystems virtual file.
	(format_proc_filesystems): New function.
	* mount.cc (fs_names): Move to global scope. Redefine as array
	of { "name", block_device? } structs.
	(fillout_mntent): Use name member of fs_names.
	* mount.h (fs_names): New prototype.

Index: fhandler_proc.cc
===================================================================
RCS file: /cvs/src/src/winsup/cygwin/fhandler_proc.cc,v
retrieving revision 1.89
diff -u -r1.89 fhandler_proc.cc
--- fhandler_proc.cc	12 Mar 2010 23:13:47 -0000	1.89
+++ fhandler_proc.cc	9 Aug 2010 05:00:16 -0000
@@ -28,6 +28,7 @@
 #include <winioctl.h>
 #include <wchar.h>
 #include "cpuid.h"
+#include "mount.h"
 
 #define _COMPILING_NEWLIB
 #include <dirent.h>
@@ -41,6 +42,7 @@
 static _off64_t format_proc_partitions (void *, char *&);
 static _off64_t format_proc_self (void *, char *&);
 static _off64_t format_proc_mounts (void *, char *&);
+static _off64_t format_proc_filesystems (void *, char *&);
 
 /* names of objects in /proc */
 static const virt_tab_t proc_tab[] = {
@@ -59,6 +61,7 @@
   { "registry32", FH_REGISTRY,	virt_directory,	NULL },
   { "registry64", FH_REGISTRY,	virt_directory,	NULL },
   { "net",	  FH_PROCNET,	virt_directory,	NULL },
+  { "filesystems", FH_PROC,	virt_file,	format_proc_filesystems },
   { NULL,	  0,		virt_none,	NULL }
 };
 
@@ -1220,4 +1223,22 @@
   return __small_sprintf (destbuf, "self/mounts");
 }
 
+static _off64_t
+format_proc_filesystems (void *, char *&destbuf)
+{
+  tmp_pathbuf tp;
+  char *buf = tp.c_get ();
+  char *bufptr = buf;
+
+  /* start at 1 to skip type "none" */
+  for (int i = 1; fs_names[i].name; i++)
+    bufptr += __small_sprintf(bufptr, "%s\t%s\n",
+                              fs_names[i].block_device ? "" : "nodev",
+                              fs_names[i].name);
+
+  destbuf = (char *) crealloc_abort (destbuf, bufptr - buf);
+  memcpy (destbuf, buf, bufptr - buf);
+  return bufptr - buf;
+}
+
 #undef print
Index: mount.cc
===================================================================
RCS file: /cvs/src/src/winsup/cygwin/mount.cc,v
retrieving revision 1.61
diff -u -r1.61 mount.cc
--- mount.cc	29 Apr 2010 10:38:04 -0000	1.61
+++ mount.cc	9 Aug 2010 05:00:17 -0000
@@ -1472,6 +1472,24 @@
 
 /************************* mount_item class ****************************/
 
+/* Order must be identical to mount.h, enum fs_info_type. */
+fs_names_t fs_names[] = {
+    { "none", false },
+    { "vfat", true },
+    { "ntfs", true },
+    { "smbfs", false },
+    { "nfs", false },
+    { "netapp", false },
+    { "iso9660", true },
+    { "udf", true },
+    { "csc-cache", false },
+    { "sunwnfs", false },
+    { "unixfs", false },
+    { "mvfs", false },
+    { "cifs", false },
+    { "nwfs", false }
+};
+
 static mntent *
 fillout_mntent (const char *native_path, const char *posix_path, unsigned flags)
 {
@@ -1509,26 +1527,8 @@
     RtlAppendUnicodeToString (&unat, L"\\");
   mntinfo.update (&unat, NULL);
 
-  /* Order must be identical to mount.h, enum fs_info_type. */
-  const char *fs_names[] = {
-    "none",
-    "vfat",
-    "ntfs",
-    "smbfs",
-    "nfs",
-    "netapp",
-    "iso9660",
-    "udf",
-    "csc-cache",
-    "sunwnfs",
-    "unixfs",
-    "mvfs",
-    "cifs",
-    "nwfs"
-  };
-
   if (mntinfo.what_fs () > 0 && mntinfo.what_fs () < max_fs_type)
-    strcpy (_my_tls.locals.mnt_type, fs_names[mntinfo.what_fs ()]);
+    strcpy (_my_tls.locals.mnt_type, fs_names[mntinfo.what_fs ()].name);
   else
     strcpy (_my_tls.locals.mnt_type, mntinfo.fsname ());
 
Index: mount.h
===================================================================
RCS file: /cvs/src/src/winsup/cygwin/mount.h,v
retrieving revision 1.13
diff -u -r1.13 mount.h
--- mount.h	26 Apr 2010 13:48:03 -0000	1.13
+++ mount.h	9 Aug 2010 05:00:17 -0000
@@ -32,6 +32,11 @@
   max_fs_type
 };
 
+extern struct fs_names_t {
+    const char *name;
+    bool block_device;
+} fs_names[];
+
 #define IMPLEMENT_FS_FLAG(func, flag) \
   bool func (bool val) { if (val) status.fs_type = flag; return val; } \
   bool func () const   { return status.fs_type == flag; }

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]