7945ddf96d5f39a907a662c04aff875403367c1f
[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
34 EfiPrintf(L"FAT Mount on Device %d\r\n", DeviceId);
35
36 /* Capture thing */
37 BlDeviceGetInformation(DeviceId, &DeviceInformation);
38 UnknownFlag = DeviceInformation.BlockDeviceInfo.Unknown;
39
40 /* Set thing to 1 */
41 DeviceInformation.BlockDeviceInfo.Unknown |= 1;
42 BlDeviceSetInformation(DeviceId, &DeviceInformation);
43
44 /* Read the boot sector */
45 EfiPrintf(L"Reading fat boot sector...\r\n");
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 EfiPrintf(L"Drive read\r\n");
62 EfiStall(3000000);
63 return STATUS_NOT_IMPLEMENTED;
64 }
65
66 NTSTATUS
67 FatInitialize (
68 VOID
69 )
70 {
71 NTSTATUS Status;
72
73 /* Allocate the device table with 2 entries*/
74 FatDeviceTableEntries = 2;
75 FatDeviceTable = BlMmAllocateHeap(sizeof(PBL_FILE_ENTRY) *
76 FatDeviceTableEntries);
77 if (FatDeviceTable)
78 {
79 /* Zero it out */
80 RtlZeroMemory(FatDeviceTable,
81 sizeof(PBL_FILE_ENTRY) * FatDeviceTableEntries);
82
83 /* Allocate a 512 byte buffer for long file name conversion */
84 FatpLongFileName = BlMmAllocateHeap(512);
85 Status = FatpLongFileName != NULL ? STATUS_SUCCESS : STATUS_NO_MEMORY;
86 }
87 else
88 {
89 /* No memory, fail */
90 Status = STATUS_NO_MEMORY;
91 }
92
93 /* Return back to caller */
94 return Status;
95 }
96