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