2
0

file-op-9p.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  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 "qemu-fsdev-throttle.h"
  18. #include "p9array.h"
  19. #ifdef CONFIG_LINUX
  20. # include <sys/vfs.h>
  21. #endif
  22. #ifdef CONFIG_DARWIN
  23. # include <sys/param.h>
  24. # include <sys/mount.h>
  25. #endif
  26. #define SM_LOCAL_MODE_BITS 0600
  27. #define SM_LOCAL_DIR_MODE_BITS 0700
  28. typedef struct FsCred {
  29. uid_t fc_uid;
  30. gid_t fc_gid;
  31. mode_t fc_mode;
  32. dev_t fc_rdev;
  33. } FsCred;
  34. typedef struct FsContext FsContext;
  35. typedef struct V9fsPath V9fsPath;
  36. typedef struct ExtendedOps {
  37. int (*get_st_gen)(FsContext *, V9fsPath *, mode_t, uint64_t *);
  38. } ExtendedOps;
  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. * multidevs option (either one of the two applies exclusively)
  64. */
  65. #define V9FS_REMAP_INODES 0x00000200
  66. #define V9FS_FORBID_MULTIDEVS 0x00000400
  67. /*
  68. * Disables certain performance warnings from being logged on host side.
  69. */
  70. #define V9FS_NO_PERF_WARN 0x00000800
  71. #define V9FS_SEC_MASK 0x0000003C
  72. typedef struct FileOperations FileOperations;
  73. typedef struct XattrOperations XattrOperations;
  74. /*
  75. * Structure to store the various fsdev's passed through command line.
  76. */
  77. typedef struct FsDriverEntry {
  78. char *fsdev_id;
  79. char *path;
  80. int export_flags;
  81. FileOperations *ops;
  82. FsThrottle fst;
  83. mode_t fmode;
  84. mode_t dmode;
  85. } FsDriverEntry;
  86. struct FsContext {
  87. uid_t uid;
  88. char *fs_root;
  89. int export_flags;
  90. XattrOperations **xops;
  91. ExtendedOps exops;
  92. FsThrottle *fst;
  93. /* fs driver specific data */
  94. void *private;
  95. mode_t fmode;
  96. mode_t dmode;
  97. };
  98. struct V9fsPath {
  99. uint16_t size;
  100. char *data;
  101. };
  102. P9ARRAY_DECLARE_TYPE(V9fsPath);
  103. typedef union V9fsFidOpenState V9fsFidOpenState;
  104. void cred_init(FsCred *);
  105. struct FileOperations {
  106. int (*parse_opts)(QemuOpts *, FsDriverEntry *, Error **errp);
  107. int (*init)(FsContext *, Error **errp);
  108. void (*cleanup)(FsContext *);
  109. int (*lstat)(FsContext *, V9fsPath *, struct stat *);
  110. ssize_t (*readlink)(FsContext *, V9fsPath *, char *, size_t);
  111. int (*chmod)(FsContext *, V9fsPath *, FsCred *);
  112. int (*chown)(FsContext *, V9fsPath *, FsCred *);
  113. int (*mknod)(FsContext *, V9fsPath *, const char *, FsCred *);
  114. int (*utimensat)(FsContext *, V9fsPath *, const struct timespec *);
  115. int (*remove)(FsContext *, const char *);
  116. int (*symlink)(FsContext *, const char *, V9fsPath *,
  117. const char *, FsCred *);
  118. int (*link)(FsContext *, V9fsPath *, V9fsPath *, const char *);
  119. int (*setuid)(FsContext *, uid_t);
  120. int (*close)(FsContext *, V9fsFidOpenState *);
  121. int (*closedir)(FsContext *, V9fsFidOpenState *);
  122. int (*opendir)(FsContext *, V9fsPath *, V9fsFidOpenState *);
  123. int (*open)(FsContext *, V9fsPath *, int, V9fsFidOpenState *);
  124. int (*open2)(FsContext *, V9fsPath *, const char *,
  125. int, FsCred *, V9fsFidOpenState *);
  126. void (*rewinddir)(FsContext *, V9fsFidOpenState *);
  127. off_t (*telldir)(FsContext *, V9fsFidOpenState *);
  128. struct dirent * (*readdir)(FsContext *, V9fsFidOpenState *);
  129. void (*seekdir)(FsContext *, V9fsFidOpenState *, off_t);
  130. ssize_t (*preadv)(FsContext *, V9fsFidOpenState *,
  131. const struct iovec *, int, off_t);
  132. ssize_t (*pwritev)(FsContext *, V9fsFidOpenState *,
  133. const struct iovec *, int, off_t);
  134. int (*mkdir)(FsContext *, V9fsPath *, const char *, FsCred *);
  135. int (*fstat)(FsContext *, int, V9fsFidOpenState *, struct stat *);
  136. int (*rename)(FsContext *, const char *, const char *);
  137. int (*truncate)(FsContext *, V9fsPath *, off_t);
  138. int (*fsync)(FsContext *, int, V9fsFidOpenState *, int);
  139. int (*statfs)(FsContext *s, V9fsPath *path, struct statfs *stbuf);
  140. ssize_t (*lgetxattr)(FsContext *, V9fsPath *,
  141. const char *, void *, size_t);
  142. ssize_t (*llistxattr)(FsContext *, V9fsPath *, void *, size_t);
  143. int (*lsetxattr)(FsContext *, V9fsPath *,
  144. const char *, void *, size_t, int);
  145. int (*lremovexattr)(FsContext *, V9fsPath *, const char *);
  146. int (*name_to_path)(FsContext *, V9fsPath *, const char *, V9fsPath *);
  147. int (*renameat)(FsContext *ctx, V9fsPath *olddir, const char *old_name,
  148. V9fsPath *newdir, const char *new_name);
  149. int (*unlinkat)(FsContext *ctx, V9fsPath *dir, const char *name, int flags);
  150. };
  151. #endif