How does the operating system handle I/O writes, that are not a multiple of the block device's sector-size?

84 views Asked by At

I am trying to understand how a data-block, that is not a multiple of the drive's default sector size is written down. In my understanding, the operating system can only do block-device actions of a multiple sector size, but it somehow manages to write down even smaller blocks of bytes.

Let's assume, I want to write down 300Bytes into a file (buffering disabled) on a block device, that has a sector size of 512 Byte. In this case the operating system would theoretically have to add some padding, in order to physically write the data. I assumed, that this padding would consist of 0x00.

Contrary to my assumption, the 300bytes have been written down perfectly without any noticeable padding. Right at byte 301, the previous written bytes are located. This seems like, the operating system does read the block first into memory, replaces the affected bytes and writes the new, 512bytes block into the specific sector at the drive. This also means, that writes, that are not a multiple of 512, take way longer and require an extra buffer in the RAM... If this is correct, what part of the operating system is responsible for taking that into account? I would be glad if I could get an example (e.g. from the Linux Kernel) to see what's going on.

0

There are 0 answers