Which of course risks breaking the files formatting. Well in Linux, by default, files are not locked by processes and its always possible for multiple processes to write to the same file. Trying to understand what your asking because it's not clear.īut if I understand properly, your asking how can multiple processes write to the same file? And calling it a "table" reinforces that misleading image.īut it's a fairly common usage so I don't expect it to die out soon. Since the open file descriptions are always accessed through those pointers, never by numerical index in some array, drawing them as a contiguous column of boxes is a little misleading. A file descriptor is an index into an array of pointers to open file descriptions. The "file table" in the diagram on wikipedia is a set of open file descriptions. So there really isn't a "file table" anymore, unless you consider every dynamic memory allocation pool to be a "table". The set of all open file descriptions in the system is not required to be arranged in a contiguous array-like setup. Nowadays, open file descriptions are allocated dynamically with a more flexible mechanism than just choosing an unused slot in a fixed-size array. In that system, "file table" is a natural name for the system-wide array of struct file. When a process needed a new open file description, the array was scanned for an unused slot and a pointer to that slot was returned. If you look at early implementations, the set of all open file descriptions in the system was an array. I'm interpreting the question as mainly about terminology, specifically the "file table". In the Linux kernel, the directory entry is split in two levels: struct inode which contains file metadata and struct dentry which keep track of where the file is in the directory tree. The directory entry contains information about what the file is, including a pointer to its parent directory, and information as to where the file is located. There can be multiple open file descriptions pointing to the same directory entry, if the same file was opened more than once. If the file is a file in the directory tree, then the open file description contains a pointer to a directory entry. The distinction is that the file API covers files such as anonymous pipes and sockets that do not live in the filesystem tree. The open file description lives at the level of the file API. Under Linux, the open file description structure is struct file. The open file description contains information about the way the file is open, including the mode (read-only vs read-write, append, etc.), the position in the file, etc. If file descriptors (even in different processes) are due to the same original open (or similar) system call, they share the same open file description. There can be multiple file descriptors pointing to the same open file description, from multiple processes, for example when a process has called dup and friends, or after a process has forked. The file descriptor structure contains a pointer to an open file description. In the Linux kernel, this structure is struct fd. The kernel keeps a table of open file descriptors for each process, mapping these small integers to a file descriptor structure. This is only a convention: the kernel doesn't care. The numbers 0, 1 and 2 have conventional meanings: processes are supposed to read normal input from 0 (standard input), write normal output to 1 (standard output), and write error messages to 2 (standard error). I'm going to describe a straightforward implementation real implementations are likely to have a lot more complications.Īn open file in a process is designated by a file descriptor, which is a small nonnegative integer. Implementation-wise, these levels generally translate into data structures in the kernel pointing to the next level. There are several levels of indirection when going from an open file in a process all the way to the file content. File descriptor → open file description → directory entry
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |