Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
158 views

Lions - Unix Operating System Source Code Level Six 197711

This document contains a list of UNIX operating system files and procedures. Some of the key files listed include sys.h, proc.h, user.h, io.h, buf.h, conf.h, bio.c and subr.c. Some of the key procedures listed include open, close, read, write, fork, exec, wait, sleep and malloc. This appears to be an alphabetized list of files and procedures that make up part of the UNIX operating system.

Uploaded by

abigarxes
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
158 views

Lions - Unix Operating System Source Code Level Six 197711

This document contains a list of UNIX operating system files and procedures. Some of the key files listed include sys.h, proc.h, user.h, io.h, buf.h, conf.h, bio.c and subr.c. Some of the key procedures listed include open, close, read, write, fork, exec, wait, sleep and malloc. This appears to be an alphabetized list of files and procedures that make up part of the UNIX operating system.

Uploaded by

abigarxes
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 110

.

UNIX
. OPERATING
SYSTEM
SOURCE .
CODE
LEVEL
SIX

I
~
The University of New South Wales
UNIX
OPERATING
SYSTEM
SOURCE
CODE

This booklet has been produced for students at the University


of New South Wales taking courses 6.602B and 6.6570.

It contains a specially edited selection of the UNIX Operating


System source code, such as might be used on a typical
PDP11/40 computer installation.

The UNIX Software System was written by K. Thompson and


D. Ritchie of Bell Telephone Laboratories, Murray Hill, NJ. It
has been made available to the University of New South Wales
under a licence from the Western Electric Company.

THIS INFORMATION IS PROPRIETARY AND IS TEE PROP-


ERTY OF BELL LABORATORIES, INC. IT IS TO BE USEr
BY AUTEORIZED BELL LABS EMPLOYEES ONLY. ITS RE-
PRODUC'I'ION OR DISCLOSURE TO UNAUTHORIZED PERSONS
EITHER ORALLY OR IN WRI'IING, IS PROHIBITED.
J. Lions
Department of Computer Science
The University of New South Wales.
November 1977 Second Printing
May 26 15:46 UNIX Operating System P roced'Jres Sorted Alphabetically Page 1

6746 access 3472 setsid 2855 nosYs 3439 setuid


6956 alloc 6181 setmdev 4999 ,".otavai 1 8201 sstty
0734 aretu: 3480 setpid 1771 nses 3949 signal
1012 backup: 3413 setswit 6577 nulldev 2066 sleep
7040 badblock 3452 getuid 2864 nullsys 3595 smdate
4856 bawrite 4136 srow 5765 open 6086 slT.o'Jnt
6585 bcopy 3420 stime 5804 openl 1293 splO:
4836 bdwrite 8165 stty 6702 openi 1297 spll:
5229 bfl'Jsh 7067 ialloc 6791 owner 1302 sp14:
5055 binit 1284 idle: 2416 panic 1303 sp15:
6415 bmap 7134 ifree 6517 passc 1308 spl6:
4754 bread 7276 iget 8669 pcclose 1313 51"17:
4773 breada 6922 iini t 8763 pcleader 3614 ssis
4869 brelse 4899 incore 8648 pcopen 5979 sslep
4809 bwrite 0895 incupc: 8748 pcoutP'Jt 6028 stat
8274 canon 5018 iodone 8739 pcpint 6045 statl
3538 chdir 6364 iomove 8682 pcread 3428 stime
3560 chiliad 4982 iowait 8719 pcrint 4016 stop
3575 chown 7344 iput 8710 pcstart 8183 stty
8234 cinit 3991 issis 8701 pcwrite 0827 subyte:
0676 clearses! 7414 itrunc 5259 phYsio 0826 suibyte:
3725 clock 7374 i'JPdat 7723 pipe 0860 s'Jiword:
5846 close 3630 kill 7862 plock 6144 s'Jmount
6643 closef 8055 klclose 2433 prdev 1739 ,'HJreS
6672 closei 8023 klopen 7882 prele 6811 suser
5038 clrbuf 8062 klread 2340 printf 0861 s'Jword!
1244 copyin! 8078 klrint 2369 printn 5196 swap
1252 COpyout! 8090 klsstty 4204 proc:·:mt 2178 swtch
0696 copyseg! 8066 klwrite 3667 profil 3486 sync
4094 co,'e 8070 k1:dnt 4043 psis 3845 timeout
6542 cpass 1393 Idiv! 3963 psisnal 3656 times
5781 creat 5909 link 4164 ptrace 2693 trap
2447 deverror 8879 Ipcanon 0967 putc! 2841 trap1
5096 devstart 8863 lpclose 2386 putchar 8535 ttread
0890 display! 8976 lpint 5731 rdwr 8486 ttr'strt
1319 dpadd! 8850 lpopen 5711 read 8505 ttstart
1327 dpcmp! 8986 lpoutput 6221 readi 8550 ttwrite
6069 d'JP 8967 lpstart 7758 readp 8333 ttYinput
1650 estabur 8870 lpwrite 0740 r'etu! 8373 ttyoutput
3020 e:·:ec 1401 lrem! 3205 re:-:it 8577 ttYstty
3219 e:dt 1410 lshift! 5123 rhstart 7689 uchar
2268 eNf>and 1550 main 542() rkaddr 6824 ufalloc
6847 falloc 7455 maknode 5451 rkintr 3510 unlink
8252 flushtty 2528 malloe 5476 rkread 7201 update
3322 for'k 5156 IT.apalloc 5440 rkstart 3270 wait
7000 free 5182 IT.apfree 5389 rkstratesy 2113 wakeup
6014 fstat 6326 mOl:·: 5483 rkwrite 7477 wdir
0815 fubyte! 2556 mfree 0889 savfp! 8217 wfl'Jshtty
08:L4 fuibyte! 6339 min 0725 sav'J! 5720 write
0844 fuiword! 5952 mknod 3354 sbreak 6276 writei
0845 fuword! 9016 mmread 7679 schar 7805 writep
4921 setblk 9042 mmwrite 194() sched 4433 :·:alloc
0930 setc! 7518 namei 5861 seek 4490 >:ccdec
5336 seterror 1826 newproc 3460 setsid 4398 >:free
6619 setf 3493 nice 2156 setpri 4368 :·:swap
7167 setfs 6566 node v 2134 set run
Maw 26 15:46 UNIX QperatinsSwstem Files and Procedures POIse 1

File paralT,.h 2369 printn File te)d:,.c 6045 stat:L 8023 1-<.1 open
File sYstm.h 2386 putchar 4368 ~<swap 6069 dlJP 8055 klclose
File ses.h 2416 F'anic 4398 )-(free 6086 smount 8062 kl T'ead
File proc.h 2433 prdev 4433 )·(alloc 6144 sumount 8066 klwrite
File 1J~;er.h 2447 deverror 4490 Nccdec 6181 setmdev 8070 khdnt
File 10w.5 File m311oc.c File buf.h File rdwT'i. c 8078 klrint
File m40.s 2528 malloc File conf.h (S22:t readi B090 k.l s~.=1tt.~
0676 .. cleal'ses: 2556 mfree File conf.c 6276 writei File ttw.c
0696 .. copwses: Fi I€,' res.h File bio.c 6326 ma)·( 8165 sthl
0725 _savu: File trap.c 4754 bT'ead 6339 min 81.83 sttw
0734 ._a retu: 2693 trap 477:3 breada 6364 iomove B201 ssttw
0740 _retu: 2841 trapl 4809 bwrite File s'Jbr.c 8217 wfllJshttw
0814 _fuibwte: 2855 nosws 4836 bdwrite 6415 blT,ap 8234 ci.nit
0815 _ fub!~te: 2864 nullsws 4856 bawrite 6517 passe 8252 flu~;httw
0826 .. suib!olte: File swsent.c 4869 brelse 6542 CP(3SS 8274 canon
0827 _subwte: File sws1.c 4899 incore 6566 nodev 8333 ttwinPlJt
0844 _flJiword: 3020 e)·(ec 4921. setblk 6577 nulldev 8373 ttwoutP'Jt
0845 .. fuwo I'd: 3205 re}dt 4982 i.owait 6585 bcop~~ 8486 ttrstrt
0860 .. suiword: 3219 e)dt 4999 notavail File fio.c 8505 ttstart
0861 _suword: 3270 wait 5018 iodone 6619 setf 8535 ttread
0889 _savfp; 3322 fOT'k 5038 clrbuf 6643 clo~;;ef 8550 tt.write
0890 _displa,d 3354 sbreak 5055 binit 6672 clQsei 85T7 ttWStt~1
0895 _incupc: File s~54.c 5096 devstart 6702 openi Fi ll? pc-.c-
ono _setc: 3413 setswit 5123 rhstart 6746 access 8648 pcopen
09b7 .. put.c: 3420 stime 5156 ITlapalloc 6791 owner' 8669 pcclose
1.012 .. back'Jp: 3428 stime 5182 IT,Clpfree 6811 suser 8682 pCT'ead
1244 _copwin: 3439 set'Jid 5196 swap 6824 ufallQc 870i. pcwT'ite
1252 _CQpwout: 3452 setuid 5229 bfllJsh 6847 falloc 8710 pcstal't
J.~o...t _idle! 3460 setsid 5259 ph~sio File alloc.c 8719 pCI'int
1.293 ._spl0: 3472 setsid 5336 seterror 6922 iinit 8739 pcpint
1297 _spu.: 3480 setpid File rk.c 6956 allQc 8748 PCO'.J"Lput
1302 _sp14: 3486 sY'nc 5389 rkstrate9w 7000 free 8763 pcl~~ad(i!r
1303 _sp15: 3493 nice 5420 rkaddr 7040 badblock File Ip.c
1308 _sp16: 3510 unlink 5440 rkstart 7067 ia110c 8850 lpopen
1.313 _sp17: 3538 chdir 5451 rkintr 7134 ifree 8863 lpclose
1317' _dPadO; 3560 l:hmud 5476 i"~:.i"2~d 716 7 getf'c. 8870 Ipwrite
1327 _dpcmp: 3575 chown 5483 rkwrite 7201 update 8879 Ipcanon
1393 _ldiv: 3595 smdate File file.h File iset.c 8967 Ipstart
1401 _lrefTI: 3614 SSi9 File filsws.h 7276 iset 8976 Iplnt
1410 _lshift: 3630 ki 11 File iroo.h 7344 iput 8986 Ipoutput
File mairo.c 3656 times File inode.h 7374 iupdat File mefTI+c
1550 main 3667 profil File sys2.c 7414 itrunc 9016 iTllT,read
1650 estab'JT' File clock.c 5711 read 7455 iTlaknode 9042 iTllT,wri te
1739 sure9 3725 clock 5720 write 7477 wdir
1771 nses 3845 timeout 5731 I'dwr File nami.c
File slp.c File sis.c 5765 open 7518 namei
1826 newproc 3949 sisnal 5781 creat 7b79 schar
1940 sched 3963 psisnal 5804 open1 7689 ,-,char
2066 sleep 3991 issis 5846 close File pipe.c
2113 wakeup 4016 stop 5861 seek 7723 pipe
2134 set run 4043 psis I::"lii\Q
...J7V7 1 inj.~. 7758 readp
2156 setpT'i 4094 core 5952 mknod 7805 writep
2178 swtch 4136 srow 5979 sslep 7862 plock
2268 e)·(pand 4164 ptrace File sys3.c 7882 prele
File prf.c 4204 proc}(mt 6014 fstat File tty.h
2340 printf File te)·(t .h 6028 stat File kl.c
Ma\,/ 26 15:46 UNIX Operating S\,/stem Defined S\,/mbols Page 1

5372 ARDY 0100 0489 EMFILE 24 5696 IREAD 0400 0160 PUSER 100 7975 TBDELAY 006000
7993 ASLEEP 0100 0496 EMLINK 31 5627 1SGID 02000 0158 PWAIT 40 2615 TBIT 020
7992 BUSY 040 0488 ENFILE 23 5694 1SGID 02000 2605 RO (0) 7984 TIMEOUT 01
8617 BUSY 04000 0484 ENODEV 19 7987 1SOF'EN 04 2606 R1 (-2) 7961 TTH1WAT 50
4584 B_ASYNC 0400 0468 ENOENT 2 5626 1SUID 04000 2607 R2 (-9) 7951 TT1PR1 10
4576 B_BUSY 010 0474 ENOEXEC 8 5693 ISUID 04000 2608 R3 (-8) 7962 TTLOWAT 30
4586 B_DELWRI 01000 0478 ENOMEM 12 5628 1SVTX 01000 2609 R4 (-7) 7952 TTOF'R1 20
4574 B_DONE 02 0493 ENOSF'C 28 5695 ISVTX 01000 2610 R5 (-6) 7963 TTYHOG 256
4575 B_ERROR 04 0480 ENOTBLK 15 5684 ITEXT 040 2611 R6 (-3) 0311 UBMAP 0170200
4579 B_MAP 040 0485 ENOTDIR 20 5680 IUPD 02 2612 R7 (1) 0308 UDSA 0177660
4577 B_PHYS 020 0490 ENOTTY 25 5683 IWANT 020 7971 RAW 040 0306 U1SA 0177640
4573 B_READ 01 0472 ENXIO 6 5630 IWRITE 0200 5094 RCOM 04 0304 U1SD 0177600
458:~ B_RELOC 0200 8612 EOF 3 5697 IWRITE 0200 8014 RDRENB 01 3706 UMODE 0170000
4581 B.. WANTED 0100 0467 EPERM 1 0165 KL 0177560 8614 RDRENB 01 2659 UMODE 0170000
4 ..cI,
-.,r)
.:.. B_WRITE 0 0497 EPIPE 3'1
"- 8008 KLADDR 0177560 8611 READING 2 2662 USER 020
0140 CANBSIZ 256 0495 EROFS 30 8009 KLBASE 0176500 5367 RESET 0 0103 USIZE 16
8840 CAP 01 8618 ERROR 0100000 7968 LCASE 04 5121 RHRCOM 070 7977 VTDELAY 040000
7990 CARR_ON 020 0494 ESPIPE 29 8812 LF'ADDR 0177514 5120 RHWCOM 060 8610 WAITING 1
7955 CEOT 004 0469 ESRCH 3 8819 LPHWAT 100 5363 RKADDR 0177400 5093 WCOM 02
8818 LPLWAT 50 0315 RO 02 5373 WLD 020000
7'154
7958
CERASE
CINTR
'*'
0177
0491
7973
ETXTBSY
EVENP
26
0200 8817 LF'PRI 10 0106 ROOTINO 1 0316 WO 04
7956 CKILL '@' 0483 EXDEV 18 8821 MAXCOL 80 2613 RPS (2) 7985 WOPEN 02
1509 CLOCKl 0177546 3018 EXPRI -1 0135 MAXMEM (64*32) 0317 F~W 06 7967 XTABS 02
1510 CLOCK2 0172540 8847 FORM 014 0130 NBUF 15 3707 SCHMAG 10
B609 CLOSED 0 5519 FPIPE 04 0143 NCALL 20 2660 SETD 0170011
0141 CMAPSIZ 100 5517 FREAD 01 0146 NCLIST 100 0385 SIDL 4
7957 CaUIT 034 5518 FWRITE 02 8012 NDL11 0 0123 SIGBLJ~; 10
7976 CRDELAY 030000 5095 GO 01 0134 NEXEC 3 0120 SIGEMT 7
7970 CRMOD 020 5368 GO 01 0132 NFILE 100 0121 SIGFPT 8
5374 CTLRDY 0200 7966 HLJPCL 01 0131 NINODE 100 01:l4 SlGHUP 1
0107 DIRSIZ 14 0147 HZ 60 8011 NKL:ll 1 O:L17 SlGINS 4
8010 DLBASE 0175610 5681 IACC 04 7974 NLDELAY 001400 0115 SIGINT 2
7980 DONE 0200 5620 IALLOC 0100000 0133 NMOUNT 5 0119 SIG10T 6
fl616 DONE 0200 5687 IALLOC 0100000 0105 NODEV (-1) 0122 SIGKIL 9
B815 DONE 0200 5092 IENABLE 0100 0139 NOFILE 15 0126 SIGPIPE 13
5369 DRESET 014 5370 IEN~IBLE 0100 0144 NPROC 50 01:L6 SIGCHT 3
5371 DRY 0200 7981 IENABLE 0100 5364 NRK 4 0124 SIGSEG 11
Bon DSRDY 02 8615 IENABLE 0100 5365 NRKBLK 4872 0125 SIGSYS 12
0473 E2BIG 7 8814 IENABLE 0100 0113 NSIG 20 01:L8 SIGTRC 5
0479 EACCES 13 5631 IEXEC 0100 0145 NTEXT 40 0138 SINCF~ 20
0477 EAGAIN 11 5698 IEXEC 0100 0104 NULL 0 0391 SLOAD 01
0475 EBADF 9 5624 IFBLK 060000 7972 ODDP 0100 0393 SLOCK 04
2658 EBIT 1 5691 IFB~K 060000 8843 OPEN 04 0142 SMAPSIZ 100
0481 EBUSY 16 5623 IFCHR 020000 B607 F'CADDH 0177550 0384 SRUN 3
0476 ECHILD 10 5690 IFCHR 020000 8624 F'CIHWAT 250 OB7 SSIZE 20
7969 ECHO 010 5622 IFDIR 040000 B620 PCIPRI 30 0382 SSLEEP 1
0318 ED 010 5689 IFDIR 040000 8623 PCOHWAT 100 798B SSTART 010
0482 EEXIST 17 5621 IFMT 060000 B622 PCOLWAT 50 0387 SSTOF' 6
0466 EFAULT 106 5688 IFMT 060000 8621 F'COF'RI 40 0394 SSWAP 010
0492 EFBIG 27 5625 ILARG 010000 0155 F'INOD --9() 0392 SSYS 02
0470 EINTR 4 5692 ILARG 010000 7715 F'IPSIZ 4096 0395 t,TRC 020
0487 EINVAL 22 5679 I LOCI":: 01 0157 F'F' I F'E 1 0166 ~3W 0177570
0471 EIO 5 5682 IMOUNT 010 0156 F'RIBIO -50 0383 SWAIT 2
0486 EISDIR 21 8844 IND 010 0164 F'S 0177776 0396 SWTED 040
8842 EJECT 02 3914 IPCPRI (-1) 0159 PSLEF' 90 2661 SYS 0104400
8820 EJUNE 60 5629 IREAD 04()0 0154 PSWP -100 0386 SZOMB 5
May 26 15:45 UNIX Operatin~ System Source Code Cross Reference Listin~ Pa~e 1

aa 2556 2563 bawrite 4845 4856 6310 buffers 4720 5067 5071 5079
abae 5123 5125 5134 bcopy 3238 6124 6585 6931 BUSY 7992 8617 8691 B... MAP 4579 5024 5172 5186
abn 7040 7046 6976 7019 7220 7636 bwrite 3239 4809 4863 4963 B_PHYS 4577 5206 5299 5397
abp 5156 5157 5171 5259 bdevsw 4617 4622 4656 4763 5241 7021 7221 7400 B_READ 2034 2042 4573 4761
5260 5268 5336 5337 4785 4795 4819 4843 3049 3153 3238 3290 4783 4793 4817 5111
5341 5389 5390 5396 4906 4934 5060 5076 4529 5044 5067 5107 5140 5479 6260
8333 8340 8373 8382 5212 6113 6166 6689 5136 5210 5305 5307 B_F:ELOC 4583 4966
access 3041 3552 4109 5815 6722 6926 6052 6124 6125 6371 b_T'esid 4533 5322
5817 6746 7563 7604 bdp 5060 5076 5077 6437 6473 6491 6931 B_WANTED 4581 4876 4878 4879
7658 bdwrite 4836 6311 6443 6449 6935 6974 7017 7098 4887 4942 4954 5030
addr 8024 8039 8041 8043 6485 6500 6501 7174 7212 7220 7328 5166 5187 5203 5216
8044 8051 8052 8079 bflg 1049 1060 1094 1108 7387 7427 7432 7433 5219 5296 5318 5321
8082 8083 8084 8086 1204 1238 7636 4528 4762 4784 4794
8508 8513 8515 8518 bflush 5229 7230 4584 4793 4820 4862 4818 5108 5137 5208
8522 bfreelis 4567 4878 4879 4880 4887 4962 5027 5239 5310
ad(~v 4773 4778 4785 4795 4884 4891 4932 4953 4524 4556 4967 4968 4572 5486 6306 6373
4899 4905 4906 4954 4955 4960 5062 4970 4971 5062 5068 6386
2344 2346 2355 2357 5063 5068 5069 5070 5070 5080 4530 5110 5134 5139
2361 5071 523~j 2454 4531 4908 4938 5173 5178 5211 5308
afp 7040 7045 bi~~er 3375 3386 4974 5209 5309 5402 call 0555 0558 0561 0564
ai.p 6221 6222 6229 6276 binit 1614 5055 5428 6442 6450 6470 0567 0570 0574 0577
6277 6284 6746 6747 blkno 4754 4758 4773 4780 6484 6498 0752 0776 2669 2771
6751 4781 4799 4899 4908 4576 4887 4941 4966 calli 0762 0771
alloe 6435 6448 6468 6480 4921 4938 4974 5196 5010 5072 5165 5169 callo 0260 3727 3847
6497 6956 5209 5202 5206 5219 5295 callout 0265 3748 3750 3767
an 6364 6370 6248 6298 6415 7626 5299 5321 3768 3773 3853
ARDY 5372 6958 6967 6968 6970 B_.DELWRI 4586 4817 4823 4847 callp 2696 2754 2755 2761
aret'.1 0724 0734 2106 2242 6973 6981 7000 7008 4961 5237 2762 2765 2771
ar!:! 3845 3871 7016 7025 2453 4527 4819 4843 CANBSIZ 0140 0202 8316
ASLEEP 7993 8224 8562 bpi 8278 8319 8322 4883 4908 4938 4973 canon 8274 8543
atp 8217 8218 8221 8252 bread 3282 4754 4799 6051 5066 5207 5238 5300 canonb 0202 8291 8300 8316
8253 8257 8274 8275 6116 6258 6305 6472 5399 5429 5431 8320
8282 8333 8334 8339 6488 6927 6973 7097 4574 4759 4782 4790 8840 8884
8486 8490 8505 8506 7319 7386 7426 7431 4817 4847 4989 5026 7990 8046 8285 8541
8512 8535 8536 8540 7625 5214 5315 8556
8550 8551 9555 8577 b!'e~d? 477~ 6256 b_error 4532 eblock 8140 8141 8146 8149
8578 8581 brelse 3195 3298 4791 4822 B_ERROR 4575 4817 4882 5220 8237
8577 8578 8582 4848 4869 5028 5073 b_error 5311 cc 8635 8731 8743 8754
4526 4884 4889 5008 6062 6118 6129 6172 B_ERROR 5342 8830 8981 8988
5009 5063 6261 6308 6481 6487 b_error 5343 ccc 8835 8910 8918 8935
av_forw 4525 4888 4891 4953 6503 6932 6977 7112 B_ERROR 5403 5467 7323 8937 8941 8942 8946
4960 5008 5009 5063 7324 7332 7436 7440 b_ fla~s 4522 4759 4761 4782 8950 8954 8955 8962
5235 5236 5407 5412 7602 7624 7656 4783 4790 4793 4816 ccp 8236 8239 8240 8244
5470 buf 4520 4523 4524 4525 4817 4847 4862 4876 8246 8247
backp 4872 4884 4888 4889 4526 4535 4555 4556 4878 4879 4882 4887 cdevsw 4635 4641 4669 6234
4890 4557 4558 4567 4721 4941 4942 4954 4961 6287 6685 6716 8213
backup 1009 1012 1015 1047 4756 4775 4810 4812 4962 4966 4989 5010 8238 8245
2812 4837 4839 4857 4859 5024 5026 5027 5030 cdp 8238 8245
badblock 6970 7008 7040 4870 4872 4902 4923 5072 5111 5140 5172 CEOT 7955 8306
badtrap 1465 1468 4983 4985 5000 5002 5186 5200 5237 5239 CERASE 7954 8048
6419 6437 6439 6473 5019 5021 5057 5065 5295 5296 5299 5315 cf 8636 8831
6479 6484 6491 6497 5097 5101 5124 5128 5318 5321 5342 5397 efree 8146 8239 8240
6499 6506 5157 5160 5183 5231 5403 5467 7323 cfreeli 0928 0954 0955 0977
base 5264 5269 5273 5278 5260 5263 5337 5339 4523 4555 4907 4937 0979· 0986 0988
5291 5305 5306 5307 5387 5390 5392 5421 4967 4968 4969 4971 cfreelis 8149 8241 8242
5308 5423 5442 5453 6365 4972 5062 5069 5070 chan 2066 2076 2089 2113
Maw 26 15:45 UNIX Operating Swstem Source Code Cross Reference Listing Page 2

2118 8379 8424 8426 8440 6250 6252 6256 6258 6551 7695
chdir 2924 3538 8441 8445 8452 8453 6281 6300 6302 6304 EFBIG 0492 6424
chlllod 2927 3560 8468 8469 8472 6305 EINTI:;; 0470 2773
choloJrl 2928 3575 0222 2141 2165 2224 DONE 7980 8518 8616 8691 E1NVAL 0487 3620 6157
cinit 161.3 8234 0263 3770 3776 3866 8714 8815 8971 E10 0471 4193 5344 8751
CINTR 7958 8344 8345 3871 dpadd 1318 1319 3292 3293 8854
CKILL 7956 8049 7910 8074 8223 8349 3295 3296 5756 5890 E1SDIR 0486 5819
c1 8637 8832 8543 8544 8560 5895 5986 6382 9051 EJECT 8842 8857 8923 8927
clearseg 0675 0676 1566 3134 c_cf 7911 dpclllP 1326 1327 5988 5989 EJLINE 8820 8927
3395 4155 c_cl 7912 5990 6243 6312 eloop 7592 7643 7647
cli.st 7908 7928 7929 7930 c_func 0264 3748 3751 3769 DRESET 5369 EMFILE 0489 6833
8634 8643 8644 3770 3774 3855 3861 DRY 5371 EMLINK 0496 5918
cl.ock 0569 0570 3725 3865 3870 DSRDY 8013 8051 end 0611 0632 0654
CLOCK1 1509 1601 c_ne:·:t 8141 8241 dUIllP 0521 0523 1352 1353 ENFILE 0488 6863 7311
CLOCK2 1510 1603 c_time 0262 3751 3753 3767 1355 ENODEV 0484 6569
cloop 7542 7667 3769 3775 3855 3856 2953 6069 ENOENT 0468 7538 7612
close 2918 5846 3859 3864 3869 4557 5409 5410 5444 ENOEXEC 0474 3102
CLOSED 8609 8653 8675 dey 2433 2436 2693 2700 5457 5470 ENOMEM 0478 1728
closef 3230 5854 6643 2702 2718 3725 4754 4553 5414 5446 5455 ENOSPC 0493 6989 7121
c1osei. 6656 6672 4758 4763 4776 4778 5458 ENOTBLK 0480 6190
clrbuf 5038 6982 4780 4781 4788 4789 4558 5412 5413 ENOTDIR 0485 3547 7560
CMAPSIZ 0141 0203 4799 4901 4905 4908 4619 4637 6166 6685 ENOTTY 0490 8210
colp 8378 8400 8401 8402 4921 4927 4931 4934 6689 ENXIO 0472 6193 6727 8027
8404 8423 8429 8435 4938 4973 5229 5238 d_errcnt 4554 5463 5469 8654
8436 8442 8443 8448 5259 5300 5476 5479 d_llIaJor 2436 4606 4763 4785 EOF 8612 8689 8728
8454 8458 8459 8475 5483 5486 6676 6679 4795 4819 4843 4906 ep 7418 7432 7433 7434
COlli 5102 5109 5112 5114 6685 6689 6706 6709 4927 4934 6113 6166 7435
5115 5i29 5138 5141 6716 6722 6956 6961 6192 6234 6287 6680 EPERM 0467 6816
5142 5143 6970 6973 6981 6988 6710 6926 8213 EPIPE 0497 7827
cont 7106 7110 7000 7004 7008 7016 2436 4605 4883 5399 EROFS 0495 6755
copsu 1245 1253 1264 7040 7048 7067 7072 5429 5431 8026 8030 err 0855 0872 0880 1656
copwin 124:5 1244 6374 7078 7097 7104 7120 8039 8040 8042 8057 1658 1661 1663 1727
CC)P!:lout 1243 1252 1630 6376 7134 713tl 7167 7173 8063 8067 8072 8081 error 4219 4226 4234 4241
C()p~jse~~ 0695 0696 1915 2292 7178 7276 7286 7296 8093 9021 9031 9047 4248 4260 4281
3380 3392 4152 7314 7319 tl023 8026 9064 ERRDR 8618 8691 8722 8727
core 4076 4094 8030 8033 8039 8040 4618 4636 5076 6113 8750
coreaddl' 51.96 5210 5211 8042 8055 8057 8062 6716 6722 6926 8245 esc 8891 8895 8899 8903
corelllap 0203 1568 1896 1982 8063 8066 8067 8070 d_read 4638 6234 8908
2278 2282 2293 3241 8072 8078 8081 8090 d_sstt!:l 4640 8213 ESPIPE 0494 5870
4383 4497 8093 8648 8669 8850 d_strat,e 4620 4763 4785 4795 ESRCH 0469 3652 4177
. count 2668 2762 2765 5196 8863 9016 9021 9031 4819 5212 estabur 1629 1650 3118 3138
5208 6585 6592 9042 9047 9064 4621 4843 4906 4934 3152 3371 4120 4146
cpl 7480 7483 7485 devbll<. 5096 5106 5123 5135 5077 4460
cp2 7480 7484 7485 deverror 2447 5460 d_write 4639 6287 ETXTBSY 0491 3106 6759
CF'ass 6388 6542 8558 8705 devioc 5096 5098 5104 5123 E2BIG 0473 3064 EVENP 7973
8874 9057 5125 5131 EACCES 0479 6778 EXDEV 0483 5937
0208 1459 1461 1571 devstart 5096 5447 EAGAIN 0477 :3330 e:-:ec 2923 3020
1655 1746 1756 5133 devtab 4551 4840 4903 4924 EBADF 0475 5740 6630 e:·:ecnt 0210 3037 3038 3039
5162 5058 5386 EBIT 2658 2753 2776 3196 3197 3198
CQUIT 7957 tl344 DIRSIZ 0107 0429 0433 3524 EBUSY 0481 6135 6163 e:dt 3209 3219 4032 4080
CRDELAY 7976 3526 7484 7486 7572 ECHILD 0476 3317 427B
ereat 2920 57tll 7576 7589 7608 7637 ECHO 7969 8047 836:1. e:·:pand 1628 2268 3129 3132
cret 1429 1430 7638 7645 ED 0318 1711 3383 3387 4148 4459
CRMOD 7970 8047 8342 8412 displaw 0888 0890 3740 edata 0611 0651 4473
csv 1419 1420 DLBASE 8010 8043 EEXIST 0482 5930 5960 EXF'RI 3018 3038
CTLRDY 5374 5462 dn 6226 6243 6245 6247 EFAULT 0466 5326 6378 6524 falloc 5827 6847 7731 7737
Maw 26 15:45 UNIX Operatins·Swstem Source Code Cross Reference ListinS PaSe 3

fetch 1051 1173 1180 1184 5889 5890 5901 5902 IFMT 3041 3522 3546 4110 3937 4185 4218
4220
1222 6858 6859 7772 7773 5621 5688 5818 5921 4225 4227 4232
4240
ff 4368 4382 7774 7796 7798 6189 6233 6242 6286 4242 4247 4249
4254
file 5507 5513 5807 6849 setblk 3040 3237 4758 4781 6297 6682 6711 7559 3938 4184 4191
4220
6854 8204 4789 4921 6123 6304 8209 4227 4235 4242
4249
filsws 5561 7042 6928 6981 7016 7216 ifree 7134 7355 4264 4266 4268
4273
flag 4813 4816 4820 ..'.823 £ietc 0930 8259 iset 1616 1618 ~5519 7078 3935 4181 4183 4194
6364 6373 6386 7518 8264 8292 8520 8544 7276 7534 7664 4209
7537 7603 7657 8023 8673 8688 8714 8971 iinit 1615 6922 3936 4186 4189 4192
8648 8652 8669 8671 Seterror 4824 4992 5323 5336 ILARG 5625 5692 6427 6444 4211 4212 4282
8833 8850 8853 8857 Setf 5736 5850 5866 6018 7425 7445 IREAD 5629 5696 5815 6651
8863 8866 8884 8923 6073 6619 8206 IL.OCI( 1617 1619 5679 5926 7789 7850 7851
8927 8936 setfs 6754 6961 7004 7072 7224 7225 7287 7303 ISGID 3176 5627 ~j694
fllJshttw 8227 8252 8346 8350 7138 7167 7383 7316 7351 7868 7872 ISOPEN 7987 8045 8046
fmt 2340 2341 2348 2353 setsid 2959 3472 7888 :issis 2073 2085 2821 3826
fork 2914 3322 setmdev 6093 6151 6181 IMOUNT 5682 6130 6168 7292 3991
FORM 8847 8859 8865 8921 Setpid 2932 3480 incore 4780 4788 4899 ISUID 3171 5626 569:~
8928 8930 setswit 2950 3413 incupc 0894 0895 3791 ISVTX 3568 4406 5628 5695
found 3329 3333 4176 4180 setuid 2936 3452 IND 8844 8857 8936 5790
6156 6160 sid 3462 3464 3465 3466 info 8142 ITEXT 3105 4410 4471 5684
foundl 1994 2021 3467 ino 7070 7077 7078 7095 6758
fClund2 1983 2031 GO 5095 5109 5138 5368 7100 7105 7107 7134 i trlJnc 4112 5825 7353 7414
FPIF'E 5519 5746 5869 6649 5461 7143 7276 7286 7297 IUPD 3530 3570 3583 5680
7746 7748 srow 2813 4056 4136 7315 7319 7328 5942 6285 6318 6452
FREAD 5517 5713 5747 5753 stirlle 2925 3420 inode 5605 5659 5675 6147 6467 7382 7396 7448
5814 5829 7748 sttw 2944 8165 6161 6222 6227 6277 7462 7609 7751
fl'ee 7000 7435 7438 7442 sword 0818 0830 0848 0851 6282 6416 6793 7104 ilJpdat 6050 7226 7357 7374
frolll 6585 6586 6590 hbcom 5096 5109 7105 7203 7223 7278 IWANT 5683 7288 7869 7889
fstat 2940 6014 hibwte 0180 3456 3476 3582 7285 7345 7521 8205 7890
fub!olte 0807 0815 3058 4225 8585 8593 inta 3921 4235 4254 IWRITE 4109 5630 5697 5817
6550 7693 httab 4728 4844 intes 0175 2070 2095 2391 6651 6753 7604 7658
fl.lib!olte 0809 0814 1564 4218 HUPCL 7966 3416 3852 3872 4885 7776 7777 7836
9034 HZ 0147 3797 3800 4892 5006 5011 8262 5613 5672 5969 6191
fui.word 0813 0844 1602 1604 IACC 5681 6232 6285 7382 8266 6192 6234 6252 6287
2734 2754 2756 2766 7391 7462 7751 10 0641 1455 6302 6439 6440 6442
!ALLOC 5620 5687 i~d~~~ S(H8 SA{)A 5.1171 64.117 6451 6456 6466
fun 3845 3870 ialloc 7067 7459 iomove 6260 6306 6364 6470 6679 6680 6709
func 7518 7519 7532 7536 IALLOC 7463 iowait 4764 4800 4821 4982 6710 7082 7330 7389
7574 7579 8510 8515 ialloc 7728 ipc 3939 4181 4182 4183 7423 7430 8213
fuword 0811 0845 0847 2758 IALLOC 7752 4184 4185 4186 4189 i_atime 5614
2763 3052 4227 8188 icode 1516 1630 4190 4191 4192 4194 i_colJnt 1883 3105 4472 5662
8189 8190 idle 1283 1284 2220 2423 4195 4209 4211 4212 6100 6681 7302 7306
FWRITE 5518 5722 5793 5795 IENABLE 5092 5109 5138 5370 4213 4218 4220 4225 7317 7350 7362 7750
5816 5829 5832 6656 7981 8051 8052 8615 4227 4232 4235 4240 7787 7825
7746 8659 8663 8692 8732 4242 4247 4249 4254 3519 5663 5935 6051
1878 5510 5836 6079 8814 8858 4264 4266 4268 4273 6053 6162 6250 6300
6655 6657 6855 6857 IEXEC 3041 3552 5631 5698 4282 6422 6754 7104 7286
7739 6764 6765 7563 IPCF'RI 3914 4182 4190 7314 7355 7383 7386
5509 5739 5746 5829 IFBLK 5624 5691 6100 6189 iput 3194 3232 3533 3534 7426 7431 7435 7438
5869 6649 6656 7746 6242 6297 6314 6688 3549 3554 3571 3584 7442 7459 7534 7625
//~o 4126 4411 5839 5931 7662
f_inode 5511 5754 5755 5830 IFCHR 5623 5690 6100 6233 5936 5945 5972 6037 1617 1619 3105 3530
5894 5895 6021 6650 6286 6314 6684 6713 6137 6169 6194 6691 3570 3583 4410 4471
6656 7747 7749 7764 7421 8209 6802 7091 7325 7344 5661 5926 5942 6130
7810 8208 IFDIR 3522 3546 5622 5689 7490 7663 7670 7733 6168 6232 6285 6318
f_offset 5512 5751 5752 5756 5818 5921 7559 7741 6452 6467 6758 7224
Ma~ 26 15:45 UNIX Operating S~stem Source Code Cross Reference listing Page 4

7225 7287 7288 7292 klread 4671 8062 lpsr 8824 8853 8858 8971 2542 2564 2565 2566
7303 7316 7351 7359 klregs 8016 Ipstart 8967 8980 8992 2568 2569 2572 2576
7382 7391 7396 7448 klrint 0557 0558 8078 Ipwrite 4675 8870 2578 2583 2584
7462 7609 7751 7868 kIsstt~ 4671 8090 Irem 1400 1401 2375 5433 namei 3034 3515 3543 4101
7869 7872 7888 7889 kltbuf 8020 8086 6052 7328 7387 5770 5786 5914 5928
7890 kItcsr 8019 8052 lshift 1409 1410 5309 6239 5958 6033 6097 6186
Lsid 3177 3582 5610 5669 kIwrite 4671 8066 6294 9024 9055 6796 7518
6771 7466 kb:int 0560 0561 8070 main 0611 0669 1550 nblkdev 4631 4927 5084 6192
i._Iastr 5673 6255 6259 7318 I<.wlp 0534 0535 0570 maknode 4105 5790 5966 7455 6720
i_mode 3041 3171 3176 3522 large 6445 6462 ITlalloc 1896 1982 2282 2528 NBUF 0130 4535 4720 5064
3546 3566 3569 4110 Ibn 6225 6239 6248 6255 3234 4375 4457 NCAll 0143 0265
4406 5607 5666 5818 6259 2515 2529 2532 2557 nchrdev 4647 6714 8247
5921 6100 6189 6233 IbC)lt 0212 3797 3800 3808 2559 NCLIST 0146 8146 8240
6242 6286 6297 6314 4925 8650 8660 mapaIIoc 5156 5398 NDl11 8012 8015 8026
6427 6444 6651 6682 lCASE 7968 8047 8309 8353 ITlapfree 5025 5182 newproc 1627 1826 3334
6711 6764 6774 7081 8399 maplock 5155 5165 5166 5167 newsize 2268 2275 2277 2278
7082 7329 7354 7388 Idiv 1392 1393 2373 4143 5169 5187 5188 5189 2282
7421 7425 7445 7463 5434 6051 7319 7386 8117 8309 8311 NEXEC 0134 3037 3196
7559 7752 7776 7777 7589 7626 ma}! 6326 8443 NFIlE 0132 5513 6854
7789 7836 7850 7851. li.nk 2921 5909 MAXCOl 8821 8954 nice 2946 3493
8209 Iks 0226 1601 1602 1603 MAXMEM 0135 NINODE 0131 5675 6161 7103
i_mtime 5615 1604 1607 3734 ma:{mem 0224 1567 1576 7223 7285
L.nIink 3529 5608 5667 5917 IC)b~te 0180 3443 3444 3455 MAXMEM 1582 NKl11 8011 8015 8026 8042
5941 7352 7464 3464 3465 3475 3581 ma:·(mem 1582 1662 8043
5664 6051 6052 6162 8584 8592 mcc 8834 8924 8925 8950 NlDElAY 7974
7105 7286 7315 7355 loop 1951 1957 1969 2025 8952 8955 8957 8960 NMOUNT 0133 0277 6103 6154
7360 7385 7482 7534 2048 2195 2221 2347 mfree 1568 1583 2044 2278 7172 7210 7294
5611 5670 5894 6243 2362 3245 3260 3276 2293 2556 3241 3283 NODEV 0105 3040
6312 6315 7446 3315 4020 4030 4930 4383 4408 4497 nodev 4659 4660 4661 4662
5612 5671 5895 6243 4945 4957 4964 5233 min 1582 6241 6247 6296 4663 4664 4665 4673
6312 6316 7447 7589 5242 7075 7092 7119 6339 7846 4675 4677 4678 4679
7772 7775 7835 7845 7283 7290 7298 7765 IlIknod 2926 5952 4680 4681 4682 4684
3173 3174 3581 5609 7791 7812 7839 7854 ITI1e 8836 8924 8926 8927 4686 4687 4688 4689
5668 6769 6798 7465 8290 8305 8931 4690 4691
.i 7070 7099 7101 Ipll 8837 8853 8857 8866 III ITt read 4682 9016 NODEV 5238 6123
.ifls 1.018 1193 1239 8884 8910 8918 8923 IlImwrite 4682 9042 nodev 6566
k 7070 7103 7104 7105 8924 8925 8926 8927 Illode 5731 5735 5804 5812 NODEV 6928 7230
ka6 0322 1459 1460 1560 8931 8935 8936 8937 6746 6752 7455 7463 nofault 0757 0766 0854 0855
1589 1599 2716 9032 8941 8942 8946 8950 ITlount 0272 0277 6090 6103 0871 0872 0876 0881
9065 8952 8954 8955 8957 6148 6154 6933 6934 0909 0910 0918 1224
kill 2949 3630 8960 8962 8971 8981 7169 7172 7204 7210 1225 1228 1232 1259
KISAO 0619 1447 8982 8988 8989 8990 7281 7293 7294 1267 1273 1277 1465
KISA6 0743 1368 1448 1460 lPADDR 8812 8853 8858 8971 ITIPid 0216 1841 1842 1843 1466
KI!JDO 0620 1449 8972 1849 1867 NDFIlE 0139 0438 1876 3227
KL. 01.65 2393 2397 2398 Ipbuf 8825 8972 1373 1450 6624 6828
2399 2406 Ipcanon 8859 8865 8875 8879 2518 2536 2537 2541 nospace 6966 6969 6986
k1.1.1. 8015 8030 8057 8063 8909 2564 2565 2567 2571 nos~s 2855 2939 2941 2945
8067 8072 8081 8093 Ipclose 4675 8863 2576 2577 2580 2581 2951 2952 2957 2961
KlADDR 8008 8039 8041. lPI-lWAT 8819 8988 0275 6104 6123 6124 2962 2963 2964 2965
KlBASE 8009 8041 8043 Ipint 0573 0574 8976 6125 6155 6170 6171 2966 2967 2968 2969
klclose 4671. 8055 IF'LWAT 8818 8981 6933 7173 7174 7211 2970 2971 2972 2973
klin 0526 0558 Ipopen 4675 8850 7212 2974 2975
klC)pen 4671 8023 Ipou 0541 0574 lTt_dev 0274 6105 6122 6155 notavail 4948 4960 4999 5240
klou 0527 0561 Ipoutput 8929 8951 8956 8959 6934 7173 7216 7296 NF'ROC 0144 0376 1846 1960
kl rblJf 8018 8083 8986 lTt_inodp 0276 6121 6167 7295 1991 2006 2120 2203
klrcsr 8017 8051 8084 lPF'RI 8817 8989 ITt_size 2517 2534 2535 2538 2206 3246 3250 3277
Ma~ 26 15:45 UNIX OperatinS S~stem Source Code Cross Reference Listin~ Pase 5

3327 3639 3810 3953 PCOPRI 8621 8755 0783 0787 0790 0798 4022 4024 4175
4023 4172 PCOIJ 0531 0567 0852 0853 0869 0870 0362 2078 2091 2141
nps 2693 3725 PC out 8644 8714 8743 8744 0877 0882 0932 0934 2167 2209 2211 3817
NRK 5364 8754 8755 8756 0935 0958 0964 0970 0363 3287 3305 3625
NRKBLK 5365 5402 PCOIJtPIJt 8706 8748 8769 0973 0974 0999 1005 3626 3971 3972 3997
r,seS 1657 1660 1771 3366 pcpbuf 8630 8715 1285 1286 1288 1294 4000 4049 4050 4273
NSIG 0113 0447 3183 3225 pcpcsr 8629 8663 8 ...., .......
·" 8750 1298 1299 1304 1305 0372 1590 1893 1895
3619 3968 pcpint 0566 0567 8739 1309 1310 1314 1444 1978 2042 2044 2274
nswap 0232 1583 4698 pcrbuf 8628 8730 2070 2095 2275 3241 4119 4148
NTEXT 0145 4314 4441 pcrcsr 8627 8659 8674 8691 PS 2693 2699 2717 2753 4149 4374 4375
rolJl1dev 4658 4682 4684 6577 8692 8722 8727 8732 2776 3725 3759 3788 0360 1591 1847 1861
nulls~s 2864 2912 2942 pcread 4673 8682 3798 3824 1903 1908 1961 1993
ODDP 7972 pcrint 0563 0564 8719 PS 3852 3872 4885 4892 2008 2077 2090 2140
el", 4256 4259 4261 pcstart 8710 8742 8758 5006 5011 8262 8266 2208 3243 3253 3280
on 6225 6240 6241 6260 pcstate 8642 8653 8657 8658 psi~ 2074 2086 2105 2822 3284 3301 3328 3811
6280 6295 6296 6306 8675 8689 8721 8724 3827 4043 3973 3974 3975 4026
9018 9025 9034 9044 8726 8728 psisnsl 2793 2818 3649 3955 4173
9056 9067 pcwrite 4673 8701 3963 7828 0374 1752 1866 1879
of'en 2917 5765 ph~sio 5259 5479 5486 PSLEP 0159 5994 1979 2032 4378 4401
OPEN 8843 8853 8857 PINOD 0155 6963 7007 7074 F'SWP 0154 1955 1968 5167 4402 4448 4469
of'en:L 5774 5793 5795 5804 7289 5204 5215 0365 1869 1962 1964
of'eni 5832 6702 piPE! 2954 7723 ptrsce 2938 4164 2009 2011 2047 3812
outl 6119 6136 F'IPSIZ 7715 7835 7846 F'USER 0160 2162 3817 3973 3813 4386
elwner 3564 3579 6791 plock 7768 7815 7862 3974 0368 1864 3288 3644
F'sd 5575 F'F'IPE 0157 7790 7838 7870 putc 0926 0967 8323 8355 3954 8031 8032
panic 1605 1853 2051 2416 prdev 2433 2453 6988 7048 8358 8414 8478 8730 0364 1863 3174 3446
2719 3236 3521 4377 7120 7178 8756 8990 3646
4381 4451 4458 4928 prele 3518 3556 5826 6131 PIJtchar 2351 2359 2375 2386 0373 2076 2089 2122
4936 6930 7184 7300 7227 7358 7363 7786 2401 2402 2403 2405 2139
F'ilnicstr 2328 2419 7799 7817 7826 7837 PWAIT 0158 3314 3221 3225 3226 3227
F'iII'tab 7947 8424 8522 7849 7882 pword 0840 0865 0868 3228 3229 3240 3241
F'SSSC 6394 6517 8544 8695 pri 2066 2072 2078 2091 p_sddr 0371 1589 1743 1894 3242 3243 3247 3251
9038 PRIBIO 0156 4943 4955 4990 1904 1913 2042 2044 3259 3632 3638 3640
pc 2693 2734 2754 2756 5297 5316 2045 2193 2228 2276 3644
2757 2766 2767 3725 printf 1576 1577 1578 1579 2290 2294 3134 3241 ~c 5393
3791 2310 2421 2436 3242 3282 3376 3388 Gl 5393
.. e' .... .,.
pcll 8641 8645 8653 8657 2454 2716 2717 2718 4149 4380 4383 4384 r 0185 i56i 1563 .L~/W

8658 8673 8675 8688 6862 7310 4467 1574 1599 1600 1745
8689 8693 8714 8721 printn 2355 2369 2374 0366 2161 3795 3796 1750 1755 1760 5175
8724 8726 8728 8730 proc 0358 0376 1589 1590 3814 3815 3816 5177 5306 7726 7736
8731 8734 8743 8744 1591 1592 1593 1829 0361 1592 1862 1907 7740 7745 9026 9027
8754 8755 8756 1830 1846 1942 1943 1961 1992 2007 2023 9029 9030 9032 9035
F'CADDR 8607 8659 8663 8674 1960 1991 2006 2115 2046 2143 2208 2240 9036 9059 9060 9062
8691 8692 8714 8715 2119 2136 2180 2182 2241 2286 3170 3224 9063 9065 9068 9069
8722 8727 8730 8732 2185 2193 2206 2207 3289 3302 3303 3309 RO 2605 2679
8750 3222 3246 3248 3250 3998 4028 4169 4187 rO 2693 2701 2777
pcclose 4673 8669 3273 3277 3324 3327 4379 4385 4466 4468 RO 3208 3281 3304 3335
PCIHWAT 8624 8731 3632 3639 3644 3728 4479 5312 5317 3344 3416 3423 3432
F'cin 0530 0564 8643 8673 3810 3951 3953 3994 0367 1865 2162 3502 3443 3455 3456 3464
8688 8693 8730 8731 4018 4023 4166 4172 0369 1849 1867 1868 3475 3476 3482 3497
8734 proc;·~iiJt 4025 ~t204 3247 3251 3278 3281 3623 3637
f'CIPRI 8620 8660 8693 profil 2956 3667 3285 3304 3335 3344 rO 3725 3825
pcleader 8664 8678 8763 PS 0164 0668 0677 0679 3482 3642 4024 4174 RO 4079 4184 4191 5736
F'COHWAT 8623 8754 0691 0697 0700 0720 4175 4183 4209 5758 5831 5850 5853
F'COLWAT 8622 8743 0726 0731 0735 0741 0370 1868 3247 3251 5866 5986 6018 6073
pcopen 4673 8648 0748 0756 0773 0777 3252 3259 3278 3286 6830 7736 7744 7745
May 26 15:45 UNIX Operating System Source Code Cross Reference Listing Page 6

8206 rkread 4684 5476 SIGFPT 0121 2793 2797 4071 SRUN 0384 1591 1861 1908
RI 2606 2679 rkstart 5415 5440 5464 5472 SIGHUP 0114 1961 2008 2140 2208
!'I 2693 rkstrate 4658 5389 5479 5486 SIGINS 0117 2734 2736 4053 ssig 2960 3614
R1 3297 3305 3424 3433 rktab 4658 5386 5409 5410 4067 SSIZE 0137 3118 3131 3150
1'1 3725 5412 5413 5414 5444 SIGINT 0115 8345 SSLEEP 0382 2008 2090
F:1 7744 5446 5455 5457 5458 SIGIOT 0119 2744 4069 sslep 2947 5979
R2 2607 2679 5463 5469 5470 SIGKIL 0122 3619 3971 ssr 0759 0760 1013 1016
R3 2608 2679 rkwc 5380 sisnal 3949 8345 1021 1023 1028 1050
R4 2609 2679 rkwrite 4684 5483 SIGPIPE 0126 7828 1150 1171 1465 1467
R5 2610 2679 RO 0315 1668 1674 SIGQIT 0116 4066 8345 SSRO 0613 0647 0759 0761
F:6 2611 2679 3155 4055 rootdeY 0228 1616 1618 4695 SIGSEG 0124 2815 4073 0765 1354 1445
4059 6926 6927 6934 7728 SIGSYS 0125 2781 4074 SSR2 0760 1446
F:7 2612 2679 3188 3347 rootdir 0206 1616 1617 7533 SIGTRC 0118 2740 4053 4068 SST ART 7988 8514
4058 4061 ROOTINO 0106 1616 1618 7297 SINCR 0138 4143 SSTOP 0387 1993 3253 3301
!'ablkno 4773 4788 4789 RPS 2613 2679 4057 4060 sleep 1955 1968 2066 3038 4026 4173
!'.lb 1. m:1<. 0235 6253 6256 6454 4262 3314 4182 4190 4943 SSWAP 0394 1907 2240 2241
6456 6504 6506 rrkbuf 5387 5479 5486 4955 4990 5167 5204 2286 4479
4775 4789 4790 4791 rsr 2315 5215 5297 5316 5994 SSYS 0392 1592 1992 2007
4793 4794 4795 runin 0218 1954 1955 2080 6963 7007 7074 7289 start 0521 0522 0611 0612
7971 8297 8344 8356 2081 2082 3820 3821 7790 7838 7870 8225 0614
8386 3822 8287 8563 8660 8693 stat 2930 6028
!'br 2316 run out 0219 1967 1968 2143 8755 8989 stat1 6021 6036 6045
ReOM 5094 5112 2144 2145 4387 4388 SLOAD 0391 1592 1862 1961 sti!lte 2937 3428
!'dfls 5196 5206 4389 1992 2007 2023 2046 stop 3999 4016
RDHENB 8014 8051 8084 8614 0220 0770 0788 2142 2143 2208 4385 str 2433 2436
8659 8692 8732 2166 2196 3807 SLOC" 0393 1992 2007 4379 strat 5259 5261 5313
!'dw!' 5713 5722 5731 RW 0317 1684 1690 1707 • 4385 4466 4468 5312 STRC 0395 3170 3224 3309
!'ead 2915 5711 1711 5317 3998 4028 4169
,'eadi 3090 3142 4464 5754 rw 5259 5299 6672 6685 sloop 1953 2004 2014 stty 2943 8183
6221 7797 6689 6702 6"716 6722 SMAPSIZ 0142 0204 slJbyte 0807 0827 3161 6523
F~EADING 8611 8724 8726 sayfp 0888 0889 2698 slTtount 2933 6086 slJibyte 0809 0826 9067
!'e.ldF' 5748 7758 sayu 0724 0725 1889 1905 SITtP 6090 6102 6108 61.09 SIJiWOI'd 0813 0860 4240 4242
!'eslc)c: 0237 1011 1025 1038 2189 2281 2284 2846 6111 6121 6122 6123 su!ltount 2934 6144
1148 2677 3186 4258 4476 4477 6124 6125 6126 6127 SIJres 1724 1739 2229 2295
f,ESET 5367 5461 sbreak 2929 3354 6128 SIJser 3431 3444 3465 3500
,'et!'y 1840 1844 1850 schar 1552 4097 4101 7679 sp 2693 2811 3725 4136 3522 3579 5921 5957
"etlJ 0724 0740 2193 2228 sched 1637 1940 4137 4141 4143 6800 6811
2294 SCHMAG 370"7 3814 3815 splO 1292 1293 1976 2022 suword 0811 0861 0864 3156
,'e;,:i.t 2913 3205 seek 2931 5861 2079 2092 4944 4947 3159 3164 3661 4057
"fp 6646 6648 6649 6650 sep 1650 1654 1677 1698 4956 4959 4991 5170 4058 4247 4249 6055
6655 6656 6657 1714 3023 3094 3100 5218 5245 5320 5416 6059 8175 8176 8177
RHHCOM 5121 51.41 3118 3151 5996 8228 8289 8565 SW 0166 2391 3416
I'h~;tart 5123 SET£! 2660 2734 8676 8697 8759 8993 SWAIT 0383 1993 2077 3975
RHWCOM 5120 5142 setgid 2958 3460 9037 9070 swap 2034 2042 4380 4467
F:KADDli: ~)363 setpri 2156 2823 3818 3828 spl1 1292 1297 3803 5196
,'k.lddl' 5420 set res 1089 1099 1117 1120 sp14 1292 1302 8672 8686 swar-,dey 0229 3237 3282 4696
RKADDR 5447 1196 8757 8991 5207 5212
rkaddr 5447 set run 2123 2134 3254 3310 sp15 1292 1303 3766 5408 swaper' 2035 2043 2050
RKADDR 5459 5460 5461 5462 3976 4188 8222 8263 8283 8559 swap!ltap 0204 1583 2044 3234
I'f.'.ba 5381 setuid 2935 3439 sp16 1292 1308 1958 1990 3283 4375 4408 4457
!''''.CS 5379 5459 5461 5462 sstty 8171 81.91 8201 2075 2088 4886 4940 swbuf 4721 5200 5207 5208
!''''.del 5~582 544"7 SIDL 0385 1903 4952 4988 5007 5164 5209 5210 5211 5212
""'.ds 5377 5460 sis 3949 3955 3963 3968 5201 5213 5234 5294 swplo 0231 1583 4697
rk£!1' 5378 5460 3972 5314 swtch 0770 0791 2084 2093
I'f.'.int I' 0576 0577 5451 SIGBUS 0123 2722 4072 spI7 1292 1313 3854 5983 2178 2287 3256 4027
"ki.o 0544 0577 SIGEMT 0120 2748 4070 9028 9061 4480
May 26 15:45 UNIX Operatin~ System Source Code Cross Reference Listin~ Pa~e 7

SWTED 0396 3302 3303 3309 7218 7219 7226 7357 8390 8399 8412 8440 update 2420 3489 6150 7201
4187 7392 7393 8452 8463 8468 8586 lIpdloci<. 0234 1559 7207 7209
sync 2948 3486 timeout 3845 8594 7229
SYS 2661 2759 TIMEOUT 7984 8491 8518 7937 8049 8304 8585 I.Jser 0413
S~lsent 2667 2670 2696 2754 timeout 8524 8593 USER 2662 2700 2721 2733
2755 2761 2910 TIMEOUT 8525 7930 8074 8075 8223 2739 2743 2747 2751
~;ZOMB 0386 3243 3280 times 2955 3656 8225 8259 8261 8414 2796 2810
s_flock 5570 6127 6936 6962 tmt,ab 4727 4844 8478 8520 8560 8563 USIZE 0103 0636 0646 0662
6963 6972 6978 6979 to 6585 6586 659:L 7928 8260 8264 8287 1442 1560 1590 1628
7006 7007 7015 7022 tOI.Jt 0214 3434 3804 3805 8292 8349 8355 8357 1662 1682 3129 3131
7023 7214 5989 5990 5991 5992 8358 3133 3370 4116 4119
5572 6983 7005 7026 5994 t_speeds 7941 8583 8591 4233 4459 4467 4473
7084 7144 7213 7217 trap 0512 0513 0514 0515 t_state 7938 8045 8046 8059 0452 2701 2812 3155
s .. f rec? 5567 6967 6976 7012 0516 0517 0518 0538 8224 8285 8491 8514 3187 3188 3208 3281
7019 7025 0547 0548 0549 0555 8518 8525 8541 8556 3297 3304 3305 3335
~; .. _fs:i.;:·:e 5564 7047 0752 0754 0755 0762 8562 3344 3347 3416 3423
s_i 1 DCI<. 5571 6126 6937 7073 2693 u 0646 0659 0662 0744 3424 3432 3433 3443
7074 7094 7116 7117 trapl 2771 2841 1440 1441 3455 3456 3464 3475
7139 7213 trf 5804 5813 5824 uO 1067 1096 3476 3482 3497 3623
s_i.node 5569 7077 7107 7143 TTHIWAT 7961 8560 ul 1067 1189 3637 3825 4055 4057
s_isize 5563 7047 7096 TTIF'RI 7951 8287 1J2 1067 1190 4058 4059 4060 4061
5565 6965 6967 6971 TTLOWAT 7962 8074 u3 1067 1191 4079 4184 4191 4258
6975 6987 7010 7011 TTOF'RI 7952 8225 8563 u4 1067 1087 4262 5736 5758 5831
7014 7018 7020 7025 ttrbuf 8157 u5 1067 1071 1075 1097 5850 5853 5866 5986
7175 7179 ttrcsr 8156 1.16 :1.067 1069 6018 6073 6830 7736
5568 7076 7077 7107 ttread 8063 8535 1.17 1067 1192 7744 7745 8206
7108 7113 7118 7141 ttrstrt 8486 8524 ub 6045 6055 6056 6059 0440 2763 2766 2770
7143 7176 7180 ttstart 8073 8363 8492 8505 6060 3052 3056 3085 3095
5573 6128 6754 6938 8561 8568 UBMAF' 0311 1573 1574 5175 3096 3097 3099 3101
7214 7383 tttbl.Jf 8159 8522 5177 3105 3116 3117 3140
s .. time 5574 6939 6940 7218 tttcsr 8158 8518 l.Jchar 3026 3034 3513 3515 3141 3208 3297 3364
7219 ttwrite 8067 8550 3541 3543 5768 5770 3568 3569 3581 3582
tOO 1056 1059 tty 7926 8015 8025 8056 5784 5786 5912 5914 3618 3624 3649 3661
tOl 1056 1079 1085 1101 8071 8080 8092 8218 5928 5955 5958 6031 3662 3670 3671 3672
t,02 1056 1102 8220 8253 8255 8275 6033 6091 6097 6184 3673 4075 4079 4168
t03 1056 1103 8279 8334 8337 8374 6186 6794 6796 7689 4174 4185 4186 4439
t04 1056 1104 8377 8488 8506 8509 UDSA 0308 5306 4455 4461 5743 5744
t05 1056 1105 8536 8538 8551 8553 ufalloc 6076 6824 6852 5756 5758 5773 5774
t06 1056 1106 TTYHOG 7963 8349 lIid 3441 3443 3444 3445 5790 5873 5875 5876
t07 1056 1093 ttyinput 8087 8333 3446 3447 5880 5927 5966 5969
UO 1057 1062 ttyoutpu 8362 8373 8392 8403 urSA 0306 1563 1599 1745 6021 6036 6096 6113
t11 1057 1110 8413 8566 1750 1763 5306 9026 6128 8174 8187 8188
t12 1057 1111 ttYstty 8094 8577 9029 9032 9035 9059 8189 8190 8590
t13 1057 1112 t_addr 7932 8044 8082 8513 9062 9065 9068 0425 3085 3139 3525
t14 1057 1113 t_canG 7929 8258 8321 8543 UISAO 0678 0680 0690 0698 4115 4121 4463 5269
U5 1057 1114 8544 0701 0719 1451 5743 6372 6374 6376
t,16 1057 1107 t_char 7940 UISA1 0699 0702 0718 1452 6381 6522 6523 6530
ti7 1057 1140 1188 t_col 7935 8393 8423 UISD 0304 1561 1600 1755 6549 6550 6557 7488
TBDELAY 7975 t_delct 7934 8265 8284 8294 1760 1763 9027 9030 9050
TBIT 2615 4060 8359 9036 9060 9063 9069 0428 1618 1619 1883
4306 4314 4436 7942 8033 U!SDO 0681 0.',82 0689 0703 3232 3554 3555 7531
tim 3845 3851 7936 8048 8299 8584 0705 0717 1453 0426 3086 3141 3526
time 0213 3423 3424 3432 8592 UISD1 0704 0706 0716 1454 4116 4122 4461 5273
3433 3801 3802 3804 7931 8047 8297 8309 UMODE 2659 2699 3706 3788 5291 5310 5322 5744
3806 5984 5985 5988 8336 8341 8342 8344 3824 5756 5758 6230 6241
5989 6050 6939 6940 8353 8356 8361 8386 unlink 2922 3510 6262 6290 6296 6319
Ma~ 26 15:45 UNIX Operatins S~stem Source Code Cross Re~erence Listins PaSe 8

6383 6527 6531 6546 0438 1876 3227 5835 8580 8582 8583 8584
6554 7486 7589 7600 5853 6078 6626 6829 8585 8586 8590 8591
7639 7811 7818 7846 6856 7740 8592 8593 8594
7847 9048 9049 0435 5935 5936 7459 VTDELAY 7977 8463
u_cstime 0451 3291 3292 3293 7489 7490 7606 wait 2919 3270
3336 3337 0424 1593 1743 1752 WAITING 8610 86S7 8658 8721
u_cutime 0450 3294 3295 3296 1859 1891 1917 2071 wal<.elJp 2082 2113 2145 3197
3339 3340 2273 2793 2818 2823 3248 3249 3434 3805
u_dbuf 0429 7484 7570 7572 3134 3170 3174 3224 3808 3822 4025 4195
7576 7645 7646 3240 3278 3314 3326 4213 4389 4877 4880
u_dent 0434 3519 3525 3527 3376 3388 3446 3482 5031 5188 5217 5319
7482 7483 7488 7636 3502 3625 3626 3638 6652 6653 6979 7023
7640 7646 7664 3794 3828 3996 4021 7117 7778 7852 7891
u_dirp 0430 2770 4100 5927 4048 4119 4148 4149 8075 8260 8261 8357
6096 7682 7693 4169 4175 4209 4273 8734 8744 8982
u_dsize 0442 3149 3152 3369 4401 4402 4448 4465 WCOM 5093 5114
3371 3373 4146 5291 4478 4479 5312 5317 wdir 5940 7467 7477
u_error 0419 1728 2752 2773 7828 8031 8032 wflushtt 8058 8217 8589
2774 2775 2777 2857 0453 3127 3670 3671 WLO 5373
3064 3092 3102 3106 3672 3673 3790 3791 1010 0316 1762
3317 3330 3547 3620 IJ_Gsav 0445 2106 2846 WOPEN 7985
3652 4052 4099 4103 u_rSid 0423 3465 3467 3475 write 2916 5720
4127 4177 4193 5326 IJ_rsav 0415 1889 2189 2281 writei 3528 4118 4124 5755
5343 5344 5740 5788 4476 6276 7489 7848
5819 5822 5833 5870 0422 3444 3447 3455 writep 5749 7805
5918 5930 5933 5937 4111 ;.:1 2340 2346
5960 5964 6094 6114 0418 3089 3091 4117 2340
6117 6135 6152 6157 4123 5745 6372 6521 :-:3 2340
6163 6190 6193 6262 6548 7487 7587 :-:4 2340
6307 6319 6378 6424 0444 3151 3152 3365 2340
6524 6551 6569 6630 3371 4146 5276 5306 :-:6 2340
6727 6755 6759 6778 0447 2734 3183 3225 :-:7 2340
6816 6833 6863 6929 3623 3624 4003 4051 :-:8 2340
6989 7121 7311 7538 4054 :-:9 2340
7548 7560 7571 7580 0446 1905 2242 2284 :-:a 2340
7612 7695 7827 8027 4477 ;-:alloc 3130 4433
8172 8210 8654 8751 0443 3150 3152 3370 ;-:b 2340
8854 9038 9057 3371 3376 3378 3389 :-:br 2318 2399
u_fsav 0416 3189 4255 4141 4143 4146 4150 :-:c 2340
u_Sid 0421 3177 3466 3476 4156 5292 :-:ccdec 4378 4403 4490
6771 7466 u_stime 0449 3293 3338 3793 ;-:free 3128 3233 4398
u_ino 0432 3519 3527 7482 u_tsize 0441 3148 3152 3366 >:swap 1906 2024 2285 4368
7640 7664 3371 4146 5275 4478
u_intfls 0454 2772 2845 2848 0420 3172 3173 3445 XTABS 7967 8047 8390
u_name 0433 7483 7646 3456 3567 3646 4111 :-:_caddr 1753 2036 4309 4497
u_offset 0427 3087 3088 3140 6763 6769 6798 6814 ;-:_ccoIJnt 1881 1980 2033 2039
3524 4113 4114 4462 7465 4313 4453 4475 4483
5309 5751 5752 6239 0436 1665 1678 1694 4495 4496
6240 6244 6294 6295 1699 1715 1716 1717 1880 4312 4404 4447
6309 6313 6315 6316 1744 4452
6382 6528 6529 6555 0437 1666 1719 1720 2034 4308 4409 4457
6556 7585 7586 7608 1721 1754 4467
7622 7626 7636 7638 0448 3296 3341 3660 4311 4405 4407 4442
7642 7795 7796 7798 3789 4446 4454
7844 7845 7846 9024 v 8090 8091 8094 8167 1981 2034 2037 4310
9025 9051 9055 9056 8170 8201 8202 8213 4408 4456 4497
Hay 24 12:28 1976 unix/param.h Page 1 Ms\,l 24 12:28 1976 unix/param.h Page 2

0100 1* fundamental constants: do not change *1 0150


0101 0151 1* priorities: do not alter much *1
0102 0152
0103 tdefine USIZE 16 1* size of user block (*64) *I 0153.
0104 tdefine NULL 0 0154 tdefine PSWP -100
0105 tdefine NODE V (-1) 0155 tdefine F'INOD -90
0106 tdefine ROOTINO 1 1* i n'-Jmber of all roots *1 0156 tdefine PRIBIO -50
0107 tdefine DIRSIZ 14 1* ma:·: characters per directory *1 0157 tdefine PPIPE 1
0108 0158 tdefine PWAIT 40
0109 0159 tdefine PSLEF' 90
0110 1* signals: do not change *1 0160 Idefine PUSER 100
0111 0161
0112 0162 1* Certain processor registers *1
0113 tdefine NSIG 20 0163
0114 tdefine SIGHUP 1 1* hangul" *1 0164 tdefine PS 0177776
0115 tdefine SIGINT 2 1* interrupt (ruboIJt) *1 0165 "'define KL 0177560
0116 tdefine SIGCUT 3 1* Guit (FS) *1 0166 tdefine SW 0177570
0117 "'define SIGINS 4 1* illegal instrlJction *1 0167
0118 tdefine SIGTRC 5 1* trace or breakpoint *1 0168 1* ------------------------- *1
0119 Idefine SIGIOT 6 1* iot *1 0169
0120 tdefine SIGEMT 7 1* emt *1 0170 1* structures to access integers *1
0121 "'define SIGFPT 8 1* floating e>:ception *1 0171
0122 tdefine SIGKIL 9 1* kill *1 0172
0123 tdefine SIGBUS 10 1* bus error *I 0173 1*.sing1e integer *1
0124 Idefine SIGSEG 11 1* segmentation violation *1 0174
0125 "'define SIGSYS 12 1* SYS *1 0175 struct { int integ; };
0126 tdefine SIGPIPE 13 1* end of pipe *I 0176
0127 0177
0128 1* tunable variables *1 0178 1* in bytes *1
0129 0179
0130 Idefine NBUF 15 1* size of buffer cache *1 0180 struct { char lobyte; char hibyte;
0131 tdefine NINODE 100 1* number of in core inodes *1 0181
0132 tdefine NFILE 100 1* number of in core file structures *1 0182
0133 Idefine NMOUNT 5 1* number of mountable file s\,lstems *I 0183 1* as a seGuence *1
0134 tdefine NEXEC 3 1* nlJmber of simlJl taneous e:·:ec's *I 0184
0135 tdefine HAXMEM (64*32) 1* ma:·: core per process; 0185 int
01~1{, first number is kw *1 0186
0137 tdefine SSIZE 20 1* initial stack size (*64 b\,ltes) *1 0187
0138 tdefine SINCF~ 20 1* increment of stack (*64 b\,ltes) *1 0188 1* -------------------------
0139 "'define NOFILE 15 1* ma:·: open files per process *I 0189
0140 Idefine CANBSIZ 256 1* max size of t\,lpewriter line *1 0190
0141 tdefine CHAPSIZ 100 1* size of core allocation area *1 0191
0142 tdefine SMAPSIZ 100 1* size of swap allocation area *1 0192
0143 tdefine NCALL 20 1* ma>~ simultaneous tillle callouts *1 0193
0144 Idefine NPROC 50 1* max number of processes *1 0194
0145 tdefine NTEXT 40 1* ma:·: nUlllber of pure te:·:ts *I 0195
0146 tdefine NCLIST 100 1* lI,a:-: total clist size *1 0196
0147 tdefine HZ 60 1* Ticks/second of the clock *I 0197
0148 0198
0149 0199

Reproduced under licence from the Western Electric Compan\,l, NY Reproduced under licence from the Western Electric Company, NY
Copyright. J. Lions, 1976 Copyright, J. Lions, 1976

Sheet 01 Sheet 01
Maw 24 12:28 1976 unix/swstm.h Pa~e 1 Maw 24 12:28 1976 unix/swstm.h Page 2

0200 1* various slobal variables *1 0250


0201 0251 1* *1
0202 char canonb[CANBSIZJI 1* buffer for erase and kill *1 0252
0203 int coremap[CMAPSIZJf 1* space for core allocation *1 0253 1* The callout structure is for a routine
0204
0205
int swapmap[SMAPSIZJf I. space for swap allocation *1 0254
0255
** arranging to be called bw the clock interrupt
(see clock.c). with s specified arSument,
0206
0207
int *r"ootdir; I
/w
'"
pointer t.o incde of root director~ 0256
0257
* within a specified amount of time.
* It is used, for example, to time tab delaws
0208 int cputwpef 1* twpe of cpu =40. 45. or 70 *1 0258 * on teletwpes. *1
0209 0259
0210 int e>:ecnt; 1* number of processes in exec *1 0260 struct callo
0211 0261 {
0212 int lbolt; 1* time of daw in 60th not in time *1 0262 int c_time; I . incremental time *1
0213 int time[2Jf 1* time in sec from 1970 *1 0263 int c_srS; 1* arSument to routine *1
0214 int to'.rt..[2J; 1* time of daw of next sleep *1 0264 int <*c_func)(); 1* routine *1
021.5 0265 } callout[NCALLJ'
02:l6 int mpid. 1* seneric for uniGue process id's *1 0266
0267
1* -------------------------
0217
0218 char r'Jnin' I I sched'.Jl i n~ flas I I 0268 1* Mount structure: used to locate
0219 char runout;
O~,~2 0 char r'Jnrun'
I I schedulin~ fla~ *1
I I schedulins flas *1
0269
0270
* the super block of a mounted file.

0221 0271 *'


0222 char c'Jrpri;
0223
0224 int ma:·:memf
0225
I.
I I more scheduling I I

actual ma:·: memorw per PI'ocess *1

0226 int Ilks; I I pointer to clock device *1


0272
0273
0274
0275
0276
str'Jct
{
mount

int m_dev'
int *m_b,Jfp;
int *m_inodp'
1* device mounted *1
1* pointer to superblock *1
1* pointer to mounted on inode *1
0227 0277 } mount[NMOUNTJ;
0228 int rootdev; 1* dev of root see confoc *1 0278 1* ------------------------- II
0229 int swapdev; I I dev of swap see conf.c I I 0279
0230 0280
0231 int swplo; 1* block number of swap space *1 0281
0232 int nswBP; I I size of swap space I I 0282
0233 0283
0234 int updlocld I I lock for swnc *1 0284
0~!35 int rablock; I I block. to be read ahead 0285
0236 *' 0286
0237 char regloc[J; I I locs. of saved user re~isters 0287
0238 (see trap.c) *1 0288
0239 0289
0240 0290
0241 1* ------------------------- 0291
0242 *' 0292
0243 0293
0244 0294
0245 0295
0246 0296
0247 0297
0248 0298
0249 0299

Reproduced under licence from the Western Electric Companw, NY Reproduced under licence from the Western Electric Companw, NY
Copwright, J. Lions, 1976 Copwrisht, J. Lions, 1976

Sheet 02 Sheet 02
May 24 12:28 1976 unix/se~.h Pase 1 May 24 12:28 1976 unix/proc.h Page 1

0300 0350 1*
0301 1* kt-ll addresses and bits *1 0351 * One structure allocated per active
0302 0352 * process. It contains all data needed
0303 0353 * about the process while the
0304 idefine UISD 0177600 1* first 'Jser I-space descriptor 0354 * process may be swapped out.
0305 register *1 0355 * Other per process data (user.h)
0306 idefine UISA 0177640 1* first user I-space address 0356 * is swapped with the process.
0307 reSister *1 0357 *1
0308 idefine UDSA 0177660 1* first 'Jser [I-space address 0358 struct proc
0309 reSister *1 0359 {
0310 0360 char p_stat;
0311 idefine UBMAP 0170200 1* access to 11170 unibus map *1 0361 char p_fla~H
0312 0362 char p_pri; 1* priority, negative is high *1
0313 0363 char p_sis; 1* signal n'JII.ber sent to this process *1
0314 0364 char p_'Jid; 1* 'Jser id, used to direct tty signals *1
0315 idefine RO 02 1* access abilities *1 0365 char p_time; 1* resident time for sched'J ling *1
0316 idefine WO 04 0366 char p_cpu; 1* cpu usage for schedulin~ *1
0317 idefine RW 06 0367 char p_nice; 1* nice for sched'JI ing *1
031.E1 #define ED 010 1* expand segment downwards *1 0368 int p_ttyp; 1* controlling tty *1
0319 0369 int p_pid; 1* 'JniG'Je process id *1
0320 1* ------------------------- *1 0370 int p_ppid; 1* process id of parent *1
0321 0371 int p_addr; 1* address of swappable image *1
0322 int 1* 11/40 KISA6; 11/45 KDSA6 *1 0372 int p_size; 1* size of swappable image (*64 bytes) *1
0323 0373 int p_w~han;l* event process is awaiting *1
0324 0374 int *p_ te:-:'!:.p; 1* pointer to te:-:t struct'Jre *1
0325 0375
0326 0376 } procCNPROCl;
0327 0377 1* ------------------------- *1
0328 0378
0329 0379 1* stat codes *1
0330 0380
0331 0381 1* null 0 not assigned *1
0332 0382 idefir.e SSLEEP 1 1* sleeping on high priority *1
0333 0383 idefine SWAIT 2 1* sleeping on low priority *1
0334 0384 idefine SRUN 3 1* running *1
0335 0385 idefine SIDL 4 1* process is being created *1
0336 0386 tdefine SZOMB 5 1* process is being te rlloi nated *1
0337 0387 tdefine SSTOP 6 1* process being traced *1
0338 0388
0339 0389 1* flag codes *1
0340 0390
0341 0391 tdefine SLOAD 01 1* in core *1
0342 0392 tdefine SSYS 02 1* sched'Jling process *1
0343 0393 "'define SLOCK 04 1* process cannot be swapped *1
0344 0394 "'define SSWAP 010 1* process is being swapped o'Jt *1
0345 0395 "'define STRC 020 1* process is being traced *1
0346 0396 "'define SWTED 040 1* another tracing flag *1
0347 0397
0348 0398
0349 0399

Reproduced under licence from the Western Electric Company, NY Reproduced under licence from the Western Electric Company, NY
CoPYright, J. Lions, 1976 Copyright, J. Lions, 1976

Sheet 03 Sheet 03
Maw 24 12:29 1976 unix/user.h PaSe 1 Maw 24 12:29 1976 unix/user.h PaSe 2

0400 1* 0450 int u_c'-Itime[2J; 1* sum of childs' utimes *!


0401 * The user structure. 0451 int u_cstilTle[2J; 1* sum of childs' stimes *1
0402 *
One allocated per process. 0452 int *u_arO; 1* address of '-Isers saved RO *I

*** 1* *1
0403 Contains all per process data 0453 int u_prof[4J; profile arsuments
0404 that doesn't need to be referenced 0454 char u_intfl.; 1* catch intr fran, sws *1
0405 while the process is swapped. 0455 f* kernel stack per user
0406 *
The user block is USIZE*64 bytes 0456
* e:o(tends from u + USIZE164
0407 *
Ions; ~esides at virtual kernel 0457 * backward not to reach here
**
04013 loc 140000; contains the swstem 0458 *I
0409 stack per user. is cross referenced 0459 } u;
0410 * with the proc structure for the 0460 f* ------------------------- *1
0411 * same process. 0461
0412 *! 0462 f* u_error codes *I
0413 struct user 0463 f* See section 'INTRO(II)' of
0414 { 0464 * the UNIX F' raS ramn,e r ' s n,anual
04:L5 int u_rsav[2J. 1*save r5,r6 when exchansins stacks *1 0465 for the meaninss of these codes. *f
0416 int u_fsav[25J; 1* *1
save fp reSisters 0466 "'define HAULT 106 *
0417 1* rsav and fsav must be first in structure *1 0467 tdefine EPERM 1
0418 char u_seSfIS; 1*flas for 10; user or kernel space *1 0468 tdefine ENOENT 2
04:[9 char u_error' 1* *1
return error code 0469 tdefine ESRCH 3
0420 char u_uid; 1*
effective user id *1 0470 tdefine EINTR 4
0421 chaT' 'Lsid; 1*
effective Sroup id *1 0471 tdefine EIO 5
0422 char u_ruid; 1*
real user id *1 0472 tdefine ENXIO 6
0423 c~har u_rsid; 1*
real Sroup id *1 0473 "'define E2BIG 7
0424 i nt u __ p rocP, 1*pointer to proc structure *1 0474 "'define ENOEXEC 8
0425 cha T' *u_base; 1*base address for 10 *1 0475 :l!:define EBADF 9
0426 cha r *u_.count; 1*bwtes remaining for 10 *1 0476 tdefine ECHILD 10
04~~7 char *u_offset[2J; 1*
offset in file for 10 *1 0477 tdefine EAGAIN 11
04213 int *u_cdir' 1* pointer to inode of current directorw *1 0478 tdefine ENOMEM 12
0429 char u_dbuf[DIRSIZ]; 1*
current pathname component *1 0479 tdefine EACCES 13
0430 char *u_dirp' 1*current pointer to inode *1 0480 tdefine ENOTBLK 15
0431 struct { 1*
current directorw entrw *1 0481 tdefine EBUSY 16
0432 int u_ino; 0482 tdefine EEXIST 17
0433 char u_name[DIRSIZ]; 0483 tdefine EXDEV 18
0434 } u_dent; 0484 tdefine ENO[IEV 19
0435 int *u_pdir; 1*inode of parent directorw of dirp *1 0485 tdefine ENOTDIR 20
0436 int u_uisa[16]; 1*prototwpe seSmentation addresses *1 0486 tdefine EISDIR 21
0437 int u_uisd[16]; 1*prototwpe seSmentation descriptors *1 0487 tdefine EINVAL 22
0438 int u_ofile[NOFILE]; 1*
pointers to file structures of 0488 tdefine ENFILE 23
0439 *1
open files 0489 tdefine EMFILE 24
0440 int u_ars[5]; 1*
arSuments to current swstem call *1 0490 tdefine ENOTTY 25
0441 int u_tsize' 1* *1
text size (*64) 0491 tdefine ETXTBSY 26
0442 int u_dsize; 1* *1
data size (*64) 0492 idefine EFBIG 27
0443 int u_ssize; 1* *1
stack size (*64) 0493 tdefine ENOSPC 28
0444 int u_sep; 1*
flaS for I and D separation *1 0494 tdefine ESF'IPE 29
0445 int u_Gsav[2]; 1*label variable for Guits & interrupts *1 0495 tdefine EROFS 30
0446 int u_ssav[2J; 1*
label variable for swapp ins *1 0496 tdefine EMLINK 31
0447 int u_siSnal[NSIG]; 1*
disposition of sisnals *1 0497 :tdefine EPIPE 32
0448 int u_utime; 1*
this process user time *1 0498
0449 int u_stime; 1*
this process swstem time *1 0499

Reproduced under licence from the Western Electric Companw, NY Reproduced under licence from the Western Electric Companw, NY
Copwrisht, J. Lions, 1976 Copwrisht, J. Lions, 1976

Sheet 04 Sheet 04
May 24 12:29 1976 unix/low.s Page 1 Ma~ 24 12:29 1976 unix/low.s Page 2

0500 I low core 0550


050l 0551 1111111111111111111111111111111111/111111/111/11111111
0502 br4 200 0552 I interface code to C
0503 br5 240 0553 11111111111/111111/111111111111/1/1/111/1/1////1//1/11
0504 bl'6 300 0554
0505 br7 340 0555 .globl call, trap
0506 0556
0507 O~. 0557 .globl _klrint
0508 br 1f 0558 l<.lin: Jsr rO,call ; _klrint
0509 4 0559
0510 0560 .globl _kb:int
0511. I trap vectors 0561 klou: Jsr rO,call; _kl:dnt
0512 trap; br7+0. I bus error 0562
0513 trap; br7+1. I illegal instruction 0563 ,globl _pcrint
0514 trap; br7+2. I bpt-trace trap 0564 pcin: Jsr rO,call; _pcrint
0515 trap; br7+3. I iot trap 0565
0516 trap; br7t4. I power fail 0566 .910bl _pcpint
0517 trap; br7+5, I emulator trap 0567 pcou: Jsr l'O,call ; _pcpint
0518 trap; br7+6. I system entry 0568
0519 0569 .globl _clocl',
052() = 40". 0570 kWlp: Jsr rO,calH _clock
0521 .9101..11 start, dump 0571
0522 1: JIT.P start 0572
0523 Jmp dump 0573 .globl _lpint
0524 0574 lpo'J: Jsr rO,call; ._lpint
0525
0526
0527
· = 60~.

klin; br4
"-.lou; br4
0575
0576
0577
.slobl
rkio:
_rkintr
Jsr rO,call; _rkintr
0528 0578
0529
0530
0531
· = 70~.

pcin; br4
pcou; br4
0579
0580
0581
0532 0582
0533 , == 10()~, 0583
0534 "-.wlp; br6 0584
0535 kwlp; br6 0585
0536 0586
0537 , = 114~ • 0587
0538 trap, br7+7. I 11/70 parity 0588
0539 0589
0540 - 200~. 0590
0541 Ipo,-d br4 0591
0542 0592
0543
0544
0545
· = 220",
rldo. br5
0593
0594
0595
0546
0547
0548
· :: 240".
trap; br7+7.
trap; br7+8.
I
I
programmed interrupt
floating point
0596
0597
0598
0549 trap; br7+9. I segmentation violation 0599

Reproduced under licence from the Western Electric Company, NY Reproduced under licence from the Western Electric Company, NY
Copyright, J. Lions, 1976 CoPYright, J. Lions, 1976

Sheet 05 Sheet 05
Ma~1 24 12:29 1976 uni )·:/m40. s POIse 1 MOl!'! 24 12:29 1976 un h:/m40. s Pase 2

0600 1 machine lansuase assist 0650


0601 1 for 11/40 0651 mov $_edata,rO
0602 0652 U
0603 / non-UNIX instructions 0653 clr (1'0)+
0604 mfpi 6500~tst 0654 cmp 1'0,$_end
0605 mtpi 6600~tst 0655 blo 1b
0606 wait 1 0656
0607 rtt 6 0657 / clear user block
0608 ,'eset 5 0658
060'7 0659 mov $_'J,I'O
0610 l* ------------------------- *1 0660 U
0611 .slobl start. _end, _edata. _main 0661 cll' (1'0)+
0612 start: 0662 cmp rO,$_u+CUSIZE*64.]
0613 bit $l,SSRO 0663 bl0 1b
0614 !:.Ine start 1 loop if restart 0664
0615 r~sct 0665 1 set UP previous mode and call main
06l.6 0666 1 on return. enter user mode at OR
0617 1 initialize s!'!stems sesments 0667
0618 0668 mov $30000.PS
0619 mov $KISAO,rO 0669 Jsr pc,_main
0620 mov $KISDO,r1 0670 mov $170000, - (sp)
0621. Il,OV $200'1'4 0671 clr -(sp)
0622 clr 1'2 0672 rtt
0623 mov $6,1'3 0673
0624 1: 0674 1* ---.------------.---------- *I
0625 mov 1'2'(1'0)+ 0675 .slobl _clearses
0626 mov $77406,(1'1)+ 1 4k rw 0676 _clearsesl
0627 add 1'4,1'2 0677 moy F'S,-(sp)
0628 sob r3r1b 0678 moy LJISAO,-(sp)
0629 0679 mov $30340,PS
0630 1 initialize user sesment 0680 moy 6(sp),LJISAO
0631 0681 moy LJISDO.-(sp)
0632 mov $_end+63"r2 0682 mov $6,LJISDO
0633 ash $-6'1'2 0683 clr 1'0
0634 bic $!1777.r2 0684 moy $32"1'1
0635 moy 1'2'(1'0)+ / ksr6 s!,!su 0685 U
0636 moy $USIZE-1\(816,(r1)+ 0686 cl I' -(sp)
0637 0687 IJltpi (1'0)+
0638 1 initialize io sesment 0688 sob r1.1b
0639 1 set UP counts on s'JPeryisor sesments 0689 moy (sp)+.LJISDO
0640 0690 moy (sp)+,LJISAO
0641. moy $IO.(rO)t 0691 mov (sp)t,PS
0642 moy $77406, (r1)t 1 rw 4k 0692 rts PC
0643 0693
0644 1 set a SP and start sesmentation 0694 /* ------------------------- */
0645 0695 .slobl _coP!'!ses
0646 mov $_u+CLJSIZE*64.],sp 0696 _cop!,!ses:
0647 inc SSRO 0697 moy F'S,-(sp)
0648 0698 IT,OV LJISAO,-(sp)
0649 I clear bss 0699 mov UISA1,-(sp)

Reproduced under licence from the Western Electric Compan!'!, NY Reproduced under licence from the Western Electric Compan!'!, NY
CoP!'!risht, J. Lions, 1976 CoP!'!risht, J. Lions, 1976

Sheet 06 Sheet 06
Ma~ 24 12:29 1976 'Jni>:/m40.s Pase 3 Ma~ 24 12:29 1976 'Jnh:/Il,40.s Page 4

0700 II,OY $30340,PS 0750


0701 may 10(sp),UISAO 0751 1* --_._---------------------
.globl trap, call
0702 mDV 12(sp),UISAl 0752
070:3 may UISDO,-(sp) 0753
0754
1* -------------------------
.slobl _trap
0704 may UISD1,-(sp)
0705 may $6,UISDO 0755 trap:
0706 mov $6,UISDl 0756 mov PS,-4(sp)
0707 may r2,-(sp) 0757 tst nofault
0708 c1r rO 0758 bne if
0709 Il,OY $8192.,rl 0759 may SSRO,ssr
0710 mov $32.,r2 0760 mov SSR2,ssrt4
0711 1: 0761 Il.ov $l,SSRO
0712 mfpi (rO)t 0762 Jsr rO,callH _trap
0713 mtpi (rl) t ()763 I no return
0714 sob r2r1b 0764 1:
0715 may (sp)t,r2 0765 mov $1 ,SSRO
0716 mov (sp)t,UISDl 0766 mov nofau1t,(sp)
0717 II'OV (sp)t,UISDO 0767 I'tt
0718 mov (sp)t,UISAl 0768
0719 mov (sp)t, UISAO 0769 1* -------------------------
ono m!)v (sp)t,PS ()77() .slobl _ run r'Jn , _swtch
0721 rts PC 0771 call:L:
0722 0772 tst -(sp)
0723 1*------------------------- *1 0773 bic $340,PS
0724 .globl _saV'J, _ ret'J, _aretu 0774 br if
0725 _savu: ()775
0726 bis $340,PS 0776 call :
0727 mov (sp)+. r1 0777 mov PS,-(sp)
0728 mov (sp) , rO 0778 1:
0729 mov sp, (rO)t 0779 mov r:l,-(sp)
ono Il,OV r5,(rO)t 0780 mfpi SP
0731 bic $340,PS 0781 mov 4(sp),-(sp)
0732 JIl,P ( r1) 0782 bic $!37,(sp)
0733 0783 bit $30000,PS
0734 _al'etu: 0784 beG if
0735 bis $340,PS 0785 JST' pc,*(rO)t
0736 ilia v (sp)t,rl 0786 2:
0737 mov (sp),rO 0787 bis $34(),PS
0738 br :Lf 0788 tstb _ rlJn run
0739 0789 beG 2f
0740 _I'etu! 0790 bic $340,PS
0741 bis $340,PS 0791 Jsr pc,_swtch
0742 Il,OV (sp)t,rl 0792 br 2b
0743 Il,C) V (sp),KISA6 0793 2:
0744 mov $_u,rO 0794 tst (sp)t
0745 l: 0795 IlItpi SP
0746 Ill!) V (rO)t,sp 0796 br 2f
0747 Il,OV (rO)t, r5 0797 1:
0748 bic $340,PS 0798 bis $30000,PS
0749 Jmp ( r1) 0799 Jsr pc,*(rO)t

Reproduced under licence from the Western Electric Compan~, NY Reproduced under licence from the Western Electric Company, NY
CoPyrisht, J. Lions, 1976 Cop~risht, J. Lions, 1976

Sheet 07 Sheet 07
Ma!:l 24 12:29 1976 uni:-:/m40. s PaSe 5 May 24 12:29 1976 unix/m40.s PaSe 6

0800 cmp (sp ) t • ( sp ) + 0850


0801 2: 0851 sword:
0802 moy (sp)-b rl 0852 ITIOV PS.-(sp)
0803 tst (sp)+ 0853 bis ~~340,PS
0804 ITIOY (sp)t. rO 0854 mov nofault.-(sp)
0805 rtt 0855 ITIOV $err,nofault
0806 1* --------------------------
_fl..lb!:lte, _sub!:lte
*! 0856
0857
mfr:--i ( 1'1)
(sp)hrO
0807 .slobl ITIOV
0808
0809
1* -------------------------
.slobl _fuibste, _suib!:lte
*1 0858
0859
br 1f

0810
0811
1* -------------------------
• slobl _f'.Jwor-d • _sl.Jword
*1 0860
0861
_suiword:
_suward:
0812 1* --------------------------
_fuiword, _sl.Jiword
*1 0862
0863
mov 2(sp),r1
4 ( sr- ) .1'0
08B .slobl ITIOV
0814 _ fl.Jib!:lte: 0864 suword:
0815 _fub!:lte! 0865 jST~ pc.pword
0816 moy 2(sp).rl 0866 rts pc
0817 bic $1,1'1 0867
0818 Jsr pc,sword 0868 pword:
0819 cmp r1,2(sp) 0869 mov PS.-(SF')
OB20 beG if 0870 bis $340,PS
0821 swab 1'0 0871 mov nofaul t. -- (sp)
0822 1! 0872 mov $err,nofault
0823 bic $!377,rO 0873 mov rO,-(sp)
0824 rts PC 0874 ITltpi (1'1)
OB25 0875 1:
OB26 _suib!:lte! 0876 mov (sp)+.nofault
0827 _subste: 0877 mov (sp) -j-, F'S
0828 ITIOY 2(sp),r1 0878 rts PC
082';> bic $1,r1 0879
0830 Jsr F'C, Sword 0880 err:
0831 ",OY rO,-(sp) 0881 mov (sp)+,nofal.Jlt
OS;32 cmp r1.4(sp) 0882 mov (sp)+,PS
0833 beG If 0883 tst (spH
0834 IIloyb 6(sp),1(sp) 0884 mov $-l,rO
0835 br 2f 0885 rts PC
0836 1: 0886
0837 rrloyb 6(sp),(sp) 0887 1* ------------------------- *1
0838 2: 0888 .slobl
0839 mov (sp)+,rO 0889 _savfp:
0840 Jsr pc,pword 0890 _displa~J:
0841 clr rO 0891 rts PC
0842 rts PC 0892
0843 0893 1* ------------------------- *1
0844 _fuiword: 0894 .slobl
0845 _fuword: 0895 _incupc:
0846 mov 2(sp),r1 0896 mov r2,-(sp)
0847 fuword: 0897 mov 6(sp)n'2 1 base of prof with base,lenS,off,scale
0848 Jsr pc.Sword 0898 mov 4(sp),rO / PC
0849 rts PC 0899 sl.Jb 4(r2hrO I offset

Reproduced under licence from the Western Electric Company, NY Reproduced under licence from the Western Electric COITIPan!:l, NY
CoPYrisht, J. Lions, 1976 CoPYrisht, J. Lions, 1976

Sheet 08 Sheet 08
Ma~ 24 12:29 1976 unix/m40.s Page 7 Ma~ 24 12:29 1976 unix/m40.s Page 8

0900 clc 0950 add $2,(rl)


090l ror rO 0951 ....
".
0902 lIIul 6(r2),rO 1 scale 0952 dec r2
0903 ashc $-14.,rO 0953 bic $7,r2
0904 inc rl 0954 11101,1 _cfreelist,(r2)
0905 bic $1,rl 0955 ilia v ,'2, .. _cfreelist
0906 CITIP r1,2(r2) 1 lensth 0956 3:
OlOY07 bhis 1f 0957 11101,1 (sp)t,r2
0908 add (r2),rl 1 base 0958 IT,OV (~;p)t,PS

0909 IlIOV nofaul tr - (sp) 0959 rts pc


0910 IT,OV $2f,nofa'.Jlt 0960 9:
091l. IT,fpi ( rl ) 0961 clr 4 (rl)
0912 inc (sp) 0962 11101,1 $-1,rO
0913 IIItpi ( rU 0963 mov (sp)t,r2
0914 br 3f 0964 11101,1 (spH,PS
0915 2: 0965 rts PC
0916 clr 6(r2) 0966
0917 3: 0967 _putc:
0918 ITIOV (sp)t,nofault 0968 11101,1 2(sp),rO
0919 1: 0969 11101,1 4(sp),r1
0920 mov (sp)t,r2 0970 11101,1 PS,-(sp)
0921 rts PC 0971 mov r2,-(sp)
0922 0972 11101,1 r3,-(sp)
0923 / Character list get/p'.Jt 0973 bis $340,PS
0924 0974 bic $100,PS / spl 5
0925 1* ------------------------- *1 0975 mav 4(rl),r2 / last ptr
0926 ,slobl _setc, _putc 0976 bne 1f
0927 ------------------------- 0977 11101,1 _cfreelist,r2
0928 '*
.slobl _cfreelist
*/
0978 beG
11101,1
9f
(r2),_cfreelist
0929 0979
0930 _setc: 0980 clr ( r2H
0931 ITIOV 2(sp),r1 0981 11101,1 r2,2(rl) / first ptr
0932 1110 V PS,-(sp) 0982 br 2f
0933 1II0V r2,-(sp) 0983 1:
0934 bis $340,PS 0984 bit $7,r2
0935 bic $100,PS / SF-I C!'
u 0985 bne 2f
0936 1110 V 2(rl),r2 / first ptr 0986 11101,1 _cfreelist,r3
0937 beG 9f / empt~ 0987 beG 9f
0938 movb (r2)t,rO / character 0988 11,01,1 (r3),_cfreelist
0939 bic $!377,rO 0989 11101,1 r3,-10(r2)
0940 11101,1 r2,2(rU 0990 mov r3,r2
0941 dec ( rUt / count 0991 clr ( r2H
0942 bns 1f 0992 2:
0943 clr (r1) t 0993 lIIovb rO,(r2H
0944 c:lr (rl) t 1 last block 0994 mov r2,4(rl)
0945 br 2f 0995 inc ( r1) / count
0946 U 0996 clr rO
0947 bit $7,r2 0997 11101,1 (sp)t,r3
0948 bne 3f 0998 11101,1 (sp)t,r2
0949 11,01,1 -10(r2),(rl) 1 ne;·:t block 0999 mov (sp)t,PS

Reproduced under licence from the Western Electric Compan~, NY Reproduced under licence frolll the Western Electric COIIIPan~, NY
Cop~risht, J. Lions, 1976 Cop~risht, J. Lions, 1976

Sheet 09 Sheet 09
Maw 24 12:29 1976 unix/m40.s Pa~e 9 Maw 24 12:29 1976 unix/m40.s Pa~e 10

100() rts PC 1050 1I10Y ss r+4. 1'0


1001 Q'
, + 1051 Jsr pc,fetch
1002 moy pc,rO 1052 1I10Y rO.rl
1003 1I10Y (sp)+.r3 1053 ash $-11.,rO
1004 moy (sp)+,r2 1054 bic $!36.rO
1()05 moy (sp)+.PS 1055 JIlIP *Of(rO)
1006 rts PC 1056 0: tOO. -tOU t02. to;3. t.04' -1:.05; -1:.06, t07
1007 1057 tl0, tlU t12' t13, t14' ti5, t1c,; ti7
1008 1* ------------------------- */ 1058
1009 .~lobl ._backIJp 1059 tOO:
1010 1* ------------------------- */ 1060 clrb bfl~
1011 .~lobl _re~loc 1061
1012 _backup: 1062 tl0:
1.013 moy 2(sp) .ssr+2 1063 mov rl.I'O
1014 mov r2.-(sp) 1064 swab rO
-I f\'1
.t.V.LW
s::::
-.J.J. pc!, bacY.'Jp 1065 bic $!16,rO
1016 mov r2,ssr+2 1066 Jmp *Of ( 1'0)
1017 1110 V (sp)+,r2 1067 0: IJO; uU 1-12 ; u3; u4, u5; u6; u7
101S movb ,jfl~, rO 1068
1.019 bne 2f 1069 u6: / simile OP. m[tfJpi, s:·:t. i lle~al
1020 1l10V 2(sp),rO 1070 bit $400,1'1
1.021 mayb ssr+2,rl 1071 beG uS / all blJt metf], s:·:t
1022 Jsr pc.lf 1072 bit $200,r1
1023 movb ssr+3. rl 1073 beG if / mfpi
ln4 Jsr pc.lf 1074 bit $:lOO,rl
1025 movb _re~loc+7,rl 1075 bne u5 / s~·~t
1026 asl r1 1076
1027 add rO.r1 1077 / simulate mtpi with double (sp)t,dd
1028 moy ssr+4,(rl) 1078 bic $4000.rl / turn instr into (sp)+
1029 clr rO 1079 br tOl
1030 ....
,."
1080
1031 rts PC 1081 / simulate mfpi with dOI.Jble ss,-(sp)
1032 1: 1082 1:
1.033 mov r1,-(sp) 1083 ash $6, rl
1034 asr (sp) 1084 bis $46,rl / _. (sp)
1035 asr (sp) 1085 br tOl
1036 asr (sp) 1086
1()37 bic $!7,r1 1087 u4: / Jsr
1038 movb _re~loc(r1),r1 1088 mov r1,rO
1039 asl r1 1089 Jsr pc.setre~ / assume no fault
1040 add rO, r1 1090 bis $173000rr2 1 -2 from sp
1041 sub (sp)+,(r1) 1091 rts PC
1042 rts PC 1092
1043 1093 t07: / EIS
1044 1 hard part 1094 clrb bfl~
1045 / simulate the ssr2 re~ister missin~ on 11140 1095
1046 1096 uO: / Jmp, swab
1.047 backup: 1097 1.15: / sin~le OP
1.048 clr r2 I backup resister ssrl 1098 1l10V rl,rO
1049 IIIOV $l,bfl~ / clrs Jfl~ 1099 or set res

Reproduced under licence from the Western Electric Companw, NY Reproduced under licence from the Western Electric Companw, NY
Copwri~ht, J. Lions, 1976 Copwri~ht, J. Lions, 1976

Sheet 10 Sheet 10
Ma~ 24 12:29 1976 'Jni:·:/m40. s Page 11 Ma~ 24 12:29 1976 uni:{/m40.s Page 12

1100 1150 add ssr+2,rO


1101 t01: / II,OV 1151 11,0 V (rO),rO
1102 t02: / CII,P 1152
1103 t03: / bit 1153 / if reg has been incremented,
11. 04 t04: / bic 1154 I must decrement it before fetch
1.1 05 t05: / bis 1155
l.J. 06 t06: / add 1156 bit $174000,r2
1107 t16! / sub 1157 ble 2f
1108 clrb bflg 1158 dec rO
1109 1159 bit $10000, r2
1.110 tl1: / movb 1160 bee! 2f
1.111 t12: / cmpb 1161 dec rO
1112 t1:~: / bitb 1162 2:
1.113 t14: / bicb 1163
ill. 4 t15! / bisb 1164 / if mode is 6,7 fetch and add X(R) to R
1115 mov rl,rO 1165
1116 ash $-6,rO 1166 bit $4000,rl
1117 Jsr pc,setreg 1167 bee! 2f
1118 swab r2 1168 bit $2000,r1
1l.1. 9 1110 V rl,rO 1169 bee! 2f
1120 Jsr pc,setreg 1170 mov rO,-(sp)
1121 1171 mov ssr+4,rO
1.122 / if delta(dest) is zero, 1172 add $2,rO
1123 / no need to fetch source 1173 Jsr pc,fetch
1124 1174 add (sp)+,rO
1125 bit $370,r2 1175 2:
1126 bee! 1f 1176
1127 1177 / fetch operand
if II,ode (so'Jrce) is R, 1178 if mode is 3,5,7 fetch
1128
1129
/
/ no fault is possible 1179
/
*
1130 1180 .isr pc,fetch
1131 bit $7000,rl 1181 bit $1000,rl
1132 beQ 1f 1182 beQ 1f
1133 1183 bit $6000,rl
1134 / if reg (so'Jrce) is reg(dest), 1184 bne fetch
1.1.35 / too bad. 1185 1:
1.136 1186 rts pc
1137 11,0 V r2,-(sp) 1187
1138 bic $174370,(sp) 1188 t17! / illegal
1139 cII,pb 1(sp),(sp)+ 1189 u1: / br
1.1.40 bee! t17 1190 u2: / br
1141 1191 'J3: / br
1.1.42 I start source c\:lcle 1192 u7: / illegal
1.1.43 / pick UP value of reg 1193 incb Jflg
l.1.44 1194 rts pc
1145 mov r1,rO 1195
1146 ash $-6,rO 1196 setreg:
1.147 bic $!7,rO 1197 mov rO,-(sp)
1.1.48 movb _regloc(rO),rO 1198 bic $!7,rO
1.149 asl rO 1199 bis rO,r2

Reproduced under licence from the Western Electric Compan~, NY Reproduced under licence from the Western Electric Compan~. NY
COP\:Iright, J. Lions, 1976 Cop~right, J. Lions, 1976

Sheet 11 Sheet 11
May 24 12:29 1976 unix/m40.s PaSe 13 May 24 12:29 1976 urti:·:/m40. s Pase 14

1200 mov (sp)t,rO 1250 br 2f


1201 ash $-3,rO 1251
1202 bic $!7,rO 1252 _COpyout:
1203 movb Of(rO),rO 1253 Jsr pc,copsu
1.204 tstb bfls 1254 1:
1205 beG if 1255 mov (rO)+,-(sp)
1206 bit $2~r2 :[256 mtpi (r1 )t
1207 b(;)(l 2f 1257 sob r2,1b
1.208 bit $4, r2 1258 ....
,..,.
1209 bet~ 2f 1259 mov (sp)t,nofault
1210 1: 1260 mov (sp)-t·, r2
1211 CITIP rO,$20 1261 clr rO
1212 beG 2f 1262 rts PC
1213 cmp rO,$-20 1263
1.214 beG 2f 1264 COPSIJ:
1215 ;!<:;] rO 1265 ITIOV (sp)·h rO
1:~:L6 2: 1266 mov r2,-(sp)
1217 bisb rO,r2 1267 ITIOV nofault,-(sp)
1218 rts pc 1268 mov rO,-(sp)
1219 1269 mov 10(sp),rO
1.~~20 0: .b\:lte 1270 mov 12(sp),rl
1.221 1271 mov 14(sp),r2
1222 fetch: 1272 asr r2
1.223 bic $1,rO 1273 mov $1f,nofault
1.224 mov nofault,-(sp) 1274 rts pc
1225 ITIOV $1f,nofault 1275
1.226 ITlfpi (rO) 1276 U
1.227 mov (sp)t,rO 1277 mov (sp)t,nofaIJlt
1.228 ITIOV (sp)t,nofault 1278 mov (sp)t,r2
1.229 rts pc 1279 mov $-1,rO
1230 1280 rts pc
1231 U 1281
1232 mov (sp)t,nofault 1282 -------------------------
1233 clrb r2 I clear out dest on fault 1283 '*,slobl ._idle
1234 ITIOV $-1,rO 1284 _idle:
1235 rts pc 1285 mov PS,-(sp)
1236 1286 bic $340,PS
1237 • bss 1287 wait
1238 bflg: 1288 ITIOV (sp)t,PS
1239 Jfls: 1289 rts pc
1240 • te:·:t 1290
1241 1291 ------------------------- *1
1292 '*,slobl _spIO, _spI1, _spI4, _spI5, _spI6, _spI7
1242 1* -------------------------
1243 .slobl _copyin, _COpyout *' 1293 _spIO:
1244 _copyin: 1294 bic $340,PS
1245 Jsr PC,COPSIJ 1295 rts pc
1246 1: 1296
1247 ITlfpi ( rO)t 1297 _spIt:
1248 ITIOV (sp)t,(r1)t 1298 bis $40,PS
1249 sob r2,1b 1299 bic $300,PS

Reproduced under licence from the Western Electric Company, NY Reproduced under licence from the Western Electric Company, NY
Copyrisht, J. Lions, 1976 Copyrisht, J, Lions, 1976

Sheet 12 Sheet 12
Ma~ 24 12:29 1976 unix/m40.s Pa~e 15 Ma~ 24 12:29 1976 unix/m40.s Pa~e 16

1300 rts PC 1350


1301. 1351 1* ------------------------- *1
1302 __ sp14: 1352 .~lobl d'.Jn,p
1303 __ sF,15 : 1353 dump:
1304 bis $340,PS 1354 bit $1,SSRO
1305 bic $100,PS 1355 bne dunlp
1306 rts PC 1356
1307 1357 I save re~s rO,r1,r2,r3,r4,r5,r6,KIA6
1.308 __ spI6: 1358 I startin~ at abs location 4
1309 bis $340,PS 1359
1.310 bic $40,PS 1360 mov 1'0,4
1.311 rts PC 1361 mov $6,1'0
1312 1362 nlov 1'1'(1'0)+
131.3 _.spI7: 1363 moy 1'2'(1'0)+
1314 bis $340,PS 1364 moy 1'3'(1'0)+
1315 rt.s PC 1365 mov 1'4'(1'0)+
1316 1366 mov 1'5,(1'0)+
1317 1* ------------------------- *1 1367 mo\' sp,(rO)+
1.31.8 .globl _dpadd 1368 mov KISA6,(1'0)t
1319 _dpadd: 1369
1320 mov 2(51")'1'0 1370 I dump all of core (ie to first mt. error)
1321 add 4(51"),2(1'0) 1371 I onto mas tape. (9 tl'ack or 7 track 'binar~')
1322 adc (1'0) 1372
1323 rts pc 1373 mov $MTC,rO
1.324 1374 Il,OY $60004'(1'0)+
1325 1* ------------------------- *1 1375 clr 2(1'0)
1326 .slobl _dpcmp 1376 1:
1327 _dpcmp! 1377 mov $-512.,(1'0)
1328 moy 2(sp),rO 1378 inc -(1'0)
1329 mov 4(51")'1'1 1379 ....
'"I.

(1'0)
1330 sub 6(51"),1'0 1380 tstb
1331 sub 8(51"),1'1 1381 b~e 2b
1332 sbc 1'0 1382 tst ( rO)t
1.333 bse 1f 1383 b~e 1b
1334 cmp 1'0,$-1 1384 reset
1335 bne 2f 1385
1336 cmp 1'1,$-512. 1386 I end of file and 1001"
1337 bhi 3f 1387
1338 2: 1388 11,0 V $60007,-(1'0)
1.:''139 mov $-512.,1'0 1389 br
1340 rts pc 1390
1341 1: 1391 1* ------------------------- *1
1342 bne 2f 1392 .slobl _ldiv
1. :~43 cmp 1'1.$512. 1393 _ldiv:
1.:,44 blo 3f 1394 clr 1'0
1345 2: 1395 mov 2(sp),rl
1346 mov $512.,1'1 1396 div 4(sp),rO
1347 ~5 : 1397 rts pc
1348 mov 1'1,1'0 1398
1.:549 T'tS PC 1399 1* ------------------------- *1

Reproduced under licence from the Western Electric Companw, NY Reproduced under licence from the Western Electric Compan~, NY
Copwrisht, J. Lions, 1976 Copwrisht, J. Lions, 1976

Sheet 13 Sheet 13
Maw 24 12:29 1976 unix/m40.s Pa~e 17 Maw 24 12:29 1976 unix/m40.s Pase 18

1400 .~lobl _lrem 1450 MTC 172522


1401 _lrem: 1451 UISAO 177640
1402 clr rO 1452 UISA1 177642
1403 mov 2(sp),r1 1453 U1SDO 177600
1404 div 4(sp),rO 1454 UISD1 177602
1405 mov r1,rO 1455 10 = 7600
1406 rts PC 1456
1407 1457 .data
1408 1* ------------------------- *1 1458 1* ------------------------- *1
1409 .~lobl _lshift 1459 .slobl _ka6. _cputype
1410 _lshift: 1460 _ka6: K1SA6
1411 mov 2(sp),r1 1461 _cputwpe:40.
1.412 11,0'1 (r1)+,rO 1462
1413 mov (r1),r1 1463 .bss
1414 ashc 4(sp),rO 1464 1* ------------------------- *1
141:.3 mov ilii'O 1465 .~lobl nofault. ssr, badtrap
1416 l'ts PC 1466 nofault:.=.+2
1417 1467 ssr: .=.+6
1418 1* ------------------------- *1 1468 badtrap:.=.+2
1419 ,slobl csv 1469
1420 csv: 1470
1421 1110'1 r5.rO 1471
1422 mov sp,r5 1472
1.423 11,0'1 r4,-(sp) 1473
1424 mov r3.-(sp) 1474
1425 mov r2,-(sp) 1475
1426 Jsr pc.(rO) 1476
1427 1477
1428 1* ------------------------- *1 1478
1429 .~lobl cret 1479
1430 cret: 1480
1431 mov r5,r1 1481
1432 mov -(rl),r4 1482
1433 mov -(r1).r3 1483
1434 mov -(r1),r2 1484
1435 mov r5,sp 1485
1436 mov (sp)+,r5 1486
1437 rts PC 1487
1438 1488
1439 1* ------------------------- *1 1489
1440 .~lobl _'J 1490
1441 _'J = 140000 1491
1442 USIZE 16. 1492
1443 1493
1444 PS 177776 1494
1445 SSRO 177572 1495
1446 SSR2 177576 1496
1447 KISAO = 172340 1497
1448 KISA6 172354 1498
1449 KISDO 172300 1499

Reproduced under licence from the Western Electric Companw, NY Reproduced under licence from the Western Electric Company, NY
CoPYri~ht, J. Lions, 1976 Copyright, J. Lions. 1976

Sheet 14 Sheet 14
Ma~ 24 12:29 1976 unix/main.c PaSe 1 Ma~ 24 12:29 1976 unix/main.c PaSe 2

1500 t 1550 maine)


1501 tinclude ',./param.h' 1551 {
1502 tinclude ' •• /user.h' 1552 extern schar;
1503 tinclude ' •• /sYstm.h' 1553 resister i, *p;
1504 tinclude ',./proc.h' 1554
1505 tinclude ',./text.h' 1555 /*
1506 tinclude ',./inode.h' 1556 * zero and free all of core
1507 tinclude ' •• /ses.h' 1557 */
1508 1558
1509 tdefine CLOCK 1 0177546 1559 'JPdlock = 0;
1510 tdefine CLOCK2 0172540 1560 i = *ka6 + USIZE;
1511 1* 1561 UISD->r[O] = 077406;
1512 * Icode is the octal bootstrap 1562 fo r ( ; ;) {
1513
1514
**
pros ram executed in user mode
to brins UP the s~stem.
1563
1564
UISA->r[O] = i;
if(fuib~te(O) < 0)

1515 *1 1565
1566
break;
clearseSCi);
1516 int icode[]
1517 { 1567 ma:·:mem++ ;
1518 0104413, 1*
s~s exec; init; initp *1 1568 mfreeCcoremap, 1, i);
1519 0000014, 1569 itt;
1520 0000010, 1570 }

1521 0000777, /* br • *1 1571 ifCcputype == 70)


1522 0000014, /* initp: init; 0 */ 1572 forCi=O; i<62; i=+2) {
1523 0000000, 1573 UBMAP->r[i] = i«12;
1524 0062457, /* init: </etclinit\O> */ 1574 UBMAP->r[i+l1 = 0;
1525 0061564, 1575 }

1.526 0064457, 1576 printfCnmem = XI\n', maxmem*5/16);


1527 0064556, 1577 printfC'RESTRICTED RIGHTS\n\n');
1528 0000164, 1578 printfC"Use, duplication or disclosure is subject to\n');
1529 }; 1579 printfC"restrictions stated in Contract with Western\n');
1530 1* ------------------------- */ 1580
1581
printfC'Electric Company, Inc.\n');
1531
1532 1* 1582 maxmem = minCmaxmem, MAXMEM);
1533 Initialization code. 1583 mfreeCswapmap, nswap, swplo);
1534 *
Called from m40.s ~r m45.s as 1584
1535 *
soon as a stack and sesmentation 1585 1** set
1536 **
have been established. 1586 UP system process
1537 Functions: 1587 *1
1538 *
clear and free user core 1588
1.539 **
find which clock is confiSured 1589
1590
proc[O].p_addr
proc[O].p_size
*ka6;
USIZE;
1540 hand craft Oth process
1541 **
call all initialization routines 1591
1592
proc[O].p_stat SRUN;
proc[O].p_flaS =: SLOAD:SSYS;
1542 fork - process 0 to schedule
1543 ** - process 1 execute bootstrap 1593
1594
u.u_procp = &proc[O];
1544 *
1545 *
panic: no clock -- neither clock responds 1595 1**
1546 *
loop at lac 6 in user mode -- /etc/init 1596 determine clock
1547 *
cannot be executed. 1597
1598
*I
1548 */
1549 1599 UISA->r[7J ka6[1]; /* io seSment */

Reproduced under licence from the Western Electric Company, NY Reproduced under licence from the Western Electric Company, NY
Cop~risht, J. Lions, 1976 CoPyrisht. J. Lions, 1976

Sheet 15 Sheet 15
May 24 12:29 1976 unix/main.c Pa~e 3 May 24 12:29 1976 unix/main.c Pa~e 4

1600 UISD-)r[7] = 077406; 1650 estaburCnt, nd, ns, sep)


1.601 1I<.s = CLOCK1; 1651 (
1602 ifCfuiwordClks) == -1) ( 1652 register a, tap, *dp;
1603 lks = CLOCK2; 1653
1604 ifCfuiword(lks) == -1) 1654 ifCsep) (
1605 panicCDno clock"). 1655 ifCcputwpe == 40)
i.bOb } 1656
1.607 *lks 0115. 1657 if(nsegCnt) > 8 :: nsegCnd)+nses(ns) 8)
1608 1658 soto err;
1609 1* 1659 } else
Ib10 * set UP 'known' i-nodes 1660 ifCnse~Cnt)+nsesCnd)tnsesCns) ) 8)
1.611 *1 1661
1662
goto err;
ifCnt+nd+ns+USIZE ) maxmem)
1.61.2
1613 cinitC); 1663 goto err;
1614 binitC); 1664 a = 0;
1615 iinit(); 1665 ap = &u.u_uisa[O].
1616 rootdir = isetCrootdev, ROOTINO); 1666 dp = &u.u_uisd[O]'
1617 rootdir-)i_fla~ =& NILOCK; 1667 whileCnt >= 128) (
1618 u.u_cdir = isetCrootdev, ROOTINO); 1668 *dp++ = CI27«8) RD;
161.9 u.u_cdir-)i_fla~ =& NILOCK; 1669 *ap++ = a;
1.620 1670 a =+ 128.
1621
1622
1** make init process
1671
1672 }
nt 128;

1623 * enter scheduling loop 1673 if(nt) (


1624 * with system process 1674 *dp++ CCnt-l)«8) RD;
1625
1626
*1 1675
1676 }
*ap++ a;

1627 ifCnewprocO) ( 1677 ifCsep)


1628 expandCUSIZE+l); 1678 whileCap < &u.u_uisa[8]) {
1629 estaburCO, 1, 0, 0); 1679 *ap++ 0;
1630 COpyoutCicode. 0, sizeof icode). 1680 *dp++ = 0;
1631 1* 1681 }
1632 * Return ~oes to loco 0 of user init 1682 a USIZE;
1633 * code Just copied out. 1683 whileCnd >= 128) (
1634
1635
*1
return;
1684
1685
*dp++ = CI27«8)
*ap++ = a'
RW;

1636 } 1686 a =t 128;


1637 schedC); 1.687 nd 128;
1638 } 1688 }
1639 1* 1689 if (nd) (
1640 1690 *dp++ = C(nd-l)«8) RW;
1641
1642
1** Set software prototype se~mentation
UP
1691
1692
*ap++ = ao
a =+ nd;
1643 * registers to implement the 3 pseudo 1693
1694
}
whileCap < &u.u_uisa[8J) {
1644 * text,data,stack se~ment sizes passed
1645 * as ar~uments. 1695 *dp++ 0;
1646 * The ar~ument sep specifies if the 1696 *ap++ = 0;
1647 * text and data+stack se~ments are to 1697 }
1648 * be separated. 1698 ifCsep)
1649 *! 1699 whileCap < &u.u_uisa[16]) {

Reproduced under licence from the Western Electric Company, NY Reproduced under licence from the Western Electric Company, NY
Copyright, J. Lions, 1976 Copyright, J. Lions, 1976

Sheet 16 Sheet 16
May 24 12:29 1976 unix/main.c Pa~e 5 May 24 12:29 1976 unix/main.c Pase 6

1700 *d?++ 0; 1750 while(rp } &UISA-)r[O])


1701 *ap++ 0; 1751 *--rp = *--uP + a;
1702 } 1752 if«up=u.u_procp-}p_text?) != NULL)
1703 a =+ ns; 1753 a =- up-}x_caddr,
1704 while(ns }= 128) { 1754 UP = &u.u_uisd[16];
1705 a =- 128; 1755 r? = &UISD-}r[16];
1706 ns =- 128, 1756 if(cputype 40) {
1707 *--dp (127«8) RW; 1757 UP 8,
1708 *--ap = a; 1758 rp 8,
1709 } 1759 }
1710 if (ns) { 1760 while(rp ) &UISD-}r[O]) {
1711 *--dp «128-ns)«8) RW ED; 1761 *--rp = *--IJP;
1712 *--ap a-128; 1762 if«*rp & WO) == 0)
1713 } 1763 rp[(UISA-UISD)/2] a;
1714 if(!sep) { 1764 }
1715 ap = &u.u_uisa[O], 1765 }
1716 dp = &u.u_uisa[8]; 1766 1* -------------------------
1717 while(ap ( &u.u_uisa[8]) 1767
*dp++ = *ap++; 1768
1718
1719 ap = &u.u_uisd[O]; '*
1769 * Return the ars/128 rounded up.
1720 dp = &u.u_uisd[8]; 1770 *1
1771 nses(n)
1721 while(ap ( &u.u_uisd[8])
1722 *dp++ = *ap++; 1772 {
1723 } 1773
1724 sures(); 1774 return«n+127)})7);
1725 return(O); 1775 }
1726 1776 1* -------------------------
1727 err: 1777
1728 u.u_error ENOMEM, 1778
1729 return(-I); 1779
1730 } 1780
1731 1* ------------------------- *1 1781
1782
1732
1733 1** Load the user hardware sesmentation 1783
1784
1734
1735 * resisters from the software prototype. 1785
1736 * The software re~isters must have 1786
1737 * been setup prior by estabur. 1787
1738
1739
*1
sIJre~( )
1.788
1789
1740 { 1790
1741. 1791
1742 1792
1743 a = u+u_procp-}p_addr; 1793
1744 UP = &u.u_uisa[16J, 1794
1745 rp = &UISA-}r[16], 1795
1746 if(cputype 40) { 1796
1747 IJP 8, 1797
1748 rp 8; 1798
1749 } 1799

Reproduced under licence from the Western Electric Company, NY Reproduced under licence from the Western Electric Company, NY
CoPYrisht, J. Lions. 1976 CoPYrisht, J. Lions. 1976

Sheet 17 Sheet 17
May 24 12:30 1976 unix/slp.c Pase 1 May 24 12:30 1976 unix/slp.c PaSe 2

1800 t 1850 sata retrY;


180:L /* 1851 }-

1802 */ 1852 if «rpp = p)==NULL)


1803 1853 panicC"no procs·);
1804 tinclude ' •• /param.h' 1854
1805 tinclude ' •• /user.h' 1855 /*
1806 iinclude
iinclude
~ •• /proc.hM
' •• /text.h'
1856
1857
*U make proc entry for new proc
1807
1808 tinclude • •• /systm.h" 1858
lEl09 tinclude ' •• /file.h' 1859 rip = u.u_procp;
1810 iinclude ' •• /inode.h' 1860 UP == rip;
1811. tinclude " •• /buf.h" 1861 rpp-)p_stat = SRUN;
1812 /* ------------------------- */ 1862 rpp-)p_flaS = SLOAD;
1813 /* 1863 rpp-)p_uid = rip-)p_uid;
1814 *
Create a new process-- the internal version of 1864 rpp-)p_ttyp = rip-)p_ttyp;
HIt!"; **
BYB fork.
It returns 1 in the new process.
1865
1866
rpp-)p_nice = rip-)p_nice'
rpp-)p_textp = rip-)p_textp;
1. Ell. 6
1817 *
How this happ~ns is rather hard to understand. 1867 rpp-)p_pid = mpid;
lEl18 **
The essential fact is that the new process is created
in such a way that it appears to have started executing
1868
1869
rpp-)p_ppid rip-)p_pid;
T'pp-)p_time = 0;
1.819
1.820 *
in the same call to newproc as the parent. 1870

***
1821 but in fact the code that runs is that of swtch. 1871 /*
1822 The subtle implication of the returned value of swtch 1872 * make duplicate entries
1823 (see above) is that this is the value that newproc's
*
caller in the new process sees.
1873
:L874
* where needed
1824 */
1825 */ 1875
1826 newproc() 1876 farerip = &u.u_ofileCO]; rip <: &u.u_ofileCNOFILE];)
1827 { 1877 if«rpp = *riptt) != NULL>
1828 int al, a2; 1878 rpp-)f_count+t;
1829 struct proc *p, *UP; 1879 if«rpp=up-)p_textp) != NULL) {
1.El30 reSister struct proc *rpp; 1880 rpp-):·:_col.mttt;
lEl31 reSister *rip, n; 1881 rpp->:·LcCOIJnttt;
l.8~~2 1882 }
1.833 ? = NULU 1883 u.u_cdir-)i_counttt;
1834 /* 1884 /*
1835 * First, Just locate a slot for a process 1885 * Partially simulate the environment
1836 *
and copy the useful info fro·m this process into it.
* The panic ·cannot happen' because fork has already
1886
1887
* of the new process so that when it is actuallY
* created (by copyins) it will look risht.
1837
1838 *
checked for the existence of a slot. 1888
1889
U
savu(u.u_rsav);
1839 U
1840 retrY: 1890 rpp == p;
1841 ITIPidtH 1891 u.u_procp = rpp;
1842 if(mpid <: 0) { 1892 rip = UP;
1843 mpid 0; 1893 n = rip-)p_size;
1El44 soto retrY. 1894 a1 = rip-)p_addr;
1845 } 1895 rpp-)p_size = n;
1846 for(rp? = &proc[O]; rpp <: &proc[NPROC]; rpptt) { 1896 a2 = malloc(coremap, n);
l.847 if(rpp-)p_stat == NULL && p==NULL) 1897 /*
1848 p = rpp;
if (rpp-)p_pid==mpid)
1898
1899
** new
If there is not enouSh core for the
process, swap out the current process to
1849

Reproduced under licence from the Western Electric Company, NY Reproduced under licence from the Western Electric Company, NY
CopyriSht, J. Lions, 1976 Copyright, J. Lions, 1976

Sheet 18 Sheet 18
Maw 24 12:30 1976 unix/slp.c Pa~e 3 Maw 24 12:30 1976 unix/slp.c PaSe 4

1900
1901
* ~enerate the copw. 1950
1951 go to loop;
*1
1902 if(a2 == NULL> { 1952
1903 rip-)p_stat = S1DL; 1953 sloop:
1904 rpp-)p_addr = al; 1954 runin+H
1905 savIJ(u.IJ_ssav) ; 1955 sleep(&runin, PSWP) ;
1906 xswap(rpp, 0, 0); 1956
1907 rpp-)p_fla~ =: SSWAP; 1957 loop:
1908 rip-)p_stat = SRUN; 1958 sp 16 ( ) ;
1909 } else { 1959 n = -1;
1910 1* 1960 for(rp = &proc[O]; rp < &proc[NPROC]; rp++)
1911 *
There is core, so Just copw. 1961 ifCrp-)p_stat==SRUN && (rp-)p_flag&SLOAD)==O &&
1912 *1 1962 rp-)p_time ) n) {
1913 rpp-)p_addr = a2; 1963 pI = rp;
1914 while(n--) 1964
1915 copwse~(a1++, a2++); 1965 }
1916 } 1966 if(n -1) {
1917 u.u_procp rip; 1967 runout++;
1918 ,'eturn(O) ; 1968 sleepC&runout, PSWP);
1919 } 1969 goto loop;
1920 1* *1 1970 }
1921 1971
1922 1* 1972 1*
1923 *
The main loop of the schedulin~ Cswappin~) 1973 * see if there is core for that process
1924 * process. 1974 *1
1925
1926
*
The basic idea is:
see if anyone wants to be swapped in;
1975
spIO() ;
1976
1927 *swap out processes until there is room; 1977
1928 ** swap him in; 1978 a = rp->p_size;
1929 reF'eat. 1979 ifCCrp=rp-)p_textp) != NULL)
1930 * Althoush it is not remarkablw evident, the basic 1980
1931 **synchronization here is on the runin fla~p which is 1981 a =+ rp->x_size;
1932 slept on and is set once per second bw the clock routine. 1982 ifCCa=mallocCcoremap, a)) != NULL)
1933
1934 ***
Core shufflin~ therefore takes place once per second. 1983
1984
~oto found2;

1935 panic: swap error -- 10 error while swappinS. 1985 1*


1936
1937
*this is the one panic that should be
*
handled in a less drastic way. Its
1986
1987
*
*
none found,
look around for easw core
1938 * verw hard. 1988 *1
1939 *1 1989
1940 sched( ) 1990 spI6C);
1941 { 1991 forCrp = &proc[O]; rp < &proc[NPROC]; rp++)
1942 struct proc *p1; 1992 ifCCrp->p_flag&CSSYS:SLOCK:SLOAD»==SLOAD &&
1943 resister struct proc *rp; 1993 Crp-)p_stat == SWAIT :: rp->p_stat==SSTOP»
1944 re~ister a, n; 1994 soto found1;
1945 1995
1946 1* 1996 1*
1947 *
find user to swap in 1997 * no easw core,
1948 *
of users readw, select one out lonsest 1998 * if this process is deserving,
1949 *1 1999 * look around for

Reproduced under licence from the Western Electric Companw, NY Reproduced under licence from the Western Electric Company, NY
CopwriSht. J. Lions, 1976 Copyright, J. Lions, 1976

Sheet 19 Sheet 19
Maw 24 12:30 1976 unix/slp.c Pa~e 5 Maw 24 12:30 1976 unix/slp.c Pa~e 6

2000
2001
* oldest process in core 2050
2051
swaper:
panicC"swap error");
*1
2002 2052 }
2003 ifCn < 3) 2053 1* -------------------------
2004 ~oto sloop; 2054
2005 n = -1; 2055 1*
2006
2007
ror(r? = &procCOJ; rp ( &procCNPROC]; rptt)
if«rp-)p_fla~&(SSYSISLOCKISLOAD»==SLOAD &&
2056
2057 ** Give the processor till a wakeup occurs
UP
on chan, at which time the process
2008 Crp-)p_stat==SRUN II rp-)p_stat==SSLEEP) &&
rp-)p_time ) n) {
2058
2059
* The
enters the Queue at priority pri.
schedulin~
most important effect of pri is that when
2009
20l.0 2060 ** pri(O a signal cannot disturb the sleep;
2011 2061 if pri)=O signals will be processed.
2012 }
ifCn ( 2)
2062
2063
** premature
Callers of this routine must be prepared for
return. and check that the reason for
2013
201.4
rp p1;
soto sloop; 2064 * sleeping has Sone awaw.
2015 2065 *!
2016 2066 sleep(chan. pri)
2017 1* 2067 (
2018 * swap user OIJt 2068 re~ister *rp, s;
2019 *1 2069
2020 2070 s = PS-)inte~;
2021 f()und1: 2071 rp = IJ. u_p rocp;
202~~ splO(); 2072 if(pri )= 0) (
2023 rp-)p_fla~ =& NSLOAD; 2073 if(issi~(»
2024 xswapCrp,l. 0); 2074 ~oto psi~;
2025 so to loop; 2075 sp16();
2026 2076 rp-)p_wchan = chan;
2027 1* 2077 rp-)p_stat = SWAIT;
2028 * swap IJser in 2078 rp-)p_pri = pri;
2029 *1 2079 splO ( );
2030 2080 ifCrunin != 0) (
2031 found2: 2081 runin = 0;
2032 ifCCrp=p1-)p_textp)!= NULL) ( 2082 wakeupC&runin);
2033 ifCrp-)x_ccount == 0) ( 2083 }
2034 ifCswapCrp-)x_daddr, a, rp-)x_size, B_READ» 2084 swtchC);
2035 soto swaper; 2085 ifCissi90)
2036 rp->x_caddr = a; 2086 goto psi!;!;
2037 a =t rp->x_size; 2087 } else (
2038 } 2088 spI6C);
2039 rp-)x_ccoIJnttt; 2089 rp-)p_wchan = chan;
2040 } 2090 rp-)p_stat = SSLEEP;
2041 rp p1; 2091 rp-)p_pri = pri;
2042 ifCswapCrp->p_addr, a, rp->p_size, B_READ» 2092 splOC);
2043 ~oto swaper; 2093 swtchC);
2044 mfree(swapmap, (rp-)p_sizet7)/8, rp-)p_addr); 2094 }
2045 rp-)p_addr = a; 2095 PS-)integ = s;
2046· rp->p_fla~ =1 SLOAD; 2096 return;
2047 rp-)p_time = 0; 2097
2048 soto loop; 2098 1*
2049 2099 * If prioritw was low ()=o) and

Reproduced under licence from the Western Electric Companw, NY Reproduced under licence from the Western Electric Companw. NY
Copwright, J. Lions, 1976 Copwright, J. Lions. 1976

Sheet 20 Sheet 20
Ma~ 24 12:30 1976 unix/slp.c PaSe 7 Ma~ 24 12:30 1976 unix/slp.c Page 8

2100 * there has been a signal, 2150 1*


2101 * execute non-local Soto to 2151 * Set user priorit~.
2102 * the Gsav location. 2152 * The reschedulinS flag (runrun)
2103 * (see trap1/trap.c) 2153 * is set if the priorit~ is higher
2104 *1 2154 * than the currentl~ running process.
2105 psis: 2155 *1
2106 aretu(u.u_Gsav)i 2156 setpriCup)
2107 } 2157 {
2108 1* ------------------------- *1 2158 resister *pp, p;
2109 2159
2110
2111
'** Wake UP all processes sleepinS on chan.
2160
2161
pp = up;
p = (pp-)p_cpu & 0377)/16;
2112 *1 2162 p =+ PUSER + pp-)p_nice;
2113 wakeup(chan) 2163 ifCp :> 127>
2114 { 2164 p = 127;
2115 resister struct proc *p; 2165 ifCp ..' curpri)
2116 resister c, i; 2166 runrIJn++;
2117 2167 pp->p_pri = p;
2118 c = chan; 2168 }
21.19 p = &proc[O]; 2169 1* -------------------------
2120 i - NPROC' 2170
2121 do { 2171
2122 if(p-)p_wchan == c) { 2172 1*
2123 set rlJn (p ) ; 2173 * This routine is called to reschedule the CPU.
2124 } 2174 * if the calling process is not in RUN state.
2125
2126
p+H
} whileC--i);
2175 * arrangements for it to restart must have
* been made elsewhere. usuall~ b~ callina via sleep.
2176
2127 } 2177 *1
2128
2129
1* ------------------------- *1 2178
2179
swtch C)
{
2130 1* 2180 static struct proc *p;
2131 * Set the process running; 2181 resister i, n'
2132 * arranSe for it to be swapped in if necessar~. 2182 reSister struct proc *rp;
2133 *1 2183
2134 setrIJn(p) 2184 ifCp NULL)
2135 { 2185 p = &proc[O];
2136
2137
resister struct proc *rp; 2186
2187
1** Remember stack of caller
2138
2139
rp = P?
rp-)p_wchan = 0;
2188
2189
*1
savu(u.u_rsav);
2140
2141
rp-)p_stat = SRUN;
if(rp-)p_pri < curpri)
2190
2191
1** Switch to scheduler's stack
2142
2143
rIJnrun++ ;
if(runout != 0 && (rp-)p_flag&SLOAD)
2192 *1
0) { 2193
2144 runout = 0; 2194
2145 wakeupC&runout); 2195 loop:
2146 } 2196 run run = 0;
2147 } 2197 rp = p;
2148 1* 2198 p = NULU
2149 2199 n = 128;

Reproduced under licence from the Western Electric Compan~, NY Reproduced under licence from the Western Electric Compan~, NY
Cop~risht, J. Lions, 1976 Cop~riSht. J. Lions, 1976

Sheet 21 Sheet 21
Ma~ 24 12:30 1976 unix/slp.c Pa~e 9 Ma~ 24 12:30 1976 unix/slp.c Pa~e 10

2200 1* 2250
2201 * Search for hi~hest-priorit~ runnable process 2251 1*
2202 *1 2252 * Chan~e the size of the datatstack re~ions of the process.
2203 i = NPROC; 2253 * If the size is shrinkin~, it's eas~-- Just release the
2204 do { 2254 * extra core. If it's ~rowin~, and there is core, Just
2205
2206 if(rp )=Iproc[NPROC])
2255
2256 **allocate it and cop~ the ima~e, takin~ care to reset
re~isters to account for the fact that the s~stem's
2207
2208
rp = &proc[O];
ifCrp-)p_stat==SRUN && Crp-)p_fla~&SLOAD)!=O) {
2257
2258
**stack has moved.
If there is no core, arran~e for the process to be
2209 ifCrp-)p_pri < n) {
p := rp;
2259 * swapped out after adjustin~ the size reGuirement--
2260 * when it comes in, enoush core will be allocated.
2210
2211 n = rp-)p_pri; 2261 * Because of the ssave and SSWAP fla~s, control will
2212 } 2262 * resume after the swap in swtch, which executes the return
221.3
2214
}
} while(.--i);
2263
2264
* from this stack level.

2215
2216
1** If no process is runnable, idle.
2265
2266
** After the expansion, the caller will take care of cop~in~
the user's stack towards or awa~ from the data ared.
221.7 *1 2267 *1
2218 if(p == NULL> { 2268 e;·:pand( newsize)
2219 p = rp; 2269 {
2220 idleC); 2270 int i, n;
2221 aoto loop; 2271 re~ister *p, al,
..')'") "/") } 2272
L~"''''

2223 rp = p; 2273 p = u.u_procp;


2224 curpri = n; 2274 n = p-)p_size;
2225 1* Switch to stack of the new process and set UP 2275 p-)p_size = newsize;
2226 *
his se~mentation re~isters. 2276 a1 = p-)p_addr;
ifCn·)= newsize) {
2227 *f 2277
2228 retuCrp-)p_addr); 2278 mfree(coremap, n-newsize, a1tnewsize);
2229 sure~C); 2279 return;
2230 1* 2280 }
2231 * If the new process paused because it was 2281 savIJCu.u_rsav) ;
2232 *
swapped out, set the stack level to the last call 2282 a2 = mallocCcoremap, newsize);
ifCa2 :== NULL) {
2233 * to savu(u_ssav). This means that the return 2283
2234 * which is executed immediatel~ after the call to aretu 2284 savu(u.IJ_ssav) ;
2235 * actuall~ returns from the last routine which did 2285 xswap (p, 1, n);
2236 * the savu. 2286 p-)p_flas =l SSWAP;
2237 2287 swtch();
2238 *
* You are not expected to understand this. 2288 1* no retlJrn *1
2239 *1 2289 }
2240 ifCrp-)p_fla~&SSWAP) { 2290 p-)p_addr := a2;
2241 rp->p_fla~ =& HSSWAP; 2291 for(i=O; i<n; itt)
2242 aretu(u.u_ssav); 2292 cop~se~(a1ti, a2tt);
2243 } 2293 mfree(coremap, n, al);
2244 1*
The value returned here has man~ subtle implications. 2294 retu(p-)p_addr);
2245 * See the newproc comments. 2295 sures();
2246 *1 2296 }
2247 return(1); 2297 1* *1
2248 } 2298
2249 1* *1 2299

Reproduced under licence from the Western Electric Compan~, NY Reproduced under licence from the Western Electric Compan~, NY
Cop~ri~ht, J. Lions, 1976 Cop~risht, J. Lions, 1976

Sheet 22
May 24 12:30 1976 unixfprf.c PaSe 1 May 24 12:30 1976 unix/prf.c Page 2

2300 t 2350 return;


2301 f* 2351 p'Jtchar(c) ;
2302 *f 2352 }
2303 2353 c *flT.ttt;
2304 tinclude ' •• fparam,h' 2354 if(c 'd':: c == 'I' :: c , 0' )
2305 tinclude ',.fses.h' 2355 printn(*adx, c=='o'? 8: 10);
2306 tinclude ',./buf,h' 2356 if(c , s') {
2307 tinclude ',.fconf.h' 2357 s = *adx;
2308 2358 while(c
2309 1* 2359 putchar(c);
2310
2311
** Address and structure of the
KL-11 console device reSisters,
2360
2361
}
ad:·:tt;
2312 *I 2362 soto loop;
2313 str'Jct 2363 }
2314 { 2364 1*
2315 int rsr; 2365
2316
2317
int
int
rbr;
:·:sr;
2366
2367
f** Print an unsisned inteser in base b.
2318 int :-:br; 2368 *1
2319 H 2369 printn(n, b)
2320
2321
/* *f 2370 {
reSister a;
2371
2322 f* 2372
2323
2324
** panicstr
In case console is off,
contains argument to last
2373
2374
if(a = ldiv(n, b»
printn(a, b);
2325 * call to panic. 2375 putchar(lrem(n, b) t '0');
2326 *f 2376 }
2327 2377 f* *I
2328 char *panicstr; 2378
2329 2379 1*
2330 f* 2380 * Print a character on console.
2331 * Scaled down version of C Library printf, 2381 * Attempts to save and restore device
2332 * Only ~s ~l Xd (==Xl) Xo are recoSQized. 2382 * st.at'Js.
2333
2334
* Used
*
to print diaSnostic information
directlw on console ttw.
2383
2384
**
If the switches .areOi::.-all
printing is inhibi·ted.
2335 * Since it is not interrupt driven, 2385 *I
2336 * all system activities are pretty much 2386 putchar(c)
2337 * suspended. 2387 {
2338 * Printf should not be ~sed for chit-chat. 2388 reSister T'C' s;
2339 *1 2389
2340 printf(fmt,x1,x2,x3,x4,x5,x6,x7,x8,x9,xa,xb,xc) 2390 rc = c;
2341 char fmt[]; 2391 if(SW-)intes == 0)
2342 { 2392 return;
2343 register char Is; 2393 while«KL-)xsr&0200) 0)
2344 reSister *adx, c; 2394
2345 2395 if(rc == 0)
2346 ad:·: = &:·:1; 2396 return;
2347 loop: 2397 s = KL-»:sr;
2348 while( (c = *fmttt) ! = 'X') { 2398 KL-):·:sr 0;
2349 if(c == '\0') 2399 KL-):·:br = rc;

Reproduced under licence from the Western Electric Company, NY Reproduced under licence from the Western Electric Company, NY
CopYrisht, J. Lions, 1976 CoPYriSht, J. Lions, 1976
Sheet 23 Sheet 23
May 24 12:30 1976 unix/prf.c PaSe 3 May 24 12:30 1976 unix/prf.c PaSe 4

2400 ifCrc == '\n') { 2450


2401 p'JtcharC '\r'); 2451
2402 putchar(0177); 2452 rbp = bp;
2403 putchar(0177) ; 2453 prdevCaerr", rbp->b_dev);
2404 } 2454 printf("bnZI erZo Zo\n", rbp->b_blkno, 01, 02);
2405 putcharCO) ; 2455 }
2406 KL->:{sr = s; 2456 /It.
2407 } 2457
2408 /* ------------------------- */ 2458
2409 2459
2410 /* 2460
2411 * Panic is called on unresolvable
2412 * fatal errors.
2461
2462
2413 * It syncs, prints "panic: mesS" and 2463
*
<'!4 1. 4
2415
then loops.
'!!/
2464
2465
2416 panicCs) 2466
2417 char *s; 2467
2418 { 2468
2419 panicstr = s; 2469
2420 ,Jpdate ( ) ; 2470
2421 printfC"panic: Xs\n", s); 2471
2422 forCH) 2472
2423 idle(); 2473
2424 } 2474
2425 1* 2475
2426 2476
2427 1* 2477
2428 * prdev prints a warnins messase of the 2478
2429 * form "mesS on dev x/yo. 2479
2430
2431
** x and yare the maJor and minor parts of
the device arSument.
2480
2481
2432 *1 2482
2433 prdev(str, dev) 2483
2434 { 2484
2435 2485
2436 printfC"Xs on dev XI/XI\n", str, dev.d_maJor, dev.d_minor);2486
2437 } 2487
2438 1* 2488
2439 2489
2440 1* 2490
2441
2442
*
*
deverr prints a diasnostic from
a device driver.
2491
2492
2443 * It prints the device, block number, 2493
2444 * and an octal word (usually some error 2494
2445 * status resister) passed as arSument. 2495
2446 *1 2496
2447 deverrorCbp, 01, 02) 2497
2448 int *bp; 2498
2449 { 2499

Reproduced under licence from the Western Electric Company, NY Reproduced under licence from the Western Electric Company, NY
CopYrisht, J. Lions, 1976 Copyrisht, J. Lions, 1976

Sheet 24 Sheet 24
Maw 24 12:30 1976 unix/malloc.c Page 1 Ma~ 24 12:30 1976 unix/malloc.c Page 2

2500
2501 1*
* 2550 1*
2551 Free the previouslw allocated space aa
2502 *1 2552 *of size units into the specified map.
2503 2553 *Sort aa into map and combine on
2504 2554 *one or both ends if possible.
2505
1*
* Structure of the coremap and swapmap 2555 *1*
2506 * arraws. Consists of non-zero count 2556 mfree(mp, size, aa)
2507 * and base address of that manw 2557 struct map *mp;
2508 * contiguous units. 2558 {
2509 * (The coremap unit is 64 bwtes, 2559 register struct map *bp;
2510 * the swapmap unit is 512 b~tes) 2560
2561
register int t;
register int a;
2511 * The addresses are increasing and
2512 * the list is terminated with the 2562
2563 a = aa;
2513 * first zero count.
2514 *! 2564 for Cbp = mp; bp-)m_addr<=a && bp-)m_size!=O; bp+t) ;
2515 struct map 2565 if (bp)mp && (bp-1)-)m_addrt(bp-1)-)m_size a) {
2516 .{ 2566 (bp-1)-)m_size =t size;
2517 char *m_size; 2567 if (atsize == bp-)m_addr) {
2518 char *m_addr; 2568 (bp-1)-)m_size =t bp-)m_size;
2519 }; 2569 while Cbp-)m_size) {
2520 2570 bptt;
2521 2571 (bp-1)-)m_addr
2522 1* 2572 (bp-1)->ITI_size
2523 * Allocate size units from the given 2573 }
2524 * map. Return the base of the allocated 2574 }
2525 * space. 2575 } else {
2526 * Algorithm is first fit. 2576 if (atsize == bp-)ITI_addr && bp-)ITI_size) {
2527 *1 2577
2528 mallocCmp, size) 2578 bp-)ITI_size =t size;
2529 struct map *mp; 2579 } else if (size) do {
2530 { 2580 t = bp-)ITI_addr;
2531 register int a; 2581 bp-)ITI_addr = a'
2532 register struct map *bp' 2582 a = t;
2533 2583 t = bp->m_size;
2534 for (bp = mp; bp-)m_size; bptt) { 2584 bp-)ITI_size = size;
2535 if (bp-)m_size )= size) { 2585 bptt;
2536 a = bp-)m_addr; 2586 } while (size = t);
2537 bp-)m_addr =t size. 2587 }
2538 if «bp-)m_size size) 0) 2588
2539 do { 2589
2540 bptt; 2590
2541 Cbp-1)-)m_addr = bp-)m_addr' 2591
2542 } whileCCbp-1)-)m_size = bp-)m_size)' 2592
2543 return(a) ; 2593
2544 } 2594
2545 } 2595
2546 return(O); 2596
2547 } 2597
2548 1* ------------------------- 2598
2549 2599

Reproduced under licence from the Western Electric Companw, NY Reproduced under licence from the Western Electric COITIPanw. NY
Copwright. J. Lions, 1976 Copwright, J. Lions, 1976

Sheet 25 Sheet 25
Maw 24 12:35 1976 unix/reg.h Page 1 Maw 24 12:35 1976 unix/trap.c Page 1

2600 1* 2650 "


2601 * Location of the users' stored 2651 "include ' •• /param.h"
2602 * registers relative to RO. 2652 "include " •• /swstm.h"
2603 * Usage is u.u_arO[XXJ. 2653 "include " •• /user.h"
2604 *1 2654 "include " •• /proc.h"
2605 "define RO (0 ) 2655 "include " •• /reg.h"
2606 "define R1 (-2) 2656 "include " •• /seg.h"
2607 "define R'"'
"- (-9) 2657
2608 "define R3 (-8) 2658 "define EBIT 1 1*
user error bit in PS: C-bit *1
2609 idefine R4 (-7) 2659 "define UMODE 0170000 1*
user-mode bits in F'S word *I
2610
2611
tdefin(~
tdefine
R5
R6
(-6)
(-3)
2660
2661
"define SETD
SYS
0170011 1*
SETD instr'Jction *I
0104400 1* sws (trap) instr'Jction *I
"define
2612
2613
tdefir.e
tdefine
R7
RPS
(1 )
(2 )
2662
2663
"define USER 020 1* user-mode flag added to dev *1
2614 2664 1*
2615 "define TBIT 020 1* PS trace bit *1 2665 * structu~e of the swstem entrw table (swsent.c)
2616 2666 *I
2617 2667 struct swsent {
2618 2668 int count; 1* argument count *1
2619 2669 int (*call)(); 1* name of handler *1
2620 2670 } swsent[64J;
2621
2622
2671 1* ------------------------- *1
2672
2623 2673 1*
2624 2674 * Offsets of the user's registers relative to
2625 2675 * the saved rOo See reg.h
2626 2676 *I
2627 2677 char regloc[9J
2628 2678 {
2629 2679 RO, Rl, R2, R3. R4, R5, R6, R7, RPS
2630 2680 };
2631 2681 1* ------------------------- *1
2632 2682
2633 2683 1*
2634 2684 * Called from 140.s or 145.s when a trap occurs.
processo~
2635 2685 * The arguments ar~ the words saved on the system stack
2636 2686 * by the hardware and software during the trap processing.
2637 2687 * Their order is dictated by the hardware and the details
2638 2688 * of C's calling seauence. They are peculiar in that
2639 2689 * this call is not 'by value' and changed user registers
2640 2690 * get copied back on return.
264:1 2691 * dev is the kind of trap that occurred.
2642 2692 *I
2643 2693 trap(dev. sp, rl, nps, rO, pc, ps)
2644 2694 {
2645 2695 register i, a;
2646 2696 register struct swsent Icallp;
2647 2697
2648 2698 savfp();
2649 2699 if «ps&UMODE) UMODE)

Reproduced under licence from the Western Electric Companw, NY Reproduced under licence from the Western Electric Companw, NY
Copwright, J. Lions, 1976 Copyright, J. Lions, 1976

Sheet 26 Sheet 26
Ma~ 24 12:35 1976 unix/trap.c Page 2 Ma~ 24 12:35 1976 unix/trap.c Page 3

2700 dev = I USEF,; 2750


2701 u.u_arO "" &rO; 2751 case 6+USER: 1* s~s call *1
2702 switch(dev) { 2752 u.u_error = 0;
2703 2753 ps =& NEBIT.
2704 1* 2754 callp = &s~sent[fuiword(pc-2)&077J,
2?05 * Trap not expected.
* Usuall~ a kernel mode bus error.
2755
2756
if (callp == s~sent) { 1* indirect *1
a:::: fuiword(pc);
27()6
2707 * The numbers printed are used to 2757 pc ,~+ 2,
2708 * find the hardware PS/PC as follows. 2758 i "" fuwoT'dCa)'
2709 * (all numbers in octal 18 bits) 2759 if C(i & N077) ! = SYS)
2?J.0 * address_of_saved_ps = 2760 i "" 077;
calIF = &s~sent[i&077J.
27:l1 * Cka6*01(0) + aps - 0140000; 2761
2712 * address_of_saved_pc = 2762 forCi=O; i<callp-)count; itt)
27:l:5 * address_of_saved_ps - 2, 2763 u.u_arg[iJ = fuword(a =t 2);
27:l4 *! 2764 } else (
2715 default: 27,<,5 forCi=O; i<callp-)count; itt) {
2716 printfC"ka6 = Xo\n", *ka6)' 2766 u,u_arg[iJ = fuiwordlpc)f
2?:l7 printfC'aps = %o\n', &ps), 2767 PC ~,t 2;
27Hl printfC"trap t~pe Xo\n', dev), 2768 }
27:[9 panic('trap'); 2769 }
2720 2770 u.u_dirp = u.u_arg[O];
2721 case O+USER: 1* bus error *1 2771 trap1(callp-)call);
::.~n2 i == SIGBUS; 2772 if Cu. IJ_intfls.j)
2?23 bT'eak; 2773 u.u_error = EINTR,
2724 2774 ifCu.u_error < 100) (
2725 1* 2775 if(u.IJ_error) {
2726 * If illegal instructions are not 2776 ps "'"I EBIT;
2727 * beingcaught and the offending instruction 2777 rO = u.u_error;
2728 * is a SETD, the trap is ignored. 2778 }
2729 * This is because C produces a SETD at 2779 soto OIJt;
2"730 * the beginning of ever~ program which 2780 }-
27:31 * will trap on CPUs without 11/45 FPU. 2781 i SIGSYS.
2732 *! 2782 break;
2733 case 1+USER: 1* illegal instruction *1 2783
2734 ifCfuiwordCpc-2)==SETD && u.u_signal[SIGINSJ==O) 2784 1*
2735 soto OIJt, 2785 * Since the floating exception is an
2736 i = SIGINS; 2786 * imprecise trap, a user generated
2n7 'break. 2787 * trap ma~ come from kernel
actuall~
2738 2788 * mode. In this case, a signal is sent
2739 case 2+USER: 1* bpt or trace *1 2789 * to the current process to be picked
2740 i = SIGTRC; 2790 * later.
UP
2741 break. 2791 *!
2742 2792 case 8: 1* floating exception *1
2743 case 3tUSER: 1*iot *1 2793 psignaICu.u_procp, SIGFPT);
2744 i = SIGWH 2794 return;
2745 break; 2795
2746 2796 case 8tUSER!
2747 case 5tUSER: 1* emt *1 2797 i = SIGFF-T;
2748 i = SIGEMH 2798 breal";
2749 breald 2799

Reproduced under licence from the Western ~lectric Compan~, NY Reproduced under licence from the Western Electric Compan~, NY
Cop~right, J. Lions, 1976 Cop~right, J. Lions, 1976

Sheet 27 Sheet 27
Ma~ 24 12:35 1976 unix/trap.c Page 4 Ma~ 24 12:35 1976 unix/tra?c Page 5

2800 1* 2850 1* ------------------------- *1


2801 * If the user SP is below the stack segment, 2851
2802 * grow the stackautomaticall~. 2852 1*
* nonexistent
2803
2804
** This relies on the
abilit~ of the hardware
to restart a half executed instruction.
2853
2854 *1
s~stem call-- set fatal error code.

2805 * On the 11/40 this is not the case and 2855 nos~s()
2806
2807
** The
the routine backup/140.s
ma~ fail.
classic example is on the instruction
2856
2857
{
u.u_error = 100;
2808 * cmp -(sp) ,-(sp) 2858 }
*I
2809 *1 2859 1* -------------------------
2810 case 9+USER: 1* segmentation exception *1 2860
2811 a = sp; 2861 1*
2812 if(backup(u.u_arO) == 0)
if(grow(a»
2862
2863
* Ignored
*1
s~stem call
2813
2814 gato out; 2864 nIJlls~s()
2815 i = SIGSEG; 2865 {
2816 break; 2866 }
2817 } 2867 1* ------------------------- *I
2818 iH 2868
2819 2869
2820 out: 2870
2821 if(issig(» 2871
2822 psig(); 2872
2823 setpri(u.u_procp); 2873
2824 } 2874
2825 1* ------------------------- *1 2875
2826 2876
2827 1* 2877
2828 Call the s~stem-entr~ routine f (out of the 2878
2829 ** s~sent table). This is a subroutine for trap, and 2879
2830 not in-line, because if a signal occurs 2880
2831 *during processing, an (abnormal) return is simulated from 2881
2832 **the last caller to savu(Gsav); if this took place 2882
2833 inside of trap, it wouldn't have a chance to clean up. 2883
2834 * 2884
2835 *
* If this occurs, the return takes place without 2885
2836 * clearing u_intflg; if it's still set, trap 2886
2837 * marks an error which means that a s~stem 2887
2838 * call (like read on a t~pewriter) got interrupted 2888
2839
2840
* b~ a sisnal. 2889
2890
*1
2841 trapl ( f ) 2891
2842 int (*f)(); 2892
2843 { 2893
2844 2894
2845 2895
2846 savu(u.u_Gsav); 2896
2847 (*f)(); 2897
2848 2898
2849 } 2899

Reproduced under licence from the Western Electric Companw, NY Reproduced under licence from the Western Electric Compan~, NY
Cop~right, J. Lions, 1976 Copwright, J. Lions, 1976

Sheet 28 Sheet 28
Ma~ 24 12:36 1976 uni:·:/s~sent. c F'ase 1 Ma\,l 24 12:36 1976 IJni}:/sssent. c F'aSe 2

2900 2950 0, &Setswit, /* 38 switch *1


2901 l** 2951 0, &nos\,lS, /* 39 ;.~
*1
2';>02 *1 2952 0,
0,
&nos'=ls, i* 40 ;< *I
dlJp *i
2903 2953 &dw"" , l* 41
2'704 1* 2954 0, &pipe, 1* 42 pipe *1
2905 * This table is the switch used to transfer 2955 1, &tilTles, /* 43 times *I
2'/06 to the appropriate routine for processins a S'=lstem call. 2956 4, &profilr /* 44 prof *1
~:9()7 ** Ei3ch row contains the nlJmbeT' of arSulTlents e}:pected 2957 0, &nos'=ls, 1* 45 tiu *I
2';>08 * and a pointer to the routine. 2958 0, &setsid, /* 46 setsid *1
2909 *1 2959 0, &Setgid, /* 47 setsid *1
2';>10 int s~~sent[ ] 2960 2, &ssig, /t 48 sis *I
29:l1 -( 2961 0, &nos'=ls, i* 49 >~ */
0, &nulls'=ls, 1* indir */ 2962 0, &nos'=ls, i* 50 *1
~!9:l2
2'?13 0, &re:·:it, °
1* 1 eHit */ 2963 0, &nos'=ls, /* 51
~<
v
*/
2914 0, &fork, 1* 2 fork *I 2964 0, &nos'=ls, I t 52 ~.~
*1
:~915 2? &r-eady !* 3 reBd *1 2965 0, &nos'=ls, 1* 53 ~.~
*1
2916 ')
.:.• !i' &write. 1* 4 write *1 2966 0, &nos'=ls, 1* 54 v
*1
2917 2, &open, 1* .;)" open *I 2967 0, &r.OSYSP i* 55 ~.~
*1
1'918 0, &close, 1* 6 close *I 2968 0, &nos'=ls, 1* 56 ~.~ *I
2919 0, &wait, 1* 7 wait *1 2969 0, &nos'=ls, 1* 57 ~.~ *f
2920 ::~ }I &creat, 1* 8 c r£!at *1 2970 0, &nos'=ls, f* 58 ~.~
*1
2921 '1 &J.ink,
"'-, 1* 9 1 inl~ *I 2971 0, &nos'=ls, .i*59 ,', *1
2922 1, &IJnl ink. l* 10 unl in/<. *1 2972 0, &nos'=ls, /* 60 >~ *1
292:~ 2, &e:·:ec, 1* 11 e:·:ec *I 2973 0. &nos'=ls, 1* 61 ;< *f
2924 l. , &chdir, 1* 1? chdir *1 2974 0, &nos'=ls. /* 6'1
"'- ;< * l
292~:; 0, &gtilTle, 1* 13 time *I 2975 0, &nos'=ls /* 63 ;< *1
2926 3. &lTlknod. f* 14 ITlknod *I 2976 };
2927 211 &chlTlod, 1* 15 = chlTlod *I 2977 1* ------------------------- */
2928 "''1-, &chown, 1* 16 c:hown *I 2978
2929 1 , &sbreak, f* 17 break *1 2979
29:';0 2, &stat, 1* 18 stat *I 2980
293:1. 2, &seek, 1* 19 seek *I 2981
2';>32 0, &Setpid, 1* 20 setF,id */ 2982
2933 3, &slTlount, f* 21 mount *I 2983
2934 1, &sumount, 1* 22 IJlTlount *1 2984
2';>35 0, &setuid, 1* 23 setlJid *1 2985
2936 0, &getuid, 1* 24 getuid *I 2986
2937 0, &stilTle, /* 25 stime *I 2987
2938 3, &F,trace, /* 26 ptrace *I 2988
2';>:39 0, &nos'=ls, 1* 27 >~ *1 2989
2940 1 , &fstat, 1* 28 fstat *I 2990
2941 0. &nOS\,lS, 1* 29
:.~ *I 2991
2942 1 • &nulls\,ls, 1* inoperative 1* 30 slTldate *1 2992
2943 1 , &stt\,l, 1* 31 stt'=l *1 2993
2';>44 1, &gtt~. 1* 32 stt'=l *1 2994
2945 0, &nos'=l~; , 1* 33 :< *1 2995
2946 0, &nice, 1* 34 nice *I 2996
2947 0, &sslep, 1* 35 sleep *1 2997
2948 0, &S'=lnc:, 1* 36 S'=lnc: */ 2998
2949 1 , &ki 11, /* 37 kill *1 2999

Reproduced under licence frolTl the Western Electric COITIPan'=l, NY Reproduced under licence from the Western Electric COITIPan'=l. NY
COP'=lright, J. Lions. 1976 COP\,lright. J. Lions, 1976

Sheet 29 Sheet 29
Haw 24 12:36 1976 unix/sws1.c Pa~e 1 Ma~ 24 12:36 1976 unix/s~s1.c PaSe 2

3000 t 3050 na = 0;
3001 tinclude ".~/param.h" 3051 nc = 0;
3002 tinclude " •• /swstm.h" 3052 while(ap = fuword(u.u_arg[l]» {
3003 linclude " •• /user.h" 3053 natt;
3004 linclude " •• /proc.h" 3054 if(ap == -1)
3005 linclude " •• /buf.h" 3055 soto bad;
3006 linclude " •• /res.h" 3056 u.u_arg[l] =t 2;
3007 tinclude " •• /inode.h" 3057 forU n {
3008 3058 c = fubyte(aptt);
3009 /* 3059 if(c == -1)
3010 * exec swstem call. 3060 goto bad;
3011 * Because of the fact that an I/O buffer is used 3061 *cptt c;
3012 * to store the caller's arguments durin~ exec, 3062 nct+;
3013 * and more buffers are needed to read in the text file, 3063 if(nc :::- 510) {
:1014 * deadly embraces waiting for free buffers are possible. 3064 u.u_error E2BIG;
3015 * Therefore the number of processes simultaneouslw 3065 soto bad;
3016 * running in exec has to be limited to NEXEC. 3066 }
3017 */ 3067 if(c 0)
3018 Idefine EXPRI -1 3068 break;
:1019 3069 }
3020 exec () 3070 }
3021 { 3071 if«nc&1) != 0) {
3022 int ap, na, nc, *bp; 3072 *cP+t 0;
3023 int ts, ds, sep; 3073 nett;
3024 register c, *ip; 3074 }
3025 resister char *cp; 3075
3026 e:-:t.e rn ucha r; 3076 1* read in first 8 b~tes
3027 3077
3078
*
of file for segment
* sizes:
3028 /*
3029 * pick UP file names 3079 * wO = 407/410/411 (410 -) RO t.ext) (411 -> sep III)
3030 * and check various modes 3080 * w1 text size
3031 * for execute permission 3081 * w2 data size
3032 */ 3082 * w3 bss size
3033 3083 *1
3034 ip = namei(&uchar, 0)' 3084
'3035 if ( i p == NULL> 3085 u.u_base = &u.u_ar~[O];
3036 return; 3086 u.u_count = 8;
3037 while(execnt )= NEXEC) 3087 u.u_offset[1] = 0;
3038 sleep(&execnt, EXPRI); 3088 u.u_offset[O] = 0;
3039 e:-:ecnttt; 3089 u.u_segflg U
3040 bp = getblk(NODEV); 3090 readi(ip);
3041 if(access(ip, IEXEC) :: (ip-)i_mode&IFHT)!=O) 3091 u.u_segflg 0;
3042 goto bad; 3092 if(u.u_error)
3043 3093 go to bad;
3044 1* 3094 sep = 0;
3045 * pack UP arguments int.o 3095 if(u.u_arg[O] == 0407) {
3046 * allocated disk buffer 3096 u.u_ars[2] =t u.u_arg[l];
3047 */ 3097 u.u_ars[1] = 0;
3048 3098 } else
3049 3099 if(u.u_ar~[O] == 0411)

Reproduced under licence from the Western Electric Companw, NY Reproduced under licence from the West.ern Electric Compan~, NY
Copwri~ht, J. Lions, 1976 Copwri~ht, J. Lions, 1976

Sheet 30 Sheet 30
Mas 24 12136 1976 unix/swsloc Page 3 Maw 24 12:36 1976 unix/sssioc Page 4

3100 sep++; else 3150 uou_ssize = SSIZE;


3101 if(uou_arg[OJ 1= 0410) { 3151 u.u_sep = sep;
3102 uou_error = ENOEXEC; 3152 estaburCuou_tsize, uou_dsize, uou_ssize. uou_sep);
3103 goto bad. 3153 cp = bp-)b_addr;
3104 } 3154 ap = -nc - na*2 - 4,
3105 ifCuou_arg[IJ1=0&&(ip-)i_flag&ITEXT)==01&ip-)i_count1=1){ 3155 uou_arO[R6] = ap;
3106 uou_error = ETXTBSYP 3156 suword(ap, na);
3107 goto bad. 3157 c = -nc;
3108 } 3158 whileCna--) {
3109 3159 suwordCap=+2, c);
3110
3111
1** find text and data sizes 3160
3161
do
subyteCc++. *cp)~
3112 * trw them out for possible 3162 whileC*cp++),
3113 * exceed of max sizes 3163 }
3114
3115
*1 3164
3165
suwordCap+2, -1);

3116 ts = «uou_arg[IJ+63»)6) & 01777, 3166 1*


3117 ds = «uou_arg[2J+uou_arg[3J+63»)6) & 01777; 3167 * set SUID/SGID protections, if no tracing
3118
3119
if(estaburCts, ds, SSIZE. sep»
goto bad;
3168 *1
3169
3120 3170 if (Cuou_procp-)p_flag&STRC)==O) {
3121 1* 3171 ifCip-)i_mode&ISUID)
3122 * allocate and clear core 3172 ifCuou_uid 1= 0) {
3123 * at this point. committed 3173 uou_uid = ip-)i_uidi
3124 * to the new image 3174 uou_procp-)p_uid = ip-)i_uid'
3125
3126
*1 3175
3176
}
ifCip-)i_mode&ISGID)
3127 u.u_prof[3J = 0, 3177 uou_sid = ip-)i_gid.
3128 xfree(), 3178 }
3129 expand(USIZE); 3179
3130 xaIIoc(ip)' 3180 1* clear sigs, regs and return *1
3131 c = USIZE+ds+SSIZE, 3181
3132 expandCc), 3182 c = ip,
3133 while(--c )= USIZEI 3183 forCip &uou_signal[O], ip < luou_signal[NSIG]. ip++)
3134 clearsegCuou_procp-)p_addr+c); 3184 if(C*ip & 1) == 0)
3135 3185 lip = 0,
3136 1* read in data segment *1 3186 forCcp = Iregloc[O]' cp < Iregloc[6],)
3137 3187 uou_arO[*cp++] = O.
3138 estabur(O, ds, 0, 0), 3188 uou_arO[R7] = 0;
3139 uou_base = 0; 3189 forCip = &uou_fsav[OJ, ip < &uou_fsav[25J,)
3140 u.u_offset[IJ = 020+uou_arg[IJ; 3190 *ip++ = 0;
3141 uou_count = uou_arg[2]; 3191
3142 readiCip); 3192
3143 3193 bad:
3144
3145
1** initialize stack segment
3194
3195
iputCip);
brelse(bp);
3146 *1 3196 ifCexecnt )= NEXEC)
3147 3197 wakeupC&execnt),
3148 u.u_tsize ts' 3198 execnt--.
3149 uou_dsize ds' 3199 }

Reproduced under licence from the Western Electric Companw, NY Reproduced under licence from the Western Electric Company, NY
Copwright, ~o Lions, 1976 Copwright, Jo Lions, 1976

Sheet 31 Sheet 31
Maw 24 12:36 1976 unix/swsl.c Page 5 Maw 24 12:36 1976 unix/swsl.c Page 6

3200 /* ------------------------- */ 3250 for(p = &proc[O]; p <: &proc[NPROC]; ptt)


3201 3251 if(a-)p_pid == p-)p_ppid) {
3202 /* exit swstem call: 3252 p-)p_ppid = 1;
3203 * pass back caller's rO 3253 if (p-)p_stat == SSTOP)
3204 */ 3254 setrIJn(p) ;
3205 rexitC) 3255 }
3206 { 3256 swtch ( ) ;
3207 3257 /* no return */
3208 IJ.u_arg[O] <:<: 8; 3258 }
3209 e~:i t (); 3259 a-)p_ppid = 1;
3210 } 3260 goto loop;
3211 /* ------------------------- */ 3261 }
3212 3262 /* -------------------------
3213 /* Release resources. 3263
3214 * Save u. area for parent to look at. 3264 /* Wait swstem call.
3215 * Enter zombie state. 3265 *
Search for a terminated (zombie) child,
3216 * Wake UP parent and init processes, 3266
3267
*
finallw law it to rest, and collect its status.
*
Look also for stopped (traced) children,
3217 * and dispose of children.
3218 */ 3268 *
and pass back status from them.
3219 e:dtC) 3269 */
3220 { 3270 waite)
3221 resister int *a, a; 3271 (
3222 resister struct proc *p; 3272 resister f, *bp;
3223 3273 resister struct proc *p;
3224 u.u_procp-)p_flas =& NSTRC; 3274
3225 forCa &u.u_sisnal[O]; a <: &u.u_sisnal[NSIG];) 3275 f = 0;
3226 *att = 1; 3276 loop:
3227 forCa &u.u_ofile[O]; a <: &u.u_6file[NOFILE]; att) 3277 for(p = &proc[O]' p <: &proc[NPROC]; ptt)
3228 i fCa = *a) { 3278 if(p-)p_ppid == u.u_procp-)p_pid) (
3229 *a = NULL; 3279 ftt;
~,230 closef(a); 3280 if(p-)p_stat == SZOMB) (
3231 } 3281 u.u_arO[RO] = p-)p_pid;
3232 iput (u .IJ_cdi r) ; 3282 bp = bread(swapdev, f=p-)p_addr);
3233 ~:free ( ) ; 3283 mfree(swapmap, 1, f);
3234 a = mallocCswapmap, 1); 3284 p-)p_stat = NULL;
3235 if(a == NULL) 3285 p-)p_pid = 0;
3236 panic("out of swap"); 3286 p-)p_ppid = 0;
3237 p = setblkCswapdev, a); 3287 p-)p_sig = 0;
3238 bcopw(&u, p-)b_addr, 256); 3288 p-)p_ttwp = 0;
3239 bwrite(p) ; 3289 p-)p_flas = 0;
3240 a = u.IJ_procp; 3290 p = bp-)b_addr;
3241 mfree(coremap, a-)p_size, a-)p_addr); 3291 u.u_cstime[O] =t p-)u_cstime[O]'
3242 a--)p_<3ddr <3; 3292 dpadd(u.u_cstime, p-)u_cstime[I]);
3243 a-)p_stat = SZOMB; 3293 dpadd(u.u_cstime, p-)u_stime);
3244 3294 u.u_cutimeCO] =t p-)u_cutimeCO];
3245 loop: 3295 dpadd(u.u_cutime, p-)u_cutime[I]);
3246 for(p = &proc[O]; p <: &proc[NPROC]; ptt) 3296 dpadd(u.u_cutime, p-)u_utime);
3247 if(a-)p_ppid == p-)p_pid) ( 3297 u.u_arO[Rl] = p-)u_ars[O];
3248 wakeup(&proc[I]); 3298 brelse(bp);
3249 wakeup(p); 3299 return;

Reproduced under licence from the Western Electric Companw, NY Reproduced under licence from the Western Electric Companw, NY
Copwrisht, J. Lions, 1976 Copwright, J. Lions, 1976

Sheet 32 Sheet 32
May 24 12:36 1976 unix/sysl.c Pa~e 7 May 24 12:36 1976 unix/sys1.c PaSe 8

3300 } 3350
330.1 if(p-)p_stat == SSTOP) { 3351 1* break system call.
3302 ifCCp-)p_fla~&SWTED) == 0) {
=1 SWTED.
3352 * --bad plannins: 'break" is a dirty word in C.
3303 p-)p_fla~ 3353 *1
3304 u.u_arO[ROJ p-)p_pid; 3354 sbreak<)
3305 u.u_arO[R1J Cp-)p_si~«8) 3355 {
~3306 017]; 3356
3307 retlJrn; 3357 int i.
3308 } 3358
3309 3359 1* set n to new data size
3310 setrlJnCp) ; 3360 set d to new-'old
3311 3361 * set n to new total size
3312 }
}
3362 *
*1
33:L3 ifCf) { 3363
3~314 3364 n = CC(u.u_ar~[OJ+63»)6) & 01777);
3315 soto lQQP~ 3365 ifC!u.u_sep)
3316
3317
}
u.u_error = ECHILD.
3366
3367 if(n < 0)
n =- nseSCu.u_tsize) *
128;

3318 } 3~568 n = 0;
3319 1* ------------------------- *1 3369 d = n - u.u~dsize;
3320 3370 n =+ USIZE+u.u_ssize;
3321 1* fork system call. *1 3371 ifCestabur(u.u_tsize. u.u_dsize+d. u.u_ssize. u.u_sep»
3322 forkC) 3372 return;
3323 { 3373 u.IJ_dsize =+ d;
3324 re~ister struct proc *pl, *p2; 3374 if Cd ) 0)
3325 3375
3326 p 1 = IJ. u_p rocp ; 3376 a u.u_procp-)p_addr + n - u.u_ssize;
3327 forCp2 = &proc[OJ; p2 < &proc[NPROCJ. p2++) 3377 i r,;
3328 ifCp2-)p_stat == NULL) 3378 n u.IJ_ssize;
3329 ~oto found. 3379 while(n--) {
3330 u.u_error = EAGAIN; 3380 coPYseS(a-d. a).
3331 ~oto out; 3381 a++;
3332 3382 }
3333 found: 3383 expand(i);
3334 ifCnewprocC» { 3384 return;
3335 u.u_arO[ROJ pl-)p_pid; 3385
3336 u.u_cstime[OJ 0; 3386 bis~er:
3337 u.u_cstime[lJ 0; 3387 expand(n);
3338 u.u_stime = 0; 3388 a = u.u_procp-)p_addr + n;
3339 u.u_cutime[OJ = 0; 3389 n = u.u_ssize;
3340 u.u_cutime[lJ = 0; 3390 whileCn--) {
3341 IJ.u_utime = 0; 3391 a--;
3342 return; 3392 coPyse~(a-d, a);
3343 } 3393 }
3344 3394 while(d--)
3345 3395 clearsesC--a);
3346 OIJt: 3396 }
3347 u.u_arO[R7J =+ 2; 3397 1* ------------------------- *1
3348 } 3398
3349 1* ------------------------- *1 3399

Reproduced under licence from the Western Electric Company, NY Reproduced under licence from the Western Electric Company, NY
Copyri~ht, J. Lions, 1976 Copyri~ht, J. Lions, 1976

Sheet 33 Sheet 33
Ma~ 24 12:36 1976 unix/sys4.c Pase 1 May 24 12:36 1976 unix/sys4.c PaSe 2

3400 t 3450 1* -------------------------


3401 1* 3451
3402 * Everything in this file is 3452 setIJid()
3403 * a routine implementins a system call. 3453
3454
{
3404 *!
3405 3455 u.u_arOCROJ.lobyte u.u_ruid;
3406 tinclude • •• /param.h· 3456 u.u_arOCROJ.hibyte u.u_uidj
3407 tinclude • •• /user.h· 3457 }
3408 iinclude • •• /res.h" 3458 1* -------------------------
3409 iinclude " •• /inode.h· 3459
3410 iinclude • •• /s~stm.h· 3460 setsidC)
3411 iinclude " •• /proc.h· 3461 {
3412 3462 resister sid;
3413 setswit() 3463
3414 { 3464 sid = u.u_arOCROJ.lob~te;
3415 3465 ifCu.u_rsid == sid.lob~te I I suserC» {
3416 u.u_arOCROJ = SW->intes; 3466 IJ.IJ_sid = sid;
3417 } 3467 IJ.u_rsid = sid;
3418 1* ------------------------- 3468 }
3419 3469 }
3420 stimeC) 3470 1*
3421 { 3471
3422 3472 setsid( )
3423 u.u_arOCROJ timeCOJ; 3473 {
3424 u.u_arOCR1J timeC1J; 3474
3425 } 3475 u.u_arOCROJ.lobyte u.u_rsidj
3426 1* ------------------------- 3476 u.u_arOCROJ.hibyte u.u_sid;
3427 3477 }
3428 stime( ) 3478 1*
3429 { 3479
3430 3480 SetpidC)
3431 ifCsuser(» { 3481 {
3432 timeCOJ = u.u_arOCROJ; 3482
3433 timeCIJ = u.u_arOCRIJ; 3483 }
3434 wal<.elJp CtOIJt) ; 3484 1*
~H35 } 3485
3436 } 3486 sync( )
3437 1* ------------------------- 3487 {
3438 3488
3439 setlJidC) 3489 IJpdate ( ) ;
3440 { 3490
3441 resister IJid; 3491
3442 3492
3443 uid = u.u_arOCROJ.lobyte; 3493 niceC)
3444 if(IJ,u_ruid == IJid.lob~te II suserC» -( 3494 {
3445 u.u_uid = uid; 3495 resister n;
3446 u.u_procp-)p_uid = uid; 3496
3447 u.u_ruid = uid; 3497 n = u.u_arOCROJ;
3448 } 3498 ifCn :> 20)
3449 } 3499 n = 20;

Reproduced under licence from the Western Electric Company, NY Reproduced under licence from the Western Electric Company, NY
Copyrisht, J. Lions, 1976 Copyrisht, J. Lions, 1976

Sheet 34 Sheet 34
Maw 24 12:36 1976 unix/sws40c PaSe 3 Maw 24 12136 1976 unix/sws40c PaSe 4

3500 if(n <


0 && !suser(» 3550 retuT'n;
3501 n =: 0; 3551 }
3502 uou_procp-)p_nice = n; 3552 if(access(ip, IEXEC»
3503 } 3553 soto bad;
3504 1* ------------------------- 3554
3505 3555 uou_cdir = ip;
3506 1* 3556 prele(ip);
3507 * Unlink swstem callo 3557 }
3508 * panic: unlink -- 'cannot happen" 3558 1* -------------------------
3509 *1 3559
3510 unlink() 3560 chlTlod ( )
3511 { 3561 {
3512 resister *ip, *pp; 3562
3513 e)·:te rn ucha 1"; 3563
3514 3564 if «ip = owner(» NULL)
3515 pp = namei(&uchar~ 2); 3565 return;
3516 if(pp == NULL) 3566 ip-)i_mode =& N07777;
3517 return; 3567 if (IJou_uid)
3518 prele(pp); 3568 u.u_arsC1J =& NISVTX;
3519 ip = iSet(pp-)i_dev, uou_dentou_ino); 3569 ip-)i_mode =: u.u_arSC1J&07777;
3520 if(ip == NULL> 3570 ip->i_flas =: IUPD;
3:521 panic('unlink -- iset'); 3571 iput (ip) ;
3522 if«ip-)i_mode&IFMT)==IFDIR && !suser(» 3572 }
3523 soto out; 3573 1*
3524 uou_offsetC1J =- DIRSIZ+2; 3574
3525 uou_base = &u.u_dent; 3575 chown()
3526 u.u_count = DIRSIZ+2; 3576 {
3527 uou_dentou_ino = 0; 3577
3528 writei(pp); 3578
3529 ip->i_nlink--; 3579 if (!suser() :: (ip = owner(» NULL)
3530 ip->i_flaS =: IUPD; 3580 return;
3531 3581 ip-)i_uid = u.u_arSC1J.lobwte;
3532 OIJt: 3582 ip-)i_sid = u.u_arsC1J.hibwte;
3533 iput(pp); 3583 ip-)i_flas =: IUPD;
3534 iput(ip); 3584 iput( ip);
3535 } 3585 }
3536 1* ------------------------- 3586 1*
3537 3587
3538 chdir() 3588 1*
3539 { 3589
3540
3541
reSisteT' *ip;
e:-:te rn IJcha 1";
3590 ** ChanSe modified date of file:
time to 1"0-1"1; sws smdate; file
3591
3542 3592 ** This call has been withdrawn because it messes
UP
incremental dumps (pseudo-old files aren't dumped).
3543 ip = namei(&uchar, 0);
3544 if(ip == NULL>
3593
3594 * It works thoush and wou can uncomment it if wou like.
3545 return; 3595 smdate()
3546 if«ip-)Lmode&IFMT> != IFDIR) { 3596 {
3547 u.u_error = ENOTDIR; 3597 resister struct inode *ip;
3548 bad: 3598 resister int *tp;
3549 3599 int tb1JfC2J;

Reproduced under licence from the Western Electric Companw, NY Reproduced under licence from the Western Electric Companw, NY
Copwrisht, Jo Lions, 1976 Copwright, J. Lions, 1976

Sheet 35 Sheet 35
May 24 12:36 1976 unix/sys4.c Pa~e 5 May 24 12:36 1976 unix/s~s4.c Pa~e 6

3600 3650 }
3601 if «ip = owner(» == NULL) 3651 ifCf 0)
3602 return; 3652 u,u_error = ESRCH,
3603 ip-)i_fla~ =: IUPD, 3653 }
3604 tp = &tboJf[2]; 3654 1* ------------------------- *1
3605 *--tp = u.u_arOCR1]; 3655
3606 *--tp = u.u_arOCRO]; 3656 times()
3607 iupdatCip, tp), 3657 {
3608 ip-)i_fla~ =& NIUPD; 3658 resister *p;
3609 iput(ip); 3659
3610 } 3660 for(p = &u.u_utime; p (&u,u_utime+6;) {
3611 *1 3661 suwordCu,u_arSCO], *p++);
3612 1* ------------------------- *1 3662 u,oJ_arSCOJ =+ 2;
3613 3663 }
3614 ssisC) 3664 }
3615 { 3665 1* ------------------------- *1
3616 resister a, 3666
3617 3667 profile)
3618 <OJ =.oJ_ars[O];
OJ 3668 {
3619 if(.(=O :: a)=NSIG :: a ==SIGKIL) { 3669
3620 u.u_error = EINVAL, 3670 u.oJ_prof[OJ 1* base of sample buf *1
3621 return; 3671 OJ .oJ_prof[ 1 J 1* size of same *1
3622 } 3672 oJ.u_prof[2J OJ, u_arsC2J; 1*
pc offset *1
3623 u.u_arOCRO] = u.u_si~nalCa]' 3673 u,u_profC3J (u.u_ars[3J»1) & 077777; 1* pc scale *1
3624 u.u_siSnal[a] = u.u_arSC1]; 3674 }
3625 ifCu.u_procp->p_si~ == a) 3675 1* ------------------------- *1
3626 u.u_procP->p_si~ = 0, 3676
3627 } 3677
3628 1* ------------------------- *1 3678
3679
3629
3630 I<.i 11 ( ) 3680
3631 { 3681
3632 re~ister struct proc *p, *0, 3682
3633 reSister a; 3683
3634 int n 3684
3635 3685
3636 f 0; 3686
3637 a = u.u_arOCRO], 3687
3638 G u.u_procp; 3688
3639 for(p = &procCO]; p ( &procCNPROC], p++) { 3689
3640 ifCp <.1) 3690
3641 continoJe, 3691
3642 if(a != 0 && p-)p_pid != a) 3692
3643 continue, 3693
3644 if(a==O&&(p-)p_ttYP!=G-)p_ttyp: :p(=&procC1]» 3694
3645 continue; 3695
3646 if(u.u_uid != 0 && u,u_uid != p-)p_uid) 3696
3647 continue; 3697
3648 3698
3649 3699

Reproduced under licence from the Western Electric Company, NY Reproduced under licence from the Western Electric Company, NY
CoPyrisht, J. Lions, 1976 Copyrisht. J, Lions. 1976

Sheet 36 Sheet 36
May 24 12:36 1976 unix/clock,c Page 1 May 24 12:36 1976 unix/clock.c Page 2

3700 t 3750 p2 = &callout[OJ;


3701 tinclude ""/param,h' 3751 while(p2-)c_time<=0 && p2-)c_func!=0)
3702 linclude '"/systm,h" 3752 p2tt;
3703 linclude ""/user,h' 3753 p2->c_time--;
3704 linclude ',./proc.h' 3754
3705 3755 II
3706
3707
Idefine
Idefine
UMODE
SCHMAG
0170000
10
3756
3757
* if PS is high, Just return
*1
3708 3758
3709 1* 3759 if«ps&0340) != 0)
3710 * clock is called straight from 3760 goto out;
3711 * the real time clock interrupt, 3761
3712 * 3762 II
3713
3714
*
Functions:
* reprime clock
3763 * callout
3764 II
3715
3716
* COP~ *switches to disp16s
* implement callouts
3765
spI5();
3766
:~717 * maintain userlsystem times 3767 if(callout[OJ.c_time <= 0) {
3718 * maintain date 3768 p1 = &calloutCOJ;
3719
3720
** PI'ofile
tout wakeup (SYS sleep)
3'769
3770
while(pl->c_fun~ != 0 && p1->c_time
,*p1->c_func)(p1->c_arg);
(= 0) {
3721 I lightning bolt wakeup (every 4 sec) 3771 Pitt;
3722 I alarm clock signals 3772 }
3723
3724 II
*
Jab the scheduler 3773 p2 &callout[OJ;
while(p2->c_func = p1-)c_func) {
3774
3725 clock(dev, sp, r1, nps, rO, pc, ps) 3775 p2->c_time = p1->c_time;
3726 { 3776 p2->c_arg = pl-)c_arS;
3727 register struct calla *pl, Ip2; 3777 Pitt;
3728 register struct proc *pp; 3778 p2tt;
3729 3779 }
3730 /* 3780 }
3"731 * restart clock 3781
3732 II 3782 II
3733 3783 I lightning bolt time-out
3734 *Iks 0115; 3784 * and time of day
3735 3785 1/
3"736 II 3786
3"737 * display register 3787 out:
3738 *1 3788 if«ps&UMODE) == UMODE) {
3'739 3789 I.J • IJ_ut i mett;
3740 display(); 3790 if(u.u_profC3J)
3741 3791
3742 1* 3792 } else
3743 * callolJts 3793
3744 * if none, Just return 3794 pp = IJ.u_procp;
3745 * else update first non-zero time 3795 if(ttpp-)p_cpu == 0)
3746 *1 3796 pp-)p_cpu--;
3747 3797 if(ttlbolt )= HZ) {
3748 if(calloutCOJ.c_func 0) 3798 if«ps&0340) != 0)
3749 goto out; 3799 return;

Reproduced under licence from the Western Electric Company, NY Reproduced under licence from the Western Electric Company, NY
Copyright, J. Lions, 1976 Copyright, J. Lions, 1976

Sheet 37 Sheet 37
May 24 12:36 1976 unix/clock.c Page 3 May 24 12:36 1976 unix/clock.c Page 4

3800 lbolt =- HZ; 3850


3801 if(tttlme[1J == 0) 3851 t = tim;
3802 tttime[O]i 3852 s = PS-)integ;
3803 spll(); 3853 p1 = Icallout[O];
3804 if(time[lJ==tout[lJ II time[O)==tout[OJ) 3854 spI7();
3805 wakeup(tout); 3855 while(p1-)c_func != 0 II p1-)c_time <= t) {
3806 if(Ctime[lJI03) == 0) { 3856 t =- p1-)c_timei
3807 runruntt; 3857 p1tt;
3808 wakeupCIlbolt); 3858 }
3809 } 3859 p1-)c_time =- t;
3810 for(pp = Iproc[O); pp < Iproc[NPROC]; pptt) 3860 p2 = pi;
3811 if (pp-)p_stat) { 3861 while(p2-)c_func != 0)
3812 ifCpp-)p_time != 127) 3862 p2tt;
3813 pp-)p_timett; 3863 while(p2 )= p1) {
3814 ifC(pp-)p_cpu I 0377) ) SCHMAG) 3864 (p2tl)-)c_time = p2-)c_time;
3815 pp-)p_cpu =- SCHMAG; else 3865 (p2tl)-)c_func = p2-)c_func;
3816 pp-)p_cpu = 0; 3866 (p2t1)-)c_srg = p2-)c_srg,
3817 ifCpp-)p_pri ) PUSER) 3867 p2--;
3818 setpri(pp); 3868 }
3819 } 3869 p1-)c~time = t;
3820 ifCrunin!=O) { 3870 p1-)c_func = fun;
3821 runin = 0; 3871 pl->c_arg arg;
3822 wakeup(lrunin); 3872 PS->integ = s;
3823 } 3873 }
3824 ifC(ps&UMODE) == UMODE) { 3874 1* */
3825 u.u_arO = IrO; 3875
3826 ifCissig(» 3876
3827 psis(); 3877
3828 setpri(u.u_procp); 3878
3829 } 3879
3830 } 3880
3831 } 3881
3832 1* *1 3882
3833 3883
3834 /* 3884
3835
3836
* timeout is called to arrange that
* funCars) is called in tim/HZ seconds.
3885
3886
3837 * An entry is sorted into the callout 3887
3838 * structure. The time in each structure 3888
3839 * entry is the number of HZ's more 3889
3890
3840 * than the previous entrY.
3841 * In this way, decrementing the 3891
3842 * first entry has the effect of 3892
3843 * updating all entries. 3893
3844 */ 3894
3845 timeout(fun. arg. tim) 3895
3846 { 3896
3847 register struct callo *pl. *p2; 3897
3848 resister tl 3898
3849 int s; 3899

Reproduced under licence from the Western Electric Company, NY Reproduced under licence from the Western Electric Company, NY
Copyright. J. Lions. 1976 Copyright, J. Lions, 1976

Sheet 38 Sheet 38
Maw 24 12:36 1976 unix/si~,c Pa~e 1 Maw 24 12:36 1976 unix/si~,c PaSe 2

3900
3901
*
1*
3950 {
3951 re~ister struct proc *1"';
3902 *1 3952
3',03 3953 forCp = &proc[O]; I'" < &proc[NPROC]; p++)
3904 tinclude ',./param,h' 3954 if(p-)p_ttwP == tp)
3905 tinclude ",./swstm.h" :~955 psigna1(p, si~);
3906 iinclude !! + + fuse r • h II 3956 }
3'~07 tinclude u •• /proc.hu 3957 1* -------------------------
3908 'B'include ".,/inode.h" 3958
3909 iinclude ""/reg,h" 3959 1*
3910 3960 * Send the specified signal to
3911 1* 3961 * the specified process.
3912 *
Prioritw for tracins 3962 *1
3913 *1 3963 psi~nal(p, si~)
3914 ltd€!fine IPCPRI (--1 ) 3964 int *1"';
39:t5 3965 {
3916 1* 3966
3917 *
Structure to access an arraw of intesers. 3967
if(sis NSIG)
3918 *1 3968 )=
3919 str'uct, 3969 return;
3'1'20 { 3970 rp = p;
3921 int inta[]; 3971 if(rp-)p_sig != SIGKIL)
3922 }; 3972 rp-)p_sis = sis;
3923 1* ------------------------- 3973 if(rp-)p_stat ) PUSER)
3924 3974 rp-)p_stat = PUSER;
3925 1* 3975 if(rp-)p_stat == SWAIT)
3926 *
Tracins variables. 3976 set r'.1n ( rp) ;
3927 *
Used to pass trace command from 3977 }
3928 *
parent to child beinS traced. 3978 1* ------------------------- *1
3929 *
This data base cannot be 3979
3930 *
shared and is locked 3980 1*
3931
39:32
*
per user.
*1
3981
3982
* Returns true if the current
* process has a signal to process,
3933 struct 3983 * This is asked at least once
3934 { 3984 * each time a process enters the
3935 int ip_Iocld 3985 * swstem,
39:56 int ip_reG; 3986 * A sisnal does not do anwthing
:3937 int ip_addr; 3987 * directlw to a process; it sets
3938 int ip_data; 3988 * a flas that asks the process to
3939
3940
} ipc; 3989
3990
*
*!
do somethins to itself.
1* -------------------------
3941 3991 issig()
3942 1* 3992 {
3943 * Send the specified sisnal to 3993 resister rd
3944 * all processes with 'tp' as its 3994 resister struct proc *1"';
3945 * controllinS teletwpe. 3995
3946 * Called bw ttw,c for Guits and 3996 = 'J, 'J_p rocp;
I'"
3947 * interrupts. 3997 if(n = p-)p_sis) {
3948 *! 3998 if (p->p_fla~&STRC) {
3949 siSnal(tp, sis) 3999 stope);

Reproduced under licence from the Western Electric Companw, NY Reproduced under licence from the Western Electric Companw, NY
Copwright, J. Lions, 1976 Copwri~ht, J, Lions, 1976

Sheet 39 Sheet 39
May 24 12:36 1976 unix/siS.c PaSe 3 Maw 24 12:36 1976 unix/sis.c PaSe 4

4000 if «n = p-)p_sis) 0) 4050 rp-)p_sis = 0;


4001 return(O); 4051 if«p=IJ.u_sisnal[nJ) != 0) {
4002 } 4052 u.IJ_error = 0;
4003 if«u.u_sisnal[nJ&1) == 0) 4053 if(n != SIGINS && n != SIGTRC)
4004 return(n); 4054 u.u_siSnaICnJ = 0;
4005 } 4055 n = u.u_arO[R6J - 4;
4006 return(O); 4056 srow(n) ;
4007 } 4057 suword(n+2, u.u_arO[RPSJ);
4008 1* ------------------------- 4058 suword(n, u.u_arO[R7J);
4009 4059 u.u_arO[R6J = n;
4010 /* 4060 u.u_arO[RPSJ =& NTBIT;
4011 * Enter the tracins STOP state. 4061 u.u_arO[R7J = p;
4012 * In this state. the parent is 4062
4063 }
retlJrn;
40:l3 * informed and the process is able to
4014 * receive commands from the parent. 4064
4065
switch(n) {
4015 *1
4016 stop() 4066 case SIGQIT:
4017 { 4067 case SIGINS:
4018 4068 case SIGTRC:
4019 4069 case SIGIOT:
4020 loop: 4070 case SIGEMT:
4021 CP u.IJ_procp; 4071 case SIGFPT:
4022 if(cp-)p_ppid != 1) 4072 case SIGBUS:
4023 for (pp = &proc[O]; pp < &proc[NPROCJ; pp++) 4073 case SIGSEG:
4024 if (pp-)p_pid == cp-)p_ppid) { 4074 case SIGSYS:
4025 wakeup(pp); 4075 u,IJ_arS[OJ n;
4026 cp-)p_stat = SSTOP; 4076 if(coreO)
4027 swtch(); 4077 n =+ 0200;
4028 if «cp-)p_flaS&STRC)==O :: proc:-(mt ( ) ) 4078 }
4029 return; 4079 IJ.u_arS[OJ (IJ. IJ_a rO[RO] «8)
4030 £Iota loop; 4080 e:dt() ;
4031 } 4081 }
4032 e:dt(); 4082 1* -------------------------
4033 } 4083
4034 1* ------------------------- 4084 1*
4035 4085 * Create a core imaSe on the file 'core"
4036 1* 4086 * If YOU are looking for protection glitches,
4037 * Perform the action specified by 4087 *
there are probably a wealth of them here
4038 * the current sisnal. 4088 * when this occurs to a suid command.
4039
4040 *** The usual seauence is:
if(issiS(»
4089
4090
4091
*** user.h
It writes USIZE block of the
area followed by the entire
4041 psis();
4042 *1 4092
4093
* data+stack seSments.
4043 psis() *I
4044 { 4094 core ( )
4045 resister n, p; 4095 {
4046 resister *rp; 4096 register s, *ip;
4047 4097 e:-:tern schar;
4048 rp = u.u_procp; 4098
4049 n = rp->p_sis; 4099

Reproduced under licence from the Western Electric Company, NY Reproduced under licence from the Western Electric Companw, NY
Copwrisht, J. Lions. 1976 Copyright, J. Lions, 1976

Sheet 40 Sheet 40
Maw 24 12:36 1976 unix/si~+c Pa~e 5 Maw 24 12:36 1976 unix/5i~+c Pase 6

4100 u+u_dirp = 'core'; 4150 for(i-u.u_ssize; i i i--) {


4101 ip = nameiC&schar. 1); 4151 a'--'"
4102 ifCip == NULL) { 4152 copwse~(a-si, a);
4103 ifCu+u_error) 4153 }
4:l04 retuT'nCO); 4154 for(i=si; i; i--)
4105 ip = maknode(0666); 4155 clear5e~(--a),
4106 if Ci p == NULL) 4156 u.u_ssize =+ si,
4107 return (0) ; 4157 ret •.J rn ( 1 ) ;
4108 } 4158 }
4109 ifC!access(ip, IWRITE) && 4159 1* -------------------------
4110 Cip-)i_mode&IFMT) == 0 && 4160
4111 u.u_uid == u+u_ruid) { 4161 1*
4112 itrunc(ip); 4162 * sws-trace swstem call.
4113 u.u_offsetCOJ = 0; 4163 */
4114 u+u_offsetC1J - 0, 4164 ptraceC)
.... L . __ . _ _ () .....
4115 U_Lld~C'
1..1 • - QI..I' 4165 -{
4116 u+u_count = USIZE*64; 4166 re~ister struct proc *p;
4117 'J+'J_se~fls = 1, 4167
4118 writeiCip); 4168 if (u+u_arsC2J <= 0) {
4119 s - u+u_procp-)p_size - USIZE; 4169 u.u_procp-)p_fla~ =1 STRC;
4120 estaburCO, s. 0, 0); 4170 return;
4121 uou_base = 0; 4171 }
4122 u+u_count = s*64; 4172 for Cp=proc; p < &procCNPROC]; p++)
4123 u+u_se~fl~ = 0; 4173 if (p-)p_stat==SSTOP
4124 wri tei (ip); 4174 && p-)p_pid==u.u_ar~COJ
4125 } 4175 && p-)p_ppid-=u.u_procp-)p_pid)
4126 iP'Jt. (ip); 4176 ~oto found;
4127 return(u.u_error==O), 4177 u.u_error ESRCH;
4128 } 4178 return;
4129 /* ------------------------- 4179
4130 4180 found:
4131 /* 4181 while Cipc+ip_lock)
4132 * srow the stack to include the SP 4182 sleepC&ipc, IPCPRI);
4133 * true return if successful+ 4183 ipc.ip_lock p-)p_pid;
4134 */ 4184 ipc.ip_data - u.u_arOCROJ,
4135 4185 ipc.ip_addr - u.u_arsC1J & N01;
4136 ~row(sp) 4186 ipc+ip_rea = u+u_ar~C2J;
4137 char *sp; 4187 p-)p_flas =& NSWTED;
4138 { 4188 setrun(p);
4139 re~ister a. sip i; 4189 while Cipc.ip_rea ) 0)
4140 4190 sleepC&ipc, IPCPRI);
4141 if(sp )- -u+u_ssize*64) 4191 u.u_arO[ROJ = ipc+ip_data;
4142 ret'Jrn(O) ; 4192 if (ipc.ip_rea < 0)
4143 si = IdivC-sp, 64) - u+u_ssize + SINCR; 4193 u.u_error = EIO,
4144 if(si <- 0) 4194 ipc.ip_Iock = 0;
4145 return(O); 4195 wake •.Jp( &ipc);
4146 if(estaburCu.u_tsize. u.u_dsize. u.u_ssize+si. u.u_sep» 4196
4147 return(O) ; 4197
4148 expand(u+u_procp-)p_size+si); 4198
4149 a = u.u_procp-)p_addr + u.u_procp-)p_size; 4199

Reproduced under licence from the Western Electric Companw. NY Reproduced under licence from the Western Electric Companw, NY
Copwrisht, J. Lions, 1976 Copwrisht, J. Lions. 1976

Sheet 41 Sheet 41
Ma~ 24 12:36 1976 unix/sis.c PaSe 7 May 24 12:36 1976 unix/sis.e Pase 8

4200 *Code that the child process 4250


4251
break;
4201 * executes to implement the command
4202 *of the parent process in tracing. 4252 1* write u *1
4203 *1 4253 case 6:
4204 proc:·:mt() 4254 p = &u.intaCipc.ip_addr»l];
4205 -{ 4255 if (p >= u.u_fsav && p < &u.u_fsavC25J)
4206 resister int i, 4256 soto old
4207 resister int *p; 4257 for (i=O; i<9' itt)
4208 4258 if (p == &u.u_arO[resloeCiJ])
4209 if (ipc.ip_lock != u.u_procp-)p_pid) 4259 soto ok'
4210 return(O) ; 4260 soto error;
4211 i = ipc.ip_reG; 4261 ov.. :
4212 ipc.ip_reG = 0, 4262 if (p == &u.u_arO[RPSJ) -{
4213 wakeup(&ipc), 4263 1* assure user space *1
4214 swi tch ( i ) { 4264 ipc.ip_data =: 0170000;
4215 4265 1* priority 0 *1
4216 1* read user I *1 4266 ipc.ip_data =& N0340;
4217 case 1: 4267 }
4218 if (fuibwte(ipc.ip_addr) == -1) 4268 *p ipc.ip_data;
4219 soto errod 4269 break;
4220 ipc.ip_data = fuiword(ipc.ip_addr)' 4270
4221 break; 4271 1* set sisnal and continue *1
4222 4272 case 7:
4223 1* read user D *1 4273 u.u_procp-}p_sis
4224 case 2: 4274 retrJrn( 1);
4225 if (fubyte(ipc.ip_addr) == -1) 4275
4226 soto error; 4276 1* force exit *1
4227 ipc.ip_data = fuword(ipc.ip_addr)' 4277 case 8:
4228 breald 4278 e:·:it();
4229 4279
4230 1* read u *1 4280 default:
4231 case 3: 4281 error:
4232 i = ipc.ip_addr; 4282
4233 if (i<O:: i >= (uSIZE«6» 4283 }
4234 So to error; 4284 return(O) ;
4235 ipc.ip_data = u.intaCi»1]; 4285 }
4236 break; 4286 1*
4237 4287
42:38 1* write user I (for now, always an error) *1 4288
4239 case 4: 4289
4240 if (suiword(ipc.ip_addr, 0) < 0) 4290
4241 soto errol'; 4291
4242 suiword(ipc.ip_addr. ipc.ip_data); 4292
4243 break; 4293
4244 4294
424:'5 1* write user D *1 4295
4246 case 5: 4296
4247 if (suword(ipc.ip_addr, 0) < 0) 4297
4248 soto error; 4298
4249 suword(ipc.ip_addr. ipc.ip_data); 4299

Reproduced under licence from the Western Electric Company. NY Reproduced under licence from the Western Electric Company. NY
Copyrisht. J. Lions. 1976 Copyrisht. J. Lions. 1976

Sheet 42 Sheet 42
Program Swapping
Basic Input/Output
Block Devices
Ma~ 24 12:40 1976 unix/text.h PaSe 1 Ma~ 24 12:41 1976 unix/text.c PaSe 1

4300 1* 4350 t
4301 * Text structure. 4351 tinclude ' •• /param.h'
4302 * One allocated per pure 4352 tinclude ' •• /s~stm.h'
4303 * procedure on swap device. 4353 tinclude ' •• /user.h'
4304
4305
* Manipulated text.c
b~ 4354 tinclude
tinclude
'
'
•• /proc.h'
•• /text.h'
*f 4355
4306 struct text 4356 tinclude ' •• /inode.h'
4307 { 4357
4308 int :cdaddr; 1* disk address of seSment *1 4358 1* Swap out process P.
4309 int 1* core address, if loaded *1 4359 * The ff flas causes its core to be freed--
4310 int :csize; 1* size C *64 j *I 4360 * it ma~ be off when called to create an imase for a
4311 int *:ciptr' 1* inode of protot~pe*1 4361 *
child process in newproc.
4312 char x_count; 1* reference count *1 4362 * as is the old size of the data area of the process,
4313 char x_ccount; 1* number of loaded references *1 4363 * and is supplied durins core expansion swaps.
4314 } te:·:t[NTEXTJ; 4364
4315 1* ------------------------- 4365 ** panic: out of swap space
4316
4317
4366
4367
**I panic: swap error -- 10 error
4318 4368 xswap(p, ff, as)
4319 4369 int *p;
4320 4370 { resister *rp, a;
4321 4371
4322 4372 rp = p;
4323 4373 if(os == 0)
4324 4374 as = T'p->p_size;
4325 4375 a = malloc(swapmap, (rp-)p_size+7)/B),
4326 4376 if (a == NULL>
4327 4377 panicC'out of swap space'),
4328 4378 xccdec(rp-)p_textp);
4329 4379 rp->p_flas =1 SLOCK,
4330 4380 if(swap(a, rp-)p_addr, as' 0»
4331 4381- panic('swap error'),
4332 4382 if(ff)
4333 4383 mfree (coremap, as' rp->"",-addr);
4334 4384 rp->p_addr = a;
4335 4385 rp->p_flas =& M(SLOADISLOCK),
4336 4386 rp->p_time :: 0;
4337 4387 if(runout) {
4338 4388 runout = 0;
4339 4389 wakeup(&runout);
4340 4390 }
4341 4391 }
4342 4392 1* -------------------------
4343 4393
4344 4394 1*
4345 4395 * relinGuish use of the shared text seSment
4346
4347
4396
4397
* of a process.
*1
4348 4398 :·:free ( )
4349 4399 { resister *xp, *ip;

Reproduced under licence from the Western Electric Compan~. NY Reproduced under licence from the Western Electric Compan~, NY
Cop~risht, J. Lions, 1976 Cop~risht, J. Lions, 1976

Sheet 43 Sheet 43
Ma~ 24 12:41 1976 unix/text.c Pa~e 2 Ma~ 24 12:41 1976 unix/text.c Pa~e 3

4400 4450 }
440l ifCCxp~u,u_procp-)p_textp) != NULL) { 4451 if(Cxp-rp) == NULL) panicC'out of text');
4402 u.u_procp-)p_textp = NULL; 4452
4403 )·:ccdec C).:p ) ; 4453
4404 ifC--xp-)x_count == 0) { 4454 xp-)x_iptr = ip;
4405 4455 ts = CCu.u_ar~[lJ+63»)6) & 01777;
4406 if«ip-)i_ffiode&ISVTX) == 0) { 4456
4407 xp-)x_iptr = NULL; 4457 if«xp-)x_daddr = malloc(swapmap, Cts+7)/8» NULL)
4408 mfreeCswapmap, Cxp-)x_size+7)/8, 4458 panicC'out of swap space');
44()9 . xp-)x_daddr); 4459 expandCUSIZE+ts);
4410 ip-)i_fla~ =& NITEXT; 4460 estabur(O. ts, 0, 0);
44i1 ipute ip); 4461 U.u_cDunt = u.u_arS[lJ;
4412 } 4462 u.u_offset[lJ = 020;
4413 } 4463 '.J. u_base = 0;
4414 } 4464 readiCip);
4415 4465 rp = u.u_procp;
4416 4466 rp-)p_fla~ =i SLOCK;
441'7 4467 swap(xp-)x_daddr, rp-)p_addr+USIZE, ts, 0);
4418 1* Attach to a shared text se~ment. 4468 rp-)p_fla~ =& NSLOCK;

4419 If there is no shared text, Just return. 4469 rp-)p_textp = xP;


442() * If there is, hook UP to it: 4470 rp = ip;
4421 * if it is not currentl~ bein~ used, it has to be read 4471 rp-)i_flaS =i ITEXT;
4422 *
in from the inode (ip) and established in the swap space. 4472 rp-)i_count++;
4423 *
If it is bein~ used, but is not currentlw in core, 4473 eHPandCUSIZE) ;
4424 **a swap has to be done to ~et it back. 4474 o'Jt:
4425 The full coroutine ~lor~ has to be invoked-- 4475 if(HP-)H_ccount == 0) {
4426 **
see slp.c-- because if the callin~ process 4476 savu(u,u_rsav) ;
4427 is misPlaced in core the text ima~e mi~ht not fit. 4477 savuCu.IJ_ssav) ;
4428
* Quite possibl~ the code after 'out:' could check to 4478 HswapCu.u_procp, 1, 0);
4429 * see if the text does fit and simplY swap it in. 4479 u.u_procp-)p_flas =i SSWAP;
443() ** 4480 swtchC) ;
4431 panic: out of swap space 4481 1* no retlJrn *1
4432 *
*1 4482
4433 )·:allocCip) 4483
4434 int hp; 4484 )-
4435 { 4485 1* -------------------------
4436 re~ister struct text *xp; 4486
4437 re~ister *rp, ts; 4487 1* Decrement the in-core usaSe count of a shared text
4438 4488 *
seSment. When it drops to zero, free the core space.
4439 ifCu.u_ar~[1] == 0) return; 4489 *1
4440 rp = NULL; 4490 )·:ccdec (xp)
4441 forCxp = &text[O]; xp < &text[NTEXTJ; xp++) 4491 int *).:p;
4442 if(xp-)x_iptr == NULL) { 4492 {
4443 if Crp == NULL) 4493
4444 rp = xP; 4494
4445 } else 4495 ifC(rp=HP)!=NULL && rp-)x_ccount!=O)
4446 if(:·:p-)~:_iptr == ip) { 4496 if(--rp-)x_ccount == 0)
4447 xp-)x_count++; 4497
4448 u.u_procp-)p_textp xp; 4498 }
4449 ~oto out; 4499

Reproduced under licence from the Western Electric Compan~, NY Reproduced under licence from the Western Electric Company, NY
Cop~ri~ht, J. Lions, 1976 Cop~ri~ht, J. Lions, 1976

Sheet 44 Sheet 44
May 24 12:41 1976 unix/buf.h Pa~e 1 May 24 12:41 1976 unix/buf.h Pa~e 2

4500 1* 4550
4501 * Each buffer in the pool is usually doubly linked into two 4551 struct devtab
4502 * lists: for the device with which it is currently associat-4552 {
4503 * ed (always) and also for a list of blocks available for 4553 char 1* busy flaS*1
4504 * allocation for other use (usually). 4554 char d_errcnt; 1* error count (for recovery)*1
4505 * The latter list is kept in last-used order, and the two 4555 struct buf *b_forwi 1* first buffer for this dev *1
4506 * lists are doubly linked to make it easY to remove 4556 struct buf *b_backi 1* last buffer for this dev *1
4507 * a buffer from one list when it was found by 4557 struct buf *d_actfi 1* head of 110 Queue *1
4508 * look inS throu~h the other. 4558 1* tail of liD Queue *1
4509 * A buffer is on the available list, and is liable 4559 };
4510 * to be reassi~ned to another disk block, if and only 4560 1* -------------------------
4511 * if it is not marked BUSY. When a buffer is busy, the 4561
4512 * available-list pointers can be used for other purposes.
4513 * Most drivers use the forward ptr as a link in their liD
4562
4563
i** This is the head of the Queue of available
4514 * active Queue. 4564 * buffers-- all unused except for the 2 list heads.
4515 * A buffer header contains all the information reQuired
4516 * to perform liD.
4565
4566
*i
4517 * Most of the routines which manipulate these thinSs 4567 struct buf bfreelisti
4518 * are in bio.c. 4568
4519 *1
4520 struct buf
4569
4570
i** These fla~s are kept in b_flass.
4521 { 4571 *i
4522 int b_fla~s; 1* see defines below *1 4572 idefine B_WRITE 0 i*non-read pseudo-fla~ *i
4523 struct buf *b_forw; 1* headed by devtab of b_dev *1 4573 idefine B_READ 01 1* read when 1/0 occurs *1
4524 struct buf *b_back; 1* *1 4574 idefine B_DONE 02 1* transaction finished *1
4525 struct buf *av_forwi 1* position on free list, *1 4575 idefine B_ERROR 04 1* transaction aborted *1
4526 strlJct buf *av_back; 1* if not BUSY*I 4576 idefine B_BUSY 010 1* not on av_forwiback list *1
4527 int b_dev; 1* maJor+minor device name *1 4577 idefine B_PHYS 020 1* Physical 10 potentiallY
4528 int b_wcol.mt; 1* transfer count (usu. words) *1 4578 usins the Unibus map *1
4529 char *b_addr; 1* low order core address *1 4579 idefine 040 1*This block has the UNIBUS
4530 char *b_xmem; 1* hish order core address *1 4580 map allocated *1
4531 char' *b __ blkno; 1* block i on device *1 4581 idefine 0100 1* issue wakeup when
4532 char b_error; 1* returned after liD *1 4582 BUSY ~oes off *1
4533 char *b_resid; 1* words not transferred after 4583 idefine 0200 1* no lonser used *1
4534 error *1 4584 idefine 0400 1* don't wait for liD
4535 } bufCNBUFJi 4585 coifIF,letion *1
4536 1* ------------------------- 4586 idefine B_DELWRI 01000 1*don't write till block
4537 4587 leaves available list *1
4538 1* 4588
4539 * Each block device has a devtab, which contains private 4589
4540 * state stuff and 2 list heads: the b_forw/b_back list, 4590
4541 * which is doubly linked and has all the buffers currently 4591
4542 * associated with that major device;
4543 * and the d_actf/d_actl list, which is private to the
4592
4593
4~544 * device but in fact is always used for the head and tail
4545 * of the liD Queue for the device.
4594
4595
4546 * Various routines in bio.c look at b_forw/b_back 4596
4547 * (notice they are the same as in the buf structure) 4597
4548 * but the rest is private to each device driver. 4598
4549 *I 4599

Reproduced under licence from the Western Electric Company, NY Reproduced under licence from the Western Electric Company, NY
Copyri~ht, J. Lions, 1976 Copyri~ht. J. Lions, 1976

Sheet 45 Sheet 45
Maw 24 12:41 1976 unix/conf.h Pa~e 1 May 24 12:41 1976 unix/conf.c Page 1

4600 1* Used to dissect inteaer device code 4650 1*


4601 * into major (driver designation) and 4651 * this file is created, along with the file "low.s",
4602 * minor (driver parameter) parts. 4652 * by the program "mkconf.c', to reflect the actual
4603 *1 4653 * configuration of peripheral devices on a swstem.
4604 struct { 4654 *1
46()5 char d_minor; 4655
4606 char d .. maJor; 4656 int <)j(bdevsw[J)()
4607 }; 4657 {
4608 1* ------------------------- 4658 &nulldev, &nulldev, &rkstrategy, &rktab, 1* rl<. *1
4609 1* Declaration of block device 4659 &nodev, &nodev, &nodev, 0, 1*
rF' *1
4610 * switch. Each entrw (row) is 4660 &nodev, &nodev, &nodev, 0, 1*
rf *I
4611 * the onlw link between the 4661 &nodev, &nodev. &nodev. 0. 1*
tIT. *I
4612 * main unix code and the driver. 4662 &nodev, &nodev. &nodev. O. 1*
tc *1
4613 * The initialization of the 4663 &nodev. &nodev. &nodev. O. 1*
hs *1
4614 * device switches is in the 4664 &nodev. &nodev, &nodev, 0, 1*
hI" *1
4615
4616
* file conr.e. 4665
4666
&nodev, &nodev, &nodev. 0,
0
1*
ht *I
*1
4617 stT'l.Jct bdevsw { 4667 };
4618 int (*d_open)(); 4668
4619 int <ld_c lose) < ) ; 4669 int (*cdevsw[])()
4620 int (*d_strate~w)(); 4670 {
4621 int *d_tab; 4671 &klopen. &klclose, &klread. &klwrite, &klsgttw.
4622 } bdevsw[]; 4672 1*
console *1
4623 1* ------------------------- 4673 &pcopen, &pcclose, &pcread, &pcwrite. &nodev.
4624 1* Nblkdev is the number of entries 4674 1* *1
pc
4625 **
(rows) in the block switch. It is 4675 &lpopen, &lpclose, &nodev, &lpwrite, &nodev.
4626 set in binit/bio.c bw making 4676 1* 11" *I
4627 *·a pass over the switch. 4677 &nodev. &nodev, &nodev, &nodev. &nodev. dc1* *I
4628
4629
**Used in bounds check in. on major
device numbers.
4678
4679
&nodev. &nodev, &nodev,
&nodev, &nodev. &nodev.
&nodev.
&nodev.
&nodev. dh
&nodev, 1* dp
1* *1
*I
4630 *I 4680 &nodev. &nodev, &nodev. &nodev. &nodev. 1* dJ *1
4631 int nblkdev; 4681
4682
&nodev, &nodev. &nodev. &nodev, &nodev.
&nulldev, &n'Jlldev, &mmread. &mmwrite, &nodev.
dn1* *I
4632
4633 1* Character device switch. 4683 1*",em *I
4634 *1 4684 &nulldev. &nulldev, &rkread. &rlt,write. &nodev.
4635 struct cdevsw { 4685 1*rk *I
4636 int (*d_open)(); 4686 &nodev. &nodev. &nodev. &nodev. &nodev. rf1* *1
4637 int (*d_close)(); 4687 &nodev. &nodev. &nodev. &nodev, &nodev, rp1* *I
4638 int <*d_read)(); 4688 &nodev, &nodev. &nodev. &nodev. &nodev, 1*
till *1
4639 int <ld_write) (); 4689 &nodev. &nodev. &nodev. &nodev. &nodev, hs1* *I
4640 int (*d_sgttw)(); 4690 &nodev, &r,odev. &nodev. &nodev. &nodev. 1*
hI" *1
4641 } cdevsw[]; 4691 &nodev. &nodev. &nodev. &nodev. &nodev, ht1* *I
4642 1* ------------------------- 4692 0
4643 4693 H
4644 1* Number of character switch entries. 4694
4645 * Set bw cinit/ttw.c 4695 int rootdev {(0{{8) :O};
4646 *1 4696 int swapdev {(0{{8):0};
4647 int nchrdev; 4697 int swplo 4000; 1* cannot be zero *1
4648 4698 int nswap 872;
4649 4699

Reproduced under licence from the Western Electric Company, NY Reproduced under licence from the Western Electric Company, NY
CoPYright, J. Lions, 1976 Copwrisht, J. Lions, 1976

Sheet 46 Sheet 46
Ma~ 24 12:41 1976 unix/bio.c Page 1 May 24 12:41 1976 unix/bio.c Page 2

4700 I 4750
4701
4702
'**1 4751 1* Read in (if necessary) the block and
4752
* return a buffer pointer,
4703 *1
4753
4704 linclude '.,/param.h' 4754 bread(dev, blkno)
4705 tinclude ',./user,h' 4755 {
4706 tinclude '"/buf.h' 4756 register struct buf *rbp;
4707 linclude ' •• /conf.h' 4757
4708 linclude ',./sYstm.h' 4758 rbp = getblk(dev, blkno);
4709 linclude ' •• /proc.h' 4759 if (rbp-)b_flaSs&B_DONE)
4710 .include '.,/seg.h' 4760 return(rbp);
4711 4761 rbp-)b_flags =: B_READ;
4712 1* 4762 rbp-)b_wcount = -256;
4/,13 * This is the set of buffers proper, whose heads 4763 (*bdevsw[dev.d_maJ~r].d_strategy)(rbp);
4714 * were declared in buf.h. There can exist buffer 4764 iowait(rbp);
4715 * headers not pointing here that are used purel~ 4765 ret'J rn ( rbp) ;
4716 * as arguments to the liD routines to describe 4766 }
4717
4718
*
liD to be done-- e.S. swbuf, Just below, for
* swappins,
4767 1*
4768
47:l9 *1 4769 1*
4720 char buffersCNBUF]C514]; 4770 * Read in the block, like bread, but also start liD on the
4721 struct b'Jf swbuf; 4771 *
read-ahead block (which is not allocated to the caller)
4722 4772 I I
4723 1* 4773 breada(adev. blkno, rablkno)
4724 • Declarations of the tables for the mastape devices; 4774 {
4725
4726 .1
*
see bdwrite. 4775 register struct buf *rbp, *rabp;
register int dey;
4776

I.
4727 int tmtab; 4777
4728 int httab; 4778 dey = adev;
4729 4779 rbp = OJ
4730 4780 if (!incore(dev, blkno» {
4731 *
The followins several routines allocate and free 4781 rbp = setblk(dev, blkno);
4732 *
buffers with various side effects. In general the 4782 if «rbp-)b_flags&B_DONE) == 0) {
4733 *
arguments to an allocate routine are a device and 4783 rbp-)b_flaSs =: B_READ;
4734 • a block number, and the value is a pointer to 4784 rbp-)b_wcount = -256;
4735 *
to the buffer header; the buffer is marked ·bus~· 4785 (*bdevswCadev.d_maJorJ.d_strateSY) (rbp);
4736 • so that no on else can touch it. If the block was 4786 }
4737 * already in core. no liD need be done; if it is 4787 }
4738 *
already busy, the process waits until it becomes free. 4788 if (rablkno && !incore(dev, rablkno» {
4739 *
The following routines allocate a buffer: 4789 rabp = setblk(dev, rablkno);
4740 *
getblk 4790 if (rabp-)b_flags & B_DONE)
4741 * bread 4791 brelse(rabp);
4742 * breada 4792 else {
4743 *
EventuallY the buffer must be released, possibly with the 4793 rabp-)b_flass =: B_READ:B_ASYNC;
4744 *
side effect of writing it out. by using one of 4794 rabp-)b_wcount = -256;
4745 * bwrite 4795 (*bdevsw[adev.d_maJorJ.d_strategy) (rabp);
4746 * bdwrite 4796 }
4747 • bawrite 4797 }
4748 * brelse 4798 if (rbp==O)
4749 *1 4799 return(bread(dev, blkno»;

Reproduced under licence from the Western Electric Company, NY Reproduced under licence from the Western Electric Company, NY
Copyright, J. Lions, 1976 COPYright, J. Lions, 1976

Sheet 47 Sheet 47
May 24 12:41 1976 unix/bio.c Pa~e 3 May 24 12:41 1976 unix/bio.c Pa~e 4

4800 iowaitCrbp); 4850 }


4801 return(rbp); 4851 /* -------------------------
4802 }- 4852
4803 1* 4853 1* Release the buffer. start 110 on it, but don't wait
4804 4854 * for completion *1
4805 1* 4855
4806 * Write the buffer, waitin~ for completion. 4856 bawrite(bp)
4807 * Then release the buffer. 4857 struct b'Jf *1..11"';
4808 *1 4858 {
4809 bwrite(bp) 4859 re~ister struct buf *rbp;
4810 struct buf *1..11"'; 4860
4811 { 4861 rbp = bp;
4812 re~ister struct buf *rbp; 4862 rbp·->b_fla~s =i
4813 re~ister fla~; 4863 bwrite( rbp);
4814 4864 }-
4815
4816 fla~ = rbp->b_fla~s;
4865
4866
1* ------------------------- */

4817 rbp-)b_fla~s =& NCB_READ i B_DONE i B_ERROR i B_DELWRI); 4867 1* release the buffer, with no 110 implied.
4818 rbp->b_wcount = -256; 4868 *1
4819 (*bdevsw[rbp->b_dev.d_maJorJ.d_strate~y)(rbp); 4869 brelse(bp)
4820 if «fla~&B_ASYNC) == 0) { 4870 struct buf *1..11"';
4821 iowait(rbp); 4871 {
4822 brelse(rbp); 4872 re~ister struct buf *rbp, **backp;
4823 } else if «fla~&B_DELWRI)==O) 4873 re~ister int SPS;
4El24 ~eterror(rbp) ; 4874
4825 } 4875 rbp = bp;
4826 1* ------------------------- 4876 if (rbp-)b_flags&B_WANTED)
4827 4877 wakeup(rbp);
4828 1* 4878 if (bfreelist.b_flagsIB_WANTED) {
4829 * Release the buffer, markin~ it so that if it is ~rabbed 4879 bfreelist.b_fla~s =& NB_WANTED;
4830 * for another purpose it will be written out before bein~ 4880 wakeup(&bfreelist);
4831 * siven UP (e.g. when writing a partial block where it is 4881 }
4832 * assumed that another write for the same block will soon 4882 if (rbp-)b_fIB~s&B_ERROR)
4KB *
follow). This can't be done for ma~tape, since writes 4883 rbp-)b_dev.d_minor -1; 1* no assoc. on error *1
4834 * must be done in the same order as reGuested. 4884 backp = &bfreelist.av_back;
4835 *1 4885 sps = PS->inte~;
4836 bdwrite(bp) 4886 spI6();
4837 struct buf *bp; 4887 rbp->b_fla~s =1 N(B_WANTEDiB_BUSYiB_ASYNC);
4838 { 4888 (*backp)-)av_forw = rbp;
4839 re~ister struct buf *rbp; 4889 rbp-)av_back = *backp;
4840 re~ister struct devtab *dp; 4890 *backp = rbp;
4841 4891 rbp-)av_forw = Ibfreelist.
4842 rbp = bp; 4892 PS-)inte~ =, sps;
4843 dp = bdevsw[rbp-)b_dev.d_maJorJ.d_tab; 4893 )
4844 if (dp == &tmtab i i dp == &httab) 4894 1* -------------------------
4845 bawrite(rbp); 4895
4846 else { 4896 1* See if the block is associated with some buffer
4847 rbp->b_fla~s =: B_DELWRI 4897 *
(mainly to avoid ~ettin~ hun~ UP on a wait in breada)
4848 brelse(rbp); 4898 *1
4849 } 4899 incore(adev, blkno)

Reproduced under licence from the Western Electric Company, NY Reproduced under licence from the Western Electric Company, NY
Copyri~ht, J. Lions, 1976 Copyri~ht, J. Lions, 1976

. Sheet 48 Sheet 48
May 24 12:41 1976 unix/bio.c PaSe 5 May 24 12:41 1976 unix/bio.c PaSe 6

4900 -( 4950 }
4901 resister int dey; 4951 }
4902 resister struct buf *bp; 4952 spI6();
4903 resister struct devtab *dpj 4953 if (bfreelist.av_forw == &bfreelist) -(
4904 4954 bfreelist.b_flags =: B_WANTED;
4<;>05 dey = adev; 4955 sleep(&bfreelist, PRIBIO);
4906 dp = bdevsw[adev.d_ma~or].d_tab; 4956 spIO();
4907 for Cbp=dp-)b_forw; bp != dp; bp = bp-}b_forw) 4957 goto loop;
4908 if Cbp-}b_blkno==blkno && bp-}b_dev==dev) 4958 }-
4909 ret<J rn Cbp ) ; 4959 spIO();
4910 returnCO); 4960 notavail(bp = bfreelist.av_forw);
4911 )- 4961 if (bp-}b_flass & B_DELWRI) -(
4912 1* 4962 bp-}b_flags =: B_ASYNC;
4913 4963 bwrite(bp);
4914 1* Assisn a buffer for the siven block. If the appropriate 4964 goto loop;
4915 * block is already associated, return it; otherwise search 4965 }
4916 * for the oldest non-busY buffer and reassiSn it. 4966 bp-}b_flags = B_BUSY : B_RELOC;
4917 * When a 512-byte area is wanted for some random reason 4967 bp-}b_back-}b_forw = bp-}b_forw;
4918 * Ce.S. durins exec. for the user arslist) setblk can be 4968 bp-}b_forw-}b_back = bp-}b_back;
4919 * called with device NODEV to avoid unwanted associativity, 4969 bp-}b_forw = dp-}b_forw;
4920 *1 4970 bp-}b_back = dp;
4921 setblkCdev, blkno) 4971 dp-}b_forw-)b_back = bp;
4922 -( 4972 dp-}b_forw = bp;
4923 resister struct buf *bp; 4973 bp-}b_dev = dey;
4924 resister struct devtab *dp; 4974 bp-}b_blkno = blkno;
4925 e}:tern lbolt; 4975 return(bp) ;
4926 4976 }-
4927
4928
ifCdev.d_lI!a~or >= nblkdev)
panic("blkdev");
4977 1* -------------------------
4978
4929 4979 1* Wait for 1/0 completion on the buffer; ret<Jrn errors
4930 loop: 4980 * to the user.
4931 if (dev < 0) 4981 *!
4932 dp &bfreelist; 4982 iowait(bp)
4933 else -( 4983 struct buf *bp;
4934 dp bdevsw[dev.d_maJor].d_tab; 4984 -(
4935 if(dp == NULL> 4985
4936 panic("devtab"); 4986
4937 for (bp=dp-)b_forw; bp != dp; bp = bp-)b_forw) -( 4987 rbp = bp;
4938 if (bp-)b_blkno!=blkno :: bp-)b_dev!=dev) 4988 spI6();
4939 continue; 4989 while (Crbp-}b_flass&B_DONE)==O)
4940 spI6(); 4990 sleep(rbp, PRIBIO);
4941 if (bp-)b_flaSs&B_BUSY) -( 4991 spIO();
4942 bp-}b_flaSs =: B_WANTED; 4992 geterrorCrbp);
4943 sleep(bp, PRIBIO); 4993 }-
4944
4945
spIO();
soto loop;
4994 1* -------------------------
4995
4946 } 4996 1* Unlink a buffer from the available list and mark it busy.
4947 splO ( ) ; 4997 * Cinternal interface)
4948 notavaiICbp); 4998 *!
4949 returnCbp); 4999 notavail(bp)

Reproduced under licence froll! the Western Electric Company, NY Reproduced under licence froll! the Western Electric Company, NY
COPYright, J. Lions, 1976 CopyriSht. J. Lions, 1976

Sheet. 49 Sheet 49
Maw 24 12:41 1976 unix/bio.c PaSe 7 Maw 24 12:41 1976 unix/bio.c PaSe 8

5000 struct buf *bpi 5050 1* -------------------------


~;001 { 5051
5002 resister struct buf *rbp; 5052 1* Initialize the buffer 1/0 swstem bw freeinS
5003 resister int sps; 5053 * all buffers and settinS all device buffer lists to elTlPtw.
5004 5054 *I
5005 rbp :: bpi 5055 binit( )
5006 sps :: F'S->intes; 5056 {
5007 sp16() ; 5057 resister struct buf *bp;
5008 rbp-)av_back->av_forw rbp-)av_forw; 5058 reSister struct devtab *dp;
5009 rbp-)av_forw->av_back rbp-)av_back; 5059 resister int i;
5010 rbp->b_flaas =1 B_BUSY; 5060 struct bdevsw *bdp;
5011 PS->intes = sps; 5061
5012 } 5062 bfreelist.b_forw = bfreelist.b_back
5013 1* ------------------------- *1 5063 bfreelist.av_forw = bfreelist.av_back &bfreelist;
5014 5064 for (i=O; i<NBUF; itt) {
5015 1* Mark 110 complete on a buff~r. release it if i/e is 5065 bp = &buf[lJ;
5016 * B5wnchronous, and wake UP anwone waitinS for it. 5066 bp->b_dev = -1;
5017 *1 5067 bp-)b_addr buffers[iJ;
5018 iodone(bp) 5068 bp->b_back = &bfreelist;
5019 stru~t buf *bp; 5069 bp->b_forw = bfreelist.b_forw;
5020 { S070 bfreelist.b_forw->b_back = bpi
5021 reSister struct buf *rbp; 5071 bfreelist.b_forw = bpi
5022 5072 bp->b_flass = B_BUSY;
5023 rbp == bp; 5073 bl'elseCbp) ;
::j024 if(rbp->b_flaSs&B_MAP) 5074 }
5025 lTIapfree(rbp); 5075 i 0;
5026 rbp->b_flass =1 B_DONE; 5076 for (bdp = bdevsw; bdp-)d_open; bdptt) {
5027 if Crbp-)b_flaSs&B_ASYNC) 5077 dp = bdp->d_tab;
5028 brelse(rbp); 5078 if(dp) {
5029 else { 5079 dp->b_forw
5030 5080 dp->b_back
5031 wakeup ( rbp) ; 5081 }
5032 } 5082 itt;
5033 } 5083 }
5034 1* ------------------------- *1 5084 nblkdev = i;
5035 5085 }
5036 1* Zero the core associated with a buffer. 5086 1* ------------------------- *1
5037 *1 5087
5038 c 1 rblJf (bp) 5088 1* Device start routine for disks
5039 int *bp; 5089 * and other devices that have the resister
5040 { 5090 * lawout of the older DEC controllers (RF, RK, RP, TM)
5041 resister *p; 5091 *I
5042 resister c; 5092 tdefine IENABLE 0100
5043 5093 tdefine WCOM 02
5044 p = bp->b_addr; 5094 tdefine RCOM 04
5045 c :: 256; 5095 tdefine GO 01
5046 do 5096 devstart(bp, devloc, devblk, hbcom)
5047 *ptt 0; 5097 struct blJf *bp;
5048 while (--c); 5098 int *devloe;
5049 } 5099 {

Reproduced under licence from the Western Electric Companw, NY Reproduced under licence from the Western Electric Companw, NY
Copwrisht, J. Lions, 1976 CopwriSht, J. Lions. 1976

Sheet 50 Sheet 50
Maw 24 12:41 1976 unix/bio.c Pa~e 9 Ma~ 24 12:41 1976 unix/bio.c Pa~e 10

5100 register int *dp; 5150 * a unibus device.


5101 register struct buf *rbp; 5151 * The code here and in
5102 register int com; 5152 * rhstart assumes that an rh on an 11/70
5103 5153 * is an rh70 and contains 22 bit addressing,
5104 dp = devloc; 5154 *1
5105 rbp = bpi 5155 int maplock;
5106 *dp = devblk; 1* block address *1 5156 mapallocCabp)
5107 *--dp = rbp-)b_addr; 1*
buffer address *1 5157 struct buf *abp;
5108 *--dp = rbp-)b_wcount; 1* word count *1 5158 {
5109 com = Chbcom«8) : IENABLE : GO 5159 resister i, a;
5110 C(rbp-)b_xmem & 03) « 4); 5160 register struct buf *bp;
5111 if Crbp-)b_flags&B_READ) 1*
command t x-mem *1 5161
5112 com =: RCOM; 5162 ifCcputwpe != 70)
5113 else 5163 return;
5114 com =: WCOM; 5164 spI6C);
5115 *--dp com; 5165 while(maplock&B_BUSY) {
5116 } 5166 maplock =: B_WANTED;
5117 1* 5167 sleepC&maplock. PSWP};
5118 5168 }
5119 1* startup routine for RH controllers. *1 5169 map lock =: B_BUSY;
5120 tdefine RHWCOM 060 5170 spIO();
5121 tdefine RHRCOM 070 5171 bp = abp;
5122 5172 bp-)b_flags =: B_MAP;
5123 rhstartCbp, devloc. devblk, abae) 5173 a = bp-)b_xmem;
5124 struct buf *bp; 5174 forCi=16; i<32; i=t2)
5125 int *devloc. *abae; 5175 UBMAP-)rCitlJ a;
5126 { 5176 forCatt; 1<48; 1=t2)
5127 register int *dp; 5177 UBMAP-)rCitlJ a;
5128 register struct buf *rbp; 5178 bp-)b_xmem = 1;
5129 register 1nt com; 5179 }
5130 5180 1*
5131 dp = devloc; 5181
5132 rbp = bpi 5182 mapfree(bp)
5133 if(cput~pe == 70) 5183 struct buf *bp;
5134 *abae = rbp-)b_xmem; 5184 {
5135 *dp = devblk; 1* block address *1 5185
5136 *--dp = rbp-)b_addr; 1* buffer address *1 5186 bp-)b_flags =& HB_MAP;
5137 *--dp = rbp-)b_wcount; 1* word count *1 5187 ifCmaplock&B_WANTED)
5138 com = IENABLE : GO : 5188 wakeupC&maplock);
5139 CCrbp-)b_xmem & 03) « 8); 5189 maplock = 0;
5140 if (rbp-)b_flags&B_READ) 1* commandt x-mem *1 5190 }
5141 com =: RHRCOM; else 5191 1* -------------------------
5142 com =: RHWCOM; 5192
5143 *--dp = com; 5193 1*
5144 } 5194 * swap 1/0
5145 1* 5195 *1
5146 5196 swapCblkno, coreaddr. count. rdflg)
5147 1* 5197 {
5148 * 11/70 routine to allocate the 5198 register int *fp;
5149 * UNIBUS map and initialize for 5199

Reproduced under licence from the Western Electric Compan~. NY Reproduced under licence from the Western Electric Companw, NY
Cop~right, J. Lions. 1976 Copwright, J. Lions. 1976

Sheet 51 Sheet 51
May 24 12:41 1976 unix/bio.c Page 11 May 24 12:41 1976 unix/bio.c Page 12

5~?00 fp = &swbuf.b_flags; 5250 * Raw liD. The arguments are


5201 spI6() ;
while (*fp&B_BUSY) {
5251 * The strategy routine for the device
~=;202 5252 * A buffer, which will always be a special buffer
5203 *fp =1 B_WANTED; 5253 * header owned exclusively by the device for this purpose
5204 sleep(fp, PSWP); 5254 * The device number
520~S }
*fp B_BUSY: B_PHYS : rdfl~;
5255
5256
*
*
Read/write flag
Essentiall~ all the work is computins ph~sical
5206 addresses
5207 swbuf.b_dev = swapdev; 5257 * and validating them.
5208 swbuf.b_wcount = - (count«5); 1* 32 w/block *1 5258 *1
5209 swbuf.b_blkno = blkno; 5259 phYsio(strat, abp, dev, rw)
5210 swbuf.b_addr = coreaddr«6; 1* 64 blblock *1 5260 struct buf *abp;
5:~11 swbuf.b_xmem = (coreaddr»iO) & 077; 5261 int <*strat)();
5212 (*bdevsw[swapdev»8J.d_strategy) (&swbuf); 5262 {
5213 sp16(); 5263 register struct buf *bp;
5214 while«*fp&B_DONE)==O) 5264 resister char *base;
~=j2 :1. ~5 sleep(fp, PSWP); 5265 resister int nb;
5216 if (*fp&B_WANTED) 5266 int ts;
5217 wakelJp (fp) ; 5267
5218 splO(); 5268 bp = abp;
5219 *fp =& N(B_BUSYIB_WANTED); 5269 base = u.u_base;
5::~20 return(*fp&B_ERROR); 5270 1*
!5221 } 5271 * Check odd base, odd count, and address wraparound
::;222 1* ------------------------- *1 5272 *1
5223 5273 if (base&Ol I I u.u_count&01 I I base>=base+u.u_count)
5224 1* make sure all write-behind blocks 5274 soto bad;
5225 *
on dev (or NODEV for all) 5275 ts = (u.u_tsize+127) & N0177;
5226 * are flushed out. 5276 if (u.u_sep)
5227 * (from umount and update) 5277 ts = OJ
5228 *1 5278 nb = (base»6) & 01777;
5229 ~flush(dev) 5279 1*
5230 { 5280 *
Check overlap with text. (ts and nb now
5231 register struct buf *bp; 5281 *
in 64-byte clicks)
5232 5282 *1
5233 loop: 5283 if (nb <: ts)
52;34 spI6(); 5284 soto bad;
5235 for (bp = bfreelist.av_forw; bp != &bfreelist; 5285 1*
::j236 bp = bp-)av_forw) { 5286 * Check that transfer is either entirely in the
5237 if (bp-)b_flags&B_DELWRI && 5287 * data or in the stack: that is, either
5238 (dev == NODE V I Idev == bp-)b_dev» { 5288 * the end is in the data or the start i~ in the stack
5239 bp-)b_flags =1 B_ASYNC; 5289 *
(remember wraparound was already checked).
5240 notavail(bp); 5290 *1
5241 bwrite(bp)j 5291 if ««base+u.u_count»)6)&01777) )= ts+u.u_dsize
5242 goto loop; 5292 && nb < 1024-u.u_ssize)
5243 } 5293 goto bad;
5244 } 5294 spI6();
5245 spIO(); 5295 while (bp-)b_flags&B_BUSY) {
5246 } 5296 bp-)b_flags =1 B_WANTED;
5247 1* ------------------------- 5297 sleep(bp, PRIBIO);
5248 5298 }
524'1 1* 5299 bp-)b_flags = B_BUSY I B_PHYS rw;

Reproduced under licence from the Western Electric Company, NY Reproduced under licence from the Western Electric Company, NY
Copyright, J. Lions, 1976 CoPYrisht, J. Lions. 1976

Sheet 52 Sheet 52
May 24 12:41 1976 unix/bio.c PaSe 13 May 24 12:42 1976 unix/rk.c PaSe 1

5300 bp-)b_dev = dev' 5350 t


5301 1* 5351 /'#.
5302 * Compute phYsical address by simulatins 5352 */
!5303
5304
**!the seSmentation hardware. 5353
5354 1*
5305 5355 * RK disk driver
5306 base = Cu.u_sep? UDSA: UISA)-)rCnb»7J + Cnb&0177); 5356 *1
5307 bp-)b_addr =t base«6P 5357
5308 bp-)b_xmem = Cbase»10) & 077; 5358 linclude ' •• /param.h"
5309 bp-)b_blkno = IshiftCu.u_offset. -9)1 5359 linclude ' •• /buf.h"
5310 bp-)b_wcount = -«u.u_count»I) & 077777); 5360 iinclude ' •• /conf.h'
5311 bp-)b_error = 0; 5361 'include ' •• /user.h"
5312 u.u_procp-)p_flaB =: SLOCK; 5362
5313 C*strat)Cbp); 5363 Idefine RKADDR 0177400
5314 spI6()' 5364 Idefine NRK 4
5315 while (Cbp-)b_flaSs&B_DONE) 0) 5365 Idefine NRKBLK 4872
5316 sleep(bp, PRIBIO); 5366
5317 u.u_procp-)p_flaB =& NSLOCKi 5367 Idefine RESET 0
5318 if Cbp-)b_flaBs&B_WANTED) 5368 'define GO 01
5319 wakeup(bp); 5369 Idet'ine DRESET 014
5320 splO(), 5370 Idefine IENABLE 0100
5321 bp-)b_flaBs =& N(B_BUSY:B_WANTED); 5371 Idefine DRY 0200
5322 u.u_count = (-bp-)b_resid)«I; 5372 tdet'ine ARDY 0100
5323 BeterrorCbp) ; 5373 'define WLO 020000
5324 return; 5374 idet'ine CTLRDY 0200
5325 bad: 5375
5326 u.u_error = EFAULT. 5376 struct (
5327 } 5377 int rkds'
5328 1* ------------------------- *1 5378 int rker;
5:529 5379 int rkcsi
5330 1* 5380 int rkwc'
5331 * Pick UP the device's error number and pass it to the 5381 int rkbai
5332 * user; if there is an error but the number is 0 set a 5382 int rl<.da;
5333 * seneralised code. Actually the latter is always true 5383 H
5334 * because devices don't yet return specific errors. 5384 1* -------------------------
5335 *1 5385
5336 seterrorCabp) 5386 struct devtab rktabi
5337 struct buf *abp; 5387 struct buf rrkbuf;
!5:338 { 5388
5339 register struct bUf *bp' 5389 rkstrategyCabp)
5:340 5390 struct buf *abp;
5341 bp = abp; 5391 -{
~'i342 if (bp-)b_flaBs&B_ERROR) 5392 register struct but' *bp;
5343 if «u.u_error = bp-)b_error)==O) 5393 register *GCr *GI.
~):3-44 u.u_error EIO' 5394 int d;
5345 } 5395
5346 1* ------------------------- 5396 bp = abp;
::'i347 5397 ifCbp-)b_flags&B_PHYS)
5348 5398 ITlapalloc (bp) ;
5:349 5399

Reproduced under licence from the Western Electric Company, NY Reproduced under licence from the Western Electric Company, NY
CopyriBht, J. Lions, 1976 Copyright, J. Lions, 1976

Sheet 53 Sheet 53
May 24 12:42 1976 unix/rk.c Pa~e 2 May 24 12142 1976 unix/rk.c Page 3

~)400 if(d <= 0) 5450


!5401. d == U 5451 rkintr()
5402 if (bp->b_blkno >= NRKBLK*d) { 5452 {
!;'j403 bp->b_fla~s =: B_ERROR; 5453 re~ister struct buf Ibp;
5404 iodone(bp); 5454
5405 return; 5455 if (rktab.d_active == 0)
5406 } 5456 return.
~j407 bp->av_forw = 0; 5457 bp = rktab.d_actf;
5408 sp15(); 5458 rktab.d_active == 0;
5409 if (rktab.d_actf==O) 5459 if (RKADDR->rkcs < 0) { 1* error bit *1
5410 rktab.d_actf = bp; 5460 deverror(bp, RKADDR->rker. RKADDR->rkds);
5411 else 5461 RKADDR->rkcs = RESETlGO.
5412 5462 while(CRKADDR->rkcs&CTLRDY) 0);
541.3 rktab.d_actl = bp; 5463 if C++rktab.d_errcnt <= 10) {
5414 if (rktab.d_active==O) 5464 rkstart();
~'i415 rkstart() ; 5465 return;
~=;416 SF-IOC); 5466 }o
54:l7 } 5467 bp->b_fla~s =: B_ERROR;
5418 1* 5468 }
~'i41 '7 5469 rktab.d_errcnt = 0;
5420 rkaddrCbp) 5470 rktab.d_actf bp->av_forw;
5421 struct buf *bp; 5471 iodone(bp);
5422 { 5472 rkstartC);
5423 re~ister struct buf *p; 5473 }
!5424 re~ister int b; 5474 1* -------------------------
~)-425 int d, IT'; 5475
~H26 5476 rkread(dev)
~=;427 p bp; 5477 {
5428 b p- >b_b 11<. no ; 5478
5429 m p->b_dev.d_minor - 7. 5479 phYsioCrkstrategy, &rrkbuf, dey. B_READ)'
5430 if(m <= 0) 5480 }
~j431 d p->b_dev.d_minor; 5481 1* ------------------------- *1
~i4~32 else { 5482
~1433 d 1 rem(b, m); 5483 rkwrite(dev)
~j434 b Idiv(b, m); 5484 {
5435 } 5485
5436 return(d«13: (b/12)«4 0::::12) ; 5486 phYsio(rkstrsteSw. &rrkbuf. dey. B_WRITE);
5437 ) 5487 }
5438 1* ------------------------- 5488 1* --------.----------------- *1
~H39 5489
~i440 rkstart ( ) 5490
544:l { 5491
5442 5492
~'i443 5493
5444 if «bp = rktab.d_actf) 0) 5494
5445 ret'.Jrn; 5495
~'i446 rktab.d_active++; 5496
~i447 devstart(bp, &RKADDR->rkda, rkaddr(bp), 0); 5497
5448 } 5498
5449 1* ------------------------- *1 5499

Reproduced under licencE frG~ tha ~25tErn Elec'tric CGmpan~p NY


Copyright, J. Lions, 1976 Copyright, J. Lions, 1976

Sheet 54 Sheet 54
May 24 12:54 1976 unix/file.h PaSe 1 May 24 12:54 1976 unix/filsys.h Page 1

5500 1* 5550 1*
5501 * One file structure is allocated 5551 *
Definition of the unix super block.
5502 * for each open/creat/pipe call. 5552 **
The root super block is allocated and
5503 ** Main use is to hold the read/write 5553 read in iinit/alloc.c. Subseouently
5504 pointer associated with each open 5554 **
a super block is allocated and read
5505
5506
* file.
*1
5555 with each mount (smount/sys3.c) and
5556 * released with unmount (sumount/sys3.c).
5507 struct file 5557 * A disk block is ripped off for storage.
5508 { 5558 * See alloc.c for general alloclfree
5509 char 5559 * routines for free list and I list.
5510 char f_count; 1* reference count *1 5560 *1
5511 int f_inodei 1* pointer to inode structure *1 5561 struct filsys
5512 char *f_offset[2]i 1* read/write character pointer */5562 {
5513 } file[NFILE]i 5563 int s_isize; 1* size in blocks of I list *1
5514 1* ------------------------- *1 5564 int s_fsizei 1* size in blocks of entire volume *1
5515 5565 int 1* number of in core free blocks
5516 1* flags *1 5566 (between 0 and 100) *1
5517 idefine FREAD 01 5567 int s_free[100]i 1* in core free blocks *1
5518 idefine FWRITE 02 5568 int s_ninodei 1* number of in core I nodes (0-100) *1
5519 Idefine FPIPE 04 5569 int s_inode[100]i/* in core free I nodes *1
5520 5570 char s_flocki 1* lock during free list manipulation *1
5521 5571 char s_ilocki 1* lock during I list manipulation *1
5522 5572 char s_fmodi 1* super block modified flag*1
5523 5573 char s_ronly; 1* mounted read-only flag *1
5524 5574 int s_time[2]i 1* current date of last update *1
5525 5575 int pad[50]i
5526 5576 };
5527 5577 1* ------------------------- *1
5528 5578
5529 5579 ~
5530 5580
5531 5581
5532 5582
5533 5583
5534 5584
5535 5585
5536 5586
5537 5587
5538 5588
5539 5589
5540 5590
5541 5591
5542 5592
5543 5593
5544 5594
5545 5595
5546 5596
5547 5597
5548 5598
5549 5599

Reproduced under licence from the Western Electric Company, NY Reproduced under licence from the Western Electric Company, NY
Ccpyrisht, J. Lions, 1976 Copyright, J. Lions. 1976

Sheet 55 Sheet 55
Ma~ 24 12:54 1976 unix/ino.h PaSe 1 Ma~ 24 12:54 1976 unix/inode.h PaSe 1

5600 1* 5650 II The I node is the focus of all


5601 *
Inode structure as it appears on 5651 * file activit~ in unix. There is a uniGue
5602 *
the disk. Not used b~ the s~stem, 5652 ** inode allocated for each active file.
5603 *
but bw thinSs like check, df, dump. 5653
5654 *
each current directorY, each mounted-on
file. text file, and the root. An inode is 'named'
5604 *1
5605 stPlJct inode 5655 • by its dev/inumber pair. (iset/iset.c)
5606 { 5656 * Data, from mode on, is read in
5607 int i_mode; 5657 * from permanent inode on volume.
5608 char j._nlinld 5658 *1
5609 char i_'Jid; 5659 struct inode
5610 char Lsid; 5660 {
5611 char i_sizeO; 5661 char
5612 char *i_size1; 5662 char i_count; 1*
reference count *1
~5613 int Laddr[8] ; 5663 int i_dev; 1* device where inode resides *1
561.4 int i_atime[2]; 5664 int i_number; 1* i number, l-to-l with device
~=j615 int i_mtime[2]; 5665 address *1
~5616 H 5666 int i_mode.
5617 1* ---.---------------------- *1 5667 char i_nlinkl 1*
directorw entries *1
:;'i618 5668 char i_uid; 1* owner *1
5619 1* modes *1 5669 char i_sid; 1* Sroup of owner *1
5620 *define IALLOC 0100000 5670 char i_sizeO; 1* most significant of size *1
:;'i621 idefine IFMT 060000 5671 char *i_size1; 1* least sis *1
5622 idefine IFDIR 040000 5672 int i_addr[8J./I device addresses constitutins file .1
!:j623 tdefine IFCHR 020000 5673 int i_Iastr' I . last logical block read (for
5624 idefine IFBLK 060000 5674 read-ahead) *1
5625 "'define lLARG 010000 5675 } inode[NINODE]'
5626 idefine lSUID 04000 5676 1* ------------------------- *1
~'i627 idefine ISGID 02000 5677
5628 idefine lSVTX 01000 5678 1* flags *1
5629 idefine IREAII 0400 5679 idefine ILOCK 01 1* inode is locked *1
5630 "'define IWRITE 0200 5680 Cdefine IUPD 02 1* inode has been modified *1
5631 "'define IEXEC 0100 5681 ~define lACC 04 Ill< inode access time to be updated :::;
5632 5682 idefine IMOUNT 010 Ill< inode is Rlounted on ;;:1
5633 5683 ~define IWANT 020 1* SORle process waiting on lock *1
5634 5684 Idefine ITEXT 040 Itt. inode is pure te:d:. prototype *1
~'i635 5685
5636 5686 1* modes *1
5637 5687 idefine IALLOC 0100000 1* file is IJsed *1
5638 5688 idefine IFMT 060000 type of file
5639 5689 idefine lFDlR 040000
1*
1* directorw *1
*'
~)640 5690 idefine lFCHR 020000 1* character special *1
5641 5691 idefine IFBLK 060000 Ill< block special. 0 is reglJlar *1
5642 5692 ~define ILARG 010000 lli< larse address inS algorithm *1
5643 5693 .define ISUID 04000 1* set user id on e>:ecution *1
5644 5694 Idefine ISGID 02000 I. set SrOIJP id on e>:ecution '/t.1
5645 5695 Idefine ISVTX 01000 1* save swapped te}~t even after use
read, write, e>(ecute permissions "ft.1
*1
5646 5696 #define IREAD 0400 1*
5647 5697 idefine IWRITE 0200
5648 5698 Idefine IEXEC 0100
5649 5699

Reppod~ced wnde~ licence from the Western Electric COffiPanyv NY Reproduced und2r licence from the :~estGrn El~ctric COffiPans~ NY
Cop~riSht, J. Lions, 1976 Cop~ri~ht. J. Lions. 1976

Sheet 56 Sheet 56
May 24 12:54 1976 unix/sys2.c Page 1 May 24 12:54 1976 unix/sys2.c Page 2

5700 t 5750 } else {


5701 tinclude ' •• /param.h" 5751 u.u_offsetClJ fp->f_offsetC1J;
5702 tinclude '.,/sYstm.h' 5752 u. 'J_offsetCOJ fp-)f_offsetCO];
5703 tinclude '"/user,h' 5753 if Cff.==FREAD)
5704 tinclude '"/reg.h' 5754 readiCfp-)f_inode); else
5705 tinclude '"/file,h' 5755 writeiCfp-)f_inode);
5706 tinclude '"/inode,h' 5756 dpaddCfp-)f_offset, u,u_argC1]-u.u_count);
~;707 5757 }
5708 1* 5758
5709 * read system call 5759 }
5710
5711 readC)
*' 5760 1*
5761
*1
5712 {
~;71 :~ rdwr(FREAD) ;
5762 '*
5763 * open system call
~j714 } 5764 *1
~'i715 1* ------------------------- *1 57650penC)
~;716 5766 {
~'i717 1* 5767 register lip;
~;718
~j119
* write system call 5768
5769
e:·:tern uctlar;
*1
!5720 write() 5770 ip = nameiC&uchar, 0);
~'i"721 { 5771 ifCip == NULL>
5722 rdwrCFWRITE); 5772 return;
5723 } 5773 u,'J_argC1J++;
5724 1* ------------------------- *1 5774 open1Cip, u,u_argC1J, 0);
5725 5775 }
5726 1* 5776 1* ------------------------- *1
5727 ** check
common code for read and write calls: 5777
5728
5729
permissions, set base, count, and offset,
* and switch out to readi, writei, or pipe code. 5778 '*
5779 * creat system call
5730 5780 *1
573:L *' r (mode)
rdw 5781 creatC)
5732 { 5782 {
5733 register *fp, m; 5783 register lip;
5734 5784 e:·:te rn uchar;
5735 m '"' mode; 5785
!5736 fp = getf(u.u_arOCROJ); 5786 ip = nameiC&us~ar, 1);
~'i737 ifefp == NULL> 5787 ifCip == NULL) {
5738 return; 5788 ifCu.u_error)
~1739 if«fp-)f_flag&m) == 0) { 5789 return;
5740 u.u_error = EBADF; 5790 ip = maknodeCu.u_argC1J&0'7777&C N ISVTX»;
~=;741 return; 5791 if Cip==NULL)
5742 } 5792 return;
5743 u.u_base = u.u_srgCOJ; 5'793 open1Cip, FWRITE, 2);
5744 u.u_count = u.u_argC1]; 5794 } else
T745 u.u_segflg = 0; 5'795 open1Cip, FWRITE, 1);
5746 ifCfp-)f_flag&FPIPE) { 5'796 }
5747 if(m==FREAD) 579'7 1* *1
5748 readp(fp); else 5798
5749 writepCfp) ; 5799 1*

Reproduced under licence from the Western Electric Company, NY Reproduced under licence from the Western Electric Company, NY
Copyright, J. Lions, 1976 Copyright, J. Lions, 1976

Sheet 57 Sheet 57
Maw 24 12:54 1976 unix/sws2.c Pa~e 3 Maw 24 12:54 1976 unix/sys2.c Pa~e 4

5800 *
COffiffion code for open and creat. 5850 fp = setf(u.u_arO[ROJ);
5801 *
Check permissions. allocate an open file structure. 5851
5852
if(fp == NULL)
return,
5802 * and call the device open routine if any.
5803 *1 5853
5854
u.u_ofile[u.u_arO[ROJJ = NULL;
closef(fp);
5804 openl(ip, mode, trf)
!5805 5855 }
5806 5856 1* -------------------------
5807 resister struct file *fp; 5857
!;'ja08 re~ister *rip, m; 5858 1*
~=;a09 int i; 5859 *
seek system call
5810
rip = ip;
5860 *1
5861 seek()
~'iBii
51312 m = mode; 5862 {
5813 if(trf ! = 2) { 5863 int n[2J;
!;'j814 if(m&FREAD) 5864 re~ister *fp, t;
!;'ji315 access(rip, IREAD); 5865
5 Ell 6 if (ffi&FWRITE) { 5866 fp = setf(u.u_arO[ROJ);
5817 access(rip, IWRITE); 5867 if(fp == NULL>
5818 if«rip-)i_mode&IFMT) == IFDIR) 5868 ret'Jrn;
5819 u.u_error = EISDIR; 5869 if(fp-)f_flas&FPIPE) {
5820 5870 u.u_error = ESPIPE;
582j. 5871 return;
5822 if(u.u_error) 5872 }
5823 soto out; 5873 t = u.u_arsI:1J;
5824 i f (trf) 5874 if(t ) 2) {
!..1825 itrunc(rip); 5875 n[IJ = u.u_ar~[OJ«9;
~=;826 prele(rip); 5876 n[OJ = u.u_arsI:OJ»7;
51327 if «f? = falloc(» == NULL) 5877 if(t -- 3)
5828 soto out; 5878 n[OJ =& 0777;
5829 fp-)f_flas = m&(FREADIFWRITE); 5879 } else {
5830 fp-)f_inode = rip; 5880 n[IJ u.u_ar~[OJ;
58;31 i = u,'J_arO[ROJ; 5881 n[OJ 0;
!;'j832 openi(rip, m&FWRITE); 5882 if(t!=O && n[IJ(O)
5833 if(u.u_error == 0) 5883 n[OJ = -1;
~'i834 return; 5884 }
5835 u.u_ofile[iJ = NULL; 5885 switch(t) {
58;36 fp-)f_count--; 5886
5837 5887 case 1:
51338 o'Jt: 5888 case 4:
5839 iput(rip); 5889 n[OJ =t fp->f_offset[O);
5840 } 5890 dpaddCn, fp-)f_offset[I]);
5841 1* ------------------------- *1 5891
5892
break;
5842
5843 1* 5893 defa'Jlt:
5844 *' close ~~steffi call 5894 n[OJ =t f?-)f_inoda->i_sizeO:0377;
5845 *1 5895 dpadd(n, fp-)f_inode-)i_sizel);
5846 close() 5896
51347 { 5897 case 0:
5848 resister *fp; 5898 case 3:
5849 5899

Reproduced under licence from the Westgrn Electric Com?anYr NY Repr~duced und8; li~=nce from tl,e W~ste~i) El~c~pic COffi?a~~; NY
Copyrisht, J. Lions, 1976 Cop~rishtv J. Lions. 1976
Sheet 58 Sheet 58

I
May 24 12:54 1976 unix/sys2.c Page 5 May 24 12:54 1976 UniK/sys2.c Page 6

5900 } 5950 * mknod system call


5901 fp->f_offset[l] n[ 1]; 5951 *1
5';>02 fp-)f_offset[O] nCO]; 5952 ITlknod C)
5903 }- 5953 {
~1'i'04 1* 5954 register *ip;
5905 5955 e;·:te rn ucha r;
5';>06 5956
5907 1* link system call 5957 ifCsl.Jser(» {
5908 *1 5958 ip = nameiC&uchar, 1);
5'1'09 link() 5959 ifCip != NULL) {
5';>lO { 5960 u.u_error = EEXIST.
5911 resister *ip, *xP; 5961 soto out;
5912 e;·:tern uchar; 5962
5'113 5963 }
~1'114 ip = namei(&uchar, 0); 5964 ifCIJ.IJ_error)
591.5 if(ip == NULL) 5965 return;
5916 retl.Jrn; 5966 ip = maknodeCu.u_arg[l]);
5917 ifCip-)i_nlink >= 127) { 5967 if (ip==NULL)
5918 u.u_error = EMLINK; 5968 retlJ rn;
5919 soto OIJt; 5969 ip-)i_addr[O] u.u_arse2];
~'i920 } 5970
~:;'121 if(Cip-)i_mode&IFMT)==IFDIR && !suserC» 5971 out:
~)922 soto out; 5972 iputCip)'
5'123 1* 5973 }
5924 *
unlock to avoid possibly hanSins the namei 5974 1* ------------------------- *1
5<l25 *1 5975
~5'126 ip-)i_flag =& NILOCK; 5976 1* sleep system call
59;D u.u_dirp = u.u_arg[l]; 5977 * not to be confused with the sleep internal routine.
5928 xp = nameiC&uchar, 1); 5978 *I
5929 ifCKP != NULL) { 5979 sslep()
5930 u.u_error = EEXIST; 5980 {
~'i931 iPI.JtC;·:p) ; 5981 char *d[2];
~,)932 } 5982
5933 ifCu.<.J_error) 5983 spI7C);
~i934 goto out; 5984 deO] = time[O]'
~W~~5 ifCu.<.J_pdir-)i_dev != .ip-)i_dev) { 5985 dC1] = timee 1];
::';'136 iputCIJ.u_pdir) ; 5986 dpadd(d, u.u_arOeRO]).
5';>37 u.u_error = EXDEV. 5987
5']38 soto OIJt. 5988 while(dpcmp(deO], dCl], timeCO], timeC1]) ) 0) (
~=;'i39 } 5989 ifCdpcmp(tout[O], toutCl], time[O], timeCl]) (= 0 ::
5940 wdirCip); 5990 dpcmpCtoutCO], toutCl], deO], dCl]) ) 0) {
5941 ip-)i_nlinktt; 5991 touteo] deO];
5942 ip-)i_flaS =: IUPD; 5992 tout[l] " dU];
~1943 5993 }
~'i944 out: 5994 sleepCtout, PSLEP)'
5945 iputCip); 5995 }
~=;946 )- 5996 spIOC);
5947 1* ------------------------- *1 5997 }
~1948 5998 1* ------------------------- *1
::';949 1* 5999

Reproduced under licence from the Western Electric Company, NY Reproduced under licence from the Western Electric Company, NY
Copyrisht, J. Lions, 1976 Copyright, J. Lions, 1976

Sheet 59 Sheet 59
Ma~ 24 12:55 1976 unix/s~s3.c Pa~e 1 Ma~ 24 12:55 1976 unix/s~s3.c Pa~e 2

6000 t 6050 iupdatCip, t.ime);


6001 ~include ""/param,h' 6051 bp bread(ip-)i_dev. IdivCip-)i_number+31, 16»;
6002 tinclude " •• /s~stm.h· 6052 cp = bp-)b_addr + 32.lremCip-)i_number+31, 16) + 24;
6003 ~include • •• /re~.h" 6053 ip = &Cip-)i_dev);
6004 tinclude " •• /buf.h· 6054 for(i=O; i<14; itt) {
6005 tinclude " •• /fils~s.h· 6055 suwordCub, *ip++);
6006 tinclude ",./user.h" "6056
6007 tinclude " •• /inode.h" 6057 }
6008 tinclude " •• /file.h· 6058 for(i=O; i<4; itt) {
6009 tinclude " •• Iconf.h" 6059 suwordCub, *cp++);
6010 6060 'Jb =+ 2;
6011 1* 6061 }
.!,012 *
the fstat s~stem call • 6062
6063 )-
brelseCbp);
.!,013 *I
6014 fstate) 6064 1* ------------------------- *1
6015 { 6065
.!,016 6066
6067
1** the dup system call.
601.7
6018 fp = ~etfeu.u_arO[RO]); 6068 *1
.!,019 if (fp == NULL> 6069 dupe )
6020 return; 6070 {
6021 stat1(fp-)f_inode, u.u_ar~[OJ); 6071 re~ister i, *fl";'
b022 } 6072
6023 1* ------------------------- 6073 fp = ~etfCu.u_arOCRO]);
6024 6074 ifCfp == NULL>
6025 1* 6075 return;
6026 *the stat s~stem call. 6076 if (Ci = ufallocC» < 0)
,:'027 *1 6077 ret'Jrn;
6028 st.atC) 6078 u.u_ofileCiJ = fp;
6029 { 6079 fp-)f_count++;
6030 resister ip; 6080 }
6031 extern uchar; 6081 1*
.!,032 6082
6033 ip = nameiC&uchar, 0); 6083 1*
6034 i f-( i p == NULL) 6084 * the mount s~steffi call.
6035 return; 6085 *1
6036 statl(ip, u.u_ar~[I]); 6086 sr;;o'Jnt C)
6037 iput( ip); 6087 {
6038 } 6088 int d;
6039 1* ------------------------- *1 6089 re~ister *ip,
6040 6090 resister struct mount *mp, *smp;
6041 1* 6091 extern uchar;
6042 *
The basic routine for fstat and stat: 6092
6043 *
set the inoda and pass appropriate parts back. 6093 d = set;;;j2'.' C) v
6044 *1 6094 ifCu.u_error)
6045 statl(ip, ub) 6095 ret'Jrn;
b046 int *ip; 6096 u.u_dirp = u,u_ars[I];
6047 { 6097 ip = nameiC&uchar, 0);
6048 6098 if(ip == NULL>
.!,049 6099 ret'Jrn;

Reppoduced un~2~ li~ence from ths Western Elactric COffiPan~p NY He-Pf-oduced lJ'ld'S' ...· licl,;;<!"";ct:;,· ?·~·U~ji Lhs {!Jes-t.er-~i El,:::-c;--(,i"ic.- COii:pi!:;;'..:r ;~ . .(
Copwrisht, J. Liens. 1976 Cop~ri~ht. J. Lions. 1976
Sheet 60 Sheet 60
Ma~ 24 12:55 1976 unix/s~s3.c Pa~e 3 Ma~ 24 12:55 1976 unix/s~s3.c Page 4

6100 ifCip-)i_count!=1 :: Cip-)i_ffiode&CIFBLK&IFCHR»!=O) 6150 updateC);


6101 goto out; 6151 d = getmdevC);
6102 smp = NULL; 6152 ifCu.u_error)
6103 forCffiP = &ffiount[O]; mp < &mount[NMOUNT]; ffiP++) { 6153 return;
6104 ifCffiP-)m_bufp != NULL) { 6154 forCmp = &mount[O]i mp < &mount[NMOUNTJ; mptt)
6105 if Cd == ffip-)m_dev) 6155 ifCmp-)m_bufp!=NULL && d==mp-)m_dev)
6106 goto out; 6156 goto found;
6107 } else 6157 u.u_error = EINVAL;
6108 ifCsmp == NULL) 6158 return;
6109 smp = mp; 6159
6110 } 6160 found:
6111 ifCsmp == NULL) 6161 forCip = &inode[O]; ip < &inode[NINODEJ; iptt)
6112 go to out; 6162 ifCip-)i_number!=O && d==ip-)i_dev) {
6113 C*bdevsw[d.d_maJor].d_open)Cd, !u.u_argC2]); 6163 u.u_error = EBUSY;
6114 ifCu.u_error) 6164 return;
6115 goto out; 6165 }
6116 mp = breadCd, 1); 6166
6117 ifCu.u_error) { 6167 ip = mp-)m_inodp;
6118 brelseCmp); 6168 ip-)i_flag =& HIMOUNT;
6119 goto out1; 6169 iputCip);
6120 } 6170 ip = mp-)m_bufp;
6121 smp-)m_inodp = ip; 6171 mp-)m_bufp = NULL;
6122 smp-)m_dev = d; 6172 brelseCip);
6123 smp-)m_bufp = getblkCNODEV); 6173 }
6124 6174 1* -------------------------
6125 SffiP = smp-)m_bufp-)b_addri 6175
6126 sffiP-)s_ilock 0; 6176 1*
6127 smp-)s_flock 0; 6177 * Common code for mount and umount.
6128 6178 * Check that the user's argument is a reasonable thing
6129 brelse(mp); 6179 * on which to mount, and return the device number if so.
6130 ip-)i_flag =i IMOUNT; 6180 *1
6131 preleCip); 6181 getmdevC)
6132 return; 6182 {
6133 6183 register d, *ip;
6134 out: 6184 extern uchar;
6135 u.u_error EBUSY; 6185
6136 outl: 6186 ip = nameiC&uchar, 0);
6137 iputCip); 6187 if(ip == NULL)
6138 } 6188 return;
6139 1* 6189 if(Cip-)i_mode&IFMT) != IFBLK)
6140 6190 u.u_error = ENOTBLK;
6141 1* 6191 d = ip-)i_addr[O];
6142 * the umount s~stem call. 6192 if(ip-)i_addr[OJ.d_maJor )= nblkdev)
6143 *1 6193 u.u_error = ENXIO;
6144 sumountC) 6194 iputCip);
6145 { 6195 returnCd);
6146 int d; 6196 }
6147 register struct inode *ip; 6197 1* -------------------------
6148 register struct mount *mp; 6198
6149 6199

Reproduced under licence from the Western Electric Compan~, NY Reproduced under licence from the Western Electric Compan~, NY
Cop~right, J. Lions, 1976 Cop~right, J. Lions, 1976

Sheet 61 Sheet 61
May 24 12:55 1976 unix/rdwri.c Page 1 May 24 12:55 1976 unix/rdwri.c Page 2

6200 i 6250 dn
6201 1* 6251 } else {
6202 *1 6252 dn ip-)i_addrCOJ;
6203 6253 rablock = bn+l;
6204 iinclude " •• /param.h" 6254 }
6205 linclude " •• /inode.h" 6255 if (ip-)i_Iastr+l == Ibn)
6206 linclude " •• /user.h" 6256 bp breada(dn, bn. rablock);
6207 *include " •• /buf.h" 6257 else
6208 iinclude ' •• /conf.h" 6258 bp bread(dn, bn);
6209 iinclude " •• /systm.h" 6259 ip-)i_Iastr = Ibn;
6210 6260 iomove(bp, on. n. B_READ);
6211 1* 6261 brelse(bp);
6212 * Read the file corresponding to 6262 } while(u.u_error==O && u.u_count!=O);
6213 * the inode pointed at bw the argument. 6263 }
6214 *
The actual read arguments are found 6264 1*
f~~~
U~&W *
in the variablc~: 6265
6216 *
u_base core address for destination 6266 1*
6217 *
u_offset byte offset in file 6267 * Write the file corresponding to
6218 *
u_count number of bytes to read 6268 *the inode pointed at by the argument.
6219
6220
*
u_segflg read to kernel/user 6269 *The actual write arSuments are found
*1 6270 * in the variables:
6221 readi(aip) 6271 * u_base core address for source
6222 struct inode *aip; 6272 * u_offset bwte offset in file
6223 { 6273 * u_count number of bytes to write
6224 int *bp; 6274 * u_segflg write to kernel/user
6225 int Ibn, bn, on; 6275 *1
6226 register dn, n; 6276 writei(aip)
6227 register struct inode *ip; 6277 struct inode *aip;
6228 6278 {
6229 ip = aip; 6279 int *bp~
6230 if(u.u_count == 0) 6280 int n, on;
6231 return; 6281 resister dn, bn;
6232 ip-)i_flaS =: IACC; 6282 register struct inode *ip;
6233 if«ip-)i_mode&IFMT) == IFCHR) { 6283
6234 (*cdevswCip-)i_addrCOJ.d_maJorJ.d_read) (ip-)i_addrCOJ) ; 6284 ip = aip;
6235 return; 6285 ip-)i_flaS =: IACCIIUPD;
6236 } 6286 if«ip-)i_mode&IFMT) == IFCHR) {
6237 6287 (*cdevswCip-)i_addr[OJ.d_maJorJ.d_write) (ip-)i_addr[OJ );
6238 do { 6288 return;
6239 Ibn = bn = lshift(u.u_offset. -9); 6289 }
6240 on = u.u_offsetC1J & 0777; 6290 if (u.u_count 0)
6241 n = min(512-on, u.u_count); 6291 return;
6242 if«ip-)i_mode&IFMT) != IFBLK) { 6292
6243 dn = dpcmp(ip-)i_sizeO&0377, ip-)i_sizel, 6293 do {
6244 u.u_offsetCOJ, u.u_offset[IJ); 6294 bn = lshift(u.u_offset, -9).
6245 if(dn <= 0) 6295 on = u.u_offset[IJ & 0777;
6246 return; 6296 n = min(512-on, u.u_count);
6247 n = min(n, dn); 6297 if«ip-)i_mode&IFMT) != IFBLK) {
6248 if «bn = bwap(ip, Ibn» 0) 6298 if (Cbn = bmap(ip, bn» == 0)
6249 return; 6299 return;

Reproduced under licence from the Western Electric Company, NY Reproduced under lic2ncG from the Western Ele=tric C~mpanY, NY
CoPYright, J. Lions. 1976 Cop~right, J. Lions. 1976

Sheet 62 Sheet 62
May 24 12:55 1976 unix/rdwri.c PaSe 3 May 24 12:55 1976 unix/rdwri.c Page 4

6300 dn ip->i_dev; 6350 /* Move 'an' bytes at byte location


6301 } else 6351 * &bp->b_addr[o] to/from Iflag) the
6302 dn ip->i_addr[O]; 6352 * user/kernel lu.segflS) area startins at u.base.
6303 ifCn -- 512) 6353 * Update all the arguments by the number
6304
6305
bp setblk(dn, bn) ; else
bp = bread(dn, bn) ;
6354
6355
* of bytes moved.
6~'106 iomoveCbp, on, n, B_WRITE); *
6356 * There are 2 alSorithms,
6307 if(u.u_error != 0) 6357 * if source address, dest address and count
6:~08 brelselbp); else 6358 * are all even in a user copy,
6309 if ICu.u_offset[1J&0777)==0) 6359 * then the machine lanSuage copyin/copyout
6310
':,311
bawrite(bp), else
bdwriteCbp).
6360
6361
**is called.
If not. its done byte-by-byte with
6312 ifldpcmpCip->i_sizeO&0377. ip->i_sizel,
u.u_offset[O], u.u_offset[l]) < 0 &&
6362 * cpass and passc.
6313 6363 *1
6~H4 (ip->i_mode&IIFBLK&IFCHR)) == 0) { 6364 iomovelbp, 0. an, flas)
.!,315 ip->i_sizeO u.u_offsetCO]; 6365 struct buf *bp;
':,316 ip->i_size1 = u.u_offset[lJ; 6366 {
6~H7 } 6367 register char *cp;
63113 ip->i_flas =: IUP[I' 6368 resister int n, t ;
.!,319 } while(u.u_error==O && u.u_count!=O); 6369
6320 } 6370 n = an;
':,321 1* 6371 CP = bp->b_addr + 0;
6322 (,372 iflu.u_segflg==O && lIn: CP : u.u_base)&01)==Ol (
6323 1* Return the 10Sicai maximum 6373 if Iflas==B_WRITE)
6324 * of the 2 arSuments. 6374 CP copyinlu.u_base, cp, nJ;
6325 *1 6375 else
6326 ma:·: I a, b) 6376 CP
6327 char *a, *b; 6377 if I cp) {
63213 -( 6378 u.u_error = EFAULTj
6329 6379 return;
6330 ifla > b) 6380 }
6331 return(a); 6381 u. ,J_base =+ n;
6332 returnlb); 6382 dpaddlu.u_offset, n);
6~'I33 } 6383 IJ .IJ_count =- n;
6334 1* ------------------------- *1 6384 return;
6335 6385 }
.:,336 1* Return the losical minimum 6386 if (flaS==B_WRITE) (
6337 * of the 2 arSuments. 6387 whileln--) {
6:nB *1 6388 if «t = cpassl») < 0)
6:339 min(a, b) 6389 retlJrn;
6340 char *a. *b; 6390 *cp++ = t;
6341 -{ 6391 }
6342 6392 } else
6343 ifla < b) 6393 while (n--)
6~'I44 returnla) ; 6394 if(passc(*cp++) , 0)
6::;45 returnlb), 6395 return;
6:346 } 6396 }
6347 1* *1 6397 1* *1
6:348 6398
6349 6399

Reproduced under licence from the Western Electric Company, NY Reproduced under licence from the Western Electric Company. NY
Copyright, J. Lions. 1976 Copyrisht, J. Lions, 1976

Sheet 63 Sheet 63
May 24 12155 1976 Gnix/sub~.c Page 1 May 24 12155 1976 unix/subr.c PaSe 2

6400
6401
*iinclude " •• /param.h"
6450
6451
nb = bp-}b_blkno;
ip->i_addrEbn] = nb;
6402 tincllJde " •• /conf.h" 6452 ip-}i_flag =: IUPD;
6403 tinclude " •• /inode.h" 6453 }
6404 tincllJde " •• /user.h" 6454 rablock =
0;
640!5 "'include " •• /buf.h" 6455 if Cbn(7)
(>406 iinclude " •• /systm.h" 6456 rablock
6407 6457 returr,(nb) ;
64013 1* Bmap defines the structure of file system storage 6458 }
(,409 * by returning the phYsical block number on a device given 6459
(>410 * the inode and the logical block number in a file.
I When convenient, it also leaves the physical
6460
6461
6411
6412 * block number of the next block of the file in rablock 6462 large:
(,413
6414
*
II
for use in read-ahead. 6463
6464
i = bn»8;
if(bn & 0174000)
6415 bmap(ip~ bn) 6465 i = 7;
6416 struct inode lip; 6466 ifC(nb=ip-}i_addrEi]) == 0) {
6417 int bn; 6467 ip->L flag =: IUP[I;
641El { 6468 if (Cbp = alloc(d» -- NULL)
6419 resister Ibp. Ibap, nb; 6469 returnCNULL);
64;!() int Inbp, d, i; 6470 ip->i_addr[i] - bp-}b_blkno;
6421 6471 } else
,5422 d = iF·-}i_dev; 6472 bp = breaded. nb);
(,423 if(bn & N077777) { 6473
lJ4~~4 u.u_error =
EFBIG; 6474
.5425 return(O); 6475 1* "hu~e" fetch of double indirect block II
6426 } 6476
M27 ifCCip-}i_mode&ILARG) ==
0) { 6477 if (i == 7) {
6428 6478 i = «bn»S) & 0377) - 7;
(,429 I I small file algorithm II 6479 if«nb=bap[i]) == 0) (
6430 6480 if«nbp = alloced» -- NULL) (
6431 i.f( (bn & N7) != 0) { 6481 brelse(bp);
6432 6482 return(NULL> ;
6433 1*
convert small to large *1 6483 }
(>434 6484 bap[i] =nbp->b_blkno;
(,43::j if (Cbp = alloc(d» NULL) 6485 bdwrite(bp);
6436 ret'Jrn(NULL> ; 6486 } else {
6437 bap = bp-)b_addr; 6487 brelse(bp);
(.438 for(i=O; i<8; itt) { 6488 nbp = breaded. nb);
(,4:39 *baptt = ip-}i_addr[i]; 6489 }
6440 ip-}i_addr[i] = 0; 6490 bp nbp;
6441 } 6491 bap = bp->b_addr;
6442 ip-}i_addr[O] = bp->b_blkno; 6492 }
6443 bdwrite(bp); 6493
6444 ip-)i_mode =: ILARG; 6494 1* normal indirect fetch *1
6445 go to large; 6495
6446 } 6496 i = brr & 0377;
6447 nb ip-)i_addrEbn]; 6497 if«nb=oa?EiJ) == 0 && (nbp al1oC(d» !=NULU {
(,448 if(nb "'= 0 && (bp = alloc(d» 1= NULL> -[ 6498 rrb = nbp->b_blkno~
(>449 bdwri te (bp); 6499 bapEiJ = rrb;

Reproduced u[)Je( ~icence from the We5tern Elsctric CGmpan~, NY ~e?rod~ced ~~de~ licence from ths ~~cst2~n E~2Ct~~~ C~~~2n~~ ~y
Copyright. J. Lions. 1976 Copyright. J. Lions. 1976

Sheet 64 Sheet 64
May 24 12:55 1976 unix/subr.c Page 3 May 24 12:55 1976 unix/subr.c Page 4

6500 bdwriteCnbp); 6550 if(Cc=fubyteCu.u_base» < 0) {


6501 bdwriteCbp); 6551 u.u_error = EFAULT;
6502 } else 6552 return(-I);
6503 brelseCbp); 6553 }
6504 rablock = 0; 6554 u.u_count--;
6505 ifCi < 255) 6555 ifCttu.u_offset[IJ == 0)
6506 rablock bap[i+1Jf 6556 u.u_offsetCOJt+;
6507 returnCnb); 6557 u.u_base++;
6508 } 6558 returnCc&0377);
6509 1* ------------------------- *1 6559 }
6510 6560 1* ------------------------- *1
6511 1* Pass back c to the user at his location u_base; 6561
6512 * update u_base, u_count, and u_offset. Return-l 6562 1*
6513 * on the last character of the user's read. 6563 * Routine which sets a user errorf placed in
6514 * u_base is in the user address space unless u_segflg 6564 * illegal entries in the bdevsw and cdevsw tables.
6515 * is set. 6565 *1
6516 *1 6566 nodevC)
6517 passc(c) 6567 {
6518 char ci 6568
6519 { 6569 u.u_error = ENODEV;
6520 6570 }
6521 ifCu.u_segflg) 6571 1* ------------------------- *1
6522 *u.u_base = c; else 6572
6523 ifCsubyteCu.u_base, c) < 0) { 6573 II
6524 u.u_error = EFAULT; 6574 * Null routine; placed in insignificant entries
6525 returnC-l); 6575 * in the bdevsw and cdevsw tables.
6526 } 6576 II
6527 u.u_count--; 6577 nulldevC)
6528 ifCttu.u_offset[IJ == 0) 6578 {
6529 u.u_offsetCOJtt; 6579 }
6530 u.u_basett; 6580 1* ------------------------- II
6531 returnCu.u_count == 0' -1: 0); 6581
6532 } 6582 1*
6533 1* ------------------------- *1 6583 * COpy count words from from to to.
6534 6584 *1
6535 1* 6585 bcopyCfrom, to. count)
6536 * Pick UP and return the next character from the user's 6586 int *from, Ito;
6537 * write call at location u_basei 6587 {
6538 I update u_base. u_count, and u_offset. Return-l 6588
6539 * when u_count is exhausted. u_base is in the user's 6589
6540 * address space unless u_segflg is set. 6590 a
6541 *1 6591 b
6542 cpassC) 6592 c count;
6543 { 6593 do
6544 resister c; 6594 *b++
6545 6595 whileC--c);
6546 ifCu.u_count == 0) 6596 }
6547 returnC-l); 6597 1* -------------------------
6548 ifCu.u_segflg) 6598
6549 c = *u.u_base; else 6599

Reproduced under licence from the Western Electric Company, NY Reproduced under licence from the Western Electric Company, NY
Copyright, J. Lions. 1976 Copyright, J. Lions, 1976

Sheet 65 Sheet 65
Maw 24 12:55 1976 unix/fio.c PaSe 1 Maw 24 12:55 1976 unix/fio.c Pase 2

,~600
[)(~01 1*
* 6650
6651
ip = rfp-)f_inode;
ip-)i_mode =& N(IREADIIWRITE);
6602 II 6652 wal<.eup( ip+l);
<,i,03 6653 wake'JP (ip+2) ,
6604 "'include • •• /param.h' 6654 }
6605 iinclude ' •• /tlser.h" 6655 if(rfp-)f_count (= 1)
.!·,606 iinclude ' •• /filsws.h" 6656 closei(7fp-)f_inode, rfp-)f_flss&FWRITE);
6607 iinclude " •• /file.h' 6657 T'fp-)f _coIJnt--;
6608 finclude " •• /conf.h" 6658 }
<,609 oM' i nc hIde ' •• /inode.h" 6659 1* ------------------------- II
.!,610 iinclude ',./res.h" 6660
6611 6661 Ill:
.:,612 II 6662 * Decrement reference count on an
6613 I Convert a user supplied 6663 * inode due to the removal of a
6614 *file descriptor into a pointer 6664 * referencins file structure.
6615 I to a file structure. 6665 * On the last closei, switchout
6616 *Onlw task is to check ranSe 6666 * to the close entrw point of special
6617 *of the descriptor. 6667
6668
I device handler.
* Note that the handler sets called
M>l8 II
.:,61 9 ~~f?tf· (f) 6669 * on everw open and onlw on the last
.:,620 {
~·)621 resister Ifp, rf,
6670
6671
* close,
*1
.!;~)22 6672 closei(ip, rw)
o!j6:~~5 rf = f; 6673 int *ip;
.~)b24 if(rf(O :: rf>=NOFILE) 6674 {
662~5 So to bad; 66'75 resister *rip;
6626 fp - u.u_ofile[rf], 6676 resister dey, maJ;
6627 if(fF' != NULL> 6677
6628 returnefp); 6678 rip == ip;
6629 bad: 6679 dev - rip->i_addrCOJ;
6630 u.u_error = EBADFf 6680 maJ rip-)i_addrCOJ.d_maJorl
6631 return(NULL), 6681 if(rip-)i_count (== 1)
.!,632 } 6682 switch(rip-)i_mode&IFMT) {
6633 1* ------------------------- *1 6683
6634 6684 case IFCHR:
<,635 1* 6685 (*cdevsw[maJJ.d_close) (dev, rw) ;
6636
6637
* Internal form
* Decrement
of close.
reference count on
6686
6687
break;

6638 * file structure and call closei 6688 case IFBLK:


6639
6640
** Also
on last closef.
make sure the pipe protocol
6689
6690 }
C!bdevsw[maJJ.d_close)(dev, rw) ;

6641 * does not constipate. 6691 iput(rip);


<,642 *1 6692 }
6643 closef(fp) 6693 1* -------------------------
6644 int Ifp; 6694
.:,645 { 6695 1*
6646 resister *rfp, *ip, 6696 * openi called to allow handler
6647 6697 * of special files to initialize and
rfp = fp; 6698 * validate before actual 10.
ifCrfp-)f_flas&FPIPE) { 6699 * Called on all sorts of opens

Re?~oduced under li=£ncG ~ro@ the :1~stcrn El~ct~ic Compan~; NY Rsproducsd under l~csnc~ from the W2stern EIE~tric CO~iP8ns~ ~!y
Copwrisht. J. Lions, 1976 Cop~risht, J. Lions. 1976

Sheet 66 Sheet 66
Ma~ 24 12:55 1976 unix/fio.c Page 3 Ma~ 24 12:55 1976 unix/fio.c Page 4

6700 * and also on mount. 6750


ip aip;
6701 *1 6751
6702 openilip, rw) 6752 m = mode;
6703 int *ip; 6753 ifCm == IWRITE) {
6704 { 6754 if(getfs(ip->i_dev)-)s_ronl~ 1= 0) {
6705 register *rip; 6755 u.u_error = EROFS;
6706 register dey, maJi 6756 returnCl);
6707 6757 }
6708 rip ip; 6758 ifCip-)i_flag I ITEXT) {
6709 dey rip-)i_addr[O]; 6759 u.u_error = ETXTBSY;
6710 maJ rip-)i_addr(OJ.d_maJor; 6760 returnCl);
6711 switchCrip-)i_modeIIFMT) { 6761 }
6712 6762 }
6713 case IFCHR: 6763 if(u.u_uid == 0) {
6714 ifCmaJ )= nchrdev) 6764 if(m == IEXEC II Cip-)i_mode I
6715 goto bad; 6765 CIEXEC : (IEXEC»3) (IEXEC»6») 0)
6716 (*cdevsw[maJJ.d_open) (dev, rw); 6766 goto bad;
6717 break; 6767 return(O);
6718 6768 }
6719 case IFBLK: 6769 ifCu.u_uid != ip-)i_uidl {
6720 ifCmaJ )=nblkdev) 6770 m =» 3.
6721 goto bad. 6771 ifCu.u_gid != ip-)i_gid)
6722 C*bdevsw[maJJ.d_open)Cdev, rw); 6772 m =~/ 3;
6723 } 6773 }
6724 return. 6774 if«ip-)i_mode&m) != 0)
6725 6775 return(O);
6726 bad! 6776
6727 = ENXIO; 6777 bad!
6728 } 6778 u.u_error EACCES;
6729 1* ------------------------- *1 6779 return(1),
6730 6780 }
6731 1* 6781 /* -------------------------
6732 * Check mode permission on inode pointer. 6782
6733 * Mode is READ, WRITE or EXEC. 6783 /*
6734 * In the case of WRITE, the 6784 * Look UP a pathname and test if
6735 * read-onl~ status of the file 6785 * the resultant inode is owned by the
**
6736
6737
6738 *
s~stem is checked.
Also in WRITE. protot~pe text
segments cannot be written.
6786
6787
6788
*** current user.
If not, try for super-user.
If permission is granted,
6739 * The mode is shifted to select 6789 * return inode pointer.
6740 * the owner/group/other fields. 6790 */
6741 * The super user is granted all 6791 owner()
6742 * permissions except for EXEC where 6792 {
6743 * at least one of the EXEC bits must 6793 register struct inode *ip;
6744
6745
*
*;
be on. 6794
6795
extern uchar();

6746 access(aip, mode) 6796 if (lip = namei(uchar. 0» NULL)


6747 int *aip, 6797 returnlNULL),
6748 { 6798
6749 6799

Reproduced under licence from the Western Electric Compan~, NY Reproduced under licence from the Western Electric Company. NY
Cop~right, J. Lions. 1976 Cop~right. J. Lions. 1976

Sheet 67 Sheet 67
Ma~ 24 12:55 1976 unix/fio.c PaSe 5 Ma~ 24 12:55 1976 unix/fiooe PaSe 6

6800 if (s'.Jser(» 6850 resister i,


.!l80l T'eturn(ip) ; 6851
.!,El02 iput( ip); 6852 if « i = ufalloc(» < 0)
.!lel03 l'et'Jrn (NULL) ; 6853 return (NULL) •
.!l804 } 6854 for (fp = &fileEOJ; fp < Ifile[NFILEJI fp++)
1*
.!l1305 6855 if (fp-)f_count==O) {
61306 6856 u.u_ofile[iJ = fp;
.!,B07
.!l808
1** Test if the current user is the
6857
6858
t'p··-)f _.crJI..Int++;
t'p-)f_offset[OJ 0;
.!l809 * super user • 6859 fp-)f_offset[lJ 0;
.!,€I10*1
6EIli suser()
6860
6861 }
returnU'p) ;

.!,8i2 { 6862 printf("no file\n");


.!,13i3 6863 u.u_error =
ENFILE,
61314 if(u.u_uid == 0) 6864 return(NULL);
.~~B:J.5 ,'sturn (1) ; 6865 }-
,!,1316
.!,8l7
u.u_error = EPERM,
return(O) ;
6866
6867
1* 1/

.!,<'H8 } 6868
61319 1* ------------------------- *1 6869
,!,820 6870

a!1822
1**
.!lB21.
Allocate a user file descriptor.
6871
68"72
6823 *1 6873
bB24 'Jfalloc ( ) 6874
6825 { 6875
.!,H26 resister i; 6876
.!,B27 6877
,!,B28 for (i=O; i<NOFILE, itt) 6878
.!,1329 if (u.u_ofileEiJ NULL) { 6879
.!l830 6880
·6831 ret'Jrn (i) ; 6881
,!,B:32 } 6882
61333 uou_error EMFILE; 6883
.!,B34 return(-1); 6884
.5835 } 6885
.!l8361* ------------------------- *1 6886
61337 6887
.!,B38
.!,839
1** Allocate a user file descriptor
6888
6889
.!,840 * and a file structure. 6890
6841 * Initialize the descriptor 6891
.!,B42 * to point at the file structure. 6892
.!,843 6893
.!,B44
** no file -- if there are no available 6894
6845 * file structures. 6895
6846 *1 6896
61347 falloc() 6897
6848 { 6898
.!l849 resister struct file *fp; 6899

Reproduced under licance f~Qrn the Weste~~ El~ctric COm?2nS; NY ~eprodu=ed wn~a~ lic~~=2 fro"i ~hE Weste!'n EIE~::tr:t Co,~p2ri~~ ~~y
Cop~risht, J. Lions1 1976 Cop~risht, J. Lions" 1976
Sheet 68 Sheet 68
Ma~ 24 12:55 1976 unix/alloc.c Page 1 Ma~ 24 12:55 1976 unix/alloc.c Page 2

6900 4 6950 * free blocks; the last of these is read to


6901 1* 6951 * obtain 100 more
6902 *1 6952
6953 *
* no space on dey x/~ when
6903
6904 iinclude u •• /param.hD 6954 * the free list is exhausted.
6905 tinclude • •• /s~stm.h· 6955 *1
6906 iinclude • •• /fils~s.h" 6956 allocCdev)
6907 iinclude " •• Iconf.h' 6957 {
6908 iinclude " •• /buf.h' 6958 int bno;
6909 linclude " •• /inode.h' 6959 resister *bp, *ip, *fp;
6910 .include " .• /user.h a 6960
6911 6961 fp = setfsedev);
6912 1* 6962 while(fp-)s_flock)
6913 * iinit is called once (from main) 6963 sleepC&fp-)s_flock, PINOD);
6914 *
* It
ver~ earl~in initialization.
reads the root's super block
6964
6965
do {
ifCfp-)s_nfree (= 0)
6915
6916 * and initializes the current date 6966 gato nospace;
6917 * from the last modified date. 6967 bno = fp-)s_freeC--fp-)s_nfreeJ;
6918 6968 ifCbno == 0)
6919 *
* panic: iinit -- cannot read the super 6969 goto nospace;
6920 * block. Usuall~ because of an 10 error. 6970 } while CbadblockCfp, bno, dey»~;
6921 *1 6971 ifCfp-)s_nfree (= 0) {
fp-)s_flock++;
6922 iinite) 6972
6923 { 6973 bp = breadedev, bno);
6924 resister *cp, *bp; 6974 ip = bp-)b_addr;
6925 6975 fp-)s_nfree = *ip++;
6926 (*bdevsw[rootdev.d_maJorJ.d_open) (rootdev, 1); 6976 bcopwCip, fp-)s_free, 100);
6927 bp = breadCrootdev, 1). 6977 brelseCbp);
6928 Cp = getblkCNODEV); 6978 fp-)s_flock = 0;
6929 ifCu.u_error) 6979 wakeupC&fp-)s_flock);
6930 panic('iinit'); 6980 }
6931 bcopwCbp-)b_addr, cp-)b_addr. 256); 6981 bp getblkCdev, bno);
6932 brelse(bp); 6982 clrbuf(bp);
6933 ffiountCOJ.ffi_bufp = cp; 6983 fp-)s_fmod = 1;
6934 ffiountCOJ.m_dev = rootdev; 6984 returnCbp);
6935 cp = cp-)b_addri 6985
6936 cP-)s_flack 0; 6986 nospace:
6937 cP-)s_ilock = 0; 6987 fp-)s_nfree = 0;
6938 cp-)s_ronl~ = 0; 6988 prdevC"no space", dey);
6939 timeCOJ cp-)s_time[OJ; 6989 u.u_error = ENOSPC;
6940 timeC1] = cp-)s_timeC1J; 6990 returnCNULL);
6941 } 6991 }
6942 1* *1 6992 1* ------------------------- *1
6943 1* *1 6993 1* ------------------------- *1
6944 6994
6945 1* 6995 1*
6946 * free
alloc will obtain the next available 6996 * place the specified disk block
* back on the free list
6947
6948
* the specified
disk block from the free list of 6997
6998 * specified device.
of the

6949 ** The super blockdevice.


has UP to 100 remembered 6999 *1
Reproduced under licence from the Western Electric Compan~, NY Reproduced under licence from the Western Electric Compsnw, NY
Cop~right, J. Lions, 1976 Copwright, J. Lions, 1976

Sheet 69 Sheet 69
Maw 24 12:55 1976 unix/alloc.c PaSe 3 Maw 24 12:55 1976 unix/alloc.c Page 4

7000 freeCdev, bno) 7050 }


7001 { 705:l return(O);
7002 7052 }
7003 7053 1* ------------------------- *1
7004 fp = getfs(dev); 7054 1* ------------------------- *1
7005 fp->s_fmod = 1; 7055
7006
7007
while(fp-)s_flock)
sleep(&fp-)s_flock. PINOD);
7056
7057
1** Allocate an unused I node
7008 if Cbadblock(fp. bno, dey») 7058 * on the specified device.
7009 retlJrn; 7059 * Used with file creation.
7010 ifCfp->s_nfree (= 0) { 7060 * The algorithm keeps to UP
7011 fp-)s_nfree = 1; 7061 * 100 spare I nodes in the
7()l2 fp-)s_free[OJ = 0; 7062 * super block. When this runs out,
7013 } 7063 * a linear search through the
7014 ifCfp-)s_nfree )= 100) { 7064 * I list is instituted to pick
7015 fp-)s .._flf.)~!<++' 7065 * 100 more.
UP
7016 bp = setblk(dev, bno); 7066 *1
701.7 ip = bp-)b_addr; 7067 ialloc(dev)
70 tEl *ip++ = fp-)s_nfree; 7068 {
701.9 bcopw(fp-)s_free, ip. 100); 7069
7020 fp-)s_nfree 0; 7070 int i. J, k, ino;
7021 bwrite(bp); 7071
7022 fp-)s_flock 0; 7072 fp = Setfs(dev);
70~~3 wakeup(8fp-)s_flock); 7073 whileCfp-)s_ilock)
7024 } 7074 sleep(&fp-)s_ilock. PINOD);
7025 fp-)s_free[fp-)s_nfree++J = bno; 7075 loop:
l026 fp->s_fmod = 1; 7076 if(fp->s_ninode > 0) {
'7027 } 7077 ino = fp->s_inode[--fp-)s_ninodeJ;
7028 1* 7078 ip = isetCdev, ino);
7029 1* 7079 if Cip==NULL)
70:10 7080 return(NULL);
70:11. 1* 7081 ifCip->i_mode == 0) {
for(bp = &ip->i_mode; bp
7032
7033 * Check that a block number is in the
range between the I list and the size
7082
7083 *bp++ = 0;
7034
70:~5 ** of the device.
This is used mainlw to check that a
7084
7085 return(ip);
7036
7037 ** garbage file swstem has not been mounted. 7086
7087
}

7038 * bad block on dey x/w not 7058


1*
* Inode was allocated after all.
7039 *1 7089 * Loo!~ some more.
7040 badblockCafp, abn, dey) 7090 *1
7041 { 7091 iP'Jt(ip);
7042 r~aister struct filsws .f~; 7092 :.!oto 1 oar:- ;
7043 register char Ibn; 7093 }
7044 7094
7045 fp = afp; 7095 inc = 0;
7046 bn = abn; 7096
7047 if (bn ( fp-)s_isize+2 :: bn >= fp-)s_fsize) { 7097 b? = b~ead(dev, i~'2);
7048 prdevC"bad block', de~); 7098 ip = bp->b_ad.:lr'
7049 return(1); 7099 for(j=O; j(256; J=+16) {

Reprodcced C~dET li2enco f~om tM~ ~2£~2rn E12ctric C02?an~r NY ~C?I-'rodu~s'd unc::- li:::<.~G r·"'Oh. '~:tE :.:25.tern El\;c~;':;'2 CDi;:P':',-::!~' :~:~
Copwright, J. Lions. 1976 Ccpwright. J. Lions, 1976
Sheet 70 Sheet 70
May 24 12:55 1976 unix/alloc.c Page 5 May 24 12:55 1976 unix/alloc.c Page 6

7100 ino++; 7150 * getfs maps a device number into


7101 if(ip[J] !== 0) 7151 * a pointer to the incore super
1102 continue, 7152 * block.
1103 for(k==O; k<NINODE, k++) 7153 * The algorithm is a linear
1104 if(dev ==== inode[k].i_dev 1& 7154 * search through the mount table.
1105 ino ==== inode[k].i_number) 7155 * A consistency check of the
n06 goto cont, 7156 * in core free-block and i-node
n07 fp->s_inode[fp->s_ninode++] == ino, 7157 * counts.
if(fp->s_ninode >== 100) 7158
n08
"7l. 09 break; 7159 *
* bad count on dey x/y -- the count
71.1.0 cant:; 7160 *
check failed. At this point, all
7111 } 7161 * the counts are zeroed which will
7112 brelse(bp)' 7162 * almost certainly lead to "no space"
n13 ifCfp->s_ninode >== 100) 7163 * diagnostic
1114 break. 7164 * panic: no fs -- the device is not mounted.
1115 } 7165 * this 'cannot happen'
7116 fp->s_ilock 0; 7166 *1
7117 wakeupClfp->s_ilock), 7167 getfsCdev)
7118 if Cfp->s_ninode > 0) 7168 -(
7119 gO to IOOF-, 7169 register struct mount *p;
07120 prdevC"Out of inodes', dey); 7170 register char *nl, *n2;
1121 u.u_error == ENOSPC, 7171
1122 returnCNULL); 7172 forCp == Imount[O]' P < Imount[NMOUNT]; p++)
"7l.23 } 7173 ifCp->m_bufp !== NULL 1& p->m_dev === dey) (
1124 1* *1 7174 P == p->m_bufp->b_addr,
7125 1* *1 7175 nl == p->s_nfree;
7126 7176 n2 == p->s_ninode;
7U7 I . 7177 ifCnl :> 100 i i n2 :> 100) -(
7128 7178 prdevC"bad count", dey);
7129 *• on
Free the specified I node
the specified device. 7179 p->s_nfree == O.
7130
7131
** to
The algorithm stores UP
100 I nodes in the super
7180
?l81 }
p-:>s_ninode == OJ

7132 * block and throws away any more. 7182


71.33 II 7183 }
7134 it'reeCdev, ina) 7184 panicC'no f5');
"7135 { 7185 }
7l.36 7186 1* ------------------------- II
"7137 7187 1* ------------------------- II
7138 fp == getfs(dev); 7188
"7139 it'(fp-:>s_ilock) 7189 1*
7:l40 retuT'n' 7190 * update is the internal name of
* 'sync'. It goes through the disk
"714l. ifCfp->s_ninode >= 100) 7191
?:l42 return; 7192 ** Queues to initiate sandbagged 10;
goes through the I nodes to write
"7143 fp->s_inode[fp->s_ninode++] ino; 7193
7144 fpo->s_fmod == 1; 7194 * modified nodes; and it goes through
?l45 } 7195 * the mount table to initiate modified
7146 1* ------------------------- *1 7196
7197
*
II
super blocks.
7147 1* ------------------------- *1
?l48 7198
7149 1* 7199

Reproduced under licence from the Western Electric Company, NY Reproduced under licence from the Western Electric Company, NY
Copyright, J. Lions, 1976 CoPYright, J. Lions, 1976

Sheet 71 Sheet 71
Ma~ 24 12:55 1976 unix/alloc.c Pa~e 7 Ma~ 24 12:56 1976 unix/i~et.c Pa~e 1

7200 7250 i
7201 updateC) 7251 iinclude • •• /param.h"
n02 { 7252 iinclude • •• /s~stm.h"
7203 re~ister struct inode lip; 7253 tinclude • •• /user.h"
7204 re~ister struct mount *mp; 7254 iinclude " •• /inode.h"
7205 re~ister *bp; 7255 iinclude • •• /fils~s.h"
n06 7256 tinclude ·~~/conf~h·
7207 ifCupdlock) 7257 iinclude " •• /buf.h"
7208 return; 7258
7209 updlocktt; 7259 1*
7210 forCmp = &mountCO]; mp < &mountCNMOUNTJ. mptt) 7260 * Look UP an inode by device.inumber.
7211
'7212
ifCmp-)m_bufp != NULL) {
ip = mp->m_bufp-)b_addr;
7261 *
If it is in core (in the inode structure),
7262 * honor the lockin~ protocol.
7213 ifCip-)s_fmod==O :: ip-)s_ilock!=O :: 7263 * If it is not in core, read it in from the
721,4 ip-)s_flock!=O :: ip-)s_ronl~!=O) 7264 * specified device.
'7215 continue; 7265 * If the inode is mounted on, perform
'7216 bp = ~etblkCmp-)m_dev, 1); 7266 * the indicated indirection.
'7217 ip-)s_fmod = 0; 7267 * In all cases, a pointer to a locked
'7218 ip-)s_timeEO] = timeEO]; 7268 * inode structure is returned.
72:l9 ip-)s_timeE1J = timeCl]; 7269 *
'72~~0 bcop~(ip, bp->b_addr, 256); 7270 * printf warnin~: no inodes -- if the inode
'7221 bwriteCbp) ; 7271 * structure is full
72~~2 } 7272 * panic: no imt -- if the mounted file
n23 forCip = &inodeCO]; ip <
&inodeENINODEJf iptt) 7273 * s~stem is not in the mount table.
'7224 ifCCip-)i_fla~&ILOCK) == 0) { 7274 * 'cannot happen"
"72:-!5
7226
ip-)i_flaS =: ILOCK;
iupdatCip, time);
7275
7276
*'
i~etCdev, ina)
7227 prele(ip); 7277 {
'7228 } 7278 re~ister struct inode *P;
'7229 IJPdlock = 0; 7279 re~ister *ip2;
'7230 bfIIJshCNODEV) ; 7280 int hp1;
}231 } 7281 re~ister struct mount *ip;
}232 1* ------------------------- *1 7282
}233 1* ------------------------- *1 7283 loop:
'7234 7284 ip = NULL.
n35 7285 for(p = &inodeCO]; p < &inodeCNINODE]; pt+) {
'7236 7286 if(dev==p->i_dev && ino==p-)i_number) {
n37 7287 if«p-')Lf1a~&ILOCK) != 0) {
'7:;'!38 7288 p-)i_fla~ =i IWANTi
}~!39 7289 sleep(p. PINOD),
'7240 7290 ~oto loop;
7241 7291 }
'7242 7292 if( (p->Lfla~&IMOUNTl != 0) {
}243 7293 for (ip = &mountCO];
7244 7294 ip < &mountCNMOUNT]; iptt)
'7245 7295 if (ip-)m_inodp == p) {
n46 7296 dey = ip->m_dev;
'7247 7297 ina = ROOTINO;
'7248 7298 ~oto loop;
7249 7299 }

Reproduced under licence from the Western Electric Company, NY Reproduced under lic~nce frGffi the Western Elec~Tic Com?snYr NY
Cop~ri~ht, J. Lions, 1976 Cop~ri~ht. J. Lions, !976

Sheet 72 Sheet 72
Ma~ 24 12:56 1976 unix/iget.c Page 2 Ma~ 24 12:56 1976 unix/iget.c Page 3

7300 panicC"no imt"); 7350 if(rp-)i_count == 1) ~


7301 } 7351 rp-)i_flag =: ILOCKi
7302 p-)i_count++; 7352
7303 p-)i_flag =: ILOCK; 7353 itrunc(rp);
7304 returnCp); 7354 rp-)i_mode = 0;
7305 } 7355 ifreeCrp-)i_dev, rp-)i_number);
7306 ifCip==NULL && p-)i_count==O) 7356 }
7307 7357 iupdat(rp, time);
7308 } 7358 preleCrp);
7309 ifC(p=ip) NULL) ~ 7359 rp-)i_flag 0;
7310 printfC"Inode table overflow\n"); 7360 rp-)i_number = 0;
7311 u.u_error = ENFILE; 7361 }
7312 return(NULL); 7362 rp-)i_count--;
7313 } 7363 preleCrp);
7314 7364 }
7315 p-)i_number = ino; 7365 1*
7316 p-)i_flag = ILOCKi 7366
7317 7367 1*
7318 p-)i_Iastr = -1; 7368 * Check accessed and update flags on
7319
7320
ip = breadCdev, Idiv(ino+31,16»; 7369
7370
*
an inode structure.
* If either is on. update the inode
1*
7321
7322
* Check 1/0 errors 7371
7372
*
with the corresponding dates
* set to the argument tm.
*/
7323 7373 *1
7324 7374 iupdat(p. tm)
7325 iput(p); 7375 int *pl
7326 returnCNULL); 7376 int *tm;
7327 } 7377 {
7328 ipl ip-)b_addr + 32*lrem(ino+31, 16)1 7378 register *ipl. *ip2, *rp;
7329 ip2 &p-)i_mode; 7379 int *bp, if
7330 whileCip2 < &p-)i_addrC8]) 7380
7331 *ip2++ = *ipl++1 7381 rp = p;
7332 brelseCip); 7382 if«rp-)i_flag&(IUPD:IACC» != 0) ~
7333 returnCp); 7383 if(getfs(rp-)i_dev)-)s_ronl~)
7334 } 7384 return;
7335 1* ------------------------- 7385 i = rp-)i_number+31;
7336 7386 bp = bread(rp-)i_dev, Idiv(i.16»;
7337 1* 7387 ipl = bp-)b_addr + 32*lremCi, 16);
7338 * Decrement reference count of 7388 ip2 = &rp-)i_modei
7339 * an inode structure. 7389 whileCip2 < &rp-)i_addrC8])
7340 * On the last reference, 7390 *ipl++ = *ip2++;
7341 * write the inode out and if necessar~, 7391 if(rp-)i_flag&IACC) {
7342 * truncate and deallocate the file. 7392 *ipl++ timeCO];
7343 *1 7393 *ipl++ = timeC1];
7344 iput(p) 7394 } else
7345 struct inode *pi 7395 ipl =+ 2;
7346 { 7396 ifCrp-)i_flag&IUPD) {
7347 register *rp; 7397 *ipl++ *tm++;
7348 7398 *ipl++ = *tm;
7349 rp = pi 7399 }

Reproduced under licence from the Western Electric Compan~, NY Reproduced under licence from the Western Electric Companw, NY
Copwright, J. Lions, 1976 Copwright, J. Lions, 1976

Sheet 73 Sheet 73
Maw 24 12:56 1976 unix/iSet.c PaSe 4 Maw 24 12:56 1976 unix/iset.c PaSe 5

7400 bwrite(bp); "7450 1* ------------------------- #1


"7401 } 7451
7402 } 7452 1*
7403 1* ------------------------- 7453 • Make a new file.
7404 7454 *1
]405 1* 7455 maknode(mode)
7406 * Free all the disk blocks associated 7456 {
]40] * with the specified inode structure. 7457
7408 * The blocks of the file are removed 7458
7409 * in reverse order. This FILO 7459 ip = ialloc(u.u_pdir->i_dev);
7410 * alSorithm will tend to maintain 7460 if (ip==NULL)
]411 * a conti~uous free list much lon~er 7461 return(NULL);
)'412
)'413
*
*!
than FIFO. 7462
7463
ip-)i_flas =: IACC:IUPD;
ip->i_mode = mode:IALLOC;
7414 itrunc(ip) 7464 ip->i_nlink = 1;
7415 int *ip; 7465 ip-)i_uid u.u_uid;
"74i6 -( 7466 ip->i_Sid = u.u_sidi
7417 resister *rp, *bp, *cp; 7467 wdir(ip);
7418 int *dp, *ep; 7468 return(ip) ;
7419 7469 }
7420 rp = ip; 7470 1*
"7421 if « rp->i..II.ode& (IFCHR&IFBLlO) ! = 0) 7471
"7422 ret'Jrn; 7472 1*
7423 for(ip = &rp-)i_addr[7J; ip )= &rp-)i_addrCO]; ip--) 7473 * Write a directory entry with
"74;!4 if(*1p) { 7474 * parameters left as side effects
"7425 if«rp->Lmode&ILARG) != 0) { 7475 * to a call to namei.
7426 bp = bread(rp-)i_dev, *ip); 7476 *1
7427 for(cp = bp->b_addrt512; cp ?= bp->b_addr; 7477 wdir(ip)
7428 cp--) 7478 int lip;
7429 if(*cp) { 7479 {
7430 if(lp &rp-)i_addrC7J) { 7480
7431 dp = bread(rp->i_dev, *cp); 7481
'7432 for(ep = dp->b_addrt5121 7482 u.u_dent.u_ino = ip-)i_number;
7433 ep >= dp->b_addr; ep--) 7483 cp1 = &u.u_dent.u_nameCOJ;
7434 7484 for(cp2 = &u.u_dbuf[OJ; cp2 < &u.u_dbufCDIRSIZJ;)
7435 free(rp->i_dev, *ep); 7485 *cplt+ = *cp2++;
'7436 brelse(dp) ; 7486 u.u_count = DIRSIZ+2;
7437 } 7487
7438 7488 u.u_base = &u.u_dent;
7439 } 7489 writei(u.u_pdir);
7440 brelse(bp) 1 7490 ipu"i:.'u.u_pdi rj;
'7441 } 7491 }
7442 free(rp->i_dev, *ip); 7492 I:'{.
7443 *ip = 0; 7493
7444 } 7494
7445 rp->i_mode =& NILARG; 7495 •
7446 rp-)i_sizeO = 01 7496
"7447 rp-)i_sizel = 01 7497
7448 rp->i_flas =: IUPDf 7498
7449 } 7499

Reproduced ~nder licence fro~ the WesLern Electric C~mpanw. NY


Copwrisht. J. Lions, 1976 Copwrisht, J. Lions, 197G

Sheet 74 Sheet 74
Maw 24 12:56 1976 unix/nami.c Pa~e 1 Maw 24 12:56 1976 unix/nami.c Page 2

7500 t 7550 if(c '\0')


7501 tinclude " •• /param.h' 7551 return(dp);
7502 tinclude ' •• /inode.h' 7552
7503 tinclude ' •• /user.h' 7553 1*
7504 tinclude ' •• /swstm.h' 7554 * If there is another component,
7505 tinclude ' •• /buf.h' 7555 * dp must be a directorw and
7506 7556 * must have x permission.
7507 1* 7557 *1
7508 * Convert a pathname into a pointer to 7558
7509 * an inode. Note that the inode is locked. 7559 if«dp-)i_mode&IFMT) != IFDIR) {
7510
7511
** func = function called to get next char of name
7560
7561
u.u_error = ENOTDIR;
goto out;
7512 * &uchar if name is in user space 7562 }
7513 * &schar if name is in system space 7563 if(access(dp, IEXEC»
7514 * flag 0 if name is sou~ht 7564 goto out;
7515 * 1 if name is to be created 7565
7516 * 2 if name is to be deleted 7566 1* Gather UP name into
7517 *1 7567 * users' dir buffer.
7518 nameiCfunc. flag) 7568 *1
7519 int C*func)(); 7569
7520 { 7570 cp = &u.u_dbuf[O];
7521 register struct inode *dp; 7571 whileCc!='I' && c!='\O' && u.u_error==O) {
7522 register c; 7572 if(cp < &u.u_dbuf[DIRSIZ])
7523 register char *cp; 7573 *cp++ = c;
7524 7574 c = (.func)();
7525 7575 }
7526 1* 7576 whileCcp < &u.u_dbuf[DIRSIZ])
7527 * If name starts with ' I ' start from 7577 *cp++ = '\0';
7528 * root; otherwise start from current dir. 7578 whileCc == 'I')
7529 *1 7579 c = C*func)C);
7530 7580 if(u.u_error)
7531 dp = u.u_cdir; 7581 goto out;
7532 ifCCc=C*func)C» == 'I') 7582
7533 dp = rootdir; 7583 1* Set UP to search a directorY. *1
7534 igetCdp-)i_dev. dp-)i_number); 7584
7535 while(c == 'I') 7585 u.u_offset[1] = 0;
7536 c = (*func)(), 7586 u.u_offset[O] = 0;
7537 ifCc == '\0' && flag != 0) { 7587 u.u_segfl~ = 1;
7538 u.u_error = ENOENT, 7588 eo = 0;
7539 goto out; 7589 u.u_count = IdivCdp-)i_sizel. DIRSIZ+2);
7540 } 7590 bp = NULL;
7541 7591
7542 cloop: 7592 eloop:
7543 1* 7593
7544 * Here dp contains pointer 7594 1*
7545 * to last component matched. 7595 * If at the end of the directors,
7546 *1 7596 * the search failed. Report what
7547 7597 * is appropriate as per flag.
7548 ifCu.u_error) 7598 *1
7549 goto out; 7599

Reproduced under licence from the Western Electric Company, NY Reproduced under licence from the Western Electric Company, NY
Copwright, J. Lions. 1976 Copyright. J. Lions, 1976

Sheet 75 Sheet 75
May 24 12:56 1976 unix/nami.c Pa~e 3 Maw 24 12:56 1976 unix/nami.c Page 4

7600 ifCu.u_count == 0) { 7650 1* Here a component matched in a directorY,


7601 ifCbp != NULL> 7651 *
If there is more pathname. go back to
7602 brelse(bp) ; 7652 *
cloop, otherwise return.
7603 if(flag==l && c=='\O') { 7653 *1
7604 if(access(dp, IWRITE» 7654
7605 goto out; 7655 i f ( bp
! = NULL>
'7606 7656 brelseCbp);
7607 if(eo) 7657 if(flag==2 && c=='\O') {
7608 u.u_offset[lJ = eo-DIRSIZ-2; else 7658 if(access(dp, IWRITE»
7609 dp-)i_flag =1 IUPDj 7659 goto OIJt;
°7610 retIJrn(NULL) ; 7660 return(dp);
l611 } 7661 }
7612 u.u_error = ENOENTj 7662 bp dp->i_dev;
7613 goto out; 7663 iPIJt(dp);
7614 } 7664 dp = iget(bp, u.u_dent.u_inol;
7615 7665 if(dp == NULL>
7616 1* 7666 retu rn (NULL> j
7617 * If offset is on a block boundary, 7667 gO to cloop;
7618 * read the next di~ectorY block. 7668
7619 * Release previous if it exists. 7669 out:
7620 *1 7670 iput(dp) ;
7621 7671 return(NULL);
7622 if«u.u_offset[lJ&0777) == 0) { 7672 }
7623 i f (bp ! = NULL>
brelse(bp) ;
7673 1* ------------------------- *1
7624 7674
7625 bp = bread(dp-)i_dev, 7675 1*
7626 bmap(dp, Idiv(u.u_offset[lJ, 512»); 7676 I Return the naxt character from the
7627 } 7677 *
kernel string pointed at by dirp.
7628
7629 1* Note first empty directory slot
7678
7679
*1
schar()
l630
7631
*
*
in eo for possible creat.
String compare the directory entry
7680 {
7681
"7632 * and the current component. 7682
"76:33 * If they do not match, go back to eloop. 7683 }
"7634
7635
*I 7684 1* ------------------------- *1
7685
7636 bcoPy(bp-)b_addrt(u.u_offset[lJ&0777), &u.u_dent, 7686 1* Return the next character from the
7637
"7638 u.u_offset[lJ =t DIRSIZt2;
(DIRSIZt2)/2); 7687 * user string pointed at bw dirp.
7688 *I
7639 u, u_coIJnt--; 7689 uchar()
"7640 if(u.u_dent.u_ino == 0) { 7690 {
7641 if(eo == 0) 7691 register c;
"7642 eo = u.u_offset[lJ; 7692
"7643 ~cto eloop; 7693 c = fub~te(u.u_dirp++);
"7644 } 7694 if(c == -1)
"7645 for~cp = t~.u_dbuf[OJ; cp < ~u.u_dbuf~DIRSIZJi cP++) 76-=;'3 u.u_error = EFAULTj
7646 ~f(*cp != cp[u.u_dc~t.u_nam~ - u.u_dbufJ) 7696 r;;;"i:.urn(c);
"7647 goto eloop; 7697 }
7648 7698 1* -------------------------
7649 7699

Reproduced under licence from the Western Electric Company, NY Reproduced under licence from the Western Electric Company, NY
CoPYri~ht. J. Lions. 1976 Copwright. J. Lions, 1976

Sheet 76 Sheet 76
Ma~ 24 12:56 1976 unix/pipe.c Pa~e 1 May 24 12:56 1976 unix/pipe.c Page 2

7700 iinclude ' •• /param.h' 7750 ip->i_count = 2;


7701 iinclude ' •• /s~stm.h' 7751 ip->i_flag IACClIUPD;
"7702 iinclude •.• /lJser.h· 7752 ip->i_mode = IALLOC;
7703 iinclude ' •• /inode.h' 7753 }
"7704 iinclude ' •• /file.h' 7754 1* *1
7705 iinclude •• • /reg.h· 7755
"7"706 7756 1* Read call directed to a pipe.
'7707 1* Max allowable bufferin~ per pipe. 7757 *1
7708
7709 *
* This is also the max size of the
file created to implement the pipe.
7758 readp(fp)
7759 int *fp;
7710 * If this size is bi~~er than 4096, 7760 -(

**
7711 pipes will be implemented in LARGe 7761 resister *rp, *ip;
"1712 files, which is probabl~ not sood. 7762
7713 *1 7763 rp
"7714 7764 ip
7715 idefine PIPSIZ 4096 7765 loop:
'7716 7766 1* Very conservative locking.
n17 1* The s~s-pipe entr~. 7767 *1
"7718 * Allocate an inode on the root device. 7768 plocldip);
"1719
"7720
* Allocate 2 file structures.
* Put it all tosether with flass.
7769 1* If the head (read) has causht UP with
* the tail (write), reset both to O.
7770
'7721 *1 7771 *1
"1722 7772 if(rp->f_offsetCIJ == ip->i_sizel) -(
"7"723 pipe() 7773 if(rp-)f_offset[lJ != 0) (
"1724 { 7774 rp-)f_offset[IJ = 0;
}72S 7775 ip->i_sizel :: 0;
7726 int r; 7776 if(ip->i_mode&IWRITE) (
"172} 7777 ip->i_mode =& NIWRITE;
"7"728 ip = ialloc(rootdev); 7778 wakeup(ip+l);
"7729 if(ip == NULL> 7779 }
'7730 return; 7780 }
'7731- rf = falloc(); 7781
'7732 if(rf == NULL) ( 7782 1* If there are not both reader and
l733 iput< ip) ; 7783 * writer active, return without
"7734 return; 7784 * satisf~ing read.
"7735 } 7785 *1
"7736 r u.u_arO[ROJ; 7786 prele(ip) ;
"7737 wf = falloc(); 7787 if(ip->i_count < 2)
"7738 if(wf == NULL) { 7788 return;
7739 rf->f_count = 0; 7789 ip->i_mode =l IREAD;
"7"740 u.u_ofile[rJ = NULL; 7790 sleep(ip+2, PPIPE);
7"741 ipfJt(ip)j 7791 goto loop;
'7742 retfJrn; 7792 }
"7743 } 7793 1* Read and return
7744 u.u_arOCRIJ = u.u_BrO[ROJ; 7794 *1
7745 u.u_arOCROJ = r; 7795 fJ. u_offset[OJ 0;
"7746 wf->f_flag = FWRITElFPIPE; 7796 u.u_offset[IJ rp->f _offset,[ 1 J;
7747 wf->f_inode = ip; 7797 readi(ip);
"7748 rf->f_flas = FREADlFPIPE; 7798 rp->f_offset[l] = u.u_offset[l];
"7:'49 rf->f_inode =ip; 7799 prele(ip);

Reproduced under licence from the Western Electric Compan~, NY Reproduced under licence from the Western Electric Compan~, NY
Cop~risht, J. Lions, 1976 Cop~ri~ht. J. Lions, 1976

Sheet 77 Sheet 77
May 24 12:56 1976 unix/pipe.c PaSe 3 May 24 12:56 1976 unix/pipe.c PaSe 4

7800 } 7850 ifCip-)i_mode&IREAD) (


7801 /* ------------------------- */ 7851 ip->i_mode =& NIREAD;
7802 7852 wakeup(ip+2);
7803 /* Write call directed to a pipe. 7853 }
°7804 *1 7854 so to loop;
7805 writep(fFo) 7855 }
7806 { 7856 /*
7807 resister *rp, *ip, c; 7857
7808 7858 /* Lock a pipe.
7809 rp = fp; 7859 * If its already locked,
7810 ip = rp-)f_inode; 7860 * set the WANT bit and sleep.
7811 c = u.u_count; 7861 */
°7812 loop: 7862 plocld ip)
7813 1* If all done, return. 7863 int *ip;
7814 */ 7864 {
7815 plock(ip); 7865 resister *rp;
"/80i6 ific == V} { 7866
7817 prele(ip); 7867 rp = ip;
7818 u.u_count 0; 7868 while(rp-)i_flaS&ILOCK) (
7819 return; 7869 rp-)i_flaS =1 IWANT;
"7820 } 7870 sleep(rp, PPIPE);
7821 /* If there are not both read and 7871 }
7822 * write sides of the pipe active, 7872
7823 *return error and siSnal too. 7873 }
7824 */ 7874 /*
7825 if(ip-)i_count < 2) ( 7875
7826 prele(ip); 7876 /* Unlock a pipe.
"7827 u.u_error = EPIPE; 7877 *
If WANT bit is on,
7828 psiSnal(u.u_procp, SIGPIPE); 7878 *
wakeup.
7829 return; 7879 * This routine is also used
7830 } 7880 *
to unlock inodes in Seneral.
7831 1* If the pipe is full, 7881 */
prele(ip)
7832 * wait for reads to deplete 7882
7833 * and truncate it. 7883 int hpj
7834 */ 7884 {
°7835 if(ip-)i_sizel == PIPSIZ) ( 7885
7836 ip->i_mode =: IWRITE; 7886
7837 prele(ip); 7887 rp = ip;
7838 sleep(ip+l, PPIPE); 7888 rp-)i_flaS =& NILOCK;
7839 soto loop; 7889 if(rp-)i_flaS&IWANT) (
7840 } 7890 rp->i_flaS =& NIWANT;
7841 /* Write what is possible and 7891 w.:;keup(rp);
7842 * loop back. 7892 }
7843 *! 7893 }
7844 u.u_offset[O] = 0; 7894 /* ;;;/
7845 u.u_offset[IJ = ip-)i_sizel; 7895
7846 u.u_count = min(c, PIPSIZ-u.u_offset[lJ); 7896
7847 c =- IJ. u_count; 7897
7848 writei(ip); 7898
7849 prele(ip); 7899

Reproduced under licence from the Western Electric Company, NY Reproduced under licence from the Western Electric Co~pany, NY
Copyright. J. Lions, 1976 Copyright. J. Lions, 1976

Sheet 78 Sheet 78
Ma~ 26 15:24 1976 unix/tts.h Page 1 Mas 26 15:24 1976 unix/ttw.h Page 2

7900 1* 7950
7901 * A clist structure is the head 7951 tdefine TTIF'RI 10
1902 * of a linked 11st aueue of characters. 7952 tdefine TTDF'RI 20
7903 ** blocks
The characters are stored in 4-word 7953
'i'
7904 containing a link and 6 characters. 7954 tdefine CERASE 1* default special characters */
7905 * The routines getc and putc (m45.s or m40.s) 7955 idefine CEDT 004
7906 * manipulate these structures. 7956 tdefine CKILL / @/
7907 *1 7957 iFdefine CQUIT 034 1* FS, cntl shift L *1
7908 struct clist 7958 idefine CINTR 0177 1* DEL *1.
7909 { 7959
7";>1 0 int c .. cc' 1* character count *1 7960 1* limits *1
7'.?11 int c_cf' 1* pointer to first block *1 7961 idefi.ne TTHIWAT 50
]'112 int c_cl; 1* pointer to last block *1 7962 "'define TTLOWAT 30
]913 }; 7963 tdefine TTYHOG 256
]'?14 Ill< *1 7964
7915 7965 1* modes *1
]'i'16 1* 7966 idefine HUPCL 01
7917 * A tts structure is needed for 7967 idefine XTABS 02
]9113 * each UNIX character device that 7968 tdefine LCASE 04
]'i'19 * is used for normal terminal 10. 7969 :idefine ECHO 010
7920 * The routines in ttw.c handle the 7970 tdefine CRMOD 020
7921 * common code associated with 7971 idefine RAW 040
7'i'22 * these 5tructures. 7972 tdefine ODDP 0100
7'123 * The definition and device dependent 7973 idefine EVENP 0200
"7924
792~5
* li<1
code i.s in each driver. (kl.c dc.c dh.c) 7974
7975
:idefine
tdefinE~
NLDELAY
TBDEL('W
001400
006000
7'i''.:.'6 struct tt~1 7976 tdefine CRDELAY 030000
7977 tdefine VTDELAY 040000
792El struct clist t_rswal 1* input chars right off device *1 7978
7929 struct clist t_csna' 1* input chars after erase and kill *1 7979 1* Hardware bits */
7'130 struct clist t_outa; 1* output list to device *1 7980 iFdf?fine DONE 0200
7931 int t_flaSs; 1* mode, settable bs stts call *1 7981 ""define IENABLE 0100
7932 int *t_addr; 1* device address (register or 7982
'79:5:3 startup fcn) li<1 7983 1* Internal state bits *1
]934 chaT' t_.delcU 1* number of delimiters in raw a *1 7984 .define TIMEOUT 01 1* Dela~ timeout in proaress *1
]'i'3~) char t_col; 1* printing column of device *1 7985 iFdefine WOPEN O? 1* Waitina for open to
] 'i'3 {, chaT' t_erasey 1* erase character *1 7986 COITIP I €~te *1
79:57 chaT' t_kill; 1* kill character *1 7987 'ltdefine ISOPEN 04 1* Device is open *1
]938 char t_state' 1* internal state. not visible 7988 iFdefine SSTMH 010 1* Has speci.aJ. start routine
7939 e;·:ternall~ *1 7989 at addr *1
7940 chaT' 1* character temporar~ *1 7990 iFdefine CARR._ON 020 1* Softwal'e cop~ of
7941 int t,_speeds; Ill< outputtinput line speed *1 7991 ca rr i e r"'p resent *1
7942 int t._dev; 1* device name *1 7992 :B'de'fine BUSY 040 1* Output in PT'Oal'ess *1
7S'43 }; 7993 tdefinE~ ASL.EEP 01.00 1* Wakeup wl'wn Clutput done *1
7944 Ill< ------------------------- *1 7994
794!5 7995
7'14/, 7996
7947 char partab[]; 1* ASCII table! paritw, character class *1 7997
7'148 7998
7949 7999

Reproduced under licence from the Western Electric Compans. NY Reproduced under licence from the Western Electric Company, NY
Copsrisht. J. Lions, 1976 Copyright. J. Lions, 1976

Slwet 79 Sheet. 79
Ma~ 26 15:24 1976 unix/kl.c Pase 1 May 26 15:24 1976 unix/kl.c Pase 2

8000 J B050 }
B001 1* KL/DL-11 driver *1 8051 addr-)klrcsr ==/ IENABLE/DSRDYIRDRENB;
8002 iincl'Jde " •• /param.h' 8052 addr-)kltcsr ==/ IENABLEf
EI003 "'include " •• /conf.h" 8053 }
8004 iincl'Jde " •• /user.h" 8054 1* ------------------------- *1
EI005 ~include " •• /tt~.h" 8055 klclose(dev)
8006 tinclude " •• /proc.h' 8056 { re~ister struct tty *tp;
8007 1* base address *1 8057 tp == &kI11[dev.d_minorJ.
8008 "'define KLADDR 0177560 1* console *1 8058 wflushtty(tp);
8009 idefine KLBASE 0176500 1* kl and dll1-a *1 8059 tp-)t_state == 0;
BOlO tdefine DLBASE 0175610 1* dl-e *1 8060 }
BOll idefine NKLil 1 8061 I I -------------------------
El012 idefine NDLil 0 8062 klread(dev)
80:L3 idefine DSRDY 02 8063 { ttreadC&kl11[dev.d_minorJ);
El014 idefine RDRENB 01 8064 }
El015 struct tty kll1[NKL11tNDLllJ; 8065 1* -------------------------
801.6 struct klress { 8066 klwrite(dev)
El017 int klrcsr; 8067 { ttwrite(&klllCdev.d_minor]);
8018 int kl rbuf; 8068 }
B019 int kltcsr; 8069 1* -------------------------
::1020 int kl tbuf; 8070 kl:-:int(dev)
El021 } 8071 { resister struct tty *tp;
El022 1* 8072 tp == &kll1[dev.d_minor];
8023 klopen(dev, flas) 8073 ttstart(tp);
8024 { resister char *addr; 8074 if (tp-)t_outG.c_cc == 0 1/ tp-)t_outG.c_cc -- TTLOWAT>
802!'i register struct tty *tp; 8075 wakeup(&tp-)t_outG),
El026 if(dev.d_minor )= NKL11+NDL11) { 8076 }
8027 u.u~error = ENXIO; 8077 I I -------------------------
8028 T'eturn; 8078 klrint(dev)
8029 } 8079 { resister int c, *addr;
8030 tp &kl11[dev.d_minorJ; 8080 register struct tty *tp;
EI031 if (u.u_procp-)p_ttyp == 0) { 8081 tp = &klll[dev.d_minor];
8032 u.u_procp-)p_ttyp tp; 8082 addr = tp-)t_addr;
ao~n tp-)t_dev == dey; 8083 c = addr-)klrbuf;
8034 } 8084 addr-)klrcsr =1 RDRENB;
8035 1* set UP minor 0 to address KLADDR 8085 if «c&0177)==0)
8036 * set UP minor 1 thru NKL11-l to address from KLBASE 8086 addr-)kltbuf = c; 1* hardware botch*1
El037
8038
*
set
*I
UP minor NKLII on to address from DLBASE 8087
8088 }
ttyinputCc, tp);

B039 addr = KLADDR t B*dev.d_minorf 8089 1* -------------------------


8040 if(dev.d_minor) 8090 klssttyCdev, v)
8041 addr =t KLBASE-KLADDR-B; 8091 int *v;
El042 if(dev.d_minor )== NKLll) 8092 { resister struct tty *tp;
8043 addr =t DLBASE-KLBASE-B*NKL11t8f 8093 tp = &kll1[dev.d_minorJ~
El044 tp-)t_addr ~ addr; 8094 ttusttw(tp< v),
8045 if «tp-)t_state&ISOPEN) == 0) { 8095 }
8046 tp-)t_state ISOPENICARR_ON5 8096 1* ------------------------- *1
B047 tp-)t_flass == XTABSILCASEIECHO/CRMODf 8097
El048 tp-)t_erase = CERASE; 8098
El049 tp-)t_kill == CKILL; 8099

Reproduced under licence from the Western Electric Company, NY Reproduced under licence from the Western Electric COffiPany, NY
Copyrisht, J. Lions. 1976 Copyright, J. Lions, 1976

Sheet 80 Sheet 80
Hay 26 15:25 1976 unix/tty,c Page 1 Hay 26 15:25 1976 unix/tty.c Page 2

8100 t 1* general TTY subroutines *1 8150 1* structure of device registers for KL, DL, and DC
8151 *
interfaces-- more particularly, those for which the
8:101
8102 tinclude ",./param,h" 8152 *
SSTART bit is off and can be treated by general routines
8103 tinclude ',./sYstm.h' 8153 *
(that is, not DH).
8104 tinclude ""/user,h" 8154 *1
8105 tinclude ',./tty.h' 8155 str'Jct {
8106 tinclude ' •• /proc.h' 8156 int ttrcsr;
8107 tinclude ' •• /inode.h' 8157 int ttrbufl
8108 iinclude '.,/file.h' 8158 int tttcsr;
8109 iinclude ".,/reg.h' 8159 int tttbufl
8110 tinclude " •• /conf.h' 8160 H
8111 8161 1* ------------------------- *1
8112 1* Input mapping table-- if an entry is non-zero, when the 8162 1* The routine implementing the gtty system call.
8:113 *
corresponding character is typed preceded by ' \ ' the 8163 *Just call lower level routine and pass back values.
8114 * escape seauence is replaced by the table value. 8164 *1
8115 * Mostly used for upper-case only terminals. 8165 gtty()
8116 *1 8166 (
8117 char maptab[J 8167 int v[3J;
8118 { 8168 register *up, *vp;
8:11 '7 000,000,000,000,004,000,000.000, 8169
8120 000,000,000.000,000,000,000,000, 8170 vp = v;
8121 000,000,000,000,000,000,000,000, 8171 sgtty(vp)'
8122 000,000,000,000,000,000,000,000, 8172 if (u.u_error)
8:123 000,': '.OOO,'t',OOO,OOO,OOO,"', 8173 return;
8124 '{','}',OOO,OOO,OOO,OOO,OOO,OOO. 8174 UP = u,'J_arg[OJ.
8125 000,000,000,000,000,000,000,000, 8175 suword(up, *vp++l;
8:126 000,000,000,000,000,000,000,000, 8176 suword(++up, *vp++l;
8127 '@',OOO,OOO,OOO,OOO,OOO,OOO,OOO. 8177 suword(++up, *vp++);
iH28 000,000,000,000,000,000,000,000, 8178 }
812'7 000,000,000,000,000,000,000,000, 8179 1* ------------------------- *1
8:130 OOO,OOO,OOO,OOO,OOO,OOO,'N',OOO. 8180 1* The routine implementing the stty system call.
8:[;31 OOO,'A','B','C','D','E','F','G', 8181 * Read in values and call lower level.
8132 .fH.I,'I','J',I"K',.IL',.IM','N','OJ', 8182 *1
8133 'P','Q','R','S/,'T','U','V','W', 8183 stty()
8134 'X','Y','Z',OOO,OOO,OOO,OOO,OOO, 8184 (

8135 H 8185
El:L36 1* ------------------------- *1 8186
8137 1* The actual structure of a clist block manipulated by 8187 'JP = u.u_arg[OJ,
::l:l38 * getc and putc (mch.s) 8188 u.u_arg[OJ fuword(up)'
8139 *1 8189 u.u_arg[lJ fuword(++up);
8140 struct cblock { 8190 u.u_arg[2J fuword(++up)'
8141 struct cblock *c_next; 819:1 sgtty(O).
8142 char info[6J' 8192 }
8143 H 8193 1*
::1144 1* ------------------------- *1 8194 n Stuff common to stty and gtty.
::1145 '* The character lists-- space for 6*NCLIST characters *1
struct cblock cfree[NCLISTJ;
8195
8196 * Check legality and switch out to individual
device routine.
8146
8197 * v is 0 for stty; the parameters are taken from u.u_argCJ.
8147
::1148 1* List head for unused character blocks. *1 8198 * c is non-zero for gtty and is the place in which the
8:l4'7 struct cblock *cfreelist. 8199 ** device routines place their information.

Reproduced under licence from the Western Electric Company, NY Reproduced under licence from the Western Electric Company, NY
Copyright, J. Lions. 1976 Copyright, J. Lions, 1976

Sheet 81 Sheet 81
May 26 15:25 1976 unix/tty.c Pa~e 3 May 26 15:25 1976 unix/tty.c Pa~e 4

8200 *1 8250 1* flush all TTY Queues


8201 sstty(v) 8251 *1
8202 int Iv; 8252 flushttY(atp)
8203 { 8253 struct tty *atp;
8204 resister struct file *fp; 8254 {
8205 resister struct inode lip; 8255 resister struct tty *tp;
8206 if CCfp = ~etf(u.u_arO[RO]» NULL) 8256 resister int sps;
8207 return; 8257 tp = atp;
8208 ip = fp-)f_inode; 8258 while (setc(&tp-)t_cana) )= 0);
8209 if «ip-)i_mode&IFMT) != IFCHR) { 8259 while (setc(&tp-)t_outa) )= 0);
8210 u.u_error = ENOTTY; 8260 wakeup(&tp-)t_rawa);
8211 return; 8261 wakeup(&tp-)t_outa);
8212 } 8262 sps = PS-)inte~;
8213 (*cdevswCip-)i_addrCOJ.d_maJorJ.d_sstty) (ip-)i_addrCOJ ,v);8263 sp15();
8214} 8264 while (setc(&tp-)t_rawa) )= 0);
8215 1* ------------------------- *1 8265 tp->t_delct = 0;
8216 1* Wait for outPIJt to drain, then flush input waitirtS. *1 8266 PS-)intes = sPs;
8217 wflushttY(atp) 8267 }
8218 struct tty *atp; 8268 1* ------------------------- *1
8219 { 8269 1* transfer raw input list to canonical list,
8220 resister struct tty *tp; 8270 * doins erase-kill processins and handlins escapes.
8221
8222
tp = atp;
sp15();
8271
8272
** It waits until a full line has been typed in cooked mode,
or until any character has been typed in raw mode.
8223 while (tp-)t_outa.c_cc) { 8273 *1
8224 tp-)t_state =1 ASLEEP; 8274 canon(atp)
8225 sleep(&tp-)t_outa, TTOPRI); 8275 struct tty *atp;
8226 } 8276 {
8227 flushtty(tp); 8277 resister char *bp;
8228 sp 1 0 ( ); 8278 cha r *bp H
8229 } 8279 resister struct tty *tp;
8230 1* ------------------------- *1 8280 resister int c;
8231 1* Initialize clist by freeins all character blocks, & count 8281
8232 * number of character devices. (Once-only routine) 8282 tp = atp;
8233 *1 8283 sp15();
8234 cinit() 8284 while (tp-)t_delct==O) {
8235 { 8285 if «tp-)t_state&CARR_ON)==O)
El236 resister int ccp; 8286 return(O);
8237 resister struct cblock *cp; 8287 sleep(&tp-)t_rawG, TTIPRI);
8238 resister struct cdevsw *cdp; 8288 }
8239 ccp = cfree; 8289 splO();
8240 for (cp=(ccp+07)&H07; cp (= &cfree[NCLIST-l]; cp++) { 8290 loop:
8241 cp-)c_next = cfreelist; 8291 bp = &canonbC2];
8242 cfreelist = cp; 8292 while «c=setc(&tp-)t_rawa» )= 0) {
8243 } 8293 if (c==0377) {
8244 ccp 0; 8294 tp-)t_delct--j
8245 for(cdp cdevsw; cdp->d_open; cdp++) 8295 break;
8246 ccp++; 8296 }
8247 nchrdev = ccp; 8297 if «tp-)t_flass&RAW)==O) {
8248 } 8298 if (bp[-i] !='\\') {
8249 1* ------------------------- *1 8299 if (c==tp-)t_eras~) {

Reproduced under licence from the Western Electric Company, NY Reproduced under licence from the Western Electric Company, NY
CoPYrisht, J. Lions, 1976 CoPYri~ht, J. Lions, 1976

Sheet 82 Sheet 82
Ma~ 26 15:25 1976 unix/ttv.c PaSe 5 Ma~ 26 15:25 1976 unix/tt~.c PaSe 6

8300 if (bp > &canonb[2]) 8350 flushtt~(tp);


8301 bp--; 8351 return;
8302 continue. 8352 }
8303 } 8353 if (t_flags&LCASE && c)='A' && c<='Z')
~L:;04 if (c==tp-)t_killl 8354 c =+ 'a'-fA';
::l305 soto loop, 8355 putcCc, &tp-)t_rawa);
:,1;306 if (c==CEOT) 8356 if (t._flass&RAW :: c=='\n' :: c==004) -(
::l307 continl..le; 8357 wakeup(&tp-)t_rawa);
~13()B ) else 8358 if (putc(0377, &tp-)t_rawa)==O)
~U09 if (maptab[c] 1& (maptab[c]==c :: (tp-)t_flaSs&LCASE») -{ 8359 tp--)t_de lctt+;
::1310 if (bc' [--2 J ! =, ' \ \ ' ) 8360 }
::1;~11 c '" maptabCc]; 8361 if (t._flaSs&ECHO) -(
fl312 8362 ttwoutput(c, tp);
fl313 } 8363 ttstartCtp) ;
::1314 }- 8364 }-
::1315 *bptt c; 8365 }
::I3U, if (bp)=canonbtCANBSIZ) 8366 1* ------------------------- *1
8367 /* put character on TTY output aueue, addins delaws,
ma7 breald
8318 }- 8368 * expanding tabs, and handling the CR/NL bit.
fl319 bpi " bpi 8369 * It is called both from the top half for output, and from
~13:~() bp = Icanonb[2Ji 8370 *
interrupt level for echoing.
a;321 c = &tp-)t_cana; 8371 * The arguments are the character and the ttw structure.
~1322 whil.e (bp<bp1)
putc (*bptt, c),
8372 *1
8373 ttwoutput(ac, tp)
8323
El;324 return(1); 8374 struct tt~ *tp;
8325 }- 8375 -{
i:l326 /* ------------------------- *1 8376 resister int c;
E13:~? /1 Pl.ace a character on raw TTY input aueue, putting in 8377 resister struct ttw *rtp;
::1328 I delimiters and waking UP top half as needed. 8378 resister char *colp,
~1329
~1~BO
*
Also echo if reauired.
* The arguments are the character and the appropriate
8379
8380
int ct!oJpe,

tl331
f.1332 */
*
tt~ structure. 8381
8382
rtp = t,p;
c = ac&OiT;;
::1:333 tt~input(ac, atp) 83K1 1*Ignore EOT in normal mode to avoid hang inS UP
fl;334 struct tt~ latp, 8384 I certain terminals.
8335 -{ 8385 *I
tl~336 resister int t_flass, c, 8386 if (c==004 && (rtp-)t_flaSs&RAW)==O)
tl33? register struct ttw *tp; 8387 return,
83~'i8 8388 1*Turn tabs to spaces as reauired
El3:W tp = atp, 8389 *I
• ::1340 c :::: ac~ 8390 if Cc=='\t' && rtp-)t_flags&XTABS) -(
El341 t_flaSs = tp-)t_flaSs, 8391 do
8342 if «c =& (177) == '\r' &1 t_flags&CRMOD) 8392 ttwoutput C' " rtp);
::1343 c =:: i\ni; El393 while (rtp-)t_col&07);
:,1344 if' «t_fla!~sIRAW)""=O && (c==CQUIT :: c==CINTR» -{ 8394 return.
::1345 siSnalCtp, c==CINTR? SIGINT:SIGQIT); 8395 }-
El346 flushttw(tp), 8396 /* for upper-case-onl~ terminals,
::1347 return; 8397 * generate escapes.
El348 }- 8398 */
tl349 if (tp-)t_rawa.c_cc)=TTYHOG) -{ 8399 if (rtp-)t_flass&LCASE) -{

Reproduced under licence from the Western Electric Companw, NY Reproduced under licence from the Western Electric Companw, NY
Copwrisht, J. Lions, 1976 Cop~right. J. Lions, 1976

Sheet 83
May 26 15:25 1976 unix/tty.c PaSe 7 May 26 15:25 1976 unix/tty.c PaSe 8

8400 coll~ == .({)}!/~H"'; 8450 1* tab *1


8401 while(*colp++) 8451 case 4:
8402 if(c ==== *colp++) { 8452 ct!:lpe = (rtp->t_flaSs » 10) & 03;
El403 ttyoutput('\\', rtp); 8453 if(ctype == 1) { 1* tty 37 *1
El404 c == colp[-2J; 8454 c == 1 - (*colp : H07);
El40~j break; 8455 if(c < 5)
8406 } 8456 c o.
El407 if ('a'<=c && c<='z') 8457 }
El408 c =+ ' A' - , a ' ; 8458 *colp =/ 07;
El409 } 8459 (*colpHH
8410 1* turn <nl) to <cr)<lf) if desired. 8460 breald
8411 *! 8461 1* vertical motion *1
El412 if (c=='\n' && rtp-)t_flaSs&CRMOD) 8462 case 5:
8413 ttYOutput('\r', rtp); 8463 if(rtp->t_flaSs & VTDELAY) 1* tty 37 *1
8414 if (putc(c, &rtp-)t_outa» 8464 c = 0177;
8415 return; 8465 break;
E!416 1* Calculate delay,s. 8466 1* carriaSe return *1
8417 * The, nUlllbers he';'el'epresent clock ticks 8467 case 6:
E/418 *- an'd al'e not.,OE?'c-es-saril!:l optimal for all termirlals. 8468 ctype = (rtp->t_flaSs » 12) & 03;
::14:[ 'i' * ThEi! delays a're"indicated b!:l'characters above 0200, 8469 if(ct!:lpe == 1) { 1* tn 300 *1
El420 * t,hl,is (IJnfortunately) restrictins the transmission 8470 c = 5;
El421 * path to 7 bits. 8471 } else
::1422 *! 8472 if(ctype === 2) { 1* ti 700 *1
El423 colp == &rtp-)t_col; 8473 c = 10;
El424 ctype == partabtcJ; 8474 }
tl425 c == 0, 8475 0;
8426 switch (ctype&077) { 8476 }
El427 1* ordinary *1 8477 if(c)
El428 case 0: 8478
8429 (*colp)+H 8479 }
8430 1* non-printinS *1 8480 1* ------------------------- *1
8431 case 1: 8481 1* Restart typewriter output followinS a delay
El432 break; 8482 * timeout.
El433 1* backspace *1 8483 * The name of the routine is passed to the timeout
El434 case 2: 8484 * subroutine and it is called durins a clock interrupt.
8435 if (*colp) 8485 *1
8436 (*colp)--; 8486 ttrstrt(atp)
El437 break; 8487 {
8438 1* newline *1 8488 resister struct tty *tp;
8439 case 3: 8489
El440 ctype = (rtp-)t_flaSs » 8) & 03; 8490 tp = atp;
tl441 if(ctype == 1) { 1* tty 37 *1 8491 tp-)t_state =& HTIMEOUT;
8442 if (*colp) 8492 ttstart(tp);
E/443 c = max«*colp»4) + 3, 6); 8493 }
8444 } else 8494 1* ------------------------- *1
8445 if(ctype 2) { 1* vt05 *1 8495 1* Start output on the typewriter. It is used from the top •
8446 c = 6; 8496 half after some characters have been put on the output
8447 } 8497 ** aueue, from the interrupt routine to transmit the next
8448 *colp 0, 8498 character. and after a timeout has finished.
8449 break; 8499 * If the SSTART bit is off for the tty the work is done
*
Reproduc.ed under licence from the Western Electric Compan!:l, NY Reproduced under licence from the Western Electric Company, NY
Copyrisht, J. Lions, 1976 CopyriSht, J. Lions, 1976

Sheet 84 Sheet 84
Ma~ 26 15:25 1976 unix/ttw.c Page 9 May 26 15:25 1976 unix/tty.c Page 10

8500 * here, using the protocol of the single-line interfaces 8550 ttwrite(atp)
1
:,1~50 * (kI, dl, dc); otherwise the address word of the tty 8551 struct tty *atp;
a~j02 * structure taken to be
1S the name of the device-dependent 8552 (
::1503 * start-up routine. 8553 register struct tty *tp;
tl504 *1 8554 l'egister int c;
8~:;05 ttstart(atp) 8555 tp = atp;
:,1506 struct tt~ *atp; 8556 if (Ctp-)t_stateICARR_ON)==O)
:,1507 { 8557 return;
:3508 register int taddr, ci 8558 while CCc=cpassC»)=O) (
8::;09 register struct tty *tp; 8559 spl5CH
:,l~:; 1. 0 struct ( int Ctfunc)C); }; 8560 while ctp-)t_outG.c_cc ) TTHIWAT) (
:,l~511 8561 ttstartCtp);
~1~512 tp = atp; 8562 tp-)t_state =: ASLEEP,
:,l~)13 addr = tp-)t_addr; 8563 sIeepCltp-)t_outG, TTOPRI);
a~5:l4 if (tp-)t_stateISSTART) ( 8564 }
8~515 C*addr.func)(tp); 8565 spIO();
::I5:l6 return; 8566 ttYoutputCc, tp);
::l~51"7 } 8567 }-
::I5:L8 if CCaddr-)tttcsrIDONE)==O :: tp-)t_state&TIMEOUT) 8568 ttstartCtp);
:,l~5
.l9 return; 8569
8520 if CCc=SetcCltp-)t_outG» )= 0) ( 8570
::I~52J. if Cc<=0177) 8571 Common code for gtty and stty functions on tspewriters.
::J!522 addr-)tttbuf = c (partab[c]&0200); 8572 If v is non-zero then gtty is beins done and information
:,152:~ else ( 8573 * is passed back therein,
::J!524 timeoutCttrstrt, tp, cI0177); *
8!:'i74 if it is zero stts is being done and the input inform-
tp-)t_state =: TIMEOUT, 8575 * ation is in the u_arg arra~.
} 8576 *1
::1527 } 8577 ttsstts(atp, av)
::I~528 } 8578 int *atp, *av;
::1529 1* ------------------------- *1 8579 -(
::1530 1* Called from device's read routine after it has 8580 register *tp, *v;
8531 * calculated the ttY-structure given as argument. 8581 tp == atp;
8532 * The pc is backed UP for the duration of this call. 8582 ifCv == av) (
::1533 * In case of a caught interrupt, an RTI will re-execute. 8583 *v++ == tp-)t_speeds;
::l~534 *1 8584 v-)lobste = tp-)t_erase;
:::J5:3~5 ttl-eadCatp) 8585 v-)hibste == tp-)t_killl
8536 struct ttw *atp; 8586 vel] == tp-)t_flagsl
~1~537 { 8587 l'f?tlJ rn CI ) ;
8~538 register struct tts *tp; 8588 }
~1~53'1 8589 wflushtts ctp)'
• 8!:;40 tp = atp, 8590 v == IJ.IJ_arg'
8541 if (ctp-)t_stateICARR_ON)==O) 85'11 tp-)t_speeds = *v+tl
::J!542 retu rro' 8592 tp-)t_erase = v-)lobyte;
:,l~j4~1 if Ctp-)t_caroG. c_cc :: canon (h» ) 8593 tp-)t_kill == v-)hibste;
• 8~544 while (tp-)t_canG.c_cc II passcC~etcC&tp-)t_canG»)=O); 8594 tp-)t_flags = v[l],
::1~54~5 } 8595 return(O);
8546 1* ------------------------- *1 8596 }-
El~547 1* Called from the device's write routine after it has 8597 1*
:,1548 * calculated the tts-structure given as argument. 8598
::1:54'1 *l 8~'599

Reproduced under licence from the Western Electric Company, NY Reproduced under licence from the Western Electric Compans, NY
Copsriaht, J. Lions, 1976 CoPYright, J. Lions, 1976

:3hf-"et 85 Sheet 85
Maw 26 15:25 1976 unix/pc.c Pase 1 Maw 26 15:25 1976 unix/pc.c PaSe 2

8600 '1= 8650 extern Ibolt;


:,l601 1* PC'-11 Paper tape reader/punch driver *I 8651
El602
8603
El604
..
tinclude •• /param.h u
tincllJde •• /conf.h"
8652
8653
8654
if (flaS==O) {
if (pcl1.pcstate!=CLOSED) {
u.u_error = ENXIO;
8605 tinclude " •• /user.h" 8655 return;
El606 8656 }
El607 idefine PCADDR 0177550 8657 pcl1.pcstate = WAITING;
8608 8658 while(pcll.pcstate==WAITING) { •
El.s09 tdefine CLOSED 0 8659 PCADDR-)pcrcsr = IENABLElRDRENB;
El610 tdefine WAITING 1 8660 sleep(&lbolt, PCIPRI);
8611 1i=define READING 2 8661 }
El612 idefine EOF 3 8662 } else {
El613 8663 PCADDR-)pcpcsr =l IENABLE;
El614 idefine RDRENB 01 8664 pcleader();
8615 idefine IENABLE 0100 8665 }
8616 tdefine DONE 0200 8666 }
El617 idefine BUSY 04000 8667 1*
8618 tdefirle ERROR 0100000 8668
El619 8669 pcclose(dev, flaS)
8620 "'define PCIPRI 30 8670 {
8621 idefine PCOPRI 40 8671 if (flaS==O) {
8(>22 idefine PCOLWAT 50 8672 sp14();
8623 idefine PCOHWAT 100 8673 while (setc(&pcll.pcin) )= 0);
8624 idefine PCIHWAT 250 8674 PCADDR-)pcrcsr = 0;
Elb25 8675 pcl1.pcstate = CLOSED;
Ell,26 struct { 8676 sp10();
8627 int pcrcsr; 8677 } else
Elb28 int pcrbuf; 8678 pc1eader();
El629 int pcpcsr; 8679 }
8630 int pcpbuf; 8680 1*
8631 H 8681
8632 1* ------------------------- *1 8682 pcread( )
86:-13 8683 {
8634 struct clist { 8684 resister int c;
8l.35 int cc; 8685
8636 int cf; 8686 sp 14 ( ) ;
8637 int cH 8687 do {
8638 H 8688 while «c = Setc(&pcll.pcin» < 0) {
8639 1* ------------------------- *1 8689 if (pcl1.pcstate==EOF)
8640 8690 soto out;
8641 struct pcl1 { 8691 if «PCADDR-)pcrcsr&(ERRORlBUSYlDONE»==O)
8642 int pcstate; 8692 PCADDR-)pcrcsr =l IENABLElRDRENB;
8643 strlJct clist pcin; 8693 sleep(&pcl1.pcin, PCIPRI);
8644 struct clist pcout; 8694 }
8645 } pclt; 8695 } while (PBSSC(C»=O); •
8646 1* ------------------------- *1 8696 out:
8647 • 8697 spIO();
8648 pcopen(dev, flaS) 8698 }
8649 { 8699 1*

Reproduced under licence from the Western Electric Companw. NY Reproduced under licence from the Western Electric Companw, NY
Copwrisht. J •. Lions. 1976 CopwriSht, J. Lions, 1976

Sheet 86 Sheet 86
Ma~ 26 15:25 1976 unix/pc.c Page 3 Ma~ 26 15:25 1976 unix/pc.c Page 4

8700 8750 if (PCADDR-)pcpcsr&ERROR) {


a701 pcwrite() 8751 u.u_error = EIO;
:3702 { 8752
8703 register int c; 8753 }
8704 8754 if (pcl1.pcout.cc )= PCOHWAT)
:3705 while «c=cpass(»)=O) 8755 sleepC&pcl1.pcout, PCOPRI);
8706 pcoutput(c); 8756 putc(c, &pcll.pcout);
• 8707 } 8757 spI4C);
pcstart();
8708 1* ------------------------- 8758
8709 8759 splOC);
8710 pcstart() 8760 }
~1711 { 8761 1* ------------------------- *1
8'712 8762
8'713 8763 pcleader()
8'714 if (PCADDR-)pcpcsr&DONE && (c getcC&pcll.pcout» )= 0) 8764 {
8715 PCADDR-)pcpbuf = c; 8765 register int i;
8'716 } 8766
8717 1* ------------------------- *1 8767 i = 100;
~1718 8768 do
~r719 pcrint() 8769 PCOI.JtPI.Jt (0) ;
8720 { 8770 while (--i);
8721 if (pcl1.pcstate==WAITING) { 8771 }
8-;'22 if (PCADDR-)pcrcsr&ERROR) 8772 1*
8723 return; 8773
:,1"724 pcl1.pcstate = READING; 8774
8725 } 8775
EI726 if (pcl1.pcstate==READING) { 8776
8727 if (PCADDR-)pcrcsr&ERROR) 8777
8728 pcll.pcstate = EOF. 8778
EI729 else { 8779
8730 Putc(PCADDR-)pcrbuf, &pcll.pcin); 8780
EI'731 if (pcl1.pcin.cc < PCIHWAT) 8781
8732 PCADDR-)pcrcsr =: IENABLE:RDRENB; 8782
8733 } 8783
8'734 wakeup(&pc11.?cin)' 8784
EI735 } 8785
8736 } 8786
8737 1* ------------------------- 8787
8788
8738
8739 pcpint() 8789
• 8740 { 8790
8791
8741
8742 pcstart() ; 8792
8743 if (pcll.pcout.cc <= PCOLWAT) 8793
" 8744
8745 }
wakeup(&pc11.pcout); 8794
8795
8746 I I ------------------------- 8796
8747 8797
8748 pcoutput(c) 8798
8749 { 8799

Reproduced under licence from the Western Electric Compan~, NY Reproduced under licence from the Western Electric Company, NY
Cop~right. J. Lions. 1976 CoPYright, J. Lions, 1976

Sheet 87 Sheet 87
May 26 15125 1976 unix/lp.c PaSe 1 May 26 15125 1976 unix/lp.c PaSe 2

8800 t 8850 IpopenCdev, flaS)


EI801 1* 8851 {
8802 *1 8852
8853 if(lpl1.flaS & OPEN:: LPADDR-)lpsr < 0) {
8803
8804
8805
1* LP-11 Line printer driver
8854
8855
u.u_error
return;
EIO;

8a06 *
*1 8856
8857
}
Ipll,flaS =: (INDIEJECTIOPEN);
sa07
8808
aa09 .
tinclude " •• /param.h"
tinclude •• /conf.h"
tinclude " •• /user.h"
8858
8859
8860 }
LPADDR-)lpsr =: IENABLE;
Ipcanon(FORM);

a810
8811
LPADDR 0177514
8861
8862
1* ------------------------- *1
8812 tdefine
8813 8863 IpcloseCdev, flaS)
a814 tdefine IENABLE 0100 8864 {
8815 tdefine DONE 0200 8865 Ipcanon(FORM);
8816 8866 Ipl1.flaS = 0;
8EI17 tr.;lefine LF'PRI 10 8867 }
8a18
8a19
tdefine
tdefine
LPLWAT
LPHWAT
50
100
8868
8869
1* ------------------------- *1
8820 tdefirie EJLINE 60 8870 lpwri te ( )
E1E121 tdefine MAXCOL 80 8871 {
El822 8872 reSister int c;
8823 strlJct { 8873
8824 int lpsr; 8874 while «c=cpassC»)=O)
8825 int IpblJf; 8875 Ipcanon(c);
8826 H 8876 )-
81327 1* ------------------------- *1 8877
8878
1* ------------------------- *1
88213
8829 strlJct { 8879 Ipcanon(c)
8830 int cc; 8880 {
8831 int cf; 8881 reSister c1, c2;
8832 int cU 8882
8833 int flaS; 8883 c1 == c;
8834 int mcc; 8884 ifClp11.flaS&CAP) {
8835 int 8885 ifCc1)='a' && cl<='z')
8836 int 8886 c 1 =t ' A' - , a ' ; else
8837 } Ipll; 8887 switchCci) {
8838 1* ------------------------- *1 8888
8839 8889 case '{':
8840 tdefine CAP 01 1* Set to 0 for 96-char printer, 8890 c2 '(';
8841 else to 01 *1 8891 goto esc; •
8842 tdefine EJECT 02 8892
8843 idefine OPEN 04 8893 case '}.f :
8844 tdefine IND 010 1* Set to 0 for no indent, 8894 c2 / ) ;/;
8845 else to 010 *1 8895 Soto esc; •
8846 8896
8847 idefine FORM 014 8897 case \ , :
;/

8El48 8898 c2 " \ ;/ I ;

8849 8899 soto esc;

Reproduced under licence from the Western Electric Company, NY Reproduced under licence from the Western Electric Company, NY
·CopyriSht, J. Lions, 1976 CopyriSht, J. Lions, 1976

Sheet 88 Sheet 88
May 26 15:25 1976 unix/lp.c Page 3 May 26 15:25 1976 unix/lp.c PaSe 4

8900
:3901
::I';'()2
case "

c2
,
I ,.

~
.
~

I .. ;
8950
8951
8952
if(lpl1.ccc < Ip11.mcc) -(
IpolJtplJt('\r');
Ipl1.mcc = 0;
::1';>03 £lata esc, 8953 }
ifClpl1.ccc < MAXCOLI {
::1904
::1905 case " +N ~
.
...... , ,
8954
8955 while(lp11.ccc ) Ipl1.mcc) -{
, ::1906
::1907
c2 /.. 8956
8957
IpolJtput C' 'i;
Ipl1.l1lcc+·H
:390B esc: 8958 }
::!909 Ipcanon(c2); 8959 IpOlJtpl.Jt C(1) ;
as':lO Ipl1. ccc-·_' 8960 Ipll.mcc·H;
::IS'1:L cl = "_/; 8961 }
::IS'I::! } 8962 Ipl1.ccc++i
89:13 } 8963 }
::1914 8964 }
fl915
fl9:l6
sw itch ( c1) -( 8965 1* ------------------------- 1/
8966
as'17 case ' \ t' : 8967 Ipstal't<)
fl9:lB lpll.eec (lpll.eect8) & N7; 8968 -{
::IS':l 9 return, 8969 l'esistel' int c;
::1920 8970
:3921 ease FORM: 8971 while (LPADDR-)lpsrIDONE II (e setc(llpl1»?= 0)
tl922 case :\n": 8972 LPADDR-)lpblJf = c;
::1923 if«lpl1.flasIEJECT) == 0 :: 8973 }
::1924 Ipl:l.mcc!=O :: Ipl1.mlc!=0) { 8974 II ------------------------- 1/
:392~) Ipl1.mcc = O. 8975
~1926 Ipl1.mlc+·H 8976 lpint()
fln7 if(lp11.mlc )= EJLINE II Ip11.flasIEJECT) 8977 (
:39213 c1 " FOf(M; 8978 l'esistel' int c;
:3929 Ipoutput(cl); 8979
::1930 if(c! == FORM) 8980 lpstsl't();
::1';>31 Ipl1.mlc 0; 8981 if (lpl1.cc == LPLWAT :: Ipl1.cc 0)
::J9~52 } 8982 wakeup(llpl1);
a9~53 8983 }
::1934 case i \T' I :
8984 II ------------------------- II
::193~:; Ipl1.ccc = 0; 8985
~19:-I6 if(lp11.flasIIND) 8986 lpoutput(c)
::19~57 Ipl1.ccc = 8; 8987 {
::l9~3B return; 8988 if (lpl1.cc ?= LPHWAT)
89:-19 8989 sleep(llp11. LPPRI);
fl940 case 010: 8990 putc(c, Ilpl1);
894l if(lpl:L.cec ) 0) 8991 sp14();
::1'i'42 l.pl1.eec---; 8992 IF··stal't().
894~5 return, 8993 spIO();
• 8944
:3 ~)45 case " "!
8994
8995
}
/I
::1946 Ipl1.ccc++' 8996
fl947 l'eturn; 8997
::1948 8998
::1949 default; 8999

Reproduced undel' licence from the Western Electric Compans, NY Repl'oduced under licence fl'om the Western Electric Compans, NY
COPsl'isht. J. Lions, 1976 COPYl'isht, J. Lions. 1976

Sheet 89
Maw 26 15:25 1976 unix/mem.c Pa~e 1 Maw 26 15:25 1976 unix/mem.c Pa~e 2

9000 i 9050 IJ. u_base =t c;


900:l 1* 9051 dpadd(u.u_offset, c);
9002 *l 9052 return;
9003 9053 }
9004 /* 9054 for(;;) (
';'005
9006
** lfiinor
Memorw special
device 0
file
is ph~sical memors
9055
9056
bn = IshiftCu.u_offset, -6);
on .. u.u_offset[l] & 077.
9007 * minor device 1 is kernel memorw 9057 if CCc=cpassC»<O :: u.IJ_error!=O) ,
9008 * minor device 2 is EOF/RATHOLE 9058 break;
9009 *1 9059 a .. UISA->r[O];
9010 9060 d .. UIS[I->r[O];
90ii iinclude " •• /param.h" 9061 sF-17 C) •
9012 iinclude " •• /user.h" 9062 UISA->r[OJ .. bn; •
90:L :3 iinclude R • • /conf.h" 9063 UIS[I->r[OJ = 077406;
9014 iinclude • •• /se~.h· 9064 if(dev.d_minor == 1)
9015 9065 UISA->r[OJ (ka6-6)->r[Cbn»7)&07J
';101.6 mmread(dev) 9066 t (bn & 0177);
9017 { 9067 slJibwteCon, c);
901B re~ister c, bn, on; 9068 UISA->r[OJ a;
9019 int a, d; 9069 UIS[I->r[OJ .. d;
9020 9070 spIO() ;
'7021 9071 }
9022 return; 9072 }
9023 do ( 9073 /* *l
9024 bn = lshift(u.u_offset, -6); 9074
on = u.u_offsetC1J & 077; 9075
9026 a = UISA->rCOJ; 9076
9027 d = UIS[I->r[OJ; 9077
9028 spI7(); 9078
9029 UISA->r[O] = bn; 9079
9030 UIS[I->r[O] = 077406; 9080
9031 ifCdev.d_minor == 1) 9081
';1032 UISA->r[O] Cka6-6)->r[(bn»7)&07J 9082
90~53 t Cbn & 0177); 9083
9034 c = fuibwteCon); 9084
'7035 UISA->r[OJ a; 9085
9036 UIS[I->r[OJ = d; 9086
'iI037 splOC) ; 9087
9038 } whileCu.u_error==O && passcCc»=O); 9088
9039 )- 9089
9040 1* ------------------------- *1 9090
9041
9042 mmwriteCdev)
9091
9092

9043 -( 9093
9044 re~ister c, bn, on; 9094
9045
9046
int a, d; 9095
9096

9047 ifCdev.d_minor == 2) { 9097
9048 c = u.u_count; 9098
9049 u.u_count = 0; 9099

Reproduced under licence from the Western Electric Cdmpanw, NY Reproduced under licence from the Western Electric Companw, NY
Copwri~ht, J. Lions, 1976 Copwri~ht, J. Lions, 1976

Sheet 90 Sheet 90

You might also like