]>
Commit | Line | Data |
---|---|---|
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 | |
55 | typedef 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 | |
61 | typedef 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 | |
88 | typedef 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 | |
117 | typedef 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 | |
134 | typedef 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 | |
169 | EFI_STATUS\r | |
170 | VirtioFsInit (\r | |
171 | IN OUT VIRTIO_FS *VirtioFs\r | |
172 | );\r | |
173 | \r | |
174 | VOID\r | |
175 | VirtioFsUninit (\r | |
176 | IN OUT VIRTIO_FS *VirtioFs\r | |
177 | );\r | |
178 | \r | |
179 | VOID\r | |
180 | EFIAPI\r | |
181 | VirtioFsExitBoot (\r | |
182 | IN EFI_EVENT ExitBootEvent,\r | |
183 | IN VOID *VirtioFsAsVoid\r | |
184 | );\r | |
185 | \r | |
6578cacb LE |
186 | EFI_STATUS\r |
187 | VirtioFsSgListsValidate (\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 | |
193 | EFI_STATUS\r | |
194 | VirtioFsSgListsSubmit (\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 |
200 | EFI_STATUS\r |
201 | VirtioFsFuseNewRequest (\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 | |
209 | EFI_STATUS\r | |
210 | VirtioFsFuseCheckResponse (\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 |
216 | EFI_STATUS\r |
217 | VirtioFsErrnoToEfiStatus (\r | |
218 | IN INT32 Errno\r | |
219 | );\r | |
220 | \r | |
9307d7c7 LE |
221 | EFI_STATUS\r |
222 | VirtioFsAppendPath (\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 |
229 | EFI_STATUS\r |
230 | VirtioFsLookupMostSpecificParentDir (\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 |
237 | EFI_STATUS\r |
238 | VirtioFsFuseAttrToEfiFileInfo (\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 |
247 | EFI_STATUS\r |
248 | VirtioFsFuseLookup (\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 |
256 | EFI_STATUS\r |
257 | VirtioFsFuseForget (\r | |
258 | IN OUT VIRTIO_FS *VirtioFs,\r | |
259 | IN UINT64 NodeId\r | |
260 | );\r | |
261 | \r | |
e3bc9577 LE |
262 | EFI_STATUS\r |
263 | VirtioFsFuseGetAttr (\r | |
264 | IN OUT VIRTIO_FS *VirtioFs,\r | |
265 | IN UINT64 NodeId,\r | |
266 | OUT VIRTIO_FS_FUSE_ATTRIBUTES_RESPONSE *FuseAttr\r | |
267 | );\r | |
268 | \r | |
f058cb69 LE |
269 | EFI_STATUS\r |
270 | VirtioFsFuseMkDir (\r | |
271 | IN OUT VIRTIO_FS *VirtioFs,\r | |
272 | IN UINT64 ParentNodeId,\r | |
273 | IN CHAR8 *Name,\r | |
274 | OUT UINT64 *NodeId\r | |
275 | );\r | |
276 | \r | |
0771671c LE |
277 | EFI_STATUS\r |
278 | VirtioFsFuseRemoveFileOrDir (\r | |
279 | IN OUT VIRTIO_FS *VirtioFs,\r | |
280 | IN UINT64 ParentNodeId,\r | |
281 | IN CHAR8 *Name,\r | |
282 | IN BOOLEAN IsDir\r | |
283 | );\r | |
284 | \r | |
da82d2e3 LE |
285 | EFI_STATUS\r |
286 | VirtioFsFuseOpen (\r | |
287 | IN OUT VIRTIO_FS *VirtioFs,\r | |
288 | IN UINT64 NodeId,\r | |
289 | IN BOOLEAN ReadWrite,\r | |
290 | OUT UINT64 *FuseHandle\r | |
291 | );\r | |
292 | \r | |
ba118463 LE |
293 | EFI_STATUS\r |
294 | VirtioFsFuseStatFs (\r | |
295 | IN OUT VIRTIO_FS *VirtioFs,\r | |
296 | IN UINT64 NodeId,\r | |
297 | OUT VIRTIO_FS_FUSE_STATFS_RESPONSE *FilesysAttr\r | |
298 | );\r | |
299 | \r | |
72d4f133 LE |
300 | EFI_STATUS\r |
301 | VirtioFsFuseReleaseFileOrDir (\r | |
302 | IN OUT VIRTIO_FS *VirtioFs,\r | |
303 | IN UINT64 NodeId,\r | |
304 | IN UINT64 FuseHandle,\r | |
305 | IN BOOLEAN IsDir\r | |
306 | );\r | |
307 | \r | |
2e151d26 LE |
308 | EFI_STATUS\r |
309 | VirtioFsFuseFsyncFileOrDir (\r | |
310 | IN OUT VIRTIO_FS *VirtioFs,\r | |
311 | IN UINT64 NodeId,\r | |
312 | IN UINT64 FuseHandle,\r | |
313 | IN BOOLEAN IsDir\r | |
314 | );\r | |
315 | \r | |
d0474399 LE |
316 | EFI_STATUS\r |
317 | VirtioFsFuseFlush (\r | |
318 | IN OUT VIRTIO_FS *VirtioFs,\r | |
319 | IN UINT64 NodeId,\r | |
320 | IN UINT64 FuseHandle\r | |
321 | );\r | |
322 | \r | |
fa97e372 LE |
323 | EFI_STATUS\r |
324 | VirtioFsFuseInitSession (\r | |
325 | IN OUT VIRTIO_FS *VirtioFs\r | |
326 | );\r | |
327 | \r | |
b62a0c56 LE |
328 | EFI_STATUS\r |
329 | VirtioFsFuseOpenDir (\r | |
330 | IN OUT VIRTIO_FS *VirtioFs,\r | |
331 | IN UINT64 NodeId,\r | |
332 | OUT UINT64 *FuseHandle\r | |
333 | );\r | |
334 | \r | |
a70860f4 LE |
335 | EFI_STATUS\r |
336 | VirtioFsFuseOpenOrCreate (\r | |
337 | IN OUT VIRTIO_FS *VirtioFs,\r | |
338 | IN UINT64 ParentNodeId,\r | |
339 | IN CHAR8 *Name,\r | |
340 | OUT UINT64 *NodeId,\r | |
341 | OUT UINT64 *FuseHandle\r | |
342 | );\r | |
343 | \r | |
b55d6622 LE |
344 | //\r |
345 | // EFI_SIMPLE_FILE_SYSTEM_PROTOCOL member functions for the Virtio Filesystem\r | |
346 | // driver.\r | |
347 | //\r | |
348 | \r | |
349 | EFI_STATUS\r | |
350 | EFIAPI\r | |
351 | VirtioFsOpenVolume (\r | |
352 | IN EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *This,\r | |
353 | OUT EFI_FILE_PROTOCOL **Root\r | |
354 | );\r | |
355 | \r | |
334c13e1 LE |
356 | //\r |
357 | // EFI_FILE_PROTOCOL member functions for the Virtio Filesystem driver.\r | |
358 | //\r | |
359 | \r | |
360 | EFI_STATUS\r | |
361 | EFIAPI\r | |
362 | VirtioFsSimpleFileClose (\r | |
363 | IN EFI_FILE_PROTOCOL *This\r | |
364 | );\r | |
365 | \r | |
366 | EFI_STATUS\r | |
367 | EFIAPI\r | |
368 | VirtioFsSimpleFileDelete (\r | |
369 | IN EFI_FILE_PROTOCOL *This\r | |
370 | );\r | |
371 | \r | |
372 | EFI_STATUS\r | |
373 | EFIAPI\r | |
374 | VirtioFsSimpleFileFlush (\r | |
375 | IN EFI_FILE_PROTOCOL *This\r | |
376 | );\r | |
377 | \r | |
378 | EFI_STATUS\r | |
379 | EFIAPI\r | |
380 | VirtioFsSimpleFileGetInfo (\r | |
381 | IN EFI_FILE_PROTOCOL *This,\r | |
382 | IN EFI_GUID *InformationType,\r | |
383 | IN OUT UINTN *BufferSize,\r | |
384 | OUT VOID *Buffer\r | |
385 | );\r | |
386 | \r | |
387 | EFI_STATUS\r | |
388 | EFIAPI\r | |
389 | VirtioFsSimpleFileGetPosition (\r | |
390 | IN EFI_FILE_PROTOCOL *This,\r | |
391 | OUT UINT64 *Position\r | |
392 | );\r | |
393 | \r | |
394 | EFI_STATUS\r | |
395 | EFIAPI\r | |
396 | VirtioFsSimpleFileOpen (\r | |
397 | IN EFI_FILE_PROTOCOL *This,\r | |
398 | OUT EFI_FILE_PROTOCOL **NewHandle,\r | |
399 | IN CHAR16 *FileName,\r | |
400 | IN UINT64 OpenMode,\r | |
401 | IN UINT64 Attributes\r | |
402 | );\r | |
403 | \r | |
404 | EFI_STATUS\r | |
405 | EFIAPI\r | |
406 | VirtioFsSimpleFileRead (\r | |
407 | IN EFI_FILE_PROTOCOL *This,\r | |
408 | IN OUT UINTN *BufferSize,\r | |
409 | OUT VOID *Buffer\r | |
410 | );\r | |
411 | \r | |
412 | EFI_STATUS\r | |
413 | EFIAPI\r | |
414 | VirtioFsSimpleFileSetInfo (\r | |
415 | IN EFI_FILE_PROTOCOL *This,\r | |
416 | IN EFI_GUID *InformationType,\r | |
417 | IN UINTN BufferSize,\r | |
418 | IN VOID *Buffer\r | |
419 | );\r | |
420 | \r | |
421 | EFI_STATUS\r | |
422 | EFIAPI\r | |
423 | VirtioFsSimpleFileSetPosition (\r | |
424 | IN EFI_FILE_PROTOCOL *This,\r | |
425 | IN UINT64 Position\r | |
426 | );\r | |
427 | \r | |
428 | EFI_STATUS\r | |
429 | EFIAPI\r | |
430 | VirtioFsSimpleFileWrite (\r | |
431 | IN EFI_FILE_PROTOCOL *This,\r | |
432 | IN OUT UINTN *BufferSize,\r | |
433 | IN VOID *Buffer\r | |
434 | );\r | |
435 | \r | |
b55d6622 | 436 | #endif // VIRTIO_FS_DXE_H_\r |