Presentation is loading. Please wait.

Presentation is loading. Please wait.

Chapter 11 File-System Interface

Similar presentations


Presentation on theme: "Chapter 11 File-System Interface"— Presentation transcript:

1 Chapter 11 File-System Interface

2 File-System The file-system consists of two distinct parts:
A collection of files, each storing related data A directory structure, which organized and provides information about all the files in the system. Some file systems have a third part, partitions, which are used to separate physically or logically large collection of directories.

3 File-System Multiple-Choices Questions:
( ) Which of the following parts is not belonging to a file system? (A) programs (B) files (C) directory structure (D) partitions The file-system consists of two distinct parts: A collection of files, each storing related data A directory structure, which organized and provides information about all the files in the system. Some file systems have a third part, partitons, which are used to seperate physically or logically large collection of directories. Ans: A

4 File Concept § 11.1 The OS abstracts from the physical properties of its storage devices to define a logical storage unit (the file). User’s view of a file as the smallest allotment of logical secondary storage. Files may be free form, such as text files, or may be formatted rigidly.

5 File Concept § 11.1 True-False Question: ( ) From a user’s perspective, a file is the largest allotment of logical secondary storage. The OS abstracts from the physical properties of its storage devices to define a logical storage unit (the file). User’s view of a file as the smallest allotment of logical secondary storage. Files may be free form, such as text files, or may be formatted rigidly. Ans: X

6 File Concept The information in a file is defined by its creator.
A file has a certain defined structure according to its type. text file: a sequence of characters organized into lines or pages. source file: a sequence of subroutines and functions. object file: a sequence of bytes organized into blocks understandable by the system’s linker. executable file: a series of code sections that the loader can bring into memory and execute.

7 File Attributes Name – only information kept in human-readable form.
§ Name – only information kept in human-readable form. Identifier – identifies the file within the file sysem; non-human-readable name for the file. Type – needed for systems that support different types. Location – pointer to a device and to the location of the file on that 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.

8 File Attributes Information about files are kept in the directory structure, which is maintained on the disk. The directory entry consists of the file’s name and its unique identifier. The identifier in turn locates the other file attributes. May take more than a kilobyte to record this information for each file. In a system with many files, the size of the directory itself may be megabytes.

9 File Operations Six basic file operations: Creating a file
§ Six basic file operations: Creating a file Writing a file Reading a file Repositioning a file Deleting a file Truncating a file

10 Other common operations
Append new info to the end of existing file. Rename existing file Copy a file (Combined from other file operations) Get and set various file attributes

11 Open-File Table To avoid directory searching for the entry associated with the named file while constantly performing above operations, many system require that an open system call be used before that file is first used actively. OS keeps the open-file table containing information about all open files. When a file is requested, the file is specified via an index into this table, no searching is required.

12 Open-File Table True-False Question:
( ) With the help of open-file table, no searching will ever be needed. To avoid directory searching for the entry associated with the named file while constantly performing above operations, many system require that an open system call be used before that file is first used activtly. OS keeps the open-file table containing information about all open files. When a file is requested, the file is specified via an index into this table, no searching is required. Ans: X

13 open Operation The open operation takes a file name and searches the directory, copying the directory entry into the open-file table. If request modes are allowed, the file is opened for the process. open returns a pointer to the entry in the open-file table. This pointer, not the actual file name, is used in all I/O, avoiding any further searching.

14 In Multiuser Environment
The open and close in multiuser environment, such as UNIX, is more complicated since several users may open the file at the same time. Two levels of internal tables: a per-process table tracks all files that a process has open. Including current file pointer, access rights, and accounting information. a system-wide table

15 In Multiuser Environment
Each entry in the per-process table in turn points to a system-wide open-file table which contains process-independent information such as the location of the file on disk, access dates, and file size. Information associated with an open file: File pointer File open count Disk location of the file Access rights

16 File Types § If an OS recognizes the type of a file, it can then operate on the file in reasonable ways. Common technique: file name extension. Example: MS-DOS TOPS-20 Apple Macintosh UNIX

17 File Types

18 TOPS-20 If the user tries to execute an object program whose source file has been modified (or edited) since the object file was produced, the source file will be recompiled automatically. Avoid wasting times executing the old object file.

19 TOPS-20 The OS must distinguish source file from the object file, check the time that each file was created or last modified, and determine the language of the source program.

20 Apple Macintosh Each file also has a creator attribute containing the name of the program that created it. When the user opens that file, the corresponding application program is invoked automatically

21 UNIX UNIX uses a crude magic number stored at the beginning of some files to indicate roughly the type of the file. Not all files have magic numbers, so system features cannot be based solely on this type of information. UNIX does not record the name of the creating program, either.

22 UNIX Multiple-Choices Questions: ( ) UNIX uses a ________ stored at the beginning of some files to indicate roughly the type of the file. (A) file pointer (B) magic number (C) index number (D) type pointer UNIX uses a crude magic number stored at the beginning of some files to indicate roughly the type of the file. Not all files have magic numbers, so system features cannot be based solely on this type of information. UNIX does not record the name of the creating program, either. Ans: B

23 File Structure § Certain files must conform to a required structure that is understood by the OS. Some system support multiple file structures ... needs to contain the code to support each different file structure. Problem may result if new applications require different structure from the system supported structures.

24 Example: UNIX UNIX support minimal number of file structure. It considers each file to be a sequence of 8-bit bytes; no interpretation of these bits is made by the OS. This scheme provides maximum flexibility, but little support. However, all OS must support at least one structure – executable file structure.

25 Example: UNIX True-False Question:
( ) UNIX support minimal number of file structure and consider each file to be a sequence of 8-bit bytes. This scheme has no flexibility at all. UNIX support minimal number of file structure. It considers each file to be a sequence of 8-bit bytes; no interpretation of these bits is made by the OS. This scheme provides maximum flexibility, but little support. However, all OS must support at least one structure – executable file structure. Ans: X

26 Example: Macintosh Files contain two parts: resource fork  and data fork.  Too few structures make programming inconvenient, whereas too many cause OS bloat and programmer confusion. Contain information of interest to the user Contain program code or data, as traditional file.

27 Internal File Structure
§ The physical record size will not exactly match the length of the logical record ... packing a number of logical records into physical records. UNIX: define all files to be simply a stream of bytes. File system automatically packs and unpacks bytes into physical disk blocks – say, 512bytes per block – as necessary.

28 Internal Fragmentation
Because disk space is always allocated in blocks, some portion of the last block of each file is generally wasted. All file systems suffer from internal fragmentation; the larger the block size, the greater the internal fragmentation.

29 Access Methods § 11.2 Sequential access. The simplest and by far the most common method. Information in the file is processed in order, one record after the other. Editor and Compiler usually use this method. Based on a tape model of a file.

30 Access Methods Direct Access. A file is made up of fixed-length logical records that allow programs to read and write records rapidly in no particular order. Based on a disk model of a file which allowing random access to any file block. Useful for immediate access to large amounts of information such as database.

31 Access Methods It is easy to simulate sequential access on a direct-access file. It is extremely inefficeint and clumsy to simulate a direct-access file on a sequential-access file.

32 Other Access Methods Other access methods can be built on top of a direct-access method. Generally using an index contains pointers to the blocks. To find a record in the file, first search the index, then use the pointer to access the file directly and to find the desired record.

33 Other Access Methods Example: Retail-price file listing the universal product codes (UPCs) and the prices for each item. Each record consists of a 10-digit UPC and a 6 digit price for a 16-byte record. For 1024 bytes per block disk, can store 64 records per block. A file of records occupy about 2000 blocks. Define an index consisting of the first UPC in each block. This index would have 2000 entries of 10 digits each, or bytes. Searching the index would know exactly which block contains the desired record.

34 Large Files With large files, the index file itself may become too large to be kept in memory ... create an index for the index file. The primary index file contain pointers to secondary index files, which would point to the actual data items.

35 ISAM of IBM IBM’s indexed sequential-access method (ISIM) uses a small master index that points to disk blocks of a secondary index. The secondary index blocks point to the actual file blocks. To find a particular item, we first make a binary search of the master index, which provides the block number of the secondary index. A search again used to find the block containing the desired record. Finally, this block is searched sequentially. In this way, any record can be located from its key by at most two direct-access reads.

36 Example – VMS indexes


Download ppt "Chapter 11 File-System Interface"

Similar presentations


Ads by Google