Presentation is loading. Please wait.

Presentation is loading. Please wait.

Operating Systems (CS 340 D)

Similar presentations


Presentation on theme: "Operating Systems (CS 340 D)"— Presentation transcript:

1 Operating Systems (CS 340 D)
Princess Nora University Faculty of Computer & Information Systems Computer science Department Operating Systems (CS 340 D)

2 File System Implementation

3 Chapter 12: File System Implementation
Allocation Methods Free Space Management

4 OBJECTIVES: Introduction to file system structure. To discuss block allocation and free-block algorithms

5 File-System Structure

6 File systems Disks: File systems
A disk can access directly any block of information it contains. Thus, it is simple to access any file either sequentially or randomly, It can switch from one file to another requires only moving the read– write heads and waiting for the disk to rotate. To improve I/O efficiency, I/O transfers between memory and disk are performed in units of blocks. Each block has one or more sectors. sector size varies from (32 -4,096) bytes; the usual block size is 512 bytes. File systems file system provides the mechanism for efficient and convenient storage and access to file contents, including data and programs. file system resides permanently on secondary storage,

7 File systems A file system poses two different design problems: The first problem is defining how the file system should look to the user. This task involves defining a file and its attributes, the operations allowed on a file, and the directory structure for organizing files. The second problem is creating algorithms and data structures to map the logical file system onto the physical secondary-storage devices

8 File-System Structure
File structure Logical storage unit Collection of related information File system resides on secondary storage (disks) Provided user interface to storage, mapping logical file system to physical Provides efficient and convenient access to disk by allowing data to be stored, located retrieved easily File control block–storage structure consisting of information about a file Device driver controls the physical device

9 File-System Structure (Cont.)
File system organized into layers (/levels) Each level in the design uses the features of lower levels to create new features for use by higher levels.

10 Metadata is data that describes other data.
Layered File-System Logical File System Level: Input: a symbolic file name Output: file information It manages metadata information (i.e. data about files) It manages the directory structure It maintains file-control blocks (FCB). It is also responsible for protection and security. Metadata is data that describes other data. FCB: contains information about the file, including ownership, permissions, location …etc.

11 Layered File-System (cont.)
The file-organization module level Input: file information (logical blocks) Output: physical block addresses. It knows about files and their logical blocks, as well as physical blocks. It translate logical block addresses to physical block addresses. Each file’s logical blocks are numbered from 0 through N. Each physical block is identified by its numeric disk address (e.g. drive 1,cylinder 73, track 2, sector 10). It includes the free-space manager, which tracks unallocated blocks .

12 Layered File-System (cont.)
The basic file system level: Input: physical block addresses Output: generic commands to device driver It needs only to issue generic commands to the appropriate device driver to read and write physical blocks on the disk. This layer also manages the memory buffers and caches that hold various file-system, directory, and data blocks.

13 Layered File-System (cont.)
The I/O control level: It consists of device drivers and interrupt handlers to transfer information between the RAM and the disk system A device driver can be thought of as a translator. Device driver input consists of high-level commands such as “retrieve block 123.” Device driver output consists of low level, hardware-specific instructions that are used by the hardware controller, which interfaces the I/O device to the rest of the system.

14 File-System Structure (cont.)
layered structure Pros. (++): useful for reducing duplication of code. The “I/O control level” and sometimes “the basic file-system code” can be used by multiple file systems. layered structure Cons. (--): Layering can introduce more operating-system overhead, which may result in decreased performance. Many file systems are in use today. Most operating systems support more than one: UNIX uses the UNIX file system (UFS), Windows NT ,2000 and XP support disk file-system formats of FAT, FAT32, and NTFS (or Windows NT File System), as well as CD- ROM, DVD, and floppy-disk file-system formats.

15 File-System Implementation

16 File-System Implementation
Several on-disk and in-memory structures are used to implement a file system. On-disk structures : Boot control block: (per volume) - contains info. needed by system to boot OS from that volume If the disk does not contain an OS, this block can be empty. Volume control block (superblock /master file table): (per volume)- contains volume details such as total # of blocks, # of free blocks, block size, free block pointers . Directory structure: (per file system) - is used to organize the files. File Control Block (FCB): (per file)- contains many details about the file

17 Virtual File Systems Main problem: Solution:
how does an operating system allow multiple types of file systems to be integrated into a directory structure? how can users seamlessly move between file-system types as they navigate the file-system space? Solution: write directory and file routines for each type Instead, most operating systems(e.g. UNIX) use object-oriented techniques to simplify the implementation. The use of these methods allows different file-system types to be implemented within the same structure, including network file systems, such as NFS.

18 Virtual File Systems Data structures and procedures are used to isolate the basic system call functionality from the implementation details. Thus, the file-system implementation consists of (3)major layers: first layer :: the file-system interface>>> based on the open(), read(), write(), and close() calls and on file descriptors. Second layer:: Virtual File System layer (VFS)>>>>It serves two important functions: Separates file-system generic operations from implementation details It provides a mechanism for uniquely representing a file throughout a network.

19 Schematic View of Virtual File System

20 Directory Implementation
How to implement the directory? Using Linear list of file names with pointer to the data blocks Simple to program (++) Time-consuming to execute (--) Linear search time (--) >>>>(long time) Sorted list can be use to decrease search time but maintaining a sorted list is complex . Hash Table a linear list stores the directory entries, but a hash data structure is also used. The hash table takes a value computed from the file name and returns a pointer to the file name in the linear list. It Decreases directory search time (++) Some provision must be made for Collisions (--) The major difficulties with a hash table are its fixed size (--) Collisions–situations where two file names hash to the same location

21 Allocation Methods

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

23 1-Contiguous Allocation

24 Contiguous Allocation
Basic Idea: Each file occupies a set of contiguous blocks on the disk The directory entry for each file indicates : address of the starting block length of the area allocated for this file

25 Contiguous Allocation (cont.)
Pros. (++): Simple Good performance-the number of disk head seeks required for accessing contiguously allocated files is minimal It support sequential and direct access efficiently Cons. (--): Dynamic storage-allocation problem (how to satisfy a request of size n from a list of free holes). First fit and best fit are the most common strategies used External fragmentation One solution is compaction (/defragmentation) which is time consuming File is difficult to grow Size declaration problem :How does the creator know the size of the file to be created?

26 Contiguous Allocation (cont.)
Many newer file systems use a modified contiguous- allocation scheme: a contiguous chunk of space is allocated initially; then, if that amount proves not to be large enough, another chunk of contiguous space, known as an extent, is added (i.e. A file consists of one or more extents) The location of a file’s blocks is then recorded as: a location a block count a link to the first block of the next extent This scheme is used to improve performance

27 2-Linked Allocation

28 Linked Allocation Basic Idea:
Each file is a linked list of disk blocks: blocks may be scattered anywhere on the disk The directory contains a pointer to the first and last blocks of the file. pointer block = *

29 Linked Allocation Pros. (++): Cons. (--):
Simple – need only starting address No external fragmentation A file can grow - no need for disk compaction no size declaration problem It is efficient for sequential access Cons. (--): It is inefficient for direct access low performance-It may required multiple disk head seeks to access single file’s blocks because the block is scattered A space is required for the pointers. Low reliability: what happen if a pointer damaged or lost?? *

30 File-allocation table (FAT)
An important variation on linked allocation is the use of a file-allocation table (FAT). It used in the MS-DOS and OS/2 operating systems. Basic Idea: A section of disk at the beginning of each volume is used to store the table (FAT). The FAT is used in much the same way as a linked list. The table has one entry for each disk block and is indexed by block number. The directory entry contains the block number of the first block of the file. The table entry indexed by that block number contains the block number of the next block in the file. This chain continues until it reaches the last block, which has a special “end-of-file” value as the table entry. An unused block is indicated by a table value of 0.

31 File-allocation table (FAT)
Pros. (++): Simple If the FAT is cached, FAT is efficient for direct access

32 3-Indexed Allocation

33 Indexed Allocation Method
Basic Idea: Each file has its own index block which is an array of disk-block addresses The directory contains the address of the index block. To find and read the ith block, we use the pointer in the ith index- block entry. *

34 Indexed Allocation (cont.)
Pros. (++): Efficient for sequential & direct access No external fragmentation Cons. (--): It needs index table….(wasted space) low performance-It may required multiple disk head seeks to access single file’s blocks because the block is scattered wasted space is more than pointers’ space used in linked allocation method Same as performance problem of linked allocation method

35 Free-Space Management

36 Free-Space Management
File system maintains free-space list to track available blocks Different methods to implement free-space list: Bit vector (/bit map): Each block is represented by 1 bit. If the block is free, the bit is 1; if the block is allocated, the bit is 0. Blocks that are not allocated for any file

37 Efficiency and Performance
Disks tend to represent a major bottleneck in system performance, since they are the slowest main computer component Efficiency depends on: The disk allocation and directory algorithms in use The types of data kept in file’s directory entry (e.g. “ last access date” field need the directory to be updated for every file access)

38 Efficiency and Performance
Improve performance by dedicating section of memory as disk cache to store frequently used blocks Some systems optimize their cache by using different replacement algorithms such as free-behind and read-ahead techniques >>>>>>(( For sequential access files )) Free-behind techniques: removes a page from the buffer as soon as the next page is requested. The previous pages are not likely to be used again . Read-ahead techniques :a requested page and several subsequent pages are read and cached. These pages are likely to be requested after the current page is processed. Retrieving these data from the disk in one transfer and caching them saves a considerable amount of time.

39 Thank you The End


Download ppt "Operating Systems (CS 340 D)"

Similar presentations


Ads by Google