subpart_entry_1.c
1 /* Subpart directory entry version 1 support */ 2 /* SPDX-License-Identifier: GPL-2.0-only */ 3 4 #include <sys/types.h> 5 6 #include "cse_serger.h" 7 8 #define SUBPART_OFFSET_SHIFT 0 9 #define SUBPART_OFFSET_MASK 0x1ffffff 10 #define SUBPART_OFFSET(x) (((x) >> SUBPART_OFFSET_SHIFT) & SUBPART_OFFSET_MASK) 11 #define SUBPART_COMPRESSED_SHIFT 25 12 #define SUBPART_COMPRESSED_MASK 1 13 #define SUBPART_COMPRESSED(x) \ 14 (((x) >> SUBPART_COMPRESSED_SHIFT) & SUBPART_COMPRESSED_MASK) 15 16 struct subpart_entry { 17 uint8_t name[12]; 18 uint32_t offset_bytes; 19 uint32_t length; 20 uint32_t rsvd2; 21 } __packed; 22 23 static void subpart_read_entry(struct buffer *buff, struct subpart_entry *e) 24 { 25 READ_MEMBER(buff, e->name); 26 READ_MEMBER(buff, e->offset_bytes); 27 READ_MEMBER(buff, e->length); 28 READ_MEMBER(buff, e->rsvd2); 29 } 30 31 static void subpart_print_entry(const struct subpart_entry *e, size_t index) 32 { 33 printf("%-25zd%-25.12s0x%-23x%-25c0x%-23x0x%-23x\n", index, 34 e->name, SUBPART_OFFSET(e->offset_bytes), 35 SUBPART_COMPRESSED(e->offset_bytes) ? 'Y' : 'N', 36 e->length, e->rsvd2); 37 } 38 39 static void subpart_print_entries(struct buffer *buff, size_t count) 40 { 41 struct subpart_entry *e = malloc(count * sizeof(*e)); 42 43 if (!e) 44 return; 45 46 for (size_t i = 0; i < count; i++) 47 subpart_read_entry(buff, &e[i]); 48 49 printf("%-25s%-25s%-25s%-25s%-25s%-25s\n", "Entry #", "Name", "Offset", 50 "Huffman Compressed?", "Length", "Rsvd"); 51 52 printf("=====================================================================" 53 "=====================================================================\n"); 54 55 for (size_t i = 0; i < count; i++) 56 subpart_print_entry(&e[i], i + 1); 57 58 printf("=====================================================================" 59 "=====================================================================\n"); 60 61 free(e); 62 } 63 64 const struct subpart_entry_ops subpart_entry_1_ops = { 65 .print = subpart_print_entries, 66 };