]> git.proxmox.com Git - qemu.git/blame - fsdev/file-op-9p.h
hw/9pfs: Add validation to {un}marshal code
[qemu.git] / fsdev / file-op-9p.h
CommitLineData
74db920c
GS
1/*
2 * Virtio 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 _FILEOP_H
14#define _FILEOP_H
15#include <sys/types.h>
16#include <dirent.h>
17#include <sys/time.h>
18#include <utime.h>
19#include <sys/stat.h>
20#include <sys/uio.h>
758e8e38 21#include <sys/vfs.h>
0174fe73 22
758e8e38
VJJ
23#define SM_LOCAL_MODE_BITS 0600
24#define SM_LOCAL_DIR_MODE_BITS 0700
25
758e8e38
VJJ
26typedef struct FsCred
27{
28 uid_t fc_uid;
29 gid_t fc_gid;
30 mode_t fc_mode;
31 dev_t fc_rdev;
32} FsCred;
74db920c 33
fc22118d 34struct xattr_operations;
e06a765e
HPB
35struct FsContext;
36struct V9fsPath;
37
38typedef struct extended_ops {
39 int (*get_st_gen)(struct FsContext *, struct V9fsPath *,
40 mode_t, uint64_t *);
41} extended_ops;
fc22118d 42
d3ab98e6 43/* export flags */
c98f1d4a
AK
44#define V9FS_IMMEDIATE_WRITEOUT 0x00000001
45#define V9FS_PATHNAME_FSCONTEXT 0x00000002
b97400ca
AK
46/*
47 * uid/gid set on fileserver files
48 */
49#define V9FS_SM_PASSTHROUGH 0x00000004
50/*
51 * uid/gid part of xattr
52 */
53#define V9FS_SM_MAPPED 0x00000008
54/*
55 * Server will try to set uid/gid.
56 * On failure ignore the error.
57 */
58#define V9FS_SM_NONE 0x00000010
2c74c2cb 59#define V9FS_RDONLY 0x00000020
b97400ca
AK
60
61#define V9FS_SEC_MASK 0x0000001C
d3ab98e6 62
2c74c2cb 63
99519f0a
AK
64typedef struct FileOperations FileOperations;
65/*
66 * Structure to store the various fsdev's passed through command line.
67 */
68typedef struct FsDriverEntry {
69 char *fsdev_id;
70 char *path;
71 int export_flags;
72 FileOperations *ops;
73} FsDriverEntry;
2c74c2cb 74
74db920c
GS
75typedef struct FsContext
76{
74db920c 77 uid_t uid;
b97400ca 78 char *fs_root;
d3ab98e6 79 int export_flags;
fc22118d 80 struct xattr_operations **xops;
e06a765e 81 struct extended_ops exops;
532decb7
AK
82 /* fs driver specific data */
83 void *private;
74db920c
GS
84} FsContext;
85
2289be19 86typedef struct V9fsPath {
2f008a8c 87 uint16_t size;
2289be19
AK
88 char *data;
89} V9fsPath;
90
cc720ddb
AK
91typedef union V9fsFidOpenState V9fsFidOpenState;
92
64b85a8f 93void cred_init(FsCred *);
758e8e38 94
99519f0a 95struct FileOperations
74db920c 96{
99519f0a 97 int (*parse_opts)(QemuOpts *, struct FsDriverEntry *);
0174fe73 98 int (*init)(struct FsContext *);
2289be19
AK
99 int (*lstat)(FsContext *, V9fsPath *, struct stat *);
100 ssize_t (*readlink)(FsContext *, V9fsPath *, char *, size_t);
101 int (*chmod)(FsContext *, V9fsPath *, FsCred *);
102 int (*chown)(FsContext *, V9fsPath *, FsCred *);
103 int (*mknod)(FsContext *, V9fsPath *, const char *, FsCred *);
104 int (*utimensat)(FsContext *, V9fsPath *, const struct timespec *);
5bae1900 105 int (*remove)(FsContext *, const char *);
2289be19
AK
106 int (*symlink)(FsContext *, const char *, V9fsPath *,
107 const char *, FsCred *);
108 int (*link)(FsContext *, V9fsPath *, V9fsPath *, const char *);
131dcb25 109 int (*setuid)(FsContext *, uid_t);
cc720ddb
AK
110 int (*close)(FsContext *, V9fsFidOpenState *);
111 int (*closedir)(FsContext *, V9fsFidOpenState *);
112 int (*opendir)(FsContext *, V9fsPath *, V9fsFidOpenState *);
113 int (*open)(FsContext *, V9fsPath *, int, V9fsFidOpenState *);
114 int (*open2)(FsContext *, V9fsPath *, const char *,
115 int, FsCred *, V9fsFidOpenState *);
116 void (*rewinddir)(FsContext *, V9fsFidOpenState *);
117 off_t (*telldir)(FsContext *, V9fsFidOpenState *);
118 int (*readdir_r)(FsContext *, V9fsFidOpenState *,
119 struct dirent *, struct dirent **);
120 void (*seekdir)(FsContext *, V9fsFidOpenState *, off_t);
121 ssize_t (*preadv)(FsContext *, V9fsFidOpenState *,
122 const struct iovec *, int, off_t);
123 ssize_t (*pwritev)(FsContext *, V9fsFidOpenState *,
124 const struct iovec *, int, off_t);
2289be19 125 int (*mkdir)(FsContext *, V9fsPath *, const char *, FsCred *);
8b888272 126 int (*fstat)(FsContext *, int, V9fsFidOpenState *, struct stat *);
8cf89e00 127 int (*rename)(FsContext *, const char *, const char *);
2289be19 128 int (*truncate)(FsContext *, V9fsPath *, off_t);
8b888272 129 int (*fsync)(FsContext *, int, V9fsFidOpenState *, int);
2289be19
AK
130 int (*statfs)(FsContext *s, V9fsPath *path, struct statfs *stbuf);
131 ssize_t (*lgetxattr)(FsContext *, V9fsPath *,
fa32ef88 132 const char *, void *, size_t);
2289be19
AK
133 ssize_t (*llistxattr)(FsContext *, V9fsPath *, void *, size_t);
134 int (*lsetxattr)(FsContext *, V9fsPath *,
10b468bd 135 const char *, void *, size_t, int);
2289be19
AK
136 int (*lremovexattr)(FsContext *, V9fsPath *, const char *);
137 int (*name_to_path)(FsContext *, V9fsPath *, const char *, V9fsPath *);
138 int (*renameat)(FsContext *ctx, V9fsPath *olddir, const char *old_name,
139 V9fsPath *newdir, const char *new_name);
140 int (*unlinkat)(FsContext *ctx, V9fsPath *dir, const char *name, int flags);
74db920c 141 void *opaque;
99519f0a 142};
fc22118d 143
74db920c 144#endif