1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 * Copyright (C) 2012 Amaury Pouly
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
20 ****************************************************************************/
33 #define RSRC_SECTOR_SIZE 2048
35 #define RSRC_TABLE_ENTRY_TYPE(e) ((e) >> 28)
36 #define RSRC_TABLE_ENTRY_OFFSET(e) ((e) & 0xfffffff)
38 #define RSRC_TYPE_NONE 0 /* empty entry */
39 #define RSRC_TYPE_NESTED 1 /* nested entry: points to a sub-table */
40 #define RSRC_TYPE_IMAGE 2 /* image entry */
41 #define RSRC_TYPE_VALUE 3 /* value stored on 28-bits */
42 #define RSRC_TYPE_AUDIO 4 /* audio entry */
43 #define RSRC_TYPE_DATA 5 /* data entry */
52 uint32_t offset
; // contains value of RSRC_TYPE_VALUE
63 struct rsrc_entry_t
*entries
;
72 RSRC_WRITE_ERROR
= -4,
73 RSRC_FORMAT_ERROR
= -5,
74 RSRC_CHECKSUM_ERROR
= -6,
75 RSRC_NO_VALID_KEY
= -7,
76 RSRC_FIRST_CRYPTO_ERROR
= -8,
77 RSRC_LAST_CRYPTO_ERROR
= RSRC_FIRST_CRYPTO_ERROR
- CRYPTO_NUM_ERRORS
,
80 enum rsrc_error_t
rsrc_write_file(struct rsrc_file_t
*rsrc
, const char *filename
);
82 typedef void (*rsrc_color_printf
)(void *u
, bool err
, color_t c
, const char *f
, ...);
83 struct rsrc_file_t
*rsrc_read_file(const char *filename
, void *u
,
84 rsrc_color_printf printf
, enum rsrc_error_t
*err
);
85 /* use size_t(-1) to use maximum size */
86 struct rsrc_file_t
*rsrc_read_file_ex(const char *filename
, size_t offset
, size_t size
, void *u
,
87 rsrc_color_printf printf
, enum rsrc_error_t
*err
);
88 struct rsrc_file_t
*rsrc_read_memory(void *buffer
, size_t size
, void *u
,
89 rsrc_color_printf printf
, enum rsrc_error_t
*err
);
91 void rsrc_dump(struct rsrc_file_t
*file
, void *u
, rsrc_color_printf printf
);
92 void rsrc_free(struct rsrc_file_t
*file
);
94 #endif /* __RSRC_H__ */