1*390f10b5Shelg /* $OpenBSD: fuse.h,v 1.14 2018/05/16 13:09:17 helg Exp $ */ 275af46c2Stedu /* 375af46c2Stedu * Copyright (c) 2013 Sylvestre Gallon <ccna.syl@gmail.com> 475af46c2Stedu * 575af46c2Stedu * Permission to use, copy, modify, and distribute this software for any 675af46c2Stedu * purpose with or without fee is hereby granted, provided that the above 775af46c2Stedu * copyright notice and this permission notice appear in all copies. 875af46c2Stedu * 975af46c2Stedu * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 1075af46c2Stedu * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 1175af46c2Stedu * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 1275af46c2Stedu * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 1375af46c2Stedu * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 1475af46c2Stedu * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 1575af46c2Stedu * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 1675af46c2Stedu */ 1775af46c2Stedu 1875af46c2Stedu #ifndef _FUSE_H_ 1975af46c2Stedu #define _FUSE_H_ 2075af46c2Stedu 2175af46c2Stedu #include <sys/types.h> 2275af46c2Stedu #include <sys/stat.h> 2375af46c2Stedu #include <sys/statvfs.h> 2475af46c2Stedu 2575af46c2Stedu #include <fcntl.h> 2675af46c2Stedu #include <utime.h> 2775af46c2Stedu 28afb7a43fSsyl #include <fuse_opt.h> 29afb7a43fSsyl 3075af46c2Stedu #ifdef __cplusplus 3175af46c2Stedu extern "C" { 3275af46c2Stedu #endif 3375af46c2Stedu 3475af46c2Stedu struct fuse_chan; 3575af46c2Stedu struct fuse_args; 3675af46c2Stedu struct fuse_session; 3775af46c2Stedu 3875af46c2Stedu struct fuse_file_info { 3975af46c2Stedu int32_t flags; /* open(2) flags */ 4075af46c2Stedu uint32_t fh_old; /* old file handle */ 4175af46c2Stedu int32_t writepage; 4275af46c2Stedu uint32_t direct_io:1; 4375af46c2Stedu uint32_t keep_cache:1; 4475af46c2Stedu uint32_t flush:1; 459af1ea27Ssyl uint32_t nonseekable:1; 469af1ea27Ssyl uint32_t __padd:27; 479af1ea27Ssyl uint32_t flock_release : 1; 4875af46c2Stedu uint64_t fh; /* file handle */ 4975af46c2Stedu uint64_t lock_owner; 5075af46c2Stedu }; 5175af46c2Stedu 529af1ea27Ssyl /* unused but needed for gvfs compilation */ 539af1ea27Ssyl #define FUSE_CAP_ASYNC_READ (1 << 0) 549af1ea27Ssyl #define FUSE_CAP_POSIX_LOCKS (1 << 1) 559af1ea27Ssyl #define FUSE_CAP_ATOMIC_O_TRUNC (1 << 3) 569af1ea27Ssyl #define FUSE_CAP_EXPORT_SUPPORT (1 << 4) 579af1ea27Ssyl #define FUSE_CAP_BIG_WRITES (1 << 5) 589af1ea27Ssyl #define FUSE_CAP_DONT_MASK (1 << 6) 599af1ea27Ssyl #define FUSE_CAP_SPLICE_WRITE (1 << 7) 609af1ea27Ssyl #define FUSE_CAP_SPLICE_MOVE (1 << 8) 619af1ea27Ssyl #define FUSE_CAP_SPLICE_READ (1 << 9) 629af1ea27Ssyl #define FUSE_CAP_FLOCK_LOCKS (1 << 10) 639af1ea27Ssyl #define FUSE_CAP_IOCTL_DIR (1 << 11) 649af1ea27Ssyl 6575af46c2Stedu struct fuse_conn_info { 6675af46c2Stedu uint32_t proto_major; 6775af46c2Stedu uint32_t proto_minor; 6875af46c2Stedu uint32_t async_read; 6975af46c2Stedu uint32_t max_write; 7075af46c2Stedu uint32_t max_readahead; 719af1ea27Ssyl uint32_t capable; 729af1ea27Ssyl uint32_t want; 739af1ea27Ssyl uint32_t max_background; 749af1ea27Ssyl uint32_t congestion_threshold; 759af1ea27Ssyl uint32_t reserved[23]; 7675af46c2Stedu }; 7775af46c2Stedu 785f1aa8d9Ssyl struct fuse_context { 795f1aa8d9Ssyl struct fuse * fuse; 805f1aa8d9Ssyl uid_t uid; 815f1aa8d9Ssyl gid_t gid; 825f1aa8d9Ssyl pid_t pid; 835f1aa8d9Ssyl void *private_data; 845f1aa8d9Ssyl mode_t umask; 855f1aa8d9Ssyl }; 865f1aa8d9Ssyl 8775af46c2Stedu typedef ino_t fuse_ino_t; 8875af46c2Stedu typedef int (*fuse_fill_dir_t)(void *, const char *, const struct stat *, 8975af46c2Stedu off_t); 9075af46c2Stedu 91*390f10b5Shelg typedef struct fuse_dirhandle *fuse_dirh_t; 9275af46c2Stedu typedef int (*fuse_dirfil_t)(fuse_dirh_t, const char *, int, ino_t); 9375af46c2Stedu 94f58844d5Sstsp /* 95f58844d5Sstsp * Fuse operations work in the same way as their UNIX file system 96f58844d5Sstsp * counterparts. A major exception is that these routines return 97f58844d5Sstsp * a negated errno value (-errno) on failure. 98f58844d5Sstsp */ 9975af46c2Stedu struct fuse_operations { 10075af46c2Stedu int (*getattr)(const char *, struct stat *); 10175af46c2Stedu int (*readlink)(const char *, char *, size_t); 10275af46c2Stedu int (*getdir)(const char *, fuse_dirh_t, fuse_dirfil_t); 10375af46c2Stedu int (*mknod)(const char *, mode_t, dev_t); 10475af46c2Stedu int (*mkdir)(const char *, mode_t); 10575af46c2Stedu int (*unlink)(const char *); 10675af46c2Stedu int (*rmdir)(const char *); 10775af46c2Stedu int (*symlink)(const char *, const char *); 10875af46c2Stedu int (*rename)(const char *, const char *); 10975af46c2Stedu int (*link)(const char *, const char *); 11075af46c2Stedu int (*chmod)(const char *, mode_t); 11175af46c2Stedu int (*chown)(const char *, uid_t, gid_t); 11275af46c2Stedu int (*truncate)(const char *, off_t); 11375af46c2Stedu int (*utime)(const char *, struct utimbuf *); 11475af46c2Stedu int (*open)(const char *, struct fuse_file_info *); 11575af46c2Stedu int (*read)(const char *, char *, size_t, off_t, 11675af46c2Stedu struct fuse_file_info *); 11775af46c2Stedu int (*write)(const char *, const char *, size_t, off_t, 11875af46c2Stedu struct fuse_file_info *); 11975af46c2Stedu int (*statfs)(const char *, struct statvfs *); 12075af46c2Stedu int (*flush)(const char *, struct fuse_file_info *); 12175af46c2Stedu int (*release)(const char *, struct fuse_file_info *); 12275af46c2Stedu int (*fsync)(const char *, int, struct fuse_file_info *); 12375af46c2Stedu int (*setxattr)(const char *, const char *, const char *, size_t, 12475af46c2Stedu int); 12575af46c2Stedu int (*getxattr)(const char *, const char *, char *, size_t); 12675af46c2Stedu int (*listxattr)(const char *, char *, size_t); 12775af46c2Stedu int (*removexattr)(const char *, const char *); 12875af46c2Stedu int (*opendir)(const char *, struct fuse_file_info *); 12975af46c2Stedu int (*readdir)(const char *, void *, fuse_fill_dir_t, off_t, 13075af46c2Stedu struct fuse_file_info *); 13175af46c2Stedu int (*releasedir)(const char *, struct fuse_file_info *); 13275af46c2Stedu int (*fsyncdir)(const char *, int, struct fuse_file_info *); 13375af46c2Stedu void *(*init)(struct fuse_conn_info *); 13475af46c2Stedu void (*destroy)(void *); 13575af46c2Stedu int (*access)(const char *, int); 13675af46c2Stedu int (*create)(const char *, mode_t, struct fuse_file_info *); 13775af46c2Stedu int (*ftruncate)(const char *, off_t, struct fuse_file_info *); 13875af46c2Stedu int (*fgetattr)(const char *, struct stat *, struct fuse_file_info *); 13975af46c2Stedu int (*lock)(const char *, struct fuse_file_info *, int, struct flock *); 14075af46c2Stedu int (*utimens)(const char *, const struct timespec *); 14175af46c2Stedu int (*bmap)(const char *, size_t , uint64_t *); 14275af46c2Stedu }; 14375af46c2Stedu 14475af46c2Stedu #ifndef FUSE_USE_VERSION 14575af46c2Stedu #define FUSE_USE_VERSION 26 14675af46c2Stedu #endif 14775af46c2Stedu 14875af46c2Stedu #if FUSE_USE_VERSION >= 26 14975af46c2Stedu #define FUSE_VERSION 26 15075af46c2Stedu #else 15175af46c2Stedu #error "Fuse version < 26 not supported" 15275af46c2Stedu #endif 15375af46c2Stedu 154b2d085eaSjasper #define FUSE_MAJOR_VERSION 2 155b2d085eaSjasper #define FUSE_MINOR_VERSION 6 15675af46c2Stedu 15775af46c2Stedu /* 15875af46c2Stedu * API prototypes 15975af46c2Stedu */ 1609874ba4aSsyl int fuse_version(void); 16175af46c2Stedu int fuse_main(int, char **, const struct fuse_operations *, void *); 16275af46c2Stedu struct fuse *fuse_new(struct fuse_chan *, struct fuse_args *, 16375af46c2Stedu const struct fuse_operations *, size_t, void *); 164e4ecea32Ssyl struct fuse *fuse_setup(int, char **, const struct fuse_operations *, 165e4ecea32Ssyl size_t, char **, int *, void *); 16675af46c2Stedu int fuse_parse_cmdline(struct fuse_args *, char **, int *, int *); 16775af46c2Stedu struct fuse_chan *fuse_mount(const char *, struct fuse_args *); 16875af46c2Stedu void fuse_remove_signal_handlers(struct fuse_session *); 16975af46c2Stedu int fuse_set_signal_handlers(struct fuse_session *); 17075af46c2Stedu struct fuse_session *fuse_get_session(struct fuse *); 1715f1aa8d9Ssyl struct fuse_context *fuse_get_context(void); 17275af46c2Stedu int fuse_is_lib_option(const char *); 17375af46c2Stedu int fuse_loop(struct fuse *); 17475af46c2Stedu int fuse_loop_mt(struct fuse *); 17575af46c2Stedu int fuse_chan_fd(struct fuse_chan *); 17675af46c2Stedu void fuse_unmount(const char *, struct fuse_chan *); 17775af46c2Stedu int fuse_daemonize(int); 17875af46c2Stedu void fuse_destroy(struct fuse *); 1796e1e865eSsyl void fuse_teardown(struct fuse *, char *); 180e4ecea32Ssyl int fuse_invalidate(struct fuse *, const char *); 18175af46c2Stedu 18275af46c2Stedu #ifdef __cplusplus 18375af46c2Stedu } 18475af46c2Stedu #endif 18575af46c2Stedu 18675af46c2Stedu #endif /* _FUSE_H_ */ 187