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