Research V5 development
[unix-history] / usr / sys / ken / subr.c
CommitLineData
52509940
KT
1#
2/*
3 * Copyright 1973 Bell Telephone Laboratories Inc
4 */
5
6#include "../param.h"
7#include "../conf.h"
8#include "../inode.h"
9#include "../user.h"
10#include "../buf.h"
11#include "../systm.h"
12
13bmap(ip, bn)
14struct inode *ip;
15int bn;
16{
17 register *bp, *bap, nb;
18 int *nbp, d, i;
19
20 d = ip->i_dev;
21
22 if (bn & ~03777) {
23 u.u_error = EFBIG;
24 return(0);
25 }
26 if((ip->i_mode&ILARG) == 0) {
27
28 /*
29 * small file algorithm
30 */
31
32 if((bn & ~7) != 0) {
33
34 /*
35 * bad part:
36 * convert small to large
37 */
38
39 if ((bp = alloc(d)) == NULL)
40 return(0);
41 bap = bp->b_addr;
42 for(i=0; i<8; i++) {
43 *bap++ = ip->i_addr[i];
44 ip->i_addr[i] = 0;
45 }
46 ip->i_addr[0] = bp->b_blkno;
47 bdwrite(bp);
48 ip->i_mode =| ILARG;
49 goto large;
50 }
51 nb = ip->i_addr[bn];
52 if(nb == 0 && (bp = alloc(d)) != NULL) {
53 bdwrite(bp);
54 nb = bp->b_blkno;
55 ip->i_addr[bn] = nb;
56 ip->i_flag =| IUPD;
57 }
58 if (bn<7)
59 rablock = ip->i_addr[bn+1];
60 else
61 rablock = 0;
62 return(nb);
63 }
64
65 /*
66 * large file algorithm
67 */
68
69 large:
70 i = bn>>8;
71 if((nb=ip->i_addr[i]) == 0) {
72 ip->i_flag =| IUPD;
73 if ((bp = alloc(d)) == NULL)
74 return(0);
75 nb = bp->b_blkno;
76 ip->i_addr[i] = nb;
77 } else
78 bp = bread(d, nb);
79 bap = bp->b_addr;
80 i = bn & 0377;
81 if((nb=bap[i]) == 0 && (nbp = alloc(d)) != NULL) {
82 nb = nbp->b_blkno;
83 bap[i] = nb;
84 bdwrite(nbp);
85 bdwrite(bp);
86 } else
87 brelse(bp);
88 rablock = bap[i+1];
89 return(nb);
90}
91
92passc(c)
93char c;
94{
95
96 if(u.u_segflg)
97 *u.u_base = c; else
98 if(subyte(u.u_base, c) < 0) {
99 u.u_error = EFAULT;
100 return(-1);
101 }
102 u.u_count--;
103 if(++u.u_offset[1] == 0)
104 u.u_offset[0]++;
105 u.u_base++;
106 return(u.u_count == 0? -1: 0);
107}
108
109cpass()
110{
111 register c;
112
113 if(u.u_count == 0)
114 return(-1);
115 if(u.u_segflg)
116 c = *u.u_base; else
117 if((c=fubyte(u.u_base)) < 0) {
118 u.u_error = EFAULT;
119 return(-1);
120 }
121 u.u_count--;
122 if(++u.u_offset[1] == 0)
123 u.u_offset[0]++;
124 u.u_base++;
125 return(c&0377);
126}
127
128nodev()
129{
130
131 u.u_error = ENODEV;
132}
133
134nulldev()
135{
136}
137
138bcopy(from, to, count)
139int *from, *to;
140{
141 register *a, *b, c;
142
143 a = from;
144 b = to;
145 c = count;
146 do
147 *b++ = *a++;
148 while(--c);
149}