717ac4f3cb77a132ae50f7ab0ebfe5509cf91f71
[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 EfiPrintf(L"Reading fat boot sector...\r\n");
47 Status = BlDeviceReadAtOffset(DeviceId,
48 sizeof(FatBootSector),
49 0,
50 &FatBootSector,
51 NULL);
52
53 /* Restore thing back */
54 DeviceInformation.BlockDeviceInfo.Unknown = UnknownFlag;
55 BlDeviceSetInformation(DeviceId, &DeviceInformation);
56 if (!NT_SUCCESS(Status))
57 {
58 EfiPrintf(L"Failed reading drive: %lx\r\n", Status);
59 return Status;
60 }
61
62 FatUnpackBios(&BiosBlock, &FatBootSector.PackedBpb);
63
64 EfiPrintf(L"Drive read\r\n");
65
66 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",
67 FatBootSector.Jump[0],
68 BiosBlock.BytesPerSector,
69 BiosBlock.SectorsPerCluster,
70 BiosBlock.ReservedSectors,
71 BiosBlock.Fats,
72 BiosBlock.Sectors,
73 BiosBlock.LargeSectors,
74 BiosBlock.Media,
75 BiosBlock.RootEntries);
76
77 EfiStall(3000000);
78 return STATUS_NOT_IMPLEMENTED;
79 }
80
81 NTSTATUS
82 FatInitialize (
83 VOID
84 )
85 {
86 NTSTATUS Status;
87
88 /* Allocate the device table with 2 entries*/
89 FatDeviceTableEntries = 2;
90 FatDeviceTable = BlMmAllocateHeap(sizeof(PBL_FILE_ENTRY) *
91 FatDeviceTableEntries);
92 if (FatDeviceTable)
93 {
94 /* Zero it out */
95 RtlZeroMemory(FatDeviceTable,
96 sizeof(PBL_FILE_ENTRY) * FatDeviceTableEntries);
97
98 /* Allocate a 512 byte buffer for long file name conversion */
99 FatpLongFileName = BlMmAllocateHeap(512);
100 Status = FatpLongFileName != NULL ? STATUS_SUCCESS : STATUS_NO_MEMORY;
101 }
102 else
103 {
104 /* No memory, fail */
105 Status = STATUS_NO_MEMORY;
106 }
107
108 /* Return back to caller */
109 return Status;
110 }
111