Generic File System Operations
Contents
Create
delete
rename
open
close
read
write
append
seek
get attributes
set attributes
File operations
The set of operations allowed on files may include
- create
- delete
- rename
- open
- close
- read
- write
- append
- seek
- get attributes (security)
- set attributes (security)
The create operation makes a new file within the file system. It is used
by
- An editor when a new file is saved
- An editor will often create temporary files to store files in the
process of being edited. The vi editor uses /tmp/vi, emacs uses
#file#
- It is used by shells
on output redirection where the file is created if it did not already
exist
- The Unix utility
touch will create a file if it does
not already exist
It will change directory entries as well as setting up space for a
new file in the filesystem.
The delete operation removes the file from the file system.
The space used by the file will be returned to the free space of the
system.
In DOS, the del command does this. In Unix, this will
only occur when all references to the file are removed.
In a file system where the filename is stored along with the file,
the rename operation will change this. This is used by DOS's
rename. It is not used by Unix, because the filename
is not stored with the file but in the directory.
In Unix, rename is a directory operation.
This opens a file in preparation for
- reading the contents of an existing file
- writing the contents of a file. Opening an existing file for
writing will usually remove the old contents first
- appending to a file
- changing the contents of a file
This creates file-open structures within a process using the file.
It may mark the file as open within the OS so that other processes
may have restricted access to it (e.g. only one process may be able
to write to a file).
The close operation is used by a process to show that it no longer requires
access to a file. It may result in buffers being flushed so that the state
of the file on disk is finalised. It may also result in flags getting
cleared in the OS so that other processes may get access to the file.
The read operation reads data from the file into buffers within a process.
Reads are in file-dependant units. A file with byte structure may allow
reads in multiples of one byte. A file with record structure may only
only allow reads in multiples of the record size.
A text file may treat end-of-line characters specially
(as in DOS).
For block structured devices like a disk, the OS may read larger chunks
than requested and store the extra information in memory caches.
A read operation may block if the device is not ready for reading. For example
an attempt to read from a serial line will block until data comes in.
Alternatively, in a non-blocking read, the read may return immediately.
The choice of these may belong in the device driver.
A write will cause data to be written to the file. This may be cached
by the OS. A write to a block device may or may not cause extra blocks to
be allocated.
An append operation will seek to the end of the file and begin writing
data there.
A seek operation will search to a specified point of the file.
Seeking beyond the end of a file will often result in the file
growing, with some data in the gaps.
Access to a file will be controlled by permissions attached to the file.
These will be used by the OS before allowing reads, writes, etc.
They may also be queried by commands such as ls -l
or dir /a.
Attributes may also include size, times of modification or
creation, etc.
Attributes may be set (if the attributes allow this), by commands
such as chmod or touch.
Program Development using Unix Home
This page is
http://jan.newmarch.name/OS/l6_1.html,
Jan Newmarch
(http://jan.newmarch.name)
<jan@newmarch.name>
Copyright © Jan Newmarch
Last modified: Wed Nov 19 17:56:29 EST 1997