Unit 5 Notes
Unit 5 Notes
Files
● File naming:
○ Process gives the name to the file when it creates it.
○ The rules for file naming(not same for all systems).
○ Upper and Lower case letters.
○ File name divided into 2 parts: Name and extension.
○ In Unix user has a choice of deciding the size of extension.
○ In UNIX, file can have 2 or more extensions.
○ The table shows examples of file extension, its meaning and type.
File Structure
1. Unstructured Sequence of bytes(Ordinary Files)
a. Any type of content can be kept in the file.
2. Sequence of fixed length records
a. Punched cards
b.
3. Tree Structure
File Operations
● For storage and retrieval purpose, different types of systems offer different operations.
● For the operations like create, write, read operating system offer the system calls.
1. Create
2. Delete
3. Open
4. Close
5. Read
6. Write
7. Append
8. Seek
9. Get attributes
10. Set attributes
11. Rename
The direct access mechanism requires the OS to perform some additional tasks but eventually
leads to much faster retrieval of records as compared to sequential access.
● The files can be retrieved right away with a direct access mechanism, reducing the
average access time of a file.
● There is no need to traverse all of the blocks that come before the required block to
access the record.
Disadvantages of Direct/Relative Access:
● The direct access mechanism is typically difficult to implement due to its complexity.
● Organizations can face security issues as a result of direct access as the users may
access/modify the sensitive information. As a result, additional security processes must
be put in place.
Primary index blocks contain the links of the secondary inner blocks which contain links to the
data in the memory.
● If the index table is appropriately arranged, it accesses the records very quickly.
● Records can be added at any position in the file quickly.
Disadvantages of Indexed Sequential Access:
● When compared to other file access methods, it is costly and less efficient.
● It needs additional storage space.
1.
Five Fundamental of file organizations
File Directories
● Directory Structure:
○ Directories keep track of files.
○ Directories are itself files in many system.
○ In order to manage all these data, we need to organize them.
The root directory is the topmost level of the The home directory is a subdirectory of the root directory.
system drive.
It is denoted by a slash '/'. It is denoted by '~' and has path "/users/username".
The admin has access to make any changes in No user other than the root user can change the settings of
the files and settings. the entire system.
The admin can create a user. Any user having a home directory cannot create a user.
In the Linux file system, everything comes The home directory contains a particular user's data.
under the root directory.
Path Names
Types of path name
1. Absolute
2. Relative
Example:
File Sharing
● It is necessary to share a file among multiple users in a multiuser system.
● It needs to deal with two issues
○ :that are access rights and
○ the management of simultaneous access.
● Access Rights:
○ It is important to grant particular access permissions or rights to users or groups of
users to access a particular file.
○ Examples:
■ None access right(Directory of file
■ Knowledge(Owner of file)
■ Execute
■ Read
■ Append
■ Update
■ Changing Protection
■ Delete
_______________________________________________________________
Whenever a hard disk is formatted, a system has many small areas called blocks or sectors that
are used to store any kind of file. File allocation methods are different ways by which the
operating system stores information in memory blocks, thus allowing the hard drive to be
utilized effectively and the file to be accessed. Below are the types of file allocation methods in
the Operating System.
First, let's understand the meaning of contiguous, here contiguous means adjacent or touching.
Now let's understand contiguous file allocation.
In contiguous file allocation, the block is allocated in such a manner that all the allocated blocks
in the hard disk are adjacent.
Assuming a file needs 'n' number of blocks in the disk and the file begins with a block at
position'x', the next blocks to be assigned to it will be x+1,x+2,x+3,...,x+n-1 so that they are in a
contiguous manner.
Example
We have three different types of files that are stored in a contiguous manner on the hard disk.
In the above image on the left side, we have a memory diagram where we can see the blocks of
memory. At first, we have a text file named file1.txt which is allocated using contiguous memory
allocation, it starts with the memory block 0 and has a length of 4 so it takes the 4 contiguous
blocks 0,1,2,3. Similarly, we have an image file and video file named sun.jpg and mov.mp4
respectively, which you can see in the directory that they are stored in the contiguous blocks.
5,6,7 and 9,10,11 respectively.
Here the directory has the entry of each file where it stores the address of the starting block and
the required space in terms of the block of memory.
Advantages
The Linked file allocation overcomes the drawback of contiguous file allocation. Here the file
which we store on the hard disk is stored in a scattered manner according to the space available
on the hard disk. Now, you must be thinking about how the OS remembers that all the scattered
blocks belong to the same file. So as the name linked File Allocation suggests, the pointers are
used to point to the next block of the same file, therefore along with the entry of each file each
block also stores the pointer to the next block.
Example
Here we have one file which is stored using Linked File Allocation.
In the above image on the right, we have a memory diagram where we can see memory blocks.
On the left side, we have a directory where we have the information like the address of the first
memory block and the last memory block.
In this allocation, the starting block given is 0 and the ending block is 15, therefore the OS
searches the empty blocks between 0 and 15 and stores the files in available blocks, but along
with that it also stores the pointer to the next block in the present block. Hence it requires some
extra space to store that link.
Advantages
Disadvantages
The indexed file allocation is somewhat similar to linked file allocation as indexed file allocation
also uses pointers but the difference is here all the pointers are put together into one location
which is called index block. That means we will get all the locations of blocks in one index file.
The blocks and pointers were spread over the memory in the Linked Allocation method, where
retrieval was accomplished by visiting each block sequentially. But here in indexed allocation, it
becomes easier with the index block to retrieve.
Example
As shown in the diagram below block 19 is the index block which contains all the addresses of
the file named text1. In order, the first storage block is 9, followed by 16, 1, then 10, and 25. The
negative number -1 here denotes the empty index block list as the file text1 is still too small to
fill more blocks.
Advantages and Disadvantages
Advantages
Disadvantages
Inode.
In Operating systems based on UNIX, every file is indexed using Inode(information-node). The
inode is the special disk block that is created with the creation of the file system. This special
block is used to store all the information related to the file like name, authority, size, etc along
with the pointers to the other blocks where the file is stored.
Explanation
In this special block, some of its space is used to store the information related to the field as
mentioned above and the remaining space is used to store the addresses of blocks that contain the
actual file.
The first few pointers in Inode point to direct blocks, i.e they contain the addresses of the disk
blocks containing the file data. A few pointers in inode point to the indirect blocks. There are
three types of indirect blocks: single indirect, double indirect, and triple indirect.
A single indirect block contains nothing but the address of the block containing the file data, not
the file itself as shown in the figure below. Furthermore, the double indirect block points to the
pointers which again point to the pointers which point to the data blocks. Further, it goes in a
similar way for triple indirect block.
Advantages
● Accessibility of file becomes easy as all the information like metadata and block address
is stored inside inode.
● Read-write and creation timestamps are stored inside the inode.
● Filenames do not affect inodes. In other words, a single file can be copied and renamed
without losing its address.
Disadvantages
● All new files and folders will be rejected as soon as a file system runs out of inodes.
● Upon 100% utilization of inodes the system will start to notice OS restarting, data loss,
applications crashing, and more OS-related issues.
__________________________________________________________________________