* fhandler_proc.cc (proc_tab): Add /proc/swaps virtual file.

(format_proc_swaps): New function.
This commit is contained in:
Yaakov Selkowitz 2011-04-11 02:09:43 +00:00
parent 30a4f5b696
commit 5f6d028db2
2 changed files with 68 additions and 0 deletions

View File

@ -1,3 +1,8 @@
2011-04-10 Yaakov Selkowitz <yselkowitz@users.sourceforge.net>
* fhandler_proc.cc (proc_tab): Add /proc/swaps virtual file.
(format_proc_swaps): New function.
2011-04-06 Yaakov Selkowitz <yselkowitz@users.sourceforge.net>
* Makefile.in: Move srcdir definition before others which uses it.

View File

@ -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