fuse
Data Structures | Macros | Typedefs | Functions
fuse.h File Reference
#include "fuse_common.h"
#include <fcntl.h>
#include <time.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/statvfs.h>
#include <sys/uio.h>

Data Structures

struct  fuse_operations
struct  fuse_context
struct  fuse_module

Macros

#define fuse_main(argc, argv, op, user_data)   fuse_main_real(argc, argv, op, sizeof(*(op)), user_data)
#define FUSE_REGISTER_MODULE(name_, factory_)

Typedefs

typedef int(* fuse_fill_dir_t )(void *buf, const char *name, const struct stat *stbuf, off_t off)

Functions

struct fuse * fuse_new (struct fuse_chan *ch, struct fuse_args *args, const struct fuse_operations *op, size_t op_size, void *user_data)
void fuse_destroy (struct fuse *f)
int fuse_loop (struct fuse *f)
void fuse_exit (struct fuse *f)
int fuse_loop_mt (struct fuse *f)
struct fuse_contextfuse_get_context (void)
int fuse_getgroups (int size, gid_t list[])
int fuse_interrupted (void)
int fuse_main_real (int argc, char *argv[], const struct fuse_operations *op, size_t op_size, void *user_data)
int fuse_start_cleanup_thread (struct fuse *fuse)
void fuse_stop_cleanup_thread (struct fuse *fuse)
int fuse_clean_cache (struct fuse *fuse)
struct fuse_fs * fuse_fs_new (const struct fuse_operations *op, size_t op_size, void *user_data)
void fuse_register_module (struct fuse_module *mod)
struct fuse_session * fuse_get_session (struct fuse *f)

Detailed Description

This file defines the library interface of FUSE

IMPORTANT: you should define FUSE_USE_VERSION before including this header.

Macro Definition Documentation

#define fuse_main (   argc,
  argv,
  op,
  user_data 
)    fuse_main_real(argc, argv, op, sizeof(*(op)), user_data)

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:

  • parses command line options (-d -s and -h)
  • passes relevant mount options to the fuse_mount()
  • installs signal handlers for INT, HUP, TERM and PIPE
  • registers an exit handler to unmount the filesystem on program exit
  • creates a fuse handle
  • registers the operations
  • calls either the single-threaded or the multi-threaded event loop

Note: this is currently implemented as a macro.

Parameters
argcthe argument counter passed to the main() function
argvthe argument vector passed to the main() function
opthe file system operation
user_datauser data supplied in the context during the init() method
Returns
0 on success, nonzero on failure

Example usage, see hello.c

#define FUSE_REGISTER_MODULE (   name_,
  factory_ 
)
Value:
static __attribute__((constructor)) void name_ ## _register(void) \
{ \
static struct fuse_module mod = \
{ #name_, factory_, NULL, NULL, 0 }; \
fuse_register_module(&mod); \
}

Register filesystem module

For the parameters, see description of the fields in 'struct fuse_module'

Typedef Documentation

typedef int(* fuse_fill_dir_t)(void *buf, const char *name, const struct stat *stbuf, off_t off)

Function to add an entry in a readdir() operation

Parameters
bufthe buffer passed to the readdir() operation
namethe file name of the directory entry
statfile attributes, can be NULL
offoffset of the next entry or zero
Returns
1 if buffer is full, zero otherwise

Function Documentation

int fuse_clean_cache ( struct fuse *  fuse)

Iterate over cache removing stale entries use in conjunction with "-oremember"

NOTE: This is already done for the standard sessions

Parameters
fusestruct fuse pointer for fuse instance
Returns
the number of seconds until the next cleanup
void fuse_destroy ( struct fuse *  f)

Destroy the FUSE handle.

The communication channel attached to the handle is also destroyed.

NOTE: This function does not unmount the filesystem. If this is needed, call fuse_unmount() before calling this function.

Parameters
fthe FUSE handle
void fuse_exit ( struct fuse *  f)

Exit from event loop

Parameters
fthe FUSE handle
struct fuse_fs* fuse_fs_new ( const struct fuse_operations op,
size_t  op_size,
void *  user_data 
)
read

Create a new fuse filesystem object

This is usually called from the factory of a fuse module to create a new instance of a filesystem.

Parameters
opthe filesystem operations
op_sizethe size of the fuse_operations structure
user_datauser data supplied in the context during the init() method
Returns
a new filesystem object
struct fuse_context* fuse_get_context ( void  )
read

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.

Returns
the context
struct fuse_session* fuse_get_session ( struct fuse *  f)
read

Get session from fuse object

int fuse_getgroups ( int  size,
gid_t  list[] 
)

Get the current supplementary group IDs for the current request

Similar to the getgroups(2) system call, except the return value is always the total number of group IDs, even if it is larger than the specified size.

The current fuse kernel module in linux (as of 2.6.30) doesn't pass the group list to userspace, hence this function needs to parse "/proc/$TID/task/$TID/status" to get the group IDs.

This feature may not be supported on all operating systems. In such a case this function will return -ENOSYS.

Parameters
sizesize of given array
listarray of group IDs to be filled in
Returns
the total number of supplementary group IDs or -errno on failure
int fuse_interrupted ( void  )

Check if the current request has already been interrupted

Returns
1 if the request has been interrupted, 0 otherwise
int fuse_loop ( struct fuse *  f)

FUSE event loop.

Requests from the kernel are processed, and the appropriate operations are called.

Parameters
fthe FUSE handle
Returns
0 if no error occurred, -1 otherwise

See also: fuse_loop()

int fuse_loop_mt ( struct fuse *  f)

FUSE event loop with multiple threads

Requests from the kernel are processed, and the appropriate 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.

Note: using fuse_loop() instead of fuse_loop_mt() means you are running in single-threaded mode, and that you will not have to worry about reentrancy, though you will have to worry about recursive lookups. In single-threaded mode, FUSE holds a global lock on your filesystem, and will wait for one callback to return before calling another. This can lead to deadlocks, if your script makes any attempt to access files or directories in the filesystem it is providing. (This includes calling stat() on the mount-point, statfs() calls from the 'df' command, and so on and so forth.) It is worth paying a little attention and being careful about this.

Enabling multiple threads, by using fuse_loop_mt(), will cause FUSE to make multiple simultaneous calls into the various callback functions given by your fuse_operations record.

If you are using multiple threads, you can enjoy all the parallel execution and interactive response benefits of threads, and you get to enjoy all the benefits of race conditions and locking bugs, too. Ensure that any code used in the callback funtion of fuse_operations is also thread-safe.

Parameters
fthe FUSE handle
Returns
0 if no error occurred, -1 otherwise

See also: fuse_loop()

int fuse_main_real ( int  argc,
char *  argv[],
const struct fuse_operations op,
size_t  op_size,
void *  user_data 
)

The real main function

Do not call this directly, use fuse_main()

struct fuse* fuse_new ( struct fuse_chan *  ch,
struct fuse_args args,
const struct fuse_operations op,
size_t  op_size,
void *  user_data 
)
read

Create a new FUSE filesystem.

Parameters
chthe communication channel
argsargument vector
opthe filesystem operations
op_sizethe size of the fuse_operations structure
user_datauser data supplied in the context during the init() method
Returns
the created FUSE handle
void fuse_register_module ( struct fuse_module mod)

Register a filesystem module

This function is used by FUSE_REGISTER_MODULE and there's usually no need to call it directly

int fuse_start_cleanup_thread ( struct fuse *  fuse)

Start the cleanup thread when using option "remember".

This is done automatically by fuse_loop_mt()

Parameters
fusestruct fuse pointer for fuse instance
Returns
0 on success and -1 on error
void fuse_stop_cleanup_thread ( struct fuse *  fuse)

Stop the cleanup thread when using option "remember".

This is done automatically by fuse_loop_mt()

Parameters
fusestruct fuse pointer for fuse instance