boot: Make file info size a constant

This commit is contained in:
Jan Janssen 2023-08-02 16:21:51 +02:00
parent 66fd078ba8
commit e80037b10f
2 changed files with 8 additions and 7 deletions

View file

@ -31,6 +31,12 @@ typedef struct {
char16_t FileName[];
} EFI_FILE_INFO;
/* Some broken firmware violates the EFI spec by still advancing the readdir
* position when returning EFI_BUFFER_TOO_SMALL, effectively skipping over any files when
* the buffer was too small. Therefore, we always start with a buffer that should handle FAT32
* max file name length. */
#define EFI_FILE_INFO_MIN_SIZE (sizeof(EFI_FILE_INFO) + 256 * sizeof(char16_t))
typedef struct EFI_SIMPLE_FILE_SYSTEM_PROTOCOL EFI_SIMPLE_FILE_SYSTEM_PROTOCOL;
struct EFI_SIMPLE_FILE_SYSTEM_PROTOCOL {
uint64_t Revision;

View file

@ -412,7 +412,7 @@ void sort_pointer_array(
}
EFI_STATUS get_file_info(EFI_FILE *handle, EFI_FILE_INFO **ret, size_t *ret_size) {
size_t size = offsetof(EFI_FILE_INFO, FileName) + 256;
size_t size = EFI_FILE_INFO_MIN_SIZE;
_cleanup_free_ EFI_FILE_INFO *fi = NULL;
EFI_STATUS err;
@ -454,12 +454,7 @@ EFI_STATUS readdir(
* the specified buffer needs to be freed by caller, after final use. */
if (!*buffer) {
/* Some broken firmware violates the EFI spec by still advancing the readdir
* position when returning EFI_BUFFER_TOO_SMALL, effectively skipping over any files when
* the buffer was too small. Therefore, start with a buffer that should handle FAT32 max
* file name length.
* As a side effect, most readdir() calls will now be slightly faster. */
sz = sizeof(EFI_FILE_INFO) + 256 * sizeof(char16_t);
sz = EFI_FILE_INFO_MIN_SIZE;
*buffer = xmalloc(sz);
*buffer_size = sz;
} else