Unit IV - File Management
Unit IV - File Management
Unit IV
File Management
• The OS abstracts from the physical properties of its storage devices to define a
logical storage unit, the file.
• Name - Some systems give special significance to names, and particularly extensions (
.exe, .txt, etc. ), and some do not. Some extensions may be of significance to the OS ( .exe
), and others only to certain applications ( .jpg )
• Size
• Protection
• User ID
06-05-2025 ©Operating Systems @ Srilakshmi V 3
File Operations
• Creating a file
• Writing a file
• Reading a file
• Deleting a file
• Truncating a file.
• Disk files are accessed in units of physical blocks, typically 512 bytes or some
power-of-two multiple thereof.
• The number of logical units which fit into one physical block determines
its packing and has an impact on the amount of internal fragmentation
( wasted space ) that occurs.
• As a general rule, half a physical block is wasted for each file, and the larger the
block sizes the more space is lost to internal fragmentation.
• Sequential Access
• Direct Access
• read next - read a record and advance the tape to the next position.
• write next - write a record and advance the tape to the next position.
• rewind
• An indexed access scheme can be easily built on top of a direct access system.
• Very large files may require a multi-tiered indexing scheme, i.e. indexes of
indexes.
• Or, multiple physical disks can be combined into one volume, i.e. a
larger virtual disk, with its own filesystem spanning the physical disks.
• A master file directory is used to keep track of each users directory, and must be
maintained when users are added to or removed from the system.
• Systems may or may not allow users to access other directories besides their
own
• Each user / process has the concept of a current directory from which
all ( relative ) searches take place.
• UNIX provides two types of links for implementing the acyclic-graph structure.
• A hard link ( usually just called a link ) involves multiple directory entries that both refer to
the same file.
• A symbolic link, that involves a special file, containing information about where to find the
linked file.
• Hard links require a reference count, or link count for each file, keeping track of how many
directory entries are currently referring to this file.
• Whenever one of the references is removed the link count is reduced, and when it reaches zero,
the disk space can be reclaimed.
• An allocation method refers to how disk blocks are allocated for files:
• Problems include finding space for file, knowing file size, external
fragmentation, need for compaction
• Each file is a linked list of disk blocks: blocks may be scattered anywhere
on the disk
• Each file has its own index block(s) of pointers to its data blocks
• Logical view
0 1 2 n-1
(number of bits per word) *
…
(number of 0-value words) +
offset of first 1 bit
1 block[i] free
bit[i] =
0 block[i] occupied
No waste of space
• Grouping
• Modify linked list to store address of next n-1 free blocks in first free block,
plus a pointer to next block that contains free-block-pointers (like this one)
• Counting
• Because space is frequently contiguously used and freed, with contiguous-
allocation allocation, extents, or clustering
• Keep address of first free block and count of following free blocks
• Free space list then has entries containing addresses and counts
• The new directory then can be added to the end of the list or at the beginning of the
list.
• In order to delete a file, we first search the directory with the name of the file to be
deleted. After searching we can delete that file by releasing the space allocated to it.
• To reuse the directory entry we can mark that entry as unused or we can append it
to the list of free directories.
• To delete a file linked list is the best choice as it takes less time.
• In the hash table for each pair in the directory key-value pair is generated. The
hash function on the file name determines the key and this key points to the
corresponding file stored in the directory.
• This method efficiently decreases the directory search time as the entire list will
not be searched on every operation. Using the keys the hash table entries are
checked and when the file is found it is fetched.