1 /* Subpart directory entry version 1 support */
2 /* SPDX-License-Identifier: GPL-2.0-only */
6 #include "cse_serger.h"
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)
16 struct subpart_entry
{
18 uint32_t offset_bytes
;
23 static void subpart_read_entry(struct buffer
*buff
, struct subpart_entry
*e
)
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
);
31 static void subpart_print_entry(const struct subpart_entry
*e
, size_t index
)
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',
39 static void subpart_print_entries(struct buffer
*buff
, size_t count
)
41 struct subpart_entry
*e
= malloc(count
* sizeof(*e
));
46 for (size_t i
= 0; i
< count
; i
++)
47 subpart_read_entry(buff
, &e
[i
]);
49 printf("%-25s%-25s%-25s%-25s%-25s%-25s\n", "Entry #", "Name", "Offset",
50 "Huffman Compressed?", "Length", "Rsvd");
52 printf("====================================================================="
53 "=====================================================================\n");
55 for (size_t i
= 0; i
< count
; i
++)
56 subpart_print_entry(&e
[i
], i
+ 1);
58 printf("====================================================================="
59 "=====================================================================\n");
64 const struct subpart_entry_ops subpart_entry_1_ops
= {
65 .print
= subpart_print_entries
,