print user@hostname; filter header lines
[unix-history] / usr / src / sys / kern / subr_xxx.c
CommitLineData
961945a8
SL
1/* subr_xxx.c 4.21 82/12/17 */
2
3#include "../machine/pte.h"
ae9e2121
BJ
4
5#include "../h/param.h"
6#include "../h/systm.h"
7#include "../h/conf.h"
8#include "../h/inode.h"
9#include "../h/dir.h"
10#include "../h/user.h"
11#include "../h/buf.h"
12#include "../h/proc.h"
6459ebe0 13#include "../h/fs.h"
cb99a88a 14#include "../h/vm.h"
cb99a88a 15#include "../h/cmap.h"
d6d7360b 16#include "../h/uio.h"
ae9e2121 17
ae9e2121 18/*
50a84b40 19 * Routine placed in illegal entries in the bdevsw and cdevsw tables.
ae9e2121
BJ
20 */
21nodev()
22{
23
50a84b40 24 return (ENODEV);
ae9e2121
BJ
25}
26
27/*
28 * Null routine; placed in insignificant entries
29 * in the bdevsw and cdevsw tables.
30 */
31nulldev()
32{
33
50a84b40 34 return (0);
ae9e2121
BJ
35}
36
37imin(a, b)
38{
39
40 return (a < b ? a : b);
41}
42
43imax(a, b)
44{
45
46 return (a > b ? a : b);
47}
48
6459ebe0
KM
49unsigned
50min(a, b)
b32450f4 51 u_int a, b;
6459ebe0
KM
52{
53
54 return (a < b ? a : b);
55}
56
57unsigned
58max(a, b)
b32450f4 59 u_int a, b;
6459ebe0
KM
60{
61
62 return (a > b ? a : b);
63}
b32450f4 64
cb99a88a
BJ
65extern cabase, calimit;
66extern struct pte camap[];
67
68caddr_t cacur = (caddr_t)&cabase;
69caddr_t camax = (caddr_t)&cabase;
70int cax = 0;
71/*
72 * This is a kernel-mode storage allocator.
73 * It is very primitive, currently, in that
74 * there is no way to give space back.
75 * It serves, for the time being, the needs of
76 * auto-configuration code and the like which
77 * need to allocate some stuff at boot time.
78 */
79caddr_t
80calloc(size)
81 int size;
82{
83 register caddr_t res;
84 register int i;
85
86 if (cacur+size >= (caddr_t)&calimit)
87 panic("calloc");
88 while (cacur+size > camax) {
89 (void) vmemall(&camap[cax], CLSIZE, &proc[0], CSYS);
90 vmaccess(&camap[cax], camax, CLSIZE);
91 for (i = 0; i < CLSIZE; i++)
92 clearseg(camap[cax++].pg_pfnum);
93 camax += NBPG * CLSIZE;
94 }
95 res = cacur;
96 cacur += size;
97 return (res);
98}
febd1daa 99
cb99a88a
BJ
100#ifndef vax
101ffs(mask)
102 register long mask;
103{
104 register int i;
105
106 for(i=1; i<NSIG; i++) {
107 if (mask & 1)
108 return (i);
109 mask >>= 1;
110 }
111 return (0);
112}
febd1daa 113
febd1daa
BJ
114bcmp(s1, s2, len)
115 register char *s1, *s2;
116 register int len;
117{
118
f49dd739 119 while (len--)
febd1daa
BJ
120 if (*s1++ != *s2++)
121 return (1);
122 return (0);
123}
124
125strlen(s1)
126 register char *s1;
127{
128 register int len;
129
130 for (len = 0; *s1++ != '\0'; len++)
131 /* void */;
132 return (len);
133}
134#endif
d6d7360b 135
d6d7360b
BJ
136/*
137 * Pass back c to the user.
138 */
139passuc(c, uio)
140 register c;
141 struct uio *uio;
142{
143 register struct iovec *iov = uio->uio_iov;
d6d7360b
BJ
144
145 switch (uio->uio_segflg) {
146
147 case 0:
148 if (subyte(iov->iov_base, c) < 0)
149 goto fault;
150 break;
151
152 case 1:
153 *iov->iov_base = c;
154 break;
155
156 case 2:
157 if (suibyte(iov->iov_base, c) < 0)
158 goto fault;
159 break;
160 }
161 iov->iov_base++;
162 iov->iov_len--;
163 uio->uio_resid--;
164 uio->uio_offset++;
165 if (iov->iov_len <= 0) {
166 uio->uio_iov++;
167 uio->uio_iovcnt--;
168 }
169 return (0);
170fault:
171 return (EFAULT);
172}