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