# Which numbers does fdisk show?

I have run `sudo fdisk -l` and have got the following information:

``````Disk /dev/sda: 120.0 GB, 120034123776 bytes
255 heads, 63 sectors/track, 14593 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
``````

This utility shows the whole size of the hard disk (`120034123776 bytes`) and its number of heads (`255 heads`), sectors per track (`63 sectors/track`) and number of cylinders (`14593 cylinders`).

Multiplying heads X sectors per track X number of cylinders we must have number of sectors in the disk.

``````255 X 63 X 14593 = 234436545
``````

Having in mind that every sector is of size 512 bytes, we have

``````234436545 X 512 = 120031511040
``````

In fact, `120031511040 != 120034123776`, therefore, the question is: does fdisk shows incorrect information or there is something that I have missed in my calculations?

-

I'd say the use of `cylinder` is now deprecated and used mainly for historical reasons.

By looking at the `fdisk` source code it seems to me that the total number of bytes of a device is retrieved via an ioctl call

``````    if (ioctl(fd, BLKGETSIZE64, bytes) >= 0)
return 0;
``````

and the other figures are then derived from this.

For instance the number of cylinders is calculated using

``````llcyls = total_number_of_sectors / (heads * sectors * sector_factor);
``````

The "problem" here is that the result of this division is truncated (rounded down), so it is bound to be imprecise.

Using your `fdisk` output as an example

``````120034123776 bytes / 512 bytes_per_sector / 255 / 63 = 14593.3176471 cylinders
``````

but the `fdisk` output will round this down to `14593`.

-
+1 that's very nice answer! I like your idea to look in the source code. Could you please tell which version of the fdisk have you looked at? – Tim Feb 12 '11 at 19:38
Yes, it is `util-linux-ng-2.17.2`, see f.e. packages.ubuntu.com/maverick/util-linux – arrange Feb 12 '11 at 19:45

Hmmm, as far as I see the difference is marginal, so it can be caused by the different meaning of "kilo", "mega" and "giga" (prefixes) in the IT world and the SI: in normal life eg "kilo" means 1000, while in IT the common habit was 1024. Now the confusion is even bigger, since there is propose (even in ubuntu) to use 1000 as kilo, and use "kibi" (or whatever ....) for 1024 if needed. So by using these prefixes someone means 1000, others 1024, and to be even more complicated, in case of HDDs things are even mixed, that some of the prefixes are power of 2, some of them are power of 10.

It's a bit complicated/confusing situation on other OSes too ...

-
@LGB: thanks for the answer, I am aware of SI binary prefixes, however in my case the measurement unit is byte and bytes are the same in SI and in JEDEC terminology, therefore, it can't influence the answer, can it? – Tim Feb 12 '11 at 16:48
Hmm, I've reread the question and my answer, maybe there can be something other here too, but fdisk interals should be known to judge: I don't know about the first line, is it calculated by fdisk from the capacity read from disk, /proc interface etc etc, or the opposite, then it can be some rounding error. Anyway it's still possible that modern drives reports different CHS geometry than the "real" one (anyway people uses LBA nowdays) so translating the real CHS of the drive into the "virtual" one may cause rounding problems at even the hw interface level? Just guessing .... – LGB Feb 12 '11 at 16:52
@LGB: Probably it makes sense to ask authors, but obviously if the numbers are different there must be some reason behind it, I don't believe that it is simply an error. – Tim Feb 12 '11 at 17:01
Btw, what does the kernel say about that drive, like in output of `dmesg` command? – LGB Feb 12 '11 at 17:02
It says [ 1.632660] sd 2:0:0:0: [sda] 234441648 512-byte logical blocks: (120 GB/111 GiB), i.e. the size is the same as fdisk shows. Could that be that there is some reserved space in the disk? If so what it is used for? – Tim Feb 12 '11 at 17:20