. - (read) (write), , , , , . - 10.3. 300 +------------------+ | - | tty00 -------------+ | - | tty01 .... | | - | ... | +--+ +------------------+ tty07 -------------+-+ |------------| ttyintr 0 | tty08 -------------+ +--+ +------------------+ tty09 .... +-+ |------------| ttyintr 1 | ... +--------+ +--+ +------------------+ tty15 ----+ +--------+ |------------| consintr | ------+ +--+ +------------------+ 00 -------------+-+ |------------| printintr 0 | .... | +--+ +------------------+ 03 -------------+ | | | - | | | | - | +--+ +------------------+ 10.6. 10.1.3  ( 6.4.1), - , - , , . , - , , - . , 10.6 ("ttyintr"), , 8 . tty09 , , - . , , . - , , 0 1, , . , , , , tty09, tty12, . - , , , . , , , , , - . - - . 10.2  , UNIX - , , 301 " [] - " (. [System V 84b]). , - , , - , . , , - , , 4 5, , . , - (, , ) , , - , , . , - , . : - , , () ; - , , . - , , . , , - , , -. +---------------------------------------------+ | | | | | = 512 | | | | 0 0 64000 | | 1 64000 944000 | | 2 168000 840000 | | 3 336000 672000 | | 4 504000 504000 | | 5 672000 336000 | | 6 840000 168000 | | 7 0 1008000 | +---------------------------------------------+ 10.7. RP07 , . , DEC RP07 , - 10.7. , "/dev/dsk0", "/dev/dsk1", "/dev/dsk2" "/dev/dsk3" RP07, 0 3, . - . 940 , "/dev/dsk3", 336940 ( 3 , 336000; 336000 + 940 = 336940) . - : . . - . , 0 1 RP07 , 0 1008000, . 7 . , - 302 , , , . , , , . . , - . , - . V , - , , , . - - , - . , UNIX , , . , , - ; - . , 4 5, , . - mkfs fsck. mkfs UNIX, , , - . fsck , 5. , 10.8, "/dev/dsk15" "/dev/rdsk15", , ls : ls -1 /dev/dsk15 /dev/rdsk15 br-------- 2 root root 0,21 Feb 12 15:40 /dev/dsk15 crw-rw---- 2 root root 7,21 Mar 7 09:29 /dev/rdsk15 , "/dev/dsk15" , "root", "root" . - 0, - 21. "/dev/rdsk15" -, "root", , . - 7, - 21. , , - - -, , 21 , , , - 2, 1. , - , , (***). , , , --------------------------------------- (***) , - , - . 303 ( ), 8192 . - , . +------------------------------------------------------------+ | #include "fcntl.h" | | main() | | { | | char buf1[4096], buf2[4096] | | int fd1, fd2, i; | | | | if (((fd1 = open("/dev/dsk5/", O_RDONLY)) == -1) || | | ((fd2 = open("/dev/rdsk5", O_RDONLY)) == -1))| | { | | printf(" \n"); | | exit(); | | } | | | | lseek(fd1, 8192L, 0); | | lseek(fd2, 8192L, 0); | | | | if ((read(fd1, buf1, sizeof(buf1)) == -1) || | | (read(fd2, buf2, sizeof(buf2)) == -1)) | | { | | printf(" \n"); | | exit(); | | } | | | | for (i = 0; i < sizeof(buf1); i++) | | if (buf1[i] != buf2[i]) | | { | | printf(" %d\n", i); | | exit(); | | } | | printf(" \n"); | | } | +------------------------------------------------------------+ 10.8. , , - , , . - - . , "/dev/dsk15" "/dev/rdsk15" "root", , "root" , - , . , , . , 3, 4 5, -, , - , . , , . , 304 , - . fsck - . . - , , , - (. bmap 4) - . - , , , , , . , ( ), , , . , , - , . , , , , - , , . , - , , . . - - , , , , . , 1 , . , . , - , - , . , 1 , - 1 . , - , , - . , - , . - , 10.8, , - 4096 , 1 , , - , - , , - . , - , - . 10.3  , : . , , , . UNIX, , . - , , - ( , , 305 ) , ; , , , . - . , , - , . ("erase"; ), - . - , (*** *). ( , (*****)) , - . : * ; * ; * "", , - ; * , ; * , , ; * ; * , , . , , , , , - . , , - 70- , , (. [Ritchie 84], .1580). , , - . , , - , , - . 10.9 , , - , . , ioctl, , , , , , . 10.3.1  . (clist) . - --------------------------------------- (****) -, , , . (*****) " " - . 306 +-----------------------+ +-----------------------+ | / | | / | +-----------------------+ +-----------------------+ - | ^ - | ^ - v | - v | - +---------------------+ - +-----------------------+ | | | | - +---------------------+ - +-----------------------+ - | ^ - | ^ - v | - v | +-----------------------+ +---------------------+ | | | | +-----------------------+ +---------------------+ | ^ v | +-----------------------+ | - | +-----------------------+ | ^ v | +-------------------------+ | - | +-------------------------+ 10.9. - 0 1 2 3 4 5 6 7 8 9 14 ----------+---------+---------++-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+--- | 7 | 14 ||g|a|r|b|a|g|e||| |e|q|n| ||| |... ----+-----+---------+---------++-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+--- | v 10.10. (cblock) , - , - ( 10.10). , - . . 1. . 2. - . 3. : - , . - 307 , . , . 4. - , - . , - , . 5. , . 6. . , - , - , . . , - 10.11 ; ( 10.11-) , ( +-------+ +---+---+---+---+---+---+---+---+ +----->| 0 8 | | p | i | c | | f | i | l | e | | ++------+ +---+---+---+---+---+---+---+---+ | v | +-------+ +---+---+---+---+---+---+---+---+ +----------+-+ | | 0 8 | | * | | | | | t | b | l | | | 27 | +--+ ++------+ +---+---+---+---+---+---+---+---+ | | +--+ v +----------+-+ | +-------+ +---+---+---+---+---+---+---+---+ | | 0 8 | | | | | t | r | o | f | f | | | ++------+ +---+---+---+---+---+---+---+---+ | v | +-------+ +---+---+---+---+---+---+---+---+ +----->| 0 3 | | - | m | m | | | | | | +-------+ +---+---+---+---+---+---+---+---+ () +-------+ +---+---+---+---+---+---+---+---+ +----->| 1 8 | | | i | c | | f | i | l | e | | ++------+ +---+---+---+---+---+---+---+---+ | v | +-------+ +---+---+---+---+---+---+---+---+ +----------+-+ | | 0 8 | | * | | | | | t | b | l | | | 26 | +--+ ++------+ +---+---+---+---+---+---+---+---+ | | +--+ v +----------+-+ | +-------+ +---+---+---+---+---+---+---+---+ | | 0 8 | | | | | t | r | o | f | f | | | ++------+ +---+---+---+---+---+---+---+---+ | v | +-------+ +---+---+---+---+---+---+---+---+ +----->| 0 3 | | - | m | m | | | | | | +-------+ +---+---+---+---+---+---+---+---+ () 308 +-------+ +---+---+---+---+---+---+---+---+ +----->| 2 8 | | | | c | | f | i | l | e | | ++------+ +---+---+---+---+---+---+---+---+ | v | +-------+ +---+---+---+---+---+---+---+---+ +----------+-+ | | 0 8 | | * | | | | | t | b | l | | | 25 | +--+ ++------+ +---+---+---+---+---+---+---+---+ | | +--+ v +----------+-+ | +-------+ +---+---+---+---+---+---+---+---+ | | 0 8 | | | | | t | r | o | f | f | | | ++------+ +---+---+---+---+---+---+---+---+ | v | +-------+ +---+---+---+---+---+---+---+---+ +----->| 0 3 | | - | m | m | | | | | | +-------+ +---+---+---+---+---+---+---+---+ () +-------+ +---+---+---+---+---+---+---+---+ +----->| 0 8 | | * | | | | | t | b | l | | | ++------+ +---+---+---+---+---+---+---+---+ +----------+-+ | v | 19 | +--+ +-------+ +---+---+---+---+---+---+---+---+ | | +--+ | 0 8 | | | | | t | r | o | f | f | | +----------+-+ | ++------+ +---+---+---+---+---+---+---+---+ | v | +-------+ +---+---+---+---+---+---+---+---+ +----->| 0 3 | | - | m | m | | | | | | +-------+ +---+---+---+---+---+---+---+---+ () 10.11. +-------+ +---+---+---+---+---+---+---+---+ +----->| 0 8 | | p | i | c | | f | i | l | e | | ++------+ +---+---+---+---+---+---+---+---+ +----------+-+ | v | 22 | +--+ +-------+ +---+---+---+---+---+---+---+---+ | | +--+ | 0 8 | | * | | | | | t | b | l | | +----------+-+ | ++------+ +---+---+---+---+---+---+---+---+ | v | +-------+ +---+---+---+---+---+---+---+---+ +----->| 0 6 | | | | | t | r | o | f | | | +-------+ +---+---+---+---+---+---+---+---+ () +-------+ +---+---+---+---+---+---+---+---+ +----->| 0 8 | | p | i | c | | f | i | l | e | | ++------+ +---+---+---+---+---+---+---+---+ +----------+-+ | v | 23 | +--+ +-------+ +---+---+---+---+---+---+---+---+ | | +--+ | 0 8 | | * | | | | | t | b | l | | +----------+-+ | ++------+ +---+---+---+---+---+---+---+---+ | v | +-------+ +---+---+---+---+---+---+---+---+ +----->| 0 7 | | | | | t | r | o | f | f | | +-------+ +---+---+---+---+---+---+---+---+ 309 () +-------+ +---+---+---+---+---+---+---+---+ +----->| 0 8 | | p | i | c | | f | i | l | e | | ++------+ +---+---+---+---+---+---+---+---+ +----------+-+ | v | 24 | +--+ +-------+ +---+---+---+---+---+---+---+---+ | | +--+ | 0 8 | | * | | | | | t | b | l | | +----------+-+ | ++------+ +---+---+---+---+---+---+---+---+ | v | +-------+ +---+---+---+---+---+---+---+---+ +----->| 0 8 | | | | | t | r | o | f | f | | +-------+ +---+---+---+---+---+---+---+---+ () +-------+ +---+---+---+---+---+---+---+---+ +----->| 0 8 | | p | i | c | | f | i | l | e | | ++------+ +---+---+---+---+---+---+---+---+ | v | +-------+ +---+---+---+---+---+---+---+---+ +----------+-+ | | 0 8 | | * | | | | | t | b | l | | | 25 | +--+ ++------+ +---+---+---+---+---+---+---+---+ | | +--+ v +----------+-+ | +-------+ +---+---+---+---+---+---+---+---+ | | 0 8 | | | | | t | r | o | f | f | | | ++------+ +---+---+---+---+---+---+---+---+ | v | +-------+ +---+---+---+---+---+---+---+---+ +----->| 0 1 | | - | | | | | | | | +-------+ +---+---+---+---+---+---+---+---+ () 10.12. 10.11); , . 10.12 , ; , 8 ( 10.12). 10.3.2  , , : , - , , , - , , - ( ) . ( 10.13), . , - . , , . , - , , - 310 +------------------------------------------------------------+ | terminal_write | | { | | ( | | ) | | { | | ( ) | | { | | | | , ; | | ( , - | | - | | ); | | ; /* */ | | } | | | | , | | : | | ..; | | } | | | | -| | , ; | | } | +------------------------------------------------------------+ 10.13. . , - , , - . - , - , - , , . , . - ; , , - . - , - , write. - , , - write, - , . , - write, - . , , . , , , write, - . , 10.14. 18 ; - ( sprintf) output, - i fork, . , - . 64 311 +----------------------------------------------------------------+ | char form[]=" "| | | main() | | { | | char output[128]; | | int i;