cpsc 410 611 file management
play

CPSC 410/611: File Management What is a file? Elements of file - PDF document

CPSC 410 / 611 : Operating Systems CPSC 410/611: File Management What is a file? Elements of file management File organization Directories File allocation UNIX file system Reading: Silberschatz, Chapter 10, 11


  1. CPSC 410 / 611 : Operating Systems CPSC 410/611: File Management • What is a file? • Elements of file management • File organization • Directories • File allocation • UNIX file system • Reading: Silberschatz, Chapter 10, 11 What is a File? • A file is a collection of data elements, grouped together for purpose of access control, retrieval, and modification • Often, files are mapped onto physical storage devices, usually nonvolatile. • Some modern systems define a file simply as a sequence, or stream of data units. • A file system is software responsible for – creating, destroying, reading, writing, modifying, moving files – controlling access to files – management of resources used by files. 1

  2. CPSC 410 / 611 : Operating Systems The Logical View of File Management user • directory management file structure • access control • access method records • blocking physical blocks in memory • disk scheduling physical blocks on disk • file allocation Logical Organization of a File • A file is perceived as an ordered collection of records , R 0 , R 1 , ..., R n . • A record is a contiguous block of information transferred during a logical read/write operation. • Records can be of fixed or variable length. • Organizations: – Pile – Sequential File – Indexed Sequential File – Indexed File – Direct/Hashed File 2

  3. CPSC 410 / 611 : Operating Systems Pile • Variable-length records • Chronological order • Random access to record by search of whole file. • What about modifying records? Pile File Sequential File • Fixed-format records • Records often stored in order key field of key field . • Good for applications that process all records. • No adequate support for random access. • What about adding new record? • Separate pile file keeps log file or transaction file. Sequential File 3

  4. CPSC 410 / 611 : Operating Systems Indexed Sequential File • Similar to sequential file, with two additions. – Index to file supports index random access. – Overflow file indexed main file from main file. • Record is added by appending it to overflow file and providing link from predecessor. overflow file Indexed Sequential File Indexed File • Multiple indexes • Variable-length records index • Exhaustive index vs . partial index index partial index 4

  5. CPSC 410 / 611 : Operating Systems File Management • What is a file? • Elements of file management • File organization • Directories user • File allocation file structure • directory management • access control • UNIX file system • access method records • blocking physical blocks in memory physical blocks on disk • disk scheduling • file allocation Directories • Large amounts of data: Partition and structure for easier access. • High-level structure: – partitions in MS-DOS – minidisks in MVS/VM – file systems in UNIX. • Directories: Map file name to directory entry (basically a symbol table). • Operations on directories: – search for file – create/delete file – rename file 5

  6. CPSC 410 / 611 : Operating Systems Directory Structures • Single-level directory: directory file • Problems: • limited-length file names • multiple users Two-Level Directories master directory user1 user2 user3 user4 user directories file • Path names • Location of system files • special directory • search path 6

  7. CPSC 410 / 611 : Operating Systems Tree-Structured Directories user bin pub user1 user2 user3 ... find count ls cp bin mail netsc openw bin demo include ... gcc gdb xmt xinit xman xmh xterm • create subdirectories • current directory • path names: complete vs. relative Generalized Tree Structures – share directories and files user bin pub – keep them easily accessible user1 user2 user3 ... find count ls cp xman bin mail opwin netsc bin demo incl ... xinit gcc gdb xmt xinit xman xmh xterm • Links: File name that, when referred, affects file to which it was linked. (hard links, symbolic links) • Problems: • consistency, deletion • Why links to directories only allowed for system managers? 7

  8. CPSC 410 / 611 : Operating Systems Bookkeeping • Open file system call: cache information about file in kernel memory: – location of file on disk – file pointer for read/write – blocking information open-file table • Single-user system: file1 file pos file location file2 file pos file location • Multi-user system: system open-file table open cnt file pos ... process open-file table file1 file pos file2 file pos open cnt file pos ... File System Architecture: Virtual File System system call layer Example: Linux Virtual File System (file system interface) (VFS) • Provides generic file-system interface (separates from implementation) virtual file system layer (v-nodes) • Provides support for network-wide identifiers for files (needed for network file systems). local UNIX file system (i-nodes) Objects in VFS: • inode objects (individual files) • fi file objects (open files) • superblock objects (file systems) • dentry objects (individual directory entries) 8

  9. CPSC 410 / 611 : Operating Systems File System Architecture: Virtual File System system call layer Example: Linux Virtual File System (file system interface) (VFS) • Provides generic file-system interface (separates from implementation) virtual file system layer (v-nodes) • Provides support for network-wide identifiers for files (needed for network file systems). local UNIX file NFS client system (i-nodes) (r-nodes) Objects in VFS: • inode objects (individual files) • fi file objects (open files) RPC client stub • superblock objects (file systems) • dentry objects (individual directory entries) File System Architecture: Virtual File System system call layer Example: Linux Virtual File System (file system interface) (VFS) • Provides generic file-system interface (separates from implementation) virtual file system layer (v-nodes) • Provides support for network-wide identifiers for files (needed for network file systems). local UNIX file Flash Memory system (i-nodes) File system Objects in VFS: • inode objects (individual files) • fi file objects (open files) • superblock objects (file systems) • dentry objects (individual directory entries) 9

  10. CPSC 410 / 611 : Operating Systems File Management • What is a file? • Elements of file management • File organization • Directories user • File allocation file structure • directory management • access control • UNIX file system • access method records • blocking physical blocks in memory physical blocks on disk • disk scheduling • file allocation Allocation Methods • File systems manage disk resources • Must allocate space so that – space on disk utilized effectively – file can be accessed quickly • Typical allocation methods: – contiguous – linked – indexed • Suitability of particular method depends on – storage device technology – access/usage patterns 10

  11. CPSC 410 / 611 : Operating Systems Contiguous Allocation • Logical file mapped onto a sequence of adjacent physical blocks. 0 1 2 3 • Advantages: – minimizes head movements 4 5 6 7 – simplicity of both sequential and direct access. 8 9 10 11 – Particularly applicable to applications where 12 13 14 15 entire files are scanned. • Disadvantages: 16 17 18 19 – Inserting/Deleting records, or changing length of records difficult. 20 21 22 23 – Size of file must be known a priori . (Solution: copy file to larger hole if 24 25 26 27 exceeds allocated size.) file start length – External fragmentation file1 0 5 – Pre-allocation causes internal file2 10 2 fragmentation file3 16 10 Linked Allocation • Scatter logical blocks throughout secondary storage. 0 1 2 3 • Link each block to next one by forward pointer. • May need a backward pointer for backspacing. 4 5 6 7 • Advantages: – blocks can be easily inserted or deleted 8 9 10 11 – no upper limit on file size necessary a 12 13 14 15 priori – size of individual records can easily 16 17 18 19 change over time. • Disadvantages: 20 21 22 23 – direct access difficult and expensive – overhead required for pointers in blocks 24 25 26 27 – reliability file start end file 1 9 23 … … … … … … 11

  12. CPSC 410 / 611 : Operating Systems Variations of Linked Allocation • Maintain all pointers as a separate linked list, preferably in main memory. 0 16 0 1 2 3 9 0 10 10 4 5 6 7 file start end 16 24 file1 9 23 8 9 10 11 ... ... ... 23 -1 12 13 14 15 ... ... ... 24 26 16 17 18 19 26 10 20 21 22 23 • Example: File-Allocation Tables (FAT) 24 25 26 27 in MS-DOS, OS/2. Indexed Allocation • Keep all pointers to blocks in one location: index block (one index block per file) 0 1 2 3 4 5 6 7 9 0 16 24 26 10 23 -1 -1 -1 8 9 10 11 • Advantages: – supports direct access 12 13 14 15 – no external fragmentation 16 17 18 19 – therefore: combines best of continuous and linked allocation. 20 21 22 23 • Disadvantages: – internal fragmentation in index blocks 24 25 26 27 • Problem: file index block – what is a good size for index block? file1 7 – fragmentation vs. file length ... ... ... ... 12

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend