1 /* $OpenBSD: fuse_file.c,v 1.6 2013/12/03 09:32:23 syl Exp $ */ 2 /* 3 * Copyright (c) 2012-2013 Sylvestre Gallon <ccna.syl@gmail.com> 4 * 5 * Permission to use, copy, modify, and distribute this software for any 6 * purpose with or without fee is hereby granted, provided that the above 7 * copyright notice and this permission notice appear in all copies. 8 * 9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 16 */ 17 18 #include <sys/param.h> 19 #include <sys/statvfs.h> 20 #include <sys/vnode.h> 21 #include <sys/fusebuf.h> 22 23 #include "fusefs_node.h" 24 #include "fusefs.h" 25 26 int 27 fusefs_file_open(struct fusefs_mnt *fmp, struct fusefs_node *ip, 28 enum fufh_type fufh_type, int flags, int isdir, struct proc *p) 29 { 30 struct fusebuf *fbuf; 31 int error = 0; 32 33 if (!fmp->sess_init) 34 return (0); 35 36 fbuf = fb_setup(0, ip->ufs_ino.i_number, 37 ((isdir) ? FBT_OPENDIR : FBT_OPEN), p); 38 fbuf->fb_io_flags = flags; 39 40 error = fb_queue(fmp->dev, fbuf); 41 if (error) { 42 fb_delete(fbuf); 43 return (error); 44 } 45 46 ip->fufh[fufh_type].fh_id = fbuf->fb_io_fd; 47 ip->fufh[fufh_type].fh_type = fufh_type; 48 49 fb_delete(fbuf); 50 return (0); 51 } 52 53 int 54 fusefs_file_close(struct fusefs_mnt *fmp, struct fusefs_node * ip, 55 enum fufh_type fufh_type, int flags, int isdir, struct proc *p) 56 { 57 struct fusebuf *fbuf; 58 int error = 0; 59 60 if (fmp->sess_init) { 61 fbuf = fb_setup(0, ip->ufs_ino.i_number, 62 ((isdir) ? FBT_RELEASEDIR : FBT_RELEASE), p); 63 fbuf->fb_io_fd = ip->fufh[fufh_type].fh_id; 64 fbuf->fb_io_flags = flags; 65 66 error = fb_queue(fmp->dev, fbuf); 67 if (error) 68 printf("fusefs: file error %d\n", error); 69 70 fb_delete(fbuf); 71 } 72 73 ip->fufh[fufh_type].fh_id = (uint64_t)-1; 74 ip->fufh[fufh_type].fh_type = FUFH_INVALID; 75 76 return (error); 77 } 78 79 uint64_t 80 fusefs_fd_get(struct fusefs_node *ip, enum fufh_type type) 81 { 82 if (ip->fufh[type].fh_type == FUFH_INVALID) 83 type = FUFH_RDWR; 84 85 return (ip->fufh[type].fh_id); 86 } 87