aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/sqfs/dir_reader.h7
-rw-r--r--include/sqfs/meta_reader.h25
-rw-r--r--lib/sqfs/src/dir_reader.c9
-rw-r--r--lib/sqfs/src/readdir.c42
4 files changed, 28 insertions, 55 deletions
diff --git a/include/sqfs/dir_reader.h b/include/sqfs/dir_reader.h
index 1c95e30..11f7ae0 100644
--- a/include/sqfs/dir_reader.h
+++ b/include/sqfs/dir_reader.h
@@ -128,7 +128,7 @@ struct sqfs_dir_reader_state_t {
* the @ref SQFS_DIR_READER_DOT_ENTRIES flag and the behavior was
* not disabled when opening the directory.
*/
- sqfs_u64 cur_ref;
+ sqfs_u64 dir_ref;
/**
* @brief A reference to the current entries inode
@@ -142,11 +142,6 @@ struct sqfs_dir_reader_state_t {
* @brief An opaque, internal state value
*/
sqfs_u8 state;
-
- /**
- * @brief A backup of `state` to reset the state if requested
- */
- sqfs_u8 start_state;
};
#ifdef __cplusplus
diff --git a/include/sqfs/meta_reader.h b/include/sqfs/meta_reader.h
index 9563b82..8e94acd 100644
--- a/include/sqfs/meta_reader.h
+++ b/include/sqfs/meta_reader.h
@@ -54,31 +54,14 @@
* @brief Encapsulates state for simple directory reading
*/
struct sqfs_readdir_state_t {
- struct {
- sqfs_u64 block;
- size_t offset;
- size_t size;
- } init, current;
-
+ sqfs_u64 inode_block;
+ sqfs_u64 block;
+ size_t offset;
+ size_t size;
size_t entries;
-
sqfs_u32 inum_base;
- sqfs_u64 inode_block;
};
-/**
- * @brief Rewind a directory state object back to its starting location
- *
- * @memberof sqfs_readdir_state_t
- *
- * @param it A pointer to the directory state.
- */
-static SQFS_INLINE void sqfs_readdir_state_reset(sqfs_readdir_state_t *s)
-{
- s->current = s->init;
- s->entries = 0;
-}
-
#ifdef __cplusplus
extern "C" {
#endif
diff --git a/lib/sqfs/src/dir_reader.c b/lib/sqfs/src/dir_reader.c
index 2b6d0e8..fdb5976 100644
--- a/lib/sqfs/src/dir_reader.c
+++ b/lib/sqfs/src/dir_reader.c
@@ -210,11 +210,11 @@ int sqfs_dir_reader_open_dir(sqfs_dir_reader_t *rd,
parent = inode->data.dir.parent_inode;
}
- if (dcache_find(rd, inode->base.inode_number, &state->cur_ref))
+ if (dcache_find(rd, inode->base.inode_number, &state->dir_ref))
return SQFS_ERROR_NO_ENTRY;
- if (state->cur_ref == rd->super.root_inode_ref) {
- state->parent_ref = state->cur_ref;
+ if (state->dir_ref == rd->super.root_inode_ref) {
+ state->parent_ref = state->dir_ref;
} else if (dcache_find(rd, parent, &state->parent_ref)) {
return SQFS_ERROR_NO_ENTRY;
}
@@ -224,7 +224,6 @@ int sqfs_dir_reader_open_dir(sqfs_dir_reader_t *rd,
state->state = DIR_STATE_ENTRIES;
}
- state->start_state = state->state;
return 0;
}
@@ -256,7 +255,7 @@ int sqfs_dir_reader_read(sqfs_dir_reader_t *rd, sqfs_dir_reader_state_t *state,
err = mk_dummy_entry(".", out);
if (err == 0) {
state->state = DIR_STATE_DOT;
- state->ent_ref = state->cur_ref;
+ state->ent_ref = state->dir_ref;
}
return err;
case DIR_STATE_DOT:
diff --git a/lib/sqfs/src/readdir.c b/lib/sqfs/src/readdir.c
index 9feaf22..1e5dd0f 100644
--- a/lib/sqfs/src/readdir.c
+++ b/lib/sqfs/src/readdir.c
@@ -73,19 +73,18 @@ int sqfs_readdir_state_init(sqfs_readdir_state_t *s, const sqfs_super_t *super,
memset(s, 0, sizeof(*s));
if (inode->base.type == SQFS_INODE_DIR) {
- s->init.block = inode->data.dir.start_block;
- s->init.offset = inode->data.dir.offset;
- s->init.size = inode->data.dir.size;
+ s->block = inode->data.dir.start_block;
+ s->offset = inode->data.dir.offset;
+ s->size = inode->data.dir.size;
} else if (inode->base.type == SQFS_INODE_EXT_DIR) {
- s->init.block = inode->data.dir_ext.start_block;
- s->init.offset = inode->data.dir_ext.offset;
- s->init.size = inode->data.dir_ext.size;
+ s->block = inode->data.dir_ext.start_block;
+ s->offset = inode->data.dir_ext.offset;
+ s->size = inode->data.dir_ext.size;
} else {
return SQFS_ERROR_NOT_DIR;
}
- s->init.block += super->directory_table_start;
- s->current = s->init;
+ s->block += super->directory_table_start;
return 0;
}
@@ -99,11 +98,10 @@ int sqfs_meta_reader_readdir(sqfs_meta_reader_t *m, sqfs_readdir_state_t *it,
if (it->entries == 0) {
sqfs_dir_header_t hdr;
- if (it->current.size <= sizeof(hdr))
+ if (it->size <= sizeof(hdr))
goto out_eof;
- ret = sqfs_meta_reader_seek(m, it->current.block,
- it->current.offset);
+ ret = sqfs_meta_reader_seek(m, it->block, it->offset);
if (ret != 0)
return ret;
@@ -111,19 +109,18 @@ int sqfs_meta_reader_readdir(sqfs_meta_reader_t *m, sqfs_readdir_state_t *it,
if (ret != 0)
return ret;
- sqfs_meta_reader_get_position(m, &it->current.block,
- &it->current.offset);
+ sqfs_meta_reader_get_position(m, &it->block, &it->offset);
- it->current.size -= sizeof(hdr);
+ it->size -= sizeof(hdr);
it->entries = hdr.count + 1;
it->inum_base = hdr.inode_number;
it->inode_block = hdr.start_block;
}
- if (it->current.size <= sizeof(**ent))
+ if (it->size <= sizeof(**ent))
goto out_eof;
- ret = sqfs_meta_reader_seek(m, it->current.block, it->current.offset);
+ ret = sqfs_meta_reader_seek(m, it->block, it->offset);
if (ret != 0)
return ret;
@@ -131,18 +128,17 @@ int sqfs_meta_reader_readdir(sqfs_meta_reader_t *m, sqfs_readdir_state_t *it,
if (ret)
return ret;
- sqfs_meta_reader_get_position(m, &it->current.block,
- &it->current.offset);
+ sqfs_meta_reader_get_position(m, &it->block, &it->offset);
- it->current.size -= sizeof(**ent);
+ it->size -= sizeof(**ent);
it->entries -= 1;
count = (*ent)->size + 1;
- if (count >= it->current.size) {
- it->current.size = 0;
+ if (count >= it->size) {
+ it->size = 0;
} else {
- it->current.size -= count;
+ it->size -= count;
}
if (inum != NULL)
@@ -155,7 +151,7 @@ int sqfs_meta_reader_readdir(sqfs_meta_reader_t *m, sqfs_readdir_state_t *it,
return 0;
out_eof:
- it->current.size = 0;
+ it->size = 0;
it->entries = 0;
return 1;
}