7chapter Seven - File Management BEST
7chapter Seven - File Management BEST
File Management
Operating System
1
Introduction
2
File Naming
• When a process creates a file, it gives the file a name. When the
process terminates, the file continues to exist and can be accessed by
other processes using its name.
• The exact rules for file naming vary somewhat from system to
system.
• But all current operating systems allow strings of one to eight letters
as legal file names.
• Frequently digits and special characters are also permitted, so names
like 2, urgent!, and Fig.2-14 are often valid as well.
• Many file systems support names as long as 255 characters.
3
File Naming (Cont.)
4
File Naming (Cont.)
5
File Structure
6
File Structure: Byte Sequence
7
File Structure: Record Sequence
8
File Structure: Tree
9
File Types
10
File Types (Cont.)
11
File Access
12
File Attribute
13
File Operations
• Create: The file is created with no data. The purpose of the call is to announce that the
file is coming and to set some of the attributes.
• Delete: When the file is no longer needed, it has to be deleted to free up disk space.
There is always a system call for this purpose.
• Open: Before using a file, a process must open it. The purpose of the open call is to allow
the system to fetch the attributes and list of disk addresses into main memory for rapid
access on latter caller.
• Close: When all the access are finished, the attributes and disk addresses are no longer
needed, so the file should be closed to free up internal table space. Many systems
encourage this by imposing a maximum number of open files on processes. A disk is
written in blocks, and closing a file forces writing of the file’s last block, even though that
block may not be entirely full not.
• Read: Data are read from file. Usually, the bytes come from the current position. The
caller must specify how much data are needed and must also provide a buffer to put
them in.
• Write: Data are written to the file again, usually at the current position. If the current
position is the end of the file, the file’s size increases. If the current position is in the
middle of the file, existing data are overwritten and lost forever.
14
File Operations (Cont.)
• Append: This call is a restricted in the form of write. It can only add data to the end of the file.
Systems that provide a minimal set of system calls do not generally have append, but many
systems provide multiple ways of doing the same thing, and these systems sometimes have
append.
• Seek: For random access files, a method is needed to specify from where to take the data. One
common approach is a system call, seek, that repositions the file pointer to a specific place in
the file. After this call has completed, data can be read from, or written to, that position.
• Get Attributes: Processes often need to read file attributes to do their work. For example, the
UNIX make program is commonly used to manage software development projects consisting
of many source files. When make is called, it examines the modification times of the entire
source and objects files and arranges for the minimum number of compilations required to
bringing everything up to date. To do its job, it must look at the attributes, namely the
modification times.
• Set Attributes: Some of the attributes are user settable and can be changed after the file has
been created. This system call makes that possible. The protection mode information is an
obvious example. Most of the flags also fall in this category.
• Rename: It frequently happens that a user needs to change the name of an existing file. This
system call makes that possible. It is not always strictly necessary, because the file can usually
be copied to a new file with the new name, and the old file then deleted.
15
• Sequential access
• Read all bytes/records from the beginning sequentially.
• Cannot jump around, could rewind or back up.
• Convenient when medium is magnetic tape, rather than disk.
• Random access
• Bytes/records read in any order.
• Essential for data base systems.
• Read can be (Move file marker (seek), then read or Read and then move file marker.) like
magnetic disk.
• Shared Files
• File system containing a shared file
• Sharing of files on multi-user systems is desirable.
• Sharing may be done through a protection scheme.
• On distributed systems, files may be shared across a network.
• Network File System (NFS) is a common distributed file-sharing method.
16
• DIRECTORY
• Directory Structure
• A collection of nodes containing information about all files.
• Both the directory structure and the files reside on disk.
• Backups of these two structures are kept on tapes.
17
• Information on Device Directory:
• Name
• Type
• Address
• Current length
• Maximum length
• Date last accessed (for archival)
• Date last updated (for dump)
• Owner ID (who pays)
• Protection information
•
18
• Operations Performed on a Directory
• Search for a file
• Create a file
• Delete a file
• List a directory
• Rename a file
• Traverse the file system
•
• Types of Directory Structures
• Single Level Directory
• Two level Directory
• Tree structured Directory
• Acyclic graph Directory
• General Graph Directory
19
Single-Level Directory Systems
20
21
• Hierarchical Directory Systems
• Efficient searching
• Grouping Capability
22
• 4. Acyclic Graph Directories:
• The acyclic directory structure is an extension of the tree-structured
directory structure. In the tree-structured directory, files and
directories starting from some fixed directory are owned by one
particular user. In the acyclic structure, this prohibition is taken out
and thus a directory or file under directory can be owned by several
users.
• Have shared subdirectories and files.
• No cycles
23
24
5. In general graph directory structure, cycles are allowed within a directory
structure where multiple directories can be derived from more than one parent
directory.
The main problem with this kind of directory structure is to calculate total size or space
that has been taken by the files and directories.
25
Thank you
26