blob: 956fda091968b34326246209109b4b05697fcf31 [file] [log] [blame]
Gautham R Shenoy74db9202010-04-29 17:44:43 +05301/*
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>
Venkateswararao Jujjuri (JV)758e8e32010-06-14 13:34:41 -070021#include <sys/vfs.h>
Aneesh Kumar K.V0174fe72011-08-02 11:35:54 +053022
Venkateswararao Jujjuri (JV)758e8e32010-06-14 13:34:41 -070023#define SM_LOCAL_MODE_BITS 0600
24#define SM_LOCAL_DIR_MODE_BITS 0700
25
Venkateswararao Jujjuri (JV)758e8e32010-06-14 13:34:41 -070026typedef 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;
Gautham R Shenoy74db9202010-04-29 17:44:43 +053033
Aneesh Kumar K.Vfc221182010-10-18 15:28:16 +053034struct xattr_operations;
Harsh Prateek Borae06a7652011-10-12 19:11:25 +053035struct 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;
Aneesh Kumar K.Vfc221182010-10-18 15:28:16 +053042
Aneesh Kumar K.Vd3ab98e2011-10-12 19:11:23 +053043/* export flags */
Aneesh Kumar K.Vc98f1d42011-10-12 20:59:18 +053044#define V9FS_IMMEDIATE_WRITEOUT 0x00000001
45#define V9FS_PATHNAME_FSCONTEXT 0x00000002
Aneesh Kumar K.Vb97400c2011-10-13 13:21:00 +053046/*
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
Aneesh Kumar K.V2c30dd72012-01-19 12:21:11 +053059/*
60 * uid/gid part of .virtfs_meatadata namespace
61 */
62#define V9FS_SM_MAPPED_FILE 0x00000020
63#define V9FS_RDONLY 0x00000040
64#define V9FS_PROXY_SOCK_FD 0x00000080
65#define V9FS_PROXY_SOCK_NAME 0x00000100
Aneesh Kumar K.Vb97400c2011-10-13 13:21:00 +053066
Aneesh Kumar K.V2c30dd72012-01-19 12:21:11 +053067#define V9FS_SEC_MASK 0x0000003C
Aneesh Kumar K.Vd3ab98e2011-10-12 19:11:23 +053068
M. Mohan Kumar2c74c2c2011-10-25 12:10:39 +053069
Aneesh Kumar K.V99519f02011-12-14 13:48:59 +053070typedef struct FileOperations FileOperations;
71/*
72 * Structure to store the various fsdev's passed through command line.
73 */
74typedef struct FsDriverEntry {
75 char *fsdev_id;
76 char *path;
77 int export_flags;
78 FileOperations *ops;
79} FsDriverEntry;
M. Mohan Kumar2c74c2c2011-10-25 12:10:39 +053080
Gautham R Shenoy74db9202010-04-29 17:44:43 +053081typedef struct FsContext
82{
Gautham R Shenoy74db9202010-04-29 17:44:43 +053083 uid_t uid;
Aneesh Kumar K.Vb97400c2011-10-13 13:21:00 +053084 char *fs_root;
Aneesh Kumar K.Vd3ab98e2011-10-12 19:11:23 +053085 int export_flags;
Aneesh Kumar K.Vfc221182010-10-18 15:28:16 +053086 struct xattr_operations **xops;
Harsh Prateek Borae06a7652011-10-12 19:11:25 +053087 struct extended_ops exops;
Aneesh Kumar K.V532decb2011-08-02 11:35:54 +053088 /* fs driver specific data */
89 void *private;
Gautham R Shenoy74db9202010-04-29 17:44:43 +053090} FsContext;
91
Aneesh Kumar K.V2289be12011-09-09 15:14:18 +053092typedef struct V9fsPath {
Aneesh Kumar K.V2f008a82011-12-21 12:37:23 +053093 uint16_t size;
Aneesh Kumar K.V2289be12011-09-09 15:14:18 +053094 char *data;
95} V9fsPath;
96
Aneesh Kumar K.Vcc720dd2011-10-25 12:10:40 +053097typedef union V9fsFidOpenState V9fsFidOpenState;
98
Blue Swirl64b85a82011-01-23 16:21:20 +000099void cred_init(FsCred *);
Venkateswararao Jujjuri (JV)758e8e32010-06-14 13:34:41 -0700100
Aneesh Kumar K.V99519f02011-12-14 13:48:59 +0530101struct FileOperations
Gautham R Shenoy74db9202010-04-29 17:44:43 +0530102{
Aneesh Kumar K.V99519f02011-12-14 13:48:59 +0530103 int (*parse_opts)(QemuOpts *, struct FsDriverEntry *);
Aneesh Kumar K.V0174fe72011-08-02 11:35:54 +0530104 int (*init)(struct FsContext *);
Aneesh Kumar K.V2289be12011-09-09 15:14:18 +0530105 int (*lstat)(FsContext *, V9fsPath *, struct stat *);
106 ssize_t (*readlink)(FsContext *, V9fsPath *, char *, size_t);
107 int (*chmod)(FsContext *, V9fsPath *, FsCred *);
108 int (*chown)(FsContext *, V9fsPath *, FsCred *);
109 int (*mknod)(FsContext *, V9fsPath *, const char *, FsCred *);
110 int (*utimensat)(FsContext *, V9fsPath *, const struct timespec *);
Anthony Liguori5bae1902010-04-29 17:45:01 +0530111 int (*remove)(FsContext *, const char *);
Aneesh Kumar K.V2289be12011-09-09 15:14:18 +0530112 int (*symlink)(FsContext *, const char *, V9fsPath *,
113 const char *, FsCred *);
114 int (*link)(FsContext *, V9fsPath *, V9fsPath *, const char *);
Anthony Liguori131dcb22010-04-29 17:44:47 +0530115 int (*setuid)(FsContext *, uid_t);
Aneesh Kumar K.Vcc720dd2011-10-25 12:10:40 +0530116 int (*close)(FsContext *, V9fsFidOpenState *);
117 int (*closedir)(FsContext *, V9fsFidOpenState *);
118 int (*opendir)(FsContext *, V9fsPath *, V9fsFidOpenState *);
119 int (*open)(FsContext *, V9fsPath *, int, V9fsFidOpenState *);
120 int (*open2)(FsContext *, V9fsPath *, const char *,
121 int, FsCred *, V9fsFidOpenState *);
122 void (*rewinddir)(FsContext *, V9fsFidOpenState *);
123 off_t (*telldir)(FsContext *, V9fsFidOpenState *);
124 int (*readdir_r)(FsContext *, V9fsFidOpenState *,
125 struct dirent *, struct dirent **);
126 void (*seekdir)(FsContext *, V9fsFidOpenState *, off_t);
127 ssize_t (*preadv)(FsContext *, V9fsFidOpenState *,
128 const struct iovec *, int, off_t);
129 ssize_t (*pwritev)(FsContext *, V9fsFidOpenState *,
130 const struct iovec *, int, off_t);
Aneesh Kumar K.V2289be12011-09-09 15:14:18 +0530131 int (*mkdir)(FsContext *, V9fsPath *, const char *, FsCred *);
Aneesh Kumar K.V8b888272011-12-04 22:35:28 +0530132 int (*fstat)(FsContext *, int, V9fsFidOpenState *, struct stat *);
Anthony Liguori8cf89e02010-04-29 17:45:00 +0530133 int (*rename)(FsContext *, const char *, const char *);
Aneesh Kumar K.V2289be12011-09-09 15:14:18 +0530134 int (*truncate)(FsContext *, V9fsPath *, off_t);
Aneesh Kumar K.V8b888272011-12-04 22:35:28 +0530135 int (*fsync)(FsContext *, int, V9fsFidOpenState *, int);
Aneesh Kumar K.V2289be12011-09-09 15:14:18 +0530136 int (*statfs)(FsContext *s, V9fsPath *path, struct statfs *stbuf);
137 ssize_t (*lgetxattr)(FsContext *, V9fsPath *,
Aneesh Kumar K.Vfa32ef82010-09-02 11:09:06 +0530138 const char *, void *, size_t);
Aneesh Kumar K.V2289be12011-09-09 15:14:18 +0530139 ssize_t (*llistxattr)(FsContext *, V9fsPath *, void *, size_t);
140 int (*lsetxattr)(FsContext *, V9fsPath *,
Aneesh Kumar K.V10b468b2010-09-02 11:09:07 +0530141 const char *, void *, size_t, int);
Aneesh Kumar K.V2289be12011-09-09 15:14:18 +0530142 int (*lremovexattr)(FsContext *, V9fsPath *, const char *);
143 int (*name_to_path)(FsContext *, V9fsPath *, const char *, V9fsPath *);
144 int (*renameat)(FsContext *ctx, V9fsPath *olddir, const char *old_name,
145 V9fsPath *newdir, const char *new_name);
146 int (*unlinkat)(FsContext *ctx, V9fsPath *dir, const char *name, int flags);
Gautham R Shenoy74db9202010-04-29 17:44:43 +0530147 void *opaque;
Aneesh Kumar K.V99519f02011-12-14 13:48:59 +0530148};
Aneesh Kumar K.Vfc221182010-10-18 15:28:16 +0530149
Gautham R Shenoy74db9202010-04-29 17:44:43 +0530150#endif