Skip to content

Commit

Permalink
Merge pull request #125 from Gottox/fix/use-uint32_t-for-inodes
Browse files Browse the repository at this point in the history
inode_map: Replace _map_set() with _map_set2()
  • Loading branch information
Gottox committed Sep 5, 2023
2 parents f3f5979 + f6e97ae commit 62bf61a
Show file tree
Hide file tree
Showing 8 changed files with 54 additions and 32 deletions.
20 changes: 18 additions & 2 deletions include/sqsh_archive.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,10 @@ sqsh_inode_map_get(const struct SqshInodeMap *map, uint64_t inode_number);
* @return The inode reference on success, 0 on error.
*/
SQSH_NO_UNUSED uint64_t sqsh_inode_map_get2(
const struct SqshInodeMap *map, uint64_t inode_number, int *err);
const struct SqshInodeMap *map, uint32_t inode_number, int *err);

/**
* @deprecated Since 1.2.0. Use sqsh_inode_map_set2() instead.
* @memberof SqshInodeMap
* @brief Sets the inode reference for a given inode number.
*
Expand All @@ -114,9 +115,24 @@ SQSH_NO_UNUSED uint64_t sqsh_inode_map_get2(
*
* @return 0 on success, a negative value on error.
*/
SQSH_NO_UNUSED int sqsh_inode_map_set(
__attribute__((deprecated("Since 1.2.0. Use sqsh_inode_map_set2() "
"instead."))) SQSH_NO_UNUSED int
sqsh_inode_map_set(
struct SqshInodeMap *map, uint64_t inode_number, uint64_t inode_ref);

/**
* @memberof SqshInodeMap
* @brief Sets the inode reference for a given inode number.
*
* @param[in] map The context to use.
* @param[in] inode_number The inode number to set the reference for.
* @param[in] inode_ref The inode reference to set.
*
* @return 0 on success, a negative value on error.
*/
SQSH_NO_UNUSED int sqsh_inode_map_set2(
struct SqshInodeMap *map, uint32_t inode_number, uint64_t inode_ref);

/***************************************
* archive/superblock_context.c
*/
Expand Down
4 changes: 2 additions & 2 deletions include/sqsh_archive_private.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ struct SqshInodeMap {
* @return 0 on success, a negative value on error.
*/
SQSH_NO_UNUSED SQSH_NO_EXPORT int
sqsh_inode_map_init(struct SqshInodeMap *map, struct SqshArchive *archive);
sqsh__inode_map_init(struct SqshInodeMap *map, struct SqshArchive *archive);

/**
* @internal
Expand All @@ -123,7 +123,7 @@ sqsh_inode_map_init(struct SqshInodeMap *map, struct SqshArchive *archive);
*
* @return 0 on success, a negative value on error.
*/
SQSH_NO_EXPORT int sqsh_inode_map_cleanup(struct SqshInodeMap *map);
SQSH_NO_EXPORT int sqsh__inode_map_cleanup(struct SqshInodeMap *map);

/***************************************
* archive/superblock.c
Expand Down
4 changes: 2 additions & 2 deletions lib/archive/archive.c
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ sqsh_archive_inode_map(
goto out;
}
if (!(archive->initialized & INITIALIZED_INODE_MAP)) {
rv = sqsh_inode_map_init(&archive->inode_map, archive);
rv = sqsh__inode_map_init(&archive->inode_map, archive);
if (rv < 0) {
goto out;
}
Expand Down Expand Up @@ -364,7 +364,7 @@ sqsh__archive_cleanup(struct SqshArchive *archive) {
sqsh__extract_manager_cleanup(&archive->data_extract_manager);
}
if (is_initialized(archive, INITIALIZED_INODE_MAP)) {
sqsh_inode_map_cleanup(&archive->inode_map);
sqsh__inode_map_cleanup(&archive->inode_map);
}
sqsh__extract_manager_cleanup(&archive->metablock_extract_manager);
sqsh__superblock_cleanup(&archive->superblock);
Expand Down
26 changes: 16 additions & 10 deletions lib/archive/inode_map.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
// empty inodes without memset()ing the inode map to all `UINT64_MAX`s.

int
sqsh_inode_map_init(struct SqshInodeMap *map, struct SqshArchive *archive) {
sqsh__inode_map_init(struct SqshInodeMap *map, struct SqshArchive *archive) {
int rv = 0;
const struct SqshSuperblock *superblock = sqsh_archive_superblock(archive);
const uint32_t inode_count = sqsh_superblock_inode_count(superblock);
Expand All @@ -79,7 +79,7 @@ sqsh_inode_map_init(struct SqshInodeMap *map, struct SqshArchive *archive) {

uint64_t
sqsh_inode_map_get2(
const struct SqshInodeMap *map, uint64_t inode_number, int *err) {
const struct SqshInodeMap *map, uint32_t inode_number, int *err) {
int rv = 0;
uint64_t inode_ref = 0;
atomic_uint_fast64_t *inode_refs = map->inode_refs;
Expand Down Expand Up @@ -109,14 +109,9 @@ sqsh_inode_map_get2(
return inode_ref;
}

uint64_t
sqsh_inode_map_get(const struct SqshInodeMap *map, uint64_t inode_number) {
return sqsh_inode_map_get2(map, inode_number, NULL);
}

int
sqsh_inode_map_set(
struct SqshInodeMap *map, uint64_t inode_number, uint64_t inode_ref) {
sqsh_inode_map_set2(
struct SqshInodeMap *map, uint32_t inode_number, uint64_t inode_ref) {
uint64_t old_value;
atomic_uint_fast64_t *inode_refs = map->inode_refs;

Expand All @@ -133,8 +128,19 @@ sqsh_inode_map_set(
return 0;
}

uint64_t
sqsh_inode_map_get(const struct SqshInodeMap *map, uint64_t inode_number) {
return sqsh_inode_map_get2(map, inode_number, NULL);
}

int
sqsh_inode_map_set(
struct SqshInodeMap *map, uint64_t inode_number, uint64_t inode_ref) {
return sqsh_inode_map_set2(map, inode_number, inode_ref);
}

int
sqsh_inode_map_cleanup(struct SqshInodeMap *map) {
sqsh__inode_map_cleanup(struct SqshInodeMap *map) {
free(map->inode_refs);
return 0;
}
2 changes: 1 addition & 1 deletion lib/file/file.c
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ sqsh__file_init(
if (rv < 0) {
goto out;
}
rv = sqsh_inode_map_set(inode_map, sqsh_file_inode(inode), inode_ref);
rv = sqsh_inode_map_set2(inode_map, sqsh_file_inode(inode), inode_ref);

out:
if (rv < 0) {
Expand Down
4 changes: 2 additions & 2 deletions lib/tree/walker.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ update_inode_from_iterator(struct SqshTreeWalker *walker) {
uint64_t inode_ref = sqsh_directory_iterator_inode_ref(iterator);

walker->current_inode_ref = inode_ref;
return sqsh_inode_map_set(walker->inode_map, inode_number, inode_ref);
return sqsh_inode_map_set2(walker->inode_map, inode_number, inode_ref);
}

static int
Expand Down Expand Up @@ -93,7 +93,7 @@ enter_directory(struct SqshTreeWalker *walker, uint64_t inode_ref) {

const uint64_t inode_number = sqsh_file_inode(cwd);
walker->current_inode_ref = inode_ref;
rv = sqsh_inode_map_set(walker->inode_map, inode_number, inode_ref);
rv = sqsh_inode_map_set2(walker->inode_map, inode_number, inode_ref);

out:
return rv;
Expand Down
24 changes: 12 additions & 12 deletions test/archive/inode_map.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ insert_inode_ref(void) {

struct SqshInodeMap map = {0};

rv = sqsh_inode_map_init(&map, &archive);
rv = sqsh__inode_map_init(&map, &archive);
assert(rv == 0);

rv = sqsh_inode_map_set(&map, 1, 4242);
Expand All @@ -60,7 +60,7 @@ insert_inode_ref(void) {
assert(rv == 0);
assert(inode_ref == 4242);

sqsh_inode_map_cleanup(&map);
sqsh__inode_map_cleanup(&map);
sqsh__archive_cleanup(&archive);
}

Expand All @@ -75,7 +75,7 @@ insert_invalid_inode(void) {

struct SqshInodeMap map = {0};

rv = sqsh_inode_map_init(&map, &archive);
rv = sqsh__inode_map_init(&map, &archive);
assert(rv == 0);

rv = sqsh_inode_map_set(&map, 0, 4242);
Expand All @@ -84,7 +84,7 @@ insert_invalid_inode(void) {
rv = sqsh_inode_map_set(&map, 1000, 4242);
assert(rv == -SQSH_ERROR_OUT_OF_BOUNDS);

sqsh_inode_map_cleanup(&map);
sqsh__inode_map_cleanup(&map);
sqsh__archive_cleanup(&archive);
}

Expand All @@ -99,13 +99,13 @@ insert_invalid_inode_ref(void) {

struct SqshInodeMap map = {0};

rv = sqsh_inode_map_init(&map, &archive);
rv = sqsh__inode_map_init(&map, &archive);
assert(rv == 0);

rv = sqsh_inode_map_set(&map, 1, UINT64_MAX);
assert(rv == -SQSH_ERROR_INVALID_ARGUMENT);

sqsh_inode_map_cleanup(&map);
sqsh__inode_map_cleanup(&map);
sqsh__archive_cleanup(&archive);
}

Expand All @@ -121,7 +121,7 @@ get_invalid_inode(void) {

struct SqshInodeMap map = {0};

rv = sqsh_inode_map_init(&map, &archive);
rv = sqsh__inode_map_init(&map, &archive);
assert(rv == 0);

inode_ref = sqsh_inode_map_get2(&map, 424242, &rv);
Expand All @@ -132,7 +132,7 @@ get_invalid_inode(void) {
assert(rv == -SQSH_ERROR_OUT_OF_BOUNDS);
assert(inode_ref == 0);

sqsh_inode_map_cleanup(&map);
sqsh__inode_map_cleanup(&map);
sqsh__archive_cleanup(&archive);
}

Expand All @@ -148,14 +148,14 @@ get_unknown_inode_ref(void) {

struct SqshInodeMap map = {0};

rv = sqsh_inode_map_init(&map, &archive);
rv = sqsh__inode_map_init(&map, &archive);
assert(rv == 0);

inode_ref = sqsh_inode_map_get2(&map, 1, &rv);
assert(rv == -SQSH_ERROR_NO_SUCH_ELEMENT);
assert(inode_ref == 0);

sqsh_inode_map_cleanup(&map);
sqsh__inode_map_cleanup(&map);
sqsh__archive_cleanup(&archive);
}

Expand All @@ -170,7 +170,7 @@ insert_inconsistent_mapping(void) {

struct SqshInodeMap map = {0};

rv = sqsh_inode_map_init(&map, &archive);
rv = sqsh__inode_map_init(&map, &archive);
assert(rv == 0);

rv = sqsh_inode_map_set(&map, 1, 4242);
Expand All @@ -182,7 +182,7 @@ insert_inconsistent_mapping(void) {
rv = sqsh_inode_map_set(&map, 1, 2424);
assert(rv == -SQSH_ERROR_INODE_MAP_IS_INCONSISTENT);

sqsh_inode_map_cleanup(&map);
sqsh__inode_map_cleanup(&map);
sqsh__archive_cleanup(&archive);
}

Expand Down
2 changes: 1 addition & 1 deletion tools/fs3.c
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ fs_lookup(fuse_req_t req, fuse_ino_t parent, const char *name) {
goto out;
}

rv = sqsh_inode_map_set(context.inode_map, inode_number, inode_ref);
rv = sqsh_inode_map_set2(context.inode_map, inode_number, inode_ref);
if (rv < 0) {
fuse_reply_err(req, -fs_common_map_err(rv));
goto out;
Expand Down

0 comments on commit 62bf61a

Please sign in to comment.