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 ****************************************************************************/
29 #define RSRC_SECTOR_SIZE 2048
31 #define RSRC_TABLE_ENTRY_TYPE(e) ((e) >> 28)
32 #define RSRC_TABLE_ENTRY_OFFSET(e) ((e) & 0xfffffff)
34 #define RSRC_TYPE_NONE 0 /* empty entry */
35 #define RSRC_TYPE_NESTED 1 /* nested entry: points to a sub-table */
36 #define RSRC_TYPE_IMAGE 2 /* image entry */
37 #define RSRC_TYPE_VALUE 3 /* value stored on 28-bits */
38 #define RSRC_TYPE_AUDIO 4 /* audio entry */
39 #define RSRC_TYPE_DATA 5 /* data entry */
53 RSRC_WRITE_ERROR
= -4,
54 RSRC_FORMAT_ERROR
= -5,
55 RSRC_CHECKSUM_ERROR
= -6,
56 RSRC_NO_VALID_KEY
= -7,
57 RSRC_FIRST_CRYPTO_ERROR
= -8,
58 RSRC_LAST_CRYPTO_ERROR
= RSRC_FIRST_CRYPTO_ERROR
- CRYPTO_NUM_ERRORS
,
61 enum rsrc_error_t
rsrc_write_file(struct rsrc_file_t
*rsrc
, const char *filename
);
63 typedef void (*rsrc_color_printf
)(void *u
, bool err
, color_t c
, const char *f
, ...);
64 struct rsrc_file_t
*rsrc_read_file(const char *filename
, void *u
,
65 rsrc_color_printf printf
, enum rsrc_error_t
*err
);
66 /* use size_t(-1) to use maximum size */
67 struct rsrc_file_t
*rsrc_read_file_ex(const char *filename
, size_t offset
, size_t size
, void *u
,
68 rsrc_color_printf printf
, enum rsrc_error_t
*err
);
69 struct rsrc_file_t
*rsrc_read_memory(void *buffer
, size_t size
, void *u
,
70 rsrc_color_printf printf
, enum rsrc_error_t
*err
);
72 void rsrc_dump(struct rsrc_file_t
*file
, void *u
, rsrc_color_printf printf
);
73 void rsrc_free(struct rsrc_file_t
*file
);
75 #endif /* __RSRC_H__ */