]> git.proxmox.com Git - mirror_edk2.git/blame - OvmfPkg/VirtioFsDxe/VirtioFsDxe.h
OvmfPkg/VirtioFsDxe: implement the wrapper function for FUSE_CREATE
[mirror_edk2.git] / OvmfPkg / VirtioFsDxe / VirtioFsDxe.h
CommitLineData
b55d6622
LE
1/** @file\r
2 Internal macro definitions, type definitions, and function declarations for\r
3 the Virtio Filesystem device driver.\r
4\r
5 Copyright (C) 2020, Red Hat, Inc.\r
6\r
7 SPDX-License-Identifier: BSD-2-Clause-Patent\r
8**/\r
9\r
10#ifndef VIRTIO_FS_DXE_H_\r
11#define VIRTIO_FS_DXE_H_\r
12\r
13#include <Base.h> // SIGNATURE_64()\r
eaa7115d 14#include <IndustryStandard/VirtioFs.h> // VIRTIO_FS_TAG_BYTES\r
b55d6622
LE
15#include <Library/DebugLib.h> // CR()\r
16#include <Protocol/SimpleFileSystem.h> // EFI_SIMPLE_FILE_SYSTEM_PROTOCOL\r
17#include <Protocol/VirtioDevice.h> // VIRTIO_DEVICE_PROTOCOL\r
eaa7115d 18#include <Uefi/UefiBaseType.h> // EFI_EVENT\r
b55d6622
LE
19\r
20#define VIRTIO_FS_SIG SIGNATURE_64 ('V', 'I', 'R', 'T', 'I', 'O', 'F', 'S')\r
21\r
334c13e1
LE
22#define VIRTIO_FS_FILE_SIG \\r
23 SIGNATURE_64 ('V', 'I', 'O', 'F', 'S', 'F', 'I', 'L')\r
24\r
9307d7c7
LE
25//\r
26// The following limit applies to two kinds of pathnames.\r
27//\r
28// - The length of a POSIX-style, canonical pathname *at rest* never exceeds\r
29// VIRTIO_FS_MAX_PATHNAME_LENGTH. (Length is defined as the number of CHAR8\r
30// elements in the canonical pathname, excluding the terminating '\0'.) This\r
31// is an invariant that is ensured for canonical pathnames created, and that\r
32// is assumed about canonical pathname inputs (which all originate\r
33// internally).\r
34//\r
35// - If the length of a UEFI-style pathname *argument*, originating directly or\r
36// indirectly from the EFI_FILE_PROTOCOL caller, exceeds\r
37// VIRTIO_FS_MAX_PATHNAME_LENGTH, then the argument is rejected. (Length is\r
38// defined as the number of CHAR16 elements in the UEFI-style pathname,\r
39// excluding the terminating L'\0'.) This is a restriction that's checked on\r
40// external UEFI-style pathname inputs.\r
41//\r
42// The limit is not expected to be a practical limitation; it's only supposed\r
43// to prevent attempts at overflowing size calculations. For both kinds of\r
44// pathnames, separate limits could be used; a common limit is used purely for\r
45// simplicity.\r
46//\r
47#define VIRTIO_FS_MAX_PATHNAME_LENGTH ((UINTN)65535)\r
48\r
eaa7115d
LE
49//\r
50// Filesystem label encoded in UCS-2, transformed from the UTF-8 representation\r
51// in "VIRTIO_FS_CONFIG.Tag", and NUL-terminated. Only the printable ASCII code\r
52// points (U+0020 through U+007E) are supported.\r
53//\r
54typedef CHAR16 VIRTIO_FS_LABEL[VIRTIO_FS_TAG_BYTES + 1];\r
55\r
b55d6622
LE
56//\r
57// Main context structure, expressing an EFI_SIMPLE_FILE_SYSTEM_PROTOCOL\r
58// interface on top of the Virtio Filesystem device.\r
59//\r
60typedef struct {\r
61 //\r
62 // Parts of this structure are initialized / torn down in various functions\r
63 // at various call depths. The table to the right should make it easier to\r
64 // track them.\r
65 //\r
66 // field init function init depth\r
67 // ----------- ------------------ ----------\r
68 UINT64 Signature; // DriverBindingStart 0\r
69 VIRTIO_DEVICE_PROTOCOL *Virtio; // DriverBindingStart 0\r
eaa7115d
LE
70 VIRTIO_FS_LABEL Label; // VirtioFsInit 1\r
71 UINT16 QueueSize; // VirtioFsInit 1\r
72 VRING Ring; // VirtioRingInit 2\r
73 VOID *RingMap; // VirtioRingMap 2\r
fa97e372 74 UINT64 RequestId; // FuseInitSession 1\r
eaa7115d 75 EFI_EVENT ExitBoot; // DriverBindingStart 0\r
334c13e1 76 LIST_ENTRY OpenFiles; // DriverBindingStart 0\r
b55d6622
LE
77 EFI_SIMPLE_FILE_SYSTEM_PROTOCOL SimpleFs; // DriverBindingStart 0\r
78} VIRTIO_FS;\r
79\r
80#define VIRTIO_FS_FROM_SIMPLE_FS(SimpleFsReference) \\r
81 CR (SimpleFsReference, VIRTIO_FS, SimpleFs, VIRTIO_FS_SIG);\r
82\r
6578cacb
LE
83//\r
84// Structure for describing a contiguous buffer, potentially mapped for Virtio\r
85// transfer.\r
86//\r
87typedef struct {\r
88 //\r
89 // The following fields originate from the owner of the buffer.\r
90 //\r
91 VOID *Buffer;\r
92 UINTN Size;\r
93 //\r
94 // All of the fields below, until the end of the structure, are\r
95 // zero-initialized when the structure is initially validated.\r
96 //\r
97 // Mapped, MappedAddress and Mapping are updated when the buffer is mapped\r
98 // for VirtioOperationBusMasterRead or VirtioOperationBusMasterWrite. They\r
99 // are again updated when the buffer is unmapped.\r
100 //\r
101 BOOLEAN Mapped;\r
102 EFI_PHYSICAL_ADDRESS MappedAddress;\r
103 VOID *Mapping;\r
104 //\r
105 // Transferred is updated after VirtioFlush() returns successfully:\r
106 // - for VirtioOperationBusMasterRead, Transferred is set to Size;\r
107 // - for VirtioOperationBusMasterWrite, Transferred is calculated from the\r
108 // UsedLen output parameter of VirtioFlush().\r
109 //\r
110 UINTN Transferred;\r
111} VIRTIO_FS_IO_VECTOR;\r
112\r
113//\r
114// Structure for describing a list of IO Vectors.\r
115//\r
116typedef struct {\r
117 //\r
118 // The following fields originate from the owner of the buffers.\r
119 //\r
120 VIRTIO_FS_IO_VECTOR *IoVec;\r
121 UINTN NumVec;\r
122 //\r
123 // TotalSize is calculated when the scatter-gather list is initially\r
124 // validated.\r
125 //\r
126 UINT32 TotalSize;\r
127} VIRTIO_FS_SCATTER_GATHER_LIST;\r
128\r
334c13e1
LE
129//\r
130// Private context structure that exposes EFI_FILE_PROTOCOL on top of an open\r
131// FUSE file reference.\r
132//\r
133typedef struct {\r
134 UINT64 Signature;\r
135 EFI_FILE_PROTOCOL SimpleFile;\r
136 BOOLEAN IsDirectory;\r
28092a39 137 BOOLEAN IsOpenForWriting;\r
334c13e1
LE
138 VIRTIO_FS *OwnerFs;\r
139 LIST_ENTRY OpenFilesEntry;\r
7e8c83f7 140 CHAR8 *CanonicalPathname;\r
334c13e1
LE
141 //\r
142 // In the FUSE wire protocol, every request except FUSE_INIT refers to a\r
143 // file, namely by the "VIRTIO_FS_FUSE_REQUEST.NodeId" field; that is, by the\r
144 // inode number of the file. However, some of the FUSE requests that we need\r
145 // for some of the EFI_FILE_PROTOCOL member functions require an open file\r
146 // handle *in addition* to the inode number. For simplicity, whenever a\r
147 // VIRTIO_FS_FILE object is created, primarily defined by its NodeId field,\r
148 // we also *open* the referenced file at once, and save the returned file\r
149 // handle in the FuseHandle field. This way, when an EFI_FILE_PROTOCOL member\r
150 // function must send a FUSE request that needs the file handle *in addition*\r
151 // to the inode number, FuseHandle will be at our disposal at once.\r
152 //\r
153 UINT64 NodeId;\r
154 UINT64 FuseHandle;\r
155} VIRTIO_FS_FILE;\r
156\r
157#define VIRTIO_FS_FILE_FROM_SIMPLE_FILE(SimpleFileReference) \\r
158 CR (SimpleFileReference, VIRTIO_FS_FILE, SimpleFile, VIRTIO_FS_FILE_SIG);\r
159\r
160#define VIRTIO_FS_FILE_FROM_OPEN_FILES_ENTRY(OpenFilesEntryReference) \\r
161 CR (OpenFilesEntryReference, VIRTIO_FS_FILE, OpenFilesEntry, \\r
162 VIRTIO_FS_FILE_SIG);\r
163\r
eaa7115d
LE
164//\r
165// Initialization and helper routines for the Virtio Filesystem device.\r
166//\r
167\r
168EFI_STATUS\r
169VirtioFsInit (\r
170 IN OUT VIRTIO_FS *VirtioFs\r
171 );\r
172\r
173VOID\r
174VirtioFsUninit (\r
175 IN OUT VIRTIO_FS *VirtioFs\r
176 );\r
177\r
178VOID\r
179EFIAPI\r
180VirtioFsExitBoot (\r
181 IN EFI_EVENT ExitBootEvent,\r
182 IN VOID *VirtioFsAsVoid\r
183 );\r
184\r
6578cacb
LE
185EFI_STATUS\r
186VirtioFsSgListsValidate (\r
187 IN VIRTIO_FS *VirtioFs,\r
188 IN OUT VIRTIO_FS_SCATTER_GATHER_LIST *RequestSgList,\r
189 IN OUT VIRTIO_FS_SCATTER_GATHER_LIST *ResponseSgList OPTIONAL\r
190 );\r
191\r
192EFI_STATUS\r
193VirtioFsSgListsSubmit (\r
194 IN OUT VIRTIO_FS *VirtioFs,\r
195 IN OUT VIRTIO_FS_SCATTER_GATHER_LIST *RequestSgList,\r
196 IN OUT VIRTIO_FS_SCATTER_GATHER_LIST *ResponseSgList OPTIONAL\r
197 );\r
198\r
6a2dc768
LE
199EFI_STATUS\r
200VirtioFsFuseNewRequest (\r
201 IN OUT VIRTIO_FS *VirtioFs,\r
202 OUT VIRTIO_FS_FUSE_REQUEST *Request,\r
203 IN UINT32 RequestSize,\r
fa97e372 204 IN VIRTIO_FS_FUSE_OPCODE Opcode,\r
6a2dc768
LE
205 IN UINT64 NodeId\r
206 );\r
207\r
208EFI_STATUS\r
209VirtioFsFuseCheckResponse (\r
210 IN VIRTIO_FS_SCATTER_GATHER_LIST *ResponseSgList,\r
211 IN UINT64 RequestId,\r
212 OUT UINTN *TailBufferFill\r
213 );\r
214\r
e8a74c9a
LE
215EFI_STATUS\r
216VirtioFsErrnoToEfiStatus (\r
217 IN INT32 Errno\r
218 );\r
219\r
9307d7c7
LE
220EFI_STATUS\r
221VirtioFsAppendPath (\r
222 IN CHAR8 *LhsPath8,\r
223 IN CHAR16 *RhsPath16,\r
224 OUT CHAR8 **ResultPath8,\r
225 OUT BOOLEAN *RootEscape\r
226 );\r
227\r
fa97e372
LE
228//\r
229// Wrapper functions for FUSE commands (primitives).\r
230//\r
231\r
92a4d30e
LE
232EFI_STATUS\r
233VirtioFsFuseForget (\r
234 IN OUT VIRTIO_FS *VirtioFs,\r
235 IN UINT64 NodeId\r
236 );\r
237\r
f058cb69
LE
238EFI_STATUS\r
239VirtioFsFuseMkDir (\r
240 IN OUT VIRTIO_FS *VirtioFs,\r
241 IN UINT64 ParentNodeId,\r
242 IN CHAR8 *Name,\r
243 OUT UINT64 *NodeId\r
244 );\r
245\r
da82d2e3
LE
246EFI_STATUS\r
247VirtioFsFuseOpen (\r
248 IN OUT VIRTIO_FS *VirtioFs,\r
249 IN UINT64 NodeId,\r
250 IN BOOLEAN ReadWrite,\r
251 OUT UINT64 *FuseHandle\r
252 );\r
253\r
72d4f133
LE
254EFI_STATUS\r
255VirtioFsFuseReleaseFileOrDir (\r
256 IN OUT VIRTIO_FS *VirtioFs,\r
257 IN UINT64 NodeId,\r
258 IN UINT64 FuseHandle,\r
259 IN BOOLEAN IsDir\r
260 );\r
261\r
2e151d26
LE
262EFI_STATUS\r
263VirtioFsFuseFsyncFileOrDir (\r
264 IN OUT VIRTIO_FS *VirtioFs,\r
265 IN UINT64 NodeId,\r
266 IN UINT64 FuseHandle,\r
267 IN BOOLEAN IsDir\r
268 );\r
269\r
d0474399
LE
270EFI_STATUS\r
271VirtioFsFuseFlush (\r
272 IN OUT VIRTIO_FS *VirtioFs,\r
273 IN UINT64 NodeId,\r
274 IN UINT64 FuseHandle\r
275 );\r
276\r
fa97e372
LE
277EFI_STATUS\r
278VirtioFsFuseInitSession (\r
279 IN OUT VIRTIO_FS *VirtioFs\r
280 );\r
281\r
b62a0c56
LE
282EFI_STATUS\r
283VirtioFsFuseOpenDir (\r
284 IN OUT VIRTIO_FS *VirtioFs,\r
285 IN UINT64 NodeId,\r
286 OUT UINT64 *FuseHandle\r
287 );\r
288\r
a70860f4
LE
289EFI_STATUS\r
290VirtioFsFuseOpenOrCreate (\r
291 IN OUT VIRTIO_FS *VirtioFs,\r
292 IN UINT64 ParentNodeId,\r
293 IN CHAR8 *Name,\r
294 OUT UINT64 *NodeId,\r
295 OUT UINT64 *FuseHandle\r
296 );\r
297\r
b55d6622
LE
298//\r
299// EFI_SIMPLE_FILE_SYSTEM_PROTOCOL member functions for the Virtio Filesystem\r
300// driver.\r
301//\r
302\r
303EFI_STATUS\r
304EFIAPI\r
305VirtioFsOpenVolume (\r
306 IN EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *This,\r
307 OUT EFI_FILE_PROTOCOL **Root\r
308 );\r
309\r
334c13e1
LE
310//\r
311// EFI_FILE_PROTOCOL member functions for the Virtio Filesystem driver.\r
312//\r
313\r
314EFI_STATUS\r
315EFIAPI\r
316VirtioFsSimpleFileClose (\r
317 IN EFI_FILE_PROTOCOL *This\r
318 );\r
319\r
320EFI_STATUS\r
321EFIAPI\r
322VirtioFsSimpleFileDelete (\r
323 IN EFI_FILE_PROTOCOL *This\r
324 );\r
325\r
326EFI_STATUS\r
327EFIAPI\r
328VirtioFsSimpleFileFlush (\r
329 IN EFI_FILE_PROTOCOL *This\r
330 );\r
331\r
332EFI_STATUS\r
333EFIAPI\r
334VirtioFsSimpleFileGetInfo (\r
335 IN EFI_FILE_PROTOCOL *This,\r
336 IN EFI_GUID *InformationType,\r
337 IN OUT UINTN *BufferSize,\r
338 OUT VOID *Buffer\r
339 );\r
340\r
341EFI_STATUS\r
342EFIAPI\r
343VirtioFsSimpleFileGetPosition (\r
344 IN EFI_FILE_PROTOCOL *This,\r
345 OUT UINT64 *Position\r
346 );\r
347\r
348EFI_STATUS\r
349EFIAPI\r
350VirtioFsSimpleFileOpen (\r
351 IN EFI_FILE_PROTOCOL *This,\r
352 OUT EFI_FILE_PROTOCOL **NewHandle,\r
353 IN CHAR16 *FileName,\r
354 IN UINT64 OpenMode,\r
355 IN UINT64 Attributes\r
356 );\r
357\r
358EFI_STATUS\r
359EFIAPI\r
360VirtioFsSimpleFileRead (\r
361 IN EFI_FILE_PROTOCOL *This,\r
362 IN OUT UINTN *BufferSize,\r
363 OUT VOID *Buffer\r
364 );\r
365\r
366EFI_STATUS\r
367EFIAPI\r
368VirtioFsSimpleFileSetInfo (\r
369 IN EFI_FILE_PROTOCOL *This,\r
370 IN EFI_GUID *InformationType,\r
371 IN UINTN BufferSize,\r
372 IN VOID *Buffer\r
373 );\r
374\r
375EFI_STATUS\r
376EFIAPI\r
377VirtioFsSimpleFileSetPosition (\r
378 IN EFI_FILE_PROTOCOL *This,\r
379 IN UINT64 Position\r
380 );\r
381\r
382EFI_STATUS\r
383EFIAPI\r
384VirtioFsSimpleFileWrite (\r
385 IN EFI_FILE_PROTOCOL *This,\r
386 IN OUT UINTN *BufferSize,\r
387 IN VOID *Buffer\r
388 );\r
389\r
b55d6622 390#endif // VIRTIO_FS_DXE_H_\r