1 /* 2 * 9p 3 * 4 * Copyright IBM, Corp. 2010 5 * 6 * Authors: 7 * Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com> 8 * 9 * This work is licensed under the terms of the GNU GPL, version 2. See 10 * the COPYING file in the top-level directory. 11 * 12 */ 13 14 #ifndef FILE_OP_9P_H 15 #define FILE_OP_9P_H 16 17 #include <dirent.h> 18 #include <utime.h> 19 #include <sys/vfs.h> 20 #include "qemu-fsdev-throttle.h" 21 22 #define SM_LOCAL_MODE_BITS 0600 23 #define SM_LOCAL_DIR_MODE_BITS 0700 24 25 typedef struct FsCred 26 { 27 uid_t fc_uid; 28 gid_t fc_gid; 29 mode_t fc_mode; 30 dev_t fc_rdev; 31 } FsCred; 32 33 struct FsContext; 34 struct V9fsPath; 35 36 typedef struct extended_ops { 37 int (*get_st_gen)(struct FsContext *, struct V9fsPath *, 38 mode_t, uint64_t *); 39 } extended_ops; 40 41 /* export flags */ 42 #define V9FS_IMMEDIATE_WRITEOUT 0x00000001 43 #define V9FS_PATHNAME_FSCONTEXT 0x00000002 44 /* 45 * uid/gid set on fileserver files 46 */ 47 #define V9FS_SM_PASSTHROUGH 0x00000004 48 /* 49 * uid/gid part of xattr 50 */ 51 #define V9FS_SM_MAPPED 0x00000008 52 /* 53 * Server will try to set uid/gid. 54 * On failure ignore the error. 55 */ 56 #define V9FS_SM_NONE 0x00000010 57 /* 58 * uid/gid part of .virtfs_meatadata namespace 59 */ 60 #define V9FS_SM_MAPPED_FILE 0x00000020 61 #define V9FS_RDONLY 0x00000040 62 #define V9FS_PROXY_SOCK_FD 0x00000080 63 #define V9FS_PROXY_SOCK_NAME 0x00000100 64 65 #define V9FS_SEC_MASK 0x0000003C 66 67 68 typedef struct FileOperations FileOperations; 69 typedef struct XattrOperations XattrOperations; 70 71 /* 72 * Structure to store the various fsdev's passed through command line. 73 */ 74 typedef struct FsDriverEntry { 75 char *fsdev_id; 76 char *path; 77 int export_flags; 78 FileOperations *ops; 79 FsThrottle fst; 80 mode_t fmode; 81 mode_t dmode; 82 } FsDriverEntry; 83 84 typedef struct FsContext 85 { 86 uid_t uid; 87 char *fs_root; 88 int export_flags; 89 XattrOperations **xops; 90 struct extended_ops exops; 91 FsThrottle *fst; 92 /* fs driver specific data */ 93 void *private; 94 mode_t fmode; 95 mode_t dmode; 96 } FsContext; 97 98 typedef struct V9fsPath { 99 uint16_t size; 100 char *data; 101 } V9fsPath; 102 103 typedef union V9fsFidOpenState V9fsFidOpenState; 104 105 void cred_init(FsCred *); 106 107 struct FileOperations 108 { 109 int (*parse_opts)(QemuOpts *, struct FsDriverEntry *); 110 int (*init)(struct FsContext *); 111 void (*cleanup)(struct FsContext *); 112 int (*lstat)(FsContext *, V9fsPath *, struct stat *); 113 ssize_t (*readlink)(FsContext *, V9fsPath *, char *, size_t); 114 int (*chmod)(FsContext *, V9fsPath *, FsCred *); 115 int (*chown)(FsContext *, V9fsPath *, FsCred *); 116 int (*mknod)(FsContext *, V9fsPath *, const char *, FsCred *); 117 int (*utimensat)(FsContext *, V9fsPath *, const struct timespec *); 118 int (*remove)(FsContext *, const char *); 119 int (*symlink)(FsContext *, const char *, V9fsPath *, 120 const char *, FsCred *); 121 int (*link)(FsContext *, V9fsPath *, V9fsPath *, const char *); 122 int (*setuid)(FsContext *, uid_t); 123 int (*close)(FsContext *, V9fsFidOpenState *); 124 int (*closedir)(FsContext *, V9fsFidOpenState *); 125 int (*opendir)(FsContext *, V9fsPath *, V9fsFidOpenState *); 126 int (*open)(FsContext *, V9fsPath *, int, V9fsFidOpenState *); 127 int (*open2)(FsContext *, V9fsPath *, const char *, 128 int, FsCred *, V9fsFidOpenState *); 129 void (*rewinddir)(FsContext *, V9fsFidOpenState *); 130 off_t (*telldir)(FsContext *, V9fsFidOpenState *); 131 struct dirent * (*readdir)(FsContext *, V9fsFidOpenState *); 132 void (*seekdir)(FsContext *, V9fsFidOpenState *, off_t); 133 ssize_t (*preadv)(FsContext *, V9fsFidOpenState *, 134 const struct iovec *, int, off_t); 135 ssize_t (*pwritev)(FsContext *, V9fsFidOpenState *, 136 const struct iovec *, int, off_t); 137 int (*mkdir)(FsContext *, V9fsPath *, const char *, FsCred *); 138 int (*fstat)(FsContext *, int, V9fsFidOpenState *, struct stat *); 139 int (*rename)(FsContext *, const char *, const char *); 140 int (*truncate)(FsContext *, V9fsPath *, off_t); 141 int (*fsync)(FsContext *, int, V9fsFidOpenState *, int); 142 int (*statfs)(FsContext *s, V9fsPath *path, struct statfs *stbuf); 143 ssize_t (*lgetxattr)(FsContext *, V9fsPath *, 144 const char *, void *, size_t); 145 ssize_t (*llistxattr)(FsContext *, V9fsPath *, void *, size_t); 146 int (*lsetxattr)(FsContext *, V9fsPath *, 147 const char *, void *, size_t, int); 148 int (*lremovexattr)(FsContext *, V9fsPath *, const char *); 149 int (*name_to_path)(FsContext *, V9fsPath *, const char *, V9fsPath *); 150 int (*renameat)(FsContext *ctx, V9fsPath *olddir, const char *old_name, 151 V9fsPath *newdir, const char *new_name); 152 int (*unlinkat)(FsContext *ctx, V9fsPath *dir, const char *name, int flags); 153 void *opaque; 154 }; 155 156 #endif 157