1 /* $OpenBSD: fusebuf.h,v 1.13 2018/06/19 11:27:54 helg Exp $ */ 2 /* 3 * Copyright (c) 2013 Sylvestre Gallon 4 * Copyright (c) 2013 Martin Pieuchot 5 * 6 * Permission to use, copy, modify, and distribute this software for any 7 * purpose with or without fee is hereby granted, provided that the above 8 * copyright notice and this permission notice appear in all copies. 9 * 10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 15 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 */ 18 19 #ifndef _SYS_FUSEBUF_H_ 20 #define _SYS_FUSEBUF_H_ 21 22 /* 23 * Fusebufs are of a single size, 4096 bytes. 24 */ 25 #define FUSEBUFSIZE (sizeof(struct fusebuf)) 26 #define FUSEBUFMAXSIZE (4096*1024) 27 28 /* header at beginning of each fusebuf: */ 29 struct fb_hdr { 30 SIMPLEQ_ENTRY(fusebuf) fh_next; /* next buffer in chain */ 31 size_t fh_len; /* Amount of data */ 32 int fh_err; /* errno to pass back */ 33 int fh_type; /* type of data */ 34 ino_t fh_ino; /* Inode of this fusebuf */ 35 uint64_t fh_uuid; /* Uuid to track the answer */ 36 pid_t fh_tid; /* calling proc thread id */ 37 uid_t fh_uid; /* calling proc uid */ 38 gid_t fh_gid; /* calling proc gid */ 39 mode_t fh_umask; /* calling proc umask */ 40 }; 41 42 /* header for fuse file operations (like read/write/mkdir): */ 43 struct fb_io { 44 uint64_t fi_fd; /* fd where the io is performed */ 45 ino_t fi_ino; /* ino for the io */ 46 off_t fi_off; /* offset for the io */ 47 size_t fi_len; /* Length of data */ 48 mode_t fi_mode; /* mode for fd */ 49 uint32_t fi_flags; /* flags on transfer */ 50 dev_t fi_rdev; /* dev for mknod */ 51 }; 52 53 /* 54 * An operation is issued by the kernel through fuse(4) when the 55 * userland file system needs to execute an action (mkdir(2), 56 * link(2), etc). 57 * 58 * F_databuf can be superior to FUSELEN for fusefs_read, fusefs_writes and 59 * fusefs_readdir. If it is the case the transfer will be split in N 60 * fusebuf with a changing offset in FD_io. 61 * 62 * When the userland file system answers to this operation it uses 63 * the same ID (fh_uuid). 64 */ 65 struct fusebuf { 66 struct fb_hdr fb_hdr; 67 union { 68 struct statvfs FD_stat; /* vfs statfs */ 69 struct stat FD_attr; /* for attr vnops */ 70 struct fb_io FD_io; /* for file io vnops */ 71 } FD; 72 uint8_t *fb_dat; /* data's */ 73 }; 74 75 #define fb_next fb_hdr.fh_next 76 #define fb_len fb_hdr.fh_len 77 #define fb_err fb_hdr.fh_err 78 #define fb_type fb_hdr.fh_type 79 #define fb_ino fb_hdr.fh_ino 80 #define fb_uuid fb_hdr.fh_uuid 81 #define fb_tid fb_hdr.fh_tid 82 #define fb_uid fb_hdr.fh_uid 83 #define fb_gid fb_hdr.fh_gid 84 #define fb_umask fb_hdr.fh_umask 85 86 #define fb_stat FD.FD_stat 87 #define fb_attr FD.FD_attr 88 #define fb_io_fd FD.FD_io.fi_fd 89 #define fb_io_ino FD.FD_io.fi_ino 90 #define fb_io_off FD.FD_io.fi_off 91 #define fb_io_len FD.FD_io.fi_len 92 #define fb_io_mode FD.FD_io.fi_mode 93 #define fb_io_flags FD.FD_io.fi_flags 94 #define fb_io_rdev FD.FD_io.fi_rdev 95 96 /* 97 * Macros for type conversion 98 * fbtod(fb,t) - convert fusebuf pointer to data pointer of correct 99 * type 100 */ 101 #define fbtod(fb,t) ((t)((fb)->fb_dat)) 102 103 /* flags needed by setattr */ 104 #define FUSE_FATTR_MODE (1 << 0) 105 #define FUSE_FATTR_UID (1 << 1) 106 #define FUSE_FATTR_GID (1 << 2) 107 #define FUSE_FATTR_SIZE (1 << 3) 108 #define FUSE_FATTR_ATIME (1 << 4) 109 #define FUSE_FATTR_MTIME (1 << 5) 110 #define FUSE_FATTR_FH (1 << 6) 111 112 /* fusebuf types */ 113 #define FBT_LOOKUP 0 114 #define FBT_GETATTR 1 115 #define FBT_SETATTR 2 116 #define FBT_READLINK 3 117 #define FBT_SYMLINK 4 118 #define FBT_MKNOD 5 119 #define FBT_MKDIR 6 120 #define FBT_UNLINK 7 121 #define FBT_RMDIR 8 122 #define FBT_RENAME 9 123 #define FBT_LINK 10 124 #define FBT_OPEN 11 125 #define FBT_READ 12 126 #define FBT_WRITE 13 127 #define FBT_STATFS 14 128 #define FBT_RELEASE 16 129 #define FBT_FSYNC 17 130 #define FBT_FLUSH 18 131 #define FBT_INIT 19 132 #define FBT_OPENDIR 20 133 #define FBT_READDIR 21 134 #define FBT_RELEASEDIR 22 135 #define FBT_FSYNCDIR 23 136 #define FBT_ACCESS 24 137 #define FBT_DESTROY 26 138 #define FBT_RECLAIM 27 139 140 #ifdef _KERNEL 141 142 /* fusebuf prototypes */ 143 struct fusebuf *fb_setup(size_t, ino_t, int, struct proc *); 144 int fb_queue(dev_t, struct fusebuf *); 145 void fb_delete(struct fusebuf *); 146 147 #endif /* _KERNEL */ 148 #endif /* _SYS_FUSEBUF_H_ */ 149