Commit | Line | Data |
---|---|---|
a1d35437 KM |
1 | /* |
2 | * Copyright (c) 1989 The Regents of the University of California. | |
3 | * All rights reserved. | |
4 | * | |
5 | * Redistribution and use in source and binary forms are permitted | |
6 | * provided that the above copyright notice and this paragraph are | |
7 | * duplicated in all such forms and that any documentation, | |
8 | * advertising materials, and other materials related to such | |
9 | * distribution and use acknowledge that the software was developed | |
10 | * by the University of California, Berkeley. The name of the | |
11 | * University may not be used to endorse or promote products derived | |
12 | * from this software without specific prior written permission. | |
13 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR | |
14 | * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED | |
15 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | |
16 | * | |
d78aeb43 | 17 | * @(#)spec_vnops.c 7.2 (Berkeley) %G% |
a1d35437 KM |
18 | */ |
19 | ||
20 | #include "param.h" | |
21 | #include "systm.h" | |
22 | #include "time.h" | |
23 | #include "conf.h" | |
24 | #include "buf.h" | |
25 | #include "vnode.h" | |
26 | #include "../ufs/inode.h" | |
27 | #include "stat.h" | |
28 | #include "uio.h" | |
29 | #include "errno.h" | |
30 | #include "malloc.h" | |
31 | ||
32 | int blk_open(), | |
33 | blk_access(), | |
34 | blk_read(), | |
35 | blk_write(), | |
36 | blk_strategy(), | |
37 | blk_ioctl(), | |
38 | blk_select(), | |
39 | blk_inactive(), | |
40 | blk_lock(), | |
41 | blk_unlock(), | |
42 | blk_close(), | |
43 | blk_badop(), | |
44 | blk_nullop(); | |
45 | ||
46 | int ufs_getattr(), | |
47 | ufs_setattr(); | |
48 | ||
49 | struct vnodeops blk_vnodeops = { | |
50 | blk_badop, | |
51 | blk_badop, | |
52 | blk_badop, | |
53 | blk_open, | |
54 | blk_close, | |
55 | blk_access, | |
56 | ufs_getattr, | |
57 | ufs_setattr, | |
58 | blk_read, | |
59 | blk_write, | |
60 | blk_ioctl, | |
61 | blk_select, | |
62 | blk_badop, | |
63 | blk_nullop, | |
64 | blk_badop, | |
65 | blk_badop, | |
66 | blk_badop, | |
67 | blk_badop, | |
68 | blk_badop, | |
69 | blk_badop, | |
70 | blk_badop, | |
71 | blk_badop, | |
72 | blk_badop, | |
73 | blk_badop, | |
74 | blk_inactive, | |
75 | blk_lock, | |
76 | blk_unlock, | |
77 | blk_badop, | |
78 | blk_strategy, | |
79 | }; | |
80 | ||
81 | /* | |
82 | * Open called to allow handler | |
83 | * of special files to initialize and | |
84 | * validate before actual IO. | |
85 | */ | |
86 | blk_open(vp, mode, cred) | |
87 | register struct vnode *vp; | |
88 | int mode; | |
89 | struct ucred *cred; | |
90 | { | |
91 | dev_t dev = (dev_t)vp->v_rdev; | |
92 | register int maj = major(dev); | |
93 | ||
94 | switch (vp->v_type) { | |
95 | ||
96 | case VCHR: | |
97 | if ((u_int)maj >= nchrdev) | |
98 | return (ENXIO); | |
99 | return ((*cdevsw[maj].d_open)(dev, mode, S_IFCHR)); | |
100 | ||
101 | case VBLK: | |
102 | if ((u_int)maj >= nblkdev) | |
103 | return (ENXIO); | |
104 | return ((*bdevsw[maj].d_open)(dev, mode, S_IFBLK)); | |
105 | } | |
106 | return (0); | |
107 | } | |
108 | ||
109 | /* | |
110 | * Check access permissions for a block device. | |
111 | */ | |
112 | blk_access(vp, mode, cred) | |
113 | struct vnode *vp; | |
114 | int mode; | |
115 | struct ucred *cred; | |
116 | { | |
117 | register struct inode *ip = VTOI(vp); | |
118 | int error; | |
119 | ||
120 | if ((ip->i_flag & ILOCKED) == 0) | |
121 | printf("access called with %d not locked\n", ip->i_number); | |
122 | error = iaccess(ip, mode, cred); | |
123 | return (error); | |
124 | } | |
125 | ||
126 | /* | |
127 | * Vnode op for read | |
128 | */ | |
129 | blk_read(vp, uio, offp, ioflag, cred) | |
130 | register struct vnode *vp; | |
131 | struct uio *uio; | |
132 | off_t *offp; | |
133 | int ioflag; | |
134 | struct ucred *cred; | |
135 | { | |
136 | register struct inode *ip = VTOI(vp); | |
137 | int count, error; | |
138 | ||
139 | if (vp->v_type == VBLK && ip) | |
140 | ILOCK(ip); | |
141 | uio->uio_offset = *offp; | |
142 | count = uio->uio_resid; | |
143 | error = readblkvp(vp, uio, cred); | |
144 | *offp += count - uio->uio_resid; | |
145 | if (vp->v_type == VBLK && ip) | |
146 | IUNLOCK(ip); | |
147 | return (error); | |
148 | } | |
149 | ||
150 | /* | |
151 | * Vnode op for write | |
152 | */ | |
153 | blk_write(vp, uio, offp, ioflag, cred) | |
154 | register struct vnode *vp; | |
155 | struct uio *uio; | |
156 | off_t *offp; | |
157 | int ioflag; | |
158 | struct ucred *cred; | |
159 | { | |
160 | register struct inode *ip = VTOI(vp); | |
161 | int count, error; | |
162 | ||
163 | if (vp->v_type == VBLK && ip) | |
164 | ILOCK(ip); | |
165 | uio->uio_offset = *offp; | |
166 | count = uio->uio_resid; | |
167 | error = writeblkvp(vp, uio, cred); | |
168 | *offp += count - uio->uio_resid; | |
169 | if (vp->v_type == VBLK && ip) | |
170 | IUNLOCK(ip); | |
171 | return (error); | |
172 | } | |
173 | ||
174 | /* | |
175 | * Device ioctl operation. | |
176 | */ | |
177 | blk_ioctl(vp, com, data, fflag, cred) | |
178 | struct vnode *vp; | |
179 | register int com; | |
180 | caddr_t data; | |
181 | int fflag; | |
182 | struct ucred *cred; | |
183 | { | |
184 | register struct inode *ip = VTOI(vp); | |
185 | dev_t dev = ip->i_rdev; | |
186 | ||
187 | switch (vp->v_type) { | |
188 | ||
189 | case VCHR: | |
190 | return ((*cdevsw[major(dev)].d_ioctl)(dev, com, data, fflag)); | |
191 | ||
192 | case VBLK: | |
193 | return ((*bdevsw[major(dev)].d_ioctl)(dev, com, data, fflag)); | |
194 | ||
195 | default: | |
196 | panic("blk_ioctl"); | |
197 | /* NOTREACHED */ | |
198 | } | |
199 | } | |
200 | ||
201 | blk_select(vp, which, cred) | |
202 | struct vnode *vp; | |
203 | int which; | |
204 | struct ucred *cred; | |
205 | { | |
206 | register struct inode *ip = VTOI(vp); | |
207 | register dev_t dev; | |
208 | ||
209 | switch (vp->v_type) { | |
210 | ||
211 | default: | |
212 | return (1); /* XXX */ | |
213 | ||
214 | case VCHR: | |
215 | dev = ip->i_rdev; | |
216 | return (*cdevsw[major(dev)].d_select)(dev, which); | |
217 | } | |
218 | } | |
219 | ||
220 | /* | |
221 | * Just call the device strategy routine | |
222 | */ | |
223 | blk_strategy(bp) | |
224 | register struct buf *bp; | |
225 | { | |
226 | (*bdevsw[major(bp->b_dev)].d_strategy)(bp); | |
227 | return (0); | |
228 | } | |
229 | ||
230 | blk_lock(vp) | |
231 | struct vnode *vp; | |
232 | { | |
233 | register struct inode *ip = VTOI(vp); | |
234 | ||
235 | if (ip) | |
236 | ILOCK(ip); | |
237 | return (0); | |
238 | } | |
239 | ||
240 | blk_unlock(vp) | |
241 | struct vnode *vp; | |
242 | { | |
243 | register struct inode *ip = VTOI(vp); | |
244 | ||
245 | if (ip) | |
246 | IUNLOCK(ip); | |
247 | return (0); | |
248 | } | |
249 | ||
250 | blk_inactive(vp) | |
251 | struct vnode *vp; | |
252 | { | |
253 | struct inode *ip = VTOI(vp); | |
254 | struct vnode *devvp = 0; | |
255 | int error; | |
256 | ||
257 | if (vp->v_count > 0) | |
258 | return (0); | |
d78aeb43 | 259 | return (irele(ip)); |
a1d35437 KM |
260 | } |
261 | ||
262 | /* | |
263 | * Device close routine | |
264 | */ | |
265 | blk_close(vp, flag, cred) | |
266 | struct vnode *vp; | |
267 | int flag; | |
268 | struct ucred *cred; | |
269 | { | |
270 | dev_t dev = vp->v_rdev; | |
271 | int type = vp->v_type; | |
272 | ||
273 | return (closei(dev, type, flag)); | |
274 | } | |
275 | ||
276 | /* | |
277 | * Block device bad operation | |
278 | */ | |
279 | blk_badop() | |
280 | { | |
281 | ||
282 | printf("blk_badop called\n"); | |
283 | return (ENXIO); | |
284 | } | |
285 | ||
286 | /* | |
287 | * Block device null operation | |
288 | */ | |
289 | blk_nullop() | |
290 | { | |
291 | ||
292 | return (0); | |
293 | } |