UNIT- IV OS
UNIT- IV OS
▪ File is a sequence of bits, bytes, lines or records whose meaning is defined by the
▪ File pointer: pointer to last read/write location, per process that has the file open
▪ File-open count: counter of number of times a file is open – to allow removal of data from
▪ Mandatory or advisory:
▪ Mandatory – If a lock is mandatory, then once a process acquires an exclusive lock, the operating
system will prevent any other process from accessing the locked file
▪ Advisory – processes can find status of locks and decide what to do
▪ A common technique for implementing file types is to include the type as part of
the file name.
▪ The name is split into two parts—
▪ name and
▪ Extension
▪ The system uses the extension to indicate the type of the file and the type of
operations that can be done on that file.
▪ File types also can be used to indicate the internal structure of the file
▪ A File Structure should be according to a required format that the operating system
can understand.
▪ A file has a certain defined structure according to its type.
▪ A text file is a sequence of characters organized into lines.
▪ A source file is a sequence of procedures and functions.
▪ An object file is a sequence of bytes organized into blocks that are understandable
by the machine.
▪ When operating system defines different file structures, it also contains the code to
support these file structure. Unix, MS-DOS support minimum number of file
structure.
▪ A directory is a container that is used to contain folders and file. It organizes files
and folders into a hierarchical manner.
▪ The directory can be viewed as a symbol table that translates file names into their
directory entries
▪ Search for a file.
▪ Create a file
▪ Delete a file
▪ List a directory
▪ Rename a file
▪ Disadvantages:
▪ 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.
▪ An acyclic graph is a graph with no cycle and allows 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 shared file is not the same as copy file . If any
programmer makes some changes in the subdirectory it will reflect in both
subdirectories.
▪ Advantages:
▪ We can share files.
▪ Searching is easy due to different-different paths.
▪ Disadvantages:
▪ We share the files via linking, in case of deleting it may create the problem,
▪ If the link is softlink then after deleting the file we left with a dangling pointer.
▪ In case of hardlink, to delete a file we have to delete all the reference associated
with it.
▪ In general graph directory structure, cycles are allowed within a directory structure
where multiple directories can be derived from more than one parent directory.
▪ The main problem with this kind of directory structure is to calculate total size or
space that has been taken by the files and directories.
▪ If cycles are allowed to exist in the directory, we likewise want to avoid searching
any component twice, for reasons of correctness as well as performance.
▪ A poorly designed algorithm might result in an infinite loop continually searching
through the cycle and never terminating
▪ Advantages:
▪ It allows cycles.
▪ It is more flexible than other directories structure.
▪ Disadvantages:
▪ It is more costly than others.
▪ It needs garbage collection.
▪ The way that files are accessed and read into memory is determined by Access
methods.
▪ Usually a single access method is supported by systems while there are OS's that
support multiple access methods.
1. Sequential-Access,
2. Direct Access,
3. Index sequential Method.
▪ Data is accessed one record right after another is an order.
▪ Read command cause a pointer to be moved ahead by one.
▪ Write command allocate space for the record and move the pointer to the new End
Of File.
▪ Such a method is reasonable for tape.
▪ This method is useful for disks.
▪ The file is viewed as a numbered sequence of blocks or records.
▪ There are no restrictions on which blocks are read/written, it can be dobe in any
order.
▪ User now says "read n" rather than "read next".
▪ "n" is a number relative to the beginning of file, not relative to an absolute physical
disk location.
▪ It is the other method of accessing a file which is built on the top of the sequential
access method.
▪ These methods construct an index for the file.
▪ The index, like an index in the back of a book, contains the pointer to the various
blocks.
▪ To find a record in the file, we first search the index and then by the help of pointer
we access the file directly.
▪ It is built on top of Sequential access.
▪ It uses an Index to control the pointer while accessing files.
▪ To keep safe the data of the user from the improper access to the system.
▪ Protection can be provided in number of ways. For a single laptop system, we might
provide protection by locking the computer in a desk drawer or file cabinet.
▪ For multi-user systems, different mechanisms are used for the protection.
▪ The files which have direct access of the any user have the need of protection.
▪ The files which are not accessible to other users doesn’t require any kind of protection.
▪ The mechanism of the protection provide the facility of the controlled access by just
limiting the types of access to the file
▪ Types of Access :
▪ Read –
Reading from a file.
▪ Write –
Writing or rewriting the file.
▪ Execute –
Loading the file and after loading the execution process starts.
▪ Append –
Writing the new information to the already existing file, editing must be end at the end of the
existing file.
▪ Delete –
Deleting the file which is of no use and using its space for the another data.
▪ List –
List the name and attributes of the file.
▪ Operations like renaming, editing the existing file, copying; these can also be controlled.
▪ Access Control :
▪ There are different methods used by different users to access any file.
▪ The general way of protection is to associate identity-dependent access with all the
files and directories an list called access-control list (ACL) which specify the names
of the users and the types of access associate with each of the user.
▪ The main problem with the access list is their length. If we want to allow everyone
to read a file, we must list all the users with the read access.
▪ The access to any system is also controlled by the password. If the use of password
are is random and it is changed often, this may be result in limit the effective access
to a file.
The use of passwords has a few disadvantages:
▪ The number of passwords are very large so it is difficult to remember the large
passwords.
▪ If one password is used for all the files, then once it is discovered, all files are
accessible; protection is on all-or-none basis.