3

Is the file located under:

/sys/block/<xxx>/size

Constantly referencing to 512 byte block count, or is there any special cases where the block count changes?

I'm curious because:

thinkpad :: /sys/block/sdf % cat queue/physical_block_size                                                                                                                         
4096
thinkpad :: /sys/block/sdf % cat queue/logical_block_size                                                                                                                          
4096
thinkpad :: /sys/block/sdf % cat size                                                                                                                                              
15408640

15408640 * 512 bytes / 1000000000 = ~8GB -> the size of my device, its correct but the device is a 4K block device.

3

The size entry returns the nr_sects field of the block device structure. Traditionally, in Unix disk size contexts, “sector” or “block” means 512 bytes, regardless of what the manufacturer of the underlying hardware might call a “sector” or “block”. I can't find authoritative documentation, but looking at the Linux source code (e.g. 1) 2) it looks like the nr_sects field is indeed expressed in units of 512 bytes.

You can approach it another way: since there is no file reporting the unit, it has to be a constant unit, otherwise applications wouldn't know what the value means. (The queue subdirectory is not necessarily present, it depends on the block device.)

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.