file-op-9p.h 4.9 KB

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