6.file Managment
6.file Managment
File Management
A file is a collection of correlated information which is recorded on secondary or non-volatile storage like
magnetic disks, optical disks, and tapes. It is a method of data collection that is used as a medium for
giving input and receiving output from that program.
In general, a file is a sequence of bits, bytes, or records whose meaning is defined by the file creator and
user. Every File has a logical location where they are located for storage and retrieval.
1.Create
Creation of the file is the most important operation on the file. Different types of files are created
by different methods for example text editors are used to create a text file, word processors are
used to create a word file and Image editors are used to create the image files.
2.Delete
Deleting the file will not only delete all the data stored inside the file, It also deletes all the
attributes of the file. The space which is allocated to the file will now become available and can
be allocated to the other files.
3. Open:
Process must open the file before using it. Attributes and list of disk addresses are obtained into
main memory for fast access next time.
4. Close :
When use of the file completes, all accesses gets finished. The attributes and disk addresses are
no longer required, so the file should be closed to free up internal table space.
5.Read
Every file is opened in three different modes : Read, Write and append. A Read pointer is
maintained by the OS, pointing to the position up to which, the data has been read.
6.Write
Writing the file is different from creating the file. The OS maintains a write pointer for every file
which points to the position in the file from which, the data needs to be written.
7.Re-position
Re-positioning is simply moving the file pointers forward or backward depending upon the user's
requirement. It is also called as seeking.
8.Rename :
User needs to change the name of an existing file. This system call makes that possible.
File Types//skip
Several operating systems support many types of files. Following are the different types of files.
1. Regular files : Regular files contain user information. The byte sequence, record sequence and
tree structured explained above are the examples of regular files.
2.Directories : These are system files for mzaintaining the structure of the file system.
3.Character special files : These are related to input/output and used to model serial i/o devices
such as terminals, printers, and networks.
4. Block special files : These are used to model disks.
3. Tree structure
In this organization, a file consists of the records which are organized in tree structure. All the
records not necessarily have same length. Each record has a key field in a fixed position.
The records in the tree are arranged in the sorted order of key field, to permit quick searching for
a particular key. The main aim in this type of organization is to search record on particular key.
The next record also can be searched.
Operating system decides where to add new record. User is not concern about this operation. This
type of the is broadly used on the large mainframe computers and still used in some commercial
data processing
Following Figs. 6.1.2 (a),(b) and (c) shows three kinds of files. Fig. 6.1.2 (c) shows the tree of
records of student file arranged in sorted order of roll numbers.
Describe sequential and direct access method. //4M 2022
File Access Methods
File access is a process that determines the way that files are accessed and read into memory.
Generally, a single access method is always supported by operating systems. Though there are
some operating system which also supports multiple access methods.
Two file access methods are:
Sequential access
Direct random access
Sequential Access
In this type of file access method, records are accessed in a certain pre-defined sequence. In the
sequential access method, information stored in the file is also processed one by one.While
accessing,skipping of any record or reading them out of order is not possible.
This access method was convienient for storage medium such as magnetic tape to a certain extent
than disk.
Most compilers access files using this access method.
Random Access
The random access method is also called direct random access. This method allow accessing the
record directly. Each record has its own address on which can be directly accessed for reading
and writing.
When use of disk started for storing files, it became possible to read the bytes or records of a file
out of order. It is because; disks allow random access to any file block.
It also became possible to access records by its key instead of by position. Files whose bytes or
records can be read in any order are called random access files. They are required by many
applications such as database systems.
Advantages
1. It is simple to implement.
2. We will get Excellent read performance.
3. Supports Random Access into files.
Disadvantages
1. The disk will become fragmented.
2. It may be difficult to have a file grow.
Write random -
Advantages
1. There is no external fragmentation with linked allocation.
2. Any free block can be utilized in order to satisfy the file block requests.
3. File can continue to grow as long as the free blocks are available.
4. Directory entry will only contain the starting block address.
Disadvantages
1. Random Access is not provided.
2. Any of the pointers in the linked list must not be broken otherwise the file will get corrupted.
3. Need to traverse each block.
3. Indexed Allocation
The Indexed allocation method is another method that is used for file allocation. In the index
allocation method, we have an additional block, and that block is known as the index block. For each
file, there is an individual index block. In the index block, the ith entry holds the disk address of the
ith file block. We can see in the below figure that the directory entry comprises of the address of the
index block.
Advantages of Index Allocation
1. The index allocation method solves the problem of external fragmentation.
2. Index allocation provides direct access.
3.
Disadvantages of Index Allocation
1. In index allocation, pointer overhead is more.
2. We can lose the entire file if an index block is not correct.
3. It is totally a wastage to create an index for a small file.
Single-Level Directory:
Single-Level Directory is the easiest directory structure. There is only one directory in a single-level
directory, and that directory is called a root directory. In a single-level directory, all the files are present in
one directory that makes it easy to understand. In this, under the root directory, the user cannot create the
subdirectories.
Advantages :
1.It is simple to implement.
2. In a single-Level directory, the operations such as searching, creation, deletion, and updating can be
performed.
Disadvantages
If the size of the directory is large in Single-Level Directory, then the searching will be tough.
In a single-level directory, we cannot group the similar type of files.
Construct and explain directory structure of a file system in terms of two level and tree
structure.
Two-Level Directory
Two-Level Directory is another type of directory structure. In this, it is possible to create an individual
directory for each of the users. There is one master node in the two-level directory that include an
individual directory for every user. At the second level of the directory, there is a different directory
present for each of the users. Without permission, no user can enter into the other user’s directory.
Advantages of Two-Level Directory
1. In the two-level directory, various users have the same file name and also directory name.
2. Because of using the user-grouping and pathname, searching of files are quite easy.
Tree-Structured Directory
In a tree-structured directory, there is an own directory of each user, and any user is not allowed
to enter into the directory of another user. Although the user can read the data of root, the user
cannot modify or write it. The system administrator only has full access to the root directory. In
this, searching is quite effective and we use the current working concept. We can access the file
by using two kinds of paths, either absolute or relative.