src/server/public/vfs.h

Sun, 19 Mar 2023 16:48:19 +0100

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Sun, 19 Mar 2023 16:48:19 +0100
changeset 484
c036a8b242a8
parent 366
47bc686fafe4
permissions
-rw-r--r--

implement webdav xattr namespace lists

/*
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
 *
 * Copyright 2018 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 WS_VFS_H
#define	WS_VFS_H

#include "nsapi.h"
#include "acl.h"

#ifdef	__cplusplus
extern "C" {
#endif

#define VFS_CHECKS_ACL 0x0001  
    
typedef struct VFS_IO     VFS_IO;
typedef struct VFS_DIRIO  VFS_DIRIO;
typedef struct VFSFile    VFSFile;
typedef struct VFSDir     VFSDir;
typedef struct VFSEntry   VFSEntry;

#define VFS_DIR           VFSDir*
#define VFS_ENTRY         VFSEntry

struct VFS {
    SYS_FILE (*open)(VFSContext *ctx, const char *path, int oflags);
    int (*stat)(VFSContext *ctx, const char *path, struct stat *buf);
    int (*fstat)(VFSContext *ctx, SYS_FILE fd, struct stat *buf);
    VFS_DIR (*opendir)(VFSContext *ctx, const char *path);
    VFS_DIR (*fdopendir)(VFSContext *ctx, SYS_FILE fd);
    int (*mkdir)(VFSContext *ctx, const char *path);
    int (*unlink)(VFSContext *ctx, const char *path);
    int (*rmdir)(VFSContext *Ctx, const char *path);
    uint32_t flags;
    void *instance;
};

struct VFSContext {
    pool_handle_t *pool;
    Session *sn;
    Request *rq;
    VFS *vfs;
    User *user;
    ACLListHandle *acllist;
    uint32_t aclreqaccess;
    int vfs_errno;
    WSBool error_response_set;
};

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 VFSDir {
    VFSContext *ctx;
    VFS_DIRIO *io;
    void *data; /* private data used by the VFSDir implementation */
    int fd; /* native file descriptor if available, or -1 */
};

struct VFSEntry {
    char *name;
    struct stat stat;
    void *stat_extra;
    int stat_errno;
};

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);
    ssize_t (*pread)(SYS_FILE fd, void *buf, size_t nbyte, off_t offset);
    ssize_t (*pwrite)(SYS_FILE fd, const void *buf, size_t nbyte, off_t offset);
    off_t (*seek)(SYS_FILE fd, off_t offset, int whence);
    void (*close)(SYS_FILE fd);
    int (*opt_aioread)(aiocb_s *aiocb);
    int (*opt_aiowrite)(aiocb_s *aiocb);
    const char* (*opt_getetag)(SYS_FILE fd);
};

struct VFS_DIRIO {
    int (*readdir)(VFS_DIR dir, VFS_ENTRY *entry, int getstat);
    void (*close)(VFS_DIR dir);
};

typedef void*(*vfs_init_func)(ServerConfiguration *cfg, pool_handle_t *pool, WSConfigNode *config);
typedef VFS*(*vfs_create_func)(Session *sn, Request *rq, pblock *pb, void *initData);

/*
 * registers a new VFS
 */
int vfs_register_type(const char *name, vfs_init_func vfsInit, vfs_create_func vfsCreate);

/*
 * Create a new VFS instance
 */
VFS* vfs_create(Session *sn, Request *rq, const char *vfs_class, pblock *pb, void *initData);

/*
 * 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, const char *path, int oflags);
SYS_FILE vfs_openRO(VFSContext *ctx, const char *path);
SYS_FILE vfs_openWO(VFSContext *ctx, const char *path);
SYS_FILE vfs_openRW(VFSContext *ctx, const char *path);
int vfs_stat(VFSContext *ctx, const char *path, struct stat *buf);
int vfs_fstat(VFSContext *ctx, SYS_FILE fd, struct stat *buf);
const char * vfs_getetag(SYS_FILE fd);
void vfs_close(SYS_FILE fd);
VFS_DIR vfs_opendir(VFSContext *ctx, const char *path);
VFS_DIR vfs_fdopendir(VFSContext *ctx, SYS_FILE fd);
int vfs_readdir(VFS_DIR dir, VFS_ENTRY *entry);
int vfs_readdir_stat(VFS_DIR dir, VFS_ENTRY *entry);
void vfs_closedir(VFS_DIR dir);
int vfs_mkdir(VFSContext *ctx, const char *path);
int vfs_unlink(VFSContext *ctx, const char *path);
int vfs_rmdir(VFSContext *ctx, const char *path);

#ifdef	__cplusplus
}
#endif

#endif	/* WS_VFS_H */

mercurial