Author: mladen.turk(a)jboss.com
Date: 2007-09-13 06:32:37 -0400 (Thu, 13 Sep 2007)
New Revision: 1027
Modified:
trunk/sight/java/org/jboss/sight/FileSystemType.java
trunk/sight/native/include/sight_types.h
trunk/sight/native/os/linux/volume.c
trunk/sight/native/share/jnu.c
Log:
Add SWAP filesystem detection
Modified: trunk/sight/java/org/jboss/sight/FileSystemType.java
===================================================================
--- trunk/sight/java/org/jboss/sight/FileSystemType.java 2007-09-13 07:34:56 UTC (rev
1026)
+++ trunk/sight/java/org/jboss/sight/FileSystemType.java 2007-09-13 10:32:37 UTC (rev
1027)
@@ -87,9 +87,13 @@
USBFS( 24),
/** VMware guest filesystem */
VMHGFS( 25),
+ /** VMware VMCI filesystem */
+ VMBLOCK( 26),
+ /** Swap filesystem */
+ SWAP( 27),
/** File system is mounted to nothing */
- NONE( 26);
+ NONE( 99);
private int value;
private FileSystemType(int v)
Modified: trunk/sight/native/include/sight_types.h
===================================================================
--- trunk/sight/native/include/sight_types.h 2007-09-13 07:34:56 UTC (rev 1026)
+++ trunk/sight/native/include/sight_types.h 2007-09-13 10:32:37 UTC (rev 1027)
@@ -172,7 +172,9 @@
#define SIGHT_FS_RPC 23
#define SIGHT_FS_USBFS 24
#define SIGHT_FS_VMHGFS 25
-#define SIGHT_FS_NONE 26
+#define SIGHT_FS_VMBLOCK 26
+#define SIGHT_FS_SWAP 27
+#define SIGHT_FS_NONE 99
#define SIGHT_CASE_SENSITIVE_SEARCH 0x00000001
#define SIGHT_CASE_PRESERVED_NAMES 0x00000002
Modified: trunk/sight/native/os/linux/volume.c
===================================================================
--- trunk/sight/native/os/linux/volume.c 2007-09-13 07:34:56 UTC (rev 1026)
+++ trunk/sight/native/os/linux/volume.c 2007-09-13 10:32:37 UTC (rev 1027)
@@ -144,9 +144,13 @@
sight_unload_class(_E, &_clazzn);
}
+#define PROC_SWAPS_FS "/proc/swaps"
+
typedef struct volume_enum_t {
- int num_mounts;
- FILE *fp;
+ int num_mounts;
+ FILE *fp;
+ sight_arr_t *swaps;
+ int swap_idx;
} volume_enum_t;
/* Initialize volume enumeration */
@@ -186,6 +190,13 @@
}
endmntent(e->fp);
e->fp = setmntent(MOUNTED, "r");
+ /* Now read the swaps */
+ if ((e->swaps = sight_arr_rload(PROC_SWAPS_FS))) {
+ if (e->swaps->siz) {
+ e->num_mounts += (e->swaps->siz - 1);
+ e->swap_idx = 1;
+ }
+ }
return e->num_mounts;
}
}
@@ -203,6 +214,28 @@
if (!e || !thiz)
return;
+ if (e->swaps && e->swap_idx < e->swaps->siz) {
+ char path[256];
+ char type[32];
+ unsigned long size, used;
+ int priority;
+
+ if (sscanf(e->swaps->arr.ca[e->swap_idx],
+ "%250s %30s %lu %lu %d",
+ path, type, &size, &used, &priority) == 5) {
+ SET_IFIELD_S(0000, thiz, path);
+ SET_IFIELD_S(0001, thiz, type);
+ SET_IFIELD_S(0002, thiz, "swap");
+ CALL_METHOD1(0000, thiz, SIGHT_FS_SWAP);
+ CALL_METHOD1(0001, thiz, SIGHT_READ_WRITE_VOLUME);
+ CALL_METHOD1(0002, thiz, SIGHT_DRIVE_SWAP);
+ SET_IFIELD_J(0005, thiz, size - used);
+ SET_IFIELD_J(0006, thiz, size);
+ SET_IFIELD_J(0007, thiz, size - used);
+ }
+ e->swap_idx++;
+ return;
+ }
if (getmntent_r(e->fp, &ent, buf, SIGHT_MBUFFER_LEN)) {
int flags = 0;
int dtype = sight_get_fs_type(ent.mnt_type);
@@ -234,15 +267,20 @@
case SIGHT_FS_PROC:
case SIGHT_FS_SYSFS:
case SIGHT_FS_TMPFS:
+ case SIGHT_FS_RAMFS:
CALL_METHOD1(0002, thiz, SIGHT_DRIVE_RAMDISK);
break;
case SIGHT_FS_NFS:
case SIGHT_FS_RPC:
+ case SIGHT_FS_VMBLOCK:
CALL_METHOD1(0002, thiz, SIGHT_DRIVE_REMOTE);
break;
case SIGHT_FS_USBFS:
CALL_METHOD1(0002, thiz, SIGHT_DRIVE_REMOVABLE);
break;
+ case SIGHT_FS_SWAP:
+ CALL_METHOD1(0002, thiz, SIGHT_DRIVE_SWAP);
+ break;
default:
CALL_METHOD1(0002, thiz, SIGHT_DRIVE_FIXED);
break;
@@ -268,6 +306,8 @@
if (e) {
if (e->fp)
endmntent(e->fp);
+ if (e->swaps)
+ sight_arr_free(e->swaps);
free(e);
}
}
Modified: trunk/sight/native/share/jnu.c
===================================================================
--- trunk/sight/native/share/jnu.c 2007-09-13 07:34:56 UTC (rev 1026)
+++ trunk/sight/native/share/jnu.c 2007-09-13 10:32:37 UTC (rev 1027)
@@ -501,6 +501,8 @@
return SIGHT_FS_VFAT;
if (memcmp(p, "MHGFS", 5) == 0)
return SIGHT_FS_VMHGFS;
+ if (memcmp(p, "MBLOCK", 6) == 0)
+ return SIGHT_FS_VMBLOCK;
else
return SIGHT_FS_UNKNOWN;
break;