Skip to content

Commit 9b037e5

Browse files
fs: add fuse primitives
This commit adds fuse structures, requests and functions to fill them Signed-off-by: Jakub Michalski <jmichalski@antmicro.com>
1 parent 25249a0 commit 9b037e5

File tree

8 files changed

+931
-0
lines changed

8 files changed

+931
-0
lines changed

doc/LICENSING.rst

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,15 @@ Python Devicetree library test files
108108

109109
* Various yaml files under ``scripts/dts/python-devicetree/tests``
110110

111+
FUSE Interface Definition Header File
112+
--------------------------------------
113+
114+
* *Licensing:* `BSD-2-clause`_
115+
* *Impact:* This header is used in Zephyr build only if :kconfig:option:`CONFIG_FUSE_CLIENT` is enabled.
116+
* *Files*:
117+
118+
* :zephyr_file:`subsys/fs/fuse_client/fuse_abi.h`
119+
111120
.. _Apache 2.0 License:
112121
https://github.com/zephyrproject-rtos/zephyr/blob/main/LICENSE
113122

@@ -120,6 +129,9 @@ Python Devicetree library test files
120129
.. _BSD-3-clause:
121130
https://opensource.org/license/bsd-3-clause
122131

132+
.. _BSD-2-clause:
133+
https://opensource.org/license/bsd-2-clause
134+
123135
.. _Coccinelle:
124136
https://coccinelle.gitlabpages.inria.fr/website/
125137

subsys/fs/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,14 @@ if(CONFIG_FILE_SYSTEM_LIB_LINK)
1717
endif()
1818

1919
add_subdirectory_ifdef(CONFIG_FILE_SYSTEM_EXT2 ext2)
20+
add_subdirectory_ifdef(CONFIG_FUSE_CLIENT fuse_client)
2021

2122
zephyr_library_link_libraries(FS)
2223

2324
target_link_libraries_ifdef(CONFIG_FAT_FILESYSTEM_ELM FS INTERFACE ELMFAT)
2425
target_link_libraries_ifdef(CONFIG_FILE_SYSTEM_LITTLEFS FS INTERFACE LITTLEFS)
2526
target_link_libraries_ifdef(CONFIG_FILE_SYSTEM_EXT2 FS INTERFACE EXT2)
27+
target_link_libraries_ifdef(CONFIG_FUSE_CLIENT FS INTERFACE FUSE_CLIENT)
2628
endif()
2729

2830
add_subdirectory_ifdef(CONFIG_FCB ./fcb)

subsys/fs/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ source "subsys/logging/Kconfig.template.log_config"
119119
rsource "Kconfig.fatfs"
120120
rsource "Kconfig.littlefs"
121121
rsource "ext2/Kconfig"
122+
rsource "fuse_client/Kconfig"
122123

123124
endif # FILE_SYSTEM_LIB_LINK
124125

subsys/fs/fuse_client/CMakeLists.txt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Copyright (c) 2025 Antmicro <www.antmicro.com>
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
# This library provides a set of functions for creating FUSE structures
5+
6+
add_library(FUSE_CLIENT INTERFACE)
7+
target_include_directories(FUSE_CLIENT INTERFACE ${CMAKE_CURRENT_SOURCE_DIR})
8+
9+
zephyr_library()
10+
zephyr_library_sources(
11+
fuse_client.c
12+
)
13+
14+
zephyr_library_link_libraries(FUSE_CLIENT)

subsys/fs/fuse_client/Kconfig

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Copyright (c) 2025 Antmicro <www.antmicro.com>
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
config FUSE_CLIENT
5+
bool "FUSE client-side primitives support"
6+
help
7+
Enable FUSE client-side primitives support.
8+
9+
config FUSE_CLIENT_UID_VALUE
10+
int "FUSE user ID"
11+
default 0
12+
help
13+
Each FUSE request contains user ID, this config allows setting
14+
that value. The result is as if user with given UID accessed the file/resource.
15+
16+
config FUSE_CLIENT_GID_VALUE
17+
int "FUSE group ID"
18+
default 0
19+
help
20+
Each FUSE request contains group ID, this config allows setting
21+
that value. The result is as if user with given GID accessed the file/resource.
22+
23+
config FUSE_CLIENT_PID_VALUE
24+
int "FUSE process ID"
25+
default 0
26+
help
27+
Each FUSE request contains process ID, this config allows setting
28+
that value. The result is as if process with given PID accessed the file/resource.
29+
30+
module = FUSE_CLIENT
31+
module-str = fuse
32+
source "subsys/logging/Kconfig.template.log_config"

subsys/fs/fuse_client/fuse_abi.h

Lines changed: 273 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,273 @@
1+
/* SPDX-License-Identifier: ((GPL-2.0 WITH Linux-syscall-note) OR BSD-2-Clause) */
2+
3+
/*
4+
* This file is based on include/uapi/linux/fuse.h from Linux, and is used
5+
* under the BSD-2-Clause license, as per the dual-license option
6+
*/
7+
/*
8+
* This file defines the kernel interface of FUSE
9+
* This -- and only this -- header file may also be distributed under
10+
* the terms of the BSD Licence as follows:
11+
*
12+
* Copyright (C) 2001-2007 Miklos Szeredi. All rights reserved.
13+
*
14+
* Redistribution and use in source and binary forms, with or without
15+
* modification, are permitted provided that the following conditions
16+
* are met:
17+
* 1. Redistributions of source code must retain the above copyright
18+
* notice, this list of conditions and the following disclaimer.
19+
* 2. Redistributions in binary form must reproduce the above copyright
20+
* notice, this list of conditions and the following disclaimer in the
21+
* documentation and/or other materials provided with the distribution.
22+
*
23+
* THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND
24+
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26+
* ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
27+
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28+
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29+
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30+
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31+
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32+
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33+
* SUCH DAMAGE.
34+
*/
35+
36+
#ifndef ZEPHYR_SUBSYS_FS_FUSE_ABI_H_
37+
#define ZEPHYR_SUBSYS_FS_FUSE_ABI_H_
38+
#include <stdint.h>
39+
40+
#define FUSE_MAJOR_VERSION 7
41+
#define FUSE_MINOR_VERSION 31
42+
43+
#define FUSE_LOOKUP 1
44+
#define FUSE_FORGET 2
45+
#define FUSE_SETATTR 4
46+
#define FUSE_MKDIR 9
47+
#define FUSE_UNLINK 10
48+
#define FUSE_RMDIR 11
49+
#define FUSE_RENAME 12
50+
#define FUSE_OPEN 14
51+
#define FUSE_READ 15
52+
#define FUSE_WRITE 16
53+
#define FUSE_STATFS 17
54+
#define FUSE_RELEASE 18
55+
#define FUSE_FSYNC 20
56+
#define FUSE_INIT 26
57+
#define FUSE_OPENDIR 27
58+
#define FUSE_READDIR 28
59+
#define FUSE_RELEASEDIR 29
60+
#define FUSE_CREATE 35
61+
#define FUSE_DESTROY 38
62+
#define FUSE_LSEEK 46
63+
64+
#define FUSE_ROOT_INODE 1
65+
66+
struct fuse_in_header {
67+
uint32_t len;
68+
uint32_t opcode;
69+
uint64_t unique;
70+
uint64_t nodeid;
71+
uint32_t uid;
72+
uint32_t gid;
73+
uint32_t pid;
74+
uint16_t total_extlen;
75+
uint16_t padding;
76+
};
77+
78+
struct fuse_out_header {
79+
uint32_t len;
80+
int32_t error;
81+
uint64_t unique;
82+
};
83+
84+
struct fuse_init_in {
85+
uint32_t major;
86+
uint32_t minor;
87+
uint32_t max_readahead;
88+
uint32_t flags;
89+
uint32_t flags2;
90+
uint32_t unused[11];
91+
};
92+
93+
struct fuse_init_out {
94+
uint32_t major;
95+
uint32_t minor;
96+
uint32_t max_readahead;
97+
uint32_t flags;
98+
uint16_t max_background;
99+
uint16_t congestion_threshold;
100+
uint32_t max_write;
101+
uint32_t time_gran;
102+
uint16_t max_pages;
103+
uint16_t map_alignment;
104+
uint32_t flags2;
105+
uint32_t max_stack_depth;
106+
uint32_t unused[6];
107+
};
108+
109+
struct fuse_open_in {
110+
uint32_t flags;
111+
uint32_t open_flags;
112+
};
113+
114+
struct fuse_open_out {
115+
uint64_t fh;
116+
uint32_t open_flags;
117+
int32_t backing_id;
118+
};
119+
120+
struct fuse_attr {
121+
uint64_t ino;
122+
uint64_t size;
123+
uint64_t blocks;
124+
uint64_t atime;
125+
uint64_t mtime;
126+
uint64_t ctime;
127+
uint32_t atimensec;
128+
uint32_t mtimensec;
129+
uint32_t ctimensec;
130+
uint32_t mode;
131+
uint32_t nlink;
132+
uint32_t uid;
133+
uint32_t gid;
134+
uint32_t rdev;
135+
uint32_t blksize;
136+
uint32_t flags;
137+
};
138+
139+
struct fuse_entry_out {
140+
uint64_t nodeid;
141+
uint64_t generation;
142+
uint64_t entry_valid;
143+
uint64_t attr_valid;
144+
uint32_t entry_valid_nsec;
145+
uint32_t attr_valid_nsec;
146+
struct fuse_attr attr;
147+
};
148+
149+
struct fuse_read_in {
150+
uint64_t fh;
151+
uint64_t offset;
152+
uint32_t size;
153+
uint32_t read_flags;
154+
uint64_t lock_owner;
155+
uint32_t flags;
156+
uint32_t padding;
157+
};
158+
159+
struct fuse_release_in {
160+
uint64_t fh;
161+
uint32_t flags;
162+
uint32_t release_flags;
163+
uint64_t lock_owner;
164+
};
165+
166+
struct fuse_create_in {
167+
uint32_t flags;
168+
uint32_t mode;
169+
uint32_t umask;
170+
uint32_t open_flags;
171+
};
172+
173+
struct fuse_create_out {
174+
struct fuse_entry_out entry_out;
175+
struct fuse_open_out open_out;
176+
};
177+
178+
struct fuse_write_in {
179+
uint64_t fh;
180+
uint64_t offset;
181+
uint32_t size;
182+
uint32_t write_flags;
183+
uint64_t lock_owner;
184+
uint32_t flags;
185+
uint32_t padding;
186+
};
187+
188+
struct fuse_write_out {
189+
uint32_t size;
190+
uint32_t padding;
191+
};
192+
193+
struct fuse_lseek_in {
194+
uint64_t fh;
195+
uint64_t offset;
196+
uint32_t whence;
197+
uint32_t padding;
198+
};
199+
200+
struct fuse_lseek_out {
201+
uint64_t offset;
202+
};
203+
204+
/* mask used to set file size, used in fuse_setattr_in::valid */
205+
#define FATTR_SIZE (1 << 3)
206+
207+
struct fuse_setattr_in {
208+
uint32_t valid;
209+
uint32_t padding;
210+
uint64_t fh;
211+
uint64_t size;
212+
uint64_t lock_owner;
213+
uint64_t atime;
214+
uint64_t mtime;
215+
uint64_t ctime;
216+
uint32_t atimensec;
217+
uint32_t mtimensec;
218+
uint32_t ctimensec;
219+
uint32_t mode;
220+
uint32_t unused4;
221+
uint32_t uid;
222+
uint32_t gid;
223+
uint32_t unused5;
224+
};
225+
226+
struct fuse_attr_out {
227+
uint64_t attr_valid;
228+
uint32_t attr_valid_nsec;
229+
uint32_t dummy;
230+
struct fuse_attr attr;
231+
};
232+
233+
struct fuse_fsync_in {
234+
uint64_t fh;
235+
uint32_t fsync_flags;
236+
uint32_t padding;
237+
};
238+
239+
struct fuse_mkdir_in {
240+
uint32_t mode;
241+
uint32_t umask;
242+
};
243+
244+
struct fuse_rename_in {
245+
uint64_t newdir;
246+
};
247+
248+
struct fuse_kstatfs {
249+
uint64_t blocks;
250+
uint64_t bfree;
251+
uint64_t bavail;
252+
uint64_t files;
253+
uint64_t ffree;
254+
uint32_t bsize;
255+
uint32_t namelen;
256+
uint32_t frsize;
257+
uint32_t padding;
258+
uint32_t spare[6];
259+
};
260+
261+
struct fuse_dirent {
262+
uint64_t ino;
263+
uint64_t off;
264+
uint32_t namelen;
265+
uint32_t type;
266+
char name[];
267+
};
268+
269+
struct fuse_forget_in {
270+
uint64_t nlookup;
271+
};
272+
273+
#endif /* ZEPHYR_SUBSYS_FS_FUSE_ABI_H_ */

0 commit comments

Comments
 (0)