Presentation is loading. Please wait.

Presentation is loading. Please wait.

Chapter 10: File System Interface Joe McCarthy CSS 430: Operating Systems - File System Interface1.

Similar presentations


Presentation on theme: "Chapter 10: File System Interface Joe McCarthy CSS 430: Operating Systems - File System Interface1."— Presentation transcript:

1 Chapter 10: File System Interface Joe McCarthy CSS 430: Operating Systems - File System Interface1

2 Chapter 10: File System Interface File Concept Access Methods Directory Structure File-System Mounting File Sharing Protection Material derived, in part, from Operating Systems Concepts with Java, 8 th Ed. © 2009 Silberschatz, Galvin & Gagne 2CSS 430: Operating Systems - File System Interface

3 File Concept What is a file? CSS430: Operating Systems - File System Interface3

4 File Concept Named collection of related information on secondary storage (nonvolatile) Smallest unit of logical secondary storage – May be composed of multiple physical secondary storage units – Logically contiguous space – May be physically distributed CSS430: Operating Systems - File System Interface4

5 File Structure Levels of structure – None - sequence of words, bytes – Simple record structure Lines Fixed length records Variable length records – Complex structures Formatted document Relocatable load file – Can simulate last two with first method by inserting appropriate control characters Structure imposed by: – Operating system – Program CSS 430: Operating Systems - File System Interface5

6 File Attributes CSS 430: Operating Systems - File System Interface6

7 File Attributes Name: only information kept in human-readable form Identifier: unique tag (number) identifies file within file system Type: needed for systems that support different types Location: pointer to file location on device Size: current file size Protection: specifies who can read, write, execute Time, date, and owner identification: data for protection, security, and usage monitoring Information about files are kept in the directory structure, which is maintained on the disk CSS 430: Operating Systems - File System Interface7

8 Linux ls –l, stat CSS 430: Operating Systems - File System Interface8 [joemcc@uw1-320-18 ThreadOS]$ ls -l Kernel*.java -rw------- 1 css430 users 10193 Nov 11 2004 Kernel_fil.java -rw------- 1 css430 users 8603 Dec 23 2010 Kernel_hw3part1.java -rw-r--r-- 1 css430 users 8395 Nov 13 2004 Kernel.java -rw------- 1 css430 users 8817 Nov 11 2004 Kernel_org.java [joemcc@uw1-320-18 ThreadOS]$ stat Kernel.java File: `Kernel.java' Size: 8395 Blocks: 24 IO Block: 32768 regular file Device: 17h/23dInode: 130884 Links: 1 Access: (0644/-rw-r--r--) Uid: ( 1803/ css430) Gid: ( 100/ users) Access: 2011-11-12 19:40:45.000000000 -0800 Modify: 2004-11-13 20:36:20.000000000 -0800 Change: 2011-10-17 14:00:43.000000000 -0700

9 File Operations CSS 430: Operating Systems - File System Interface9

10 File Operations CSS 430: Operating Systems - File System Interface10 OperationsDescriptionsUnixThreadOS CreateCreate a file with its attributecreat(filename,mode)N/A OpenOpen the specified file. (Create it if mode specified and necessary) open(filename,flag,mode)SysLib.open(filename,mode) ReadRead from a fileread(fd, buf, size)SysLib.read(fd, buffer) WriteWrite a filewrite(fd, buf, size)SysLib.write(fd, buffer) SeekReposition a file access pointlseek(fd, offset, origin)SysLib.seek(fd, offset, whence) CloseClose the file specified with fdclose(fd)SysLib.close(fd) DeleteDestroy the specified fileremove(filename)SysLib.delete(filename) TruncateResize the file to a specified lengthtruncate(filename, length)N/A StatusReturns the specified file statusstat(fd, statbuf)SysLib.fsize(fd) FormatFormat the diskN/ASysLib.format(files)

11 lseek (logical seek) lseek( int fd, int offset, int origin ) – Reposition logical file pointer (fp) within an open file – fd : file descriptor 0 (STDIN_FILENO) 1 (STDOUT_FILENO) 2 (STDERR_FILENO) … – offset can be + or – (down/right or up/left) – origin ( whence in SysLib.seek() ) 0 (SEEK_SET), offset from start of file ( offset must be +) 1 (SEEK_CUR), offset from current fp position 2 (SEEK_END), offset from end of file ( offset must be -) CSS430: Operating Systems - File System Interface11

12 CSS430: Operating Systems - File System Interface12 lseek (logical seek) lseek( int fd, int offset, int origin ) origin == 0 (SEEK_SET) origin == 1 (SEEK_CUR) origin == 2 (SEEK_END) offset (> 0) new file pointer position EOF offset (> 0) new file pointer position EOF offset (< 0) EOF current file pointer position new file pointer position

13 Open Files Several pieces of data are needed to manage open files: – File pointer: pointer to next read/write location, per process that has the file open – File open count: counter of # processes that have opened file - # of processes that have closed it when 0, can remove entry from system-wide open file table – Disk location of the file: cache of data access information – Access rights: per-process access mode information CSS 430: Operating Systems - File System Interface13

14 Recall: File Descriptors (Ch. 3) CSS 430: Operating Systems - File System Interface14 http://www.cis.temple.edu/~ingargio/cis 307/readings/unix1.html http://cs.oberlin.edu/~jdonalds/3 41/lecture24.html

15 File Types 15CSS 430: Operating Systems - File System Interface

16 File Types 16CSS 430: Operating Systems - File System Interface

17 Access Methods Sequential Access read next block write next block reset no read after last write (rewrite) Direct Access read block n write block n position to block n read next block write next block rewrite block n n = relative block number 17CSS 430: Operating Systems - File System Interface

18 Directory Structure A collection of nodes containing information about all files F 1 F 2 F 3 F 4 F n Directory Files * Both the directory structure and the files reside on disk 18CSS 430: Operating Systems - File System Interface

19 A Typical File-System Organization CSS 430: Operating Systems - File System Interface19

20 Operations Performed on Directory CSS 430: Operating Systems - File System Interface20

21 Operations Performed on Directory Search for a file Create a file Delete a file List a directory Rename a file Change working directory – Navigate / traverse the file system CSS 430: Operating Systems - File System Interface21

22 Single-Level Directory A single directory for all users CSS 430: Operating Systems - File System Interface22 Naming problem Grouping problem

23 Two-Level Directory Separate directory for each user CSS 430: Operating Systems - File System Interface23 Path names Can [re]use the same file name for different users Efficient searching No grouping capability

24 Tree-Structured Directories CSS 430: Operating Systems - File System Interface24 Absolute & relative paths, current working directory Can [re]use the same file name in any directory Efficient searching Grouping capability

25 Acyclic-Graph Directories For sharing subdirectories and files CSS 430: Operating Systems - File System Interface25

26 Acyclic-Graph Directories For sharing subdirectories and files CSS 430: Operating Systems - File System Interface26 What if /dict/w/list is deleted?

27 General Graph Directory CSS 430: Operating Systems - File System Interface27

28 General Graph Directory How do we guarantee no cycles? CSS 430: Operating Systems - File System Interface28

29 General Graph Directory How do we guarantee no cycles? – Allow only links to files (not subdirectories) – Garbage collection – Every time a new link is added use a cycle detection algorithm to determine whether it is OK CSS 430: Operating Systems - File System Interface29

30 File System Mounting A file system must be mounted before it can be accessed A unmounted file system is mounted at a mount point CSS 430: Operating Systems - File System Interface30

31 Linux df CSS 430: Operating Systems - File System Interface31 [css430@uw1-320-19 ~]$ df Filesystem 1K-blocks Used Available Use% Mounted on /dev/mapper/VG00-lv_root 2951952 900344 1899240 33% / /dev/sda1 101086 24835 71032 26% /boot tmpfs 1036984 0 1036984 0% /dev/shm /dev/mapper/VG00-lv_home 1967952 35808 1830564 2% /home /dev/mapper/VG00-lv_tmp 1967952 36960 1829412 2% /tmp /dev/mapper/VG00-lv_usr 60216936 14042456 43071736 25% /usr /dev/mapper/VG00-lv_var 2984720 1169764 1664236 42% /var metis.uwb.edu:/usr/apps 18385920 14719200 2736224 85% /usr/apps medusa.uwb.edu:/home/uwagent 35318528 21919264 11611904 66% /home/uwagent medusa.uwb.edu:/home/condor 35318528 21919264 11611904 66% /home/condor medusa.uwb.edu:/home/hadoop 35318528 21919264 11611904 66% /home/hadoop 69.91.206.17:/home2 108598240 77730208 26454816 75% /net/metis/home2 metis:/home4 12095040 1847840 9632800 17% /net/metis/home4

32 File Sharing Sharing of files on multi-user systems is desirable Sharing may be done through a protection scheme On distributed systems, files may be shared across a network Network File System (NFS) is a common distributed file-sharing method 32CSS 430: Operating Systems - File System Interface

33 File Sharing – Multiple Users User IDs identify users, allowing permissions and protections to be per-user Group IDs allow users to be in groups, permitting group access rights CSS 430: Operating Systems - File System Interface33

34 Protection File owner/creator should be able to control: – what can be done – by whom Types of access – Read – Write – Execute – Append – Delete – List CSS 430: Operating Systems - File System Interface34

35 Access Lists & Groups CSS 430: Operating Systems - File System Interface35 Only administrators can create users & groups 3 modes of access: read, write, execute 3 classes of users: RWX a) owner 7  1 1 1 RWX b) group 6  1 1 0 RWX c) universe4  1 0 0 Example settings (Linux): – 755 (-rwxr-xr-x) – 644 (-rw-r--r--) – 700 (drwx------) [“d” = directory]

36 Windows XP Access-control List Management CSS 430: Operating Systems - File System Interface36

37 A Sample UNIX Directory Listing CSS 430: Operating Systems - File System Interface37


Download ppt "Chapter 10: File System Interface Joe McCarthy CSS 430: Operating Systems - File System Interface1."

Similar presentations


Ads by Google