filecore_vfsops.c revision 1.5.2.3 1 /* $NetBSD: filecore_vfsops.c,v 1.5.2.3 2004/08/03 10:52:24 skrll Exp $ */
2
3 /*-
4 * Copyright (c) 1994 The Regents of the University of California.
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. Neither the name of the University nor the names of its contributors
16 * may be used to endorse or promote products derived from this software
17 * without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * SUCH DAMAGE.
30 *
31 * filecore_vfsops.c 1.1 1998/6/26
32 */
33
34 /*-
35 * Copyright (c) 1998 Andrew McMurry
36 *
37 * Redistribution and use in source and binary forms, with or without
38 * modification, are permitted provided that the following conditions
39 * are met:
40 * 1. Redistributions of source code must retain the above copyright
41 * notice, this list of conditions and the following disclaimer.
42 * 2. Redistributions in binary form must reproduce the above copyright
43 * notice, this list of conditions and the following disclaimer in the
44 * documentation and/or other materials provided with the distribution.
45 * 3. All advertising materials mentioning features or use of this software
46 * must display the following acknowledgement:
47 * This product includes software developed by the University of
48 * California, Berkeley and its contributors.
49 * 4. Neither the name of the University nor the names of its contributors
50 * may be used to endorse or promote products derived from this software
51 * without specific prior written permission.
52 *
53 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
54 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
55 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
56 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
57 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
58 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
59 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
60 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
61 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
62 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
63 * SUCH DAMAGE.
64 *
65 * filecore_vfsops.c 1.1 1998/6/26
66 */
67
68 #include <sys/cdefs.h>
69 __KERNEL_RCSID(0, "$NetBSD: filecore_vfsops.c,v 1.5.2.3 2004/08/03 10:52:24 skrll Exp $");
70
71 #if defined(_KERNEL_OPT)
72 #include "opt_compat_netbsd.h"
73 #endif
74
75 #include <sys/param.h>
76 #include <sys/systm.h>
77 #include <sys/namei.h>
78 #include <sys/proc.h>
79 #include <sys/vnode.h>
80 #include <miscfs/specfs/specdev.h>
81 #include <sys/mount.h>
82 #include <sys/buf.h>
83 #include <sys/file.h>
84 #include <sys/device.h>
85 #include <sys/errno.h>
86 #include <sys/malloc.h>
87 #include <sys/pool.h>
88 #include <sys/conf.h>
89 #include <sys/sysctl.h>
90
91 #include <fs/filecorefs/filecore.h>
92 #include <fs/filecorefs/filecore_extern.h>
93 #include <fs/filecorefs/filecore_node.h>
94 #include <fs/filecorefs/filecore_mount.h>
95
96 MALLOC_DEFINE(M_FILECOREMNT, "filecore mount", "Filecore FS mount structures");
97
98 extern const struct vnodeopv_desc filecore_vnodeop_opv_desc;
99
100 const struct vnodeopv_desc * const filecore_vnodeopv_descs[] = {
101 &filecore_vnodeop_opv_desc,
102 NULL,
103 };
104
105 struct vfsops filecore_vfsops = {
106 MOUNT_FILECORE,
107 filecore_mount,
108 filecore_start,
109 filecore_unmount,
110 filecore_root,
111 filecore_quotactl,
112 filecore_statvfs,
113 filecore_sync,
114 filecore_vget,
115 filecore_fhtovp,
116 filecore_vptofh,
117 filecore_init,
118 filecore_reinit,
119 filecore_done,
120 NULL,
121 NULL, /* filecore_mountroot */
122 filecore_checkexp,
123 (int (*)(struct mount *, struct vnode *, struct timespec *)) eopnotsupp,
124 filecore_vnodeopv_descs,
125 };
126
127 struct genfs_ops filecore_genfsops = {
128 genfs_size,
129 };
130
131 /*
132 * Called by vfs_mountroot when iso is going to be mounted as root.
133 *
134 * Name is updated by mount(8) after booting.
135 */
136
137 static int filecore_mountfs __P((struct vnode *devvp, struct mount *mp,
138 struct lwp *l, struct filecore_args *argp));
139
140 #if 0
141 int
142 filecore_mountroot()
143 {
144 struct mount *mp;
145 extern struct vnode *rootvp;
146 struct proc *p = curproc; /* XXX */
147 int error;
148 struct filecore_args args;
149
150 if (root_device->dv_class != DV_DISK)
151 return (ENODEV);
152
153 /*
154 * Get vnodes for swapdev and rootdev.
155 */
156 if (bdevvp(rootdev, &rootvp))
157 panic("filecore_mountroot: can't setup rootvp");
158
159 if ((error = vfs_rootmountalloc(MOUNT_FILECORE, "root_device", &mp)) != 0)
160 return (error);
161
162 args.flags = FILECOREMNT_ROOT;
163 if ((error = filecore_mountfs(rootvp, mp, p, &args)) != 0) {
164 mp->mnt_op->vfs_refcount--;
165 vfs_unbusy(mp);
166 free(mp, M_MOUNT);
167 return (error);
168 }
169 simple_lock(&mountlist_slock);
170 CIRCLEQ_INSERT_TAIL(&mountlist, mp, mnt_list);
171 simple_unlock(&mountlist_slock);
172 (void)filecore_statvfs(mp, &mp->mnt_stat, p);
173 vfs_unbusy(mp);
174 return (0);
175 }
176 #endif
177
178 /*
179 * VFS Operations.
180 *
181 * mount system call
182 */
183 int
184 filecore_mount(mp, path, data, ndp, l)
185 struct mount *mp;
186 const char *path;
187 void *data;
188 struct nameidata *ndp;
189 struct lwp *l;
190 {
191 struct vnode *devvp;
192 struct filecore_args args;
193 struct proc *p;
194 int error;
195 struct filecore_mnt *fcmp = NULL;
196
197 p = l->l_proc;
198 if (mp->mnt_flag & MNT_GETARGS) {
199 fcmp = VFSTOFILECORE(mp);
200 if (fcmp == NULL)
201 return EIO;
202 args.flags = fcmp->fc_mntflags;
203 args.uid = fcmp->fc_uid;
204 args.gid = fcmp->fc_gid;
205 args.fspec = NULL;
206 vfs_showexport(mp, &args.export, &fcmp->fc_export);
207 return copyout(&args, data, sizeof(args));
208 }
209 error = copyin(data, &args, sizeof (struct filecore_args));
210 if (error)
211 return (error);
212
213 if ((mp->mnt_flag & MNT_RDONLY) == 0)
214 return (EROFS);
215
216 /*
217 * If updating, check whether changing from read-only to
218 * read/write; if there is no device name, that's all we do.
219 */
220 if (mp->mnt_flag & MNT_UPDATE) {
221 fcmp = VFSTOFILECORE(mp);
222 if (args.fspec == 0)
223 return (vfs_export(mp, &fcmp->fc_export, &args.export));
224 }
225 /*
226 * Not an update, or updating the name: look up the name
227 * and verify that it refers to a sensible block device.
228 */
229 NDINIT(ndp, LOOKUP, FOLLOW, UIO_USERSPACE, args.fspec, l);
230 if ((error = namei(ndp)) != 0)
231 return (error);
232 devvp = ndp->ni_vp;
233
234 if (devvp->v_type != VBLK) {
235 vrele(devvp);
236 return ENOTBLK;
237 }
238 if (bdevsw_lookup(devvp->v_rdev) == NULL) {
239 vrele(devvp);
240 return ENXIO;
241 }
242 /*
243 * If mount by non-root, then verify that user has necessary
244 * permissions on the device.
245 */
246 if (p->p_ucred->cr_uid != 0) {
247 vn_lock(devvp, LK_EXCLUSIVE | LK_RETRY);
248 error = VOP_ACCESS(devvp, VREAD, p->p_ucred, l);
249 VOP_UNLOCK(devvp, 0);
250 if (error) {
251 vrele(devvp);
252 return (error);
253 }
254 }
255 if ((mp->mnt_flag & MNT_UPDATE) == 0)
256 error = filecore_mountfs(devvp, mp, l, &args);
257 else {
258 if (devvp != fcmp->fc_devvp)
259 error = EINVAL; /* needs translation */
260 else
261 vrele(devvp);
262 }
263 if (error) {
264 vrele(devvp);
265 return error;
266 }
267 fcmp = VFSTOFILECORE(mp);
268 return set_statvfs_info(path, UIO_USERSPACE, args.fspec, UIO_USERSPACE,
269 mp, l);
270 }
271
272 /*
273 * Common code for mount and mountroot
274 */
275 static int
276 filecore_mountfs(devvp, mp, l, argp)
277 struct vnode *devvp;
278 struct mount *mp;
279 struct lwp *l;
280 struct filecore_args *argp;
281 {
282 struct filecore_mnt *fcmp = (struct filecore_mnt *)0;
283 struct buf *bp = NULL;
284 dev_t dev = devvp->v_rdev;
285 int error = EINVAL;
286 int ronly = (mp->mnt_flag & MNT_RDONLY) != 0;
287 extern struct vnode *rootvp;
288 struct filecore_disc_record *fcdr;
289 unsigned map;
290 unsigned log2secsize;
291
292 if (!ronly)
293 return EROFS;
294
295 /*
296 * Disallow multiple mounts of the same device.
297 * Disallow mounting of a device that is currently in use
298 * (except for root, which might share swap device for miniroot).
299 * Flush out any old buffers remaining from a previous use.
300 */
301 if ((error = vfs_mountedon(devvp)) != 0)
302 return error;
303 if (vcount(devvp) > 1 && devvp != rootvp)
304 return EBUSY;
305 if ((error = vinvalbuf(devvp, V_SAVE, l->l_proc->p_ucred, l, 0, 0))
306 != 0)
307 return (error);
308
309 error = VOP_OPEN(devvp, ronly ? FREAD : FREAD|FWRITE, FSCRED, l);
310 if (error)
311 return error;
312
313 /* Read the filecore boot block to check FS validity and to find the map */
314 error = bread(devvp, FILECORE_BOOTBLOCK_BLKN,
315 FILECORE_BOOTBLOCK_SIZE, NOCRED, &bp);
316 #ifdef FILECORE_DEBUG_BR
317 printf("bread(%p, %x, %d, CRED, %p)=%d\n", devvp,
318 FILECORE_BOOTBLOCK_BLKN, FILECORE_BOOTBLOCK_SIZE,
319 bp, error);
320 #endif
321 if (error != 0)
322 goto out;
323 if (filecore_bbchecksum(bp->b_data) != 0) {
324 error = EINVAL;
325 goto out;
326 }
327 fcdr = (struct filecore_disc_record *)(bp->b_data+FILECORE_BB_DISCREC);
328 map = ((((8 << fcdr->log2secsize) - fcdr->zone_spare)
329 * (fcdr->nzones / 2) - 8 * FILECORE_DISCREC_SIZE)
330 << fcdr->log2bpmb) >> fcdr->log2secsize;
331 log2secsize = fcdr->log2secsize;
332 bp->b_flags |= B_AGE;
333 #ifdef FILECORE_DEBUG_BR
334 printf("brelse(%p) vf1\n", bp);
335 #endif
336 brelse(bp);
337 bp = NULL;
338
339 /* Read the bootblock in the map */
340 error = bread(devvp, map, 1 << log2secsize, NOCRED, &bp);
341 #ifdef FILECORE_DEBUG_BR
342 printf("bread(%p, %x, %d, CRED, %p)=%d\n", devvp,
343 map, 1 << log2secsize, bp, error);
344 #endif
345 if (error != 0)
346 goto out;
347 fcdr = (struct filecore_disc_record *)(bp->b_data + 4);
348 fcmp = malloc(sizeof *fcmp, M_FILECOREMNT, M_WAITOK);
349 memset(fcmp, 0, sizeof *fcmp);
350 if (fcdr->log2bpmb > fcdr->log2secsize)
351 fcmp->log2bsize = fcdr->log2bpmb;
352 else fcmp->log2bsize = fcdr->log2secsize;
353 fcmp->blksize = 1 << fcmp->log2bsize;
354 memcpy(&fcmp->drec, fcdr, sizeof(*fcdr));
355 fcmp->map = map;
356 fcmp->idspz = ((8 << fcdr->log2secsize) - fcdr->zone_spare)
357 / (fcdr->idlen + 1);
358 fcmp->mask = (1 << fcdr->idlen) - 1;
359 if (fcdr->big_flag & 1) {
360 fcmp->nblks = ((((u_int64_t)fcdr->disc_size_2) << 32)
361 + fcdr->disc_size) / fcmp->blksize;
362 } else {
363 fcmp->nblks=fcdr->disc_size / fcmp->blksize;
364 }
365
366 bp->b_flags |= B_AGE;
367 #ifdef FILECORE_DEBUG_BR
368 printf("brelse(%p) vf2\n", bp);
369 #endif
370 brelse(bp);
371 bp = NULL;
372
373 mp->mnt_data = fcmp;
374 mp->mnt_stat.f_fsidx.__fsid_val[0] = (long)dev;
375 mp->mnt_stat.f_fsidx.__fsid_val[1] = makefstype(MOUNT_FILECORE);
376 mp->mnt_stat.f_fsid = mp->mnt_stat.f_fsidx.__fsid_val[0];
377 mp->mnt_maxsymlinklen = 0;
378 mp->mnt_flag |= MNT_LOCAL;
379 mp->mnt_dev_bshift = fcdr->log2secsize;
380 mp->mnt_fs_bshift = fcmp->log2bsize;
381
382 fcmp->fc_mountp = mp;
383 fcmp->fc_dev = dev;
384 fcmp->fc_devvp = devvp;
385 fcmp->fc_mntflags = argp->flags;
386 if (argp->flags & FILECOREMNT_USEUID) {
387 fcmp->fc_uid = l->l_proc->p_cred->p_ruid;
388 fcmp->fc_gid = l->l_proc->p_cred->p_rgid;
389 } else {
390 fcmp->fc_uid = argp->uid;
391 fcmp->fc_gid = argp->gid;
392 }
393
394 return 0;
395 out:
396 if (bp) {
397 #ifdef FILECORE_DEBUG_BR
398 printf("brelse(%p) vf3\n", bp);
399 #endif
400 brelse(bp);
401 }
402 vn_lock(devvp, LK_EXCLUSIVE | LK_RETRY);
403 (void)VOP_CLOSE(devvp, ronly ? FREAD : FREAD|FWRITE, NOCRED, l);
404 VOP_UNLOCK(devvp, 0);
405 if (fcmp) {
406 free(fcmp, M_FILECOREMNT);
407 mp->mnt_data = NULL;
408 }
409 return error;
410 }
411
412 /*
413 * Make a filesystem operational.
414 * Nothing to do at the moment.
415 */
416 /* ARGSUSED */
417 int
418 filecore_start(mp, flags, l)
419 struct mount *mp;
420 int flags;
421 struct lwp *l;
422 {
423 return 0;
424 }
425
426 /*
427 * unmount system call
428 */
429 int
430 filecore_unmount(mp, mntflags, l)
431 struct mount *mp;
432 int mntflags;
433 struct lwp *l;
434 {
435 struct filecore_mnt *fcmp;
436 int error, flags = 0;
437
438 if (mntflags & MNT_FORCE)
439 flags |= FORCECLOSE;
440 #if 0
441 mntflushbuf(mp, 0);
442 if (mntinvalbuf(mp))
443 return EBUSY;
444 #endif
445 if ((error = vflush(mp, NULLVP, flags)) != 0)
446 return (error);
447
448 fcmp = VFSTOFILECORE(mp);
449
450 if (fcmp->fc_devvp->v_type != VBAD)
451 fcmp->fc_devvp->v_specmountpoint = NULL;
452 vn_lock(fcmp->fc_devvp, LK_EXCLUSIVE | LK_RETRY);
453 error = VOP_CLOSE(fcmp->fc_devvp, FREAD, NOCRED, l);
454 vput(fcmp->fc_devvp);
455 free(fcmp, M_FILECOREMNT);
456 mp->mnt_data = NULL;
457 mp->mnt_flag &= ~MNT_LOCAL;
458 return (error);
459 }
460
461 /*
462 * Return root of a filesystem
463 */
464 int
465 filecore_root(mp, vpp, l)
466 struct mount *mp;
467 struct vnode **vpp;
468 struct lwp *l;
469 {
470 struct vnode *nvp;
471 int error;
472
473 if ((error = VFS_VGET(mp, FILECORE_ROOTINO, &nvp, l)) != 0)
474 return (error);
475 *vpp = nvp;
476 return (0);
477 }
478
479 /*
480 * Do operations associated with quotas, not supported
481 */
482 /* ARGSUSED */
483 int
484 filecore_quotactl(mp, cmd, uid, arg, l)
485 struct mount *mp;
486 int cmd;
487 uid_t uid;
488 void *arg;
489 struct lwp *l;
490 {
491
492 return (EOPNOTSUPP);
493 }
494
495 /*
496 * Get file system statistics.
497 */
498 int
499 filecore_statvfs(mp, sbp, l)
500 struct mount *mp;
501 struct statvfs *sbp;
502 struct lwp *l;
503 {
504 struct filecore_mnt *fcmp = VFSTOFILECORE(mp);
505
506 sbp->f_bsize = fcmp->blksize;
507 sbp->f_frsize = sbp->f_bsize; /* XXX */
508 sbp->f_iosize = sbp->f_bsize; /* XXX */
509 sbp->f_blocks = fcmp->nblks;
510 sbp->f_bfree = 0; /* total free blocks */
511 sbp->f_bavail = 0; /* blocks free for non superuser */
512 sbp->f_bresvd = 0; /* reserved blocks */
513 sbp->f_files = 0; /* total files */
514 sbp->f_ffree = 0; /* free file nodes for non superuser */
515 sbp->f_favail = 0; /* free file nodes */
516 sbp->f_fresvd = 0; /* reserved file nodes */
517 copy_statvfs_info(sbp, mp);
518 return 0;
519 }
520
521 /* ARGSUSED */
522 int
523 filecore_sync(mp, waitfor, cred, l)
524 struct mount *mp;
525 int waitfor;
526 struct ucred *cred;
527 struct lwp *l;
528 {
529 return (0);
530 }
531
532 /*
533 * File handle to vnode
534 *
535 * Have to be really careful about stale file handles:
536 * - check that the inode number is in range
537 * - call iget() to get the locked inode
538 * - check for an unallocated inode (i_mode == 0)
539 * - check that the generation number matches
540 */
541
542 struct ifid {
543 ushort ifid_len;
544 ushort ifid_pad;
545 u_int32_t ifid_ino;
546 };
547
548 /* ARGSUSED */
549 int
550 filecore_fhtovp(mp, fhp, vpp, l)
551 struct mount *mp;
552 struct fid *fhp;
553 struct vnode **vpp;
554 struct lwp *l;
555 {
556 struct ifid *ifhp = (struct ifid *)fhp;
557 struct vnode *nvp;
558 struct filecore_node *ip;
559 int error;
560
561 if ((error = VFS_VGET(mp, ifhp->ifid_ino, &nvp, l)) != 0) {
562 *vpp = NULLVP;
563 return (error);
564 }
565 ip = VTOI(nvp);
566 if (filecore_staleinode(ip)) {
567 vput(nvp);
568 *vpp = NULLVP;
569 return (ESTALE);
570 }
571 *vpp = nvp;
572 return (0);
573 }
574
575 /* ARGSUSED */
576 int
577 filecore_checkexp(mp, nam, exflagsp, credanonp)
578 struct mount *mp;
579 struct mbuf *nam;
580 int *exflagsp;
581 struct ucred **credanonp;
582 {
583 struct filecore_mnt *fcmp = VFSTOFILECORE(mp);
584 struct netcred *np;
585
586 /*
587 * Get the export permission structure for this <mp, client> tuple.
588 */
589 np = vfs_export_lookup(mp, &fcmp->fc_export, nam);
590 if (np == NULL)
591 return (EACCES);
592
593 *exflagsp = np->netc_exflags;
594 *credanonp = &np->netc_anon;
595 return (0);
596 }
597
598 /* This looks complicated. Look at other vgets as well as the iso9660 one.
599 *
600 * The filecore inode number is made up of 1 byte directory entry index and
601 * 3 bytes of the internal disc address of the directory. On a read-only
602 * filesystem this is unique. For a read-write version we may not be able to
603 * do vget, see msdosfs.
604 */
605
606 int
607 filecore_vget(mp, ino, vpp, l)
608 struct mount *mp;
609 ino_t ino;
610 struct vnode **vpp;
611 struct lwp *l;
612 {
613 struct filecore_mnt *fcmp;
614 struct filecore_node *ip;
615 struct buf *bp;
616 struct vnode *vp;
617 dev_t dev;
618 int error;
619
620 fcmp = VFSTOFILECORE(mp);
621 dev = fcmp->fc_dev;
622 if ((*vpp = filecore_ihashget(dev, ino, l)) != NULLVP)
623 return (0);
624
625 /* Allocate a new vnode/filecore_node. */
626 if ((error = getnewvnode(VT_FILECORE, mp, filecore_vnodeop_p, &vp))
627 != 0) {
628 *vpp = NULLVP;
629 return (error);
630 }
631 ip = pool_get(&filecore_node_pool, PR_WAITOK);
632 memset(ip, 0, sizeof(struct filecore_node));
633 vp->v_data = ip;
634 ip->i_vnode = vp;
635 ip->i_dev = dev;
636 ip->i_number = ino;
637 ip->i_block = -1;
638 ip->i_parent = -2;
639
640 /*
641 * Put it onto its hash chain and lock it so that other requests for
642 * this inode will block if they arrive while we are sleeping waiting
643 * for old data structures to be purged or for the contents of the
644 * disk portion of this inode to be read.
645 */
646 filecore_ihashins(ip);
647
648 if (ino == FILECORE_ROOTINO) {
649 /* Here we need to construct a root directory inode */
650 memcpy(ip->i_dirent.name, "root", 4);
651 ip->i_dirent.load = 0;
652 ip->i_dirent.exec = 0;
653 ip->i_dirent.len = FILECORE_DIR_SIZE;
654 ip->i_dirent.addr = fcmp->drec.root;
655 ip->i_dirent.attr = FILECORE_ATTR_DIR | FILECORE_ATTR_READ;
656
657 } else {
658 /* Read in Data from Directory Entry */
659 if ((error = filecore_bread(fcmp, ino & FILECORE_INO_MASK,
660 FILECORE_DIR_SIZE, NOCRED, &bp)) != 0) {
661 vput(vp);
662 #ifdef FILECORE_DEBUG_BR
663 printf("brelse(%p) vf4\n", bp);
664 #endif
665 brelse(bp);
666 *vpp = NULL;
667 return (error);
668 }
669
670 memcpy(&ip->i_dirent,
671 fcdirentry(bp->b_data, ino >> FILECORE_INO_INDEX),
672 sizeof(struct filecore_direntry));
673 #ifdef FILECORE_DEBUG_BR
674 printf("brelse(%p) vf5\n", bp);
675 #endif
676 brelse(bp);
677 }
678
679 ip->i_mnt = fcmp;
680 ip->i_devvp = fcmp->fc_devvp;
681 ip->i_diroff = 0;
682 VREF(ip->i_devvp);
683
684 /*
685 * Setup type
686 */
687 vp->v_type = VREG;
688 if (ip->i_dirent.attr & FILECORE_ATTR_DIR)
689 vp->v_type = VDIR;
690
691 /*
692 * Initialize the associated vnode
693 */
694 switch (vp->v_type) {
695 case VFIFO:
696 case VCHR:
697 case VBLK:
698 /*
699 * Devices not supported.
700 */
701 vput(vp);
702 return (EOPNOTSUPP);
703 case VLNK:
704 case VNON:
705 case VSOCK:
706 case VDIR:
707 case VBAD:
708 case VREG:
709 break;
710 }
711
712 if (ino == FILECORE_ROOTINO)
713 vp->v_flag |= VROOT;
714
715 /*
716 * XXX need generation number?
717 */
718
719 genfs_node_init(vp, &filecore_genfsops);
720 vp->v_size = ip->i_size;
721 *vpp = vp;
722 return (0);
723 }
724
725 /*
726 * Vnode pointer to File handle
727 */
728 /* ARGSUSED */
729 int
730 filecore_vptofh(vp, fhp)
731 struct vnode *vp;
732 struct fid *fhp;
733 {
734 struct filecore_node *ip = VTOI(vp);
735 struct ifid *ifhp;
736
737 ifhp = (struct ifid *)fhp;
738 ifhp->ifid_len = sizeof(struct ifid);
739 ifhp->ifid_ino = ip->i_number;
740 return 0;
741 }
742
743 SYSCTL_SETUP(sysctl_vfs_filecore_setup, "sysctl vfs.filecore subtree setup")
744 {
745
746 sysctl_createv(clog, 0, NULL, NULL,
747 CTLFLAG_PERMANENT,
748 CTLTYPE_NODE, "vfs", NULL,
749 NULL, 0, NULL, 0,
750 CTL_VFS, CTL_EOL);
751 sysctl_createv(clog, 0, NULL, NULL,
752 CTLFLAG_PERMANENT,
753 CTLTYPE_NODE, "filecore",
754 SYSCTL_DESCR("Acorn FILECORE file system"),
755 NULL, 0, NULL, 0,
756 CTL_VFS, 19, CTL_EOL);
757 /*
758 * XXX the "19" above could be dynamic, thereby eliminating
759 * one more instance of the "number to vfs" mapping problem,
760 * but "19" is the order as taken from sys/mount.h
761 */
762 }
763