0% found this document useful (0 votes)
25 views11 pages

File System-1

This document discusses the key concepts of file systems including what a file is, file structures and types, file operations and attributes. It describes file management systems and how they allocate space and manage free space. Methods for accessing files include sequential, direct/random and indexed sequential access. Directory systems are discussed from single-level to more complex hierarchical structures. Common operations on directories like search, create, delete and rename files are also outlined.

Uploaded by

Leslie Qwer
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
25 views11 pages

File System-1

This document discusses the key concepts of file systems including what a file is, file structures and types, file operations and attributes. It describes file management systems and how they allocate space and manage free space. Methods for accessing files include sequential, direct/random and indexed sequential access. Directory systems are discussed from single-level to more complex hierarchical structures. Common operations on directories like search, create, delete and rename files are also outlined.

Uploaded by

Leslie Qwer
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

File System

Contents
 What is a File?
 File Structure
 File Type
 Operations of Files
 File attributes
 File Management System (FMS)
 File accessing methods
o Sequential access
o Direct/Random access
o Indexed sequential access
 File directories
 Operations on file Directory
 File Directory System
o Single-Level Directory System
o Two-Level Directory System
o Tree-Structured /Hierarchical Directories
o General graph directory structure
 FILE Allocation Method (Space Allocation)
o Contiguous Allocation
o Linked Allocation
o Indexed Allocation(Group Allocation)
 Free-Space Management (Disk space Management)
o Bit Vector
o Chain Free points (Linked Free space list)
o Index block list
 Record Blocking
o Fixed blocking
o Variable Length spanned blocking
o Variable length un spanned blocking
File Management System
File concept
 A file is a named collection of related information that is recorded on secondary storage such as
magnetic disks, magnetic tapes and optical disks.
 From user’s perspective file is the smallest allotment of logical secondary storage. Data cannot be
written to secondary storage unless they are within a file.
 The physical storage is converted into a logical storage unit by the operating system. The logical
unit is said to be the ‘FILE’.
 In general, a file is a sequence of bits, bytes, lines or records whose meaning is defined by the files
creator and user.
 Many different types of information may be stored in a file such as source program, object
program, executable program, numeric data, text, payroll records, graphic images, sound recording
and so on.

File Structure
 File structure is a structure, which is according to a required format that operating system can
understand. A file has a certain defined structure according to its type.
 A text file structure is a sequence of characters organized into lines.
 A source file structure is a sequence of procedures and functions.
 An object file structure is a sequence of bytes organized into blocks that are understandable by the
machine.
File Types
 File type refers to the ability of the operating system to distinguish different types of file.
 Operating system implements file type as a part of file name. The name of the file is split into two
parts a name and an extension.
 The system uses the extension to indicate the type of a file.
 Many operating systems support many types of files. Some types of files are:
Ordinary files
 These are the files that contain user information.
 These may have text, databases or executable program.
 The user can apply various operations on such files like add, modify, delete or even remove the
entire file.
Directory files
 These files contain list of file names and other information related to these files.

Special files:
 These files are also known as device files.
 These files represent physical device like disks, terminals, printers, networks, tape drive etc.
File type Extension Purpose/function
Executable .exe, .com, .bin Ready to run
Source code .c, .cpp, .pas, .java Source code in various
language
Batch .bat, .sh Command to the command
interpreter
Library .lib, .a, Libraries of routines
Text .txt, .doc, Textual data documents
Multimedia .mpeg, .mov, .rm Audio/video information

Operations of Files
The OS provides system calls to do operations on programmable file.The six basic file operations are:

1. Creating a file: There are two steps to create a file. First check weather space is available for the
file and secondly the entry for new file must be made in a directory. Directory entry include name
of the file, location of the file etc..

2. Writing a file: Two steps to write a file. Make a system call specifying the name of the file. Given
the name of the file, system searches the directory to find the location and then if the file is found
then secondly system must keep a pointer to the location in the file where the next write is to take
place.

3. Reading a file: To read file first to search the directories if found the system need to keep a read
pointer to the location in the file

4. Repositioning within a file: This file operation is also known as File Seek. That is resetting the
current file position to a given value.

5. Deleting a file: File searched and erased from the directory

6. Truncating a file: Remove the file contents only, but the attributes remains.

Other common operations include Appending new information and Renaming an existing file.

File attributes:
Attributes of a File are :

1. Name – A file is named for user convenience and is referred by its name. File name is the only
information kept in human-readable form.
2. Type – Files are many types, the type is depending on the extension of the file. Type is needed
for systems that support different types
3. Location – pointer to file location on device
4. Size – current file size (in bytes or blocks)
5. Protection – It specifies access control, controls who can do reading, writing, executing and so
on
6. Time, date– it specifies the time and date a file is created or last accessed.
7. User identification- This is the information for protection, security, and usage monitoring.

Information about files is kept in the directory structure, which is maintained on the disk.

File management System (FMS)

 The File Manager (or File Management System) is the manager in the Operating System that
creates the logical form of files that are stored in computer memory.
 FMS is a collection of system software programs that provides File services to the users.

 The File Manager responsibilities are:

 Keeps track of where files are stored


 Determines how the files are stored
 Follows operating system file allocation policies
 Uses available storage space efficiently for files
 Creates a record/log of all file usage
 Allocates a file to a user if is free, and if they are permitted access to it.
 De-allocates file when user finished with it.

 The file manager ALLOCATES a file by reading it from the hard disk and loading it into memory
while updating its record of who is using what file.

 The file manager DEALLOCATES a file by updating the file tables and rewriting the file (if
changed) to the hard disk.

FILE ACCESSING METHODS


File access mechanism refers to the manner in which the records of a file may be accessed.
There are several ways to access files
 Sequential access
 Direct/Random access
 Indexed sequential access

(1)Sequential access
 A sequential access is that in which the records are accessed and processed in order, one record
after the other.
o Example: If a file consists of 100 records the current position of read/write head is 45th
record and want to read the 75th record then it access sequentially by traversing from 45
to 75
 This access method is the simplest and the most primitive one.
 Sequential access is based on a tape model of a file.
 Used by editors and compliers.
 Work well on sequential access devices such as batch systems.
(2)Direct/Random access
 Random access file organization provides, accessing the records directly.
 Direct access is also called relative access.
 A direct-access file allows arbitrary blocks to be read or written, Jump to any record and read
that record.
 Each record has its own address on the file with by the help of which it can be directly
accessed for reading or writing.
 The records need not be in any sequence within the file and they need not be in adjacent
locations on the storage medium.
 The direct access method is based on a disk model of a file which allows random access to any
file block.
(3)Indexed sequential access
 This mechanism is built on top of direct access method.
 This method requires the construction of an index for the file. Index is a small table stored in
memory
 Index created for each file contains pointers to various blocks.
 To find an entry in the file, the index is searched first and the pointer is then used to access the
file directly
 The master index divide the total records into blocks each block consist of a pointer to
secondary index which consists of a pointer to its original location.
 Index is searched sequentially and its pointer is used to access the file directly.

FILE DIRECTORIES
 Directory contains information about the files, including attributes, locations and ownership.
Directories also consist of sub directories.
 A directory structure provides a mechanism for organizing many files in the system.

Operations on file Directory

1. Search for a file- for the required file


2. Create a file - add to the directory
3. Delete a file - erase from the directory
4. List a directory - possibly ordered in different ways.
5. Rename a file - change the name of a file
6. Traverse the file system- to access every directory and every file within a directory
Single-Level Directory System

 Simple to implement, but each file must have a unique name.


 Directory system has only one directory it consists of all files.
 It is said to be root directory.
Two-Level Directory System

 In multi user system each user need a private directory


 File name chosen by one user do not interface with names chosen by a different user.

Tree-Structured /Hierarchical Directories

 Tree structure satisfies for users with a large number of files.


 In this method each user has directories and subdirectories.

General graph directory structure


 We can add links to an existing tree structure directory.
 This structure helps traversing easy and file sharing also possible.
FILE ALLOCATION METHOD (Space Allocation)
(File organization)

 Files are allocated to disk spaces by operating system.


 Allocation of space to these files helps to utilize space effectively and files can be accessed
quickly.
Operating systems deploy following three main ways to allocate disk space to files.
1. Contiguous Allocation
2. Linked Allocation
3. Indexed Allocation

(1)Contiguous Allocation

 Each file occupy a contiguous address space on disk, a set of contiguous blocks on the disk..
 Assigned disk address is in linear order.
 This method make use of FAT (File allocation table ) which contains an entry for each file. It
shows the file name, starting block of the file and size of the file.
 This method is best suited for sequential files
 Easy to implement.
 Drawback: It is difficult to find the contiguous free blocks in the disk and also external
fragmentation means some free blocks could happen between two files.
(2)Linked Allocation

 Each file carries a list of links to disk blocks.


 Each block contains a pointer to the next free block in the chain.
 Here also FAT consists of a single entry for each file.
 There is a link between one block to another block
 No external fragmentation
 Effectively used in sequential access file and Inefficient in case of direct access file.
 The pointer itself occupies some memory within the block

(3)Indexed Allocation (Grouped allocation)

 In this method the FAT contains a single entry for each file which contains the address of
index blocks of files.
 The entry consists of one index block having all the pointers to the other blocks which were
occupied by the particular file
 Each file has its own index block which stores the addresses of disk space occupied by the file.
 Provides solutions to problems of contiguous and linked allocation.
FREE-SPACE MANAGEMENT

 If we want to allocate the space for the files we have to know what blocks on the disk are available.
For that a disk allocation table is used.
 To keep track of free disk space the system maintains a free space list. The free space list records all
the disk blocks which are free
 To create a file first search the free space list for the required amount of space and allocate it to
the new file.
 When a file is deleted its disk space is added to the free space list.
The following are the various techniques to maintain free list:

(1) Bit Vector

 Free-space list is implemented as a bit map or bit vector.


 Each block is represented by one bit value.
 If the block is free, the bit is 1;
 If the block is allocated, the bit is 0.

 For example consider a disk where blocks 2, 3, 4, 5, 8, 9, 10, 11, 12, 13, 17, 18, 25, 26, and 27 are
free, and the rest of the blocks are allocated. The free-space bit map would be

01111001111110001100000011100000 …..

1 1 0 0 1 1 0 means blocks 1,2, 5, 6 are free and 3,4,7 are allocated

 The main advantage of this approach is that it is relatively simple and efficient to find the first free
block or n consecutive free blocks on the disk.

(2) Chain free points (or Linked List)

 Another approach is to link together all the free disk blocks, keeping a pointer to the first free
block .That is free blocks are chained together, each holding a pointer to the next one free
 This first block contains a pointer to the next free disk block, and so on.
o For example we could keep a pointer to Block 2 as the first free block and 2 would contain a
pointer to block 3, which would point to block 4, which would point to block 5, which
would point to block 8, and so on.
 Usually, the operating system simply needs a free block so that it can allocate that block to a file,
so the first block in the free list is used.
(3) Grouping (indexed block list)

 A modification compared to the previous is to store the addresses of n free blocks in the first free
block. The first n-1 of these blocks is actually free.
 The last block contains address of another n free block and so.
 The importance of this implementation is that the addresses of a large number of free blocks can be
found quickly, unlike in the standard linked-list approach.

Index block

Block 2 3,4,5

Block 5 8,9,10,11,12,13

Block 13 17,18

Block18 25,26,27

RECORD BLOCKING
 Records are the logical unit of access of a structured file. But blocks are the unit for I/O with
secondary storage.
 For I/O to be performed on file, records must be organized as blocks.
 Disk and tape devices recognize blocks of data, which consist of one or more records.
 A blank space, known as an interblock gap (IBG), separates one block from another.
o For example the disk may specify a blocking factor, such as three records per block, In
this format, the system writes or reads an entire block length of three records.
 Blocking records makes better use of disk and tape storage.
 Given the size of a block(no: of records per block), there are three methods of blocking can be
used:
(1) Fixed-Length Blocking
 In this method records length are fixed and a prescribed number of records (or bytes) are stored in
a block.
 May waste space at the end of the block
For example: The block capacity is 5 records but the number of records in the block is 3
then the wasted space is an internal fragmentation

(2)Variable-Length Spanned Blocking


 In this method record sizes are not same, variable length records are packed into blocks with no
unused space.
 So some records may divide into two blocks and a pointer is passed from one block to another

Pointer
Block1 Block2
IMG R1 R2 R3 R4 IMG R4 R5 R6 IMG

(3)Variable-Length Un spanned Blocking


 Here records are of variable lengths but the records are not spanned between blocks
 Biggest problem in this method is the wasted space in most blocks because of the inability to use
the remainder of a block if the next record is larger than the remaining unused space. The entire
record has to move to a new block

Block1 Block2

IMG Wasted area

What is FAT (File Allocation Table)?


A file allocation table (FAT) is a file system developed for hard drives that originally used 12 or 16
bits for each cluster entry into the file allocation table. It is used by the operating system (OS) to
manage files on hard drives and other computer systems. It is often also found on in flash memory,
digital cameras and portable devices. It is used to store file information and extend the life of a hard
drive.

You might also like