#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,
char *path,
int oflags);
int (*stat)(VFSContext *ctx,
char *path,
struct stat *buf);
int (*fstat)(VFSContext *ctx,
SYS_FILE fd,
struct stat *buf);
VFS_DIR (*opendir)(VFSContext *ctx,
char *path);
int (*mkdir)(VFSContext *ctx,
char *path);
int (*unlink)(VFSContext *ctx,
char *path);
uint32_t flags;
};
struct VFSContext {
pool_handle_t *pool;
Session *sn;
Request *rq;
VFS *vfs;
User *user;
ACLListHandle *acllist;
uint32_t aclreqaccess;
int vfs_errno;
};
struct VFSFile {
VFSContext *ctx;
VFS_IO *io;
void *data;
int fd;
};
struct VFSDir {
VFSContext *ctx;
VFS_DIRIO *io;
void *data;
int fd;
};
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);
};
struct VFS_DIRIO {
int (*readdir)(
VFS_DIR dir,
VFS_ENTRY *entry,
int getstat);
void (*close)(
VFS_DIR dir);
};
void vfs_add(
char *name,
VFS *vfs);
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);
VFS_DIR vfs_opendir(VFSContext *ctx,
char *path);
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,
char *path);
int vfs_unlink(VFSContext *ctx,
char *path);
#ifdef __cplusplus
}
#endif
#endif