Hello,
I've got some algorithms on calculating CHS and LBA
but the formula seem to me strange and unreasonable.
The formula looks like this:
LBA = ( (cylinder * heads_per_cylinder + heads ) * sectors_per_track ) + sector - 1
cylinder = LBA / (heads_per_cylinder * sectors_per_track)
temp = LBA % (heads_per_cylinder * sectors_per_track)
head = temp / sectors_per_track
sector = temp % sectors_per_track + 1
-----------------------------------------
Can anyone describle maybe proof how each formula is derived?
And again, for the "%" thing, is there a way to write
like "x mod y"? General concepts are cool, too.
Thanks.
Ben Hsu
File System Maths
RE:File System Maths
>On 2001-03-28 18:45:43, Ben Hsu wrote:
>Hello,
>I've got some algorithms on calculating CHS and LBA
>but the formula seem to me strange and unreasonable.
>
>The formula looks like this:
>
>LBA = ( (cylinder * heads_per_cylinder + heads ) * sectors_per_track ) + sector - 1
>cylinder = LBA / (heads_per_cylinder * sectors_per_track)
>temp = LBA % (heads_per_cylinder * sectors_per_track)
>head = temp / sectors_per_track
>sector = temp % sectors_per_track + 1
>-----------------------------------------
>Can anyone describle maybe proof how each formula is derived?
>And again, for the "%" thing, is there a way to write
>like "x mod y"? General concepts are cool, too.
>Thanks.
>Ben Hsu
>
>
yes, it seems correct formula to me.
LBA is seeing disk as continuos array of sectors.
For CHS you should look disk in "3d" view:
there is multiple disks. 1 head reads one side of
one disk. so, for example, if there is 2 disks in
your hard disk, head 0 reads upper side of top
disk and head 3 down side of bottom disk. so
track consist of all sectors on one side (head)
and cylinder consist of same track on all sides.
so if like read continuosly all sectors as in LBA you read first all sectors on 0 track(cyl) 0 head,
then you go for sectors on 0 track, 1 head until
0 track last head and after that go for next cyl,
reading 1. track 0 head etc. Because in BIOS CHS
(cylinder, head, sector) cylinder and head
counting is 0 based and sectors 1 based (i don't
know why) is there at end of formula - 1 (LBA
starts counting from 0).
>Hello,
>I've got some algorithms on calculating CHS and LBA
>but the formula seem to me strange and unreasonable.
>
>The formula looks like this:
>
>LBA = ( (cylinder * heads_per_cylinder + heads ) * sectors_per_track ) + sector - 1
>cylinder = LBA / (heads_per_cylinder * sectors_per_track)
>temp = LBA % (heads_per_cylinder * sectors_per_track)
>head = temp / sectors_per_track
>sector = temp % sectors_per_track + 1
>-----------------------------------------
>Can anyone describle maybe proof how each formula is derived?
>And again, for the "%" thing, is there a way to write
>like "x mod y"? General concepts are cool, too.
>Thanks.
>Ben Hsu
>
>
yes, it seems correct formula to me.
LBA is seeing disk as continuos array of sectors.
For CHS you should look disk in "3d" view:
there is multiple disks. 1 head reads one side of
one disk. so, for example, if there is 2 disks in
your hard disk, head 0 reads upper side of top
disk and head 3 down side of bottom disk. so
track consist of all sectors on one side (head)
and cylinder consist of same track on all sides.
so if like read continuosly all sectors as in LBA you read first all sectors on 0 track(cyl) 0 head,
then you go for sectors on 0 track, 1 head until
0 track last head and after that go for next cyl,
reading 1. track 0 head etc. Because in BIOS CHS
(cylinder, head, sector) cylinder and head
counting is 0 based and sectors 1 based (i don't
know why) is there at end of formula - 1 (LBA
starts counting from 0).