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