#include <malloc.h>
#include <asm/byteorder.h>
-enum cbfs_result file_cbfs_result;
static const u32 good_magic = 0x4f524243;
static const u8 good_file_magic[] = "LARCHIVE";
int initialized;
struct cbfs_header header;
struct cbfs_cachenode *file_cache;
+ enum cbfs_result result;
};
static struct cbfs_priv cbfs_s;
const char *file_cbfs_error(void)
{
- switch (file_cbfs_result) {
+ switch (cbfs_s.result) {
case CBFS_SUCCESS:
return "Success";
case CBFS_NOT_INITIALIZED:
}
}
+enum cbfs_result cbfs_get_result(void)
+{
+ return cbfs_s.result;
+}
+
/* Do endian conversion on the CBFS header structure. */
static void swap_header(struct cbfs_header *dest, struct cbfs_header *src)
{
swap_file_header(&header, fileHeader);
if (header.offset < sizeof(struct cbfs_fileheader)) {
- file_cbfs_result = CBFS_BAD_FILE;
+ priv->result = CBFS_BAD_FILE;
return -1;
}
newNode->next = NULL;
size -= used;
start += used;
}
- file_cbfs_result = CBFS_SUCCESS;
+ priv->result = CBFS_SUCCESS;
}
/* Get the CBFS header out of the ROM and do endian conversion. */
if (header->magic != good_magic || header->offset >
header->rom_size - header->boot_block_size) {
- file_cbfs_result = CBFS_BAD_HEADER;
+ cbfs_s.result = CBFS_BAD_HEADER;
return 1;
}
return 0;
file_cbfs_fill_cache(priv, start_of_rom, priv->header.rom_size,
priv->header.align);
- if (file_cbfs_result == CBFS_SUCCESS)
+ if (priv->result == CBFS_SUCCESS)
priv->initialized = 1;
}
struct cbfs_priv *priv = &cbfs_s;
if (priv->initialized) {
- file_cbfs_result = CBFS_SUCCESS;
+ priv->result = CBFS_SUCCESS;
return &priv->header;
} else {
- file_cbfs_result = CBFS_NOT_INITIALIZED;
+ priv->result = CBFS_NOT_INITIALIZED;
return NULL;
}
}
struct cbfs_priv *priv = &cbfs_s;
if (!priv->initialized) {
- file_cbfs_result = CBFS_NOT_INITIALIZED;
+ priv->result = CBFS_NOT_INITIALIZED;
return NULL;
} else {
- file_cbfs_result = CBFS_SUCCESS;
+ priv->result = CBFS_SUCCESS;
return priv->file_cache;
}
}
struct cbfs_priv *priv = &cbfs_s;
if (!priv->initialized) {
- file_cbfs_result = CBFS_NOT_INITIALIZED;
+ priv->result = CBFS_NOT_INITIALIZED;
*file = NULL;
return;
}
if (*file)
*file = (*file)->next;
- file_cbfs_result = CBFS_SUCCESS;
+ priv->result = CBFS_SUCCESS;
}
const struct cbfs_cachenode *cbfs_find_file(struct cbfs_priv *priv,
struct cbfs_cachenode *cache_node = priv->file_cache;
if (!priv->initialized) {
- file_cbfs_result = CBFS_NOT_INITIALIZED;
+ priv->result = CBFS_NOT_INITIALIZED;
return NULL;
}
cache_node = cache_node->next;
}
if (!cache_node)
- file_cbfs_result = CBFS_FILE_NOT_FOUND;
+ priv->result = CBFS_FILE_NOT_FOUND;
else
- file_cbfs_result = CBFS_SUCCESS;
+ priv->result = CBFS_SUCCESS;
return cache_node;
}
size -= used;
start += used;
}
- file_cbfs_result = CBFS_FILE_NOT_FOUND;
+ cbfs_s.result = CBFS_FILE_NOT_FOUND;
return NULL;
}
const char *file_cbfs_name(const struct cbfs_cachenode *file)
{
- file_cbfs_result = CBFS_SUCCESS;
+ cbfs_s.result = CBFS_SUCCESS;
+
return file->name;
}
u32 file_cbfs_size(const struct cbfs_cachenode *file)
{
- file_cbfs_result = CBFS_SUCCESS;
+ cbfs_s.result = CBFS_SUCCESS;
+
return file->data_length;
}
u32 file_cbfs_type(const struct cbfs_cachenode *file)
{
- file_cbfs_result = CBFS_SUCCESS;
+ cbfs_s.result = CBFS_SUCCESS;
+
return file->type;
}
size = maxsize;
memcpy(buffer, file->data, size);
+ cbfs_s.result = CBFS_SUCCESS;
- file_cbfs_result = CBFS_SUCCESS;
return size;
}