Skip to content

Commit 5983232

Browse files
jmichalski-antfkokosinski
authored andcommitted
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 5983232

File tree

7 files changed

+915
-0
lines changed

7 files changed

+915
-0
lines changed

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

0 commit comments

Comments
 (0)