Sunteți pe pagina 1din 74

Chapter 3.

Secondary Storage and System Software


Ki-Joon Han School of Computer Science & Engineering Konkuk University

kjhan@db.konkuk.ac.kr

Chapter Outline (1/2)


3.1 Disk 3.2 Magnetic Tape 3.3 Disk versus Tape 3.4 Introduction to CD-ROM 3.5 Physical Organization of CD-ROM 3.6 CD-ROM Strengths and Weakness 3.7 Storage as a Hierarchy 3.8 A Journey of a Byte 3.9 Buffer Management 3.10 I/O in Unix
File Processing (3) Konkuk University (DB Lab.) 2

Chapter Outline (2/2)


Secondary storage devices (v.s. memory)
accesses take much more time than do accesses to memory all accesses are not equal

Good file structure design


use knowledge of disk and tape performance to arrange data in ways that minimize access costs

This chapter
the characteristics of secondary storage devices the journey of a byte buffering
File Processing (3) Konkuk University (DB Lab.) 3

3.1 Disks (1/2)


DASD
magnetic disk direct (random) access and serial access

Serial device
magnetic tape only serial access

File Processing (3)

Konkuk University (DB Lab.)

3.1 Disks (2/2)


Magnetic disk
1. hard disks (exterior HDD)
high capacity and low cost per bit removable disk pack

2. floppy disks
inexpensive, but slow with relatively little data

3. disk cartridge
Zip (750 megabytes) and Jaz (1~2 gigabytes) disks

Optical disks: CD-ROM, CD-RW, DVD-ROM, DVD-RW,


become increasingly important for secondary storage (Appendix A)
File Processing (3) Konkuk University (DB Lab.) 5

3.1.1 The Organization of Disks (1/4)


Disk pack
consists of a number of platters Spindle

Platters Read/write heads


File Processing (3) Konkuk University (DB Lab.)

Boom
6

3.1.1 The Organization of Disks (2/4)


Track
divided into a number of sectors

File Processing (3)

Konkuk University (DB Lab.)

3.1.1 The Organization of Disks (3/4)


Sector
the smallest addressable portion of a disk

read() : a particular byte from a disk file


O.S. (i) find the correct surface, track, and sector (ii) read the entire sector into a buffer in RAM (iii) find the requested byte within the buffer

File Processing (3)

Konkuk University (DB Lab.)

3.1.1 The Organization of Disks (4/4)


Cylinder
no seeking (same radius)

File Processing (3)

Konkuk University (DB Lab.)

3.1.2 Estimating Capacities and Space Needs (1/3)


Disk
capacity: 20GB~750GB, spindle speed: 4,200 rpm~ 15,000rpm, buffer: 2MB~16MB

File Processing (3)

Konkuk University (DB Lab.)

10

3.1.2 Estimating Capacities and Space Needs (2/3)


Cylinder -> Track -> Sector -> Byte Capacity
1. track capacity = # of sectors / track * bytes/sector 2. cylinder capacity = # of tracks / cylinder * track capacity 3. drive capacity = # of cylinders * cylinder capacity

File Processing (3)

Konkuk University (DB Lab.)

11

3.1.2 Estimating Capacities and Space Needs (3/3)


Ex) a file with 50,000 fixed-length records on 2.1GB disk
# # # # of of of of bytes / sector sectors / track tracks / cylinder cylinders = 512 = 63 = 16 = 4096

=> How many cylinders for 256 byte records ?


50,000 / 2 = 25,000 sectors / file 63 * 16 = 1008 sectors / cylinder 25,000 / 1008 = 24.8 cylinders / file

File Processing (3)

Konkuk University (DB Lab.)

12

3.1.3 Organizing Tracks by Sector (1/7)


Data organization method
1. by sector 2. by user-defined block

Physical placement of sectors (controller)


1. adjacent sectors : Fig.3.4 (a) [recent]
can't [can] read adjacent sectors 32 [1] revolutions for 32 sectors

2. interleaved sectors : Fig.3.4 (b) interleaving factor : 5 5 revolutions for 32 sectors

File Processing (3)

Konkuk University (DB Lab.)

13

3.1.3 Organizing Tracks by Sector (2/7)


Two views
. . 5 4 3 .

Disk
27 2 1 32 31 30 29 28

Fig.3.4(a)

. 2

. 21

Disk
19 8 27 14 1 20 7 26 13 32

. .

Fig.3.4(b)

File Processing (3)

Konkuk University (DB Lab.)

14

3.1.3 Organizing Tracks by Sector (3/7)


File
a series of clusters of sectors

Cluster
a fixed # of contiguous sectors (not always physically) that can be accessed without requiring an additional seek the smallest allocation unit (default size: 3 512-bytes sectors) size : 1 ~ 65,535 sectors (in VAX system)

Trade-offs of cluster size


1. large cluster size for large files with sequential access 2. small cluster size for small files or files with random access => Cluster size is set when the disk is initialized
File Processing (3) Konkuk University (DB Lab.) 15

3.1.3 Organizing Tracks by Sector (4/7)


FAT (File Allocation Table)
contains a list of all the clusters in a file, ordered according to the logical order of their sectors cluster entry --> physical location of the cluster Cluster number
1 2 3 . . .

Cluster location

The part of the FAT pertaining to our file

2
. . .

3
File Processing (3) Konkuk University (DB Lab.) 16

3.1.3 Organizing Tracks by Sector (5/7)


Extent
adjacent clusters allocated as part (or all) of a file to minimize seeking file : one extent or several extents

file extents

extent extent extent

File Processing (3)

Konkuk University (DB Lab.)

17

3.1.3 Organizing Tracks by Sector (6/7)


Fragmentation
1. use of sectors
512-byte sector and 300-byte record 1) within sectors: Fig. 3.7(a)
adv. : retrieving one sector for any record disadv. : unused space within each sector ( -> internal fragmentation )

2) span sectors: Fig. 3.7(b)


adv. : no unused space disadv. : retrieving two sectors for some records

2. use of clusters
cluster with three 512-byte sectors and 1537-byte file --- 1535 bytes are wasted large cluster size : for large or sequential files small cluster size : for small files or random access
File Processing (3) Konkuk University (DB Lab.) 18

3.1.3 Organizing Tracks by Sector (7/7)


Record organization within sectors

File Processing (3)

Konkuk University (DB Lab.)

19

3.1.4 Organizing Tracks by Block (1/3)


Disk tracks
divided into integral numbers of user-defined blocks whose size can vary (not into sectors)

Block
unit of I/O operation : vary fixed or variable in length an integral number of logical records (blocking factor) different meaning in the context of the Unix I/O system

Block organization
remove the sector-spanning and fragmentation problems of sectors (no wasted space) no loss due to internal fragmentation ex) for 300 byte records => block : n * 300 bytes
File Processing (3) Konkuk University (DB Lab.) 20

3.1.4 Organizing Tracks by Block (2/3)


Sectored tracks vs. blocked tracks
Sector 1 111111 Sector 2 111111 Sector 3 Sector 4 Sector 5

111 222 22 333 4 444 555

(a) Sector organization

111111

111111

111 222 22 333 4 444 555

(b) Block organization (more desirable)


File Processing (3) Konkuk University (DB Lab.) 21

3.1.4 Organizing Tracks by Block (3/3)


Block-addressing schemes
block : one or more subblocks 1. count subblock : # of bytes in the data subblock 2. key subblock : key for the last record in the data subblock 3. data subblock : data

Count subblock

Data subblock

Count subblock

Data subblock

Count subblock

Key subblock

Data subblock

Count subblock

Key subblock

Data subblock

File Processing (3)

Konkuk University (DB Lab.)

22

3.1.5 Nondata Overhead (1/2)


Nondata overhead (during preformatting) 1. sector-addressable disk
at the beginning of each sector, sector address, track address, and condition gaps and synchronization marks between fields of information for the read/write mechanism

2. block-organized disk
subblocks and interblock gabs more nondata overhead

File Processing (3)

Konkuk University (DB Lab.)

23

3.1.5 Nondata Overhead (2/2)


Block-addressable disk drive : How many records ?
100 bytes/record, 20,000 bytes/track , and 300 bytes/block for subblocks and interblock gabs (1) bf = 10
10 * 100 bytes + 300 bytes = 1,300 bytes/block 20,000 / 1,300 = 15.38 = 15. blocks/track = 150 records/track

(2) bf = 60
60 * 100 bytes + 300 bytes = 6,300 bytes/block 20,000 / 6,300 = 3.17 = 3. blocks/track = 180 records/track

the larger blocking factor, the more efficient use of storage the greater the block size, the greater potential amount of

internal track fragmentation


File Processing (3) Konkuk University (DB Lab.) 24

3.1.6 The Cost of a Disk Access (1/4)


Disk access time
1. seek time
to move the access arm to the correct cylinder more costly in a multiuser environment average seek traverses 1/3 of the total # of cylinders

2. rotational delay
to rotate so the required sector is under the real/write head average rotational delay is 1/2 of a revolution (ex) Hard disk : 5000 rpm (12 msec/revolution) Floppy disk : 360 rpm (166.6 msec/revolution)

3. transfer time
# of bytes transferred / # of bytes on a track * rotation time (ex) 63 sectors per track => Transfer time/sector = 1 / 63 * rotation time = 0.19 msec
File Processing (3) Konkuk University (DB Lab.) 25

3.1.6 The Cost of a Disk Access (2/4)


Some timing computations
9 - Gbyte fixed disk described in Table 3.1 8,704,000 (bytes/file) => 8,704,000 (bytes/file) / 256 (bytes/record) = 34,000 256-byte records/file [512 bytes/sector] = 34,000 (records/file) / 16 (records/cluster) = 2,125 clusters/file [8 sectors/cluster = 16 records/cluster = 4096 bytes/cluster] = 100 tracks/file 87,040 bytes/track => 87,040 (bytes/track) /4096 (bytes/cluster) = 21.25 clusters/track
File Processing (3) Konkuk University (DB Lab.) 26

3.1.6 The Cost of a Disk Access (3/4)

File Processing (3)

Konkuk University (DB Lab.)

27

3.1.6 The Cost of a Disk Access (4/4)


(1) Sequential access
average seek 8 msec rotational delay 3 msec read one track 6 msec -----------------------------------------total 17 msec/track total time = 100 * 17 msec = 1,700 msec = 1.7 sec/file

(2) Random access


average seek 8 msec (one for every access) rotational delay 3 msec read one cluster 0.28 msec (<= 1 / 21.25 * 6 msec) ---------------------- (one cluster= 1/21.25 track) total 11.28 msec/record total time = 34,000 * 11.28 msec = 9,250 msec = 9.25 sec/file
File Processing (3) Konkuk University (DB Lab.) 28

3.1.7 Effect of Block Size on Performance : A UNIX Example (1/2)


Disk storage allocation (BSD Unix ) : Table 3.2
trade-offs between block size and performance (block size, fragmentation, access time) 512-byte block : slowest throughput with small amount of wasted space 1024-byte block : 4 % of the theoretical maximum throughput 4096-byte block : fastest throughput, but large amount of wasted space (45.6 %) due to internal fragmentation

Berkeley Group implementation (4,096/512 system)


large file : allocate 4,096-byte blocks small file : divide the large blocks into 512-byte fragments wasted space => about 12 %
File Processing (3) Konkuk University (DB Lab.) 29

3.1.7 Effect of Block Size on Performance : A UNIX Example (2/2)

File Processing (3)

Konkuk University (DB Lab.)

30

3.1.8 Disk as Bottleneck (1/4)


Disk bound process
disk : 5 MB/sec network : 100 MB/sec => ? GB/sec CPU : more fast

Solutions for disk bound process 1. Multiprogramming


CPU works on other jobs while waiting for the data to arrive

File Processing (3)

Konkuk University (DB Lab.)

31

3.1.8 Disk as Bottleneck (2/4)


2. Disk striping
involve splitting the parts of a file on several different drivers, then letting the separate drives deliver parts of the file to the network simultaneously (=> parallelism) (ex) 10 MB file spread across 20 drives (3 MB/sec) that hold 50 KB per track
1 drive 2 drive 3 drive 1st 50KB 2nd 50KB 3rd 50KB 21th 50KB : : 181th 50KB 20 drive 20th 50KB 40th 50KB : : 200th 50KB

20 drives can deliver to the network 1 MB/revolution (combined rate = 60 MB/sec)

File Processing (3)

Konkuk University (DB Lab.)

32

3.1.8 Disk as Bottleneck (3/4)


3. RAID : 8 drives
spread individual blocks onto different drives the disk controller breaks each block into 8 pieces
1st piece is stored in the 1st drive 2nd piece is stored in the 2nd drive 8th pieces is stored in the 8th drive

read and write speed can be ten times faster the block is reassembled in cache

File Processing (3)

Konkuk University (DB Lab.)

33

3.1.8 Disk as Bottleneck (4/4)


4. Buffering
avoid accessing the disk (1) RAM disk a large part of memory is configured to simulate the behavior of a mechanical disk in every respect except speed and volatility without a seek or rotational delay, but volatile (2) Disk cache a large block of memory is configured to contain pages of data from a disk (256 KB cache) for high degree of locality

File Processing (3)

Konkuk University (DB Lab.)

34

3.3 Disk Versus Tape


Disk
excellent for random access and storage of file for which immediate access was desired for several processes => between accesses : tend to require an extensive seek

Tape
ideal for processing data sequentially and for long-term storage of files for one process

File Processing (3)

Konkuk University (DB Lab.)

35

3.7 Storage as a Hierarchy (1/2)


Hierarchy of storage devices : Fig. 3.17
different access time, capacity, and cost

(1) Primary storage


registers, memory, RAM disk, disk cache : semiconductors

(2) Secondary storage


direct-access : magnetic disks serial : tape, mass storage

(3) Offline storage


archival and backup : removable magnetic disks, optical discs, tapes

File Processing (3)

Konkuk University (DB Lab.)

36

3.7 Storage as a Hierarchy (2/2)


Hierarchy of storage devices (Cont.)

File Processing (3)

Konkuk University (DB Lab.)

37

3.8 A Journey of a Byte (1/2)


write(textfile, ch, 1)
User Program

ch : P
How the byte is stored on a disk, when a program write a byte to a file on a disk ? I/O buffer

Operating system File manager I/O processor Disk controller

Disk
File Processing (3) Konkuk University (DB Lab.) 38

3.8 A Journey of a Byte (2/2)


write(textfile, ch, 1) ch : P

File Processing (3)

Konkuk University (DB Lab.)

39

3.8.1 The File Manager (1/3)


1

Logical layer

The program asks the OS to write the contents of the variable ch to the next available position in textfile. The OS passes the job on to the file manager The file manager looks up textfile in a table containing information about it, such as whether the file is open and available for use, what types of access are allowed, if any, and what physical file the logical name textfile corresponds to. The file manager searches a FAT for the physical location of the sector that is to contain the byte. The file manager makes sure that the last sector in the file has been stored in a system I/O buffer in RAM, then deposits the P into its proper position in the buffer.
File Processing (3) Konkuk University (DB Lab.) 40

2 3

3.8.1 The File Manager (2/3)


6

The file manager gives instructions to the I/O processor about where the byte is stored in RAM and where it needs to be sent on the disk The I/O processor finds a time when the drive is available to receive the data and puts the data in proper format for the disk. It may also buffer the data to send it out in chunks of the proper size for the disk. The I/O processor sends the data to the disk controller. The disk controller instructs the drive to move the r/w head to the proper track, waits for the desired sector to come under the r/w head, then sends the byte to the drive to be deposited, bit-by-bit, on the surface of the disk.
File Processing (3) Konkuk University (DB Lab.)

8 9

Physical layer
41

3.8.1 The File Manager (3/3)


File manager v.s. O.S.
programs that deal with file-related matters and I/O devices several layers of procedures : logical ~ physical (i) check the logical characteristics of the file whether the file has been opened what type of file the byte is being sent to (binary, text file) who the file's owner is whether write access is allowed for the user (ii) determine where in the file textfile the P is to be deposited => physical location of the last sector ( <= FAT ) (iii) locate the drive, cylinder, track, and sector where the byte is to be stored

File Processing (3)

Konkuk University (DB Lab.)

42

3.8.2 The I/O Buffer (1/2)


(iv) determine whether the sector that is to contain the P is already in RAM or needs to be loaded into RAM (v) if not, find an available system I/O buffer space for it and read it from disk (vi) deposit the P into its proper position in the buffer (Fig. 3.20) 3.20 (vii) wait to see if the sector can accumulate more bytes going to the same sector before actually transmitting anything => if closed, flush all output buffers

File Processing (3)

Konkuk University (DB Lab.)

43

3.8.2 The I/O Buffer (2/2)

File Processing (3)

Konkuk University (DB Lab.)

44

3.8.3 The Byte Leaves Memory : The I/O Processor and Disk Controller (1/3)
Data path
the byte traveled along data paths 1. internal data path (CPU) : 32 bits in fast speed 2. external data path (disk) : 16 bits in slow speed => bottlenecks caused by differences in speeds & widths

I/O Processor
from a simple chip capable of taking a byte and passing it along one cue; to a powerful, small computer capable of executing very sophisticated programs and communicating with many devices simultaneously takes its instructions from the OS, but once it begins processing I/O, it runs independently => I/O processes and internal computing are overlapped
File Processing (3) Konkuk University (DB Lab.) 45

3.8.3 The Byte Leaves Memory : The I/O Processor and Disk Controller (2/3)
Information(program) : file manager => I/O Processor
1. data in the buffer that is to be transmitted to the disk 2. how much data there is 3. where it is to go on the disk

Disk controller : Fig. 3.21


responsible for the job of actually controlling the operation of the disk instruct the disk drive to set the read/write head to the desired sector, then sends the byte to the drive to be deposited

File Processing (3)

Konkuk University (DB Lab.)

46

3.8.3 The Byte Leaves Memory : The I/O Processor and Disk Controller (3/3)
I/O Processor & Disk controller
Users program .. .. .. Users data area: c: P File Manager . Invoke I/O processor . . . I/O processor Program . . p

p
Disk controller

p
System buffer

p
I/O processor

FIGURE 3.21 The file manager sends the I/O processor instructions in the from of an I/O Processor program. The I/O processor gets the data from the system buffer, prepares it on the disk, then sends it to the disk controller, deposits it on the surface of the disk. File Processing (3) Konkuk University (DB Lab.) 47

3.9 Buffer Management


Buffering
work with large chunks of data in memory so the number of accesses to secondary storage can be reduced the use of system I/O buffers within programs can substantially affect performance

Buffer
the part of main memory available for storage of copies of disk blocks not controlled by programmers, but by the operating system

File Processing (3)

Konkuk University (DB Lab.)

48

3.9.1 Buffer Bottlenecks (1/2)


Program for both input and output on one character at a time and only one I/O buffer
(i) program asks for its first character
I/O buffer is loaded with the sector containing the character the character is transmitted to the program

(ii) program decides to output a character


I/O buffer is filled with sector that will contain the character (i.e., destroy its original contents)

(iii) program asks for the next character


buffer contents have to be written to disk to make room for the (original) sector containing the second input character

=> two buffers (one for input and one for output)
File Processing (3) Konkuk University (DB Lab.) 49

3.9.1 Buffer Bottlenecks (2/2)


Program transmits data in only one direction, or is I/O bound
use multiple buffers CPU : process the current buffer

overlapping
I/O system : fill the next buffer

File Processing (3)

Konkuk University (DB Lab.)

50

3.9.2 Buffering Strategies (1/6)


Double buffering
the method of swapping the roles of two buffers after each output (or input) operation O.S. : operating on one buffer I/O system : loading or emptying overlapping the other buffer

Buffer pooling
when a system buffer is needed, it is taken from a pool of available buffers and used buffer selection for replacement : least recently used (LRU)

File Processing (3)

Konkuk University (DB Lab.)

51

3.9.2 Buffering Strategies (2/6)


Double buffering
I/O buffer 1 Program data area I/O buffer 2 To disk

I/O buffer 1 Program data area I/O buffer 2


File Processing (3) Konkuk University (DB Lab.)

To disk
52

3.9.2 Buffering Strategies (3/6)


Buffer handling (by file manager)
1. move mode
data : system buffer (RAM) <=> program buffer (RAM) (= program's data area) take the amount of time

2. locate mode
data : secondary storage <=> program's data area nmap()
no extra move

use system buffers to handle all I/O, but provide the program with the locations of the system buffers
program can operate directly on data in the I/O buffer

File Processing (3)

Konkuk University (DB Lab.)

53

3.9.2 Buffering Strategies (4/6)


Move mode & Locate mode
Move mode
programs data area system buffer

Disk

Locate mode

users program

location (pointer)

system buffer

Disk

File Processing (3)

Konkuk University (DB Lab.)

54

3.9.2 Buffering Strategies (5/6)


Block (header + data)
headers ... in one buffer data ... in a different buffer two-step process
(i) read whole block into a single big buffer (ii) move the different parts to their own buffers

Two methods (to reduce the running time) 1. scatter input : readv( )
a single READ call identifies a collection of buffers into which data from a single block is to be scattered

2. gather output : writev( )


several buffers can be gathered and written with a single WRITE call
File Processing (3) Konkuk University (DB Lab.) 55

3.9.2 Buffering Strategies (6/6)


Scatter input & Gather output
Scatter input
buffer 1 readv() Disk

buffer 2

Gather output

buffer 1 buffer 3 buffer 2


File Processing (3) Konkuk University (DB Lab.)

Disk writev()

56

3.10 I/O in UNIX 3.10.1 The Kernel (1/11)


Kernel I/O Structure
1. topmost layer
deal with data in logical, structural terms (e.g., file name, a body of text, an image, an array of numbers, or some other logical entity) application view on a file processes ... shell routines (cat, tail), user programs, library routines (scanf(), fread())

2. bottom layers
carry out the task of turning the logical object into a collection of bits on a physical device system view on a file UNIX Kernel ... views all I/O as operating on a sequence of bytes
File Processing (3) Konkuk University (DB Lab.) 57

3.10.1 The Kernel (2/11)


PROCESSES
User programs Libraries Shell commands System call interface

KERNEL

I/O system

Block I/O system (normal files)

Character I/O system (terminals, printers, etc.)

Network I/O system (sockets)

block device drivers disk

character device drivers

network interface drivers ...networks...


58

disk... consoles printers...

HARDWARE
File Processing (3) Konkuk University (DB Lab.)

3.10.1 The Kernel (3/11)


Journey of a byte
write (fd, &ch, 1) : (vs. fprintf(): library call)
(i) the system call instructs the kernel to write a character to a file (ii) the kernel I/O system begins by connecting the file descriptor (fp) to some file or device (scan a series of 4 tables) file descriptor table open file table file allocation table table of index nodes (inode table)

File Processing (3)

Konkuk University (DB Lab.)

59

3.10.1 The Kernel (4/11)


File descriptor table
owned by the process (your program) associates each of the file descriptors used by a process with an entry in the open file table every process has its own descriptor table includes entries for all opened files, including stdin, stdout,

stderr

File Processing (3)

Konkuk University (DB Lab.)

60

3.10.1 The Kernel (5/11)


File descriptor table
File descriptor 0 (keyboard) 1 (screen) 2 (error) 3 (normal) 4 (normal) 5 (normal) . . . File table entry

to open file table

File Processing (3)

Konkuk University (DB Lab.)

61

3.10.1 The Kernel (6/11)


Open file table
owned by the kernel contains entries (called "file structures") for every open file R/W mode, the number of processes currently using it, offset of next access, pointers to generic functions (i.e., read and write routines), inode table entry, etc. transitory (during opened)

File Processing (3)

Konkuk University (DB Lab.)

62

3.10.1 The Kernel (7/11)


Open file table
R/W mode # of processes using it Offset of next access ptr to write routine ...... inode table entry

write

100

......

to inode table

write() routine for this type of file


File Processing (3) Konkuk University (DB Lab.) 63

3.10.1 The Kernel (8/11)


Two methods
1. several different processes can refer to the same open file table entry
two processes : dependent

2. the same file can be opened by two separate open() statements (i.e., two separate entries)
two processes : independent inode : shared

File Processing (3)

Konkuk University (DB Lab.)

64

3.10.1 The Kernel (9/11)


File allocation table (FAT)
owned by the kernel a list (index) of the disk blocks that make up the file part of an index node(inode) dynamic tree - like structure, not a simple linear array

inode (index node) table


owned by the kernel when a file is opened, a copy of its inode is usually loaded into the inode table in memory for rapid access

File Processing (3)

Konkuk University (DB Lab.)

65

3.10.1 The Kernel (10/11)


Index node (inode)
permanent (during the existence of files), so kept on disk with the file information about file position, file size, owner's id, permissions, block count, etc. => once the kernel's I/O system has the inode information, it invokes an I/O processor program ( device driver)

Device driver
appropriate for the type of data, the type of operation, and the type of device that is to be written see that your data is moved from its buffer to its proper place on disk
File Processing (3) Konkuk University (DB Lab.) 66

3.10.1 The Kernel (11/11)


inode
device permissions owners userid file size . . . block count file allocation table

. . .
Konkuk University (DB Lab.) 67

File Processing (3)

3.10.2 Linking File Names to Files (1/2)


Directory
a small file that contains, for each file, a file name together with a pointer (called "hard link") to the file's inode on disk file name : 14 bytes, inode number : 2 byes

Shell commands
ln file-name1 file-name2 (cf., link())
two file names have the same inode number

rm file-name,
it removes directory entries & links

cp file-name1 file-name2
two file names have different inode numbers

mv file-name1 file-name2
file name is changed, but with the same inode number
File Processing (3) Konkuk University (DB Lab.) 68

3.10.2 Linking File Names to Files (2/2)


Hard link
an entry in a directory that connects a file name to the inode of the corresponding file by its inode number several file names can point to the same inode when a file name is deleted, file itself is not deleted, but its hard-link count is decremented by one

Soft link (or symbolic link)


an entry in a directory that gives the pathname of a file links a file name to another file name rather than to an actual file (i.e., an indirect pointer to a file) can refer to a directory or even to a file in a different file system UNIX 4.3 BSD (not System V)
File Processing (3) Konkuk University (DB Lab.) 69

3.10.3 Normal Files, Special Files, and Sockets


Three types of files
1. Normal files
files that this text is about

2. Special files
represent a stream of characters and control signals that drive some devices (e.g., line printer or graphic device)

3. Sockets
abstractions that serve as endpoints for interprocess communication

=> many of the same routines can be used to access any of them
(e.g., open() and write() system calls)

File Processing (3)

Konkuk University (DB Lab.)

70

3.10.4 Block I/O


Three I/O systems
1. block I/O system
for block-oriented device like a disk or a tape access blocks randomly sequence of bytes <=> block block size = 512 bytes (common sector size) --> 1024 bytes

2. character I/O system


for character-oriented device like a keyboard or a printer read and write streams of data, not blocks

3. network I/O system


for data communication on the network

File Processing (3)

Konkuk University (DB Lab.)

71

3.10.5 Device Drivers


Device driver ( I/O processor program)
a separate set of routines for each peripheral device performs the actual I/O between the I/O buffer and the device

Block I/O device driver


take a block from a buffer, destined for one of physical blocks, and see that it gets deposited in the proper physical place on the device => Block I/O part of kernel need not know anything about the specific device it is writing to

File Processing (3)

Konkuk University (DB Lab.)

72

3.10.6 The Kernel and File Systems(1/2)


UNIX file system Kernel's I/O system
a collection of files, together with secondary information about the files in the system includes the directory structure, the directories, ordinary files, and the inodes that describes the files

File Processing (3)

Konkuk University (DB Lab.)

73

3.10.6 The Kernel and File Systems(2/2)


Separation (file system kernel)
1. all parts of a file system
reside on disk some parts are brought into memory by the kernel as needed

2. kernel
reside in memory

Advantages of separation
we can tune a file system to a particular device or usage pattern independently of how the kernel views files we can have separate file systems that are organized differently, perhaps on different devices, but are accessible by the same kernel (e.g., file system on CD-ROM)
File Processing (3) Konkuk University (DB Lab.) 74

S-ar putea să vă placă și