File System Print
File System Print
• Six basic file operations. The OS can provide system calls to create, write, read, reposition, delete, and
truncate files.
o Creating a file.: Two steps are necessary to create a file.
1. Space in the file system must be found for the file.
2. An entry for the new file must be made in the directory.
o Writing a file. :To write a file, we make a system call specifying both the name of the file and
the information to be written to the file. The system must keep a write pointer to the location in
the file where the next write is to take place. The write pointer must be updated whenever a
write occurs.
o Reading a file. :This operation reads the contents from a file. A Read pointer is
maintained by the OS, pointing to the position up to which the data has been read.
o Repositioning within a file or Seek operation.: The directory is searched for the
appropriate entry, and the current-file-position pointer is repositioned to a given value.
Repositioning within a file need not involve any actual I/O. This file operation is also known
as a file seek.
o Deleting a file.: To delete a file, we search the directory for the named file. Having found the
associated directory entry, we release all file space, so that it can be reused by other files, and
erase the directory entry.
o Truncating a file:Truncating is simply deleting the file except deleting attributes. The
file is not completely deleted although the information stored inside the file gets
replaced.
o 8. Close operation:When the processing of the file is complete, it should be closed so
that all the changes made permanent and all the resources occupied should be
released. On closing it deallocates all the internal descriptors that were created when
the file was opened.
o 9. Append operation:This operation adds data to the end of the file.
o 10. Rename operation:This operation is used to rename the existing file.
File Types:
There are a large number of file types. Each has a particular purpose. The type of a file indicates its use
File type Usual extension Function
Word
Processor wp, tex, rrf, doc Various word processor formats
File Managment
Archive arc, zip, tar Related files grouped into one compressed file
1. Media:
Media files store media data such as images, audio, icons, video, etc. Common extensions: img, mp3,
mp4, jpg, png, flac, etc.
2. Programs:
These files store code, markup, commands, scripts, and are usually executable. Common
extensions: c, cpp, java, xml, html, css, js, ts, py, sql, etc.
4. Operating System Level:
These files are present with the OS for its internal use. Common extensions: bin, sh, bat, dl, etc.
5. Document:
These files are used for managing office programs such as documents, spreadsheets, etc. Common
extensions: xl, doc, docx, pdf, ppt, etc.
6. Miscellaneous:
Generic text file(.txt), canvas files, proprietary files, etc.
The idea of Sequential access is based on the tape model which is a sequential access device.
We consider Sequential access method is best because most of the records in a file are to be
processed. For example, transaction files.
File Managment
The figure represents a file. The current pointer is pointing to the record currently being
accessed. In the sequential access method, the current pointer cannot directly jump to any
record. It has to "cross" every record that comes in its path. Suppose there are nine records in
the file from R1 to R9. The current pointer is at record R6. If we want to access record R8, we
have to first access record R6 and record R7. This is one of the major disadvantages of the
sequential access method.
Write next: This operation is used when some more information is to be included in the file. A
new node (a record) will be added at the end of the file.
• Rewind: This will bring the read and write pointers to the beginning of the file.
2. Direct or Random Access Methods
Sometimes it is not necessary to process every record in a file. It is not necessary to process all
the records in the order in which they are present in the memory. In all such cases, direct access
is used.
The disk is a direct access device which gives us the reliability to random access of any file block.
In the file, there is a collection of physical blocks and the records of that blocks.
Eg. Databases are often of this type since they allow query processing that involves immediate
access to large amounts of information. All reservation systems fall into this category.
Not all operating systems support direct access files. The sequential and direct access of the file
is defined at the time of creation and accessed accordingly later. The direct access of a
sequential file is not possible but Sequential access to a direct access file is possible.
3. Index Access Method
An indexed file is a computer file with an index that allows easy random access to any record
given its file key. The key is an attribute that uniquely identifies a record. We can say that If more
than one index is present the other ones are alternate indexes. The creation of the indexes is
done with the file but maintained by the system.
Directory Structure
What is a directory?
Directory can be defined as the listing of the related files on the disk. The directory may store some
or the entire file attributes.
The simplest method is to have one big list of all the files on the disk. The entire system will contain
only one directory which is supposed to mention all the files present in the file system. The directory
contains one entry per each file present on the file system.
File Managment
Advantages
1. Implementation is very simple.
2. If the sizes of the files are very small then the searching becomes faster.
3. File creation, searching, deletion is very simple since we have only one directory.
Disadvantages
1. We cannot have two files with the same name.
2. The directory may be very big therefore searching for a file may take so much time.
3. Protection cannot be implemented for multiple users.
4. There are no ways to group same kind of files.
5. Choosing the unique name for every file is a bit complex and limits the number of files in the
system because most of the Operating System limits the number of characters used to
construct the file name.
Single Level Directory
The simplest method is to have one big list of all the files on the disk. The entire system will contain
only one directory which is supposed to mention all the files present in the file system. The directory
contains one entry per each file present on the file system.
Advantages
1. Implementation is very simple.
2. If the sizes of the files are very small then the searching becomes faster.
3. File creation, searching, deletion is very simple since we have only one directory.
Disadvantages
1. We cannot have two files with the same name.
2. The directory may be very big therefore searching for a file may take so much time.
3. Protection cannot be implemented for multiple users.
4. There are no ways to group same kind of files.
5. Choosing the unique name for every file is a bit complex and limits the number of files in the
system because most of the Operating System limits the number of characters used to
construct the file name.
Tree-structured directory –
Once we have seen a two-level directory as a tree of height 2, the natural
generalization is to extend the directory structure to a tree of arbitrary height.
This generalization allows the user to create their own subdirectories and to organize their files
accordingly.
A tree structure is the most common directory structure. The tree has a root
directory, and every file in the system has a unique path.
Advantages:
• Very general, since full pathname can be given.
• Very scalable, the probability of name collision is less.
• Searching becomes very easy, we can use both absolute paths as well as relative.
Disadvantages:
File Managment
• Every file does not fit into the hierarchical model, files may be saved into multiple
directories.
• We can not share files.
• It is inefficient, because accessing a file may go under multiple directories.
Acyclic graph directory –
An acyclic graph is a graph with no cycle and allows us to share
subdirectories and files. The same file or subdirectories may be in two different directories. It is a
natural generalization of the tree-structured directory.
It is used in the situation like when two programmers are working on a joint project and
they need to access files. The associated files are stored in a subdirectory, separating
them from other projects and files of other programmers since they are working on a
joint project so they want the subdirectories to be into their own directories. The
common subdirectories should be shared. So here we use Acyclic directories.
It is the point to note that the shared file is not the same as the copy file. If any
programmer makes some changes in the subdirectory it will reflect in both
subdirectories.
5. File management is the process of organizing, storing, naming and deleting files. It is
important because it can make a difference in how easy it is to find and access files you
need.
6. It can be done manually or with a software program. There are many file management
system that are available, but they all have the same basic functions:
7. -Organizing – putting files into folders
8. -Storing – keeping your files saved on your computer
9. -Naming – giving your files an appropriate name for easy identification
10. -Deleting – deleting old or unnecessary files to free up space on your hard drive