Commit 64ac239e authored by Petri Hintukainen's avatar Petri Hintukainen

factorize metadata reading code

parent 15a8bbd0
......@@ -771,15 +771,11 @@ static int _read_metadata_blocks(udfread *udf, uint8_t *buf,
return tag_id;
}
static struct file_entry *_read_file_entry(udfread *udf,
const struct long_ad *icb)
static uint8_t *_read_metadata(udfread *udf, const struct long_ad *icb, int *tag_id)
{
struct file_entry *fe = NULL;
uint32_t num_blocks = (icb->length + UDF_BLOCK_SIZE - 1) / UDF_BLOCK_SIZE;
uint8_t *buf;
int tag_id;
udf_trace("file entry size %u bytes\n", icb->length);
if (num_blocks < 1) {
return NULL;
}
......@@ -790,13 +786,31 @@ static struct file_entry *_read_file_entry(udfread *udf,
return NULL;
}
tag_id = _read_metadata_blocks(udf, buf, icb);
if (tag_id < 0) {
udf_error("reading file entry failed\n");
*tag_id = _read_metadata_blocks(udf, buf, icb);
if (*tag_id < 0) {
udf_log("reading icb blocks failed\n");
free(buf);
return NULL;
}
return buf;
}
static struct file_entry *_read_file_entry(udfread *udf,
const struct long_ad *icb)
{
struct file_entry *fe = NULL;
uint8_t *buf;
int tag_id;
udf_trace("file entry size %u bytes\n", icb->length);
buf = _read_metadata(udf, icb, &tag_id);
if (!buf) {
udf_error("reading file entry failed\n");
return NULL;
}
switch (tag_id) {
case ECMA_FileEntry:
fe = decode_file_entry(buf, UDF_BLOCK_SIZE, icb->partition);
......@@ -857,28 +871,18 @@ static int _parse_dir(const uint8_t *data, uint32_t length, struct udf_dir *dir)
static struct udf_dir *_read_dir_file(udfread *udf, const struct long_ad *loc)
{
uint32_t num_blocks = (loc->length + UDF_BLOCK_SIZE - 1) / UDF_BLOCK_SIZE;
uint8_t *data;
struct udf_dir *dir = NULL;
uint8_t *data;
int tag_id;
if (num_blocks < 1) {
return NULL;
}
udf_trace("directory size %u bytes\n", loc->length);
data = (uint8_t *)malloc(num_blocks * UDF_BLOCK_SIZE);
data = _read_metadata(udf, loc, &tag_id);
if (!data) {
udf_error("out of memory\n");
return NULL;
}
if (_read_metadata_blocks(udf, data, loc) < 0) {
udf_error("reading directory file failed\n");
free(data);
return NULL;
}
udf_trace("directory size %u bytes\n", loc->length);
dir = (struct udf_dir *)calloc(1, sizeof(struct udf_dir));
if (dir) {
if (_parse_dir(data, loc->length, dir) < 0) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment