TianoCore EDK2 master
Loading...
Searching...
No Matches
Info.c
Go to the documentation of this file.
1
11#include "Fat.h"
12
27 IN FAT_VOLUME *Volume,
28 IN OUT UINTN *BufferSize,
29 OUT VOID *Buffer
30 );
31
48 IN FAT_VOLUME *Volume,
49 IN UINTN BufferSize,
50 IN VOID *Buffer
51 );
52
69 IN BOOLEAN IsSet,
70 IN EFI_FILE_PROTOCOL *FHand,
71 IN EFI_GUID *Type,
72 IN OUT UINTN *BufferSize,
73 IN OUT VOID *Buffer
74 );
75
90 IN FAT_OFILE *OFile,
91 IN OUT UINTN *BufferSize,
92 OUT VOID *Buffer
93 )
94{
95 return FatGetDirEntInfo (OFile->Volume, OFile->DirEnt, BufferSize, Buffer);
96}
97
112 IN FAT_VOLUME *Volume,
113 IN OUT UINTN *BufferSize,
114 OUT VOID *Buffer
115 )
116{
117 UINTN Size;
118 UINTN NameSize;
119 UINTN ResultSize;
120 CHAR16 Name[FAT_NAME_LEN + 1];
121 EFI_STATUS Status;
123 UINT8 ClusterAlignment;
124
126 Status = FatGetVolumeEntry (Volume, Name);
127 NameSize = StrSize (Name);
128 ResultSize = Size + NameSize;
129 ClusterAlignment = Volume->ClusterAlignment;
130
131 //
132 // If we don't have valid info, compute it now
133 //
134 FatComputeFreeInfo (Volume);
135
136 Status = EFI_BUFFER_TOO_SMALL;
137 if (*BufferSize >= ResultSize) {
138 Status = EFI_SUCCESS;
139
140 Info = Buffer;
142
143 Info->Size = ResultSize;
144 Info->ReadOnly = Volume->ReadOnly;
145 Info->BlockSize = (UINT32)Volume->ClusterSize;
146 Info->VolumeSize = LShiftU64 (Volume->MaxCluster, ClusterAlignment);
147 Info->FreeSpace = LShiftU64 (
148 Volume->FatInfoSector.FreeInfo.ClusterCount,
149 ClusterAlignment
150 );
151 CopyMem ((CHAR8 *)Buffer + Size, Name, NameSize);
152 }
153
154 *BufferSize = ResultSize;
155 return Status;
156}
157
172 IN FAT_VOLUME *Volume,
173 IN OUT UINTN *BufferSize,
174 OUT VOID *Buffer
175 )
176{
177 UINTN Size;
178 UINTN NameSize;
179 UINTN ResultSize;
180 CHAR16 Name[FAT_NAME_LEN + 1];
181 EFI_STATUS Status;
182
183 Size = SIZE_OF_EFI_FILE_SYSTEM_VOLUME_LABEL;
184 Status = FatGetVolumeEntry (Volume, Name);
185 NameSize = StrSize (Name);
186 ResultSize = Size + NameSize;
187
188 Status = EFI_BUFFER_TOO_SMALL;
189 if (*BufferSize >= ResultSize) {
190 Status = EFI_SUCCESS;
191 CopyMem ((CHAR8 *)Buffer + Size, Name, NameSize);
192 }
193
194 *BufferSize = ResultSize;
195 return Status;
196}
197
214 IN FAT_VOLUME *Volume,
215 IN UINTN BufferSize,
216 IN VOID *Buffer
217 )
218{
220
221 Info = (EFI_FILE_SYSTEM_INFO *)Buffer;
222
223 if ((BufferSize < SIZE_OF_EFI_FILE_SYSTEM_INFO + 2) || (Info->Size > BufferSize)) {
224 return EFI_BAD_BUFFER_SIZE;
225 }
226
227 return FatSetVolumeEntry (Volume, Info->VolumeLabel);
228}
229
246 IN FAT_VOLUME *Volume,
247 IN UINTN BufferSize,
248 IN VOID *Buffer
249 )
250{
252
253 Info = (EFI_FILE_SYSTEM_VOLUME_LABEL *)Buffer;
254
255 if (BufferSize < SIZE_OF_EFI_FILE_SYSTEM_VOLUME_LABEL + 2) {
256 return EFI_BAD_BUFFER_SIZE;
257 }
258
259 return FatSetVolumeEntry (Volume, Info->VolumeLabel);
260}
261
288 IN FAT_VOLUME *Volume,
289 IN FAT_IFILE *IFile,
290 IN FAT_OFILE *OFile,
291 IN UINTN BufferSize,
292 IN VOID *Buffer
293 )
294{
295 EFI_STATUS Status;
296 EFI_FILE_INFO *NewInfo;
297 FAT_OFILE *DotOFile;
298 FAT_OFILE *Parent;
299 CHAR16 NewFileName[EFI_PATH_STRING_LENGTH];
300 EFI_TIME ZeroTime;
301 FAT_DIRENT *DirEnt;
302 FAT_DIRENT *TempDirEnt;
303 UINT8 NewAttribute;
304 BOOLEAN ReadOnly;
305
306 TempDirEnt = NULL;
307
308 ZeroMem (&ZeroTime, sizeof (EFI_TIME));
309 Parent = OFile->Parent;
310 DirEnt = OFile->DirEnt;
311 //
312 // If this is the root directory, we can't make any updates
313 //
314 if (Parent == NULL) {
315 return EFI_ACCESS_DENIED;
316 }
317
318 //
319 // Make sure there's a valid input buffer
320 //
321 NewInfo = Buffer;
322 if ((BufferSize < SIZE_OF_EFI_FILE_INFO + 2) || (NewInfo->Size > BufferSize)) {
323 return EFI_BAD_BUFFER_SIZE;
324 }
325
326 ReadOnly = (BOOLEAN)(IFile->ReadOnly || (DirEnt->Entry.Attributes & EFI_FILE_READ_ONLY));
327 //
328 // if a zero time is specified, then the original time is preserved
329 //
330 if (CompareMem (&ZeroTime, &NewInfo->CreateTime, sizeof (EFI_TIME)) != 0) {
331 if (!FatIsValidTime (&NewInfo->CreateTime)) {
332 return EFI_INVALID_PARAMETER;
333 }
334
335 if (!ReadOnly) {
336 FatEfiTimeToFatTime (&NewInfo->CreateTime, &DirEnt->Entry.FileCreateTime);
337 }
338 }
339
340 if (CompareMem (&ZeroTime, &NewInfo->ModificationTime, sizeof (EFI_TIME)) != 0) {
341 if (!FatIsValidTime (&NewInfo->ModificationTime)) {
342 return EFI_INVALID_PARAMETER;
343 }
344
345 if (!ReadOnly) {
346 FatEfiTimeToFatTime (&NewInfo->ModificationTime, &DirEnt->Entry.FileModificationTime);
347 }
348
349 OFile->PreserveLastModification = TRUE;
350 }
351
352 if (NewInfo->Attribute & (~EFI_FILE_VALID_ATTR)) {
353 return EFI_INVALID_PARAMETER;
354 }
355
356 NewAttribute = (UINT8)NewInfo->Attribute;
357 //
358 // Can not change the directory attribute bit
359 //
360 if ((NewAttribute ^ DirEnt->Entry.Attributes) & EFI_FILE_DIRECTORY) {
361 return EFI_ACCESS_DENIED;
362 }
363
364 //
365 // Set the current attributes even if the IFile->ReadOnly is TRUE
366 //
367 DirEnt->Entry.Attributes = (UINT8)((DirEnt->Entry.Attributes &~EFI_FILE_VALID_ATTR) | NewAttribute);
368 //
369 // Open the filename and see if it refers to an existing file
370 //
371 Status = FatLocateOFile (&Parent, NewInfo->FileName, DirEnt->Entry.Attributes, NewFileName);
372 if (EFI_ERROR (Status)) {
373 return Status;
374 }
375
376 if (*NewFileName != 0) {
377 //
378 // File was not found. We do not allow rename of the current directory if
379 // there are open files below the current directory
380 //
381 if (!IsListEmpty (&OFile->ChildHead) || (Parent == OFile)) {
382 return EFI_ACCESS_DENIED;
383 }
384
385 if (ReadOnly) {
386 return EFI_ACCESS_DENIED;
387 }
388
389 Status = FatRemoveDirEnt (OFile->Parent, DirEnt);
390 if (EFI_ERROR (Status)) {
391 return Status;
392 }
393
394 //
395 // Create new dirent
396 //
397 Status = FatCreateDirEnt (Parent, NewFileName, DirEnt->Entry.Attributes, &TempDirEnt);
398 if (EFI_ERROR (Status)) {
399 return Status;
400 }
401
402 FatCloneDirEnt (TempDirEnt, DirEnt);
403 FatFreeDirEnt (DirEnt);
404 DirEnt = TempDirEnt;
405 DirEnt->OFile = OFile;
406 OFile->DirEnt = DirEnt;
407 OFile->Parent = Parent;
408 RemoveEntryList (&OFile->ChildLink);
409 InsertHeadList (&Parent->ChildHead, &OFile->ChildLink);
410 //
411 // If this is a directory, synchronize its dot directory entry
412 //
413 if (OFile->ODir != NULL) {
414 //
415 // Synchronize its dot entry
416 //
417 FatResetODirCursor (OFile);
418 ASSERT (OFile->Parent != NULL);
419 for (DotOFile = OFile; DotOFile != OFile->Parent->Parent; DotOFile = DotOFile->Parent) {
420 Status = FatGetNextDirEnt (OFile, &DirEnt);
421 if (EFI_ERROR (Status) || (DirEnt == NULL) || !FatIsDotDirEnt (DirEnt)) {
422 return EFI_VOLUME_CORRUPTED;
423 }
424
425 FatCloneDirEnt (DirEnt, DotOFile->DirEnt);
426 Status = FatStoreDirEnt (OFile, DirEnt);
427 if (EFI_ERROR (Status)) {
428 return Status;
429 }
430 }
431 }
432
433 //
434 // If the file is renamed, we should append the ARCHIVE attribute
435 //
436 OFile->Archive = TRUE;
437 } else if (Parent != OFile) {
438 //
439 // filename is to a different filename that already exists
440 //
441 return EFI_ACCESS_DENIED;
442 }
443
444 //
445 // If the file size has changed, apply it
446 //
447 if (NewInfo->FileSize != OFile->FileSize) {
448 if ((OFile->ODir != NULL) || ReadOnly) {
449 //
450 // If this is a directory or the file is read only, we can't change the file size
451 //
452 return EFI_ACCESS_DENIED;
453 }
454
455 if (NewInfo->FileSize > OFile->FileSize) {
456 Status = FatExpandOFile (OFile, NewInfo->FileSize);
457 } else {
458 Status = FatTruncateOFile (OFile, (UINTN)NewInfo->FileSize);
459 }
460
461 if (EFI_ERROR (Status)) {
462 return Status;
463 }
464
466 }
467
468 OFile->Dirty = TRUE;
469 return FatOFileFlush (OFile);
470}
471
488 IN BOOLEAN IsSet,
489 IN EFI_FILE_PROTOCOL *FHand,
490 IN EFI_GUID *Type,
491 IN OUT UINTN *BufferSize,
492 IN OUT VOID *Buffer
493 )
494{
495 FAT_IFILE *IFile;
496 FAT_OFILE *OFile;
497 FAT_VOLUME *Volume;
498 EFI_STATUS Status;
499
500 IFile = IFILE_FROM_FHAND (FHand);
501 OFile = IFile->OFile;
502 Volume = OFile->Volume;
503
504 Status = OFile->Error;
505 if (Status == EFI_NOT_FOUND) {
506 return EFI_DEVICE_ERROR;
507 }
508
510
512
513 //
514 // Verify the file handle isn't in an error state
515 //
516 if (!EFI_ERROR (Status)) {
517 //
518 // Get the proper information based on the request
519 //
520 Status = EFI_UNSUPPORTED;
521 if (IsSet) {
522 if (CompareGuid (Type, &gEfiFileInfoGuid)) {
523 Status = Volume->ReadOnly ? EFI_WRITE_PROTECTED : FatSetFileInfo (Volume, IFile, OFile, *BufferSize, Buffer);
524 }
525
526 if (CompareGuid (Type, &gEfiFileSystemInfoGuid)) {
527 Status = Volume->ReadOnly ? EFI_WRITE_PROTECTED : FatSetVolumeInfo (Volume, *BufferSize, Buffer);
528 }
529
530 if (CompareGuid (Type, &gEfiFileSystemVolumeLabelInfoIdGuid)) {
531 Status = Volume->ReadOnly ? EFI_WRITE_PROTECTED : FatSetVolumeLabelInfo (Volume, *BufferSize, Buffer);
532 }
533 } else {
534 if (CompareGuid (Type, &gEfiFileInfoGuid)) {
535 Status = FatGetFileInfo (OFile, BufferSize, Buffer);
536 }
537
538 if (CompareGuid (Type, &gEfiFileSystemInfoGuid)) {
539 Status = FatGetVolumeInfo (Volume, BufferSize, Buffer);
540 }
541
542 if (CompareGuid (Type, &gEfiFileSystemVolumeLabelInfoIdGuid)) {
543 Status = FatGetVolumeLabelInfo (Volume, BufferSize, Buffer);
544 }
545 }
546 }
547
548 Status = FatCleanupVolume (Volume, NULL, Status, NULL);
549
551 return Status;
552}
553
568EFIAPI
570 IN EFI_FILE_PROTOCOL *FHand,
571 IN EFI_GUID *Type,
572 IN OUT UINTN *BufferSize,
573 OUT VOID *Buffer
574 )
575{
576 return FatSetOrGetInfo (FALSE, FHand, Type, BufferSize, Buffer);
577}
578
593EFIAPI
595 IN EFI_FILE_PROTOCOL *FHand,
596 IN EFI_GUID *Type,
597 IN UINTN BufferSize,
598 IN VOID *Buffer
599 )
600{
601 return FatSetOrGetInfo (TRUE, FHand, Type, &BufferSize, Buffer);
602}
UINT64 UINTN
UINTN EFIAPI StrSize(IN CONST CHAR16 *String)
Definition: String.c:72
BOOLEAN EFIAPI IsListEmpty(IN CONST LIST_ENTRY *ListHead)
Definition: LinkedList.c:403
LIST_ENTRY *EFIAPI InsertHeadList(IN OUT LIST_ENTRY *ListHead, IN OUT LIST_ENTRY *Entry)
Definition: LinkedList.c:218
LIST_ENTRY *EFIAPI RemoveEntryList(IN CONST LIST_ENTRY *Entry)
Definition: LinkedList.c:590
UINT64 EFIAPI LShiftU64(IN UINT64 Operand, IN UINTN Count)
Definition: LShiftU64.c:28
INTN EFIAPI CompareMem(IN CONST VOID *DestinationBuffer, IN CONST VOID *SourceBuffer, IN UINTN Length)
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
VOID *EFIAPI ZeroMem(OUT VOID *Buffer, IN UINTN Length)
EFI_STATUS FatRemoveDirEnt(IN FAT_OFILE *OFile, IN FAT_DIRENT *DirEnt)
EFI_STATUS FatStoreDirEnt(IN FAT_OFILE *OFile, IN FAT_DIRENT *DirEnt)
EFI_STATUS FatGetDirEntInfo(IN FAT_VOLUME *Volume, IN FAT_DIRENT *DirEnt, IN OUT UINTN *BufferSize, OUT VOID *Buffer)
EFI_STATUS FatCreateDirEnt(IN FAT_OFILE *OFile, IN CHAR16 *FileName, IN UINT8 Attributes, OUT FAT_DIRENT **PtrDirEnt)
BOOLEAN FatIsDotDirEnt(IN FAT_DIRENT *DirEnt)
EFI_STATUS FatLocateOFile(IN OUT FAT_OFILE **PtrOFile, IN CHAR16 *FileName, IN UINT8 Attributes, OUT CHAR16 *NewFileName)
EFI_STATUS FatSetVolumeEntry(IN FAT_VOLUME *Volume, IN CHAR16 *Name)
EFI_STATUS FatGetNextDirEnt(IN FAT_OFILE *OFile, OUT FAT_DIRENT **PtrDirEnt)
EFI_STATUS FatGetVolumeEntry(IN FAT_VOLUME *Volume, IN CHAR16 *Name)
VOID FatCloneDirEnt(IN FAT_DIRENT *DirEnt1, IN FAT_DIRENT *DirEnt2)
VOID FatUpdateDirEntClusterSizeInfo(IN FAT_OFILE *OFile)
VOID FatResetODirCursor(IN FAT_OFILE *OFile)
VOID FatEfiTimeToFatTime(IN EFI_TIME *ETime, OUT FAT_DATE_TIME *FTime)
Definition: Misc.c:487
EFI_STATUS FatOFileFlush(IN FAT_OFILE *OFile)
Definition: Flush.c:218
EFI_STATUS FatExpandOFile(IN FAT_OFILE *OFile, IN UINT64 ExpandedSize)
Definition: ReadWrite.c:537
VOID FatWaitNonblockingTask(FAT_IFILE *IFile)
Definition: Misc.c:75
BOOLEAN FatIsValidTime(IN EFI_TIME *Time)
Definition: Misc.c:573
VOID FatComputeFreeInfo(IN FAT_VOLUME *Volume)
Definition: FileSpace.c:720
VOID FatFreeDirEnt(IN FAT_DIRENT *DirEnt)
Definition: Misc.c:441
VOID FatAcquireLock(VOID)
Definition: Misc.c:395
VOID FatReleaseLock(VOID)
Definition: Misc.c:426
EFI_STATUS FatTruncateOFile(IN FAT_OFILE *OFile, IN UINTN TruncatedSize)
Definition: ReadWrite.c:622
EFI_STATUS FatCleanupVolume(IN FAT_VOLUME *Volume, IN FAT_OFILE *OFile, IN EFI_STATUS EfiStatus, IN FAT_TASK *Task)
Definition: Flush.c:382
#define SIZE_OF_EFI_FILE_INFO
Definition: FileInfo.h:62
#define SIZE_OF_EFI_FILE_SYSTEM_INFO
EFI_STATUS FatGetVolumeInfo(IN FAT_VOLUME *Volume, IN OUT UINTN *BufferSize, OUT VOID *Buffer)
Definition: Info.c:111
EFI_STATUS EFIAPI FatGetInfo(IN EFI_FILE_PROTOCOL *FHand, IN EFI_GUID *Type, IN OUT UINTN *BufferSize, OUT VOID *Buffer)
Definition: Info.c:569
EFI_STATUS FatSetVolumeLabelInfo(IN FAT_VOLUME *Volume, IN UINTN BufferSize, IN VOID *Buffer)
Definition: Info.c:245
EFI_STATUS FatGetVolumeLabelInfo(IN FAT_VOLUME *Volume, IN OUT UINTN *BufferSize, OUT VOID *Buffer)
Definition: Info.c:171
EFI_STATUS FatSetFileInfo(IN FAT_VOLUME *Volume, IN FAT_IFILE *IFile, IN FAT_OFILE *OFile, IN UINTN BufferSize, IN VOID *Buffer)
Definition: Info.c:287
EFI_STATUS FatGetFileInfo(IN FAT_OFILE *OFile, IN OUT UINTN *BufferSize, OUT VOID *Buffer)
Definition: Info.c:89
EFI_STATUS EFIAPI FatSetInfo(IN EFI_FILE_PROTOCOL *FHand, IN EFI_GUID *Type, IN UINTN BufferSize, IN VOID *Buffer)
Definition: Info.c:594
EFI_STATUS FatSetVolumeInfo(IN FAT_VOLUME *Volume, IN UINTN BufferSize, IN VOID *Buffer)
Definition: Info.c:213
EFI_STATUS FatSetOrGetInfo(IN BOOLEAN IsSet, IN EFI_FILE_PROTOCOL *FHand, IN EFI_GUID *Type, IN OUT UINTN *BufferSize, IN OUT VOID *Buffer)
Definition: Info.c:487
#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
RETURN_STATUS EFI_STATUS
Definition: UefiBaseType.h:29
#define EFI_SUCCESS
Definition: UefiBaseType.h:112
EFI_TIME ModificationTime
Definition: FileInfo.h:43
EFI_TIME CreateTime
Definition: FileInfo.h:35
UINT64 Size
Definition: FileInfo.h:23
UINT64 Attribute
Definition: FileInfo.h:47
CHAR16 FileName[1]
Definition: FileInfo.h:52
UINT64 FileSize
Definition: FileInfo.h:27
Definition: Fat.h:217
Definition: Base.h:213