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