0

I'm going to write a disk partition creator program for flash memory removable devices, mostly controlled by SCSI based I/O and accessed with LBA address.

For reference, I'm researching the partition table on the SD cards that were partitioned and formatted by the disk utility of Ubuntu.

I used the 'unit' command of 'parted' software in Linux to watch the parameters of the cards with CHS unit and byte unit.

The following is for a 8GB sd card with 15122432 sectors of LBA:

pi@raspberrypi:~ $ sudo parted /dev/sda
GNU Parted 3.2
Using /dev/sda
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) unit chs print
Model: Generic CRM01 SD Reader (scsi)
Disk /dev/sda: 1020,130,11
Sector size (logical/physical): 512B/512B
BIOS cylinder,head,sector geometry: 1020,239,62.  Each cylinder is 7587kB.
Partition Table: msdos
Disk Flags:

Number  Start  End          Type     File system  Flags
 1      0,1,0  1019,238,61  primary  ext3

(parted) unit b print
Model: Generic CRM01 SD Reader (scsi)
Disk /dev/sda: 7742685184B
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags:

Number  Start   End          Size         Type     File system  Flags
 1      31744B  7738552319B  7738520576B  primary  ext3

The following is for a 4GB sd card with 7585792 sectors of LBA:

(parted) unit chs print
Model: Generic CRM01 SD Reader (scsi)
Disk /dev/sda: 1019,71,29
Sector size (logical/physical): 512B/512B
BIOS cylinder,head,sector geometry: 1019,120,62.  Each cylinder is 3809kB.
Partition Table: msdos
Disk Flags:

Number  Start  End          Type     File system  Flags
 1      0,1,0  1018,119,61  primary  ext3

(parted) unit b print
Model: Generic CRM01 SD Reader (scsi)
Disk /dev/sda: 3883925504B
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags:

Number  Start   End          Size         Type     File system  Flags
 1      31744B  3881656319B  3881624576B  primary  ext3

From my observation, the disk geometry values (C/H/S) are different on different capacity SD card, and the geometry values are seem associated with the end CHS address of the end of the partition. It is seems like..

The card with the partition which end CHS tuple is (c, h, s), which disk geometry will be (c + 1 / h + 1 / s + 1). Are they related?

But how the values are determined? Does those depend on OS or file system?

1
  • The SD card firmware reports them. It's whatever the writers of the SD card firmware decided to be convenient. – dirkt Aug 10 '17 at 5:49
3

In the 1980s, the BIOS in a PC needed to know the geometry of a hard disk in order to operate it properly. Users had to enter the correct number of cylinders, heads and sectors.

At some point (with the introduction of the IDE interface? My memory is rather fuzzy on this topic), disks became capable of reporting their geometry to the computer.

By the early to mid-1990s, disk firmware managed the disk geometry on its own. The BIOS still needed to have a value for C/H/S, because it used that to calculate the disk size. But the breakdown into C/H/S value could be arbitrary. So disks reported values of C/H/S that had nothing to do with the disk's actual geometry but fitted the allowed range and gave the correct total size.

A storage medium to which the concept of cylinders and heads doesn't apply would likewise make up some value that resulted in the correct total size.

1
  • IIRC the reporting feature dates back to ATA-2 (aka EIDE, more or less). – Stephen Kitt Aug 11 '17 at 15:59
0

I might have solved my problem. What I confused is how does the partition program decide the geometry of a device when it making partition tables. But after some experiments, I found that there is no fixed geometric for a flash memory device (actually it does not have a physical disk), a partition program can decide the header number and the sectors per track by itself, then use the customized geometric to calculate the partition's start CHS and end CHS in the partition table. No matter how the geometry be, OS can find the boundary of the partition by the given CHS information.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.