Gautham R Shenoy | 74db920 | 2010-04-29 17:44:43 +0530 | [diff] [blame] | 1 | /* |
Greg Kurz | af8b38b | 2016-06-06 11:52:34 +0200 | [diff] [blame] | 2 | * 9p |
Gautham R Shenoy | 74db920 | 2010-04-29 17:44:43 +0530 | [diff] [blame] | 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 | */ |
Markus Armbruster | 121d071 | 2016-06-29 10:12:57 +0200 | [diff] [blame] | 13 | |
| 14 | #ifndef FILE_OP_9P_H |
| 15 | #define FILE_OP_9P_H |
| 16 | |
Gautham R Shenoy | 74db920 | 2010-04-29 17:44:43 +0530 | [diff] [blame] | 17 | #include <dirent.h> |
Gautham R Shenoy | 74db920 | 2010-04-29 17:44:43 +0530 | [diff] [blame] | 18 | #include <utime.h> |
Venkateswararao Jujjuri (JV) | 758e8e3 | 2010-06-14 13:34:41 -0700 | [diff] [blame] | 19 | #include <sys/vfs.h> |
Pradeep Jagadeesh | b8bbdb8 | 2017-02-28 10:31:46 +0100 | [diff] [blame] | 20 | #include "qemu-fsdev-throttle.h" |
Aneesh Kumar K.V | 0174fe7 | 2011-08-02 11:35:54 +0530 | [diff] [blame] | 21 | |
Venkateswararao Jujjuri (JV) | 758e8e3 | 2010-06-14 13:34:41 -0700 | [diff] [blame] | 22 | #define SM_LOCAL_MODE_BITS 0600 |
| 23 | #define SM_LOCAL_DIR_MODE_BITS 0700 |
| 24 | |
Greg Kurz | 1a8d0bb | 2018-01-08 11:18:22 +0100 | [diff] [blame] | 25 | typedef struct FsCred { |
Venkateswararao Jujjuri (JV) | 758e8e3 | 2010-06-14 13:34:41 -0700 | [diff] [blame] | 26 | uid_t fc_uid; |
| 27 | gid_t fc_gid; |
| 28 | mode_t fc_mode; |
| 29 | dev_t fc_rdev; |
| 30 | } FsCred; |
Gautham R Shenoy | 74db920 | 2010-04-29 17:44:43 +0530 | [diff] [blame] | 31 | |
Greg Kurz | 1a8d0bb | 2018-01-08 11:18:22 +0100 | [diff] [blame] | 32 | typedef struct FsContext FsContext; |
| 33 | typedef struct V9fsPath V9fsPath; |
Harsh Prateek Bora | e06a765 | 2011-10-12 19:11:25 +0530 | [diff] [blame] | 34 | |
Greg Kurz | 1a8d0bb | 2018-01-08 11:18:22 +0100 | [diff] [blame] | 35 | typedef struct ExtendedOps { |
| 36 | int (*get_st_gen)(FsContext *, V9fsPath *, mode_t, uint64_t *); |
| 37 | } ExtendedOps; |
Aneesh Kumar K.V | fc22118 | 2010-10-18 15:28:16 +0530 | [diff] [blame] | 38 | |
Aneesh Kumar K.V | d3ab98e | 2011-10-12 19:11:23 +0530 | [diff] [blame] | 39 | /* export flags */ |
Aneesh Kumar K.V | c98f1d4 | 2011-10-12 20:59:18 +0530 | [diff] [blame] | 40 | #define V9FS_IMMEDIATE_WRITEOUT 0x00000001 |
| 41 | #define V9FS_PATHNAME_FSCONTEXT 0x00000002 |
Aneesh Kumar K.V | b97400c | 2011-10-13 13:21:00 +0530 | [diff] [blame] | 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 |
Aneesh Kumar K.V | 2c30dd7 | 2012-01-19 12:21:11 +0530 | [diff] [blame] | 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 |
Antonios Motakis | 1a6ed33 | 2019-10-10 11:36:05 +0200 | [diff] [blame] | 62 | /* |
| 63 | * multidevs option (either one of the two applies exclusively) |
| 64 | */ |
| 65 | #define V9FS_REMAP_INODES 0x00000200 |
| 66 | #define V9FS_FORBID_MULTIDEVS 0x00000400 |
Aneesh Kumar K.V | b97400c | 2011-10-13 13:21:00 +0530 | [diff] [blame] | 67 | |
Aneesh Kumar K.V | 2c30dd7 | 2012-01-19 12:21:11 +0530 | [diff] [blame] | 68 | #define V9FS_SEC_MASK 0x0000003C |
Aneesh Kumar K.V | d3ab98e | 2011-10-12 19:11:23 +0530 | [diff] [blame] | 69 | |
M. Mohan Kumar | 2c74c2c | 2011-10-25 12:10:39 +0530 | [diff] [blame] | 70 | |
Aneesh Kumar K.V | 99519f0 | 2011-12-14 13:48:59 +0530 | [diff] [blame] | 71 | typedef struct FileOperations FileOperations; |
Greg Kurz | 0184752 | 2018-01-08 11:18:22 +0100 | [diff] [blame] | 72 | typedef struct XattrOperations XattrOperations; |
| 73 | |
Aneesh Kumar K.V | 99519f0 | 2011-12-14 13:48:59 +0530 | [diff] [blame] | 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; |
Pradeep Jagadeesh | b8bbdb8 | 2017-02-28 10:31:46 +0100 | [diff] [blame] | 82 | FsThrottle fst; |
Tobias Schramm | b96feb2 | 2017-06-29 15:11:50 +0200 | [diff] [blame] | 83 | mode_t fmode; |
| 84 | mode_t dmode; |
Aneesh Kumar K.V | 99519f0 | 2011-12-14 13:48:59 +0530 | [diff] [blame] | 85 | } FsDriverEntry; |
M. Mohan Kumar | 2c74c2c | 2011-10-25 12:10:39 +0530 | [diff] [blame] | 86 | |
Greg Kurz | 1a8d0bb | 2018-01-08 11:18:22 +0100 | [diff] [blame] | 87 | struct FsContext { |
Gautham R Shenoy | 74db920 | 2010-04-29 17:44:43 +0530 | [diff] [blame] | 88 | uid_t uid; |
Aneesh Kumar K.V | b97400c | 2011-10-13 13:21:00 +0530 | [diff] [blame] | 89 | char *fs_root; |
Aneesh Kumar K.V | d3ab98e | 2011-10-12 19:11:23 +0530 | [diff] [blame] | 90 | int export_flags; |
Greg Kurz | 0184752 | 2018-01-08 11:18:22 +0100 | [diff] [blame] | 91 | XattrOperations **xops; |
Greg Kurz | 1a8d0bb | 2018-01-08 11:18:22 +0100 | [diff] [blame] | 92 | ExtendedOps exops; |
Pradeep Jagadeesh | b8bbdb8 | 2017-02-28 10:31:46 +0100 | [diff] [blame] | 93 | FsThrottle *fst; |
Aneesh Kumar K.V | 532decb | 2011-08-02 11:35:54 +0530 | [diff] [blame] | 94 | /* fs driver specific data */ |
| 95 | void *private; |
Tobias Schramm | b96feb2 | 2017-06-29 15:11:50 +0200 | [diff] [blame] | 96 | mode_t fmode; |
| 97 | mode_t dmode; |
Greg Kurz | 1a8d0bb | 2018-01-08 11:18:22 +0100 | [diff] [blame] | 98 | }; |
Gautham R Shenoy | 74db920 | 2010-04-29 17:44:43 +0530 | [diff] [blame] | 99 | |
Greg Kurz | 1a8d0bb | 2018-01-08 11:18:22 +0100 | [diff] [blame] | 100 | struct V9fsPath { |
Aneesh Kumar K.V | 2f008a8 | 2011-12-21 12:37:23 +0530 | [diff] [blame] | 101 | uint16_t size; |
Aneesh Kumar K.V | 2289be1 | 2011-09-09 15:14:18 +0530 | [diff] [blame] | 102 | char *data; |
Greg Kurz | 1a8d0bb | 2018-01-08 11:18:22 +0100 | [diff] [blame] | 103 | }; |
Aneesh Kumar K.V | 2289be1 | 2011-09-09 15:14:18 +0530 | [diff] [blame] | 104 | |
Aneesh Kumar K.V | cc720dd | 2011-10-25 12:10:40 +0530 | [diff] [blame] | 105 | typedef union V9fsFidOpenState V9fsFidOpenState; |
| 106 | |
Blue Swirl | 64b85a8 | 2011-01-23 16:21:20 +0000 | [diff] [blame] | 107 | void cred_init(FsCred *); |
Venkateswararao Jujjuri (JV) | 758e8e3 | 2010-06-14 13:34:41 -0700 | [diff] [blame] | 108 | |
Aneesh Kumar K.V | 99519f0 | 2011-12-14 13:48:59 +0530 | [diff] [blame] | 109 | struct FileOperations |
Gautham R Shenoy | 74db920 | 2010-04-29 17:44:43 +0530 | [diff] [blame] | 110 | { |
Greg Kurz | 91cda4e | 2018-01-08 11:18:23 +0100 | [diff] [blame] | 111 | int (*parse_opts)(QemuOpts *, FsDriverEntry *, Error **errp); |
Greg Kurz | 65603a8 | 2018-01-08 11:18:23 +0100 | [diff] [blame] | 112 | int (*init)(FsContext *, Error **errp); |
Greg Kurz | 1a8d0bb | 2018-01-08 11:18:22 +0100 | [diff] [blame] | 113 | void (*cleanup)(FsContext *); |
Aneesh Kumar K.V | 2289be1 | 2011-09-09 15:14:18 +0530 | [diff] [blame] | 114 | int (*lstat)(FsContext *, V9fsPath *, struct stat *); |
| 115 | ssize_t (*readlink)(FsContext *, V9fsPath *, char *, size_t); |
| 116 | int (*chmod)(FsContext *, V9fsPath *, FsCred *); |
| 117 | int (*chown)(FsContext *, V9fsPath *, FsCred *); |
| 118 | int (*mknod)(FsContext *, V9fsPath *, const char *, FsCred *); |
| 119 | int (*utimensat)(FsContext *, V9fsPath *, const struct timespec *); |
Anthony Liguori | 5bae190 | 2010-04-29 17:45:01 +0530 | [diff] [blame] | 120 | int (*remove)(FsContext *, const char *); |
Aneesh Kumar K.V | 2289be1 | 2011-09-09 15:14:18 +0530 | [diff] [blame] | 121 | int (*symlink)(FsContext *, const char *, V9fsPath *, |
| 122 | const char *, FsCred *); |
| 123 | int (*link)(FsContext *, V9fsPath *, V9fsPath *, const char *); |
Anthony Liguori | 131dcb2 | 2010-04-29 17:44:47 +0530 | [diff] [blame] | 124 | int (*setuid)(FsContext *, uid_t); |
Aneesh Kumar K.V | cc720dd | 2011-10-25 12:10:40 +0530 | [diff] [blame] | 125 | int (*close)(FsContext *, V9fsFidOpenState *); |
| 126 | int (*closedir)(FsContext *, V9fsFidOpenState *); |
| 127 | int (*opendir)(FsContext *, V9fsPath *, V9fsFidOpenState *); |
| 128 | int (*open)(FsContext *, V9fsPath *, int, V9fsFidOpenState *); |
| 129 | int (*open2)(FsContext *, V9fsPath *, const char *, |
| 130 | int, FsCred *, V9fsFidOpenState *); |
| 131 | void (*rewinddir)(FsContext *, V9fsFidOpenState *); |
| 132 | off_t (*telldir)(FsContext *, V9fsFidOpenState *); |
Greg Kurz | 635324e | 2016-06-06 11:52:34 +0200 | [diff] [blame] | 133 | struct dirent * (*readdir)(FsContext *, V9fsFidOpenState *); |
Aneesh Kumar K.V | cc720dd | 2011-10-25 12:10:40 +0530 | [diff] [blame] | 134 | void (*seekdir)(FsContext *, V9fsFidOpenState *, off_t); |
| 135 | ssize_t (*preadv)(FsContext *, V9fsFidOpenState *, |
| 136 | const struct iovec *, int, off_t); |
| 137 | ssize_t (*pwritev)(FsContext *, V9fsFidOpenState *, |
| 138 | const struct iovec *, int, off_t); |
Aneesh Kumar K.V | 2289be1 | 2011-09-09 15:14:18 +0530 | [diff] [blame] | 139 | int (*mkdir)(FsContext *, V9fsPath *, const char *, FsCred *); |
Aneesh Kumar K.V | 8b88827 | 2011-12-04 22:35:28 +0530 | [diff] [blame] | 140 | int (*fstat)(FsContext *, int, V9fsFidOpenState *, struct stat *); |
Anthony Liguori | 8cf89e0 | 2010-04-29 17:45:00 +0530 | [diff] [blame] | 141 | int (*rename)(FsContext *, const char *, const char *); |
Aneesh Kumar K.V | 2289be1 | 2011-09-09 15:14:18 +0530 | [diff] [blame] | 142 | int (*truncate)(FsContext *, V9fsPath *, off_t); |
Aneesh Kumar K.V | 8b88827 | 2011-12-04 22:35:28 +0530 | [diff] [blame] | 143 | int (*fsync)(FsContext *, int, V9fsFidOpenState *, int); |
Aneesh Kumar K.V | 2289be1 | 2011-09-09 15:14:18 +0530 | [diff] [blame] | 144 | int (*statfs)(FsContext *s, V9fsPath *path, struct statfs *stbuf); |
| 145 | ssize_t (*lgetxattr)(FsContext *, V9fsPath *, |
Aneesh Kumar K.V | fa32ef8 | 2010-09-02 11:09:06 +0530 | [diff] [blame] | 146 | const char *, void *, size_t); |
Aneesh Kumar K.V | 2289be1 | 2011-09-09 15:14:18 +0530 | [diff] [blame] | 147 | ssize_t (*llistxattr)(FsContext *, V9fsPath *, void *, size_t); |
| 148 | int (*lsetxattr)(FsContext *, V9fsPath *, |
Aneesh Kumar K.V | 10b468b | 2010-09-02 11:09:07 +0530 | [diff] [blame] | 149 | const char *, void *, size_t, int); |
Aneesh Kumar K.V | 2289be1 | 2011-09-09 15:14:18 +0530 | [diff] [blame] | 150 | int (*lremovexattr)(FsContext *, V9fsPath *, const char *); |
| 151 | int (*name_to_path)(FsContext *, V9fsPath *, const char *, V9fsPath *); |
| 152 | int (*renameat)(FsContext *ctx, V9fsPath *olddir, const char *old_name, |
| 153 | V9fsPath *newdir, const char *new_name); |
| 154 | int (*unlinkat)(FsContext *ctx, V9fsPath *dir, const char *name, int flags); |
Aneesh Kumar K.V | 99519f0 | 2011-12-14 13:48:59 +0530 | [diff] [blame] | 155 | }; |
Aneesh Kumar K.V | fc22118 | 2010-10-18 15:28:16 +0530 | [diff] [blame] | 156 | |
Gautham R Shenoy | 74db920 | 2010-04-29 17:44:43 +0530 | [diff] [blame] | 157 | #endif |