]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Universal/Disk/RamDiskDxe/RamDiskFileExplorer.c
MdeModulePkg/UefiPxeBcDxe: Add the clarification compared to UefiPxeBcDxe in NetworkPkg.
[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 This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
9
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
12
13 **/
14
15 #include "RamDiskImpl.h"
16
17
18 /**
19 Helper function called as part of the code needed to allocate the proper
20 sized buffer for various EFI interfaces.
21
22 @param[in, out] Status Current status.
23 @param[in, out] Buffer Current allocated buffer, or NULL.
24 @param[in] BufferSize Current buffer size needed.
25
26 @retval TRUE If the buffer was reallocated and the caller should
27 try the API again.
28 @retval FALSE The caller should not call this function again.
29
30 **/
31 BOOLEAN
32 GrowBuffer (
33 IN OUT EFI_STATUS *Status,
34 IN OUT VOID **Buffer,
35 IN UINTN BufferSize
36 )
37 {
38 BOOLEAN TryAgain;
39
40 //
41 // If this is an initial request, buffer will be null with a new buffer size
42 //
43 if ((*Buffer == NULL) && (BufferSize != 0)) {
44 *Status = EFI_BUFFER_TOO_SMALL;
45 }
46 //
47 // If the status code is "buffer too small", resize the buffer
48 //
49 TryAgain = FALSE;
50 if (*Status == EFI_BUFFER_TOO_SMALL) {
51
52 if (*Buffer != NULL) {
53 FreePool (*Buffer);
54 }
55
56 *Buffer = AllocateZeroPool (BufferSize);
57
58 if (*Buffer != NULL) {
59 TryAgain = TRUE;
60 } else {
61 *Status = EFI_OUT_OF_RESOURCES;
62 }
63 }
64 //
65 // If there's an error, free the buffer
66 //
67 if (!TryAgain && EFI_ERROR (*Status) && (*Buffer != NULL)) {
68 FreePool (*Buffer);
69 *Buffer = NULL;
70 }
71
72 return TryAgain;
73 }
74
75
76 /**
77 This function gets the file information from an open file descriptor,
78 and stores it in a buffer allocated from pool.
79
80 @param[in] FHand File Handle.
81
82 @return A pointer to a buffer with file information or NULL is returned.
83
84 **/
85 EFI_FILE_INFO *
86 FileInfo (
87 IN EFI_FILE_HANDLE FHand
88 )
89 {
90 EFI_STATUS Status;
91 EFI_FILE_INFO *Buffer;
92 UINTN BufferSize;
93
94 //
95 // Initialize for GrowBuffer loop
96 //
97 Buffer = NULL;
98 BufferSize = SIZE_OF_EFI_FILE_INFO + 200;
99
100 //
101 // Call the real function
102 //
103 while (GrowBuffer (&Status, (VOID **) &Buffer, BufferSize)) {
104 Status = FHand->GetInfo (
105 FHand,
106 &gEfiFileInfoGuid,
107 &BufferSize,
108 Buffer
109 );
110 }
111
112 return Buffer;
113 }