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> 19b8bbdb88SPradeep Jagadeesh #include "qemu-fsdev-throttle.h" 20cc82fde9SChristian Schoenebeck #include "p9array.h" 210174fe73SAneesh Kumar K.V 22*e0bd743bSKeno Fischer #ifdef CONFIG_LINUX 23*e0bd743bSKeno Fischer # include <sys/vfs.h> 24*e0bd743bSKeno Fischer #endif 25*e0bd743bSKeno Fischer #ifdef CONFIG_DARWIN 26*e0bd743bSKeno Fischer # include <sys/param.h> 27*e0bd743bSKeno Fischer # include <sys/mount.h> 28*e0bd743bSKeno Fischer #endif 29*e0bd743bSKeno Fischer 30353ac78dSAneesh Kumar K.V #define SM_LOCAL_MODE_BITS 0600 31353ac78dSAneesh Kumar K.V #define SM_LOCAL_DIR_MODE_BITS 0700 32353ac78dSAneesh Kumar K.V 331a8d0bb3SGreg Kurz typedef struct FsCred { 34353ac78dSAneesh Kumar K.V uid_t fc_uid; 35353ac78dSAneesh Kumar K.V gid_t fc_gid; 36353ac78dSAneesh Kumar K.V mode_t fc_mode; 37353ac78dSAneesh Kumar K.V dev_t fc_rdev; 38353ac78dSAneesh Kumar K.V } FsCred; 39353ac78dSAneesh Kumar K.V 401a8d0bb3SGreg Kurz typedef struct FsContext FsContext; 411a8d0bb3SGreg Kurz typedef struct V9fsPath V9fsPath; 42e06a765eSHarsh Prateek Bora 431a8d0bb3SGreg Kurz typedef struct ExtendedOps { 441a8d0bb3SGreg Kurz int (*get_st_gen)(FsContext *, V9fsPath *, mode_t, uint64_t *); 451a8d0bb3SGreg Kurz } ExtendedOps; 46353ac78dSAneesh Kumar K.V 47d3ab98e6SAneesh Kumar K.V /* export flags */ 48c98f1d4aSAneesh Kumar K.V #define V9FS_IMMEDIATE_WRITEOUT 0x00000001 49c98f1d4aSAneesh Kumar K.V #define V9FS_PATHNAME_FSCONTEXT 0x00000002 50b97400caSAneesh Kumar K.V /* 51b97400caSAneesh Kumar K.V * uid/gid set on fileserver files 52b97400caSAneesh Kumar K.V */ 53b97400caSAneesh Kumar K.V #define V9FS_SM_PASSTHROUGH 0x00000004 54b97400caSAneesh Kumar K.V /* 55b97400caSAneesh Kumar K.V * uid/gid part of xattr 56b97400caSAneesh Kumar K.V */ 57b97400caSAneesh Kumar K.V #define V9FS_SM_MAPPED 0x00000008 58b97400caSAneesh Kumar K.V /* 59b97400caSAneesh Kumar K.V * Server will try to set uid/gid. 60b97400caSAneesh Kumar K.V * On failure ignore the error. 61b97400caSAneesh Kumar K.V */ 62b97400caSAneesh Kumar K.V #define V9FS_SM_NONE 0x00000010 632c30dd74SAneesh Kumar K.V /* 642c30dd74SAneesh Kumar K.V * uid/gid part of .virtfs_meatadata namespace 652c30dd74SAneesh Kumar K.V */ 662c30dd74SAneesh Kumar K.V #define V9FS_SM_MAPPED_FILE 0x00000020 672c30dd74SAneesh Kumar K.V #define V9FS_RDONLY 0x00000040 682c30dd74SAneesh Kumar K.V #define V9FS_PROXY_SOCK_FD 0x00000080 692c30dd74SAneesh Kumar K.V #define V9FS_PROXY_SOCK_NAME 0x00000100 701a6ed33cSAntonios Motakis /* 711a6ed33cSAntonios Motakis * multidevs option (either one of the two applies exclusively) 721a6ed33cSAntonios Motakis */ 731a6ed33cSAntonios Motakis #define V9FS_REMAP_INODES 0x00000200 741a6ed33cSAntonios Motakis #define V9FS_FORBID_MULTIDEVS 0x00000400 75c418f935SChristian Schoenebeck /* 76c418f935SChristian Schoenebeck * Disables certain performance warnings from being logged on host side. 77c418f935SChristian Schoenebeck */ 78c418f935SChristian Schoenebeck #define V9FS_NO_PERF_WARN 0x00000800 79b97400caSAneesh Kumar K.V 802c30dd74SAneesh Kumar K.V #define V9FS_SEC_MASK 0x0000003C 81d3ab98e6SAneesh Kumar K.V 822c74c2cbSM. Mohan Kumar 8399519f0aSAneesh Kumar K.V typedef struct FileOperations FileOperations; 8401847522SGreg Kurz typedef struct XattrOperations XattrOperations; 8501847522SGreg Kurz 8699519f0aSAneesh Kumar K.V /* 8799519f0aSAneesh Kumar K.V * Structure to store the various fsdev's passed through command line. 8899519f0aSAneesh Kumar K.V */ 8999519f0aSAneesh Kumar K.V typedef struct FsDriverEntry { 9099519f0aSAneesh Kumar K.V char *fsdev_id; 9199519f0aSAneesh Kumar K.V char *path; 9299519f0aSAneesh Kumar K.V int export_flags; 9399519f0aSAneesh Kumar K.V FileOperations *ops; 94b8bbdb88SPradeep Jagadeesh FsThrottle fst; 95b96feb2cSTobias Schramm mode_t fmode; 96b96feb2cSTobias Schramm mode_t dmode; 9799519f0aSAneesh Kumar K.V } FsDriverEntry; 982c74c2cbSM. Mohan Kumar 991a8d0bb3SGreg Kurz struct FsContext { 100353ac78dSAneesh Kumar K.V uid_t uid; 101b97400caSAneesh Kumar K.V char *fs_root; 102d3ab98e6SAneesh Kumar K.V int export_flags; 10301847522SGreg Kurz XattrOperations **xops; 1041a8d0bb3SGreg Kurz ExtendedOps exops; 105b8bbdb88SPradeep Jagadeesh FsThrottle *fst; 106532decb7SAneesh Kumar K.V /* fs driver specific data */ 107532decb7SAneesh Kumar K.V void *private; 108b96feb2cSTobias Schramm mode_t fmode; 109b96feb2cSTobias Schramm mode_t dmode; 1101a8d0bb3SGreg Kurz }; 111353ac78dSAneesh Kumar K.V 1121a8d0bb3SGreg Kurz struct V9fsPath { 1132f008a8cSAneesh Kumar K.V uint16_t size; 1142289be19SAneesh Kumar K.V char *data; 1151a8d0bb3SGreg Kurz }; 116cc82fde9SChristian Schoenebeck P9ARRAY_DECLARE_TYPE(V9fsPath); 1172289be19SAneesh Kumar K.V 118cc720ddbSAneesh Kumar K.V typedef union V9fsFidOpenState V9fsFidOpenState; 119cc720ddbSAneesh Kumar K.V 120353ac78dSAneesh Kumar K.V void cred_init(FsCred *); 121353ac78dSAneesh Kumar K.V 12287b804ecSzhouyang struct FileOperations { 12391cda4e8SGreg Kurz int (*parse_opts)(QemuOpts *, FsDriverEntry *, Error **errp); 12465603a80SGreg Kurz int (*init)(FsContext *, Error **errp); 1251a8d0bb3SGreg Kurz void (*cleanup)(FsContext *); 1262289be19SAneesh Kumar K.V int (*lstat)(FsContext *, V9fsPath *, struct stat *); 1272289be19SAneesh Kumar K.V ssize_t (*readlink)(FsContext *, V9fsPath *, char *, size_t); 1282289be19SAneesh Kumar K.V int (*chmod)(FsContext *, V9fsPath *, FsCred *); 1292289be19SAneesh Kumar K.V int (*chown)(FsContext *, V9fsPath *, FsCred *); 1302289be19SAneesh Kumar K.V int (*mknod)(FsContext *, V9fsPath *, const char *, FsCred *); 1312289be19SAneesh Kumar K.V int (*utimensat)(FsContext *, V9fsPath *, const struct timespec *); 132353ac78dSAneesh Kumar K.V int (*remove)(FsContext *, const char *); 1332289be19SAneesh Kumar K.V int (*symlink)(FsContext *, const char *, V9fsPath *, 1342289be19SAneesh Kumar K.V const char *, FsCred *); 1352289be19SAneesh Kumar K.V int (*link)(FsContext *, V9fsPath *, V9fsPath *, const char *); 136353ac78dSAneesh Kumar K.V int (*setuid)(FsContext *, uid_t); 137cc720ddbSAneesh Kumar K.V int (*close)(FsContext *, V9fsFidOpenState *); 138cc720ddbSAneesh Kumar K.V int (*closedir)(FsContext *, V9fsFidOpenState *); 139cc720ddbSAneesh Kumar K.V int (*opendir)(FsContext *, V9fsPath *, V9fsFidOpenState *); 140cc720ddbSAneesh Kumar K.V int (*open)(FsContext *, V9fsPath *, int, V9fsFidOpenState *); 141cc720ddbSAneesh Kumar K.V int (*open2)(FsContext *, V9fsPath *, const char *, 142cc720ddbSAneesh Kumar K.V int, FsCred *, V9fsFidOpenState *); 143cc720ddbSAneesh Kumar K.V void (*rewinddir)(FsContext *, V9fsFidOpenState *); 144cc720ddbSAneesh Kumar K.V off_t (*telldir)(FsContext *, V9fsFidOpenState *); 145635324e8SGreg Kurz struct dirent * (*readdir)(FsContext *, V9fsFidOpenState *); 146cc720ddbSAneesh Kumar K.V void (*seekdir)(FsContext *, V9fsFidOpenState *, off_t); 147cc720ddbSAneesh Kumar K.V ssize_t (*preadv)(FsContext *, V9fsFidOpenState *, 148cc720ddbSAneesh Kumar K.V const struct iovec *, int, off_t); 149cc720ddbSAneesh Kumar K.V ssize_t (*pwritev)(FsContext *, V9fsFidOpenState *, 150cc720ddbSAneesh Kumar K.V const struct iovec *, int, off_t); 1512289be19SAneesh Kumar K.V int (*mkdir)(FsContext *, V9fsPath *, const char *, FsCred *); 1528b888272SAneesh Kumar K.V int (*fstat)(FsContext *, int, V9fsFidOpenState *, struct stat *); 153353ac78dSAneesh Kumar K.V int (*rename)(FsContext *, const char *, const char *); 1542289be19SAneesh Kumar K.V int (*truncate)(FsContext *, V9fsPath *, off_t); 1558b888272SAneesh Kumar K.V int (*fsync)(FsContext *, int, V9fsFidOpenState *, int); 1562289be19SAneesh Kumar K.V int (*statfs)(FsContext *s, V9fsPath *path, struct statfs *stbuf); 1572289be19SAneesh Kumar K.V ssize_t (*lgetxattr)(FsContext *, V9fsPath *, 158353ac78dSAneesh Kumar K.V const char *, void *, size_t); 1592289be19SAneesh Kumar K.V ssize_t (*llistxattr)(FsContext *, V9fsPath *, void *, size_t); 1602289be19SAneesh Kumar K.V int (*lsetxattr)(FsContext *, V9fsPath *, 161353ac78dSAneesh Kumar K.V const char *, void *, size_t, int); 1622289be19SAneesh Kumar K.V int (*lremovexattr)(FsContext *, V9fsPath *, const char *); 1632289be19SAneesh Kumar K.V int (*name_to_path)(FsContext *, V9fsPath *, const char *, V9fsPath *); 1642289be19SAneesh Kumar K.V int (*renameat)(FsContext *ctx, V9fsPath *olddir, const char *old_name, 1652289be19SAneesh Kumar K.V V9fsPath *newdir, const char *new_name); 1662289be19SAneesh Kumar K.V int (*unlinkat)(FsContext *ctx, V9fsPath *dir, const char *name, int flags); 16799519f0aSAneesh Kumar K.V }; 168353ac78dSAneesh Kumar K.V 169353ac78dSAneesh Kumar K.V #endif 170