advnops.c revision 1.1.2.2 1 1.1.2.2 thorpej /* $NetBSD: advnops.c,v 1.1.2.2 2002/12/29 19:55:29 thorpej Exp $ */
2 1.1.2.2 thorpej
3 1.1.2.2 thorpej /*
4 1.1.2.2 thorpej * Copyright (c) 1994 Christian E. Hopps
5 1.1.2.2 thorpej * Copyright (c) 1996 Matthias Scheler
6 1.1.2.2 thorpej * All rights reserved.
7 1.1.2.2 thorpej *
8 1.1.2.2 thorpej * Redistribution and use in source and binary forms, with or without
9 1.1.2.2 thorpej * modification, are permitted provided that the following conditions
10 1.1.2.2 thorpej * are met:
11 1.1.2.2 thorpej * 1. Redistributions of source code must retain the above copyright
12 1.1.2.2 thorpej * notice, this list of conditions and the following disclaimer.
13 1.1.2.2 thorpej * 2. Redistributions in binary form must reproduce the above copyright
14 1.1.2.2 thorpej * notice, this list of conditions and the following disclaimer in the
15 1.1.2.2 thorpej * documentation and/or other materials provided with the distribution.
16 1.1.2.2 thorpej * 3. All advertising materials mentioning features or use of this software
17 1.1.2.2 thorpej * must display the following acknowledgement:
18 1.1.2.2 thorpej * This product includes software developed by Christian E. Hopps.
19 1.1.2.2 thorpej * 4. The name of the author may not be used to endorse or promote products
20 1.1.2.2 thorpej * derived from this software without specific prior written permission
21 1.1.2.2 thorpej *
22 1.1.2.2 thorpej * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
23 1.1.2.2 thorpej * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
24 1.1.2.2 thorpej * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
25 1.1.2.2 thorpej * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
26 1.1.2.2 thorpej * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
27 1.1.2.2 thorpej * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 1.1.2.2 thorpej * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 1.1.2.2 thorpej * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 1.1.2.2 thorpej * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
31 1.1.2.2 thorpej * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 1.1.2.2 thorpej */
33 1.1.2.2 thorpej
34 1.1.2.2 thorpej #include <sys/cdefs.h>
35 1.1.2.2 thorpej __KERNEL_RCSID(0, "$NetBSD: advnops.c,v 1.1.2.2 2002/12/29 19:55:29 thorpej Exp $");
36 1.1.2.2 thorpej
37 1.1.2.2 thorpej #if defined(_KERNEL_OPT)
38 1.1.2.2 thorpej #include "opt_quota.h"
39 1.1.2.2 thorpej #endif
40 1.1.2.2 thorpej
41 1.1.2.2 thorpej #include <sys/param.h>
42 1.1.2.2 thorpej #include <sys/systm.h>
43 1.1.2.2 thorpej #include <sys/vnode.h>
44 1.1.2.2 thorpej #include <sys/mount.h>
45 1.1.2.2 thorpej #include <sys/time.h>
46 1.1.2.2 thorpej #include <sys/queue.h>
47 1.1.2.2 thorpej #include <sys/namei.h>
48 1.1.2.2 thorpej #include <sys/buf.h>
49 1.1.2.2 thorpej #include <sys/dirent.h>
50 1.1.2.2 thorpej #include <sys/malloc.h>
51 1.1.2.2 thorpej #include <sys/pool.h>
52 1.1.2.2 thorpej #include <sys/stat.h>
53 1.1.2.2 thorpej #include <sys/unistd.h>
54 1.1.2.2 thorpej #include <sys/proc.h>
55 1.1.2.2 thorpej
56 1.1.2.2 thorpej #include <miscfs/genfs/genfs.h>
57 1.1.2.2 thorpej #include <miscfs/specfs/specdev.h>
58 1.1.2.2 thorpej #include <fs/adosfs/adosfs.h>
59 1.1.2.2 thorpej
60 1.1.2.2 thorpej extern struct vnodeops adosfs_vnodeops;
61 1.1.2.2 thorpej
62 1.1.2.2 thorpej #define adosfs_open genfs_nullop
63 1.1.2.2 thorpej int adosfs_getattr __P((void *));
64 1.1.2.2 thorpej int adosfs_read __P((void *));
65 1.1.2.2 thorpej int adosfs_write __P((void *));
66 1.1.2.2 thorpej #define adosfs_fcntl genfs_fcntl
67 1.1.2.2 thorpej #define adosfs_ioctl genfs_enoioctl
68 1.1.2.2 thorpej #define adosfs_poll genfs_poll
69 1.1.2.2 thorpej int adosfs_strategy __P((void *));
70 1.1.2.2 thorpej int adosfs_link __P((void *));
71 1.1.2.2 thorpej int adosfs_symlink __P((void *));
72 1.1.2.2 thorpej #define adosfs_abortop genfs_abortop
73 1.1.2.2 thorpej int adosfs_bmap __P((void *));
74 1.1.2.2 thorpej int adosfs_print __P((void *));
75 1.1.2.2 thorpej int adosfs_readdir __P((void *));
76 1.1.2.2 thorpej int adosfs_access __P((void *));
77 1.1.2.2 thorpej int adosfs_readlink __P((void *));
78 1.1.2.2 thorpej int adosfs_inactive __P((void *));
79 1.1.2.2 thorpej int adosfs_reclaim __P((void *));
80 1.1.2.2 thorpej int adosfs_pathconf __P((void *));
81 1.1.2.2 thorpej
82 1.1.2.2 thorpej #define adosfs_close genfs_nullop
83 1.1.2.2 thorpej #define adosfs_fsync genfs_nullop
84 1.1.2.2 thorpej #define adosfs_lease_check genfs_lease_check
85 1.1.2.2 thorpej #define adosfs_seek genfs_seek
86 1.1.2.2 thorpej #define adosfs_vfree genfs_nullop
87 1.1.2.2 thorpej
88 1.1.2.2 thorpej #define adosfs_advlock genfs_einval
89 1.1.2.2 thorpej #define adosfs_blkatoff genfs_eopnotsupp
90 1.1.2.2 thorpej #define adosfs_bwrite genfs_eopnotsupp
91 1.1.2.2 thorpej #define adosfs_create genfs_eopnotsupp
92 1.1.2.2 thorpej #define adosfs_mkdir genfs_eopnotsupp
93 1.1.2.2 thorpej #define adosfs_mknod genfs_eopnotsupp
94 1.1.2.2 thorpej #define adosfs_revoke genfs_revoke
95 1.1.2.2 thorpej #define adosfs_mmap genfs_mmap
96 1.1.2.2 thorpej #define adosfs_remove genfs_eopnotsupp
97 1.1.2.2 thorpej #define adosfs_rename genfs_eopnotsupp
98 1.1.2.2 thorpej #define adosfs_rmdir genfs_eopnotsupp
99 1.1.2.2 thorpej #define adosfs_setattr genfs_eopnotsupp
100 1.1.2.2 thorpej #define adosfs_truncate genfs_eopnotsupp
101 1.1.2.2 thorpej #define adosfs_update genfs_nullop
102 1.1.2.2 thorpej #define adosfs_valloc genfs_eopnotsupp
103 1.1.2.2 thorpej
104 1.1.2.2 thorpej const struct vnodeopv_entry_desc adosfs_vnodeop_entries[] = {
105 1.1.2.2 thorpej { &vop_default_desc, vn_default_error },
106 1.1.2.2 thorpej { &vop_lookup_desc, adosfs_lookup }, /* lookup */
107 1.1.2.2 thorpej { &vop_create_desc, adosfs_create }, /* create */
108 1.1.2.2 thorpej { &vop_mknod_desc, adosfs_mknod }, /* mknod */
109 1.1.2.2 thorpej { &vop_open_desc, adosfs_open }, /* open */
110 1.1.2.2 thorpej { &vop_close_desc, adosfs_close }, /* close */
111 1.1.2.2 thorpej { &vop_access_desc, adosfs_access }, /* access */
112 1.1.2.2 thorpej { &vop_getattr_desc, adosfs_getattr }, /* getattr */
113 1.1.2.2 thorpej { &vop_setattr_desc, adosfs_setattr }, /* setattr */
114 1.1.2.2 thorpej { &vop_read_desc, adosfs_read }, /* read */
115 1.1.2.2 thorpej { &vop_write_desc, adosfs_write }, /* write */
116 1.1.2.2 thorpej { &vop_lease_desc, adosfs_lease_check }, /* lease */
117 1.1.2.2 thorpej { &vop_fcntl_desc, adosfs_fcntl }, /* fcntl */
118 1.1.2.2 thorpej { &vop_ioctl_desc, adosfs_ioctl }, /* ioctl */
119 1.1.2.2 thorpej { &vop_poll_desc, adosfs_poll }, /* poll */
120 1.1.2.2 thorpej { &vop_kqfilter_desc, genfs_kqfilter }, /* kqfilter */
121 1.1.2.2 thorpej { &vop_revoke_desc, adosfs_revoke }, /* revoke */
122 1.1.2.2 thorpej { &vop_mmap_desc, adosfs_mmap }, /* mmap */
123 1.1.2.2 thorpej { &vop_fsync_desc, adosfs_fsync }, /* fsync */
124 1.1.2.2 thorpej { &vop_seek_desc, adosfs_seek }, /* seek */
125 1.1.2.2 thorpej { &vop_remove_desc, adosfs_remove }, /* remove */
126 1.1.2.2 thorpej { &vop_link_desc, adosfs_link }, /* link */
127 1.1.2.2 thorpej { &vop_rename_desc, adosfs_rename }, /* rename */
128 1.1.2.2 thorpej { &vop_mkdir_desc, adosfs_mkdir }, /* mkdir */
129 1.1.2.2 thorpej { &vop_rmdir_desc, adosfs_rmdir }, /* rmdir */
130 1.1.2.2 thorpej { &vop_symlink_desc, adosfs_symlink }, /* symlink */
131 1.1.2.2 thorpej { &vop_readdir_desc, adosfs_readdir }, /* readdir */
132 1.1.2.2 thorpej { &vop_readlink_desc, adosfs_readlink }, /* readlink */
133 1.1.2.2 thorpej { &vop_abortop_desc, adosfs_abortop }, /* abortop */
134 1.1.2.2 thorpej { &vop_inactive_desc, adosfs_inactive }, /* inactive */
135 1.1.2.2 thorpej { &vop_reclaim_desc, adosfs_reclaim }, /* reclaim */
136 1.1.2.2 thorpej { &vop_lock_desc, genfs_lock }, /* lock */
137 1.1.2.2 thorpej { &vop_unlock_desc, genfs_unlock }, /* unlock */
138 1.1.2.2 thorpej { &vop_bmap_desc, adosfs_bmap }, /* bmap */
139 1.1.2.2 thorpej { &vop_strategy_desc, adosfs_strategy }, /* strategy */
140 1.1.2.2 thorpej { &vop_print_desc, adosfs_print }, /* print */
141 1.1.2.2 thorpej { &vop_islocked_desc, genfs_islocked }, /* islocked */
142 1.1.2.2 thorpej { &vop_pathconf_desc, adosfs_pathconf }, /* pathconf */
143 1.1.2.2 thorpej { &vop_advlock_desc, adosfs_advlock }, /* advlock */
144 1.1.2.2 thorpej { &vop_blkatoff_desc, adosfs_blkatoff }, /* blkatoff */
145 1.1.2.2 thorpej { &vop_valloc_desc, adosfs_valloc }, /* valloc */
146 1.1.2.2 thorpej { &vop_vfree_desc, adosfs_vfree }, /* vfree */
147 1.1.2.2 thorpej { &vop_truncate_desc, adosfs_truncate }, /* truncate */
148 1.1.2.2 thorpej { &vop_update_desc, adosfs_update }, /* update */
149 1.1.2.2 thorpej { &vop_bwrite_desc, adosfs_bwrite }, /* bwrite */
150 1.1.2.2 thorpej { &vop_getpages_desc, genfs_getpages }, /* getpages */
151 1.1.2.2 thorpej { &vop_putpages_desc, genfs_putpages }, /* putpages */
152 1.1.2.2 thorpej { NULL, NULL }
153 1.1.2.2 thorpej };
154 1.1.2.2 thorpej
155 1.1.2.2 thorpej const struct vnodeopv_desc adosfs_vnodeop_opv_desc =
156 1.1.2.2 thorpej { &adosfs_vnodeop_p, adosfs_vnodeop_entries };
157 1.1.2.2 thorpej
158 1.1.2.2 thorpej int
159 1.1.2.2 thorpej adosfs_getattr(v)
160 1.1.2.2 thorpej void *v;
161 1.1.2.2 thorpej {
162 1.1.2.2 thorpej struct vop_getattr_args /* {
163 1.1.2.2 thorpej struct vnode *a_vp;
164 1.1.2.2 thorpej struct vattr *a_vap;
165 1.1.2.2 thorpej struct ucred *a_cred;
166 1.1.2.2 thorpej struct proc *a_p;
167 1.1.2.2 thorpej } */ *sp = v;
168 1.1.2.2 thorpej struct vattr *vap;
169 1.1.2.2 thorpej struct adosfsmount *amp;
170 1.1.2.2 thorpej struct anode *ap;
171 1.1.2.2 thorpej u_long fblks;
172 1.1.2.2 thorpej
173 1.1.2.2 thorpej #ifdef ADOSFS_DIAGNOSTIC
174 1.1.2.2 thorpej advopprint(sp);
175 1.1.2.2 thorpej #endif
176 1.1.2.2 thorpej vap = sp->a_vap;
177 1.1.2.2 thorpej ap = VTOA(sp->a_vp);
178 1.1.2.2 thorpej amp = ap->amp;
179 1.1.2.2 thorpej vattr_null(vap);
180 1.1.2.2 thorpej vap->va_uid = ap->uid;
181 1.1.2.2 thorpej vap->va_gid = ap->gid;
182 1.1.2.2 thorpej vap->va_fsid = sp->a_vp->v_mount->mnt_stat.f_fsid.val[0];
183 1.1.2.2 thorpej vap->va_atime.tv_sec = vap->va_mtime.tv_sec = vap->va_ctime.tv_sec =
184 1.1.2.2 thorpej ap->mtime.days * 24 * 60 * 60 + ap->mtime.mins * 60 +
185 1.1.2.2 thorpej ap->mtime.ticks / 50 + (8 * 365 + 2) * 24 * 60 * 60;
186 1.1.2.2 thorpej vap->va_atime.tv_nsec = vap->va_mtime.tv_nsec = vap->va_ctime.tv_nsec = 0;
187 1.1.2.2 thorpej vap->va_gen = 0;
188 1.1.2.2 thorpej vap->va_flags = 0;
189 1.1.2.2 thorpej vap->va_rdev = NODEV;
190 1.1.2.2 thorpej vap->va_fileid = ap->block;
191 1.1.2.2 thorpej vap->va_type = sp->a_vp->v_type;
192 1.1.2.2 thorpej vap->va_mode = adunixprot(ap->adprot) & amp->mask;
193 1.1.2.2 thorpej if (sp->a_vp->v_type == VDIR) {
194 1.1.2.2 thorpej vap->va_nlink = 1; /* XXX bogus, oh well */
195 1.1.2.2 thorpej vap->va_bytes = amp->bsize;
196 1.1.2.2 thorpej vap->va_size = amp->bsize;
197 1.1.2.2 thorpej } else {
198 1.1.2.2 thorpej /*
199 1.1.2.2 thorpej * XXX actually we can track this if we were to walk the list
200 1.1.2.2 thorpej * of links if it exists.
201 1.1.2.2 thorpej * XXX for now, just set nlink to 2 if this is a hard link
202 1.1.2.2 thorpej * to a file, or a file with a hard link.
203 1.1.2.2 thorpej */
204 1.1.2.2 thorpej vap->va_nlink = 1 + (ap->linkto != 0);
205 1.1.2.2 thorpej /*
206 1.1.2.2 thorpej * round up to nearest blocks add number of file list
207 1.1.2.2 thorpej * blocks needed and mutiply by number of bytes per block.
208 1.1.2.2 thorpej */
209 1.1.2.2 thorpej fblks = howmany(ap->fsize, amp->dbsize);
210 1.1.2.2 thorpej fblks += howmany(fblks, ANODENDATBLKENT(ap));
211 1.1.2.2 thorpej vap->va_bytes = fblks * amp->dbsize;
212 1.1.2.2 thorpej vap->va_size = ap->fsize;
213 1.1.2.2 thorpej
214 1.1.2.2 thorpej vap->va_blocksize = amp->dbsize;
215 1.1.2.2 thorpej }
216 1.1.2.2 thorpej #ifdef ADOSFS_DIAGNOSTIC
217 1.1.2.2 thorpej printf(" 0)");
218 1.1.2.2 thorpej #endif
219 1.1.2.2 thorpej return(0);
220 1.1.2.2 thorpej }
221 1.1.2.2 thorpej /*
222 1.1.2.2 thorpej * are things locked??? they need to be to avoid this being
223 1.1.2.2 thorpej * deleted or changed (data block pointer blocks moving about.)
224 1.1.2.2 thorpej */
225 1.1.2.2 thorpej int
226 1.1.2.2 thorpej adosfs_read(v)
227 1.1.2.2 thorpej void *v;
228 1.1.2.2 thorpej {
229 1.1.2.2 thorpej struct vop_read_args /* {
230 1.1.2.2 thorpej struct vnode *a_vp;
231 1.1.2.2 thorpej struct uio *a_uio;
232 1.1.2.2 thorpej int a_ioflag;
233 1.1.2.2 thorpej struct ucred *a_cred;
234 1.1.2.2 thorpej } */ *sp = v;
235 1.1.2.2 thorpej struct vnode *vp = sp->a_vp;
236 1.1.2.2 thorpej struct adosfsmount *amp;
237 1.1.2.2 thorpej struct anode *ap;
238 1.1.2.2 thorpej struct uio *uio;
239 1.1.2.2 thorpej struct buf *bp;
240 1.1.2.2 thorpej daddr_t lbn;
241 1.1.2.2 thorpej int size, diff, error;
242 1.1.2.2 thorpej long n, on;
243 1.1.2.2 thorpej
244 1.1.2.2 thorpej #ifdef ADOSFS_DIAGNOSTIC
245 1.1.2.2 thorpej advopprint(sp);
246 1.1.2.2 thorpej #endif
247 1.1.2.2 thorpej error = 0;
248 1.1.2.2 thorpej uio = sp->a_uio;
249 1.1.2.2 thorpej ap = VTOA(sp->a_vp);
250 1.1.2.2 thorpej amp = ap->amp;
251 1.1.2.2 thorpej /*
252 1.1.2.2 thorpej * Return EOF for character devices, EIO for others
253 1.1.2.2 thorpej */
254 1.1.2.2 thorpej if (sp->a_vp->v_type != VREG) {
255 1.1.2.2 thorpej error = EIO;
256 1.1.2.2 thorpej goto reterr;
257 1.1.2.2 thorpej }
258 1.1.2.2 thorpej if (uio->uio_resid == 0)
259 1.1.2.2 thorpej goto reterr;
260 1.1.2.2 thorpej if (uio->uio_offset < 0) {
261 1.1.2.2 thorpej error = EINVAL;
262 1.1.2.2 thorpej goto reterr;
263 1.1.2.2 thorpej }
264 1.1.2.2 thorpej
265 1.1.2.2 thorpej /*
266 1.1.2.2 thorpej * to expensive to let general algorithm figure out that
267 1.1.2.2 thorpej * we are beyond the file. Do it now.
268 1.1.2.2 thorpej */
269 1.1.2.2 thorpej if (uio->uio_offset >= ap->fsize)
270 1.1.2.2 thorpej goto reterr;
271 1.1.2.2 thorpej
272 1.1.2.2 thorpej /*
273 1.1.2.2 thorpej * taken from ufs_read()
274 1.1.2.2 thorpej */
275 1.1.2.2 thorpej
276 1.1.2.2 thorpej if (vp->v_type == VREG && IS_FFS(amp)) {
277 1.1.2.2 thorpej error = 0;
278 1.1.2.2 thorpej while (uio->uio_resid > 0) {
279 1.1.2.2 thorpej void *win;
280 1.1.2.2 thorpej vsize_t bytelen = MIN(ap->fsize - uio->uio_offset,
281 1.1.2.2 thorpej uio->uio_resid);
282 1.1.2.2 thorpej
283 1.1.2.2 thorpej if (bytelen == 0) {
284 1.1.2.2 thorpej break;
285 1.1.2.2 thorpej }
286 1.1.2.2 thorpej win = ubc_alloc(&vp->v_uobj, uio->uio_offset,
287 1.1.2.2 thorpej &bytelen, UBC_READ);
288 1.1.2.2 thorpej error = uiomove(win, bytelen, uio);
289 1.1.2.2 thorpej ubc_release(win, 0);
290 1.1.2.2 thorpej if (error) {
291 1.1.2.2 thorpej break;
292 1.1.2.2 thorpej }
293 1.1.2.2 thorpej }
294 1.1.2.2 thorpej goto out;
295 1.1.2.2 thorpej }
296 1.1.2.2 thorpej
297 1.1.2.2 thorpej do {
298 1.1.2.2 thorpej size = amp->dbsize;
299 1.1.2.2 thorpej lbn = uio->uio_offset / size;
300 1.1.2.2 thorpej on = uio->uio_offset % size;
301 1.1.2.2 thorpej n = MIN(size - on, uio->uio_resid);
302 1.1.2.2 thorpej diff = ap->fsize - uio->uio_offset;
303 1.1.2.2 thorpej /*
304 1.1.2.2 thorpej * check for EOF
305 1.1.2.2 thorpej */
306 1.1.2.2 thorpej if (diff <= 0)
307 1.1.2.2 thorpej return(0);
308 1.1.2.2 thorpej if (diff < n)
309 1.1.2.2 thorpej n = diff;
310 1.1.2.2 thorpej /*
311 1.1.2.2 thorpej * read ahead could possibly be worth something
312 1.1.2.2 thorpej * but not much as ados makes little attempt to
313 1.1.2.2 thorpej * make things contigous
314 1.1.2.2 thorpej */
315 1.1.2.2 thorpej error = bread(sp->a_vp, lbn * amp->bsize / DEV_BSIZE,
316 1.1.2.2 thorpej amp->bsize, NOCRED, &bp);
317 1.1.2.2 thorpej if (error) {
318 1.1.2.2 thorpej brelse(bp);
319 1.1.2.2 thorpej goto reterr;
320 1.1.2.2 thorpej }
321 1.1.2.2 thorpej if (!IS_FFS(amp)) {
322 1.1.2.2 thorpej if (bp->b_resid > 0)
323 1.1.2.2 thorpej error = EIO; /* OFS needs the complete block */
324 1.1.2.2 thorpej else if (adoswordn(bp, 0) != BPT_DATA) {
325 1.1.2.2 thorpej #ifdef DIAGNOSTIC
326 1.1.2.2 thorpej printf("adosfs: bad primary type blk %ld\n",
327 1.1.2.2 thorpej bp->b_blkno / (amp->bsize / DEV_BSIZE));
328 1.1.2.2 thorpej #endif
329 1.1.2.2 thorpej error = EINVAL;
330 1.1.2.2 thorpej } else if (adoscksum(bp, ap->nwords)) {
331 1.1.2.2 thorpej #ifdef DIAGNOSTIC
332 1.1.2.2 thorpej printf("adosfs: blk %ld failed cksum.\n",
333 1.1.2.2 thorpej bp->b_blkno / (amp->bsize / DEV_BSIZE));
334 1.1.2.2 thorpej #endif
335 1.1.2.2 thorpej error = EINVAL;
336 1.1.2.2 thorpej }
337 1.1.2.2 thorpej }
338 1.1.2.2 thorpej
339 1.1.2.2 thorpej if (error) {
340 1.1.2.2 thorpej brelse(bp);
341 1.1.2.2 thorpej goto reterr;
342 1.1.2.2 thorpej }
343 1.1.2.2 thorpej #ifdef ADOSFS_DIAGNOSTIC
344 1.1.2.2 thorpej printf(" %d+%d-%d+%d", lbn, on, lbn, n);
345 1.1.2.2 thorpej #endif
346 1.1.2.2 thorpej n = MIN(n, size - bp->b_resid);
347 1.1.2.2 thorpej error = uiomove(bp->b_data + on +
348 1.1.2.2 thorpej amp->bsize - amp->dbsize, (int)n, uio);
349 1.1.2.2 thorpej brelse(bp);
350 1.1.2.2 thorpej } while (error == 0 && uio->uio_resid > 0 && n != 0);
351 1.1.2.2 thorpej
352 1.1.2.2 thorpej out:
353 1.1.2.2 thorpej reterr:
354 1.1.2.2 thorpej #ifdef ADOSFS_DIAGNOSTIC
355 1.1.2.2 thorpej printf(" %d)", error);
356 1.1.2.2 thorpej #endif
357 1.1.2.2 thorpej return(error);
358 1.1.2.2 thorpej }
359 1.1.2.2 thorpej
360 1.1.2.2 thorpej int
361 1.1.2.2 thorpej adosfs_write(v)
362 1.1.2.2 thorpej void *v;
363 1.1.2.2 thorpej {
364 1.1.2.2 thorpej #ifdef ADOSFS_DIAGNOSTIC
365 1.1.2.2 thorpej struct vop_write_args /* {
366 1.1.2.2 thorpej struct vnode *a_vp;
367 1.1.2.2 thorpej struct uio *a_uio;
368 1.1.2.2 thorpej int a_ioflag;
369 1.1.2.2 thorpej struct ucred *a_cred;
370 1.1.2.2 thorpej } */ *sp = v;
371 1.1.2.2 thorpej advopprint(sp);
372 1.1.2.2 thorpej printf(" EOPNOTSUPP)");
373 1.1.2.2 thorpej #endif
374 1.1.2.2 thorpej return(EOPNOTSUPP);
375 1.1.2.2 thorpej }
376 1.1.2.2 thorpej
377 1.1.2.2 thorpej /*
378 1.1.2.2 thorpej * Just call the device strategy routine
379 1.1.2.2 thorpej */
380 1.1.2.2 thorpej int
381 1.1.2.2 thorpej adosfs_strategy(v)
382 1.1.2.2 thorpej void *v;
383 1.1.2.2 thorpej {
384 1.1.2.2 thorpej struct vop_strategy_args /* {
385 1.1.2.2 thorpej struct buf *a_bp;
386 1.1.2.2 thorpej } */ *sp = v;
387 1.1.2.2 thorpej struct buf *bp;
388 1.1.2.2 thorpej struct anode *ap;
389 1.1.2.2 thorpej struct vnode *vp;
390 1.1.2.2 thorpej int error;
391 1.1.2.2 thorpej
392 1.1.2.2 thorpej #ifdef ADOSFS_DIAGNOSTIC
393 1.1.2.2 thorpej advopprint(sp);
394 1.1.2.2 thorpej #endif
395 1.1.2.2 thorpej error = 0;
396 1.1.2.2 thorpej bp = sp->a_bp;
397 1.1.2.2 thorpej if (bp->b_vp == NULL) {
398 1.1.2.2 thorpej bp->b_flags |= B_ERROR;
399 1.1.2.2 thorpej biodone(bp);
400 1.1.2.2 thorpej error = EIO;
401 1.1.2.2 thorpej goto reterr;
402 1.1.2.2 thorpej }
403 1.1.2.2 thorpej vp = bp->b_vp;
404 1.1.2.2 thorpej ap = VTOA(vp);
405 1.1.2.2 thorpej if (bp->b_blkno == bp->b_lblkno) {
406 1.1.2.2 thorpej error = VOP_BMAP(vp, bp->b_lblkno, NULL, &bp->b_blkno, NULL);
407 1.1.2.2 thorpej if (error) {
408 1.1.2.2 thorpej bp->b_flags |= B_ERROR;
409 1.1.2.2 thorpej biodone(bp);
410 1.1.2.2 thorpej goto reterr;
411 1.1.2.2 thorpej }
412 1.1.2.2 thorpej }
413 1.1.2.2 thorpej if ((long)bp->b_blkno == -1) {
414 1.1.2.2 thorpej biodone(bp);
415 1.1.2.2 thorpej error = 0;
416 1.1.2.2 thorpej goto reterr;
417 1.1.2.2 thorpej }
418 1.1.2.2 thorpej vp = ap->amp->devvp;
419 1.1.2.2 thorpej bp->b_dev = vp->v_rdev;
420 1.1.2.2 thorpej VOCALL(vp->v_op, VOFFSET(vop_strategy), sp);
421 1.1.2.2 thorpej reterr:
422 1.1.2.2 thorpej #ifdef ADOSFS_DIAGNOSTIC
423 1.1.2.2 thorpej printf(" %d)", error);
424 1.1.2.2 thorpej #endif
425 1.1.2.2 thorpej return(error);
426 1.1.2.2 thorpej }
427 1.1.2.2 thorpej
428 1.1.2.2 thorpej int
429 1.1.2.2 thorpej adosfs_link(v)
430 1.1.2.2 thorpej void *v;
431 1.1.2.2 thorpej {
432 1.1.2.2 thorpej struct vop_link_args /* {
433 1.1.2.2 thorpej struct vnode *a_dvp;
434 1.1.2.2 thorpej struct vnode *a_vp;
435 1.1.2.2 thorpej struct componentname *a_cnp;
436 1.1.2.2 thorpej } */ *ap = v;
437 1.1.2.2 thorpej
438 1.1.2.2 thorpej VOP_ABORTOP(ap->a_dvp, ap->a_cnp);
439 1.1.2.2 thorpej vput(ap->a_dvp);
440 1.1.2.2 thorpej return (EROFS);
441 1.1.2.2 thorpej }
442 1.1.2.2 thorpej
443 1.1.2.2 thorpej int
444 1.1.2.2 thorpej adosfs_symlink(v)
445 1.1.2.2 thorpej void *v;
446 1.1.2.2 thorpej {
447 1.1.2.2 thorpej struct vop_symlink_args /* {
448 1.1.2.2 thorpej struct vnode *a_dvp;
449 1.1.2.2 thorpej struct vnode **a_vpp;
450 1.1.2.2 thorpej struct componentname *a_cnp;
451 1.1.2.2 thorpej struct vattr *a_vap;
452 1.1.2.2 thorpej char *a_target;
453 1.1.2.2 thorpej } */ *ap = v;
454 1.1.2.2 thorpej
455 1.1.2.2 thorpej VOP_ABORTOP(ap->a_dvp, ap->a_cnp);
456 1.1.2.2 thorpej vput(ap->a_dvp);
457 1.1.2.2 thorpej return (EROFS);
458 1.1.2.2 thorpej }
459 1.1.2.2 thorpej
460 1.1.2.2 thorpej /*
461 1.1.2.2 thorpej * Wait until the vnode has finished changing state.
462 1.1.2.2 thorpej */
463 1.1.2.2 thorpej int
464 1.1.2.2 thorpej adosfs_bmap(v)
465 1.1.2.2 thorpej void *v;
466 1.1.2.2 thorpej {
467 1.1.2.2 thorpej struct vop_bmap_args /* {
468 1.1.2.2 thorpej struct vnode *a_vp;
469 1.1.2.2 thorpej daddr_t a_bn;
470 1.1.2.2 thorpej struct vnode **a_vpp;
471 1.1.2.2 thorpej daddr_t *a_bnp;
472 1.1.2.2 thorpej int *a_runp;
473 1.1.2.2 thorpej } */ *sp = v;
474 1.1.2.2 thorpej struct anode *ap;
475 1.1.2.2 thorpej struct buf *flbp;
476 1.1.2.2 thorpej long nb, flblk, flblkoff, fcnt;
477 1.1.2.2 thorpej daddr_t *bnp;
478 1.1.2.2 thorpej daddr_t bn;
479 1.1.2.2 thorpej int error;
480 1.1.2.2 thorpej
481 1.1.2.2 thorpej #ifdef ADOSFS_DIAGNOSTIC
482 1.1.2.2 thorpej advopprint(sp);
483 1.1.2.2 thorpej #endif
484 1.1.2.2 thorpej ap = VTOA(sp->a_vp);
485 1.1.2.2 thorpej bn = sp->a_bn / (ap->amp->bsize / DEV_BSIZE);
486 1.1.2.2 thorpej bnp = sp->a_bnp;
487 1.1.2.2 thorpej if (sp->a_runp) {
488 1.1.2.2 thorpej *sp->a_runp = 0;
489 1.1.2.2 thorpej }
490 1.1.2.2 thorpej error = 0;
491 1.1.2.2 thorpej
492 1.1.2.2 thorpej if (sp->a_vpp != NULL)
493 1.1.2.2 thorpej *sp->a_vpp = ap->amp->devvp;
494 1.1.2.2 thorpej if (bnp == NULL)
495 1.1.2.2 thorpej goto reterr;
496 1.1.2.2 thorpej if (bn < 0) {
497 1.1.2.2 thorpej error = EFBIG;
498 1.1.2.2 thorpej goto reterr;
499 1.1.2.2 thorpej }
500 1.1.2.2 thorpej if (sp->a_vp->v_type != VREG) {
501 1.1.2.2 thorpej error = EINVAL;
502 1.1.2.2 thorpej goto reterr;
503 1.1.2.2 thorpej }
504 1.1.2.2 thorpej
505 1.1.2.2 thorpej /*
506 1.1.2.2 thorpej * walk the chain of file list blocks until we find
507 1.1.2.2 thorpej * the one that will yield the block pointer we need.
508 1.1.2.2 thorpej */
509 1.1.2.2 thorpej if (ap->type == AFILE)
510 1.1.2.2 thorpej nb = ap->block; /* pointer to ourself */
511 1.1.2.2 thorpej else if (ap->type == ALFILE)
512 1.1.2.2 thorpej nb = ap->linkto; /* pointer to real file */
513 1.1.2.2 thorpej else {
514 1.1.2.2 thorpej error = EINVAL;
515 1.1.2.2 thorpej goto reterr;
516 1.1.2.2 thorpej }
517 1.1.2.2 thorpej
518 1.1.2.2 thorpej flblk = bn / ANODENDATBLKENT(ap);
519 1.1.2.2 thorpej flbp = NULL;
520 1.1.2.2 thorpej
521 1.1.2.2 thorpej /*
522 1.1.2.2 thorpej * check last indirect block cache
523 1.1.2.2 thorpej */
524 1.1.2.2 thorpej if (flblk < ap->lastlindblk)
525 1.1.2.2 thorpej fcnt = 0;
526 1.1.2.2 thorpej else {
527 1.1.2.2 thorpej flblk -= ap->lastlindblk;
528 1.1.2.2 thorpej fcnt = ap->lastlindblk;
529 1.1.2.2 thorpej nb = ap->lastindblk;
530 1.1.2.2 thorpej }
531 1.1.2.2 thorpej while (flblk >= 0) {
532 1.1.2.2 thorpej if (flbp)
533 1.1.2.2 thorpej brelse(flbp);
534 1.1.2.2 thorpej if (nb == 0) {
535 1.1.2.2 thorpej #ifdef DIAGNOSTIC
536 1.1.2.2 thorpej printf("adosfs: bad file list chain.\n");
537 1.1.2.2 thorpej #endif
538 1.1.2.2 thorpej error = EINVAL;
539 1.1.2.2 thorpej goto reterr;
540 1.1.2.2 thorpej }
541 1.1.2.2 thorpej error = bread(ap->amp->devvp, nb * ap->amp->bsize / DEV_BSIZE,
542 1.1.2.2 thorpej ap->amp->bsize, NOCRED, &flbp);
543 1.1.2.2 thorpej if (error) {
544 1.1.2.2 thorpej brelse(flbp);
545 1.1.2.2 thorpej goto reterr;
546 1.1.2.2 thorpej }
547 1.1.2.2 thorpej if (adoscksum(flbp, ap->nwords)) {
548 1.1.2.2 thorpej #ifdef DIAGNOSTIC
549 1.1.2.2 thorpej printf("adosfs: blk %ld failed cksum.\n", nb);
550 1.1.2.2 thorpej #endif
551 1.1.2.2 thorpej brelse(flbp);
552 1.1.2.2 thorpej error = EINVAL;
553 1.1.2.2 thorpej goto reterr;
554 1.1.2.2 thorpej }
555 1.1.2.2 thorpej /*
556 1.1.2.2 thorpej * update last indirect block cache
557 1.1.2.2 thorpej */
558 1.1.2.2 thorpej ap->lastlindblk = fcnt++;
559 1.1.2.2 thorpej ap->lastindblk = nb;
560 1.1.2.2 thorpej
561 1.1.2.2 thorpej nb = adoswordn(flbp, ap->nwords - 2);
562 1.1.2.2 thorpej flblk--;
563 1.1.2.2 thorpej }
564 1.1.2.2 thorpej /*
565 1.1.2.2 thorpej * calculate offset of block number in table. The table starts
566 1.1.2.2 thorpej * at nwords - 51 and goes to offset 6 or less if indicated by the
567 1.1.2.2 thorpej * valid table entries stored at offset ADBI_NBLKTABENT.
568 1.1.2.2 thorpej */
569 1.1.2.2 thorpej flblkoff = bn % ANODENDATBLKENT(ap);
570 1.1.2.2 thorpej if (flblkoff < adoswordn(flbp, 2 /* ADBI_NBLKTABENT */)) {
571 1.1.2.2 thorpej flblkoff = (ap->nwords - 51) - flblkoff;
572 1.1.2.2 thorpej *bnp = adoswordn(flbp, flblkoff) * ap->amp->bsize / DEV_BSIZE;
573 1.1.2.2 thorpej } else {
574 1.1.2.2 thorpej #ifdef DIAGNOSTIC
575 1.1.2.2 thorpej printf("flblk offset %ld too large in lblk %ld blk %d\n",
576 1.1.2.2 thorpej flblkoff, bn / (ap->amp->bsize / DEV_BSIZE), flbp->b_blkno);
577 1.1.2.2 thorpej #endif
578 1.1.2.2 thorpej error = EINVAL;
579 1.1.2.2 thorpej }
580 1.1.2.2 thorpej brelse(flbp);
581 1.1.2.2 thorpej reterr:
582 1.1.2.2 thorpej #ifdef ADOSFS_DIAGNOSTIC
583 1.1.2.2 thorpej if (error == 0 && bnp)
584 1.1.2.2 thorpej printf(" %d => %d", bn, *bnp);
585 1.1.2.2 thorpej printf(" %d)", error);
586 1.1.2.2 thorpej #endif
587 1.1.2.2 thorpej return(error);
588 1.1.2.2 thorpej }
589 1.1.2.2 thorpej
590 1.1.2.2 thorpej /*
591 1.1.2.2 thorpej * Print out the contents of a adosfs vnode.
592 1.1.2.2 thorpej */
593 1.1.2.2 thorpej /* ARGSUSED */
594 1.1.2.2 thorpej int
595 1.1.2.2 thorpej adosfs_print(v)
596 1.1.2.2 thorpej void *v;
597 1.1.2.2 thorpej {
598 1.1.2.2 thorpej #if 0
599 1.1.2.2 thorpej struct vop_print_args /* {
600 1.1.2.2 thorpej struct vnode *a_vp;
601 1.1.2.2 thorpej } */ *sp = v;
602 1.1.2.2 thorpej #endif
603 1.1.2.2 thorpej return(0);
604 1.1.2.2 thorpej }
605 1.1.2.2 thorpej
606 1.1.2.2 thorpej struct adirent {
607 1.1.2.2 thorpej u_long fileno;
608 1.1.2.2 thorpej u_short reclen;
609 1.1.2.2 thorpej char type;
610 1.1.2.2 thorpej char namlen;
611 1.1.2.2 thorpej char name[32]; /* maxlen of 30 plus 2 NUL's */
612 1.1.2.2 thorpej };
613 1.1.2.2 thorpej
614 1.1.2.2 thorpej int
615 1.1.2.2 thorpej adosfs_readdir(v)
616 1.1.2.2 thorpej void *v;
617 1.1.2.2 thorpej {
618 1.1.2.2 thorpej struct vop_readdir_args /* {
619 1.1.2.2 thorpej struct vnode *a_vp;
620 1.1.2.2 thorpej struct uio *a_uio;
621 1.1.2.2 thorpej struct ucred *a_cred;
622 1.1.2.2 thorpej int *a_eofflag;
623 1.1.2.2 thorpej off_t **a_cookies;
624 1.1.2.2 thorpej int *a_ncookies;
625 1.1.2.2 thorpej } */ *sp = v;
626 1.1.2.2 thorpej int error, useri, chainc, hashi, scanned, uavail;
627 1.1.2.2 thorpej struct adirent ad, *adp;
628 1.1.2.2 thorpej struct anode *pap, *ap;
629 1.1.2.2 thorpej struct adosfsmount *amp;
630 1.1.2.2 thorpej struct vnode *vp;
631 1.1.2.2 thorpej struct uio *uio;
632 1.1.2.2 thorpej u_long nextbn;
633 1.1.2.2 thorpej off_t uoff, *cookies = NULL;
634 1.1.2.2 thorpej int ncookies = 0;
635 1.1.2.2 thorpej
636 1.1.2.2 thorpej #ifdef ADOSFS_DIAGNOSTIC
637 1.1.2.2 thorpej advopprint(sp);
638 1.1.2.2 thorpej #endif
639 1.1.2.2 thorpej if (sp->a_vp->v_type != VDIR) {
640 1.1.2.2 thorpej error = ENOTDIR;
641 1.1.2.2 thorpej goto reterr;
642 1.1.2.2 thorpej }
643 1.1.2.2 thorpej
644 1.1.2.2 thorpej uio = sp->a_uio;
645 1.1.2.2 thorpej uoff = uio->uio_offset;
646 1.1.2.2 thorpej if (uoff < 0) {
647 1.1.2.2 thorpej error = EINVAL;
648 1.1.2.2 thorpej goto reterr;
649 1.1.2.2 thorpej }
650 1.1.2.2 thorpej
651 1.1.2.2 thorpej pap = VTOA(sp->a_vp);
652 1.1.2.2 thorpej amp = pap->amp;
653 1.1.2.2 thorpej adp = &ad;
654 1.1.2.2 thorpej error = nextbn = hashi = chainc = scanned = 0;
655 1.1.2.2 thorpej uavail = uio->uio_resid / sizeof(ad);
656 1.1.2.2 thorpej useri = uoff / sizeof(ad);
657 1.1.2.2 thorpej
658 1.1.2.2 thorpej /*
659 1.1.2.2 thorpej * if no slots available or offset requested is not on a slot boundry
660 1.1.2.2 thorpej */
661 1.1.2.2 thorpej if (uavail < 1 || uoff % sizeof(ad)) {
662 1.1.2.2 thorpej error = EINVAL;
663 1.1.2.2 thorpej goto reterr;
664 1.1.2.2 thorpej }
665 1.1.2.2 thorpej
666 1.1.2.2 thorpej if (sp->a_ncookies) {
667 1.1.2.2 thorpej ncookies = 0;
668 1.1.2.2 thorpej cookies = malloc(sizeof (off_t) * uavail, M_TEMP, M_WAITOK);
669 1.1.2.2 thorpej *sp->a_cookies = cookies;
670 1.1.2.2 thorpej }
671 1.1.2.2 thorpej
672 1.1.2.2 thorpej while (uavail) {
673 1.1.2.2 thorpej if (hashi == pap->ntabent) {
674 1.1.2.2 thorpej *sp->a_eofflag = 1;
675 1.1.2.2 thorpej break;
676 1.1.2.2 thorpej }
677 1.1.2.2 thorpej if (pap->tab[hashi] == 0) {
678 1.1.2.2 thorpej hashi++;
679 1.1.2.2 thorpej continue;
680 1.1.2.2 thorpej }
681 1.1.2.2 thorpej if (nextbn == 0)
682 1.1.2.2 thorpej nextbn = pap->tab[hashi];
683 1.1.2.2 thorpej
684 1.1.2.2 thorpej /*
685 1.1.2.2 thorpej * first determine if we can skip this chain
686 1.1.2.2 thorpej */
687 1.1.2.2 thorpej if (chainc == 0) {
688 1.1.2.2 thorpej int skip;
689 1.1.2.2 thorpej
690 1.1.2.2 thorpej skip = useri - scanned;
691 1.1.2.2 thorpej if (pap->tabi[hashi] > 0 && pap->tabi[hashi] <= skip) {
692 1.1.2.2 thorpej scanned += pap->tabi[hashi];
693 1.1.2.2 thorpej hashi++;
694 1.1.2.2 thorpej nextbn = 0;
695 1.1.2.2 thorpej continue;
696 1.1.2.2 thorpej }
697 1.1.2.2 thorpej }
698 1.1.2.2 thorpej
699 1.1.2.2 thorpej /*
700 1.1.2.2 thorpej * now [continue to] walk the chain
701 1.1.2.2 thorpej */
702 1.1.2.2 thorpej ap = NULL;
703 1.1.2.2 thorpej do {
704 1.1.2.2 thorpej error = VFS_VGET(amp->mp, (ino_t)nextbn, &vp);
705 1.1.2.2 thorpej if (error)
706 1.1.2.2 thorpej goto reterr;
707 1.1.2.2 thorpej ap = VTOA(vp);
708 1.1.2.2 thorpej scanned++;
709 1.1.2.2 thorpej chainc++;
710 1.1.2.2 thorpej nextbn = ap->hashf;
711 1.1.2.2 thorpej
712 1.1.2.2 thorpej /*
713 1.1.2.2 thorpej * check for end of chain.
714 1.1.2.2 thorpej */
715 1.1.2.2 thorpej if (nextbn == 0) {
716 1.1.2.2 thorpej pap->tabi[hashi] = chainc;
717 1.1.2.2 thorpej hashi++;
718 1.1.2.2 thorpej chainc = 0;
719 1.1.2.2 thorpej } else if (pap->tabi[hashi] <= 0 &&
720 1.1.2.2 thorpej -chainc < pap->tabi[hashi])
721 1.1.2.2 thorpej pap->tabi[hashi] = -chainc;
722 1.1.2.2 thorpej
723 1.1.2.2 thorpej if (useri >= scanned) {
724 1.1.2.2 thorpej vput(vp);
725 1.1.2.2 thorpej ap = NULL;
726 1.1.2.2 thorpej }
727 1.1.2.2 thorpej } while (ap == NULL && nextbn != 0);
728 1.1.2.2 thorpej
729 1.1.2.2 thorpej /*
730 1.1.2.2 thorpej * we left the loop but without a result so do main over.
731 1.1.2.2 thorpej */
732 1.1.2.2 thorpej if (ap == NULL)
733 1.1.2.2 thorpej continue;
734 1.1.2.2 thorpej /*
735 1.1.2.2 thorpej * Fill in dirent record
736 1.1.2.2 thorpej */
737 1.1.2.2 thorpej memset(adp, 0, sizeof(struct adirent));
738 1.1.2.2 thorpej adp->fileno = ap->block;
739 1.1.2.2 thorpej /*
740 1.1.2.2 thorpej * this deserves an function in kern/vfs_subr.c
741 1.1.2.2 thorpej */
742 1.1.2.2 thorpej switch (ATOV(ap)->v_type) {
743 1.1.2.2 thorpej case VREG:
744 1.1.2.2 thorpej adp->type = DT_REG;
745 1.1.2.2 thorpej break;
746 1.1.2.2 thorpej case VDIR:
747 1.1.2.2 thorpej adp->type = DT_DIR;
748 1.1.2.2 thorpej break;
749 1.1.2.2 thorpej case VLNK:
750 1.1.2.2 thorpej adp->type = DT_LNK;
751 1.1.2.2 thorpej break;
752 1.1.2.2 thorpej default:
753 1.1.2.2 thorpej adp->type = DT_UNKNOWN;
754 1.1.2.2 thorpej break;
755 1.1.2.2 thorpej }
756 1.1.2.2 thorpej adp->reclen = sizeof(struct adirent);
757 1.1.2.2 thorpej adp->namlen = strlen(ap->name);
758 1.1.2.2 thorpej memcpy(adp->name, ap->name, adp->namlen);
759 1.1.2.2 thorpej vput(vp);
760 1.1.2.2 thorpej
761 1.1.2.2 thorpej error = uiomove((caddr_t) adp, sizeof(struct adirent), uio);
762 1.1.2.2 thorpej if (error)
763 1.1.2.2 thorpej break;
764 1.1.2.2 thorpej if (sp->a_ncookies) {
765 1.1.2.2 thorpej *cookies++ = uoff;
766 1.1.2.2 thorpej ncookies++;
767 1.1.2.2 thorpej }
768 1.1.2.2 thorpej uoff += sizeof(struct adirent);
769 1.1.2.2 thorpej useri++;
770 1.1.2.2 thorpej uavail--;
771 1.1.2.2 thorpej }
772 1.1.2.2 thorpej #if doesnt_uiomove_handle_this
773 1.1.2.2 thorpej uio->uio_offset = uoff;
774 1.1.2.2 thorpej #endif
775 1.1.2.2 thorpej reterr:
776 1.1.2.2 thorpej #ifdef ADOSFS_DIAGNOSTIC
777 1.1.2.2 thorpej printf(" %d)", error);
778 1.1.2.2 thorpej #endif
779 1.1.2.2 thorpej if (sp->a_ncookies) {
780 1.1.2.2 thorpej if (error) {
781 1.1.2.2 thorpej free(*sp->a_cookies, M_TEMP);
782 1.1.2.2 thorpej *sp->a_ncookies = 0;
783 1.1.2.2 thorpej *sp->a_cookies = NULL;
784 1.1.2.2 thorpej } else
785 1.1.2.2 thorpej *sp->a_ncookies = ncookies;
786 1.1.2.2 thorpej }
787 1.1.2.2 thorpej return(error);
788 1.1.2.2 thorpej }
789 1.1.2.2 thorpej
790 1.1.2.2 thorpej
791 1.1.2.2 thorpej int
792 1.1.2.2 thorpej adosfs_access(v)
793 1.1.2.2 thorpej void *v;
794 1.1.2.2 thorpej {
795 1.1.2.2 thorpej struct vop_access_args /* {
796 1.1.2.2 thorpej struct vnode *a_vp;
797 1.1.2.2 thorpej int a_mode;
798 1.1.2.2 thorpej struct ucred *a_cred;
799 1.1.2.2 thorpej struct proc *a_p;
800 1.1.2.2 thorpej } */ *sp = v;
801 1.1.2.2 thorpej struct anode *ap;
802 1.1.2.2 thorpej struct vnode *vp = sp->a_vp;
803 1.1.2.2 thorpej int error;
804 1.1.2.2 thorpej
805 1.1.2.2 thorpej #ifdef ADOSFS_DIAGNOSTIC
806 1.1.2.2 thorpej advopprint(sp);
807 1.1.2.2 thorpej #endif
808 1.1.2.2 thorpej
809 1.1.2.2 thorpej ap = VTOA(vp);
810 1.1.2.2 thorpej #ifdef DIAGNOSTIC
811 1.1.2.2 thorpej if (!VOP_ISLOCKED(vp)) {
812 1.1.2.2 thorpej vprint("adosfs_access: not locked", sp->a_vp);
813 1.1.2.2 thorpej panic("adosfs_access: not locked");
814 1.1.2.2 thorpej }
815 1.1.2.2 thorpej #endif
816 1.1.2.2 thorpej /*
817 1.1.2.2 thorpej * Disallow write attempts unless the file is a socket,
818 1.1.2.2 thorpej * fifo, or a block or character device resident on the
819 1.1.2.2 thorpej * file system.
820 1.1.2.2 thorpej */
821 1.1.2.2 thorpej if (sp->a_mode & VWRITE) {
822 1.1.2.2 thorpej switch (vp->v_type) {
823 1.1.2.2 thorpej case VDIR:
824 1.1.2.2 thorpej case VLNK:
825 1.1.2.2 thorpej case VREG:
826 1.1.2.2 thorpej return (EROFS);
827 1.1.2.2 thorpej default:
828 1.1.2.2 thorpej break;
829 1.1.2.2 thorpej }
830 1.1.2.2 thorpej }
831 1.1.2.2 thorpej #ifdef QUOTA
832 1.1.2.2 thorpej #endif
833 1.1.2.2 thorpej error = vaccess(sp->a_vp->v_type, adunixprot(ap->adprot) & ap->amp->mask,
834 1.1.2.2 thorpej ap->uid, ap->gid, sp->a_mode, sp->a_cred);
835 1.1.2.2 thorpej #ifdef ADOSFS_DIAGNOSTIC
836 1.1.2.2 thorpej printf(" %d)", error);
837 1.1.2.2 thorpej #endif
838 1.1.2.2 thorpej return(error);
839 1.1.2.2 thorpej }
840 1.1.2.2 thorpej
841 1.1.2.2 thorpej int
842 1.1.2.2 thorpej adosfs_readlink(v)
843 1.1.2.2 thorpej void *v;
844 1.1.2.2 thorpej {
845 1.1.2.2 thorpej struct vop_readlink_args /* {
846 1.1.2.2 thorpej struct vnode *a_vp;
847 1.1.2.2 thorpej struct uio *a_uio;
848 1.1.2.2 thorpej struct ucred *a_cred;
849 1.1.2.2 thorpej } */ *sp = v;
850 1.1.2.2 thorpej struct anode *ap;
851 1.1.2.2 thorpej int error;
852 1.1.2.2 thorpej
853 1.1.2.2 thorpej #ifdef ADOSFS_DIAGNOSTIC
854 1.1.2.2 thorpej advopprint(sp);
855 1.1.2.2 thorpej #endif
856 1.1.2.2 thorpej ap = VTOA(sp->a_vp);
857 1.1.2.2 thorpej error = uiomove(ap->slinkto, strlen(ap->slinkto), sp->a_uio);
858 1.1.2.2 thorpej #ifdef ADOSFS_DIAGNOSTIC
859 1.1.2.2 thorpej printf(" %d)", error);
860 1.1.2.2 thorpej #endif
861 1.1.2.2 thorpej return (error);
862 1.1.2.2 thorpej }
863 1.1.2.2 thorpej
864 1.1.2.2 thorpej /*ARGSUSED*/
865 1.1.2.2 thorpej int
866 1.1.2.2 thorpej adosfs_inactive(v)
867 1.1.2.2 thorpej void *v;
868 1.1.2.2 thorpej {
869 1.1.2.2 thorpej struct vop_inactive_args /* {
870 1.1.2.2 thorpej struct vnode *a_vp;
871 1.1.2.2 thorpej struct proc *a_p;
872 1.1.2.2 thorpej } */ *sp = v;
873 1.1.2.2 thorpej struct vnode *vp = sp->a_vp;
874 1.1.2.2 thorpej struct proc *p = sp->a_p;
875 1.1.2.2 thorpej #ifdef ADOSFS_DIAGNOSTIC
876 1.1.2.2 thorpej advopprint(sp);
877 1.1.2.2 thorpej #endif
878 1.1.2.2 thorpej VOP_UNLOCK(vp, 0);
879 1.1.2.2 thorpej /* XXX this needs to check if file was deleted */
880 1.1.2.2 thorpej vrecycle(vp, NULL, p);
881 1.1.2.2 thorpej
882 1.1.2.2 thorpej #ifdef ADOSFS_DIAGNOSTIC
883 1.1.2.2 thorpej printf(" 0)");
884 1.1.2.2 thorpej #endif
885 1.1.2.2 thorpej return(0);
886 1.1.2.2 thorpej }
887 1.1.2.2 thorpej
888 1.1.2.2 thorpej /*
889 1.1.2.2 thorpej * the kernel wants its vnode back.
890 1.1.2.2 thorpej * no lock needed we are being called from vclean()
891 1.1.2.2 thorpej */
892 1.1.2.2 thorpej int
893 1.1.2.2 thorpej adosfs_reclaim(v)
894 1.1.2.2 thorpej void *v;
895 1.1.2.2 thorpej {
896 1.1.2.2 thorpej struct vop_reclaim_args /* {
897 1.1.2.2 thorpej struct vnode *a_vp;
898 1.1.2.2 thorpej } */ *sp = v;
899 1.1.2.2 thorpej struct vnode *vp;
900 1.1.2.2 thorpej struct anode *ap;
901 1.1.2.2 thorpej
902 1.1.2.2 thorpej #ifdef ADOSFS_DIAGNOSTIC
903 1.1.2.2 thorpej printf("(reclaim 0)");
904 1.1.2.2 thorpej #endif
905 1.1.2.2 thorpej vp = sp->a_vp;
906 1.1.2.2 thorpej ap = VTOA(vp);
907 1.1.2.2 thorpej LIST_REMOVE(ap, link);
908 1.1.2.2 thorpej cache_purge(vp);
909 1.1.2.2 thorpej if (vp->v_type == VDIR && ap->tab)
910 1.1.2.2 thorpej free(ap->tab, M_ANODE);
911 1.1.2.2 thorpej else if (vp->v_type == VLNK && ap->slinkto)
912 1.1.2.2 thorpej free(ap->slinkto, M_ANODE);
913 1.1.2.2 thorpej pool_put(&adosfs_node_pool, ap);
914 1.1.2.2 thorpej vp->v_data = NULL;
915 1.1.2.2 thorpej return(0);
916 1.1.2.2 thorpej }
917 1.1.2.2 thorpej
918 1.1.2.2 thorpej /*
919 1.1.2.2 thorpej * POSIX pathconf info, grabbed from kern/u fs, probably need to
920 1.1.2.2 thorpej * investigate exactly what each return type means as they are probably
921 1.1.2.2 thorpej * not valid currently
922 1.1.2.2 thorpej */
923 1.1.2.2 thorpej int
924 1.1.2.2 thorpej adosfs_pathconf(v)
925 1.1.2.2 thorpej void *v;
926 1.1.2.2 thorpej {
927 1.1.2.2 thorpej struct vop_pathconf_args /* {
928 1.1.2.2 thorpej struct vnode *a_vp;
929 1.1.2.2 thorpej int a_name;
930 1.1.2.2 thorpej register_t *a_retval;
931 1.1.2.2 thorpej } */ *sp = v;
932 1.1.2.2 thorpej
933 1.1.2.2 thorpej switch (sp->a_name) {
934 1.1.2.2 thorpej case _PC_LINK_MAX:
935 1.1.2.2 thorpej *sp->a_retval = LINK_MAX;
936 1.1.2.2 thorpej return (0);
937 1.1.2.2 thorpej case _PC_PIPE_BUF:
938 1.1.2.2 thorpej *sp->a_retval = PIPE_BUF;
939 1.1.2.2 thorpej return (0);
940 1.1.2.2 thorpej case _PC_CHOWN_RESTRICTED:
941 1.1.2.2 thorpej *sp->a_retval = 1;
942 1.1.2.2 thorpej return (0);
943 1.1.2.2 thorpej case _PC_VDISABLE:
944 1.1.2.2 thorpej *sp->a_retval = _POSIX_VDISABLE;
945 1.1.2.2 thorpej return (0);
946 1.1.2.2 thorpej case _PC_SYNC_IO:
947 1.1.2.2 thorpej *sp->a_retval = 1;
948 1.1.2.2 thorpej return (0);
949 1.1.2.2 thorpej case _PC_FILESIZEBITS:
950 1.1.2.2 thorpej *sp->a_retval = 32;
951 1.1.2.2 thorpej return (0);
952 1.1.2.2 thorpej default:
953 1.1.2.2 thorpej return (EINVAL);
954 1.1.2.2 thorpej }
955 1.1.2.2 thorpej /* NOTREACHED */
956 1.1.2.2 thorpej }
957