1353ac78dSAneesh Kumar K.V /* 2af8b38b0SGreg Kurz * 9p 3353ac78dSAneesh Kumar K.V * 4353ac78dSAneesh Kumar K.V * Copyright IBM, Corp. 2010 5353ac78dSAneesh Kumar K.V * 6353ac78dSAneesh Kumar K.V * Authors: 7353ac78dSAneesh Kumar K.V * Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com> 8353ac78dSAneesh Kumar K.V * 9353ac78dSAneesh Kumar K.V * This work is licensed under the terms of the GNU GPL, version 2. See 10353ac78dSAneesh Kumar K.V * the COPYING file in the top-level directory. 11353ac78dSAneesh Kumar K.V * 12353ac78dSAneesh Kumar K.V */ 13121d0712SMarkus Armbruster 14121d0712SMarkus Armbruster #ifndef FILE_OP_9P_H 15121d0712SMarkus Armbruster #define FILE_OP_9P_H 16121d0712SMarkus Armbruster 17353ac78dSAneesh Kumar K.V #include <dirent.h> 18353ac78dSAneesh Kumar K.V #include <utime.h> 19353ac78dSAneesh Kumar K.V #include <sys/vfs.h> 20b8bbdb88SPradeep Jagadeesh #include "qemu-fsdev-throttle.h" 210174fe73SAneesh Kumar K.V 22353ac78dSAneesh Kumar K.V #define SM_LOCAL_MODE_BITS 0600 23353ac78dSAneesh Kumar K.V #define SM_LOCAL_DIR_MODE_BITS 0700 24353ac78dSAneesh Kumar K.V 25353ac78dSAneesh Kumar K.V typedef struct FsCred 26353ac78dSAneesh Kumar K.V { 27353ac78dSAneesh Kumar K.V uid_t fc_uid; 28353ac78dSAneesh Kumar K.V gid_t fc_gid; 29353ac78dSAneesh Kumar K.V mode_t fc_mode; 30353ac78dSAneesh Kumar K.V dev_t fc_rdev; 31353ac78dSAneesh Kumar K.V } FsCred; 32353ac78dSAneesh Kumar K.V 33353ac78dSAneesh Kumar K.V struct xattr_operations; 34e06a765eSHarsh Prateek Bora struct FsContext; 35e06a765eSHarsh Prateek Bora struct V9fsPath; 36e06a765eSHarsh Prateek Bora 37e06a765eSHarsh Prateek Bora typedef struct extended_ops { 38e06a765eSHarsh Prateek Bora int (*get_st_gen)(struct FsContext *, struct V9fsPath *, 39e06a765eSHarsh Prateek Bora mode_t, uint64_t *); 40e06a765eSHarsh Prateek Bora } extended_ops; 41353ac78dSAneesh Kumar K.V 42d3ab98e6SAneesh Kumar K.V /* export flags */ 43c98f1d4aSAneesh Kumar K.V #define V9FS_IMMEDIATE_WRITEOUT 0x00000001 44c98f1d4aSAneesh Kumar K.V #define V9FS_PATHNAME_FSCONTEXT 0x00000002 45b97400caSAneesh Kumar K.V /* 46b97400caSAneesh Kumar K.V * uid/gid set on fileserver files 47b97400caSAneesh Kumar K.V */ 48b97400caSAneesh Kumar K.V #define V9FS_SM_PASSTHROUGH 0x00000004 49b97400caSAneesh Kumar K.V /* 50b97400caSAneesh Kumar K.V * uid/gid part of xattr 51b97400caSAneesh Kumar K.V */ 52b97400caSAneesh Kumar K.V #define V9FS_SM_MAPPED 0x00000008 53b97400caSAneesh Kumar K.V /* 54b97400caSAneesh Kumar K.V * Server will try to set uid/gid. 55b97400caSAneesh Kumar K.V * On failure ignore the error. 56b97400caSAneesh Kumar K.V */ 57b97400caSAneesh Kumar K.V #define V9FS_SM_NONE 0x00000010 582c30dd74SAneesh Kumar K.V /* 592c30dd74SAneesh Kumar K.V * uid/gid part of .virtfs_meatadata namespace 602c30dd74SAneesh Kumar K.V */ 612c30dd74SAneesh Kumar K.V #define V9FS_SM_MAPPED_FILE 0x00000020 622c30dd74SAneesh Kumar K.V #define V9FS_RDONLY 0x00000040 632c30dd74SAneesh Kumar K.V #define V9FS_PROXY_SOCK_FD 0x00000080 642c30dd74SAneesh Kumar K.V #define V9FS_PROXY_SOCK_NAME 0x00000100 65b97400caSAneesh Kumar K.V 662c30dd74SAneesh Kumar K.V #define V9FS_SEC_MASK 0x0000003C 67d3ab98e6SAneesh Kumar K.V 682c74c2cbSM. Mohan Kumar 6999519f0aSAneesh Kumar K.V typedef struct FileOperations FileOperations; 7099519f0aSAneesh Kumar K.V /* 7199519f0aSAneesh Kumar K.V * Structure to store the various fsdev's passed through command line. 7299519f0aSAneesh Kumar K.V */ 7399519f0aSAneesh Kumar K.V typedef struct FsDriverEntry { 7499519f0aSAneesh Kumar K.V char *fsdev_id; 7599519f0aSAneesh Kumar K.V char *path; 7699519f0aSAneesh Kumar K.V int export_flags; 7799519f0aSAneesh Kumar K.V FileOperations *ops; 78b8bbdb88SPradeep Jagadeesh FsThrottle fst; 79*b96feb2cSTobias Schramm mode_t fmode; 80*b96feb2cSTobias Schramm mode_t dmode; 8199519f0aSAneesh Kumar K.V } FsDriverEntry; 822c74c2cbSM. Mohan Kumar 83353ac78dSAneesh Kumar K.V typedef struct FsContext 84353ac78dSAneesh Kumar K.V { 85353ac78dSAneesh Kumar K.V uid_t uid; 86b97400caSAneesh Kumar K.V char *fs_root; 87d3ab98e6SAneesh Kumar K.V int export_flags; 88353ac78dSAneesh Kumar K.V struct xattr_operations **xops; 89e06a765eSHarsh Prateek Bora struct extended_ops exops; 90b8bbdb88SPradeep Jagadeesh FsThrottle *fst; 91532decb7SAneesh Kumar K.V /* fs driver specific data */ 92532decb7SAneesh Kumar K.V void *private; 93*b96feb2cSTobias Schramm mode_t fmode; 94*b96feb2cSTobias Schramm mode_t dmode; 95353ac78dSAneesh Kumar K.V } FsContext; 96353ac78dSAneesh Kumar K.V 972289be19SAneesh Kumar K.V typedef struct V9fsPath { 982f008a8cSAneesh Kumar K.V uint16_t size; 992289be19SAneesh Kumar K.V char *data; 1002289be19SAneesh Kumar K.V } V9fsPath; 1012289be19SAneesh Kumar K.V 102cc720ddbSAneesh Kumar K.V typedef union V9fsFidOpenState V9fsFidOpenState; 103cc720ddbSAneesh Kumar K.V 104353ac78dSAneesh Kumar K.V void cred_init(FsCred *); 105353ac78dSAneesh Kumar K.V 10699519f0aSAneesh Kumar K.V struct FileOperations 107353ac78dSAneesh Kumar K.V { 10899519f0aSAneesh Kumar K.V int (*parse_opts)(QemuOpts *, struct FsDriverEntry *); 1090174fe73SAneesh Kumar K.V int (*init)(struct FsContext *); 110702dbcc2SLi Qiang void (*cleanup)(struct FsContext *); 1112289be19SAneesh Kumar K.V int (*lstat)(FsContext *, V9fsPath *, struct stat *); 1122289be19SAneesh Kumar K.V ssize_t (*readlink)(FsContext *, V9fsPath *, char *, size_t); 1132289be19SAneesh Kumar K.V int (*chmod)(FsContext *, V9fsPath *, FsCred *); 1142289be19SAneesh Kumar K.V int (*chown)(FsContext *, V9fsPath *, FsCred *); 1152289be19SAneesh Kumar K.V int (*mknod)(FsContext *, V9fsPath *, const char *, FsCred *); 1162289be19SAneesh Kumar K.V int (*utimensat)(FsContext *, V9fsPath *, const struct timespec *); 117353ac78dSAneesh Kumar K.V int (*remove)(FsContext *, const char *); 1182289be19SAneesh Kumar K.V int (*symlink)(FsContext *, const char *, V9fsPath *, 1192289be19SAneesh Kumar K.V const char *, FsCred *); 1202289be19SAneesh Kumar K.V int (*link)(FsContext *, V9fsPath *, V9fsPath *, const char *); 121353ac78dSAneesh Kumar K.V int (*setuid)(FsContext *, uid_t); 122cc720ddbSAneesh Kumar K.V int (*close)(FsContext *, V9fsFidOpenState *); 123cc720ddbSAneesh Kumar K.V int (*closedir)(FsContext *, V9fsFidOpenState *); 124cc720ddbSAneesh Kumar K.V int (*opendir)(FsContext *, V9fsPath *, V9fsFidOpenState *); 125cc720ddbSAneesh Kumar K.V int (*open)(FsContext *, V9fsPath *, int, V9fsFidOpenState *); 126cc720ddbSAneesh Kumar K.V int (*open2)(FsContext *, V9fsPath *, const char *, 127cc720ddbSAneesh Kumar K.V int, FsCred *, V9fsFidOpenState *); 128cc720ddbSAneesh Kumar K.V void (*rewinddir)(FsContext *, V9fsFidOpenState *); 129cc720ddbSAneesh Kumar K.V off_t (*telldir)(FsContext *, V9fsFidOpenState *); 130635324e8SGreg Kurz struct dirent * (*readdir)(FsContext *, V9fsFidOpenState *); 131cc720ddbSAneesh Kumar K.V void (*seekdir)(FsContext *, V9fsFidOpenState *, off_t); 132cc720ddbSAneesh Kumar K.V ssize_t (*preadv)(FsContext *, V9fsFidOpenState *, 133cc720ddbSAneesh Kumar K.V const struct iovec *, int, off_t); 134cc720ddbSAneesh Kumar K.V ssize_t (*pwritev)(FsContext *, V9fsFidOpenState *, 135cc720ddbSAneesh Kumar K.V const struct iovec *, int, off_t); 1362289be19SAneesh Kumar K.V int (*mkdir)(FsContext *, V9fsPath *, const char *, FsCred *); 1378b888272SAneesh Kumar K.V int (*fstat)(FsContext *, int, V9fsFidOpenState *, struct stat *); 138353ac78dSAneesh Kumar K.V int (*rename)(FsContext *, const char *, const char *); 1392289be19SAneesh Kumar K.V int (*truncate)(FsContext *, V9fsPath *, off_t); 1408b888272SAneesh Kumar K.V int (*fsync)(FsContext *, int, V9fsFidOpenState *, int); 1412289be19SAneesh Kumar K.V int (*statfs)(FsContext *s, V9fsPath *path, struct statfs *stbuf); 1422289be19SAneesh Kumar K.V ssize_t (*lgetxattr)(FsContext *, V9fsPath *, 143353ac78dSAneesh Kumar K.V const char *, void *, size_t); 1442289be19SAneesh Kumar K.V ssize_t (*llistxattr)(FsContext *, V9fsPath *, void *, size_t); 1452289be19SAneesh Kumar K.V int (*lsetxattr)(FsContext *, V9fsPath *, 146353ac78dSAneesh Kumar K.V const char *, void *, size_t, int); 1472289be19SAneesh Kumar K.V int (*lremovexattr)(FsContext *, V9fsPath *, const char *); 1482289be19SAneesh Kumar K.V int (*name_to_path)(FsContext *, V9fsPath *, const char *, V9fsPath *); 1492289be19SAneesh Kumar K.V int (*renameat)(FsContext *ctx, V9fsPath *olddir, const char *old_name, 1502289be19SAneesh Kumar K.V V9fsPath *newdir, const char *new_name); 1512289be19SAneesh Kumar K.V int (*unlinkat)(FsContext *ctx, V9fsPath *dir, const char *name, int flags); 152353ac78dSAneesh Kumar K.V void *opaque; 15399519f0aSAneesh Kumar K.V }; 154353ac78dSAneesh Kumar K.V 155353ac78dSAneesh Kumar K.V #endif 156