I'm pretty sure that a sector is basically a block, but I was moreso confused about chunk sizes and especially records. Some system calls require that your area in memory that buffers data from disk to be a multiple of the disk record size. What does this mean?
migrated from programmers.stackexchange.com Oct 25 '11 at 19:17
This question came from our site for professional programmers interested in conceptual questions about software development.
I used to do some file system development years ago. What follows is the terminology we used on our projects.
A disk sector is the smallest addressable set of bytes on the media. Typically this was 512 bytes for most devices, though sector sizes of 4096 bytes is becoming more common.
The file system accessed the device in terms of physical blocks. A physical block would be one or more contiguous sectors (typically a power of two).
The files within a file system accessed data in terms of logical blocks. A logical block was one or more contiguous physical blocks.
Sector is a physical region on the disk drive, and the sector size is set by the hardware. Reads of and writes to the disk platter are performed on sectors. Data to and from the HDD are in sector-sized transfers.
(The first disk controller (for 14" disk drives) I ever programmed did not use sectors, but rather (disk) records. Each track had to be formatted with the record layout. If you wanted to go crazy, each record on the track could have a unique length. But typically all records on each track of the entire disk volume were formatted with the same record length. Modern disk drives no longer have such formatting capabilities, but instead use sectors. Since then, I don't recall ever hearing the phrase "disk record". Note: 8" floppies had a similar but simplified formatting scheme which became known as "soft sectoring", since the records were always a consistent, but not fixed, length.)
(At the device level, the term record used to be used also for the physical block, e.g. a mag tape record or disk record. A tape transport or disk drive technical document might refer to a record as the smallest physical block of I/O. But unless you are actually using tape or working at the disk controller level, record can be regarded as a userland/file/filesystem entity.)
Record is (most commonly used as) a filesystem (or logical) concept, and is (then) irrelevant at the lower (disk) I/O level (i.e. reading or writing a record occurs only at the user-to-system interface). The contents and size of the record can be user defined or dictated by the file. The record could be fixed length and correspond to a data structure, or the record could be variable length (e.g. a line of text with a new-line delimiter).
Regardless of the record's length, the filesystem will utilize intermediate buffers to allow the user/application to perform read/writes of records, and perform the actual device I/O in sectors. Reading sectors or physical blocks from the device into the "system buffer" and then extracting the "logical" records is often called "deblocking".
The size of a record can be arbitrary. Ideally the record size is chosen so that a multiple of it equals the sector (or physical block) size, and then block I/O (directly to/from the user buffer) can be performed instead of buffered I/O. Block I/O is faster since it involves one less copy and uses one less buffer, although the user program may have to do its own blocking and deblocking of records.