Directory Structures-Operating Systems-Lecture Notes, Study notes of Operating Systems

Operating Systems is necessary course in Computer Science. Its about threading, process scheduling, deadlocks, memory management etc. This lecture includes: Directory, Linux, Unix, File, System, Sharing, Protection, Structure, File, Copy, Graph

Typology: Study notes

2011/2012

Uploaded on 08/06/2012

sarang
sarang 🇮🇳

4.5

(47)

86 documents

1 / 7

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
222
Operating Systems Lecture No.43
Operating Systems
Lecture No. 42
Reading Material
Chapter 11 of the textbook
Lecture 43 on Virtual TV
Summary
x Directory Structures
x Links in UNIX/Linux
x File System Mounting
x File Sharing
x File Protection
Acyclic-Graph Directories
A tree structure prohibits sharing of files. An acyclic graph allows directories to have
shared subdirectories and files. The same file may be in two different directories.
Acyclic-graph directory structure
A shared file is not the same as two copies of the file. Only one actual copy exists, so
any changes made by one user are immediately visible to the other. A common way of
implementing shared files and directories is to create a new directory entry called a link,
which is effectively a pointer to another file or subdirectory. A link can be implemented
as an absolute or relative path name. A file may now have multiple absolute path names.
This problem is similar to the aliasing problem in programming languages. Consequently
distinct file name may refer to the same files. If we are traversing the entire file system-to
find a file, to accumulate statistics, etc, this problem becomes significant since we do not
want to traverse the shared structures more than once. Another problem involves deletion.
docsity.com
pf3
pf4
pf5

Partial preview of the text

Download Directory Structures-Operating Systems-Lecture Notes and more Study notes Operating Systems in PDF only on Docsity!

Operating Systems Lecture No.

Operating Systems

Lecture No. 42

Reading Material

 Chapter 11 of the textbook  Lecture 43 on Virtual TV

Summary

 Directory Structures  Links in UNIX/Linux  File System Mounting  File Sharing  File Protection

Acyclic-Graph Directories

A tree structure prohibits sharing of files. An acyclic graph allows directories to have shared subdirectories and files. The same file may be in two different directories.

Acyclic-graph directory structure

A shared file is not the same as two copies of the file. Only one actual copy exists, so any changes made by one user are immediately visible to the other. A common way of implementing shared files and directories is to create a new directory entry called a link, which is effectively a pointer to another file or subdirectory. A link can be implemented as an absolute or relative path name. A file may now have multiple absolute path names. This problem is similar to the aliasing problem in programming languages. Consequently distinct file name may refer to the same files. If we are traversing the entire file system-to find a file, to accumulate statistics, etc, this problem becomes significant since we do not want to traverse the shared structures more than once. Another problem involves deletion.

If the file is removed when anyone deletes it, we may end up with dangling pointers to the now-nonexistent file. Solutions: AAnnootthheerr aapppprrooaacchh iiss ttoo pprreesseerrvvee tthhee ffiillee uunnttiill aallll rreeffeerreenncceess ttoo iitt aarree ddeelleetteedd.. WWhheenn aa lliinnkk oorr aa ccooppyy ooff tthhee ddiirreeccttoorryy eennttrryy iiss eessttaabblliisshheess,, aa nneeww eennttrryy iiss aaddddeedd ttoo tthhee ffiillee--rreeffeerreennccee lliisstt.. WWhheenn aa lliinnkk iiss ddeelleetteedd,, wwee rreemmoovvee iittss eennttrryy oonn tthhee lliisstt.. TThhee ffiillee iiss ddeelleetteedd wwhheenn iittss ffiillee--rreeffeerreennccee lliisstt iiss eemmppttyy.. SSiinnccee tthhee rreeffeerreennccee lliisstt ccaann bbee vveerryy llaarrggee wwee ccaann kkeeeepp aa ccoouunntt ooff tthhee nnuummbbeerr ooff rreeffeerreenncceess.. AA nneeww lliinnkk oorr ddiirreeccttoorryy iinnccrreemmeennttss tthhee rreeffeerreennccee ccoouunntt ,, ddeelleettiinngg aa lliinnkk oorr eennttrryy ddeeccrreemmeennttss tthhee ccoouunntt.. WWhheenn tthhee ccoouunntt iiss 00,, tthhee ffiillee ccaann bbee ddeelleetteedd.. UUNNIIXX uusseess tthhiiss ssoolluuttiioonn ffoorr hhaarrdd lliinnkkss..^ BBaacckkppooiinntteerrss^ can also be maintained so we can delete all pointers.

General Graph Directory

General graph directory

One serious problem with using an acyclic-graph structure is ensuring that there are no cycles. A solution is to allow only links to files not subdirectories. Also every time a new link is added use a ccyyccllee ddeetteeccttiioonn aallggoorriitthhmm to determine whether it is OK. If cycles are allowed, we want to avoid searching any component twice. A similar problem exists when we are trying to determine when a file can be deleted. A value of 0 in the reference count means no more references to the file/directory can be deleted. However, cycles can exist, e.g, due to self-referencing. In this case we need to use a garbage collection scheme, which involves traversing the entire file system, marking everything that can be accessed. Then a second pass collects everything that is not marked onto a list of free space. However this is extremely time consuming and is seldom used. However it is necessary because of possible cycles in a graph.

Links in UNIX

UNIX supports two types of links:  (^) HHaarrdd lliinnkkss  SSoofftt ( ssyymmbboolliicc ) lilinnkkss The ln command is used to create both links, ln –s is used to create a soft link  ln [options] existing-file new-file  ln [options] existing-file-list directory

Soft Links

prog2.c 4678

A file of type ‘link’ is created, which contains the pathname for the existing file as specified in the ln command. The existing file and the new (link) files have different inode numbers. When you make a reference to the link file, the UNIX system sees that the type of file is link and reads the link file to find the pathname for the actual file to which you are referring. When the existing file is removed, you have a ‘dangling pointer’ to it in the link file. Soft links take care of all the problems inherent in hard links. They are flexible. You may have soft links to directories and across file systems. However, UNIX has to support an additional file type, the link type, and a new file is created for every link, slowing down file operations.

File System Mounting

A file system is best visualized as a tree, rooted at /. /dev, /etc, /usr, and other directories in the root directory are branches, which may have their own branches, such as /etc/passwd, /usr/local, and /usr/bin. Filling up the root file system is not a good idea, so splitting /var from / is a good idea.Another common reason to contain certain directory trees on other file systems is if they are to be housed on separate physical disks, or are separate virtual disks, or CDROM drives. MMoouunnttiinngg^ makes file systems, files, directories, devices, and special files available for use at a particular location. (^) MMoouunntt ppooiinntt is the actual location from which the file system is mounted and accessed. You can mount a file or directory if you have access to the file or directory being mounted and write permission for the mount point There are types of mounts: ^ RReemmoottee mmoouunntt ^ LLooccaall mmoouunntt RReemmoottee mmoouunnttss are done on a remote system on which data is transmitted over a telecommunication line. LLooccaall mmoouunnttss are mounts done on your local system.

prog2_soft.c 98765

programs

OS

courses

Co Conntteennttss ooff pprroogg22__ssoofftt..cc

~/~/ccoouurrsseess//OOSS//pprrooggrraammss//pprroogg22..cc

Mounting in UNIX

All files accessible in a Unix system are arranged in one big tree, the file hierarchy, rooted at /. These files can be spread out over several devices. The mount command serves to attach the file system found on some device to the big file tree. Conversely, the umount command will detach it again. Here is the syntax of the mount command

mount -t type device dir

This command tells the kernel to attach the file system found on device (which is of type type ) at the directory dir. The previous contents (if any) and owner and mode of dir become invisible. As long as this file system remains mounted, the pathname dir refers to the root of the file system on device.

Existing Tree Unmounted filesystem

New Tree after mounting Filesystem

A few examples: –To let people in your UNIX group add, delete, and rename files in a directory of yours - and read or edit other people's files if the file permissions let them - use chmod 775 dirname. –To make a private file that only you can edit, use chmod 600 filename. To protect it from accidental editing, use chmod 400 filename.  CCoommmmoonn ggrroouuppss for members of a team. : System admin creates a new user group consisting of the members of team only. All team members get individual logins and set access permissions for their files so that they are accessible to other group members  (^) LLiinnkkss.. A link is a way to establish a connection between the file to be shared and the directory entries of the users who want to have aces to this file. The two types of links supported by UNIX: –Hard link –Soft/symbolic link