blob: 474c79d003f6fc4b9a20538bde8445deef3f5485 [file] [log] [blame]
Gautham R Shenoy74db9202010-04-29 17:44:43 +05301/*
Greg Kurzaf8b38b2016-06-06 11:52:34 +02002 * 9p
Gautham R Shenoy74db9202010-04-29 17:44:43 +05303 *
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 Armbruster121d0712016-06-29 10:12:57 +020013
14#ifndef FILE_OP_9P_H
15#define FILE_OP_9P_H
16
Gautham R Shenoy74db9202010-04-29 17:44:43 +053017#include <dirent.h>
Gautham R Shenoy74db9202010-04-29 17:44:43 +053018#include <utime.h>
Venkateswararao Jujjuri (JV)758e8e32010-06-14 13:34:41 -070019#include <sys/vfs.h>
Pradeep Jagadeeshb8bbdb82017-02-28 10:31:46 +010020#include "qemu-fsdev-throttle.h"
Aneesh Kumar K.V0174fe72011-08-02 11:35:54 +053021
Venkateswararao Jujjuri (JV)758e8e32010-06-14 13:34:41 -070022#define SM_LOCAL_MODE_BITS 0600
23#define SM_LOCAL_DIR_MODE_BITS 0700
24
Venkateswararao Jujjuri (JV)758e8e32010-06-14 13:34:41 -070025typedef 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;
Gautham R Shenoy74db9202010-04-29 17:44:43 +053032
Aneesh Kumar K.Vfc221182010-10-18 15:28:16 +053033struct xattr_operations;
Harsh Prateek Borae06a7652011-10-12 19:11:25 +053034struct FsContext;
35struct V9fsPath;
36
37typedef struct extended_ops {
38 int (*get_st_gen)(struct FsContext *, struct V9fsPath *,
39 mode_t, uint64_t *);
40} extended_ops;
Aneesh Kumar K.Vfc221182010-10-18 15:28:16 +053041
Aneesh Kumar K.Vd3ab98e2011-10-12 19:11:23 +053042/* export flags */
Aneesh Kumar K.Vc98f1d42011-10-12 20:59:18 +053043#define V9FS_IMMEDIATE_WRITEOUT 0x00000001
44#define V9FS_PATHNAME_FSCONTEXT 0x00000002
Aneesh Kumar K.Vb97400c2011-10-13 13:21:00 +053045/*
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
Aneesh Kumar K.V2c30dd72012-01-19 12:21:11 +053058/*
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
Aneesh Kumar K.Vb97400c2011-10-13 13:21:00 +053065
Aneesh Kumar K.V2c30dd72012-01-19 12:21:11 +053066#define V9FS_SEC_MASK 0x0000003C
Aneesh Kumar K.Vd3ab98e2011-10-12 19:11:23 +053067
M. Mohan Kumar2c74c2c2011-10-25 12:10:39 +053068
Aneesh Kumar K.V99519f02011-12-14 13:48:59 +053069typedef struct FileOperations FileOperations;
70/*
71 * Structure to store the various fsdev's passed through command line.
72 */
73typedef struct FsDriverEntry {
74 char *fsdev_id;
75 char *path;
76 int export_flags;
77 FileOperations *ops;
Pradeep Jagadeeshb8bbdb82017-02-28 10:31:46 +010078 FsThrottle fst;
Tobias Schrammb96feb22017-06-29 15:11:50 +020079 mode_t fmode;
80 mode_t dmode;
Aneesh Kumar K.V99519f02011-12-14 13:48:59 +053081} FsDriverEntry;
M. Mohan Kumar2c74c2c2011-10-25 12:10:39 +053082
Gautham R Shenoy74db9202010-04-29 17:44:43 +053083typedef struct FsContext
84{
Gautham R Shenoy74db9202010-04-29 17:44:43 +053085 uid_t uid;
Aneesh Kumar K.Vb97400c2011-10-13 13:21:00 +053086 char *fs_root;
Aneesh Kumar K.Vd3ab98e2011-10-12 19:11:23 +053087 int export_flags;
Aneesh Kumar K.Vfc221182010-10-18 15:28:16 +053088 struct xattr_operations **xops;
Harsh Prateek Borae06a7652011-10-12 19:11:25 +053089 struct extended_ops exops;
Pradeep Jagadeeshb8bbdb82017-02-28 10:31:46 +010090 FsThrottle *fst;
Aneesh Kumar K.V532decb2011-08-02 11:35:54 +053091 /* fs driver specific data */
92 void *private;
Tobias Schrammb96feb22017-06-29 15:11:50 +020093 mode_t fmode;
94 mode_t dmode;
Gautham R Shenoy74db9202010-04-29 17:44:43 +053095} FsContext;
96
Aneesh Kumar K.V2289be12011-09-09 15:14:18 +053097typedef struct V9fsPath {
Aneesh Kumar K.V2f008a82011-12-21 12:37:23 +053098 uint16_t size;
Aneesh Kumar K.V2289be12011-09-09 15:14:18 +053099 char *data;
100} V9fsPath;
101
Aneesh Kumar K.Vcc720dd2011-10-25 12:10:40 +0530102typedef union V9fsFidOpenState V9fsFidOpenState;
103
Blue Swirl64b85a82011-01-23 16:21:20 +0000104void cred_init(FsCred *);
Venkateswararao Jujjuri (JV)758e8e32010-06-14 13:34:41 -0700105
Aneesh Kumar K.V99519f02011-12-14 13:48:59 +0530106struct FileOperations
Gautham R Shenoy74db9202010-04-29 17:44:43 +0530107{
Aneesh Kumar K.V99519f02011-12-14 13:48:59 +0530108 int (*parse_opts)(QemuOpts *, struct FsDriverEntry *);
Aneesh Kumar K.V0174fe72011-08-02 11:35:54 +0530109 int (*init)(struct FsContext *);
Li Qiang702dbcc2016-11-23 13:53:34 +0100110 void (*cleanup)(struct FsContext *);
Aneesh Kumar K.V2289be12011-09-09 15:14:18 +0530111 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 *);
Anthony Liguori5bae1902010-04-29 17:45:01 +0530117 int (*remove)(FsContext *, const char *);
Aneesh Kumar K.V2289be12011-09-09 15:14:18 +0530118 int (*symlink)(FsContext *, const char *, V9fsPath *,
119 const char *, FsCred *);
120 int (*link)(FsContext *, V9fsPath *, V9fsPath *, const char *);
Anthony Liguori131dcb22010-04-29 17:44:47 +0530121 int (*setuid)(FsContext *, uid_t);
Aneesh Kumar K.Vcc720dd2011-10-25 12:10:40 +0530122 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 *);
Greg Kurz635324e2016-06-06 11:52:34 +0200130 struct dirent * (*readdir)(FsContext *, V9fsFidOpenState *);
Aneesh Kumar K.Vcc720dd2011-10-25 12:10:40 +0530131 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);
Aneesh Kumar K.V2289be12011-09-09 15:14:18 +0530136 int (*mkdir)(FsContext *, V9fsPath *, const char *, FsCred *);
Aneesh Kumar K.V8b888272011-12-04 22:35:28 +0530137 int (*fstat)(FsContext *, int, V9fsFidOpenState *, struct stat *);
Anthony Liguori8cf89e02010-04-29 17:45:00 +0530138 int (*rename)(FsContext *, const char *, const char *);
Aneesh Kumar K.V2289be12011-09-09 15:14:18 +0530139 int (*truncate)(FsContext *, V9fsPath *, off_t);
Aneesh Kumar K.V8b888272011-12-04 22:35:28 +0530140 int (*fsync)(FsContext *, int, V9fsFidOpenState *, int);
Aneesh Kumar K.V2289be12011-09-09 15:14:18 +0530141 int (*statfs)(FsContext *s, V9fsPath *path, struct statfs *stbuf);
142 ssize_t (*lgetxattr)(FsContext *, V9fsPath *,
Aneesh Kumar K.Vfa32ef82010-09-02 11:09:06 +0530143 const char *, void *, size_t);
Aneesh Kumar K.V2289be12011-09-09 15:14:18 +0530144 ssize_t (*llistxattr)(FsContext *, V9fsPath *, void *, size_t);
145 int (*lsetxattr)(FsContext *, V9fsPath *,
Aneesh Kumar K.V10b468b2010-09-02 11:09:07 +0530146 const char *, void *, size_t, int);
Aneesh Kumar K.V2289be12011-09-09 15:14:18 +0530147 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);
Gautham R Shenoy74db9202010-04-29 17:44:43 +0530152 void *opaque;
Aneesh Kumar K.V99519f02011-12-14 13:48:59 +0530153};
Aneesh Kumar K.Vfc221182010-10-18 15:28:16 +0530154
Gautham R Shenoy74db9202010-04-29 17:44:43 +0530155#endif