]> git.proxmox.com Git - mirror_edk2.git/blame - OvmfPkg/Include/IndustryStandard/VirtioFs.h
UefiCpuPkg: Move AsmRelocateApLoopStart from Mpfuncs.nasm to AmdSev.nasm
[mirror_edk2.git] / OvmfPkg / Include / IndustryStandard / VirtioFs.h
CommitLineData
eaa7115d
LE
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
ac0a286f 25#define VIRTIO_FS_REQUEST_QUEUE 1\r
eaa7115d
LE
26\r
27//\r
28// Number of bytes in the "VIRTIO_FS_CONFIG.Tag" field.\r
29//\r
ac0a286f 30#define VIRTIO_FS_TAG_BYTES 36\r
eaa7115d
LE
31\r
32//\r
33// Device configuration layout.\r
34//\r
35#pragma pack (1)\r
36typedef 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
ac0a286f 43 UINT8 Tag[VIRTIO_FS_TAG_BYTES];\r
eaa7115d
LE
44 //\r
45 // The total number of request virtqueues exposed by the device (i.e.,\r
46 // excluding the "hiprio" queue).\r
47 //\r
ac0a286f 48 UINT32 NumReqQueues;\r
eaa7115d
LE
49} VIRTIO_FS_CONFIG;\r
50#pragma pack ()\r
51\r
6a2dc768
LE
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
ac0a286f 77#define VIRTIO_FS_FUSE_MINOR 31\r
6a2dc768 78\r
334c13e1
LE
79//\r
80// The inode number of the root directory.\r
81//\r
ac0a286f 82#define VIRTIO_FS_FUSE_ROOT_DIR_NODE_ID 1\r
334c13e1 83\r
b6ce961a
LE
84//\r
85// Distinguished errno values.\r
86//\r
ac0a286f 87#define VIRTIO_FS_FUSE_ERRNO_ENOENT (-2)\r
b6ce961a 88\r
f058cb69
LE
89//\r
90// File mode bitmasks.\r
91//\r
ac0a286f
MK
92#define VIRTIO_FS_FUSE_MODE_TYPE_MASK 0170000u\r
93#define VIRTIO_FS_FUSE_MODE_TYPE_REG 0100000u\r
94#define VIRTIO_FS_FUSE_MODE_TYPE_DIR 0040000u\r
95#define VIRTIO_FS_FUSE_MODE_PERM_RWXU 0000700u\r
96#define VIRTIO_FS_FUSE_MODE_PERM_RUSR 0000400u\r
97#define VIRTIO_FS_FUSE_MODE_PERM_WUSR 0000200u\r
98#define VIRTIO_FS_FUSE_MODE_PERM_XUSR 0000100u\r
99#define VIRTIO_FS_FUSE_MODE_PERM_RWXG 0000070u\r
100#define VIRTIO_FS_FUSE_MODE_PERM_RGRP 0000040u\r
101#define VIRTIO_FS_FUSE_MODE_PERM_WGRP 0000020u\r
102#define VIRTIO_FS_FUSE_MODE_PERM_XGRP 0000010u\r
103#define VIRTIO_FS_FUSE_MODE_PERM_RWXO 0000007u\r
104#define VIRTIO_FS_FUSE_MODE_PERM_ROTH 0000004u\r
105#define VIRTIO_FS_FUSE_MODE_PERM_WOTH 0000002u\r
106#define VIRTIO_FS_FUSE_MODE_PERM_XOTH 0000001u\r
f058cb69 107\r
647340b0
LE
108//\r
109// Flags for VirtioFsFuseOpSetAttr, in the VIRTIO_FS_FUSE_SETATTR_REQUEST.Valid\r
110// field.\r
111//\r
ac0a286f
MK
112#define VIRTIO_FS_FUSE_SETATTR_REQ_F_MODE BIT0\r
113#define VIRTIO_FS_FUSE_SETATTR_REQ_F_SIZE BIT3\r
114#define VIRTIO_FS_FUSE_SETATTR_REQ_F_ATIME BIT4\r
115#define VIRTIO_FS_FUSE_SETATTR_REQ_F_MTIME BIT5\r
647340b0 116\r
da82d2e3
LE
117//\r
118// Flags for VirtioFsFuseOpOpen.\r
119//\r
ac0a286f
MK
120#define VIRTIO_FS_FUSE_OPEN_REQ_F_RDONLY 0\r
121#define VIRTIO_FS_FUSE_OPEN_REQ_F_RDWR 2\r
da82d2e3 122\r
d98d7e30
LE
123//\r
124// Flags for VirtioFsFuseOpInit.\r
125//\r
ac0a286f 126#define VIRTIO_FS_FUSE_INIT_REQ_F_DO_READDIRPLUS BIT13\r
d98d7e30
LE
127\r
128/**\r
129 Macro for calculating the size of a directory stream entry.\r
130\r
131 The macro may evaluate Namelen multiple times.\r
132\r
133 The macro evaluates to a UINTN value that is safe to cast to UINT32.\r
134\r
135 @param[in] Namelen The size of the filename byte array that follows\r
136 VIRTIO_FS_FUSE_DIRENTPLUS_RESPONSE in the directory\r
137 stream, as reported by\r
138 VIRTIO_FS_FUSE_STATFS_RESPONSE.Namelen or\r
139 VIRTIO_FS_FUSE_DIRENTPLUS_RESPONSE.Namelen. The filename\r
140 byte array is not NUL-terminated.\r
141\r
142 @retval 0 Namelen was zero or greater than SIZE_4KB.\r
143\r
144 @return The number of bytes in the directory entry, including the\r
145 VIRTIO_FS_FUSE_DIRENTPLUS_RESPONSE header.\r
146**/\r
147#define VIRTIO_FS_FUSE_DIRENTPLUS_RESPONSE_SIZE(Namelen) \\r
148 ((Namelen) == 0 || (Namelen) > SIZE_4KB ? \\r
149 (UINTN)0 : \\r
150 ALIGN_VALUE ( \\r
151 sizeof (VIRTIO_FS_FUSE_DIRENTPLUS_RESPONSE) + (UINTN)(Namelen), \\r
152 sizeof (UINT64) \\r
153 ) \\r
154 )\r
155\r
bea1f51d
LE
156//\r
157// Flags for VirtioFsFuseOpRename2.\r
158//\r
ac0a286f 159#define VIRTIO_FS_FUSE_RENAME2_REQ_F_NOREPLACE BIT0\r
bea1f51d 160\r
fa97e372
LE
161//\r
162// FUSE operation codes.\r
163//\r
164typedef enum {\r
b6ce961a 165 VirtioFsFuseOpLookup = 1,\r
92a4d30e 166 VirtioFsFuseOpForget = 2,\r
e3bc9577 167 VirtioFsFuseOpGetAttr = 3,\r
647340b0 168 VirtioFsFuseOpSetAttr = 4,\r
f058cb69 169 VirtioFsFuseOpMkDir = 9,\r
0771671c
LE
170 VirtioFsFuseOpUnlink = 10,\r
171 VirtioFsFuseOpRmDir = 11,\r
da82d2e3 172 VirtioFsFuseOpOpen = 14,\r
d98d7e30 173 VirtioFsFuseOpRead = 15,\r
6f7bc719 174 VirtioFsFuseOpWrite = 16,\r
ba118463 175 VirtioFsFuseOpStatFs = 17,\r
72d4f133 176 VirtioFsFuseOpRelease = 18,\r
2e151d26 177 VirtioFsFuseOpFsync = 20,\r
d0474399 178 VirtioFsFuseOpFlush = 25,\r
fa97e372 179 VirtioFsFuseOpInit = 26,\r
b62a0c56 180 VirtioFsFuseOpOpenDir = 27,\r
72d4f133 181 VirtioFsFuseOpReleaseDir = 29,\r
2e151d26 182 VirtioFsFuseOpFsyncDir = 30,\r
a70860f4 183 VirtioFsFuseOpCreate = 35,\r
d98d7e30 184 VirtioFsFuseOpReadDirPlus = 44,\r
bea1f51d 185 VirtioFsFuseOpRename2 = 45,\r
fa97e372
LE
186} VIRTIO_FS_FUSE_OPCODE;\r
187\r
6a2dc768
LE
188#pragma pack (1)\r
189//\r
190// Request-response headers common to all request types.\r
191//\r
192typedef struct {\r
ac0a286f
MK
193 UINT32 Len;\r
194 UINT32 Opcode;\r
195 UINT64 Unique;\r
196 UINT64 NodeId;\r
197 UINT32 Uid;\r
198 UINT32 Gid;\r
199 UINT32 Pid;\r
200 UINT32 Padding;\r
6a2dc768
LE
201} VIRTIO_FS_FUSE_REQUEST;\r
202\r
203typedef struct {\r
ac0a286f
MK
204 UINT32 Len;\r
205 INT32 Error;\r
206 UINT64 Unique;\r
6a2dc768 207} VIRTIO_FS_FUSE_RESPONSE;\r
fa97e372 208\r
f058cb69
LE
209//\r
210// Structure with which the Virtio Filesystem device reports a NodeId to the\r
211// FUSE client (i.e., to the Virtio Filesystem driver). This structure is a\r
212// part of the response headers for operations that inform the FUSE client of\r
213// an inode.\r
214//\r
215typedef struct {\r
ac0a286f
MK
216 UINT64 NodeId;\r
217 UINT64 Generation;\r
218 UINT64 EntryValid;\r
219 UINT64 AttrValid;\r
220 UINT32 EntryValidNsec;\r
221 UINT32 AttrValidNsec;\r
f058cb69
LE
222} VIRTIO_FS_FUSE_NODE_RESPONSE;\r
223\r
224//\r
225// Structure describing the host-side attributes of an inode. This structure is\r
226// a part of the response headers for operations that inform the FUSE client of\r
227// an inode.\r
228//\r
229typedef struct {\r
ac0a286f
MK
230 UINT64 Ino;\r
231 UINT64 Size;\r
232 UINT64 Blocks;\r
233 UINT64 Atime;\r
234 UINT64 Mtime;\r
235 UINT64 Ctime;\r
236 UINT32 AtimeNsec;\r
237 UINT32 MtimeNsec;\r
238 UINT32 CtimeNsec;\r
239 UINT32 Mode;\r
240 UINT32 Nlink;\r
241 UINT32 Uid;\r
242 UINT32 Gid;\r
243 UINT32 Rdev;\r
244 UINT32 Blksize;\r
245 UINT32 Padding;\r
f058cb69
LE
246} VIRTIO_FS_FUSE_ATTRIBUTES_RESPONSE;\r
247\r
92a4d30e
LE
248//\r
249// Header for VirtioFsFuseOpForget.\r
250//\r
251typedef struct {\r
ac0a286f 252 UINT64 NumberOfLookups;\r
92a4d30e
LE
253} VIRTIO_FS_FUSE_FORGET_REQUEST;\r
254\r
e3bc9577 255//\r
647340b0
LE
256// Headers for VirtioFsFuseOpGetAttr (VIRTIO_FS_FUSE_GETATTR_RESPONSE is also\r
257// for VirtioFsFuseOpSetAttr).\r
e3bc9577
LE
258//\r
259typedef struct {\r
ac0a286f
MK
260 UINT32 GetAttrFlags;\r
261 UINT32 Dummy;\r
262 UINT64 FileHandle;\r
e3bc9577
LE
263} VIRTIO_FS_FUSE_GETATTR_REQUEST;\r
264\r
265typedef struct {\r
ac0a286f
MK
266 UINT64 AttrValid;\r
267 UINT32 AttrValidNsec;\r
268 UINT32 Dummy;\r
e3bc9577
LE
269} VIRTIO_FS_FUSE_GETATTR_RESPONSE;\r
270\r
647340b0
LE
271//\r
272// Header for VirtioFsFuseOpSetAttr.\r
273//\r
274typedef struct {\r
ac0a286f
MK
275 UINT32 Valid;\r
276 UINT32 Padding;\r
277 UINT64 FileHandle;\r
278 UINT64 Size;\r
279 UINT64 LockOwner;\r
280 UINT64 Atime;\r
281 UINT64 Mtime;\r
282 UINT64 Ctime;\r
283 UINT32 AtimeNsec;\r
284 UINT32 MtimeNsec;\r
285 UINT32 CtimeNsec;\r
286 UINT32 Mode;\r
287 UINT32 Unused4;\r
288 UINT32 Uid;\r
289 UINT32 Gid;\r
290 UINT32 Unused5;\r
647340b0
LE
291} VIRTIO_FS_FUSE_SETATTR_REQUEST;\r
292\r
f058cb69
LE
293//\r
294// Header for VirtioFsFuseOpMkDir.\r
295//\r
296typedef struct {\r
ac0a286f
MK
297 UINT32 Mode;\r
298 UINT32 Umask;\r
f058cb69
LE
299} VIRTIO_FS_FUSE_MKDIR_REQUEST;\r
300\r
da82d2e3
LE
301//\r
302// Headers for VirtioFsFuseOpOpen and VirtioFsFuseOpOpenDir.\r
303//\r
304typedef struct {\r
ac0a286f
MK
305 UINT32 Flags;\r
306 UINT32 Unused;\r
da82d2e3
LE
307} VIRTIO_FS_FUSE_OPEN_REQUEST;\r
308\r
309typedef struct {\r
ac0a286f
MK
310 UINT64 FileHandle;\r
311 UINT32 OpenFlags;\r
312 UINT32 Padding;\r
da82d2e3
LE
313} VIRTIO_FS_FUSE_OPEN_RESPONSE;\r
314\r
d98d7e30
LE
315//\r
316// Header for VirtioFsFuseOpRead and VirtioFsFuseOpReadDirPlus.\r
317//\r
318typedef struct {\r
ac0a286f
MK
319 UINT64 FileHandle;\r
320 UINT64 Offset;\r
321 UINT32 Size;\r
322 UINT32 ReadFlags;\r
323 UINT64 LockOwner;\r
324 UINT32 Flags;\r
325 UINT32 Padding;\r
d98d7e30
LE
326} VIRTIO_FS_FUSE_READ_REQUEST;\r
327\r
6f7bc719
LE
328//\r
329// Headers for VirtioFsFuseOpWrite.\r
330//\r
331typedef struct {\r
ac0a286f
MK
332 UINT64 FileHandle;\r
333 UINT64 Offset;\r
334 UINT32 Size;\r
335 UINT32 WriteFlags;\r
336 UINT64 LockOwner;\r
337 UINT32 Flags;\r
338 UINT32 Padding;\r
6f7bc719
LE
339} VIRTIO_FS_FUSE_WRITE_REQUEST;\r
340\r
341typedef struct {\r
ac0a286f
MK
342 UINT32 Size;\r
343 UINT32 Padding;\r
6f7bc719
LE
344} VIRTIO_FS_FUSE_WRITE_RESPONSE;\r
345\r
ba118463
LE
346//\r
347// Header for VirtioFsFuseOpStatFs.\r
348//\r
349typedef struct {\r
ac0a286f
MK
350 UINT64 Blocks;\r
351 UINT64 Bfree;\r
352 UINT64 Bavail;\r
353 UINT64 Files;\r
354 UINT64 Ffree;\r
355 UINT32 Bsize;\r
356 UINT32 Namelen;\r
357 UINT32 Frsize;\r
358 UINT32 Padding;\r
359 UINT32 Spare[6];\r
ba118463
LE
360} VIRTIO_FS_FUSE_STATFS_RESPONSE;\r
361\r
72d4f133
LE
362//\r
363// Header for VirtioFsFuseOpRelease and VirtioFsFuseOpReleaseDir.\r
364//\r
365typedef struct {\r
ac0a286f
MK
366 UINT64 FileHandle;\r
367 UINT32 Flags;\r
368 UINT32 ReleaseFlags;\r
369 UINT64 LockOwner;\r
72d4f133
LE
370} VIRTIO_FS_FUSE_RELEASE_REQUEST;\r
371\r
2e151d26
LE
372//\r
373// Header for VirtioFsFuseOpFsync and VirtioFsFuseOpFsyncDir.\r
374//\r
375typedef struct {\r
ac0a286f
MK
376 UINT64 FileHandle;\r
377 UINT32 FsyncFlags;\r
378 UINT32 Padding;\r
2e151d26
LE
379} VIRTIO_FS_FUSE_FSYNC_REQUEST;\r
380\r
d0474399
LE
381//\r
382// Header for VirtioFsFuseOpFlush.\r
383//\r
384typedef struct {\r
ac0a286f
MK
385 UINT64 FileHandle;\r
386 UINT32 Unused;\r
387 UINT32 Padding;\r
388 UINT64 LockOwner;\r
d0474399
LE
389} VIRTIO_FS_FUSE_FLUSH_REQUEST;\r
390\r
fa97e372
LE
391//\r
392// Headers for VirtioFsFuseOpInit.\r
393//\r
394typedef struct {\r
ac0a286f
MK
395 UINT32 Major;\r
396 UINT32 Minor;\r
397 UINT32 MaxReadahead;\r
398 UINT32 Flags;\r
fa97e372
LE
399} VIRTIO_FS_FUSE_INIT_REQUEST;\r
400\r
401typedef struct {\r
ac0a286f
MK
402 UINT32 Major;\r
403 UINT32 Minor;\r
404 UINT32 MaxReadahead;\r
405 UINT32 Flags;\r
406 UINT16 MaxBackground;\r
407 UINT16 CongestionThreshold;\r
408 UINT32 MaxWrite;\r
409 UINT32 TimeGran;\r
410 UINT16 MaxPages;\r
411 UINT16 MapAlignment;\r
412 UINT32 Unused[8];\r
fa97e372 413} VIRTIO_FS_FUSE_INIT_RESPONSE;\r
a70860f4
LE
414\r
415//\r
416// Header for VirtioFsFuseOpCreate.\r
417//\r
418typedef struct {\r
ac0a286f
MK
419 UINT32 Flags;\r
420 UINT32 Mode;\r
421 UINT32 Umask;\r
422 UINT32 Padding;\r
a70860f4 423} VIRTIO_FS_FUSE_CREATE_REQUEST;\r
d98d7e30
LE
424\r
425//\r
426// Header for VirtioFsFuseOpReadDirPlus.\r
427//\r
428// Diverging from the rest of the headers, this structure embeds other\r
429// structures. The reason is that a scatter list cannot be used to receive\r
430// NodeResp and AttrResp separately; the record below is followed by a variable\r
431// size filename byte array, and then such pairs are repeated a number of\r
432// times. Thus, later header start offsets depend on earlier filename array\r
433// sizes.\r
434//\r
435typedef struct {\r
ac0a286f
MK
436 VIRTIO_FS_FUSE_NODE_RESPONSE NodeResp;\r
437 VIRTIO_FS_FUSE_ATTRIBUTES_RESPONSE AttrResp;\r
438 UINT64 NodeId;\r
439 UINT64 CookieForNextEntry;\r
440 UINT32 Namelen;\r
441 UINT32 Type;\r
d98d7e30 442} VIRTIO_FS_FUSE_DIRENTPLUS_RESPONSE;\r
bea1f51d
LE
443\r
444//\r
445// Header for VirtioFsFuseOpRename2.\r
446//\r
447typedef struct {\r
ac0a286f
MK
448 UINT64 NewDir;\r
449 UINT32 Flags;\r
450 UINT32 Padding;\r
bea1f51d 451} VIRTIO_FS_FUSE_RENAME2_REQUEST;\r
6a2dc768
LE
452#pragma pack ()\r
453\r
eaa7115d 454#endif // VIRTIO_FS_H_\r