advfsops.c revision 1.7 1 /* $NetBSD: advfsops.c,v 1.7 2003/06/29 18:53:52 thorpej 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: advfsops.c,v 1.7 2003/06/29 18:53:52 thorpej Exp $");
36
37 #if defined(_KERNEL_OPT)
38 #include "opt_compat_netbsd.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/proc.h>
46 #include <sys/time.h>
47 #include <sys/malloc.h>
48 #include <sys/pool.h>
49 #include <sys/disklabel.h>
50 #include <miscfs/specfs/specdev.h> /* XXX */
51 #include <sys/fcntl.h>
52 #include <sys/namei.h>
53 #include <sys/ioctl.h>
54 #include <sys/queue.h>
55 #include <sys/buf.h>
56 #include <sys/conf.h>
57 #include <fs/adosfs/adosfs.h>
58
59 void adosfs_init __P((void));
60 void adosfs_reinit __P((void));
61 void adosfs_done __P((void));
62 int adosfs_mount __P((struct mount *, const char *, void *, struct nameidata *,
63 struct lwp *));
64 int adosfs_start __P((struct mount *, int, struct lwp *));
65 int adosfs_unmount __P((struct mount *, int, struct lwp *));
66 int adosfs_root __P((struct mount *, struct vnode **));
67 int adosfs_quotactl __P((struct mount *, int, uid_t, caddr_t, struct lwp *));
68 int adosfs_statfs __P((struct mount *, struct statfs *, struct lwp *));
69 int adosfs_sync __P((struct mount *, int, struct ucred *, struct lwp *));
70 int adosfs_vget __P((struct mount *, ino_t, struct vnode **));
71 int adosfs_fhtovp __P((struct mount *, struct fid *, struct vnode **));
72 int adosfs_checkexp __P((struct mount *, struct mbuf *, int *,
73 struct ucred **));
74 int adosfs_vptofh __P((struct vnode *, struct fid *));
75
76 int adosfs_mountfs __P((struct vnode *, struct mount *, struct lwp *));
77 int adosfs_loadbitmap __P((struct adosfsmount *));
78 int adosfs_sysctl __P((int *, u_int, void *, size_t *, void *, size_t,
79 struct lwp *));
80
81 struct simplelock adosfs_hashlock;
82
83 struct pool adosfs_node_pool;
84
85 MALLOC_DEFINE(M_ADOSFSMNT, "adosfs mount", "adosfs mount structures");
86 MALLOC_DEFINE(M_ANODE, "adosfs anode", "adosfs anode structures and tables");
87 MALLOC_DEFINE(M_ADOSFSBITMAP, "adosfs bitmap", "adosfs bitmap");
88
89 struct genfs_ops adosfs_genfsops = {
90 genfs_size,
91 };
92
93 int (**adosfs_vnodeop_p) __P((void *));
94
95 int
96 adosfs_mount(mp, path, data, ndp, l)
97 struct mount *mp;
98 const char *path;
99 void *data;
100 struct nameidata *ndp;
101 struct lwp *l;
102 {
103 struct vnode *devvp;
104 struct adosfs_args args;
105 struct adosfsmount *amp;
106 struct proc *p = l->l_proc;
107 int error;
108 mode_t accessmode;
109
110 if (mp->mnt_flag & MNT_GETARGS) {
111 amp = VFSTOADOSFS(mp);
112 if (amp == NULL)
113 return EIO;
114 args.uid = amp->uid;
115 args.gid = amp->gid;
116 args.mask = amp->mask;
117 args.fspec = NULL;
118 vfs_showexport(mp, &args.export, &->export);
119 return copyout(&args, data, sizeof(args));
120 }
121 error = copyin(data, &args, sizeof(struct adosfs_args));
122 if (error)
123 return(error);
124
125 if ((mp->mnt_flag & MNT_RDONLY) == 0)
126 return (EROFS);
127 /*
128 * If updating, check whether changing from read-only to
129 * read/write; if there is no device name, that's all we do.
130 */
131 if (mp->mnt_flag & MNT_UPDATE) {
132 amp = VFSTOADOSFS(mp);
133 if (args.fspec == 0)
134 return (vfs_export(mp, &->export, &args.export));
135 }
136 /*
137 * Not an update, or updating the name: look up the name
138 * and verify that it refers to a sensible block device.
139 */
140 NDINIT(ndp, LOOKUP, FOLLOW, UIO_USERSPACE, args.fspec, l);
141 if ((error = namei(ndp)) != 0)
142 return (error);
143 devvp = ndp->ni_vp;
144
145 if (devvp->v_type != VBLK) {
146 vrele(devvp);
147 return (ENOTBLK);
148 }
149 if (bdevsw_lookup(devvp->v_rdev) == NULL) {
150 vrele(devvp);
151 return (ENXIO);
152 }
153 /*
154 * If mount by non-root, then verify that user has necessary
155 * permissions on the device.
156 */
157 if (p->p_ucred->cr_uid != 0) {
158 accessmode = VREAD;
159 if ((mp->mnt_flag & MNT_RDONLY) == 0)
160 accessmode |= VWRITE;
161 vn_lock(devvp, LK_EXCLUSIVE | LK_RETRY);
162 error = VOP_ACCESS(devvp, accessmode, p->p_ucred, l);
163 if (error) {
164 vput(devvp);
165 return (error);
166 }
167 VOP_UNLOCK(devvp, 0);
168 }
169 /* MNT_UPDATE? */
170 if ((error = adosfs_mountfs(devvp, mp, l)) != 0) {
171 vrele(devvp);
172 return (error);
173 }
174 amp = VFSTOADOSFS(mp);
175 amp->uid = args.uid;
176 amp->gid = args.gid;
177 amp->mask = args.mask;
178 return set_statfs_info(path, UIO_USERSPACE, args.fspec, UIO_USERSPACE,
179 mp, l);
180 }
181
182 int
183 adosfs_mountfs(devvp, mp, l)
184 struct vnode *devvp;
185 struct mount *mp;
186 struct lwp *l;
187 {
188 struct proc *p = l->l_proc;
189 struct disklabel dl;
190 struct partition *parp;
191 struct adosfsmount *amp;
192 struct buf *bp;
193 struct vnode *rvp;
194 int error, part, i;
195
196 part = DISKPART(devvp->v_rdev);
197 amp = NULL;
198
199 /*
200 * Disallow multiple mounts of the same device.
201 * Disallow mounting of a device that is currently in use
202 * (except for root, which might share swap device for miniroot).
203 * Flush out any old buffers remaining from a previous use.
204 */
205 if ((error = vfs_mountedon(devvp)) != 0)
206 return (error);
207 if (vcount(devvp) > 1 && devvp != rootvp)
208 return (EBUSY);
209 if ((error = vinvalbuf(devvp, V_SAVE, p->p_ucred, l, 0, 0)) != 0)
210 return (error);
211
212 /*
213 * open blkdev and read root block
214 */
215 if ((error = VOP_OPEN(devvp, FREAD, NOCRED, l)) != 0)
216 return (error);
217 error = VOP_IOCTL(devvp, DIOCGDINFO, &dl, FREAD, NOCRED, l);
218 if (error)
219 goto fail;
220
221 parp = &dl.d_partitions[part];
222 amp = malloc(sizeof(struct adosfsmount), M_ADOSFSMNT, M_WAITOK);
223 memset((char *)amp, 0, (u_long)sizeof(struct adosfsmount));
224 amp->mp = mp;
225 if (dl.d_type == DTYPE_FLOPPY) {
226 amp->bsize = dl.d_secsize;
227 amp->secsperblk = 1;
228 }
229 else {
230 amp->bsize = parp->p_fsize * parp->p_frag;
231 amp->secsperblk = parp->p_frag;
232 }
233
234 /* invalid fs ? */
235 if (amp->secsperblk == 0) {
236 error = EINVAL;
237 goto fail;
238 }
239
240 bp = NULL;
241 if ((error = bread(devvp, (daddr_t)BBOFF,
242 amp->bsize, NOCRED, &bp)) != 0) {
243 brelse(bp);
244 goto fail;
245 }
246 amp->dostype = adoswordn(bp, 0);
247 brelse(bp);
248
249 /* basic sanity checks */
250 if (amp->dostype < 0x444f5300 || amp->dostype > 0x444f5305) {
251 error = EINVAL;
252 goto fail;
253 }
254
255 amp->rootb = (parp->p_size / amp->secsperblk - 1 + parp->p_cpg) >> 1;
256 amp->numblks = parp->p_size / amp->secsperblk - parp->p_cpg;
257
258 amp->nwords = amp->bsize >> 2;
259 amp->dbsize = amp->bsize - (IS_FFS(amp) ? 0 : OFS_DATA_OFFSET);
260 amp->devvp = devvp;
261
262 mp->mnt_data = amp;
263 mp->mnt_stat.f_fsid.val[0] = (long)devvp->v_rdev;
264 mp->mnt_stat.f_fsid.val[1] = makefstype(MOUNT_ADOSFS);
265 mp->mnt_fs_bshift = ffs(amp->bsize) - 1;
266 mp->mnt_dev_bshift = DEV_BSHIFT; /* XXX */
267 mp->mnt_flag |= MNT_LOCAL;
268
269 /*
270 * init anode table.
271 */
272 for (i = 0; i < ANODEHASHSZ; i++)
273 LIST_INIT(&->anodetab[i]);
274
275 /*
276 * get the root anode, if not a valid fs this will fail.
277 */
278 if ((error = VFS_ROOT(mp, &rvp)) != 0)
279 goto fail;
280 /* allocate and load bitmap, set free space */
281 amp->bitmap = malloc(((amp->numblks + 31) / 32) * sizeof(*amp->bitmap),
282 M_ADOSFSBITMAP, M_WAITOK);
283 if (amp->bitmap)
284 adosfs_loadbitmap(amp);
285 if (mp->mnt_flag & MNT_RDONLY && amp->bitmap) {
286 /*
287 * Don't need the bitmap any more if it's read-only.
288 */
289 free(amp->bitmap, M_ADOSFSBITMAP);
290 amp->bitmap = NULL;
291 }
292 vput(rvp);
293
294 return(0);
295
296 fail:
297 vn_lock(devvp, LK_EXCLUSIVE | LK_RETRY);
298 (void) VOP_CLOSE(devvp, FREAD, NOCRED, l);
299 VOP_UNLOCK(devvp, 0);
300 if (amp && amp->bitmap)
301 free(amp->bitmap, M_ADOSFSBITMAP);
302 if (amp)
303 free(amp, M_ADOSFSMNT);
304 return (error);
305 }
306
307 int
308 adosfs_start(mp, flags, l)
309 struct mount *mp;
310 int flags;
311 struct lwp *l;
312 {
313
314 return (0);
315 }
316
317 int
318 adosfs_unmount(mp, mntflags, l)
319 struct mount *mp;
320 int mntflags;
321 struct lwp *l;
322 {
323 struct adosfsmount *amp;
324 int error, flags;
325
326 flags = 0;
327 if (mntflags & MNT_FORCE)
328 flags |= FORCECLOSE;
329 if ((error = vflush(mp, NULLVP, flags)) != 0)
330 return (error);
331 amp = VFSTOADOSFS(mp);
332 if (amp->devvp->v_type != VBAD)
333 amp->devvp->v_specmountpoint = NULL;
334 vn_lock(amp->devvp, LK_EXCLUSIVE | LK_RETRY);
335 error = VOP_CLOSE(amp->devvp, FREAD, NOCRED, l);
336 vput(amp->devvp);
337 if (amp->bitmap)
338 free(amp->bitmap, M_ADOSFSBITMAP);
339 free(amp, M_ADOSFSMNT);
340 mp->mnt_data = NULL;
341 mp->mnt_flag &= ~MNT_LOCAL;
342 return (error);
343 }
344
345 int
346 adosfs_root(mp, vpp)
347 struct mount *mp;
348 struct vnode **vpp;
349 {
350 struct vnode *nvp;
351 int error;
352
353 if ((error = VFS_VGET(mp, (ino_t)VFSTOADOSFS(mp)->rootb, &nvp)) != 0)
354 return (error);
355 /* XXX verify it's a root block? */
356 *vpp = nvp;
357 return (0);
358 }
359
360 int
361 adosfs_statfs(mp, sbp, l)
362 struct mount *mp;
363 struct statfs *sbp;
364 struct lwp *l;
365 {
366 struct adosfsmount *amp;
367
368 amp = VFSTOADOSFS(mp);
369 #ifdef COMPAT_09
370 sbp->f_type = 16;
371 #else
372 sbp->f_type = 0;
373 #endif
374 sbp->f_bsize = amp->bsize;
375 sbp->f_iosize = amp->dbsize;
376 sbp->f_blocks = amp->numblks;
377 sbp->f_bfree = amp->freeblks;
378 sbp->f_bavail = amp->freeblks;
379 sbp->f_files = 0; /* who knows */
380 sbp->f_ffree = 0; /* " " */
381 copy_statfs_info(sbp, mp);
382 return (0);
383 }
384
385 /*
386 * lookup an anode, check mount's hash table if not found, create
387 * return locked and referenced al la vget(vp, 1);
388 */
389 int
390 adosfs_vget(mp, an, vpp)
391 struct mount *mp;
392 ino_t an;
393 struct vnode **vpp;
394 {
395 struct adosfsmount *amp;
396 struct vnode *vp;
397 struct anode *ap;
398 struct buf *bp;
399 char *nam, *tmp;
400 int namlen, error;
401
402 error = 0;
403 amp = VFSTOADOSFS(mp);
404 bp = NULL;
405
406 /*
407 * check hash table. we are done if found
408 */
409 if ((*vpp = adosfs_ahashget(mp, an)) != NULL)
410 return (0);
411
412 error = getnewvnode(VT_ADOSFS, mp, adosfs_vnodeop_p, &vp);
413 if (error)
414 return (error);
415
416 /*
417 * setup, insert in hash, and lock before io.
418 */
419 vp->v_data = ap = pool_get(&adosfs_node_pool, PR_WAITOK);
420 memset(ap, 0, sizeof(struct anode));
421 ap->vp = vp;
422 ap->amp = amp;
423 ap->block = an;
424 ap->nwords = amp->nwords;
425 adosfs_ainshash(amp, ap);
426
427 if ((error = bread(amp->devvp, an * amp->bsize / DEV_BSIZE,
428 amp->bsize, NOCRED, &bp)) != 0) {
429 brelse(bp);
430 vput(vp);
431 return (error);
432 }
433
434 /*
435 * get type and fill rest in based on that.
436 */
437 switch (ap->type = adosfs_getblktype(amp, bp)) {
438 case AROOT:
439 vp->v_type = VDIR;
440 vp->v_flag |= VROOT;
441 ap->mtimev.days = adoswordn(bp, ap->nwords - 10);
442 ap->mtimev.mins = adoswordn(bp, ap->nwords - 9);
443 ap->mtimev.ticks = adoswordn(bp, ap->nwords - 8);
444 ap->created.days = adoswordn(bp, ap->nwords - 7);
445 ap->created.mins = adoswordn(bp, ap->nwords - 6);
446 ap->created.ticks = adoswordn(bp, ap->nwords - 5);
447 break;
448 case ALDIR:
449 case ADIR:
450 vp->v_type = VDIR;
451 break;
452 case ALFILE:
453 case AFILE:
454 vp->v_type = VREG;
455 ap->fsize = adoswordn(bp, ap->nwords - 47);
456 break;
457 case ASLINK: /* XXX soft link */
458 vp->v_type = VLNK;
459 /*
460 * convert from BCPL string and
461 * from: "part:dir/file" to: "/part/dir/file"
462 */
463 nam = bp->b_data + (6 * sizeof(long));
464 namlen = strlen(nam);
465 tmp = nam;
466 while (*tmp && *tmp != ':')
467 tmp++;
468 if (*tmp == 0) {
469 ap->slinkto = malloc(namlen + 1, M_ANODE, M_WAITOK);
470 memcpy(ap->slinkto, nam, namlen);
471 } else if (*nam == ':') {
472 ap->slinkto = malloc(namlen + 1, M_ANODE, M_WAITOK);
473 memcpy(ap->slinkto, nam, namlen);
474 ap->slinkto[0] = '/';
475 } else {
476 ap->slinkto = malloc(namlen + 2, M_ANODE, M_WAITOK);
477 ap->slinkto[0] = '/';
478 memcpy(&ap->slinkto[1], nam, namlen);
479 ap->slinkto[tmp - nam + 1] = '/';
480 namlen++;
481 }
482 ap->slinkto[namlen] = 0;
483 ap->fsize = namlen;
484 break;
485 default:
486 brelse(bp);
487 vput(vp);
488 return (EINVAL);
489 }
490
491 /*
492 * Get appropriate data from this block; hard link needs
493 * to get other data from the "real" block.
494 */
495
496 /*
497 * copy in name (from original block)
498 */
499 nam = bp->b_data + (ap->nwords - 20) * sizeof(u_int32_t);
500 namlen = *(u_char *)nam++;
501 if (namlen > 30) {
502 #ifdef DIAGNOSTIC
503 printf("adosfs: aget: name length too long blk %d\n", an);
504 #endif
505 brelse(bp);
506 vput(vp);
507 return (EINVAL);
508 }
509 memcpy(ap->name, nam, namlen);
510 ap->name[namlen] = 0;
511
512 /*
513 * if dir alloc hash table and copy it in
514 */
515 if (vp->v_type == VDIR) {
516 int i;
517
518 ap->tab = malloc(ANODETABSZ(ap) * 2, M_ANODE, M_WAITOK);
519 ap->ntabent = ANODETABENT(ap);
520 ap->tabi = (int *)&ap->tab[ap->ntabent];
521 memset(ap->tabi, 0, ANODETABSZ(ap));
522 for (i = 0; i < ap->ntabent; i++)
523 ap->tab[i] = adoswordn(bp, i + 6);
524 }
525
526 /*
527 * misc.
528 */
529 ap->pblock = adoswordn(bp, ap->nwords - 3);
530 ap->hashf = adoswordn(bp, ap->nwords - 4);
531 ap->linknext = adoswordn(bp, ap->nwords - 10);
532 ap->linkto = adoswordn(bp, ap->nwords - 11);
533
534 /*
535 * setup last indirect block cache.
536 */
537 ap->lastlindblk = 0;
538 if (ap->type == AFILE) {
539 ap->lastindblk = ap->block;
540 if (adoswordn(bp, ap->nwords - 10))
541 ap->linkto = ap->block;
542 } else if (ap->type == ALFILE) {
543 ap->lastindblk = ap->linkto;
544 brelse(bp);
545 bp = NULL;
546 error = bread(amp->devvp, ap->linkto * amp->bsize / DEV_BSIZE,
547 amp->bsize, NOCRED, &bp);
548 if (error) {
549 brelse(bp);
550 vput(vp);
551 return (error);
552 }
553 ap->fsize = adoswordn(bp, ap->nwords - 47);
554 /*
555 * Should ap->block be set to the real file header block?
556 */
557 ap->block = ap->linkto;
558 }
559
560 if (ap->type == AROOT) {
561 ap->adprot = 15;
562 ap->uid = amp->uid;
563 ap->gid = amp->gid;
564 } else {
565 ap->adprot = adoswordn(bp, ap->nwords - 48) ^ 15;
566 /*
567 * ADOS directories do not have a `x' protection bit as
568 * it is known in VFS; this functionality is fulfilled
569 * by the ADOS `r' bit.
570 *
571 * To retain the ADOS behaviour, fake execute permissions
572 * in that case.
573 */
574 if ((ap->type == ADIR || ap->type == ALDIR) &&
575 (ap->adprot & 0x00000008) == 0)
576 ap->adprot &= ~0x00000002;
577
578 /*
579 * Get uid/gid from extensions in file header
580 * (really need to know if this is a muFS partition)
581 */
582 ap->uid = (adoswordn(bp, ap->nwords - 49) >> 16) & 0xffff;
583 ap->gid = adoswordn(bp, ap->nwords - 49) & 0xffff;
584 if (ap->uid || ap->gid) {
585 if (ap->uid == 0xffff)
586 ap->uid = 0;
587 if (ap->gid == 0xffff)
588 ap->gid = 0;
589 ap->adprot |= 0x40000000; /* Kludge */
590 }
591 else {
592 /*
593 * uid & gid extension don't exist,
594 * so use the mount-point uid/gid
595 */
596 ap->uid = amp->uid;
597 ap->gid = amp->gid;
598 }
599 }
600 ap->mtime.days = adoswordn(bp, ap->nwords - 23);
601 ap->mtime.mins = adoswordn(bp, ap->nwords - 22);
602 ap->mtime.ticks = adoswordn(bp, ap->nwords - 21);
603
604 genfs_node_init(vp, &adosfs_genfsops);
605 *vpp = vp;
606 brelse(bp);
607 vp->v_size = ap->fsize;
608 return (0);
609 }
610
611 /*
612 * Load the bitmap into memory, and count the number of available
613 * blocks.
614 * The bitmap will be released if the filesystem is read-only; it's
615 * only needed to find the free space.
616 */
617 int
618 adosfs_loadbitmap(amp)
619 struct adosfsmount *amp;
620 {
621 struct buf *bp, *mapbp;
622 u_long bn;
623 int blkix, endix, mapix;
624 int bmsize;
625 int error;
626
627 bp = mapbp = NULL;
628 bn = amp->rootb;
629 if ((error = bread(amp->devvp, bn * amp->bsize / DEV_BSIZE, amp->bsize,
630 NOCRED, &bp)) != 0) {
631 brelse(bp);
632 return (error);
633 }
634 blkix = amp->nwords - 49;
635 endix = amp->nwords - 24;
636 mapix = 0;
637 bmsize = (amp->numblks + 31) / 32;
638 while (mapix < bmsize) {
639 int n;
640 u_long bits;
641
642 if (adoswordn(bp, blkix) == 0)
643 break;
644 if (mapbp != NULL)
645 brelse(mapbp);
646 if ((error = bread(amp->devvp,
647 adoswordn(bp, blkix) * amp->bsize / DEV_BSIZE, amp->bsize,
648 NOCRED, &mapbp)) != 0)
649 break;
650 if (adoscksum(mapbp, amp->nwords)) {
651 #ifdef DIAGNOSTIC
652 printf("adosfs: loadbitmap - cksum of blk %d failed\n",
653 adoswordn(bp, blkix));
654 #endif
655 /* XXX Force read-only? Set free space 0? */
656 break;
657 }
658 n = 1;
659 while (n < amp->nwords && mapix < bmsize) {
660 amp->bitmap[mapix++] = bits = adoswordn(mapbp, n);
661 ++n;
662 if (mapix == bmsize && amp->numblks & 31)
663 bits &= ~(0xffffffff << (amp->numblks & 31));
664 while (bits) {
665 if (bits & 1)
666 ++amp->freeblks;
667 bits >>= 1;
668 }
669 }
670 ++blkix;
671 if (mapix < bmsize && blkix == endix) {
672 bn = adoswordn(bp, blkix);
673 brelse(bp);
674 if ((error = bread(amp->devvp, bn * amp->bsize / DEV_BSIZE,
675 amp->bsize, NOCRED, &bp)) != 0)
676 break;
677 /*
678 * Why is there no checksum on these blocks?
679 */
680 blkix = 0;
681 endix = amp->nwords - 1;
682 }
683 }
684 if (bp)
685 brelse(bp);
686 if (mapbp)
687 brelse(mapbp);
688 return (error);
689 }
690
691
692 /*
693 * File handle to vnode
694 *
695 * Have to be really careful about stale file handles:
696 * - check that the inode number is in range
697 * - call iget() to get the locked inode
698 * - check for an unallocated inode (i_mode == 0)
699 * - check that the generation number matches
700 */
701
702 struct ifid {
703 ushort ifid_len;
704 ushort ifid_pad;
705 int ifid_ino;
706 long ifid_start;
707 };
708
709 int
710 adosfs_fhtovp(mp, fhp, vpp)
711 struct mount *mp;
712 struct fid *fhp;
713 struct vnode **vpp;
714 {
715 struct ifid *ifhp = (struct ifid *)fhp;
716 #if 0
717 struct anode *ap;
718 #endif
719 struct vnode *nvp;
720 int error;
721
722 #ifdef ADOSFS_DIAGNOSTIC
723 printf("adfhtovp(%x, %x, %x)\n", mp, fhp, vpp);
724 #endif
725
726 if ((error = VFS_VGET(mp, ifhp->ifid_ino, &nvp)) != 0) {
727 *vpp = NULLVP;
728 return (error);
729 }
730 #if 0
731 ap = VTOA(nvp);
732 if (ap->inode.iso_mode == 0) {
733 vput(nvp);
734 *vpp = NULLVP;
735 return (ESTALE);
736 }
737 #endif
738 *vpp = nvp;
739 return(0);
740 }
741
742 int
743 adosfs_checkexp(mp, nam, exflagsp, credanonp)
744 struct mount *mp;
745 struct mbuf *nam;
746 int *exflagsp;
747 struct ucred **credanonp;
748 {
749 struct adosfsmount *amp = VFSTOADOSFS(mp);
750 #if 0
751 struct anode *ap;
752 #endif
753 struct netcred *np;
754
755 #ifdef ADOSFS_DIAGNOSTIC
756 printf("adcheckexp(%x, %x, %x)\n", mp, nam, exflagsp);
757 #endif
758
759 /*
760 * Get the export permission structure for this <mp, client> tuple.
761 */
762 np = vfs_export_lookup(mp, &->export, nam);
763 if (np == NULL)
764 return (EACCES);
765
766 *exflagsp = np->netc_exflags;
767 *credanonp = &np->netc_anon;
768 return(0);
769 }
770
771 int
772 adosfs_vptofh(vp, fhp)
773 struct vnode *vp;
774 struct fid *fhp;
775 {
776 struct anode *ap = VTOA(vp);
777 struct ifid *ifhp;
778
779 ifhp = (struct ifid *)fhp;
780 ifhp->ifid_len = sizeof(struct ifid);
781
782 ifhp->ifid_ino = ap->block;
783 ifhp->ifid_start = ap->block;
784
785 #ifdef ADOSFS_DIAGNOSTIC
786 printf("advptofh(%x, %x)\n", vp, fhp);
787 #endif
788 return(0);
789 }
790
791 int
792 adosfs_quotactl(mp, cmds, uid, arg, l)
793 struct mount *mp;
794 int cmds;
795 uid_t uid;
796 caddr_t arg;
797 struct lwp *l;
798 {
799 return(EOPNOTSUPP);
800 }
801
802 int
803 adosfs_sync(mp, waitfor, uc, l)
804 struct mount *mp;
805 int waitfor;
806 struct ucred *uc;
807 struct lwp *l;
808 {
809 #ifdef ADOSFS_DIAGNOSTIC
810 printf("ad_sync(%x, %x)\n", mp, waitfor);
811 #endif
812 return(0);
813 }
814
815 void
816 adosfs_init()
817 {
818 simple_lock_init(&adosfs_hashlock);
819
820 pool_init(&adosfs_node_pool, sizeof(struct anode), 0, 0, 0,
821 "adosndpl", &pool_allocator_nointr);
822 }
823
824 void
825 adosfs_done()
826 {
827 pool_destroy(&adosfs_node_pool);
828 }
829
830 int
831 adosfs_sysctl(name, namelen, oldp, oldlenp, newp, newlen, l)
832 int *name;
833 u_int namelen;
834 void *oldp;
835 size_t *oldlenp;
836 void *newp;
837 size_t newlen;
838 struct lwp *l;
839 {
840 return (EOPNOTSUPP);
841 }
842
843 /*
844 * vfs generic function call table
845 */
846
847 extern const struct vnodeopv_desc adosfs_vnodeop_opv_desc;
848
849 const struct vnodeopv_desc *adosfs_vnodeopv_descs[] = {
850 &adosfs_vnodeop_opv_desc,
851 NULL,
852 };
853
854 struct vfsops adosfs_vfsops = {
855 MOUNT_ADOSFS,
856 adosfs_mount,
857 adosfs_start,
858 adosfs_unmount,
859 adosfs_root,
860 adosfs_quotactl,
861 adosfs_statfs,
862 adosfs_sync,
863 adosfs_vget,
864 adosfs_fhtovp,
865 adosfs_vptofh,
866 adosfs_init,
867 NULL,
868 adosfs_done,
869 adosfs_sysctl,
870 NULL, /* vfs_mountroot */
871 adosfs_checkexp,
872 adosfs_vnodeopv_descs,
873 };
874