Both worked for me. To gain access to Partition C: or the whole drive, administrator privileges are needed. Here an example as replacement for open():
def open_physical_drive(
number,
mode="rb",
buffering=-1,
encoding=None,
errors=None,
newline=None,
closefd=True,
opener=None,
):
"""
Opens a physical drive in read binary mode by default
The numbering starts with 0
"""
return open(
fr"\\.\PhysicalDrive{number}",
mode,
buffering,
encoding,
errors,
newline,
closefd,
opener,
)
def open_windows_partition(
letter,
mode="rb",
buffering=-1,
encoding=None,
errors=None,
newline=None,
closefd=True,
opener=None,
):
"""
Opens a partition of a windows drive letter in read binary mode by default
"""
return open(
fr"\\.\{letter}:", mode, buffering, encoding, errors, newline, closefd, opener
)
# first 16 bytes from partition C:
# on Linux it's like /dev/sda1
with open_windows_partition("C") as drive_c:
print(drive_c.read(16))
# first 16 bytes of first drive
# on Linux it's like /dev/sda
with open_physical_drive(0) as drive_0:
print(drive_0.read(16))