ReactOS 0.4.15-dev-7934-g1dc8d80
fat.c
Go to the documentation of this file.
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 <fs_rec/fs_rec.h>
13
14/* DATA VARIABLES ************************************************************/
15
19
20/* FUNCTIONS *****************************************************************/
21
24 _In_ ULONG DeviceId,
26 _Out_ PBL_FILE_ENTRY* FileEntry
27 )
28{
29 BL_DEVICE_INFORMATION DeviceInformation;
30 ULONG UnknownFlag;
32 PACKED_BOOT_SECTOR FatBootSector;
33 BIOS_PARAMETER_BLOCK BiosBlock;
34
35 /* Capture thing */
36 BlDeviceGetInformation(DeviceId, &DeviceInformation);
37 UnknownFlag = DeviceInformation.BlockDeviceInfo.Unknown;
38
39 /* Set thing to 1 */
40 DeviceInformation.BlockDeviceInfo.Unknown |= 1;
41 BlDeviceSetInformation(DeviceId, &DeviceInformation);
42
43 /* Read the boot sector */
45 sizeof(FatBootSector),
46 0,
47 &FatBootSector,
48 NULL);
49
50 /* Restore thing back */
51 DeviceInformation.BlockDeviceInfo.Unknown = UnknownFlag;
52 BlDeviceSetInformation(DeviceId, &DeviceInformation);
53 if (!NT_SUCCESS(Status))
54 {
55 EfiPrintf(L"Failed reading drive: %lx\r\n", Status);
56 return Status;
57 }
58
59 FatUnpackBios(&BiosBlock, &FatBootSector.PackedBpb);
60
61 /* For now, quickly fail if this isn't FAT */
62 if (FatBootSector.Jump[0] != 0xE9)
63 {
65 }
66
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,
72 BiosBlock.Fats,
73 BiosBlock.Sectors,
74 BiosBlock.LargeSectors,
75 BiosBlock.Media,
76 BiosBlock.RootEntries);
78}
79
82 VOID
83 )
84{
86
87 /* Allocate the device table with 2 entries*/
92 {
93 /* Zero it out */
96
97 /* Allocate a 512 byte buffer for long file name conversion */
100 }
101 else
102 {
103 /* No memory, fail */
105 }
106
107 /* Return back to caller */
108 return Status;
109}
110
LONG NTSTATUS
Definition: precomp.h:26
NTSTATUS BlDeviceGetInformation(_In_ ULONG DeviceId, _Out_ PBL_DEVICE_INFORMATION DeviceInformation)
Definition: device.c:682
NTSTATUS BlDeviceReadAtOffset(_In_ ULONG DeviceId, _In_ ULONG Size, _In_ ULONGLONG Offset, _In_ PVOID Buffer, _Out_ PULONG BytesRead)
Definition: device.c:773
VOID EfiPrintf(_In_ PWCHAR Format,...)
Definition: firmware.c:126
PVOID BlMmAllocateHeap(_In_ SIZE_T Size)
Definition: heapalloc.c:569
NTSTATUS BlDeviceSetInformation(_In_ ULONG DeviceId, _In_ PBL_DEVICE_INFORMATION DeviceInformation)
NTSTATUS FatInitialize(VOID)
Definition: fat.c:81
NTSTATUS FatMount(_In_ ULONG DeviceId, _In_ ULONG Unknown, _Out_ PBL_FILE_ENTRY *FileEntry)
Definition: fat.c:23
ULONG FatDeviceTableEntries
Definition: fat.c:17
PVOID * FatDeviceTable
Definition: fat.c:16
PWCHAR FatpLongFileName
Definition: fat.c:18
#define NULL
Definition: types.h:112
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define FatUnpackBios(Bios, Pbios)
Definition: fat.h:136
Status
Definition: gdiplustypes.h:25
@ Unknown
Definition: i8042prt.h:114
#define _Out_
Definition: ms_sal.h:345
#define _In_
Definition: ms_sal.h:308
#define STATUS_NO_MEMORY
Definition: ntstatus.h:260
#define STATUS_NOT_IMPLEMENTED
Definition: ntstatus.h:239
#define L(x)
Definition: ntvdm.h:50
#define STATUS_SUCCESS
Definition: shellext.h:65
USHORT ReservedSectors
Definition: fat.h:106
USHORT BytesPerSector
Definition: fat.h:104
USHORT Sectors
Definition: fat.h:109
ULONG32 LargeSectors
Definition: fat.h:115
USHORT RootEntries
Definition: fat.h:108
UCHAR SectorsPerCluster
Definition: fat.h:105
BL_BLOCK_DEVICE_INFORMATION BlockDeviceInfo
Definition: bl.h:1228
Definition: bl.h:1038
UCHAR Jump[3]
Definition: fat.h:163
PACKED_BIOS_PARAMETER_BLOCK PackedBpb
Definition: fat.h:165
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
uint16_t * PWCHAR
Definition: typedefs.h:56
uint32_t ULONG
Definition: typedefs.h:59
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132