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

The create operation makes a new file within the file system. It is used by It will change directory entries as well as setting up space for a new file in the filesystem.

delete

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.

rename

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.

open

This opens a file in preparation for 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).

close

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.

read

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.

write

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.

append

An append operation will seek to the end of the file and begin writing data there.

seek

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.

get attributes

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.

set attributes

Attributes may be set (if the attributes allow this), by commands such as chmod or touch. Home 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