]>
Commit | Line | Data |
---|---|---|
74db920c GS |
1 | /* |
2 | * Virtio 9p | |
3 | * | |
4 | * Copyright IBM, Corp. 2010 | |
5 | * | |
6 | * Authors: | |
7 | * Aneesh Kumar K.V <[email protected]> | |
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 VJ |
21 | #include <sys/vfs.h> |
22 | #define SM_LOCAL_MODE_BITS 0600 | |
23 | #define SM_LOCAL_DIR_MODE_BITS 0700 | |
24 | ||
25 | typedef enum | |
26 | { | |
12848bfc AK |
27 | /* |
28 | * Server will try to set uid/gid. | |
29 | * On failure ignore the error. | |
30 | */ | |
31 | SM_NONE = 0, | |
32 | /* | |
33 | * uid/gid set on fileserver files | |
34 | */ | |
35 | SM_PASSTHROUGH = 1, | |
36 | /* | |
37 | * uid/gid part of xattr | |
38 | */ | |
39 | SM_MAPPED, | |
758e8e38 VJ |
40 | } SecModel; |
41 | ||
42 | typedef struct FsCred | |
43 | { | |
44 | uid_t fc_uid; | |
45 | gid_t fc_gid; | |
46 | mode_t fc_mode; | |
47 | dev_t fc_rdev; | |
48 | } FsCred; | |
74db920c | 49 | |
fc22118d AK |
50 | struct xattr_operations; |
51 | ||
74db920c GS |
52 | typedef struct FsContext |
53 | { | |
54 | char *fs_root; | |
758e8e38 | 55 | SecModel fs_sm; |
74db920c | 56 | uid_t uid; |
fc22118d | 57 | struct xattr_operations **xops; |
74db920c GS |
58 | } FsContext; |
59 | ||
64b85a8f | 60 | void cred_init(FsCred *); |
758e8e38 | 61 | |
74db920c GS |
62 | typedef struct FileOperations |
63 | { | |
131dcb25 AL |
64 | int (*lstat)(FsContext *, const char *, struct stat *); |
65 | ssize_t (*readlink)(FsContext *, const char *, char *, size_t); | |
e95ead32 | 66 | int (*chmod)(FsContext *, const char *, FsCred *); |
f7613bee | 67 | int (*chown)(FsContext *, const char *, FsCred *); |
1c293312 | 68 | int (*mknod)(FsContext *, const char *, FsCred *); |
74bc02b2 | 69 | int (*utimensat)(FsContext *, const char *, const struct timespec *); |
5bae1900 | 70 | int (*remove)(FsContext *, const char *); |
879c2813 | 71 | int (*symlink)(FsContext *, const char *, const char *, FsCred *); |
c494dd6f | 72 | int (*link)(FsContext *, const char *, const char *); |
131dcb25 AL |
73 | int (*setuid)(FsContext *, uid_t); |
74 | int (*close)(FsContext *, int); | |
75 | int (*closedir)(FsContext *, DIR *); | |
a6568fe2 AL |
76 | DIR *(*opendir)(FsContext *, const char *); |
77 | int (*open)(FsContext *, const char *, int); | |
4750a96f | 78 | int (*open2)(FsContext *, const char *, int, FsCred *); |
a9231555 AL |
79 | void (*rewinddir)(FsContext *, DIR *); |
80 | off_t (*telldir)(FsContext *, DIR *); | |
81 | struct dirent *(*readdir)(FsContext *, DIR *); | |
82 | void (*seekdir)(FsContext *, DIR *, off_t); | |
56d15a53 SG |
83 | ssize_t (*preadv)(FsContext *, int, const struct iovec *, int, off_t); |
84 | ssize_t (*pwritev)(FsContext *, int, const struct iovec *, int, off_t); | |
00ec5c37 | 85 | int (*mkdir)(FsContext *, const char *, FsCred *); |
c494dd6f | 86 | int (*fstat)(FsContext *, int, struct stat *); |
8cf89e00 AL |
87 | int (*rename)(FsContext *, const char *, const char *); |
88 | int (*truncate)(FsContext *, const char *, off_t); | |
49594973 | 89 | int (*fsync)(FsContext *, int, int); |
be940c87 | 90 | int (*statfs)(FsContext *s, const char *path, struct statfs *stbuf); |
fa32ef88 AK |
91 | ssize_t (*lgetxattr)(FsContext *, const char *, |
92 | const char *, void *, size_t); | |
93 | ssize_t (*llistxattr)(FsContext *, const char *, void *, size_t); | |
10b468bd AK |
94 | int (*lsetxattr)(FsContext *, const char *, |
95 | const char *, void *, size_t, int); | |
9ed3ef26 | 96 | int (*lremovexattr)(FsContext *, const char *, const char *); |
74db920c GS |
97 | void *opaque; |
98 | } FileOperations; | |
fc22118d AK |
99 | |
100 | static inline const char *rpath(FsContext *ctx, const char *path) | |
101 | { | |
102 | /* FIXME: so wrong... */ | |
103 | static char buffer[4096]; | |
104 | snprintf(buffer, sizeof(buffer), "%s/%s", ctx->fs_root, path); | |
105 | return buffer; | |
106 | } | |
74db920c | 107 | #endif |