1.1k likes | 2.73k Views
10. File Systems. Kai Bu kaibu@zju.edu.cn http://list.zju.edu.cn/kaibu/cmpt300. File Systems. the most visible aspect of an OS. File Systems. the most visible aspect of an OS storage and access to data & programs of the OS and all the users. File Systems. files:
E N D
10 File Systems Kai Bu kaibu@zju.edu.cn http://list.zju.edu.cn/kaibu/cmpt300
File Systems the most visible aspect of an OS
File Systems the most visible aspect of an OS storage and access to data & programs of the OS and all the users
File Systems files: each stores related data directory: organizes & provides info about all the files
File • A logical storage unit • abstracted by OS from the physical properties of its storage devices • A named collection of related information that is recorded on secondary storage
File • Text file a sequence of characters organized into lines (and possibly pages) • Source file a sequence of functions, each of which is further organized as declarations followed by executable statements • Executable file a series of code sections that the loader can bring into memory and execute
File Attributes • Name the symbolic file name is the only info kept in human-readable form • Identifier a unique tag, usually a number, identifies the file within the file system • Type for systems to differentiate diff file types cont.
File Types name.extension
File Attributes • Location a pointer to a device and to the location of the file on that device • Size current file size (in bytes, words, blocks) and possibly the maximum allowed size cont.
File Attributes • Protection access-control information, who can read, write, execute, and so on • Time, date, and user identification may be kept for creation, last modification, and last use; useful for protection, security, and usage monitoring
File Operations • Create allocate space in the file system make an entry in the directory cont.
File Operations • Write via a system call specifying file name and the info to be written to the file; locate the file using its name to search directory; keep a write pointer to the location in the file where the next write is to take place cont.
File Operations • Read via a system call specifying file name and where (in memory) the next block of the file should be put; keep a read pointer to the location in the file where the next read is to take place; r&w share current-file-position pointer cont.
File Operations • Reposition within a file reposition current-file-position pointer to a given value; also known as file seek cont.
File Operations • Delete search the directory for the named file, release the space of the file; erase the directory entry; so the released space can be reused; cont.
File Operations • Truncate erase the contents of a file but keep its attributes; reset file length as zero; release its file space;
always search directory? not if record the search history
Open-File Table • Contain information of all open files • Each entry has an open count that indicates how many processes have the file open • File pointer to track the last read-write location • Disk location for locating a file on disk • Access rights
Sequential Access • Process information in the file in order one record after another • read_next(): reads the next portion of the file and advances a file pointer • write_next(): appends to the end of the file and advances to the end of the newly written material • Pointer can be reset to the beginning
Direct Access • Organize a file as fixed-length logical records • number the records/blocks • Allow program to read and write records rapidly in no particular order • Enable immediate access to large amounts of information • read(n), write(n)
devices partitioned into volumes; each volume maintains a directory, which records file name, location, size, type, etc.
Operations over Directory • Search for a file • Create a file • Delete a file • List a directory • Rename a file • Traverse the file system
Single-Level Directory • Contain all files in the same directory • Require unique file names
Two-Level Directory • Create a separate directory per user UFD: user file directory • Unique file names for the same user • Diff users may have same-name files • Maintain a master file directory (MFD) to index the UFD of each user
Two-Level Directory • Resembles a tree with MFD as the root and UFDs as leaves • Path name: user name + file name; for each file in the system
Tree-Structured Directory • Allow users to create subdirectories • Treat directory as a special file in each directory entry: bit 0 for file: bit 1 for subdirectory:
Tree-Structured Directory • Allow users to create subdirectories • Treat directory as a special file absolute path name: from the root to the specified file:
Tree-Structured Directory • Allow users to create subdirectories • Treat directory as a special file relative path name: a path from the current directory:
Tree-Structured Directory • Allow users to create subdirectories • Treat directory as a special file Example: current directory root/spell/mail: prt/first = root/spell/mail/prt/first:
Acyclic-Graph Directory • Allow directories to share subdirectories and files • Share file/directory among users
General Graph Directory unwanted; cycles need to be avoided; run cycle detection alg upon adding links in acyclic G
how to mount a file system? so that a volume is available within the file-system name space
File-System Mounting • The OS is given the following info: name of the device; mount point – the location within the file structure where the file system is to be attached; and file system type for some OS • OS then verifies that the device contains a valid file system and updates directory
File-System Mounting /device/dsk Existing System Unmounted Volume
File-System Mounting accessible files /device/dsk Existing System Unmounted Volume
File-System Mounting /device/dsk mounted over /users its files become accessible; original mounted files are obscured untill /device/dsk is unmounted;
how to share files? owner: the user with the most control over the file; change file attributes and grant access; group: users who can share access to the file;
how to share files? owner ID compared with the user ID when that user requests an operation on a file; group ID(s) compared with that user’s group ID(s)
how to share files remotely? in a network
The Client-Server Model • Server the machine containing the files to share • Client the machine seeking access to the files • Server specifies exactly which resource to share with exactly which users
The Client-Server Model • Server the machine containing the files to share • Client the machine seeking access to the files • Server specifies exactly which resource to share with exactly which users • Server checks user credentials before granting access
Consistency Semantics • Specify how multiple users to access a shared file simultaneously • UNIX Semantics writes to an open file by a user are visible immediately to other users who have this file open;
Consistency Semantics • Specify how multiple users to access a shared file simultaneously • Session Semantics writes to an open file by a user are not visible immediately to other users that have the same file open; once a file is closed, the changes are visible only in later sessions*; *the series of accesses between open() and close()