OSDN Git Service

* fhandler_proc.cc (proc_tab): Add entry for mounts symlink.
authorcorinna <corinna>
Wed, 4 Feb 2009 16:40:04 +0000 (16:40 +0000)
committercorinna <corinna>
Wed, 4 Feb 2009 16:40:04 +0000 (16:40 +0000)
(format_proc_mounts): New function to implement mounts symlink.
* fhandler_process.cc (process_tab): Add entry for mounts file.
(format_process_mounts): New function to implement mounts file.

winsup/cygwin/ChangeLog
winsup/cygwin/fhandler_proc.cc
winsup/cygwin/fhandler_process.cc

index 382b778..94edfa2 100644 (file)
@@ -1,5 +1,12 @@
 2009-02-04  Corinna Vinschen  <corinna@vinschen.de>
 
+       * fhandler_proc.cc (proc_tab): Add entry for mounts symlink.
+       (format_proc_mounts): New function to implement mounts symlink.
+       * fhandler_process.cc (process_tab): Add entry for mounts file.
+       (format_process_mounts): New function to implement mounts file.
+
+2009-02-04  Corinna Vinschen  <corinna@vinschen.de>
+
        * security.cc (alloc_sd): Disable generating default permission entries
        for directories.
 
index eba39a3..4e516e5 100644 (file)
@@ -40,6 +40,7 @@ static _off64_t format_proc_uptime (void *, char *&);
 static _off64_t format_proc_cpuinfo (void *, char *&);
 static _off64_t format_proc_partitions (void *, char *&);
 static _off64_t format_proc_self (void *, char *&);
+static _off64_t format_proc_mounts (void *, char *&);
 
 /* names of objects in /proc */
 static const virt_tab_t proc_tab[] = {
@@ -54,6 +55,7 @@ static const virt_tab_t proc_tab[] = {
   { "cpuinfo",   FH_PROC,      virt_file,      format_proc_cpuinfo },
   { "partitions", FH_PROC,     virt_file,      format_proc_partitions },
   { "self",      FH_PROC,      virt_symlink,   format_proc_self },
+  { "mounts",    FH_PROC,      virt_symlink,   format_proc_mounts },
   { "registry32", FH_REGISTRY, virt_directory, NULL },
   { "registry64", FH_REGISTRY, virt_directory, NULL },
   { "net",       FH_PROCNET,   virt_directory, NULL },
@@ -1127,4 +1129,11 @@ format_proc_self (void *, char *&destbuf)
   return __small_sprintf (destbuf, "%d", getpid ());
 }
 
+static _off64_t
+format_proc_mounts (void *, char *&destbuf)
+{
+  destbuf = (char *) crealloc_abort (destbuf, sizeof ("self/mounts"));
+  return __small_sprintf (destbuf, "self/mounts");
+}
+
 #undef print
index 710fbe7..fa8aff7 100644 (file)
@@ -10,6 +10,7 @@ details. */
 
 #include "winsup.h"
 #include <stdlib.h>
+#include <stdio.h>
 #include <sys/cygwin.h>
 #include "cygerrno.h"
 #include "security.h"
@@ -22,6 +23,7 @@ details. */
 #include "cygheap.h"
 #include "ntdll.h"
 #include "cygtls.h"
+#include "pwdgrp.h"
 #include "tls_pbuf.h"
 #include <sys/param.h>
 #include <ctype.h>
@@ -47,6 +49,7 @@ static _off64_t format_process_sid (void *, char *&);
 static _off64_t format_process_gid (void *, char *&);
 static _off64_t format_process_ctty (void *, char *&);
 static _off64_t format_process_fd (void *, char *&);
+static _off64_t format_process_mounts (void *, char *&);
 
 static const virt_tab_t process_tab[] =
 {
@@ -70,6 +73,7 @@ static const virt_tab_t process_tab[] =
   { "root",       FH_PROCESS,   virt_symlink,   format_process_root },
   { "exe",        FH_PROCESS,   virt_symlink,   format_process_exename },
   { "cwd",        FH_PROCESS,   virt_symlink,   format_process_cwd },
+  { "mounts",     FH_PROCESS,   virt_file,      format_process_mounts },
   { NULL,         0,            virt_none,      NULL }
 };
 
@@ -876,6 +880,68 @@ format_process_statm (void *data, char *&destbuf)
                          vmsize, vmrss, vmshare, vmtext, vmlib, vmdata, 0);
 }
 
+extern "C" {
+  FILE *setmntent (const char *, const char *);
+  struct mntent *getmntent (FILE *);
+};
+
+static _off64_t
+format_process_mounts (void *data, char *&destbuf)
+{
+  _pinfo *p = (_pinfo *) data;
+  user_info *u_shared = NULL;
+  HANDLE u_hdl = NULL;
+  _off64_t len = 0;
+  struct mntent *mnt;
+
+  if (p->pid != myself->pid)
+    {
+      WCHAR sid_string[UNLEN + 1] = L""; /* Large enough for SID */
+      shared_locations sl = SH_JUSTOPEN;
+
+      cygsid p_sid;
+
+      if (!p_sid.getfrompw (internal_getpwuid (p->uid)))
+       return 0;
+      p_sid.string (sid_string);
+      u_shared = (user_info *) open_shared (sid_string, USER_VERSION, u_hdl,
+                                           sizeof (user_info), sl,
+                                           &sec_none_nih);
+      if (!u_shared)
+       return 0;
+    }
+  else
+    u_shared = user_shared;
+
+  /* Store old value of _my_tls.locals here. */
+  int iteration = _my_tls.locals.iteration;
+  unsigned available_drives = _my_tls.locals.available_drives;
+  /* This reinitializes the above values in _my_tls. */
+  setmntent (NULL, NULL);
+  while ((mnt = getmntent (NULL)))
+    {
+      destbuf = (char *) crealloc_abort (destbuf, len
+                                                 + strlen (mnt->mnt_fsname)
+                                                 + strlen (mnt->mnt_dir)
+                                                 + strlen (mnt->mnt_type)
+                                                 + strlen (mnt->mnt_opts)
+                                                 + 28);
+      len += __small_sprintf (destbuf + len, "%s %s %s %s %d %d\n",
+                             mnt->mnt_fsname, mnt->mnt_dir, mnt->mnt_type,
+                             mnt->mnt_opts, mnt->mnt_freq, mnt->mnt_passno);
+    }
+  /* Restore old value of _my_tls.locals here. */
+  _my_tls.locals.iteration = iteration;
+  _my_tls.locals.available_drives = available_drives;
+
+  if (u_hdl) /* Only not-NULL if open_shared has been called. */
+    {
+      UnmapViewOfFile (u_shared);
+      CloseHandle (u_hdl);
+    }
+  return len;
+}
+
 static int
 get_process_state (DWORD dwProcessId)
 {