Why a file system?Why a file system There is a general need for long-term and shared data storage: need to store large amount of information persistent storage (outlives process and system reboots) concurrent sharing of information Files meet these requirements The file manager or file system within the OS Set of system software proving services to users and applications in use of files Files are accessed through file management system2Concept of a file A named collection of related data stored on secondary storage File name may encode the file type file extensions in UNIX and Windows Abstraction presented to the user Common examples of File types Regular files, directories Executable files special files (block and character) Archives3File structure (logical) None - sequence of words, bytes Simple record structure Lines, Fixed length, Variable length Complex Structures Formatted document, multi-media documents Who decides: Operating system Application DBMS4File attributes Name – only information kept in human-readable form Type – needed for systems that support different types Location – pointer to file location on device Size – current file size Protection – controls who can do reading, writing, executing Time, date, and user identification – data for protection, security, and usage monitoring. Information about files are kept in the directory structure, which is maintained on the disk.5File operations create write read reposition within file – file seek delete truncate open(file_i) – search the directory structure on disk for entry file_i, and move the content of entry to memory. close (file_i) – move the content of entry file_i from memory to directory structure on disk.6Examples of file types7File Type Usual extension Functiion Executable exe, com, bin or none ready-to-run machine-language program Object obj, o complied, machine language, not linked Source code c, p, pas, 177, asm, a source code in various languages Batch bat, sh commands to the command interpreter Text txt, doc textual data documents Word processor wp, tex, rrf, etc. various word-processor formats Library lib, a libraries of routines Print or view ps, dvi, gif ASCII or binary file Archive arc, zip, tar, rar related files grouped into one file, sometimes compressed.Access methods for file data Sequential Access – (most common) read next write next , (rewrite) reset no read after last write Direct Access: n = relative block number (on disk) read n write n, rewrite n position to n read next write next 8Directory structure Directory contains a collection of nodes containing information about all files Both the directory structure and the files reside on disk Backups of these two structures are kept on tapes9F 1F 2F 3F 4F nDirectoryFilesInformation per file in a directory Name Type Address Current length Maximum length Date last accessed (for archival) Date last updated (for dump) Owner ID (who pays) Protection information (discuss later)10Directory operations Search for a file Create a file Delete a file List a directory Rename a file Traverse the file system11Organize the directory (logically) Efficiency – locating a file quickly. Naming – convenient to users. Two users can have same name for different files. The same file can have several different names. Grouping – logical grouping of files by properties, (e.g., all Java programs, all games, …)12Single-level directory13 A single directory for all users.• Naming problem• Grouping problemTwo-level directory14 Separate directory for each user.• Path name• Can have the same file name for different user• Efficient searching• No grouping capabilityTree-structured directories15Tree-structured directories Efficient searching Grouping Capability Absolute or relative path name Current directory (working directory) cd /Users/faculty/defoe/Public/ type echo Creating a new file is done in current directory Creating a new subdirectory is done in current directory16Protection File owner/creator should be able to control: what can be done by whom Types of access Read Write Execute Append Delete List17Access lists and groups18 Mode of access: read, write, execute Three classes of usersRWXa) owner access 7 1 1 1RWXb) groups access 6 1 1 0RWXc) public access 1 0 0 1 Ask manager to create a group (unique name), say G, and add some users to the group. For particular file or subdirectory, define an appropriate access.owner group publicchmod 761 gameAttach a group to a filechgrp G gameFilesystem structure Disk divided into one or more partitions independent file system on each partition Sector 0 contains the Master Boot Record (MBR) MBR contains partition table one partition marked as active boot block – first block of active partition BIOS reads and executes MBR, which reads boot block and executes it program in boot block loads OS and runs it Often file system contains superblock which contains key file system parameters 19Example disk and filesystem layout20boot block super block inode list root dirMBRPartition Tablepartition 1partition 2 (active)partition 3free space management files & dirsFile allocation on disk Disk is divided into blocks or sectors Files are stored on secondary storage in blocks or sectors Blocks are the unit of I/O transfer with secondary storage (on LINUX and UNIX, sectors on Windows) Blocks can be of fixed length or variable-length Need file allocation table (FAT) to keep track of files on disk Each file has a FAT entry21File allocation methods Keep track of which sectors/blocks on the disk belong to which logical file/directory. Methods include Contiguous allocation Linked (chained) allocation Indexed allocation22Contiguous allocation Each file occupies a set of contiguous blocks on the disk Simple FAT entry only starting location (block #) and length (number of blocks) are required Random access Wasteful of space external fragmentation, may use compaction to fix Files cannot grow Pre-allocation of blocks is required Maximum file size is known in advance23Contiguous allocation24What happens if file F
View Full Document