0

My question is about the minimum data block size (cluster, number of sectors) that the OS use to communicate with the hard drive using ATA commands?

I know that the physical sector size is 512 Bytes AND

new hard drive have 4096 Bytes (4K) AND

the OS allocation unit (aka cluster) equals to 1 or more sectors.

Is the cluster size depend on the file system or the OS?

assuming the cluster size is (4096 Bytes, 8 physical sector) ==> Is it always enforced with ATA commands? that is, if an application issued an ATA READ SECTOR command to read 1 sector, does the OS enforce cluster size and request 8 sectors or request 1 sector?

Is the number of sectors or clusters that the OS reserve for files always even number or could be odd number?

0

No, because filesystems are layered on top of ATA, not the other way around.

if an application issued an ATA READ SECTOR command to read 1 sector

Generally, applications do not issue ATA commands. They issue file operations to the OS, and the OS filesystem layer translates them (usually through an abstract "block device" layer) to ATA or SCSI or NVMe commands.

Even programs which bypass the filesystem, almost always perform their reading/writing by using the OS-provided "block device" operations and not raw disk commands. They only issue raw ATA commands when they need ATA-specific features (e.g. querying SMART status, etc).

does the OS enforce cluster size and request 8 sectors

No. If an application does ever issue raw ATA commands, then it does so in order to bypass the entire filesystem layer (indeed, it might even be reading/writing a disk which has no filesystem), so it makes no sense to enforce filesystem-level options at this point.

Is the number of sectors or clusters that the OS reserve for files always even number or could be odd number?

In most filesystems the length of a file can be any number; there is no reason at all for it to be limited to an even number. If a file needs 3 clusters, it'll be stored in 3 clusters.

| improve this answer | |
  • Thanks for your answer. So can I say that the minimum transfer size between PC and hard drive is 1 sector I am working on hardware close to the hard drive, that is why I need to know the minimum transfer size. can I say as the number of sectors inside each cluster is even, then all files will have a size that is even number of sectors? – Ahmad Zaklouta Jan 17 at 12:13
2

The cluster size of a file system does not equal the minimum transfer size between the physical host and the drive. It can be lower or higher.

  • Assume a file system with a 64K cluster size, and a file rename changes only a single byte in a block holding a directory. While the cluster is now dirty, only the single page (usually 4K) holding the changed part is now dirty and will be written back to the disk with the next *sync() call. In this case the write size is smaller than the cluster size.
  • Assume again a file system with a 64K cluster size and one of the clusters has recently been read. Of the 16 pages it consumes in buffer/cache 15 are still there, but 1 has been evicted. On the next read, only the missing page will be read. In this case, the read size is less than the cluster size.
  • Assume a file system with 4K cluster size and the readahead is set to 64K. If a cluster, that is not in buffer/cache is read, the read size will be 64K. In this case the read size is higher than the cluster size.
  • Assume a file system with 4K cluster size and two neighbouring clusters are dirty in buffer/cache. When the elevator marks these pages for writeout, it is very likely that they will be written in a single operation. In this case the write size is larger than the cluster size.

I only gave one example each for bigger/smaller read/write, but there must be hundreds of cases, where the physical transfer size is smaller or bigger (by orders of magnitude) than the cluster size.

| improve this answer | |
  • thank you for your answer. So apart from cluster size, would the OS issue a ATA command to read/write just one physical sector? If NO, how can I know the minimum transfer size between the physical host and the drive? – Ahmad Zaklouta Jan 17 at 12:09
  • That depends on the OS. If it allows sub-page disk access (such as FreeDOS), then yes. – Eugen Rieck Jan 17 at 12:26

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.