Sie sind auf Seite 1von 42

Chapter 6 File Systems

Essential requirements

1. Store very large amount of information


2. Must survive the termination of processes
 persistent
3. Concurrent access by multiple processes
File names
File name issues

 Length
 Distinguish between upper and lower case
 Characters allowed
File structure types

(keyed)
File types

1. Regular files
2. Directories (folders)
3. Special
1. Character special (used for serial I/O: ports,
printers, networks, etc.)
2. Block special (used for disks)
Regular files

 ASCII or binary
 ASCII is easy to use
 Record oriented (delimiter)?
 Binary is space efficient
 Fixed or variable length
File access

1. Sequential
2. Random
 seek() and fseek()
 Binary
 unbuffered: read(), write()
 Buffered: fread(), fwrite()
 ASCII, buffered: fscanf(), fprintf()
File attributes
File operations

 Create  Append
 Delete  Seek
 Open  Get attributes
 Close  Set attributes
 Read  Rename
 Write
Memory-mapped files

 Mapping files into process virtual address


space
Directories (folders)

1. Single level
2. Two level
3. Hierarchical
Two level directory systems
Hierarchical directory systems
Path names

 We already described file names.


 How do we specify the “path” to a file i.e., how do
we navigate the directory structure?
 Path names:
1. Absolute
 c:\usr\ginger\mailbox\junk.cpp
 /usr/ginger/mailbox/junk.cpp
2. Relative (to the current working (default) directory)
1. . = current directory: ./hw1/junk.cpp or hw1/junk.cpp
2. .. = directory above current: ../music/mm.mp3
Directory operations

 Create  Readdir
 Delete  Rename
Same or similar
 Opendir so be careful!  Link
 Closedir  Unlink
Disk organization

 Disks: sector, intersector gap,


cluster, track, cylinder
 Cluster = one or more contiguous
sectors.
 In NTFS, a cluster is the smallest
amount of disk space that can be
allocated to hold a file.
File system implementation

 Physical disks
 Divided into one or more “partitions” (logical, separate
disks).
 Each partition can have its own file system.
 Sector 0 = MBR (master boot record)
 List of partitions (start and ends)
 Indicates boot partition
 Every partition has a boot block (although it may be empty)
 Boot steps:
1. boot code in MBR executes
2. reads in boot block code of boot partition and executes it
3. boot block code boots OS code in partition
File system layout
IMPLEMENTING FILES
Implementing files

1. Contiguous allocation

2. Linked list allocation

3. Linked list allocation w/ table in memory

4. I-nodes (index-nodes)
1. Implementing files: contiguous
allocation
Given 1KB blocks, a 50KB file would be allocated 50
consecutive blocks
+ simple: all we need to know if the disk address of the
first block and the number of blocks (or length of the
file)
+ fast: only 1 seek + one read needed for the entire file
+ sequential and random access are efficient
- fragmentation (holes or compaction)
- Must specify the size of the file ahead of time.
 Excellent for CDs and DVDs.
1. Implementing files: contiguous
allocation
2. Implementing files: linked list allocation
2. Implementing files: linked list allocation

+ no fragmentation
- Sequential access is easy but requires
multiple seeks and reads.
- Random access is slow (basically becomes
sequential access).
3. Implementing files: linked list w/ table
in memory
 FAT = file allocation table
+ random access requires only sequential
memory access (which is fast)
- Need memory to store the table.
 20GB and 1KB blocks requires a table with 20M
entries. (20M x 4 bytes-per-entry = 80MB)
 Size of table is proportional to disk size.
3. Implementing files: linked list w/ table
in memory
4. Implementing files: i-nodes

 i-node table for a file need only be in memory


when the file is open.
 Size of table is proportional to number of files
we allow to be open at any time.
4. Implementing files: i-nodes file

(disk)
MISC. TOPICS
Implementing directories (folders)

 We need to locate (the first block of) the file!


 We need to store file attributes (e.g., owner,
creation time, etc.).

i-nodes
Shared files (i.e., files in more than one
directory)
Disk space management

 Block size
 Might want/need to consider:
 page size
 sector, track, or cylinder size
 what is the average size of a file
 For Unix, 1KB is commonly used.
 Keeping track of free blocks
 Linked list of free block numbers
 Bitmap
 Disk quotas
 Limits on disk space usage by users.
File system reliability

 Backups
1. Full
2. Incremental
 Backups
1. Physical dump
2. Logical dump
 Consistency
 When the system is not shut down properly.
File system performance

 Caching (FIFO, second chance, LRU, etc.).

 Block read ahead.

 Reducing disk arm motion.


Example file systems

 MS-DOS/Windows3.1/Windows95

 Windows98

 NTFS

 Unix V7
MS-DOS/Windows3.1/Windows95

Attributes Each entry is 32 bytes.


1. Read-only
2. Hidden
3. System file
4. Should be archived
Windows98

 Problem: We outgrew 8.3 file names (in


1988).
Windows98 & old MS-DOS file names
MS-DOS file name: “THEQUI~1.”
Long file name: “The quick brown fox jumps over the lazy dog.”

First byte is sequence number & Invalid attr’s 0x0f for all long file entries.
NTFS (from ntfs.com and msdn.com)

 NTFS volume organization


 MFT = Master File Table
Unix V7 file system

 simple
disk addr of file block 0
disk addr of file block 9

disk addrs of file blocks 10-15

disk addrs of file blocks 16-51

disk addrs of file blocks 52…

Das könnte Ihnen auch gefallen