File Descriptor: Difference between revisions
From COMP15212 Wiki
m (1 revision imported) |
m (1 revision imported) |
||
| (One intermediate revision by one other user not shown) | |||
| Line 2: | Line 2: | ||
-->{{Path|Filing|12}}<!-- | -->{{Path|Filing|12}}<!-- | ||
-->{{#invoke:Dependencies|add|File Access,3|Filing System Implementation,4}} | -->{{#invoke:Dependencies|add|File Access,3|Filing System Implementation,4}} | ||
The descriptor will be created when a [[Files|file]] is opened and is | The descriptor will be created when a [[Files|file]] is opened and is associated with a particular file within a particular process. It is used for immediate [[File_Access|file access]]. It will hold information such as: | ||
associated with a particular file within a particular process. It is | |||
used for immediate [[File_Access|file access]]. It will hold | |||
information such as: | |||
*the access permissions. | *the access permissions. | ||
| Line 15: | Line 12: | ||
[[Image:file_access.png|link=|alt=File Access Abstraction]] | [[Image:file_access.png|link=|alt=File Access Abstraction]] | ||
The <em>details</em> are deliberately kept <em>opaque</em> – loosely the equivalent | The <em>details</em> are deliberately kept <em>opaque</em> – loosely the equivalent of having <code>private</code> variables. A <em>sketch</em> (not 100% guaranteed!) is shown below. Do not try and memorise (or even understand!) all the details here – mostly marvel at the complexity! | ||
of having <code>private</code> variables. A <em>sketch</em> (not 100% guaranteed!) is | |||
shown below. Do not try and memorise (or even understand!) all the | |||
details here – mostly marvel at the complexity! | |||
[[Image:file_descriptors.png|link=|alt=File Descriptors]] | [[Image:file_descriptors.png|link=|alt=File Descriptors]] | ||
| Line 32: | Line 26: | ||
=== File Descriptor vs. File Attributes === | === File Descriptor vs. File Attributes === | ||
Like the [[File_Attributes|file attributes]], a file descriptor holds | Like the [[File_Attributes|file attributes]], a file descriptor holds some [[Metadata|metadata]] about a file. However these are not the same thing. | ||
some [[Metadata|metadata]] about a file. However these are not the | |||
same thing. | |||
*The file attributes are ‘permanent’, in that they exist with the file; the file descriptor only exists whilst the file is <em>in use</em>. | *The file attributes are ‘permanent’, in that they exist with the file; the file descriptor only exists whilst the file is <em>in use</em>. | ||
| Line 40: | Line 32: | ||
---- | ---- | ||
{{BookChapter|14.2.2|568}} | |||
{{PageGraph}} | {{PageGraph}} | ||
{{Category|Filing System}} | {{Category|Filing System}} | ||
Latest revision as of 10:03, 5 August 2019
| On path: Filing | 1: Filing System • 2: File Systems • 3: Files • 4: File Attributes • 5: File Types • 6: File Permissions • 7: File Access • 9: Filing System Implementation • 10: I-nodes • 11: Links • 12: File Descriptor |
|---|
| Depends on | File Access • Filing System Implementation |
|---|
The descriptor will be created when a file is opened and is associated with a particular file within a particular process. It is used for immediate file access. It will hold information such as:
- the access permissions.
- e.g. whether you can currently read or write; different from the file access rights.
- the current position (index) in the file.
- the error status.
- control flags.
The details are deliberately kept opaque – loosely the equivalent of having private variables. A sketch (not 100% guaranteed!) is shown below. Do not try and memorise (or even understand!) all the details here – mostly marvel at the complexity!
A couple of points:
- Unix maintains a simple table of files for each process.
- One file may be opened several times, simultaneously; each ‘opening’ has its own descriptor.
- Opened files can be shared: several processes can read the same file at the same time, for example.
- Eventually there is a pointer to the appropriate i-node.
File Descriptor vs. File Attributes
Like the file attributes, a file descriptor holds some metadata about a file. However these are not the same thing.
- The file attributes are ‘permanent’, in that they exist with the file; the file descriptor only exists whilst the file is in use.
- There is exactly one set of file attributes per file; there can be several file descriptors for the same file if it has been opened multiple times concurrently. Each descriptor will have (for example) its own file position.
| Also refer to: | Operating System Concepts, 10th Edition: Chapter 14.2.2, pages 568 |
|---|
Articles on Filing System
"Everything is a File" • FAT • File Access • File Attributes • File Descriptor • File Locking • File Permissions • File Systems • File Types • Files • Filing System • Filing System Implementation • Fragmentation • I-nodes • Journalling File System • Links • Network File System (NFS) • Resources