mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] - 2.5.67 - proc interface to ramdisk driver.
@ 2003-04-08 16:11 Krishnakumar. R
  2003-04-08 16:49 ` Christoph Hellwig
  0 siblings, 1 reply; 2+ messages in thread
From: Krishnakumar. R @ 2003-04-08 16:11 UTC (permalink / raw)
  To: Linus Torvalds; +Cc: page0588, alan, linux-kernel

Hi,

The following patch will provide a 
proc interface to the ramdisk driver. 

Using this interface the size of the 
ramdisk can be changed at runtime.

Without the patch changing this size 
requires a recompilation of the kernel
or rebooting to enter as boot parameter.

Patch specification: -
Interface location : /proc/ramdisk_size
Operations possible:
1. read  
   eg: cat /proc/ramdisk_size
   will give the current ramdisk size.
2. write
   eg: echo "8000" > /proc/ramdisk_size
   will change the ramdisk size to 8000.

Regards and Thanks
KK


The patch was created using command: "diff  -urN"

--- drivers/block/rd.c.orig	Tue Apr  8 19:46:44 2003
+++ drivers/block/rd.c	Tue Apr  8 21:26:03 2003
@@ -56,6 +56,10 @@
 #include <linux/blkpg.h>
 #include <asm/uaccess.h>
 
+#ifdef CONFIG_PROC_FS
+#include <linux/proc_fs.h>
+#endif
+
 /* The RAM disk size is now a parameter */
 #define NUM_RAMDISKS 16		/* This cannot be overridden (yet) */ 
 
@@ -356,6 +360,70 @@
 	.ioctl =	rd_ioctl,
 };
 
+
+#ifdef CONFIG_PROC_FS
+/* The Call back functions for the proc interface  */
+
+static struct proc_dir_entry *rd_sz;
+
+static int rd_proc_read(char *page, char **start, off_t off,
+			int count, int *eof, void *data)
+{
+
+	int len;
+	len = sprintf(page, "%d\n", rd_size);
+       	return len;
+}
+
+#define MAX_RDSTR_LEN 5
+static char rd_buf[MAX_RDSTR_LEN+1];
+
+static int rd_proc_write(struct file *file, const char *buf,
+			 unsigned long count, void *data)
+
+{
+	int len = 0, i = 0;
+	int temp = 0;
+	
+	for (i = 0; i < NUM_RAMDISKS; i++) {
+		struct block_device *bdev = rd_bdev[i];
+		if (bdev != NULL ) {
+			down (&bdev->bd_sem);
+			if ( bdev->bd_openers > 1 ){
+				up (&bdev->bd_sem);
+				return -EBUSY;
+			}
+			up (&bdev->bd_sem);
+		}
+	}	
+	if (len>MAX_RDSTR_LEN)
+		len = MAX_RDSTR_LEN;
+	else 
+		len = count;
+	
+	if (copy_from_user(rd_buf, buf, len)){
+		return -EFAULT;
+	}
+	temp = simple_strtol(rd_buf,NULL,0);
+	/* If the size is negative dont do anything */
+	if (temp < 0 ) return len;
+
+	rd_size = temp;	
+	/* Update the ramdisk capacity */
+	for (i = 0; i < NUM_RAMDISKS; i++) {
+		struct gendisk *disk = rd_disks[i];
+		struct block_device *bdev = rd_bdev[i];
+		set_capacity(disk, rd_size * 2);
+		if (bdev != NULL ) {
+			down (&bdev->bd_sem);
+			bdev->bd_inode->i_size = get_capacity(rd_disks[i])<<9;
+			up (&bdev->bd_sem);
+		}
+	}	
+	return len;
+}
+#endif
+
 /* Before freeing the module, invalidate all of the protected buffers! */
 static void __exit rd_cleanup (void)
 {
@@ -451,6 +519,17 @@
 	       "%d RAM disks of %dK size %d blocksize\n",
 	       NUM_RAMDISKS, rd_size, rd_blocksize);
 
+	
+#ifdef CONFIG_PROC_FS
+/* The entry would be created at /proc/ramdisk_size */	
+	rd_sz = create_proc_entry("ramdisk_size", 0644, NULL); 
+	if (rd_sz != NULL) {
+		rd_sz->read_proc  = rd_proc_read;
+		rd_sz->write_proc = rd_proc_write;
+	} else {
+		printk("RAMDISK: proc entry could not be created\n");
+	}	
+#endif
 	return 0;
 out:
 	while (i--)




^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] - 2.5.67 - proc interface to ramdisk driver.
  2003-04-08 16:11 [PATCH] - 2.5.67 - proc interface to ramdisk driver Krishnakumar. R
@ 2003-04-08 16:49 ` Christoph Hellwig
  0 siblings, 0 replies; 2+ messages in thread
From: Christoph Hellwig @ 2003-04-08 16:49 UTC (permalink / raw)
  To: Krishnakumar. R; +Cc: Linus Torvalds, page0588, alan, linux-kernel

On Tue, Apr 08, 2003 at 09:41:46PM +0530, Krishnakumar. R wrote:
> Hi,
> 
> The following patch will provide a 
> proc interface to the ramdisk driver. 
> 
> Using this interface the size of the 
> ramdisk can be changed at runtime.

I think you really want a sysfs interface instead.  Maybe Rusty could
submit the patch to actually implement the sysfs acess to his new module
parameter stuff as promised and you'd get it almost for free :)



^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2003-04-08 16:37 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-04-08 16:11 [PATCH] - 2.5.67 - proc interface to ramdisk driver Krishnakumar. R
2003-04-08 16:49 ` Christoph Hellwig

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®