xref: /openbmc/qemu/fsdev/file-op-9p.h (revision e06a765efbe3239d4b6148727a29342ab234180e)
1353ac78dSAneesh Kumar K.V /*
2353ac78dSAneesh Kumar K.V  * Virtio 9p
3353ac78dSAneesh Kumar K.V  *
4353ac78dSAneesh Kumar K.V  * Copyright IBM, Corp. 2010
5353ac78dSAneesh Kumar K.V  *
6353ac78dSAneesh Kumar K.V  * Authors:
7353ac78dSAneesh Kumar K.V  *  Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
8353ac78dSAneesh Kumar K.V  *
9353ac78dSAneesh Kumar K.V  * This work is licensed under the terms of the GNU GPL, version 2.  See
10353ac78dSAneesh Kumar K.V  * the COPYING file in the top-level directory.
11353ac78dSAneesh Kumar K.V  *
12353ac78dSAneesh Kumar K.V  */
13353ac78dSAneesh Kumar K.V #ifndef _FILEOP_H
14353ac78dSAneesh Kumar K.V #define _FILEOP_H
15353ac78dSAneesh Kumar K.V #include <sys/types.h>
16353ac78dSAneesh Kumar K.V #include <dirent.h>
17353ac78dSAneesh Kumar K.V #include <sys/time.h>
18353ac78dSAneesh Kumar K.V #include <utime.h>
19353ac78dSAneesh Kumar K.V #include <sys/stat.h>
20353ac78dSAneesh Kumar K.V #include <sys/uio.h>
21353ac78dSAneesh Kumar K.V #include <sys/vfs.h>
220174fe73SAneesh Kumar K.V 
23353ac78dSAneesh Kumar K.V #define SM_LOCAL_MODE_BITS    0600
24353ac78dSAneesh Kumar K.V #define SM_LOCAL_DIR_MODE_BITS    0700
25353ac78dSAneesh Kumar K.V 
26353ac78dSAneesh Kumar K.V typedef enum
27353ac78dSAneesh Kumar K.V {
28353ac78dSAneesh Kumar K.V     /*
29353ac78dSAneesh Kumar K.V      * Server will try to set uid/gid.
30353ac78dSAneesh Kumar K.V      * On failure ignore the error.
31353ac78dSAneesh Kumar K.V      */
32353ac78dSAneesh Kumar K.V     SM_NONE = 0,
33353ac78dSAneesh Kumar K.V     /*
34353ac78dSAneesh Kumar K.V      * uid/gid set on fileserver files
35353ac78dSAneesh Kumar K.V      */
36353ac78dSAneesh Kumar K.V     SM_PASSTHROUGH = 1,
37353ac78dSAneesh Kumar K.V     /*
38353ac78dSAneesh Kumar K.V      * uid/gid part of xattr
39353ac78dSAneesh Kumar K.V      */
40353ac78dSAneesh Kumar K.V     SM_MAPPED,
41353ac78dSAneesh Kumar K.V } SecModel;
42353ac78dSAneesh Kumar K.V 
43353ac78dSAneesh Kumar K.V typedef struct FsCred
44353ac78dSAneesh Kumar K.V {
45353ac78dSAneesh Kumar K.V     uid_t   fc_uid;
46353ac78dSAneesh Kumar K.V     gid_t   fc_gid;
47353ac78dSAneesh Kumar K.V     mode_t  fc_mode;
48353ac78dSAneesh Kumar K.V     dev_t   fc_rdev;
49353ac78dSAneesh Kumar K.V } FsCred;
50353ac78dSAneesh Kumar K.V 
51353ac78dSAneesh Kumar K.V struct xattr_operations;
52*e06a765eSHarsh Prateek Bora struct FsContext;
53*e06a765eSHarsh Prateek Bora struct V9fsPath;
54*e06a765eSHarsh Prateek Bora 
55*e06a765eSHarsh Prateek Bora typedef struct extended_ops {
56*e06a765eSHarsh Prateek Bora     int (*get_st_gen)(struct FsContext *, struct V9fsPath *,
57*e06a765eSHarsh Prateek Bora                       mode_t, uint64_t *);
58*e06a765eSHarsh Prateek Bora } extended_ops;
59353ac78dSAneesh Kumar K.V 
60532decb7SAneesh Kumar K.V /* FsContext flag values */
61532decb7SAneesh Kumar K.V #define PATHNAME_FSCONTEXT 0x1
62532decb7SAneesh Kumar K.V 
63d3ab98e6SAneesh Kumar K.V /* export flags */
64d3ab98e6SAneesh Kumar K.V #define V9FS_IMMEDIATE_WRITEOUT 0x1
65d3ab98e6SAneesh Kumar K.V 
66353ac78dSAneesh Kumar K.V typedef struct FsContext
67353ac78dSAneesh Kumar K.V {
68532decb7SAneesh Kumar K.V     int flags;
69353ac78dSAneesh Kumar K.V     char *fs_root;
70353ac78dSAneesh Kumar K.V     SecModel fs_sm;
71353ac78dSAneesh Kumar K.V     uid_t uid;
72d3ab98e6SAneesh Kumar K.V     int export_flags;
73353ac78dSAneesh Kumar K.V     struct xattr_operations **xops;
74*e06a765eSHarsh Prateek Bora     struct extended_ops exops;
75532decb7SAneesh Kumar K.V     /* fs driver specific data */
76532decb7SAneesh Kumar K.V     void *private;
77353ac78dSAneesh Kumar K.V } FsContext;
78353ac78dSAneesh Kumar K.V 
792289be19SAneesh Kumar K.V typedef struct V9fsPath {
802289be19SAneesh Kumar K.V     int16_t size;
812289be19SAneesh Kumar K.V     char *data;
822289be19SAneesh Kumar K.V } V9fsPath;
832289be19SAneesh Kumar K.V 
84353ac78dSAneesh Kumar K.V void cred_init(FsCred *);
85353ac78dSAneesh Kumar K.V 
86353ac78dSAneesh Kumar K.V typedef struct FileOperations
87353ac78dSAneesh Kumar K.V {
880174fe73SAneesh Kumar K.V     int (*init)(struct FsContext *);
892289be19SAneesh Kumar K.V     int (*lstat)(FsContext *, V9fsPath *, struct stat *);
902289be19SAneesh Kumar K.V     ssize_t (*readlink)(FsContext *, V9fsPath *, char *, size_t);
912289be19SAneesh Kumar K.V     int (*chmod)(FsContext *, V9fsPath *, FsCred *);
922289be19SAneesh Kumar K.V     int (*chown)(FsContext *, V9fsPath *, FsCred *);
932289be19SAneesh Kumar K.V     int (*mknod)(FsContext *, V9fsPath *, const char *, FsCred *);
942289be19SAneesh Kumar K.V     int (*utimensat)(FsContext *, V9fsPath *, const struct timespec *);
95353ac78dSAneesh Kumar K.V     int (*remove)(FsContext *, const char *);
962289be19SAneesh Kumar K.V     int (*symlink)(FsContext *, const char *, V9fsPath *,
972289be19SAneesh Kumar K.V                    const char *, FsCred *);
982289be19SAneesh Kumar K.V     int (*link)(FsContext *, V9fsPath *, V9fsPath *, const char *);
99353ac78dSAneesh Kumar K.V     int (*setuid)(FsContext *, uid_t);
100353ac78dSAneesh Kumar K.V     int (*close)(FsContext *, int);
101353ac78dSAneesh Kumar K.V     int (*closedir)(FsContext *, DIR *);
1022289be19SAneesh Kumar K.V     DIR *(*opendir)(FsContext *, V9fsPath *);
1032289be19SAneesh Kumar K.V     int (*open)(FsContext *, V9fsPath *, int);
1042289be19SAneesh Kumar K.V     int (*open2)(FsContext *, V9fsPath *, const char *, int, FsCred *);
105353ac78dSAneesh Kumar K.V     void (*rewinddir)(FsContext *, DIR *);
106353ac78dSAneesh Kumar K.V     off_t (*telldir)(FsContext *, DIR *);
1075f524c1eSHarsh Prateek Bora     int (*readdir_r)(FsContext *, DIR *, struct dirent *, struct dirent **);
108353ac78dSAneesh Kumar K.V     void (*seekdir)(FsContext *, DIR *, off_t);
109353ac78dSAneesh Kumar K.V     ssize_t (*preadv)(FsContext *, int, const struct iovec *, int, off_t);
110353ac78dSAneesh Kumar K.V     ssize_t (*pwritev)(FsContext *, int, const struct iovec *, int, off_t);
1112289be19SAneesh Kumar K.V     int (*mkdir)(FsContext *, V9fsPath *, const char *, FsCred *);
112353ac78dSAneesh Kumar K.V     int (*fstat)(FsContext *, int, struct stat *);
113353ac78dSAneesh Kumar K.V     int (*rename)(FsContext *, const char *, const char *);
1142289be19SAneesh Kumar K.V     int (*truncate)(FsContext *, V9fsPath *, off_t);
115353ac78dSAneesh Kumar K.V     int (*fsync)(FsContext *, int, int);
1162289be19SAneesh Kumar K.V     int (*statfs)(FsContext *s, V9fsPath *path, struct statfs *stbuf);
1172289be19SAneesh Kumar K.V     ssize_t (*lgetxattr)(FsContext *, V9fsPath *,
118353ac78dSAneesh Kumar K.V                          const char *, void *, size_t);
1192289be19SAneesh Kumar K.V     ssize_t (*llistxattr)(FsContext *, V9fsPath *, void *, size_t);
1202289be19SAneesh Kumar K.V     int (*lsetxattr)(FsContext *, V9fsPath *,
121353ac78dSAneesh Kumar K.V                      const char *, void *, size_t, int);
1222289be19SAneesh Kumar K.V     int (*lremovexattr)(FsContext *, V9fsPath *, const char *);
1232289be19SAneesh Kumar K.V     int (*name_to_path)(FsContext *, V9fsPath *, const char *, V9fsPath *);
1242289be19SAneesh Kumar K.V     int (*renameat)(FsContext *ctx, V9fsPath *olddir, const char *old_name,
1252289be19SAneesh Kumar K.V                     V9fsPath *newdir, const char *new_name);
1262289be19SAneesh Kumar K.V     int (*unlinkat)(FsContext *ctx, V9fsPath *dir, const char *name, int flags);
127353ac78dSAneesh Kumar K.V     void *opaque;
128353ac78dSAneesh Kumar K.V } FileOperations;
129353ac78dSAneesh Kumar K.V 
130353ac78dSAneesh Kumar K.V #endif
131