0% found this document useful (0 votes)
1K views9 pages

File Systems in Operating Systems

The document discusses file systems and file operations in an operating system. It provides definitions of a file system and describes key characteristics like long-term storage, structure, and sharing capabilities. It then covers file naming, attributes, common file operations like create, read and write, and different file access mechanisms like sequential, direct and index access. Finally, it discusses two methods for allocating space to files on disk: contiguous allocation and linked list allocation.
Copyright
© Attribution Non-Commercial (BY-NC)
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)
1K views9 pages

File Systems in Operating Systems

The document discusses file systems and file operations in an operating system. It provides definitions of a file system and describes key characteristics like long-term storage, structure, and sharing capabilities. It then covers file naming, attributes, common file operations like create, read and write, and different file access mechanisms like sequential, direct and index access. Finally, it discusses two methods for allocating space to files on disk: contiguous allocation and linked list allocation.
Copyright
© Attribution Non-Commercial (BY-NC)
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

Operating System

Lecture notes:
Prep. By: Mr. Daya Ram Budhathoki

Chapter:6
File-systems
• Files and Directories
• File system Implementation
• File Sharing and Locking

What is File-System?
From the user point of view one of the most important part of the operating system is file-system. The
file-system provides the resource abstraction typically associated with secondary storage. The file
system permits users to create data collections, called files, with desirable properties, such as
• Long-term existence: Files are stored on disk or other secondary storage and do not disappear
when a user logs off.
• Sharable between processes: Files have names and can have associated access permissions
that permit controlled sharing.
• Structure: Depending on the file system, a file can have an internal structure that is
convenient for particular applications. In addition, files can be organized into hierarchical or
more complex structure to reflect the relationships among files.

File Naming
Files are an abstraction mechanism. They provide a way to store information on the disk and read it
back later. This must be done in such a way as to shield the user from the details of how and where the
information is stored, and how the disks actually work.
Probably the most important characteristic of any abstraction mechanism is the way the objects being
managed are named, so we will start our examination of file systems with the subject of file naming.
When a process creates a file, it gives the file a name. When the process terminates, the file continues
to exist and can be accessed by other processes using its name.

Operation Performed on Files:


1. Creating a File
2. Writing a file
3. Reading a file
4. Repositioning a file
5. Deleting a file
6. Truncating a file
File Attributes
Every file has a name and its data. In addition, all operating systems associate other information with
each file, for example, the date and time the file was created and the file's size. We will call these extra
items the file's attributes although some people called them metadata. The list of attributes varies
considerably from system to system.

Attribute Meaning
Protection Who can access the file and in what way
Password Password needed to access the file
Creator ID of the person who created the file
Owner Current owner
Read-only flag 0 for read/write; 1 for read only
Hidden flag 0 for normal; 1 for do not display in
listings
System flag 0 for normal files; 1 for system file
Archive flag 0 for has been backed up; 1 for needs to
be backed up
ASCII/binary flag 0 for ASCII file; 1 for binary file
Random access flag 0 for sequential access only; 1 for random
access
Temporary flag 0 for normal; 1 for delete file on process
exit
Lock flags 0 for unlocked; nonzero for locked
Record length Number of bytes in a record
Key position Offset of the key within each record
Key length Number of bytes in the key field
Creation time Date and time the file was created
Time of last access Date and time the file was last accessed
Time of last change Date and time the file has last changed
Current size Number of bytes in the file
Maximum size Number of bytes the file may grow to

File Operations
Files exist to store information and allow it to be retrieved later. Different systems provide different
operations to allow storage and retrieval. Below is a discussion of the most common system calls
relating to files.

1. Create. The file is created with no data. The purpose of the call is to announce that the file is
coming and to set some of the attributes.

2. Delete. When the file is no longer needed, it has to be deleted to free up disk space. A system
call for this purpose is always provided.

3. Open. Before using a file, a process must open it. The purpose of the open call is to allow the
system to fetch the attributes and list of disk addresses into main memory for rapid access on
later calls.

4. Close. When all the accesses are finished, the attributes and disk addresses are no longer
needed, so the file should be closed to free up some internal table space. Many systems
encourage this by imposing a maximum number of open files on processes. A disk is written in
blocks, and closing a file forces writing of the file's last block, even though that block may not
be entirely full yet.

5. Read. Data are read from file. Usually, the bytes come from the current position. The caller
must specify how much data are needed and must also provide a buffer to put them in.

6. Write. Data are written to the file, again, usually at the current position. If the current position
is the end of the file, the file's size increases. If the current position is in the middle of the file,
existing data are overwritten and lost forever.

7. Append. This call is a restricted form of write. It can only add data to the end of the file.
Systems that provide a minimal set of system calls do not generally have append, but many
systems provide multiple ways of doing the same thing, and these systems sometimes have
append.

8. Seek. For random access files, a method is needed to specify from where to take the data. One
common approach is a system call, seek, that repositions the file pointer to a specific place in
the file. After this call has completed, data can be read from, or written to, that position.

9. Get attributes. Processes often need to read file attributes to do their work. For example, the
UNIX make program is commonly used to manage software development projects consisting of
many source files. When make is called, it examines the modification times of all the source
and object files and arranges for the minimum number of compilations required to bring
everything up to date. To do its job, it must look at the attributes, namely, the modification
times.

10. Set attributes. Some of the attributes are user settable and can be changed after the file has
been created. This system call makes that possible. The protection mode information is an
obvious example. Most of the flags also fall in this category.

11. Rename. It frequently happens that a user needs to change the name of an existing file. This
system call makes that possible. It is not always strictly necessary, because the file can usually
be copied to a new file with the new name, and the old file then deleted.

12. Lock. Locking a file or a part of a file prevents multiple simultaneous access by different
process. For an airline reservation system, for instance, locking the database while making a
reservation prevents reservation of a seat for two different travelers.
File Structure:

Three kinds of files. (a) Byte sequence. (b) Record sequence. (c) Tree.

a. Byte Sequence:
The file in Fig. (a) is just an unstructured sequence of bytes. In effect, the operating system does not
know or care what is in the file. All it sees are bytes. Any meaning must be imposed by user-level
programs. Both UNIX and Windows 98 use this approach.

b. Record Sequence:
In this model, a file is a sequence of fixed-length records, each with some internal structure. Central to
the idea of a file being a sequence of records is the idea that the read operation returns one record and
the write operation overwrites or appends one record. As a historical note, when the 80-column
punched card was king many (mainframe) operating systems based their file systems on files consisting
of 80-character records, in effect, card images

c. Record Sequence:
In this organization, a file consists of a tree of records, not necessarily all the same length, each
containing a key field in a fixed position in the record. The tree is sorted on the key field, to allow rapid
searching for a particular key.

Files Organization and Access Mechanism:


When a file is used then the stored information in the file must be accessed and read into the memory
of a computer system. Various mechanism are provided to access a file from the operating system.
i. Sequential access
ii. Direct Access
iii. Index Access

Sequential Access:
It is the simplest access mechanism, in which informations stored in a file are accessed in an order such
that one record is processed after the other. For example editors and compilers usually access files in
this manner.

Direct Access:
It is an alternative method for accessing a file, which is based on the disk model of a file, since disk
allows random access to any block or record of a file. For this method, a file is viewed as a numbered
sequence of blocks or records which are read/written in an arbitrary manner, i.e. there is no restriction
on the order of reading or writing. It is well suited for Database management System.

Index Access:
In this method an index is created which contains a key field and pointers to the various block. To find
an entry in the file for a key value , we first search the index and then use the pointer to directly access
a file and find the desired entry.

With large files , the index file itself may become too large to be keep in memory. One solution is to
create an index for the index file. The primary index file would contain pointers to secondary index
files, which would point to the actual data items.

File Allocation Method:


1. Contiguous Allocation
2. Linked List Allocation
3. Linked List Allocation Using a Table in Memory
4. I-Nodes

Contiguous allocation:
It requires each file to occupy a set of contiguous addresses on a disk. It sore each file as a contiguous
run of disk blocks. Thus on a disk with 1-KB blocks, a 50-KB file would be allocated 50 consecutive
blocks. Both sequential and direct access is supported by the contiguous allocation method.
Contiguous disk space allocation has two significant advantages.

1. First, it is simple to implement because keeping track of where a file's blocks are is reduced to
remembering two numbers: the disk address of the first block and the number of blocks in the
file. Given the number of the first block, the number of any other block can be found by a
simple addition.
2. Second, the read performance is excellent because the entire file can be read from the disk in
a single operation. Only one seek is needed (to the first block). After that, no more seeks or
rotational delays are needed so data come in at the full bandwidth of the disk.
Thus contiguous allocation is simple to implement and has high performance.
Unfortunately, contiguous allocation also has a major drawback: in time, the disk becomes fragmented,
consisting of files and holes. It needs compaction to avoid this.

Example of contiguous allocation: CD and DVD ROMs

Linked List Allocation:


keep each file as a linked list of disk blocks as shown in the fig. The first word of each block is used as
a pointer to the next one. The rest of the block is for data.

Fig:Storing a file as a linked list of disk blocks.

Unlike contiguous allocation, every disk block can be used in this method. No space is lost to disk
fragmentation. The major problem with linked allocation is that it can be used only for sequential
access files. To find the ith block of a file, we must start at the beginning of that file, and follow the
pointers until we get the ith block. It is inefficient to support direct access capability for linked
allocation of files.

Another problem of linked list allocation is reliability. Since the files are linked together with the
pointer scattered all over the disk. Consider what will happen if a pointer is lost or damaged.
Indexed allocation (I-Nodes):
It solves the external fragmentation and size declaration problems of contiguous allocation. In this
allocation all pointers are brought together into one location called Index block.
Each file has its own index block, which is an array of disk-block addresses. The ith entry in the index
block points to the ith block of the file. The directory contains the address of the index block.

Inex alloction of Disk sapce

To read the ith block, we use the pointer in the ith index block entry to find and read the desired block.
This scheme is similar to the paging scheme.
Fig: An i-node with three levels of indirect blocks.

File System Layout:

Fig:A possible file system layout.


Directories:
To keep track of files, file systems normally have directories or folders, which, in many systems, are
themselves files. In this section we will discuss directories, their organization, their properties, and the
operations that can be performed on them.

Simple Directories
A directory typically contains a number of entries, one per file. One possibility is shown in Fig. (a), in
which each entry contains the file name, the file attributes, and the disk addresses where the data are
stored.

Three file system designs. (a) Single directory shared by all users. (b) One directory per
user. (c) Arbitrary tree per user. The letters indicate the directory or file's owner.

Common questions

Powered by AI

The temporary flag impacts file operations by indicating to the system that the file should be deleted upon process exit if set to 1, making it useful for scratch or temporary files that only need to exist during a session . Lock flags affect file operations by preventing multiple simultaneous accesses, which is critical for data integrity in systems that require serialization of access, such as databases or reservation systems. A nonzero lock flag indicates a locked file or part of a file, preventing data corruption or simultaneous modifications by different processes .

Seek operations improve file access efficiency by repositioning the file pointer to a specific location within a file, enabling direct access to data without reading sequentially from the start . This is particularly beneficial in random access systems where only specific parts of a file are needed. However, the limitations include complexity in the implementation of file systems to support such operations, and potential overhead in systems where seek times are relatively long compared to the actual read/write operations. Moreover, not all file systems or allocation methods (e.g., linked list allocation) can efficiently support seek operations due to their inherent design .

Different file allocation methods come with various trade-offs. Contiguous allocation is simple to implement and offers excellent read performance due to reduced seek time, but it leads to disk fragmentation over time and requires file compaction . In contrast, linked list allocation eliminates fragmentation since every disk block can be used, but it is inefficient for direct access due to the need to traverse the link chain to access the ith block . Indexed allocation, like I-Nodes, addresses fragmentation and size declaration problems and supports both sequential and random access by centralizing pointers in an index block, but it introduces overhead due to the management of index blocks .

Metadata attributes in file management provide critical information that facilitates efficient file access, security, and integrity. Attributes such as file creation time, last access time, and modification time allow systems to manage files based on time criteria, essential for activities like backups and versioning . Protection attributes define access permissions, enhancing file security by controlling who can view or modify a file. Metadata also includes file size and other flags (e.g., read-only, hidden), which help in optimizing storage management and user interaction .

Lock mechanisms in file systems prevent data corruption by ensuring that only one process can access a file or data block at a time, particularly crucial in environments where concurrent access could lead to conflicting changes, such as databases or collaborative software . While beneficial for maintaining data integrity, these mechanisms can introduce performance bottlenecks, increase system complexity, and risk deadlocks if not managed properly, as processes may be indefinitely postponed while waiting for locks to release .

Sequential access mechanism, being simple and applicable in scenarios like text file processing and compilers, offers efficient processing since each record is processed one after the other without random disk seeks . Direct access allows for data retrieval and modification in arbitrary order, suiting database systems that require rapid access to large datasets but requiring more complex management to track and allocate precise block positions . Index access mechanisms introduce an index for quick location of data blocks, balancing speed of direct access with scalability, especially in systems with very large datasets. However, index complexity can also introduce overhead and require additional maintenance .

A hierarchical file structure, organized into directories and subdirectories, allows for better organization and management of files, reflecting relationships between files and offering a logical and intuitive way to store and retrieve files . One disadvantage is the complexity it introduces in navigating the file system, requiring users to understand the directory paths and relationships. Additionally, managing permissions and accessing files across different levels can become complicated, especially in large systems with many users and files .

Indexed allocation overcomes the fragmentation issue inherent in contiguous allocation by using an index block that holds pointers to the actual data blocks, allowing for files to be non-contiguously stored on the disk . Unlike linked list allocation, which requires traversing block pointers for data access and is limited in supporting only sequential access, indexed allocation centralizes all pointers in a single location, enabling efficient direct access to any block within a file . This method also mitigates issues with file size declaration and eases management, as the size of a file is not rigidly defined at the outset, unlike contiguous allocation .

Hierarchical directory structures use a tree-like model with directories and subdirectories, allowing easier management and locating of files due to its organized structure reflecting real-world file relationships . Flat directory structures, in contrast, contain no hierarchy, leading to simple but potentially chaotic systems due to the lack of organized grouping, which can complicate file management and retrieval in large systems . Other structures might include network or database-based organizations, offering varying degrees of access speed and organizational complexity based on specific system needs, balancing between simplicity and capability .

File sharing is facilitated in a file-system by allowing files to have names and associated access permissions, which permit controlled sharing between processes . The challenges associated with file sharing include maintaining data consistency and integrity, especially when multiple processes attempt to access and modify a file simultaneously. Locking mechanisms are employed to prevent simultaneous access, which can lead to issues such as deadlock and complexity in managing locks .

You might also like