SlideShare una empresa de Scribd logo
1 de 35
Descargar para leer sin conexión
OPERATING SYSTEMS
iv -1
UNIT –IV FILE SYSTEMS
OPERATING SYSTEMS
iv -2
UNIT –IV FILE SYSTEMS
File-system interface: File concept-Access methods-Directory structure-File-system
mounting-Protection. File-system implementation: directory implementation-Allocation
methods-free-space management-efficiency and performance-recovery-log structures file
systems. Case studies: file system in Linux-file system in WindowsXP
Chapter 11 FILES SYSTEM INTERFACE
File concepts
Access methods
Directory Structure
File system Mounting
File sharing
Protection
11.1 FILE CONCEPT
The file system consists of two distinct parts a collection of files, each storing related data
and directory structure, which organizes and provides information about all the file in the
system. Some file systems have a third part, partitions, which are used to separate
physically or logically large collections of directories.
File Attributes
 Name – only information kept in human-readable form
 Identifier – unique tag (number) identifies file within file system
 Type – needed for systems that support different types
 Location – pointer to file location on device
 Size – current file size
 Protection – controls who can do reading, writing, executing
 Time, date, and user identification – data for protection, security,
and usage monitoring
 Information about files are kept in the directory structure, which is
maintained on the disk
File Operations
 File is an abstract data type
OPERATING SYSTEMS
iv -3
Creating a file: Two steps are necessary to create a file. First space in the file system
must be found for the file. The directory entry records the name of the file and the
location in the file system and possibly other information.
Writing a file:
To write a file, we make a system call specifying both the name of the file
and the information to be written to the file. Given the name of the file, the
system searches the directory to find the location of the file. The system
must keep a write pointer to the location in the file where the next write is
to take place. The write pointer must be updated whenever a write is is to
take place .The write pointer must be updated whenever a write occurs.
Reading file: To read from a file, we use a system call that specifies the name of the
file and where the next block of the file should be put. Again the directory is searched for
searched for the associated directory entry and the system needs to keep a read pointer to
the location in the file where the next read is to take place. Once the read has taken place,
the read pointer is updated. A given process is usually only reading or writing a given file
and the current operation location is kept. Current file position pointer is used to save and
reducing the system.
Reposition within file
The directory is searched for the appropriate entry and the current file position is set to a
given value. Repositioning within a file does not need to involve any actual I/O. This file
operation also known as a file seek.
 Deleting a file: To delete a file, we search the directory for the named
file having found the associated directory entry, we release all file
space, so that it can be reused by other files and erase the directory
entry.
 Truncating a file: The user may want to release the contents of a file
but keep its attributes. Rather that forcing the user to delete the file and
then recreate it this function allows all attributes to remain unchanged-
except for file length-but lets the file be rest to length zero and its file
space released.
 Open(Fi) – search the directory structure on disk for entry Fi, and
move the content of entry to memory
OPERATING SYSTEMS
iv -4
 Close (Fi) – move the content of entry Fi in memory to directory
structure on disk
Several pieces of data are needed to manage open files:
o File pointer: pointer to last read/write location, per process
that has the file open
o File-open count: counter of number of times a file is open – to
allow removal of data from open-file table when last processes
closes it
o Disk location of the file: cache of data access information
o Access rights: per-process access mode information
File Types – Name, Extension
11.2Access Methods
 Sequential Access
 read next
 write next
 reset
 no read after last write
 (rewrite)
 Direct Access
 read n
 write n
 position to n
 read next
 write next
OPERATING SYSTEMS
iv -5
 rewrite n
o n = relative block number
Sequential-access File
1. The simplest access method is sequential access. Information in the file is
processed in order, one record after the other.
2. This mode of access A read operation reads the next portion of the file and
automatically advances a file pointer,
3. A file can be reset to the beginning and on some systems, a program may be able
to skip forward or backward n records, for integer n .
4. Sequential access is based on tape model of a file and works as well on sequential
–access devices as it does on random-access ones.
Simulation of Sequential Access on a Direct-access File
1. Another method is direct access(or relative access).A file is made up of fixed
length logical records that allow programs to tread write records rapidly in no
particular order.
2. The direct access method is based on a disk model of a file is viewed as a
numbered sequence of blocks or records.
3. A direct-access file allows arbitrary blocks to be read or written. Thus we may
read block 14 then read blocks 53, and then write block 7.There are no restriction
on the order of reading or writing for a direct-access file.
OPERATING SYSTEMS
iv -6
4. The block number provided by the user to the operating system is normally a
relative block number. A relative block number is an index relative to the
beginning of the file.
5. Thus the first relative block of the file is 0, the next is 1 and so on, even though
the actual absolute disk address of the block may be 14703 for the first block and
3192 for the second.
6. The use of relative block numbers allows the operating system to decide where
the file should be placed
7. Cp that defines our current position then we can simulate sequential file
operations,
8.Given a logical record length L, a request for record N is turned into an I/O request
for L bytes starting at location L*(N-) within the file.
Example of Index and Relative Files
These methods generally involve the construction of an index for the file .The index like
an index in the back of a book, contains pointers to the various blocks.
To find a record in the file, we first search the index, and then use the pointer to access
the file directly and to find the desired record.
With large files, the index file itself may become too large to be kept in index file would
contain pointers to secondary memory.
One solution is to create an index for the index file. The primary index file would contain
pointers to secondary index files, which would point to the actual data items.
OPERATING SYSTEMS
iv -7
Example:
IBMS indexed sequential-access method (ISAM) uses a small master index that points to
disk blocks of secondary index.
The secondary index blocks point to the actual file blocks.
The file is kept sorted on a defined key.
To find a particular item, we first make a binary search of the master index, which
provides the block number of the secondary index .This block is read in and again a
binary search is used to find the block containing the desired record. This block is
searched sequentially.
OPERATING SYSTEMS
iv -8
Operations Performed on Directory
 Search for a file: To fine the entry for a particular file. Since files have
symbolic names and similar names may indicate a relationship between files,
we may want to be able to find all files whose names match a particular
pattern.
 Create a file: New files need to be created and added to the directory.
 Delete a file: When a file is no longer needed ,we want to remove it from the
directory.
 List a directory: we need to be able to list the file in a directory and the
contents of the directory entry for each file in the list.
Rename a file: Because the name of a file represents its contents to its users the name
must be changeable when the contents or use of the file changes
Backups of these two structures are kept on tapes
1111..33 DDiirreeccttoorryy SSttrruuccttuurree
A collection of nodes containing information about all files
F 1 F 2 F 3 F 4
F n
Directory
Files
Both the directory structure and the files reside on disk
Backups of these two structures are kept on tapes
OPERATING SYSTEMS
iv -9
 renaming a file may also allow its position within the directory structure to be
changed
 Traverse the file system: we may wish to access every directory and every
file within a directory structure. For reliability, it is good idea to save the
contents and structure of the entire file system at regular intervals. This saving
often consists of copying all files to magnetic tape.
 Efficiency – locating a file quickly
 Naming – convenient to users
 Two users can have same name for different files
 The same file can have several different names
 Grouping – logical grouping of files by properties, (e.g., all Java
programs, all games, …)
SSiinnggllee--LLeevveell DDiirreeccttoorryy
The simplest directory structure is the single-level directory. All the files are
contained in the same directory, which is easy to support and understand.
A single directory for all users
Naming problem:
when the number of files increases or when the system has more than one user.
Since all files are in the same directory, they must have unique names. If two users call
their data file test, then the unique names. If two users call their data file test, then the
unique-name rule is violated.
Grouping problem:
OPERATING SYSTEMS
iv -10
TTwwoo--LLeevveell DDiirreeccttoorryy
Separate directory for each user
In the two level directory structures, each user has her own user file directory (UFD).
Each UFD has a similar structure, but lists only the files of single user. When a user job
starts or a user logs in, the system’s master file directory (MFD) is searched.
The MFD is indexed by user name or account number, and each entry points to the UFD
for that user.
To create a file for a user, the operating system searches only that user’s UFD to
ascertain whether another file of that name exists.
To delete a file, the operating system confines its search to the local UFD
Thus, it cannot accidentally delete another user’s file that has the same name.
Path name
Can have the same file name for different user
Efficient searching
No grouping capability
OPERATING SYSTEMS
iv -11
TTrreeee--SSttrruuccttuurreedd DDiirreeccttoorriieess
Tree-Structured Directories (Cont)
 Efficient searching
 Grouping Capability
 Current directory (working directory)
o cd /spell/mail/prog
o type list
TTrreeee--SSttrruuccttuurreedd DDiirreeccttoorriieess ((CCoonntt))
Absolute or relative path name
Creating a new file is done in current directory
Delete a file
rm <file-name>
Creating a new subdirectory is done in current directory
mkdir <dir-name>
Example: if in current directory /mail
mkdir count
Mail
progcopy prt exp count
OPERATING SYSTEMS
iv -12
Deleting “mail”  deleting the entire subtree rooted by “mail”
A directory (or subdirectory) contains a set of files or subdirectories. A directory is
simply another file, but it is treated in a special way. All directories have the same
internal format. One bit in each directory entry defines the entry as a file (0) or as a
subdirectory (1).Special system calls are used to create and delete directories.
The current directory should contain most of the files that are of current interest to the
user .When reference is made to a file, the current directory is searched .If a file is needed
that is not in the current directory, then the user must either specify a path name or
change the current directory.
Path names can be of two types: Absolute path names or relative path names .An
absolute path name begins at the root and follows a path down to the specified file, giving
the file directory names on the path.
A relative path name defines a path from the current directory. if the current directory is
root/spell/mail, the relative path name prt/first refers to the same file as does the absolute
path name root/spell/mail/prt/first.
AAccyycclliicc--GGrraapphh DDiirreeccttoorriieess
Have shared subdirectories and files
A link is effectively a pointer to another file or subdirectory .For example a link may be
implemented as an absolute or relative path name. When a reference to a file is made, we
OPERATING SYSTEMS
iv -13
search the directory. If the directory entry is marked as a link, then the name of the real
life(or directory )is given.
Hard Links:
A new link or directory entry increments the references count; deleting a link or entry
decrements the count. When the count is 0, the file can be deleted there are no remaining
references to it. The UNIX operating system uses this approach for no symbolic links.
GGeenneerraall GGrraapphh DDiirreeccttoorryy ((CCoonntt..))
How do we guarantee no cycles?
Allow only links to file not subdirectories
Garbage collection
Every time a new link is added use a cycle detection
algorithm to determine whether it is OK
A file system must be mounted before it can be accessed
An unmounted file system (i.e. Fig. 11-11(b)) is mounted at a mount point
The primary advantage of an acyclic graph is the relative simplicity of the algorithms
to traverse the graph and to determine when there are no more references to a file.
The graph and to determine when there are no more references to a file. We want to
avoid traversing shared sections of an cyclic graph twice, mainly for performance
reasons.
OPERATING SYSTEMS
iv -14
11. 4 File System Mounting
File must be opened before it is used, a file system be
mounted before it can be available to processes on the system. The operating system
is given the name of the device and the location within the file structure at which to
attach the file system (or mount point)
Mount point is an empty directory at which the mounted file system will be attached.
A file system containing user’s home directories might be mounted as /home then to
access the directory structure within that files system; one could precede the directory
names with/home as in/home/Jane. Mounting that file system under/users would
result in the path name /users/jane to reach the same directory.
(a) Existing. (b) UnMounted Partition
Where the triangles represent sub trees of directories that are of interest. Fig a an existing
file system is shown while a)un mounted partition residing on device/dsk is shown. At
this point only the files on the existing file system can be accessed. The effects of the
mounting of the partition residing on device/dsk/ over users are shown. If the partition is
unmounted the file system is restored to the situation depicted.
OPERATING SYSTEMS
iv -15
Mount Point
11. 5 File sharing
1. Sharing of files on multi-user systems is desirable
2. Sharing may be done through a protection scheme
3. On distributed systems, files may be shared across a network
4. Network File System (NFS) is a common distributed file-sharing method
User IDs identify users, allowing permissions and protections to be per-user
Group IDs allow users to be in groups, permitting group access rights
 Uses networking to allow file system access between systems
o Manually via programs like FTP
o Automatically, seamlessly using distributed file systems
o Semi automatically via the world wide web
 Client-server model allows clients to mount remote file systems from servers
o Server can serve multiple clients
o Client and user-on-client identification is insecure or complicated
o NFS is standard UNIX client-server file sharing protocol
o CIFS is standard Windows protocol
o Standard operating system file calls are translated into remote calls
 Distributed Information Systems (distributed naming services) such as LDAP,
DNS, NIS, Active Directory implement unified access to information needed for
remote computing
File Sharing – Failure Modes
 Remote file systems add new failure modes, due to network failure, server failure
 Recovery from failure can involve state information about status of each remote
request
 Stateless protocols such as NFS include all information in each request, allowing
easy recovery but less security
OPERATING SYSTEMS
iv -16
File Sharing – Consistency Semantics
 Consistency semantics specify how multiple users are to access a shared file
simultaneously
o Similar to Ch 7 process synchronization algorithms
 Tend to be less complex due to disk I/O and network latency (for
remote file systems
o Andrew File System (AFS) implemented complex remote file sharing
semantics
o Unix file system (UFS) implements:
 Writes to an open file visible immediately to other users of the
same open file
 Sharing file pointer to allow multiple users to read and write
concurrently
o AFS has session semantics
 Writes only visible to sessions starting after the file is closed
11. 6 Protection
To keep it safe from physical damage (reliability) and improper access (protection).
File owner/creator should be able to control:
What can be done?
by whom
Types of access
Protection mechanisms provide controlled access by limiting the types of file access
that can be made. Access is permitted or denied depending on several factors, one of
which is the type of access requested. Several different types of operations may be
controlled.
Read: Read from the file.
Write: Write or rewrite the file.
Execute: Load the file into memory and execute it
Append: Write new information at the end of the file.
Delete: Delete the file and free its space for possible reuse.
List: List the name and attributes of the file.
Access Control
Owner: The user who created the file is the owner.
Group: A set of user who is sharing the file and need similar access is a group, or
work group.
OPERATING SYSTEMS
iv -17
Universe: All other users in the system constitute the universe.
Access Lists and Groups
The most common approach to the protection problem is to make access dependent
on the identity of the user. Various users may need different identity-dependent access is
to associate with each file and directory an Access-Control List(ACL)
 Mode of access: read, write, execute
 Three classes of users
 RWX
 a) owner access 7  1 1 1
RWX
 b) group access 6  1 1 0
 RWX
 c) public access 1  0 0 1
 Ask manager to create a group (unique name), say G, and add some users to the
group.
 For a particular file (say game) or subdirectory, define an appropriate access.
WWiinnddoowwss XXPP AAcccceessss--ccoonnttrrooll LLiisstt MMaannaaggeemmeenntt
OPERATING SYSTEMS
iv -18
CChhaapptteerr 1122:: FFiillee SSyysstteemm IImmpplleemmeennttaattiioonn
1122..11 FFiillee--SSyysstteemm SSttrruuccttuurree
File structure
Logical storage unit
Collection of related information
File system resides on secondary storage (disks)
File system organized into layers
File control block – storage structure consisting of information about a file
 File System Structure
 File-System Implementation
 Directory Implementation
 Allocation Methods
 Free space Management
AA SSaammppllee UUNNIIXX DDiirreeccttoorryy LLiissttiinngg
OPERATING SYSTEMS
iv -19
LLaayyeerreedd FFiillee SSyysstteemm
I/O control:
o The lowest level, the I/O control consists of device drivers and interrupts
handlers to transfer information between the main memory and the disk
system.
 A device driver acts as a translator.
 Its input consists of high level commands such as retrieve block 123.Its output
consists of low-level hardware-specific instructions that are used by the hardware
controller, which interfaces the I/O device to the rest of the system.
 The device driver write specific bit patterns to special locations in the I/O
controllers memory to tell the controller on which device location to act and what
actions to take.
Basic File system
It needs only to issue generic commands to the appropriate device driver
to read and write physical blocks on the disk. Each physical block is identified by its
numeric disk address.
OPERATING SYSTEMS
iv -20
File organization Module:
 It knows about files and their logical blocks as well as physical blocks.
 File organization module can translate logical block addresses to physical block
addresses for the basic file system, to transfer.
 Each file logical blocks are numbered form 0 through n whereas the physical
blocks containing the data usually do not match logical numbers, so a translation
is needed to locate each block.
Logical file system:
1. It manages metadata information.
2. Metadata includes all of the file-system structure excluding the actual data(or
contents of the files).
3. The logical file system manages the directory structure to provide the file-
organization module with the information.
4. It maintains file structure via file control blocks.
5. A file control block (FCB) contains information about file, including
ownership, permissions and location of the file contents.
6. The logical file system is also responsible for protection and security.
AA TTyyppiiccaall FFiillee CCoonnttrrooll BBlloocckk
OPERATING SYSTEMS
iv -21
Application programs:
To create new file, an application program calls the logical file system. The logical file
system knows the format of the directory structures. To create a new file it allocates a
new FCB, reads the appropriate directory into memory updates it with the new file name
and FCB and writes it back to the disk
1122..22 FFiillee SSyysstteemm IImmpplleemmeennttaattiioonn
The on-disk structures include:
A boot control block :
It contains information needed by the system to boot an operating from that
partition.
If the disk does not contain an operating system, this block can be empty.
UNIX file system structure
UNIX File System structure (UFS) Network Transfer File system
(NTFS)
A partition control block:
It contains partition details, such as the number of blocks in the partition size of the
blocks, free-block count and free block pointers and free FCB count and FCB pointers.
Super block:
A directory structure is used to organize the file.
Partition boot sector
Partition control block
Master file table
Data block
Boot control block
Partition control block
Super block
Data block
OPERATING SYSTEMS
iv -22
An FCB contains many of the file’s details including file permissions ownership, size
and location of the data blocks. In UFS this is called the inode.
In NTFS this information is actually stored within the master file table, which uses a
relational data base structure with row per file.
An in-memory partition table containing information about the directory information of
recently accesses directories
The system wide open file table contains a copy of the FCB of each open file as well as
otjher information.
The per process open file table contains a pointer to the appropriate entry in the system
wide open file table as well as other information.
Partitions and mounting:
 The following figure illustrates the necessary file system structures provided by
the operating systems.
 Figure 12-3(a) refers to opening a file.
 Figure 12-3(b) refers to reading a file.
OPERATING SYSTEMS
iv -23
 Each partition can either be raw containing no file system or cooked containing a
file system. Raw disk is used where no file system is appropriate UNIX swap
space can use a raw partition as it uses its own format on disk and does not use a
file system.
 Boot information can be stored in a separate partition.
 It has its own format because at boot time the system does not have file-system
device drivers loaded and therefore cannot interpret the file-system format.
 Sequential series of blocks loaded as an image into memory. Execution of the
image starts at a predefined location such as the first byte.
 This boot image can contain more than the instructions for how to boot a specific
operating system. PCS and other systems can be double booted.
 The root partition which contains the os kernel and other system files is mounted
at boot time. The operating system verifies the device contains a valid file system
.It asks device driver to red the device directory and verifying that the directory
has the expected format. If the format is invalid, the partition must have its
consistency checked and possibly corrected either with or without user
intervention. In Mount table structure that a file system is mounted and the type of
the file system. This detail of this function depends on the operating system.
Virtual file System:
File system implementation consists of three major layers;
The first layer is the file system interface, based on the open, read write and close calls
and file descriptors.
The second layer is called the virtual File system (VFS) layer; it server two important
function
1. It separates file-system operations from their implementation by
defining a clean VFS interface.
2. The VFS is based on a file-representation structure called a vnode,
that contains a numerical designator for a network unique file. This
network wide uniqueness is required for support of network file
OPERATING SYSTEMS
iv -24
systems. The kernel maintains one vnode structure for each active
node(File or directory).
3. VFS distinguishes locakl files from remote ones and local files are
further distinguished according to their file system types.
4. The VFS activates file-system specific operation to handle local
requests according to their file-system types and even calls the
NFS protocol procedures for remote requests.
5. File handlers are constructed from the relevant VNODES and are
passed as arguments to these procedures.
The layer implementing the file-system type or remote file system protocol is the
bottom layer of the architecture
SScchheemmaattiicc VViieeww ooff VViirrttuuaall FFiillee ssyysstteemm
1122..33 DDiirreeccttoorryy IImmpplleemmeennttaattiioonn
Linear List:
 The simplest method of implementing a directory is to use a linear list of file
names with pointers to the data blocks.
 A linear list of directory entries requires a linear search to find a particular entry.
 To create a new file, operating must first search the directory to be sure that no
existing file has the same name. Then operating system adds new entry at the end
of the directory.
OPERATING SYSTEMS
iv -25
 To delete a file, operating system search the directory for the named file then
release the space allocated to it.
 To reuse the directory entry, operating system can do one of several things.
 Os can mark the entry as unused assigning it a special name, such as an all blank
name, or with a used-unused or operating system can attach it to a list of free
directory entries.
 A third alternative is to copy the last entry in the directory into the freed location,
and to decrease the length of the directory.
 A linked list can also be used to decrease the time to delete a file.
Advantage:
This method is simple to program but time consuming to execute.
Disadvantage:
 This linear list of directory entries is the linear search to find a file.
 Directory information is used frequently and users would notice a slow
implementation of access to it.
 Many operating systems implement a software cache to store the most recently
used directory information.
 A cache hit avoids constantly rereading the information from disk.
Hash Table:
Another data structure that has been used for a file directory is a hash table.
The hash table takes a value computed from the file name and returns a pointer to the file
name in the linear list.
It can decrease the directory search time.
If two file names hash to the same location then it is called collisions.
The major difficulties with a hash table are its generally fixed size and the dependence of
the hash function on that size.
Disadvantage:
For example we make a linear probing hash table that holds 64 entries. The hash
function converts names into integer from 0 to 63 for instance by using the remainder of a
division by 64.
OPERATING SYSTEMS
iv -26
If we later try to create a 65th
file, we must enlarge the directory hash table say to 128
entries. As results we need a new hash function that must map file names to the range 0
1o 127.we must reorganize the existing directory entries to reflect their new hash function
1122..44 AAllllooccaattiioonn MMeetthhooddss
An allocation method refers to how disk blocks are allocated for files:
Contiguous allocation
Linked allocation
Indexed allocation
CCoonnttiigguuoouuss AAllllooccaattiioonn
Each file occupies a set of contiguous blocks on the disk
Simple – only starting location (block #) and length (number of blocks) are required
Random access
Wasteful of space (dynamic storage-allocation problem)
Files cannot grow
CCoonnttiigguuoouuss AAllllooccaattiioonn ooff DDiisskk SSppaaccee
LLiinnkkeedd AAllllooccaattiioonn
OPERATING SYSTEMS
iv -27
Each file is a linked list of disk blocks: blocks may be scattered anywhere on the
disk.
LLiinnkkeedd AAllllooccaattiioonn ((CCoonntt..))
Simple – need only starting address
Free-space management system – no waste of space
No random access
Mapping
Block to be accessed is the Qth block in the linked chain of blocks representing
the file.
Displacement into block = R + 1
File-allocation table (FAT) – disk-space allocation used by MS-DOS and OS/2.
lliinnkkeedd AAllllooccaattiioonn
FFiillee--AAllllooccaattiioonn
pointerblock =
LA/511
Q
R
OPERATING SYSTEMS
iv -28
 The FAT allocation scheme can result in a significant number of disk head seeks,
unless the FAT is cached. The disk head must move to the start of the partition to
read the FAT and fine the location of the block in question then move to the
location of the block itself.
 A benefit is that random access time is improved, because the disk head can fine
the location of any block by reading the information
OPERATING SYSTEMS
iv -29
IInnddeexxeedd AAllllooccaattiioonn
Brings all pointers together into the index block.
Logical view.
index table
EExxaammppllee ooff IInnddeexxeedd AAllllooccaattiioonn
OPERATING SYSTEMS
iv -30
IInnddeexxeedd AAllllooccaattiioonn –– MMaappppiinngg ((CCoonntt..))
Mapping from logical to physical in a file of unbounded length (block
size of 512 words).
Linked scheme – Link blocks of index table (no limit on size).
LA / (512 x 511)
Q1
R1
Q1 = block of index table
R1 is used as follows:
R1 / 512
Q2
R2
Q2 = displacement into block of index table
R2 displacement into block of file:
OPERATING SYSTEMS
iv -31
IInnddeexxeedd AAllllooccaattiioonn –– MMaappppiinngg ((CCoonntt..))
Two-level index (maximum file size is 5123
)
LA / (512 x 512)
Q1
R1
Q1 = displacement into outer-index
R1 is used as follows:
R1 / 512
Q2
R2
Q2 = displacement into block of index table
R2 displacement into block of file:
OPERATING SYSTEMS
iv -32
1122..55 FFrreeee--SSppaaccee MMaannaaggeemmeenntt ((CCoonntt..))
 To keep track of free disk space, the system maintains a free space list.
 The free space list records all free disk blocks-those not allocated to some file or
directory.
 To create a file, we search the free space list for the required amount of space and
allocate that space to the new file.
 This space is then removed from the free-space list.
 When a file is deleted, its disk space is added to the free-space list.
The free space list are implemented as follows
1) Bit Vector
The free space list is implemented as a bit map or bit vector. Each block is represented
by 1 bit. If the block is free; the bit is 1; if the block is allocated; the bit is 0.
For example consider a disk where blocks 2,3,4,5,8,9,10,11,12,13,17,18,25,26 and 27 are
free and the rest of the blocks are allocated .The free space bit map would be
0011110011111100000011100000…
IInnddeexxeedd AAllllooccaattiioonn –– MMaappppiinngg ((CCoonntt..))

outer-index
index table file
OPERATING SYSTEMS
iv -33
Advantage:
The main advantage this approach is its relatively simplicity and efficiency in finding the
first free block or n consecutive free blocks on the disk.
2)Linked List
Another method to free space management is to link together all the free disk blocks keeping a
pointer to the first free block in a special location on the disk and caching it in memory.
The first block contains a pointer to the next free disk block and so on.
In our example we would keep a pointer to block 2, as the first free block. Block 2 would contain
a pointer to block 3, which would point to block 4, which would point to block 5, which would
point to block 8 and so on.
FFrreeee--SSppaaccee MMaannaaggeemmeenntt
Bit vector (n blocks)
…
0 1 2 n-1
bit[i] =
0  block[i] free
1  block[i] occupied
Block number calculation
(number of bits per word) *
(number of 0-value words) +
offset of first 1 bit
OPERATING SYSTEMS
iv -34
Disadvantage:
This scheme is not efficient; to traverse the list; It takes more time.
3)Grouping:
This free list approach is to store the addresses of n free blocks in the first free
block. The first n-1 of these blocks are actually free. The last block contains the addresses
of another n free blocks.
Advantage:
That the addresses of a large number of free blocks can be found quickly
4) Counting
Thus ,rather than keeping a list of n free disk addresses ,we can keep the address of the
first free block and the number n of free contiguous blocks that follow the first block.
Each entry in the free space list consists of a disk address and a count.
Disadvantage:
Each entry requires more space than would a simple disk address.
OPERATING SYSTEMS
iv -35
16 marks questions
1. Expalin files system structure
2. Explain the file system implementation
3. Explain how the VFS layer allows an operating system easily to support multiple
types of file systems.
4. Explain the different types of allocation methods
5. Discuss about the free space management
6. Explain directory implementation
***************************

Más contenido relacionado

La actualidad más candente

File management
File managementFile management
File management
Mohd Arif
 
File implementation
File implementationFile implementation
File implementation
Mohd Arif
 
The unix file system
The unix file systemThe unix file system
The unix file system
gsandeepmenon
 

La actualidad más candente (19)

File management
File managementFile management
File management
 
File Management in Operating Systems
File Management in Operating SystemsFile Management in Operating Systems
File Management in Operating Systems
 
Types of files
Types of filesTypes of files
Types of files
 
File management
File managementFile management
File management
 
Ch10
Ch10Ch10
Ch10
 
File Management – File Concept, access methods, File types and File Operation
File Management – File Concept, access methods,  File types and File OperationFile Management – File Concept, access methods,  File types and File Operation
File Management – File Concept, access methods, File types and File Operation
 
File
FileFile
File
 
File system implementation
File system implementationFile system implementation
File system implementation
 
Ch11 file system interface
Ch11 file system interfaceCh11 file system interface
Ch11 file system interface
 
File implementation
File implementationFile implementation
File implementation
 
Chapter 11 - File System Implementation
Chapter 11 - File System ImplementationChapter 11 - File System Implementation
Chapter 11 - File System Implementation
 
File Management
File ManagementFile Management
File Management
 
File system
File systemFile system
File system
 
Files
FilesFiles
Files
 
File System Interface
File System InterfaceFile System Interface
File System Interface
 
The unix file system
The unix file systemThe unix file system
The unix file system
 
Xfs file system for linux
Xfs file system for linuxXfs file system for linux
Xfs file system for linux
 
File structures
File structuresFile structures
File structures
 
OSCh11
OSCh11OSCh11
OSCh11
 

Similar a Unit ivos - file systems

Ch11 OS
Ch11 OSCh11 OS
Ch11 OS
C.U
 
3. distributed file system requirements
3. distributed file system requirements3. distributed file system requirements
3. distributed file system requirements
AbDul ThaYyal
 

Similar a Unit ivos - file systems (20)

Learn about the File Concept in operating systems ppt
Learn about the File Concept in operating systems pptLearn about the File Concept in operating systems ppt
Learn about the File Concept in operating systems ppt
 
Unit 3 file management
Unit 3 file managementUnit 3 file management
Unit 3 file management
 
Unit 3 chapter 1-file management
Unit 3 chapter 1-file managementUnit 3 chapter 1-file management
Unit 3 chapter 1-file management
 
File management
File managementFile management
File management
 
file management_osnotes.ppt
file management_osnotes.pptfile management_osnotes.ppt
file management_osnotes.ppt
 
CH11.pdf
CH11.pdfCH11.pdf
CH11.pdf
 
Chapter 10 - File System Interface
Chapter 10 - File System InterfaceChapter 10 - File System Interface
Chapter 10 - File System Interface
 
Chapter 12.pptx
Chapter 12.pptxChapter 12.pptx
Chapter 12.pptx
 
Ch11 OS
Ch11 OSCh11 OS
Ch11 OS
 
OS_Ch11
OS_Ch11OS_Ch11
OS_Ch11
 
Introduction to File System
Introduction to File SystemIntroduction to File System
Introduction to File System
 
File
FileFile
File
 
File structure
File structureFile structure
File structure
 
File organisation
File organisationFile organisation
File organisation
 
File Management in Operating System
File Management in Operating SystemFile Management in Operating System
File Management in Operating System
 
Directory structure
Directory structureDirectory structure
Directory structure
 
File concept and access method
File concept and access methodFile concept and access method
File concept and access method
 
file management
 file management file management
file management
 
Dude.pptx
Dude.pptxDude.pptx
Dude.pptx
 
3. distributed file system requirements
3. distributed file system requirements3. distributed file system requirements
3. distributed file system requirements
 

Más de donny101 (9)

Unit v
Unit vUnit v
Unit v
 
Unit iv
Unit ivUnit iv
Unit iv
 
Unit iii
Unit iiiUnit iii
Unit iii
 
Unit ii
Unit   iiUnit   ii
Unit ii
 
Unit 1
Unit  1Unit  1
Unit 1
 
Unit vos - File systems
Unit vos - File systemsUnit vos - File systems
Unit vos - File systems
 
Unit iios process scheduling and synchronization
Unit iios process scheduling and synchronizationUnit iios process scheduling and synchronization
Unit iios process scheduling and synchronization
 
Unit iiios Storage Management
Unit iiios Storage ManagementUnit iiios Storage Management
Unit iiios Storage Management
 
Unit 1os processes and threads
Unit 1os processes and threadsUnit 1os processes and threads
Unit 1os processes and threads
 

Último

VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
dharasingh5698
 
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar ≼🔝 Delhi door step de...
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar  ≼🔝 Delhi door step de...Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar  ≼🔝 Delhi door step de...
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar ≼🔝 Delhi door step de...
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
dollysharma2066
 
Standard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power PlayStandard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power Play
Epec Engineered Technologies
 

Último (20)

DC MACHINE-Motoring and generation, Armature circuit equation
DC MACHINE-Motoring and generation, Armature circuit equationDC MACHINE-Motoring and generation, Armature circuit equation
DC MACHINE-Motoring and generation, Armature circuit equation
 
COST-EFFETIVE and Energy Efficient BUILDINGS ptx
COST-EFFETIVE  and Energy Efficient BUILDINGS ptxCOST-EFFETIVE  and Energy Efficient BUILDINGS ptx
COST-EFFETIVE and Energy Efficient BUILDINGS ptx
 
2016EF22_0 solar project report rooftop projects
2016EF22_0 solar project report rooftop projects2016EF22_0 solar project report rooftop projects
2016EF22_0 solar project report rooftop projects
 
Unleashing the Power of the SORA AI lastest leap
Unleashing the Power of the SORA AI lastest leapUnleashing the Power of the SORA AI lastest leap
Unleashing the Power of the SORA AI lastest leap
 
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
 
data_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdfdata_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdf
 
Bhosari ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready For ...
Bhosari ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready For ...Bhosari ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready For ...
Bhosari ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready For ...
 
Thermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.pptThermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.ppt
 
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
 
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar ≼🔝 Delhi door step de...
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar  ≼🔝 Delhi door step de...Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar  ≼🔝 Delhi door step de...
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar ≼🔝 Delhi door step de...
 
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
 
Work-Permit-Receiver-in-Saudi-Aramco.pptx
Work-Permit-Receiver-in-Saudi-Aramco.pptxWork-Permit-Receiver-in-Saudi-Aramco.pptx
Work-Permit-Receiver-in-Saudi-Aramco.pptx
 
Generative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPTGenerative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPT
 
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
 
KubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlyKubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghly
 
Hazard Identification (HAZID) vs. Hazard and Operability (HAZOP): A Comparati...
Hazard Identification (HAZID) vs. Hazard and Operability (HAZOP): A Comparati...Hazard Identification (HAZID) vs. Hazard and Operability (HAZOP): A Comparati...
Hazard Identification (HAZID) vs. Hazard and Operability (HAZOP): A Comparati...
 
Standard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power PlayStandard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power Play
 
(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7
(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7
(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7
 
22-prompt engineering noted slide shown.pdf
22-prompt engineering noted slide shown.pdf22-prompt engineering noted slide shown.pdf
22-prompt engineering noted slide shown.pdf
 
Water Industry Process Automation & Control Monthly - April 2024
Water Industry Process Automation & Control Monthly - April 2024Water Industry Process Automation & Control Monthly - April 2024
Water Industry Process Automation & Control Monthly - April 2024
 

Unit ivos - file systems

  • 1. OPERATING SYSTEMS iv -1 UNIT –IV FILE SYSTEMS
  • 2. OPERATING SYSTEMS iv -2 UNIT –IV FILE SYSTEMS File-system interface: File concept-Access methods-Directory structure-File-system mounting-Protection. File-system implementation: directory implementation-Allocation methods-free-space management-efficiency and performance-recovery-log structures file systems. Case studies: file system in Linux-file system in WindowsXP Chapter 11 FILES SYSTEM INTERFACE File concepts Access methods Directory Structure File system Mounting File sharing Protection 11.1 FILE CONCEPT The file system consists of two distinct parts a collection of files, each storing related data and directory structure, which organizes and provides information about all the file in the system. Some file systems have a third part, partitions, which are used to separate physically or logically large collections of directories. File Attributes  Name – only information kept in human-readable form  Identifier – unique tag (number) identifies file within file system  Type – needed for systems that support different types  Location – pointer to file location on device  Size – current file size  Protection – controls who can do reading, writing, executing  Time, date, and user identification – data for protection, security, and usage monitoring  Information about files are kept in the directory structure, which is maintained on the disk File Operations  File is an abstract data type
  • 3. OPERATING SYSTEMS iv -3 Creating a file: Two steps are necessary to create a file. First space in the file system must be found for the file. The directory entry records the name of the file and the location in the file system and possibly other information. Writing a file: To write a file, we make a system call specifying both the name of the file and the information to be written to the file. Given the name of the file, the system searches the directory to find the location of the file. The system must keep a write pointer to the location in the file where the next write is to take place. The write pointer must be updated whenever a write is is to take place .The write pointer must be updated whenever a write occurs. Reading file: To read from a file, we use a system call that specifies the name of the file and where the next block of the file should be put. Again the directory is searched for searched for the associated directory entry and the system needs to keep a read pointer to the location in the file where the next read is to take place. Once the read has taken place, the read pointer is updated. A given process is usually only reading or writing a given file and the current operation location is kept. Current file position pointer is used to save and reducing the system. Reposition within file The directory is searched for the appropriate entry and the current file position is set to a given value. Repositioning within a file does not need to involve any actual I/O. This file operation also known as a file seek.  Deleting a file: To delete a file, we search the directory for the named file having found the associated directory entry, we release all file space, so that it can be reused by other files and erase the directory entry.  Truncating a file: The user may want to release the contents of a file but keep its attributes. Rather that forcing the user to delete the file and then recreate it this function allows all attributes to remain unchanged- except for file length-but lets the file be rest to length zero and its file space released.  Open(Fi) – search the directory structure on disk for entry Fi, and move the content of entry to memory
  • 4. OPERATING SYSTEMS iv -4  Close (Fi) – move the content of entry Fi in memory to directory structure on disk Several pieces of data are needed to manage open files: o File pointer: pointer to last read/write location, per process that has the file open o File-open count: counter of number of times a file is open – to allow removal of data from open-file table when last processes closes it o Disk location of the file: cache of data access information o Access rights: per-process access mode information File Types – Name, Extension 11.2Access Methods  Sequential Access  read next  write next  reset  no read after last write  (rewrite)  Direct Access  read n  write n  position to n  read next  write next
  • 5. OPERATING SYSTEMS iv -5  rewrite n o n = relative block number Sequential-access File 1. The simplest access method is sequential access. Information in the file is processed in order, one record after the other. 2. This mode of access A read operation reads the next portion of the file and automatically advances a file pointer, 3. A file can be reset to the beginning and on some systems, a program may be able to skip forward or backward n records, for integer n . 4. Sequential access is based on tape model of a file and works as well on sequential –access devices as it does on random-access ones. Simulation of Sequential Access on a Direct-access File 1. Another method is direct access(or relative access).A file is made up of fixed length logical records that allow programs to tread write records rapidly in no particular order. 2. The direct access method is based on a disk model of a file is viewed as a numbered sequence of blocks or records. 3. A direct-access file allows arbitrary blocks to be read or written. Thus we may read block 14 then read blocks 53, and then write block 7.There are no restriction on the order of reading or writing for a direct-access file.
  • 6. OPERATING SYSTEMS iv -6 4. The block number provided by the user to the operating system is normally a relative block number. A relative block number is an index relative to the beginning of the file. 5. Thus the first relative block of the file is 0, the next is 1 and so on, even though the actual absolute disk address of the block may be 14703 for the first block and 3192 for the second. 6. The use of relative block numbers allows the operating system to decide where the file should be placed 7. Cp that defines our current position then we can simulate sequential file operations, 8.Given a logical record length L, a request for record N is turned into an I/O request for L bytes starting at location L*(N-) within the file. Example of Index and Relative Files These methods generally involve the construction of an index for the file .The index like an index in the back of a book, contains pointers to the various blocks. To find a record in the file, we first search the index, and then use the pointer to access the file directly and to find the desired record. With large files, the index file itself may become too large to be kept in index file would contain pointers to secondary memory. One solution is to create an index for the index file. The primary index file would contain pointers to secondary index files, which would point to the actual data items.
  • 7. OPERATING SYSTEMS iv -7 Example: IBMS indexed sequential-access method (ISAM) uses a small master index that points to disk blocks of secondary index. The secondary index blocks point to the actual file blocks. The file is kept sorted on a defined key. To find a particular item, we first make a binary search of the master index, which provides the block number of the secondary index .This block is read in and again a binary search is used to find the block containing the desired record. This block is searched sequentially.
  • 8. OPERATING SYSTEMS iv -8 Operations Performed on Directory  Search for a file: To fine the entry for a particular file. Since files have symbolic names and similar names may indicate a relationship between files, we may want to be able to find all files whose names match a particular pattern.  Create a file: New files need to be created and added to the directory.  Delete a file: When a file is no longer needed ,we want to remove it from the directory.  List a directory: we need to be able to list the file in a directory and the contents of the directory entry for each file in the list. Rename a file: Because the name of a file represents its contents to its users the name must be changeable when the contents or use of the file changes Backups of these two structures are kept on tapes 1111..33 DDiirreeccttoorryy SSttrruuccttuurree A collection of nodes containing information about all files F 1 F 2 F 3 F 4 F n Directory Files Both the directory structure and the files reside on disk Backups of these two structures are kept on tapes
  • 9. OPERATING SYSTEMS iv -9  renaming a file may also allow its position within the directory structure to be changed  Traverse the file system: we may wish to access every directory and every file within a directory structure. For reliability, it is good idea to save the contents and structure of the entire file system at regular intervals. This saving often consists of copying all files to magnetic tape.  Efficiency – locating a file quickly  Naming – convenient to users  Two users can have same name for different files  The same file can have several different names  Grouping – logical grouping of files by properties, (e.g., all Java programs, all games, …) SSiinnggllee--LLeevveell DDiirreeccttoorryy The simplest directory structure is the single-level directory. All the files are contained in the same directory, which is easy to support and understand. A single directory for all users Naming problem: when the number of files increases or when the system has more than one user. Since all files are in the same directory, they must have unique names. If two users call their data file test, then the unique names. If two users call their data file test, then the unique-name rule is violated. Grouping problem:
  • 10. OPERATING SYSTEMS iv -10 TTwwoo--LLeevveell DDiirreeccttoorryy Separate directory for each user In the two level directory structures, each user has her own user file directory (UFD). Each UFD has a similar structure, but lists only the files of single user. When a user job starts or a user logs in, the system’s master file directory (MFD) is searched. The MFD is indexed by user name or account number, and each entry points to the UFD for that user. To create a file for a user, the operating system searches only that user’s UFD to ascertain whether another file of that name exists. To delete a file, the operating system confines its search to the local UFD Thus, it cannot accidentally delete another user’s file that has the same name. Path name Can have the same file name for different user Efficient searching No grouping capability
  • 11. OPERATING SYSTEMS iv -11 TTrreeee--SSttrruuccttuurreedd DDiirreeccttoorriieess Tree-Structured Directories (Cont)  Efficient searching  Grouping Capability  Current directory (working directory) o cd /spell/mail/prog o type list TTrreeee--SSttrruuccttuurreedd DDiirreeccttoorriieess ((CCoonntt)) Absolute or relative path name Creating a new file is done in current directory Delete a file rm <file-name> Creating a new subdirectory is done in current directory mkdir <dir-name> Example: if in current directory /mail mkdir count Mail progcopy prt exp count
  • 12. OPERATING SYSTEMS iv -12 Deleting “mail”  deleting the entire subtree rooted by “mail” A directory (or subdirectory) contains a set of files or subdirectories. A directory is simply another file, but it is treated in a special way. All directories have the same internal format. One bit in each directory entry defines the entry as a file (0) or as a subdirectory (1).Special system calls are used to create and delete directories. The current directory should contain most of the files that are of current interest to the user .When reference is made to a file, the current directory is searched .If a file is needed that is not in the current directory, then the user must either specify a path name or change the current directory. Path names can be of two types: Absolute path names or relative path names .An absolute path name begins at the root and follows a path down to the specified file, giving the file directory names on the path. A relative path name defines a path from the current directory. if the current directory is root/spell/mail, the relative path name prt/first refers to the same file as does the absolute path name root/spell/mail/prt/first. AAccyycclliicc--GGrraapphh DDiirreeccttoorriieess Have shared subdirectories and files A link is effectively a pointer to another file or subdirectory .For example a link may be implemented as an absolute or relative path name. When a reference to a file is made, we
  • 13. OPERATING SYSTEMS iv -13 search the directory. If the directory entry is marked as a link, then the name of the real life(or directory )is given. Hard Links: A new link or directory entry increments the references count; deleting a link or entry decrements the count. When the count is 0, the file can be deleted there are no remaining references to it. The UNIX operating system uses this approach for no symbolic links. GGeenneerraall GGrraapphh DDiirreeccttoorryy ((CCoonntt..)) How do we guarantee no cycles? Allow only links to file not subdirectories Garbage collection Every time a new link is added use a cycle detection algorithm to determine whether it is OK A file system must be mounted before it can be accessed An unmounted file system (i.e. Fig. 11-11(b)) is mounted at a mount point The primary advantage of an acyclic graph is the relative simplicity of the algorithms to traverse the graph and to determine when there are no more references to a file. The graph and to determine when there are no more references to a file. We want to avoid traversing shared sections of an cyclic graph twice, mainly for performance reasons.
  • 14. OPERATING SYSTEMS iv -14 11. 4 File System Mounting File must be opened before it is used, a file system be mounted before it can be available to processes on the system. The operating system is given the name of the device and the location within the file structure at which to attach the file system (or mount point) Mount point is an empty directory at which the mounted file system will be attached. A file system containing user’s home directories might be mounted as /home then to access the directory structure within that files system; one could precede the directory names with/home as in/home/Jane. Mounting that file system under/users would result in the path name /users/jane to reach the same directory. (a) Existing. (b) UnMounted Partition Where the triangles represent sub trees of directories that are of interest. Fig a an existing file system is shown while a)un mounted partition residing on device/dsk is shown. At this point only the files on the existing file system can be accessed. The effects of the mounting of the partition residing on device/dsk/ over users are shown. If the partition is unmounted the file system is restored to the situation depicted.
  • 15. OPERATING SYSTEMS iv -15 Mount Point 11. 5 File sharing 1. Sharing of files on multi-user systems is desirable 2. Sharing may be done through a protection scheme 3. On distributed systems, files may be shared across a network 4. Network File System (NFS) is a common distributed file-sharing method User IDs identify users, allowing permissions and protections to be per-user Group IDs allow users to be in groups, permitting group access rights  Uses networking to allow file system access between systems o Manually via programs like FTP o Automatically, seamlessly using distributed file systems o Semi automatically via the world wide web  Client-server model allows clients to mount remote file systems from servers o Server can serve multiple clients o Client and user-on-client identification is insecure or complicated o NFS is standard UNIX client-server file sharing protocol o CIFS is standard Windows protocol o Standard operating system file calls are translated into remote calls  Distributed Information Systems (distributed naming services) such as LDAP, DNS, NIS, Active Directory implement unified access to information needed for remote computing File Sharing – Failure Modes  Remote file systems add new failure modes, due to network failure, server failure  Recovery from failure can involve state information about status of each remote request  Stateless protocols such as NFS include all information in each request, allowing easy recovery but less security
  • 16. OPERATING SYSTEMS iv -16 File Sharing – Consistency Semantics  Consistency semantics specify how multiple users are to access a shared file simultaneously o Similar to Ch 7 process synchronization algorithms  Tend to be less complex due to disk I/O and network latency (for remote file systems o Andrew File System (AFS) implemented complex remote file sharing semantics o Unix file system (UFS) implements:  Writes to an open file visible immediately to other users of the same open file  Sharing file pointer to allow multiple users to read and write concurrently o AFS has session semantics  Writes only visible to sessions starting after the file is closed 11. 6 Protection To keep it safe from physical damage (reliability) and improper access (protection). File owner/creator should be able to control: What can be done? by whom Types of access Protection mechanisms provide controlled access by limiting the types of file access that can be made. Access is permitted or denied depending on several factors, one of which is the type of access requested. Several different types of operations may be controlled. Read: Read from the file. Write: Write or rewrite the file. Execute: Load the file into memory and execute it Append: Write new information at the end of the file. Delete: Delete the file and free its space for possible reuse. List: List the name and attributes of the file. Access Control Owner: The user who created the file is the owner. Group: A set of user who is sharing the file and need similar access is a group, or work group.
  • 17. OPERATING SYSTEMS iv -17 Universe: All other users in the system constitute the universe. Access Lists and Groups The most common approach to the protection problem is to make access dependent on the identity of the user. Various users may need different identity-dependent access is to associate with each file and directory an Access-Control List(ACL)  Mode of access: read, write, execute  Three classes of users  RWX  a) owner access 7  1 1 1 RWX  b) group access 6  1 1 0  RWX  c) public access 1  0 0 1  Ask manager to create a group (unique name), say G, and add some users to the group.  For a particular file (say game) or subdirectory, define an appropriate access. WWiinnddoowwss XXPP AAcccceessss--ccoonnttrrooll LLiisstt MMaannaaggeemmeenntt
  • 18. OPERATING SYSTEMS iv -18 CChhaapptteerr 1122:: FFiillee SSyysstteemm IImmpplleemmeennttaattiioonn 1122..11 FFiillee--SSyysstteemm SSttrruuccttuurree File structure Logical storage unit Collection of related information File system resides on secondary storage (disks) File system organized into layers File control block – storage structure consisting of information about a file  File System Structure  File-System Implementation  Directory Implementation  Allocation Methods  Free space Management AA SSaammppllee UUNNIIXX DDiirreeccttoorryy LLiissttiinngg
  • 19. OPERATING SYSTEMS iv -19 LLaayyeerreedd FFiillee SSyysstteemm I/O control: o The lowest level, the I/O control consists of device drivers and interrupts handlers to transfer information between the main memory and the disk system.  A device driver acts as a translator.  Its input consists of high level commands such as retrieve block 123.Its output consists of low-level hardware-specific instructions that are used by the hardware controller, which interfaces the I/O device to the rest of the system.  The device driver write specific bit patterns to special locations in the I/O controllers memory to tell the controller on which device location to act and what actions to take. Basic File system It needs only to issue generic commands to the appropriate device driver to read and write physical blocks on the disk. Each physical block is identified by its numeric disk address.
  • 20. OPERATING SYSTEMS iv -20 File organization Module:  It knows about files and their logical blocks as well as physical blocks.  File organization module can translate logical block addresses to physical block addresses for the basic file system, to transfer.  Each file logical blocks are numbered form 0 through n whereas the physical blocks containing the data usually do not match logical numbers, so a translation is needed to locate each block. Logical file system: 1. It manages metadata information. 2. Metadata includes all of the file-system structure excluding the actual data(or contents of the files). 3. The logical file system manages the directory structure to provide the file- organization module with the information. 4. It maintains file structure via file control blocks. 5. A file control block (FCB) contains information about file, including ownership, permissions and location of the file contents. 6. The logical file system is also responsible for protection and security. AA TTyyppiiccaall FFiillee CCoonnttrrooll BBlloocckk
  • 21. OPERATING SYSTEMS iv -21 Application programs: To create new file, an application program calls the logical file system. The logical file system knows the format of the directory structures. To create a new file it allocates a new FCB, reads the appropriate directory into memory updates it with the new file name and FCB and writes it back to the disk 1122..22 FFiillee SSyysstteemm IImmpplleemmeennttaattiioonn The on-disk structures include: A boot control block : It contains information needed by the system to boot an operating from that partition. If the disk does not contain an operating system, this block can be empty. UNIX file system structure UNIX File System structure (UFS) Network Transfer File system (NTFS) A partition control block: It contains partition details, such as the number of blocks in the partition size of the blocks, free-block count and free block pointers and free FCB count and FCB pointers. Super block: A directory structure is used to organize the file. Partition boot sector Partition control block Master file table Data block Boot control block Partition control block Super block Data block
  • 22. OPERATING SYSTEMS iv -22 An FCB contains many of the file’s details including file permissions ownership, size and location of the data blocks. In UFS this is called the inode. In NTFS this information is actually stored within the master file table, which uses a relational data base structure with row per file. An in-memory partition table containing information about the directory information of recently accesses directories The system wide open file table contains a copy of the FCB of each open file as well as otjher information. The per process open file table contains a pointer to the appropriate entry in the system wide open file table as well as other information. Partitions and mounting:  The following figure illustrates the necessary file system structures provided by the operating systems.  Figure 12-3(a) refers to opening a file.  Figure 12-3(b) refers to reading a file.
  • 23. OPERATING SYSTEMS iv -23  Each partition can either be raw containing no file system or cooked containing a file system. Raw disk is used where no file system is appropriate UNIX swap space can use a raw partition as it uses its own format on disk and does not use a file system.  Boot information can be stored in a separate partition.  It has its own format because at boot time the system does not have file-system device drivers loaded and therefore cannot interpret the file-system format.  Sequential series of blocks loaded as an image into memory. Execution of the image starts at a predefined location such as the first byte.  This boot image can contain more than the instructions for how to boot a specific operating system. PCS and other systems can be double booted.  The root partition which contains the os kernel and other system files is mounted at boot time. The operating system verifies the device contains a valid file system .It asks device driver to red the device directory and verifying that the directory has the expected format. If the format is invalid, the partition must have its consistency checked and possibly corrected either with or without user intervention. In Mount table structure that a file system is mounted and the type of the file system. This detail of this function depends on the operating system. Virtual file System: File system implementation consists of three major layers; The first layer is the file system interface, based on the open, read write and close calls and file descriptors. The second layer is called the virtual File system (VFS) layer; it server two important function 1. It separates file-system operations from their implementation by defining a clean VFS interface. 2. The VFS is based on a file-representation structure called a vnode, that contains a numerical designator for a network unique file. This network wide uniqueness is required for support of network file
  • 24. OPERATING SYSTEMS iv -24 systems. The kernel maintains one vnode structure for each active node(File or directory). 3. VFS distinguishes locakl files from remote ones and local files are further distinguished according to their file system types. 4. The VFS activates file-system specific operation to handle local requests according to their file-system types and even calls the NFS protocol procedures for remote requests. 5. File handlers are constructed from the relevant VNODES and are passed as arguments to these procedures. The layer implementing the file-system type or remote file system protocol is the bottom layer of the architecture SScchheemmaattiicc VViieeww ooff VViirrttuuaall FFiillee ssyysstteemm 1122..33 DDiirreeccttoorryy IImmpplleemmeennttaattiioonn Linear List:  The simplest method of implementing a directory is to use a linear list of file names with pointers to the data blocks.  A linear list of directory entries requires a linear search to find a particular entry.  To create a new file, operating must first search the directory to be sure that no existing file has the same name. Then operating system adds new entry at the end of the directory.
  • 25. OPERATING SYSTEMS iv -25  To delete a file, operating system search the directory for the named file then release the space allocated to it.  To reuse the directory entry, operating system can do one of several things.  Os can mark the entry as unused assigning it a special name, such as an all blank name, or with a used-unused or operating system can attach it to a list of free directory entries.  A third alternative is to copy the last entry in the directory into the freed location, and to decrease the length of the directory.  A linked list can also be used to decrease the time to delete a file. Advantage: This method is simple to program but time consuming to execute. Disadvantage:  This linear list of directory entries is the linear search to find a file.  Directory information is used frequently and users would notice a slow implementation of access to it.  Many operating systems implement a software cache to store the most recently used directory information.  A cache hit avoids constantly rereading the information from disk. Hash Table: Another data structure that has been used for a file directory is a hash table. The hash table takes a value computed from the file name and returns a pointer to the file name in the linear list. It can decrease the directory search time. If two file names hash to the same location then it is called collisions. The major difficulties with a hash table are its generally fixed size and the dependence of the hash function on that size. Disadvantage: For example we make a linear probing hash table that holds 64 entries. The hash function converts names into integer from 0 to 63 for instance by using the remainder of a division by 64.
  • 26. OPERATING SYSTEMS iv -26 If we later try to create a 65th file, we must enlarge the directory hash table say to 128 entries. As results we need a new hash function that must map file names to the range 0 1o 127.we must reorganize the existing directory entries to reflect their new hash function 1122..44 AAllllooccaattiioonn MMeetthhooddss An allocation method refers to how disk blocks are allocated for files: Contiguous allocation Linked allocation Indexed allocation CCoonnttiigguuoouuss AAllllooccaattiioonn Each file occupies a set of contiguous blocks on the disk Simple – only starting location (block #) and length (number of blocks) are required Random access Wasteful of space (dynamic storage-allocation problem) Files cannot grow CCoonnttiigguuoouuss AAllllooccaattiioonn ooff DDiisskk SSppaaccee LLiinnkkeedd AAllllooccaattiioonn
  • 27. OPERATING SYSTEMS iv -27 Each file is a linked list of disk blocks: blocks may be scattered anywhere on the disk. LLiinnkkeedd AAllllooccaattiioonn ((CCoonntt..)) Simple – need only starting address Free-space management system – no waste of space No random access Mapping Block to be accessed is the Qth block in the linked chain of blocks representing the file. Displacement into block = R + 1 File-allocation table (FAT) – disk-space allocation used by MS-DOS and OS/2. lliinnkkeedd AAllllooccaattiioonn FFiillee--AAllllooccaattiioonn pointerblock = LA/511 Q R
  • 28. OPERATING SYSTEMS iv -28  The FAT allocation scheme can result in a significant number of disk head seeks, unless the FAT is cached. The disk head must move to the start of the partition to read the FAT and fine the location of the block in question then move to the location of the block itself.  A benefit is that random access time is improved, because the disk head can fine the location of any block by reading the information
  • 29. OPERATING SYSTEMS iv -29 IInnddeexxeedd AAllllooccaattiioonn Brings all pointers together into the index block. Logical view. index table EExxaammppllee ooff IInnddeexxeedd AAllllooccaattiioonn
  • 30. OPERATING SYSTEMS iv -30 IInnddeexxeedd AAllllooccaattiioonn –– MMaappppiinngg ((CCoonntt..)) Mapping from logical to physical in a file of unbounded length (block size of 512 words). Linked scheme – Link blocks of index table (no limit on size). LA / (512 x 511) Q1 R1 Q1 = block of index table R1 is used as follows: R1 / 512 Q2 R2 Q2 = displacement into block of index table R2 displacement into block of file:
  • 31. OPERATING SYSTEMS iv -31 IInnddeexxeedd AAllllooccaattiioonn –– MMaappppiinngg ((CCoonntt..)) Two-level index (maximum file size is 5123 ) LA / (512 x 512) Q1 R1 Q1 = displacement into outer-index R1 is used as follows: R1 / 512 Q2 R2 Q2 = displacement into block of index table R2 displacement into block of file:
  • 32. OPERATING SYSTEMS iv -32 1122..55 FFrreeee--SSppaaccee MMaannaaggeemmeenntt ((CCoonntt..))  To keep track of free disk space, the system maintains a free space list.  The free space list records all free disk blocks-those not allocated to some file or directory.  To create a file, we search the free space list for the required amount of space and allocate that space to the new file.  This space is then removed from the free-space list.  When a file is deleted, its disk space is added to the free-space list. The free space list are implemented as follows 1) Bit Vector The free space list is implemented as a bit map or bit vector. Each block is represented by 1 bit. If the block is free; the bit is 1; if the block is allocated; the bit is 0. For example consider a disk where blocks 2,3,4,5,8,9,10,11,12,13,17,18,25,26 and 27 are free and the rest of the blocks are allocated .The free space bit map would be 0011110011111100000011100000… IInnddeexxeedd AAllllooccaattiioonn –– MMaappppiinngg ((CCoonntt..))  outer-index index table file
  • 33. OPERATING SYSTEMS iv -33 Advantage: The main advantage this approach is its relatively simplicity and efficiency in finding the first free block or n consecutive free blocks on the disk. 2)Linked List Another method to free space management is to link together all the free disk blocks keeping a pointer to the first free block in a special location on the disk and caching it in memory. The first block contains a pointer to the next free disk block and so on. In our example we would keep a pointer to block 2, as the first free block. Block 2 would contain a pointer to block 3, which would point to block 4, which would point to block 5, which would point to block 8 and so on. FFrreeee--SSppaaccee MMaannaaggeemmeenntt Bit vector (n blocks) … 0 1 2 n-1 bit[i] = 0  block[i] free 1  block[i] occupied Block number calculation (number of bits per word) * (number of 0-value words) + offset of first 1 bit
  • 34. OPERATING SYSTEMS iv -34 Disadvantage: This scheme is not efficient; to traverse the list; It takes more time. 3)Grouping: This free list approach is to store the addresses of n free blocks in the first free block. The first n-1 of these blocks are actually free. The last block contains the addresses of another n free blocks. Advantage: That the addresses of a large number of free blocks can be found quickly 4) Counting Thus ,rather than keeping a list of n free disk addresses ,we can keep the address of the first free block and the number n of free contiguous blocks that follow the first block. Each entry in the free space list consists of a disk address and a count. Disadvantage: Each entry requires more space than would a simple disk address.
  • 35. OPERATING SYSTEMS iv -35 16 marks questions 1. Expalin files system structure 2. Explain the file system implementation 3. Explain how the VFS layer allows an operating system easily to support multiple types of file systems. 4. Explain the different types of allocation methods 5. Discuss about the free space management 6. Explain directory implementation ***************************