lkml.org 
[lkml]   [1997]   [Jan]   [19]   [last100]   RSS Feed
Views: [more markup]  [less markup]  [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
DateSun, 19 Jan 1997 10:46:24 -0500 (EST)
FromIon Badulescu <>
SubjectRe: Swap Files
Hi everyone,

Okay, here is the second version of the /proc/swap[s] patch and swapoff
utility. Changes:

- /proc/swap renamed to /proc/swaps for consistency with /proc/mounts
(suggestion from Lars Wirzenius)
- swapoff now accepts an optional -t f[ile] | p[artition] (suggestion from
Gerd Knorr)
The whole package can be retrieved from

	ftp://moisil.wal.rhno.columbia.edu/pub/linux/mount-2.6a2.tar.gz

Patch follows...

Ionut

--
  It is better to keep your mouth shut and be thought a fool,
            than to open it and remove all doubt.

--- linux-2.0.28.vanilla/fs/proc/root.c.old	Tue Apr 30 06:09:45 1996
+++ linux/fs/proc/root.c	Sat Jan 18 16:36:16 1997
@@ -366,6 +366,9 @@
 	proc_register( &proc_root, &(struct proc_dir_entry)
 	   { PROC_MTAB, 6, "mounts", S_IFREG | S_IRUGO, 1, 0, 0, } );
 		   
+	proc_register( &proc_root, &(struct proc_dir_entry)
+	   { PROC_SWAP, 5, "swaps", S_IFREG | S_IRUGO, 1, 0, 0, } );
+		   
 	if (prof_shift) {
 		proc_register(&proc_root, &(struct proc_dir_entry) {
 			PROC_PROFILE, 7, "profile",
--- linux-2.0.28.vanilla/fs/proc/array.c.old	Tue Oct 29 20:42:41 1996
+++ linux/fs/proc/array.c	Sat Jan 18 17:04:34 1997
@@ -976,6 +976,7 @@
 extern int get_md_status (char *);
 extern int get_rtc_status (char *);
 extern int get_locks_status (char *);
+extern int get_swaparea_info (char *);
 #ifdef __SMP_PROF__
 extern int get_smp_prof_list(char *);
 #endif
@@ -1046,6 +1047,9 @@
 
                 case PROC_MTAB:
                        return get_filesystem_info( page );
+
+                case PROC_SWAP:
+                       return get_swaparea_info(page);
 #ifdef CONFIG_RTC
 		case PROC_RTC:
 			return get_rtc_status(page);
--- linux-2.0.28.vanilla/mm/swapfile.c.old	Sat Dec 14 07:24:31 1996
+++ linux/mm/swapfile.c	Sat Jan 18 16:10:34 1997
@@ -16,6 +16,7 @@
 #include <linux/swap.h>
 #include <linux/fs.h>
 #include <linux/swapctl.h>
+#include <linux/malloc.h>
 #include <linux/blkdev.h> /* for blk_size */
 
 #include <asm/dma.h>
@@ -387,6 +388,8 @@
 
 	nr_swap_pages -= p->pages;
 	iput(p->swap_file);
+	if (p->swap_filename)
+		kfree(p->swap_filename);
 	p->swap_file = NULL;
 	p->swap_device = 0;
 	vfree(p->swap_map);
@@ -397,6 +400,27 @@
 	return 0;
 }
 
+int get_swaparea_info(char *buf)
+{
+	struct swap_info_struct *ptr = swap_info;
+	int i, len = 0;
+
+	len += sprintf(buf, "Filename\t\tType\t\tSize\n");
+        for (i = 0 ; i < nr_swapfiles ; i++, ptr++)
+		if (ptr->flags & SWP_USED) {
+	                if (ptr->swap_filename)
+				len += sprintf(buf + len, "%s\t\t", ptr->swap_filename);
+			else
+				len += sprintf(buf + len, "(null)\t\t");
+			if (ptr->swap_file)
+				len += sprintf(buf + len, "file\t\t");
+			else
+				len += sprintf(buf + len, "partition\t");
+			len += sprintf(buf + len, "%d\n", ptr->pages << (PAGE_SHIFT - 10));
+		}
+	return len;
+}
+
 /*
  * Written 01/25/92 by Simmule Turner, heavily changed by Linus.
  *
@@ -409,6 +433,7 @@
 	unsigned int type;
 	int i, j, prev;
 	int error;
+	char *tmp;
 	struct file filp;
 	static int least_priority = 0;
 
@@ -424,6 +449,7 @@
 	if (type >= nr_swapfiles)
 		nr_swapfiles = type+1;
 	p->flags = SWP_USED;
+	p->swap_filename = NULL;
 	p->swap_file = NULL;
 	p->swap_device = 0;
 	p->swap_map = NULL;
@@ -530,6 +556,12 @@
 		prev = i;
 	}
 	p->next = i;
+        if (!getname(specialfile, &tmp)) {
+                if ((p->swap_filename =
+                    (char *) kmalloc(strlen(tmp)+1, GFP_KERNEL)) != (char *)NULL)
+                        strcpy(p->swap_filename, tmp);
+                putname(tmp);
+        }
 	if (prev < 0) {
 		swap_list.head = swap_list.next = p - swap_info;
 	} else {
--- linux-2.0.28.vanilla/include/linux/swap.h.old	Mon Jun  3 08:38:37 1996
+++ linux/include/linux/swap.h	Sat Jan 18 15:04:28 1997
@@ -19,6 +19,7 @@
 struct swap_info_struct {
 	unsigned int flags;
 	kdev_t swap_device;
+	char *swap_filename;
 	struct inode * swap_file;
 	unsigned char * swap_map;
 	unsigned char * swap_lockmap;
--- linux-2.0.28.vanilla/include/linux/proc_fs.h.old	Sun Dec  1 12:59:28 1996
+++ linux/include/linux/proc_fs.h	Sat Jan 18 18:24:17 1997
@@ -41,5 +41,6 @@
 	PROC_CMDLINE,
 	PROC_SYS,
 	PROC_MTAB,
+	PROC_SWAP,
 	PROC_MD,
 	PROC_RTC,

\
 
 \ /
  Last update: 2005-03-22 12:38    [from the cache]
©2003-2008