Minix FS
Minix FS
Minix FS
" Process FS, running in user mode " Main loop which
" Waits for a message " Extracts and uses msg type as index into table with procedure pointers (handlers) " Procedure does the work and returns a status value, which is send back as the reply
MINIX FS Messages
1!
" File name lookup is done one entry at a time. " When a new file is created, a new i-node is allocated (alloc_node) and its name is written into the directory entry
i-node-nr! 2 bytes!
File Descriptors
" File descriptor is an index in a filp (file position) table. " Filp table contains file position and I-node pointer of the file, the file mode, and the count of processes using it. " Filp is a shared table that allows for:
" sharing files without sharing file positions " sharing files and share file positions (e.g. between parent and a child)
Process P1: fd=open() Process P2: fd=open()
Pos = file position inp = i-node pointer
Table lp!
Pos/inp Pos/inp Pos/inp Pos/inp Pos/inp Pos/inp pos1! pos2!
OpenFileTable!
2!
FS Layout
" Same structure for any block device. " Uses i-nodes and zones (allocation unit composed of 2n blocks) " Uses bit-maps to keep track of used/free i-nodes and zones (bit maps are not normal blocks)
" To find the zone of a block, do a n-bit shift-right of the block number.
" n=3, Each zone has 8 Blocks. And block #128 is in zone #16
" Utility program mkfs formats disk, and includes magic number in super-block (valid Minix FS)
3!
FS Mounting
A mouting is a glue between the mounted-on i-node, and the inode of the root directory of the mounted file system. Example: mount t devtype device mounted-on-dir The i-node of the mounted-on directory has the mount-flag set. At the path resolution, this means: continue search in the mounted FS
4!
Minix FS
" When a device is mounted, its super-block is copied into a super-block table in memory, including several information: " if FS is read-only " device from which the super-block came " pointers to the first free i-nodes/zones in the bit maps " etc
" When path resolution reaches /usr, it searches all the super-block table for the i-node pointer, and gets the pointer to the mounted-FS
i-node of the mounted-on-FS!
Super-block table!
/usr!
/!
10
5!
Minix i-node
" File Type (regular, directory, special, pipe, etc.) and protection bits " 9 zone pointers (7 direct, 2 indirect), each 32 bits " Status change time updated at every file operation " When a file is opened, the inode is copied to memory into a i-node table " If an open file is re-opened, a used-counter is incremented (only if counter=0) i-node is removed from table
11
Minix FS
" When a new file is created, uses the first-free-bit pointers in the super-block to allocate a new inode and one or more new zones " When a file is deleted, FS:
" locates the corresponding bits in the i-node and zone bit maps and sets them to 0 " updates the first-free-bit pointers in the super-block table entry for the device
" All blocks within a newly allocated zone are initialized (zeroed), to avaiod problem of seek +write beyond the original size of the file
Seek+write!
12
6!
Reading/Writing Files
All in files read.c and write.c: read_write is the common procedure, which calls: " rw_chunk to obtain the block address, and request the copy of it to the user space, which calls: " read_map/write_map to convert the logical position within a file to the block number (write_map) may also insert new zone numbers into the i-node or index blocks " rd_indir/wr_indir to obtain the target block address when indirect (simple/double) indexing is used " get_block checks if the required block is in the cache, if yes, gets the pointer to it. If not, then: " rw_block copies data to/from a block to memory, and calls lower-layer procedures: dev_io, rw_dev, sendrec " sys_copy transfers data from the File Server to the user process
13
zones:
Exampls: Free zones are: 12, 20, 31, 36 (Blocks: 24/25, 40/41, etc.)
24! 24! 25! 24! 25! 40! 24! 25! 40! 41! 24! 25! 40! 41! 62! Fig: Successive allocation of blocks of 1 KB and Zones of 2KB!
14
7!
16
8!
9!