ReactOS  0.4.14-dev-315-gbb6fece
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 */
44  Status = BlDeviceReadAtOffset(DeviceId,
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  {
64  return STATUS_UNSUCCESSFUL;
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*/
91  if (FatDeviceTable)
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 
UCHAR Jump[3]
Definition: fat.h:163
PVOID * FatDeviceTable
Definition: fat.c:16
#define STATUS_NOT_IMPLEMENTED
Definition: ntstatus.h:225
NTSTATUS FatMount(_In_ ULONG DeviceId, _In_ ULONG Unknown, _Out_ PBL_FILE_ENTRY *FileEntry)
Definition: fat.c:23
LONG NTSTATUS
Definition: precomp.h:26
uint16_t * PWCHAR
Definition: typedefs.h:54
NTSTATUS BlDeviceGetInformation(_In_ ULONG DeviceId, _Out_ PBL_DEVICE_INFORMATION DeviceInformation)
Definition: device.c:682
USHORT Sectors
Definition: fat.h:109
smooth NULL
Definition: ftsmooth.c:416
PVOID BlMmAllocateHeap(_In_ SIZE_T Size)
Definition: heapalloc.c:569
BL_BLOCK_DEVICE_INFORMATION BlockDeviceInfo
Definition: bl.h:1229
#define _Out_
Definition: no_sal2.h:323
PWCHAR FatpLongFileName
Definition: fat.c:18
NTSTATUS BlDeviceReadAtOffset(_In_ ULONG DeviceId, _In_ ULONG Size, _In_ ULONGLONG Offset, _In_ PVOID Buffer, _Out_ PULONG BytesRead)
Definition: device.c:773
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
USHORT BytesPerSector
Definition: fat.h:104
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
USHORT RootEntries
Definition: fat.h:108
static const WCHAR L[]
Definition: oid.c:1250
PACKED_BIOS_PARAMETER_BLOCK PackedBpb
Definition: fat.h:165
Status
Definition: gdiplustypes.h:24
#define _In_
Definition: no_sal2.h:204
USHORT ReservedSectors
Definition: fat.h:106
ULONG FatDeviceTableEntries
Definition: fat.c:17
Definition: bl.h:1038
NTSTATUS FatInitialize(VOID)
Definition: fat.c:81
#define STATUS_NO_MEMORY
Definition: ntstatus.h:246
VOID EfiPrintf(_In_ PWCHAR Format,...)
Definition: firmware.c:126
unsigned int ULONG
Definition: retypes.h:1
UCHAR SectorsPerCluster
Definition: fat.h:105
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:261
#define FatUnpackBios(Bios, Pbios)
Definition: fat.h:136
NTSTATUS BlDeviceSetInformation(_In_ ULONG DeviceId, _In_ PBL_DEVICE_INFORMATION DeviceInformation)
return STATUS_SUCCESS
Definition: btrfs.c:2938
ULONG32 LargeSectors
Definition: fat.h:115