[PATCH] Ramdisk ioctl bug fix, kernel 2.4.14

Malcolm H. Teas (mhteas@btech.com)
Mon, 12 Nov 2001 20:39:22 -0600


The patch below makes the ramdisk return the actual size that is currently
allocated instead of returning the max size we can possibly allocate. Affects
system calls ioctl(filedes, BLKGETSIZE) and ioctl(filedes, BLKGETSIZE64) for
ramdisk devices.

Malcolm Teas
mhteas@btech.com
http://www.btech.com
Austin, TX USA

--- linux-2.4.14/drivers/block/rd.c Thu Oct 25 15:58:35 2001
+++ linux/drivers/block/rd.c Mon Nov 12 20:15:16 2001
@@ -40,6 +40,9 @@
*
* Make block size and block size shift for RAM disks a global macro
* and set blk_size for -ENOSPC, Werner Fink <werner@suse.de>, Apr '99
+ *
+ * Make BLKGETSIZE and BLKGETSIZE64 return the actual allocated size, not
+ * the max possible allocated size - Malcolm Teas Nov 2001
*/

#include <linux/config.h>
@@ -349,6 +352,7 @@
{
int error = -EINVAL;
unsigned int minor;
+
unsigned long size;

if (!inode || !inode->i_rdev)
goto out;
@@ -373,10 +377,12 @@
case BLKGETSIZE: /* Return device size */

if (!arg)

break;
-
error = put_user(rd_kbsize[minor] << 1, (unsigned long *) arg);
+
size = (rd_bdev[minor]->bd_inode->i_mapping->nrpages * PAGE_SIZE) >> 9;
+
error = put_user(size, (unsigned long *) arg);

break;
case BLKGETSIZE64:
-
error = put_user((u64)rd_kbsize[minor]<<10, (u64*)arg);
+
size = rd_bdev[minor]->bd_inode->i_mapping->nrpages;
+
error = put_user((u64) (size * PAGE_SIZE), (u64*)arg);

break;
case BLKROSET:
case BLKROGET:

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/