Lines Matching refs:f
42 def read_le_short(f): argument
44 return struct.unpack("<H", f.read(2))[0]
46 def read_le_long(f): argument
48 return struct.unpack("<L", f.read(4))[0]
50 def read_byte(f): argument
52 return struct.unpack("B", f.read(1))[0]
54 def skip_bytes(f, n): argument
56 f.seek(n, os.SEEK_CUR)
58 def skip_short(f): argument
60 skip_bytes(f, 2)
62 def skip_byte(f): argument
64 skip_bytes(f, 1)
66 def rewind_bytes(f, n): argument
68 skip_bytes(f, -n)
70 def rewind_short(f): argument
72 rewind_bytes(f, 2)
370 def commit(self, f): argument
375 f.seek(0)
399 record = f.read(32)
403 f.write("\0" * self.fs.bytes_per_cluster)
404 f.seek(-self.fs.bytes_per_cluster, os.SEEK_CUR)
405 record = f.read(32)
414 f.seek(-(record_count * 32), os.SEEK_CUR)
415 f.write(entry)
428 f = self.fs.f
429 f.seek(self.fs.data_start() + self.idx)
434 ret = f.read(count)
439 f = self.fs.f
440 f.seek(self.fs.data_start() + self.idx)
445 f.write(data)
457 f = open(path, "r+b")
459 self.f = f
461 f.seek(0xb)
462 bytes_per_sector = read_le_short(f)
463 sectors_per_cluster = read_byte(f)
467 reserved_sectors = read_le_short(f)
471 fat_count = read_byte(f)
474 self.root_entries = read_le_short(f)
476 skip_short(f) # Image size. Sort of. Useless field.
477 skip_byte(f) # Media type. We don't care.
479 self.fat_size = read_le_short(f) * bytes_per_sector
496 f = self.f
497 f.seek(FAT_TABLE_START + head_cluster * 2)
503 head_cluster = read_le_short(f)
504 f.seek(FAT_TABLE_START + head_cluster * 2)
508 def read_dentry(self, f=None): argument
513 f = f or self.f
521 skip_bytes(f, 11)
522 attributes = read_byte(f)
523 rewind_bytes(f, 12)
530 seq = read_byte(f)
531 chars = f.read(10)
532 skip_bytes(f, 3) # Various hackish nonsense
533 chars += f.read(12)
534 skip_short(f) # Lots more nonsense
535 chars += f.read(4)
541 ind = read_byte(f)
544 skip_bytes(f, 31)
553 skip_bytes(f, 31)
556 shortname = ind + f.read(7).rstrip()
557 ext = f.read(3).rstrip()
558 skip_bytes(f, 15) # Assorted flags, ctime/atime/mtime, etc.
559 first_cluster = read_le_short(f)
560 size = read_le_long(f)
581 f = self.f
602 f.seek(self.data_start() + bytes_from_data_start)
603 line = f.read(size_now)
614 f.seek(FAT_TABLE_START + head_cluster * 2)
616 head_cluster = read_le_short(f)
626 f = self.f
627 f.write(struct.pack("<H", entry))
628 skip_bytes(f, self.fat_size - 2)
629 f.write(struct.pack("<H", entry))
630 rewind_bytes(f, self.fat_size)
639 f = self.f
640 f.seek(FAT_TABLE_START + 4)
648 data = read_le_short(f)
690 f.seek(FAT_TABLE_START + cluster * 2)
703 f = self.f
705 f.seek(entry_offset)
706 assert read_le_short(f) == 0xFFFF, "Extending from middle of chain"
709 f.seek(entry_offset)
721 f = self.f
734 f.seek(cluster_file_offset + max(0, start_byte - current_offset))
735 f.write(data[data_begin:data_end])
740 f.seek(FAT_TABLE_START + current_cluster * 2)
741 next_cluster = read_le_short(f)
763 with open(item, 'rb') as f:
764 directory.new_file(os.path.basename(item), f)