| f | import sys | f | import sys |
| | | |
| def main(): | | def main(): |
| n | data = sys.stdin.buffer.read() | n | file_data = sys.stdin.buffer.read() |
| boot = data[:512] | | boot_sector = file_data[:512] |
| bytes_per_sector = int.from_bytes(boot[11:13], 'little') | | sector_size = int.from_bytes(boot_sector[11:13], 'little') |
| sectors_per_cluster = boot[13] | | cluster_size_sectors = boot_sector[13] |
| reserved_sectors = int.from_bytes(boot[14:16], 'little') | | reserved_sectors_count = int.from_bytes(boot_sector[14:16], 'little' |
| | | ) |
| num_fats = boot[16] | | fat_count = boot_sector[16] |
| max_root_entries = int.from_bytes(boot[17:19], 'little') | | root_entries_max = int.from_bytes(boot_sector[17:19], 'little') |
| sectors_per_fat = int.from_bytes(boot[22:24], 'little') | | fat_sectors = int.from_bytes(boot_sector[22:24], 'little') |
| root_dir_sector = reserved_sectors + num_fats * sectors_per_fat | | root_start_sector = reserved_sectors_count + fat_count * fat_sectors |
| root_dir_size_bytes = max_root_entries * 32 | | root_size_bytes = root_entries_max * 32 |
| root_dir_sectors = (root_dir_size_bytes + bytes_per_sector - 1) // b | | root_sectors_needed = (root_size_bytes + sector_size - 1) // sector_ |
| ytes_per_sector | | size |
| root_dir_offset = root_dir_sector * bytes_per_sector | | root_data_start = root_start_sector * sector_size |
| root_dir = data[root_dir_offset:root_dir_offset + root_dir_sectors * | | root_data = file_data[root_data_start:root_data_start + root_sectors |
| bytes_per_sector] | | _needed * sector_size] |
| entries = [] | | items = [] |
| for off in range(0, root_dir_size_bytes, 32): | | for position in range(0, root_size_bytes, 32): |
| entry = root_dir[off:off + 32] | | record = root_data[position:position + 32] |
| if len(entry) < 32: | | if len(record) < 32: |
| break | | break |
| n | first_byte = entry[0] | n | first_char = record[0] |
| if first_byte == 0: | | if first_char == 0: |
| break | | break |
| n | if first_byte == 229: | n | if first_char == 229: |
| continue | | continue |
| n | attr = entry[11] | n | attributes = record[11] |
| if attr == 15: | | if attributes == 15: |
| continue | | continue |
| n | if attr & 8: | n | if attributes & 8: |
| continue | | continue |
| n | name_raw = entry[0:8] | n | name_part = record[0:8] |
| ext_raw = entry[8:11] | | extension_part = record[8:11] |
| name = name_raw.decode('cp866', errors='replace').rstrip() | | |
| ext = ext_raw.decode('cp866', errors='replace').rstrip() | | name_text = name_part.decode('cp866', errors='replace').rstrip() |
| | | extension_text = extension_part.decode('cp866', errors='replace' |
| | | ).rstrip() |
| if not name: | | if not name_text: |
| continue | | continue |
| n | if attr & 16: | n | if attributes & 16: |
| if name.startswith('.'): | | if name_text.startswith('.'): |
| continue | | continue |
| n | size_repr = 'dir' | n | item_size = 'dir' |
| else: | | else: |
| t | size = int.from_bytes(entry[28:32], 'little') | t | file_size = int.from_bytes(record[28:32], 'little') |
| size_repr = str(size) | | item_size = str(file_size) |
| full_name = name | | complete_name = name_text |
| if ext: | | if extension_text: |
| full_name = f'{name}.{ext}' | | complete_name = f'{name_text}.{extension_text}' |
| entries.append((full_name, size_repr)) | | items.append((complete_name, item_size)) |
| entries.sort(key=lambda x: x[0]) | | items.sort(key=lambda item: item[0]) |
| for fname, sz in entries: | | for filename, size_info in items: |
| print(f'{fname:<12} {sz}') | | print(f'{filename:<12} {size_info}') |
| if __name__ == '__main__': | | if __name__ == '__main__': |
| main() | | main() |