jcs's openbsd hax
openbsd
1/* $OpenBSD: fuse_lowlevel.h,v 1.2 2026/01/22 11:53:31 helg Exp $ */
2/*
3 * Copyright (c) 2025 Helg Bredow <helg@openbsd.org>
4 *
5 * Permission to use, copy, modify, and distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
8 *
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16 */
17
18#ifndef _FUSE_LOWLEVEL_H_
19#define _FUSE_LOWLEVEL_H_
20
21#ifndef FUSE_USE_VERSION
22#define FUSE_USE_VERSION 26
23#endif
24
25#include <sys/stat.h>
26#include <sys/statvfs.h>
27#include <sys/uio.h>
28
29#include "fuse_common.h"
30
31#ifdef __cplusplus
32extern "C" {
33#endif
34
35typedef ino_t fuse_ino_t;
36
37typedef struct fuse_req *fuse_req_t;
38
39struct fuse_entry_param {
40 fuse_ino_t ino;
41 unsigned long generation;
42 struct stat attr;
43 double attr_timeout;
44 double entry_timeout;
45};
46
47struct fuse_ctx {
48 uid_t uid;
49 gid_t gid;
50 pid_t pid;
51 mode_t umask;
52};
53
54struct fuse_lowlevel_ops {
55 void (*init)(void *, struct fuse_conn_info *);
56 void (*destroy)(void *);
57 void (*lookup)(fuse_req_t, fuse_ino_t, const char *);
58 void (*forget)(fuse_req_t, fuse_ino_t, uint64_t);
59 void (*getattr)(fuse_req_t, fuse_ino_t, struct fuse_file_info *);
60 void (*setattr)(fuse_req_t, fuse_ino_t, struct stat *, int,
61 struct fuse_file_info *);
62 void (*readlink)(fuse_req_t, fuse_ino_t);
63 void (*mknod)(fuse_req_t, fuse_ino_t, const char *, mode_t, dev_t);
64 void (*mkdir)(fuse_req_t, fuse_ino_t, const char *, mode_t);
65 void (*unlink)(fuse_req_t, fuse_ino_t, const char *);
66 void (*rmdir)(fuse_req_t, fuse_ino_t, const char *);
67 void (*symlink)(fuse_req_t, const char *, fuse_ino_t, const char *);
68 void (*rename)(fuse_req_t, fuse_ino_t, const char *, fuse_ino_t,
69 const char *);
70 void (*link)(fuse_req_t, fuse_ino_t, fuse_ino_t, const char *);
71 void (*open)(fuse_req_t, fuse_ino_t, struct fuse_file_info *);
72 void (*read)(fuse_req_t, fuse_ino_t, size_t, off_t,
73 struct fuse_file_info *);
74 void (*write)(fuse_req_t, fuse_ino_t, const char *, size_t, off_t,
75 struct fuse_file_info *);
76 void (*flush)(fuse_req_t, fuse_ino_t, struct fuse_file_info *);
77 void (*release)(fuse_req_t, fuse_ino_t, struct fuse_file_info *);
78 void (*fsync)(fuse_req_t, fuse_ino_t, int, struct fuse_file_info *);
79 void (*opendir)(fuse_req_t, fuse_ino_t, struct fuse_file_info *);
80 void (*readdir)(fuse_req_t, fuse_ino_t, size_t, off_t,
81 struct fuse_file_info *);
82 void (*releasedir)(fuse_req_t, fuse_ino_t, struct fuse_file_info *);
83 void (*statfs)(fuse_req_t, fuse_ino_t);
84
85 /*
86 * The following are not supported on OpenBSD but are included for
87 * compatibilty. Porters must take care that ports do not rely on
88 * these file system operations being called. In particular, if create
89 * is implemented but mknod is not. On OpenBSD, file creation results
90 * in mknod() and then open() being called instead.
91 */
92 void (*access) (fuse_req_t req, fuse_ino_t ino, int mask);
93 void (*create)(fuse_req_t, fuse_ino_t, const char *, mode_t,
94 struct fuse_file_info *);
95 void (*bmap)(fuse_req_t, fuse_ino_t, size_t, uint64_t);
96 void (*fsyncdir)(fuse_req_t, fuse_ino_t, int, struct fuse_file_info *);
97
98 /* setxattr */
99 /* getxattr */
100 /* listxattr */
101 /* removexattr */
102 /* getlk */
103 /* setlk */
104 /* others... */
105};
106
107
108/*
109 * Helper function for readdir operations
110 */
111size_t fuse_add_direntry(fuse_req_t, char *, const size_t, const char *,
112 const struct stat *, off_t);
113
114/*
115 * FUSE Sesssion API Prototypes
116 */
117struct fuse_session *fuse_lowlevel_new(struct fuse_args *,
118 const struct fuse_lowlevel_ops *, const size_t, void *);
119int fuse_session_loop(struct fuse_session *);
120int fuse_session_exited(const struct fuse_session *);
121void fuse_session_exit(struct fuse_session *);
122void fuse_session_add_chan(struct fuse_session *, struct fuse_chan *);
123void fuse_session_remove_chan(struct fuse_chan *);
124void fuse_session_destroy(struct fuse_session *);
125void fuse_session_reset(struct fuse_session *);
126void fuse_session_process(struct fuse_session *, const char *, size_t,
127 struct fuse_chan *);
128
129
130/*
131 * FUSE Channel API Prototypes
132 */
133int fuse_chan_recv(struct fuse_chan **, char *, size_t);
134int fuse_chan_send(struct fuse_chan *, const struct iovec *, size_t);
135int fuse_chan_fd(struct fuse_chan *);
136
137/*
138 * API Prototypes to reply from a file system operation back to the kernel.
139 */
140int fuse_reply_err(fuse_req_t, int);
141int fuse_reply_buf(fuse_req_t, const char *, off_t);
142int fuse_reply_attr(fuse_req_t, const struct stat *, double);
143int fuse_reply_open(fuse_req_t, const struct fuse_file_info *);
144int fuse_reply_write(fuse_req_t, size_t);
145int fuse_reply_entry(fuse_req_t, const struct fuse_entry_param *);
146int fuse_reply_statfs(fuse_req_t, const struct statvfs *);
147int fuse_reply_readlink(fuse_req_t, char *);
148void fuse_reply_none(fuse_req_t);
149
150/*
151 * The following are unsupported but are included for compatibility.
152 */
153int fuse_reply_bmap(fuse_req_t, uint64_t);
154int fuse_reply_create(fuse_req_t, const struct fuse_entry_param *,
155 const struct fuse_file_info *);
156
157/*
158 * FUSE Request API Prototypes
159 */
160const struct fuse_ctx *fuse_req_ctx(fuse_req_t);
161void *fuse_req_userdata(fuse_req_t);
162
163/*
164 * Bitmasks for setattr to indicate what to set.
165 */
166#define FUSE_SET_ATTR_MODE (1 << 0)
167#define FUSE_SET_ATTR_UID (1 << 1)
168#define FUSE_SET_ATTR_GID (1 << 2)
169#define FUSE_SET_ATTR_SIZE (1 << 3)
170#define FUSE_SET_ATTR_ATIME (1 << 4)
171#define FUSE_SET_ATTR_MTIME (1 << 5)
172#define FUSE_SET_ATTR_ATIME_NOW (1 << 7)
173#define FUSE_SET_ATTR_MTIME_NOW (1 << 8)
174
175#ifdef __cplusplus
176}
177#endif
178
179#endif /* _FUSE_LOWLEVEL_H_ */