Operations on Files
Operations on files:
- Reading, writing, creating, and deleting: These are the basic operations
on files. In ANSI-C [21] a file is created implicitly when a non-existing
file is opened for reading. (Notice that creating and deleting files are also
operations on directories,see Section 3.1.3).
- Scanning (positioning): This can be thought of as reading a file until a
certain position is reached, without caring about what was read "on the way
there".
- Opening and closing: In many systems, and especially those using session
semantics it is impossible to read from or write to a file without having
opened it (for reading or writing) first. Reads and writes to a file may be
performed locally (i.e., without the rest of the system being able to notice
it) before the file is closed.
- Linking and unlinking: UNIX synonyms for creating and deleting. The
files are not physically removed, but they are linked to or unlinked from the
directory structure, and cannot be referenced any more. The space they
previously occupied can be garbage collected. (Linking and unlinking files are
operations on directories, see Section 3.1.3).
- Updating: Synonym for reading and writing a file.
- Rewriting: A composite operation; rewrite
file
= if
file
exists then delete
file
, create
file
, write
file
.
- Copying: A composite operation on two files; copy
file1
file2
= read
file1
, create
file1
, write
file2
.
- Renaming and moving: Composite operations on two (or more) files;
rename/move
file1
file2
= read
file1
, create
file2
,
write
file2
, delete
file2
.
When a file is opened in (ANSI-)C [21] it must be specified whether
the file is to be read, rewritten (written), updated (read and written), or appended to
(which is just a particular form of updating; the file is "read"
to the end and written from there).
Possible conflicts
- Read/write conflicts occur when something wrong is written into a file
due to the reading of (a replica of) another file that is out-dated (or stale).
These conflicts are not easily detected, since the system seldom knows how to
relate reads and writes. It is easy to detect the possible use of stale date,
but not to relate it to following updates. For this purpose transactions can
be of great value; operations within the same transaction are logically bound
together, and the system knows it because it has been told. The resolution of
these conflicts are easy--redo the reads and thereafter the writes based upon
them.
- Write/write conflicts occur when the same (logical) file is being updated
concurrently in to different places (i.e., two replicas). These conflicts are
(relatively) easily detected; comparing (vector) timestamps or file contents.
The resolution of these conflicts are not always easy--which updates are the
"correct" ones?
michael@garfield.dk
2000-10-13