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 struct FsCred 27353ac78dSAneesh Kumar K.V { 28353ac78dSAneesh Kumar K.V uid_t fc_uid; 29353ac78dSAneesh Kumar K.V gid_t fc_gid; 30353ac78dSAneesh Kumar K.V mode_t fc_mode; 31353ac78dSAneesh Kumar K.V dev_t fc_rdev; 32353ac78dSAneesh Kumar K.V } FsCred; 33353ac78dSAneesh Kumar K.V 34353ac78dSAneesh Kumar K.V struct xattr_operations; 35e06a765eSHarsh Prateek Bora struct FsContext; 36e06a765eSHarsh Prateek Bora struct V9fsPath; 37e06a765eSHarsh Prateek Bora 38e06a765eSHarsh Prateek Bora typedef struct extended_ops { 39e06a765eSHarsh Prateek Bora int (*get_st_gen)(struct FsContext *, struct V9fsPath *, 40e06a765eSHarsh Prateek Bora mode_t, uint64_t *); 41e06a765eSHarsh Prateek Bora } extended_ops; 42353ac78dSAneesh Kumar K.V 43d3ab98e6SAneesh Kumar K.V /* export flags */ 44c98f1d4aSAneesh Kumar K.V #define V9FS_IMMEDIATE_WRITEOUT 0x00000001 45c98f1d4aSAneesh Kumar K.V #define V9FS_PATHNAME_FSCONTEXT 0x00000002 46*b97400caSAneesh Kumar K.V /* 47*b97400caSAneesh Kumar K.V * uid/gid set on fileserver files 48*b97400caSAneesh Kumar K.V */ 49*b97400caSAneesh Kumar K.V #define V9FS_SM_PASSTHROUGH 0x00000004 50*b97400caSAneesh Kumar K.V /* 51*b97400caSAneesh Kumar K.V * uid/gid part of xattr 52*b97400caSAneesh Kumar K.V */ 53*b97400caSAneesh Kumar K.V #define V9FS_SM_MAPPED 0x00000008 54*b97400caSAneesh Kumar K.V /* 55*b97400caSAneesh Kumar K.V * Server will try to set uid/gid. 56*b97400caSAneesh Kumar K.V * On failure ignore the error. 57*b97400caSAneesh Kumar K.V */ 58*b97400caSAneesh Kumar K.V #define V9FS_SM_NONE 0x00000010 59*b97400caSAneesh Kumar K.V 60*b97400caSAneesh Kumar K.V 61*b97400caSAneesh Kumar K.V #define V9FS_SEC_MASK 0x0000001C 62d3ab98e6SAneesh Kumar K.V 63353ac78dSAneesh Kumar K.V typedef struct FsContext 64353ac78dSAneesh Kumar K.V { 65353ac78dSAneesh Kumar K.V uid_t uid; 66*b97400caSAneesh Kumar K.V char *fs_root; 67d3ab98e6SAneesh Kumar K.V int export_flags; 68353ac78dSAneesh Kumar K.V struct xattr_operations **xops; 69e06a765eSHarsh Prateek Bora struct extended_ops exops; 70532decb7SAneesh Kumar K.V /* fs driver specific data */ 71532decb7SAneesh Kumar K.V void *private; 72353ac78dSAneesh Kumar K.V } FsContext; 73353ac78dSAneesh Kumar K.V 742289be19SAneesh Kumar K.V typedef struct V9fsPath { 752289be19SAneesh Kumar K.V int16_t size; 762289be19SAneesh Kumar K.V char *data; 772289be19SAneesh Kumar K.V } V9fsPath; 782289be19SAneesh Kumar K.V 79353ac78dSAneesh Kumar K.V void cred_init(FsCred *); 80353ac78dSAneesh Kumar K.V 81353ac78dSAneesh Kumar K.V typedef struct FileOperations 82353ac78dSAneesh Kumar K.V { 830174fe73SAneesh Kumar K.V int (*init)(struct FsContext *); 842289be19SAneesh Kumar K.V int (*lstat)(FsContext *, V9fsPath *, struct stat *); 852289be19SAneesh Kumar K.V ssize_t (*readlink)(FsContext *, V9fsPath *, char *, size_t); 862289be19SAneesh Kumar K.V int (*chmod)(FsContext *, V9fsPath *, FsCred *); 872289be19SAneesh Kumar K.V int (*chown)(FsContext *, V9fsPath *, FsCred *); 882289be19SAneesh Kumar K.V int (*mknod)(FsContext *, V9fsPath *, const char *, FsCred *); 892289be19SAneesh Kumar K.V int (*utimensat)(FsContext *, V9fsPath *, const struct timespec *); 90353ac78dSAneesh Kumar K.V int (*remove)(FsContext *, const char *); 912289be19SAneesh Kumar K.V int (*symlink)(FsContext *, const char *, V9fsPath *, 922289be19SAneesh Kumar K.V const char *, FsCred *); 932289be19SAneesh Kumar K.V int (*link)(FsContext *, V9fsPath *, V9fsPath *, const char *); 94353ac78dSAneesh Kumar K.V int (*setuid)(FsContext *, uid_t); 95353ac78dSAneesh Kumar K.V int (*close)(FsContext *, int); 96353ac78dSAneesh Kumar K.V int (*closedir)(FsContext *, DIR *); 972289be19SAneesh Kumar K.V DIR *(*opendir)(FsContext *, V9fsPath *); 982289be19SAneesh Kumar K.V int (*open)(FsContext *, V9fsPath *, int); 992289be19SAneesh Kumar K.V int (*open2)(FsContext *, V9fsPath *, const char *, int, FsCred *); 100353ac78dSAneesh Kumar K.V void (*rewinddir)(FsContext *, DIR *); 101353ac78dSAneesh Kumar K.V off_t (*telldir)(FsContext *, DIR *); 1025f524c1eSHarsh Prateek Bora int (*readdir_r)(FsContext *, DIR *, struct dirent *, struct dirent **); 103353ac78dSAneesh Kumar K.V void (*seekdir)(FsContext *, DIR *, off_t); 104353ac78dSAneesh Kumar K.V ssize_t (*preadv)(FsContext *, int, const struct iovec *, int, off_t); 105353ac78dSAneesh Kumar K.V ssize_t (*pwritev)(FsContext *, int, const struct iovec *, int, off_t); 1062289be19SAneesh Kumar K.V int (*mkdir)(FsContext *, V9fsPath *, const char *, FsCred *); 107353ac78dSAneesh Kumar K.V int (*fstat)(FsContext *, int, struct stat *); 108353ac78dSAneesh Kumar K.V int (*rename)(FsContext *, const char *, const char *); 1092289be19SAneesh Kumar K.V int (*truncate)(FsContext *, V9fsPath *, off_t); 110353ac78dSAneesh Kumar K.V int (*fsync)(FsContext *, int, int); 1112289be19SAneesh Kumar K.V int (*statfs)(FsContext *s, V9fsPath *path, struct statfs *stbuf); 1122289be19SAneesh Kumar K.V ssize_t (*lgetxattr)(FsContext *, V9fsPath *, 113353ac78dSAneesh Kumar K.V const char *, void *, size_t); 1142289be19SAneesh Kumar K.V ssize_t (*llistxattr)(FsContext *, V9fsPath *, void *, size_t); 1152289be19SAneesh Kumar K.V int (*lsetxattr)(FsContext *, V9fsPath *, 116353ac78dSAneesh Kumar K.V const char *, void *, size_t, int); 1172289be19SAneesh Kumar K.V int (*lremovexattr)(FsContext *, V9fsPath *, const char *); 1182289be19SAneesh Kumar K.V int (*name_to_path)(FsContext *, V9fsPath *, const char *, V9fsPath *); 1192289be19SAneesh Kumar K.V int (*renameat)(FsContext *ctx, V9fsPath *olddir, const char *old_name, 1202289be19SAneesh Kumar K.V V9fsPath *newdir, const char *new_name); 1212289be19SAneesh Kumar K.V int (*unlinkat)(FsContext *ctx, V9fsPath *dir, const char *name, int flags); 122353ac78dSAneesh Kumar K.V void *opaque; 123353ac78dSAneesh Kumar K.V } FileOperations; 124353ac78dSAneesh Kumar K.V 125353ac78dSAneesh Kumar K.V #endif 126