def raw_track(self): # List of sector IDs missing from the sector map: missing = iter([x for x in range(self.nsec) if not x in self.map]) # Sector map with the missing entries filled in: full_map = [next(missing) if x is None else x for x in self.map] # Post-index track gap. t = encode(bytes(128 * (self.nsec // 11))) for nr, sec_id in zip(range(self.nsec), full_map): sector = self.sector[sec_id] label, data = (bytes(16), bytes(512)) if sector is None else sector header = bytes([0xff, self.tracknr, sec_id, self.nsec - nr]) t += sync_bytes t += encode(header) t += encode(label) t += encode(struct.pack('>I', checksum(header + label))) t += encode(struct.pack('>I', checksum(data))) t += encode(data) t += encode(bytes(2)) # Add the pre-index gap. tlen = 101376 * (self.nsec // 11) t += bytes(tlen // 8 - len(t)) track = MasterTrack(bits=mfm_encode(t), time_per_rev=0.2) track.verify = self return track
def raw_track(self): areas = heapq.merge(self.iams, self.sectors, key=lambda x: x.start) t = bytes() for a in areas: start = a.start // 16 - self.gap_presync gap = max(start - len(t) // 2, 0) t += encode(bytes([self.gapbyte] * gap)) t += encode(bytes(self.gap_presync)) if isinstance(a, IAM): t += iam_sync_bytes elif isinstance(a, Sector): idam = bytes( [self.IDAM, a.idam.c, a.idam.h, a.idam.r, a.idam.n]) idam += struct.pack('>H', crc16.new(idam).crcValue) t += sync(idam[0]) + encode(idam[1:]) start = a.dam.start // 16 - self.gap_presync gap = max(start - len(t) // 2, 0) t += encode(bytes([self.gapbyte] * gap)) t += encode(bytes(self.gap_presync)) dam = bytes([a.dam.mark]) + a.dam.data dam += struct.pack('>H', crc16.new(dam).crcValue) t += sync(dam[0]) + encode(dam[1:]) # Add the pre-index gap. tlen = int((self.time_per_rev / self.clock) // 16) gap = max(tlen - len(t) // 2, 0) t += encode(bytes([self.gapbyte] * gap)) track = MasterTrack(bits=t, time_per_rev=self.time_per_rev) track.verify = self track.verify_revs = default_revs return track
def raw_track(self): track = MasterTrack(bits=self.bits, time_per_rev=self.time_per_rev, weak=self.weak) track.verify = self track.verify_revs = 1 return track
def get_track(self, cyl, head, writeout=False): pi = self.pi if head < pi.minhead or head > pi.maxhead: return None if cyl < pi.mincylinder or cyl > pi.maxcylinder: return None ti = CapsTrackInfoT2(2) res = self.lib.CAPSLockTrack(ct.byref(ti), self.iid, cyl, head, DI_LOCK.def_flags) error.check(res == 0, "Could not lock IPF track %d.%d" % (cyl, head)) if not ti.trackbuf: return None # unformatted/empty carray_type = ct.c_ubyte * ((ti.tracklen + 7) // 8) carray = carray_type.from_address(ct.addressof(ti.trackbuf.contents)) trackbuf = bitarray(endian='big') trackbuf.frombytes(bytes(carray)) trackbuf = trackbuf[:ti.tracklen] #for i in range(ti.sectorcnt): # si = CapsSectorInfo() # res = self.lib.CAPSGetInfo(ct.byref(si), self.iid, # cyl, head, 1, i) # error.check(res == 0, "Couldn't get sector info") # range.append((si.datastart, si.datasize)) weak = [] for i in range(ti.weakcnt): wi = CapsDataInfo() res = self.lib.CAPSGetInfo(ct.byref(wi), self.iid, cyl, head, 2, i) error.check(res == 0, "Couldn't get weak data info") weak.append((wi.start, wi.size)) timebuf = None if ti.timebuf: carray_type = ct.c_uint * ti.timelen carray = carray_type.from_address(ct.addressof( ti.timebuf.contents)) # Unpack the per-byte timing info into per-bitcell timebuf = [] for i in carray: for j in range(8): timebuf.append(i) # Pad the timing info with normal cell lengths as necessary for j in range(len(carray) * 8, ti.tracklen): timebuf.append(1000) # Clip the timing info, if necessary. timebuf = timebuf[:ti.tracklen] # We don't really have access to the bitrate. It depends on RPM. # So we assume a rotation rate of 300 RPM (5 rev/sec). rpm = 300 track = MasterTrack(bits=trackbuf, time_per_rev=60 / rpm, bit_ticks=timebuf, splice=ti.overlap, weak=weak) return track
def get_track(self, cyl, side): if (cyl, side) not in self.to_track: return None bitlen, rawbytes = self.to_track[cyl, side] tdat = bitarray(endian='little') tdat.frombytes(rawbytes) track = MasterTrack(bits=tdat[:bitlen], time_per_rev=bitlen / (2000 * self.opts.bitrate)) return track
def get_track(self, cyl, side, writeout=False): if side >= self.nr_sides or cyl < self.start_cyl: return None off = cyl * self.nr_sides + side if off >= len(self.track_list): return None bitlen, rawbytes = self.track_list[off] tdat = bitarray(endian='little') tdat.frombytes(rawbytes) track = MasterTrack(bits=tdat[:bitlen], time_per_rev=bitlen / (2000 * self.bitrate)) return track
def raw_track(self): areas = heapq.merge(self.iams, self.sectors, key=lambda x:x.start) t = bytes() for a in areas: start = a.start//16 - self.gap_presync gap = max(start - len(t)//2, 0) t += encode(bytes([self.filler] * gap)) t += encode(bytes(self.gap_presync)) if isinstance(a, IAM): t += iam_sync_bytes t += encode(bytes([self.IAM])) elif isinstance(a, Sector): t += sync_bytes idam = bytes([0xa1, 0xa1, 0xa1, self.IDAM, a.idam.c, a.idam.h, a.idam.r, a.idam.n]) idam += struct.pack('>H', crc16.new(idam).crcValue) t += encode(idam[3:]) start = a.dam.start//16 - self.gap_presync gap = max(start - len(t)//2, 0) t += encode(bytes([self.filler] * gap)) t += encode(bytes(self.gap_presync)) t += sync_bytes dam = bytes([0xa1, 0xa1, 0xa1, a.dam.mark]) + a.dam.data dam += struct.pack('>H', crc16.new(dam).crcValue) t += encode(dam[3:]) # Add the pre-index gap. tlen = 200000//16 gap = max(tlen - len(t)//2, 0) t += encode(bytes([self.filler] * gap)) track = MasterTrack( bits = mfm_encode(t), time_per_rev = 0.2) track.verify = self track.verify_revs = default_revs return track