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