]> git.proxmox.com Git - mirror_edk2.git/blobdiff - BaseTools/Source/C/BootSectImage/bootsectimage.c
BaseTools: Clean up source files
[mirror_edk2.git] / BaseTools / Source / C / BootSectImage / bootsectimage.c
index 36e896e5c4bee0866715711e17587e6f481ff12c..72cad168698c7fcae317f24683a10dd90eea06f2 100644 (file)
@@ -4,14 +4,14 @@ Abstract:
   Patch the BPB information in boot sector image file.\r
   Patch the MBR code in MBR image file.\r
 \r
   Patch the BPB information in boot sector image file.\r
   Patch the MBR code in MBR image file.\r
 \r
-Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>\r
-This program and the accompanying materials                          \r
-are licensed and made available under the terms and conditions of the BSD License         \r
-which accompanies this distribution.  The full text of the license may be found at        \r
-http://opensource.org/licenses/bsd-license.php                                            \r
-                                                                                          \r
-THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,                     \r
-WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.             \r
+Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>\r
+This program and the accompanying materials\r
+are licensed and made available under the terms and conditions of the BSD License\r
+which accompanies this distribution.  The full text of the license may be found at\r
+http://opensource.org/licenses/bsd-license.php\r
+\r
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
 \r
 **/\r
 \r
 \r
 **/\r
 \r
@@ -33,8 +33,8 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 //\r
 // Utility version information\r
 //\r
 //\r
 // Utility version information\r
 //\r
-#define UTILITY_MAJOR_VERSION 0\r
-#define UTILITY_MINOR_VERSION 1\r
+#define UTILITY_MAJOR_VERSION 1\r
+#define UTILITY_MINOR_VERSION 0\r
 \r
 void\r
 Version (\r
 \r
 void\r
 Version (\r
@@ -56,8 +56,7 @@ Returns:
 \r
 --*/\r
 {\r
 \r
 --*/\r
 {\r
-  printf ("%s v%d.%d %s - Utility to break a file into two pieces at the specified offset.\n", UTILITY_NAME, UTILITY_MAJOR_VERSION, UTILITY_MINOR_VERSION, __BUILD_VERSION);\r
-  printf ("Copyright (c) 1999-2010 Intel Corporation. All rights reserved.\n");\r
+  printf ("%s Version %d.%d Build %s\n", UTILITY_NAME, UTILITY_MAJOR_VERSION, UTILITY_MINOR_VERSION, __BUILD_VERSION);\r
 }\r
 \r
 void\r
 }\r
 \r
 void\r
@@ -80,6 +79,9 @@ Returns:
 --*/\r
 {\r
   Version();\r
 --*/\r
 {\r
   Version();\r
+  printf ("Copyright (c) 1999-2016 Intel Corporation. All rights reserved.\n");\r
+  printf ("\n  The BootSectImage tool prints information or patch destination file by source\n");\r
+  printf ("  file for BIOS Parameter Block (BPB) or Master Boot Record (MBR).\n");\r
   printf ("\nUsage: \n\\r
    BootSectImage\n\\r
      [-f, --force force patch even if the FAT type of SrcImage and DstImage mismatch]\n\\r
   printf ("\nUsage: \n\\r
    BootSectImage\n\\r
      [-f, --force force patch even if the FAT type of SrcImage and DstImage mismatch]\n\\r
@@ -96,7 +98,7 @@ Returns:
 }\r
 \r
 int WriteToFile (\r
 }\r
 \r
 int WriteToFile (\r
-  void *BootSector, \r
+  void *BootSector,\r
   char *FileName\r
   )\r
 /*++\r
   char *FileName\r
   )\r
 /*++\r
@@ -116,7 +118,7 @@ Return:
   FILE *FileHandle;\r
   int  result;\r
 \r
   FILE *FileHandle;\r
   int  result;\r
 \r
-  FileHandle = fopen (FileName, "r+b");\r
+  FileHandle = fopen (LongFilePath (FileName), "r+b");\r
   if (FileHandle == NULL) {\r
     DebugMsg (NULL, 0, DEBUG_ERROR, NULL, "Open file: %s", FileName);\r
     return 0;\r
   if (FileHandle == NULL) {\r
     DebugMsg (NULL, 0, DEBUG_ERROR, NULL, "Open file: %s", FileName);\r
     return 0;\r
@@ -134,7 +136,7 @@ Return:
 }\r
 \r
 int ReadFromFile (\r
 }\r
 \r
 int ReadFromFile (\r
-  void *BootSector, \r
+  void *BootSector,\r
   char *FileName\r
   )\r
 /*++\r
   char *FileName\r
   )\r
 /*++\r
@@ -154,7 +156,7 @@ Return:
   FILE *FileHandle;\r
   int  result;\r
 \r
   FILE *FileHandle;\r
   int  result;\r
 \r
-  FileHandle = fopen (FileName, "rb");\r
+  FileHandle = fopen (LongFilePath (FileName), "rb");\r
   if (FileHandle == NULL) {\r
     DebugMsg (NULL, 0, DEBUG_ERROR, NULL, "ERROR: E0001: Error opening file: %s", FileName);\r
     return 0;\r
   if (FileHandle == NULL) {\r
     DebugMsg (NULL, 0, DEBUG_ERROR, NULL, "ERROR: E0001: Error opening file: %s", FileName);\r
     return 0;\r
@@ -444,17 +446,17 @@ Return:
         FatBpb->Fat32.BS_BootSig, FAT_BS_BOOTSIG);\r
     return FatTypeUnknown;\r
   }\r
         FatBpb->Fat32.BS_BootSig, FAT_BS_BOOTSIG);\r
     return FatTypeUnknown;\r
   }\r
-  \r
+\r
   if ((FatType == FatTypeFat12) || (FatType == FatTypeFat16)) {\r
     memcpy (FilSysType, FatBpb->Fat12_16.BS_FilSysType, 8);\r
     FilSysType[8] = 0;\r
   if ((FatType == FatTypeFat12) || (FatType == FatTypeFat16)) {\r
     memcpy (FilSysType, FatBpb->Fat12_16.BS_FilSysType, 8);\r
     FilSysType[8] = 0;\r
-    if ((FatType == FatTypeFat12) && \r
+    if ((FatType == FatTypeFat12) &&\r
         (strcmp (FilSysType, FAT12_FILSYSTYPE) != 0) &&\r
         (strcmp (FilSysType, FAT_FILSYSTYPE) != 0)) {\r
       DebugMsg (NULL, 0, DEBUG_WARN, NULL, "ERROR: E3003: FAT12 - BS_FilSysType - %s, expected: %s, or %s\n",\r
           FilSysType, FAT12_FILSYSTYPE, FAT_FILSYSTYPE);\r
     }\r
         (strcmp (FilSysType, FAT12_FILSYSTYPE) != 0) &&\r
         (strcmp (FilSysType, FAT_FILSYSTYPE) != 0)) {\r
       DebugMsg (NULL, 0, DEBUG_WARN, NULL, "ERROR: E3003: FAT12 - BS_FilSysType - %s, expected: %s, or %s\n",\r
           FilSysType, FAT12_FILSYSTYPE, FAT_FILSYSTYPE);\r
     }\r
-    if ((FatType == FatTypeFat16) && \r
+    if ((FatType == FatTypeFat16) &&\r
         (strcmp (FilSysType, FAT16_FILSYSTYPE) != 0) &&\r
         (strcmp (FilSysType, FAT_FILSYSTYPE) != 0)) {\r
       DebugMsg (NULL, 0, DEBUG_WARN, NULL, "ERROR: E3003: FAT16 - BS_FilSysType - %s, expected: %s, or %s\n",\r
         (strcmp (FilSysType, FAT16_FILSYSTYPE) != 0) &&\r
         (strcmp (FilSysType, FAT_FILSYSTYPE) != 0)) {\r
       DebugMsg (NULL, 0, DEBUG_WARN, NULL, "ERROR: E3003: FAT16 - BS_FilSysType - %s, expected: %s, or %s\n",\r
@@ -484,11 +486,11 @@ ParseBootSector (
 {\r
   FAT_BPB_STRUCT  FatBpb;\r
   FAT_TYPE        FatType;\r
 {\r
   FAT_BPB_STRUCT  FatBpb;\r
   FAT_TYPE        FatType;\r
-  \r
+\r
   if (ReadFromFile ((void *)&FatBpb, FileName) == 0) {\r
     return ;\r
   }\r
   if (ReadFromFile ((void *)&FatBpb, FileName) == 0) {\r
     return ;\r
   }\r
-  \r
+\r
   FatType = GetFatType (&FatBpb);\r
   if (FatType <= FatTypeUnknown || FatType >= FatTypeMax) {\r
     printf ("ERROR: E3002: Unknown FAT Type!\n");\r
   FatType = GetFatType (&FatBpb);\r
   if (FatType <= FatTypeUnknown || FatType >= FatTypeMax) {\r
     printf ("ERROR: E3002: Unknown FAT Type!\n");\r
@@ -606,7 +608,7 @@ ParseBootSector (
   printf ("  1FE    Signature                    %04x\n", FatBpb.Fat12_16.Signature);\r
   printf ("\n");\r
 \r
   printf ("  1FE    Signature                    %04x\n", FatBpb.Fat12_16.Signature);\r
   printf ("\n");\r
 \r
-  \r
+\r
   return ;\r
 }\r
 \r
   return ;\r
 }\r
 \r
@@ -632,14 +634,14 @@ Arguments:
   FAT_TYPE        SourceFatType;\r
   CHAR8           VolLab[11];\r
   CHAR8           FilSysType[8];\r
   FAT_TYPE        SourceFatType;\r
   CHAR8           VolLab[11];\r
   CHAR8           FilSysType[8];\r
-  \r
+\r
   if (ReadFromFile ((void *)&DestFatBpb, DestFileName) == 0) {\r
     return ;\r
   }\r
   if (ReadFromFile ((void *)&SourceFatBpb, SourceFileName) == 0) {\r
     return ;\r
   }\r
   if (ReadFromFile ((void *)&DestFatBpb, DestFileName) == 0) {\r
     return ;\r
   }\r
   if (ReadFromFile ((void *)&SourceFatBpb, SourceFileName) == 0) {\r
     return ;\r
   }\r
-  \r
+\r
   DestFatType = GetFatType (&DestFatBpb);\r
   SourceFatType = GetFatType (&SourceFatBpb);\r
 \r
   DestFatType = GetFatType (&DestFatBpb);\r
   SourceFatType = GetFatType (&SourceFatBpb);\r
 \r
@@ -648,10 +650,10 @@ Arguments:
     // FAT type mismatch\r
     //\r
     if (ForcePatch) {\r
     // FAT type mismatch\r
     //\r
     if (ForcePatch) {\r
-      DebugMsg (NULL, 0, DEBUG_WARN, NULL, "ERROR: E3004: FAT type mismatch: Source - %s, Dest - %s", \r
+      DebugMsg (NULL, 0, DEBUG_WARN, NULL, "ERROR: E3004: FAT type mismatch: Source - %s, Dest - %s",\r
         FatTypeToString(SourceFatType), FatTypeToString(DestFatType));\r
     } else {\r
         FatTypeToString(SourceFatType), FatTypeToString(DestFatType));\r
     } else {\r
-      DebugMsg (NULL, 0, DEBUG_ERROR, NULL, "ERROR: E3004: FAT type mismatch: Source - %s, Dest - %s", \r
+      DebugMsg (NULL, 0, DEBUG_ERROR, NULL, "ERROR: E3004: FAT type mismatch: Source - %s, Dest - %s",\r
         FatTypeToString(SourceFatType), FatTypeToString(DestFatType));\r
       return ;\r
     }\r
         FatTypeToString(SourceFatType), FatTypeToString(DestFatType));\r
       return ;\r
     }\r
@@ -705,7 +707,7 @@ Arguments:
     memcpy (DestFatBpb.Fat32.BS_VolLab, VolLab, sizeof(VolLab));\r
     memcpy (DestFatBpb.Fat32.BS_FilSysType, FilSysType, sizeof(FilSysType));\r
   }\r
     memcpy (DestFatBpb.Fat32.BS_VolLab, VolLab, sizeof(VolLab));\r
     memcpy (DestFatBpb.Fat32.BS_FilSysType, FilSysType, sizeof(FilSysType));\r
   }\r
-  \r
+\r
   //\r
   // Set Signature of DestFatBpb to 55AA\r
   //\r
   //\r
   // Set Signature of DestFatBpb to 55AA\r
   //\r
@@ -729,11 +731,11 @@ ParseMbr (
   )\r
 {\r
   MASTER_BOOT_RECORD  Mbr;\r
   )\r
 {\r
   MASTER_BOOT_RECORD  Mbr;\r
-  \r
+\r
   if (ReadFromFile ((void *)&Mbr, FileName) == 0) {\r
     return ;\r
   }\r
   if (ReadFromFile ((void *)&Mbr, FileName) == 0) {\r
     return ;\r
   }\r
\r
+\r
   printf ("\nMaster Boot Record:\n");\r
   printf ("\n");\r
   printf ("  Offset Title                        Value\n");\r
   printf ("\nMaster Boot Record:\n");\r
   printf ("\n");\r
   printf ("  Offset Title                        Value\n");\r
@@ -803,14 +805,14 @@ PatchMbr (
 {\r
   MASTER_BOOT_RECORD  DestMbr;\r
   MASTER_BOOT_RECORD  SourceMbr;\r
 {\r
   MASTER_BOOT_RECORD  DestMbr;\r
   MASTER_BOOT_RECORD  SourceMbr;\r
-  \r
+\r
   if (ReadFromFile ((void *)&DestMbr, DestFileName) == 0) {\r
     return ;\r
   }\r
   if (ReadFromFile ((void *)&SourceMbr, SourceFileName) == 0) {\r
     return ;\r
   }\r
   if (ReadFromFile ((void *)&DestMbr, DestFileName) == 0) {\r
     return ;\r
   }\r
   if (ReadFromFile ((void *)&SourceMbr, SourceFileName) == 0) {\r
     return ;\r
   }\r
-  \r
+\r
   if (SourceMbr.Signature != MBR_SIGNATURE) {\r
     printf ("ERROR: E3000: Invalid MBR!\n");\r
     return;\r
   if (SourceMbr.Signature != MBR_SIGNATURE) {\r
     printf ("ERROR: E3000: Invalid MBR!\n");\r
     return;\r
@@ -889,6 +891,9 @@ main (
       ProcessMbr = TRUE;\r
     } else if (strcmp (*argv, "-v") == 0 || strcmp (*argv, "--verbose") == 0) {\r
       Verbose    = TRUE;\r
       ProcessMbr = TRUE;\r
     } else if (strcmp (*argv, "-v") == 0 || strcmp (*argv, "--verbose") == 0) {\r
       Verbose    = TRUE;\r
+    } else if (strcmp (*argv, "--version") == 0) {\r
+      Version();\r
+      return 0;\r
     } else if ((stricmp (*argv, "-d") == 0) || (stricmp (*argv, "--debug") == 0)) {\r
       argc--; argv++;\r
       if (argc < 1) {\r
     } else if ((stricmp (*argv, "-d") == 0) || (stricmp (*argv, "--debug") == 0)) {\r
       argc--; argv++;\r
       if (argc < 1) {\r