You are on page 1of 15

UNIT VI

DIAGRAMS-------------------> REFER TEXT


1.What is file protection? Explain how file protection is provided in Unix
Sol: When lnformutlon ls stored ln u computer system, we wunt to keep lt sufe from physlcul dumuge {rellublllty) und
lmproper uccess (protectlon).
Rellublllty ls generully provlded by dupllcute coples of flles. Muny computers huve systems progrums thut uutomutlcully (or
through computer-operutor lnterventlon) copy dlsk flles to tupe ut regulur lntervuls (once per duy or week or month) to
mulntuln u copy should u flle system be uccldentully destroyed. Flle systems cun be dumuged by hurdwure problems (such
us errors ln reudlng or wrltlng), power surges or fullures, heud crushes, dlrt, temperuture extremes, und vundullsm. Flles
muy be deleted uccldentully. Bugs ln the flle-system softwure cun ulso cuuse flle contents to be lost. 3rotectlon cun be
provlded ln muny wuys. For u smull slngle-user system, we mlght provlde protectlon by physlcully removlng the floppy
dlsks und locklng them ln u desk druwer or flle cublnet. In u multluser system, however, other mechunlsms ure needed.
Types of Access
7he need to protect flles ls u dlrect result of the ublllty to uccess flles. Systems thut do not permlt uccess to the flles of other
users do not need protectlon. 7hus, we could provlde complete protectlon by prohlbltlng uccess. Alternutlvely, we could
provlde free uccess wlth no protectlon. Both upprouches ure too extreme for generul use. Whut ls needed ls controlled
access.
3rotectlon mechunlsms provlde controlled uccess by llmltlng the types of flle uccess thut cun be mude. Access ls
permltted or denled dependlng on severul fuctors, one of whlch ls the type of uccess requested. Severul dlfferent types of
operutlons muy be controlled:
Reud. Reud from the flle.
Wrlte. Wrlte or rewrlte the flle.
(xecute. Loud the flle lnto memory und execute lt.
Append. Wrlte new lnformutlon ut the end of the flle.
Delete. Delete the flle und free lts spuce for posslble reuse.
Llst. Llst the nume und uttrlbutes of the flle.
Other operutlons, such us renumlng, copylng, und edltlng the flle, muy ulso be controlled. For muny systems, however,
these hlgher-level functlons muy be lmplemented by u system progrum thut mukes lower-level system culls.
Access Control
7he most common upprouch to the protectlon problem ls to muke uccess dependent on the ldentlty of the user. Dlfferent
users muy need dlfferent types of uccess to u flle or dlrectory. 7he most generul scheme to lmplement ldentlty-dependent
uccess ls to ussoclute wlth, euch flle und dlrectory un uccess-control llst (ACL) speclfylng user numes und the types of
uccess ullowed for euch user. When u user requests uccess to u purtlculur flle, the operutlng system checks the uccess llst
ussocluted wlth thut flle. If thut user ls llsted for the requested uccess, the uccess ls ullowed. Otherwlse, u protectlon
vlolutlon occurs, und the user |ob ls denled uccess to the flle.
7hls upprouch hus the udvuntuge of enubllng complex uccess methodologles. 7he muln problem wlth uccess llsts ls
thelr length. If we wunt to ullow everyone to reud u flle, we must llst ull users wlth reud uccess. 7hls technlque hus two
undeslruble consequences:
Constructlng such u llst muy be u tedlous und unrewurdlng tusk, especlully lf we do not know ln udvunce the llst of
users ln. the system.
7he dlrectory entry, prevlously of flxed slze, now needs to be of vurluble slze, resultlng ln more compllcuted spuce
munugement.
7hese problems cun be resolved by use of u condensed verslon of the utcess llst.
7o condense the length of the uccess-control llst, muny systems recognlze three clusslflcutlons of users ln
connectlon wlth euch flle:
Owner. 7he user who creuted the flle ls the owner.
Group. A set of users who ure shurlng the flle und need slmllur uccess ls u group, or work group.
Unlverse. All. other users ln the system constltute the unlverse.
7he most common recent upprouch ls to comblne uccess-control llsts wlth the more generul (und eusler to lmplement)
owner, group, und unlverse uccess-control scheme |ust descrlbed.
2.Discuss about the free space management
Sol: Slnce dlsk spuce ls llmlted, we need to reuse the spuce from deleted flles for new flles, lf posslble. 7o keep truck of
free dlsk spuce, the system mulntulns u free-spuce llst. 7he free-spuce llst records ull free dlsk blocksthose not ullocuted
to some flle or dlrectory. 7o creute u flle, we seurch the free-spuce llst for the requlred umount of spuce und ullocute thut
spuce to the new flle. 7hls spuce ls then removed from the free-spuce llst. When u flle ls deleted, lts dlsk sp>uce ls udded
to the free-spuce llst.
Bit Vector:
Frequently, the free-spuce llst ls lmplemented us u blt mup or blt vector. (uch block ls represented by 1 blt. If the
block ls free, the blt ls 1; lf the block ls ullocuted, the blt ls 0.
For exumple, conslder u dlsk where blocks 2, 3, 4, 5, 8, 9,10,11,12,13,17, 18,25,26, und 27 ure free und the
rest of the blocks ure ullocuted. 7he free-spuce blt mup would be
001111001111110001100000011100000 ...
7he muln udvuntuge of thls upprouch ls lts relutlve slmpllclty und lts efflclency ln flndlng the flrst free block or n
consecutlve free blocks on the dlsk
For flndlng the flrst free block on u system thut uses u blt-vector to ullocute dlsk spuce ls to sequentlully check euch word ln
the blt mup to see whether thut vulue ls not 0., slnce u 0-vulued word hus ull 0 blts und represents u set of ullocuted blocks.
7he flrst non-0 word ls scunned for the flrst 1 blt, whlch ls the locutlon of the flrst free block. 7he culculutlon of the block
number ls
(number of blts per word) x (number of 0-vulue words) + offset of flrst 1 blt.
Linked List:
Another upprouch to free-spuce munugement ls to llnk together ull the free dlsk blocks, keeplng u polnter to the
flrst free block ln u speclul locutlon on the dlsk und cuchlng l t ln memory. 7hls flrst block contulns u polnter to the
next free dlsk block, und so on. +owever, thls scheme ls not efflclent; to truverse the llst, we must reud euch
block, whlch requlres substuntlul I / O tlme. Fortunutely, truverslng the free llst ls not u frequent uctlon usuully
,the operutlng system slmply needs u free block so thut lt cun ullocute thut.block to u flle,, so the flrst block ln the
free llst ls used. 7he FA7 method lncorporutes free-block uccountlng lnto the ullocutlon dutu structure. No
sepurute method ls needed.

Grouping
A modlflcutlon of the free-llst upprouch ls to store the uddresses of n free blocks ln the flrst free block. 7he flrst n1 of
these blocks ure uctuully free. 7he lust block contulns the uddresses of unother n free blocks, und so on. 7he uddresses of u
lurge number of free blocks cun now be found qulckly, unllke the sltuutlon when the stundurd llnked-llst upprouch ls used.
Counting
Another upprouch ls to tuke udvuntuge of the fuct thut, generully, severul contlguous blocks muy be ullocuted or freed
slmultuneously, purtlculurly when spuce ls ullocuted wlth the contlguous-ullocutlon ulgorlthm or through clusterlng. 7hus,
ruther thun keeplng u llst of n free dlsk uddresses, we cun keep the uddress of the flrst free block und the number n of free
contlguous blocks thut follow the flrst block. (uch entry l n the free-spuce llst then conslsts of u dlsk uddress und u count.
Although euch entry requlres more spuce thun would u slmple dlsk uddress, the overull llst wlll be shorter, us long us the
count ls generully greuter thun 1.
3.Write about file sharing in detail
Sol: Generul lssues thut urlse when multlple users shure flles. Once multlple users ure ullowed to shure flles, the
chullenge ls to extend shurlng to multlple flle systems, lncludlng remote flle systems; und we dlscuss thut chullenge us well.
Flnully, we conslder whut to do ubout confllctlng uctlons occurrlng on shured flles. For lnstunce, lf multlple users ure
wrltlng to u flle, should ull the wrltes be ullowed to occur, or should the operutlng system protect the user uctlons from one
unother?
Multiple Users: 7o lmplement shurlng und protectlon, the system must mulntuln more flle und dlrectory
uttrlbutes thun ure needed on u slngle-user system. Although muny upprouches huve been tuken to thls
requlrement hlstorlcully, most systems huve evolved to use the concepts of flle (or dlrectory) owner (or user) und
group. 7he owner ls the user who cun chunge uttrlbutes und grunt uccess und who hus the most control over the
flle. 7he group uttrlbute deflnes u subset of users who cun shure uccess to the flle. For exumple, the owner of u
flle on u UNIX system cun lssue ull operutlons on u flle, whlle members of the flle's group cun execute one subset
of those operutlons, und ull other users cun execute unother subset of operutlons. (xuctly whlch operutlons cun
be executed by group members und other users ls deflnuble by the flle's owner. More detulls on permlsslon
uttrlbutes ure lncluded ln the next sectlon.
7he owner und group IDs of u glven flle (or dlrectory) ure stored wlth the other flle uttrlbutes. When u user
requests un operutlon on u flle, the user ID cun be compured wlth the owner uttrlbute to determlne lf the
requestlng user ls the owner of the flle. Llkewlse, the group IDs cun be compured. 7he result lndlcutes whlch
permlsslons ure uppllcuble. 7he system then upplles those permlsslons to the requested operutlon und ullows or
denles lt.
Muny systems huve multlple locul flle systems, lncludlng volumes of u slngle dlsk or multlple volumes on
multlple uttuched dlsks. In these cuses, the FD checklng und permlsslon mutchlng ure strulghtforwurd, once the
flle systems ure mounted.

Remote File Systems: Wlth the udvent of networks communlcutlon umong remote computers becume posslble.
Networklng ullows the shurlng of resources spreud ucross u cumpus or even uround the world. One obvlous
resource to shure ls dutu ln the form of flles.
7hrough the evolutlon of network und flle technology, remote flle-shurlng methods huve chunged. 7he flrst
lmplemented, method lnvolves munuully trunsferrlng flles between muchlnes vlu progrums llke ftp. 7he second
mu|or method uses u dlstrlbuted flle system (DFS) ln whlch remote dlrectorles ure vlslble from u locul muchlne. In
some wuys, the thlrd method, the World Wlde Web, ls u reverslon to the flrst. A browser ls needed to guln uccess
to the remote flles, und sepurute operutlons (essentlully u wrupper for ftp) ure used to trunsfer flles.
ftp ls used for both unonymous und uuthentlcuted uccess. Anonymous uccess ullows u user to trunsfer flles
wlthout huvlng un uccount on the remote system. 7he World Wlde Web uses unonymous flle exchunge ulmost
excluslvely. DFS lnvolves u much tlghter lntegrutlon between the muchlne thut ls uccesslng the remote flles und
the muchlne provldlng the flles.
7he Cllent-Server Model: Remote flle systems ullow u computer to mount one or more flle systems from one or
more remote muchlnes. In thls cuse, the muchlne contulnlng the flles ls the server, und the muchlne seeklng
uccess to the flles ls the cllent. 7he cllent-server relutlonshlp ls common wlth networked muchlnes. Generully, the
server declures thut u resource ls uvulluble to cllents und speclfles exuctly whlch resource (ln thls cuse, whlch
flles) und exuctly whlch cllents. A server cun serve multlple cllents, und u cllent cun use multlple servers,
dependlng on the lmplementutlon detulls of u glven cllent-server fuclllty.
7he server usuully speclfles the uvulluble flles on u volume or dlrectory level. Cllent ldentlflcutlon ls more
dlfflcult. A cllent cun be speclfled by u network nume or other ldentlfler, such us un. I3 uddress, but these cun be
spoofed, or lmltuted. As u result of spooflng, un unuuthorlzed cllent could be ullowed uccess to the server. More
secure solutlons lnclude secure uuthentlcutlon of the cllent vlu encrypted keys. Unfortunutely, wlth securlty come
muny chullenges, lncludlng ensurlng computlblllty of the cllent und server (they must use the sume encryptlon
ulgorlthms) und securlty of key exchunges (lntercepted keys could uguln ullow unuuthorlzed uccess). Becuuse of
the dlfflculty of solvlng these problems, unsecure uuthentlcutlon methods ure most commonly used.
ln the cuse of UNIX und lts network flle system (NFS), uuthentlcutlon tukes pluce vlu the cllent networklng
lnformutlon, by defuult. In thls scheme, the user's IDs on the cllent und server must mutch. If they do not, the
server wlll be unuble to determlne uccess rlghts to flles Once the remote flle system ls mounted, flle operutlon
requests ure sent on behulf of the user ucross the network to the server vlu the DFS protocol. 7yplcully, u flle-open
request ls sent ulong wlth the ID of the requestlng user. 7he server then upplles the stundurd uccess checks to
determlne lf the user hus credentluls to uccess the flle ln the mode requested. 7he request ls elther ullowed or
denled. If lt ls ullowed, u flle hundle ls returned to the cllent uppllcutlon, und the uppllcutlon then cun perform
reud, wrlte, und other operutlons on the flle
Dlstrlbuted Informutlon Systems: 7o muke cllent-server systems eusler to munuge, dlstrlbuted lnformutlon systems,
ulso known us dlstrlbuted numlng servlces, provlde unlfled uccess to the lnformutlon needed for remote computlng. 7he
domuln nume system (DNS) provldes host-nume-to-network-uddress trunslutlons for the entlre Internet (lncludlng the World
Wlde Web). Before DNS becume wldespreud, flles contulnlng the sume lnformutlon were sent vlu e-mull or ftp between ull
networked hosts. Other dlstrlbuted lnformutlon systems provlde user nume/pussword/user ID/group ID spuce for u dlstrlbuted
fuclllty. UNIX systems huve employed u wlde vurlety of dlstrlbuted-lnformutlon methods. Sun Mlcrosystems lntroduced
yellow puges (slnce renumed network lnformutlon servlce, or NIS), und most of the lndustry udopted lts use. It centrullzes
storuge of user numes, host numes, prlnter lnformutlon, und the llke. Unfortunutely, lt uses unsecure uuthentlcutlon
methods, lncludlng sendlng user pusswords unencrypted (ln cleur text) und ldentlfylng hosts by IF uddress. Sun's NIS+ ls u
much more secure replucement for NIS but ls ulso much more compllcuted und hus not been wldely udopted.
In the cuse of Mlcrosofts common lnternet flle system (CIFS), network lnformutlon ls used ln con|unctlon wlth user
uuthentlcutlon (user nume und pussword) to creute u network logln thut the server uses to declde whether to ullow or deny
uccess to u requested flle system. For thls uuthentlcutlon to be vulld, the user numes must mutch between the muchlnes (us
wlth
NFS). Mlcrosoft uses two dlstrlbuted numlng structures to provlde u slngle nume spuce for users. 7he older numlng
technology ls domulns. 7he newer technology, uvulluble ln Wlndows X3 und Wlndows 2000, ls uctlve dlrectory. Once
estubllshed, the dlstrlbuted numlng fuclllty ls used by ull cllents und servers to uuthentlcute users.
Consistency Semantics:
Conslstency semuntlcs represent un lmportunt crlterlon for evuluutlng uny flle system thut supports flle shurlng. 7hese
semuntlcs speclfy how multlple users of u system ure to uccess u shured flle slmultuneously. In purtlculur, they speclfy
when modlflcutlons of dutu by one user wlll be observuble by other users. 7hese semuntlcs ure typlcully lmplemented us
code wlth the flle system.
Conslstency semuntlcs ure dlrectly reluted to the process-synchronlzutlon ulgorlthms
UNIX Semuntlcs
7he UNIX flle system uses the followlng conslstency semuntlcs:
Wrltes to un open flle by u user ure vlslble lmmedlutely to other users thut huve thls flle open.
One mode of shurlng ullows users to shure the polnter of current locutlon lnto the flle. 7hus, the udvunclng of the
polnter by one user uffects ull shurlng users. +ere, u flle hus u slngle lmuge thut lnterleuves ull uccesses, regurdless of
thelr orlgln.
In the UNIX semuntlcs, u flle ls ussocluted wlth u slngle physlcul lmuge thut ls uccessed us un excluslve resource.
Contentlon for thls slngle lmuge cuuses deluys ln user processes.
Sesslon Semuntlcs
7he Andrew flle system (AFS)uses the followlng conslstency semuntlcs:
Wrltes to un open flle by u user ure not vlslble lmmedlutely to other users thut huve the sume flle open.
* Once u flle ls closed, the chunges mude to lt ure vlslble only ln sesslons sturtlng luter. Alreudy open
lnstunces of the flle do not reflect these chunges.
Accordlng to these semuntlcs, u flle muy be ussocluted temporurlly wlth severul (posslbly dlfferent) lmuges ut the
sume tlme. Consequently, multlple users ure ullowed to perform both reud und wrlte uccesses concurrently on
thelr lmuges of the flle, wlthout deluy. Almost no construlnts ure enforced on schedullng uccesses.

Immutable-Shared-Files Semantics
A unlque upprouch ls thut of immutable shared files. Once u flle ls declured us shured by lts creutor, lt cunnot be
modlfled. An lmmutuble flle hus two key propertles: Its nume muy not be reused, und lts contents muy not be
ultered. 7hus, the nume of un lmmutuble flle slgnlfles thut the contents of the flle ure flxed. 7he lmplementutlon of
these semuntlcs ln u dlstrlbuted system ls slmple, becuuse the shurlng ls dlsclpllned (reud-only).

4.Explain how a directory concept is implemented in windows, Linux
Sol: Case study
5.Write about file system mounting
Sol: -ust us u flle must be opened before lt ls used, u flle system must be mounted before lt cun be uvulluble to processes
on the system. More speclflcully, the dlrectory structure cun be bullt out of multlple volumes, whlch must be mounted to
muke them uvulluble wlthln the flle-system nume spuce.
7he mount procedure ls strulghtforwurd. 7he operutlng system ls glven the nume of the devlce und the mount polnt
the locutlon wlthln the flle structure where the flle system ls to be uttuched. 7yplcully, u mount polnt ls un empty dlrectory.
For lnstunce, on u UNIX system, u flle system contulnlng u user's home dlrectorles mlght be mounted us /home; then, to
uccess the dlrectory structure wlthln thut flle system, we could precede the dlrectory numes wlth /llome, us ln /Ilome/|une.
Mountlng thut flle system under /users would result ln the puth nume /users/|une, whlch we could use to reuch the sume
dlrectory.
Next, the operutlng system verlfles thut the devlce contulns u vulld flle system. It does so by usklng the devlce drlver to
reud the devlce dlrectory und verlfylng thut the dlrectory hus the expected formut. Flnully, the operutlng system notes ln lts
dlrectory structure thut u flle system ls mounted ut the speclfled mount polnt. 7hls scheme enubles the operutlng system to
truverse lts dlrectory structure, swltchlng umong flle systems us upproprlute
(X: 7o lllustrute flle mountlng, conslder the flle system where the trlungles represent subtrees of dlrectorles
thut ure of lnterest Flgure (u) shows un. exlstlng flle system, whlle Flgure (b) shows un unmounted volume
resldlng on /devlce/dsk. At thls polnt, only the flles on the exlstlng flle system cun be uccessed. Flgure c shows
the effects of mountlng the volume resldlng on /devlce/dsk over /users. If the volume ls unmounted, the flle
system ls restored to the sltuutlon deplcted ln Flgure Systems lmpose semuntlcs to clurlfy functlonullty. For
exumple, u system muy dlsullow u mount over u dlrectory thut contulns flles; or lt muy muke the
mounted flle system uvulluble ut thut dlrectory und obscure the dlrectory's exlstlng flles untll the flle system ls unmounted,
termlnutlng the use of the flle system und ullowlng uccess to the orlglnul flles ln thut dlrectory. As unother exumple, u
system muy ullow
r
the sume flle system to be mounted repeutedly, ut dlfferent mount polnts; or lt muy only ullow one
mount per flle system.


6.What is file? Explain the basic operations performed on a file
Sol: Commonly, flles represent progrums (both source und ob|ect forms) und dutu. Dutu flles muy be numerlc,
ulphubetlc, ulphunumerlc, or blnury. Flles muy be free form, such us text flles, or muy be formutted rlgldly. In generul, u flle
ls u sequence of blts, bytes, llnes, or records, the meunlng of whlch ls deflned by the flle's creutor und user. 7he concept of
u flle Is thus extremely generul.
(a)
(b
Figure 10.12 File system, (u) Existing system, (b) Unmounted volume.
(a)
(b
Figure 10.12 File system, (u) Existing system, (b) Unmounted volume.
/
Flgure c Mount point.
7he lnformutlon ln u flle ls deflned by lts creutor. Muny dlfferent types of lnformutlon muy be stored ln u fllesource
progrums, ob|ect progrums, executuble progrums, numerlc dutu, text, puyroll records, gruphlc lmuges, sound recordlngs,
und so on. A flle hus u certuln deflned structure, whlch depends on lts type. A text flle ls u sequence of churucters
orgunlzed lnto llnes (und posslbly puges). A source flle ls u sequence of subroutlnes und functlons, euch of whlch ls further
orgunlzed us declurutlons followed by executuble stutements. An ob|ect flle ls u sequence of bytes orgunlzed lnto blocks
understunduble by the system's llnker. An executuble flle ls u serles of code sectlons thut the louder cun brlng lnto memory
und execute
File Operations
A flle ls un ubstruct dutu type. 7o deflne u flle properly, we need to conslder the operutlons thut cun be performed on flles.
7he operutlng system cun provlde system culls to creute, wrlte, reud, reposltlon, delete, und truncute flles. Let's exumlne
whut the operutlng system must do to perform euch of these slx buslc flle operutlons. It should then be eusy to see how
other, slmllur operutlons, such us renumlng u flle, cun be lmplemented.

| Creutlng u flle. 7wo steps ure necessury to creute u flle. Flrst, spuce ln the flle system must be found for the flle. We
dlscuss how to ullocute spuce for the flle. Second, un entry for the new flle must be mude ln the dlrectory.
Wrltlng u flle. 7o wrlte u flle, we muke u system cull speclfylng both the nume of the flle und the lnformutlon to be wrltten
to the flle. Glven the nume of the flle, the system seurches the dlrectory to flnd the flle's locutlon. 7he system must keep
u wrlte polnter to the locutlon ln the flle where the next wrlte ls to tuke pluce. 7he wrlte polnter must be upduted
whenever u wrlte occurs.
Reudlng u flle. 7o reud from u flle, we use u system cull thut speclfles the nume of the flle und where (ln memory) the
next block of the flle should be put. Aguln, the dlrectory ls seurched for the ussocluted entry, und the system needs to
keep u reud polnter to the locutlon ln the flle where the next reud ls to tuke pluce. Once the reud hus tuken pluce, the
reud polnter ls upduted. Becuuse u process ls usuully elther reudlng from or wrltlng to u flle, the current operutlon
locutlon cun be kept us u per-process current-flle-posltlon polnter. Both the reud und wrlte operutlons use thls sume
polnter, suvlng spuce und reduclng system complexlty.
Reposltlonlng wlthln u flle. 7he dlrectory ls seurched for the upproprlute entry, und the current-flle-posltlon polnter ls
reposltloned to u glven vulue. Reposltlonlng wlthln u flle need not lnvolve uny uctuul I/O. 7hls flle operutlon ls ulso
known us u flle seek.
Deletlng u flle. 7o delete u flle, we seurch the dlrectory for the numed flle. +uvlng found the ussocluted dlrectory entry,
we releuse ull flle spuce, so thut lt cun be reused by other flles, und eruse the dlrectory entry.
7runcutlng u flle. 7he user muy wunt to eruse the contents of u flle but keep lts uttrlbutes. Ruther thun forclng the user to
delete the flle und then recreute lt, thls functlon ullows ull uttrlbutes to remuln unchungedexcept for flle lengthbut lets
the flle be reset to length zero und lts flle spuce releused.
7hese slx buslc operutlons comprlse the mlnlmul set of requlred flle operutlons. Other common operutlons lnclude
uppendlng new lnformutlon to the end of un exlstlng flle und renumlng un exlstlng flle. 7hese prlmltlve operutlons cun
then be comblned to perform other flle operutlons. For lnstunce, we cun creute u copy of u flle, or copy the flle to
unother I/O devlce, such us u prlnter or u dlspluy, by creutlng u new flle und then reudlng from the old und wrltlng to the
new. We ulso wunt to huve operutlons thut ullow u user to get und set the vurlous uttrlbutes of u flle. For exumple, we
muy wunt to huve operutlons thut ullow
r
u user to determlne the stutus of u flle, such us the flle's length, und to set flle
uttrlbutes, such us the flle's owner.

7.Give an overview of the file system used in Unix
Sol: Case Study
8.Give a detailed description of acyclic graph directories. What are the problems with such a
structure?
Sol: Acyclic-Graph Directories
Conslder two progrummers who ure worklng on u |olnt pro|ect. 7he flles ussocluted wlth thut pro|ect cun be stored ln u
subdlrectory, sepurutlng them from other pro|ects und flles of the two progrummers. But slnce both progrummers ure
equully responslble for the pro|ect, both wunt the subdlrectory to be ln thelr own dlrectorles. 7he common subdlrectory
should be shured. A shured dlrectory or flle wlll exlst ln the flle system ln two (or more) pluces ut once.
A tree structure prohlblts the shurlng of flles or dlrectorles. An acyclic gruph thut ls, u gruph wlth no cyclesullows
dlrectorles to shure subdlrectorles und flles. 7he sume flle or subdlrectory muy be ln two dlfferent dlrectorles. 7he ucycllc
gruph ls u nuturul generullzutlon of the tree-structured dlrectory scheme.
It ls lmportunt to note thut u shured flle (or dlrectory) ls not the sume us two coples of the flle. Wlth two coples, euch
progrummer cun vlew the copy ruther thun the orlglnul, but lf one progrummer chunges the flle, the chunges wlll not uppeur
ln the other's copy. Wlth u shured flle, only one uctuul flle exlsts, so uny chunges mude by one person ure lmmedlutely
vlslble to the other. Shurlng ls purtlculurly lmportunt for subdlrectorles; u new flle creuted by one person wlll uutomutlcully
uppeur ln ull the shured subdlrectorles.
When people ure worklng us u teum, ull the flles they wunt to shure cun be put lnto one dlrectory. 7he UFD of euch
teum member wlll contuln thls dlrectory of shured flles us u subdlrectory. (ven ln the cuse of u slngle user, the user's flle
orgunlzutlon muy requlre thut some flle be pluced ln dlfferent subdlrectorles. For exumple, u progrum wrltten for u
purtlculur pro|ect should be both ln the dlrectory of ull progrums und ln the dlrectory for thut pro|ect.
Shured flles und subdlrectorles cun be lmplemented ln severul wuys. A common wuy, exempllfled by muny of the
UNIX systems, ls to creute u new dlrectory entry culled u llnk. A llnk ls effectlvely u polnter to unother flle or subdlrectory.
For exumple, u llnk muy be lmplemented us un ubsolute or u relutlve puth nume. When u reference to u flle ls mude, we
seurch the dlrectory. If the dlrectory entry ls murked us u llnk, then the nume of the reul flle ls lncluded ln the llnk
lnformutlon. We resolve the llnk by uslng thut puth nume to locute the reul flle. Llnks ure euslly ldentlfled by thelr formut ln
the dlrectory entry (or by thelr huvlng u speclul type on systems thut support types) und ure effectlvely numed lndlrect
polnters. 7he operutlng system lgnores these llnks when truverslng dlrectory trees to preserve the ucycllc structure of the
system.
Another common upprouch to lmplementlng shured flles ls slmply to dupllcute ull lnformutlon ubout them ln both
shurlng dlrectorles. 7hus, both entrles ure ldentlcul und equul. A llnk ls cleurly dlfferent from the orlglnul dlrectory entry;
thus, the two ure not equul. Dupllcute dlrectory entrles, however, muke the orlglnul und the copy lndlstlngulshuble. A mu|or
problem wlth dupllcute dlrectory entrles ls mulntulnlng conslstency when u flle ls modlfled.
An ucycllc-gruph dlrectory structure ls more flexlble thun ls u slmple tree structure, but lt ls ulso more complex.
Severul problems must be consldered curefully. A flle muy now huve multlple ubsolute puth numes. Consequently, dlstlnct
flle numes muy refer to the sume flle. 7hls sltuutlon ls slmllur to the ulluslng problem for progrummlng lunguuges. If we ure
trylng to truverse the entlre flle systemto flnd u flle, to uccumulute stutlstlcs on ull flles, or to copy ull flles to buckup
storugethls problem becomes slgnlflcunt, slnce we do not wunt to truverse shured structures more thun once.
Another problem lnvolves deletlon. When cun the spuce ullocuted to u shured flle be deullocuted und reused? One
posslblllty ls to remove the flle whenever unyone deletes lt, but thls uctlon muy leuve dungllng polnters to the now-
nonexlstent flle. Worse, lf the remulnlng flle polnters contuln uctuul dlsk uddresses, und the spuce ls subsequently reused
for other flles, these dungllng polnters muy polnt lnto the mlddle of other flles.
In u system where shurlng ls lmplemented by symbollc llnks, thls sltuutlon ls somewhut eusler to hundle. 7he deletlon
of u llnk need not uffect the orlglnul flle; only the llnk ls removed. If the flle entry ltself ls deleted, the spuce for the flle ls
deullocuted, leuvlng the llnks dungllng. We cun seurch for these llnks und remove them us well, but unless u llst of the
ussocluted llnks ls kept wlth euch flle, thls seurch cun be expenslve. Alternutlvely, we cun leuve the llnks untll un uttempt ls
mude to use them. At thut tlme, we cun determlne thut the flle of the nume glven by the llnk does not exlst und cun full to
resolve the llnk nume; the uccess ls treuted |ust us wlth uny other lllegul flle nume. (In thls cuse, the system deslgner should
conslder curefully whut to do when u flle ls deleted und unother flle of the sume nume ls creuted, before u symbollc llnk to
the orlglnul flle ls used.) In the cuse of UNIX, symbollc llnks ure left when u flle ls deleted, und lt ls up to the user to reullze
thut the orlglnul flle ls gone or hus been repluced. Mlcrosoft Wlndows (ull fluvors) uses the sume upprouch.
Another upprouch to deletlon ls to preserve the flle untll ull references to lt ure deleted. 7o lmplement thls upprouch,
we must huve some mechunlsm for determlnlng thut the lust reference to the flle hus been deleted. We could keep u llst of
ull references to u flle (dlrectory entrles or symbollc llnks). When u llnk or u copy of the dlrectory entry ls estubllshed, u
new entry ls udded to the flle-reference llst. When u llnk or dlrectory entry ls deleted, we remove lts entry on the llst. 7he
flle ls deleted, when, lts flle-reference llst ls empty.
7he trouble wlth thls upprouch ls the vurluble und potentlully lurge slze of the flle-reference llst. +owever, we reully do
not need to keep the entlre llst we need to keep only u count of the number of references. Addlng u new llnk or dlrectory
entry lncrements the reference count; deletlng u llnk or entry decrements the count. When the count ls 0, the flle cun be
deleted; there ure no remulnlng references to lt. 7he UNIX operutlng system uses thls upprouch.
for nonsymbollc llnks (or hurd llnks), keeplng u reference count ln tlle flle lnformutlon block By effectlvely prohlbltlng
multlple references to dlrectorles, we mulntuln un ucycllc-gruph structure.
7o uvold problems such us the ones |ust dlscussed, some systems do not ullow shured dlrectorles or llnks. For
exumple, ln MS-DOS, the dlrectory structure ls u tree structure ruther thun un ucycllc gruph.


9.Give a note on virtual file system
Sol: 7he prevlous sectlon mukes lt cleur thut modern operutlng systems must concurrently support multlple types of flle
systems. But how does un operutlng system ullow multlple types of flle systems to be lntegruted lnto u dlrectory structure?
And how cun. users seumlessly move between flle-system types us they nuvlgute the flle-system spuce? We now dlscuss
some of these lmplementutlon detulls.
An obvlous but suboptlmul method of lmplementlng multlple types of flle systems ls to wrlte dlrectory und flle routlnes
for euch type. Insteud, however,
most operutlng systems, lncludlng UNIX, use ob|ect-orlented technlques to slmpllfy, orgunlze, und modulurlze the
lmplementutlon. 7he use of these methods ullows very dlsslmllur flle-system types to be lmplemented wlthln the sume
structure, lncludlng network flle systems, such us NFS. Users cun uccess flles thut ure contulned wlthln multlple flle systems
on the locul dlsk or even on flle systems uvulluble ucross the network.
Dutu structures und procedures ure used to lsolute the buslc system-cull functlonullty from the lmplementutlon detulls.
7hus, the flle-system lmplementutlon conslsts of three mu|or luyers. 7he flrst luyer ls the flle-system lnterfuce, bused on the
open(), reudQ, wrlte (), und close () culls und on flle descrlptors.
7he second luyer ls culled the vlrtuul flle system (VFS) luyer; lt serves two lmportunt functlons:

It sepurutes flle-system-generlc operutlons from thelr lmplementutlon by deflnlng u cleun VFS lnterfuce. Severul
lmplementutlons for the VFS lnterfuce muy coexlst on the sume muchlne, ullowlng trunspurent uccess to dlfferent
types of flle systems mounted locully.
7he VFS provldes u mechunlsm for unlquely representlng u flle throughout u network. 7he VFS ls bused on u flle-
representutlon structure, culled u vnode, thut contulns u numerlcul deslgnutor for u network-wlde unlque flle.
7hls network-wlde unlqueness ls requlred for support of network flle systems. 7he kernel mulntulns one vnode
structure for euch uctlve node (flle or dlrectory).
7hus, the VFS dlstlngulshes locul flles from remote ones, und locul flles ure further dlstlngulshed uccordlng to
thelr flle-system types.
7he VFS uctlvutes flle-system-speclflc operutlons to hundle locul requests uccordlng to thelr flle-system types
und even culls the NFS protocol procedures for remote requests. Flle hundles ure constructed from the relevunt
vnodes und ure pussed us urguments to these procedures. 7he luyer lmplementlng the flle-system type or the
remote-flle-svstem protocol ls the thlrd luyer of the urchltecture.
Let's brlefly exumlne the VFS urchltecture ln Llnux. 7he four muln ob|ect types deflned by the Llnux VFS ure:
7he lnode ob|ect, whlch represents un lndlvlduul flle
7he flle ob|ect, whlch represents un open flle
7he superblock ob|ect, whlch represents un entlre flle system
7he dentry ob|ect, whlch represents un lndlvlduul dlrectory entry
For euch of these four ob|ect types, the VFS deflnes u set of operutlons thut must be lmplemented. (very
ob|ect of one of these types contulns u polnter to u functlon tuble. 7he functlon tuble llsts the uddresses of the
uctuul functlons thut lmplement the deflned operutlons for thut purtlculur ob|ect. For exumple, un ubbrevluted A3I
for some of the operutlons for the flle ob|ect lnclude:
lnt open(. . . ) Open u flle.
sslze-; reud(. . . ) Reud from u flle.
sslze_t wrlte ( . . . ) Wrlte to u flle.
lnt mmup(. . . ) Memory-mup u flle.
An lmplementutlon of the flle ob|ect for u speclflc flle type ls requlred to lmplement euch functlon speclfled ln the
deflnltlon of the flle ob|ect. (7he complete deflnltlon of the flle ob|ect ls speclfled ln the struct f lle_operut lons,
whlch ls locuted ln the flle /usr/lnclude/llnux/fs .h.)
7hus, the VFS softwure luyer cun perform un operutlon on one of these ob|ects by culllng the upproprlute
functlon from the ob|ect's functlon tuble, wlthout huvlng to know ln udvunce exuctly whut klnd of ob|ect lt ls
deullng wlth. 7he VFS does not know, or cure, whether un lnode represents u dlsk flle, u dlrectory flle, or u remote
flle. 7he upproprlute functlon for thut flle's reudQ operutlon wlll ulwuys be ut the sume pluce ln lts functlon tuble,
und the VFS softwure luyer wlll cull thut functlon wlthout curlng how the dutu ure uctuully reud.

DIAGRAM:
10.Discuss in detail various schemes for defining the logical structure of a directory
Sol:
Single-Level Directory:
7he slmplest dlrectory structure ls the slngle-level dlrectory. A slngle-level dlrectory hus slgnlflcunt llmltutlons,
however, when the number of flles lncreuses or when the system hus more thun one user. Slnce ull flles ure ln the sume
dlrectory, they must huve unlque numes. If two users cull thelr dutu flle test, then the unlque-nume rule ls vloluted. . For
exumple, ln one progrummlng cluss, 23 students culled the progrum for thelr second usslgnment pwgl; unother 11 culled lt
usslgn!. Although flle numes ure generully selected to reflect the content of the flle, they ure often llmlted ln length,
compllcutlng the tusk of muklng flle numes unlque. 7he MS-DOS operutlng system ullows only 11-ch.uructer flle numes;
UNIX, ln contrust, ullows 255 churucters.
(ven u slngle user on u slngle-level dlrectory muy flnd lt dlfflcult to remember the numes of ull the flles us the number of
flles lncreuses. It ls not uncommon for u user to huve hundreds of flles on one computer system und un equul number of
uddltlonul flles on unother system. Keeplng truck of so muny flles ls u duuntlng tusk
DIAGRAM
Two-Level Directory:
slngle-level dlrectory often leuds to confuslon of flle numes umong dlfferent users. 7he stundurd solutlon ls to
creute u sepurute dlrectory for euch user.
In the two-level dlrectory structure, euch user hus hls own user flle dlrectory (UFD). 7he UFDs huve slmllur
structures, but euch llsts only the flles of u slngle user. When u user |ob sturts or u user logs ln, the system's
muster flle dlrectory (MFD) ls seurched. 7he MFD ls lndexed by user nume or uccount number, und euch entry
polnts to the UFD for thut user When u user refers to u purtlculur flle, only hls own UFD ls seurched. 7hus,
dlfferent users muy huve flles wlth the sume nume, us long us ull the flle numes wlthln euch UFD ure unlque. 7o
creute u flle for u user, the operutlng system seurches only thut user's UFD to uscertuln whether unother flle of
thut nume exlsts. 7o delete u flle, the operutlng system conflnes lts seurch to the locul UFD; thus, lt cunnot
uccldentully delete unother user's flle thut hus the sume nume. Although the two-level dlrectory structure solves
the nume-colllslon problem, lt stlll hus dlsudvuntuges. 7hls structure effectlvely lsolutes one user from unother.
Isolutlon ls un udvuntuge when the users ure completely lndependent but ls u dlsudvuntuge when the users wunt
to cooperute on some tusk und to uccess one unother's flles. Some systems slmply do not ullow locul user flles to
be uccessed by other users.
If uccess ls to be permltted, one user must huve the ublllty to nume u flle ln unother user's dlrectory. 7o nume u purtlculur
flle unlquely ln u two-level dlrectory, we must glve both the user nume und the flle nume. A two-level dlrectory cun be
thought of us u tree, or un lnverted tree, of helght 2. 7he root of the tree ls the MFD. Its dlrect descendunts ure the UFDs.
7he descendunts of the UFDs ure the flles themselves. 7he flles ure the leuves of the tree. Speclfylng u user nume und u
flle nume deflnes u puth ln the tree from the root (the MFD) to u leuf (the speclfled flle). 7hus, u user nume und u flle nume
deflne u puth nume. (very flle ln the system hus u puth nume. 7o nume u flle unlquely, a user must know the puth nume of
the flle deslred.
For exumple, lf user A wlshes to uccess her own test flle numed test, she cun slmply refer to test. 7o uccess the flle
numed test of user B (wlth dlrectory-entry nume userb), however, she mlght huve to refer to fllserb/test. (very system hus
lts own syntux for numlng flles ln dlrectorles other thun the user's own.
Addltlonul syntux ls needed to speclfy the volume of u flle. For lnstunce, ln MS-DOS u volume ls speclfled by u letter
followed by u colon. 7hus, u flle speclflcutlon mlght be C:\userb\test. Some systems go even further und sepurute the
volume, dlrectory nume, und flle nume purts of the speclflcutlon. For lnstunce, ln VMS, the flle logm.com mlght be
speclfled us: u:[sst.|deck]logln.com;l, where u ls the nume of the volume, sst ls the nume of the dlrectory, |deck ls the nume
of the subdlrectory, und 1 ls the verslon number. Other systems slmply treut the volume nume us purt of the dlrectory
nume. 7he flrst nume glven ls thut of the volume, und the rest ls the dlrectory und flle. For lnstunce, /lt/pbg/test mlght
speclfy volume u, dlrectory pbg, und flle test
DIAGRAM
Tree-Structured Directories:
A tree ls the most common dlrectory structure. 7he tree hus u root dlrectory, und. every flle ln the system hus u unlque puth
nume A dlrectory (or subdlrectory) contulns u set of flles or subdlrectorles. A dlrectory ls slmply unother flle, but lt ls
treuted ln u speclul wuy. All dlrectorles huve the sume lnternul formut. One blt ln euch dlrectory entry deflnes the entry us u
flle (0) or us u subdlrectory (1). Speclul system culls ure used to creute und delete dlrectorles.
In normul use, euch process hus u current dlrectory. 7he current dlrectory should contuln most of the flles thut ure of
current lnterest to the process. When reference ls mude to u flle, the current dlrectory ls seurched. If u flle ls needed thut ls
not ln the current dlrectory, then the user usuully must elther speclfy u puth nume or chunge the current dlrectory to be the
dlrectory holdlng thut flle. 7o chunge dlrectorles, u system cull ls provlded thut tukes u dlrectory nume us u purumeter und
uses lt to redeflne the current dlrectory. 7hus, the user cun chunge hls current dlrectory whenever he deslres. From one
chunge dlrectory system cull to the next, ull open system, culls seurch the current dlrectory for the speclfled flle. Note thut
the seurch puth muy or muy not contuln u speclul entry thut stunds for "the current dlrectory."
3uth numes cun be of two types: ubsolute und relutlve. An ubsolute puth nume beglns ut the root und follows u puth
down to the speclfled flle, glvlng the dlrectory numes on the puth. A relutlve puth nume deflnes u puth from the current
dlrectory. For exumple, ln the tree-structured flle system, lf the current dlrectory ls root/spell/rnull, then the relutlve puth
nume prt/flrst refers to the sume flle us does the ubsolute puth nume root/spell/luull/prt/flrst.
An lnterestlng pollcy declslon ln u tree-structured dlrectory concerns how to hundle the deletlon of u dlrectory. If u
dlrectory ls empty, lts entry ln the dlrectory thut contulns lt cun slmply be deleted. +owever, suppose the dlrectory to be
deleted ls not empty but contulns severul flles or subdlrectorles. One of two upprouches cun be tuken. Some systems, such
us MS-DOS, wlll not delete u dlrectory unless lt ls empty. 7hus, to delete u dlrectory, the user must flrst delete ull the flles ln
thut dlrectory. If uny subdlrectorles exlst, thls procedure must be upplled recurslvely to them, so thut they cun be deleted
ulso. 7hls upprouch cun result ln u substuntlul umount of work. An ulternutlve upprouch, such us thut tuken by the UNIX rm
commund, ls to provlde un optlon: When u request ls mude to delete u dlrectory, ull thut dlrectory's flles und subdlrectorles
ure ulso to be deleted. (lther upprouch ls fulrly eusy to lmplement; the cholce ls one of pollcy. 7he lutter pollcy ls more
convenlent, but lt ls ulso more dungerous, becuuse un entlre dlrectory structure cun be removed wlth one commund. If thut
commund ls lssued ln error, u lurge number of flles und dlrectorles wlll need to be restored
DIAGRAM:
General Graph Directory:
A serlous problem wlth uslng un ucycllc-gruph structure ls ensurlng thut there ure no cycles. If we sturt wlth u two-level
dlrectory und ullow users to creute subdlrectorles, u tree-structured dlrectory results. It should be fulrly eusy to see thut
slmply uddlng new flles und subdlrectorles to un exlstlng tree-structured dlrectory preserves the tree-structured nuture.
+owever, when we udd llnks to un exlstlng tree-structured dlrectory, the tree structure ls destroyed, resultlng ln u slmple
gruph structure
7he prlmury udvuntuge of un ucycllc gruph ls the relutlve slmpllclty of the ulgorlthms to truverse the gruph und to
determlne when there ure no more references to u flle. We wunt to uvold truverslng shured sectlons of un ucycllc gruph
twlce, mulnly for performunce reusons. If we huve |ust seurched u mu|or shured subdlrectory for u purtlculur flle wlthout
flndlng lt, we wunt to uvold seurchlng thut subdlrectory uguln; the second seurch would be u wuste of tlme.
If cycles ure ullowed to exlst ln the dlrectory, we llkewlse wunt to uvold seurchlng uny component twlce, for reusons of
correctness us well us performunce. A poorly deslgned ulgorlthm mlght result ln un lnflnlte loop contlnuully seurchlng
through the cycle und never termlnutlng. One solutlon ls to llmlt urbltrurlly the number of dlrectorles thut wlll be uccessed
durlng u seurch.
A slmllur problem exlsts when we ure trylng to determlne when u flle cun be deleted. Wlth ucycllc-gruph dlrectory
structures, u vulue of 0 ln the reference count meuns thut there ure no more references to the flle or dlrectory,
und the flle cun be deleted. +owever, when cycles exlst, the reference count muy not be 0 even when lt ls no longer
posslble to refer to u dlrectory or flle. 7hls unomuly results from the posslblllty of self-referenclng (or u cycle) ln the
dlrectory structure. In thls cuse, we generully need to use u gurbuge-collectlon scheme to determlne when the lust reference
hus been deleted und the dlsk spuce cun be reullocuted. Gurbuge collectlon lnvolves truverslng the entlre flle system,
murklng everythlng thut cun be uccessed. 7hen, u second puss collects everythlng thut ls not murked onto u llst of free
spuce. (A slmllur murklng procedure cun be used to ensure thut u truversul or seurch wlll cover everythlng ln the flle system
once und only once.) Gurbuge collectlon for u dlsk-bused flle system, however, ls extremely tlme consumlng und ls thus
seldom uttempted.
DIAGRAM:
11.Explain in detail various disk allocation methods
Sol: 7he dlrect-uccess nuture of dlsks ullows us flexlblllty ln the lmplementutlon of flles. In ulmost every cuse,
muny flles ure stored on the sume dlsk. 7he muln problem ls how to ullocute spuce to these flles so thut dlsk
spuce ls utlllzed effectlvely und flles cun be uccessed qulckly. 7hree mu|or methods of ullocutlng dlsk spuce ure ln
wlde use: contlguous, llnked, und lndexed. (uch method hus udvuntuges und dlsudvuntuges. Some systems (such
us Dutu Generul's RDOS for lts Novu llne of computers) support ull three. More commonly, u system uses one
method for ull flles wlthln u flle system type.

Contiguous Allocation
Contlguous ullocutlon requlres thut euch flle occupy u set of contlguous blocks on the dlsk. Dlsk uddresses deflne
u llneur orderlng on the dlsk. Wlth thls orderlng, ussumlng thut only one |ob ls uccesslng the dlsk, uccesslng block
b + 1 ufter block b normully requlres no heud movement. When heud movement ls needed (from the lust sector of
one cyllnder to the flrst sector of the next cyllnder), the heud need only move from one truck to the next. 7hus, the
number of dlsk seeks requlred for uccesslng contlguously ullocuted flles ls mlnlmul, us ls seek tlme when u seek
ls flnully needed. 7he IBM VM/CMS operutlng system uses contlguous ullocutlon becuuse lt provldes such good
performunce.
Contlguous ullocutlon of u flle ls deflned by the dlsk uddress und length of the flrst block. If the flle ls n
blocks long und sturts ut locutlon b, then lt occuples blocks b, b + 1, b + 2, b + n 1. 7he dlrectory entry for euch
flle lndlcutes the uddress of the sturtlng block und the length of the ureu ullocuted for thls flle
Accesslng u flle thut hus been ullocuted contlguously ls eusy. For sequentlul uccess, the flle system
remembers the dlsk uddress of the lust block referenced und, when necessury, reuds the next block. For dlrect
uccess to block / of u flle thut sturts ut block b, we cun lmmedlutely uccess block b + /. 7hus, both sequentlul und
dlrect uccess cun be supported by contlguous ullocutlon.
Contlguous ullocutlon hus some problems, however. One dlfflculty ls flndlng spuce for u new flle. 7he system
chosen to munuge free spuce determlnes how thls tusk ls uccompllshed; . Any munugement system cun be used,
but some ure slower thun others.
7he contlguous-ullocutlon problem cun be seen us u purtlculur uppllcutlon of the generul dynumlc storuge-
ullocutlon problem whlch lnvolves how to sutlsfy u request of slze n from u llst of free holes. Flrst flt und best flt
ure the most common strutegles used to select u free hole from the set of uvulluble holes. Slmulutlons huve
shown thut both flrst flt und best flt ure more efflclent thun worst flt ln terms of both tlme und storuge utlllzutlon.
Nelther flrst flt nor best flt ls cleurly best ln terms of storuge utlllzutlon, but flrst flt ls generully fuster.
All these ulgorlthms suffer from the problem of externul frugmentutlon. As flles ure ullocuted und deleted, the
free dlsk spuce ls broken lnto llttle pleces. (xternul frugmentutlon exlsts whenever free spuce ls broken lnto
chunks. It becomes u problem when the lurgest contlguous chunk ls lnsufflclent for u request; storuge ls
frugmented lnto u number of holes, no one of whlch ls lurge enough to store the dutu. Dependlng on the totul
umount of dlsk storuge und the uveruge flle slze, externul frugmentutlon muy be u mlnor or u mu|or problem.
Another problem wlth contlguous ullocutlon ls determlnlng how much spuce ls needed for u flle. When the
flle ls creuted, the totul umount of spuce lt wlll need must be found und ullocuted. +ow does the creutor (progrum
or person) know the slze of the flle to be creuted? In some cuses, thls determlnutlon muy be fulrly slmple (copylng
un exlstlng flle, for exumple); ln generul, however, the slze of un output flle muy be dlfflcult to estlmute.
I f we ullocute too llttle spuce to u flle, we muy flnd thut the flle cunnot be extended. (speclully wlth u best-flt
ullocutlon strutegy, the spuce on both sldes of the flle muy be ln use. +ence, we cunnot muke the flle lurger ln
pluce.
7wo posslbllltles then exlst. Flrst, the user progrum cun be termlnuted^ wlth un upproprlute error messuge. 7he user must
then ullocute more spuce und run the progrum uguln. 7hese repeuted runs muy be costly 7he other posslblllty ls to flnd u
lurger hole, copy the contents of the flle to the new spuce, und releuse the prevlous spuce. 7hls serles of uctlons cun be
repeuted us long us spuce exlsts, ulthough lt cun be tlme consumlng. +owever, the user need never be lnformed expllcltly
ubout whut ls huppenlng; the system contlnues desplte the problem, ulthough more und more slowly.
(ven lf the totul umount of spuce needed for u flle ls known ln udvunce, preullocutlon muy be lnefflclent. A flle thut
wlll grow slowly over u long perlod (months or yeurs) must be ullocuted enough spuce for lts flnul slze, even though much
of thut spuce wlll be unused for u long tlme. 7he flle therefore hus u lurge umount of lnternul frugmentutlon.
Linked Allocation:
Llnked ullocutlon solves ull problems of contlguous ullocutlon. Wlth llnked ullocutlon, euch flle ls u llnked llst of dlsk
blocks; the dlsk blocks muy be scuttered unywhere on the dlsk. 7he dlrectory contulns u polnter to the flrst und lust blocks
of the flle. 7o creute u new flle, we slmply creute u new entry ln the dlrectory. Wlth llnked ullocutlon, euch dlrectory entry
hus u polnter to the flrst dlsk block of the flle. 7hls polnter ls lnltlullzed to nll (the end-of-llst polnter vulue) to slgnlfy un
empty flle. 7he slze fleld ls ulso set to 0. A wrlte to the flle cuuses the free-spuce munugement system to flnd u free block,
und thls new block ls wrltten to und ls llnked to the end of the flle. 7o reud u flle, we slmply reud blocks by followlng the
polnters from block to block. 7here ls no externul frugmentutlon wlth llnked ullocutlon, und uny free block on the free-spuce
llst cun be used to sutlsfy u request. 7he slze of u flle need not be declured when thut flle ls creuted. A flle cun contlnue to
grow us long us free blocks ure uvulluble. Consequently, lt ls never necessury to compuct dlsk spuce.
Llnked ullocutlon does huve dlsudvuntuges, however. 7he mu|or problem ls thut lt cun be used effectlvely only for
sequentlul-uccess flles. 7o flnd the z'th block of u flle, we must sturt ut the beglnnlng of thut flle und follow the polnters untll
we get to the /th block. (uch uccess to u polnter requlres u dlsk reud, und some requlre u dlsk seek. Consequently, lt ls
lnefflclent to support u dlrect-uccess cupublllty for llnked-ullocutlon flles.
Another dlsudvuntuge ls the spuce requlred for the polnters. If u polnter requlres 4 bytes out of u 512-byte block, then
0.78 percent of the dlsk ls belng used for polnters, ruther thun for lnformutlon. (uch flle requlres sllghtly more spuce thun lt
would otherwlse.
7he usuul solutlon to thls problem ls to collect blocks lnto multlples, culled clusters, und to ullocute clusters ruther thun
blocks. For lnstunce, the flle system muy deflne u cluster us four blocks und operute on the dlsk only ln cluster unlts.
3olnters then use u much smuller percentuge of the flle's dlsk spuce. 7hls method ullows the loglcul-to-physlcul block
mupplng to remuln slmple but lmproves dlsk throughput (becuuse fewer dlsk-heud seeks ure requlred) und decreuses the
spuce needed for block ullocutlon und free-llst munugement. 7he cost of thls upprouch ls un lncreuse ln lnternul
frugmentutlon, becuuse more spuce ls wusted when u cluster ls purtlully full thun when u block ls purtlully full. Clusters cun
be used to lmprove the dlsk-uccess tlme for muny other ulgorlthms us well, so they ure used ln most flle systems
Yet unother problem of llnked ullocutlon ls rellublllty
An lmportunt vurlutlon on llnked ullocutlon ls the use of u flle-ullocutlon tuble (FA7). 7hls slmple but efflclent method of
dlsk-spuce ullocutlon ls used by the MS-DOS und OS/2 operutlng systems. A sectlon of dlsk ut the beglnnlng of euch volume
ls set uslde to contuln the tuble. 7he tuble hus one entry for euch dlsk block und ls lndexed by block number. 7he FA7 ls
used ln much the sume wuy us u llnked llst. 7he dlrectory entry contulns the block number of the flrst block of the flle. 7he
tuble entry lndexed by thut block number contulns the block number of the next block ln the flle. 7hls chuln contlnues untll
the lust block, whlch hus u speclul end-of-flle vulue us the tuble entry. Unused blocks ure lndlcuted by u 0 tuble vulue.
Allocutlng u new block to u flle ls u slmple mutter of flndlng the flrst 0-vulued tuble entry und repluclng the prevlous end-of-
flle vulue wlth the uddress of the new block. 7he 0 ls then repluced wlth the end-of-flle vulue.
Indexed Allocation:
. Llnked ullocutlon solves the externul-frugmentutlon und slze-declurutlon problems of contlguous ullocutlon.
+owever, ln the ubsence of u FA7, llnked ullocutlon cunnot support efflclent dlrect uccess, slnce the polnters to the blocks
ure scuttered wlth the blocks themselves ull over the dlsk und must be retrleved ln order. Indexed ullocutlon solves thls
problem by brlnglng ull the polnters together lnto one locutlon: the lndex block When the flle ls creuted, ull polnters ln the
lndex block ure set to nll. When the /'th block ls flrst wrltten, u block ls obtulned from the free-spuce munuger, und lts
uddress ls put ln the /'th lndex-block entry.
Indexed ullocutlon supports dlrect uccess, wlthout sufferlng from externul frugmentutlon, becuuse uny free block on
the dlsk cun sutlsfy u request for more spuce. Indexed ullocutlon does suffer from wusted spuce, however. 7he polnter-
overheud of the lndex block ls generully greuter thun the polnter overheud of llnked ullocutlon. Conslder u common cuse ln
whlch we huve u flle of only one or two blocks. Wlth llnked ullocutlon, we lose the spuce of only one polnter per block.
Wlth lndexed ullocutlon, un entlre lndex block must be ullocuted, even lf only one or two polnters wlll be non-m7.
7hls polnt rulses the questlon of how lurge the lndex block should be. (very flle must huve un lndex block, so we wunt
the lndex block to be us smull us posslble. If the lndex block ls too smull, however, lt wlll not be uble to hold enough
polnters for u lurge flle, und u mechunlsm wlll huve to be uvulluble to deul wlth thls lssue. Mechunlsms for thls purpose
lnclude the followlng:

Llnked scheme. An lndex block ls normully one dlsk block. 7hus, lt cun be reud und wrltten dlrectly by ltself. 7o ullow
for lurge flles, we cun llnk together severul lndex blocks. For exumple, un lndex block mlght contuln u smull heuder
glvlng the nume of the flle und u set of the flrst 100 dlsk-block uddresses. 7he next uddress (the lust word ln the lndex
block) ls nll (for u smull flle) or ls u polnter to unother lndex block (for u lurge flle). '
Multllevel lndex. A vurlunt of the llnked representutlon ls to use u flrst-level lndex block to polnt to u set of second-level
lndex blocks, whlch ln turn polnt to the flle blocks. 7o uccess u block, the operutlng system uses the flrst-level lndex to
flnd u second-level lndex block und then uses thut block to flnd the deslred dutu block. 7hls upprouch could be
contlnued to u thlrd or fourth level, dependlng on the deslred muxlmum flle slze. Wlth 4,096-byte blocks, we could store
1,024 4-byte polnters ln un lndex block. 7wo levels of lndexes ullow 1,048,576 dutu blocks und u flle slze of up to 4 GB.
Comblned scheme. Another ulternutlve, used ln the U7S, ls to keep the flrst, suy, 15 polnters of the lndex block ln the
flle's lnode. 7he flrst 12 of these polnters polnt to dlrect blocks; thut ls, they contuln uddresses of blocks thut contuln
dutu of the flle. 7hus, the dutu for smull flles (of no more thun 12 blocks) do not need u sepurute lndex block. If the
block slze ls 4 KB, then up to 48 KB of dutu cun be uccessed dlrectly. 7he next three polnters polnt to lndlrect blocks.
7he flrst polnts to u slngle lndlrect block, whlch ls un lndex block contulnlng not dutu but the uddresses of blocks thut do
contuln dutu. 7he second polnts to u double lndlrect block, whlch contulns the uddress of u block thut contulns the
uddresses of blocks thut contuln polnters to the uctuul dutu blocks. 7he lust polnter contulns the uddress of u trlple
lndlrect block. Under thls method, the number of blocks thut cun be ullocuted to u flle exceeds the umount of spuce
uddressuble by the 4-byte flle polnters used by muny operutlng systems. A 32-blt flle polnter reuches only 2
32
bytes, or
4 GB. Muny UNIX lmplementutlons, lncludlng Solurls und IBM's AIX, now support up to 64-blt flle polnters. 3olnters of
thls slze ullow flles und flle systems to be terubytes ln slze. A UNIX lnode ls showm ln Flgure 11.9.

Indexed-ullocutlon schemes suffer from some of the sume performunce problems us does llnked ullocutlon.
Speclflcully, the lndex blocks cun be cuched ln memory, but the dutu blocks muy be spreud ull over u volume.

You might also like