160 likes | 173 Views
Understand file systems, file managers, file formats, functions, and storage block management in modern operating systems. Learn about file descriptors, storage blocks, allocation methods, and free space management.
E N D
CSI 400/500 Operating SystemsSpring 2009 Lecture #10 – File Manager Monday-Wednesday, March 2nd and 4th
File Directory File System File Manager Collection of data in some organized fashion Organized collection of files Defined means of storing and manipulating files That part of the operating system that works with files and directories Terms
Typical File Format • File is a collection of records • Each record is a collection of fields • Number and type of fields could vary across records (variable file) or remain constant (structured file) • Variable file require some translation format for copying data into storage • One job of file system is to hold these translations
Open( ) Read(id, buffer, len) Write(…) Close( ) Establishes connection to file and sets position pointer at beginning Read a particular length of char data into specified I/O buffer. Moves position pointer len places Writes len characters from buffer to file Moves position pointer len places Removes copy from local storage Low-level file functions
Seek function • Most modern operating systems have a seek function • Allows you to find particular character (like some delimiter) forward from position pointer (default) or from specified location • Doesn’t move position pointer • Use return value to determine read length
Open( ) Get() Put() Seek() Close( ) Establishes connection to file and sets position pointer at beginning Reads next record Writes a new record Find particular record by index or key Removes copy from local storage Structured file functions
Sequential Indexed sequential Inverted Consecutive records Must read in order Consecutive records Records have unique index field Can search Non-consecutive Find by index File types
File Descriptor Block • Also called “file header” • Contains important information: • File name • File Owner • Permissions • Creation: Date, time, owner • Last modified: Date, time, user • System storage information: block size, file length, etc
Open File Descriptor • Used on local open files • Contains file use information like: • Owning process id • Position pointer or record index position • Lock state: read or write • File copy state: open, archived, deleted, closed
File Manager functions • Locate file and ensure permission • Create local copy – for files on external storage, may only get one block at a time • Create open file descriptor • Pass data between local copy and cache • Get additional external blocks • Manage storage • Clean up when close
File Manager Storage Block Management • Managing blocks of data storage • Adding blocks, releasing blocks, and reallocating blocks • Arrangement is key difference in most operating systems • Contiguous • Linked list • Index table
Contiguous Allocation • Files stored in consecutive blocks • Easy retrieval – File table maintains starting offset and length • Edit overhead – adding data means entire file moves to next free offset • Creates internal fragmentation
Linked lists • Allows dynamic additions and subtractions • Individual records chained • Each record contains pointer to next • Often two-headed, so previous pointer exists • Lengthy search process • Run chain until desired record found
Index table • Dynamic blocks contain records • Records can be scattered across secondary storage • Instant retrieval • Index table contains pointer to specific record with that index • Storage hog for large files • Index table gets larger and larger
Hash table • Improvement over index table • Mix of linked lists and index table • Multiple records can have same “index” • Index table points to head of hash chain • Prevents need to extend index table
Free Space • File Manager also maintains list of available space • Can be maintained with linked list chain, free space index table, or block status map • Block status map marks whether block is allocated or free