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