2 * COPYRIGHT: See COPYING.ARM in the top level directory
3 * PROJECT: ReactOS UEFI Boot Library
4 * FILE: boot/environ/lib/io/fat.c
5 * PURPOSE: Boot Library FAT File System Management Routines
6 * PROGRAMMER: Alex Ionescu (alex.ionescu@reactos.org)
9 /* INCLUDES ******************************************************************/
12 #include <fs_rec/fs_rec.h>
14 /* DATA VARIABLES ************************************************************/
16 PVOID
* FatDeviceTable
;
17 ULONG FatDeviceTableEntries
;
18 PWCHAR FatpLongFileName
;
20 /* FUNCTIONS *****************************************************************/
26 _Out_ PBL_FILE_ENTRY
* FileEntry
29 BL_DEVICE_INFORMATION DeviceInformation
;
32 PACKED_BOOT_SECTOR FatBootSector
;
33 BIOS_PARAMETER_BLOCK BiosBlock
;
36 BlDeviceGetInformation(DeviceId
, &DeviceInformation
);
37 UnknownFlag
= DeviceInformation
.BlockDeviceInfo
.Unknown
;
40 DeviceInformation
.BlockDeviceInfo
.Unknown
|= 1;
41 BlDeviceSetInformation(DeviceId
, &DeviceInformation
);
43 /* Read the boot sector */
44 Status
= BlDeviceReadAtOffset(DeviceId
,
45 sizeof(FatBootSector
),
50 /* Restore thing back */
51 DeviceInformation
.BlockDeviceInfo
.Unknown
= UnknownFlag
;
52 BlDeviceSetInformation(DeviceId
, &DeviceInformation
);
53 if (!NT_SUCCESS(Status
))
55 EfiPrintf(L
"Failed reading drive: %lx\r\n", Status
);
59 FatUnpackBios(&BiosBlock
, &FatBootSector
.PackedBpb
);
61 /* For now, quickly fail if this isn't FAT */
62 if (FatBootSector
.Jump
[0] != 0xE9)
64 return STATUS_UNSUCCESSFUL
;
67 EfiPrintf(L
"Jump: %lx Bytes Per Sector: %d Sectors Per Cluster: %d Reserved: %d Fats: %d Sectors: %d Large Sectors: %d Media: %lx RootEntries: %d\r\n",
68 FatBootSector
.Jump
[0],
69 BiosBlock
.BytesPerSector
,
70 BiosBlock
.SectorsPerCluster
,
71 BiosBlock
.ReservedSectors
,
74 BiosBlock
.LargeSectors
,
76 BiosBlock
.RootEntries
);
77 return STATUS_NOT_IMPLEMENTED
;
87 /* Allocate the device table with 2 entries*/
88 FatDeviceTableEntries
= 2;
89 FatDeviceTable
= BlMmAllocateHeap(sizeof(PBL_FILE_ENTRY
) *
90 FatDeviceTableEntries
);
94 RtlZeroMemory(FatDeviceTable
,
95 sizeof(PBL_FILE_ENTRY
) * FatDeviceTableEntries
);
97 /* Allocate a 512 byte buffer for long file name conversion */
98 FatpLongFileName
= BlMmAllocateHeap(512);
99 Status
= FatpLongFileName
!= NULL
? STATUS_SUCCESS
: STATUS_NO_MEMORY
;
103 /* No memory, fail */
104 Status
= STATUS_NO_MEMORY
;
107 /* Return back to caller */