OS CHAPTER-11_File Management
OS CHAPTER-11_File Management
CONTENTS
File concept
Access Methods
Disk and directory structure
File system mounting
Protection
2
Introduction
File system is used to define storage devices and control
how data is stored and retrieved.
From the system point of view, file system helps to
organize and distribute storage spaces, and provides
some protective measures to ensure the data security.
Specifically, it can help to create file, store file, modify file,
and control access to file, and undo file when users don't
need it.
3
WHAT IS A FILE?
A file is a collection of related information that is recorded on
secondary storage.
It is a continuous logical address space provided to us in the
secondary memory.
WHAT IS A FILE SYSTEM THEN?
A file system is a process that manages how and where data on a
storage disk, typically a hard disk drive (HDD), is stored,
accessed and managed. It is a logical disk component that
manages a disk's internal operations as it relates to a computer
and is abstract to a human user.
File attributes
A file access classification that determines how a file can be viewed or
whether it can be edited. File attributes are maintained in the file system's
directories.
A file’s attributes vary from one operating system to another but typically consist of these:
Name: The symbolic file name is the only information kept in human
readable form.
Identifier: This unique tag, usually a number, identifies the file within the
file system; it is the non- human-readable name for the file.
Type : This information is needed for systems that support different types
of files.
Location: This information is a pointer to a device and to the location of
the file on that device.
Size: The current size of the file (in bytes, words, or blocks) and possibly
the maximum allowed size are included in this attribute.
5
Protection: Access-control
information determines who can
do reading, writing, executing,
and so on.
Time, date, and user identification:
This information may be kept for
creation, last modification and,
last use. These data can be useful
for protection, security, and usage
monitoring.
File operations
Creating a file: finding a space in the file system directory
making an entry for the new file in the directory
Open Files
Open-file table: contains information about all open files.
No searching for specified file required while performing file operations
The open() system call returns a pointer to the entry in the open file table
To handle same files opened by multiple processes, 2 levels of internal tables
are used by the operating system:
Per-process open file table: contains info about all open files of that
process,
plus pointer to entry in global open file table (can be many)
System wide open file table: global table maintained by the OS
containing process independent open file information (only one)
Information related to an 9
open file
File pointer: pointer to last read/write location
unique to each process that has the file open
File-open count: counter of number of times a file is open in the system wide
open file table – to allow removal of data from open-file table when last
processes closes it
Disk location of the file: cache of data access information
Access rights: access mode information
stored in per process table
Open file 10
locking
֍ Mediates access to a file (shared or exclusive)
֍ Useful for processes that are shared by several
processes
֍ Provided by some operating systems and file systems
Similar to reader-writer locks
Shared lock:- similar to reader lock
several processes can acquire
concurrently
Exclusive lock:- similar to writer lock
only one process can acquire at a
time
11
ACCESS
METHOD
S
SEQUENTIAL ACCESS
A sequential access file emulates magnetic tape operation
Information is accessed in order- one record after the other
read_next() - read the next portion of file and advance the tape to
the next position.
DIRECT ACCESS
The file is viewed as a numbered sequence of blocks or
records
Allows arbitrary blocks to be read or written
reset cp:=0;
OTHER ACCESS
METHODS
An indexed access method can be easily built on top of a direct
access system.
DISK STRUCTURE
A storage device(disk) can be used in its entirety for a file
system.
FILE
special-purpose file SYSTEM
Along with general-purpose file systems there are many
systems, frequently all within the same
operating system or computer like:
TYPES
tmpfs —“temporary” file system in volatile main memory,
contents erased if the system reboots or crashes
objfs —a “virtual” file system (essentially an interface to the
kernel that looks like a file system) that gives debuggers access to
kernel symbols
Ctfs — a virtual file system that maintains “contract” information
to manage which processes start when the system boots and must
continue to run during operation
lofs—a “loop back” file system that allows one file system to be
accessed in place of another one
procfs—a virtual file system that presents information on all
processes as a file system
Ufs,zfs — general purpose file systems
23
Directory Overview
The directory can be viewed as a symbol table that translates file names
into their directory entries. The organisation of the directory must allow
us to perform many operations with these entries.
These include:
Advantages:
Easy to support, understand and maintain
Convenient to implement for the developer due to its simple structure
Limitations:
All files needs to be associated with a unique name to avoid name-space
collisions
Keeping track of large number of files in this scheme becomes very difficult
and daunting
Difficult to use for when multiple users are supported
All in all, brings down user convenience
25
files
Single-Level directory
26
Two-Level Directory
In this view, each user has his own user file directory (UDF). The UDFs have
similar structures, but each lists only the files of a single user.
When a user first logs in, the system’s master file directory (MDF) is
searched. The MFD is indexed by user name or account number, and each entry
points to the UDF for that user.
files
27
Specifying a user name and a file name defines a path in the tree from the root
(MFD) to a leaf (the specified file). Thus, in this structure, a user name and a file
name defines a path name. Every file has a unique path name. To name a file
uniquely, one must know the path name of the desired file. E.g. if user2 wants to
access “data” in its own UFD, “data” is the path name while if he wants to
access “test” of user1, the path name becomes “/user1/test”. Path names are
relative to users.
In UNIX, search path of the kernel is saved in the environment variable “PATH”
When we talk about adding Java to the path of our system, it is to this
variable that we append the java file’s path name
In this structure, the users are allowed to make subdirectories within their own
UFDs. Therefore, improving organisation of files
system structure
/
bin boot dev etc home lib usr root mnt val
(MFD)
File1.txt Project3.pdf
Current directory should contain most of the files that are of current interest of
the process. If a reference to a file is made, first “.” Is checked. If found, it is used.
Otherwise, the user must change directory or specify file’s path name. Path
name is the sequence of directories that needs to be traversed to get to
the desired file. It is of two types:
Absolute path name: path name begins at the root(MFD) and follows a path
down to the specified file, giving the directory names on the path. E.g. in the UNIX
example, absolute path to file “Project3.pdf” is
/home/tanisha/Documents/Project3.pdf
Relative path name: path name defined from the current directory. E.g. if
current directory (.) is Downloads then , relative path to “Project3.pdf” is
../Documents/Project3.pdf
33
list rade w7
35
Working with copies, changes made into one is not reflected on others. With
shared files, only one actual file exist. So any changes made by one user is
immediately visible to others, therefore, making working on projects easier.
Shared files can be implemented using links. There are two types of links in
UNIX:
Hard Link: hard links to a files are actually dynamic copies of a file such that
whenever any changes are made, it adopts the same. They share the same
inode number as the original file.
Symbolic/soft links: symbolic links are pointers to a file. They can be thought
of as aliases of a file.
Link count
File type
Link count is the number of hard links to a file, including the original.
orphan link
37
Difference between hard link and symbolic link
Deleting the original file doesn’t Deleting the original file cause
affect the hard link and it the symbolic link to become
preserves its contents orphan. Therefore, results in
dangling pointers
Deleting the original file is
When hard link exists, then to
truly delete a file, one must enough to delete desired
delete the original file and all of contents. However, these
its hard links. Bring down link dangling pointers must be
count to 0 to deallocate handled to prevent problems
memory
PROTECTION
• prevention of improper or illegal access of data/files
• Protection Mechanism provides controlled access by limiting the types of files
access that can be made
Types of Accesses:
ACCESS CONTROL
• access dependant on the identity of the user
• Access Control List – list specifying user names
and type of access allowed for each user , associated with
each file and directory
Advantages :
1. enables complex methodologies
Disadvantages:
1. tedious
2. directory entry of variable size – more complicated
space management
40
2. Group : a set of users who are sharing a file and need similar
access
Example
Sara is writing a new book
hires three graduate students Jill , Dawn and Jill
text of the book kept in file named ‘book.tex’
UNIX/LINUX
• three fields of 3 bits each
r – read access
w -write access
x -execution
R W X
Owner 7 >> 1 1 1
1 1 0
Group
6 >>
0 0 1
Universe 1 >>
43
• Windows
manages
access control
list via GUI
Windows 7
access
control list
management
44
OTHER PROTECTION
APPROACHES
• associate Password with each file
• Effective in limiting access to a file – password chosen
randomly and changed often
Disadvantages:
1. User needs to remember a large number of passwords
2. If only one password is used then, all files become accessible
once it is discovered.
• as a solution to this problem , many systems allow
users to associate password with a subdirectory than a
individual file