[PATCH v2] util-linux: support erofs filesystem

Denys Vlasenko vda.linux at googlemail.com
Wed Nov 18 18:20:00 UTC 2020


Applied, thank you.

On Mon, Jul 13, 2020 at 5:22 PM Norbert Lange <nolange79 at gmail.com> wrote:
>
> Add erofs to the known volume_ids.
>
> Signed-off-by: Norbert Lange <nolange79 at gmail.com>
> ---
>  util-linux/volume_id/erofs.c              | 71 +++++++++++++++++++++++
>  util-linux/volume_id/volume_id.c          |  3 +
>  util-linux/volume_id/volume_id_internal.h |  2 +
>  3 files changed, 76 insertions(+)
>  create mode 100644 util-linux/volume_id/erofs.c
>
> diff --git a/util-linux/volume_id/erofs.c b/util-linux/volume_id/erofs.c
> new file mode 100644
> index 000000000..6007221ee
> --- /dev/null
> +++ b/util-linux/volume_id/erofs.c
> @@ -0,0 +1,71 @@
> +/*
> + * volume_id - reads filesystem label and uuid
> + *
> + * Copyright (C) 2020 Norbert Lange <nolange79 at gmail.com>
> + *
> + * Licensed under GPLv2, see file LICENSE in this source tree.
> + */
> +//config:config FEATURE_VOLUMEID_EROFS
> +//config:      bool "erofs filesystem"
> +//config:      default y
> +//config:      depends on VOLUMEID
> +//config:      help
> +//config:      Erofs is a compressed-friendly, readonly filesystem for Linux.
> +//config:      Erofs leverages fixed-sized output compression and
> +//config:      memory-efficient decompression to achieve high performance
> +//config:      with little extra memory overhead.
> +
> +//kbuild:lib-$(CONFIG_FEATURE_VOLUMEID_EROFS) += erofs.o
> +
> +#include "volume_id_internal.h"
> +
> +#define EROFS_SUPER_MAGIC_V1    0xE0F5E1E2
> +#define EROFS_SUPER_OFFSET      1024
> +#define EROFS_FEATURE_COMPAT_SB_CHKSUM         0x00000001
> +
> +/* 128-byte erofs on-disk super block */
> +struct erofs_super_block {
> +       uint32_t magic;           /* file system magic number */
> +       uint32_t checksum;        /* crc32c(super_block) */
> +       uint32_t feature_compat;
> +       uint8_t blkszbits;         /* support block_size == PAGE_SIZE only */
> +       uint8_t reserved;
> +
> +       uint16_t root_nid;      /* nid of root directory */
> +       uint64_t inos;            /* total valid ino # (== f_files - f_favail) */
> +
> +       uint64_t build_time;      /* inode v1 time derivation */
> +       uint32_t build_time_nsec;       /* inode v1 time derivation in nano scale */
> +       uint32_t blocks;          /* used for statfs */
> +       uint32_t meta_blkaddr;  /* start block address of metadata area */
> +       uint32_t xattr_blkaddr; /* start block address of shared xattr area */
> +       uint8_t uuid[16];          /* 128-bit uuid for volume */
> +       uint8_t volume_name[16];   /* volume name */
> +       uint32_t feature_incompat;
> +       uint8_t reserved2[44];
> +} PACKED;
> +
> +UNUSED_PARAM typedef char _static_assert_erofs_sb[sizeof(struct erofs_super_block) == 128 ? 1 : -1];
> +
> +
> +int FAST_FUNC volume_id_probe_erofs(struct volume_id *id /*,uint64_t off*/)
> +{
> +       struct erofs_super_block *sb;
> +
> +       dbg("erofs: probing at offset 0x%llx", EROFS_SUPER_OFFSET);
> +       sb = volume_id_get_buffer(id, EROFS_SUPER_OFFSET, sizeof(*sb));
> +       if (!sb)
> +               return -1;
> +
> +       if (sb->magic != cpu_to_le32(EROFS_SUPER_MAGIC_V1))
> +               return -1;
> +
> +       IF_FEATURE_BLKID_TYPE(id->type = "erofs");
> +
> +       volume_id_set_label_string(id, sb->volume_name,
> +               MIN(sizeof(sb->volume_name), VOLUME_ID_LABEL_SIZE));
> +
> +       volume_id_set_uuid(id, sb->uuid, UUID_DCE);
> +
> +       return 0;
> +}
> diff --git a/util-linux/volume_id/volume_id.c b/util-linux/volume_id/volume_id.c
> index c3f07a741..99150a5b7 100644
> --- a/util-linux/volume_id/volume_id.c
> +++ b/util-linux/volume_id/volume_id.c
> @@ -106,6 +106,9 @@ static const probe_fptr fs1[] = {
>  #if ENABLE_FEATURE_VOLUMEID_SQUASHFS
>         volume_id_probe_squashfs,
>  #endif
> +#if ENABLE_FEATURE_VOLUMEID_EROFS
> +       volume_id_probe_erofs,
> +#endif
>  #if ENABLE_FEATURE_VOLUMEID_XFS
>         volume_id_probe_xfs,
>  #endif
> diff --git a/util-linux/volume_id/volume_id_internal.h b/util-linux/volume_id/volume_id_internal.h
> index ada18339d..609beb84e 100644
> --- a/util-linux/volume_id/volume_id_internal.h
> +++ b/util-linux/volume_id/volume_id_internal.h
> @@ -215,6 +215,8 @@ int FAST_FUNC volume_id_probe_romfs(struct volume_id *id /*,uint64_t off*/);
>
>  int FAST_FUNC volume_id_probe_squashfs(struct volume_id *id /*,uint64_t off*/);
>
> +int FAST_FUNC volume_id_probe_erofs(struct volume_id *id /*,uint64_t off*/);
> +
>  int FAST_FUNC volume_id_probe_sysv(struct volume_id *id /*,uint64_t off*/);
>
>  int FAST_FUNC volume_id_probe_udf(struct volume_id *id /*,uint64_t off*/);
> --
> 2.27.0
>
> _______________________________________________
> busybox mailing list
> busybox at busybox.net
> http://lists.busybox.net/mailman/listinfo/busybox


More information about the busybox mailing list