advnops.c revision 1.30 1 /* $NetBSD: advnops.c,v 1.30 2008/11/26 20:17:33 pooka 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.30 2008/11/26 20:17:33 pooka 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/inttypes.h>
51 #include <sys/malloc.h>
52 #include <sys/pool.h>
53 #include <sys/stat.h>
54 #include <sys/unistd.h>
55 #include <sys/proc.h>
56 #include <sys/kauth.h>
57
58 #include <miscfs/genfs/genfs.h>
59 #include <miscfs/specfs/specdev.h>
60 #include <fs/adosfs/adosfs.h>
61
62 extern struct vnodeops adosfs_vnodeops;
63
64 #define adosfs_open genfs_nullop
65 int adosfs_getattr __P((void *));
66 int adosfs_read __P((void *));
67 int adosfs_write __P((void *));
68 #define adosfs_fcntl genfs_fcntl
69 #define adosfs_ioctl genfs_enoioctl
70 #define adosfs_poll genfs_poll
71 int adosfs_strategy __P((void *));
72 int adosfs_link __P((void *));
73 int adosfs_symlink __P((void *));
74 #define adosfs_abortop genfs_abortop
75 int adosfs_bmap __P((void *));
76 int adosfs_print __P((void *));
77 int adosfs_readdir __P((void *));
78 int adosfs_access __P((void *));
79 int adosfs_readlink __P((void *));
80 int adosfs_inactive __P((void *));
81 int adosfs_reclaim __P((void *));
82 int adosfs_pathconf __P((void *));
83
84 #define adosfs_close genfs_nullop
85 #define adosfs_fsync genfs_nullop
86 #define adosfs_seek genfs_seek
87
88 #define adosfs_advlock genfs_einval
89 #define adosfs_bwrite genfs_eopnotsupp
90 #define adosfs_create genfs_eopnotsupp
91 #define adosfs_mkdir genfs_eopnotsupp
92 #define adosfs_mknod genfs_eopnotsupp
93 #define adosfs_revoke genfs_revoke
94 #define adosfs_mmap genfs_mmap
95 #define adosfs_remove genfs_eopnotsupp
96 #define adosfs_rename genfs_eopnotsupp
97 #define adosfs_rmdir genfs_eopnotsupp
98 #define adosfs_setattr genfs_eopnotsupp
99
100 const struct vnodeopv_entry_desc adosfs_vnodeop_entries[] = {
101 { &vop_default_desc, vn_default_error },
102 { &vop_lookup_desc, adosfs_lookup }, /* lookup */
103 { &vop_create_desc, adosfs_create }, /* create */
104 { &vop_mknod_desc, adosfs_mknod }, /* mknod */
105 { &vop_open_desc, adosfs_open }, /* open */
106 { &vop_close_desc, adosfs_close }, /* close */
107 { &vop_access_desc, adosfs_access }, /* access */
108 { &vop_getattr_desc, adosfs_getattr }, /* getattr */
109 { &vop_setattr_desc, adosfs_setattr }, /* setattr */
110 { &vop_read_desc, adosfs_read }, /* read */
111 { &vop_write_desc, adosfs_write }, /* write */
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 kauth_cred_t a_cred;
156 } */ *sp = v;
157 struct vattr *vap;
158 struct adosfsmount *amp;
159 struct anode *ap;
160 u_long fblks;
161
162 #ifdef ADOSFS_DIAGNOSTIC
163 advopprint(sp);
164 #endif
165 vap = sp->a_vap;
166 ap = VTOA(sp->a_vp);
167 amp = ap->amp;
168 vattr_null(vap);
169 vap->va_uid = ap->uid;
170 vap->va_gid = ap->gid;
171 vap->va_fsid = sp->a_vp->v_mount->mnt_stat.f_fsidx.__fsid_val[0];
172 vap->va_atime.tv_sec = vap->va_mtime.tv_sec = vap->va_ctime.tv_sec =
173 ap->mtime.days * 24 * 60 * 60 + ap->mtime.mins * 60 +
174 ap->mtime.ticks / 50 + (8 * 365 + 2) * 24 * 60 * 60;
175 vap->va_atime.tv_nsec = vap->va_mtime.tv_nsec = vap->va_ctime.tv_nsec = 0;
176 vap->va_gen = 0;
177 vap->va_flags = 0;
178 vap->va_rdev = NODEV;
179 vap->va_fileid = ap->block;
180 vap->va_type = sp->a_vp->v_type;
181 vap->va_mode = adunixprot(ap->adprot) & amp->mask;
182 if (sp->a_vp->v_type == VDIR) {
183 vap->va_nlink = 1; /* XXX bogus, oh well */
184 vap->va_bytes = amp->bsize;
185 vap->va_size = amp->bsize;
186 } else {
187 /*
188 * XXX actually we can track this if we were to walk the list
189 * of links if it exists.
190 * XXX for now, just set nlink to 2 if this is a hard link
191 * to a file, or a file with a hard link.
192 */
193 vap->va_nlink = 1 + (ap->linkto != 0);
194 /*
195 * round up to nearest blocks add number of file list
196 * blocks needed and mutiply by number of bytes per block.
197 */
198 fblks = howmany(ap->fsize, amp->dbsize);
199 fblks += howmany(fblks, ANODENDATBLKENT(ap));
200 vap->va_bytes = fblks * amp->dbsize;
201 vap->va_size = ap->fsize;
202
203 vap->va_blocksize = amp->dbsize;
204 }
205 #ifdef ADOSFS_DIAGNOSTIC
206 printf(" 0)");
207 #endif
208 return(0);
209 }
210 /*
211 * are things locked??? they need to be to avoid this being
212 * deleted or changed (data block pointer blocks moving about.)
213 */
214 int
215 adosfs_read(v)
216 void *v;
217 {
218 struct vop_read_args /* {
219 struct vnode *a_vp;
220 struct uio *a_uio;
221 int a_ioflag;
222 kauth_cred_t a_cred;
223 } */ *sp = v;
224 struct vnode *vp = sp->a_vp;
225 struct adosfsmount *amp;
226 struct anode *ap;
227 struct uio *uio;
228 struct buf *bp;
229 daddr_t lbn;
230 int size, diff, error;
231 long n, on;
232
233 #ifdef ADOSFS_DIAGNOSTIC
234 advopprint(sp);
235 #endif
236 error = 0;
237 uio = sp->a_uio;
238 ap = VTOA(sp->a_vp);
239 amp = ap->amp;
240 /*
241 * Return EOF for character devices, EIO for others
242 */
243 if (sp->a_vp->v_type != VREG) {
244 error = EIO;
245 goto reterr;
246 }
247 if (uio->uio_resid == 0)
248 goto reterr;
249 if (uio->uio_offset < 0) {
250 error = EINVAL;
251 goto reterr;
252 }
253
254 /*
255 * to expensive to let general algorithm figure out that
256 * we are beyond the file. Do it now.
257 */
258 if (uio->uio_offset >= ap->fsize)
259 goto reterr;
260
261 /*
262 * taken from ufs_read()
263 */
264
265 if (vp->v_type == VREG && IS_FFS(amp)) {
266 const int advice = IO_ADV_DECODE(sp->a_ioflag);
267 error = 0;
268
269 while (uio->uio_resid > 0) {
270 vsize_t bytelen = MIN(ap->fsize - uio->uio_offset,
271 uio->uio_resid);
272
273 if (bytelen == 0) {
274 break;
275 }
276 error = ubc_uiomove(&vp->v_uobj, uio, bytelen, advice,
277 UBC_READ | UBC_PARTIALOK | UBC_UNMAP_FLAG(vp));
278 if (error) {
279 break;
280 }
281 }
282 goto out;
283 }
284
285 do {
286 size = amp->dbsize;
287 lbn = uio->uio_offset / size;
288 on = uio->uio_offset % size;
289 n = MIN(size - on, uio->uio_resid);
290 diff = ap->fsize - uio->uio_offset;
291 /*
292 * check for EOF
293 */
294 if (diff <= 0)
295 return(0);
296 if (diff < n)
297 n = diff;
298 /*
299 * read ahead could possibly be worth something
300 * but not much as ados makes little attempt to
301 * make things contigous
302 */
303 error = bread(sp->a_vp, lbn, amp->bsize, NOCRED, 0, &bp);
304 if (error) {
305 brelse(bp, 0);
306 goto reterr;
307 }
308 if (!IS_FFS(amp)) {
309 if (bp->b_resid > 0)
310 error = EIO; /* OFS needs the complete block */
311 else if (adoswordn(bp, 0) != BPT_DATA) {
312 #ifdef DIAGNOSTIC
313 printf("adosfs: bad primary type blk %" PRId64 "\n",
314 bp->b_blkno / (amp->bsize / DEV_BSIZE));
315 #endif
316 error = EINVAL;
317 } else if (adoscksum(bp, ap->nwords)) {
318 #ifdef DIAGNOSTIC
319 printf("adosfs: blk %" PRId64 " failed cksum.\n",
320 bp->b_blkno / (amp->bsize / DEV_BSIZE));
321 #endif
322 error = EINVAL;
323 }
324 }
325
326 if (error) {
327 brelse(bp, 0);
328 goto reterr;
329 }
330 #ifdef ADOSFS_DIAGNOSTIC
331 printf(" %" PRId64 "+%ld-%" PRId64 "+%ld", lbn, on, lbn, n);
332 #endif
333 n = MIN(n, size - bp->b_resid);
334 error = uiomove((char *)bp->b_data + on +
335 amp->bsize - amp->dbsize, (int)n, uio);
336 brelse(bp, 0);
337 } while (error == 0 && uio->uio_resid > 0 && n != 0);
338
339 out:
340 reterr:
341 #ifdef ADOSFS_DIAGNOSTIC
342 printf(" %d)", error);
343 #endif
344 return(error);
345 }
346
347 int
348 adosfs_write(v)
349 void *v;
350 {
351 #ifdef ADOSFS_DIAGNOSTIC
352 struct vop_write_args /* {
353 struct vnode *a_vp;
354 struct uio *a_uio;
355 int a_ioflag;
356 kauth_cred_t a_cred;
357 } */ *sp = v;
358 advopprint(sp);
359 printf(" EOPNOTSUPP)");
360 #endif
361 return(EOPNOTSUPP);
362 }
363
364 /*
365 * Just call the device strategy routine
366 */
367 int
368 adosfs_strategy(v)
369 void *v;
370 {
371 struct vop_strategy_args /* {
372 struct vnode *a_vp;
373 struct buf *a_bp;
374 } */ *sp = v;
375 struct buf *bp;
376 struct anode *ap;
377 struct vnode *vp;
378 int error;
379
380 #ifdef ADOSFS_DIAGNOSTIC
381 advopprint(sp);
382 #endif
383 bp = sp->a_bp;
384 if (bp->b_vp == NULL) {
385 bp->b_error = EIO;
386 biodone(bp);
387 error = EIO;
388 goto reterr;
389 }
390 vp = sp->a_vp;
391 ap = VTOA(vp);
392 if (bp->b_blkno == bp->b_lblkno) {
393 error = VOP_BMAP(vp, bp->b_lblkno, NULL, &bp->b_blkno, NULL);
394 if (error) {
395 bp->b_flags = error;
396 biodone(bp);
397 goto reterr;
398 }
399 }
400 if ((long)bp->b_blkno == -1) {
401 biodone(bp);
402 error = 0;
403 goto reterr;
404 }
405 vp = ap->amp->devvp;
406 error = VOP_STRATEGY(vp, bp);
407 reterr:
408 #ifdef ADOSFS_DIAGNOSTIC
409 printf(" %d)", error);
410 #endif
411 return(error);
412 }
413
414 int
415 adosfs_link(v)
416 void *v;
417 {
418 struct vop_link_args /* {
419 struct vnode *a_dvp;
420 struct vnode *a_vp;
421 struct componentname *a_cnp;
422 } */ *ap = v;
423
424 VOP_ABORTOP(ap->a_dvp, ap->a_cnp);
425 vput(ap->a_dvp);
426 return (EROFS);
427 }
428
429 int
430 adosfs_symlink(v)
431 void *v;
432 {
433 struct vop_symlink_args /* {
434 struct vnode *a_dvp;
435 struct vnode **a_vpp;
436 struct componentname *a_cnp;
437 struct vattr *a_vap;
438 char *a_target;
439 } */ *ap = v;
440
441 VOP_ABORTOP(ap->a_dvp, ap->a_cnp);
442 vput(ap->a_dvp);
443 return (EROFS);
444 }
445
446 /*
447 * Wait until the vnode has finished changing state.
448 */
449 int
450 adosfs_bmap(v)
451 void *v;
452 {
453 struct vop_bmap_args /* {
454 struct vnode *a_vp;
455 daddr_t a_bn;
456 struct vnode **a_vpp;
457 daddr_t *a_bnp;
458 int *a_runp;
459 } */ *sp = v;
460 struct anode *ap;
461 struct buf *flbp;
462 long nb, flblk, flblkoff, fcnt;
463 daddr_t *bnp;
464 daddr_t bn;
465 int error;
466
467 #ifdef ADOSFS_DIAGNOSTIC
468 advopprint(sp);
469 #endif
470 ap = VTOA(sp->a_vp);
471 bn = sp->a_bn;
472 bnp = sp->a_bnp;
473 if (sp->a_runp) {
474 *sp->a_runp = 0;
475 }
476 error = 0;
477
478 if (sp->a_vpp != NULL)
479 *sp->a_vpp = ap->amp->devvp;
480 if (bnp == NULL)
481 goto reterr;
482 if (bn < 0) {
483 error = EFBIG;
484 goto reterr;
485 }
486 if (sp->a_vp->v_type != VREG) {
487 error = EINVAL;
488 goto reterr;
489 }
490
491 /*
492 * walk the chain of file list blocks until we find
493 * the one that will yield the block pointer we need.
494 */
495 if (ap->type == AFILE)
496 nb = ap->block; /* pointer to ourself */
497 else if (ap->type == ALFILE)
498 nb = ap->linkto; /* pointer to real file */
499 else {
500 error = EINVAL;
501 goto reterr;
502 }
503
504 flblk = bn / ANODENDATBLKENT(ap);
505 flbp = NULL;
506
507 /*
508 * check last indirect block cache
509 */
510 if (flblk < ap->lastlindblk)
511 fcnt = 0;
512 else {
513 flblk -= ap->lastlindblk;
514 fcnt = ap->lastlindblk;
515 nb = ap->lastindblk;
516 }
517 while (flblk >= 0) {
518 if (flbp)
519 brelse(flbp, 0);
520 if (nb == 0) {
521 #ifdef DIAGNOSTIC
522 printf("adosfs: bad file list chain.\n");
523 #endif
524 error = EINVAL;
525 goto reterr;
526 }
527 error = bread(ap->amp->devvp, nb * ap->amp->bsize / DEV_BSIZE,
528 ap->amp->bsize, NOCRED, 0, &flbp);
529 if (error) {
530 brelse(flbp, 0);
531 goto reterr;
532 }
533 if (adoscksum(flbp, ap->nwords)) {
534 #ifdef DIAGNOSTIC
535 printf("adosfs: blk %ld failed cksum.\n", nb);
536 #endif
537 brelse(flbp, 0);
538 error = EINVAL;
539 goto reterr;
540 }
541 /*
542 * update last indirect block cache
543 */
544 ap->lastlindblk = fcnt++;
545 ap->lastindblk = nb;
546
547 nb = adoswordn(flbp, ap->nwords - 2);
548 flblk--;
549 }
550 /*
551 * calculate offset of block number in table. The table starts
552 * at nwords - 51 and goes to offset 6 or less if indicated by the
553 * valid table entries stored at offset ADBI_NBLKTABENT.
554 */
555 flblkoff = bn % ANODENDATBLKENT(ap);
556 if (flblkoff < adoswordn(flbp, 2 /* ADBI_NBLKTABENT */)) {
557 flblkoff = (ap->nwords - 51) - flblkoff;
558 *bnp = adoswordn(flbp, flblkoff) * ap->amp->bsize / DEV_BSIZE;
559 } else {
560 #ifdef DIAGNOSTIC
561 printf("flblk offset %ld too large in lblk %ld blk %" PRId64 "\n",
562 flblkoff, (long)bn, flbp->b_blkno);
563 #endif
564 error = EINVAL;
565 }
566 brelse(flbp, 0);
567 reterr:
568 #ifdef ADOSFS_DIAGNOSTIC
569 if (error == 0 && bnp)
570 printf(" %lld => %lld", (long long)bn, (long long)*bnp);
571 printf(" %d)\n", error);
572 #endif
573 return(error);
574 }
575
576 /*
577 * Print out the contents of a adosfs vnode.
578 */
579 /* ARGSUSED */
580 int
581 adosfs_print(v)
582 void *v;
583 {
584 #if 0
585 struct vop_print_args /* {
586 struct vnode *a_vp;
587 } */ *sp = v;
588 #endif
589 return(0);
590 }
591
592 int
593 adosfs_readdir(v)
594 void *v;
595 {
596 struct vop_readdir_args /* {
597 struct vnode *a_vp;
598 struct uio *a_uio;
599 kauth_cred_t a_cred;
600 int *a_eofflag;
601 off_t **a_cookies;
602 int *a_ncookies;
603 } */ *sp = v;
604 int error, first, useri, chainc, hashi, scanned;
605 u_long nextbn;
606 struct dirent ad, *adp;
607 struct anode *pap, *ap;
608 struct vnode *vp;
609 struct uio *uio = sp->a_uio;
610 off_t uoff = uio->uio_offset;
611 off_t *cookies = NULL;
612 int ncookies = 0;
613
614 #ifdef ADOSFS_DIAGNOSTIC
615 advopprint(sp);
616 #endif
617
618 if (sp->a_vp->v_type != VDIR) {
619 error = ENOTDIR;
620 goto reterr;
621 }
622
623 if (uoff < 0) {
624 error = EINVAL;
625 goto reterr;
626 }
627
628 pap = VTOA(sp->a_vp);
629 adp = &ad;
630 error = nextbn = hashi = chainc = scanned = 0;
631 first = useri = uoff / sizeof ad;
632
633 /*
634 * If offset requested is not on a slot boundary
635 */
636 if (uoff % sizeof ad) {
637 error = EINVAL;
638 goto reterr;
639 }
640
641 for (;;) {
642 if (hashi == pap->ntabent) {
643 *sp->a_eofflag = 1;
644 break;
645 }
646 if (pap->tab[hashi] == 0) {
647 hashi++;
648 continue;
649 }
650 if (nextbn == 0)
651 nextbn = pap->tab[hashi];
652
653 /*
654 * First determine if we can skip this chain
655 */
656 if (chainc == 0) {
657 int skip;
658
659 skip = useri - scanned;
660 if (pap->tabi[hashi] > 0 && pap->tabi[hashi] <= skip) {
661 scanned += pap->tabi[hashi];
662 hashi++;
663 nextbn = 0;
664 continue;
665 }
666 }
667
668 /*
669 * Now [continue to] walk the chain
670 */
671 ap = NULL;
672 do {
673 error = VFS_VGET(pap->amp->mp, (ino_t)nextbn, &vp);
674 if (error)
675 goto reterr;
676 ap = VTOA(vp);
677 scanned++;
678 chainc++;
679 nextbn = ap->hashf;
680
681 /*
682 * check for end of chain.
683 */
684 if (nextbn == 0) {
685 pap->tabi[hashi] = chainc;
686 hashi++;
687 chainc = 0;
688 } else if (pap->tabi[hashi] <= 0 &&
689 -chainc < pap->tabi[hashi])
690 pap->tabi[hashi] = -chainc;
691
692 if (useri >= scanned) {
693 vput(vp);
694 ap = NULL;
695 }
696 } while (ap == NULL && nextbn != 0);
697
698 /*
699 * We left the loop but without a result so do main over.
700 */
701 if (ap == NULL)
702 continue;
703 /*
704 * Fill in dirent record
705 */
706 memset(adp, 0, sizeof *adp);
707 adp->d_fileno = ap->block;
708 /*
709 * This deserves a function in kern/vfs_subr.c
710 */
711 switch (ATOV(ap)->v_type) {
712 case VREG:
713 adp->d_type = DT_REG;
714 break;
715 case VDIR:
716 adp->d_type = DT_DIR;
717 break;
718 case VLNK:
719 adp->d_type = DT_LNK;
720 break;
721 default:
722 adp->d_type = DT_UNKNOWN;
723 break;
724 }
725 adp->d_namlen = strlen(ap->name);
726 memcpy(adp->d_name, ap->name, adp->d_namlen);
727 adp->d_reclen = _DIRENT_SIZE(adp);
728 vput(vp);
729
730 if (adp->d_reclen > uio->uio_resid) {
731 if (useri == first) /* no room for even one entry */
732 error = EINVAL;
733 break;
734 }
735 error = uiomove(adp, adp->d_reclen, uio);
736 if (error)
737 break;
738 useri++;
739 }
740 ncookies = useri - first;
741 uio->uio_offset = uoff + ncookies * sizeof ad;
742 reterr:
743 #ifdef ADOSFS_DIAGNOSTIC
744 printf(" %d)", error);
745 #endif
746 if (sp->a_ncookies != NULL) {
747 *sp->a_ncookies = ncookies;
748 if (!error) {
749 *sp->a_cookies = cookies =
750 malloc(ncookies * sizeof *cookies, M_TEMP, M_WAITOK);
751
752 while (ncookies--) {
753 uoff += sizeof ad;
754 *cookies++ = uoff;
755 }
756 } else
757 *sp->a_cookies = NULL;
758 }
759
760 return(error);
761 }
762
763
764 int
765 adosfs_access(v)
766 void *v;
767 {
768 struct vop_access_args /* {
769 struct vnode *a_vp;
770 int a_mode;
771 kauth_cred_t a_cred;
772 } */ *sp = v;
773 struct anode *ap;
774 struct vnode *vp = sp->a_vp;
775 int error;
776
777 #ifdef ADOSFS_DIAGNOSTIC
778 advopprint(sp);
779 #endif
780
781 ap = VTOA(vp);
782 #ifdef DIAGNOSTIC
783 if (!VOP_ISLOCKED(vp)) {
784 vprint("adosfs_access: not locked", sp->a_vp);
785 panic("adosfs_access: not locked");
786 }
787 #endif
788 /*
789 * Disallow write attempts unless the file is a socket,
790 * fifo, or a block or character device resident on the
791 * file system.
792 */
793 if (sp->a_mode & VWRITE) {
794 switch (vp->v_type) {
795 case VDIR:
796 case VLNK:
797 case VREG:
798 return (EROFS);
799 default:
800 break;
801 }
802 }
803 #ifdef QUOTA
804 #endif
805 error = vaccess(sp->a_vp->v_type, adunixprot(ap->adprot) & ap->amp->mask,
806 ap->uid, ap->gid, sp->a_mode, sp->a_cred);
807 #ifdef ADOSFS_DIAGNOSTIC
808 printf(" %d)", error);
809 #endif
810 return(error);
811 }
812
813 int
814 adosfs_readlink(v)
815 void *v;
816 {
817 struct vop_readlink_args /* {
818 struct vnode *a_vp;
819 struct uio *a_uio;
820 kauth_cred_t a_cred;
821 } */ *sp = v;
822 struct anode *ap;
823 int error;
824
825 #ifdef ADOSFS_DIAGNOSTIC
826 advopprint(sp);
827 #endif
828 ap = VTOA(sp->a_vp);
829 error = uiomove(ap->slinkto, strlen(ap->slinkto), sp->a_uio);
830 #ifdef ADOSFS_DIAGNOSTIC
831 printf(" %d)", error);
832 #endif
833 return (error);
834 }
835
836 /*ARGSUSED*/
837 int
838 adosfs_inactive(v)
839 void *v;
840 {
841 struct vop_inactive_args /* {
842 struct vnode *a_vp;
843 bool *a_recycle;
844 } */ *sp = v;
845 struct vnode *vp = sp->a_vp;
846 #ifdef ADOSFS_DIAGNOSTIC
847 advopprint(sp);
848 #endif
849 VOP_UNLOCK(vp, 0);
850 /* XXX this needs to check if file was deleted */
851 *sp->a_recycle = true;
852
853 #ifdef ADOSFS_DIAGNOSTIC
854 printf(" 0)");
855 #endif
856 return(0);
857 }
858
859 /*
860 * the kernel wants its vnode back.
861 * no lock needed we are being called from vclean()
862 */
863 int
864 adosfs_reclaim(v)
865 void *v;
866 {
867 struct vop_reclaim_args /* {
868 struct vnode *a_vp;
869 } */ *sp = v;
870 struct vnode *vp;
871 struct anode *ap;
872
873 #ifdef ADOSFS_DIAGNOSTIC
874 printf("(reclaim 0)");
875 #endif
876 vp = sp->a_vp;
877 ap = VTOA(vp);
878 LIST_REMOVE(ap, link);
879 cache_purge(vp);
880 if (vp->v_type == VDIR && ap->tab)
881 free(ap->tab, M_ANODE);
882 else if (vp->v_type == VLNK && ap->slinkto)
883 free(ap->slinkto, M_ANODE);
884 genfs_node_destroy(vp);
885 pool_put(&adosfs_node_pool, ap);
886 vp->v_data = NULL;
887 return(0);
888 }
889
890 /*
891 * POSIX pathconf info, grabbed from kern/u fs, probably need to
892 * investigate exactly what each return type means as they are probably
893 * not valid currently
894 */
895 int
896 adosfs_pathconf(v)
897 void *v;
898 {
899 struct vop_pathconf_args /* {
900 struct vnode *a_vp;
901 int a_name;
902 register_t *a_retval;
903 } */ *ap = v;
904
905 switch (ap->a_name) {
906 case _PC_LINK_MAX:
907 *ap->a_retval = LINK_MAX;
908 return (0);
909 case _PC_NAME_MAX:
910 *ap->a_retval = ap->a_vp->v_mount->mnt_stat.f_namemax;
911 return (0);
912 case _PC_PATH_MAX:
913 *ap->a_retval = PATH_MAX;
914 return (0);
915 case _PC_PIPE_BUF:
916 *ap->a_retval = PIPE_BUF;
917 return (0);
918 case _PC_CHOWN_RESTRICTED:
919 *ap->a_retval = 1;
920 return (0);
921 case _PC_VDISABLE:
922 *ap->a_retval = _POSIX_VDISABLE;
923 return (0);
924 case _PC_SYNC_IO:
925 *ap->a_retval = 1;
926 return (0);
927 case _PC_FILESIZEBITS:
928 *ap->a_retval = 32;
929 return (0);
930 default:
931 return (EINVAL);
932 }
933 /* NOTREACHED */
934 }
935