Presentation is loading. Please wait.

Presentation is loading. Please wait.

Operating System File-System Interface

Similar presentations


Presentation on theme: "Operating System File-System Interface"— Presentation transcript:

1 Operating System File-System Interface

2 Files A file is a collection of data with some properties contents, size, owner, last read/write time, protection … Files may also have types understood by file system device, directory, symbolic link understood by other parts of OS or by runtime libraries executable, dll, source code, object code, text file, …

3 Type can be encoded in the file’s name or contents
windows encodes type in name .com, .exe, .bat, .dll, .jpg, .mov, .mp3, … old Mac OS stored the name of the creating program along with the file unix has a smattering of both in content via magic numbers or initial characters (e.g., #!)

4 File Structure Simple record structure Lines Fixed length
Variable length Complex Structures Formatted document Re-locatable load file Can simulate last two with first method by inserting appropriate control characters Who decides: Operating system Program

5 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 – 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

6 File Operations File is an abstract data type Create Write Read
Reposition within file Delete Truncate Open(Fi) – search the directory structure on disk for entry Fi, and move the content of entry to memory Close (Fi) – move the content of entry Fi in memory to directory structure on disk

7 Basic operations Windows Unix CreateFile(name, CREATE) create(name)
CreateFile(name, OPEN) ReadFile(handle, …) WriteFile(handle, …) FlushFileBuffers(handle, …) SetFilePointer(handle, …) CloseHandle(handle, …) DeleteFile(name) CopyFile(name) MoveFile(name) Unix create(name) open(name, mode) read(fd, buf, len) write(fd, buf, len) sync(fd) seek(fd, pos) close(fd) unlink(name) rename(old, new)

8 Open Files Several pieces of data are needed to manage open files:
File pointer: pointer to last read/write location, per process that has the file open File-open count: counter of number of times a file is open – to allow removal of data from open-file table when last processes closes it Disk location of the file: cache of data access information Access rights: per-process access mode information

9 File Types – Name, Extension

10 File access methods Some file systems provide different access methods that specify ways the application will access data sequential access read bytes one at a time, in order direct access random access given a block/byte # record access file is array of fixed- or variable-sized records indexed access FS contains an index to a particular field of each record in a file apps can find a file based on value in that record (similar to DB) Why do we care about distinguishing sequential from direct access? what might the FS do differently in these cases?

11 Access Methods Sequential Access read next write next reset
no read after last write (rewrite) Direct Access read n write n position to n rewrite n n = relative block number

12 Directories Directories provide:
a way for users to organize their files a convenient file name space for both users and FS’s Most file systems support multi-level directories naming hierarchies (/, /usr, /usr/local, /usr/local/bin, …) Most file systems support the notion of current directory absolute names: fully-qualified starting from root of FS bash$ cd /usr/local relative names: specified with respect to current directory bash$ cd /usr/local (absolute) bash$ cd bin (relative, equivalent to cd /usr/local/bin)

13 Directory internals A directory is typically just a file that happens to contain special metadata directory = list of (name of file, file attributes) attributes include such things as: size, protection, location on disk, creation time, access time, … the directory list is usually unordered (effectively random) when you type “ls”, the “ls” command sorts the results for you

14 Directory Structure A collection of nodes containing information about all files Directory Files F 1 F 2 F 3 F 4 F n Both the directory structure and the files reside on disk Backups of these two structures are kept on tapes

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

16 Disk Structure Disk can be subdivided into partitions Entity containing file system known as a volume Each volume containing file system also tracks that file system’s info in device directory or volume table of contents As well as general-purpose file systems there are many special-purpose file systems, frequently all within the same operating system or computer

17 Tree-Structured Directories

18 Acyclic-Graph Directories
Have shared subdirectories and files

19 General Graph Directory

20 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

21 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

22 memory-resident i-node table
Process 1 Process 2 (child) Process 3 channel table channel table channel table open file table file offset file offset memory-resident i-node table disk file buffer cache

23 File Sharing – Remote File Systems
Uses networking to allow file system access between systems Manually via programs like FTP Automatically, seamlessly using distributed file systems Semi automatically via the world wide web Client-server model allows clients to mount remote file systems from servers Server can serve multiple clients Client and user-on-client identification is insecure or complicated NFS is standard UNIX client-server file sharing protocol CIFS is standard Windows protocol Standard operating system file calls are translated into remote calls

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

25 Access Lists and Groups
Mode of access: read, write, execute Three classes of users RWX a) owner access 7  RWX b) group access 6  1 1 0 c) public access 1  0 0 1 Ask manager to create a group (unique name), say G, and add some users to the group. For a particular file (say game) or subdirectory, define an appropriate access.

26 ACLs vs. Capabilities Capabilities are easy to transfer
they are like keys: can hand them off they make sharing easy ACLs are easier to manage object-centric, easy to grant and revoke to revoke capability, need to keep track of principals that have it hard to do, given that principals can hand off capabilities ACLs grow large when object is heavily shared can simplify by using “groups” put users in groups, put groups in ACLs you are all in the “VMware powerusers” group on Win2K additional benefit change group membership, affects ALL objects that have this group in its ACL

27 A Typical File Control Block

28 Allocation Methods An allocation method refers to how disk blocks are allocated for files: Contiguous allocation Linked allocation Indexed allocation

29 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). Files cannot grow.

30 Contiguous Allocation of Disk Space
Operating System Concepts

31 Linked Allocation Each file is a linked list of disk blocks: blocks may be scattered anywhere on the disk. pointer block = File-allocation table (FAT) – disk-space allocation used by MS-DOS and OS/2.

32 Linked Allocation

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

34 Example of Indexed Allocation

35 Indexed Allocation (Cont.)
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.

36 The original Unix file system
Dennis Ritchie and Ken Thompson, Bell Labs, 1969 “UNIX rose from the ashes of a multi-organizational effort in the early 1960s to develop a dependable timesharing operating system” – Multics Designed for a “workgroup” sharing a single system Did its job exceedingly well Although it has been stretched in many directions and made ugly in the process A wonderful study in engineering tradeoffs

37 (Old) Unix disks are divided into five parts …
Boot block can boot the system by loading from this block Superblock specifies boundaries of next 3 areas, and contains head of freelists of inodes and file blocks i-node area contains descriptors (i-nodes) for each file on the disk; all i-nodes are the same size; head of freelist is in the superblock File contents area fixed-size blocks; head of freelist is in the superblock Swap area holds processes that have been swapped out of memory

38 i-node format User number Group number Protection bits
Times (file last read, file last written, inode last written) File code: specifies if the i-node represents a directory, an ordinary user file, or a “special file” (typically an I/O device) Size: length of file in bytes Block list: locates contents of file (in the file contents area) more on this soon! Link count: number of directories referencing this i-node


Download ppt "Operating System File-System Interface"

Similar presentations


Ads by Google