UNIX File System
Total Page:16
File Type:pdf, Size:1020Kb
The UNIX File System * UNIX: a time-sharing system. * UNIX: AT&T version, BSD version (Berkeley Software Distribution). * File: a uniform logical view of information storage. - A file is a collection of related information defined by its creator. * Why file system ? 1) when size of files is large. 2) for back-up. 3) sharing. * We are cared about how files are structed, named, accessed, used, protected, and implemented ==> a file system. * File System: 1) the directory structure. 2) the collection of actual fields. * File structure: byte sequence, record sequence, tree. FileSystem - 1 Ant Fox Pig 1 Byte 1 Record Cat Cow Dog Coat Lion Owl Pony Rat Worm Hen lbis Lamb FileSystem - 2 * File access: 1) sequential access: tape. 2) random access: disk. * Types of files: 1) test files. (characters) 2) source files. 3) object files. (binary files) 4) database. (record) or 1) regular files (user files): ASCII files/binary files. - ASCII files: they can be displayed and printed as is, and they can be edited with an ordinary test editor. - binary files: consists of a collection of library procedures compiled but not linked. 2) directories (system files). 3) character special files: related to I/O terminal, printer, network. 4) block special files (model disk). FileSystem - 3 The UNIX File System * A File system is the organization framework that specifies how a mass storage device is organized. -File systems usually contain a map, which is called the i-node table on the UNIX system, that is used to locate a file, given its name. *UNIX File Types 1) ordinary files: text and binary files. 2) directory files: collections of files. A directory file stores the names of the files it contains plus information that is used to locate and access the files. 3) device files: special device files. A device file is a means of accessing a hardhare device, usually an I/O device. Ex. a pseudo-tty. 4) symbolic link files. A symbolic link is a way to make a new name for an existing files. It makes it easy to place “copies” of things whenever they are needed, without the overlead ( and duplications ) of truly making copies. 5) the named pipes. * File Access Modes + Protection + Security FileSystem - 4 * The directory system can be viewed as a symbol table that translates file names into their directory entries. ==> the directory itself can be organized in many ways. ==> problem: how to search the entry ? 1) linear search. 2) hash. * UNIX directory - files are organized in tree-structured directories. - absolute/relative path name. - working directory. * Implementing Directories - When a file is opened, OS uses the path name supplied by the user to locate the directory entry. The directory entry provides the information needed to find the disk blocks. - Depending on the system, the information may be the disk address of the entire file (continuous allocation), the number of the first block or the number of the I-node (in UNIX). - The main function of the directory system is to map the ASCII name of the file to the information needed to locate the data. - Issue: where the attributes of a file should be stored ? 1) store them directly in the directory entry. 2) i-node: store the attributes in the i-node, rather than directory entry. FileSystem - 5 FileSystem - 6 FileSystem - 7 Directory Description /bin Frequently used system binaries /dev Special files for I/O devices /etc Miscellaneous system administration /lib Frequently used libraries /tmp Some utilities generate their temporary files here /usr All user files are in this part of the tree /usr/adm System accounting /usr/ast Home directory for the user whose login name is ast /usr/bin Other system binaries are kept here /usr/include System header files /usr/lib Libraries, compiler passes, miscellaneous /usr/man Online manuals /usr/spool Spooling directories for printer and other daemous /usr/src System source code /usr/tmp Other utilities put their temporary files here FileSystem - 8 Figure 1 ■ A Simplified Diagram of a Typical UNIX File System In this diagram, directory files are shown in triangles, special device files are shown in diamonds, and ordinary files are shown without borders. FileSystem - 9 * File system implementation - implement file storage; keep track of which disk blocks go with which files. 1) continuous allocation. - simple, good performance. - but not flexible (must know the size of the file in advance), large fragmentation. 2) Link list allocation: a linked list of disk block. - no space is wasted to disk fragmentation. - it is sufficient for the directory entry to merely store the disk address of the first block. - however, reading a file sequentially is straightforward. - random access is slow. FileSystem - 10 3) Linked list allocation using an index. - the entire block is available for date. - random access is much easier. - however, the entire table must be in memory. FileSystem - 11 4) I-node in UNIX. - associate with each file a little table called i-node (index-node), which lists the attributes and disk addresses of the file's blocks. - for small files: all the necessary information is in i-node. - for large files: one of the addresses in i-node is the address of a disk block called a single direct block. - file descriptor is an index to a small table of open files for this process. - in this table, each entry contains an pointer to a file structure, which in trun, points to the i-node. - ls -l after get i-node number, copy i-node information from disk to memory (called in-core i-node). - each i-node contains 15 direct link pointer (each of them pointing to a page <= 12 blocks), 3 inderect block pointers (single, double, triple: indirect block pointer). FileSystem - 12 FileSystem - 13 Inode Filename number UNIX directory entry Mode File table of File Permission Access Modification Number Owner Group Modification Size contents type vector time time Of links time (for file map) UNIX inode Figure 2 block 0 Boot Super Inode Data block block list UNIX File System Figure 3 FileSystem - 14 Figure 3 ■ File Systems Traditionally Used This Simple Layout Figure 4 ■ Disks are Usually Divided into Partitions or Slices FileSystem - 15 Figure 5 ■ File Descriptors, File Table, and Inode Table Figure 6 ■ File System Layout A file system has the following structure ( Figure 6 ). ⚫ The boot block occupies the beginning of a file system, typically the first sector, and may contain the bootstrap code that is read into the machine to boot, or initialize, the operating system. Although only one boot block is needed to boot the system, every file system has a ( possibly empty ) boot book. ⚫ The super block describes the state of a file system – how large it is, how many files it can store, where to find free space on the file system, and other information. ⚫ The inode list is a list of inodes that follows the super block in the file system. Admi nistrators specify the size of the inode list when configuring a file system. The kernel references inodes by index into the inode list. One inode is the root inode of the file system: it is the inode by which the directory structure of the file system is accessible after execution of the mount system call. ⚫ The data blocks start at the end of the inode list and contain file data and administrative data. An allocated data block can belong to one and only one file in the file system. FileSystem - 16 FileSystem - 17 Figure 7 ■ The Kernel Data Structure for Accessing Files FileSystem - 18 FileSystem - 19 Figure 8 ■ The I-node, showing How I-node Block Pointers Are Used to Locate the Blocks in a File FileSystem - 20 FileSystem - 21 Figure 10 ■ Kernel Operations for Following the Pathname ../a/b FileSystem - 22 * File Operations: 1) create - find spce on disk for the file. - insert the directory entry, records the name of the file and the location in the file system. 2) open - the open operation takes a file name, searches the directory, copying the directory entry into the table (in memory) of open files; then, OS returns an pointer to the entry in the table of open files, avoiding any further searching. 3) write - input: the file name + data. - according to the file name, find the directory entry. - the directory entry will need to store a pointer to the current block of the file. (write pointer) 4) read 5) reset 6) delete 7) link 8) unlink. (only when the number of linked file names = 0) * To avoid to search the directory entry again, when a file operation is requested, an index into to this table is used (returned), so no searching is required. FileSystem - 23 * Disk space management: page/segment - block size. - keep track of free blocks. - disk quotas of each user. * File system reliability: backup, recovery, consistency (concurrency control). * Security and Protection - (owner, group, universal) + (rwx) -rwxrwxrwx (777) FileSystem - 24 * Mount FileSystem - 25 * Managing your Files ( utilities for file management ) -pwd, cd, ls, rm, mv, cp. -ln : create links. It creates a new name which references the original file. Only one copy exists although it has two names. a) hard links (traditional forms). -Ex. In old new. Those two files have the same I-node number. -Two problems: (1) They only work within a file system because they are based on I-node. (2) They can be very transitory because they operate at such a low level in the UNIX file system. b) symbolic links. -Ex. Ln –s old new. -A symbolic link operates at a higher level then a hard link because a symbolic link refers to a file by name, not through the I-node table.