-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathreaddisk.py
More file actions
executable file
·33 lines (25 loc) · 999 Bytes
/
readdisk.py
File metadata and controls
executable file
·33 lines (25 loc) · 999 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
"""Read a single sector of a physical disk. Tested on Mac OS 10.13.3 and Windows 8."""
import os
def main(): # Read the first sector of the first disk as example.
"""Demo usage of function."""
if os.name == "nt":
# Windows based OS normally uses '\\.\physicaldriveX' for disk drive identification.
print(read_sector(r"\\.\physicaldrive0"))
else:
# Linux based OS normally uses '/dev/diskX' for disk drive identification.
print(read_sector("/dev/disk0"))
def read_sector(disk, sector_no=0):
"""Read a single sector of the specified disk.
Keyword arguments:
disk -- the physical ID of the disk to read.
sector_no -- the sector number to read (default: 0).
"""
# Static typed variable
read = None
# File operations with `with` syntax. To reduce file handeling efforts.
with open(disk, 'rb') as fp:
fp.seek(sector_no * 512)
read = fp.read(512)
return read
if __name__ == "__main__":
main()