]> git.proxmox.com Git - mirror_edk2.git/blobdiff - BaseTools/Source/C/GenBootSector/GenBootSector.c
BaseTools: Clean up source files
[mirror_edk2.git] / BaseTools / Source / C / GenBootSector / GenBootSector.c
index c02de49ba2ad6e3e67e59f68853e8655cf572e68..2385ccc640088429b38cbd1374440c32c8619835 100644 (file)
@@ -3,15 +3,15 @@ Reading/writing MBR/DBR.
   NOTE:\r
     If we write MBR to disk, we just update the MBR code and the partition table wouldn't be over written.\r
     If we process DBR, we will patch MBR to set first partition active if no active partition exists.\r
-    \r
-Copyright (c) 2006 - 2017, 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
+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
@@ -166,16 +166,16 @@ Return:
                    );\r
   if (VolumeHandle == INVALID_HANDLE_VALUE) {\r
     fprintf (\r
-      stderr, \r
-      "error E0005: CreateFile failed: Volume = %s, LastError = 0x%lx\n", \r
-      VolumeAccessPath, \r
+      stderr,\r
+      "error E0005: CreateFile failed: Volume = %s, LastError = 0x%lx\n",\r
+      VolumeAccessPath,\r
       GetLastError ()\r
       );\r
     return FALSE;\r
   }\r
 \r
   //\r
-  // Get Disk Number. It should fail when operating on floppy. That's ok \r
+  // Get Disk Number. It should fail when operating on floppy. That's ok\r
   //  because Disk Number is only needed when operating on Hard or USB disk.\r
   //\r
   // To direct write to disk:\r
@@ -183,13 +183,13 @@ Return:
   //   for floppy:     use path = \\.\X:, where X can be A or B\r
   //\r
   Success = DeviceIoControl(\r
-              VolumeHandle, \r
+              VolumeHandle,\r
               IOCTL_STORAGE_GET_DEVICE_NUMBER,\r
-              NULL, \r
-              0, \r
-              &StorageDeviceNumber, \r
+              NULL,\r
+              0,\r
+              &StorageDeviceNumber,\r
               sizeof(StorageDeviceNumber),\r
-              &BytesReturned, \r
+              &BytesReturned,\r
               NULL\r
               );\r
   //\r
@@ -207,7 +207,7 @@ Return:
     DriveInfo->DiskNumber = StorageDeviceNumber.DeviceNumber;\r
   }\r
   CloseHandle(VolumeHandle);\r
-  \r
+\r
   //\r
   // Fill in the type string\r
   //\r
@@ -241,7 +241,7 @@ Routine Description:
 {\r
   UINT       Index;\r
   DRIVE_INFO DriveInfo;\r
-  \r
+\r
   UINT Mask =  GetLogicalDrives();\r
 \r
   for (Index = 0; Index < MAX_DRIVE; Index++) {\r
@@ -258,9 +258,9 @@ Routine Description:
         } else {\r
           fprintf (\r
             stdout,\r
-            "%c: - DiskNum: %u, Type: %s\n", \r
+            "%c: - DiskNum: %u, Type: %s\n",\r
             DriveInfo.VolumeLetter,\r
-            (unsigned) DriveInfo.DiskNumber, \r
+            (unsigned) DriveInfo.DiskNumber,\r
             DriveInfo.DriveType->Description\r
             );\r
         }\r
@@ -301,7 +301,7 @@ Return:
 \r
   DbrOffset = 0;\r
   HasMbr    = FALSE;\r
-  \r
+\r
   SetFilePointer(DiskHandle, 0, NULL, FILE_BEGIN);\r
   if (!ReadFile (DiskHandle, DiskPartition, 0x200, &BytesReturn, NULL)) {\r
     return -1;\r
@@ -359,12 +359,12 @@ Return:
 }\r
 \r
 /**\r
- * Get window file handle for input/ouput disk/file. \r
- *  \r
+ * Get window file handle for input/ouput disk/file.\r
+ *\r
  * @param PathInfo\r
  * @param ProcessMbr\r
  * @param FileHandle\r
- * \r
+ *\r
  * @return ERROR_STATUS\r
  */\r
 ERROR_STATUS\r
@@ -384,11 +384,11 @@ GetFileHandle (
 \r
   *FileHandle = CreateFile(\r
                    PathInfo->PhysicalPath,\r
-                   GENERIC_READ | GENERIC_WRITE, \r
-                   FILE_SHARE_READ, \r
-                   NULL, \r
-                   OpenFlag, \r
-                   FILE_ATTRIBUTE_NORMAL, \r
+                   GENERIC_READ | GENERIC_WRITE,\r
+                   FILE_SHARE_READ,\r
+                   NULL,\r
+                   OpenFlag,\r
+                   FILE_ATTRIBUTE_NORMAL,\r
                    NULL\r
                    );\r
   if (*FileHandle == INVALID_HANDLE_VALUE) {\r
@@ -419,19 +419,19 @@ GetFileHandle (
 }\r
 \r
 /**\r
-  Writing or reading boot sector or MBR according to the argument. \r
-   \r
+  Writing or reading boot sector or MBR according to the argument.\r
+\r
   @param InputInfo PATH_INFO instance for input path\r
   @param OutputInfo PATH_INFO instance for output path\r
   @param ProcessMbr TRUE is to process MBR, otherwise, processing boot sector\r
-  \r
+\r
   @return ERROR_STATUS\r
  **/\r
 ERROR_STATUS\r
 ProcessBsOrMbr (\r
   PATH_INFO     *InputInfo,\r
   PATH_INFO     *OutputInfo,\r
-  BOOL         ProcessMbr\r
+  BOOL          ProcessMbr\r
   )\r
 {\r
   BYTE              DiskPartition[0x200] = {0};\r
@@ -462,14 +462,14 @@ ProcessBsOrMbr (
 \r
   //\r
   // Read boot sector from source disk/file\r
-  // \r
+  //\r
   if (!ReadFile (InputHandle, DiskPartition, 0x200, &BytesReturn, NULL)) {\r
     Status = ErrorFileReadWrite;\r
     goto Done;\r
   }\r
 \r
   if (InputInfo->Type == PathUsb) {\r
-      // Manually set BS_DrvNum to 0x80 as window's format.exe has a bug which will clear this field discarding USB disk's MBR. \r
+      // Manually set BS_DrvNum to 0x80 as window's format.exe has a bug which will clear this field discarding USB disk's MBR.\r
       // offset of BS_DrvNum is 0x24 for FAT12/16\r
       //                        0x40 for FAT32\r
       //\r
@@ -509,7 +509,7 @@ ProcessBsOrMbr (
 \r
   //\r
   // Write boot sector to taget disk/file\r
-  // \r
+  //\r
   if (!WriteFile (OutputHandle, DiskPartition, 0x200, &BytesReturn, NULL)) {\r
     Status = ErrorFileReadWrite;\r
     goto Done;\r
@@ -555,7 +555,7 @@ PrintUsage (
   )\r
 {\r
   printf ("Usage: GenBootSector [options] --cfg-file CFG_FILE\n\n\\r
-Copyright (c) 2009 - 2014, Intel Corporation.  All rights reserved.\n\n\\r
+Copyright (c) 2009 - 2018, Intel Corporation.  All rights reserved.\n\n\\r
   Utility to retrieve and update the boot sector or MBR.\n\n\\r
 optional arguments:\n\\r
   -h, --help            Show this help message and exit\n\\r
@@ -601,7 +601,7 @@ GetPathInfo (
   //\r
   if (IsLetter(PathInfo->Path[0]) && (PathInfo->Path[1] == ':') && (PathInfo->Path[2] == '\0')) {\r
     VolumeLetter = PathInfo->Path[0];\r
-    if ((VolumeLetter == 'A') || (VolumeLetter == 'a') || \r
+    if ((VolumeLetter == 'A') || (VolumeLetter == 'a') ||\r
         (VolumeLetter == 'B') || (VolumeLetter == 'b')) {\r
       PathInfo->Type = PathFloppy;\r
       sprintf (PathInfo->PhysicalPath, FloppyPathTemplate, VolumeLetter);\r
@@ -628,8 +628,8 @@ GetPathInfo (
       return ErrorPath;\r
     }\r
 \r
-       return ErrorSuccess;\r
-  } \r
+  return ErrorSuccess;\r
+  }\r
 \r
   //\r
   // Check the path length\r
@@ -660,7 +660,7 @@ GetPathInfo (
   PathInfo->PhysicalPath[sizeof (PathInfo->PhysicalPath) / sizeof (PathInfo->PhysicalPath[0]) - 1] = 0;\r
 \r
   return ErrorSuccess;\r
-}    \r
+}\r
 \r
 INT\r
 main (\r
@@ -682,14 +682,14 @@ main (
   AppName = *argv;\r
   argv ++;\r
   argc --;\r
-  \r
+\r
   ProcessMbr    = FALSE;\r
 \r
   if (argc == 0) {\r
     PrintUsage();\r
     return 0;\r
   }\r
-   \r
+\r
   //\r
   // Parse command line\r
   //\r
@@ -697,23 +697,23 @@ main (
     if ((stricmp (argv[Index], "-l") == 0) || (stricmp (argv[Index], "--list") == 0)) {\r
       ListDrive ();\r
       return 0;\r
-    } \r
-    \r
+    }\r
+\r
     if ((stricmp (argv[Index], "-m") == 0) || (stricmp (argv[Index], "--mbr") == 0)) {\r
       ProcessMbr = TRUE;\r
       continue;\r
-    } \r
-    \r
+    }\r
+\r
     if ((stricmp (argv[Index], "-i") == 0) || (stricmp (argv[Index], "--input") == 0)) {\r
       InputPathInfo.Path  = argv[Index + 1];\r
       InputPathInfo.Input = TRUE;\r
       if (InputPathInfo.Path == NULL) {\r
         Error (NULL, 0, 1003, "Invalid option value", "Input file name can't be NULL");\r
         return 1;\r
-      } \r
+      }\r
       if (InputPathInfo.Path[0] == '-') {\r
         Error (NULL, 0, 1003, "Invalid option value", "Input file is missing");\r
-        return 1;       \r
+        return 1;\r
       }\r
       ++Index;\r
       continue;\r
@@ -725,33 +725,33 @@ main (
       if (OutputPathInfo.Path == NULL) {\r
         Error (NULL, 0, 1003, "Invalid option value", "Output file name can't be NULL");\r
         return 1;\r
-      } \r
+      }\r
       if (OutputPathInfo.Path[0] == '-') {\r
         Error (NULL, 0, 1003, "Invalid option value", "Output file is missing");\r
-        return 1;       \r
+        return 1;\r
       }\r
       ++Index;\r
       continue;\r
     }\r
-    \r
+\r
     if ((stricmp (argv[Index], "-h") == 0) || (stricmp (argv[Index], "--help") == 0)) {\r
       PrintUsage ();\r
       return 0;\r
-    } \r
-    \r
+    }\r
+\r
     if (stricmp (argv[Index], "--version") == 0) {\r
       Version ();\r
       return 0;\r
-    } \r
-    \r
+    }\r
+\r
     if ((stricmp (argv[Index], "-v") == 0) || (stricmp (argv[Index], "--verbose") == 0)) {\r
       continue;\r
-    } \r
-    \r
+    }\r
+\r
     if ((stricmp (argv[Index], "-q") == 0) || (stricmp (argv[Index], "--quiet") == 0)) {\r
       continue;\r
-    } \r
-    \r
+    }\r
+\r
     if ((stricmp (argv[Index], "-d") == 0) || (stricmp (argv[Index], "--debug") == 0)) {\r
       EfiStatus = AsciiStringToUint64 (argv[Index + 1], FALSE, &LogLevel);\r
       if (EFI_ERROR (EfiStatus)) {\r
@@ -774,7 +774,7 @@ main (
     Error (NULL, 0, 1000, "Unknown option", "%s", argv[Index]);\r
     return 1;\r
   }\r
-  \r
+\r
   if (InputPathInfo.Path == NULL) {\r
     Error (NULL, 0, 1001, "Missing options", "Input file is missing");\r
     return 1;\r
@@ -784,7 +784,7 @@ main (
     Error (NULL, 0, 1001, "Missing options", "Output file is missing");\r
     return 1;\r
   }\r
-  \r
+\r
   if (GetPathInfo(&InputPathInfo) != ErrorSuccess) {\r
     Error (NULL, 0, 1003, "Invalid option value", "Input file can't be found.");\r
     return 1;\r
@@ -794,7 +794,7 @@ main (
     Error (NULL, 0, 1003, "Invalid option value", "Output file can't be found.");\r
     return 1;\r
   }\r
-  \r
+\r
   //\r
   // Process DBR (Patch or Read)\r
   //\r
@@ -802,19 +802,19 @@ main (
 \r
   if (Status == ErrorSuccess) {\r
     fprintf (\r
-      stdout, \r
-      "%s %s: successful!\n", \r
-      (OutputPathInfo.Type != PathFile) ? "Write" : "Read", \r
+      stdout,\r
+      "%s %s: successful!\n",\r
+      (OutputPathInfo.Type != PathFile) ? "Write" : "Read",\r
       ProcessMbr ? "MBR" : "DBR"\r
       );\r
     return 0;\r
   } else {\r
     fprintf (\r
-      stderr, \r
+      stderr,\r
       "%s: %s %s: failed - %s (LastError: 0x%lx)!\n",\r
       (Status == ErrorNoMbr) ? "WARNING" : "ERROR",\r
-      (OutputPathInfo.Type != PathFile) ? "Write" : "Read", \r
-      ProcessMbr ? "MBR" : "DBR", \r
+      (OutputPathInfo.Type != PathFile) ? "Write" : "Read",\r
+      ProcessMbr ? "MBR" : "DBR",\r
       ErrorStatusDesc[Status],\r
       GetLastError ()\r
       );\r