xref: /qemu/fsdev/file-op-9p.h (revision c418f935)
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 
251a8d0bb3SGreg Kurz typedef struct FsCred {
26353ac78dSAneesh Kumar K.V     uid_t   fc_uid;
27353ac78dSAneesh Kumar K.V     gid_t   fc_gid;
28353ac78dSAneesh Kumar K.V     mode_t  fc_mode;
29353ac78dSAneesh Kumar K.V     dev_t   fc_rdev;
30353ac78dSAneesh Kumar K.V } FsCred;
31353ac78dSAneesh Kumar K.V 
321a8d0bb3SGreg Kurz typedef struct FsContext FsContext;
331a8d0bb3SGreg Kurz typedef struct V9fsPath V9fsPath;
34e06a765eSHarsh Prateek Bora 
351a8d0bb3SGreg Kurz typedef struct ExtendedOps {
361a8d0bb3SGreg Kurz     int (*get_st_gen)(FsContext *, V9fsPath *, mode_t, uint64_t *);
371a8d0bb3SGreg Kurz } ExtendedOps;
38353ac78dSAneesh Kumar K.V 
39d3ab98e6SAneesh Kumar K.V /* export flags */
40c98f1d4aSAneesh Kumar K.V #define V9FS_IMMEDIATE_WRITEOUT     0x00000001
41c98f1d4aSAneesh Kumar K.V #define V9FS_PATHNAME_FSCONTEXT     0x00000002
42b97400caSAneesh Kumar K.V /*
43b97400caSAneesh Kumar K.V  * uid/gid set on fileserver files
44b97400caSAneesh Kumar K.V  */
45b97400caSAneesh Kumar K.V #define V9FS_SM_PASSTHROUGH         0x00000004
46b97400caSAneesh Kumar K.V /*
47b97400caSAneesh Kumar K.V  * uid/gid part of xattr
48b97400caSAneesh Kumar K.V  */
49b97400caSAneesh Kumar K.V #define V9FS_SM_MAPPED              0x00000008
50b97400caSAneesh Kumar K.V /*
51b97400caSAneesh Kumar K.V  * Server will try to set uid/gid.
52b97400caSAneesh Kumar K.V  * On failure ignore the error.
53b97400caSAneesh Kumar K.V  */
54b97400caSAneesh Kumar K.V #define V9FS_SM_NONE                0x00000010
552c30dd74SAneesh Kumar K.V /*
562c30dd74SAneesh Kumar K.V  * uid/gid part of .virtfs_meatadata namespace
572c30dd74SAneesh Kumar K.V  */
582c30dd74SAneesh Kumar K.V #define V9FS_SM_MAPPED_FILE         0x00000020
592c30dd74SAneesh Kumar K.V #define V9FS_RDONLY                 0x00000040
602c30dd74SAneesh Kumar K.V #define V9FS_PROXY_SOCK_FD          0x00000080
612c30dd74SAneesh Kumar K.V #define V9FS_PROXY_SOCK_NAME        0x00000100
621a6ed33cSAntonios Motakis /*
631a6ed33cSAntonios Motakis  * multidevs option (either one of the two applies exclusively)
641a6ed33cSAntonios Motakis  */
651a6ed33cSAntonios Motakis #define V9FS_REMAP_INODES           0x00000200
661a6ed33cSAntonios Motakis #define V9FS_FORBID_MULTIDEVS       0x00000400
67*c418f935SChristian Schoenebeck /*
68*c418f935SChristian Schoenebeck  * Disables certain performance warnings from being logged on host side.
69*c418f935SChristian Schoenebeck  */
70*c418f935SChristian Schoenebeck #define V9FS_NO_PERF_WARN           0x00000800
71b97400caSAneesh Kumar K.V 
722c30dd74SAneesh Kumar K.V #define V9FS_SEC_MASK               0x0000003C
73d3ab98e6SAneesh Kumar K.V 
742c74c2cbSM. Mohan Kumar 
7599519f0aSAneesh Kumar K.V typedef struct FileOperations FileOperations;
7601847522SGreg Kurz typedef struct XattrOperations XattrOperations;
7701847522SGreg Kurz 
7899519f0aSAneesh Kumar K.V /*
7999519f0aSAneesh Kumar K.V  * Structure to store the various fsdev's passed through command line.
8099519f0aSAneesh Kumar K.V  */
8199519f0aSAneesh Kumar K.V typedef struct FsDriverEntry {
8299519f0aSAneesh Kumar K.V     char *fsdev_id;
8399519f0aSAneesh Kumar K.V     char *path;
8499519f0aSAneesh Kumar K.V     int export_flags;
8599519f0aSAneesh Kumar K.V     FileOperations *ops;
86b8bbdb88SPradeep Jagadeesh     FsThrottle fst;
87b96feb2cSTobias Schramm     mode_t fmode;
88b96feb2cSTobias Schramm     mode_t dmode;
8999519f0aSAneesh Kumar K.V } FsDriverEntry;
902c74c2cbSM. Mohan Kumar 
911a8d0bb3SGreg Kurz struct FsContext {
92353ac78dSAneesh Kumar K.V     uid_t uid;
93b97400caSAneesh Kumar K.V     char *fs_root;
94d3ab98e6SAneesh Kumar K.V     int export_flags;
9501847522SGreg Kurz     XattrOperations **xops;
961a8d0bb3SGreg Kurz     ExtendedOps exops;
97b8bbdb88SPradeep Jagadeesh     FsThrottle *fst;
98532decb7SAneesh Kumar K.V     /* fs driver specific data */
99532decb7SAneesh Kumar K.V     void *private;
100b96feb2cSTobias Schramm     mode_t fmode;
101b96feb2cSTobias Schramm     mode_t dmode;
1021a8d0bb3SGreg Kurz };
103353ac78dSAneesh Kumar K.V 
1041a8d0bb3SGreg Kurz struct V9fsPath {
1052f008a8cSAneesh Kumar K.V     uint16_t size;
1062289be19SAneesh Kumar K.V     char *data;
1071a8d0bb3SGreg Kurz };
1082289be19SAneesh Kumar K.V 
109cc720ddbSAneesh Kumar K.V typedef union V9fsFidOpenState V9fsFidOpenState;
110cc720ddbSAneesh Kumar K.V 
111353ac78dSAneesh Kumar K.V void cred_init(FsCred *);
112353ac78dSAneesh Kumar K.V 
11399519f0aSAneesh Kumar K.V struct FileOperations
114353ac78dSAneesh Kumar K.V {
11591cda4e8SGreg Kurz     int (*parse_opts)(QemuOpts *, FsDriverEntry *, Error **errp);
11665603a80SGreg Kurz     int (*init)(FsContext *, Error **errp);
1171a8d0bb3SGreg Kurz     void (*cleanup)(FsContext *);
1182289be19SAneesh Kumar K.V     int (*lstat)(FsContext *, V9fsPath *, struct stat *);
1192289be19SAneesh Kumar K.V     ssize_t (*readlink)(FsContext *, V9fsPath *, char *, size_t);
1202289be19SAneesh Kumar K.V     int (*chmod)(FsContext *, V9fsPath *, FsCred *);
1212289be19SAneesh Kumar K.V     int (*chown)(FsContext *, V9fsPath *, FsCred *);
1222289be19SAneesh Kumar K.V     int (*mknod)(FsContext *, V9fsPath *, const char *, FsCred *);
1232289be19SAneesh Kumar K.V     int (*utimensat)(FsContext *, V9fsPath *, const struct timespec *);
124353ac78dSAneesh Kumar K.V     int (*remove)(FsContext *, const char *);
1252289be19SAneesh Kumar K.V     int (*symlink)(FsContext *, const char *, V9fsPath *,
1262289be19SAneesh Kumar K.V                    const char *, FsCred *);
1272289be19SAneesh Kumar K.V     int (*link)(FsContext *, V9fsPath *, V9fsPath *, const char *);
128353ac78dSAneesh Kumar K.V     int (*setuid)(FsContext *, uid_t);
129cc720ddbSAneesh Kumar K.V     int (*close)(FsContext *, V9fsFidOpenState *);
130cc720ddbSAneesh Kumar K.V     int (*closedir)(FsContext *, V9fsFidOpenState *);
131cc720ddbSAneesh Kumar K.V     int (*opendir)(FsContext *, V9fsPath *, V9fsFidOpenState *);
132cc720ddbSAneesh Kumar K.V     int (*open)(FsContext *, V9fsPath *, int, V9fsFidOpenState *);
133cc720ddbSAneesh Kumar K.V     int (*open2)(FsContext *, V9fsPath *, const char *,
134cc720ddbSAneesh Kumar K.V                  int, FsCred *, V9fsFidOpenState *);
135cc720ddbSAneesh Kumar K.V     void (*rewinddir)(FsContext *, V9fsFidOpenState *);
136cc720ddbSAneesh Kumar K.V     off_t (*telldir)(FsContext *, V9fsFidOpenState *);
137635324e8SGreg Kurz     struct dirent * (*readdir)(FsContext *, V9fsFidOpenState *);
138cc720ddbSAneesh Kumar K.V     void (*seekdir)(FsContext *, V9fsFidOpenState *, off_t);
139cc720ddbSAneesh Kumar K.V     ssize_t (*preadv)(FsContext *, V9fsFidOpenState *,
140cc720ddbSAneesh Kumar K.V                       const struct iovec *, int, off_t);
141cc720ddbSAneesh Kumar K.V     ssize_t (*pwritev)(FsContext *, V9fsFidOpenState *,
142cc720ddbSAneesh Kumar K.V                        const struct iovec *, int, off_t);
1432289be19SAneesh Kumar K.V     int (*mkdir)(FsContext *, V9fsPath *, const char *, FsCred *);
1448b888272SAneesh Kumar K.V     int (*fstat)(FsContext *, int, V9fsFidOpenState *, struct stat *);
145353ac78dSAneesh Kumar K.V     int (*rename)(FsContext *, const char *, const char *);
1462289be19SAneesh Kumar K.V     int (*truncate)(FsContext *, V9fsPath *, off_t);
1478b888272SAneesh Kumar K.V     int (*fsync)(FsContext *, int, V9fsFidOpenState *, int);
1482289be19SAneesh Kumar K.V     int (*statfs)(FsContext *s, V9fsPath *path, struct statfs *stbuf);
1492289be19SAneesh Kumar K.V     ssize_t (*lgetxattr)(FsContext *, V9fsPath *,
150353ac78dSAneesh Kumar K.V                          const char *, void *, size_t);
1512289be19SAneesh Kumar K.V     ssize_t (*llistxattr)(FsContext *, V9fsPath *, void *, size_t);
1522289be19SAneesh Kumar K.V     int (*lsetxattr)(FsContext *, V9fsPath *,
153353ac78dSAneesh Kumar K.V                      const char *, void *, size_t, int);
1542289be19SAneesh Kumar K.V     int (*lremovexattr)(FsContext *, V9fsPath *, const char *);
1552289be19SAneesh Kumar K.V     int (*name_to_path)(FsContext *, V9fsPath *, const char *, V9fsPath *);
1562289be19SAneesh Kumar K.V     int (*renameat)(FsContext *ctx, V9fsPath *olddir, const char *old_name,
1572289be19SAneesh Kumar K.V                     V9fsPath *newdir, const char *new_name);
1582289be19SAneesh Kumar K.V     int (*unlinkat)(FsContext *ctx, V9fsPath *dir, const char *name, int flags);
15999519f0aSAneesh Kumar K.V };
160353ac78dSAneesh Kumar K.V 
161353ac78dSAneesh Kumar K.V #endif
162