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 46b97400caSAneesh Kumar K.V /* 47b97400caSAneesh Kumar K.V * uid/gid set on fileserver files 48b97400caSAneesh Kumar K.V */ 49b97400caSAneesh Kumar K.V #define V9FS_SM_PASSTHROUGH 0x00000004 50b97400caSAneesh Kumar K.V /* 51b97400caSAneesh Kumar K.V * uid/gid part of xattr 52b97400caSAneesh Kumar K.V */ 53b97400caSAneesh Kumar K.V #define V9FS_SM_MAPPED 0x00000008 54b97400caSAneesh Kumar K.V /* 55b97400caSAneesh Kumar K.V * Server will try to set uid/gid. 56b97400caSAneesh Kumar K.V * On failure ignore the error. 57b97400caSAneesh Kumar K.V */ 58b97400caSAneesh Kumar K.V #define V9FS_SM_NONE 0x00000010 59*2c74c2cbSM. Mohan Kumar #define V9FS_RDONLY 0x00000020 60b97400caSAneesh Kumar K.V 61b97400caSAneesh Kumar K.V #define V9FS_SEC_MASK 0x0000001C 62d3ab98e6SAneesh Kumar K.V 63*2c74c2cbSM. Mohan Kumar 64*2c74c2cbSM. Mohan Kumar 65353ac78dSAneesh Kumar K.V typedef struct FsContext 66353ac78dSAneesh Kumar K.V { 67353ac78dSAneesh Kumar K.V uid_t uid; 68b97400caSAneesh Kumar K.V char *fs_root; 69d3ab98e6SAneesh Kumar K.V int export_flags; 70353ac78dSAneesh Kumar K.V struct xattr_operations **xops; 71e06a765eSHarsh Prateek Bora struct extended_ops exops; 72532decb7SAneesh Kumar K.V /* fs driver specific data */ 73532decb7SAneesh Kumar K.V void *private; 74353ac78dSAneesh Kumar K.V } FsContext; 75353ac78dSAneesh Kumar K.V 762289be19SAneesh Kumar K.V typedef struct V9fsPath { 772289be19SAneesh Kumar K.V int16_t size; 782289be19SAneesh Kumar K.V char *data; 792289be19SAneesh Kumar K.V } V9fsPath; 802289be19SAneesh Kumar K.V 81353ac78dSAneesh Kumar K.V void cred_init(FsCred *); 82353ac78dSAneesh Kumar K.V 83353ac78dSAneesh Kumar K.V typedef struct FileOperations 84353ac78dSAneesh Kumar K.V { 850174fe73SAneesh Kumar K.V int (*init)(struct FsContext *); 862289be19SAneesh Kumar K.V int (*lstat)(FsContext *, V9fsPath *, struct stat *); 872289be19SAneesh Kumar K.V ssize_t (*readlink)(FsContext *, V9fsPath *, char *, size_t); 882289be19SAneesh Kumar K.V int (*chmod)(FsContext *, V9fsPath *, FsCred *); 892289be19SAneesh Kumar K.V int (*chown)(FsContext *, V9fsPath *, FsCred *); 902289be19SAneesh Kumar K.V int (*mknod)(FsContext *, V9fsPath *, const char *, FsCred *); 912289be19SAneesh Kumar K.V int (*utimensat)(FsContext *, V9fsPath *, const struct timespec *); 92353ac78dSAneesh Kumar K.V int (*remove)(FsContext *, const char *); 932289be19SAneesh Kumar K.V int (*symlink)(FsContext *, const char *, V9fsPath *, 942289be19SAneesh Kumar K.V const char *, FsCred *); 952289be19SAneesh Kumar K.V int (*link)(FsContext *, V9fsPath *, V9fsPath *, const char *); 96353ac78dSAneesh Kumar K.V int (*setuid)(FsContext *, uid_t); 97353ac78dSAneesh Kumar K.V int (*close)(FsContext *, int); 98353ac78dSAneesh Kumar K.V int (*closedir)(FsContext *, DIR *); 992289be19SAneesh Kumar K.V DIR *(*opendir)(FsContext *, V9fsPath *); 1002289be19SAneesh Kumar K.V int (*open)(FsContext *, V9fsPath *, int); 1012289be19SAneesh Kumar K.V int (*open2)(FsContext *, V9fsPath *, const char *, int, FsCred *); 102353ac78dSAneesh Kumar K.V void (*rewinddir)(FsContext *, DIR *); 103353ac78dSAneesh Kumar K.V off_t (*telldir)(FsContext *, DIR *); 1045f524c1eSHarsh Prateek Bora int (*readdir_r)(FsContext *, DIR *, struct dirent *, struct dirent **); 105353ac78dSAneesh Kumar K.V void (*seekdir)(FsContext *, DIR *, off_t); 106353ac78dSAneesh Kumar K.V ssize_t (*preadv)(FsContext *, int, const struct iovec *, int, off_t); 107353ac78dSAneesh Kumar K.V ssize_t (*pwritev)(FsContext *, int, const struct iovec *, int, off_t); 1082289be19SAneesh Kumar K.V int (*mkdir)(FsContext *, V9fsPath *, const char *, FsCred *); 109353ac78dSAneesh Kumar K.V int (*fstat)(FsContext *, int, struct stat *); 110353ac78dSAneesh Kumar K.V int (*rename)(FsContext *, const char *, const char *); 1112289be19SAneesh Kumar K.V int (*truncate)(FsContext *, V9fsPath *, off_t); 112353ac78dSAneesh Kumar K.V int (*fsync)(FsContext *, int, int); 1132289be19SAneesh Kumar K.V int (*statfs)(FsContext *s, V9fsPath *path, struct statfs *stbuf); 1142289be19SAneesh Kumar K.V ssize_t (*lgetxattr)(FsContext *, V9fsPath *, 115353ac78dSAneesh Kumar K.V const char *, void *, size_t); 1162289be19SAneesh Kumar K.V ssize_t (*llistxattr)(FsContext *, V9fsPath *, void *, size_t); 1172289be19SAneesh Kumar K.V int (*lsetxattr)(FsContext *, V9fsPath *, 118353ac78dSAneesh Kumar K.V const char *, void *, size_t, int); 1192289be19SAneesh Kumar K.V int (*lremovexattr)(FsContext *, V9fsPath *, const char *); 1202289be19SAneesh Kumar K.V int (*name_to_path)(FsContext *, V9fsPath *, const char *, V9fsPath *); 1212289be19SAneesh Kumar K.V int (*renameat)(FsContext *ctx, V9fsPath *olddir, const char *old_name, 1222289be19SAneesh Kumar K.V V9fsPath *newdir, const char *new_name); 1232289be19SAneesh Kumar K.V int (*unlinkat)(FsContext *ctx, V9fsPath *dir, const char *name, int flags); 124353ac78dSAneesh Kumar K.V void *opaque; 125353ac78dSAneesh Kumar K.V } FileOperations; 126353ac78dSAneesh Kumar K.V 127353ac78dSAneesh Kumar K.V #endif 128