|
|
|
Modern Operating Systems by Herbert Bos and Andrew S. Tanenb...
Modern_Operating_Systems_by_Herbert_Bos_and_Andrew_S._Tanenbaum_4th_Ed.pdf
Showing 322-323 out of 1137
Modern Operating Systems by Herbert Bos and Andrew...
Modern_Operating_Systems_by_Herbert_Bos_and_Andrew_S._Tanenbaum_4th_Ed.pdf-M ODERN O PERATING S YSTEMS
Modern Operating Systems by Herbert...
Modern_Operating_Systems_by_Herbert_Bos_and_Andrew_S._Tanenbaum_4th_Ed.pdf-M ODERN O PERATING S YSTEMS
Page 322
SEC. 4.3
FILE-SYSTEM IMPLEMENTATION
291
link
.
The file system itself is now a
Directed Acyclic Graph
, or
DAG
, rather than
a tree. Having the file system be a DAG complicates maintenance, but such is life.
Root directory
B
B
B
C
C
C
C
A
B
C
B
?
C
C
C
A
Shared file
Figure 4-16.
File system containing a shared file.
Sharing files is convenient, but it also introduces some problems.
To start
with, if directories really do contain disk addresses, then a copy of the disk ad-
dresses will have to be made in
B
’s directory when the file is linked. If either
B
or
C
subsequently appends to the file, the new blocks will be listed only in the direc-
tory of the user doing the append. The changes will not be visible to the other user,
thus defeating the purpose of sharing.
This problem can be solved in two ways. In the first solution, disk blocks are
not listed in directories, but in a little data structure associated with the file itself.
The directories would then point just to the little data structure.
This is the ap-
proach used in UNIX (where the little data structure is the i-node).
In the second solution,
B
links to one of
C
’s files by having the system create a
new file, of type LINK, and entering that file in
B
’s directory. The new file con-
tains just the path name of the file to which it is linked. When
B
reads from the
linked file, the operating system sees that the file being read from is of type LINK,
looks up the name of the file, and reads that file. This approach is called
symbolic
linking
, to contrast it with traditional (hard) linking.
Each of these methods has its drawbacks. In the first method, at the moment
that
B
links to the shared file, the i-node records the file’s owner as
C
.
Creating a
link does not change the ownership (see Fig. 4-17), but it does increase the link
count in the i-node, so the system knows how many directory entries currently
point to the file.
If
C
subsequently tries to remove the file, the system is faced with a problem.
If it removes the file and clears the i-node,
B
will have a directory entry pointing to
Page 323
292
FILE SYSTEMS
CHAP. 4
C's directory
B's directory
B's directory
C's directory
Owner = C
Count = 1
Owner = C
Count = 2
Owner = C
Count = 1
(a)
(b)
(c)
Figure 4-17.
(a) Situation prior to linking. (b) After the link is created. (c) After
the original owner removes the file.
an invalid i-node.
If the i-node is later reassigned to another file,
B
’s link will
point to the wrong file. The system can see from the count in the i-node that the
file is still in use, but there is no easy way for it to find all the directory entries for
the file, in order to erase them. Pointers to the directories cannot be stored in the i-
node because there can be an unlimited number of directories.
The only thing to do is remove
C
’s directory entry, but leave the i-node intact,
with count set to 1, as shown in Fig. 4-17(c). We now have a situation in which
B
is the only user having a directory entry for a file owned by
C
.
If the system does
accounting or has quotas,
C
will continue to be billed for the file until
B
decides to
remove it, if ever, at which time the count goes to 0 and the file is deleted.
With symbolic links this problem does not arise because only the true owner
has a pointer to the i-node. Users who have linked to the file just have path names,
not i-node pointers.
When the
owner
removes the file, it is destroyed. Subsequent
attempts to use the file via a symbolic link will fail when the system is unable to
locate the file. Removing a symbolic link does not affect the file at all.
The problem with symbolic links is the extra overhead required. The file con-
taining the path must be read, then the path must be parsed and followed, compo-
nent by component, until the i-node is reached. All of this activity may require a
considerable number of extra disk accesses. Furthermore, an extra i-node is needed
for each symbolic link, as is an extra disk block to store the path, although if the
path name is short, the system could store it in the i-node itself, as a kind of opti-
mization. Symbolic links have the advantage that they can be used to link to files
on machines anywhere in the world, by simply providing the network address of
the machine where the file resides in addition to its path on that machine.
There is also another problem introduced by links, symbolic or otherwise.
When links are allowed, files can have two or more paths.
Programs that start at a
given directory and find all the files in that directory and its subdirectories will
locate a linked file multiple times. For example, a program that dumps all the files
Ace your assessments! Get Better Grades
Browse thousands of Study Materials & Solutions from your Favorite Schools
Concordia University
Concordia_University
School:
Operating_Systems
Course:
Introducing Study Plan
Using AI Tools to Help you understand and remember your course concepts better and faster than any other resource.
Find the best videos to learn every concept in that course from Youtube and Tiktok without searching.
Save All Relavent Videos & Materials and access anytime and anywhere
Prepare Smart and Guarantee better grades
Students also viewed documents
lab 18.docx
lab_18.docx
Course
Course
3
Module5QuizSTA2023.d...
Module5QuizSTA2023.docx.docx
Course
Course
10
Week 7 Test Math302....
Week_7_Test_Math302.docx.docx
Course
Course
30
Chapter 1 Assigment ...
Chapter_1_Assigment_Questions.docx.docx
Course
Course
5
Week 4 tests.docx.do...
Week_4_tests.docx.docx
Course
Course
23
Week 6 tests.docx.do...
Week_6_tests.docx.docx
Course
Course
106