TianoCore EDK2 master
Loading...
Searching...
No Matches
SimpleFsOpenVolume.c
Go to the documentation of this file.
1
10#include <Library/BaseLib.h> // InsertTailList()
11#include <Library/MemoryAllocationLib.h> // AllocatePool()
12
13#include "VirtioFsDxe.h"
14
22EFIAPI
26 )
27{
28 VIRTIO_FS *VirtioFs;
29 VIRTIO_FS_FILE *VirtioFsFile;
30 EFI_STATUS Status;
31 CHAR8 *CanonicalPathname;
32 UINT64 RootDirHandle;
33
34 VirtioFs = VIRTIO_FS_FROM_SIMPLE_FS (This);
35
36 VirtioFsFile = AllocatePool (sizeof *VirtioFsFile);
37 if (VirtioFsFile == NULL) {
38 return EFI_OUT_OF_RESOURCES;
39 }
40
41 CanonicalPathname = AllocateCopyPool (sizeof "/", "/");
42 if (CanonicalPathname == NULL) {
43 Status = EFI_OUT_OF_RESOURCES;
44 goto FreeVirtioFsFile;
45 }
46
47 //
48 // Open the root directory.
49 //
50 Status = VirtioFsFuseOpenDir (
51 VirtioFs,
52 VIRTIO_FS_FUSE_ROOT_DIR_NODE_ID,
53 &RootDirHandle
54 );
55 if (EFI_ERROR (Status)) {
56 goto FreeCanonicalPathname;
57 }
58
59 //
60 // Populate the new VIRTIO_FS_FILE object.
61 //
62 VirtioFsFile->Signature = VIRTIO_FS_FILE_SIG;
63 VirtioFsFile->SimpleFile.Revision = EFI_FILE_PROTOCOL_REVISION;
64 VirtioFsFile->SimpleFile.Open = VirtioFsSimpleFileOpen;
65 VirtioFsFile->SimpleFile.Close = VirtioFsSimpleFileClose;
66 VirtioFsFile->SimpleFile.Delete = VirtioFsSimpleFileDelete;
67 VirtioFsFile->SimpleFile.Read = VirtioFsSimpleFileRead;
68 VirtioFsFile->SimpleFile.Write = VirtioFsSimpleFileWrite;
69 VirtioFsFile->SimpleFile.GetPosition = VirtioFsSimpleFileGetPosition;
70 VirtioFsFile->SimpleFile.SetPosition = VirtioFsSimpleFileSetPosition;
71 VirtioFsFile->SimpleFile.GetInfo = VirtioFsSimpleFileGetInfo;
72 VirtioFsFile->SimpleFile.SetInfo = VirtioFsSimpleFileSetInfo;
73 VirtioFsFile->SimpleFile.Flush = VirtioFsSimpleFileFlush;
74 VirtioFsFile->IsDirectory = TRUE;
75 VirtioFsFile->IsOpenForWriting = FALSE;
76 VirtioFsFile->OwnerFs = VirtioFs;
77 VirtioFsFile->CanonicalPathname = CanonicalPathname;
78 VirtioFsFile->FilePosition = 0;
79 VirtioFsFile->NodeId = VIRTIO_FS_FUSE_ROOT_DIR_NODE_ID;
80 VirtioFsFile->FuseHandle = RootDirHandle;
81 VirtioFsFile->FileInfoArray = NULL;
82 VirtioFsFile->SingleFileInfoSize = 0;
83 VirtioFsFile->NumFileInfo = 0;
84 VirtioFsFile->NextFileInfo = 0;
85
86 //
87 // One more file open for the filesystem.
88 //
89 InsertTailList (&VirtioFs->OpenFiles, &VirtioFsFile->OpenFilesEntry);
90
91 *Root = &VirtioFsFile->SimpleFile;
92 return EFI_SUCCESS;
93
94FreeCanonicalPathname:
95 FreePool (CanonicalPathname);
96
97FreeVirtioFsFile:
98 FreePool (VirtioFsFile);
99
100 return Status;
101}
LIST_ENTRY *EFIAPI InsertTailList(IN OUT LIST_ENTRY *ListHead, IN OUT LIST_ENTRY *Entry)
Definition: LinkedList.c:259
VOID EFIAPI FreePool(IN VOID *Buffer)
VOID *EFIAPI AllocateCopyPool(IN UINTN AllocationSize, IN CONST VOID *Buffer)
EFI_STATUS VirtioFsFuseOpenDir(IN OUT VIRTIO_FS *VirtioFs, IN UINT64 NodeId, OUT UINT64 *FuseHandle)
Definition: FuseOpenDir.c:38
#define NULL
Definition: Base.h:319
#define TRUE
Definition: Base.h:301
#define FALSE
Definition: Base.h:307
#define IN
Definition: Base.h:279
#define OUT
Definition: Base.h:284
VOID *EFIAPI AllocatePool(IN UINTN AllocationSize)
EFI_STATUS EFIAPI VirtioFsOpenVolume(IN EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *This, OUT EFI_FILE_PROTOCOL **Root)
RETURN_STATUS EFI_STATUS
Definition: UefiBaseType.h:29
#define EFI_SUCCESS
Definition: UefiBaseType.h:112