Skip to content
This repository was archived by the owner on Sep 27, 2023. It is now read-only.

Commit

Permalink
Merge branch 'hsiangkao:dev' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
affggh authored Jul 18, 2023
2 parents 7817a63 + f7357a6 commit 78bbd73
Show file tree
Hide file tree
Showing 25 changed files with 2,901 additions and 123 deletions.
47 changes: 47 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,15 @@ AC_ARG_ENABLE(lzma,
[AS_HELP_STRING([--enable-lzma], [enable LZMA compression support @<:@default=no@:>@])],
[enable_lzma="$enableval"], [enable_lzma="no"])

AC_ARG_WITH(zlib,
[AS_HELP_STRING([--without-zlib],
[Ignore presence of zlib inflate support @<:@default=enabled@:>@])])

AC_ARG_WITH(libdeflate,
[AS_HELP_STRING([--with-libdeflate],
[Enable and build with libdeflate inflate support @<:@default=disabled@:>@])], [],
[with_libdeflate="no"])

AC_ARG_ENABLE(fuse,
[AS_HELP_STRING([--enable-fuse], [enable erofsfuse @<:@default=no@:>@])],
[enable_fuse="$enableval"], [enable_fuse="no"])
Expand Down Expand Up @@ -167,6 +176,7 @@ AC_CHECK_HEADERS(m4_flatten([
fcntl.h
getopt.h
inttypes.h
linux/aufs_type.h
linux/falloc.h
linux/fs.h
linux/types.h
Expand Down Expand Up @@ -395,6 +405,34 @@ if test "x$enable_lzma" = "xyes"; then
CPPFLAGS="${saved_CPPFLAGS}"
fi

# Configure zlib
AS_IF([test "x$with_zlib" != "xno"], [
PKG_CHECK_MODULES([zlib], [zlib])
# Paranoia: don't trust the result reported by pkgconfig before trying out
saved_LIBS="$LIBS"
saved_CPPFLAGS=${CPPFLAGS}
CPPFLAGS="${zlib_CFLAGS} ${CPPFLAGS}"
LIBS="${zlib_LIBS} $LIBS"
AC_CHECK_LIB(z, inflate, [
have_zlib="yes" ], [
AC_MSG_ERROR([zlib doesn't work properly])])
LIBS="${saved_LIBS}"
CPPFLAGS="${saved_CPPFLAGS}"], [have_zlib="no"])

# Configure libdeflate
AS_IF([test "x$with_libdeflate" != "xno"], [
PKG_CHECK_MODULES([libdeflate], [libdeflate])
# Paranoia: don't trust the result reported by pkgconfig before trying out
saved_LIBS="$LIBS"
saved_CPPFLAGS=${CPPFLAGS}
CPPFLAGS="${libdeflate_CFLAGS} ${CPPFLAGS}"
LIBS="${libdeflate_LIBS} $LIBS"
AC_CHECK_LIB(deflate, libdeflate_deflate_decompress, [
have_libdeflate="yes" ], [
AC_MSG_ERROR([libdeflate doesn't work properly])])
LIBS="${saved_LIBS}"
CPPFLAGS="${saved_CPPFLAGS}"], [have_libdeflate="no"])

# Enable 64-bit off_t
CFLAGS+=" -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64"

Expand All @@ -413,6 +451,7 @@ AM_CONDITIONAL([ENABLE_LZ4], [test "x${have_lz4}" = "xyes"])
AM_CONDITIONAL([ENABLE_LZ4HC], [test "x${have_lz4hc}" = "xyes"])
AM_CONDITIONAL([ENABLE_FUSE], [test "x${have_fuse}" = "xyes"])
AM_CONDITIONAL([ENABLE_LIBLZMA], [test "x${have_liblzma}" = "xyes"])
AM_CONDITIONAL([ENABLE_LIBDEFLATE], [test "x${have_libdeflate}" = "xyes"])

if test "x$have_uuid" = "xyes"; then
AC_DEFINE([HAVE_LIBUUID], 1, [Define to 1 if libuuid is found])
Expand Down Expand Up @@ -450,6 +489,14 @@ if test "x${have_liblzma}" = "xyes"; then
AC_SUBST([liblzma_CFLAGS])
fi

if test "x$have_zlib" = "xyes"; then
AC_DEFINE([HAVE_ZLIB], 1, [Define to 1 if zlib is found])
fi

if test "x$have_libdeflate" = "xyes"; then
AC_DEFINE([HAVE_LIBDEFLATE], 1, [Define to 1 if libdeflate is found])
fi

# Dump maximum block size
AS_IF([test "x$erofs_cv_max_block_size" = "x"],
[$erofs_cv_max_block_size = 4096], [])
Expand Down
2 changes: 1 addition & 1 deletion dump/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ AM_CPPFLAGS = ${libuuid_CFLAGS}
dump_erofs_SOURCES = main.c
dump_erofs_CFLAGS = -Wall -I$(top_srcdir)/include
dump_erofs_LDADD = $(top_builddir)/lib/liberofs.la ${libselinux_LIBS} \
${liblz4_LIBS} ${liblzma_LIBS}
${liblz4_LIBS} ${liblzma_LIBS} ${zlib_LIBS} ${libdeflate_LIBS}
4 changes: 2 additions & 2 deletions fsck/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ AM_CPPFLAGS = ${libuuid_CFLAGS}
fsck_erofs_SOURCES = main.c
fsck_erofs_CFLAGS = -Wall -I$(top_srcdir)/include
fsck_erofs_LDADD = $(top_builddir)/lib/liberofs.la ${libselinux_LIBS} \
${liblz4_LIBS} ${liblzma_LIBS}
${liblz4_LIBS} ${liblzma_LIBS} ${zlib_LIBS} ${libdeflate_LIBS}

if ENABLE_FUZZING
noinst_PROGRAMS = fuzz_erofsfsck
fuzz_erofsfsck_SOURCES = main.c
fuzz_erofsfsck_CFLAGS = -Wall -I$(top_srcdir)/include -DFUZZING
fuzz_erofsfsck_LDFLAGS = -fsanitize=address,fuzzer
fuzz_erofsfsck_LDADD = $(top_builddir)/lib/liberofs.la ${libselinux_LIBS} \
${liblz4_LIBS} ${liblzma_LIBS}
${liblz4_LIBS} ${liblzma_LIBS} ${zlib_LIBS} ${libdeflate_LIBS}
endif
2 changes: 1 addition & 1 deletion fuse/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ erofsfuse_SOURCES = main.c
erofsfuse_CFLAGS = -Wall -I$(top_srcdir)/include
erofsfuse_CFLAGS += -DFUSE_USE_VERSION=26 ${libfuse_CFLAGS} ${libselinux_CFLAGS}
erofsfuse_LDADD = $(top_builddir)/lib/liberofs.la ${libfuse_LIBS} ${liblz4_LIBS} \
${libselinux_LIBS} ${liblzma_LIBS}
${libselinux_LIBS} ${liblzma_LIBS} ${zlib_LIBS} ${libdeflate_LIBS}
4 changes: 3 additions & 1 deletion include/erofs/blobchunk.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@ extern "C"

#include "erofs/internal.h"

struct erofs_blobchunk *erofs_get_unhashed_chunk(erofs_off_t chunksize,
unsigned int device_id, erofs_blk_t blkaddr);
int erofs_blob_write_chunk_indexes(struct erofs_inode *inode, erofs_off_t off);
int erofs_blob_write_chunked_file(struct erofs_inode *inode);
int erofs_blob_write_chunked_file(struct erofs_inode *inode, int fd);
int erofs_blob_remap(void);
void erofs_blob_exit(void);
int erofs_blob_init(const char *blobfile_path);
Expand Down
12 changes: 12 additions & 0 deletions include/erofs/inode.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,23 @@ extern "C"

#include "erofs/internal.h"

static inline struct erofs_inode *erofs_igrab(struct erofs_inode *inode)
{
++inode->i_count;
return inode;
}

u32 erofs_new_encode_dev(dev_t dev);
unsigned char erofs_mode_to_ftype(umode_t mode);
unsigned char erofs_ftype_to_dtype(unsigned int filetype);
void erofs_inode_manager_init(void);
unsigned int erofs_iput(struct erofs_inode *inode);
erofs_nid_t erofs_lookupnid(struct erofs_inode *inode);
struct erofs_dentry *erofs_d_alloc(struct erofs_inode *parent,
const char *name);
int tarerofs_dump_tree(struct erofs_inode *dir);
int erofs_init_empty_dir(struct erofs_inode *dir);
struct erofs_inode *erofs_new_inode(void);
struct erofs_inode *erofs_mkfs_build_tree_from_path(const char *path);
struct erofs_inode *erofs_mkfs_build_special_from_fd(int fd, const char *name);

Expand Down
7 changes: 6 additions & 1 deletion include/erofs/internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ typedef unsigned short umode_t;
#include "erofs_fs.h"
#include <fcntl.h>
#include <sys/types.h> /* for off_t definition */
#include <stdio.h>

#ifndef PATH_MAX
#define PATH_MAX 4096 /* # chars in a path name including nul */
Expand Down Expand Up @@ -170,13 +171,17 @@ struct erofs_inode {
} u;

char *i_srcpath;

union {
char *i_link;
FILE *i_tmpfile;
};
unsigned char datalayout;
unsigned char inode_isize;
/* inline tail-end packing size */
unsigned short idata_size;
bool compressed_idata;
bool lazy_tailblock;
bool with_tmpfile;

unsigned int xattr_isize;
unsigned int extent_isize;
Expand Down
29 changes: 29 additions & 0 deletions include/erofs/tar.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/* SPDX-License-Identifier: GPL-2.0+ OR Apache-2.0 */
#ifndef __EROFS_TAR_H
#define __EROFS_TAR_H

#include <sys/stat.h>

struct erofs_pax_header {
struct stat st;
bool use_mtime;
bool use_size;
bool use_uid;
bool use_gid;
char *path, *link;
};

struct erofs_tarfile {
struct erofs_pax_header global;

int fd;
u64 offset;
bool index_mode, aufs;
};

int tarerofs_init_empty_dir(struct erofs_inode *inode);
int tarerofs_parse_tar(struct erofs_inode *root, struct erofs_tarfile *tar);
int tarerofs_reserve_devtable(unsigned int devices);
int tarerofs_write_devtable(struct erofs_tarfile *tar);

#endif
4 changes: 4 additions & 0 deletions include/erofs/xattr.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ static inline unsigned int xattrblock_offset(unsigned int xattr_id)
#define XATTR_NAME_POSIX_ACL_DEFAULT "system.posix_acl_default"
#endif

int erofs_scan_file_xattrs(struct erofs_inode *inode);
int erofs_prepare_xattr_ibody(struct erofs_inode *inode);
char *erofs_export_xattr_ibody(struct list_head *ixattrs, unsigned int size);
int erofs_build_shared_xattrs_from_path(const char *path);
Expand All @@ -80,6 +81,9 @@ int erofs_xattr_insert_name_prefix(const char *prefix);
void erofs_xattr_cleanup_name_prefixes(void);
int erofs_xattr_write_name_prefixes(FILE *f);

int erofs_setxattr(struct erofs_inode *inode, char *key,
const void *value, size_t size);

#ifdef __cplusplus
}
#endif
Expand Down
7 changes: 7 additions & 0 deletions include/erofs_fs.h
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,7 @@ enum {
enum {
Z_EROFS_COMPRESSION_LZ4 = 0,
Z_EROFS_COMPRESSION_LZMA = 1,
Z_EROFS_COMPRESSION_DEFLATE = 2,
Z_EROFS_COMPRESSION_MAX
};
#define Z_EROFS_ALL_COMPR_ALGS ((1 << Z_EROFS_COMPRESSION_MAX) - 1)
Expand All @@ -317,6 +318,12 @@ struct z_erofs_lzma_cfgs {

#define Z_EROFS_LZMA_MAX_DICT_SIZE (8 * Z_EROFS_PCLUSTER_MAX_SIZE)

/* 6 bytes (+ length field = 8 bytes) */
struct z_erofs_deflate_cfgs {
u8 windowbits; /* 8..15 for DEFLATE */
u8 reserved[5];
} __packed;

/*
* bit 0 : COMPACTED_2B indexes (0 - off; 1 - on)
* e.g. for 4k logical cluster size, 4B if compacted 2B is off;
Expand Down
8 changes: 7 additions & 1 deletion lib/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ noinst_HEADERS = $(top_srcdir)/include/erofs_fs.h \
$(top_srcdir)/include/erofs/io.h \
$(top_srcdir)/include/erofs/list.h \
$(top_srcdir)/include/erofs/print.h \
$(top_srcdir)/include/erofs/tar.h \
$(top_srcdir)/include/erofs/trace.h \
$(top_srcdir)/include/erofs/xattr.h \
$(top_srcdir)/include/erofs/compress_hints.h \
Expand All @@ -29,7 +30,7 @@ noinst_HEADERS += compressor.h
liberofs_la_SOURCES = config.c io.c cache.c super.c inode.c xattr.c exclude.c \
namei.c data.c compress.c compressor.c zmap.c decompress.c \
compress_hints.c hashmap.c sha256.c blobchunk.c dir.c \
fragments.c rb_tree.c dedupe.c uuid_unparse.c uuid.c
fragments.c rb_tree.c dedupe.c uuid_unparse.c uuid.c tar.c

liberofs_la_CFLAGS = -Wall ${libuuid_CFLAGS} -I$(top_srcdir)/include
if ENABLE_LZ4
Expand All @@ -43,3 +44,8 @@ if ENABLE_LIBLZMA
liberofs_la_CFLAGS += ${liblzma_CFLAGS}
liberofs_la_SOURCES += compressor_liblzma.c
endif

liberofs_la_SOURCES += kite_deflate.c compressor_deflate.c
if ENABLE_LIBDEFLATE
liberofs_la_SOURCES += compressor_libdeflate.c
endif
47 changes: 32 additions & 15 deletions lib/blobchunk.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@
#include <unistd.h>

struct erofs_blobchunk {
struct hashmap_entry ent;
union {
struct hashmap_entry ent;
struct list_head list;
};
char sha256[32];
unsigned int device_id;
erofs_off_t chunksize;
Expand All @@ -29,6 +32,23 @@ static struct erofs_buffer_head *bh_devt;
struct erofs_blobchunk erofs_holechunk = {
.blkaddr = EROFS_NULL_ADDR,
};
static LIST_HEAD(unhashed_blobchunks);

struct erofs_blobchunk *erofs_get_unhashed_chunk(erofs_off_t chunksize,
unsigned int device_id, erofs_blk_t blkaddr)
{
struct erofs_blobchunk *chunk;

chunk = calloc(1, sizeof(struct erofs_blobchunk));
if (!chunk)
return ERR_PTR(-ENOMEM);

chunk->chunksize = chunksize;
chunk->device_id = device_id;
chunk->blkaddr = blkaddr;
list_add_tail(&chunk->list, &unhashed_blobchunks);
return chunk;
}

static struct erofs_blobchunk *erofs_blob_getchunk(int fd,
erofs_off_t chunksize)
Expand Down Expand Up @@ -165,17 +185,14 @@ int erofs_blob_write_chunk_indexes(struct erofs_inode *inode,
return dev_write(inode->chunkindexes, off, inode->extent_isize);
}

int erofs_blob_write_chunked_file(struct erofs_inode *inode)
int erofs_blob_write_chunked_file(struct erofs_inode *inode, int fd)
{
unsigned int chunkbits = cfg.c_chunkbits;
unsigned int count, unit;
struct erofs_inode_chunk_index *idx;
erofs_off_t pos, len, chunksize;
int fd, ret;
int ret;

fd = open(inode->i_srcpath, O_RDONLY | O_BINARY);
if (fd < 0)
return -errno;
#ifdef SEEK_DATA
/* if the file is fully sparsed, use one big chunk instead */
if (lseek(fd, 0, SEEK_DATA) < 0 && errno == ENXIO) {
Expand All @@ -199,10 +216,8 @@ int erofs_blob_write_chunked_file(struct erofs_inode *inode)

inode->extent_isize = count * unit;
idx = malloc(count * max(sizeof(*idx), sizeof(void *)));
if (!idx) {
close(fd);
if (!idx)
return -ENOMEM;
}
inode->chunkindexes = idx;

for (pos = 0; pos < inode->i_size; pos += len) {
Expand Down Expand Up @@ -241,10 +256,8 @@ int erofs_blob_write_chunked_file(struct erofs_inode *inode)
*(void **)idx++ = chunk;
}
inode->datalayout = EROFS_INODE_CHUNK_BASED;
close(fd);
return 0;
err:
close(fd);
free(inode->chunkindexes);
inode->chunkindexes = NULL;
return ret;
Expand Down Expand Up @@ -296,19 +309,23 @@ void erofs_blob_exit(void)
{
struct hashmap_iter iter;
struct hashmap_entry *e;
struct erofs_blobchunk *bc, *n;

if (blobfile)
fclose(blobfile);

while ((e = hashmap_iter_first(&blob_hashmap, &iter))) {
struct erofs_blobchunk *bc =
container_of((struct hashmap_entry *)e,
struct erofs_blobchunk, ent);

bc = container_of((struct hashmap_entry *)e,
struct erofs_blobchunk, ent);
DBG_BUGON(hashmap_remove(&blob_hashmap, e) != e);
free(bc);
}
DBG_BUGON(hashmap_free(&blob_hashmap));

list_for_each_entry_safe(bc, n, &unhashed_blobchunks, list) {
list_del(&bc->list);
free(bc);
}
}

int erofs_blob_init(const char *blobfile_path)
Expand Down
Loading

0 comments on commit 78bbd73

Please sign in to comment.