]> git.proxmox.com Git - mirror_edk2.git/blame - OvmfPkg/VirtioFsDxe/VirtioFsDxe.h
OvmfPkg/VirtioFsDxe: manage path lifecycle in OpenVolume, Close, Delete
[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
72d4f133
LE
238EFI_STATUS\r
239VirtioFsFuseReleaseFileOrDir (\r
240 IN OUT VIRTIO_FS *VirtioFs,\r
241 IN UINT64 NodeId,\r
242 IN UINT64 FuseHandle,\r
243 IN BOOLEAN IsDir\r
244 );\r
245\r
2e151d26
LE
246EFI_STATUS\r
247VirtioFsFuseFsyncFileOrDir (\r
248 IN OUT VIRTIO_FS *VirtioFs,\r
249 IN UINT64 NodeId,\r
250 IN UINT64 FuseHandle,\r
251 IN BOOLEAN IsDir\r
252 );\r
253\r
d0474399
LE
254EFI_STATUS\r
255VirtioFsFuseFlush (\r
256 IN OUT VIRTIO_FS *VirtioFs,\r
257 IN UINT64 NodeId,\r
258 IN UINT64 FuseHandle\r
259 );\r
260\r
fa97e372
LE
261EFI_STATUS\r
262VirtioFsFuseInitSession (\r
263 IN OUT VIRTIO_FS *VirtioFs\r
264 );\r
265\r
b62a0c56
LE
266EFI_STATUS\r
267VirtioFsFuseOpenDir (\r
268 IN OUT VIRTIO_FS *VirtioFs,\r
269 IN UINT64 NodeId,\r
270 OUT UINT64 *FuseHandle\r
271 );\r
272\r
b55d6622
LE
273//\r
274// EFI_SIMPLE_FILE_SYSTEM_PROTOCOL member functions for the Virtio Filesystem\r
275// driver.\r
276//\r
277\r
278EFI_STATUS\r
279EFIAPI\r
280VirtioFsOpenVolume (\r
281 IN EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *This,\r
282 OUT EFI_FILE_PROTOCOL **Root\r
283 );\r
284\r
334c13e1
LE
285//\r
286// EFI_FILE_PROTOCOL member functions for the Virtio Filesystem driver.\r
287//\r
288\r
289EFI_STATUS\r
290EFIAPI\r
291VirtioFsSimpleFileClose (\r
292 IN EFI_FILE_PROTOCOL *This\r
293 );\r
294\r
295EFI_STATUS\r
296EFIAPI\r
297VirtioFsSimpleFileDelete (\r
298 IN EFI_FILE_PROTOCOL *This\r
299 );\r
300\r
301EFI_STATUS\r
302EFIAPI\r
303VirtioFsSimpleFileFlush (\r
304 IN EFI_FILE_PROTOCOL *This\r
305 );\r
306\r
307EFI_STATUS\r
308EFIAPI\r
309VirtioFsSimpleFileGetInfo (\r
310 IN EFI_FILE_PROTOCOL *This,\r
311 IN EFI_GUID *InformationType,\r
312 IN OUT UINTN *BufferSize,\r
313 OUT VOID *Buffer\r
314 );\r
315\r
316EFI_STATUS\r
317EFIAPI\r
318VirtioFsSimpleFileGetPosition (\r
319 IN EFI_FILE_PROTOCOL *This,\r
320 OUT UINT64 *Position\r
321 );\r
322\r
323EFI_STATUS\r
324EFIAPI\r
325VirtioFsSimpleFileOpen (\r
326 IN EFI_FILE_PROTOCOL *This,\r
327 OUT EFI_FILE_PROTOCOL **NewHandle,\r
328 IN CHAR16 *FileName,\r
329 IN UINT64 OpenMode,\r
330 IN UINT64 Attributes\r
331 );\r
332\r
333EFI_STATUS\r
334EFIAPI\r
335VirtioFsSimpleFileRead (\r
336 IN EFI_FILE_PROTOCOL *This,\r
337 IN OUT UINTN *BufferSize,\r
338 OUT VOID *Buffer\r
339 );\r
340\r
341EFI_STATUS\r
342EFIAPI\r
343VirtioFsSimpleFileSetInfo (\r
344 IN EFI_FILE_PROTOCOL *This,\r
345 IN EFI_GUID *InformationType,\r
346 IN UINTN BufferSize,\r
347 IN VOID *Buffer\r
348 );\r
349\r
350EFI_STATUS\r
351EFIAPI\r
352VirtioFsSimpleFileSetPosition (\r
353 IN EFI_FILE_PROTOCOL *This,\r
354 IN UINT64 Position\r
355 );\r
356\r
357EFI_STATUS\r
358EFIAPI\r
359VirtioFsSimpleFileWrite (\r
360 IN EFI_FILE_PROTOCOL *This,\r
361 IN OUT UINTN *BufferSize,\r
362 IN VOID *Buffer\r
363 );\r
364\r
b55d6622 365#endif // VIRTIO_FS_DXE_H_\r