This is the mail archive of the
cygwin-patches
mailing list for the Cygwin project.
[PATCH] implement /proc/swaps
- From: "Yaakov (Cygwin/X)" <yselkowitz at users dot sourceforge dot net>
- To: cygwin-patches <cygwin-patches at cygwin dot com>
- Date: Sun, 10 Apr 2011 20:59:56 -0500
- Subject: [PATCH] implement /proc/swaps
This patch implements /proc/swaps, as found on Linux[1]:
$ cat /proc/swaps
Filename Type Size Used Priority
/cygdrive/c/pagefile.sys file 4192440 16376 0
/cygdrive/d/pagefile.sys file 4192440 14208 0
(The first line is tab-delineated, the following lines use spaces.)
If there is no paging file on the system (a legal but discouraged
configuration), then only the header line is displayed.
According to Microsoft[2], there's no simple way to set or determine
which paging file will be used at any given time. Therefore I list all
paging files with priority 0.
Patches for winsup/cygwin and winsup/doc attached.
Yaakov
[1] http://docs.redhat.com/docs/en-US/Red_Hat_Enterprise_Linux/6/html/Deployment_Guide/s2-proc-swaps.html
[2] http://support.microsoft.com/kb/314482
2011-04-10 Yaakov Selkowitz <yselkowitz@users.sourceforge.net>
* new-features.sgml (ov-new1.7.10): Document /proc/swaps.
Index: new-features.sgml
===================================================================
RCS file: /cvs/src/src/winsup/doc/new-features.sgml,v
retrieving revision 1.73
diff -u -r1.73 new-features.sgml
--- new-features.sgml 4 Apr 2011 12:25:37 -0000 1.73
+++ new-features.sgml 11 Apr 2011 01:16:27 -0000
@@ -19,6 +19,10 @@
</para></listitem>
<listitem><para>
+Added /proc/swaps, which shows the location and size of Windows paging file(s).
+</para></listitem>
+
+<listitem><para>
Added /proc/sysvipc/msg, /proc/sysvipc/sem, and /proc/sysvipc/shm which
provide information about System V IPC message queues, semaphores, and
shared memory.
2011-04-10 Yaakov Selkowitz <yselkowitz@users.sourceforge.net>
* fhandler_proc.cc (proc_tab): Add /proc/swaps virtual file.
(format_proc_swaps): New function.
Index: fhandler_proc.cc
===================================================================
RCS file: /cvs/src/src/winsup/cygwin/fhandler_proc.cc,v
retrieving revision 1.100
diff -u -r1.100 fhandler_proc.cc
--- fhandler_proc.cc 4 Apr 2011 12:23:35 -0000 1.100
+++ fhandler_proc.cc 11 Apr 2011 01:11:57 -0000
@@ -12,6 +12,7 @@
#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_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 @@
{ _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 @@
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