File Descriptor: Difference between revisions

From COMP15212 Wiki
pc>Yuron
No edit summary
 
gravatar W81054ch [userbureaucratinterface-adminsysopPHRhYmxlIGNsYXNzPSJ0d3BvcHVwIj48dHI+PHRkIGNsYXNzPSJ0d3BvcHVwLWVudHJ5dGl0bGUiPkdyb3Vwczo8L3RkPjx0ZD51c2VyPGJyIC8+YnVyZWF1Y3JhdDxiciAvPmludGVyZmFjZS1hZG1pbjxiciAvPnN5c29wPGJyIC8+PC90ZD48L3RyPjwvdGFibGU+] (talk | contribs)
m (1 revision imported)
 
(2 intermediate revisions by 2 users 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 AccessFiling 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.

File Access Abstraction

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!

File Descriptors

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