]>
Commit | Line | Data |
---|---|---|
1 | /** @file\r | |
2 | Type and macro definitions specific to the Virtio Filesystem device.\r | |
3 | \r | |
4 | At the time of this writing, the latest released Virtio specification (v1.1)\r | |
5 | does not include the virtio-fs device. The development version of the\r | |
6 | specification defines it however; see the latest version at\r | |
7 | <https://github.com/oasis-tcs/virtio-spec/blob/87fa6b5d8155/virtio-fs.tex>.\r | |
8 | \r | |
9 | This header file is minimal, and only defines the types and macros that are\r | |
10 | necessary for the OvmfPkg implementation.\r | |
11 | \r | |
12 | Copyright (C) 2020, Red Hat, Inc.\r | |
13 | \r | |
14 | SPDX-License-Identifier: BSD-2-Clause-Patent\r | |
15 | **/\r | |
16 | \r | |
17 | #ifndef VIRTIO_FS_H_\r | |
18 | #define VIRTIO_FS_H_\r | |
19 | \r | |
20 | #include <IndustryStandard/Virtio.h>\r | |
21 | \r | |
22 | //\r | |
23 | // Lowest numbered queue for sending normal priority requests.\r | |
24 | //\r | |
25 | #define VIRTIO_FS_REQUEST_QUEUE 1\r | |
26 | \r | |
27 | //\r | |
28 | // Number of bytes in the "VIRTIO_FS_CONFIG.Tag" field.\r | |
29 | //\r | |
30 | #define VIRTIO_FS_TAG_BYTES 36\r | |
31 | \r | |
32 | //\r | |
33 | // Device configuration layout.\r | |
34 | //\r | |
35 | #pragma pack (1)\r | |
36 | typedef struct {\r | |
37 | //\r | |
38 | // The Tag field can be considered the filesystem label, or a mount point\r | |
39 | // hint. It is UTF-8 encoded, and padded to full size with NUL bytes. If the\r | |
40 | // encoded bytes take up the entire Tag field, then there is no NUL\r | |
41 | // terminator.\r | |
42 | //\r | |
43 | UINT8 Tag[VIRTIO_FS_TAG_BYTES];\r | |
44 | //\r | |
45 | // The total number of request virtqueues exposed by the device (i.e.,\r | |
46 | // excluding the "hiprio" queue).\r | |
47 | //\r | |
48 | UINT32 NumReqQueues;\r | |
49 | } VIRTIO_FS_CONFIG;\r | |
50 | #pragma pack ()\r | |
51 | \r | |
52 | //\r | |
53 | // FUSE-related definitions follow.\r | |
54 | //\r | |
55 | // From virtio-v1.1-cs01-87fa6b5d8155, 5.11 File System Device: "[...] The\r | |
56 | // driver acts as the FUSE client mounting the file system. The virtio file\r | |
57 | // system device provides the mechanism for transporting FUSE requests [...]"\r | |
58 | //\r | |
59 | // Unfortunately, the documentation of the FUSE wire protocol is lacking. The\r | |
60 | // Virtio spec (as of this writing) simply defers to\r | |
61 | // "include/uapi/linux/fuse.h" in the Linux kernel source -- see the reference\r | |
62 | // in virtio spec file "introduction.tex", at commit 87fa6b5d8155.\r | |
63 | //\r | |
64 | // Of course, "include/uapi/linux/fuse.h" is a moving target (the virtio spec\r | |
65 | // does not specify a particular FUSE interface version). The OvmfPkg code\r | |
66 | // targets version 7.31, because that's the lowest version that the QEMU\r | |
67 | // virtio-fs daemon supports at this time -- see QEMU commit 72c42e2d6551\r | |
68 | // ("virtiofsd: Trim out compatibility code", 2020-01-23).\r | |
69 | //\r | |
70 | // Correspondingly, Linux's "include/uapi/linux/fuse.h" is consulted as checked\r | |
71 | // out at commit (c6ff213fe5b8^) = d78092e4937d ("fuse: fix page dereference\r | |
72 | // after free", 2020-09-18); that is, right before commit c6ff213fe5b8 ("fuse:\r | |
73 | // add submount support to <uapi/linux/fuse.h>", 2020-09-18) introduces FUSE\r | |
74 | // interface version 7.32.\r | |
75 | //\r | |
76 | #define VIRTIO_FS_FUSE_MAJOR 7\r | |
77 | #define VIRTIO_FS_FUSE_MINOR 31\r | |
78 | \r | |
79 | //\r | |
80 | // The inode number of the root directory.\r | |
81 | //\r | |
82 | #define VIRTIO_FS_FUSE_ROOT_DIR_NODE_ID 1\r | |
83 | \r | |
84 | //\r | |
85 | // File mode bitmasks.\r | |
86 | //\r | |
87 | #define VIRTIO_FS_FUSE_MODE_TYPE_MASK 0170000u\r | |
88 | #define VIRTIO_FS_FUSE_MODE_TYPE_REG 0100000u\r | |
89 | #define VIRTIO_FS_FUSE_MODE_TYPE_DIR 0040000u\r | |
90 | #define VIRTIO_FS_FUSE_MODE_PERM_RWXU 0000700u\r | |
91 | #define VIRTIO_FS_FUSE_MODE_PERM_RUSR 0000400u\r | |
92 | #define VIRTIO_FS_FUSE_MODE_PERM_WUSR 0000200u\r | |
93 | #define VIRTIO_FS_FUSE_MODE_PERM_RWXG 0000070u\r | |
94 | #define VIRTIO_FS_FUSE_MODE_PERM_RGRP 0000040u\r | |
95 | #define VIRTIO_FS_FUSE_MODE_PERM_WGRP 0000020u\r | |
96 | #define VIRTIO_FS_FUSE_MODE_PERM_RWXO 0000007u\r | |
97 | #define VIRTIO_FS_FUSE_MODE_PERM_ROTH 0000004u\r | |
98 | #define VIRTIO_FS_FUSE_MODE_PERM_WOTH 0000002u\r | |
99 | \r | |
100 | //\r | |
101 | // Flags for VirtioFsFuseOpOpen.\r | |
102 | //\r | |
103 | #define VIRTIO_FS_FUSE_OPEN_REQ_F_RDONLY 0\r | |
104 | #define VIRTIO_FS_FUSE_OPEN_REQ_F_RDWR 2\r | |
105 | \r | |
106 | //\r | |
107 | // FUSE operation codes.\r | |
108 | //\r | |
109 | typedef enum {\r | |
110 | VirtioFsFuseOpForget = 2,\r | |
111 | VirtioFsFuseOpMkDir = 9,\r | |
112 | VirtioFsFuseOpOpen = 14,\r | |
113 | VirtioFsFuseOpRelease = 18,\r | |
114 | VirtioFsFuseOpFsync = 20,\r | |
115 | VirtioFsFuseOpFlush = 25,\r | |
116 | VirtioFsFuseOpInit = 26,\r | |
117 | VirtioFsFuseOpOpenDir = 27,\r | |
118 | VirtioFsFuseOpReleaseDir = 29,\r | |
119 | VirtioFsFuseOpFsyncDir = 30,\r | |
120 | VirtioFsFuseOpCreate = 35,\r | |
121 | } VIRTIO_FS_FUSE_OPCODE;\r | |
122 | \r | |
123 | #pragma pack (1)\r | |
124 | //\r | |
125 | // Request-response headers common to all request types.\r | |
126 | //\r | |
127 | typedef struct {\r | |
128 | UINT32 Len;\r | |
129 | UINT32 Opcode;\r | |
130 | UINT64 Unique;\r | |
131 | UINT64 NodeId;\r | |
132 | UINT32 Uid;\r | |
133 | UINT32 Gid;\r | |
134 | UINT32 Pid;\r | |
135 | UINT32 Padding;\r | |
136 | } VIRTIO_FS_FUSE_REQUEST;\r | |
137 | \r | |
138 | typedef struct {\r | |
139 | UINT32 Len;\r | |
140 | INT32 Error;\r | |
141 | UINT64 Unique;\r | |
142 | } VIRTIO_FS_FUSE_RESPONSE;\r | |
143 | \r | |
144 | //\r | |
145 | // Structure with which the Virtio Filesystem device reports a NodeId to the\r | |
146 | // FUSE client (i.e., to the Virtio Filesystem driver). This structure is a\r | |
147 | // part of the response headers for operations that inform the FUSE client of\r | |
148 | // an inode.\r | |
149 | //\r | |
150 | typedef struct {\r | |
151 | UINT64 NodeId;\r | |
152 | UINT64 Generation;\r | |
153 | UINT64 EntryValid;\r | |
154 | UINT64 AttrValid;\r | |
155 | UINT32 EntryValidNsec;\r | |
156 | UINT32 AttrValidNsec;\r | |
157 | } VIRTIO_FS_FUSE_NODE_RESPONSE;\r | |
158 | \r | |
159 | //\r | |
160 | // Structure describing the host-side attributes of an inode. This structure is\r | |
161 | // a part of the response headers for operations that inform the FUSE client of\r | |
162 | // an inode.\r | |
163 | //\r | |
164 | typedef struct {\r | |
165 | UINT64 Ino;\r | |
166 | UINT64 Size;\r | |
167 | UINT64 Blocks;\r | |
168 | UINT64 Atime;\r | |
169 | UINT64 Mtime;\r | |
170 | UINT64 Ctime;\r | |
171 | UINT32 AtimeNsec;\r | |
172 | UINT32 MtimeNsec;\r | |
173 | UINT32 CtimeNsec;\r | |
174 | UINT32 Mode;\r | |
175 | UINT32 Nlink;\r | |
176 | UINT32 Uid;\r | |
177 | UINT32 Gid;\r | |
178 | UINT32 Rdev;\r | |
179 | UINT32 Blksize;\r | |
180 | UINT32 Padding;\r | |
181 | } VIRTIO_FS_FUSE_ATTRIBUTES_RESPONSE;\r | |
182 | \r | |
183 | //\r | |
184 | // Header for VirtioFsFuseOpForget.\r | |
185 | //\r | |
186 | typedef struct {\r | |
187 | UINT64 NumberOfLookups;\r | |
188 | } VIRTIO_FS_FUSE_FORGET_REQUEST;\r | |
189 | \r | |
190 | //\r | |
191 | // Header for VirtioFsFuseOpMkDir.\r | |
192 | //\r | |
193 | typedef struct {\r | |
194 | UINT32 Mode;\r | |
195 | UINT32 Umask;\r | |
196 | } VIRTIO_FS_FUSE_MKDIR_REQUEST;\r | |
197 | \r | |
198 | //\r | |
199 | // Headers for VirtioFsFuseOpOpen and VirtioFsFuseOpOpenDir.\r | |
200 | //\r | |
201 | typedef struct {\r | |
202 | UINT32 Flags;\r | |
203 | UINT32 Unused;\r | |
204 | } VIRTIO_FS_FUSE_OPEN_REQUEST;\r | |
205 | \r | |
206 | typedef struct {\r | |
207 | UINT64 FileHandle;\r | |
208 | UINT32 OpenFlags;\r | |
209 | UINT32 Padding;\r | |
210 | } VIRTIO_FS_FUSE_OPEN_RESPONSE;\r | |
211 | \r | |
212 | //\r | |
213 | // Header for VirtioFsFuseOpRelease and VirtioFsFuseOpReleaseDir.\r | |
214 | //\r | |
215 | typedef struct {\r | |
216 | UINT64 FileHandle;\r | |
217 | UINT32 Flags;\r | |
218 | UINT32 ReleaseFlags;\r | |
219 | UINT64 LockOwner;\r | |
220 | } VIRTIO_FS_FUSE_RELEASE_REQUEST;\r | |
221 | \r | |
222 | //\r | |
223 | // Header for VirtioFsFuseOpFsync and VirtioFsFuseOpFsyncDir.\r | |
224 | //\r | |
225 | typedef struct {\r | |
226 | UINT64 FileHandle;\r | |
227 | UINT32 FsyncFlags;\r | |
228 | UINT32 Padding;\r | |
229 | } VIRTIO_FS_FUSE_FSYNC_REQUEST;\r | |
230 | \r | |
231 | //\r | |
232 | // Header for VirtioFsFuseOpFlush.\r | |
233 | //\r | |
234 | typedef struct {\r | |
235 | UINT64 FileHandle;\r | |
236 | UINT32 Unused;\r | |
237 | UINT32 Padding;\r | |
238 | UINT64 LockOwner;\r | |
239 | } VIRTIO_FS_FUSE_FLUSH_REQUEST;\r | |
240 | \r | |
241 | //\r | |
242 | // Headers for VirtioFsFuseOpInit.\r | |
243 | //\r | |
244 | typedef struct {\r | |
245 | UINT32 Major;\r | |
246 | UINT32 Minor;\r | |
247 | UINT32 MaxReadahead;\r | |
248 | UINT32 Flags;\r | |
249 | } VIRTIO_FS_FUSE_INIT_REQUEST;\r | |
250 | \r | |
251 | typedef struct {\r | |
252 | UINT32 Major;\r | |
253 | UINT32 Minor;\r | |
254 | UINT32 MaxReadahead;\r | |
255 | UINT32 Flags;\r | |
256 | UINT16 MaxBackground;\r | |
257 | UINT16 CongestionThreshold;\r | |
258 | UINT32 MaxWrite;\r | |
259 | UINT32 TimeGran;\r | |
260 | UINT16 MaxPages;\r | |
261 | UINT16 MapAlignment;\r | |
262 | UINT32 Unused[8];\r | |
263 | } VIRTIO_FS_FUSE_INIT_RESPONSE;\r | |
264 | \r | |
265 | //\r | |
266 | // Header for VirtioFsFuseOpCreate.\r | |
267 | //\r | |
268 | typedef struct {\r | |
269 | UINT32 Flags;\r | |
270 | UINT32 Mode;\r | |
271 | UINT32 Umask;\r | |
272 | UINT32 Padding;\r | |
273 | } VIRTIO_FS_FUSE_CREATE_REQUEST;\r | |
274 | #pragma pack ()\r | |
275 | \r | |
276 | #endif // VIRTIO_FS_H_\r |