TianoCore EDK2 master
Loading...
Searching...
No Matches
SimpleFsGetInfo.c
Go to the documentation of this file.
1
9#include <Guid/FileSystemInfo.h> // gEfiFileSystemInfoGuid
10#include <Guid/FileSystemVolumeLabelInfo.h> // gEfiFileSystemVolumeLabelInfo...
11#include <Library/BaseLib.h> // StrSize()
12#include <Library/BaseMemoryLib.h> // CompareGuid()
13
14#include "VirtioFsDxe.h"
15
23 IN OUT UINTN *BufferSize,
24 OUT VOID *Buffer
25 )
26{
27 VIRTIO_FS_FILE *VirtioFsFile;
28 VIRTIO_FS *VirtioFs;
29 UINTN AllocSize;
30 UINTN BasenameSize;
31 EFI_STATUS Status;
34
35 VirtioFsFile = VIRTIO_FS_FILE_FROM_SIMPLE_FILE (This);
36 VirtioFs = VirtioFsFile->OwnerFs;
37
38 AllocSize = *BufferSize;
39
40 //
41 // Calculate the needed size.
42 //
43 BasenameSize = 0;
44 Status = VirtioFsGetBasename (
45 VirtioFsFile->CanonicalPathname,
46 NULL,
47 &BasenameSize
48 );
49 ASSERT (Status == EFI_BUFFER_TOO_SMALL);
50 *BufferSize = OFFSET_OF (EFI_FILE_INFO, FileName) + BasenameSize;
51
52 if (*BufferSize > AllocSize) {
53 return EFI_BUFFER_TOO_SMALL;
54 }
55
56 //
57 // Set the structure size, and store the basename.
58 //
59 FileInfo = Buffer;
60 FileInfo->Size = *BufferSize;
61 Status = VirtioFsGetBasename (
62 VirtioFsFile->CanonicalPathname,
64 &BasenameSize
65 );
66 ASSERT_EFI_ERROR (Status);
67
68 //
69 // Fetch the file attributes, and convert them into the caller's buffer.
70 //
71 Status = VirtioFsFuseGetAttr (VirtioFs, VirtioFsFile->NodeId, &FuseAttr);
72 if (!EFI_ERROR (Status)) {
73 Status = VirtioFsFuseAttrToEfiFileInfo (&FuseAttr, FileInfo);
74 }
75
76 return (Status == EFI_BUFFER_TOO_SMALL) ? EFI_DEVICE_ERROR : Status;
77}
78
86 IN OUT UINTN *BufferSize,
87 OUT VOID *Buffer
88 )
89{
90 VIRTIO_FS_FILE *VirtioFsFile;
91 VIRTIO_FS *VirtioFs;
92 UINTN AllocSize;
93 UINTN LabelSize;
94 EFI_STATUS Status;
96 UINT64 MaxBlocks;
97 EFI_FILE_SYSTEM_INFO *FilesysInfo;
98
99 VirtioFsFile = VIRTIO_FS_FILE_FROM_SIMPLE_FILE (This);
100 VirtioFs = VirtioFsFile->OwnerFs;
101
102 AllocSize = *BufferSize;
103
104 //
105 // Calculate the needed size.
106 //
107 LabelSize = StrSize (VirtioFs->Label);
108 *BufferSize = OFFSET_OF (EFI_FILE_SYSTEM_INFO, VolumeLabel) + LabelSize;
109
110 if (*BufferSize > AllocSize) {
111 return EFI_BUFFER_TOO_SMALL;
112 }
113
114 //
115 // Fetch the filesystem attributes.
116 //
117 Status = VirtioFsFuseStatFs (VirtioFs, VirtioFsFile->NodeId, &FilesysAttr);
118 if (EFI_ERROR (Status)) {
119 return (Status == EFI_BUFFER_TOO_SMALL) ? EFI_DEVICE_ERROR : Status;
120 }
121
122 //
123 // Sanity checks...
124 //
125 if (FilesysAttr.Frsize != FilesysAttr.Bsize) {
126 return EFI_UNSUPPORTED;
127 }
128
129 if ((FilesysAttr.Frsize == 0) || (FilesysAttr.Blocks == 0) ||
130 (FilesysAttr.Bavail > FilesysAttr.Blocks))
131 {
132 return EFI_DEVICE_ERROR;
133 }
134
135 MaxBlocks = DivU64x32 (MAX_UINT64, FilesysAttr.Frsize);
136 if ((FilesysAttr.Blocks > MaxBlocks) || (FilesysAttr.Bavail > MaxBlocks)) {
137 return EFI_DEVICE_ERROR;
138 }
139
140 //
141 // Fill in EFI_FILE_SYSTEM_INFO.
142 //
143 FilesysInfo = Buffer;
144 FilesysInfo->Size = *BufferSize;
145 FilesysInfo->ReadOnly = FALSE;
146 FilesysInfo->VolumeSize = MultU64x32 (
147 FilesysAttr.Blocks,
148 FilesysAttr.Frsize
149 );
150 FilesysInfo->FreeSpace = MultU64x32 (
151 FilesysAttr.Bavail,
152 FilesysAttr.Frsize
153 );
154 FilesysInfo->BlockSize = FilesysAttr.Frsize;
155 CopyMem (FilesysInfo->VolumeLabel, VirtioFs->Label, LabelSize);
156
157 return EFI_SUCCESS;
158}
159
163STATIC
166 IN EFI_FILE_PROTOCOL *This,
167 IN OUT UINTN *BufferSize,
168 OUT VOID *Buffer
169 )
170{
171 VIRTIO_FS_FILE *VirtioFsFile;
172 VIRTIO_FS *VirtioFs;
173 UINTN AllocSize;
174 UINTN LabelSize;
175 EFI_FILE_SYSTEM_VOLUME_LABEL *FilesysVolumeLabel;
176
177 VirtioFsFile = VIRTIO_FS_FILE_FROM_SIMPLE_FILE (This);
178 VirtioFs = VirtioFsFile->OwnerFs;
179
180 AllocSize = *BufferSize;
181
182 //
183 // Calculate the needed size.
184 //
185 LabelSize = StrSize (VirtioFs->Label);
186 *BufferSize = (OFFSET_OF (EFI_FILE_SYSTEM_VOLUME_LABEL, VolumeLabel) +
187 LabelSize);
188
189 if (*BufferSize > AllocSize) {
190 return EFI_BUFFER_TOO_SMALL;
191 }
192
193 //
194 // Store the label.
195 //
196 FilesysVolumeLabel = Buffer;
197 CopyMem (FilesysVolumeLabel->VolumeLabel, VirtioFs->Label, LabelSize);
198
199 return EFI_SUCCESS;
200}
201
203EFIAPI
204VirtioFsSimpleFileGetInfo (
205 IN EFI_FILE_PROTOCOL *This,
206 IN EFI_GUID *InformationType,
207 IN OUT UINTN *BufferSize,
208 OUT VOID *Buffer
209 )
210{
211 if (CompareGuid (InformationType, &gEfiFileInfoGuid)) {
212 return GetFileInfo (This, BufferSize, Buffer);
213 }
214
215 if (CompareGuid (InformationType, &gEfiFileSystemInfoGuid)) {
216 return GetFileSystemInfo (This, BufferSize, Buffer);
217 }
218
219 if (CompareGuid (InformationType, &gEfiFileSystemVolumeLabelInfoIdGuid)) {
220 return GetFileSystemVolumeLabelInfo (This, BufferSize, Buffer);
221 }
222
223 return EFI_UNSUPPORTED;
224}
UINT64 UINTN
UINTN EFIAPI StrSize(IN CONST CHAR16 *String)
Definition: String.c:72
UINT64 EFIAPI DivU64x32(IN UINT64 Dividend, IN UINT32 Divisor)
Definition: DivU64x32.c:29
UINT64 EFIAPI MultU64x32(IN UINT64 Multiplicand, IN UINT32 Multiplier)
Definition: MultU64x32.c:27
VOID *EFIAPI CopyMem(OUT VOID *DestinationBuffer, IN CONST VOID *SourceBuffer, IN UINTN Length)
BOOLEAN EFIAPI CompareGuid(IN CONST GUID *Guid1, IN CONST GUID *Guid2)
Definition: MemLibGuid.c:73
EFI_STATUS VirtioFsFuseGetAttr(IN OUT VIRTIO_FS *VirtioFs, IN UINT64 NodeId, OUT VIRTIO_FS_FUSE_ATTRIBUTES_RESPONSE *FuseAttr)
Definition: FuseGetAttr.c:39
EFI_STATUS VirtioFsFuseStatFs(IN OUT VIRTIO_FS *VirtioFs, IN UINT64 NodeId, OUT VIRTIO_FS_FUSE_STATFS_RESPONSE *FilesysAttr)
Definition: FuseStatFs.c:38
#define NULL
Definition: Base.h:319
#define STATIC
Definition: Base.h:264
#define FALSE
Definition: Base.h:307
#define IN
Definition: Base.h:279
#define OFFSET_OF(TYPE, Field)
Definition: Base.h:758
#define OUT
Definition: Base.h:284
#define ASSERT_EFI_ERROR(StatusParameter)
Definition: DebugLib.h:462
EFI_FILE_INFO * FileInfo(IN EFI_FILE_HANDLE FHand)
STATIC EFI_STATUS GetFileSystemVolumeLabelInfo(IN EFI_FILE_PROTOCOL *This, IN OUT UINTN *BufferSize, OUT VOID *Buffer)
STATIC EFI_STATUS GetFileInfo(IN EFI_FILE_PROTOCOL *This, IN OUT UINTN *BufferSize, OUT VOID *Buffer)
STATIC EFI_STATUS GetFileSystemInfo(IN EFI_FILE_PROTOCOL *This, IN OUT UINTN *BufferSize, OUT VOID *Buffer)
RETURN_STATUS EFI_STATUS
Definition: UefiBaseType.h:29
#define EFI_SUCCESS
Definition: UefiBaseType.h:112
EFI_STATUS VirtioFsGetBasename(IN CHAR8 *Path, OUT CHAR16 *Basename OPTIONAL, IN OUT UINTN *BasenameSize)
Definition: Helpers.c:1823
EFI_STATUS VirtioFsFuseAttrToEfiFileInfo(IN VIRTIO_FS_FUSE_ATTRIBUTES_RESPONSE *FuseAttr, OUT EFI_FILE_INFO *FileInfo)
Definition: Helpers.c:2090
UINT64 Size
Definition: FileInfo.h:23
CHAR16 FileName[1]
Definition: FileInfo.h:52
Definition: Base.h:213