MCPcopy Create free account
hub / github.com/qilingframework/qiling / QlDisk

Class QlDisk

qiling/os/disk.py:23–103  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

21# http://www.uruk.org/orig-grub/PC_partitioning.txt
22
23class QlDisk(QlFsMappedObject):
24
25 # 512 bytes/sector
26 # 63 sectors/track
27 # 255 heads (tracks/cylinder)
28 # 1024 cylinders
29
30 def __init__(self, host_path: AnyStr, drive_path, n_cylinders: int = 1, n_heads: int = 1, sector_size: int = 512):
31 self._drive_path = drive_path
32 self._fp = open(host_path, "rb+")
33 self._n_heads = n_heads
34 self._n_cylinders = n_cylinders
35 self._sector_size = sector_size
36 self.lseek(0, 2)
37 self._filesize = self.tell()
38 self._n_sectors = (self._filesize - 1) // self.sector_size + 1
39
40 def __del__(self):
41 if not self.fp.closed:
42 self.fp.close()
43
44 @property
45 def filesize(self):
46 return self._filesize
47
48 @property
49 def n_heads(self):
50 return self._n_heads
51
52 @property
53 def n_sectors(self):
54 return self._n_sectors
55
56 @property
57 def n_cylinders(self):
58 return self._n_cylinders
59
60 @property
61 def sector_size(self):
62 return self._sector_size
63
64 @property
65 def fp(self):
66 return self._fp
67
68 # Methods from FsMappedObject
69 def read(self, size: Optional[int]) -> bytes:
70 return self.fp.read(size)
71
72 def write(self, buffer: ReadableBuffer) -> int:
73 return self.fp.write(buffer)
74
75 def lseek(self, offset: int, origin: int) -> int:
76 return self.fp.seek(offset, origin)
77
78 def tell(self) -> int:
79 return self.fp.tell()
80

Callers 6

runMethod · 0.90
third_stageFunction · 0.90
second_stageFunction · 0.90
first_stageFunction · 0.90
third_stageFunction · 0.90
first_stageFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected