Operációs rendszerek UNIX fájlrendszer
UNIX fájlrendszer • Alapegység: a file, amelyet byte-folyamként kezel. • Soros (szekvenciális) elérés. • Transzparens (átlátszó) file-szerkezet. • Link-ek (kapcsolatok) létrehozásának lehet!sége: –egy file-ra több névvel is hivatkozhatunk.
• Blokkméret: – 512, majd 1024 byte, –azaz n! az adatátvitel sávszélessége, de n! a bels! tördel!dés is!
2
Fájlrendszer névtér • A könyvtárak szerkezete hierarchikus fa struktúra (irányított körmentes gráf). • Egyetlen gyökérkönyvtár ("/"). • File-rendszerek összekapcsolása (mount). • Aktuális könyvtár fogalmának támogatása. Página 8 de 30
Página 9 de 30
constituent file system becomes /bin/cc after mounting. There is also a system call to unmount a file system.
Figure 24.4. Separate file systems are mounted to form a single hierarchy.
3 24.4.2 Graph navigation and the current directory The namespace can also contain various kinds of special file which provide access to devices or IPC mechanisms through the same interface that is used for accessing normal files. These It is inconvenient to use the full pathname, starting11 from Página dethe30root, every time a filename is special device files are traditionally held in the /dev directory. For example, opening the used. For this reason, the UNIX kernel associates a current or working directory with each file /dev/hda may provide direct access to the blocks held on the first hard drive in the system. process and filenames are interpreted relative to that. Aside from being a convenience for the Access to such special files is usually restricted to privileged users of the system. Integrating user, maintaining a current directory can make lookup operations more efficient if the file access, IPC and device access enables the modular composition of communicating implementation follows the scheme we will see in Section 24.5. For example, in Figure 24.3: processes: a particular program can be written to perform generic I/O operations without (in many cases) being aware of the kind of data the source or destination it istogether using. Keeping information onthat files in an inode table is isconvenient. An alternative a pathname starting from the root, is /; to ! /bin/sh
use a disk block as an indirection on the path to each file, thus scattering the information and
A small number of system calls provide I/O operations. The file's pathname is given when a file the same file's name of if /bin is the directory. ! sh isthe leading to many more disk reads. Algorithms for checking consistency the filecurrent system are is opened for use along with flags indicating the kind of access that will be made and the easy to implement inode table (see Section 24.5.6). The disadvantage of an inode desired behaviour if the file does not already exist. If all isusing well, athe small integer, the file Furthermore, each user has a home-directory setting defining an initial working directory that table isfile that is vulnerable tocalls. head crashes or bad isblocks in that area. that the may change its current directory at any descriptor or fd, is returned for the open anditused in subsequent A current offset established at login by theFor shell. Afterreason, that, a process into the file is maintained by the system for usually reads and writes. This can be manipulated explicitly time, using a system call, chdir. table is replicated. by the user, but for sequential reads and writes the system will remember where you got to.
Könyvtár fájlok
24.5.2 Directory files
fd
= open(pathname, flags)
result
= close (fd)
bytes
= read (fd, where-to-in-memory, byte-count) component is located,
count result result
UNIX also allows navigation of the naming graph upwards from the current directory towards the root. Each directory contains an entry for itself named '.' and an entry for its parent named '..'. If /home/tlh20 is the current directory, .. /jmb is a pathname up to directory /home (the parent of /home/tlh20) then down to directory /home/jmb. It is often more convenient to change working directory thaninode to construct long relative of a pathname to the at which that pathnames of this kind.
Directory files contain mappings from components either for the next directory within a hierarchy or for a file occurring as a Although related, these three mechanisms are provided by different parts of the system: the = write (fd, where-from-in-memory, byte-count) leaf node. Figure 24.6 gives an example of the resulting style the of pathname lookup the the home directory is managed by the kernel records current directory for eachfor process; shell; and the '.' and '..' entries are actually reflected in links of those names stored in every file /home/tlh20/.mail. = seek (fd, where to position the current offset in the file)
• Könyvtár leírás: a "." nev" file. directory.
= create (pathname)
Figure 24.6. Pathname resolution.
24.4.1 Mounting and unmounting file systems The hierarchical namespace is typically large and constructed from a number of separate file systems on separate devices. A file system can be mounted into the existing naming tree, its root replacing some specified directory, using the mount system call (see Figure 24.4). For example:
file://C:\Documents and Settings\Administrador\Configurações locais\Temp\~hh7A97.ht... 3/6/2010
mount ('/bin', '/dev/hda', R/W) causes the file system which is on device hda (with special file /dev/hda) to be mounted over the directory /bin. R/W indicates that it can be read and written. The file /cc shown on a
file://C:\Documents and Settings\Administrador\Configurações locais\Temp\~hh7A97.ht... 3/6/2010
4 This separation between directories and inodes allows one file to be accessible via multiple names, since there may be more than one directory entry that specifies a particular inode. This might be useful when organizing the file system hierarchy because it allows a single file to be available in different parts of the namespace. Each such occurrence of a file's inode within a
inode • File típusa, ami lehet: – speciális (karakteres vagy blokkos eszköz, I/O), – adatállomány, – könyvtár (katalógus) bejegyzés (. és ..), – PIPE/FIFO. Página 10 de 30 • Az adott i-node-ra mutató link-ek száma (a szimbolikus link-ek nélkül). • Eszköz ID. • UID, GID (a file tulajdonosának felhasználói és [ Team LiB ] [ Team LiB csoportazonosítója). ] • Id!címkék: – utolsó elérés, 24.5 File system implementation – utolsó módosítás, – utolsó attribútum módosítás módosítás). In Section 24.4 we described the interface that(i-node an application uses when accessing the file system and the way in which directory names are presented to users. In this section we • A file hozzáférési jogai (rwx). introduce• the primary data structures that are used to implement a basic UNIX file system and Címtábla, (13 mutató a file-hoz tartozó adatblokkokra): show how these might be held on a disk. – 10 direkt és 5 – 1 indirekt, 1 kétszeresen indirekt és 1 háromszorosan indirekt. 24.5.1 Inodes Central to each file system is a metadata table held on disk and cached in main memory in which each file occurring there has an entry (irrespective of whether it is a normal file, a directory file or a special file). These entries are called index nodes or inodes and contain information on the corresponding file. By convention, the inode of the root of a file system is the first entry in the table. Figure 24.5 shows the information held in an inode.
inode (folyt.)
Figure 24.5. A UNIX inode structure.
The inode identifies the owner of the file, the ways in which the file may be accessed, the times at which it was last subject to particular kinds of access, the type of the file, its size in bytes, a reference count for the file and the location of the disk blocks that contain the file's
6
A buffer cache • folyamatok számára hozzáférhet! közös adatszerkezet a kernel területen –lemez blokk hozzáférések gyorsítása
• blokk fejléc info –busy, locked –dirty
• relokálási algoritmus –least recently used
Página 12 de 30
• konzisztencia kérdések
class of students or a project team) and others. The types of access that can be specified for a normal file are read, write and execute. This information is coded as shown in Figure 24.7. 7 The same coding is used for directory files, but the interpretation of the access types is different: a 'read' permission allows the directory contents to be listed, a 'write' permission allows directory entries to be added or removed and an 'execute' permission allows the directory to be traversed. A consequence of this is that deleting a file requires write access to the directory in which the file resides, not write access to the file itself.
–sync
Figure 24.7. Access permissions for a normal file.
Página 12 de 30
Hozzáférési védelem
class of students or a project team) and others. The types of access that can be specified for a normal file are read, write and execute. This information is coded as shown in Figure 24.7. The same coding is used for directory files, but the interpretation of the access types is different: a 'read' permission allows the directory contents to be listed, a 'write' permission allows directory entries to be added or removed and an 'execute' permission allows the directory to be traversed. A consequence of this is that deleting a file requires write access to the directory in which the file resides, not write access to the file itself.
• Az inodeban tárolva • Jogosultságok
Figure 24.7. Access permissions for a normal file. An additional permissions bit, called the set user-id bit, allows access by program to be specified as well as access by categories of user. When this bit is set for a program file, any user having permission to execute the program inherits the privileges of the owner while executing the program. It is therefore possible for a given user to write to some data file (accessible to the owner of the program being executed) while executing a set-uid program, but not otherwise. The set group-id bit performs a similar function but with the group id. A further bit is also defined, but its precise semantics differ between versions of UNIX. It was originally known as the sticky bit because, if applied to an executable program, the code would remain additional permissions called set user-idexecuted bit, allows access by program in physical memory An once loaded. It was bit, used forthe frequently programs such to asbethe specified as well as access by categories of user. When this bit is set for a program file, any shell or popular tools: need has been superseded by larger memories andwhile more userits having permission to execute the program inheritsphysical the privileges of the owner effective strategies for caching and sharing code between executing the program. It is therefore possible forprocesses. a given user to write to some data file
–olvasás (r), írás (w), végrehajtás (x)
• Felhasználói csoportok
(accessible to the owner of the program being executed) while executing a set-uid program, but not otherwise. The set group-id bit performs a similar function but with the group id. A further
Figure 24.8 gives anbitexample of UNIX permissions. A user PROF has written a originally program is also defined, but its precise semantics differ named between versions of UNIX. It was known as the sticky if applied to an executable program, the codethem would some remain called TEST which students must runbit inbecause, order to be assessed. The program gives in physical once loaded. wasfile used for frequently executed has programs such as to thethe tasks to carry out and writesmemory their scores into Itthe SCORES. A student no access shell or popular tools: its need has been superseded by larger physical memories and more file SCORES except effective when running the program TEST so cannot bypass the test procedure and strategies for caching and sharing code between processes. either write a high score into the file or read the scores of fellow students.
–tulajdonos (owner), csoport (group), mások (other)
Figure 24.8 gives an example of UNIX permissions. A user named PROF has written a program called TEST which students must run in order to be assessed. The program gives them some Figure 24.8. facility. tasks to carry out andUse writes of theirthe scoresset-user-id into the file SCORES. A student has no access to the file SCORES except when running the program TEST so cannot bypass the test procedure and either write a high score into the file or read the scores of fellow students.
• set user-id bit –owner jogok futatáskor –real-id, effective-id
Figure 24.8. Use of the set-user-id facility.
Another aspect of this facility is that while running the set-uid program the process retains the Another aspect this facility is that while running theeffective-id set-uid program(of the the process retains the original real-id (of the user thatofcreated the process) and an owner the 8 of original real-id (of the user that created the process) and an effective-id (of the owner of the program). These areprogram). both available to the program and may be used to ensure that only a These are both available to the program and may be used to ensure that only a certain group of users carry out in the example UNIX UNIX provides system certain group of the usersTEST carry out the TEST in the above. example above. provides systemcalls, calls, seteuid setreuid,between for switching real-id the effective-id thataaprocess process seteuid and setreuid, forand switching thebetween real-idthe and theand effective-id so so that can perform operations both as its invoker as its creator. can perform operations both as its invoker and as its and creator.
Adatszerkezetek és filerendszer leírók a lemezen • Boot block: – a rendszer indításához szükséges információkat tartalmazza, – bár csak 1 file-rendszernél szükséges, mindegyik tartalmazza, legfeljebb üres.
• Super block: – a file-rendszer metaadatait tartalmazza, leírva ezzel annak állapotát, – buffer cache szint" kezelés (állandó memóriában lév!ség), – több file-rendszer esetén egy mount() rendszerhívással kerülnek a memóriába egészen egy umount() rendszerhívásig, – egy ún. mount-tábla tartja nyilván !ket. 9
Adatszerkezetek és file-rendszer leírók a lemezen (folyt.) • i-node list: –az i-node-ok nyilvántartásának a helye, –a file-rendszerben maximálisan létrehozható fileok számát határozza meg (super user által).
• Data blocks: –az adatok fizikai tárolási helyei. BOOT BLOCK
SUPER BLOCK
I-NODE LISTA
ADATOK
10
A SUPER BLOCK tartalma • • • • • • • • • •
A file-rendszer mérete blokkokban. A szabad adatblokkok száma. A szabad adatblokkok listája. A következ! szabad adatblokk indexe a szabad adatblokkok listájában. Az i-node lista mérete (a maximális file szám). A szabad i-node-ok száma. A szabad i-node-ok listája. Mutató az els! szabad i-node-ra a lemezen tárolt i-node listában. Lock mez!k (i-node, blokklista). Módosítás jelz!bit.
11
Szabad inode nyílvántartás • Tárolásuk egy lineáris listában. Ha közvetlenül innen történne a kiszolgálás, az lassú lenne. • Ezért a hatékonyság növelése miatt, a super block tartalmaz egy fix tömböt, amelyben a szabad i-node-ok sorszámai vannak. • A tömb feldolgozása mindig hátulról történik egy tömb mutató segítségével. • A 0. tömb elem az ún. megjegyzett i-node, ez mutat a lemezen lév! els! szabad i-node-ra.
12
Szabad adatblokkok nyílvántartása • Szabad adatblokkokra mutató tömbök láncolt listája, a super block-ban illetve a lemez adatterületén. super block
következ! szabad adat blokk mutatója 83
Szabad adatblokkok listája
szabad blokk
szabad blokk
szabad blokk
adat blokkok területe a lemezen
Láncolt lista els! eleme (83-as adat blokk)
95 szabad blokk
szabad blokk
szabad blokk
szabad blokk
szabad blokk
szabad blokk
13
File-ok kezelése • Processz: –File Descriptor Table.
• Rendszer:
Página 14 de 30
–Global File Descriptor Table, –i-node Table (in-core i-node Table).
the file system interface so the user's terminal device as well as normal files that are open will be represented here.
Figure 24.9. The organization of file system structures on disk and in memory.
14 A system-wide open file table contains at least one entry for each open file: this identifies the file system and inode being accessed and contains the current file offset for that file. The active inode table contains a 'copy' of the inode of each open file. In fact the information will differ from that held in the inode on disk in a number of ways. The active inode must identify its
Adatszerkezetek • File Descriptor Table, avagy folyamatonkénti állományleíró tábla: –minden egyes folyamathoz tartozik 1 ilyen tábla, –logikai perifériákat nyilvántartó rekordok sorozata, –mindegyik megnyitott állományhoz egy mutató is tartozik, amelyik a Global File Descriptor Table megfelel! struktúrájára mutat, –az els! három rekord a standard: input, output és error. Ezeket a folyamatok az indulásukkor megnyitva kapják meg. 15
Adatszerkezetek (folyt.) • Global File Descriptor Table, avagy globális állományleíró tábla: –minden open() rendszerhívás esetén létrejön egy struktúra, (1 munkamenet) amely az adott fizikai file-hoz rendel!dik, –a struktúra jellemz! elemei: • elérési útvonal, • megnyitási mód, • jogosultságok, • egy file-on belüli pozíció mutató (eltolás), • hivatkozás számláló, amely megmutatja, hogy hány darab File Descriptor Table bejegyzés mutat rá,
–biztosítja az osztott file használatot.
16
Página 8
Adatszerkezetek (folyt.) • i-node Table (in-core i-node Table), avagy i-node memória tábla minden nyitott filehoz: –hivatkozásszámláló, amely megmutatja, hogy az adott fizikai file-t hány példányban használják azaz, hogy hány darab Global File Descriptor Table bejegyzés mutat rá, –biztosítja a fizikai file elérését.
The namespace can also contain various kinds of special file which provide access to dev or IPC mechanisms through the same interface that is used for accessing normal17files. The special device files are traditionally held in the /dev directory. For example, opening the file /dev/hda may provide direct access to the blocks held on the first hard drive in the sys Access to such special files is usually restricted to privileged users of the system. Integrat file access, IPC and device access enables the modular composition of communicating processes: a particular program can be written to perform generic I/O operations without many cases) being aware of the kind of data source or destination that it is using.
A file-kezel! UNIX rendszerhívások
A small number of system calls provide I/O operations. The file's pathname is given when is opened for use along with flags indicating the kind of access that will be made and the desired behaviour if the file does not already exist. If all is well, a small integer, the file descriptor or fd, is returned for the open file and used in subsequent calls. A current offs into the file is maintained by the system for reads and writes. This can be manipulated ex by the user, but for sequential reads and writes the system will remember where you got fd
= open(pathname, flags)
result
= close (fd)
bytes
= read (fd, where-to-in-memory, byte-count)
count
= write (fd, where-from-in-memory, byte-count)
result
= seek (fd, where to position the current offset in the file)
result
= create (pathname)
24.4.1 Mounting and unmounting file systems
The hierarchical namespace is typically large and constructed from a number of separate f systems on separate devices. A file system can be mounted into the existing naming tree, root replacing some specified directory, using the mount system call (see Figure1824.4). Fo example: