Chapter 5 File Management
Chapter 5 File Management
File Management
Introduction
• Computer applications store and retrieve information.
• When a process is running, it can store information within its
address space.
• A problem with keeping information within the address space is
that when a process terminates, that information is lost.
• For some applications like database systems, we need a
permanent form of storage.
• Furthermore, it is necessary to have multiple processes
accessing the same information or parts of it at the same time.
• To solve this problem, we should make the information to be
independent of any one process
Long Term Storage
• The OS associates
other information with
each file, for example,
the date and time of
creation and file size.
• This extra information
is referred to as file
attributes.
• The list of attributes
varies from one
system to another.
File Attributes (cont)
• The first four relate to file protection and tell who may access it
and who may not.
• In some systems, the user must supply a password to access a
file, in which case the password must be one of the attributes.
• Flags are bits or short fields that control some specific
property.
• Hidden files, for example, do not appear in the listing of all files.
• The archive flag keeps track of whether a file has been backed
up.
• Temporary flag allows a file to be marked for automatic deletion
when the process that created it terminates.
File Operations
• Files store information and allow it to be retrieved later on.
• Different systems provide different operations to allow storage and
retrieval.
• CREATE – Creates a file with no data. The purpose of this is to announce
that a new file is being created and set some of the attributes.
• DELETE – Deletes a file when it is no longer needed to free some disk
space.
• OPEN – Used to open a file before it can be used by a process. The
purpose is to allow the operating system fetch the attributes and list of
disk addresses into memory for rapid access later on.
• CLOSE – When a process is through with a file, it should be closed to
free up internal table space. A disk is written in blocks and closing a file
forces writing of the file’s last block even though the block may not be full.
File Operations (cont)
• READ – Data are read from a file. The caller must specify the size of data and provide a
buffer to put them in.
• WRITE – Data is usually written to the file at the current position. If the current position is at
the end of the file, the size is increased. If it is in the middle, existing data are overwritten and
lost forever.
• APPEND – This is used to add data at the end of a file. Some systems do not provide for this
since it can be derived from other system calls.
• SEEK – For random access files, a method is needed to specify from where to read. The
SEEK system call repositions the pointer from the current position to a specific position in the
file. After this, data can be read from the current position.
• GET ATTRIBUTES – Processes often need to read the file attributes to do their work. This
system call is used to return specific attributes requested for.
• SET ATTRIBUTES – Some of the file attributes are user settable and can be changed after
the file has been created. This system call makes that possible.
• RENAME – Often, users will want to change the name of an existing file. This system call is
used for that, but it is not necessary since a file can usually be copied to a new file with the
new name and then the old one deleted.
File Structures
• Files can be structured in several ways. The three most common
possibilities are:
– Unstructured sequence of bytes
– Fixed length records
– Tree of variable records
• Basic Information
– File name: must be unique
– File type: e.g., text, binary
– File organization
• Address Information
– Volume: device on which file is stored
– Starting address: e.g., cylinder, track on disk
– Size used: in bytes, words or blocks
– Size allocated: maximum size of the file
Directory Elements (cont)
• Usage Information
– Date Created, Identity of Creator, Date Last Read
Access, Identity of Last Reader, Date Last Modified
Directory Operations
• CREATE – Used for creating a directory.
• DELETE – Deletes a directory. Only an empty directory can be deleted.
• OPENDIR – Directories can be read. For example to list all files in a directory, a
listing program opens the directory to read out the names of all the files it contains.
• CLOSEDIR – When a directory has been read, it should be closed to free up
internal table space.
• READDIR – Returns the next entry in an open directory. Formerly, it was possible
to read directories using the normal READ system call, but this has the
disadvantage of forcing the programmer to know and deal with the internal structure
of the directories.
• RENAME – Used to rename directories just like in files
• LINK – Linking is a technique that is used to allow a file appear in more than one
directory. This system call specifies an existing file and a path name and creates a
link from the existing file to a path specified by the path.
Hierarchical, or
Tree-Structured Directory
• Master directory with
user directories
underneath it
• Each user directory may
have subdirectories and
files as entries
• Each directory and
subdirectory can be
organized as a
sequential file
Hierarchical, or
Tree-Structured Directory
Easily enforce access restriction on
directories.
• Two issues
– Access rights
– Management of simultaneous access
Access Rights
• Execution
– The user can load and execute a program but
cannot copy it, e.g., proprietary programs
• Reading
– The user can read the file for any purpose,
including copying and execution
• Appending
– The user can add data to the file but cannot
modify or delete any of the file’s contents
Access Rights cont…
• Updating
– The user can modify, delete, and add to the
file’s data.
• Changing protection
– User can change access rights granted to
other users
• Deletion
– User can delete the file
User Classes