Add FUSE implementation and dependencies

Imported from the genode repository.

Fixes #129.

Issue genodelabs/genode#3104.
This commit is contained in:
Josef Söntgen
2019-01-04 13:28:10 +01:00
committed by Norman Feske
parent 4ab0ad26ca
commit fd713e737d
67 changed files with 4303 additions and 0 deletions

161
include/fuse/fuse.h Normal file
View File

@@ -0,0 +1,161 @@
/*
* \brief libfuse re-implementation public API
* \author Josef Soentgen
* \date 2013-11-07
*/
/*
* Copyright (C) 2013-2017 Genode Labs GmbH
*
* This file is part of the Genode OS framework, which is distributed
* under the terms of the GNU Affero General Public License version 3.
*/
#ifndef _INCLUDE__FUSE_H_
#define _INCLUDE__FUSE_H_
/* libc includes */
#include <sys/stat.h>
#include <sys/statvfs.h>
#include <sys/types.h>
#include <fcntl.h>
#include <utime.h>
#ifdef __cplusplus
extern "C" {
#endif
#ifndef FUSE_USE_VERSION
#define FUSE_USE_VERSION 26
#endif
#if FUSE_USE_VERSION >= 26
#define FUSE_VERSION 26
#else
#error "No support for FUSE_VERSION < 26"
#endif
void fuse_genode(const char*);
#include "fuse_opt.h"
struct fuse_chan;
struct fuse_args;
struct fuse_session;
struct fuse_file_info {
int32_t flags; /* open(2) flags */
uint32_t fh_old; /* old file handle */
int32_t writepage;
uint32_t direct_io:1;
uint32_t keep_cache:1;
uint32_t flush:1;
uint32_t nonseekable:1;
uint32_t __padd:27;
uint32_t flock_release : 1;
uint64_t fh; /* file handle */
uint64_t lock_owner;
};
struct fuse_conn_info {
uint32_t proto_major;
uint32_t proto_minor;
uint32_t async_read;
uint32_t max_write;
uint32_t max_readahead;
uint32_t capable;
uint32_t want;
uint32_t max_background;
uint32_t congestion_threshold;
uint32_t reserved[23];
};
struct fuse_context {
struct fuse *fuse;
uid_t uid;
gid_t gid;
pid_t pid;
void *private_data;
mode_t umask;
};
typedef ino_t fuse_ino_t;
typedef int (*fuse_fill_dir_t)(void *, const char *, const struct stat *, off_t);
typedef int (*fuse_dirfil_t)(void *, const char *, int, ino_t);
/* only operations available in 2.6 */
struct fuse_operations {
int (*getattr)(const char *, struct stat *);
int (*readlink)(const char *, char *, size_t);
int (*getdir)(const char *, void *, fuse_dirfil_t);
int (*mknod)(const char *, mode_t, dev_t);
int (*mkdir)(const char *, mode_t);
int (*unlink)(const char *);
int (*rmdir)(const char *);
int (*symlink)(const char *, const char *);
int (*rename)(const char *, const char *);
int (*link)(const char *, const char *);
int (*chmod)(const char *, mode_t);
int (*chown)(const char *, uid_t, gid_t);
int (*truncate)(const char *, off_t);
int (*utime)(const char *, struct utimbuf *);
int (*open)(const char *, struct fuse_file_info *);
int (*read)(const char *, char *, size_t, off_t,
struct fuse_file_info *);
int (*write)(const char *, const char *, size_t, off_t,
struct fuse_file_info *);
int (*statfs)(const char *, struct statvfs *);
int (*flush)(const char *, struct fuse_file_info *);
int (*release)(const char *, struct fuse_file_info *);
int (*fsync)(const char *, int, struct fuse_file_info *);
int (*setxattr)(const char *, const char *, const char *, size_t,
int);
int (*getxattr)(const char *, const char *, char *, size_t);
int (*listxattr)(const char *, char *, size_t);
int (*removexattr)(const char *, const char *);
int (*opendir)(const char *, struct fuse_file_info *);
int (*readdir)(const char *, void *, fuse_fill_dir_t, off_t,
struct fuse_file_info *);
int (*releasedir)(const char *, struct fuse_file_info *);
int (*fsyncdir)(const char *, int, struct fuse_file_info *);
void *(*init)(struct fuse_conn_info *);
void (*destroy)(void *);
int (*access)(const char *, int);
int (*create)(const char *, mode_t, struct fuse_file_info *);
int (*ftruncate)(const char *, off_t, struct fuse_file_info *);
int (*fgetattr)(const char *, struct stat *, struct fuse_file_info *);
int (*lock)(const char *, struct fuse_file_info *, int, struct flock *);
int (*utimens)(const char *, const struct timespec *);
int (*bmap)(const char *, size_t , uint64_t *);
};
/* API */
int fuse_version(void);
struct fuse *fuse_new(struct fuse_chan *, struct fuse_args *,
const struct fuse_operations *, size_t, void *);
void fuse_destroy(struct fuse *);
void fuse_exit(struct fuse *f);
struct fuse_session *fuse_get_session(struct fuse *);
struct fuse_context *fuse_get_context(void);
int fuse_loop(struct fuse *);
int fuse_loop_mt(struct fuse *);
int fuse_main(int, char **, const struct fuse_operations *, void *);
struct fuse_chan *fuse_mount(const char *, struct fuse_args *);
int fuse_parse_cmdline(struct fuse_args *, char **, int *, int *);
void fuse_remove_signal_handlers(struct fuse_session *);
int fuse_set_signal_handlers(struct fuse_session *);
int fuse_chan_fd(struct fuse_chan *);
int fuse_daemonize(int);
int fuse_is_lib_option(const char *);
void fuse_teardown(struct fuse *, char *);
void fuse_unmount(const char *, struct fuse_chan *);
#ifdef __cplusplus
}
#endif
#endif /* _INCLUDE__FUSE_H_ */

56
include/fuse/fuse_opt.h Normal file
View File

@@ -0,0 +1,56 @@
/*
* \brief libfuse public API
* \author Josef Soentgen
* \date 2013-11-07
*/
/*
* Copyright (C) 2013-2017 Genode Labs GmbH
*
* This file is part of the Genode OS framework, which is distributed
* under the terms of the GNU Affero General Public License version 3.
*/
#ifndef _FUSE_OPT_H_
#define _FUSE_OPT_H_
#ifdef __cplusplus
extern "C" {
#endif
struct fuse_opt {
const char *templ;
unsigned long off;
int val;
};
struct fuse_args {
int argc;
char **argv;
int allocated;
};
typedef int (*fuse_opt_proc_t)(void *, const char *, int, struct fuse_args *);
int fuse_opt_add_arg(struct fuse_args *, const char *);
int fuse_opt_insert_arg(struct fuse_args *, int, const char *);
void fuse_opt_free_args(struct fuse_args *);
int fuse_opt_add_opt(char **, const char *);
int fuse_opt_add_opt_escaped(char **, const char *);
int fuse_opt_match(const struct fuse_opt *, const char *);
int fuse_opt_parse(struct fuse_args *, void *, struct fuse_opt *,
fuse_opt_proc_t);
#define FUSE_ARGS_INIT(ac, av) { ac, av, 0 }
#define FUSE_OPT_KEY(t, k) { t, -1, k }
#define FUSE_OPT_END { NULL, 0, 0 }
#define FUSE_OPT_KEY_OPT -1
#define FUSE_OPT_KEY_NONOPT -2
#define FUSE_OPT_KEY_KEEP -3
#define FUSE_OPT_KEY_DISCARD -4
#ifdef __cplusplus
}
#endif
#endif /* _FUSE_OPT_H_ */

154
include/fuse/fuse_private.h Normal file
View File

@@ -0,0 +1,154 @@
/*
* \brief libfuse private API
* \author Josef Soentgen
* \date 2013-11-07
* */
/*
* Copyright (C) 2013-2017 Genode Labs GmbH
*
* This file is part of the Genode OS framework, which is distributed
* under the terms of the GNU Affero General Public License version 3.
*/
#ifndef _INCLUDE__FUSE_PRIVATE_H_
#define _INCLUDE__FUSE_PRIVATE_H_
#include "fuse.h"
#ifdef __cplusplus
extern "C" {
#endif
struct fuse_dirhandle;
struct fuse_args;
struct fuse_session {
void *args;
};
struct fuse_chan {
char *dir;
struct fuse_args *args;
};
struct fuse_config {
uid_t uid;
gid_t gid;
pid_t pid;
mode_t umask;
int set_mode;
int set_uid;
int set_gid;
};
typedef struct fuse_dirhandle {
fuse_fill_dir_t filler;
void *buf;
size_t size;
off_t offset;
} *fuse_dirh_t;
struct fuse {
struct fuse_chan *fc;
struct fuse_operations op;
struct fuse_args *args;
struct fuse_config conf;
struct fuse_session se;
fuse_fill_dir_t filler;
void *userdata;
/* Block_session info */
uint32_t block_size;
uint64_t block_count;
};
#ifdef __cplusplus
}
#endif
namespace Fuse {
struct fuse* fuse();
bool initialized();
/**
* Initialize the file system
*
* Mount the medium containg the file system, e.g. by
* using a Block_session connection, and call the file system
* init function as well as initialize needed fuse structures.
*/
bool init_fs();
/**
* Deinitialize the file system
*
* Unmount the medium, call the file system cleanup function
* and free all fuse structures.
*/
void deinit_fs();
/**
* Synchronize the file system
*
* Request the file system to flush all internal caches
* to disk.
*/
void sync_fs();
/**
* FUSE File system implementation supports symlinks
*/
bool support_symlinks();
/* list of FUSE operations as of version 2.6 */
enum Fuse_operations {
FUSE_OP_GETATTR = 0,
FUSE_OP_READLINK = 1,
FUSE_OP_GETDIR = 2,
FUSE_OP_MKNOD = 3,
FUSE_OP_MKDIR = 4,
FUSE_OP_UNLINK = 5,
FUSE_OP_RMDIR = 6,
FUSE_OP_SYMLINK = 7,
FUSE_OP_RENAME = 8,
FUSE_OP_LINK = 9,
FUSE_OP_CHMOD = 10,
FUSE_OP_CHOWN = 11,
FUSE_OP_TRUNCATE = 12,
FUSE_OP_UTIME = 13,
FUSE_OP_OPEN = 14,
FUSE_OP_READ = 15,
FUSE_OP_WRITE = 16,
FUSE_OP_STATFS = 17,
FUSE_OP_FLUSH = 18,
FUSE_OP_RELEASE = 19,
FUSE_OP_FSYNC = 20,
FUSE_OP_SETXATTR = 21,
FUSE_OP_GETXATTR = 22,
FUSE_OP_LISTXATTR = 23,
FUSE_OP_REMOVEXATTR = 24,
FUSE_OP_OPENDIR = 25,
FUSE_OP_READDIR = 26,
FUSE_OP_RELEASEDIR = 27,
FUSE_OP_FSYNCDIR = 28,
FUSE_OP_INIT = 29,
FUSE_OP_DESTROY = 30,
FUSE_OP_ACCESS = 31,
FUSE_OP_CREATE = 32,
FUSE_OP_FTRUNCATE = 33,
FUSE_OP_FGETATTR = 34,
FUSE_OP_LOCK = 35,
FUSE_OP_UTIMENS = 36,
FUSE_OP_BMAP = 37,
FUSE_OP_MAX = 38,
};
}
#endif /* _INCLUDE__FUSE_PRIVATE_ */