2001-10-29 03:44:14 +08:00
|
|
|
/*
|
|
|
|
FUSE: Filesystem in Userspace
|
|
|
|
Copyright (C) 2001 Miklos Szeredi (mszeredi@inf.bme.hu)
|
|
|
|
|
2002-10-25 20:41:16 +08:00
|
|
|
This program can be distributed under the terms of the GNU LGPL.
|
|
|
|
See the file COPYING.LIB.
|
2001-10-29 03:44:14 +08:00
|
|
|
*/
|
|
|
|
|
2001-12-09 04:29:20 +08:00
|
|
|
#ifndef _FUSE_H_
|
|
|
|
#define _FUSE_H_
|
|
|
|
|
2001-10-29 03:44:14 +08:00
|
|
|
/* This file defines the library interface of FUSE */
|
|
|
|
|
2002-12-04 02:45:21 +08:00
|
|
|
/* Now and forever: this interface uses 64 bit off_t */
|
|
|
|
#define _FILE_OFFSET_BITS 64
|
|
|
|
|
2001-10-29 03:44:14 +08:00
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
2001-10-31 22:52:35 +08:00
|
|
|
#include <utime.h>
|
2001-10-29 03:44:14 +08:00
|
|
|
|
2001-11-21 18:03:39 +08:00
|
|
|
/* ----------------------------------------------------------- *
|
|
|
|
* Basic FUSE API *
|
|
|
|
* ----------------------------------------------------------- */
|
|
|
|
|
2001-11-06 23:07:17 +08:00
|
|
|
/** Handle for a FUSE filesystem */
|
2001-10-29 03:44:14 +08:00
|
|
|
struct fuse;
|
2001-11-06 23:07:17 +08:00
|
|
|
|
2002-10-07 18:24:26 +08:00
|
|
|
/* Statfs structure used by FUSE */
|
|
|
|
struct fuse_statfs {
|
|
|
|
long block_size;
|
|
|
|
long blocks;
|
|
|
|
long blocks_free;
|
|
|
|
long files;
|
|
|
|
long files_free;
|
|
|
|
long namelen;
|
|
|
|
};
|
|
|
|
|
2001-11-06 23:07:17 +08:00
|
|
|
/** Handle for a getdir() operation */
|
2001-11-06 20:03:23 +08:00
|
|
|
typedef struct fuse_dirhandle *fuse_dirh_t;
|
2001-10-29 03:44:14 +08:00
|
|
|
|
2001-11-06 23:07:17 +08:00
|
|
|
/** Function to add an entry in a getdir() operation */
|
2001-11-06 20:03:23 +08:00
|
|
|
typedef int (*fuse_dirfil_t) (fuse_dirh_t, const char *, int type);
|
|
|
|
|
2001-11-06 23:07:17 +08:00
|
|
|
/**
|
|
|
|
* The file system operations:
|
|
|
|
*
|
|
|
|
* Most of these should work very similarly to the well known UNIX
|
|
|
|
* file system operations. Exceptions are:
|
|
|
|
*
|
|
|
|
* - All operations should return the negated error value (-errno) on
|
|
|
|
* error.
|
|
|
|
*
|
2001-11-14 00:11:35 +08:00
|
|
|
* - Getattr() doesn't need to fill in the following fields:
|
|
|
|
* st_ino
|
|
|
|
* st_dev
|
|
|
|
* st_blksize
|
|
|
|
*
|
2001-11-12 02:20:17 +08:00
|
|
|
* - readlink() should fill the buffer with a null terminated string. The
|
|
|
|
* buffer size argument includes the space for the terminating null
|
|
|
|
* character. If the linkname is too long to fit in the buffer, it should
|
|
|
|
* be truncated. The return value should be 0 for success.
|
2001-11-06 23:07:17 +08:00
|
|
|
*
|
|
|
|
* - getdir() is the opendir(), readdir(), ..., closedir() sequence
|
|
|
|
* in one call. For each directory entry the filldir parameter should
|
|
|
|
* be called.
|
|
|
|
*
|
|
|
|
* - There is no create() operation, mknod() will be called for
|
|
|
|
* creation of all non directory, non symlink nodes.
|
|
|
|
*
|
|
|
|
* - open() should not return a filehandle, but 0 on success. No
|
|
|
|
* creation, or trunctation flags (O_CREAT, O_EXCL, O_TRUNC) will be
|
|
|
|
* passed to open(). Open should only check if the operation is
|
|
|
|
* permitted for the given flags.
|
|
|
|
*
|
|
|
|
* - read(), write() are not passed a filehandle, but rather a
|
|
|
|
* pathname. The offset of the read and write is passed as the last
|
2001-11-12 02:20:17 +08:00
|
|
|
* argument, like the pread() and pwrite() system calls.
|
2002-12-10 20:26:00 +08:00
|
|
|
*
|
|
|
|
* - release() is called when an open file has:
|
|
|
|
* 1) all file descriptors closed
|
|
|
|
* 2) all memory mappings unmapped
|
|
|
|
* This call need only be implemented if this information is required,
|
|
|
|
* otherwise set this function to NULL.
|
|
|
|
*
|
2001-11-12 02:20:17 +08:00
|
|
|
*/
|
2001-10-29 03:44:14 +08:00
|
|
|
struct fuse_operations {
|
2001-11-12 02:20:17 +08:00
|
|
|
int (*getattr) (const char *, struct stat *);
|
|
|
|
int (*readlink) (const char *, char *, size_t);
|
|
|
|
int (*getdir) (const char *, fuse_dirh_t, 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 *, int);
|
|
|
|
int (*read) (const char *, char *, size_t, off_t);
|
|
|
|
int (*write) (const char *, const char *, size_t, off_t);
|
2002-03-17 14:58:33 +08:00
|
|
|
int (*statfs) (struct fuse_statfs *);
|
2002-12-11 17:50:26 +08:00
|
|
|
int (*release) (const char *, int);
|
2001-10-29 03:44:14 +08:00
|
|
|
};
|
|
|
|
|
2001-12-20 20:17:25 +08:00
|
|
|
/** Extra context that may be needed by some filesystems */
|
|
|
|
struct fuse_context {
|
|
|
|
uid_t uid;
|
|
|
|
gid_t gid;
|
|
|
|
};
|
|
|
|
|
2001-11-06 23:07:17 +08:00
|
|
|
/* FUSE flags: */
|
2001-11-07 20:35:06 +08:00
|
|
|
|
|
|
|
/** Enable debuging output */
|
|
|
|
#define FUSE_DEBUG (1 << 1)
|
|
|
|
|
2001-12-09 04:29:20 +08:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
2001-11-21 18:03:39 +08:00
|
|
|
|
2002-04-19 23:57:02 +08:00
|
|
|
/*
|
|
|
|
* Create a FUSE mountpoint
|
|
|
|
*
|
|
|
|
* Returns a control file descriptor suitable for passing to
|
|
|
|
* fuse_new()
|
|
|
|
*
|
|
|
|
* @param mountpoint the mount point path
|
2002-10-25 19:40:14 +08:00
|
|
|
* @param args array of arguments to be passed to fusermount (NULL
|
|
|
|
* terminated). Can be NULL if no arguments are needed.
|
2002-04-19 23:57:02 +08:00
|
|
|
* @return the control file descriptor on success, -1 on failure
|
|
|
|
*/
|
2002-10-25 19:40:14 +08:00
|
|
|
int fuse_mount(const char *mountpoint, const char *args[]);
|
2002-04-19 23:57:02 +08:00
|
|
|
|
2002-12-05 22:23:01 +08:00
|
|
|
/*
|
|
|
|
* Umount a FUSE mountpoint
|
|
|
|
*
|
|
|
|
* @param mountpoint the mount point path
|
|
|
|
*/
|
|
|
|
void fuse_unmount(const char *mountpoint);
|
|
|
|
|
2001-11-06 23:07:17 +08:00
|
|
|
/**
|
2001-11-09 22:49:18 +08:00
|
|
|
* Create a new FUSE filesystem.
|
2001-11-06 23:07:17 +08:00
|
|
|
*
|
2001-11-09 22:49:18 +08:00
|
|
|
* @param fd the control file descriptor
|
2001-11-06 23:07:17 +08:00
|
|
|
* @param flags any combination of the FUSE flags defined above, or 0
|
|
|
|
* @param op the operations
|
2001-12-20 20:17:25 +08:00
|
|
|
* @return the created FUSE handle
|
2001-11-06 23:07:17 +08:00
|
|
|
*/
|
2001-12-20 20:17:25 +08:00
|
|
|
struct fuse *fuse_new(int fd, int flags, const struct fuse_operations *op);
|
2001-10-29 03:44:14 +08:00
|
|
|
|
2002-12-05 22:23:01 +08:00
|
|
|
/**
|
|
|
|
* Destroy the FUSE handle.
|
|
|
|
*
|
|
|
|
* The filesystem is not unmounted.
|
|
|
|
*
|
|
|
|
* @param f the FUSE handle
|
|
|
|
*/
|
|
|
|
void fuse_destroy(struct fuse *f);
|
|
|
|
|
2001-11-06 23:07:17 +08:00
|
|
|
/**
|
|
|
|
* FUSE event loop.
|
|
|
|
*
|
|
|
|
* Requests from the kernel are processed, and the apropriate
|
|
|
|
* operations are called.
|
|
|
|
*
|
|
|
|
* @param f the FUSE handle
|
|
|
|
*/
|
2001-10-29 03:44:14 +08:00
|
|
|
void fuse_loop(struct fuse *f);
|
|
|
|
|
2002-12-05 22:23:01 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Exit from event loop
|
|
|
|
*
|
|
|
|
* @param f the FUSE handle
|
|
|
|
*/
|
|
|
|
void fuse_exit(struct fuse *f);
|
|
|
|
|
2001-11-16 18:12:59 +08:00
|
|
|
/**
|
|
|
|
* FUSE event loop with multiple threads
|
|
|
|
*
|
|
|
|
* Requests from the kernel are processed, and the apropriate
|
|
|
|
* operations are called. Request are processed in parallel by
|
|
|
|
* distributing them between multiple threads.
|
|
|
|
*
|
|
|
|
* Calling this function requires the pthreads library to be linked to
|
|
|
|
* the application.
|
|
|
|
*
|
|
|
|
* @param f the FUSE handle
|
|
|
|
*/
|
|
|
|
void fuse_loop_mt(struct fuse *f);
|
|
|
|
|
2001-12-20 20:17:25 +08:00
|
|
|
/**
|
|
|
|
* Get the current context
|
|
|
|
*
|
|
|
|
* The context is only valid for the duration of a filesystem
|
|
|
|
* operation, and thus must not be stored and used later.
|
|
|
|
*
|
|
|
|
* @param f the FUSE handle
|
|
|
|
* @return the context
|
|
|
|
*/
|
|
|
|
struct fuse_context *fuse_get_context(struct fuse *f);
|
|
|
|
|
2001-11-21 18:03:39 +08:00
|
|
|
/* ----------------------------------------------------------- *
|
|
|
|
* Miscellaneous helper fuctions *
|
|
|
|
* ----------------------------------------------------------- */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Main function of FUSE.
|
|
|
|
*
|
|
|
|
* This is for the lazy. This is all that has to be called from the
|
|
|
|
* main() function.
|
|
|
|
*
|
|
|
|
* This function does the following:
|
|
|
|
* - mounts the filesystem
|
|
|
|
* - installs signal handlers for INT, HUP, TERM and PIPE
|
|
|
|
* - registers an exit handler to unmount the filesystem on program exit
|
|
|
|
* - parses command line options (-d -s and -h)
|
|
|
|
* - creates a fuse handle
|
|
|
|
* - registers the operations
|
|
|
|
* - calls either the single-threaded or the multi-threaded event loop
|
|
|
|
*
|
|
|
|
* @param argc the argument counter passed to the main() function
|
|
|
|
* @param argv the argument vector passed to the main() function
|
2002-05-29 15:06:09 +08:00
|
|
|
* @param op the file system operation
|
2001-11-21 18:03:39 +08:00
|
|
|
*/
|
|
|
|
void fuse_main(int argc, char *argv[], const struct fuse_operations *op);
|
2001-11-16 18:12:59 +08:00
|
|
|
|
2001-11-16 21:31:14 +08:00
|
|
|
/* ----------------------------------------------------------- *
|
|
|
|
* Advanced API for event handling, don't worry about this... *
|
|
|
|
* ----------------------------------------------------------- */
|
2001-11-16 18:12:59 +08:00
|
|
|
|
|
|
|
struct fuse_cmd;
|
2001-11-17 01:46:45 +08:00
|
|
|
typedef void (*fuse_processor_t)(struct fuse *, struct fuse_cmd *, void *);
|
2001-11-16 18:12:59 +08:00
|
|
|
struct fuse_cmd *__fuse_read_cmd(struct fuse *f);
|
|
|
|
void __fuse_process_cmd(struct fuse *f, struct fuse_cmd *cmd);
|
2001-11-17 01:46:45 +08:00
|
|
|
void __fuse_loop_mt(struct fuse *f, fuse_processor_t proc, void *data);
|
|
|
|
|
2001-12-09 04:29:20 +08:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif /* _FUSE_H_ */
|