remap-badblocks 0.8.1__py3-none-any.whl → 0.9__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,3 +1,3 @@
1
1
  from packaging.version import Version
2
2
 
3
- __version__ = Version("0.8.1")
3
+ __version__ = Version("0.9")
@@ -9,7 +9,7 @@ from remap_badblocks.src.badblocks._find_badblocks import (
9
9
  get_all_badblocks, read_known_badblocks)
10
10
  from remap_badblocks.src.badblocks._mapping_generation import generate_mapping
11
11
  from remap_badblocks.src.badblocks._remap_badblocks import (
12
- count_used_spare_sectors, iter_all_spare_sectors, iter_free_spare_sectors,
12
+ filter_out_used_and_bad_spare_sectors, iter_all_spare_sectors,
13
13
  remap_badblocks, simplify_mapping)
14
14
  from remap_badblocks.src.devices.device_config import DeviceConfig
15
15
  from remap_badblocks.src.devices.devices_config import DevicesConfig
@@ -165,13 +165,15 @@ def update_mapping(
165
165
  good_ranges,
166
166
  )
167
167
  else:
168
+ badblocks_ = set(badblocks)
168
169
  spare_sectors = iter_all_spare_sectors(n_spare_sectors, device.logical_range[0])
169
- n_used_spare_sectors = count_used_spare_sectors(device.mapping, spare_sectors)
170
- current_mapping = map(lambda x: x.to_tuple(), device.mapping)
170
+ spare_sectors = filter_out_used_and_bad_spare_sectors(
171
+ spare_sectors, device.mapping, badblocks_
172
+ )
171
173
  new_mapping = remap_badblocks(
172
- current_mapping,
173
- badblocks,
174
- spare_sectors=iter_free_spare_sectors(spare_sectors, n_used_spare_sectors),
174
+ device.mapping,
175
+ badblocks_,
176
+ spare_sectors,
175
177
  )
176
178
 
177
179
  new_mapping = list(new_mapping)
@@ -1,13 +1,13 @@
1
- import itertools
2
- from typing import Iterable, Iterator, Optional, Union
1
+ from collections.abc import Container, Generator, Iterable, Iterator
2
+ from typing import Optional, Union
3
3
 
4
4
  from remap_badblocks.src.devices.devices_config import Mapping
5
5
 
6
6
 
7
7
  def remap_badblocks(
8
- mapping: Iterable[tuple[int, int, int]],
8
+ mapping: Union[Iterable[tuple[int, int, int]], Mapping],
9
9
  badblocks: Iterable[int],
10
- spare_sectors: Iterator[int],
10
+ usable_spare_sectors: Iterator[int],
11
11
  ) -> Iterable[tuple[int, int, int]]:
12
12
  sorted_badblocks = sorted(badblocks)
13
13
 
@@ -37,10 +37,11 @@ def remap_badblocks(
37
37
  yield current_start_virtual, current_start_real, end_real - current_start_real + 1
38
38
  for virt_to_remap in sorted_to_remap_virtual:
39
39
  try:
40
- while (spare_sector := next(spare_sectors)) in badblocks:
41
- pass
40
+ spare_sector = next(usable_spare_sectors)
42
41
  except StopIteration:
43
- raise RuntimeError
42
+ raise RuntimeError(
43
+ "Not enough spare sectors to remap all new badblocks"
44
+ )
44
45
  # remap
45
46
  yield virt_to_remap, spare_sector, 1
46
47
 
@@ -93,22 +94,21 @@ def iter_all_spare_sectors(
93
94
  return iter(range(first_spare_sector, first_spare_sector + n_spare_sectors))
94
95
 
95
96
 
96
- def iter_free_spare_sectors(
97
- spare_sectors: Iterable[int], n_used_spare_sectors: int
98
- ) -> Iterator[int]:
99
- return itertools.islice(spare_sectors, n_used_spare_sectors, None)
100
-
101
-
102
- def count_used_spare_sectors(
103
- mapping: Union[Iterable[tuple[int, int, int]], Mapping],
104
- spare_sectors: Iterable[int],
105
- ) -> int:
106
- spare_sectors = set(spare_sectors)
107
- used = 0
97
+ def is_sector_used_in_mapping(
98
+ s: int, mapping: Union[Iterable[tuple[int, int, int]], Mapping]
99
+ ):
108
100
  for _, start, length in mapping:
109
101
  end = start + length
110
- for s in spare_sectors:
111
- if start <= s < end:
112
- used += 1
102
+ if start <= s < end:
103
+ return True
104
+ return False
113
105
 
114
- return used
106
+
107
+ def filter_out_used_and_bad_spare_sectors(
108
+ spare_sectors: Iterable[int],
109
+ current_mapping: Mapping,
110
+ badblocks: Container[int],
111
+ ) -> Generator[int]:
112
+ for s in spare_sectors:
113
+ if s not in badblocks and not is_sector_used_in_mapping(s, current_mapping):
114
+ yield s
@@ -1,6 +1,6 @@
1
1
  import sqlite3
2
2
  from dataclasses import dataclass
3
- from typing import Collection, Iterator
3
+ from typing import Collection, Iterable, Iterator
4
4
 
5
5
  from remap_badblocks.src.utils._iterable_bytes_converter import (
6
6
  iterable_from_bytes, iterable_to_bytes)
@@ -107,3 +107,7 @@ class Mapping:
107
107
 
108
108
  def __iter__(self) -> Iterator[MappingElement]:
109
109
  return iter(self.elements)
110
+
111
+ @classmethod
112
+ def from_tuples(cls, mapping_tuples: Iterable[tuple[int, int, int]]) -> "Mapping":
113
+ return cls(set(map(MappingElement.from_tuple, mapping_tuples)))
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: remap_badblocks
3
- Version: 0.8.1
3
+ Version: 0.9
4
4
  Summary: CLI tool for remapping bad sectors on Linux disks using device-mapper
5
5
  Author-email: Luigi Privitera <priviteraluigi98@gmail.com>
6
6
  License-Expression: GPL-3.0-only
@@ -89,11 +89,11 @@ ls /dev/mapper/
89
89
 
90
90
  We welcome feedback, bug reports, feature ideas, code contributions, and help shaping the roadmap — or even rethinking the project from the ground up.
91
91
 
92
- Start with [CONTRIBUTING.md](./CONTRIBUTING.md), then open an issue or submit a merge request to get involved.
92
+ Start with CONTRIBUTING.md, then open an issue or submit a merge request to get involved.
93
93
 
94
94
  ## License
95
95
 
96
- GPL v3 License — see [LICENSE](./LICENSE) for details.
96
+ GPL v3 License — see LICENSE for details.
97
97
 
98
98
  ## Community
99
99
 
@@ -1,4 +1,4 @@
1
- remap_badblocks/__init__.py,sha256=M-LWfLH5N-kMq3R47UMpl1RZ9ZK-XiHd5kRy6jemVPY,70
1
+ remap_badblocks/__init__.py,sha256=uh9pQzPKdlMD_35fZuzjLFDquAyCl9a9KlBFbGf0sQI,68
2
2
  remap_badblocks/cli/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
3
3
  remap_badblocks/cli/__main__.py,sha256=9p8yZNyu012JYMfAkQVcVkhShaoyre44jcYzK0ow4NY,7132
4
4
  remap_badblocks/cli/commands/__init__.py,sha256=tGo7_yWZsDpvIIcA9y-4AlLB6grVlK2zaJ6VUKdpONo,216
@@ -6,15 +6,15 @@ remap_badblocks/cli/commands/add.py,sha256=XRNtzUlwRmFD-5VM2us-odvx5smUcIBM6MBF7
6
6
  remap_badblocks/cli/commands/apply.py,sha256=uwLqEGYz4HVV_5V5Fe3dDDpmS9pt6VUmdZBsVyCnwyk,2534
7
7
  remap_badblocks/cli/commands/get.py,sha256=qDb_KP4YZA9wiXMlXk2i19TDRGaHasPQKcnkWiVv2dA,740
8
8
  remap_badblocks/cli/commands/remove.py,sha256=C3eBGmujtRktBJlGCtvdCRHBVWjRaTDx0o-LQpLEKB8,1186
9
- remap_badblocks/cli/commands/update.py,sha256=h-PJNWNPSuobOV1byl4nlOtjCFuWG2zGjt2fc8O55RA,7109
9
+ remap_badblocks/cli/commands/update.py,sha256=kX_ZGvkm5dx6tOsViLHc_6S9ybuBcBvAW1i9yFjMGrA,7042
10
10
  remap_badblocks/cli/commands/version.py,sha256=uJIZLqK8zlNEgXlx-V7-yhhvsZfBKAE1tlF76t_Fg2I,168
11
11
  remap_badblocks/src/devices_config_constants.py,sha256=spRtelXdR9kWw-MzFI-CWfmZ6QM0gXvVHbk4J1CeKcM,103
12
- remap_badblocks/src/mapping.py,sha256=o_r6fiPkzwmsUqzspVkWY7PjWGdRMgxjE5n4w1lEAls,3222
12
+ remap_badblocks/src/mapping.py,sha256=1OI4Si8QTWa3IM9dG5ms7bHNVDjqAsvK8hqF9r1XvGM,3409
13
13
  remap_badblocks/src/test_utils.py,sha256=6kzIHJ04VJMQFYLYNw6wLX0Zy-i_aWDRmWc-zFsiw7Y,437
14
14
  remap_badblocks/src/badblocks/_compute_good_ranges.py,sha256=hMNiDurMvtxyt9VxJYTqF_i-8S0_zBLvzKybC6rA9Js,1425
15
15
  remap_badblocks/src/badblocks/_find_badblocks.py,sha256=aKgCsUpMj0KDPh_WhAXM5-sxTouVgy61ZS2UyPvcdfQ,2263
16
16
  remap_badblocks/src/badblocks/_mapping_generation.py,sha256=M9ENd3fol_C0PA2Pi7AcZ9KRPpUqiVAq8-8n7u_I0Ec,381
17
- remap_badblocks/src/badblocks/_remap_badblocks.py,sha256=G9ZAzGJmG_hGUrKAcGHjn6I3XGYU_BPJWPzryZY7RBk,3963
17
+ remap_badblocks/src/badblocks/_remap_badblocks.py,sha256=XmdlXHucfW6hHitsO8xDxgBgo01uHmEa601bYVYWYcU,4063
18
18
  remap_badblocks/src/badblocks/badblocks.py,sha256=AYuh0VRG6vY7of_fqqTCeoe2METVJ-xy7ZvMZw7VqTI,1046
19
19
  remap_badblocks/src/devices/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
20
20
  remap_badblocks/src/devices/device_config.py,sha256=5ZkCxvObgxGf1zVOgzy8GlEX4BfHp8KlD7XzdkJI4zs,1943
@@ -28,9 +28,9 @@ remap_badblocks/src/utils/_iterable_bytes_converter.py,sha256=H0PDLANQLTaakNBHMD
28
28
  remap_badblocks/src/utils/_parse_inputs.py,sha256=KggQ80y97LIAolbhS1OsBMVdt-XDXDO3w4glJQPd4Tw,2772
29
29
  remap_badblocks/src/utils/_run_command.py,sha256=3EXIPcjx7MFsXGSDDfnS2qBwXfV-98Efj_enfQS1C_Q,2435
30
30
  remap_badblocks/src/utils/_sort_devices.py,sha256=f9w3DoMbRdkDjjaoSrz8qnmDzfaOvk2I_mq4-wwS65A,876
31
- remap_badblocks-0.8.1.dist-info/licenses/LICENSE,sha256=OXLcl0T2SZ8Pmy2_dmlvKuetivmyPd5m1q-Gyd-zaYY,35149
32
- remap_badblocks-0.8.1.dist-info/METADATA,sha256=c8DLW8dbmZh0z89WOMUpIgyqWR6-zzt_ZJB_LTcMlXI,3329
33
- remap_badblocks-0.8.1.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
34
- remap_badblocks-0.8.1.dist-info/entry_points.txt,sha256=JmLHnqW16bljetWHJrYYAuP0vBrxfO0QY0mFdaWqOKg,70
35
- remap_badblocks-0.8.1.dist-info/top_level.txt,sha256=FqRo65stYjF_GyJQCLGIQN1Tj0YQcaiinI5bvzd0OpY,16
36
- remap_badblocks-0.8.1.dist-info/RECORD,,
31
+ remap_badblocks-0.9.dist-info/licenses/LICENSE,sha256=OXLcl0T2SZ8Pmy2_dmlvKuetivmyPd5m1q-Gyd-zaYY,35149
32
+ remap_badblocks-0.9.dist-info/METADATA,sha256=AZAzZOzzYCrz2CF8d4BMXvdvNpCEpHQia03_ZBX53ww,3293
33
+ remap_badblocks-0.9.dist-info/WHEEL,sha256=wUyA8OaulRlbfwMtmQsvNngGrxQHAvkKcvRmdizlJi0,92
34
+ remap_badblocks-0.9.dist-info/entry_points.txt,sha256=JmLHnqW16bljetWHJrYYAuP0vBrxfO0QY0mFdaWqOKg,70
35
+ remap_badblocks-0.9.dist-info/top_level.txt,sha256=FqRo65stYjF_GyJQCLGIQN1Tj0YQcaiinI5bvzd0OpY,16
36
+ remap_badblocks-0.9.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: setuptools (80.9.0)
2
+ Generator: setuptools (80.10.2)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5