]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Universal/Disk/RamDiskDxe/RamDiskFileExplorer.c
MdeModulePkg: Apply uncrustify changes
[mirror_edk2.git] / MdeModulePkg / Universal / Disk / RamDiskDxe / RamDiskFileExplorer.c
1 /** @file
2 Internal file explorer helper functions for RamDiskDxe driver.
3
4 Copyright (c) 2016, Intel Corporation. All rights reserved.<BR>
5 SPDX-License-Identifier: BSD-2-Clause-Patent
6
7 **/
8
9 #include "RamDiskImpl.h"
10
11 /**
12 Helper function called as part of the code needed to allocate the proper
13 sized buffer for various EFI interfaces.
14
15 @param[in, out] Status Current status.
16 @param[in, out] Buffer Current allocated buffer, or NULL.
17 @param[in] BufferSize Current buffer size needed.
18
19 @retval TRUE If the buffer was reallocated and the caller should
20 try the API again.
21 @retval FALSE The caller should not call this function again.
22
23 **/
24 BOOLEAN
25 GrowBuffer (
26 IN OUT EFI_STATUS *Status,
27 IN OUT VOID **Buffer,
28 IN UINTN BufferSize
29 )
30 {
31 BOOLEAN TryAgain;
32
33 //
34 // If this is an initial request, buffer will be null with a new buffer size
35 //
36 if ((*Buffer == NULL) && (BufferSize != 0)) {
37 *Status = EFI_BUFFER_TOO_SMALL;
38 }
39
40 //
41 // If the status code is "buffer too small", resize the buffer
42 //
43 TryAgain = FALSE;
44 if (*Status == EFI_BUFFER_TOO_SMALL) {
45 if (*Buffer != NULL) {
46 FreePool (*Buffer);
47 }
48
49 *Buffer = AllocateZeroPool (BufferSize);
50
51 if (*Buffer != NULL) {
52 TryAgain = TRUE;
53 } else {
54 *Status = EFI_OUT_OF_RESOURCES;
55 }
56 }
57
58 //
59 // If there's an error, free the buffer
60 //
61 if (!TryAgain && EFI_ERROR (*Status) && (*Buffer != NULL)) {
62 FreePool (*Buffer);
63 *Buffer = NULL;
64 }
65
66 return TryAgain;
67 }
68
69 /**
70 This function gets the file information from an open file descriptor,
71 and stores it in a buffer allocated from pool.
72
73 @param[in] FHand File Handle.
74
75 @return A pointer to a buffer with file information or NULL is returned.
76
77 **/
78 EFI_FILE_INFO *
79 FileInfo (
80 IN EFI_FILE_HANDLE FHand
81 )
82 {
83 EFI_STATUS Status;
84 EFI_FILE_INFO *Buffer;
85 UINTN BufferSize;
86
87 //
88 // Initialize for GrowBuffer loop
89 //
90 Buffer = NULL;
91 BufferSize = SIZE_OF_EFI_FILE_INFO + 200;
92
93 //
94 // Call the real function
95 //
96 while (GrowBuffer (&Status, (VOID **)&Buffer, BufferSize)) {
97 Status = FHand->GetInfo (
98 FHand,
99 &gEfiFileInfoGuid,
100 &BufferSize,
101 Buffer
102 );
103 }
104
105 return Buffer;
106 }