libfuse: example/printcap.c Source File

libfuse

printcap.c
Go to the documentation of this file.
1 /*
2 FUSE: Filesystem in Userspace
3 Copyright (C) 2017 Nikolaus Rath <Nikolaus@rath.org>
4
5 This program can be distributed under the terms of the GNU GPLv2.
6 See the file COPYING.
7 */
8
22 #define FUSE_USE_VERSION 31
23
24 #include <config.h>
25
26 #include <fuse_lowlevel.h>
27 #include <stdio.h>
28 #include <unistd.h>
29 #include <string.h>
30 #include <stdlib.h>
31
32 struct fuse_session *se;
33
34 static void pc_init(void *userdata,
35 struct fuse_conn_info *conn)
36 {
37 (void) userdata;
38
39 printf("Protocol version: %d.%d\n", conn->proto_major,
40 conn->proto_minor);
41 printf("Capabilities:\n");
42 if(conn->capable & FUSE_CAP_WRITEBACK_CACHE)
43 printf("\tFUSE_CAP_WRITEBACK_CACHE\n");
44 if(conn->capable & FUSE_CAP_ASYNC_READ)
45 printf("\tFUSE_CAP_ASYNC_READ\n");
46 if(conn->capable & FUSE_CAP_POSIX_LOCKS)
47 printf("\tFUSE_CAP_POSIX_LOCKS\n");
48 if(conn->capable & FUSE_CAP_ATOMIC_O_TRUNC)
49 printf("\tFUSE_CAP_ATOMIC_O_TRUNC\n");
50 if(conn->capable & FUSE_CAP_EXPORT_SUPPORT)
51 printf("\tFUSE_CAP_EXPORT_SUPPORT\n");
52 if(conn->capable & FUSE_CAP_DONT_MASK)
53 printf("\tFUSE_CAP_DONT_MASK\n");
54 if(conn->capable & FUSE_CAP_SPLICE_MOVE)
55 printf("\tFUSE_CAP_SPLICE_MOVE\n");
56 if(conn->capable & FUSE_CAP_SPLICE_READ)
57 printf("\tFUSE_CAP_SPLICE_READ\n");
58 if(conn->capable & FUSE_CAP_SPLICE_WRITE)
59 printf("\tFUSE_CAP_SPLICE_WRITE\n");
60 if(conn->capable & FUSE_CAP_FLOCK_LOCKS)
61 printf("\tFUSE_CAP_FLOCK_LOCKS\n");
62 if(conn->capable & FUSE_CAP_IOCTL_DIR)
63 printf("\tFUSE_CAP_IOCTL_DIR\n");
64 if(conn->capable & FUSE_CAP_AUTO_INVAL_DATA)
65 printf("\tFUSE_CAP_AUTO_INVAL_DATA\n");
66 if(conn->capable & FUSE_CAP_READDIRPLUS)
67 printf("\tFUSE_CAP_READDIRPLUS\n");
68 if(conn->capable & FUSE_CAP_READDIRPLUS_AUTO)
69 printf("\tFUSE_CAP_READDIRPLUS_AUTO\n");
70 if(conn->capable & FUSE_CAP_ASYNC_DIO)
71 printf("\tFUSE_CAP_ASYNC_DIO\n");
72 if(conn->capable & FUSE_CAP_WRITEBACK_CACHE)
73 printf("\tFUSE_CAP_WRITEBACK_CACHE\n");
74 if(conn->capable & FUSE_CAP_NO_OPEN_SUPPORT)
75 printf("\tFUSE_CAP_NO_OPEN_SUPPORT\n");
76 if(conn->capable & FUSE_CAP_PARALLEL_DIROPS)
77 printf("\tFUSE_CAP_PARALLEL_DIROPS\n");
78 if(conn->capable & FUSE_CAP_POSIX_ACL)
79 printf("\tFUSE_CAP_POSIX_ACL\n");
80 if(conn->capable & FUSE_CAP_CACHE_SYMLINKS)
81 printf("\tFUSE_CAP_CACHE_SYMLINKS\n");
82 if(conn->capable & FUSE_CAP_NO_OPENDIR_SUPPORT)
83 printf("\tFUSE_CAP_NO_OPENDIR_SUPPORT\n");
84 if(conn->capable & FUSE_CAP_EXPLICIT_INVAL_DATA)
85 printf("\tFUSE_CAP_EXPLICIT_INVAL_DATA\n");
86 fuse_session_exit(se);
87 }
88
89
90 static const struct fuse_lowlevel_ops pc_oper = {
91 .init = pc_init,
92 };
93
94 int main(int argc, char **argv)
95 {
96 struct fuse_args args = FUSE_ARGS_INIT(argc, argv);
97 char *mountpoint;
98 int ret = -1;
99
100 mountpoint = strdup("/tmp/fuse_printcap_XXXXXX");
101 if(mkdtemp(mountpoint) == NULL) {
102 perror("mkdtemp");
103 return 1;
104 }
105
106 printf("FUSE library version %s\n", fuse_pkgversion());
107 fuse_lowlevel_version();
108
109 se = fuse_session_new(&args, &pc_oper,
110 sizeof(pc_oper), NULL);
111 if (se == NULL)
112 goto err_out1;
113
114 if (fuse_set_signal_handlers(se) != 0)
115 goto err_out2;
116
117 if (fuse_session_mount(se, mountpoint) != 0)
118 goto err_out3;
119
120 ret = fuse_session_loop(se);
121
122 fuse_session_unmount(se);
123 err_out3:
124 fuse_remove_signal_handlers(se);
125 err_out2:
126 fuse_session_destroy(se);
127 err_out1:
128 rmdir(mountpoint);
129 free(mountpoint);
130 fuse_opt_free_args(&args);
131
132 return ret ? 1 : 0;
133 }
fuse_session_destroy
void fuse_session_destroy(struct fuse_session *se)
Definition: fuse_lowlevel.c:2708
FUSE_CAP_IOCTL_DIR
#define FUSE_CAP_IOCTL_DIR
Definition: fuse_common.h:218
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:2894
fuse_session_exit
void fuse_session_exit(struct fuse_session *se)
fuse_conn_info::capable
unsigned capable
Definition: fuse_common.h:459
fuse_session_loop
int fuse_session_loop(struct fuse_session *se)
Definition: fuse_loop.c:19
fuse_conn_info
Definition: fuse_common.h:421
fuse_session_mount
int fuse_session_mount(struct fuse_session *se, const char *mountpoint)
Definition: fuse_lowlevel.c:2990
fuse_conn_info::proto_minor
unsigned proto_minor
Definition: fuse_common.h:430
FUSE_CAP_ASYNC_READ
#define FUSE_CAP_ASYNC_READ
Definition: fuse_common.h:141
FUSE_CAP_EXPORT_SUPPORT
#define FUSE_CAP_EXPORT_SUPPORT
Definition: fuse_common.h:165
FUSE_CAP_CACHE_SYMLINKS
#define FUSE_CAP_CACHE_SYMLINKS
Definition: fuse_common.h:360
FUSE_CAP_READDIRPLUS_AUTO
#define FUSE_CAP_READDIRPLUS_AUTO
Definition: fuse_common.h:276
fuse_set_signal_handlers
int fuse_set_signal_handlers(struct fuse_session *se)
Definition: fuse_signals.c:62
FUSE_CAP_SPLICE_WRITE
#define FUSE_CAP_SPLICE_WRITE
Definition: fuse_common.h:181
fuse_remove_signal_handlers
void fuse_remove_signal_handlers(struct fuse_session *se)
Definition: fuse_signals.c:79
FUSE_CAP_NO_OPEN_SUPPORT
#define FUSE_CAP_NO_OPEN_SUPPORT
Definition: fuse_common.h:309
fuse_lowlevel_version
void fuse_lowlevel_version(void)
Definition: fuse_lowlevel.c:2691
fuse_opt_free_args
void fuse_opt_free_args(struct fuse_args *args)
Definition: fuse_opt.c:34
FUSE_CAP_SPLICE_MOVE
#define FUSE_CAP_SPLICE_MOVE
Definition: fuse_common.h:189
FUSE_CAP_NO_OPENDIR_SUPPORT
#define FUSE_CAP_NO_OPENDIR_SUPPORT
Definition: fuse_common.h:372
FUSE_CAP_AUTO_INVAL_DATA
#define FUSE_CAP_AUTO_INVAL_DATA
Definition: fuse_common.h:240
FUSE_CAP_SPLICE_READ
#define FUSE_CAP_SPLICE_READ
Definition: fuse_common.h:198
fuse_session_unmount
void fuse_session_unmount(struct fuse_session *se)
Definition: fuse_lowlevel.c:3045
FUSE_CAP_FLOCK_LOCKS
#define FUSE_CAP_FLOCK_LOCKS
Definition: fuse_common.h:211
FUSE_CAP_EXPLICIT_INVAL_DATA
#define FUSE_CAP_EXPLICIT_INVAL_DATA
Definition: fuse_common.h:395
fuse_conn_info::proto_major
unsigned proto_major
Definition: fuse_common.h:425
FUSE_CAP_ASYNC_DIO
#define FUSE_CAP_ASYNC_DIO
Definition: fuse_common.h:287
FUSE_CAP_WRITEBACK_CACHE
#define FUSE_CAP_WRITEBACK_CACHE
Definition: fuse_common.h:296
FUSE_CAP_POSIX_LOCKS
#define FUSE_CAP_POSIX_LOCKS
Definition: fuse_common.h:149
FUSE_CAP_POSIX_ACL
#define FUSE_CAP_POSIX_ACL
Definition: fuse_common.h:338
fuse_lowlevel.h
fuse_lowlevel_ops
Definition: fuse_lowlevel.h:172
FUSE_CAP_ATOMIC_O_TRUNC
#define FUSE_CAP_ATOMIC_O_TRUNC
Definition: fuse_common.h:158
fuse_args
Definition: fuse_opt.h:109
FUSE_CAP_READDIRPLUS
#define FUSE_CAP_READDIRPLUS
Definition: fuse_common.h:248
fuse_pkgversion
const char * fuse_pkgversion(void)
Definition: fuse.c:5122
FUSE_ARGS_INIT
#define FUSE_ARGS_INIT(argc, argv)
Definition: fuse_opt.h:123
FUSE_CAP_PARALLEL_DIROPS
#define FUSE_CAP_PARALLEL_DIROPS
Definition: fuse_common.h:319
fuse_lowlevel_ops::init
void(* init)(void *userdata, struct fuse_conn_info *conn)
Definition: fuse_lowlevel.h:189
FUSE_CAP_DONT_MASK
#define FUSE_CAP_DONT_MASK
Definition: fuse_common.h:173