libsqsh v1.5.1
Loading...
Searching...
No Matches
list_dir_ll.c
Go to the documentation of this file.
1
9#include <sqsh.h>
10#include <stdio.h>
11
12int
13main(int argc, char *argv[]) {
14 int error_code = 0;
15 if (argc != 2) {
16 printf("Usage: %s <sqsh-file>\n", argv[0]);
17 return 1;
18 }
19 struct SqshConfig config = {
20 // Read the header file to find documentation on these fields.
21 // It's safe to set them all to 0.
23 .source_size = 0,
24 .mapper_block_size = 0,
25 .mapper_lru_size = 0,
26 .metablock_lru_size = 0,
27 .data_lru_size = 0,
28 .archive_offset = 0,
29 .max_symlink_depth = 0,
30 };
31 struct SqshArchive *archive =
32 sqsh_archive_open(argv[1], &config, &error_code);
33 if (error_code != 0) {
34 sqsh_perror(error_code, "sqsh_archive_new");
35 return 1;
36 }
37 const struct SqshSuperblock *superblock = sqsh_archive_superblock(archive);
38 uint64_t inode_root_ref = sqsh_superblock_inode_root_ref(superblock);
39 struct SqshFile *file =
40 sqsh_open_by_ref(archive, inode_root_ref, &error_code);
41 if (error_code != 0) {
42 sqsh_perror(error_code, "sqsh_file_new");
43 return 1;
44 }
45
46 struct SqshDirectoryIterator *iterator =
47 sqsh_directory_iterator_new(file, &error_code);
48 if (error_code != 0) {
49 sqsh_perror(error_code, "sqsh_directory_iterator_new");
50 return 1;
51 }
52
53 while (sqsh_directory_iterator_next(iterator, &error_code)) {
54 size_t size;
55 const char *name = sqsh_directory_iterator_name2(iterator, &size);
56 fwrite(name, size, 1, stdout);
57 fputc('\n', stdout);
58 }
59 if (error_code < 0) {
60 sqsh_perror(error_code, "sqsh_directory_iterator_next");
61 return 1;
62 }
63
65 sqsh_close(file);
66 sqsh_archive_close(archive);
67 return 0;
68}
int main(int argc, char *argv[])
Definition list_dir_ll.c:13
void sqsh_perror(int error_code, const char *msg)
Print the error message for the given error code.
const struct SqshMemoryMapperImpl *const sqsh_mapper_impl_mmap
a mapper that uses mmap to map the file into memory.
SQSH_NO_UNUSED struct SqshArchive * sqsh_archive_open(const void *source, const struct SqshConfig *config, int *err)
initializes a archive context in heap.
The SqshConfig struct contains all the configuration options for a sqsh session.
const struct SqshMemoryMapperImpl * source_mapper
source_mapper is the memory mapper implementation that will be used to map the archive.
A directory iterator.
SQSH_NO_UNUSED struct SqshDirectoryIterator * sqsh_directory_iterator_new(const struct SqshFile *file, int *err)
Allocates and initializes a new directory iterator.
int sqsh_directory_iterator_free(struct SqshDirectoryIterator *iterator)
Frees the resources used by a directory iterator.
SQSH_NO_UNUSED bool sqsh_directory_iterator_next(struct SqshDirectoryIterator *iterator, int *err)
Advances the iterator to the next entry.
const char * sqsh_directory_iterator_name2(const struct SqshDirectoryIterator *iterator, size_t *len)
Retrieves the name of the current entry.
The Inode context.
SQSH_NO_UNUSED struct SqshFile * sqsh_open_by_ref(struct SqshArchive *archive, uint64_t inode_ref, int *err)
Initializes a file context in heap.
The superblock context is used to access the superblock of the archive.
uint64_t sqsh_superblock_inode_root_ref(const struct SqshSuperblock *context)
Retrieves the reference of the root inode in a superblock context.