CSC 453 Operating Systems Lecture 10 : File-System Interface The Concept of A File A file is a collection of data stored on external device or A file is a collection of data entering or exiting the computer.
File Attributes Files have various attributes, some of which vary from one system to another but generally include: Name a string intended for human use. Type needed on some system that support different file types Location a pointer to the device or file location Size expressed in bytes, words or blocks Protection who can read, write or execute it. Time, data and user identification File Operations Operations on file includes: opening and closing existing files creating and deleting files copying, renaming and listing files
Opening and Closing Files Files can be manipulated as a unit by operations such as: open - prepare the file to be referenced close - prevent further reference to a file until it is reopened Creating and Destroying Files Files operations also include: create - build a new file destroy- remove a file
Copying, Renaming and Listing Files copy - create another version of the file with a new name rename - change the name of a file list - print or display the contents of a file. File I/O Operations Individual data items within the file can be manipulated by operations such as: read - input a data item to process from a file write - output a data item from a process to a file update - modify an existing data item in a file
Data About An Open File Operating systems have a table containing the necessary data about open files. Such data includes: File pointer pointing to the position of the next read or write operation. File open count tracking the number of processes that have opened the file. Disk location of the file File Types File Type Executable Object Source code Batch Text Library Print or view Archive Usual Extension exe, com, bin (or none) obj, o c, p, pas, f, f77, asm, a bat, sh txt, doc lib, a ps, dvi, gif arc, zip, tar Function ready-to-run programs compiled & unlinked programs source code for programs series of commands Text data Library routines ASCII or binary files or viewing or printing related files compressed for archival purposes
File Structure Some files are structured in a particular way. E.g., Executable files must follow a certain format so the operating systems can load them and begin program execution. Some operating systems extend the concept to certain files types whose operations are supported by the operating system. Why Not Support Many File Structures? It s cumbersome, adding more code to the operating system What if the a new structure is needed? What if the operating system only supported text files and executable files? How would we implement encrypted files?
UNIX File Structure UNIX files are all considered to be a sequence of bytes. Any necessary structure can be imposed by an application program. The application program is responsible for implementing the necessary operations. MS-DOS and Windows have since adopted this approach. Bytes and the Data Hierarchy A pattern containing n bits will have 2 n possible different patterns. Bits are usually organized into groups of 8 bits called a byte, which provide 256 different combinations, more than enough to represent all the printable characters plus an entire set of control characters. This may be replaced in the future by code that use larger bit patterns (such as unicode) that can represent multiple character sets.
Files: Data Hierarchy Field - a collection of bytes used to represent a single data item relevant to an application. Record - a collection of related fields. File - a collection of related records, usually (but not always) of matching format. Searching A File By Key 123-45-6789.............. 123-45-6789 John Doe 118 Elm Street 11210..............
Access Methods The two most common access methods are: Sequential access Random access Sequential Access Rewind Read/write Start
Direct Access Record # 42 Indexed-Sequential Access Method 39 72 110 148 148 299 514 750 Disk Index File Index 80 90 98 101 107 110 Track index
What Is A Directory? Directories are a table of contents for a file system or an individual device. They can typically contain: - File Name - File Type - Location - Current & max. size - Protection - Owner - Usage count - Time, Date Directory Operations Directory operations include: Searching for a file Creating and deleting files Listing directory contents Renaming files Traversing the file system
Disk Organization Partition Table Directory Files Volume A Directory Files Volume B Directory Files Volume C Single Level Directory Dir File A File B File C File D
Two-Level Directory Dir User 1 User 2 User 3 File A File B File A File A File B Tree-structured Directories Dir OS Group 1 Group 2 Bob Ted Mary Nancy Sluggo
Acyclic-Graph Directories General-Graph Directory
Protection Protection can be implemented using: Controlled access Access Lists and Groups Passwords Controlled Access Controlled access means that we allow certain rights to the user to perform certain operations. These operations can be: read write execute append delete list
Access Lists and Groups We can make file access dependent of the user s identity. We can create access lists and specify the users and the access rights that they have. The largest problem is the length of such lists. File Protection In UNIX -rw-rw-r-- 1 rms faculty33002 May 3 13:08:02 590l1 -rwxr-xr- x 1 rms faculty 14532 May12 9:10:34 hello.c drwxr- x--x 2 rms faculty1024 May 1 11:00:03 Source drwxrw---x 3 rms faculty1024 May 1 11:00:03 lib
Passwords We can require passwords to gain access to a file. IBM VM/CMS allows three password per minidisk (or volume) and one per file. What is Consistency Semantics? Consistency semantics characterizes how a file system supports the concurrent sharing of files by multiple users. E.g., UNIX makes the results of write operations immediately visible to users who also have this file open.
Immutable-Shared-Files Semantics Immutable shared files are declared as shared by its creators and cannot be modified. This, their contents are fixed