Re: Bug in block device read/write!

From: Andries Brouwer (aeb@veritas.com)
Date: Fri Sep 08 2000 - 14:26:56 EST


On Fri, Sep 08, 2000 at 03:41:27AM +0100, Anton Altaparmakov wrote:

> [kernel-2.4.0-test3 to kernel-2.4.0-test8-pre6, bug present in those two,
> didn't try others]
>
> I have been trying to get the linear md driver to work with NTFS volumes
> for several months and it never worked. - I was suspecting the NTFS driver
> (after having fixed linear md and verified that at least that worked fine)
> but today I finally found why it doesn't work:
>
> There is a bug in reading/writing to block devices. - It manifests itself
> in the form that partitions are too small by exactly one sector!
>
> Even though a cfdisk shows that a partition has a certain number of
> sectors, you can never seek + read and/or write to the last sector (doing
> file i/o using read/write(2) [also tried fread/fwrite(3), same result]. -
> Last sector doesn't seem to exist. However reading the actual hd (/dev/hdb
> or /dev/sda, ie. affects both IDE and SCSI) instead of the partition
> (/dev/hdb7 or whatever) the sector does exist and contains the expected
> information!

The size of a partition (as seen by fdisk) is a number of 512-byte sectors.
The size of a partition (as seen by the kernel, for reading and writing)
is a number of 1024-byte blocks. This number is 1 for an extended partition
(just enough to put LILO there) and number_of_sectors/2 otherwise.

[see fs/partitions/check.c:grok_partitions()
        dev->sizes[i] = dev->part[i].nr_sects >> (BLOCK_SIZE_BITS - 9);
]

Thus, indeed, if the number of sectors in the partition is odd
you are presently unable to read the last sector by accessing
the partition, but you can access it via the whole-disk device.

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



This archive was generated by hypermail 2b29 : Fri Sep 15 2000 - 21:00:11 EST