Introduction to Operating Systems: Unit IV(b): File System

File Directory and Directory Structure

File System - Introduction to Operating Systems

User stores file in file system using directory. File system stores files of many users. Files are stored on the secondary storage device like hard disk, optical disk and memory disk. These device support random access method.

File Directory and Directory Structure

• User stores file in file system using directory. File system stores files of many users. Files are stored on the secondary storage device like hard disk, optical disk and memory disk. These device support random access method.

• Directory structure organizes and provides information about all files in the system. Every partition has a file system which consists of files and directory. Hard disks are split into one or more partitions. It is called as minidisks or volumes. User can assign names to volumes. Each disk contains minimum one partition.

• Operating systems support upto 24 partitions. Partitions can be larger than a disk i.e combing two hard disks. These partitions are called "virtual disks". Partition maintains information about files in "Device Directory".

• Files are stored in the directory. Directory is created by user. User is free to create as many as directory and assign suitable names. File system contains many directories. Directory maintains information about the file. File information includes type, size, date modified and name.

• In some operating system, directory itself is considered as a file. A set of logically associated files is called directory. Directory structure of the file system connects a directory to other directories in the system.

• Directory is a data structure that lists files and subdirectories in a collection. Directory structure contains a list of entries one for each file.

• Directory does not store any user data. Single dot (.) indicates a current directory rote and double dot (..) indicates parent directory. The root is identified by the directory '/'. The root file system has several subdirectories.

Windows file system uses a letter followed by colon for specifying root directory.  For example, root directory in windows is C: or D: or E:

• UNIX and Linux based file system uses slash (/) for specifying root directory.

A directory can contain any number of files. A directory can also contain subdirectories. Because a directory is nothing more than a special kind of file, directories also have names.

Operation on directory :

1. File searching: Directory structure is searched for particular file entry. File uses symbolic names and similar names may indicate a relationship between files.

2. Create a file: User creates new files and added to the directory.

3. Delete a file: User remove the file after completing its work on files.

4. Rename a file: User change the file name if file content is change.

5. Listing of directory: Listing of files in the directory for some use. MS-DOS and windows uses "dir" command and Linux/UNIX uses "ls" command for this purposes.

Single Level Directory

• Single level directory is a simple structure and there are no sub-directories.

• Fig. 6.3.1 shows three files with single level directory. It is also called flat directory structure.

• Single level directory structure is suitable only for single user. If user increases, it creates the problem with assigning the name to files.

• In single level directory structure, no two files can have the same name.

• It is simple to implement and searching of file is faster. This type of directory system is used in cameras and phones.

• Because of limitation of file names, this structure is rarely implemented.

• File name size varies according to the operating system. MS-DOS operating system allows only 11 character file names and UNIX OS allows upto 255 characters.

Disadvantages of single level directory:

1. Not suitable for a large number of files

2. Limitation of unique file name.

3. For large number of file, recalling file name is difficult.

Hierarchical Directory System

• Here files are grouped together to form a sub directory. Each directory may contain several subdirectories. In hierarchical file system, a root directory points to other directories and files.

• Hierarchical directory system contains various forms of directory structures. They are as follows:

1. Two-level directory structure

2. Tree structured directories

3. Acyclic graph directories.

Two-level Directory Structure

Two-level directory structure contains master file directory at the top level then user file directory at the second level. Actual user files are at the third level.

• File system maintains a master block for each user. Master block has one entry for each user.

User directory address is stored in the master block. Each user has a private directory. Different user can assign same names to their files as the directories for each user are now separate.

• Fig. 6.3.2 shows two-level directory structure.


Here user can work only in own directory. Other user need not worry about deleting or modifying files by other users.

• When user wants to create a file, system search that particular file name in the directory. If same file name is not found, then it creates a file otherwise it gives error messages.

• In this structure, different users may have files with same name. It solves the Viol name conflict problem. When user want to open a file, filename is searched for in users directory.

• A two level directory can be a tree or an inverted tree of height 2.

• There are still problems with two-level directory structure. It effectively isolates one user from another. This is some time advantage or some time disadvantages. For completely independent user is an advantages and disadvantages when cooperation between two users is required.

Tree Structured Directory

• Fig. 6.3.3 shows the tree structured directory.

• In this structure, directory itself is a file. A directory and sub directory contains a set of files. Internal format is same for all directories

• Commonly used directory structure is tree structure. Tree has a root directory. All files in disk have a unique path name.

A path name describes the path that the operating system must take to get from some starting point in the file system to the destination object. Each process has its own working directory. Path names are of two types : relative and absolute.

Relative path name : Its path starts from current working directory (may start with

Absolute path name: Its path starts from root directory (starts from "/").

• Tree structured directory differentiate file and subdirectory by using one bit representation. Zero (0) represents file and one (1) represents subdirectory.

• When process makes reference to a file for opening, file system search this file in the current directory. If needed file is not found in the current directory, then user either change the directory or give the full path of the file. System calls are used for performing any operation on the files or directory.

• Empty directory and its entry are easily deleted by operating system. If directory contains files and subdirectory, i.e. non-empty directory, some operating systems not delete the directory.

• To delete a directory, user must first delete all the files and subdirectory in that directory.

Merits

1. User can create his/her own directory.

2. User can access other user files by specifying path name.

3. Separate subdirectory for files associated with different topics

4. Searching id fast and efficient.

Demerits

1. Sub directory can not share between the user

2. Path is longer than two level directory structure

Acyclic Graph Directory

• Acyclic graph directory solve the problem of tree structure directory.

• It allows sharing the directory in between two users. At a time more than one places shared directory or file will exist in the file system.

Fig. 6.3.4 shows acyclic graph directory. Links can be used to construct acyclic graph

It is very interesting to note that a shared directory or file is not the same as two copies of the file. When there are two copies of files, each user can view the copy rather than the original, but if one user changes the file content, the changes will e file content, t not appear in the other's copy.

• Only one original file exists for shared copy. Any changes made by one user are immediately visible to the other user. When user create file in shared directory, it automatically appear in all the shared subdirectories.

Implementation of shared files and directory: 

1. Using link :

Link is used for creating shared files and directory. A link is a pointer to another file or subdirectory. If reference to a file is made, the directory is first searched. A link is a logical relationship between an inode and a file that relates the name of a file to its physical location.

• UNIX operating system uses acyclic graph directory structure. Reference count is maintained by UNIX for files and directory. UNIX operating system provides two types of links: hard link and symbolic link

• A hard link contains multiple directory entries that both refer to the same file. Hard links are only used with ordinary files in the same file system.

• A symbolic link is also called soft link. It contains a special file which maintains the information about file where to find the linked file. Symbolic links may be used to link directories and files in other file systems.

• Soft links were designed for two specific situations: Links to directories, which must be symbolic, and links to files in other file systems.

• Windows operating system only supports symbolic links.

• Hard links require a reference count, or link count for each file, keeping track of how many directory entries are currently referring to this file. Whenever one of the references is removed the link count is reduced, and when it reaches zero, the disk space can be reclaimed.

2. Duplicating information:

• Duplicate all information about shared files in both sharing directories. Original file will remain as it is without modifying any content by shared user.

 Consistency is not supported by copied file and shared file. Shared files may have more than one absolute path.

Advantages:

1. Simple for file traverse.

2. Structure is more flexible than a simple tree structure.

3. It allows directories and files to be shared between other users.

Disadvantages:

1. Deletion of file is difficult.

2. Problem with duplicate directory entries is maintaining consistency if the file is modified.


University Question

1. With neat sketch explain about the directory structure.

Introduction to Operating Systems: Unit IV(b): File System : Tag: : File System - Introduction to Operating Systems - File Directory and Directory Structure