libfuse: example/printcap.c File Reference

libfuse

printcap.c File Reference
`#include <config.h>`
`#include <fuse_lowlevel.h>`
`#include <stdio.h>`
`#include <unistd.h>`
`#include <string.h>`
`#include <stdlib.h>`

Go to the source code of this file.

## Detailed Description

minimal example filesystem that prints out all capabilities supported by the kernel and then exits.

Compile with:

    gcc -Wall printcap.c `pkg-config fuse3 --cflags --libs` -o printcap

## Source code

/*
FUSE: Filesystem in Userspace
Copyright (C) 2017 Nikolaus Rath <Nikolaus@rath.org>
This program can be distributed under the terms of the GNU GPLv2.
See the file COPYING.
*/
#define FUSE_USE_VERSION 31
#include <config.h>
#include <fuse_lowlevel.h>
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <stdlib.h>
struct fuse_session *se;
static void pc_init(void *userdata,
struct fuse_conn_info *conn)
{
(void) userdata;
printf("Protocol version: %d.%d\n", conn->proto_major,
conn->proto_minor);
printf("Capabilities:\n");
if(conn->capable & FUSE_CAP_ASYNC_READ)
printf("\tFUSE_CAP_ASYNC_READ\n");
if(conn->capable & FUSE_CAP_POSIX_LOCKS)
printf("\tFUSE_CAP_POSIX_LOCKS\n");
if(conn->capable & FUSE_CAP_ATOMIC_O_TRUNC)
printf("\tFUSE_CAP_ATOMIC_O_TRUNC\n");
if(conn->capable & FUSE_CAP_EXPORT_SUPPORT)
printf("\tFUSE_CAP_EXPORT_SUPPORT\n");
if(conn->capable & FUSE_CAP_DONT_MASK)
printf("\tFUSE_CAP_DONT_MASK\n");
if(conn->capable & FUSE_CAP_SPLICE_MOVE)
printf("\tFUSE_CAP_SPLICE_MOVE\n");
if(conn->capable & FUSE_CAP_SPLICE_READ)
printf("\tFUSE_CAP_SPLICE_READ\n");
if(conn->capable & FUSE_CAP_SPLICE_WRITE)
printf("\tFUSE_CAP_SPLICE_WRITE\n");
if(conn->capable & FUSE_CAP_FLOCK_LOCKS)
printf("\tFUSE_CAP_FLOCK_LOCKS\n");
if(conn->capable & FUSE_CAP_IOCTL_DIR)
printf("\tFUSE_CAP_IOCTL_DIR\n");
if(conn->capable & FUSE_CAP_AUTO_INVAL_DATA)
printf("\tFUSE_CAP_AUTO_INVAL_DATA\n");
if(conn->capable & FUSE_CAP_READDIRPLUS)
printf("\tFUSE_CAP_READDIRPLUS\n");
if(conn->capable & FUSE_CAP_READDIRPLUS_AUTO)
printf("\tFUSE_CAP_READDIRPLUS_AUTO\n");
if(conn->capable & FUSE_CAP_ASYNC_DIO)
printf("\tFUSE_CAP_ASYNC_DIO\n");
if(conn->capable & FUSE_CAP_WRITEBACK_CACHE)
printf("\tFUSE_CAP_WRITEBACK_CACHE\n");
if(conn->capable & FUSE_CAP_NO_OPEN_SUPPORT)
printf("\tFUSE_CAP_NO_OPEN_SUPPORT\n");
if(conn->capable & FUSE_CAP_PARALLEL_DIROPS)
printf("\tFUSE_CAP_PARALLEL_DIROPS\n");
if(conn->capable & FUSE_CAP_POSIX_ACL)
printf("\tFUSE_CAP_POSIX_ACL\n");
if(conn->capable & FUSE_CAP_CACHE_SYMLINKS)
printf("\tFUSE_CAP_CACHE_SYMLINKS\n");
if(conn->capable & FUSE_CAP_NO_OPENDIR_SUPPORT)
printf("\tFUSE_CAP_NO_OPENDIR_SUPPORT\n");
if(conn->capable & FUSE_CAP_EXPLICIT_INVAL_DATA)
printf("\tFUSE_CAP_EXPLICIT_INVAL_DATA\n");
if(conn->capable & FUSE_CAP_EXPIRE_ONLY)
printf("\tFUSE_CAP_EXPIRE_ONLY\n");
fuse_session_exit(se);
}
static const struct fuse_lowlevel_ops pc_oper = {
.init = pc_init,
};
int main(int argc, char **argv)
{
struct fuse_args args = FUSE_ARGS_INIT(argc, argv);
char *mountpoint;
int ret = -1;
mountpoint = strdup("/tmp/fuse_printcap_XXXXXX");
if(mkdtemp(mountpoint) == NULL) {
perror("mkdtemp");
return 1;
}
printf("FUSE library version %s\n", fuse_pkgversion());
fuse_lowlevel_version();
se = fuse_session_new(&args, &pc_oper,
sizeof(pc_oper), NULL);
if (se == NULL)
goto err_out1;
if (fuse_set_signal_handlers(se) != 0)
goto err_out2;
if (fuse_session_mount(se, mountpoint) != 0)
goto err_out3;
ret = fuse_session_loop(se);
fuse_session_unmount(se);
err_out3:
fuse_remove_signal_handlers(se);
err_out2:
fuse_session_destroy(se);
err_out1:
rmdir(mountpoint);
free(mountpoint);
fuse_opt_free_args(&args);
return ret ? 1 : 0;
}
FUSE_CAP_IOCTL_DIR
#define FUSE_CAP_IOCTL_DIR
Definition: fuse_common.h:232
FUSE_CAP_DONT_MASK
#define FUSE_CAP_DONT_MASK
Definition: fuse_common.h:187
FUSE_CAP_AUTO_INVAL_DATA
#define FUSE_CAP_AUTO_INVAL_DATA
Definition: fuse_common.h:254
fuse_set_signal_handlers
int fuse_set_signal_handlers(struct fuse_session *se)
Definition: fuse_signals.c:62
FUSE_CAP_SPLICE_READ
#define FUSE_CAP_SPLICE_READ
Definition: fuse_common.h:212
FUSE_CAP_PARALLEL_DIROPS
#define FUSE_CAP_PARALLEL_DIROPS
Definition: fuse_common.h:333
FUSE_CAP_WRITEBACK_CACHE
#define FUSE_CAP_WRITEBACK_CACHE
Definition: fuse_common.h:310
FUSE_CAP_EXPIRE_ONLY
#define FUSE_CAP_EXPIRE_ONLY
Definition: fuse_common.h:425
FUSE_CAP_ATOMIC_O_TRUNC
#define FUSE_CAP_ATOMIC_O_TRUNC
Definition: fuse_common.h:172
FUSE_CAP_ASYNC_READ
#define FUSE_CAP_ASYNC_READ
Definition: fuse_common.h:155
FUSE_CAP_SPLICE_WRITE
#define FUSE_CAP_SPLICE_WRITE
Definition: fuse_common.h:195
FUSE_CAP_CACHE_SYMLINKS
#define FUSE_CAP_CACHE_SYMLINKS
Definition: fuse_common.h:374
FUSE_CAP_POSIX_ACL
#define FUSE_CAP_POSIX_ACL
Definition: fuse_common.h:352
FUSE_CAP_EXPORT_SUPPORT
#define FUSE_CAP_EXPORT_SUPPORT
Definition: fuse_common.h:179
FUSE_CAP_POSIX_LOCKS
#define FUSE_CAP_POSIX_LOCKS
Definition: fuse_common.h:163
FUSE_CAP_EXPLICIT_INVAL_DATA
#define FUSE_CAP_EXPLICIT_INVAL_DATA
Definition: fuse_common.h:409
FUSE_CAP_READDIRPLUS_AUTO
#define FUSE_CAP_READDIRPLUS_AUTO
Definition: fuse_common.h:290
FUSE_CAP_NO_OPENDIR_SUPPORT
#define FUSE_CAP_NO_OPENDIR_SUPPORT
Definition: fuse_common.h:386
FUSE_CAP_ASYNC_DIO
#define FUSE_CAP_ASYNC_DIO
Definition: fuse_common.h:301
fuse_pkgversion
const char * fuse_pkgversion(void)
Definition: fuse.c:5106
FUSE_CAP_NO_OPEN_SUPPORT
#define FUSE_CAP_NO_OPEN_SUPPORT
Definition: fuse_common.h:323
FUSE_CAP_READDIRPLUS
#define FUSE_CAP_READDIRPLUS
Definition: fuse_common.h:262
fuse_remove_signal_handlers
void fuse_remove_signal_handlers(struct fuse_session *se)
Definition: fuse_signals.c:79
FUSE_CAP_SPLICE_MOVE
#define FUSE_CAP_SPLICE_MOVE
Definition: fuse_common.h:203
FUSE_CAP_FLOCK_LOCKS
#define FUSE_CAP_FLOCK_LOCKS
Definition: fuse_common.h:225
fuse_lowlevel.h
fuse_session_destroy
void fuse_session_destroy(struct fuse_session *se)
Definition: fuse_lowlevel.c:2759
fuse_session_exit
void fuse_session_exit(struct fuse_session *se)
fuse_session_loop
int fuse_session_loop(struct fuse_session *se)
Definition: fuse_loop.c:19
fuse_session_unmount
void fuse_session_unmount(struct fuse_session *se)
Definition: fuse_lowlevel.c:3145
fuse_session_new
struct fuse_session * fuse_session_new(struct fuse_args *args, const struct fuse_lowlevel_ops *op, size_t op_size, void *userdata)
Definition: fuse_lowlevel.c:2960
fuse_session_mount
int fuse_session_mount(struct fuse_session *se, const char *mountpoint)
Definition: fuse_lowlevel.c:3090
fuse_lowlevel_version
void fuse_lowlevel_version(void)
Definition: fuse_lowlevel.c:2742
fuse_opt_free_args
void fuse_opt_free_args(struct fuse_args *args)
Definition: fuse_opt.c:34
FUSE_ARGS_INIT
#define FUSE_ARGS_INIT(argc, argv)
Definition: fuse_opt.h:123
fuse_args
Definition: fuse_opt.h:109
fuse_args::argc
int argc
Definition: fuse_opt.h:111
fuse_args::argv
char ** argv
Definition: fuse_opt.h:114
fuse_conn_info
Definition: fuse_common.h:451
fuse_conn_info::proto_major
unsigned proto_major
Definition: fuse_common.h:455
fuse_conn_info::proto_minor
unsigned proto_minor
Definition: fuse_common.h:460
fuse_conn_info::capable
unsigned capable
Definition: fuse_common.h:489
fuse_lowlevel_ops
Definition: fuse_lowlevel.h:192
fuse_lowlevel_ops::init
void(* init)(void *userdata, struct fuse_conn_info *conn)
Definition: fuse_lowlevel.h:209

Definition in file printcap.c.