diff options
author | Yaakov Selkowitz <yselkowi@redhat.com> | 2011-04-11 02:09:43 +0000 |
---|---|---|
committer | Yaakov Selkowitz <yselkowi@redhat.com> | 2011-04-11 02:09:43 +0000 |
commit | 5f6d028db254ef3fb6584306b47e4b8637048342 (patch) | |
tree | 042ad3f6461c3df25e55b6c129a999491aeefced /winsup/cygwin/fhandler_proc.cc | |
parent | 30a4f5b6969c510db84eb3319fe6af8331076911 (diff) | |
download | cygnal-5f6d028db254ef3fb6584306b47e4b8637048342.tar.gz cygnal-5f6d028db254ef3fb6584306b47e4b8637048342.tar.bz2 cygnal-5f6d028db254ef3fb6584306b47e4b8637048342.zip |
* fhandler_proc.cc (proc_tab): Add /proc/swaps virtual file.
(format_proc_swaps): New function.
Diffstat (limited to 'winsup/cygwin/fhandler_proc.cc')
-rw-r--r-- | winsup/cygwin/fhandler_proc.cc | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/winsup/cygwin/fhandler_proc.cc b/winsup/cygwin/fhandler_proc.cc index 86cafba46..acf3cf552 100644 --- a/winsup/cygwin/fhandler_proc.cc +++ b/winsup/cygwin/fhandler_proc.cc @@ -12,6 +12,7 @@ details. */ #include "miscfuncs.h" #include <unistd.h> #include <stdlib.h> +#include <stdio.h> #include "cygerrno.h" #include "security.h" #include "path.h" @@ -43,6 +44,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 *&); +static _off64_t format_proc_swaps (void *, char *&); /* names of objects in /proc */ static const virt_tab_t proc_tab[] = { @@ -60,6 +62,7 @@ static const virt_tab_t proc_tab[] = { { _VN ("registry64"), FH_REGISTRY, virt_directory, NULL }, { _VN ("self"), FH_PROC, virt_symlink, format_proc_self }, { _VN ("stat"), FH_PROC, virt_file, format_proc_stat }, + { _VN ("swaps"), FH_PROC, virt_file, format_proc_swaps }, { _VN ("sys"), FH_PROCSYS, virt_directory, NULL }, { _VN ("sysvipc"), FH_PROCSYSVIPC, virt_directory, NULL }, { _VN ("uptime"), FH_PROC, virt_file, format_proc_uptime }, @@ -1301,4 +1304,64 @@ format_proc_filesystems (void *, char *&destbuf) return bufptr - buf; } +static _off64_t +format_proc_swaps (void *, char *&destbuf) +{ + unsigned long total = 0UL, used = 0UL; + char *filename = NULL; + ssize_t filename_len; + PSYSTEM_PAGEFILE_INFORMATION spi = NULL; + ULONG size = 512; + NTSTATUS ret = STATUS_SUCCESS; + + tmp_pathbuf tp; + char *buf = tp.c_get (); + char *bufptr = buf; + + spi = (PSYSTEM_PAGEFILE_INFORMATION) malloc (size); + if (spi) + { + ret = NtQuerySystemInformation (SystemPagefileInformation, (PVOID) spi, + size, &size); + if (ret == STATUS_INFO_LENGTH_MISMATCH) + { + free (spi); + spi = (PSYSTEM_PAGEFILE_INFORMATION) malloc (size); + if (spi) + ret = NtQuerySystemInformation (SystemPagefileInformation, + (PVOID) spi, size, &size); + } + } + + bufptr += __small_sprintf (bufptr, + "Filename\t\t\t\tType\t\tSize\tUsed\tPriority\n"); + + if (spi && !ret && GetLastError () != ERROR_PROC_NOT_FOUND) + { + PSYSTEM_PAGEFILE_INFORMATION spp = spi; + do + { + total = spp->CurrentSize * getsystempagesize (); + used = spp->TotalUsed * getsystempagesize (); + + filename_len = cygwin_conv_path (CCP_WIN_W_TO_POSIX, spp->FileName.Buffer, filename, 0); + filename = (char *) malloc (filename_len); + cygwin_conv_path (CCP_WIN_W_TO_POSIX, spp->FileName.Buffer, filename, filename_len); + + bufptr += sprintf (bufptr, "%-40s%-16s%-8ld%-8ld%-8d\n", + filename, "file", total >> 10, used >> 10, 0); + } + while (spp->NextEntryOffset + && (spp = (PSYSTEM_PAGEFILE_INFORMATION) + ((char *) spp + spp->NextEntryOffset))); + } + + if (spi) + free (spi); + + destbuf = (char *) crealloc_abort (destbuf, bufptr - buf); + memcpy (destbuf, buf, bufptr - buf); + return bufptr - buf; +} + #undef print |