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