Fix FS#12824 : Malfunctioning FFT plugin in Sansa Clip Zip
[maemo-rb.git] / utils / imxtools / sbtools / rsrc.h
blob3e03d97d733f9ba85aaab737865078695a3392f8
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
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 ****************************************************************************/
21 #ifndef __RSRC_H__
22 #define __RSRC_H__
24 #include <stdint.h>
25 #include <stdbool.h>
27 #include "misc.h"
29 /**
30 * Low-Level
31 **/
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 */
45 /**
46 * API
47 **/
49 struct rsrc_entry_t
51 uint32_t id;
52 uint32_t offset; // contains value of RSRC_TYPE_VALUE
53 int size;
56 struct rsrc_file_t
58 void *data;
59 int size;
61 int nr_entries;
62 int capacity;
63 struct rsrc_entry_t *entries;
66 enum rsrc_error_t
68 RSRC_SUCCESS = 0,
69 RSRC_ERROR = -1,
70 RSRC_OPEN_ERROR = -2,
71 RSRC_READ_ERROR = -3,
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__ */