UNIXworkcode

1 /* 2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. 3 * 4 * Copyright 2018 Olaf Wintermann. All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions are met: 8 * 9 * 1. Redistributions of source code must retain the above copyright 10 * notice, this list of conditions and the following disclaimer. 11 * 12 * 2. Redistributions in binary form must reproduce the above copyright 13 * notice, this list of conditions and the following disclaimer in the 14 * documentation and/or other materials provided with the distribution. 15 * 16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 20 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 26 * POSSIBILITY OF SUCH DAMAGE. 27 */ 28 29 #ifndef WS_VFS_H 30 #define WS_VFS_H 31 32 #include "nsapi.h" 33 #include "acl.h" 34 35 #ifdef __cplusplus 36 extern "C" { 37 #endif 38 39 #define VFS_CHECKS_ACL 0x0001 40 41 typedef struct VFS_IO VFS_IO; 42 typedef struct VFS_DIRIO VFS_DIRIO; 43 typedef struct VFSFile VFSFile; 44 typedef struct VFSDir VFSDir; 45 typedef struct VFSEntry VFSEntry; 46 47 #define VFS_DIR VFSDir* 48 #define VFS_ENTRY VFSEntry 49 50 struct VFS { 51 SYS_FILE (*open)(VFSContext *ctx, const char *path, int oflags); 52 int (*stat)(VFSContext *ctx, const char *path, struct stat *buf); 53 int (*fstat)(VFSContext *ctx, SYS_FILE fd, struct stat *buf); 54 VFS_DIR (*opendir)(VFSContext *ctx, const char *path); 55 VFS_DIR (*fdopendir)(VFSContext *ctx, SYS_FILE fd); 56 int (*mkdir)(VFSContext *ctx, const char *path); 57 int (*unlink)(VFSContext *ctx, const char *path); 58 int (*rmdir)(VFSContext *Ctx, const char *path); 59 uint32_t flags; 60 void *instance; 61 }; 62 63 struct VFSContext { 64 pool_handle_t *pool; 65 Session *sn; 66 Request *rq; 67 VFS *vfs; 68 User *user; 69 ACLListHandle *acllist; 70 uint32_t aclreqaccess; 71 int vfs_errno; 72 WSBool error_response_set; 73 }; 74 75 struct VFSFile { 76 VFSContext *ctx; 77 VFS_IO *io; /* IO functions */ 78 void *data; /* private data used by the VFSFile implementation */ 79 int fd; /* native file descriptor if available, or -1 */ 80 }; 81 82 struct VFSDir { 83 VFSContext *ctx; 84 VFS_DIRIO *io; 85 void *data; /* private data used by the VFSDir implementation */ 86 int fd; /* native file descriptor if available, or -1 */ 87 }; 88 89 struct VFSEntry { 90 char *name; 91 struct stat stat; 92 void *stat_extra; 93 int stat_errno; 94 }; 95 96 struct VFS_IO { 97 ssize_t (*read)(SYS_FILE fd, void *buf, size_t nbyte); 98 ssize_t (*write)(SYS_FILE fd, const void *buf, size_t nbyte); 99 ssize_t (*pread)(SYS_FILE fd, void *buf, size_t nbyte, off_t offset); 100 ssize_t (*pwrite)(SYS_FILE fd, const void *buf, size_t nbyte, off_t offset); 101 off_t (*seek)(SYS_FILE fd, off_t offset, int whence); 102 void (*close)(SYS_FILE fd); 103 int (*opt_aioread)(aiocb_s *aiocb); 104 int (*opt_aiowrite)(aiocb_s *aiocb); 105 const char* (*opt_getetag)(SYS_FILE fd); 106 }; 107 108 struct VFS_DIRIO { 109 int (*readdir)(VFS_DIR dir, VFS_ENTRY *entry, int getstat); 110 void (*close)(VFS_DIR dir); 111 }; 112 113 typedef void*(*vfs_init_func)(ServerConfiguration *cfg, pool_handle_t *pool, WSConfigNode *config); 114 typedef VFS*(*vfs_create_func)(Session *sn, Request *rq, pblock *pb, void *initData); 115 116 /* 117 * registers a new VFS 118 */ 119 int vfs_register_type(const char *name, vfs_init_func vfsInit, vfs_create_func vfsCreate); 120 121 /* 122 * Create a new VFS instance 123 */ 124 VFS* vfs_create(Session *sn, Request *rq, const char *vfs_class, pblock *pb, void *initData); 125 126 /* 127 * creates a VFSContext for a Request 128 * vfs calls will do ACL checks 129 */ 130 VFSContext* vfs_request_context(Session *sn, Request *rq); 131 132 SYS_FILE vfs_open(VFSContext *ctx, const char *path, int oflags); 133 SYS_FILE vfs_openRO(VFSContext *ctx, const char *path); 134 SYS_FILE vfs_openWO(VFSContext *ctx, const char *path); 135 SYS_FILE vfs_openRW(VFSContext *ctx, const char *path); 136 int vfs_stat(VFSContext *ctx, const char *path, struct stat *buf); 137 int vfs_fstat(VFSContext *ctx, SYS_FILE fd, struct stat *buf); 138 const char * vfs_getetag(SYS_FILE fd); 139 void vfs_close(SYS_FILE fd); 140 VFS_DIR vfs_opendir(VFSContext *ctx, const char *path); 141 VFS_DIR vfs_fdopendir(VFSContext *ctx, SYS_FILE fd); 142 int vfs_readdir(VFS_DIR dir, VFS_ENTRY *entry); 143 int vfs_readdir_stat(VFS_DIR dir, VFS_ENTRY *entry); 144 void vfs_closedir(VFS_DIR dir); 145 int vfs_mkdir(VFSContext *ctx, const char *path); 146 int vfs_unlink(VFSContext *ctx, const char *path); 147 int vfs_rmdir(VFSContext *ctx, const char *path); 148 149 #ifdef __cplusplus 150 } 151 #endif 152 153 #endif /* WS_VFS_H */ 154 155