-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcbfslib.h
74 lines (63 loc) · 1.68 KB
/
cbfslib.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#include <stdio.h>
#include "stdint.h"
#include <stddef.h>
#include <stdlib.h>
#include "stdbool.h"
#define CBFS_FILE_MAGIC "LARCHIVE"
#define CBFS_HEADER_MAGIC 0x4F524243
#define CBFS_HEADER_VERSION1 0x31313131
#define CBFS_HEADER_VERSION2 0x31313132
#define CBFS_ENTRY_ALIGNMENT 64
#define CBFS_SUBHEADER(_p) ( (void *) ((((uint8_t *) (_p)) + ntohl((_p)->offset))) )
#define __PACKED __attribute__((gcc_struct, packed))
struct cbfs_file_attr_compression {
uint32_t tag;
uint32_t len;
/* whole file compression format. 0 if no compression. */
uint32_t compression;
uint32_t decompressed_size;
} __PACKED;
struct cbfs_file_attribute {
uint32_t tag;
/* len covers the whole structure, incl. tag and len */
uint32_t len;
uint8_t data[0];
} __PACKED;
struct buffer {
char *name;
char *data;
size_t offset;
size_t size;
};
struct cbfs_header {
uint32_t magic;
uint32_t version;
uint32_t romsize;
uint32_t bootblocksize;
uint32_t align; /* hard coded to 64 byte */
uint32_t offset;
uint32_t architecture; /* Version 2 */
uint32_t pad[1];
} __PACKED;
struct cbfs_file {
uint8_t magic[8];
/* length of file data */
uint32_t len;
uint32_t type;
/* offset to struct cbfs_file_attribute or 0 */
uint32_t attributes_offset;
/* length of header incl. variable data */
uint32_t offset;
char filename[];
} __PACKED;
struct cbfs_image {
struct buffer buffer;
/* An image has a header iff it's a legacy CBFS. */
bool has_header;
/* Only meaningful if has_header is selected. */
struct cbfs_header header;
};
typedef int (*cbfs_entry_callback)(struct cbfs_image *image,
struct cbfs_file *file,
void *arg);
int cbfs_remove_entry(struct cbfs_image *image, const char *name);