Chapter File Allocation Methods and Free Space Management
Chapter File Allocation Methods and Free Space Management
File Management
• File Management:
– Ensure consistency of data when multiple users access the files
– Provides measures for file security and protection
File Concept
• File is a sequence of bits, bytes, lines, or records, the
meaning of which is defined by the file’s creator and user.
• Field
• Record
• File
• Data Base
File Attributes
• Name – Name is usually a string of characters
• 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 – Access Permissions, 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
All operations involve some system calls
1. Create: using a specific system call. Two steps are
necessary to create a file.
2. Open a file
3. Delete a file
4. Write in to file
5. Close
6. Reposition within file
Directory Structure
• Symbol table of files that stores all related information about a
file it holds with its contents
Directory
F1 F2 F3 F4
Fn
Files
Operations:
• Search for a file
• Create a file
• Delete a file
• List a directory
• Rename a file
• Traverse the file system : Search all directories/ sub directories
and files
Directory Schemes
1. Single Level Directory
One directory many 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.
• Three has Root directory and files have unique file names
Paths
• Absolute Path: Begins at the root and follows a path down to the
specified file giving directory names on the path.
Only hash table entries are checked using the key and if an
entry found then the corresponding file will be fetched using
the value.
Allocation Methods
• Files are stored on disk
• Problems:
• Finding space for new file
• External fragmentation
• Determining space requirement of a file
Allocation Methods
1. Contiguous File Allocation
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
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.
• 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
E.g., Block 2 contains address of next 5 free blocks (3, 4, 5, 9, 10) out of
which blocks 3, 4, 5 and 9 are free while block 10 contains the
address of next five free blocks.
Grouping
4. Counting:
This method keeps the address of first free block and number of free
contiguous blocks that follow the free block.
MCQ