0% found this document useful (0 votes)
14 views41 pages

Lecture 9 File System

Lecture 9 of CS 334 covers the principles of file systems, including their structure, types, attributes, and operations. It discusses various file allocation methods and free space management techniques, as well as the importance of file naming conventions. The lecture emphasizes the role of the file system in managing data storage and retrieval on different operating systems.

Uploaded by

erickmwanri22
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)
14 views41 pages

Lecture 9 File System

Lecture 9 of CS 334 covers the principles of file systems, including their structure, types, attributes, and operations. It discusses various file allocation methods and free space management techniques, as well as the importance of file naming conventions. The lecture emphasizes the role of the file system in managing data storage and retrieval on different operating systems.

Uploaded by

erickmwanri22
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/ 41

CS 334: Principles of Operating

System

Lecture 9: File System


Outline
• Overview of file system
• File structure
• File naming
• File types
• File attributes
• File Operations
• File System Implementation
Introduction
• Computers store data and other information permanently
in storage devices as files
• A file system is the part of the operating system which is
responsible for file management.
• File systems are used to store, organize, and manage files
and directories on storage devices.
Introduction
The file system provides a convenient mechanism to store and
retrieve the data and programs from the disks. Some common
types of file systems include:
•FAT (File Allocation Table): An older file system used by older
versions of Windows and other operating systems.
•NTFS (New Technology File System): A modern file system
used by Windows. It supports features such as file and folder
permissions, compression, and encryption.
•ext (Extended File System): A file system commonly used
on Linux and Unix-based operating systems.
•HFS (Hierarchical File System): A file system used by macOS.
•APFS (Apple File System): A new file system introduced by
Apple for their Macs and iOS devices.
Introduction
• A file is a named collection of related information that is
recorded on secondary storage such as magnetic disks,
magnetic tapes and optical disks.
• it is a sequence of bits, bytes, lines or records that store
data and information in media.
Introduction
The file system is responsible for the following functions
i. File Management. It manages how the files are stored,
referenced, shared, and secured.
ii. File Allocation. It provides the methods to allocate files
on the disk space.
iii. File Access Methods. It provides the methods to access
stored files.
File Structure
A typical file consist of the following elements
A Field
• Basic element of data storage
• Is a single valued item for example, name, date,
employee ID.
• It is characterized by its length and data type.
File Structure
A Record
• A record is a combination of multiple fields to form a
meaningful collection
• For example, a student’s information can be one record,
consisting of fields such as registration number, name,
program, and so on.
File Structure
A File
• When such similar records are collected, it is known as a
file.
• File has also a name similar to a field or record.
• Thus, a file is treated as a single entity that may be used
by a programmer or application.

File structure
File Structure
Unstructured Files
• Unstructured files also called flat files are in the form of
an unstructured sequence of bytes with no fields or
records.
• UNIX and Windows use this kind of file structure.
File Types
There are three types of files
i. Regular files
ii. Directories
iii. Special files
File Types
Regular Files
• Regular files contain the user information.
• Regular files may be either of ASCII (can be read or
edited using any text editor) or binary type.
File Types
Regular Files
Some types of files are mentioned below:
• Source code files are used when writing programs. For
example, a C language program will be written in a file
with a .c extension.
• Object file. It is a compiled or machine language file. Its
extension are .obj or .o
• Executable file contains executable (linked and ready to
run) code. Its extensions are .exe, .com, .bin, etc.
File Types
Regular Files
• Text file. A general text document is known as a text file.
Its extension is .txt or .doc.
• Batch file consist of some commands to be executed and
given to the command interpreter. Its extension is .bat.
• Archive file: When a group of files is compressed in a
single file, it is known as an archive file. It extensions are
.zip, .rar etc
• Multimedia file: It is a file containing audio or video
information. Its extensions are .mpeg, .mov, .mp3, .jpg,
etc.
File Types
Directories
• Directory is a file type used to organize other files into a
group.
• That is to say, a directory is a collection of files
• Every file belongs to one or more directories.

Advantages of Maintaining Directories


i. Efficiency: A file can be located more quickly.
ii. Naming: It becomes convenient for users as two users
can have same name for different files or may have
different name for same file.
iii. Grouping: Logical grouping of files can be done by
properties e.g. all java programs, all games etc.
File Types
Directories
Logical structure of directories

Single level directory


There is a single directory structure under which all files are
stored for all users
Used on earlier systems before the concept of multiuser
File Types
Directories
Logical structure of directories

Two level directory


Each user has their own directory structures
Advantage: Same file name can be used by different users
Limitation: User is limited to single directory
File Types
Directories
Logical structure of directories
Tree level directory
An extended design of the two level structure
Users can create sub-directories under directories
Users can access other user files using a path name
File Types
Directories
Logical structure of directories
Acyclic graph directory
Implemented using pointers (symbolic link in linux)
Allows directories to share sub-directories and files among
users
File Types
Special files
• A special file contains no data but provides a mechanism
to map physical devices to file names.
• They are used to access I/O devices like printers, disks
etc.
File Attributes
General attributes including:
i. Name. The symbolic file name is the only information
kept in human- readable form.
ii. Identifier. This unique tag, usually a number, identifies
the file within the file system; it is the non-human-
readable name for the file.
iii. Type. This information is needed for systems that
support different types of files.
iv. Location. This information is a pointer to a device and
to the location of the file on that device.
v. Size. The current size of the file and optionally the
maximum allowed size are included in this attribute.
File Attributes
• Protection attributes which includes access control
information:
i. File access rights, for example, read, write, and
execute permissions.
ii. File owner
iii. File password

• Timestamps which are useful for protection, security,


and usage monitoring. Includes :
i. Time of creation,
ii. Time of last modification,
iii. Time of last access
File Attributes
Flags: Enable some specific property of the file example
i. Read-only flag, 0 for read/write and 1 for read-
only.
ii. Hidden flag: It is used to hide a file in the listing of
the files.
iii. System flag: It is used to designate a file as system
file.
iv. Archive flag: It is used to keep track of whether the
file has been backed up or not. The OS sets it
whenever a file is changed. The flag is 0, when the
changed file has been backed up.
v. Access flag: It is used to convey how the file is
accessed. It is set when the file is accessed
randomly, otherwise, the file is accessed
sequentially.
File Naming
• Files are named for easy identification and retrieval by
users without knowing the actual storage details on the
hardware.
• The rules for naming the files may vary from system to
system.
❖ Some systems distinguish between uppercase and
lowercase letters, while some do not.
❖ Different systems support different file name length
❖ Some systems allow special characters in file names
File Naming
• In most systems, the file name has two parts, separated
by a period (.).
• The first part is the name of the file, defined by the user,
and the second part is known as an extension.
• The extension part usually indicates what type of file has
been created.
• Some systems support two or more extensions in the file
name as in UNIX.
• An OS must recognize the type of the file, because the
operations performed on it depend on its type.
File Operations
• The OS provides system calls for each operation to be
implemented on the file.
• The following are some operations that are performed
on a file:
i. Creating a file
ii. Writing a file
iii. Saving a file
iv. Deleting a file
v. Opening a file
vi. Closing a file
vii. Reading a file
viii. Appending a file
ix. Seeking a file
x. Get attributes for a file
File System Implementation
Blocks
• A block is a unit of storage in a disk
• Since the logical file will be mapped to the secondary
storage, the internal structure of a file is defined in
terms of a block.
• In this way, a file may be considered as a sequence of
blocks, and therefore, all basic I/O functions are
performed in terms of blocks.
Blocks
Three different methods are used when mapping data
records to blocks (record blocking)
i. Fixed Blocking
ii. Variable-length Un-spanned Blocking
iii. Variable-length Spanned Blocking
Blocks
Fixed blocking
• In this blocking, fixed sized records are used.
• There may be a mismatch between the sizes of a
record and a block, leaving some unused space in some
block.
• Can lead to internal fragmentation.
Blocks
Variable-length Un-spanned Blocking
• In this blocking, records of variable lengths are used,
but spanning is not considered in case of small-size
blocks.
• A small-size block is left unused, causing wastage of
memory space, and the records are allocated to a
bigger block.
• In Figure below, R3 does not fit in a small block and
therefore, it is allocated to the next block, which is
bigger.
• It causes wastage of block space.
Blocks
Variable-length Spanned Blocking
• In this blocking, variable length records are used
instead of fixed size.
• A record can span more than one block in continuation
when it happens a block is smaller in size as compared
to the size of a record.
• Example in the figure below, R3 spans two variable-
sized blocks.
• This method of blocking does not cause fragmentation.
File Allocation
Three methods are used to store files on storage
i. Contiguous
ii. Linked
iii. Indexed
File Allocation
Contiguous file allocation
• A single continuous set of blocks is allocated to a file at the
time of file creation
• All blocks of a file are kept together contiguously.
• Performance is fast, because reading successive blocks of the
same file requires less movement of the disk heads

Disadvantages
i. External fragmentation due to over estimation of file size
ii. Files growing beyond originally allocated space
File Allocation
Linked file allocation
• Allocation is on an individual block basis.
• Each block contains a pointer to the next block in the
chain.

Disadvantages:
Linked allocation is only efficient for sequential access files
Internal fragmentation
File Allocation
Indexed file allocation
• The file allocation table contains a separate one-level
index for each file
• The index has one entry for each block allocated to the
file.
Free Space Management
• Since storage space is limited, we need to reuse the
space from deleted files for new files.
• To keep track of free disk space, the system maintains a
free-space list that records all free blocks that are not
allocated to some file or directory.
Free Space Management
The following approaches are used for free disk space
management
Bit Vector
• The free-space list is implemented as a bit vector with
each block is represented by one bit.
• If the block is free, the bit is set to 1 otherwise if the
block is allocated the bit is set to 0.
• For example, a disk with free blocks 2, 3, 4, 5, 8, 9, 10,
11, 12, 13, 17, 18, 25, 26, and 27 would have a bit vector
below
001111001111110001100000011100000 ...
It is a fast and efficient
The downside is it requires some disk space to store the bit
vector
Free Space Management
Linked List
• Another approach to free-space management is to link
together all the free blocks
• A special pointer on the disk is reserved that points to
the first free disk block. The first free block points to the
second free block, the second block points to the third
one, and so on
Free Space Management
Other free space management approaches
• Grouping
• Counting
• Space Maps
Further Reading
Find below topics for further reading
• Efficiency and performance
• Recovery
• Back up and restore
• File system mounting
• Partitioning
• File sharing
• Virtual file system
• Network file system
• Remote file system

You might also like