0% found this document useful (0 votes)
18 views25 pages

Part 1 Os

The document discusses various aspects of file management in UNIX systems, including directory structures, file permissions, and system calls for file operations. It covers topics such as creating files, reading and writing data, and managing file permissions for different user types. Additionally, it explains the concept of inodes and how file systems are structured and accessed in UNIX.

Uploaded by

Ajay Khule
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)
18 views25 pages

Part 1 Os

The document discusses various aspects of file management in UNIX systems, including directory structures, file permissions, and system calls for file operations. It covers topics such as creating files, reading and writing data, and managing file permissions for different user types. Additionally, it explains the concept of inodes and how file systems are structured and accessed in UNIX.

Uploaded by

Ajay Khule
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/ 25

Cdeurce

ffles
deu
"_evesy
-Contoos
-UNIXhaspresent vi)fie "letclposSaod
idRnteall4
creatag
ussTag fsmaiotaoed fCleS
6hich-USertipasSWOTduidgidi
aSbe
directo
bome
Bydefault
diecto4
boe
multpleuSersas
qrouphasgoufp a
StUctuYe
data
tee
tdimectory [executoble uniquefd as.
ame
mkdir
System enit
Command
allfofoY
USeYi bieraschical usique
assignedqihasassiqnedoso
d
Secondary io the

directery heiraichical ioodenane


$cd. USeY2 ma+ioo
os
by
directOy ofall
fi id
using Ie andVey
USer
deviceabout
System Cioter
Files.
CPasSw al nane nally)
ords]
-by desoult

parent
thece tuso directeries are cIeoted
pathname specT4ies hosto
partcular ftie fo

hierarchy
locat3on for fiie
patbname specified bytoo Gs
OAbSolute pathname
Spectfying Storting
Juserfavol toial. fova

(3Relatiye pathoame
6tat

StotS Seoch om Cument directory


when curent directory is
- fo Ahese a5e have tokoouthe cunent
dtrectory
tor evey pess oS uses these deitces
as

Stondard Sle evice

kéyboord by defouit
(t7) t andcrd Olpdevice

nonrtor bydefout
Gi)tondasd erordevice
montor by defout
-Shellis-also-assoiot edcaithalheSe
deviCes

ction.
ofedire
we con-chonqe
devices
usingredirectioo
) Redirection f
poog*am.
OLP

Cusiog operator]
exi$ pud>filetxt

Outut

$ cat frletxt
aftesqivingthese Connand
Ro the f l e t x t
one Éleioto othey
OCopy
charch Cioo];
fiie2
fot fi le l, t2,fid, f2d;

if (fie 2 open demQtxt 0_RD9NLY)>0)

while ((fid =reodLfile, ch l ol)0)

fid:write fiie2,chFLdl;

e\se
pintfC fnor occunedto 'open fiue 2")
lose FTLe2)}.
els e
P f f eno 0ccued to open ffte 1");
Ctose( fite):
open canbe usedio tuoways
O to open exising fiie
to rreote andop n newfíle

to Ceote newHle fn UNIX

Syntax:
întcreat pathname, mode)
Ceote
where to storethe petmissian
<reated file

. (Teat(l Ceates
andopens the new ffle
orikng
Lwheneverile fS Ceated in_0S itiS
3 type5 0f
pesmisSion
aliowS to See
the Content of the file
" allowS to oite the (n tent io fiie
)execute
-allowS to
execute the
.this pesmission is for
only executobe files
". for
eveyfi\e there oreà typeS of usexs
Oowner
qouP
others.

owneiS.the usex
whohos cKeated the i
uppe here S 4fie
omed fiie.zt
bere are d
5usersouped Into 2
q2(uuG)
then
ond. u ueoted
files.txt

otheKSu4,US

ench pesmiSSTon ( Ieod, ôite, e xecute ) con be


assiqned to each of the user type
security can be tmpiemeoted by asstgning pesm
isston6 to the file,
E we execute s L we cotll qet Shr ng
choractess
Inthese lo character
First'charocter is file type and
remaiatng nine are. file pesm+S6ions.

qiven then I is used


1f reod pesmis6fon Rs used
wite. permissioNiS 9rven +hen o tS
f used
If eXecute pemission. isgiven then x fs
anyofthe pexmíssîons ts not Tven then
if
undersCore ) isUsed.

thers

the
pemiss.
oconerhas sights tochange
nly
OOSoftheffle
Home as6iqnment
ead every looth çh£ioter
Wiite a Cprogam to
Fie and sh dTsplay
used to
tnternaiy
characters Cre not
Stseam iepnesent
pesmiSsions4uses bit.
Ofor permssionotetee denied

pesmissTen. qaoted
1 for. StseamniS
Suppose pesmission

Converted to ctol representation


ti6
that fs. and it is pefixed byo
6Lo

o5 2
Io|olo

peamiSsions aTe provided into octal format

writtoq data ioto files


-pesitHon of character within tle is called as fie
offGet
cohen coe open file for seod ope ta ion es Cen hooiooi.
P read offset tsmaiataine d by oS
by defoult t Rs Set to o.(beginainq).
Valu of offset is chonqed by default after read
S4stem Sall executed
orite offSet is set to ile si2e u defauit
It also changed bu defauit ohenortte,system
callexecu ted

|Seek funchon c all alloaDS us to readand


ostte thedata randomly
lSeer Lint E,iat offSet, fot
where).
fde open("
Gomple.dot", o.6966sus)
pecty he pasarneter aG
of Gti9 tnteqe
SECKSET
SEEK-CUR
SEEK ENS
to uoe 4he5e
unistd heoder fie io ee ded
SEE K. SET
Foom beqinning (300 i5 added
SEEKCuRE 900 iS added to cuaent
9ffset
SEEK. ENo lo99 fs adAod tD end ofthe
(ile

(an. stort fom canyohere.


+?te a C proqTamto read
character from FRie onddSplay it
f tnclude <std fo: h>
+ fncude< Std|fbh>
#foclude <unistdh
+ocIude<fcot|h

Char fnane Cioo], <h3

pofntf L Ente, file namne:");

hfie ((fd= 0pencfoame, 0-RQNLY))>0)

fCTeodcfd, fch,i)4z 1)1


break ,
paintf("characteat d posiian s.

inode
Koode_Contains the Characteisticsofftie
physícal device can ae ategorized inton.
multípe loqícol devtces
physiral devire

FS
loqical devi ces

We Can attach the anothex fiie Systtm


&le 5ystem is knoan as mountinq
caoTth unmount system call we can detach the
anotheY fiie System..
eve ry fie system has sSpetftc Gtuctue
Do
|boot supe |fst Aottused fo Stoiinq fiue
data.

Lo24 bytes
-biocks o6sigoed ha
store_file data are
Scatte red 9ot Sequen
tial
OSal0oys store the fle to temS af blocks
oSneeds to Ikeep toack on al the blocks
allocated to fle.
(jciatie)

primary
PoM perreenant

stuctre
Tabieof content 1s
present

to stre tne fie chGsoctesttice


.num bes cf

Jarge
{ogdeS aiereusabie
Oumber of incdes and biocks ase dependent on

facde is sequíred for one fite


hiockS ale required oed oothe cize cf file

Super
în
. A fnformation abut fiie systern e present
these biork
.ex : hcw many toodes. has mnany fee inedes
and iSst of free 1ocdes
about data biocKs
stmtiarly
centaiing To fo.
5mall function
- +boot
preseot in t ohichiocater.
a Smoll Toutine.tG
on hosd disk.
the operading sytem
stortedRom functoo. ideotifies
hen System is
boet bioc k aod then routine Ts -itenHfied
the
which lecates0s
" all pzores5es have cnlq

mapping is dene wth the helpaf directoes

then no nee¶ to Io0d 1t


in these case locking neshanisrn ts usod tor
Concument acress to fiies
" 05 poDyides lock on fies Tn an fie s curerts
acessing the ftie

<npde Iype
pezmission

Himtng Snfo types Glosd accSed


bighest offset 53ze lost mdified
ntbe file Aable of
ohere dato 1s contentS msfied.
Stored

hat contofns biock

to ohtch they are Stored

hole ) Do dato.
e mpty area in f Tie ohere no data is present
declaed outGTde
loCal as deleared tnside tuna yeheye

to access l2eq th
then t diuides
we qet 2Gq by blocr charater
4hen al nteqer iuteton value hen
to that. Vele fadex fatable of ontent
and 4hat black (ontotns the dete 12.04 th
char acter
these block contaros lo4 bytes
Me boo to ind tho Se pasition use 126g.
lo24 4hat positian Contatns l2Gqth charocter

ortte a poogram to (reate frle wth hele


Ftoclude<staioh
foiude<unistdh
+nclude<fcoti-h
+ iaclude <Stdib h>
1otmain c)f
foame
char fteame C25]
iotfd
priotf c"Enter fiiename ;");
S Canfc S f n a m e ),

LY)i

lo-wR0NLYJ;
fde0pen (foeme, 0ADoNAr
3itefdhello", sl;
lseek(fd, 50,5EEKSUR);
write fd," orld'5):
aritten to the
-printf ". S0cessfull
poimany memosy in core memory

Q Ioode toble
.It ts present fn primavs memsry
I} rs used to Store tnode looded from
device
wheninode is iooded secunday
alL characteaistics
is loaded
ta jncde loaded from dísk is knoon tocore
disk faode )Se(ondany memoy
iocere fnode rimory mnemory
add1tional prepesties of focere inode
Oiaode numbex
. in tnode \ist 3nodes are stored Sequenialls
Do need of it
ioincore inode are_ \oaded as pe reqiYemeot
So esçentialy needed

refereoce Count
It tells that hoo mans pIOCSSes are
inede
using tha
Too pocesses can access faode at same tne
but cant madify Lupdate it
3) stotUS
for lack¯nq purpose

2FRle toble.
Tt contoíos folloeing properies.
Ormode Lopeiation
Io cohich mode user
Yemembex
opened the filet has to
tode st2e is aloays Powe of2

redoffset
oeeds tomafntoin offset tor Teadíng the
data from next chaIocter.

6 elemeot of Rocore inede table ohich contoins

refeece count

Fiie Desssiptor Table


1: Uses for
Sftst3entsies of UEDT arereserved

Stdip stdop ond stden.


monitor
keyboard
doesaot need Rie s defauLH*
if pxoqram
these 3 leS are opened Lused
qlobal Ds
. fle toble and ode toble are
UFDT fs local DS
files tor Seperate pices
dseper ate
lcal means pecses
common Hle for all
qiobo meons ) Kenel mode onts
aCcessed io
qloba DS are
mode
not o usex
to fle table.
Contatos the pointe
fie table fnode table
stdtp opeiaton
Yead
Stdop o-ffseta0. lref.cowot: 1.
2 Stter
Semple dat
ef(aunt:
operattan:
ote
offsete 6

atoial-do operafon
eod
le ffSet :o

opeiation:
(orite
Offset
taial. dot

4Hiakdat

only one OFDT pe proess.


Capy per process not fot evexy
reference number in inode tabie_is oo_open
of files
table entiies yeferencing that node

tIEopenuSampledat AR DONLY)
f2 open ( tiol dat',oMRONLY)
P2

fdl e open("ial dat oR0NLr)


fd2 open(oialdot owRoNLY)
op:re od fogde tah
ref count:'
Gample
2
4tial
dot
P2UFDT

|Yef count3

teial offset: o
8Sespie
dat

opoite
offSeto

Some time in Some mode but teantoork


sith Scime fíie simultoneouslq
PooreSS
eS entexs in keroel made
to executeSystem call
(ornpletion Ccmes bock Usermoe
4ofteY
CPU schedulinq?
processes equaiy
cpU should be given to all eU Scheduliog
for c
scheduler (0S module) used
Round-Aobin, alqorithms for schedu
. UNIXx uses
quantum).
ing tAR uSes time

Race conditons
is possibilityot
.because of shoríng their.
inceDsistency prepealyllectíng
4.meanGeven if takíng care
0CCULS
theDs inconsístency
Atoriity iether both should beeXe Cuted
no one should be executed

there to avoid
are20ayS
O it pOuides appendfiaa (O.AePEND) KAceCondions
"open tle at append mode ifyou aloays
to cote data ct end of file
thee are 2additiona funcHons poulded bu ns
Opead and pite.
Opreod (omb of xead k lseet)
Syatax preod(fd,St,no_0f_char, offset)
what off Set you coat to
ead the dato
puonite (comb afoite R lseek)
Syntax poriteltd, St,
oofÁchor,offSet)
lhat ffset ou coint
to corite the data
atomicity
opetations
Can be
ensuredfrm the Se fetee

open ( Etxt,0-WRsNLYloCREAT)
IE file exist ît
tonrate the ile ad cae (an
isS all the dato
ale
E-0pen "ÁNtxt oRoNLY)

aqain tbhese sheuld be


opebaions atomic
these there
xcLi these

ope

dup 54siem calL


. dup alloos us to duplicate uFOT
faropen(" f1.4xt,o.RoNr) enties

rd and fdi has different index Vaue

uill Share the Same offset


(etthe Iead or write)

* Vatiotions of usinq dup)


fd2 dup(fd)

JFDT cnty In which First UPoT


entiy o be Copied

dupfdi,lo)
tt 7l CiSe alre ady
uGe 4hen
fie and copies fdI into e
Opened

problenin (opying
dupc)retuins - l f there is
enoY
the fle or there is

Tmportonce ef ustng dup().


redirecion ustng dup
econ Imelement

outpt
&
stondard Input edirection
olP
>
dedirettong chongíng.
edtrecion
g t
Jess + K io Put
int minu int fdl, fa

printf Text prqam";


CieseL1);

2duptfdi;
printfc Text"};

letuxno,

Hoo read. orfe cperatians takes plate


.hord dis is biock devices
tueo types of devices
O biocK devices lex: hord dis)
e chaa cter devices (exs keyboord) dist
RAM (erimay memoy)

sbuffes
buffe hs Same si2e os
thatof block
both iie o1e are io texms of
bLocks
choxactex
posses dotacharacte by chracter
pooblemn. Is that 0S does not
baiddisk tmme tsonsfen bufrer to.
for
HI
Ahese
all
àiately
O5 does not
wite buffe fmmedíately
buffer. pocessupdotes it or
tilltreuse the
Content
1eULed

Suitched 01F 4hen we con lost he dato


updated y protess
fos hese

fsnccfd)
fdato syoc Cfd).

.ey u37nq 4hese t ce reod kaite he data 4


4he fiie Gf specified d it forces Qe tu tsanst
er lcaite the chonqes toà hard dícr biscKs
aiso force fullq Gends the changes ct incde
to the hord disK

fdato Sync (fa)


" I is simiior ta. fdsync ) ois díffes ence is
cnly
i cnig &ynchroníSel tronsfer the data
and not inode

syncc)ollthe buttes
hen any process Calls towríte
ohich are. nodífid Ore queued.up
staods_forStotus
"Gtat
he headexf1e StothContaosLthe stat) totype of
characteISticsof
It qives status (ie
Syntax :
st_Stsu c t i
Stat (pathname

Stsuct Stat StstoUct


definatiaoof Stauct stat îs def present in
KStath

stuct Stat

st_mode (fie type & ie permissiansticks hits)

Stdev Cdevices numbery(logical devtse


St nlink (oumbex of linkS) (0o of altexnaty
we
(usex idof ooner)
St qíd HSer qoupid of aone)
stsze (highest offset ohere data is Stored)
St-aimecallocation)
stmtine (modikcaton)
St-chme (nodiicatons)
Stxdev (usedfor deuíices nunbl
St blksiee block Size)
St blockS

*Tups of iles fo
yNTX
eqular (NKMal data)
3directors files GCotains ee
nodes axe stuctuneoll
diIectories
nonleatCon be
leaf0de
3) pipe fIes ( Fles)for eg, folder
Ttrs used Tnte
pocess Communication)
anothes file
1Stato l Stonds for fak,

These are 2
Varíatíunsof stato
fstat(o
Syntax:
f5tatlfd, ¢ 5+.Stsuct)

Ghuct 6tat S:
Gtat ( Gompiedat"4 S);
*S-15fEG (S.stmode))

else
printf"Requla"),
prínt Not reglor")

pipefiies are pureiy temporaig fiies


heu areCicce55ed l xead io Secauentiol mooner
" they aie tsansient (temp9TaTy)
pípe fíies have 2 types
ODaned (bavíog name)
) UnnGmed( doesnt have name)

deutce fiies
evesy deuice has on entySoto fiie system
..devices ffis aie stored in dev fie.
there are 2 tupes of device fiies.

block character

Unix alloos usto assiqn new Dame to tile

Eink(s alias forfiles.


1heugh ink nomes are differeot taode fs Sane
data.
Ansnome toacess the
bo4h nomes gTues the Same data.
nk faCKeateA by using
Iypes of \fnk
Ohard |takloode fs same)
single.
. hod \fak (ieates-same nmesD,
Syntax
\in('exísting_fiie"e w fiie").

different)
Smbolfc \iok.C (nodes are
Syntax
Syrmlink ("existinq-fiie,oeofiie'):
aS writes the pathoame ot exsinq-file into o

t doesnt caotain anything coithout patbnaa


when we ead anyhinq ram the neuofie
is acthualy read from existing-fie
4hese ead is done automaticaly bu the os

1s usedto qet. the chorac teristiCS of Iiok


fies
and not of the oriqinal vaue fiie
Syntax
lstat" filenarnet stouctstat)

(6)Socket fiies
these are used for Sendinq data to
machie ovex netork another
Ttfs usedfor
(omnunicatian betoeen mochines
ovethe fotenetLnetooxk.
Stat,h paouides certain
machos
TSLK () block
OS-1SREGO aular s_ISEIFO ( Lpipe
s-1SDIRL)(titetoy 5-1sLINKULSubolic ns
acter
bat

Homeassígnment
poss fiieaame caS Command
Line agunent
eck the fieype and dfsplay type of Aie
iocide<stdiohs
ioclude <StdR6h>
foclude<syslstath
0ludes fcotl-h>

tot main Liot arqc, chor


stsuct stat fiie-Stat,
SAat (argv1], {fi kestot);
nee-t mode: fle-Stat St-ms de:

pinte Reqular fiie ");


else f(S-SSIR Lode)
priotf (" Directo Hle)
cS-IS CHR odel)
elseîf
painttf" character fiie"3
S~ISFI£o mode)
else ff (
priotf ptpe fie");
( nDde)
elseif (S-PS GLk
príotfC G4ock fiie);
else i f cSIS,LINK(mode))
pintfLink (symbolic) fiie"),
else f(S1SSQCE Cnode)
ptiotf(" Socket fiie"

else
fie tpe")j
priotfc" Uokogws
Absolute ) ( use Samplet

Relafve = (£mple-t xt

St odeCantains file pemissie0s. andfile


to Soving mnemors 6t-mode contains muitin
elements
prede ioed constants are auailab le
Check for the fi1e pexmission
OS-IRUSR (S-1 RGRP s-IWoTH
SIUSR S-1ROTH
(ssKGRP S-IXOTH
(for usel
.1E sex
(forqoup)
onts to xead
For(others)
a teataio Hle os chor
the user ype aleq oth peamssin using thesea
Constonts
exeutabie fies
means pagams
execute permission n dírectory eaaS_Seatch th
ditectoy
f e aie
Creaiag
the directais should ave both execute and
wrte permissioos
ae delettng a filefie
orite
permission and díiectors nee ds both
execute aod corite permissians
Censtant hNe volues ing bits
if coe uant to chneck he
othes and qooup uepermission is given or
not för
Nalue oíth Constan Simpiy the

permisston is
pexmissisn is qiuen.
-a umasko O
to.O.Se+omas
it cIeatingfor
umaSk
Io..createoeH.cawn e. we.Can ons
permiustsostgComon these_functan Constants offiles ewner
kis permission
Son YetuinSe t (pathome,
acceGS
nude)
umask(pemiwantto
tohotssio.gnsiven).
set be
Tfhese
for +hese
mask
to f
qíve alJowG Ts
USe
oBhes.fwmasK
termioal etin yivenfunction
all tunc15oo
cífyspecimasfki.eudvalsiogpeue smis ion
Coo?4) s
pe to
UmasK(0) proqamandcon
9ups
miSsio0S. t
permission
USe CEate
Alenotq1venmeo0s tetusns (exçcte)
il
p.eimissiao
Specife
ie d. 1
al beSet not)
den' constants othe

You might also like