BLKGETSIZE64 (bytes or sectors?)
[email protected] wrote, and he is right:
Quoted 3 lines
Is the BLKGETSIZE64 ioctl supposed to return the size of the device in bytes (as the comment says, and is implemented in all places *except*
blkpg.c), or in sectors (as is implemented inblkpg.csince 2.4.15)?
Yes, in bytes. blkpg.c has to be fixed.
Several people submitted patches. Sooner or later I suppose this will be fixed.
Then Tim Pepper answered, and he is wrong:
Wouldn't it be better to do the following (against 2.4.17).
+ else {
+ if (hardsect_size[MAJOR(dev)][MINOR(dev)]) {
+ ullval *= hardsect_size[MAJOR(dev)][MINOR(dev)];
+ } else {
+ ullval *= 512;
+ }
return put_user(ullval, (u64 *)arg);
+ }
You see, the 512 here is 512, and has no relation to hardware sector size. Multiplying with hardsect_size[][] is a bad bug.
Indeed, you can check this in fs/partitions/msdos.c, where one reads
int sector_size = get_hardsect_size(to_kdev_t(bdev->bd_dev)) / 512; ... offs = START_SECT(p)*sector_size; size = NR_SECTS(p)*sector_size; ... add_gd_partition(...);
So, indeed, we have already multiplied by hardsect_size, struct gendisk uses sectors of size 512, independent of the hardware, and we must not again multiply by hardsect_size.
Unfortunately Matt Domsch replied:
Quoted 1 line
Yes, I agree.
but he meant: No!
Andries
Quoted 11 lines · On Thu 17 Jan at 23:48:16 +0000 [email protected] done said:
[email protected] wrote, and he is right:
Yes, in bytes.
blkpg.chas to be fixed.
Several people submitted patches. Sooner or later I suppose this will be fixed.--8< snip-----------
So, indeed, we have already multiplied by
hardsect_size, struct gendisk uses sectors of size 512, independent of the hardware, and we must not again multiply byhardsect_size.
Doh. It's obviously much cleaner and more efficient that way.
Have any of the other patch submitters added a comment to note this in include/linux/genhd.h? hd_struct doesn't have any mention of start_sect and nr_sect being stored in sectors of 512bytes. But maybe that's just to weed out fools like me.
Signature · 4 lines
********************************************************* * tpepper@vato dot org * Venimus, Vidimus, * * http://www.vato.org/~tpepper * Dolavimus * *********************************************************