#include <asm/system.h>
#include <asm/uaccess.h>
@@ -93,6 +94,7 @@
/* Various static variables go here. Most are used only in the RAM disk code.
*/
+static char *rd_memory[NUM_RAMDISKS]; /* where the data is kept */
static unsigned long rd_length[NUM_RAMDISKS]; /* Size of RAM disks in bytes */
static int rd_hardsec[NUM_RAMDISKS]; /* Size of real blocks in bytes */
static int rd_blocksizes[NUM_RAMDISKS]; /* Size of 1024 byte blocks :) */
@@ -210,17 +212,10 @@
goto repeat;
}
- /*
- * If we're reading, fill the buffer with 0's. This is okay since
- * we're using protected buffers which should never get freed...
- *
- * If we're writing, we protect the buffer.
- */
-
if (CURRENT->cmd == READ)
- memset(CURRENT->buffer, 0, len);
+ memcpy(CURRENT->buffer, rd_memory[minor] + offset, len);
else
- set_bit(BH_Protected, &CURRENT->bh->b_state);
+ memcpy(rd_memory[minor] + offset, CURRENT->buffer, len);
end_request(1);
goto repeat;
@@ -237,7 +232,8 @@
switch (cmd) {
case BLKFLSBUF:
- if (!capable(CAP_SYS_ADMIN)) return -EACCES;
+ if (!capable(CAP_SYS_ADMIN))
+ return -EACCES;
invalidate_buffers(inode->i_rdev);
break;
@@ -304,8 +300,10 @@
static int rd_open(struct inode * inode, struct file * filp)
{
+ int minor = DEVICE_NR(inode->i_rdev);
+
#ifdef CONFIG_BLK_DEV_INITRD
- if (DEVICE_NR(inode->i_rdev) == INITRD_MINOR) {
+ if (minor == INITRD_MINOR) {
if (!initrd_start) return -ENODEV;
initrd_users++;
filp->f_op = &initrd_fops;
@@ -313,11 +311,21 @@
}
#endif
- if (DEVICE_NR(inode->i_rdev) >= NUM_RAMDISKS)
+ if (minor >= NUM_RAMDISKS)
return -ENXIO;
- for (i = 0 ; i < NUM_RAMDISKS; i++)
+ for (i = 0; i < NUM_RAMDISKS; i++) {
+ if (rd_memory[i] != NULL)
+ vfree(rd_memory[i]);
invalidate_buffers(MKDEV(MAJOR_NR, i));
-
+ }
unregister_blkdev( MAJOR_NR, "ramdisk" );
blk_cleanup_queue(BLK_DEFAULT_QUEUE(MAJOR_NR));
}
@@ -356,16 +366,16 @@
/* This is the registration and initialization section of the RAM disk driver */
int __init rd_init (void)
{
- int i;
+ int i;