VM: only single page chunks
[minix.git] / sys / ufs / chfs / chfs_vfsops.c
bloba08d15fb7d393a44827b6bac8bc70e2fa8c8dbdc
1 /* $NetBSD: chfs_vfsops.c,v 1.2 2011/11/24 21:09:37 agc Exp $ */
3 /*-
4 * Copyright (c) 2010 Department of Software Engineering,
5 * University of Szeged, Hungary
6 * Copyright (C) 2010 Tamas Toth <ttoth@inf.u-szeged.hu>
7 * Copyright (C) 2010 Adam Hoka <ahoka@NetBSD.org>
8 * All rights reserved.
10 * This code is derived from software contributed to The NetBSD Foundation
11 * by the Department of Software Engineering, University of Szeged, Hungary
13 * Redistribution and use in source and binary forms, with or without
14 * modification, are permitted provided that the following conditions
15 * are met:
16 * 1. Redistributions of source code must retain the above copyright
17 * notice, this list of conditions and the following disclaimer.
18 * 2. Redistributions in binary form must reproduce the above copyright
19 * notice, this list of conditions and the following disclaimer in the
20 * documentation and/or other materials provided with the distribution.
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,
27 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
29 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
30 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 * SUCH DAMAGE.
35 #include <sys/cdefs.h>
37 #include <sys/param.h>
38 #include <sys/types.h>
39 #include <sys/kmem.h>
40 #include <sys/mount.h>
41 #include <sys/stat.h>
42 #include <sys/systm.h>
43 #include <sys/proc.h>
44 #include <sys/module.h>
45 #include <sys/namei.h>
46 #include <sys/malloc.h>
47 #include <sys/fcntl.h>
48 #include <sys/conf.h>
49 #include <sys/buf.h>
50 //XXX needed just for debugging
51 #include <sys/fstrans.h>
52 #include <sys/sleepq.h>
53 #include <sys/lockdebug.h>
54 #include <sys/ktrace.h>
56 #include <uvm/uvm.h>
57 #include <uvm/uvm_pager.h>
58 #include <ufs/ufs/dir.h>
59 //#include <ufs/ufs/inode.h>
60 #include <ufs/ufs/ufs_extern.h>
61 #include <miscfs/genfs/genfs.h>
62 #include <miscfs/genfs/genfs_node.h>
63 #include <miscfs/specfs/specdev.h>
64 //#include </root/xipffs/netbsd.chfs/chfs.h>
65 //#include </root/xipffs/netbsd.chfs/chfs_args.h>
66 #include "chfs.h"
67 #include "chfs_args.h"
69 MODULE(MODULE_CLASS_VFS, chfs, "flash");
71 /* --------------------------------------------------------------------- */
72 /* functions */
74 static int chfs_mount(struct mount *, const char *, void *, size_t *);
75 static int chfs_unmount(struct mount *, int);
76 static int chfs_root(struct mount *, struct vnode **);
77 static int chfs_vget(struct mount *, ino_t, struct vnode **);
78 static int chfs_fhtovp(struct mount *, struct fid *, struct vnode **);
79 static int chfs_vptofh(struct vnode *, struct fid *, size_t *);
80 static int chfs_start(struct mount *, int);
81 static int chfs_statvfs(struct mount *, struct statvfs *);
82 static int chfs_sync(struct mount *, int, kauth_cred_t);
83 static void chfs_init(void);
84 static void chfs_reinit(void);
85 static void chfs_done(void);
86 static int chfs_snapshot(struct mount *, struct vnode *,
87 struct timespec *);
89 /* --------------------------------------------------------------------- */
90 /* structures */
92 int
93 chfs_gop_alloc(struct vnode *vp, off_t off, off_t len, int flags,
94 kauth_cred_t cred)
96 return (0);
99 const struct genfs_ops chfs_genfsops = {
100 .gop_size = genfs_size,
101 .gop_alloc = chfs_gop_alloc,
102 .gop_write = genfs_gop_write,
103 .gop_markupdate = ufs_gop_markupdate,
107 static const struct ufs_ops chfs_ufsops = {
108 .uo_itimes = chfs_itimes,
109 .uo_update = chfs_update,
113 struct pool chfs_inode_pool;
115 /* for looking up the major for flash */
116 extern const struct cdevsw flash_cdevsw;
118 /* --------------------------------------------------------------------- */
120 static int
121 chfs_mount(struct mount *mp,
122 const char *path, void *data, size_t *data_len)
124 struct lwp *l = curlwp;
125 struct nameidata nd;
126 struct pathbuf *pb;
127 struct vnode *devvp = NULL;
128 struct ufs_args *args = data;
129 struct ufsmount *ump = NULL;
130 struct chfs_mount *chmp;
131 int err = 0;
132 int xflags;
134 dbg("mount()\n");
136 if (*data_len < sizeof *args)
137 return EINVAL;
139 if (mp->mnt_flag & MNT_GETARGS) {
140 ump = VFSTOUFS(mp);
141 if (ump == NULL)
142 return EIO;
143 memset(args, 0, sizeof *args);
144 args->fspec = NULL;
145 *data_len = sizeof *args;
146 return 0;
149 if (mp->mnt_flag & MNT_UPDATE) {
150 /* XXX: There is no support yet to update file system
151 * settings. Should be added. */
153 return ENODEV;
156 if (args->fspec != NULL) {
157 err = pathbuf_copyin(args->fspec, &pb);
158 if (err) {
159 return err;
162 * Look up the name and verify that it's sane.
164 NDINIT(&nd, LOOKUP, FOLLOW, pb);
165 if ((err = namei(&nd)) != 0 )
166 return (err);
167 devvp = nd.ni_vp;
170 * Be sure this is a valid block device
172 if (devvp->v_type != VBLK)
173 err = ENOTBLK;
174 else if (bdevsw_lookup(devvp->v_rdev) == NULL)
175 err = ENXIO;
178 if (err) {
179 vrele(devvp);
180 return (err);
183 if (mp->mnt_flag & MNT_RDONLY)
184 xflags = FREAD;
185 else
186 xflags = FREAD|FWRITE;
188 err = VOP_OPEN(devvp, xflags, FSCRED);
189 if (err)
190 goto fail;
193 err = chfs_mountfs(devvp, mp);
194 if (err) {
195 vn_lock(devvp, LK_EXCLUSIVE | LK_RETRY);
196 (void)VOP_CLOSE(devvp, xflags, NOCRED);
197 VOP_UNLOCK(devvp);
198 goto fail;
200 ump = VFSTOUFS(mp);
201 chmp = ump->um_chfs;
203 vfs_getnewfsid(mp);
204 chmp->chm_fsmp = mp;
206 return set_statvfs_info(path,
207 UIO_USERSPACE, args->fspec,
208 UIO_USERSPACE, mp->mnt_op->vfs_name, mp, l);
210 fail:
211 vrele(devvp);
212 return (err);
217 chfs_mountfs(struct vnode *devvp, struct mount *mp)
219 struct lwp *l = curlwp;
220 struct proc *p;
221 kauth_cred_t cred;
222 devmajor_t flash_major;
223 dev_t dev;
224 struct ufsmount* ump = NULL;
225 struct chfs_mount* chmp;
226 struct vnode *vp;
227 int err = 0;
229 dbg("mountfs()\n");
231 dev = devvp->v_rdev;
232 p = l ? l->l_proc : NULL;
233 cred = l ? l->l_cred : NOCRED;
235 /* Flush out any old buffers remaining from a previous use. */
236 vn_lock(devvp, LK_EXCLUSIVE | LK_RETRY);
237 err = vinvalbuf(devvp, V_SAVE, cred, l, 0, 0);
238 VOP_UNLOCK(devvp);
239 if (err)
240 return (err);
242 flash_major = cdevsw_lookup_major(&flash_cdevsw);
244 if (devvp->v_type != VBLK)
245 err = ENOTBLK;
246 else if (bdevsw_lookup(dev) == NULL)
247 err = ENXIO;
248 else if (major(dev) != flash_major) {
249 dbg("major(dev): %d, flash_major: %d\n",
250 major(dev), flash_major);
251 err = ENODEV;
253 if (err) {
254 vrele(devvp);
255 return (err);
258 ump = malloc(sizeof(*ump), M_UFSMNT, M_WAITOK);
259 memset(ump, 0, sizeof(*ump));
260 ump->um_fstype = UFS1;
261 //ump->um_ops = &chfs_ufsops;
262 ump->um_chfs = malloc(sizeof(struct chfs_mount),
263 M_UFSMNT, M_WAITOK);
264 memset(ump->um_chfs, 0, sizeof(struct chfs_mount));
266 mutex_init(&ump->um_lock, MUTEX_DEFAULT, IPL_NONE);
268 /* Get superblock and set flash device number */
269 chmp = ump->um_chfs;
270 if (!chmp)
271 return ENOMEM;
273 chmp->chm_ebh = kmem_alloc(sizeof(struct chfs_ebh), KM_SLEEP);
275 dbg("[]opening flash: %u\n", (unsigned int)devvp->v_rdev);
276 err = ebh_open(chmp->chm_ebh, devvp->v_rdev);
277 if (err) {
278 dbg("error while opening flash\n");
279 kmem_free(chmp->chm_ebh, sizeof(struct chfs_ebh));
280 free(chmp, M_UFSMNT);
281 return err;
284 //TODO check flash sizes
286 chmp->chm_gbl_version = 0;
287 chmp->chm_vnocache_hash = chfs_vnocache_hash_init();
289 chmp->chm_blocks = kmem_zalloc(chmp->chm_ebh->peb_nr *
290 sizeof(struct chfs_eraseblock), KM_SLEEP);
292 if (!chmp->chm_blocks) {
293 kmem_free(chmp->chm_ebh, chmp->chm_ebh->peb_nr *
294 sizeof(struct chfs_eraseblock));
295 ebh_close(chmp->chm_ebh);
296 free(chmp, M_UFSMNT);
297 return ENOMEM;
300 mutex_init(&chmp->chm_lock_mountfields, MUTEX_DEFAULT, IPL_NONE);
301 mutex_init(&chmp->chm_lock_sizes, MUTEX_DEFAULT, IPL_NONE);
302 mutex_init(&chmp->chm_lock_vnocache, MUTEX_DEFAULT, IPL_NONE);
304 //XXX
305 chmp->chm_fs_bmask = -4096;
306 chmp->chm_fs_bsize = 4096;
307 chmp->chm_fs_qbmask = 4095;
308 chmp->chm_fs_bshift = 12;
309 chmp->chm_fs_fmask = -2048;
310 chmp->chm_fs_qfmask = 2047;
312 chmp->chm_wbuf_pagesize = chmp->chm_ebh->flash_if->page_size;
313 dbg("wbuf size: %zu\n", chmp->chm_wbuf_pagesize);
314 chmp->chm_wbuf = kmem_alloc(chmp->chm_wbuf_pagesize, KM_SLEEP);
315 rw_init(&chmp->chm_lock_wbuf);
317 //init queues
318 TAILQ_INIT(&chmp->chm_free_queue);
319 TAILQ_INIT(&chmp->chm_clean_queue);
320 TAILQ_INIT(&chmp->chm_dirty_queue);
321 TAILQ_INIT(&chmp->chm_very_dirty_queue);
322 TAILQ_INIT(&chmp->chm_erasable_pending_wbuf_queue);
323 TAILQ_INIT(&chmp->chm_erase_pending_queue);
325 chfs_calc_trigger_levels(chmp);
327 chmp->chm_nr_free_blocks = 0;
328 chmp->chm_nr_erasable_blocks = 0;
329 chmp->chm_max_vno = 2;
330 chmp->chm_checked_vno = 2;
331 chmp->chm_unchecked_size = 0;
332 chmp->chm_used_size = 0;
333 chmp->chm_dirty_size = 0;
334 chmp->chm_wasted_size = 0;
335 chmp->chm_free_size = chmp->chm_ebh->eb_size * chmp->chm_ebh->peb_nr;
336 err = chfs_build_filesystem(chmp);
338 if (err) {
339 chfs_vnocache_hash_destroy(chmp->chm_vnocache_hash);
340 kmem_free(chmp->chm_ebh, chmp->chm_ebh->peb_nr *
341 sizeof(struct chfs_eraseblock));
342 ebh_close(chmp->chm_ebh);
343 free(chmp, M_UFSMNT);
344 return EIO;
347 mp->mnt_data = ump;
348 mp->mnt_stat.f_fsidx.__fsid_val[0] = (long)dev;
349 mp->mnt_stat.f_fsidx.__fsid_val[1] = makefstype(MOUNT_CHFS);
350 mp->mnt_stat.f_fsid = mp->mnt_stat.f_fsidx.__fsid_val[0];
351 mp->mnt_stat.f_namemax = MAXNAMLEN;
352 mp->mnt_flag |= MNT_LOCAL;
353 mp->mnt_fs_bshift = PAGE_SHIFT;
354 mp->mnt_dev_bshift = DEV_BSHIFT;
355 mp->mnt_iflag |= IMNT_MPSAFE;
356 ump->um_flags = 0;
357 ump->um_mountp = mp;
358 ump->um_dev = dev;
359 ump->um_devvp = devvp;
360 ump->um_maxfilesize = 1048512 * 1024;
361 /*TODO fill these fields
362 ump->um_nindir =
363 ump->um_lognindir =
364 ump->um_bptrtodb =
365 ump->um_seqinc =
366 ump->um_maxsymlinklen =
367 ump->um_dirblksiz =
368 ump->um_maxfilesize =
372 * Allocate the root vnode.
374 err = VFS_VGET(mp, CHFS_ROOTINO, &vp);
375 if (err) {
376 dbg("error: %d while allocating root node\n", err);
377 return err;
379 vput(vp);
381 chfs_gc_thread_start(chmp);
382 mutex_enter(&chmp->chm_lock_mountfields);
383 chfs_gc_trigger(chmp);
384 mutex_exit(&chmp->chm_lock_mountfields);
386 devvp->v_specmountpoint = mp;
387 return 0;
390 /* --------------------------------------------------------------------- */
392 /* ARGSUSED2 */
393 static int
394 chfs_unmount(struct mount *mp, int mntflags)
396 int flags = 0, i = 0;
397 struct ufsmount *ump;
398 struct chfs_mount *chmp;
399 // struct chfs_vnode_cache *vc, *next;
401 if (mntflags & MNT_FORCE)
402 flags |= FORCECLOSE;
404 dbg("[START]\n");
406 ump = VFSTOUFS(mp);
407 chmp = ump->um_chfs;
409 chfs_gc_thread_stop(chmp);
411 (void)vflush(mp, NULLVP, flags);
413 if (chmp->chm_wbuf_len) {
414 mutex_enter(&chmp->chm_lock_mountfields);
415 chfs_flush_pending_wbuf(chmp);
416 mutex_exit(&chmp->chm_lock_mountfields);
419 for (i = 0; i < chmp->chm_ebh->peb_nr; i++) {
420 chfs_free_node_refs(&chmp->chm_blocks[i]);
423 chfs_vnocache_hash_destroy(chmp->chm_vnocache_hash);
425 ebh_close(chmp->chm_ebh);
427 rw_destroy(&chmp->chm_lock_wbuf);
428 mutex_destroy(&chmp->chm_lock_vnocache);
429 mutex_destroy(&chmp->chm_lock_sizes);
430 mutex_destroy(&chmp->chm_lock_mountfields);
432 if (ump->um_devvp->v_type != VBAD) {
433 ump->um_devvp->v_specmountpoint = NULL;
435 vn_lock(ump->um_devvp, LK_EXCLUSIVE | LK_RETRY);
436 (void)VOP_CLOSE(ump->um_devvp, FREAD|FWRITE, NOCRED);
437 vput(ump->um_devvp);
439 mutex_destroy(&ump->um_lock);
441 //free(ump->um_chfs, M_UFSMNT);
442 free(ump, M_UFSMNT);
443 mp->mnt_data = NULL;
444 mp->mnt_flag &= ~MNT_LOCAL;
445 dbg("[END]\n");
446 return (0);
449 /* --------------------------------------------------------------------- */
451 static int
452 chfs_root(struct mount *mp, struct vnode **vpp)
454 struct vnode *vp;
455 int error;
457 if ((error = VFS_VGET(mp, (ino_t)ROOTINO, &vp)) != 0)
458 return error;
459 *vpp = vp;
460 return 0;
463 /* --------------------------------------------------------------------- */
465 extern rb_tree_ops_t frag_rbtree_ops;
467 static int
468 chfs_vget(struct mount *mp, ino_t ino, struct vnode **vpp)
470 struct chfs_mount *chmp;
471 struct chfs_inode *ip;
472 struct ufsmount *ump;
473 struct vnode *vp;
474 dev_t dev;
475 int error;
476 struct chfs_vnode_cache* chvc = NULL;
477 struct chfs_node_ref* nref = NULL;
478 struct buf *bp;
480 dbg("vget() | ino: %llu\n", (unsigned long long)ino);
482 ump = VFSTOUFS(mp);
483 dev = ump->um_dev;
484 retry:
485 if (!vpp) {
486 vpp = kmem_alloc(sizeof(struct vnode*), KM_SLEEP);
489 if ((*vpp = chfs_ihashget(dev, ino, LK_EXCLUSIVE)) != NULL) {
490 return 0;
493 /* Allocate a new vnode/inode. */
494 if ((error = getnewvnode(VT_CHFS,
495 mp, chfs_vnodeop_p, NULL, &vp)) != 0) {
496 *vpp = NULL;
497 return (error);
499 ip = pool_get(&chfs_inode_pool, PR_WAITOK);
501 mutex_enter(&chfs_hashlock);
502 if ((*vpp = chfs_ihashget(dev, ino, LK_EXCLUSIVE)) != NULL) {
503 mutex_exit(&chfs_hashlock);
504 ungetnewvnode(vp);
505 pool_put(&chfs_inode_pool, ip);
506 goto retry;
509 vp->v_vflag |= VV_LOCKSWORK;
511 memset(ip, 0, sizeof(*ip));
512 vp->v_data = ip;
513 ip->vp = vp;
514 ip->ump = ump;
515 ip->chmp = chmp = ump->um_chfs;
516 ip->dev = dev;
517 ip->ino = ino;
518 vp->v_mount = mp;
519 genfs_node_init(vp, &chfs_genfsops);
521 rb_tree_init(&ip->fragtree, &frag_rbtree_ops);
522 //mutex_init(&ip->inode_lock, MUTEX_DEFAULT, IPL_NONE);
524 chfs_ihashins(ip);
525 mutex_exit(&chfs_hashlock);
527 // set root inode
528 if (ino == CHFS_ROOTINO) {
529 dbg("SETROOT\n");
530 vp->v_vflag |= VV_ROOT;
531 vp->v_type = VDIR;
532 ip->mode = IFMT | IEXEC | IWRITE | IREAD;
533 ip->iflag |= (IN_ACCESS | IN_CHANGE | IN_UPDATE);
534 chfs_update(vp, NULL, NULL, UPDATE_WAIT);
535 // ip->dents = NULL; XXXTAILQ
536 TAILQ_INIT(&ip->dents);
537 chfs_set_vnode_size(vp, 512);
540 // set vnode cache
541 mutex_enter(&chmp->chm_lock_vnocache);
542 chvc = chfs_vnode_cache_get(chmp, ino);
543 mutex_exit(&chmp->chm_lock_vnocache);
544 if (!chvc) {
545 dbg("!chvc\n");
546 /* XXX, we cant alloc under a lock, refactor this! */
547 chvc = chfs_vnode_cache_alloc(ino);
548 mutex_enter(&chmp->chm_lock_vnocache);
549 if (ino == CHFS_ROOTINO) {
550 chvc->nlink = 2;
551 chvc->pvno = CHFS_ROOTINO;
552 chfs_vnode_cache_set_state(chmp,
553 chvc, VNO_STATE_CHECKEDABSENT);
555 chfs_vnode_cache_add(chmp, chvc);
556 mutex_exit(&chmp->chm_lock_vnocache);
558 ip->chvc = chvc;
559 TAILQ_INIT(&ip->dents);
560 } else {
561 dbg("chvc\n");
562 ip->chvc = chvc;
563 // if we have a vnode cache, the node is already on flash, so read it
564 if (ino == CHFS_ROOTINO) {
565 chvc->pvno = CHFS_ROOTINO;
566 TAILQ_INIT(&chvc->scan_dirents);
567 } else {
568 chfs_readvnode(mp, ino, &vp);
571 mutex_enter(&chmp->chm_lock_mountfields);
572 // init type specific things
573 switch (vp->v_type) {
574 case VDIR:
575 nref = chvc->dirents;
576 while (nref &&
577 (struct chfs_vnode_cache *)nref != chvc) {
578 chfs_readdirent(mp, nref, ip);
579 nref = nref->nref_next;
581 chfs_set_vnode_size(vp, 512);
582 break;
583 case VREG:
584 case VSOCK:
585 //build the fragtree of the vnode
586 dbg("read_inode_internal | ino: %llu\n",
587 (unsigned long long)ip->ino);
588 error = chfs_read_inode(chmp, ip);
589 if (error) {
590 vput(vp);
591 *vpp = NULL;
592 mutex_exit(&chmp->chm_lock_mountfields);
593 return (error);
595 break;
596 case VLNK:
597 //build the fragtree of the vnode
598 dbg("read_inode_internal | ino: %llu\n",
599 (unsigned long long)ip->ino);
600 error = chfs_read_inode_internal(chmp, ip);
601 if (error) {
602 vput(vp);
603 *vpp = NULL;
604 mutex_exit(&chmp->chm_lock_mountfields);
605 return (error);
608 dbg("size: %llu\n", (unsigned long long)ip->size);
609 bp = getiobuf(vp, true);
610 bp->b_blkno = 0;
611 bp->b_bufsize = bp->b_resid =
612 bp->b_bcount = ip->size;
613 bp->b_data = kmem_alloc(ip->size, KM_SLEEP);
614 chfs_read_data(chmp, vp, bp);
615 if (!ip->target)
616 ip->target = kmem_alloc(ip->size,
617 KM_SLEEP);
618 memcpy(ip->target, bp->b_data, ip->size);
619 kmem_free(bp->b_data, ip->size);
620 putiobuf(bp);
622 break;
623 case VCHR:
624 case VBLK:
625 case VFIFO:
626 //build the fragtree of the vnode
627 dbg("read_inode_internal | ino: %llu\n",
628 (unsigned long long)ip->ino);
629 error = chfs_read_inode_internal(chmp, ip);
630 if (error) {
631 vput(vp);
632 *vpp = NULL;
633 mutex_exit(&chmp->chm_lock_mountfields);
634 return (error);
637 bp = getiobuf(vp, true);
638 bp->b_blkno = 0;
639 bp->b_bufsize = bp->b_resid =
640 bp->b_bcount = sizeof(dev_t);
641 bp->b_data = kmem_alloc(sizeof(dev_t), KM_SLEEP);
642 chfs_read_data(chmp, vp, bp);
643 memcpy(&ip->rdev,
644 bp->b_data, sizeof(dev_t));
645 kmem_free(bp->b_data, sizeof(dev_t));
646 putiobuf(bp);
647 if (vp->v_type == VFIFO)
648 vp->v_op = chfs_fifoop_p;
649 else {
650 vp->v_op = chfs_specop_p;
651 spec_node_init(vp, ip->rdev);
654 break;
655 case VNON:
656 case VBAD:
657 break;
659 mutex_exit(&chmp->chm_lock_mountfields);
663 /* finish inode initalization */
664 ip->devvp = ump->um_devvp;
665 vref(ip->devvp);
667 uvm_vnp_setsize(vp, ip->size);
668 *vpp = vp;
670 return 0;
673 /* --------------------------------------------------------------------- */
675 static int
676 chfs_fhtovp(struct mount *mp, struct fid *fhp, struct vnode **vpp)
678 return ENODEV;
681 /* --------------------------------------------------------------------- */
683 static int
684 chfs_vptofh(struct vnode *vp, struct fid *fhp, size_t *fh_size)
686 return ENODEV;
689 /* --------------------------------------------------------------------- */
691 static int
692 chfs_start(struct mount *mp, int flags)
694 return 0;
697 /* --------------------------------------------------------------------- */
699 /* ARGSUSED2 */
700 static int
701 chfs_statvfs(struct mount *mp, struct statvfs *sbp)
703 struct chfs_mount *chmp;
704 struct ufsmount *ump;
705 dbg("statvfs\n");
707 ump = VFSTOUFS(mp);
708 chmp = ump->um_chfs;
710 sbp->f_flag = mp->mnt_flag;
711 sbp->f_bsize = chmp->chm_ebh->eb_size;
712 sbp->f_frsize = chmp->chm_ebh->eb_size;
713 sbp->f_iosize = chmp->chm_ebh->eb_size;
715 sbp->f_blocks = chmp->chm_ebh->peb_nr;
716 sbp->f_files = 0;
717 sbp->f_bavail = chmp->chm_nr_free_blocks - chmp->chm_resv_blocks_write;
718 #if 0
719 printf("chmp->chm_nr_free_blocks: %jd\n",
720 (intmax_t )chmp->chm_nr_free_blocks);
721 printf("chmp->chm_resv_blocks_write: %jd\n",
722 (intmax_t) chmp->chm_resv_blocks_write);
723 printf("chmp->chm_ebh->peb_nr: %jd\n",
724 (intmax_t) chmp->chm_ebh->peb_nr);
725 #endif
727 sbp->f_bfree = chmp->chm_nr_free_blocks;
728 sbp->f_bresvd = chmp->chm_resv_blocks_write;
730 /* FFS specific */
731 sbp->f_ffree = 0;
732 sbp->f_favail = 0;
733 sbp->f_fresvd = 0;
735 copy_statvfs_info(sbp, mp);
737 return 0;
740 /* --------------------------------------------------------------------- */
742 /* ARGSUSED0 */
743 static int
744 chfs_sync(struct mount *mp, int waitfor,
745 kauth_cred_t uc)
747 return 0;
750 /* --------------------------------------------------------------------- */
752 static void
753 chfs_init(void)
755 chfs_alloc_pool_caches();
756 chfs_ihashinit();
757 pool_init(&chfs_inode_pool, sizeof(struct chfs_inode), 0, 0, 0,
758 "chfsinopl", &pool_allocator_nointr, IPL_NONE);
759 ufs_init();
762 /* --------------------------------------------------------------------- */
764 static void
765 chfs_reinit(void)
767 chfs_ihashreinit();
768 ufs_reinit();
771 /* --------------------------------------------------------------------- */
773 static void
774 chfs_done(void)
776 ufs_done();
777 chfs_ihashdone();
778 pool_destroy(&chfs_inode_pool);
779 chfs_destroy_pool_caches();
782 /* --------------------------------------------------------------------- */
784 static int
785 chfs_snapshot(struct mount *mp, struct vnode *vp,
786 struct timespec *ctime)
788 return ENODEV;
791 /* --------------------------------------------------------------------- */
794 * chfs vfs operations.
797 extern const struct vnodeopv_desc chfs_fifoop_opv_desc;
798 extern const struct vnodeopv_desc chfs_specop_opv_desc;
799 extern const struct vnodeopv_desc chfs_vnodeop_opv_desc;
801 const struct vnodeopv_desc * const chfs_vnodeopv_descs[] = {
802 &chfs_fifoop_opv_desc,
803 &chfs_specop_opv_desc,
804 &chfs_vnodeop_opv_desc,
805 NULL,
808 struct vfsops chfs_vfsops = {
809 MOUNT_CHFS, /* vfs_name */
810 sizeof (struct chfs_args),
811 chfs_mount, /* vfs_mount */
812 chfs_start, /* vfs_start */
813 chfs_unmount, /* vfs_unmount */
814 chfs_root, /* vfs_root */
815 ufs_quotactl, /* vfs_quotactl */
816 chfs_statvfs, /* vfs_statvfs */
817 chfs_sync, /* vfs_sync */
818 chfs_vget, /* vfs_vget */
819 chfs_fhtovp, /* vfs_fhtovp */
820 chfs_vptofh, /* vfs_vptofh */
821 chfs_init, /* vfs_init */
822 chfs_reinit, /* vfs_reinit */
823 chfs_done, /* vfs_done */
824 NULL, /* vfs_mountroot */
825 chfs_snapshot, /* vfs_snapshot */
826 vfs_stdextattrctl, /* vfs_extattrctl */
827 (void *)eopnotsupp, /* vfs_suspendctl */
828 genfs_renamelock_enter,
829 genfs_renamelock_exit,
830 (void *)eopnotsupp,
831 chfs_vnodeopv_descs,
832 0, /* vfs_refcount */
833 { NULL, NULL },
836 static int
837 chfs_modcmd(modcmd_t cmd, void *arg)
839 switch (cmd) {
840 case MODULE_CMD_INIT:
841 return vfs_attach(&chfs_vfsops);
842 case MODULE_CMD_FINI:
843 return vfs_detach(&chfs_vfsops);
844 default:
845 return ENOTTY;