1 #ifndef LIBRARIES_FILESYSBOX_H 2 #define LIBRARIES_FILESYSBOX_H 1 3 4 /*********************************************************************/ 5 /********** Public structures and definitions of Filesysbox **********/ 6 /*********************************************************************/ 7 8 #include <sys/types.h> 9 #include <sys/stat.h> 10 #include <sys/statvfs.h> 11 #if !defined(_FILESYSBOX_SYS_TYPES_H_) || !defined(_FILESYSBOX_SYS_STAT_H_) || !defined(_FILESYSBOX_SYS_STATVFS_H_) 12 #error "filesysbox include priority is wrong" 13 #endif 14 #include <utime.h> 15 #include <fcntl.h> 16 17 #include <utility/tagitem.h> 18 19 #define FILESYSBOX_VERSION 5 20 #define FILESYSBOX_NAME "filesysbox.library" 21 22 #define FUSE_VERSION 26 23 24 #define FBXQMM_MOUNT_NAME 1 25 #define FBXQMM_MOUNT_CONTROL 2 26 // v1 27 #define FBXQMM_FSSM 3 28 #define FBXQMM_ENVIRON 4 29 30 #define CONN_VOLUME_NAME_BYTES 128 31 32 // v1: attributes for fs->getfsattr(), fs->setfsattr() 33 #define GFSA_VOLUME_TIMESPEC 0 // struct timespec 34 //#define GFSA_VOLUME_NAME 1 // CSTRING 35 36 // v1: FbxCauseVolumeChange() numbers 37 #define FBX_VCHANGE_SETUP 1 38 #define FBX_VCHANGE_CLEANUP 2 39 #define FBX_VCHANGE_RESETUP 3 40 41 struct fuse_conn_info { 42 /* not used yet, just cleared */ 43 unsigned proto_major; 44 unsigned proto_minor; 45 unsigned async_read; 46 unsigned max_write; 47 unsigned max_readahead; 48 unsigned reserved[27]; 49 /* filesysbox addition */ 50 char volume_name[CONN_VOLUME_NAME_BYTES]; // for .init() to fill 51 }; 52 53 // filesysbox sets flags and reads nonseekable for now. 54 // rest is cleared and untouched. "fh_old" and "fh" are 55 // safe to be poked by FS. 56 struct fuse_file_info { 57 int flags; 58 unsigned long fh_old; 59 int writepage; 60 unsigned int direct_io : 1; 61 unsigned int keep_cache : 1; 62 unsigned int flush : 1; 63 unsigned int nonseekable : 1; // fuse 2.9 64 unsigned int padding : 28; 65 long long fh; 66 long long lock_owner; /* not used */ 67 }; 68 69 // flags for FBXT_FSFLAGS 70 #define FBXF_ENABLE_UTF8_NAMES 1 // does nothing as of v1 71 // v1 72 #define FBXF_STAT_PROTECTION 2 73 // v2 74 #define FBXF_PROPER_READDIR 4 75 76 // tags for FbxSetupFS() 77 #define FBXT_FSFLAGS (TAG_USER + 1) // ULONG 78 #define FBXT_FSSM (TAG_USER + 2) // struct FileSysStartupMsg* 79 #define FBXT_DOSTYPE (TAG_USER + 3) // ULONG 80 #define FBXT_GET_CONTEXT (TAG_USER + 4) // struct fuse_context** 81 // v1 82 #define FBXT_AUTO_UPDATE (TAG_USER + 5) // ULONG ((iaut << 16) | aut) 83 // iaut: inactive update timeout in tens of seconds 84 // aut: active update timeout in tens of seconds 85 // v4 86 #define FBXT_PATH_PREFIX (TAG_USER + 6) // pass cstring (gets copied). 87 // 4.10 88 #define FBXT_ADD_DEVICE (TAG_USER + 7) // pass name of dummy device 89 90 typedef int (*fuse_fill_dir32_t ) (void *buf, const char *name, const struct FbxStat32 *stbuf, off_t off); 91 typedef int (*fuse_fill_dir_t ) (void *buf, const char *name, const struct FbxStat *stbuf, off_t off); 92 93 // v1. 94 struct FbxDiskChange { 95 void *userdata; 96 void *privdata; 97 struct Library *sysbase; 98 int num_methods; // 2 99 int (*isdiskinserted) (struct FbxDiskChange *); 100 int (*isdiskprotected) (struct FbxDiskChange *); 101 }; 102 typedef void (*FbxDiskChangeFunc) (struct FbxDiskChange *); 103 104 // v1: errors set by FbxInstallDiskChangeHandler() 105 #define IDCHERR_MEMORY 1 106 #define IDCHERR_MSGPORT 2 107 #define IDCHERR_OPENDEV 3 108 109 // lazy macros 110 #define fuse_get_context() _fuse_context_ 111 #define fuse_version() FbxFuseVersion() 112 #define fuse_new(fh,tags,ops,opssize,udata) FbxSetupFS(fh,tags,ops,opssize,udata) 113 #define fuse_loop(fh) FbxEventLoop(fh) 114 #define fuse_destroy(fh) FbxCleanupFS(fh) 115 116 struct FbxFS; 117 118 struct fuse_context { 119 120 // return value of FbxSetupFS() 121 struct FbxFS *fuse; 122 123 // these are all zero for now, but may change in future 124 uid_t uid; 125 gid_t gid; 126 pid_t pid; 127 128 // user_data argument of FbxSetupFS() 129 void *private_data; 130 }; 131 132 struct fuse_operations { 133 int (*getattr32) (const char *, struct FbxStat32 *); 134 int (*readlink) (const char *, char *, size_t); 135 int (*mknod) (const char *, mode_t, dev_t); 136 int (*mkdir) (const char *, mode_t); 137 int (*unlink) (const char *); 138 int (*rmdir) (const char *); 139 int (*symlink) (const char *, const char *); 140 int (*rename) (const char *, const char *); 141 int (*link) (const char *, const char *); 142 int (*chmod) (const char *, mode_t); 143 int (*chown) (const char *, uid_t, gid_t); 144 int (*truncate) (const char *, off_t); 145 int (*utime32) (const char *, struct fsb_utimbuf32 *); 146 int (*open) (const char *, struct fuse_file_info *); 147 int (*read) (const char *, char *, size_t, off_t, struct fuse_file_info *); 148 int (*write) (const char *, const char *, size_t, off_t, struct fuse_file_info *); 149 int (*statfs) (const char *, struct statvfs *); 150 int (*flush) (const char *, struct fuse_file_info *); 151 int (*release) (const char *, struct fuse_file_info *); 152 int (*fsync) (const char *, int, struct fuse_file_info *); 153 int (*setxattr) (const char *, const char *, const char *, size_t, int); 154 int (*getxattr) (const char *, const char *, char *, size_t); 155 int (*listxattr) (const char *, char *, size_t); 156 int (*removexattr) (const char *, const char *); 157 int (*opendir) (const char *, struct fuse_file_info *); 158 int (*readdir32) (const char *, void *, fuse_fill_dir32_t, off_t, struct fuse_file_info *); 159 int (*releasedir) (const char *, struct fuse_file_info *); 160 int (*fsyncdir) (const char *, int, struct fuse_file_info *); 161 void *(*init) (struct fuse_conn_info *conn); 162 void (*destroy) (void *); 163 int (*access) (const char *, int); 164 int (*create) (const char *, mode_t, struct fuse_file_info *); 165 int (*ftruncate) (const char *, off_t, struct fuse_file_info *); 166 int (*fgetattr32) (const char *, struct FbxStat32 *, struct fuse_file_info *); 167 int (*lock) (const char *, struct fuse_file_info *, int cmd, struct flock *); 168 int (*utimens32) (const char *, const struct fsb_timespec32 tv[2]); 169 int (*bmap) (const char *, size_t blocksize, off_t *idx); 170 unsigned int flag_nullpath_ok : 1; 171 unsigned int flag_reserved : 31; 172 /* v1 additions */ 173 int (*setprotect) (const char *, unsigned long); 174 int (*update) (void); 175 int (*getfsattr) (int, void *, int); // not used yet 176 int (*setfsattr) (int, void *, int); // not used yet 177 int (*relabel) (const char *); // not used yet 178 /* v5 - 64-bit time functions */ 179 int (*getattr) (const char *, struct FbxStat *); 180 int (*utime) (const char *, struct fsb_utimbuf64 *); 181 int (*readdir) (const char *, void *, fuse_fill_dir_t, off_t, struct fuse_file_info *); 182 int (*fgetattr) (const char *, struct FbxStat *, struct fuse_file_info *); 183 int (*utimens) (const char *, const struct fsb_timespec64 tv[2]); 184 }; 185 186 187 // v2 188 typedef void (*FbxTimerCallbackFunc)(struct fuse_context *fcntx); 189 typedef void (*FbxSignalCallbackFunc)(size_t matching_signals, struct fuse_context *fcntx); 190 191 // V2, forward declaration 192 struct FbxTimerCallbackData; 193 194 // v3 195 typedef void (*FbxPushCallbackFunc)(void *arg, struct fuse_context *fcntx); 196 197 // v5 utimens() can see FSB_UTIME_OMIT in tv_nsec, in which case that time is 198 // not changed. Note that FSB_UTIME_NOW will be replaced by the current time 199 // by the library and thus is not seen by the utimens(). 200 #define FSB_UTIME_NOW ((1l << 30) - 1l) // set time to current time 201 #define FSB_UTIME_OMIT ((1l << 30) - 2l) // don't touch time 202 203 #endif /* LIBRARIES_FILESYSBOX_H */