File Systems: The Interface

a file

Think of a file as a labelled folder in a filing cabinet, except the cabinet is your disk and the label is the file's name. Inside is whatever you put there: the words of a document, the pixels of a photo, the bytes of a program. The point of a file is that you can name it, save it, close your computer, come back tomorrow, and find exactly the same contents waiting under the same name. It is the everyday unit in which we store information that should outlive any single running program.

Underneath, a storage device just offers a huge array of numbered blocks, like a warehouse of identical numbered boxes. A file is the operating system's abstraction on top of that: a named sequence of bytes that you can read and write as if it were one continuous stream, while the OS quietly remembers which scattered blocks actually hold your data. To a program, a file is simply a contiguous run of bytes numbered from 0; whether those bytes live in one place or fifty places on the platter is the file system's problem, not yours. The OS also keeps a small record of facts about the file (its name, size, owner, timestamps) separate from the data itself.

Why it matters: the file is probably the single most successful abstraction in all of computing. It hides the messy details of physical storage behind a simple, uniform idea so that the same read and write operations work whether the data is on a spinning disk, a flash drive, or even a network. A common misconception is that a file is a physical thing on the disk; really it is a contract the OS keeps with you, mapping a name and a stream of bytes onto whatever raw blocks happen to be available.

You save a one-line text document called notes.txt. On disk its 30 bytes might actually sit inside block 4192. To you it is just "notes.txt", a thing you can open, edit, and close. The OS remembers the name-to-block mapping so you never have to think about block 4192.

A name and a stream of bytes; the OS hides where the bytes physically live.

A file is the user-facing abstraction. How its bytes are actually scattered across disk blocks is a separate topic (file-system implementation), and the device that stores them is yet another (storage).

Also called
regular file資料檔