File System Flashcards
What is the File System for?
File System provides:
- Large and cheap storage space
- Non-volatility
- Sharing information between processes
What is a File System?
It is a collection of files + directory structures
What are files?
A container for storing information.
File abstracts away the different kinds of information into a single struct - devices, pipes, text files, data files.
Where are files stored?
Generally, they are stored on disk.
what are the different kinds of representations a file has?
Three kinds of files:
- byte sequence
- record sequence
- tree of records
What kind of types a file has?
User files:
- ASCII
- Binary
System files
- Directories
- Special files
How many kinds of access-to-file we have?
Sequential access:
- Read all bytes/records from the beginning
- cannot jump around
Random access
- bytes/records read in any order
- All files of modren OSs are random access
-
read/write functions can
- recieve an offset parameter
-
seek(offset, start_from)
-
start_from = {0,1,2}
- 0 - beginning
- 1 - current
- 2 - end
-
start_from = {0,1,2}
What are the file attributes?
General info - user ID, Group ID, dates, times
Location & size - pointer to a device and location on it
Flags that store information for the system
Another special flags - Protection, password..
What are the file’s operations?
Create ; Delete
Open ; Close
Write ; Read ; Seek
Get attributes
Set attributes
What are the directory’s operations?
Create entry ; Delete entry (?)
Search for a file
Create/Delete a directory file
List a directory
Rename a file
Link a file to a directory
Traverse a file system
What are the dot and dotdot directory entries?
What’s the relation between a process and a path?
. - the current directory.
.. - the parent directory
Each process has its own working directory, which is shared by its threads.
Using which tool files(inodes) are shared?
Links
What are soft links and hard links?
Soft
- Containing a path name. access is slower
- If source is removed the link becomes broken
Hard
- information about a shared file is duplicated in sharing directories.
- fast, points to file
- Link count must be maintained.
- if source is removed link still accessible
What is the difference between shared and exclusive locks?
Exclusive - protects updates to file resources and can be owned by only one transaction at a time.
Acquiring an exclusive lock demands waiting if another process is currently holding an exclusive lock or a shared lock of the same resource.
shared - can be owned by several processes at a time.
Acquiring a shared lock demands waiting if another process is currently holding an exclusive lock.
A new request for a shared lock must wait if there’s a request for an exclusive lock on a resource that already has a shared lock.
How can i block or unblock a file?
Using the command flock(file descriptor, operation)
-
operation:
- LOCK_SH - place a shared lock.
- LOCK_EX - place an exclusive lock.
- LOCK_UN - remove an existing lock held by this process.
What happens to the lock when a file is closed or a process terminates?
File lock is removed.
Can we lock parts of the file?
Yes.
Any part of the file may be blocked.
What are the concerns of the user/kernel regarding files?
User:
- File names
- operations allowed
- location(directory structures)
System:
- Storage of files and directories
- Disk space management
- implementation efficiency and reliability.
Disk allocation:
Advantages/Disadvantages of:
- Contiguous allocation?
- Linked list of disk blocks
- Linked list using in-memory Files Allocation Table
Contiguous:
- Simple; access is fast
-
external fragmentation
- How much size to allocate at creation time?
Linked list of disk blocks:
- No fragmentation and easy allocation
-
slow random access
-
n disk accesses to get to the n’th block
- because the pointer to the next block is held within the block.
-
n disk accesses to get to the n’th block
- weird block size
Linked list using in-memory Files Allocation Table
- none of the above disadvantages.
- Uses a table to store the pointers of all blocks in the linked list that represent files - last file block has a special EOF symbol.
- we don’t need allocations to be continguous - segmentation free
- Can access the nth block of some file using the table and not using the table blocks.
- A very large table in memory
What is an inode and who holds it?
It is a place, on disk, where data about the file is stored.
Each file struct holds inode. (might be two files pointing to the same inode..)
There is a struct called dinode which holds the:
- File Attributes
- Time last accessed
- Time last modified
- Size
- File type, protection bits
- Nlinks
- Number of directory entries pointing to this i-node.
- Address of disk block 0
- Address of disk block 1
- ..
- Address of block of pointer
- Containing additional disk addresses
What is the classic Unix disk structure?
- Boot Sector
-
Super Block
- Number of inodes
- Number of Blocks
- Number of free blocks
- Pointer to free blocks list
- Pointer to free i-node list
- …
- i-nodes
- Data blocks
Unix inodes - how bytes counting work?
I didn’t get it. You try.