pyocf: add from_page() method to Size class

Signed-off-by: Adam Rutkowski <adam.j.rutkowski@intel.com>
This commit is contained in:
Adam Rutkowski 2021-12-29 23:57:27 +01:00
parent 650511df4e
commit c37ffea4c2

View File

@ -1,5 +1,5 @@
# #
# Copyright(c) 2019-2021 Intel Corporation # Copyright(c) 2019-2022 Intel Corporation
# SPDX-License-Identifier: BSD-3-Clause # SPDX-License-Identifier: BSD-3-Clause
# #
@ -72,6 +72,7 @@ class Size:
_GiB = _MiB * 1024 _GiB = _MiB * 1024
_TiB = _GiB * 1024 _TiB = _GiB * 1024
_SECTOR_SIZE = 512 _SECTOR_SIZE = 512
_PAGE_SIZE = 4096
def __init__(self, b: int, sector_aligned: bool = False): def __init__(self, b: int, sector_aligned: bool = False):
if sector_aligned: if sector_aligned:
@ -130,6 +131,10 @@ class Size:
def from_sector(cls, value): def from_sector(cls, value):
return cls(value * cls._SECTOR_SIZE) return cls(value * cls._SECTOR_SIZE)
@classmethod
def from_page(cls, value):
return cls(value * cls._PAGE_SIZE)
@property @property
def B(self): def B(self):
return self.bytes return self.bytes