filecore_vfsops.c revision 1.6 1 /* $NetBSD: filecore_vfsops.c,v 1.6 2003/08/07 16:31:38 agc 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.6 2003/08/07 16:31:38 agc 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
90 #include <fs/filecorefs/filecore.h>
91 #include <fs/filecorefs/filecore_extern.h>
92 #include <fs/filecorefs/filecore_node.h>
93 #include <fs/filecorefs/filecore_mount.h>
94
95 MALLOC_DEFINE(M_FILECOREMNT, "filecore mount", "Filecore FS mount structures");
96
97 extern const struct vnodeopv_desc filecore_vnodeop_opv_desc;
98
99 const struct vnodeopv_desc * const filecore_vnodeopv_descs[] = {
100 &filecore_vnodeop_opv_desc,
101 NULL,
102 };
103
104 struct vfsops filecore_vfsops = {
105 MOUNT_FILECORE,
106 filecore_mount,
107 filecore_start,
108 filecore_unmount,
109 filecore_root,
110 filecore_quotactl,
111 filecore_statfs,
112 filecore_sync,
113 filecore_vget,
114 filecore_fhtovp,
115 filecore_vptofh,
116 filecore_init,
117 filecore_reinit,
118 filecore_done,
119 filecore_sysctl,
120 NULL, /* filecore_mountroot */
121 filecore_checkexp,
122 filecore_vnodeopv_descs,
123 };
124
125 struct genfs_ops filecore_genfsops = {
126 genfs_size,
127 };
128
129 /*
130 * Called by vfs_mountroot when iso is going to be mounted as root.
131 *
132 * Name is updated by mount(8) after booting.
133 */
134
135 static int filecore_mountfs __P((struct vnode *devvp, struct mount *mp,
136 struct proc *p, struct filecore_args *argp));
137
138 #if 0
139 int
140 filecore_mountroot()
141 {
142 struct mount *mp;
143 extern struct vnode *rootvp;
144 struct proc *p = curproc; /* XXX */
145 int error;
146 struct filecore_args args;
147
148 if (root_device->dv_class != DV_DISK)
149 return (ENODEV);
150
151 /*
152 * Get vnodes for swapdev and rootdev.
153 */
154 if (bdevvp(rootdev, &rootvp))
155 panic("filecore_mountroot: can't setup rootvp");
156
157 if ((error = vfs_rootmountalloc(MOUNT_FILECORE, "root_device", &mp)) != 0)
158 return (error);
159
160 args.flags = FILECOREMNT_ROOT;
161 if ((error = filecore_mountfs(rootvp, mp, p, &args)) != 0) {
162 mp->mnt_op->vfs_refcount--;
163 vfs_unbusy(mp);
164 free(mp, M_MOUNT);
165 return (error);
166 }
167 simple_lock(&mountlist_slock);
168 CIRCLEQ_INSERT_TAIL(&mountlist, mp, mnt_list);
169 simple_unlock(&mountlist_slock);
170 (void)filecore_statfs(mp, &mp->mnt_stat, p);
171 vfs_unbusy(mp);
172 return (0);
173 }
174 #endif
175
176 /*
177 * VFS Operations.
178 *
179 * mount system call
180 */
181 int
182 filecore_mount(mp, path, data, ndp, p)
183 struct mount *mp;
184 const char *path;
185 void *data;
186 struct nameidata *ndp;
187 struct proc *p;
188 {
189 struct vnode *devvp;
190 struct filecore_args args;
191 int error;
192 struct filecore_mnt *fcmp = NULL;
193
194 if (mp->mnt_flag & MNT_GETARGS) {
195 fcmp = VFSTOFILECORE(mp);
196 if (fcmp == NULL)
197 return EIO;
198 args.flags = fcmp->fc_mntflags;
199 args.uid = fcmp->fc_uid;
200 args.gid = fcmp->fc_gid;
201 args.fspec = NULL;
202 vfs_showexport(mp, &args.export, &fcmp->fc_export);
203 return copyout(&args, data, sizeof(args));
204 }
205 error = copyin(data, (caddr_t)&args, sizeof (struct filecore_args));
206 if (error)
207 return (error);
208
209 if ((mp->mnt_flag & MNT_RDONLY) == 0)
210 return (EROFS);
211
212 /*
213 * If updating, check whether changing from read-only to
214 * read/write; if there is no device name, that's all we do.
215 */
216 if (mp->mnt_flag & MNT_UPDATE) {
217 fcmp = VFSTOFILECORE(mp);
218 if (args.fspec == 0)
219 return (vfs_export(mp, &fcmp->fc_export, &args.export));
220 }
221 /*
222 * Not an update, or updating the name: look up the name
223 * and verify that it refers to a sensible block device.
224 */
225 NDINIT(ndp, LOOKUP, FOLLOW, UIO_USERSPACE, args.fspec, p);
226 if ((error = namei(ndp)) != 0)
227 return (error);
228 devvp = ndp->ni_vp;
229
230 if (devvp->v_type != VBLK) {
231 vrele(devvp);
232 return ENOTBLK;
233 }
234 if (bdevsw_lookup(devvp->v_rdev) == NULL) {
235 vrele(devvp);
236 return ENXIO;
237 }
238 /*
239 * If mount by non-root, then verify that user has necessary
240 * permissions on the device.
241 */
242 if (p->p_ucred->cr_uid != 0) {
243 vn_lock(devvp, LK_EXCLUSIVE | LK_RETRY);
244 error = VOP_ACCESS(devvp, VREAD, p->p_ucred, p);
245 VOP_UNLOCK(devvp, 0);
246 if (error) {
247 vrele(devvp);
248 return (error);
249 }
250 }
251 if ((mp->mnt_flag & MNT_UPDATE) == 0)
252 error = filecore_mountfs(devvp, mp, p, &args);
253 else {
254 if (devvp != fcmp->fc_devvp)
255 error = EINVAL; /* needs translation */
256 else
257 vrele(devvp);
258 }
259 if (error) {
260 vrele(devvp);
261 return error;
262 }
263 fcmp = VFSTOFILECORE(mp);
264 return set_statfs_info(path, UIO_USERSPACE, args.fspec, UIO_USERSPACE,
265 mp, p);
266 }
267
268 /*
269 * Common code for mount and mountroot
270 */
271 static int
272 filecore_mountfs(devvp, mp, p, argp)
273 struct vnode *devvp;
274 struct mount *mp;
275 struct proc *p;
276 struct filecore_args *argp;
277 {
278 struct filecore_mnt *fcmp = (struct filecore_mnt *)0;
279 struct buf *bp = NULL;
280 dev_t dev = devvp->v_rdev;
281 int error = EINVAL;
282 int ronly = (mp->mnt_flag & MNT_RDONLY) != 0;
283 extern struct vnode *rootvp;
284 struct filecore_disc_record *fcdr;
285 unsigned map;
286 unsigned log2secsize;
287
288 if (!ronly)
289 return EROFS;
290
291 /*
292 * Disallow multiple mounts of the same device.
293 * Disallow mounting of a device that is currently in use
294 * (except for root, which might share swap device for miniroot).
295 * Flush out any old buffers remaining from a previous use.
296 */
297 if ((error = vfs_mountedon(devvp)) != 0)
298 return error;
299 if (vcount(devvp) > 1 && devvp != rootvp)
300 return EBUSY;
301 if ((error = vinvalbuf(devvp, V_SAVE, p->p_ucred, p, 0, 0)) != 0)
302 return (error);
303
304 error = VOP_OPEN(devvp, ronly ? FREAD : FREAD|FWRITE, FSCRED, p);
305 if (error)
306 return error;
307
308 /* Read the filecore boot block to check FS validity and to find the map */
309 error = bread(devvp, FILECORE_BOOTBLOCK_BLKN,
310 FILECORE_BOOTBLOCK_SIZE, NOCRED, &bp);
311 #ifdef FILECORE_DEBUG_BR
312 printf("bread(%p, %x, %d, CRED, %p)=%d\n", devvp,
313 FILECORE_BOOTBLOCK_BLKN, FILECORE_BOOTBLOCK_SIZE,
314 bp, error);
315 #endif
316 if (error != 0)
317 goto out;
318 if (filecore_bbchecksum(bp->b_data) != 0) {
319 error = EINVAL;
320 goto out;
321 }
322 fcdr = (struct filecore_disc_record *)(bp->b_data+FILECORE_BB_DISCREC);
323 map = ((((8 << fcdr->log2secsize) - fcdr->zone_spare)
324 * (fcdr->nzones / 2) - 8 * FILECORE_DISCREC_SIZE)
325 << fcdr->log2bpmb) >> fcdr->log2secsize;
326 log2secsize = fcdr->log2secsize;
327 bp->b_flags |= B_AGE;
328 #ifdef FILECORE_DEBUG_BR
329 printf("brelse(%p) vf1\n", bp);
330 #endif
331 brelse(bp);
332 bp = NULL;
333
334 /* Read the bootblock in the map */
335 error = bread(devvp, map, 1 << log2secsize, NOCRED, &bp);
336 #ifdef FILECORE_DEBUG_BR
337 printf("bread(%p, %x, %d, CRED, %p)=%d\n", devvp,
338 map, 1 << log2secsize, bp, error);
339 #endif
340 if (error != 0)
341 goto out;
342 fcdr = (struct filecore_disc_record *)(bp->b_data + 4);
343 fcmp = malloc(sizeof *fcmp, M_FILECOREMNT, M_WAITOK);
344 memset((caddr_t)fcmp, 0, sizeof *fcmp);
345 if (fcdr->log2bpmb > fcdr->log2secsize)
346 fcmp->log2bsize = fcdr->log2bpmb;
347 else fcmp->log2bsize = fcdr->log2secsize;
348 fcmp->blksize = 1 << fcmp->log2bsize;
349 memcpy((caddr_t)&fcmp->drec, (caddr_t)fcdr, sizeof(*fcdr));
350 fcmp->map = map;
351 fcmp->idspz = ((8 << fcdr->log2secsize) - fcdr->zone_spare)
352 / (fcdr->idlen + 1);
353 fcmp->mask = (1 << fcdr->idlen) - 1;
354 if (fcdr->big_flag & 1) {
355 fcmp->nblks = ((((u_int64_t)fcdr->disc_size_2) << 32)
356 + fcdr->disc_size) / fcmp->blksize;
357 } else {
358 fcmp->nblks=fcdr->disc_size / fcmp->blksize;
359 }
360
361 bp->b_flags |= B_AGE;
362 #ifdef FILECORE_DEBUG_BR
363 printf("brelse(%p) vf2\n", bp);
364 #endif
365 brelse(bp);
366 bp = NULL;
367
368 mp->mnt_data = fcmp;
369 mp->mnt_stat.f_fsid.val[0] = (long)dev;
370 mp->mnt_stat.f_fsid.val[1] = makefstype(MOUNT_FILECORE);
371 mp->mnt_maxsymlinklen = 0;
372 mp->mnt_flag |= MNT_LOCAL;
373 mp->mnt_dev_bshift = fcdr->log2secsize;
374 mp->mnt_fs_bshift = fcmp->log2bsize;
375
376 fcmp->fc_mountp = mp;
377 fcmp->fc_dev = dev;
378 fcmp->fc_devvp = devvp;
379 fcmp->fc_mntflags = argp->flags;
380 if (argp->flags & FILECOREMNT_USEUID) {
381 fcmp->fc_uid = p->p_cred->p_ruid;
382 fcmp->fc_gid = p->p_cred->p_rgid;
383 } else {
384 fcmp->fc_uid = argp->uid;
385 fcmp->fc_gid = argp->gid;
386 }
387
388 return 0;
389 out:
390 if (bp) {
391 #ifdef FILECORE_DEBUG_BR
392 printf("brelse(%p) vf3\n", bp);
393 #endif
394 brelse(bp);
395 }
396 vn_lock(devvp, LK_EXCLUSIVE | LK_RETRY);
397 (void)VOP_CLOSE(devvp, ronly ? FREAD : FREAD|FWRITE, NOCRED, p);
398 VOP_UNLOCK(devvp, 0);
399 if (fcmp) {
400 free((caddr_t)fcmp, M_FILECOREMNT);
401 mp->mnt_data = NULL;
402 }
403 return error;
404 }
405
406 /*
407 * Make a filesystem operational.
408 * Nothing to do at the moment.
409 */
410 /* ARGSUSED */
411 int
412 filecore_start(mp, flags, p)
413 struct mount *mp;
414 int flags;
415 struct proc *p;
416 {
417 return 0;
418 }
419
420 /*
421 * unmount system call
422 */
423 int
424 filecore_unmount(mp, mntflags, p)
425 struct mount *mp;
426 int mntflags;
427 struct proc *p;
428 {
429 struct filecore_mnt *fcmp;
430 int error, flags = 0;
431
432 if (mntflags & MNT_FORCE)
433 flags |= FORCECLOSE;
434 #if 0
435 mntflushbuf(mp, 0);
436 if (mntinvalbuf(mp))
437 return EBUSY;
438 #endif
439 if ((error = vflush(mp, NULLVP, flags)) != 0)
440 return (error);
441
442 fcmp = VFSTOFILECORE(mp);
443
444 if (fcmp->fc_devvp->v_type != VBAD)
445 fcmp->fc_devvp->v_specmountpoint = NULL;
446 vn_lock(fcmp->fc_devvp, LK_EXCLUSIVE | LK_RETRY);
447 error = VOP_CLOSE(fcmp->fc_devvp, FREAD, NOCRED, p);
448 vput(fcmp->fc_devvp);
449 free((caddr_t)fcmp, M_FILECOREMNT);
450 mp->mnt_data = NULL;
451 mp->mnt_flag &= ~MNT_LOCAL;
452 return (error);
453 }
454
455 /*
456 * Return root of a filesystem
457 */
458 int
459 filecore_root(mp, vpp)
460 struct mount *mp;
461 struct vnode **vpp;
462 {
463 struct vnode *nvp;
464 int error;
465
466 if ((error = VFS_VGET(mp, FILECORE_ROOTINO, &nvp)) != 0)
467 return (error);
468 *vpp = nvp;
469 return (0);
470 }
471
472 /*
473 * Do operations associated with quotas, not supported
474 */
475 /* ARGSUSED */
476 int
477 filecore_quotactl(mp, cmd, uid, arg, p)
478 struct mount *mp;
479 int cmd;
480 uid_t uid;
481 caddr_t arg;
482 struct proc *p;
483 {
484
485 return (EOPNOTSUPP);
486 }
487
488 /*
489 * Get file system statistics.
490 */
491 int
492 filecore_statfs(mp, sbp, p)
493 struct mount *mp;
494 struct statfs *sbp;
495 struct proc *p;
496 {
497 struct filecore_mnt *fcmp = VFSTOFILECORE(mp);
498
499 #ifdef COMPAT_09
500 sbp->f_type = 255;
501 #else
502 sbp->f_type = 0;
503 #endif
504 sbp->f_bsize = fcmp->blksize;
505 sbp->f_iosize = sbp->f_bsize; /* XXX */
506 sbp->f_blocks = fcmp->nblks;
507 sbp->f_bfree = 0; /* total free blocks */
508 sbp->f_bavail = 0; /* blocks free for non superuser */
509 sbp->f_files = 0; /* total files */
510 sbp->f_ffree = 0; /* free file nodes */
511 copy_statfs_info(sbp, mp);
512 return 0;
513 }
514
515 /* ARGSUSED */
516 int
517 filecore_sync(mp, waitfor, cred, p)
518 struct mount *mp;
519 int waitfor;
520 struct ucred *cred;
521 struct proc *p;
522 {
523 return (0);
524 }
525
526 /*
527 * File handle to vnode
528 *
529 * Have to be really careful about stale file handles:
530 * - check that the inode number is in range
531 * - call iget() to get the locked inode
532 * - check for an unallocated inode (i_mode == 0)
533 * - check that the generation number matches
534 */
535
536 struct ifid {
537 ushort ifid_len;
538 ushort ifid_pad;
539 u_int32_t ifid_ino;
540 };
541
542 /* ARGSUSED */
543 int
544 filecore_fhtovp(mp, fhp, vpp)
545 struct mount *mp;
546 struct fid *fhp;
547 struct vnode **vpp;
548 {
549 struct ifid *ifhp = (struct ifid *)fhp;
550 struct vnode *nvp;
551 struct filecore_node *ip;
552 int error;
553
554 if ((error = VFS_VGET(mp, ifhp->ifid_ino, &nvp)) != 0) {
555 *vpp = NULLVP;
556 return (error);
557 }
558 ip = VTOI(nvp);
559 if (filecore_staleinode(ip)) {
560 vput(nvp);
561 *vpp = NULLVP;
562 return (ESTALE);
563 }
564 *vpp = nvp;
565 return (0);
566 }
567
568 /* ARGSUSED */
569 int
570 filecore_checkexp(mp, nam, exflagsp, credanonp)
571 struct mount *mp;
572 struct mbuf *nam;
573 int *exflagsp;
574 struct ucred **credanonp;
575 {
576 struct filecore_mnt *fcmp = VFSTOFILECORE(mp);
577 struct netcred *np;
578
579 /*
580 * Get the export permission structure for this <mp, client> tuple.
581 */
582 np = vfs_export_lookup(mp, &fcmp->fc_export, nam);
583 if (np == NULL)
584 return (EACCES);
585
586 *exflagsp = np->netc_exflags;
587 *credanonp = &np->netc_anon;
588 return (0);
589 }
590
591 /* This looks complicated. Look at other vgets as well as the iso9660 one.
592 *
593 * The filecore inode number is made up of 1 byte directory entry index and
594 * 3 bytes of the internal disc address of the directory. On a read-only
595 * filesystem this is unique. For a read-write version we may not be able to
596 * do vget, see msdosfs.
597 */
598
599 int
600 filecore_vget(mp, ino, vpp)
601 struct mount *mp;
602 ino_t ino;
603 struct vnode **vpp;
604 {
605 struct filecore_mnt *fcmp;
606 struct filecore_node *ip;
607 struct buf *bp;
608 struct vnode *vp;
609 dev_t dev;
610 int error;
611
612 fcmp = VFSTOFILECORE(mp);
613 dev = fcmp->fc_dev;
614 if ((*vpp = filecore_ihashget(dev, ino)) != NULLVP)
615 return (0);
616
617 /* Allocate a new vnode/filecore_node. */
618 if ((error = getnewvnode(VT_FILECORE, mp, filecore_vnodeop_p, &vp))
619 != 0) {
620 *vpp = NULLVP;
621 return (error);
622 }
623 ip = pool_get(&filecore_node_pool, PR_WAITOK);
624 memset(ip, 0, sizeof(struct filecore_node));
625 vp->v_data = ip;
626 ip->i_vnode = vp;
627 ip->i_dev = dev;
628 ip->i_number = ino;
629 ip->i_block = -1;
630 ip->i_parent = -2;
631
632 /*
633 * Put it onto its hash chain and lock it so that other requests for
634 * this inode will block if they arrive while we are sleeping waiting
635 * for old data structures to be purged or for the contents of the
636 * disk portion of this inode to be read.
637 */
638 filecore_ihashins(ip);
639
640 if (ino == FILECORE_ROOTINO) {
641 /* Here we need to construct a root directory inode */
642 memcpy((caddr_t)ip->i_dirent.name, (caddr_t)"root", 4);
643 ip->i_dirent.load = 0;
644 ip->i_dirent.exec = 0;
645 ip->i_dirent.len = FILECORE_DIR_SIZE;
646 ip->i_dirent.addr = fcmp->drec.root;
647 ip->i_dirent.attr = FILECORE_ATTR_DIR | FILECORE_ATTR_READ;
648
649 } else {
650 /* Read in Data from Directory Entry */
651 if ((error = filecore_bread(fcmp, ino & FILECORE_INO_MASK,
652 FILECORE_DIR_SIZE, NOCRED, &bp)) != 0) {
653 vput(vp);
654 #ifdef FILECORE_DEBUG_BR
655 printf("brelse(%p) vf4\n", bp);
656 #endif
657 brelse(bp);
658 *vpp = NULL;
659 return (error);
660 }
661
662 memcpy((caddr_t)&ip->i_dirent,
663 (caddr_t)fcdirentry(bp->b_data, ino >> FILECORE_INO_INDEX),
664 sizeof(struct filecore_direntry));
665 #ifdef FILECORE_DEBUG_BR
666 printf("brelse(%p) vf5\n", bp);
667 #endif
668 brelse(bp);
669 }
670
671 ip->i_mnt = fcmp;
672 ip->i_devvp = fcmp->fc_devvp;
673 ip->i_diroff = 0;
674 VREF(ip->i_devvp);
675
676 /*
677 * Setup type
678 */
679 vp->v_type = VREG;
680 if (ip->i_dirent.attr & FILECORE_ATTR_DIR)
681 vp->v_type = VDIR;
682
683 /*
684 * Initialize the associated vnode
685 */
686 switch (vp->v_type) {
687 case VFIFO:
688 case VCHR:
689 case VBLK:
690 /*
691 * Devices not supported.
692 */
693 vput(vp);
694 return (EOPNOTSUPP);
695 case VLNK:
696 case VNON:
697 case VSOCK:
698 case VDIR:
699 case VBAD:
700 case VREG:
701 break;
702 }
703
704 if (ino == FILECORE_ROOTINO)
705 vp->v_flag |= VROOT;
706
707 /*
708 * XXX need generation number?
709 */
710
711 genfs_node_init(vp, &filecore_genfsops);
712 vp->v_size = ip->i_size;
713 *vpp = vp;
714 return (0);
715 }
716
717 /*
718 * Vnode pointer to File handle
719 */
720 /* ARGSUSED */
721 int
722 filecore_vptofh(vp, fhp)
723 struct vnode *vp;
724 struct fid *fhp;
725 {
726 struct filecore_node *ip = VTOI(vp);
727 struct ifid *ifhp;
728
729 ifhp = (struct ifid *)fhp;
730 ifhp->ifid_len = sizeof(struct ifid);
731 ifhp->ifid_ino = ip->i_number;
732 return 0;
733 }
734
735 int
736 filecore_sysctl(name, namelen, oldp, oldlenp, newp, newlen, p)
737 int *name;
738 u_int namelen;
739 void *oldp;
740 size_t *oldlenp;
741 void *newp;
742 size_t newlen;
743 struct proc *p;
744 {
745 return (EOPNOTSUPP);
746 }
747