2. File system
ā¢ A file system is a method for storing and organizing computer files and the
data they contain to make it easy to find and access them.
ā¢ File systems may use a data storage device such as a hard disk or CD-
ROM and involve maintaining the physical location of the files,
ā¢ they might provide access to data on a fi le server by acting as clients for a
network protocol or
ā¢ they may be virtual and exist only as an access method for virtual data
3. File Concept
ā¢ Computers can store information on various storage media such as,
magnetic disks, magnetic tapes, optical disks.
ā¢ The physical storage is converted into a logical storage unit by operating
system.
ā¢ The logical storage unit is called FILE.
ā¢ A file is a collection of similar records.
ā¢ A record is a collection of related fields that can be treated as a unit by
some application program.
ā¢ A field is some basic element of data.
ā¢ Any individual field contains a single value. A data base is collection of
related data.
4. File Concept
ā¢ Contiguous logical address space
ā¢ Types:
ā¢ Data
ā¢ numeric
ā¢ character
ā¢ binary
ā¢ Program
ā¢ Contents defined by fileās creator
ā¢ Many types
ā¢ Consider text file, source file, executable file
5. File Attributes
ā¢ Name ā only information kept in human-readable form
ā¢ Identifier ā unique tag (number) identifies file within file system
ā¢ Type ā needed for systems that support different types
ā¢ Location ā pointer to file location on device
ā¢ Size ā current file size
ā¢ Protection ā controls who can do reading, writing, executing
ā¢ Time, date, and user identification ā data for protection, security,
and usage monitoring
ā¢ Information about files are kept in the directory structure, which is
maintained on the disk
ā¢ Many variations, including extended file attributes such as file
checksum
ā¢ Information kept in the directory structure
6. File operations: File is an abstract data type
ā¢ 1. Creating a file : Two steps are needed to create a file.
ā¢ They are:
ā¢ 1. Check whether the space is available or not.
ā¢ 2. If the space is available then made an entry for the new file in the directory. The entry includes name of the file, path of the file, etcā¦
ā¢ 2. Writing a file : To write a file, we have to know 2 things.
ā¢ One is name of the file and
ā¢ second is the information or data to be written on the file,
ā¢ the system searches the entered given location for the file.
ā¢ If the file is found, the system must keep a write pointer to the location in the file where the next write is to take place.
ā¢ 3. Reading a file : To read a file, first of all we search the directories for the file,
ā¢ if the file is found, the system needs to keep a read pointer to the location in the file where the next read is to take place.
ā¢ Once the read has taken place, the read pointer is updated.
ā¢ 4. Repositioning within a file : The directory is searched for the appropriate entry and the current file position pointer is
repositioned to a given value.
ā¢ This operation is also called file seek.
ā¢ 5. Deleting a file : To delete a file, first of all search the directory for named file, then released the file space and erase the
directory entry.
ā¢ 6. Truncating a file : To truncate a file, remove the file contents only but, the attributes are as it is.
8. FILE ACCESS METHODS
ā¢ Files stores information, this information must be accessed and read
into computer memory.
ā¢ There are so many ways that the information in the file can be
accessed.
ā¢ 1. Sequential file access: Information in the file is processed in order
i.e. one record after the other.
ā¢ Magnetic tapes are supporting this type of file accessing.
ā¢ Eg : A file consisting of 100 records, the current position of read/write head is
45th record, suppose we want to read the 75th record then, it access
sequentially from 45, 46, 47 ā¦ā¦.. 74, 75.
ā¢ So the read/write head traverse all the records between 45 to 75.
9. Direct access:
ā¢ 2. Direct access: Direct access is also called relative access.
ā¢ Here records can read/write randomly without any order.
ā¢ The direct access method is based on a disk model of a file,
because disks allow random access to any file block.
ā¢ Eg : A disk containing of 256 blocks, the position of
read/write head is at 95th block.
ā¢ The block is to be read or write is 250th block.
ā¢ Then we can access the 250th block directly without any
restrictions.
ā¢ Eg : CD consists of 10 songs, at present we are listening song
3, If we want to listen song 10, we can shift to 10.
10.
11. 3. Indexed Sequential File access
ā¢ The main disadvantage in the sequential file is, it takes more time to
access a Record .
ā¢ Records are organized in sequence based on a key field.
ā¢ Eg : A file consisting of 60000 records, the master index divide the
total records into 6 blocks, each block consisting of a pointer to
secondary index.
ā¢ The secondary index divide the 10,000 records into 10 indexes.
ā¢ Each index consisting of a pointer to its original location.
ā¢ Each record in the index file consisting of 2 field, A key field and a
pointer field.
13. DIRECTORY STRUCTURE
ā¢ The directories themselves are simply files
indexing other files, which may in turn be
directories
ā¢ if a hierarchical indexing scheme is used.
ā¢ Sometimes the file system consisting of millions
of files, at that situation it is very hard to manage
the files.
ā¢ To manage these files, grouped these files and load
one group into one partition.
ā¢ Each partition is called a directory .
ā¢ a directory structure provides a mechanism for
organizing many files in the file system.
14. Directory structureā¦
ā¢ The typical contents of a directory are:
ā¢ 1. file name (string uniquely identifying the fi le), type (e.g. text, binary data, executable,
ā¢ library), organization (for systems that support different organizations);
ā¢ 2. device (where the file is physically stored), size (in blocks), starting address on device
(to
ā¢ be used by the device I/O subsystem to physically locate the file);
ā¢ 3. creator, owner, access information (who is allowed to access the file, and what they
may do with it);
ā¢ 4. date of creation/of last modification;
ā¢ 5. locking information (for the system that provide fi le/record locking).
15. OPERATION ON THE DIRECTORIES :
ā¢ 1. Searchfor a file:Searcha directorystructureforrequiredfile.
ā¢ 2. createafile: Newfilesneedtobe created,addedtothe directory.
ā¢ 3. Delete a file:Whena fileis nolongerneeded,wewantto removeitfromthe directory.
ā¢ 4. Lista directory:We canknow thelistoffilesinthe directory.
ā¢ 5. Rename afile: Wheneverwe needtochangethe nameofthe file,wecanchangethe name.
ā¢ 6. Traversethe filesystem: We needtoaccesseverydirectoryandeveryfilewithina directorystructurewecan
traversethe filesystem
16.
17. various directory structures
ā¢ In single level directory all files are contained in the same directory. It is easy to support and
ā¢ understand. It has some limitations like:
ā¢ 1. Large number of files (naming).
ā¢ 2. Ability to support different users/topics (grouping).
The problem here is different users may accidentally use the same names for their files.
E.g : If user 1 creates a files called sample and then later user 2 to creates a file called sample, then user2ās file
will overwrite user 1 file. That's why it is not used in the multi user system.
18. Two Level Directory
ā¢ In two level directory structure one is master file directory and the other is user file directory.
ā¢ Here each user has their own user file directory.
ā¢ Each entry in the master file directory points to a user fi le directory.
ā¢ Each user has rights to access their own directory but canāt access other userās directory, if
permission is not given by the owner of the second one.
19. ā¢ To avoid this problem each user need a private directory,
ā¢ Names chosen by one user don't interfere with names chosen by a different user.
20. Tree Level Directory
ā¢ In Tree level directory the directory structure is a tree
with arbitrary height.
ā¢ Here users may create their own subdirectories.
ā¢ Two level directory eliminates name conflicts among
users but it is not satisfactory for users with a large
number of files.
ā¢ To avoid this create the sub-directory and load the
same type of files into the sub-directory.
ā¢ so, here each can have as many directories are
needed.
There are 2 types of path
ā¢ 1. Absoulte path
ā¢ 2. Relative path
ā¢ Absoulte path : Begging with root and follows a path
down to specified files giving directory, directory
name on the path.
ā¢ Relative path : A path from current directory.
21. ā¢ Absolute or relative path name
ā¢ Creating a new file is done in current directory
ā¢ Delete a file
rm <file-name>
ā¢ Creating a new subdirectory is done in current
directory
mkdir <dir-name>
Example: if in current directory /mail
mkdir count
Deleting āmailā ļ deleting the entire subtree rooted
by āmailā
22. Acyclic graphdirectory
ā¢ Multiple users are working on a project, the project files can be
stored in a common sub-directory of the multiple users.
ā¢ This type of directory is called acyclic graph directory .
ā¢ The common directory will be declared a shared directory.
ā¢ The graph contain no cycles with shared files, changes made by
one user are made visible to other users.
ā¢ A file may now have multiple absolute paths.
ā¢ when shared directory/file is deleted, all pointers to the
directory/ files also to be removed.
23. General graph directory:
ā¢ When we add links to an existing tree structured
directory, the tree structure is destroyed, resulting is a
simple graph structure.
ā¢ How do we guarantee no cycles?
ā¢ Allow only links to file not subdirectories
ā¢ Garbage collection
ā¢ Every time a new link is added use a cycle
detection algorithm to determine
whether it is OK
ā¢
24. File allocation methods
ā¢ An allocation method refers to how disk blocks are allocated for files.
ā¢ One main problem in file management is how to allocate space for files so that disk space is utilized
effectively and files can be accessed quickly.
ā¢ Three major methods of allocating disk space are contiguous, linked, and indexed. Each method
has its advantages and disadvantages.
ā¢ Accordingly, some systems support all three (e.g. Data Generalās RDOS). More commonly, a
ā¢ system will use one particular method for all files.
25. Contiguous allocation
ā¢ The contiguous allocation method
requires each file to occupy a set of
contiguous address on the disk.
ā¢ Disk addresses define a linear
ordering on the disk.
ā¢ each file occupies set of contiguous
blocks
ā¢ Best performance in most cases
ā¢ Simple ā only starting location (block
#) and length (number of blocks) are
required
ā¢ Problems include finding space for file,
knowing file size, external
fragmentation, need for compaction
off-line (downtime) or on-line
Linked.
26. Linked allocation
ā¢ Linked allocation ā each file a linked list of blocks o File
ends at nil pointer
ā¢ No external fragmentation
ā¢ Each block contains pointer to next block
ā¢ No compaction, external fragmentation
ā¢ Free space management system called when new block
needed
ā¢ Improve efficiency by clustering blocks into groups but
increases internal fragmentation
ā¢ Reliability can be a problem
ā¢ Locating a block can take many I/O s and disk seeks FAT
(File Allocation Table) variation
ā¢ Beginning of volume has table, indexed by block number
ā¢ Much like a linked list, but faster on disk and cacheable
28. Indexed allocation
ā¢ Each file has its own index block(s) of pointers to its data blocks
ā¢ The indexed allocation method is the solution to the problem of both contiguous and linked
allocation.
ā¢ This is done by bringing all the pointers together into one location called the index block.
ā¢ Of course, the index block will occupy some space and thus could be considered as an overhead of
the method.
ā¢ In indexed allocation, each fi le has its own index block, which is an array of disk sector of
addresses.
ā¢ The ith entry in the index block points to the ith sector of the file.
ā¢ The directory contains the address of the index block of a file.
ā¢ To read the ith sector of the fi le, the pointer in the ith index block entry is read to find the desired
sector.
ā¢ Indexed allocation supports direct access, without suffering from external fragmentation.
ā¢ Any free block anywhere on the disk may satisfy a request for more space.