From 8c71dc5878ef96ba4c81652777d12fc53a5f403a Mon Sep 17 00:00:00 2001 From: Corinna Vinschen Date: Wed, 4 Feb 2009 16:40:04 +0000 Subject: [PATCH] * 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. --- winsup/cygwin/ChangeLog | 7 ++++ winsup/cygwin/fhandler_proc.cc | 9 +++++ winsup/cygwin/fhandler_process.cc | 66 +++++++++++++++++++++++++++++++ 3 files changed, 82 insertions(+) diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog index 382b77817..94edfa223 100644 --- a/winsup/cygwin/ChangeLog +++ b/winsup/cygwin/ChangeLog @@ -1,3 +1,10 @@ +2009-02-04 Corinna Vinschen + + * 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 * security.cc (alloc_sd): Disable generating default permission entries diff --git a/winsup/cygwin/fhandler_proc.cc b/winsup/cygwin/fhandler_proc.cc index eba39a349..4e516e58e 100644 --- a/winsup/cygwin/fhandler_proc.cc +++ b/winsup/cygwin/fhandler_proc.cc @@ -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 diff --git a/winsup/cygwin/fhandler_process.cc b/winsup/cygwin/fhandler_process.cc index 710fbe72d..fa8aff7c6 100644 --- a/winsup/cygwin/fhandler_process.cc +++ b/winsup/cygwin/fhandler_process.cc @@ -10,6 +10,7 @@ details. */ #include "winsup.h" #include +#include #include #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 #include @@ -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) {