]>
git.proxmox.com Git - mirror_edk2.git/blob - BaseTools/Source/C/GenBootSector/GetDrvNumOffset.c
3 Get Drv Num offset from Fat file system.
5 Copyright (c) 2006 - 2008, Intel Corporation. All rights reserved.<BR>
6 This program and the accompanying materials
7 are licensed and made available under the terms and conditions of the BSD License
8 which accompanies this distribution. The full text of the license may be found at
9 http://opensource.org/licenses/bsd-license.php
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
17 #include "FatFormat.h"
24 FAT_BPB_STRUCT
*FatBpb
;
29 UINTN CountOfClusters
;
31 FatBpb
= (FAT_BPB_STRUCT
*) BootSector
;
34 // Check FAT type algorithm from FAT spec
36 RootDirSectors
= ((FatBpb
->Fat12_16
.BPB_RootEntCnt
* sizeof(FAT_DIRECTORY_ENTRY
)) +
37 (FatBpb
->Fat12_16
.BPB_BytsPerSec
- 1)) / FatBpb
->Fat12_16
.BPB_BytsPerSec
;
39 if (FatBpb
->Fat12_16
.BPB_FATSz16
!= 0) {
40 FATSz
= FatBpb
->Fat12_16
.BPB_FATSz16
;
42 FATSz
= FatBpb
->Fat32
.BPB_FATSz32
;
45 fprintf (stderr
, "error E3003: FAT - BPB_FATSz16, BPB_FATSz32 - 0, expected: Non-Zero number\n");
49 if (FatBpb
->Fat12_16
.BPB_TotSec16
!= 0) {
50 TotSec
= FatBpb
->Fat12_16
.BPB_TotSec16
;
52 TotSec
= FatBpb
->Fat12_16
.BPB_TotSec32
;
55 fprintf (stderr
, "error E3003: FAT - BPB_TotSec16, BPB_TotSec32 - 0, expected: Non-Zero number\n");
60 FatBpb
->Fat12_16
.BPB_RsvdSecCnt
+
61 FatBpb
->Fat12_16
.BPB_NumFATs
* FATSz
+
65 CountOfClusters
= DataSec
/ FatBpb
->Fat12_16
.BPB_SecPerClus
;
67 if (CountOfClusters
< FAT_MAX_FAT16_CLUSTER
) {
68 return (INTN
) ((UINTN
) &FatBpb
->Fat12_16
.BS_DrvNum
- (UINTN
) FatBpb
);
70 return (INTN
) ((UINTN
) &FatBpb
->Fat32
.BS_DrvNum
- (UINTN
) FatBpb
);