[patch] breada bug

From: Mikulas Patocka (mikulas@artax.karlin.mff.cuni.cz)
Date: Tue Feb 29 2000 - 05:10:20 EST


Hi.

This code in breada

        if (blocks < (read_ahead[MAJOR(dev)] >> index))
                blocks = read_ahead[MAJOR(dev)] >> index;

will increase number of block that are read ahead. However the code
doesn't check for end of device and so it can generate accesses beyond end
of device.

This is the patch (is there any better way to find number of blocks? what
if partitions had odd number of sectors?) The patch is for both 2.2 and
2.3.

Mikulas

--- linux/fs/buffer.c_ Tue Feb 29 00:29:18 2000
+++ linux/fs/buffer.c Tue Feb 29 01:11:07 2000
@@ -958,6 +958,15 @@
         if (blocks > NBUF)
                 blocks = NBUF;
 
+ if (blk_size[MAJOR(dev)]) {
+ unsigned int dev_size;
+ if (index < 1) dev_size = blk_size[MAJOR(dev)][MINOR(dev)] >> (1 - index);
+ else dev_size = blk_size[MAJOR(dev)][MINOR(dev)] << (index - 1);
+ if (block + blocks > dev_size)
+ if (dev_size > block) blocks = dev_size - block;
+ else blocks = 1;
+ }
+
 /* if (blocks) printk("breada (new) %d blocks\n",blocks); */
 
 

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



This archive was generated by hypermail 2b29 : Tue Feb 29 2000 - 21:00:22 EST