The referent of a file descriptor

file-descriptorsopen filesterminology

My understanding is that a file descriptor is an integer which is a key in the kernel's per-process mapping to objects such as open()ed files, pipes, sockets, etc.

Is there a proper, short, and specific name for “open files/sockets/pipes/…”, the referents of file descriptors?

Calling them “files” leads to confusion with unopened files stored in the file system. Simply referring to file descriptors does not adequately describe the semantics (e.g. copying the integer between processes is useless).

Consulting The Open Group Base Specifications and my own system's manpages leads me to the conclusion that the referent of a file descriptor is an object and when it is specifically an open file it is, well, an open file. Is there a more specific term than object?

Best Answer

There is not really a more specific term. In traditional Unix, file descriptors reference entries in the file table, entries of which are referred to as files, or sometimes open files. This is in a specific context, so while obviously the term file is quite generic, in the context of the file table it specifically refers to open files.

Files on disk are often referred to as inodes, although technically the inode is the metadata portion of the file. However since the relationship between the inode and the data blocks is one-to-one, referring to an inode implicitly refers to the data to which it points. More modern filesystems may support features such as copy-on-write where data blocks may be shared, so this is not universally true, but is for traditional Unix. However, given the term filesystem, it is no small leap to consider the contents of that to be files.

inodes are also read into memory as in-core inodes when a file on disk is opened, and maintained in the inode table, but that is one level of indirection further than you are asking.

This leads to the conflict in terminology: files on disk (referenced by an inode), and open files (referenced by entries in the file table).

I would suggest that "open file" or "file table entry" are both adequate descriptions of what you are looking to describe.

One reasonably concise reference I found is at: http://www.hicom.net/~shchuang/Unix/unix4.html. References of the form (Bach nn) are references to the book The Design Of The Unix Operating System by Maurice J. Bach.

Related Question