Statistics
| Branch: | Revision:

root / hw / file-op-9p.h @ 56d15a53

History | View | Annotate | Download (3.1 kB)

1 74db920c Gautham R Shenoy
/*
2 74db920c Gautham R Shenoy
 * Virtio 9p
3 74db920c Gautham R Shenoy
 *
4 74db920c Gautham R Shenoy
 * Copyright IBM, Corp. 2010
5 74db920c Gautham R Shenoy
 *
6 74db920c Gautham R Shenoy
 * Authors:
7 74db920c Gautham R Shenoy
 *  Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
8 74db920c Gautham R Shenoy
 *
9 74db920c Gautham R Shenoy
 * This work is licensed under the terms of the GNU GPL, version 2.  See
10 74db920c Gautham R Shenoy
 * the COPYING file in the top-level directory.
11 74db920c Gautham R Shenoy
 *
12 74db920c Gautham R Shenoy
 */
13 74db920c Gautham R Shenoy
#ifndef _FILEOP_H
14 74db920c Gautham R Shenoy
#define _FILEOP_H
15 74db920c Gautham R Shenoy
#include <sys/types.h>
16 74db920c Gautham R Shenoy
#include <dirent.h>
17 74db920c Gautham R Shenoy
#include <sys/time.h>
18 74db920c Gautham R Shenoy
#include <utime.h>
19 74db920c Gautham R Shenoy
#include <sys/stat.h>
20 74db920c Gautham R Shenoy
#include <sys/uio.h>
21 758e8e38 Venkateswararao Jujjuri (JV)
#include <sys/vfs.h>
22 758e8e38 Venkateswararao Jujjuri (JV)
#define SM_LOCAL_MODE_BITS    0600
23 758e8e38 Venkateswararao Jujjuri (JV)
#define SM_LOCAL_DIR_MODE_BITS    0700
24 758e8e38 Venkateswararao Jujjuri (JV)
25 758e8e38 Venkateswararao Jujjuri (JV)
typedef enum
26 758e8e38 Venkateswararao Jujjuri (JV)
{
27 12848bfc Aneesh Kumar K.V
    /*
28 12848bfc Aneesh Kumar K.V
     * Server will try to set uid/gid.
29 12848bfc Aneesh Kumar K.V
     * On failure ignore the error.
30 12848bfc Aneesh Kumar K.V
     */
31 12848bfc Aneesh Kumar K.V
    SM_NONE = 0,
32 12848bfc Aneesh Kumar K.V
    /*
33 12848bfc Aneesh Kumar K.V
     * uid/gid set on fileserver files
34 12848bfc Aneesh Kumar K.V
     */
35 12848bfc Aneesh Kumar K.V
    SM_PASSTHROUGH = 1,
36 12848bfc Aneesh Kumar K.V
    /*
37 12848bfc Aneesh Kumar K.V
     * uid/gid part of xattr
38 12848bfc Aneesh Kumar K.V
     */
39 12848bfc Aneesh Kumar K.V
    SM_MAPPED,
40 758e8e38 Venkateswararao Jujjuri (JV)
} SecModel;
41 758e8e38 Venkateswararao Jujjuri (JV)
42 758e8e38 Venkateswararao Jujjuri (JV)
typedef struct FsCred
43 758e8e38 Venkateswararao Jujjuri (JV)
{
44 758e8e38 Venkateswararao Jujjuri (JV)
    uid_t   fc_uid;
45 758e8e38 Venkateswararao Jujjuri (JV)
    gid_t   fc_gid;
46 758e8e38 Venkateswararao Jujjuri (JV)
    mode_t  fc_mode;
47 758e8e38 Venkateswararao Jujjuri (JV)
    dev_t   fc_rdev;
48 758e8e38 Venkateswararao Jujjuri (JV)
} FsCred;
49 74db920c Gautham R Shenoy
50 fc22118d Aneesh Kumar K.V
struct xattr_operations;
51 fc22118d Aneesh Kumar K.V
52 74db920c Gautham R Shenoy
typedef struct FsContext
53 74db920c Gautham R Shenoy
{
54 74db920c Gautham R Shenoy
    char *fs_root;
55 758e8e38 Venkateswararao Jujjuri (JV)
    SecModel fs_sm;
56 74db920c Gautham R Shenoy
    uid_t uid;
57 fc22118d Aneesh Kumar K.V
    struct xattr_operations **xops;
58 74db920c Gautham R Shenoy
} FsContext;
59 74db920c Gautham R Shenoy
60 758e8e38 Venkateswararao Jujjuri (JV)
extern void cred_init(FsCred *);
61 758e8e38 Venkateswararao Jujjuri (JV)
62 74db920c Gautham R Shenoy
typedef struct FileOperations
63 74db920c Gautham R Shenoy
{
64 131dcb25 Anthony Liguori
    int (*lstat)(FsContext *, const char *, struct stat *);
65 131dcb25 Anthony Liguori
    ssize_t (*readlink)(FsContext *, const char *, char *, size_t);
66 e95ead32 Venkateswararao Jujjuri (JV)
    int (*chmod)(FsContext *, const char *, FsCred *);
67 f7613bee Venkateswararao Jujjuri (JV)
    int (*chown)(FsContext *, const char *, FsCred *);
68 1c293312 Venkateswararao Jujjuri (JV)
    int (*mknod)(FsContext *, const char *, FsCred *);
69 74bc02b2 M. Mohan Kumar
    int (*utimensat)(FsContext *, const char *, const struct timespec *);
70 5bae1900 Anthony Liguori
    int (*remove)(FsContext *, const char *);
71 879c2813 Venkateswararao Jujjuri (JV)
    int (*symlink)(FsContext *, const char *, const char *, FsCred *);
72 c494dd6f Anthony Liguori
    int (*link)(FsContext *, const char *, const char *);
73 131dcb25 Anthony Liguori
    int (*setuid)(FsContext *, uid_t);
74 131dcb25 Anthony Liguori
    int (*close)(FsContext *, int);
75 131dcb25 Anthony Liguori
    int (*closedir)(FsContext *, DIR *);
76 a6568fe2 Anthony Liguori
    DIR *(*opendir)(FsContext *, const char *);
77 a6568fe2 Anthony Liguori
    int (*open)(FsContext *, const char *, int);
78 4750a96f Venkateswararao Jujjuri (JV)
    int (*open2)(FsContext *, const char *, int, FsCred *);
79 a9231555 Anthony Liguori
    void (*rewinddir)(FsContext *, DIR *);
80 a9231555 Anthony Liguori
    off_t (*telldir)(FsContext *, DIR *);
81 a9231555 Anthony Liguori
    struct dirent *(*readdir)(FsContext *, DIR *);
82 a9231555 Anthony Liguori
    void (*seekdir)(FsContext *, DIR *, off_t);
83 56d15a53 Sanchit Garg
    ssize_t (*preadv)(FsContext *, int, const struct iovec *, int, off_t);
84 56d15a53 Sanchit Garg
    ssize_t (*pwritev)(FsContext *, int, const struct iovec *, int, off_t);
85 00ec5c37 Venkateswararao Jujjuri (JV)
    int (*mkdir)(FsContext *, const char *, FsCred *);
86 c494dd6f Anthony Liguori
    int (*fstat)(FsContext *, int, struct stat *);
87 8cf89e00 Anthony Liguori
    int (*rename)(FsContext *, const char *, const char *);
88 8cf89e00 Anthony Liguori
    int (*truncate)(FsContext *, const char *, off_t);
89 8cf89e00 Anthony Liguori
    int (*fsync)(FsContext *, int);
90 be940c87 M. Mohan Kumar
    int (*statfs)(FsContext *s, const char *path, struct statfs *stbuf);
91 fa32ef88 Aneesh Kumar K.V
    ssize_t (*lgetxattr)(FsContext *, const char *,
92 fa32ef88 Aneesh Kumar K.V
                         const char *, void *, size_t);
93 fa32ef88 Aneesh Kumar K.V
    ssize_t (*llistxattr)(FsContext *, const char *, void *, size_t);
94 10b468bd Aneesh Kumar K.V
    int (*lsetxattr)(FsContext *, const char *,
95 10b468bd Aneesh Kumar K.V
                     const char *, void *, size_t, int);
96 9ed3ef26 Aneesh Kumar K.V
    int (*lremovexattr)(FsContext *, const char *, const char *);
97 74db920c Gautham R Shenoy
    void *opaque;
98 74db920c Gautham R Shenoy
} FileOperations;
99 fc22118d Aneesh Kumar K.V
100 fc22118d Aneesh Kumar K.V
static inline const char *rpath(FsContext *ctx, const char *path)
101 fc22118d Aneesh Kumar K.V
{
102 fc22118d Aneesh Kumar K.V
    /* FIXME: so wrong... */
103 fc22118d Aneesh Kumar K.V
    static char buffer[4096];
104 fc22118d Aneesh Kumar K.V
    snprintf(buffer, sizeof(buffer), "%s/%s", ctx->fs_root, path);
105 fc22118d Aneesh Kumar K.V
    return buffer;
106 fc22118d Aneesh Kumar K.V
}
107 74db920c Gautham R Shenoy
#endif