Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for decoding erofs into lcfs_node, and some tooling using it #185

Merged
merged 19 commits into from
Sep 15, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions libcomposefs/lcfs-utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,41 @@

#include <assert.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <unistd.h>

#define max(a, b) ((a > b) ? (a) : (b))
#define min(a, b) (((a) < (b)) ? (a) : (b))

static inline bool str_has_prefix(const char *str, const char *prefix)
{
return strncmp(str, prefix, strlen(prefix)) == 0;
}

static inline char *memdup(const char *s, size_t len)
{
char *s2 = malloc(len);
if (s2 == NULL) {
errno = ENOMEM;
return NULL;
}
memcpy(s2, s, len);
return s2;
}

static inline char *str_join(const char *a, const char *b)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

optional: This is just code motion, so OK, but same question re asprintf - can be a followup.

{
size_t a_len = strlen(a);
size_t b_len = strlen(b);
char *res = malloc(a_len + b_len + 1);
if (res) {
memcpy(res, a, a_len);
memcpy(res + a_len, b, b_len + 1);
}
return res;
}

static inline void _lcfs_reset_errno_(int *saved_errno)
{
if (*saved_errno < 0)
Expand Down
17 changes: 0 additions & 17 deletions libcomposefs/lcfs-writer-erofs.c
Original file line number Diff line number Diff line change
Expand Up @@ -256,11 +256,6 @@ static int xattrs_ht_sort(const void *d1, const void *d2)
return memcmp(v2->xattr->value, v1->xattr->value, v1->xattr->value_len);
}

static bool str_has_prefix(const char *str, const char *prefix)
{
return strncmp(str, prefix, strlen(prefix)) == 0;
}

static uint8_t xattr_erofs_entry_index(struct lcfs_xattr_s *xattr, char **rest)
{
char *key = xattr->key;
Expand Down Expand Up @@ -1054,18 +1049,6 @@ static int write_erofs_shared_xattrs(struct lcfs_ctx_s *ctx)
return 0;
}

static char *str_join(const char *a, const char *b)
{
size_t a_len = strlen(a);
size_t b_len = strlen(b);
char *res = malloc(a_len + b_len + 1);
if (res) {
memcpy(res, a, a_len);
memcpy(res + a_len, b, b_len + 1);
}
return res;
}

static int add_overlayfs_xattrs(struct lcfs_node_s *node)
{
int type = node->inode.st_mode & S_IFMT;
Expand Down
11 changes: 0 additions & 11 deletions libcomposefs/lcfs-writer.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,17 +61,6 @@ char *maybe_join_path(const char *a, const char *b)
return res;
}

static char *memdup(const char *s, size_t len)
{
char *s2 = malloc(len);
if (s2 == NULL) {
errno = ENOMEM;
return NULL;
}
memcpy(s2, s, len);
return s2;
}

size_t hash_memory(const char *string, size_t len, size_t n_buckets)
{
size_t i, value = 0;
Expand Down