File System Interface (1)
File System Interface (1)
• File Management:
– Ensure consistency of data when multiple users access the files
– Provides measures for file security and protection
Directory
F1 F2 F3 F4
Fn
Files
Single-Level Directory
• UFDs have the similar structure, but each lists files of a single user.
Tree Structure
• Users can create their sub directories to manage the files.
• Tree has Root directory and files have unique file names
users
Paths
• Absolute Path: Begins at the root and follows a path down to the
specified file giving directory names on the path.
• Relative Path: Defines a path from the current directory.
• 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>
Delete Directory:
2 Hash Table
• A hash table can also be used to speed up searches.
• Implementation is by using Hash value.
• (Division/Variant Method)
Chapter 11: Implementing File-System
File System Structure
• File System resides on Secondary Storage
read next: reads a portion of the file (read record) and automatically
updates pointer. (move pointer to next location)
write next: Append to end of the file (write and update the pointer.
rewind or reset: to reset the file from beginning
Access Methods
2. Direct Access: Or Relative access
• A file is made up of fixed length logical records that allow
programs to read and write records rapidly in no particular
order.
• For Direct Access, File is a numbered sequence of blocks or
records.
read n
write n
position to n (jump to record n)
read next
write next
n = relative block number
• First Relative Block of file is 0, Second is 1 and so on.
Absolute address could be anything.
Indexed Access
• Index is created for file.
• Index contain pointers for various
blocks of a file.
• To find the record in the file, search
the index and then use the pointer
to access the file directly and to find
the desired record.
• An indexed file is a computer
file with an index that allows
easy random access to
any record given its file key.
• The key must be such that it
uniquely identifies a record.
• A relative file is a file in which each
record is identified by its ordinal
position in the file
Allocation Methods
• Files are stored on disk
Directory entry for each file = Address of the starting block and
length of area allocated.
Best suited:
a) For Sequential Access: File system remembers disk address
of the last block referenced and reads next block when
required.
b) For Direct Access: Direct Access to block i of a file that starts
at block b, block b+i can be accessed immediately.
Contiguous Allocation
• Problems can arise:
– Finding space for a new file
– When files grow
– if the exact size of a file is
unknown at creation time
– Suffers from problem of
external fragmentation.
– Difficult to know how much
space is needed for a file
– Alot of space becomes
unusable before the file fills
the space
Linked Allocation
• Each file is a linked list of disk blocks
• Disk blocks can be scattered any where in disk
• Directory contains a pointer to first and last block of the
file.
• Exp: if file of 5 blocks might start at block 9, continue at
block 16, then block 1, block 10 and finally block 25.
• Each block contains a pointer to next block.
• If each block is 512 bytes and disk address requires 4
bytes then user see block of 508 bytes
• To create a new file , create a new entry in directory
• Each directory has a entry has a pointer to first disk
block of file.
• Pointer is initialized to NIL and size / data part is set to 0
Linked Allocation
• Disk files can be stored as linked lists
• Linked allocation does not require pre-known file
sizes, and allows files to grow dynamically at any time.
Drawback
• It is efficient for sequential access files
• To find ith block of a file, we must start at the beginning
of that file and follow the pointers until we go to ith block.
• Requires extra space for pointers
• Multi-Level Index -
Counting:
This method keeps the address of first free block and number of free
contiguous blocks that follow the free block,
(X100 + 10 free blocks)
Mounting
Mount: Mounting makes file systems, files, directories, devices
and special files available for use and available to the user.
Multiple users:
1. Access Control
Permissions:
Read
Write
Execute
Chmod 777 filename
2. Password Protection
File System Mounting
• A file system must be mounted before it can be accessed
• A unmounted file system (i.e. Fig. 11-11(b)) is mounted at a mount
point
(a) Existing. (b) Unmounted Partition
Mount Point
File Sharing
• Sharing of files on multi-user systems is desirable
• Types of access
– Read
Protection
– Write
– Execute
– Append
– Delete
– List
Access Lists and Groups
• Mode of access: read, write, execute
• Three classes of users
RWX
a) owner access 7 111
RWX
b) group access 6 110
RWX
c) public access 1 001
• 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.