Sat, 16 Mar 2013 23:11:34 +0100
new vfs api
/* * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. * * Copyright 2013 Olaf Wintermann. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ #ifndef VFS_H #define VFS_H #include "../public/nsapi.h" #include "acl.h" #ifdef __cplusplus extern "C" { #endif typedef struct VFS_IO VFS_IO; typedef struct VFSFile VFSFile; struct VFS { SYS_FILE (*open)(VFSContext *ctx, char *path, int oflags); int (*stat)(VFSContext *ctx, char *path, struct stat *buf); int (*fstat)(VFSContext *ctx, SYS_FILE fd, struct stat *buf); }; struct VFSContext { Session *sn; Request *rq; VFS *vfs; pool_handle_t *pool; User *user; ACLListHandle *acllist; uint32_t aclreqaccess; int vfs_errno; }; struct VFSFile { VFSContext *ctx; VFS_IO *io; // IO functions void *data; // private data used by the VFSFile implementation int fd; // native file descriptor if available, or -1 }; struct VFS_IO { ssize_t (*read)(SYS_FILE fd, void *buf, size_t nbyte); ssize_t (*write)(SYS_FILE fd, const void *buf, size_t nbyte); void (*close)(SYS_FILE fd); }; /* * creates a VFSContext for a Request * vfs calls will do ACL checks */ VFSContext* vfs_request_context(Session *sn, Request *rq); SYS_FILE vfs_open(VFSContext *ctx, char *path, int oflags); SYS_FILE vfs_openRO(VFSContext *ctx, char *path); SYS_FILE vfs_openWO(VFSContext *ctx, char *path); SYS_FILE vfs_openRW(VFSContext *ctx, char *path); int vfs_stat(VFSContext *ctx, char *path, struct stat *buf); int vfs_fstat(VFSContext *ctx, SYS_FILE fd, struct stat *buf); void vfs_close(SYS_FILE fd); // private int sys_acl_check(VFSContext *ctx, uint32_t acm, uid_t *uid, gid_t *gid); void sys_set_error_status(VFSContext *ctx); ssize_t sys_file_read(SYS_FILE fd, void *buf, size_t nbyte); ssize_t sys_file_write(SYS_FILE fd, const void *buf, size_t nbyte); void sys_file_close(SYS_FILE fd); #ifdef __cplusplus } #endif #endif /* VFS_H */