]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Universal/Disk/RamDiskDxe/RamDiskBlockIo.c
MdeModulePkg: Replace BSD License with BSD+Patent License
[mirror_edk2.git] / MdeModulePkg / Universal / Disk / RamDiskDxe / RamDiskBlockIo.c
index 4f74b5ef1531aa80cead18f867e1744dd98ab176..13f81bae1e07b07d118c22009dd712dde94c09b0 100644 (file)
@@ -1,14 +1,8 @@
 /** @file\r
   Produce EFI_BLOCK_IO_PROTOCOL on a RAM disk device.\r
 \r
-  Copyright (c) 2016 - 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
+  Copyright (c) 2016 - 2019, Intel Corporation. All rights reserved.<BR>\r
+  SPDX-License-Identifier: BSD-2-Clause-Patent\r
 \r
 **/\r
 \r
@@ -54,6 +48,7 @@ RamDiskInitBlockIo (
   EFI_BLOCK_IO_PROTOCOL           *BlockIo;\r
   EFI_BLOCK_IO2_PROTOCOL          *BlockIo2;\r
   EFI_BLOCK_IO_MEDIA              *Media;\r
+  UINT32                          Remainder;\r
 \r
   BlockIo  = &PrivateData->BlockIo;\r
   BlockIo2 = &PrivateData->BlockIo2;\r
@@ -69,11 +64,18 @@ RamDiskInitBlockIo (
   Media->LogicalPartition = FALSE;\r
   Media->ReadOnly         = FALSE;\r
   Media->WriteCaching     = FALSE;\r
-  Media->BlockSize        = RAM_DISK_BLOCK_SIZE;\r
-  Media->LastBlock        = DivU64x32 (\r
-                              PrivateData->Size + RAM_DISK_BLOCK_SIZE - 1,\r
-                              RAM_DISK_BLOCK_SIZE\r
-                              ) - 1;\r
+\r
+  for (Media->BlockSize = RAM_DISK_DEFAULT_BLOCK_SIZE;\r
+       Media->BlockSize >= 1;\r
+       Media->BlockSize = Media->BlockSize >> 1) {\r
+    Media->LastBlock = DivU64x32Remainder (PrivateData->Size, Media->BlockSize, &Remainder) - 1;\r
+    if (Remainder == 0) {\r
+      break;\r
+    }\r
+  }\r
+  ASSERT (Media->BlockSize != 0);\r
+\r
+  return;\r
 }\r
 \r
 \r