libsqsh v1.5.2
Loading...
Searching...
No Matches
list_xattrs_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 != 3) {
16 printf("Usage: %s <sqsh-file> <path>\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 struct SqshFile *file = sqsh_open(archive, argv[2], &error_code);
38 if (error_code != 0) {
39 sqsh_perror(error_code, "sqsh_open");
40 return 1;
41 }
42
43 struct SqshXattrIterator *iterator =
44 sqsh_xattr_iterator_new(file, &error_code);
45 if (error_code != 0) {
46 sqsh_perror(error_code, "sqsh_xattr_iterator_new");
47 return 1;
48 }
49
50 while (sqsh_xattr_iterator_next(iterator, &error_code)) {
51 const char *prefix = sqsh_xattr_iterator_prefix(iterator);
52 const size_t prefix_size = sqsh_xattr_iterator_prefix_size(iterator);
53 const char *name = sqsh_xattr_iterator_name(iterator);
54 const size_t name_size = sqsh_xattr_iterator_name_size(iterator);
55 const char *value = sqsh_xattr_iterator_value(iterator);
56 const size_t value_size = sqsh_xattr_iterator_value_size2(iterator);
57
58 printf("%.*s%.*s=%.*s\n", (int)prefix_size, prefix, (int)name_size,
59 name, (int)value_size, value);
60 }
61 if (error_code < 0) {
62 sqsh_perror(error_code, "sqsh_xattr_iterator_next");
63 return 1;
64 }
65
67 sqsh_close(file);
68 sqsh_archive_close(archive);
69 return 0;
70}
int main(int argc, char *argv[])
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.
The Inode context.
SQSH_NO_UNUSED struct SqshFile * sqsh_open(struct SqshArchive *archive, const char *path, int *err)
Initialize the file context from a path.
An iterator over extended attributes.
int sqsh_xattr_iterator_free(struct SqshXattrIterator *iterator)
Frees the resources used by an xattr iterator.
uint32_t sqsh_xattr_iterator_value_size2(const struct SqshXattrIterator *iterator)
Retrieves the size of the value of the current xattr.
SQSH_NO_UNUSED struct SqshXattrIterator * sqsh_xattr_iterator_new(const struct SqshFile *file, int *err)
Allocates and initializes a new xattr iterator.
uint16_t sqsh_xattr_iterator_name_size(const struct SqshXattrIterator *iterator)
Retrieves the size of the name of the current xattr.
const char * sqsh_xattr_iterator_prefix(const struct SqshXattrIterator *iterator)
Retrieves the prefix of the current xattr.
const char * sqsh_xattr_iterator_value(const struct SqshXattrIterator *iterator)
Retrieves the value of the current xattr.
const char * sqsh_xattr_iterator_name(const struct SqshXattrIterator *iterator)
Retrieves the name of the current xattr excluding the prefix.
SQSH_NO_UNUSED bool sqsh_xattr_iterator_next(struct SqshXattrIterator *iterator, int *err)
Advances the iterator to the next xattr.
uint16_t sqsh_xattr_iterator_prefix_size(const struct SqshXattrIterator *iterator)
Retrieves the size of the prefix of the current xattr.