#ifndef VFSI_H
#define VFSI_H
#include <stdarg.h>
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include <stdlib.h>
#define VFSI_ABI_VERSION 3
#define VFSI_ERROR_NONE 0
#define VFSI_ERROR_FILESYSTEM 1
#define VFSI_ERROR_TRANSPORT 2
#define VFSI_ERROR_UNSUPPORTED 3
#define VFSI_ERROR_INVALID_ARGUMENT 4
#define VFSI_ERROR_NOT_ATTEMPTED 5
#define VFSI_ERROR_INDETERMINATE 6
#define VFSI_RESULT_MESSAGE_SIZE 160
#define VFSI_ATTR_MODE (1 << 0)
#define VFSI_ATTR_SIZE (1 << 1)
#define VFSI_ATTR_NLINK (1 << 2)
#define VFSI_ATTR_FILEID (1 << 3)
#define VFSI_ATTR_BLOCKS (1 << 4)
#define VFSI_ATTR_UID (1 << 5)
#define VFSI_ATTR_GID (1 << 6)
#define VFSI_ATTR_RDEV (1 << 7)
#define VFSI_ATTR_ATIME (1 << 8)
#define VFSI_ATTR_MTIME (1 << 9)
#define VFSI_ATTR_CTIME (1 << 10)
#define VFSI_CAP_SERVER_COPY (1 << 0)
#define VFSI_CAP_POSIX_METADATA (1 << 1)
#define VFSI_CAP_SYMLINKS (1 << 2)
#define VFSI_CAP_HARDLINKS (1 << 3)
#define VFSI_CAP_NON_UTF8_PATHS (1 << 4)
#define VFSI_CAP_LSTAT (1 << 5)
typedef struct vfsi_fs vfsi_fs;
typedef struct vfsi_attrs {
uint32_t struct_size;
uint32_t abi_version;
uint32_t ftype;
uint32_t mode;
uint64_t size;
uint32_t nlink;
uint64_t fileid;
uint32_t uid;
uint32_t gid;
uint64_t blocks;
int64_t atime_sec;
uint32_t atime_nsec;
int64_t mtime_sec;
uint32_t mtime_nsec;
int64_t ctime_sec;
uint32_t ctime_nsec;
} vfsi_attrs;
typedef struct vfsi_result {
uint32_t struct_size;
uint32_t abi_version;
size_t index;
uint32_t category;
uint32_t err_no;
char message[VFSI_RESULT_MESSAGE_SIZE];
} vfsi_result;
typedef struct vfsi_open_op {
const char *path;
int flags;
uint32_t mode;
int fd;
} vfsi_open_op;
typedef struct vfsi_stat_op {
const char *path;
struct vfsi_attrs attrs;
} vfsi_stat_op;
typedef struct vfsi_setattr_op {
const char *path;
uint32_t mask;
uint32_t mode;
uint64_t size;
int64_t atime_sec;
uint32_t atime_nsec;
int64_t mtime_sec;
uint32_t mtime_nsec;
} vfsi_setattr_op;
typedef struct vfsi_pread_op {
int fd;
void *buf;
size_t len;
uint64_t offset;
size_t got;
} vfsi_pread_op;
typedef struct vfsi_pwrite_op {
int fd;
const void *buf;
size_t len;
uint64_t offset;
size_t wrote;
} vfsi_pwrite_op;
typedef struct vfsi_mkdir_op {
const char *path;
uint32_t mode;
} vfsi_mkdir_op;
typedef struct vfsi_rename_op {
const char *oldpath;
const char *newpath;
} vfsi_rename_op;
typedef struct vfsi_copy_op {
const char *src;
uint64_t src_offset;
const char *dst;
uint64_t dst_offset;
uint64_t length;
bool to_eof;
} vfsi_copy_op;
typedef bool (*vfsi_read_stream_cb)(const char *path,
size_t index,
uint64_t offset,
const uint8_t *data,
size_t len,
bool eof,
void *userdata);
typedef bool (*vfsi_listdir_cb)(const char *name, const struct vfsi_attrs *attrs, void *userdata);
typedef bool (*vfsi_listdirv_cb)(const char *dir,
const char *name,
const struct vfsi_attrs *attrs,
void *userdata);
typedef bool (*vfsi_read_paths_cb)(const char *path, const uint8_t *data, size_t len, void *userdata);
#ifdef __cplusplus
extern "C" {
#endif
uint32_t vfsi_abi_version(void);
uint32_t vfsi_nfs_minorversion(const struct vfsi_fs *fs);
uint16_t vfsi_smb_dialect(const struct vfsi_fs *fs);
uint64_t vfsi_capabilities(const struct vfsi_fs *fs);
int vfsi_dummy_open(const char *root, struct vfsi_fs **out);
int vfsi_dummy_open_mount(const char *root, const char *mountpoint, struct vfsi_fs **out);
int vfsi_nfs_open(const char *host, struct vfsi_fs **out);
int vfsi_nfs_open_minor(const char *host, uint32_t minorversion, struct vfsi_fs **out);
int vfsi_nfs_open_mount(const char *host, const char *mountpoint, struct vfsi_fs **out);
int vfsi_nfs_open_mount_export(const char *host,
const char *export_root,
const char *mountpoint,
struct vfsi_fs **out);
int vfsi_smb_open(const char *server,
const char *share,
const char *username,
const char *password,
const char *domain,
struct vfsi_fs **out);
int vfsi_smb_open_mount(const char *server,
const char *share,
const char *username,
const char *password,
const char *domain,
const char *share_root,
const char *mountpoint,
struct vfsi_fs **out);
void vfsi_free(struct vfsi_fs *fs);
int vfsi_stat(struct vfsi_fs *fs, const char *path, struct vfsi_attrs *out);
int vfsi_open(struct vfsi_fs *fs, const char *path, int flags, uint32_t mode);
int vfsi_close(struct vfsi_fs *fs, int fd);
int vfsi_pread(struct vfsi_fs *fs, int fd, void *buf, size_t len, uint64_t offset, size_t *got);
int vfsi_pwrite(struct vfsi_fs *fs,
int fd,
const void *buf,
size_t len,
uint64_t offset,
size_t *wrote);
int vfsi_mkdir(struct vfsi_fs *fs, const char *path, uint32_t mode, int create_parents);
int vfsi_remove(struct vfsi_fs *fs, const char *path);
int vfsi_rename(struct vfsi_fs *fs, const char *oldpath, const char *newpath);
int vfsi_copy(struct vfsi_fs *fs,
const char *src,
uint64_t src_offset,
const char *dst,
uint64_t dst_offset,
uint64_t length,
bool to_eof);
struct vfsi_result vfsi_openv(struct vfsi_fs *fs,
struct vfsi_open_op *ops,
size_t count,
struct vfsi_result *item_results);
struct vfsi_result vfsi_closev(struct vfsi_fs *fs,
const int *fds,
size_t count,
struct vfsi_result *item_results);
struct vfsi_result vfsi_statv(struct vfsi_fs *fs,
struct vfsi_stat_op *ops,
size_t count,
struct vfsi_result *item_results);
struct vfsi_result vfsi_setattrv(struct vfsi_fs *fs,
const struct vfsi_setattr_op *ops,
size_t count,
struct vfsi_result *item_results);
struct vfsi_result vfsi_preadv(struct vfsi_fs *fs,
struct vfsi_pread_op *ops,
size_t count,
struct vfsi_result *item_results);
struct vfsi_result vfsi_pwritev(struct vfsi_fs *fs,
struct vfsi_pwrite_op *ops,
size_t count,
struct vfsi_result *item_results);
struct vfsi_result vfsi_mkdirv(struct vfsi_fs *fs,
const struct vfsi_mkdir_op *ops,
size_t count,
struct vfsi_result *item_results);
struct vfsi_result vfsi_removev(struct vfsi_fs *fs,
const char *const *paths,
size_t count,
struct vfsi_result *item_results);
struct vfsi_result vfsi_renamev(struct vfsi_fs *fs,
const struct vfsi_rename_op *ops,
size_t count,
struct vfsi_result *item_results);
struct vfsi_result vfsi_copyv(struct vfsi_fs *fs,
const struct vfsi_copy_op *ops,
size_t count,
struct vfsi_result *item_results);
struct vfsi_result vfsi_read_streamv(struct vfsi_fs *fs,
const char *const *paths,
size_t count,
size_t chunk_size,
size_t memory_limit,
vfsi_read_stream_cb cb,
void *userdata);
int vfsi_listdir(struct vfsi_fs *fs, const char *dir, vfsi_listdir_cb cb, void *userdata);
int vfsi_listdirv(struct vfsi_fs *fs,
const char *const *dirs,
size_t count,
size_t max_entries,
bool recursive,
vfsi_listdirv_cb cb,
void *userdata);
int vfsi_read_paths(struct vfsi_fs *fs,
const char *const *paths,
size_t count,
vfsi_read_paths_cb cb,
void *userdata);
#ifdef __cplusplus
} #endif
#endif