Skip to content

Commit

Permalink
add documentation, fix issues found while documenting
Browse files Browse the repository at this point in the history
  • Loading branch information
Gottox committed Sep 27, 2022
1 parent c22d09c commit f10a9c8
Show file tree
Hide file tree
Showing 10 changed files with 109 additions and 16 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
######################################################################

NINJA_TARGETS := test benchmark install dist scan-build clang-format uninstall \
all tidy doc
all tidy doc coverage-html

MESON_FLAGS = -Dtest=true -Ddoc=true
MESON_FLAGS = -Dtest=true -Ddoc=true -Db_coverage=true

SANATIZE = 1

Expand Down
2 changes: 1 addition & 1 deletion doc/Doxyfile.in
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ INTERACTIVE_SVG = YES
FULL_PATH_NAMES = NO

# Warning and progress messages
QUIET = YES
QUIET = NO
WARNINGS = YES
WARN_IF_UNDOCUMENTED = YES

Expand Down
2 changes: 2 additions & 0 deletions src/error.c
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,8 @@ sqsh_error_str(int error_code) {
return "Hashmap internal error";
case HSQS_ERROR_NO_EXTENDED_DIRECTORY:
return "No extended directory";
case HSQS_ERROR_NO_FRAGMENT_TABLE:
return "No fragment table";
case HSQS_ERROR_NO_EXPORT_TABLE:
return "No export table";
case HSQS_ERROR_NO_XATTR_TABLE:
Expand Down
1 change: 1 addition & 0 deletions src/error.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ enum SqshError {
HSQS_ERROR_INTEGER_OVERFLOW,
HSQS_ERROR_NO_SUCH_FILE,
HSQS_ERROR_NO_FRAGMENT,
HSQS_ERROR_NO_FRAGMENT_TABLE,
HSQS_ERROR_NO_DATABLOCKS,
HSQS_ERROR_SEEK_OUT_OF_RANGE,
HSQS_ERROR_SEEK_IN_FRAGMENT,
Expand Down
4 changes: 4 additions & 0 deletions src/iterator/directory_iterator.c
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ directory_iterator_index_lookup(
sqsh_inode_directory_index_iterator_index(&index_iterator);
}
iterator->remaining_entries = 0;
if (rv < 0) {
return rv;
}
rv = sqsh_inode_directory_index_iterator_clean(&index_iterator);
return rv;
}

Expand Down
4 changes: 2 additions & 2 deletions src/iterator/xattr_iterator.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@ sqsh_xattr_iterator_init(

uint64_t start_block = sqsh_xattr_table_start(xattr_table);

// TODO upper bounds should not be ~0.
// TODO upper bounds should not be SIZE_MAX.
rv = sqsh_metablock_stream_init(
&iterator->metablock, xattr_table->sqsh, start_block, ~0);
&iterator->metablock, xattr_table->sqsh, start_block, SIZE_MAX);
if (rv < 0) {
goto out;
}
Expand Down
8 changes: 2 additions & 6 deletions src/sqsh.c
Original file line number Diff line number Diff line change
Expand Up @@ -138,9 +138,6 @@ int
sqsh_id_table(struct Sqsh *sqsh, struct SqshTable **id_table) {
int rv = 0;
uint64_t table_start = sqsh_superblock_id_table_start(&sqsh->superblock);
if (table_start == NO_SEGMENT) {
return -HSQS_ERROR_NO_XATTR_TABLE;
}

if (!is_initialized(sqsh, INITIALIZED_ID_TABLE)) {
rv = sqsh_table_init(
Expand All @@ -162,7 +159,7 @@ sqsh_export_table(struct Sqsh *sqsh, struct SqshTable **export_table) {
uint64_t table_start =
sqsh_superblock_export_table_start(&sqsh->superblock);
if (table_start == NO_SEGMENT) {
return -HSQS_ERROR_NO_XATTR_TABLE;
return -HSQS_ERROR_NO_EXPORT_TABLE;
}

if (!(sqsh->initialized & INITIALIZED_EXPORT_TABLE)) {
Expand All @@ -186,7 +183,7 @@ sqsh_fragment_table(
uint64_t table_start =
sqsh_superblock_fragment_table_start(&sqsh->superblock);
if (table_start == NO_SEGMENT) {
return -HSQS_ERROR_NO_XATTR_TABLE;
return -HSQS_ERROR_NO_FRAGMENT_TABLE;
}

if (!is_initialized(sqsh, INITIALIZED_FRAGMENT_TABLE)) {
Expand All @@ -207,7 +204,6 @@ sqsh_xattr_table(struct Sqsh *sqsh, struct SqshXattrTable **xattr_table) {
int rv = 0;
uint64_t table_start =
sqsh_superblock_xattr_id_table_start(&sqsh->superblock);

if (table_start == NO_SEGMENT) {
return -HSQS_ERROR_NO_XATTR_TABLE;
}
Expand Down
68 changes: 67 additions & 1 deletion src/sqsh.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,27 +90,93 @@ HSQS_NO_UNUSED int sqsh_open(struct Sqsh *sqsh, const char *path);

#ifdef CONFIG_CURL
/**
* @brief sqsh_open_url opens the sqsh file at the given url.
* @brief sqsh_open_url opens the sqsh file at the given url. Only available if
* `curl` is enabled.
* @param sqsh the Sqsh structure to initialize.
* @param url the url to the sqsh file.
* @return 0 on success, less than 0 on error.
*/
int sqsh_open_url(struct Sqsh *sqsh, const char *url);
#endif

/**
* @brief sqsh_superblock returns the superblock context.
* @param sqsh the Sqsh structure.
* @return the superblock context.
*/
struct SqshSuperblockContext *sqsh_superblock(struct Sqsh *sqsh);

/**
* @brief sqsh_mapper returns the mapper to retrieve chunks of the sqsh file.
* @param sqsh the Sqsh structure.
* @return the mapper context.
*/
struct SqshMapper *sqsh_mapper(struct Sqsh *sqsh);
/**
* @brief sqsh_data_compression returns the compression context for data blocks
* @param sqsh the Sqsh structure.
* @return the compression context.
*/
struct SqshCompression *sqsh_data_compression(struct Sqsh *sqsh);

/**
* @brief sqsh_data_compression returns the compression context for metadata
* blocks
* @param sqsh the Sqsh structure.
* @return the compression context.
*/
struct SqshCompression *sqsh_metablock_compression(struct Sqsh *sqsh);

/**
* @brief sqsh_id_table returns the id table context.
* @param sqsh the Sqsh structure.
* @param id_table double pointer that will be set to the uid/gid table.
* @return 0 on success, less than 0 on error.
*/
int sqsh_id_table(struct Sqsh *sqsh, struct SqshTable **id_table);

/**
* @brief sqsh_export_table returns the export table context. If the archive
* does not contain an export table, the function returns
* `-HSQS_ERROR_NO_EXPORT_TABLE`
* @param sqsh the Sqsh structure.
* @param export_table double pointer that will be set to the export table.
* @return 0 on success, less than 0 on error.
*/
int sqsh_export_table(struct Sqsh *sqsh, struct SqshTable **export_table);

/**
* @brief sqsh_fragment_table returns the fragment table context. If the archive
* does not contain a fragment table, the function returns
* `-HSQS_ERROR_NO_FRAGMENT_TABLE`.
* @param sqsh the Sqsh structure.
* @param fragment_table double pointer that will be set to the fragment table.
* @return 0 on success, less than 0 on error.
*/
int sqsh_fragment_table(
struct Sqsh *sqsh, struct SqshFragmentTable **fragment_table);

/**
* @brief sqsh_xattr_table returns the xattr table context. If the archive
* does not contain an xattr table, the function returns
* `-HSQS_ERROR_NO_XATTR_TABLE`.
* @param sqsh the Sqsh structure.
* @param xattr_table double pointer that will be set to the xattr table.
* @return 0 on success, less than 0 on error.
*/
int sqsh_xattr_table(struct Sqsh *sqsh, struct SqshXattrTable **xattr_table);

/**
* @brief sqsh_compression_options returns the compression options context.
* @param sqsh the Sqsh structure.
* @param compression_options double pointer that will be set to the
* compression options context.
* @return the compression options context.
*/
int sqsh_compression_options(
struct Sqsh *sqsh,
struct SqshCompressionOptionsContext **compression_options);

/**
* @brief sqsh_cleanup frees all resources allocated by the Sqsh structure and
* cleans up the structure.
Expand Down
30 changes: 26 additions & 4 deletions test/integration.c
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,13 @@ sqsh_ls() {
assert(strcmp("b", name) == 0);
free(name);

rv = sqsh_directory_iterator_next(&iter);
assert(rv >= 0);
rv = sqsh_directory_iterator_name_dup(&iter, &name);
assert(rv == 9);
assert(strcmp("large_dir", name) == 0);
free(name);

rv = sqsh_directory_iterator_next(&iter);
// End of file list
assert(rv == 0);
Expand Down Expand Up @@ -251,6 +258,24 @@ sqsh_test_uid_and_gid() {
assert(rv == 0);
}

static void
sqsh_test_extended_dir() {
int rv;
struct SqshInodeContext inode = {0};
struct Sqsh sqsh = {0};
rv = sqsh_init(&sqsh, squash_image, sizeof(squash_image));
assert(rv == 0);

rv = sqsh_inode_load_by_path(&inode, &sqsh, "/large_dir/999");
assert(rv == 0);

rv = sqsh_inode_cleanup(&inode);
assert(rv == 0);

rv = sqsh_cleanup(&sqsh);
assert(rv == 0);
}

static void
sqsh_test_xattr() {
const char *expected_value = "1234567891234567891234567890001234567890";
Expand Down Expand Up @@ -333,10 +358,6 @@ sqsh_test_xattr() {
rv = sqsh_inode_cleanup(&entry_inode);
assert(rv == 0);

rv = sqsh_directory_iterator_next(&dir_iter);
// End of file list
assert(rv == 0);

rv = sqsh_directory_iterator_cleanup(&dir_iter);
assert(rv == 0);

Expand Down Expand Up @@ -577,6 +598,7 @@ TEST(sqsh_cat_fragment);
TEST(sqsh_cat_datablock_and_fragment);
TEST(sqsh_cat_size_overflow);
TEST(sqsh_test_uid_and_gid);
TEST(sqsh_test_extended_dir);
TEST(sqsh_test_xattr);
TEST_OFF(fuzz_crash_1); // Fails since the library sets up tables
TEST_OFF(fuzz_crash_2); // Fails since the library sets up tables
Expand Down
2 changes: 2 additions & 0 deletions utils/create_squashfs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ tmp=$3
mkdir -p "$tmp"
echo a > "$tmp/a"
seq 1 1050000 | tr -cd "\n" | tr '\n' b > "$tmp/b"
mkdir "$tmp/large_dir"
seq 1 1050 | sed "s#.*#$tmp/large_dir/&#" | xargs touch
$SETFATTR -n user.foo -v 1234567891234567891234567890001234567890 "$tmp/a"
$SETFATTR -n user.bar -v 1234567891234567891234567890001234567890 "$tmp/b"
[ -e "$out" ] && rm "$out"
Expand Down

0 comments on commit f10a9c8

Please sign in to comment.