erofs-utils: support calculating checksum of superblock
PATCH v10 1/2 erofs-utils: support calculating checksum of superblock
From: Pratik Shinde <[email protected]>
Added code for calculating crc of superblock.
Note that the first 1024 bytes are not checksummed to allow for the installation of x86 boot sectors and other oddities.
Fill 'feature_compat' field of erofs_super_block so that it can be used on kernel side. also fixing one typo.
---
changes since v9:
- fix a typo found by checkpatch "checksumed" -> "checksummed";
- update commit message since it's now limited to superblock;
- update function name "erofs_superblock_csum_set" -> "erofs_mkfs_superblock_csum_set".
(I'd like to apply this version finally if no more comments...)
include/erofs/internal.h | 1 + include/erofs/io.h | 8 +++++ include/erofs_fs.h | 3 +- lib/io.c | 27 ++++++++++++++++ mkfs/main.c | 69 ++++++++++++++++++++++++++++++++++++++++ 5 files changed, 107 insertions(+), 1 deletion(-)
include/erofs/internal.h +1 -0
@@ -52,6 +52,7 @@ struct erofs_sb_info {erofs_blk_t meta_blkaddr;erofs_blk_t xattr_blkaddr; +u32 feature_compat;u32 feature_incompat;u64 build_time;u32 build_time_nsec;
include/erofs/io.h +8 -0
@@ -19,6 +19,7 @@int dev_open (const char *devname);void dev_close (void );int dev_write (const void *buf,u64 offset,size_t len); +int dev_read (void *buf,u64 offset,size_t len);int dev_fillzero (u64 offset,size_t len,bool padding);int dev_fsync (void );int dev_resize (erofs_blk_t nblocks);
@@ -31,5 +32,12 @@ static inline int blk_write(const void *buf, erofs_blk_t blkaddr, blknr_to_addr(nblocks)); } +static inline int blk_read (void *buf,erofs_blk_t start, +u32 nblocks) +{ +return dev_read (buf,blknr_to_addr (start), +blknr_to_addr (nblocks)); +} +#endif
include/erofs_fs.h +2 -1
@@ -13,6 +13,8 @@#define EROFS_SUPER_MAGIC_V1 0xE0F5E1E2#define EROFS_SUPER_OFFSET 1024 +#define EROFS_FEATURE_COMPAT_SB_CHKSUM 0x00000001 +/* * Any bits that aren't in EROFS_ALL_FEATURE_INCOMPAT should * be incompatible with this kernel version.
@@ -39,7 +41,6 @@ struct erofs_super_block {__u8 uuid[16 ];/* 128-bit uuid for volume */ __u8 volume_name[16 ];/* volume name */ __le32 feature_incompat; -__u8 reserved2[44 ]; };
lib/io.c +27 -0
@@ -207,3 +207,30 @@ int dev_resize(unsigned int blocks)return dev_fillzero (st.st_size, length, true); } +int dev_read (void *buf,u64 offset,size_t len) +{ +int ret; + +if (cfg.c_dry_run) +return 0 ; + +if (!buf) { +erofs_err ("buf is NULL" ); +return -EINVAL ; + } +if (offset >= erofs_devsz || len > erofs_devsz || + offset > erofs_devsz - len) { +erofs_err ("read posion[%" PRIu64", %zd] is too large beyond" +"the end of device(%" PRIu64")." , + offset, len, erofs_devsz); +return -EINVAL ; + } + + ret =pread64 (erofs_devfd, buf, len, (off64_t )offset); +if (ret != (int )len) { +erofs_err ("Failed to read data from device - %s:[%" PRIu64", %zd]." , + erofs_devname, offset, len); +return -errno; + } +return 0 ; +}
mkfs/main.c +69 -0
99 lines not on this page · raw message
Signature · 1 line
2.17.1
PATCH 2/2 erofs-utils: support 128-bit filesystem UUID
Introduce filesystem UUID and a new feature_compat flag to indicate uuid field is available.
--- configure.ac | 18 ++++++++++++++++++ include/erofs/internal.h | 1 + include/erofs_fs.h | 1 + mkfs/Makefile.am | 3 ++- mkfs/main.c | 18 ++++++++++++++++++ 5 files changed, 40 insertions(+), 1 deletion(-)
configure.ac +18 -0
@@ -54,6 +54,10 @@ AC_ARG_ENABLE(lz4, [AS_HELP_STRING([--disable-lz4], [disable LZ4 compression support @<:@default=enabled@:>@])], [enable_lz4="$enableval"], [enable_lz4="yes"]) +AC_ARG_WITH(uuid, + [AS_HELP_STRING([--without-uuid], + [Ignore presence of libuuid and disable uuid support @<:@default=enabled@:>@])]) + # Checks for libraries. # Use customized LZ4 library path when specified. AC_ARG_WITH(lz4-incdir,
@@ -172,6 +176,20 @@ fi AM_CONDITIONAL([ENABLE_LZ4], [test "x${have_lz4}" = "xyes"]) AM_CONDITIONAL([ENABLE_LZ4HC], [test "x${have_lz4hc}" = "xyes"]) +# Configure libuuid +AS_IF([test "x$with_uuid" != "xno"], + [PKG_CHECK_MODULES([libuuid], [uuid], + [have_uuid=yes], [have_uuid=no])], + [have_uuid=no] +) + +AS_IF([test "x$have_uuid" = "xyes"], + [AC_DEFINE([HAVE_LIBUUID], 1, [Define to 1 if libuuid is found])], + [AS_IF([test "x$with_uuid" = "xyes"], + [AC_MSG_ERROR([uuid support requested but libuuid not found])] + )] +) + AC_CONFIG_FILES([Makefile man/Makefile lib/Makefile
include/erofs/internal.h +1 -0
@@ -56,6 +56,7 @@ struct erofs_sb_info {u32 feature_incompat;u64 build_time;u32 build_time_nsec; +u8 uuid[16 ]; };/* global sbi */
include/erofs_fs.h +1 -0
@@ -14,6 +14,7 @@#define EROFS_SUPER_OFFSET 1024#define EROFS_FEATURE_COMPAT_SB_CHKSUM 0x00000001 +#define EROFS_FEATURE_COMPAT_SB_UUID 0x00000002/* * Any bits that aren't in EROFS_ALL_FEATURE_INCOMPAT should
mkfs/Makefile.am +2 -1
@@ -3,7 +3,8 @@ AUTOMAKE_OPTIONS = foreign bin_PROGRAMS = mkfs.erofs +AM_CPPFLAGS = ${libuuid_CFLAGS} mkfs_erofs_SOURCES = main.c mkfs_erofs_CFLAGS = -Wall -Werror -I$(top_srcdir)/include -mkfs_erofs_LDADD = $(top_builddir)/lib/liberofs.la +mkfs_erofs_LDADD = $(top_builddir)/lib/liberofs.la ${libuuid_LIBS}
mkfs/main.c +18 -0
@@ -22,6 +22,10 @@#include "erofs/compress.h" #include "erofs/xattr.h" +#ifdef HAVE_LIBUUID +#include <uuid/uuid.h> +#endif +#define EROFS_SUPER_END (EROFS_SUPER_OFFSET + sizeof(struct erofs_super_block))static struct option long_options[] = {
@@ -234,6 +238,7 @@ int erofs_mkfs_update_super_block(struct erofs_buffer_head *bh, *blocks =erofs_mapbh (NULL , true); sb.blocks =cpu_to_le32 (*blocks); sb.root_nid =cpu_to_le16 (root_nid); +memcpy (sb.uuid, sbi.uuid,sizeof (sb.uuid)); buf =calloc (sb_blksize,1 );if (!buf) {
@@ -305,6 +310,18 @@ static int erofs_mkfs_superblock_csum_set(void)return 0 ; } +static void erofs_mkfs_generate_uuid (void ) +{ +char uuid_str[37 ] ="not available" ; + +#ifdef HAVE_LIBUUID +uuid_generate (sbi.uuid); +uuid_unparse_lower (sbi.uuid, uuid_str); + sbi.feature_compat |=EROFS_FEATURE_COMPAT_SB_UUID ; +#endif +erofs_info ("filesystem UUID: %s" , uuid_str); +} +int main (int argc,char **argv) {int err =0 ;
@@ -376,6 +393,7 @@ int main(int argc, char **argv) goto exit; } +erofs_mkfs_generate_uuid ();erofs_inode_manager_init (); err =erofs_build_shared_xattrs_from_path (cfg.c_src_path);
Signature · 1 line
2.17.1
PATCH v2 1/1 erofs-utils: support 128-bit filesystem UUID
Complete filesystem UUID feature on userspace side.
---
changes since v1:
- drop feature_compat since kernel side can already parse UUID from erofs superblock.
configure.ac | 18 ++++++++++++++++++ include/erofs/internal.h | 1 + mkfs/Makefile.am | 3 ++- mkfs/main.c | 20 ++++++++++++++++++++ 4 files changed, 41 insertions(+), 1 deletion(-)
configure.ac +18 -0
@@ -54,6 +54,10 @@ AC_ARG_ENABLE(lz4, [AS_HELP_STRING([--disable-lz4], [disable LZ4 compression support @<:@default=enabled@:>@])], [enable_lz4="$enableval"], [enable_lz4="yes"]) +AC_ARG_WITH(uuid, + [AS_HELP_STRING([--without-uuid], + [Ignore presence of libuuid and disable uuid support @<:@default=enabled@:>@])]) + # Checks for libraries. # Use customized LZ4 library path when specified. AC_ARG_WITH(lz4-incdir,
@@ -172,6 +176,20 @@ fi AM_CONDITIONAL([ENABLE_LZ4], [test "x${have_lz4}" = "xyes"]) AM_CONDITIONAL([ENABLE_LZ4HC], [test "x${have_lz4hc}" = "xyes"]) +# Configure libuuid +AS_IF([test "x$with_uuid" != "xno"], + [PKG_CHECK_MODULES([libuuid], [uuid], + [have_uuid=yes], [have_uuid=no])], + [have_uuid=no] +) + +AS_IF([test "x$have_uuid" = "xyes"], + [AC_DEFINE([HAVE_LIBUUID], 1, [Define to 1 if libuuid is found])], + [AS_IF([test "x$with_uuid" = "xyes"], + [AC_MSG_ERROR([uuid support requested but libuuid not found])] + )] +) + AC_CONFIG_FILES([Makefile man/Makefile lib/Makefile
include/erofs/internal.h +1 -0
@@ -56,6 +56,7 @@ struct erofs_sb_info {u32 feature_incompat;u64 build_time;u32 build_time_nsec; +u8 uuid[16 ]; };/* global sbi */
mkfs/Makefile.am +2 -1
@@ -3,7 +3,8 @@ AUTOMAKE_OPTIONS = foreign bin_PROGRAMS = mkfs.erofs +AM_CPPFLAGS = ${libuuid_CFLAGS} mkfs_erofs_SOURCES = main.c mkfs_erofs_CFLAGS = -Wall -Werror -I$(top_srcdir)/include -mkfs_erofs_LDADD = $(top_builddir)/lib/liberofs.la +mkfs_erofs_LDADD = $(top_builddir)/lib/liberofs.la ${libuuid_LIBS}
mkfs/main.c +20 -0
@@ -22,6 +22,10 @@#include "erofs/compress.h" #include "erofs/xattr.h" +#ifdef HAVE_LIBUUID +#include <uuid/uuid.h> +#endif +#define EROFS_SUPER_END (EROFS_SUPER_OFFSET + sizeof(struct erofs_super_block))static struct option long_options[] = {
@@ -234,6 +238,7 @@ int erofs_mkfs_update_super_block(struct erofs_buffer_head *bh, *blocks =erofs_mapbh (NULL , true); sb.blocks =cpu_to_le32 (*blocks); sb.root_nid =cpu_to_le16 (root_nid); +memcpy (sb.uuid, sbi.uuid,sizeof (sb.uuid)); buf =calloc (sb_blksize,1 );if (!buf) {
@@ -305,6 +310,20 @@ static int erofs_mkfs_superblock_csum_set(void)return 0 ; } +static void erofs_mkfs_generate_uuid (void ) +{ +char uuid_str[37 ] ="not available" ; + +#ifdef HAVE_LIBUUID +do { +uuid_generate (sbi.uuid); + }while (uuid_is_null (sbi.uuid)); + +uuid_unparse_lower (sbi.uuid, uuid_str); +#endif +erofs_info ("filesystem UUID: %s" , uuid_str); +} +int main (int argc,char **argv) {int err =0 ;
@@ -376,6 +395,7 @@ int main(int argc, char **argv) goto exit; } +erofs_mkfs_generate_uuid ();erofs_inode_manager_init (); err =erofs_build_shared_xattrs_from_path (cfg.c_src_path);
Signature · 1 line
2.17.1
PATCH v3 1/1 erofs-utils: support 128-bit filesystem UUID
Complete filesystem UUID feature on userspace side.
---
changes since v2:
- fix multilib false positive reported by erofs-utils-ci #83
https://travis-ci.org/erofs/erofs-utils-ci/builds/609603134
- test presence of pkg-config in advance.
configure.ac | 33 +++++++++++++++++++++++++++++++++ include/erofs/internal.h | 1 + mkfs/Makefile.am | 3 ++- mkfs/main.c | 20 ++++++++++++++++++++ 4 files changed, 56 insertions(+), 1 deletion(-)
configure.ac +33 -0
@@ -20,6 +20,15 @@ AC_PROG_INSTALL LT_INIT +# Test presence of pkg-config +AC_MSG_CHECKING([pkg-config m4 macros]) +if test m4_ifdef([PKG_CHECK_MODULES], [yes], [no]) = "yes"; then + AC_MSG_RESULT([yes]); +else + AC_MSG_RESULT([no]); + AC_MSG_ERROR([pkg-config is required. See pkg-config.freedesktop.org]) +fi + dnl EROFS_UTILS_PARSE_DIRECTORY dnl Input: $1 = a string to a relative or absolute directory dnl Output: $2 = the variable to set with the absolute directory
@@ -54,6 +63,10 @@ AC_ARG_ENABLE(lz4, [AS_HELP_STRING([--disable-lz4], [disable LZ4 compression support @<:@default=enabled@:>@])], [enable_lz4="$enableval"], [enable_lz4="yes"]) +AC_ARG_WITH(uuid, + [AS_HELP_STRING([--without-uuid], + [Ignore presence of libuuid and disable uuid support @<:@default=enabled@:>@])]) + # Checks for libraries. # Use customized LZ4 library path when specified. AC_ARG_WITH(lz4-incdir,
@@ -123,6 +136,19 @@ AC_CHECK_DECL(lseek64,[AC_DEFINE(HAVE_LSEEK64_PROTOTYPE, 1, # Checks for library functions. AC_CHECK_FUNCS([fallocate gettimeofday memset realpath strdup strerror strrchr strtoull]) +# Configure libuuid +AS_IF([test "x$with_uuid" != "xno"], [ + PKG_CHECK_MODULES([libuuid], [uuid]) + # Paranoia: don't trust the result reported by pkgconfig before trying out + saved_LIBS="$LIBS" + LIBS="${libuuid_LIBS} $LIBS" + AC_TRY_LINK([ +#include <uuid.h> +], [ +return uuid_generate(); +], [have_uuid=yes], [have_uuid=no]) + LIBS="${saved_LIBS}"], [have_uuid=no]) + # Configure lz4 test -z $LZ4_LIBS && LZ4_LIBS='-llz4'
@@ -169,6 +195,13 @@ if test "x$enable_lz4" = "xyes"; then CFLAGS=${saved_CPPFLAGS} fi +AS_IF([test "x$have_uuid" = "xyes"], + [AC_DEFINE([HAVE_LIBUUID], 1, [Define to 1 if libuuid is found])], + [AS_IF([test "x$with_uuid" = "xyes"], + [AC_MSG_ERROR([uuid support requested but libuuid not found])] + )] +) + AM_CONDITIONAL([ENABLE_LZ4], [test "x${have_lz4}" = "xyes"]) AM_CONDITIONAL([ENABLE_LZ4HC], [test "x${have_lz4hc}" = "xyes"])
include/erofs/internal.h +1 -0
@@ -56,6 +56,7 @@ struct erofs_sb_info {u32 feature_incompat;u64 build_time;u32 build_time_nsec; +u8 uuid[16 ]; };/* global sbi */
mkfs/Makefile.am +2 -1
@@ -3,7 +3,8 @@ AUTOMAKE_OPTIONS = foreign bin_PROGRAMS = mkfs.erofs +AM_CPPFLAGS = ${libuuid_CFLAGS} mkfs_erofs_SOURCES = main.c mkfs_erofs_CFLAGS = -Wall -Werror -I$(top_srcdir)/include -mkfs_erofs_LDADD = $(top_builddir)/lib/liberofs.la +mkfs_erofs_LDADD = $(top_builddir)/lib/liberofs.la ${libuuid_LIBS}
mkfs/main.c +20 -0
@@ -22,6 +22,10 @@#include "erofs/compress.h" #include "erofs/xattr.h" +#ifdef HAVE_LIBUUID +#include <uuid/uuid.h> +#endif +#define EROFS_SUPER_END (EROFS_SUPER_OFFSET + sizeof(struct erofs_super_block))static struct option long_options[] = {
@@ -234,6 +238,7 @@ int erofs_mkfs_update_super_block(struct erofs_buffer_head *bh, *blocks =erofs_mapbh (NULL , true); sb.blocks =cpu_to_le32 (*blocks); sb.root_nid =cpu_to_le16 (root_nid); +memcpy (sb.uuid, sbi.uuid,sizeof (sb.uuid)); buf =calloc (sb_blksize,1 );if (!buf) {
@@ -305,6 +310,20 @@ static int erofs_mkfs_superblock_csum_set(void)return 0 ; } +static void erofs_mkfs_generate_uuid (void ) +{ +char uuid_str[37 ] ="not available" ; + +#ifdef HAVE_LIBUUID +do { +uuid_generate (sbi.uuid); + }while (uuid_is_null (sbi.uuid)); + +uuid_unparse_lower (sbi.uuid, uuid_str); +#endif +erofs_info ("filesystem UUID: %s" , uuid_str); +} +int main (int argc,char **argv) {int err =0 ;
@@ -376,6 +395,7 @@ int main(int argc, char **argv) goto exit; } +erofs_mkfs_generate_uuid ();erofs_inode_manager_init (); err =erofs_build_shared_xattrs_from_path (cfg.c_src_path);
Signature · 1 line
2.17.1
PATCH v4 1/1 erofs-utils: support 128-bit filesystem UUID
Complete filesystem UUID feature on userspace side.
---
changes since v3:
- fix configure.ac script and fully passed travis CI
https://travis-ci.org/erofs/erofs-utils-ci/builds/611213382
configure.ac | 41 ++++++++++++++++++++++++++++++++++++++++ include/erofs/internal.h | 1 + mkfs/Makefile.am | 3 ++- mkfs/main.c | 20 ++++++++++++++++++++ 4 files changed, 64 insertions(+), 1 deletion(-)
configure.ac +41 -0
@@ -20,6 +20,15 @@ AC_PROG_INSTALL LT_INIT +# Test presence of pkg-config +AC_MSG_CHECKING([pkg-config m4 macros]) +if test m4_ifdef([PKG_CHECK_MODULES], [yes], [no]) = "yes"; then + AC_MSG_RESULT([yes]); +else + AC_MSG_RESULT([no]); + AC_MSG_ERROR([pkg-config is required. See pkg-config.freedesktop.org]) +fi + dnl EROFS_UTILS_PARSE_DIRECTORY dnl Input: $1 = a string to a relative or absolute directory dnl Output: $2 = the variable to set with the absolute directory
@@ -54,6 +63,10 @@ AC_ARG_ENABLE(lz4, [AS_HELP_STRING([--disable-lz4], [disable LZ4 compression support @<:@default=enabled@:>@])], [enable_lz4="$enableval"], [enable_lz4="yes"]) +AC_ARG_WITH(uuid, + [AS_HELP_STRING([--without-uuid], + [Ignore presence of libuuid and disable uuid support @<:@default=enabled@:>@])]) + # Checks for libraries. # Use customized LZ4 library path when specified. AC_ARG_WITH(lz4-incdir,
@@ -123,6 +136,30 @@ AC_CHECK_DECL(lseek64,[AC_DEFINE(HAVE_LSEEK64_PROTOTYPE, 1, # Checks for library functions. AC_CHECK_FUNCS([fallocate gettimeofday memset realpath strdup strerror strrchr strtoull]) +# Configure libuuid +AS_IF([test "x$with_uuid" != "xno"], [ + PKG_CHECK_MODULES([libuuid], [uuid]) + # Paranoia: don't trust the result reported by pkgconfig before trying out + saved_LIBS="$LIBS" + saved_CPPFLAGS=${CPPFLAGS} + CPPFLAGS="${libuuid_CFLAGS} ${CPPFLAGS}" + LIBS="${libuuid_LIBS} $LIBS" + AC_MSG_CHECKING([libuuid usability]) + AC_TRY_LINK([ +#include <uuid.h> +], [ +uuid_t tmp; + +uuid_generate(tmp); +return 0; +], [have_uuid="yes" + AC_MSG_RESULT([yes])], [ + have_uuid="no" + AC_MSG_RESULT([no]) + AC_MSG_ERROR([libuuid doesn't work properly])]) + LIBS="${saved_LIBS}" + CPPFLAGS="${saved_CPPFLAGS}"], [have_uuid="no"]) + # Configure lz4 test -z $LZ4_LIBS && LZ4_LIBS='-llz4'
@@ -169,6 +206,10 @@ if test "x$enable_lz4" = "xyes"; then CFLAGS=${saved_CPPFLAGS} fi +if test "x$have_uuid" = "xyes"; then + AC_DEFINE([HAVE_LIBUUID], 1, [Define to 1 if libuuid is found]) +fi + AM_CONDITIONAL([ENABLE_LZ4], [test "x${have_lz4}" = "xyes"]) AM_CONDITIONAL([ENABLE_LZ4HC], [test "x${have_lz4hc}" = "xyes"])
include/erofs/internal.h +1 -0
@@ -56,6 +56,7 @@ struct erofs_sb_info {u32 feature_incompat;u64 build_time;u32 build_time_nsec; +u8 uuid[16 ]; };/* global sbi */
mkfs/Makefile.am +2 -1
@@ -3,7 +3,8 @@ AUTOMAKE_OPTIONS = foreign bin_PROGRAMS = mkfs.erofs +AM_CPPFLAGS = ${libuuid_CFLAGS} mkfs_erofs_SOURCES = main.c mkfs_erofs_CFLAGS = -Wall -Werror -I$(top_srcdir)/include -mkfs_erofs_LDADD = $(top_builddir)/lib/liberofs.la +mkfs_erofs_LDADD = $(top_builddir)/lib/liberofs.la ${libuuid_LIBS}
mkfs/main.c +20 -0
@@ -22,6 +22,10 @@#include "erofs/compress.h" #include "erofs/xattr.h" +#ifdef HAVE_LIBUUID +#include <uuid/uuid.h> +#endif +#define EROFS_SUPER_END (EROFS_SUPER_OFFSET + sizeof(struct erofs_super_block))static struct option long_options[] = {
@@ -234,6 +238,7 @@ int erofs_mkfs_update_super_block(struct erofs_buffer_head *bh, *blocks =erofs_mapbh (NULL , true); sb.blocks =cpu_to_le32 (*blocks); sb.root_nid =cpu_to_le16 (root_nid); +memcpy (sb.uuid, sbi.uuid,sizeof (sb.uuid)); buf =calloc (sb_blksize,1 );if (!buf) {
@@ -305,6 +310,20 @@ static int erofs_mkfs_superblock_csum_set(void)return 0 ; } +static void erofs_mkfs_generate_uuid (void ) +{ +char uuid_str[37 ] ="not available" ; + +#ifdef HAVE_LIBUUID +do { +uuid_generate (sbi.uuid); + }while (uuid_is_null (sbi.uuid)); + +uuid_unparse_lower (sbi.uuid, uuid_str); +#endif +erofs_info ("filesystem UUID: %s" , uuid_str); +} +int main (int argc,char **argv) {int err =0 ;
@@ -376,6 +395,7 @@ int main(int argc, char **argv) goto exit; } +erofs_mkfs_generate_uuid ();erofs_inode_manager_init (); err =erofs_build_shared_xattrs_from_path (cfg.c_src_path);
Signature · 1 line
2.17.1
Re: [PATCH v4] erofs-utils: support 128-bit filesystem UUID
Quoted 6 lines · Gao Xiang
Complete filesystem UUID feature on userspace side.
Cc Chao Yu <[email protected]>Cc Li Guifu <[email protected]>Signed-off-by Gao Xiang <[email protected]>---
It looks good
Thanks,