0% found this document useful (0 votes)
6 views

5.File Management

The document provides an overview of file management, emphasizing the importance of files for long-term data storage and access across multiple processes. It discusses file structures, naming conventions, and types of files, highlighting the differences between operating systems. Additionally, it outlines the necessity for files to retain information beyond process termination and the various ways files can be organized.

Uploaded by

JYOTI MAURYA
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

5.File Management

The document provides an overview of file management, emphasizing the importance of files for long-term data storage and access across multiple processes. It discusses file structures, naming conventions, and types of files, highlighting the differences between operating systems. Additionally, it outlines the necessity for files to retain information beyond process termination and the various ways files can be organized.

Uploaded by

JYOTI MAURYA
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 21

::i:Module -

5 :K File Management

J,~:'i'l~~·Mj•iH~,,L_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ __ _
Overview, File Organization and Access, File Directories, File Sharing

5.1 Overview

5.1.1 Files and File Systems

:J Every application needs to access and store the information. During execution, process can keeps th e information
in its address space.

:J This address space to store information is sufficient for some type of applications but not for others, which
requires huge size of information.

:J After finishing the execution, process terminates and information also vanishes.

::i For many applications, it is required that information should be retained forever.

:::i Even though computer crashes or process is killed, still information should remain retained. Most of the time, th e
information is sharable among many processes.

:J If information kept in the address space of one process, other processes will not be able to access it.

o It is necessary to keep information independent of the processes.

::i Following are the necessities for long term information storage.

0 It must be possible to store a very large amount of information.

0 The information should not loss after termination of the process using it.
0 Several processes must be able to access the information simultaneously.
0 In order to fulfill the above requirements, it is necessary to store 1·nformat·10n on d'1s ks an d ot h er secon d ary storage
in units called files.

0 A file is a named collection of related information that is r d d t be


ecor e on secondary storage. The data canno
written directly to secondary storage unless they are within fil1 p . . f the
a e. rocesses can then read mformat10n rom
file.

0 It also can write new information into the file if n d d Aft . h uld
. . ee e · er process termination, information in file 5 0
remam retamed and should not vanish. A file should on) . ating
Y vamsh when its holder clearly removes it. Oper
system manages the files.

0 File system describes how files are structured d


' name 'accessed, used, protected and implemented.
~:.=--~~-=-~-~------------==-
,.,,ting Syr;t.em (MUJ S- L
ii ope,,, -
~ Files
. f I 1t:.
about files from user's po int <Jf view ' tha t i!.. ' hrJV/
. ., ,,, discus sion arr.; U' td
fO 11 (J y1111 O - . ri.a rr,,.;.d, a n..c ·,.,t, ,, . ;; ~t tT. 1::
t properties they have.
differen
l File Nami ng
5, 2.
aives the name to the file when it create s it.
:J Proc ess 1:r
sti ll e-.1.1st and other proc eSses can _.: cctss
comole
•'-M tion of the execution, even thou.gh proce ss term inates , fi le
:J J-IJL<-• •

th.at file by the same name.

J The rules for file namin g are not same for all system
s. It varies from system to system , but all curren t operat ina 0

systems allow string s of one to eight letters as legal file names.

:J If an operating system distinguishes the type of


a file, it can then opera te on the fi le in logica l ways.

J Digits and special charac ters are also allowe


d to use wh il e givmg the file names . UNLX operat ing system
MS-DO S does not.
differentiates betwe en upper and lower case letters , where as
suppo rt the MS-DOS file system and thus inheri t its
J Windows 95, Windows 98, Windo ws NT and Windo ws 2000
properties.
wh ich are se parate d by period charac ter. User and
J File name is divided into two pa rts - nam e and extens ion
operating syste m can recogn ize the type of file from name o nly.
with an option al exten sion of 1 to 3 charac ters.
J MS-DOS allows the file names contai ning l to 8 ch aracte rs along
size of extens ion. In UNIX, file can have two or more
J On the co ntrary, in UNIX user has a choice of deci ding the
extensions.
meani ng, and type.
J The Table 5.2. l shows the some examp les of file extens ion, its
Table 5.2.1

Mean ing Type


Extension

html
glf Comp uServ e Graph ical Interc hange Forma t image

World Wide Web Hyper text Marku p Language


Image

We b page
___ ___ ___ ___ ___ __
I
:..:.e=-:n:.:..t::____ _ _ _ _ _ _ __ _ _ _ _ _ _
r - -- - +d:..o:.:c=-::u:..:.m 1
r _ _ _ _ _ _ _ _ _ _ _ _ ___!I
_ _ _ _~ O_b_j_ec_
r o_b..:_i':...:o:___ _~ c:::o:m~p~li.:::.e:d_.:.:ma:=.:c:..:.h:..:.in:..:.e_la_n..::.gu:__a=.ge_n_o_t_li _nke_d_ _
= te=-m_a_c_h_in_e_Ia_n_gua __m_ _ _ _r E_x_e_cu_ta_b_l_e_ _ _ _ _ _ _ _ _ _ _ _
__g_e_p_r_ogra
_JI
t- ex_.e..:_, n:, :co:m
b•:.::·
-=- : _~ R:e::a:.:d'!..y.....:to=....:e:x~e:.::cu
Text
txt, doc I Text, docum ent, data
. _:_r~o:u~ti,:.:n.:e:.s..:fo ra m_m
ro...::g::..___
._=._:r_ 'p.....- _ er_s_ _ _ _ _ _ L:--i_ _ _ _ _ _ _ _ _ _ _ _ _ _ _J
b~ra_ry
,_::_lib b~ra~n..'.·=es~o~f
:_::,_:a'.,'._d~l'.'l.__ _l_'.L~i~ 1
Group ed flies togeth e r so me ti me compr essed for Arch ive

--- -----.-----r-=-===~- --- --- --- -_J


I arc, zip, tar
r - __ _ _ ~ a~r~c~h~iv~i~n~g~o~r_:s'.:'.to~r~a~g~e'.:... d / ·d Multim edia
1
Binary files co ntaini ng audio or au io v1 eo
-
mp3,.av i,
- - - - t: : = ~ ~ ===::=~----
.~m~p!g_ _ __J_~i~n~fo~r~m~a~t~io~n~- - - - - - -- - - -- Portable docum ent forma t and 0
f ' P stscn pt 1
Pdf, ps Its conte nt cann ot be chang ed --.. :_
.
V OporotinR Syswin (MU) 5.3 File Manaoe"'
~ .. ,ent

5.2.2 File Structure

Th e Pi~!• 5.2.l shows the three ways in which files can be structured.

Three ways of file structure

, Unstructured sequence of bytes

2. Sequence of fixed-tength records

3. Tree Structure

Fig. 5.2.l : Three ways of file structure

1. Unstructured sequence of bytes

0 "" C fi lc as scquenc~ of bytes. Any mc:ming must· be


In this stru cturing, operating system rrcats content of 1Jl
Imposed by user-level programs.
□ Both UNIX and Wind ows use th is approach. Th is stnJcturl ng provtdcs more flexi bility.
o Any types of content ca n be kept in the file Jnd ,h JH'f <011w n1t·nc1: of the user. 11.Jmr can bl' givc u to thl' Ille.

2. Sequence offlxed-length records

o In this approach Ille Is treated as sc-quenn· or ll~l'd k 11i,h t't'<()nh

o Each record has its internal structu re. r\n~• 1'\'.Jd opcr.1uon on Ole n-tums one record and write operation will
append or overwrite one record.

o When pu11chcd cards wcrr in usr. re-rord sttl' ins of 80 charaners and oi 132 characte rs proposed for line
printers.

o Many operating systems based th eir fi le systems on files rons tsnng or SO-character records when punched cards
were in use.

a Progra ms read input from file in the unit orso characters and wrote in units of 132 chara cters keeping remai ning
52 characters blank.

3. Tree structure

D In this organization, a file consists of the records which are organ ized in rree strucrure.
D All the records not necessarily have same length. Each record has a key field in a fixed position.
0 The records in the tree are arranoed in the sorted O rd f k fi I · -
key. b er o ey e d, to perm it quick searching for a particular

:J The main aim in this type of or0 anization is to search record · ul


b · on partic ar key.
O The next record also can be searched. Operating system d ·ct . ,
eci es wnere to add new record.
0 User is not concern about this operation. This type f fil · b
0 . ·
still used in some commercial data . e LS roadly used on the large mainframe computers and
processmg.
Cl Following Figs. 5.2.2 (a), (b) and (c) shows above three ki d f fil .
O
studentfilearranged insortedorderofrolln umb n s es. Fig. 5.2.2 (c) shows the tree of records 01
ers.
ii_ operating System (MU) 5-4
~
1 Byte

(a) Byte Sequence (b) Re<:ord s.quenc-e

us 11 n,o 11 9

(<) y,._
r""V SU
Disadvantage of supporting multiple file struct\J,.,

a If 11111ltlplc Ille st ruct 111'1'.S .m.· ,uppt1r11'd by 1i1r ol)t'rlttnii ))">tc-m thc-tt 11 ,, \MJ.ld I>\· hugt- 1n s11.-e.

O For supporting th r rl1lkrt•111 file , trurture~ 11, .. ro N\")J)t)lldlng rode ~,()Uld 1ho prt-ll'ot 111 opera ting ,ystcm.
U Atld lt, on:illy, 11 ls rcq111r1'<1 ll1 d1•lin1• t'l'cry fil r 1, oper111ng system ,uppon~ ror one of die Ille cy 1, e.

a If 01wr.111 11i; system docs not support dw srru('(uf'f' ol mtonnauon nt-<:Ot'd b)' apphntton t11en 11 ca n lead to severe
pro bkms.

o Opi'l'.ttln~ systcms like UNIX. MS-DOS enlol"C't' and suppon file strunures wturh are leasl tn numbers .

O UNIX tre:1ts L'.trh i11e :i~ :i scqurn("(' 01 8-bll bytes and operaong s;-st.em does not carry out die understanding of
thr,c bits.
a As a rt'sul t of this appro:irh. m1x1mum flexib1hry but hrde suppon IS offered.

0 In order to interprN an mpu t file to the suitable stn1crure. applicaaon should have tnd uded its own c.ode.

0 On the other hand. all opera ting systems must suppor1 m1mmum one StruCTUre of an executable file.
. support the svstem
a Dlit' to th 1s , will be capable of loadmg aod runrung the programs.

S.2.3 File Types


. ._
Several operating s~ ~terns sup pore many types of files. The Fig. 5.2.3 shows the different types of files ·

" llpt'I ,11111µ ~\"1 1' 111 l ~HIJ ', ',

llr,u11l11r hf11·, _J
;, IJlf P.<.i<,llt1• _J
:J ~ 11c.11J r t.(1',<,11JI f,1t,,. J
4 BlrJ(.I\ \, (>'JC.IF/ I trw _J
Fig. S.2.J : FIie typet

l. Regular flies
rd s1-nu1-nce ,3nd tT~ ~tr, <;t..t.r~ ~/..;,✓• - ~ ~-,,,, .
Regular files contain user information, The byte sequ ence, reco .,.., ~ - -

a~ the examples of regular files.

2. Dlrectories

These are system files for maintaining the structure of the file syst.em-

3. Character sped al fiJ es

Character sped.al fil es are related to input/output and used to model serial f/0 d.e-lices ._.. r\ ~ ~--:-,: -~ :
pn nters, and networks.

4. Block special files

These are used to model disks.

:J All regular files are normally either ASCII files or binary files.

:J ASCII fil es contain li nes of text Each line is terminated by either carriage rerum character o~ •;.,"' :::ec -"-:c-~
MS-DOS uses both types of fi les. Lines can be of different length.

:J The great benefit of ASCII files is that they can be displayed and printed as they are.

:J Any text editor can edit ASCII file. Furthermore, if large numbers of programs use ASO I files for tnp~: ,;,-✓ .:--:-_:
it is easy to connea the output of one program to the input of another, as in shell pipelines. Bi.nzr:,· :._-=$ 2"= :..::
ASCII files.

:J Listing them on the printer gives listing which is beyond the und ersr.anding, le gives the ranrlo~ ga_~? .:
.i~U:d on the printer. Usually, they have some internal scrucrure known co programs that use chem..

-:J l,! '., fX bina ry file Is an arch ive. It rnnsists of a collection of library procedures compiled bm oo: ....::'.~ :-~~
. . ~dulnts~ of flit types can be understood from the T0PS-20 operating system.

:J Ti~t rccompil.acion of sou re<:: file will be carried ouc automatically after its modificaaon.

:; l r.,!; reu.1mp1laoon i5. d<;nt 1( U!tr wan ts to execute rhe object file. It guarantees that th e U5rr all ~c u:::e r-"l>.?..:

JP·", •datJ: vh/t:ct fl it. ft savts the waste of ti me in execun ng the old object fil e.

J Tu i:s~h it ve: ct11~ auwm;ic1c re:wmprlaaon of modified source file, the operaung system musr h_;n•e me e3pa'::: - ~·- ::
malrx a drstincw,n bt:cwte:n !><,urc.e file and ohj ect file.

Y• ,.r~I 'I
5-6 11,·1c Mana/lp (ll:n t
) .
. system (Mu
operating
time and time at whlc:h Ole was lautly modlfi c•d• 1" order v, c:11,1ri •,,:
Id be able to check file creation . .
of the rw urcc rmw,.,r·,,m.
150 OS shoU iler OS must also have a ability to determine the language
CJ A
the right comp ,
utable binary file.
. demonstrates the UNIX version of exec
2
Cl f ,g. 5. .
4 nno t r·x,-c uu·- th'•
a prop er format operating system ca · ·• 1 , 11
, ':.
. file is 1·ust a sequence of bytes, without bol t;J hl c.
!thou gh t I11s cation bi ts, and sym
head er, text, data, relo
Cl A . d' •ded into five segments. These are
The file is 1v1 utable fll c.
It recognizes the type of fil e as an exec
. fi . t field in header is magic number.
Cl Thevery 11 s fo rma t
.. to prevent the unintentional
execution of a fil e which is not in this
J It facilitates e various sect ion size-;, tht
ber the size s of the different sect ions of the file are shown . After thes
. num , .
After mag ic some flag bits are pres ent
J t whic h exec utio n star ts, and
address a memory and relocate d
er are the text and data of the program itself. These are load ed into
. the head
J follo wmg e is used for .debugging.
. the relocation bits. The symbol tabl
using
Magic Number
Text Size
Data Size Header
BSS Size
Symbol Table Size
Entry Point

Flags
Text
Data
Relocation Bits
Sym bol Table

Fig. 5.2.4 : An executable file

5.2.4 File Attributes


a name and its data. All operating
string of the characters. Every file has
File is identified by its name which is tion and the size of
r informa tion with each file, for example, the date and time of file crea
systems associate othe
the file.
attributes are not same
rma tion associated by oper ating syst em is called as attributes. The lists of
D Such extra info
ating system to another.
for all the systems and vary from one oper
in some system.
all of these attributes, but each one is present
□ No singl e existing system supp orts

5·2-4(A) Attributes and its Meaning

Meaning
Attributes
g, and so on.
who can do reading, writing, executin
Protection Access-control information determines
Size The current size of the file
support different types of files.
Type Information is needed for systems that
·~
v Operating System (MU)

Attributes

Creato r ID of the person who created the file


.-;J - 7

Meaning
o;;

--
l'l lc M;,11;1v,,:rr,,.nt

Owner

Password
Current owner of the file

Password needed to access the file


--
Identifier

Hidden flag
This unique number whi ch identifi es the fil e within the file system.

O for normal; 1 for do not display in listings


-- J

Read-only flag 0 for read/write; 1 for read only


l
ASCII/ binary flag 0 for ASCII file; 1 for binary file
I
Lock flags 0 for unlocked; nonzero for locked
Key length Number of bytes in the key field

Time of last access Date and time the file was last accessed
Time of last change Date and time the file has last changed

Maximum size Number of bytes the file may grow to


System flag 0 for nonnal files; 1 for system file

5.2.5 File Operations

□ Files are used to store informatio n which can be used later on. For storage and retrieval purpose,
different types
of systems offer different operations .

::J For the operations like create, write, read, reposition, operating system offer the system calls. The
majority of
common system calls relating to files are listed in Fig. 5.2.5.
Common system calls
relating to files

1. Create

2. Delete

3. Open

4 . Close

5. Read

6. Write

?. Append

8. Seek

9. Get attribu tes

10. Sel attributes

11 . Rename

Fig. 5.2.5 : Common system calls relating to files

~ •:::;- Tech Knowledq•


, .,,
. t,·ng svs tem (MU)
" opera ,
~ te
crea u 1·11t,•d 111,, 111 111 ,, 1,y ,, INn
j. fil l' -~111 w1• ,,,,. 111111
da ta. IL Is 11 eed 1•cl to lul'11 l r
r hr new fil e is crea trd without
J No rrw 111 '' "' allr 11111 1,:,, ,,,.,
,,JtJ 111 b,! ,, ,.1
ntio n of tll C' rail is tu drd a re th :11 ll1 l' Ille 1.~ rrt• 111 c d 11 11d
r tir inte
)

oelett>
when IL Is r1C1 lu11 ger req uir ed,
' th e dis k spa ce t1 ccu pl cd hy Ille
File nr-ed tn be deleted to 1-cleas<

open quick ac:ce';sc !; in futu re, all


is req uire d to ope n the nl c fi rst by any process. To have
i:;et,'lre ma king use of file , it
ma in me mory.
.1. attributes and
dis k add resses are bought in to
~ ·1I ('

~ c1ose dis k add resses in memory are


ple tes, all accesses get s finished. The fetched attributes and
_ ~:ter use of the file com
ase the internal table space.
:1 -1 longer requ ired, so
th e file sho uld be closed to rele
ting of the file's last block.
blocks and is wri tten in blocks. Closing a file compel wri
- 7he disk space is divi ded in

: , . Read
specifies the name of the file.
:i Thes~rstem call that is used for reading a file
in read pointe r at the
from the cur ren t position. The system should mainta
J ~en eraJly, the bytes are fetched
t read is to begin.
aC:cress in the file from where nex
fer to put them in.
st sta te the am oun t of dat a desired and must also offer a buf
J :he call er mu

6. Wri te
and info rmation to be written to the file.
J System caU to write the
data in to file specify file name
the file. In
exi sting file size will increase if writing starts from end of
J in at the current position. The
Writing is aga
:!11s case, the current positio
n is at the end of file.
data will be
ew her e in the middle of the file , the previously existed
J Cin rhe contrary, if writing
is done at som
nently.
'JVerwritten and van ished perma

i. Append
number
of the fil e. Systems offering less
of app end sys tem call ; dat a gets append ed only to the end
Wi th the help
provide app end.
of system calls do not generally

a. Seek
lar loca tion in th e fil e.
The seek sys tem call is use d to place the poin ter at a particu
J
has comple ted, da ta
les to spe cify from wh ere to obta in the data. After this call
:J ft is nee ded for random
access fi
tten to, tha t pos itio n.
can be read from, or wri
9
· Get attributes

ir des ignated wo rk Get attributes sys tem call IS
d fi le attr ibutes to com ple te the
Proc esses frequently need to rea
Used for this purpose.

• T1chk110111l1dte
I o II!.
p I.I U I l C ,J t
File Managernent
-4,;;
5-9
V• Operating System (MU )
'bl
10. Set attr ibu tes ••111 tem call mak es that pos s, e.
. f fil e afte r Its crea tio n. I s sys
es 0
Use r can cha nge the som e attr ibut
.
11. Rename , . . II makes that pos sibl e
existing hie. 1 his syst em ca
Use r needs to change th e nam e of an

______ _ _ _ _ _ _ _ _ _ _ __
~S~.3~ ~Fi~le:_O~rg~a~n~iz~a~t~io~n~ an~d~A~c~ce!:s~s'.___ _

5.3.1 File Access MU - June 15, 10 Marks

Ia. Explain different file access methods.


Different access met hod s
for files

1. Sequential access

2. Random or Direct access

3. Other access methods

s for files
Fig. S.3.1 : Different access met hod

1. Sequential acc ess acces;J


ems pro vide d only this kind of file
sim ples t acce ss met hod is sequ ential access. Early ope rati ng syst
::J The
at the
one reco rd afte r othe r, star ti~i .
type of file access, proc ess read s all the reco rds in a file in ord er
:i In this
begin ni ng]
pos sibl e.
rd or read ing them out of ord er is not
:J While accessing, skipping of any reco
a cert ain exte nt than disks.
for stor age medium such as mag neti c tape to
:J This access method was convenient
ical ly file poin ter is moved
nex t port ion of the file is carr ied out by read ope rati on and auto mat
:J The reading of the
forw ard.
te ope rati on and file pointer
of new info rma tion to the end of the file is carr ied out by wri
:J The appending
ten portion.
advances to the end of the newly writ

2. Ran dom or Direct acc ess


a file out of ord er. It is
for stor ing files, it beca me pos sibl e to read the byte s or reco rds of
:J When use of disk star ted
to any file bloc k
because; disks allow random access
h b d be
poss ible to acce ss reco rds by its key inst ead of by pos,·t,·on • F'l1 es w ose ytes or reco r s can
It also became · base
.
read in any orde r are called random
acc ess files Th ey are requ ired
· by man y app lica tion s suc h as data
systems.
.
□ If railway custo mer calls
up and wants to rese rve a s eat on a part icul ar train , the rese rvat ion pro gram mus t be
directly inst ead 0 f d' er trai ns first.
able to access the record for that train rea mg hun dred s of reco rds of oth
mus t be d. .
D For the ra ndom access method, the file ope rati ons ber as a parameter.
mo tfied to incl ude the bloc k num

-~ Techlu tolllled ft
V l11 i! l dHi
Pu1J
p
5-10
ii l)p,
.,.-1till'' ~\-s~m [ MUJ
I - <- . File Management

rJ 1_.n1. . han ? rea d n and ,-rrite n. where n is the relative block number. Actual a bso 1ute disk
1, W t'
.
address of the block
is difft>1"t.'nt

Th<' Ot'gi nning of the relativ e block numb er is from addre


ss o.
J
__h , 11 next block numb er is 1 and so on altJ10ugh the
absolute disk addre ss of the first 'block is 14045 and second
J t t -
t,ll>rk is 3191.
to take the decision about locatfon of placing the file
J Th e rt'i:1tin :' block numb ers permi ts the opera ting system
_;nd f.icilita te the user to stop from accessing file system
portions which are other than his file portion.
ion, seek,
J [wry read operntion gives the position in the
file to start reading at. In the second one, a special operat
:~pnwicie<l to set th e curren t position.
urrent position.
J Artt'r :1 seek, the file can be read sequentially from the now-c

access metho ds
3_ other
ess method.
J These' access methods can be built on top of a random-acc

Thes e methods generally involve the construction of an


index for the file.
J

J Th e index has pointers to the variou s blocks .

Th e reco rd in the file is search ed by searching the index


first and then uses the pointe r to access the file directly
J
_;:1d ro r1nd th e desired record .
Th ese are
J St'n'ral factors are impor tant in choice of file organizatio n.
~linimu m access time
Ease of update
:- Eco nomy of storage
Sim ple main tenance
Reliabili ty

7 r, File Organizations
Five fundamental
organizations of file

I 1. The pile

2 The sequentia l hie

3. The indexed sequential file

! 4. The indexed tile

5. The direct, or hashed , fil e

Fig. 5.3.2 : Five fundamental organizations of file

1. Pile
file
::i It is sim plest form of file organ ization. ln chis file
data is stored in the order of arrival. Each record in this
con1 prises one bu rst of data.
• • TecUnowltdtt
V P1..D l lt J l lon,
e...,_. Operating System (MU) 5- 1 I l'llf' Manriv,cnie,i,

u The idoo behind the pile is simply to coll ect th e moss of datn 0 11d save It.

::J Rerords rn nt~ ln difTere11t or sa me type of llcld!- 111 div erse ord ers. 1-:lu..: h Oeld lndw.Jcs a ncld name In adtll t·lon to a
,·alue.
:i The delimiters impli ritJ~, ~how~ ncld lc11ijth, c•r It Is cxplldtly lnducJcd as a suhn eld, o r recognized a 11 tl cfault frJr
that fiel d ty-p e.

:::i A pile file do es not have any stru cture, so exhaustive searc h Is used to access a ny record.

::J To search record with p.~rti cul ar field ,1 11d value, the sea rch Ins pec ts eac h record In the pllc until t he dc •:! rrd
record is located or the complete file has been searched.

:::i Th e complete file must be searched to locate all records of particular fi eld a nd value.

2. Sequential File

::J It is most commonly used structure and records have a fixed format.

::J Each and every record in the file has same length, with equal number of fixed-length fi elds in a partic ul ar ord er.

:i As the length and location of each field are known, simply the values of fields are required to be stored. Th e fi el d
nam e and each field length are attributes of the file structure.

=i The first field in each record is considered as key field and it is used to identify the record.

:::i As a resul t, the val ues of key in each record are always different. The records are stored in the logical order of
key.

:::i For batch applications these files are more suitable. This file can be organized with no trouble on tape as well as
disk.

:J The sequential file physically can be organized as a linked list. Each physical block contains one or more records.

:::i .::acb block on disk holds a pointer to the next block.

:J If new record is inserted, a pointer needs to be manipulated only and new records would not occupy a particular
ph ysical block position.

3. Th e indexed sequential file

- The in dexed sequential file eliminate drawback of sequential file. Similar to sequential file, records a re orga nized
logica l order of a key field .

..J Th<: nd.e>:ed seq uential file contains index to the file to support random access, and an overflow fil e. The index
rJffers a searchi ng abili ty to reach speedily the required record.

" II owmg
Th<= overflow file is used in orde r that a record in the overflow file is searclled by 10 ,
. a pomter f
rom
,·ts
ancestor record.

In a $Ingle level of ind exing, the ind ex is a sim pl e seq uential fil e I th · ct f' l . •
. . . · n c m ex I e, eac h reco rd co ntains two fi elds.
A key fiel d 1dent1cal to th e key fie ld m the main file, and a pointe r into the main file.

To s earch a pa rti cular fi eld, the index Is searched to locate the larges t k .
. , . . . ey va 1ue th a t 1s equal to or precedes th e
key valu e to be sea rched. l he search carries on 111 th e main file at th e lo .. t' ct .
ca ion e noted by the pomter.
The ind exed sequ entia l file really decreases the time needed to acces 5 _ .
. c1 smgle record, without giving up th e
sequential nat ure of the file .

• T1d1Mno111l1dgi
• 1iv1JII Lfl \ lllU ',
:,- 12 1% i Manaw1ment
·;iting System (M U)
f, aper
e nl c, thr
, . IJ
reco rds uf the main. Ill e arc vl ll ll·cd set jUtn t1a Y untl l ;J p!Jlnter to
. 5eq uentially process ing of com plet •
For · _ . • •
ncccss tn g goes on 111 lhc ovprfl ow
fil e 1111111 a 11 ull Jmln lur 1·',, r,.,am c ,acrr r,·i :J I •Nhlch
:I ,crn ow Ill e 1s loca trd, then '
tlH' o, m ed whe re II left oil
. rcessi ng of the mni n fil e is resu
onic a
The lnde~ed File
filt . Apa rt
4-
inde xed sequ enti al fil e co n sea rch the reco rd buse d on a sing le field ,Jt the:
Th? srqurntial fi le and the rd.
J . ti, iPo key fie ld, they ca nnot sea
rch reco rd usin g other attribu te of reco
!nllll · 't' onr: for tadi
ty and acco mpl ish th e flex ibility, a stru ctur e con ta inin g mul tiple lndexe'l,
T,' ,-r:·come this difl kul
0
J
r.-pe l1f field is req uire d.
ugh their indexes.
J inde xed file, reco rds are accessed only thro
111
in as a mi nimum one index refers
placing of records providing a pointer
J As 3 resu lt, there is now no limit on the
records can be used.
r,1 that record. In add ition , vari able-length
y for each reco rd in the main
used. An exhaustive index holds one entr
J ln ti'1is structure, tvvo kinds of indexes are
r..e.
-1

organized as a sequential file.


J ;:, order to search easily, the index itself is
A parti al inde x holds entries to records
where the field of concern exists.
J
record to the mai n
of variable-length, som e reco rds will not have all fields. After addition of a new
J .!..s records are
;lie, all of the index files must be updated.

5. The Direct or Hashed File


k of a known address. There is
type of file mak es use of the ability found on disks to access straight any bloc
J T:iis
:lO idea of sequential ordering
like sequential or indexed sequential file.
function.
J _L_ hashing operation
is performed on the key value using hash
use of fixed length records,
t fil es are frequent ly used whe re very fast access is necessary, where there is
J J!rec
and wher e records are always accessed
one by one.

5.4 File Directories


5.4.1 Directory Structures
store huge number of files on
J
ries keep track of files. Directories are itself files in many system. Systems
Directo
these data, we need to organize them.
large capacity disk. In order to manage all
ies.
This organization involves th e use of director
J
a directo,y.
J hods for defining the logical structure of
The Fig. 5.4.1 shows the mos t common met
Common methods for defining
the logic al structure of a directory

(A ) Sing le-Level Direc tory Systems

(8) Two- level Direc tory Sysl ems

(CJ Hierarchical Direc tory Systems

Fig. 5.4.1

~J TechK110111l1dge
· p ll b I IC ii l j o 11 ':.
V Operating System (MU) 5-13 File Managernent
5.4.l(A) Single-Level Directory Systems

D Single-level directory is the simplest directory structure. In this directory st ructure, one directory
contains all
the files.
□ This single directory is also called as a root directory. Since on early personal computers, only one
user was
working, this system was more general.
· 5.4.2 shows .
F1g. . · • g f'1ve filI es, owned by three different users P Q, and R
0 smgle-level directory system contamm • .
User P has two files, User Q has two files and R has one file in the directory.

Fig. 5.4.2 : Single-level directory system

Advantages

o It is simple to implement.
□ Locating files become faster as there is only one place to look.
Limitations

□ If single user has huge number of files kept in single directory, it becomes difficult to remembe
r the name of each
file.
o If more than one user keeps the files in a single directory, then different users may give
the same names to their
files, violating the rule of uniqueness of names.

5.4.l(B) Two-Level Directory Systems

□ Two-level Directory System overcomes the limitations of Single-level directory. In this directory
system, a private
directory is given to each user. When a user refers to a particular file, only his own directory is searched.

□ As different users directories are different, the same name given to the files do not interfere
each other. There is
no problem in giving the same name to the files in different directories.

□ Single user directory have a compulsion of having all files unique name. While creating the
file for particular
user, the operating system makes confirmation about whether another file of that name exists in
the same user's
directory or not. To know this existence of file or not, the OS searches the directory of the user for
which file is to
be created. To delete a file, the operating system has to search only local user directory .
+-- Root directory

+-- User directories

S +-- User files

Fig. 5.4.3 : Two-level Directory Systems


~
'i 11 ,1" M.111.,v,- m••r,,
(Ill~ 51 ~((' Ill (MU)
, ,rr ,1 ,.. ,., ,
~
'tJ 1 1 11 111111•1 11 st•r ',q //le 11, 111 1I 1 11 JI 'HJ, r,r , ,,:i 1r1,,. f'l ~u r/ ,,A 1 ~>, t.1 •11 •,
li:! svs tc11 1 co11 1wl 1111t11l to11.!> IV drl l' tC' 11 -
·
,rr,tlll . 11rl 11 ~ 111 ,..,
I od ' Pl IIM ' r II n•c 111 r I t'I-I rr
J
l! , drrrlforv sys em
l s w ft, I o,r par.1 rI 'I I
1 • , , ,., ,, 1111, 1 q1,,,r ,.,J ,j ( l11fJ1r,1,r, /tf ,
[\ l t'h ' I I
put cr or 011 1
, sh 11p l t• 11t•lwork 11 / fJ t'r!l111 111 I , urr 1 111
f •-igo mult ius er r-0 111 ced un • lo; rtr•,·d,•d
11,,' l l l ( . ork . In th is sys tem su 111 c· so rt of lul(l 11 JH'u
• , rr ,1 h1c al
art\ 1 ne tw
~ er to kn()w wh li ~ I I~·'J(Pt , l/, f j If)
s whlclr user It Is In ord
q ., t
11

., nlc , the sy.! , tl' lll k11 ow


u1:rr att rm pL<i to op rn
\\ '-,~ .l
re-;,d, thi;,-,.
' ;, ., co mp lie rs, utlllty ruu tl ncs, librar ies. Load er
rs, ass emble rs,
, f' ,; "C cr~ tc m
programs such as loacic opera tin g sys tem .
111ma 11 ds arc give n to the

tes wh en the righ t co
- .... , (' \'<.'
.. C' ""u
cu
fil e In ord er to load an
d exe cute. In case
th e nam e of a
erp re ters as
-·c ,c ;(lm mands are
treated by comma nd int r dir ectory.
file na me wo uld be sea rched in the current use
:i, ,' cn•I director
y systems, this
resolved .
y then problem can be
,, 5~c ..i files are ke
pt in each user dir ec tor s. If specia l user
h us er dir ect ory co nta ins the copied system file
ry as eac
- . ~ ~,1:uo on lea
ds to wastage of memo .
_
e problem can be solved
· con ta ini ng all sys tem files is defined the abov
:: -e:~ o~

~"ls,tages
every user has sep arate directory.
• ~- re ilame collisi on problem as
m each other.
- 13 ~e:>e.id
ent user gets isolated fro

umiration s the
es not all ow access ing
rking on com mo n tas k, then some system do
tive, that is, wo
- :: ::-.c users are co-opera
o'.:Jff :.:ser's files. a
er's directory. To name
st ha ve the ab ility to name a file in another us
J .: so::-,f system, if
permitted, one user mu d the file name.
directory , we mu st giv e both the user name an
pa"Jcllar file uni quely in
a two-level
l computer, it is not
nu mb er of file s. Ev en on a single-user persona
J i! s ,wr satisfacto
ry for users with a large
cor. vtr..: ent

S.4.l(C) Hierarchical Dire


ctory Systems
dent for example,
up the ir files tog eth er in logical ways. A stu
to gro
:i It 15 quite general and
advantageous for users
ts of her curriculum.
lection offile s rel ated to differ t subjec
en
IIlighthave a col ated to seconci
on e sub jec t, a sec on d collection of files rel
to
F,rQ collection can be th
e group of files related flexible way.
wa y is req uir ed to gro up these files together in
e
rJbJtct and so on . Here, som structur e.
of file s. A tre e is the most common dir ectory
up
Alrf:e of directories is the
sol ution to sto re such gro eth er in
as are ne ed ed so tha t fil es can be group eci tog
J li, this a
h, each use r can have
as ma ny dir ectori es
pproac
t>:ptcttd ways. .
.
.
pa th na me . Th e ap proac h rs shown in
.
:i Tht tree h a root dir ectory, and every fi le 111 the
sys tem has a uniqu e
ers Q and S have
F' as
R, an d S which belongs to differ ent use rs. Us
544 ns dir ectory P, Q,
r}· · - . Root dir ectory contai
tated the subdirectories.

•\r T1ehKnowl111ti
P uo l , l .J ! t011
•,
V
• Operating System (MU) 5-15 File Management

s _ user subdirectory

"'User subdirectory
-userfrle

Fig. 5.4.4 : Hierarchical Directory Systems



As user can create random number of subd1rectones, · · ofiers a commanding structuring
it . . tool for users to

organize their work. This is the reason, nearly all modern file systems are organized m this approach.

Advantage

□ ··
· addition
With a hierarchical directory system, m · fil1 es, users can access the files of other users by
to t h e1r
specifying its pathname.

5.4.2 Path Names

□ When file system is organized as tree of directories, a file is accessed by specifying the path name. Path names
can be of two types. These are :

Types of path names

1. Absolute Path name

2. Relative Path name

Fig. 5.4.5 : Types of path names

1. Absolute path name

It consists of the path from the root directory to the file. The meaning of the path /usr/myfolder/myfile is that,
the root directory contains a subdirectory user, which in turn contains a subdirectory my/older, which contains
the file myjile.

2. Relative path name

It consists of the path from the current working directory to the file. A user can assign one directory as the
current working directory, in which case all path names not beginning at the root directory are taken relative to
the working directory. If the current working directory is /usr/myfolder, then the file whose absolute path
usr/myfolder/myfile can be referenced simply as myjile.

0 In UNIX operating system the elements of the path are separated by/. In Windows the separator is \. The same
path/usr/myfolder/myfile in UNIX, is specified in Windows as \usr\myfolder\myfile.

t' g System (MU) 5-16 File Management
if opera in
working, program always needs a
~ f the first character of path is separato r then path is absolute path. If during
CJ particular file, it should use absolute path to access
that file from any current working directory .

Directory Operations
5,4. 3
from system to system with
To manage the directories, different system calls demonstrate more dissimilarity
for directories, consider the
to system calls for files. In order to give an idea of working of system calls
respec t
ioJlowing examples from UNIX.
Directory operations

1. Create

2. Delete

3. Opendir

4. Closedir

5. Readdir

6. Renam e

7. Link

8. Unlink

Fig. 5.4.6 : Directory operatjons

are placed there automatically, by


1. Create: Empty directory is created excluding dot and dot-dot (. and .. ), which
the operating system.
2· Delete: If only single dot and double dot (. and .. ) is present in directory then it is treated as empty. single dot
and double dot within directory cannot usually be deleted.

3. Opendir : Directory can be read to list all the files from it Directory
should be opened before reading just
opening and reading the file.
4 table space.
· Closedir : After reading completes, a directory should be closed to free up inner
5 one entry in a standar d format
· Readdir: It returns the next entry in an open directory. readdir always returns
irrespective of possible directory structures is being used.
6 y.
' Rename: Directories can be renamed just like files. Rename renames the director
7
· Link: Due to linking, a file appears in more than one directory.
the existing file to the name
Link system call specify an existing file and its path name, and creates a link from
ies.
specified by the path. In this fashion, the same file may come into view in several director
one directory then it is deleted
a. Unlink: Unlink removes the directory entry. If the file being unlinked only exist in
fro111 r·11 e system.
File Mana11oenieht
ri -:t 7 ¾
V Operatin g System (MIi)

5.4.4 Directory Implementation


·I , tO'ICCCSS the fil e.
. . IJse r prnv l<los pu t 1 11orn o ' ,·
ned he lore II rl'nd
D Eve ry 111c mus t lw ope
I ti · n 0 to find the directory ent ry.
pa 'rw r
ul the opcrn tln j;( sy,11tc111 uses t ,e 1-11 1111
0
D \·v 1en <1 Ille is 01w 1wd, to fi nd the
un l'l1od,'l, the tllr·octory ontry
con ta lnHthe Info rma tion nee ded
□ t1llo rntl
d In Ille 111l'
Aswe hnv c discusse
dl!-k blucks of th r f1lp,
tho entire fil e.
nnul Ion muy be tho disk uddress of
In ro ntlg 11011 s .lllora th111 , this lnfo
D xed
k number of a fil e and In inde
t allocation, dire ctor y w nta lns the stu rtln g and end ing bloc ctory
O ln link ed lis
s, the maln fun ctio n of the dire
on, dire ctor y con tain s star ting block number of u fil e. In all scheme
allocati
e of the fil e unto the In fo rma tion
nee ded to find th e data.
syst em is to map the ASC II nam
e already disc usse d.
D Every fi le also has its ::ittr
ibu tes. Diffe rent fll e attribu tes wo hav

□ Directory entry stor es


these attribut es of a fil e.
inin g a fil e name of fixed
dire ctor y con sist s of a list of fixed-size entries, on e per fil e, conta
::J In th e simple des ign, a e max imu m) denoting where
e of th e file attr ibut es, and one or more disk add ress es(u p to som
length, a stru ctur
1 shows this design.
the disk blocks are. The Table. 5.4. the
containing fixed-size entries with
Table 5.4. l : A simple directory
the directory entry
disk addresses and attributes in

File Attributes
A attr ibu tes

B attr ibu tes

C attributes

D attr ibu tes


the
the file and i-node num ber All
i-nodes. In this case, directory entries are just name of ·
□ So~ e syst ems us~
attn but es of a file 1s stored in i-node.

□ Fig. 5.4.7 shows this design.

File

A
8
C
D
bute s
Data structure cont ainin g attri

ea h
Fig. 5.4. 7 : A directory In which c entry just refers to an I-node

Abo ve two approac hes are corr


esponds to MS-DO S which have sh f and optional
D ort lie nam es of 1-8 cha ract ers
exte nsio n of 1-3 characters.
e 1-14 cha racters 1 • drng
.
0 In UN IX Ver sion 7, fil e names wer ' oclu any exte nslons.
s-.1IJ Pil e Ma nagement
ting system (MU) .
, , .•
if_ ope ra . gth rtl c names. ro ll owl 11/, arc lrte two app roa c; hcs to
po rt longe r and variab le-len
dern ope rat ing sys tem s up
Ail mo
D . 1e111 ent it.
255 cha rac ter s.
p fil e le ng th of max im um
JJ11P
. ple st solu tio n is to kee e
-r1tes11J1 ters Is rese rved for fi le nam .
J n ca n be use d in wh i ch max lm u111 255 cha rac
ve two des ig ns the
r11c abo u ld be wustc cJ.
.J all fil es s uch lo nge r na mes, d ire cto ry s pace wo
·r i<: not co mm on to hav e
~111 CC I .
t co nsi der ed.
J a ll dir ect o ry e ntri es is no
.. ·piproach, fixed siz e of a
a nd the n fo ll ow ed by dat
)
ill till ~ • t
tio n, wh i ch beg ins wi th length of the en try,
a fixed sec
Jirectot1' ent ry co nta ins wn in Fig. 5.4.8.
l' 1C Il o
ma t whi ch are ge ner a lly fil e a ttr ibu tes. It is s ho
J ' · 3 fi xed for
111tl1 '
1 en try length
FIie
File 1 attributes
n V e
Entry for firs t file i
n t 0 r
y X

~
File 2 entry length
:
File 2 attributes Entry for second file
a b 1, · C . ,/
I X

File 3 entry length i


' >; .
:,·

• '

., Oth er tile entries ·

dling of long names


Fig. 5.4 .8 : In- lin e han
ss
wn in Fig. 5.4 .8 by cro
d abc is sho wn . Te rm ina tio n of eac h file is sho
inv ent ory an
- In mis example two file
,_;·.'Ilbol. . It
tia ted int o the dir ect ory
rem ov ing file, a var iab le- siz ed fre e spa ce is ini
d is tha t, aft er
- -~~raw back of this me tho in thi s fre e spa ce.
t, nex t file to com e, ma y no t be acc om mo dat ed
'.::ay hap pen tha ect ory en try spr ead s in
ory . An oth er pro ble m is tha t a if sin gle dir
pac tio n of dir ect
Solu tion on this iss ue is com
din g of a file.
several pages, pag e fau lt occ urs du rin g rea
e
~ Po inte r to file 1's nam
En try for firs t file
rt File 1 attr ibu tes
Po inte r to file 1's nam
ibu tes ·
e
7
1

En try tor sec ond file


File 2 attr

i
Oth er file ent ries
e
__,. I n V
l..---"
0 _V
n t
X
a..,.. b
y
0 X

i
O the r file nam es

handling using heap


Fig. 5.4 .9 : Long name

• TecltKno11l1d1e
P VII 11 c ,1 t Io II S
FIio Mnnnr,(l'll
r, ' <Jnt
V Operating System (MU)
5-19

The second approach to deal with variable-length names is to allow directory entries of fixed lc ngrlt anct rnalntr1ln
□ 9
the file names jointly in a heap at the end of the directory as shown In Fig. 5.4. .
□ The drawback discussed above is defeated here. When an entry is removed, th e next fil e e nte red wlll always fl t 1
11

freed space. The management of heap will be the burden here and page faults ca nno t be a void ed as In prcvl<Hl!l

method.
□ All the designs discussed, supports searching of directory sequentially from beginning to end for find ing up the
file name. Sequential search would be inefficient if directories are longer.
Solution to this problem is use of hash table in each directory as hash search is efficie nt compa re to sequential

search.

5.5 File Sharing

It is necessary to share a file among multiple of users in multiuser system. It needs to deal with two iss ues : th at
are access rights and the management of simultaneous access.
Issues related to file
sharing

1. Access Rights

2. Simultaneous Access

Fig. 5.5.1 : Issues related to file sharing

5.5.1 Access Rights

□ The file system should offer a flexible facility for permitting widespread fiI es h anng .
· among multiple users.

□ It is also a responsibility
. . of file system to offer a many alternatives in or d er to control the way of file accessing.

In general, . h ts to users or groups f


it important to grant particular access permissions o r ng
□ •
part1cu1ar file. A broad category of access rights has been used. o users to access a

Examples of access rights

1. None access right

2. Knowledge

Fig. 5.5.2 : Example~ o; .. .... . .


access rights
5-2 0 PI I
·ngSystem (MU) c Ma1111ge ni cnl
•~ Operatl '
t, c,111 he ,,ranlc d lo .' 1 IJ·irll . . .
· F·g 5•5.2 shows the some of the examples of access ri ghts thul , ' cu1.ir use r lor a
rhe I •
Cl ocular file.
par h
pul into effect thi ·s •·•<,·c·•·" ,
None aCc
ess right: The user may not still know about presence of the nlc. To ......~s 11rn 1l. l <;
1, . restricted from reading the user directo ry that co nta ins this Ill e.
user ,s
ce of Ill e and own er of IL Th e user ca n
l{nowledge: With knowledge acce~s right, th e user can 11nd out existen
z. 1the owner for added access nghts.
appea
g it is no t allowed.
te ·A loading and execution of progra n1 is possibl e to user bu t copyin
3, E.xecu •
togeth er wi th copyin g and execut ion.
d. Aread access right allows the use to read the fil e for any work,
4, Rea ·
Append :The user can only add data to the file at the end.
5,
and add th e data to th e fil e's data.
Update: The update access right allows the user to modify, delete,
6,
d to other users. Norma lly, this right is
Changing protection : The user can alter the access rights assigne
i,
associated only with the owner of the file.
s
The owner is allowed to extend this right to other users in some system
is allowed to delete the file from the file system as per need.
s. Delete: The user
J Th ese rights assigned to user form a hierarchy, with
each right involving those that precede it.
then that user also gets following rights:
J Thus, if any user is assigned the read right for a particular file,
knowledge, execute.
file. The owner is granted all of the access
J The person responsible to create file is by default the owner of that
rights and may grant rights to others.

J Thedifferent categories of users to which access can be given are :

o Specific user: Individual users having its own user ID


The system keeps track of the membership
0 User groups : A group of users who belonging to particular user group.
of user groups.
:. All : Authenticated users of this system.

5.5.2 Simultaneous Access

J It is necessary to protect the shared file from simultaneous


updating from more than one user.

J Whe n mo re than one user grante d access to append


or update a file, the operating system or file management
system must implement some way to restrict it

J A brute-force scheme permits a user to lock the comple


te file when it is to be updated. It is also possible to lock
inct·iv,·ct ual records during update.

• T1thKnawled1e
p ll IJ I / C ,I t IO 11 ~
88
w,ite shot1 note Fila TW •
Q.1 explain various t110 att1ibutos In brief,
Q.2 explain various filo operations In brief,
Q.3 Write short note FIie Access (sequential accell and random
Q.4 Explain different types of file organization,
Q. 5
E>,:p!ain ptle file organization.
Q. 6
=.o.E.-Z. s...~~ential file organization.
Q.1
=.o•; in ·c-o:-'(_:d file organization.
Q, S

Q.E
=-0 -~n :-as--~-= f:e organization.
=-0 ~ j;:=;-;.:-:!. ~::-:.-ctory structures.
s~._~ n• ..,=--- -
- ·· ~.:. •• e,7e:;tory operations .
-::.>::i~
_
-.
-._ .6 -:-----+.
- c--~=-'
.
'~ •,-::;. i..auon of directory · d .
Q.1 2
= ·"..- r-- --- . m eta1I.
Q. 13 =>::J~ :,~ rs.£;;d to file sharing.
Q.1 ~ .:::.... • ,_..,-;:~ a...~ss rights to the f10.
I

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy