[BOOTMGFW]
[reactos.git] / reactos / boot / environ / lib / io / fat.c
1 /*
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)
7 */
8
9 /* INCLUDES ******************************************************************/
10
11 #include "bl.h"
12 #include "../drivers/filesystems/fs_rec/fs_rec.h"
13
14 /* DATA VARIABLES ************************************************************/
15
16 PVOID* FatDeviceTable;
17 ULONG FatDeviceTableEntries;
18 PWCHAR FatpLongFileName;
19
20 /* FUNCTIONS *****************************************************************/
21
22 NTSTATUS
23 FatMount (
24 _In_ ULONG DeviceId,
25 _In_ ULONG Unknown,
26 _Out_ PBL_FILE_ENTRY* FileEntry
27 )
28 {
29 BL_DEVICE_INFORMATION DeviceInformation;
30 ULONG UnknownFlag;
31 NTSTATUS Status;
32 PACKED_BOOT_SECTOR FatBootSector;
33 BIOS_PARAMETER_BLOCK BiosBlock;
34
35 EfiPrintf(L"FAT Mount on Device %d\r\n", DeviceId);
36
37 /* Capture thing */
38 BlDeviceGetInformation(DeviceId, &DeviceInformation);
39 UnknownFlag = DeviceInformation.BlockDeviceInfo.Unknown;
40
41 /* Set thing to 1 */
42 DeviceInformation.BlockDeviceInfo.Unknown |= 1;
43 BlDeviceSetInformation(DeviceId, &DeviceInformation);
44
45 /* Read the boot sector */
46 Status = BlDeviceReadAtOffset(DeviceId,
47 sizeof(FatBootSector),
48 0,
49 &FatBootSector,
50 NULL);
51
52 /* Restore thing back */
53 DeviceInformation.BlockDeviceInfo.Unknown = UnknownFlag;
54 BlDeviceSetInformation(DeviceId, &DeviceInformation);
55 if (!NT_SUCCESS(Status))
56 {
57 EfiPrintf(L"Failed reading drive: %lx\r\n", Status);
58 return Status;
59 }
60
61 FatUnpackBios(&BiosBlock, &FatBootSector.PackedBpb);
62
63 /* For now, quickly fail if this isn't FAT */
64 if (FatBootSector.Jump[0] != 0xE9)
65 {
66 return STATUS_UNSUCCESSFUL;
67 }
68
69 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",
70 FatBootSector.Jump[0],
71 BiosBlock.BytesPerSector,
72 BiosBlock.SectorsPerCluster,
73 BiosBlock.ReservedSectors,
74 BiosBlock.Fats,
75 BiosBlock.Sectors,
76 BiosBlock.LargeSectors,
77 BiosBlock.Media,
78 BiosBlock.RootEntries);
79
80 return STATUS_NOT_IMPLEMENTED;
81 }
82
83 NTSTATUS
84 FatInitialize (
85 VOID
86 )
87 {
88 NTSTATUS Status;
89
90 /* Allocate the device table with 2 entries*/
91 FatDeviceTableEntries = 2;
92 FatDeviceTable = BlMmAllocateHeap(sizeof(PBL_FILE_ENTRY) *
93 FatDeviceTableEntries);
94 if (FatDeviceTable)
95 {
96 /* Zero it out */
97 RtlZeroMemory(FatDeviceTable,
98 sizeof(PBL_FILE_ENTRY) * FatDeviceTableEntries);
99
100 /* Allocate a 512 byte buffer for long file name conversion */
101 FatpLongFileName = BlMmAllocateHeap(512);
102 Status = FatpLongFileName != NULL ? STATUS_SUCCESS : STATUS_NO_MEMORY;
103 }
104 else
105 {
106 /* No memory, fail */
107 Status = STATUS_NO_MEMORY;
108 }
109
110 /* Return back to caller */
111 return Status;
112 }
113