Presentation is loading. Please wait.

Presentation is loading. Please wait.

Operating Systems Files, Directory and File Systems Operating Systems Files, Directory and File Systems.

Similar presentations


Presentation on theme: "Operating Systems Files, Directory and File Systems Operating Systems Files, Directory and File Systems."— Presentation transcript:

1 Operating Systems Files, Directory and File Systems Operating Systems Files, Directory and File Systems

2 Topics Files and Directories File-System Structure Allocation Methods Free-Space Management Directory Implementation Efficiency and Performance Recovery Files and Directories File-System Structure Allocation Methods Free-Space Management Directory Implementation Efficiency and Performance Recovery

3 File Structure None - sequence of words, bytes Simple record structure Complex Structures Can simulate last two with first method by inserting appropriate control characters Responsible by –Operating system –Program None - sequence of words, bytes Simple record structure Complex Structures Can simulate last two with first method by inserting appropriate control characters Responsible by –Operating system –Program

4 File Attributes Name Type Location Size Protection Time, date, and user identification Information about files are kept in the directory structure. Name Type Location Size Protection Time, date, and user identification Information about files are kept in the directory structure.

5 File Operations Create Write Read Reposition within file - file seek Delete Truncate Open(F i )-search the directory structure on disk for entry F i, and move the content of entry to memory. Close(F i )-move the content of entry F i in memory to directory structure on disk. Create Write Read Reposition within file - file seek Delete Truncate Open(F i )-search the directory structure on disk for entry F i, and move the content of entry to memory. Close(F i )-move the content of entry F i in memory to directory structure on disk.

6 File Types Executable Object Source Code Batch Text Word processor Library Print or view Archive Executable Object Source Code Batch Text Word processor Library Print or view Archive

7 Access Methods Sequential Access read next write next reset no read after last write (rewrite) Sequential Access read next write next reset no read after last write (rewrite)

8 Access Methods (continued) Direct Access read n write n position to n read next write next rewrite n n=relative block number Direct Access read n write n position to n read next write next rewrite n n=relative block number

9 Directory Structure 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 tapes. 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 tapes.

10 Information in a Directory Name Type Address Current Length Maximum Length Date last accessed (for archival) Date last update (for dump) Owner ID (who pays) Protection information (discuss later) Name Type Address Current Length Maximum Length Date last accessed (for archival) Date last update (for dump) Owner ID (who pays) Protection information (discuss later)

11 Operations on a Directory Search for a file Create a file Delete a file List a directory Rename a file Traverse the file system Search for a file Create a file Delete a file List a directory Rename a file Traverse the file system

12 Organization of the Directory Efficiency Naming Grouping Efficiency Naming Grouping

13 Single-Level Directory A single directory for all users. Naming problem Grouping problem A single directory for all users. Naming problem Grouping problem

14 Two-Level Directory Separate directory for each user Path name No naming problem Efficient searching No grouping capability Separate directory for each user Path name No naming problem Efficient searching No grouping capability

15 Tree-Structured Directories Efficient searching Grouping capability Current directory –cd /spell/mail/prog –cat list Efficient searching Grouping capability Current directory –cd /spell/mail/prog –cat list

16 Tree-Structured Directories (continued) Absolute or relative path name Creating a new file is done in current directory. Delete a file Creating a new subdirectory is done in current directory. Deleting a directory Absolute or relative path name Creating a new file is done in current directory. Delete a file Creating a new subdirectory is done in current directory. Deleting a directory

17 Acyclic-Graph Directories Two different names (aliasing) If dict deletes list dangling pointer. Solutions: –Backpointers, so we can delete all pointers. Variable size records a problem. –Backpointers using a daisy chain organization. –Entry-hold-count solution., Two different names (aliasing) If dict deletes list dangling pointer. Solutions: –Backpointers, so we can delete all pointers. Variable size records a problem. –Backpointers using a daisy chain organization. –Entry-hold-count solution.,

18 General Graph Directory How do we guarantee no cycles? –Allow only links to file not subdirectories. –Garbage collection –Every time a new link is added, use a cycle detection algorithm to determine whether it is OK. How do we guarantee no cycles? –Allow only links to file not subdirectories. –Garbage collection –Every time a new link is added, use a cycle detection algorithm to determine whether it is OK.

19 Protection File owner/creator should be able to control –what can be done –by whom Types of access –Read –Write –Execute –Append –Delete –List File owner/creator should be able to control –what can be done –by whom Types of access –Read –Write –Execute –Append –Delete –List

20 Access Lists and Groups -NFS Mode of access: read, write, execute Three classes of users RWX a) owner access 7 1 1 1 RWX b) groups access 6 1 1 0 RWX c) public access 1 0 0 1 Ask manager to create a group (unique name), say G, and add some users to that group. Mode of access: read, write, execute Three classes of users RWX a) owner access 7 1 1 1 RWX b) groups access 6 1 1 0 RWX c) public access 1 0 0 1 Ask manager to create a group (unique name), say G, and add some users to that group.

21 Access Lists and Groups (continued) For a particular file (say game) or subdirectory, define an appropriate access. Attach a group to that file chgrp G game For a particular file (say game) or subdirectory, define an appropriate access. Attach a group to that file chgrp G game owner group public chmod 761 game

22 File-System Structure File structure File system resides on secondary storage File system organized into layers. File control block - storage structure consisting of information about a file. File structure File system resides on secondary storage File system organized into layers. File control block - storage structure consisting of information about a file.

23 Contiguous Allocation Each file occupies a set of contiguous blocks on the disk. Simple-only starting location (block #) and length (number of blocks) are required. Random Access. Wasteful of space (dynamic storage-allocation problem). Each file occupies a set of contiguous blocks on the disk. Simple-only starting location (block #) and length (number of blocks) are required. Random Access. Wasteful of space (dynamic storage-allocation problem).

24 Contiguous Allocation (continued) Files cannot grow Mapping from logical to physical. Starting address and displacement. Files cannot grow Mapping from logical to physical. Starting address and displacement.

25 Linked Allocation Each file is a linked list of disk blocks; blocks may be scattered anywhere on the disk. Block = pointer

26 Linked Allocation Simple - need only starting address Free-space management system - no waste of space No random access Mapping File-allocation table (FAT) - disk-space allocation used by MS-DOS and OS/2. Simple - need only starting address Free-space management system - no waste of space No random access Mapping File-allocation table (FAT) - disk-space allocation used by MS-DOS and OS/2.

27 Indexed Allocation Brings all pointers together into the index block. Logical view Brings all pointers together into the index block. Logical view

28 Indexed Allocation (continued) Need index table Random access Dynamic access without external fragmentation, but have overhead of index block. Mapping from logical to physical in a file of maximum size of 256K words and block size of 512 words. We need only 1 block for index table –Q –R Need index table Random access Dynamic access without external fragmentation, but have overhead of index block. Mapping from logical to physical in a file of maximum size of 256K words and block size of 512 words. We need only 1 block for index table –Q –R

29 Indexed Allocation- Mapping (continued) Mapping from logical to physical in a file of unbounded length (block size of 512 words). Linked scheme - Link blocks of index tables (no limit on size). LA / (512 x 511) Mapping from logical to physical in a file of unbounded length (block size of 512 words). Linked scheme - Link blocks of index tables (no limit on size). LA / (512 x 511) Q1R1Q1R1

30 Indexed Allocation - Mapping (continued) –Q 1 = block of index table –R 1 is used as follows: R 1 / 512 –Q 2 = displacement into block of index table. –R 2 = displacement into block of file. –Q 1 = block of index table –R 1 is used as follows: R 1 / 512 –Q 2 = displacement into block of index table. –R 2 = displacement into block of file. Q2R2Q2R2

31 Indexed Allocation - Mapping (continued) Two-level index (maximum file size is 512 3 ) LA / (512 x 512) –Q 1 = displacement into outer-index –R 1 is used as follows: R 1 / 512 Two-level index (maximum file size is 512 3 ) LA / (512 x 512) –Q 1 = displacement into outer-index –R 1 is used as follows: R 1 / 512 Q1R1Q1R1 Q2R2Q2R2

32 Indexed Allocation - Mapping (continued) –Q 2 = displacement into block of index table –R 2 = displacement into block of file –Q 2 = displacement into block of index table –R 2 = displacement into block of file

33 Indexed Allocation - Mapping (continued) outer- index index table file

34 Combined Scheme: UNIX (4K bytes per block) Mode owners (2) timestamps (3) size block count direct blocks single indirect double indirect triple indirect data....................................

35 Free-Space Management Bit vector (n blocks) bit[ i ] = Bit vector (n blocks) bit[ i ] = 01 2 n-1... 0 block [ i ] free 1 block [ i ] occupied

36 Free-Space Management (continued) Block number calculation (number of bits per word) * (number of 0-value words) + offset of first 1 bit Bit map requires extra space. Example block size = 2 12 bytes disk size = 2 30 bytes ( 1 gigabyte) n = 2 30 /2 12 =2 18 (or 32K bytes) Block number calculation (number of bits per word) * (number of 0-value words) + offset of first 1 bit Bit map requires extra space. Example block size = 2 12 bytes disk size = 2 30 bytes ( 1 gigabyte) n = 2 30 /2 12 =2 18 (or 32K bytes)

37 Free-Space Management (continued) Easy to get contiguous files Linked list (free list) –Cannot get contiguous space easily –No waste of space Grouping Counting Easy to get contiguous files Linked list (free list) –Cannot get contiguous space easily –No waste of space Grouping Counting

38 Free-Space Management (continued) Need to protect –Pointer to free list –Bit map Must be kept on disk Copy in memory and disk may differ Cannot allow for block [ i ] to have a situation where bit [ i ] = 1 in memory and bit [ i ] = 0 on disk. Need to protect –Pointer to free list –Bit map Must be kept on disk Copy in memory and disk may differ Cannot allow for block [ i ] to have a situation where bit [ i ] = 1 in memory and bit [ i ] = 0 on disk.

39 Free-Space Management (continued) –Solution Set bit [ i ] = 1 in disk. Allocate block [ i ]. Set bit [ i ] = 1 in memory. –Solution Set bit [ i ] = 1 in disk. Allocate block [ i ]. Set bit [ i ] = 1 in memory.

40 Directory Implementation Linear list of file names with pointers to the data blocks Hash Table - linear list with hash data structure. Linear list of file names with pointers to the data blocks Hash Table - linear list with hash data structure.


Download ppt "Operating Systems Files, Directory and File Systems Operating Systems Files, Directory and File Systems."

Similar presentations


Ads by Google