xref: /aosp_15_r20/external/coreboot/util/archive/archive.h (revision b9411a12aaaa7e1e6a6fb7c5e057f44ee179a49c)
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 
3 #ifndef __ARCHIVE_H
4 #define __ARCHIVE_H
5 
6 #include <stdint.h>
7 
8 /*
9  * Archive file layout:
10  *
11  *  +----------------------------------+
12  *  |           root header            |
13  *  +----------------------------------+
14  *  |         file_header[0]           |
15  *  +----------------------------------+
16  *  |         file_header[1]           |
17  *  +----------------------------------+
18  *  |              ...                 |
19  *  +----------------------------------+
20  *  |         file_header[count-1]     |
21  *  +----------------------------------+
22  *  |         file(0) content          |
23  *  +----------------------------------+
24  *  |         file(1) content          |
25  *  +----------------------------------+
26  *  |              ...                 |
27  *  +----------------------------------+
28  *  |         file(count-1) content    |
29  *  +----------------------------------+
30  */
31 
32 #define VERSION		0
33 #define CBAR_MAGIC	"CBAR"
34 #define NAME_LENGTH	32
35 
36 /* Root header */
37 struct directory {
38 	char magic[4];
39 	uint32_t version;	/* version of the header. little endian */
40 	uint32_t size;		/* total size of archive. little endian */
41 	uint32_t count;		/* number of files. little endian */
42 };
43 
44 /* File header */
45 struct dentry {
46 	/* file name. null-terminated if shorter than NAME_LENGTH */
47 	char name[NAME_LENGTH];
48 	/* file offset from the root header. little endian */
49 	uint32_t offset;
50 	/* file size. little endian */
51 	uint32_t size;
52 };
53 
get_first_dentry(const struct directory * dir)54 static inline struct dentry *get_first_dentry(const struct directory *dir)
55 {
56 	return (struct dentry *)(dir + 1);
57 }
58 
get_first_offset(const struct directory * dir)59 static inline uint32_t get_first_offset(const struct directory *dir)
60 {
61 	return sizeof(struct directory) + sizeof(struct dentry) * dir->count;
62 }
63 
64 #endif
65