1
+ #include "riscv.h"
2
+ #include "virtio.h"
3
+
4
+ #define FUSE_REC_ALIGN (x ) \
5
+ (((x) + sizeof(uint64_t) - 1) & ~(sizeof(uint64_t) - 1))
6
+ #define FUSE_DIRENT_ALIGN (x ) FUSE_REC_ALIGN(x)
7
+
8
+ struct fuse_in_header {
9
+ uint32_t len ;
10
+ uint32_t opcode ;
11
+ uint64_t unique ;
12
+ uint64_t nodeid ;
13
+ uint32_t uid ;
14
+ uint32_t gid ;
15
+ uint32_t pid ;
16
+ uint32_t padding ;
17
+ };
18
+
19
+ struct fuse_out_header {
20
+ uint32_t len ;
21
+ int32_t error ;
22
+ uint64_t unique ;
23
+ };
24
+
25
+
26
+ struct vfs_req_header {
27
+ struct fuse_in_header in ;
28
+ };
29
+
30
+ struct vfs_resp_header {
31
+ struct fuse_out_header out ;
32
+ };
33
+
34
+ struct fuse_init_in {
35
+ uint32_t major ; // FUSE major version supported by the guest (typically 7)
36
+ uint32_t minor ; // FUSE minor version supported by the guest (e.g., 31, 26)
37
+ uint32_t max_readahead ; // Maximum readahead size supported by the guest
38
+ // (e.g., 0x10000)
39
+ uint32_t flags ; // Flags requested by the guest (e.g., support for
40
+ // writeback cache)
41
+ };
42
+
43
+ struct fuse_init_out {
44
+ uint32_t major ; // FUSE major version supported by the device
45
+ uint32_t minor ; // FUSE minor version supported by the device
46
+ uint32_t max_readahead ; // Maximum readahead size accepted by the device
47
+ uint32_t
48
+ flags ; // Flags supported by the device (negotiated with the guest)
49
+ uint16_t max_background ; // Maximum number of background requests
50
+ uint16_t
51
+ congestion_threshold ; // Threshold for marking the connection congested
52
+ uint32_t max_write ; // Maximum write size the device can handle
53
+ uint32_t time_gran ; // Time granularity (in nanoseconds)
54
+ uint32_t unused [11 ]; // Reserved
55
+ };
56
+
57
+ struct fuse_getattr_in {
58
+ uint32_t getattr_flags ; // bitmask for valid fields (e.g. FUSE_GETATTR_FH)
59
+ uint32_t padding ; // unused, reserved for alignment
60
+ uint64_t fh ; // optional: file handle (used when getattr_flags has
61
+ // FUSE_GETATTR_FH)
62
+ };
63
+
64
+ struct fuse_attr {
65
+ uint64_t ino ; // inode number
66
+ uint64_t size ; // file size in bytes
67
+ uint64_t blocks ; // number of 512B blocks allocated
68
+ uint64_t atime ; // last access time (UNIX time)
69
+ uint64_t mtime ; // last modification time
70
+ uint64_t ctime ; // last status change time
71
+ uint32_t atimensec ; // nanoseconds part
72
+ uint32_t mtimensec ;
73
+ uint32_t ctimensec ;
74
+ uint32_t mode ; // file mode (e.g. S_IFDIR | 0755)
75
+ uint32_t nlink ; // number of hard links
76
+ uint32_t uid ; // owner uid
77
+ uint32_t gid ; // owner gid
78
+ uint32_t rdev ; // device ID (if special file)
79
+ uint32_t blksize ; // block size
80
+ uint32_t flags ; // reserved
81
+ };
82
+
83
+ struct fuse_attr_out {
84
+ uint64_t attr_valid ; // seconds the attributes are valid
85
+ uint32_t attr_valid_nsec ; // nanoseconds part of attr_valid
86
+ uint32_t dummy ; // padding for alignment
87
+ struct fuse_attr attr ; // actual attributes
88
+ };
89
+
90
+ struct fuse_open_in {
91
+ uint32_t flags ;
92
+ uint32_t open_flags ; /* FUSE_OPEN_... */
93
+ };
94
+
95
+ struct fuse_open_out {
96
+ uint64_t fh ; // file handle
97
+ uint32_t open_flags ;
98
+ int32_t backing_id ;
99
+ };
100
+
101
+ struct fuse_read_in {
102
+ uint64_t fh ;
103
+ uint64_t offset ;
104
+ uint32_t size ;
105
+ uint32_t read_flags ;
106
+ uint64_t lock_owner ;
107
+ uint32_t flags ;
108
+ uint32_t padding ;
109
+ };
110
+
111
+ struct fuse_entry_out {
112
+ uint64_t nodeid ; // inode number
113
+ uint64_t generation ; // inode generation
114
+ uint64_t entry_valid ; // cache timeout (sec)
115
+ uint64_t attr_valid ; // attr cache timeout (sec)
116
+ uint32_t entry_valid_nsec ; // cache timeout (nsec)
117
+ uint32_t attr_valid_nsec ; // attr cache timeout (nsec)
118
+ struct fuse_attr attr ; // file attributes (與 stat 結構相似)
119
+ };
120
+
121
+ struct fuse_dirent {
122
+ uint64_t ino ; // inode number
123
+ uint64_t off ; // offset to next entry
124
+ uint32_t namelen ; // length of the entry name
125
+ uint32_t type ; // file type (DT_REG, DT_DIR, etc.)
126
+ char name []; // name (not null-terminated)
127
+ };
128
+
129
+ struct fuse_direntplus {
130
+ struct fuse_entry_out entry_out ;
131
+ struct fuse_dirent dirent ;
132
+ };
133
+
134
+ struct fuse_lookup_in {
135
+ uint64_t parent ; // inode of parent dir
136
+ // char name[]; // followed by name (not null-terminated!)
137
+ };
138
+
139
+ struct fuse_forget_in {
140
+ uint64_t nlookup ;
141
+ };
142
+
143
+ struct fuse_create_in {
144
+ uint32_t flags ;
145
+ uint32_t mode ;
146
+ uint32_t umask ;
147
+ uint32_t open_flags ; /* FUSE_OPEN_... */
148
+ };
149
+
150
+ struct fuse_release_in {
151
+ uint64_t fh ;
152
+ uint32_t flags ;
153
+ uint32_t release_flags ;
154
+ uint64_t lock_owner ;
155
+ };
156
+
157
+ struct fuse_flush_in {
158
+ uint64_t fh ;
159
+ uint32_t unused ;
160
+ uint32_t padding ;
161
+ uint64_t lock_owner ;
162
+ };
0 commit comments