2 * Copyright (c) 2019 Tomohiro Kusumi <tkusumi@netbsd.org>
3 * Copyright (c) 2019 The DragonFly Project
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 static MALLOC_DEFINE(M_FUSE_FH, "fuse_fh", "FUSE fh");
32 static struct objcache *fuse_fh_objcache = NULL;
33 static struct objcache_malloc_args fuse_fh_args = {
34 sizeof(uint64_t), M_FUSE_FH,
37 uint64_t fuse_fh(struct file *fp)
39 uint64_t *fhp = fp->private_data;
42 fuse_dbg("fh=%jx\n", *fhp);
46 void fuse_get_fh(struct file *fp, uint64_t fh)
48 uint64_t *fhp = objcache_get(fuse_fh_objcache, M_WAITOK);
52 fuse_dbg("fh=%jx\n", *fhp);
54 KKASSERT(!fp->private_data);
55 fp->private_data = fhp;
58 void fuse_put_fh(struct file *fp)
60 uint64_t *fhp = fp->private_data;
63 fuse_dbg("fh=%jx\n", *fhp);
65 objcache_put(fuse_fh_objcache, fhp);
66 fp->private_data = NULL;
70 * nfh - per node fh (ad-hoc hack)
72 * XXX This should be gone, as the concept of nfh is already wrong.
73 * This exists due to how BSD VFS is implemented.
74 * There are situations where FUSE VOP's can't access fh required by FUSE ops.
76 uint64_t fuse_nfh(struct fuse_node *fnp)
78 fuse_dbg("ino=%ju fh=%jx\n", fnp->ino, fnp->fh);
82 void fuse_get_nfh(struct fuse_node *fnp, uint64_t fh)
85 fuse_dbg("ino=%ju fh=%jx\n", fnp->ino, fnp->fh);
88 void fuse_put_nfh(struct fuse_node *fnp)
90 fuse_dbg("ino=%ju fh=%jx\n", fnp->ino, fnp->fh);
96 fuse_fh_objcache = objcache_create("fuse_fh", 0, 0,
98 objcache_malloc_alloc_zero, objcache_malloc_free, &fuse_fh_args);
102 fuse_file_cleanup(void)
104 objcache_destroy(fuse_fh_objcache);