9

I'm looking for a formal definition of file that does not only include storage but also abstractions like procfs or /dev/null (or any fuse-based file) that do not relate to storage.

So far I know that all files are abstractions that

  • can be identified
  • can have names (usually organized in hierarchical structures)
  • can be accessed as a byte stream
  • usually provide permissions and other (system specific) metadata

however I was unable to find any useful formal definition in any OS book I've read so far.

reinierpost
  • 6,294
  • 1
  • 24
  • 40

2 Answers2

6

According to Wikipedia, a computer file is simply a resource for storing information. The term appears to have originated in the punch card era, where a computer program was literally stored in a file (as in, a box used to store loose pages, see image below). As other forms of media were introduced, such as disks, the nomenclature followed.

From a *nix point of view, everything is a file: sockets, devices, terminals, screens/monitors, data files, pipes, and so on. Microsoft Windows, in contrast, tends to call permanent storage data "files", and volatile resources as whatever they are, such as named pipes, sockets, raster devices, etc. Other systems may have similar definitions somewhere between these two extremes.

Unfortunately, as I've just stated, there's no single definition of what a file is, because it is different things to different people, except that everyone tends to agree on the base-line definition that a file is a named resource that stores data on permanent media (permanent does not imply that it can never be modified, simply that it persists through power cycles).

Punch Card File] (Wikipedia)

phyrfox
  • 1
  • 2
2

I think of a file as a sequence of bytes. Even after it loses its name (usually caused by a call to rm, which unlinks it), it still exists on the disk until its chunks get overwritten by other stuff. File formats are contexts for reading files. It all goes back to the principle that information is bytes plus context.

The previous poster is right that devices, whilst being treated as files, are not really files. This is a very useful hack.

So my definition of a file: a sequence of bytes stored in memory.

ncmathsadist
  • 209
  • 4
  • 6