cast,
)
-from .syscall import blkpg_add_partition, blkpg_del_partition
+from .syscall import (
+ blkpg_add_partition,
+ blkpg_del_partition,
+ block_reread_partition_table,
+)
PathString = Union[Path, str]
if 'disk' in ARG_DEBUG:
print_between_lines(spec)
- cmd: List[PathString] = ["sfdisk", "--color=never", "--no-reread", device]
+ cmd: List[PathString] = ["sfdisk", "--color=never", "--no-reread", "--no-tell-kernel", device]
if quiet:
cmd += ["--quiet"]
for p in self.partitions.values():
blkpg_add_partition(f.fileno(), p.number, self.partition_offset(p), self.partition_size(p))
+ try:
+ block_reread_partition_table(f.fileno())
+ except OSError as e:
+ msg = f"Failed to reread partition table of {device}: {e.strerror}"
+ # BLKRRPART fails with EINVAL if the operation is not supported, let's not fail if that's
+ # the case.
+ if e.errno == errno.EINVAL:
+ warn(msg)
+ else:
+ die(msg)
+
@dataclasses.dataclass
class MkosiArgs:
def reflink(oldfd: int, newfd: int) -> None:
fcntl.ioctl(newfd, FICLONE, oldfd)
+
+
+BLKRRPART = _IO(0x12, 95)
+
+
+def block_reread_partition_table(fd: int) -> None:
+ fcntl.ioctl(fd, BLKRRPART, 0)