Linux-EROFS Archive on lore.kernel.org
 help / color / Atom feed
* [PATCH 1/3] erofs-utils: complete special file support
       [not found] <20190917054913.24187-1-hsiangkao.ref@aol.com>
@ 2019-09-17  5:49 ` Gao Xiang via Linux-erofs
  2019-09-17  5:49   ` [PATCH 2/3] erofs-utils: resize image to the correct size Gao Xiang via Linux-erofs
                     ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Gao Xiang via Linux-erofs @ 2019-09-17  5:49 UTC (permalink / raw)
  To: linux-erofs, bluce.liguifu, miaoxie, fangwei1

From: Gao Xiang <gaoxiang25@huawei.com>

Special file was already supported by obsoleted_mkfs,
let's complete it for new erofs-utils now.

Signed-off-by: Gao Xiang <gaoxiang25@huawei.com>
---

Hi Guifu,
Could you kindly take a look of these patches?

Thanks,
Gao Xiang

 configure.ac |  1 +
 lib/inode.c  | 34 ++++++++++++++++++++++++++++++----
 2 files changed, 31 insertions(+), 4 deletions(-)

diff --git a/configure.ac b/configure.ac
index fcdf30a..07e034e 100644
--- a/configure.ac
+++ b/configure.ac
@@ -82,6 +82,7 @@ AC_CHECK_HEADERS(m4_flatten([
 	string.h
 	sys/ioctl.h
 	sys/stat.h
+	sys/sysmacros.h
 	sys/time.h
 	unistd.h
 ]))
diff --git a/lib/inode.c b/lib/inode.c
index e3495f4..c8cf847 100644
--- a/lib/inode.c
+++ b/lib/inode.c
@@ -12,6 +12,7 @@
 #include <stdlib.h>
 #include <stdio.h>
 #include <sys/stat.h>
+#include <sys/sysmacros.h>
 #include <dirent.h>
 #include "erofs/print.h"
 #include "erofs/inode.h"
@@ -128,7 +129,6 @@ static int __allocate_inode_bh_data(struct erofs_inode *inode,
 	int ret;
 
 	if (!nblocks) {
-		inode->bh_data = NULL;
 		/* it has only tail-end inlined data */
 		inode->u.i_blkaddr = NULL_ADDR;
 		return 0;
@@ -302,6 +302,11 @@ int erofs_write_file(struct erofs_inode *inode)
 	unsigned int nblocks, i;
 	int ret, fd;
 
+	if (!inode->i_size) {
+		inode->data_mapping_mode = EROFS_INODE_FLAT_PLAIN;
+		return 0;
+	}
+
 	if (cfg.c_compr_alg_master && erofs_file_is_compressible(inode)) {
 		ret = erofs_write_compressed_file(inode);
 
@@ -573,6 +578,14 @@ out:
 	return 0;
 }
 
+static u32 erofs_new_encode_dev(dev_t dev)
+{
+	const unsigned int major = major(dev);
+	const unsigned int minor = minor(dev);
+
+	return (minor & 0xff) | (major << 8) | ((minor & ~0xff) << 12);
+}
+
 int erofs_fill_inode(struct erofs_inode *inode,
 		     struct stat64 *st,
 		     const char *path)
@@ -582,10 +595,22 @@ int erofs_fill_inode(struct erofs_inode *inode,
 	inode->i_gid = st->st_gid;
 	inode->i_nlink = 1;	/* fix up later if needed */
 
-	if (!S_ISDIR(inode->i_mode))
-		inode->i_size = st->st_size;
-	else
+	switch (inode->i_mode & S_IFMT) {
+	case S_IFCHR:
+	case S_IFBLK:
+	case S_IFIFO:
+	case S_IFSOCK:
+		inode->u.i_rdev = erofs_new_encode_dev(st->st_rdev);
+	case S_IFDIR:
 		inode->i_size = 0;
+		break;
+	case S_IFREG:
+	case S_IFLNK:
+		inode->i_size = st->st_size;
+		break;
+	default:
+		return -EINVAL;
+	}
 
 	strncpy(inode->i_srcpath, path, sizeof(inode->i_srcpath) - 1);
 	inode->i_srcpath[sizeof(inode->i_srcpath) - 1] = '\0';
@@ -613,6 +638,7 @@ struct erofs_inode *erofs_new_inode(void)
 	inode->i_count = 1;
 
 	init_list_head(&inode->i_subdirs);
+	inode->idata_size = 0;
 	inode->xattr_isize = 0;
 	inode->extent_isize = 0;
 
-- 
2.17.1


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH 2/3] erofs-utils: resize image to the correct size
  2019-09-17  5:49 ` [PATCH 1/3] erofs-utils: complete special file support Gao Xiang via Linux-erofs
@ 2019-09-17  5:49   ` Gao Xiang via Linux-erofs
  2019-09-17 15:15     ` Li Guifu
  2019-09-17  5:49   ` [PATCH 3/3] erofs-utils: keep up with in-kernel ondisk format naming Gao Xiang via Linux-erofs
  2019-09-17 15:15   ` [PATCH 1/3] erofs-utils: complete special file support Li Guifu
  2 siblings, 1 reply; 6+ messages in thread
From: Gao Xiang via Linux-erofs @ 2019-09-17  5:49 UTC (permalink / raw)
  To: linux-erofs, bluce.liguifu, miaoxie, fangwei1

From: Gao Xiang <gaoxiang25@huawei.com>

In the end, it's necessary to resize image to
the proper size since buffers could be dropped.

Signed-off-by: Gao Xiang <gaoxiang25@huawei.com>
---
 include/erofs/io.h |  1 +
 lib/io.c           | 32 +++++++++++++++++++++++++++++++-
 mkfs/main.c        | 11 ++++++++---
 3 files changed, 40 insertions(+), 4 deletions(-)

diff --git a/include/erofs/io.h b/include/erofs/io.h
index 4b574bd..9775047 100644
--- a/include/erofs/io.h
+++ b/include/erofs/io.h
@@ -21,6 +21,7 @@ void dev_close(void);
 int dev_write(const 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);
 u64 dev_length(void);
 
 static inline int blk_write(const void *buf, erofs_blk_t blkaddr,
diff --git a/lib/io.c b/lib/io.c
index 15c5a35..7f5f94d 100644
--- a/lib/io.c
+++ b/lib/io.c
@@ -79,6 +79,7 @@ int dev_open(const char *dev)
 			close(fd);
 			return ret;
 		}
+		erofs_devsz = round_down(erofs_devsz, EROFS_BLKSIZ);
 		break;
 	case S_IFREG:
 		ret = ftruncate(fd, 0);
@@ -98,7 +99,6 @@ int dev_open(const char *dev)
 
 	erofs_devname = dev;
 	erofs_devfd = fd;
-	erofs_devsz = round_down(erofs_devsz, EROFS_BLKSIZ);
 
 	erofs_info("successfully to open %s", dev);
 	return 0;
@@ -177,3 +177,33 @@ int dev_fsync(void)
 	}
 	return 0;
 }
+
+int dev_resize(unsigned int blocks)
+{
+	int ret;
+	struct stat st;
+	u64 length;
+
+	if (cfg.c_dry_run || erofs_devsz != INT64_MAX)
+		return 0;
+
+	ret = fstat(erofs_devfd, &st);
+	if (ret) {
+		erofs_err("failed to fstat.");
+		return -errno;
+	}
+
+	length = (u64)blocks * EROFS_BLKSIZ;
+	if (st.st_size == length)
+		return 0;
+	if (st.st_size > length)
+		return ftruncate(erofs_devfd, length);
+
+	length = length - st.st_size;
+#if defined(HAVE_FALLOCATE)
+	if (fallocate(erofs_devfd, 0, st.st_size, length) >= 0)
+		return 0;
+#endif
+	return dev_fillzero(st.st_size, length, true);
+}
+
diff --git a/mkfs/main.c b/mkfs/main.c
index 5efbf30..2dfd68e 100644
--- a/mkfs/main.c
+++ b/mkfs/main.c
@@ -145,7 +145,8 @@ static int mkfs_parse_options_cfg(int argc, char *argv[])
 }
 
 int erofs_mkfs_update_super_block(struct erofs_buffer_head *bh,
-				  erofs_nid_t root_nid)
+				  erofs_nid_t root_nid,
+				  erofs_blk_t *blocks)
 {
 	struct erofs_super_block sb = {
 		.magic     = cpu_to_le32(EROFS_SUPER_MAGIC_V1),
@@ -166,7 +167,8 @@ int erofs_mkfs_update_super_block(struct erofs_buffer_head *bh,
 		sb.build_time_nsec = cpu_to_le32(t.tv_usec);
 	}
 
-	sb.blocks       = cpu_to_le32(erofs_mapbh(NULL, true));
+	*blocks         = erofs_mapbh(NULL, true);
+	sb.blocks       = cpu_to_le32(*blocks);
 	sb.root_nid     = cpu_to_le16(root_nid);
 
 	buf = calloc(sb_blksize, 1);
@@ -189,6 +191,7 @@ int main(int argc, char **argv)
 	struct erofs_inode *root_inode;
 	erofs_nid_t root_nid;
 	struct stat64 st;
+	erofs_blk_t nblocks;
 
 	erofs_init_configure();
 	fprintf(stderr, "%s %s\n", basename(argv[0]), cfg.c_version);
@@ -250,13 +253,15 @@ int main(int argc, char **argv)
 	root_nid = erofs_lookupnid(root_inode);
 	erofs_iput(root_inode);
 
-	err = erofs_mkfs_update_super_block(sb_bh, root_nid);
+	err = erofs_mkfs_update_super_block(sb_bh, root_nid, &nblocks);
 	if (err)
 		goto exit;
 
 	/* flush all remaining buffers */
 	if (!erofs_bflush(NULL))
 		err = -EIO;
+	else
+		err = dev_resize(nblocks);
 exit:
 	z_erofs_compress_exit();
 	dev_close();
-- 
2.17.1


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH 3/3] erofs-utils: keep up with in-kernel ondisk format naming
  2019-09-17  5:49 ` [PATCH 1/3] erofs-utils: complete special file support Gao Xiang via Linux-erofs
  2019-09-17  5:49   ` [PATCH 2/3] erofs-utils: resize image to the correct size Gao Xiang via Linux-erofs
@ 2019-09-17  5:49   ` Gao Xiang via Linux-erofs
  2019-09-17 15:15     ` Li Guifu
  2019-09-17 15:15   ` [PATCH 1/3] erofs-utils: complete special file support Li Guifu
  2 siblings, 1 reply; 6+ messages in thread
From: Gao Xiang via Linux-erofs @ 2019-09-17  5:49 UTC (permalink / raw)
  To: linux-erofs, bluce.liguifu, miaoxie, fangwei1

From: Gao Xiang <gaoxiang25@huawei.com>

This patch adapts erofs-utils to the latest kernel ondisk definitions,
especially the following kernel commits:

4b66eb51d2c4 erofs: remove all the byte offset comments
60a49ba8fee1 erofs: on-disk format should have explicitly assigned numbers
b6796abd3cc1 erofs: some macros are much more readable as a function
ed34aa4a8a7d erofs: kill __packed for on-disk structures
c39747f770be erofs: update erofs_inode_is_data_compressed helper
426a930891cf erofs: use feature_incompat rather than requirements
8a76568225de erofs: better naming for erofs inode related stuffs
ea559e7b8451 erofs: update erofs_fs.h comments

Signed-off-by: Gao Xiang <gaoxiang25@huawei.com>
---
 include/erofs/cache.h    |   2 +-
 include/erofs/internal.h |   6 +-
 include/erofs_fs.h       | 198 ++++++++++++++++++++-------------------
 lib/compress.c           |   9 +-
 lib/config.c             |   2 +-
 lib/inode.c              |  42 ++++-----
 mkfs/main.c              |   5 +-
 7 files changed, 137 insertions(+), 127 deletions(-)

diff --git a/include/erofs/cache.h b/include/erofs/cache.h
index 108757a..71df811 100644
--- a/include/erofs/cache.h
+++ b/include/erofs/cache.h
@@ -53,7 +53,7 @@ static inline const int get_alignsize(int type, int *type_ret)
 
 	if (type == INODE) {
 		*type_ret = META;
-		return sizeof(struct erofs_inode_v1);
+		return sizeof(struct erofs_inode_compact);
 	} else if (type == XATTR) {
 		*type_ret = META;
 		return sizeof(struct erofs_xattr_entry);
diff --git a/include/erofs/internal.h b/include/erofs/internal.h
index b7ce6f8..07a32d2 100644
--- a/include/erofs/internal.h
+++ b/include/erofs/internal.h
@@ -52,7 +52,7 @@ struct erofs_sb_info {
 	erofs_blk_t meta_blkaddr;
 	erofs_blk_t xattr_blkaddr;
 
-	u32 requirements;
+	u32 feature_incompat;
 };
 
 /* global sbi */
@@ -82,7 +82,7 @@ struct erofs_inode {
 
 	char i_srcpath[PATH_MAX + 1];
 
-	unsigned char data_mapping_mode;
+	unsigned char datalayout;
 	unsigned char inode_isize;
 	/* inline tail-end packing size */
 	unsigned short idata_size;
@@ -100,7 +100,7 @@ struct erofs_inode {
 
 static inline bool is_inode_layout_compression(struct erofs_inode *inode)
 {
-	return erofs_inode_is_data_compressed(inode->data_mapping_mode);
+	return erofs_inode_is_data_compressed(inode->datalayout);
 }
 
 #define IS_ROOT(x)	((x) == (x)->i_parent)
diff --git a/include/erofs_fs.h b/include/erofs_fs.h
index 601b477..f29aa25 100644
--- a/include/erofs_fs.h
+++ b/include/erofs_fs.h
@@ -1,6 +1,7 @@
 /* SPDX-License-Identifier: GPL-2.0-only OR Apache-2.0 */
 /*
  * erofs_utils/include/erofs_fs.h
+ * EROFS (Enhanced ROM File System) on-disk format definition
  *
  * Copyright (C) 2017-2018 HUAWEI, Inc.
  *             http://www.huawei.com/
@@ -9,41 +10,41 @@
 #ifndef __EROFS_FS_H
 #define __EROFS_FS_H
 
-/* Enhanced(Extended) ROM File System */
 #define EROFS_SUPER_MAGIC_V1    0xE0F5E1E2
 #define EROFS_SUPER_OFFSET      1024
 
 /*
- * Any bits that aren't in EROFS_ALL_REQUIREMENTS should be
- * incompatible with this kernel version.
+ * Any bits that aren't in EROFS_ALL_FEATURE_INCOMPAT should
+ * be incompatible with this kernel version.
  */
-#define EROFS_REQUIREMENT_LZ4_0PADDING	0x00000001
-#define EROFS_ALL_REQUIREMENTS		EROFS_REQUIREMENT_LZ4_0PADDING
+#define EROFS_FEATURE_INCOMPAT_LZ4_0PADDING	0x00000001
+#define EROFS_ALL_FEATURE_INCOMPAT		EROFS_FEATURE_INCOMPAT_LZ4_0PADDING
 
+/* 128-byte erofs on-disk super block */
 struct erofs_super_block {
-/*  0 */__le32 magic;           /* in the little endian */
-/*  4 */__le32 checksum;        /* crc32c(super_block) */
-/*  8 */__le32 features;        /* (aka. feature_compat) */
-/* 12 */__u8 blkszbits;         /* support block_size == PAGE_SIZE only */
-/* 13 */__u8 reserved;
-
-/* 14 */__le16 root_nid;
-/* 16 */__le64 inos;            /* total valid ino # (== f_files - f_favail) */
-
-/* 24 */__le64 build_time;      /* inode v1 time derivation */
-/* 32 */__le32 build_time_nsec;
-/* 36 */__le32 blocks;          /* used for statfs */
-/* 40 */__le32 meta_blkaddr;
-/* 44 */__le32 xattr_blkaddr;
-/* 48 */__u8 uuid[16];          /* 128-bit uuid for volume */
-/* 64 */__u8 volume_name[16];   /* volume name */
-/* 80 */__le32 requirements;    /* (aka. feature_incompat) */
-
-/* 84 */__u8 reserved2[44];
-} __packed;                     /* 128 bytes */
+	__le32 magic;           /* file system magic number */
+	__le32 checksum;        /* crc32c(super_block) */
+	__le32 feature_compat;
+	__u8 blkszbits;         /* support block_size == PAGE_SIZE only */
+	__u8 reserved;
+
+	__le16 root_nid;	/* nid of root directory */
+	__le64 inos;            /* total valid ino # (== f_files - f_favail) */
+
+	__le64 build_time;      /* inode v1 time derivation */
+	__le32 build_time_nsec;	/* inode v1 time derivation in nano scale */
+	__le32 blocks;          /* used for statfs */
+	__le32 meta_blkaddr;	/* start block address of metadata area */
+	__le32 xattr_blkaddr;	/* start block address of shared xattr area */
+	__u8 uuid[16];          /* 128-bit uuid for volume */
+	__u8 volume_name[16];   /* volume name */
+	__le32 feature_incompat;
+
+	__u8 reserved2[44];
+};
 
 /*
- * erofs inode data mapping:
+ * erofs inode datalayout (i_format in on-disk inode):
  * 0 - inode plain without inline data A:
  * inode, [xattrs], ... | ... | no-holed data
  * 1 - inode VLE compression B (legacy):
@@ -55,82 +56,83 @@ struct erofs_super_block {
  * 4~7 - reserved
  */
 enum {
-	EROFS_INODE_FLAT_PLAIN,
-	EROFS_INODE_FLAT_COMPRESSION_LEGACY,
-	EROFS_INODE_FLAT_INLINE,
-	EROFS_INODE_FLAT_COMPRESSION,
-	EROFS_INODE_LAYOUT_MAX
+	EROFS_INODE_FLAT_PLAIN			= 0,
+	EROFS_INODE_FLAT_COMPRESSION_LEGACY	= 1,
+	EROFS_INODE_FLAT_INLINE			= 2,
+	EROFS_INODE_FLAT_COMPRESSION		= 3,
+	EROFS_INODE_DATALAYOUT_MAX
 };
 
 static inline bool erofs_inode_is_data_compressed(unsigned int datamode)
 {
-	if (datamode == EROFS_INODE_FLAT_COMPRESSION)
-		return true;
-	return datamode == EROFS_INODE_FLAT_COMPRESSION_LEGACY;
+	return datamode == EROFS_INODE_FLAT_COMPRESSION ||
+		datamode == EROFS_INODE_FLAT_COMPRESSION_LEGACY;
 }
 
 /* bit definitions of inode i_advise */
 #define EROFS_I_VERSION_BITS            1
-#define EROFS_I_DATA_MAPPING_BITS       3
+#define EROFS_I_DATALAYOUT_BITS         3
 
 #define EROFS_I_VERSION_BIT             0
-#define EROFS_I_DATA_MAPPING_BIT        1
+#define EROFS_I_DATALAYOUT_BIT          1
 
-struct erofs_inode_v1 {
-/*  0 */__le16 i_advise;
+/* 32-byte reduced form of an ondisk inode */
+struct erofs_inode_compact {
+	__le16 i_format;	/* inode format hints */
 
 /* 1 header + n-1 * 4 bytes inline xattr to keep continuity */
-/*  2 */__le16 i_xattr_icount;
-/*  4 */__le16 i_mode;
-/*  6 */__le16 i_nlink;
-/*  8 */__le32 i_size;
-/* 12 */__le32 i_reserved;
-/* 16 */union {
+	__le16 i_xattr_icount;
+	__le16 i_mode;
+	__le16 i_nlink;
+	__le32 i_size;
+	__le32 i_reserved;
+	union {
 		/* file total compressed blocks for data mapping 1 */
 		__le32 compressed_blocks;
 		__le32 raw_blkaddr;
 
 		/* for device files, used to indicate old/new device # */
 		__le32 rdev;
-	} i_u __packed;
-/* 20 */__le32 i_ino;           /* only used for 32-bit stat compatibility */
-/* 24 */__le16 i_uid;
-/* 26 */__le16 i_gid;
-/* 28 */__le32 i_reserved2;
-} __packed;
+	} i_u;
+	__le32 i_ino;           /* only used for 32-bit stat compatibility */
+	__le16 i_uid;
+	__le16 i_gid;
+	__le32 i_reserved2;
+};
 
 /* 32 bytes on-disk inode */
-#define EROFS_INODE_LAYOUT_V1   0
+#define EROFS_INODE_LAYOUT_COMPACT	0
 /* 64 bytes on-disk inode */
-#define EROFS_INODE_LAYOUT_V2   1
+#define EROFS_INODE_LAYOUT_EXTENDED	1
 
-struct erofs_inode_v2 {
-/*  0 */__le16 i_advise;
+/* 64-byte complete form of an ondisk inode */
+struct erofs_inode_extended {
+	__le16 i_format;	/* inode format hints */
 
 /* 1 header + n-1 * 4 bytes inline xattr to keep continuity */
-/*  2 */__le16 i_xattr_icount;
-/*  4 */__le16 i_mode;
-/*  6 */__le16 i_reserved;
-/*  8 */__le64 i_size;
-/* 16 */union {
+	__le16 i_xattr_icount;
+	__le16 i_mode;
+	__le16 i_reserved;
+	__le64 i_size;
+	union {
 		/* file total compressed blocks for data mapping 1 */
 		__le32 compressed_blocks;
 		__le32 raw_blkaddr;
 
 		/* for device files, used to indicate old/new device # */
 		__le32 rdev;
-	} i_u __packed;
+	} i_u;
 
 	/* only used for 32-bit stat compatibility */
-/* 20 */__le32 i_ino;
-
-/* 24 */__le32 i_uid;
-/* 28 */__le32 i_gid;
-/* 32 */__le64 i_ctime;
-/* 40 */__le32 i_ctime_nsec;
-/* 44 */__le32 i_nlink;
-/* 48 */__u8   i_reserved2[16];
-} __packed;                     /* 64 bytes */
+	__le32 i_ino;
+
+	__le32 i_uid;
+	__le32 i_gid;
+	__le64 i_ctime;
+	__le32 i_ctime_nsec;
+	__le32 i_nlink;
+	__u8   i_reserved2[16];
+};
 
 #define EROFS_MAX_SHARED_XATTRS         (128)
 /* h_shared_count between 129 ... 255 are special # */
@@ -152,7 +154,7 @@ struct erofs_xattr_ibody_header {
 	__u8   h_shared_count;
 	__u8   h_reserved2[7];
 	__le32 h_shared_xattrs[0];      /* shared xattr id array */
-} __packed;
+};
 
 /* Name indexes */
 #define EROFS_XATTR_INDEX_USER              1
@@ -169,22 +171,28 @@ struct erofs_xattr_entry {
 	__le16 e_value_size;    /* size of attribute value */
 	/* followed by e_name and e_value */
 	char   e_name[0];       /* attribute name */
-} __packed;
+};
 
-#define ondisk_xattr_ibody_size(count)	({\
-	u32 __count = le16_to_cpu(count); \
-	((__count) == 0) ? 0 : \
-	sizeof(struct erofs_xattr_ibody_header) + \
-		sizeof(__u32) * ((__count) - 1); })
+static inline unsigned int erofs_xattr_ibody_size(__le16 i_xattr_icount)
+{
+	if (!i_xattr_icount)
+		return 0;
+
+	return sizeof(struct erofs_xattr_ibody_header) +
+		sizeof(__u32) * (le16_to_cpu(i_xattr_icount) - 1);
+}
 
 #define EROFS_XATTR_ALIGN(size) round_up(size, sizeof(struct erofs_xattr_entry))
-#define EROFS_XATTR_ENTRY_SIZE(entry) EROFS_XATTR_ALIGN( \
-	sizeof(struct erofs_xattr_entry) + \
-	(entry)->e_name_len + le16_to_cpu((entry)->e_value_size))
 
-/* available compression algorithm types */
+static inline unsigned int erofs_xattr_entry_size(struct erofs_xattr_entry *e)
+{
+	return EROFS_XATTR_ALIGN(sizeof(struct erofs_xattr_entry) +
+				 e->e_name_len + le16_to_cpu(e->e_value_size));
+}
+
+/* available compression algorithm types (for h_algorithmtype) */
 enum {
-	Z_EROFS_COMPRESSION_LZ4,
+	Z_EROFS_COMPRESSION_LZ4	= 0,
 	Z_EROFS_COMPRESSION_MAX
 };
 
@@ -212,12 +220,12 @@ struct z_erofs_map_header {
 	 * bit 5-7 : (physical - logical) cluster bits of head 2.
 	 */
 	__u8	h_clusterbits;
-} __packed;
+};
 
 #define Z_EROFS_VLE_LEGACY_HEADER_PADDING       8
 
 /*
- * Z_EROFS Variable-sized Logical Extent cluster type:
+ * Fixed-sized output compression ondisk Logical Extent cluster type:
  *    0 - literal (uncompressed) cluster
  *    1 - compressed cluster (for the head logical cluster)
  *    2 - compressed cluster (for the other logical clusters)
@@ -242,10 +250,10 @@ struct z_erofs_map_header {
  *                (di_advise could be 0, 1 or 2)
  */
 enum {
-	Z_EROFS_VLE_CLUSTER_TYPE_PLAIN,
-	Z_EROFS_VLE_CLUSTER_TYPE_HEAD,
-	Z_EROFS_VLE_CLUSTER_TYPE_NONHEAD,
-	Z_EROFS_VLE_CLUSTER_TYPE_RESERVED,
+	Z_EROFS_VLE_CLUSTER_TYPE_PLAIN		= 0,
+	Z_EROFS_VLE_CLUSTER_TYPE_HEAD		= 1,
+	Z_EROFS_VLE_CLUSTER_TYPE_NONHEAD	= 2,
+	Z_EROFS_VLE_CLUSTER_TYPE_RESERVED	= 3,
 	Z_EROFS_VLE_CLUSTER_TYPE_MAX
 };
 
@@ -267,18 +275,18 @@ struct z_erofs_vle_decompressed_index {
 		 * [1] - pointing to the tail cluster
 		 */
 		__le16 delta[2];
-	} di_u __packed;		/* 8 bytes */
-} __packed;
+	} di_u;
+};
 
 #define Z_EROFS_VLE_EXTENT_ALIGN(size) round_up(size, \
 	sizeof(struct z_erofs_vle_decompressed_index))
 
 /* dirent sorts in alphabet order, thus we can do binary search */
 struct erofs_dirent {
-	__le64 nid;     /*  0, node number */
-	__le16 nameoff; /*  8, start offset of file name */
-	__u8 file_type; /* 10, file type */
-	__u8 reserved;  /* 11, reserved */
+	__le64 nid;     /* node number */
+	__le16 nameoff; /* start offset of file name */
+	__u8 file_type; /* file type */
+	__u8 reserved;  /* reserved */
 } __packed;
 
 /* file types used in inode_info->flags */
@@ -300,8 +308,8 @@ enum {
 static inline void erofs_check_ondisk_layout_definitions(void)
 {
 	BUILD_BUG_ON(sizeof(struct erofs_super_block) != 128);
-	BUILD_BUG_ON(sizeof(struct erofs_inode_v1) != 32);
-	BUILD_BUG_ON(sizeof(struct erofs_inode_v2) != 64);
+	BUILD_BUG_ON(sizeof(struct erofs_inode_compact) != 32);
+	BUILD_BUG_ON(sizeof(struct erofs_inode_extended) != 64);
 	BUILD_BUG_ON(sizeof(struct erofs_xattr_ibody_header) != 12);
 	BUILD_BUG_ON(sizeof(struct erofs_xattr_entry) != 4);
 	BUILD_BUG_ON(sizeof(struct z_erofs_map_header) != 8);
diff --git a/lib/compress.c b/lib/compress.c
index 1919609..7935fce 100644
--- a/lib/compress.c
+++ b/lib/compress.c
@@ -120,7 +120,7 @@ static int write_uncompressed_block(struct z_erofs_vle_compress_ctx *ctx,
 	int ret;
 	unsigned int count;
 
-	if (!(sbi.requirements & EROFS_REQUIREMENT_LZ4_0PADDING)) {
+	if (!(sbi.feature_incompat & EROFS_FEATURE_INCOMPAT_LZ4_0PADDING)) {
 		/* fix up clusterofs to 0 if possable */
 		if (ctx->head >= ctx->clusterofs) {
 			ctx->head -= ctx->clusterofs;
@@ -184,7 +184,8 @@ nocompression:
 			erofs_dbg("Writing %u compressed data to block %u",
 				  count, ctx->blkaddr);
 
-			if (sbi.requirements & EROFS_REQUIREMENT_LZ4_0PADDING)
+			if (sbi.feature_incompat &
+			    EROFS_FEATURE_INCOMPAT_LZ4_0PADDING)
 				ret = blk_write(dst - (EROFS_BLKSIZ - ret),
 						ctx->blkaddr, 1);
 			else
@@ -382,7 +383,7 @@ int z_erofs_convert_to_compacted_format(struct erofs_inode *inode,
 					      4, logical_clusterbits, true);
 	}
 	inode->extent_isize = out - (u8 *)inode->compressmeta;
-	inode->data_mapping_mode = EROFS_INODE_FLAT_COMPRESSION;
+	inode->datalayout = EROFS_INODE_FLAT_COMPRESSION;
 	return 0;
 }
 
@@ -473,7 +474,7 @@ int erofs_write_compressed_file(struct erofs_inode *inode)
 	legacymetasize = ctx.metacur - compressmeta;
 	if (cfg.c_legacy_compress) {
 		inode->extent_isize = legacymetasize;
-		inode->data_mapping_mode = EROFS_INODE_FLAT_COMPRESSION_LEGACY;
+		inode->datalayout = EROFS_INODE_FLAT_COMPRESSION_LEGACY;
 	} else {
 		ret = z_erofs_convert_to_compacted_format(inode, blkaddr - 1,
 							  legacymetasize, 12);
diff --git a/lib/config.c b/lib/config.c
index 2e91b92..9c78142 100644
--- a/lib/config.c
+++ b/lib/config.c
@@ -21,7 +21,7 @@ void erofs_init_configure(void)
 	cfg.c_dry_run  = false;
 	cfg.c_legacy_compress = false;
 	cfg.c_compr_level_master = -1;
-	sbi.requirements = EROFS_REQUIREMENT_LZ4_0PADDING;
+	sbi.feature_incompat = EROFS_FEATURE_INCOMPAT_LZ4_0PADDING;
 }
 
 void erofs_show_config(void)
diff --git a/lib/inode.c b/lib/inode.c
index c8cf847..4e1e29f 100644
--- a/lib/inode.c
+++ b/lib/inode.c
@@ -179,7 +179,7 @@ int erofs_prepare_dir_file(struct erofs_inode *dir)
 	dir->i_size = d_size;
 
 	/* no compression for all dirs */
-	dir->data_mapping_mode = EROFS_INODE_FLAT_INLINE;
+	dir->datalayout = EROFS_INODE_FLAT_INLINE;
 
 	/* allocate dir main data */
 	ret = __allocate_inode_bh_data(dir, erofs_blknr(d_size));
@@ -274,7 +274,7 @@ int erofs_write_file_from_buffer(struct erofs_inode *inode, char *buf)
 	const unsigned int nblocks = erofs_blknr(inode->i_size);
 	int ret;
 
-	inode->data_mapping_mode = EROFS_INODE_FLAT_INLINE;
+	inode->datalayout = EROFS_INODE_FLAT_INLINE;
 
 	ret = __allocate_inode_bh_data(inode, nblocks);
 	if (ret)
@@ -303,7 +303,7 @@ int erofs_write_file(struct erofs_inode *inode)
 	int ret, fd;
 
 	if (!inode->i_size) {
-		inode->data_mapping_mode = EROFS_INODE_FLAT_PLAIN;
+		inode->datalayout = EROFS_INODE_FLAT_PLAIN;
 		return 0;
 	}
 
@@ -315,7 +315,7 @@ int erofs_write_file(struct erofs_inode *inode)
 	}
 
 	/* fallback to all data uncompressed */
-	inode->data_mapping_mode = EROFS_INODE_FLAT_INLINE;
+	inode->datalayout = EROFS_INODE_FLAT_INLINE;
 	nblocks = inode->i_size / EROFS_BLKSIZ;
 
 	ret = __allocate_inode_bh_data(inode, nblocks);
@@ -366,39 +366,39 @@ static bool erofs_bh_flush_write_inode(struct erofs_buffer_head *bh)
 	struct erofs_inode *const inode = bh->fsprivate;
 	erofs_off_t off = erofs_btell(bh, false);
 
-	/* let's support v1 currently */
-	struct erofs_inode_v1 v1 = {0};
+	/* let's support compact inode currently */
+	struct erofs_inode_compact dic = {0};
 	int ret;
 
-	v1.i_advise = cpu_to_le16(0 | (inode->data_mapping_mode << 1));
-	v1.i_mode = cpu_to_le16(inode->i_mode);
-	v1.i_nlink = cpu_to_le16(inode->i_nlink);
-	v1.i_size = cpu_to_le32((u32)inode->i_size);
+	dic.i_format = cpu_to_le16(0 | (inode->datalayout << 1));
+	dic.i_mode = cpu_to_le16(inode->i_mode);
+	dic.i_nlink = cpu_to_le16(inode->i_nlink);
+	dic.i_size = cpu_to_le32((u32)inode->i_size);
 
-	v1.i_ino = cpu_to_le32(inode->i_ino[0]);
+	dic.i_ino = cpu_to_le32(inode->i_ino[0]);
 
-	v1.i_uid = cpu_to_le16((u16)inode->i_uid);
-	v1.i_gid = cpu_to_le16((u16)inode->i_gid);
+	dic.i_uid = cpu_to_le16((u16)inode->i_uid);
+	dic.i_gid = cpu_to_le16((u16)inode->i_gid);
 
 	switch ((inode->i_mode) >> S_SHIFT) {
 	case S_IFCHR:
 	case S_IFBLK:
 	case S_IFIFO:
 	case S_IFSOCK:
-		v1.i_u.rdev = cpu_to_le32(inode->u.i_rdev);
+		dic.i_u.rdev = cpu_to_le32(inode->u.i_rdev);
 		break;
 
 	default:
 		if (is_inode_layout_compression(inode))
-			v1.i_u.compressed_blocks =
+			dic.i_u.compressed_blocks =
 				cpu_to_le32(inode->u.i_blocks);
 		else
-			v1.i_u.raw_blkaddr =
+			dic.i_u.raw_blkaddr =
 				cpu_to_le32(inode->u.i_blkaddr);
 		break;
 	}
 
-	ret = dev_write(&v1, off, sizeof(struct erofs_inode_v1));
+	ret = dev_write(&dic, off, sizeof(struct erofs_inode_compact));
 	if (ret)
 		return false;
 	off += inode->inode_isize;
@@ -468,13 +468,13 @@ int erofs_prepare_inode_buffer(struct erofs_inode *inode)
 	 * should use EROFS_INODE_FLAT_PLAIN data mapping mode.
 	 */
 	if (!inode->idata_size)
-		inode->data_mapping_mode = EROFS_INODE_FLAT_PLAIN;
+		inode->datalayout = EROFS_INODE_FLAT_PLAIN;
 
 	bh = erofs_balloc(INODE, inodesize, 0, inode->idata_size);
 	if (bh == ERR_PTR(-ENOSPC)) {
 		int ret;
 
-		inode->data_mapping_mode = EROFS_INODE_FLAT_PLAIN;
+		inode->datalayout = EROFS_INODE_FLAT_PLAIN;
 noinline:
 		/* expend an extra block for tail-end data */
 		ret = erofs_prepare_tail_block(inode);
@@ -487,7 +487,7 @@ noinline:
 	} else if (IS_ERR(bh)) {
 		return PTR_ERR(bh);
 	} else if (inode->idata_size) {
-		inode->data_mapping_mode = EROFS_INODE_FLAT_INLINE;
+		inode->datalayout = EROFS_INODE_FLAT_INLINE;
 
 		/* allocate inline buffer */
 		ibh = erofs_battach(bh, META, inode->idata_size);
@@ -616,7 +616,7 @@ int erofs_fill_inode(struct erofs_inode *inode,
 	inode->i_srcpath[sizeof(inode->i_srcpath) - 1] = '\0';
 
 	inode->i_ino[1] = st->st_ino;
-	inode->inode_isize = sizeof(struct erofs_inode_v1);
+	inode->inode_isize = sizeof(struct erofs_inode_compact);
 
 	list_add(&inode->i_hash,
 		 &inode_hashtable[st->st_ino % NR_INODE_HASHTABLE]);
diff --git a/mkfs/main.c b/mkfs/main.c
index 2dfd68e..effc26b 100644
--- a/mkfs/main.c
+++ b/mkfs/main.c
@@ -69,7 +69,8 @@ static int parse_extended_opts(const char *opts)
 				return -EINVAL;
 			/* disable compacted indexes and 0padding */
 			cfg.c_legacy_compress = true;
-			sbi.requirements &= ~EROFS_REQUIREMENT_LZ4_0PADDING;
+			sbi.feature_incompat &=
+				~EROFS_FEATURE_INCOMPAT_LZ4_0PADDING;
 		}
 	}
 	return 0;
@@ -155,7 +156,7 @@ int erofs_mkfs_update_super_block(struct erofs_buffer_head *bh,
 		.blocks = 0,
 		.meta_blkaddr  = sbi.meta_blkaddr,
 		.xattr_blkaddr = 0,
-		.requirements = cpu_to_le32(sbi.requirements),
+		.feature_incompat = cpu_to_le32(sbi.feature_incompat),
 	};
 	const unsigned int sb_blksize =
 		round_up(EROFS_SUPER_END, EROFS_BLKSIZ);
-- 
2.17.1


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 1/3] erofs-utils: complete special file support
  2019-09-17  5:49 ` [PATCH 1/3] erofs-utils: complete special file support Gao Xiang via Linux-erofs
  2019-09-17  5:49   ` [PATCH 2/3] erofs-utils: resize image to the correct size Gao Xiang via Linux-erofs
  2019-09-17  5:49   ` [PATCH 3/3] erofs-utils: keep up with in-kernel ondisk format naming Gao Xiang via Linux-erofs
@ 2019-09-17 15:15   ` Li Guifu
  2 siblings, 0 replies; 6+ messages in thread
From: Li Guifu @ 2019-09-17 15:15 UTC (permalink / raw)
  To: Gao Xiang, linux-erofs, bluce.liguifu, miaoxie, fangwei1



在 2019/9/17 13:49, Gao Xiang via Linux-erofs 写道:
> From: Gao Xiang <gaoxiang25@huawei.com>
> 
> Special file was already supported by obsoleted_mkfs,
> let's complete it for new erofs-utils now.
> 
> Signed-off-by: Gao Xiang <gaoxiang25@huawei.com>
> 
It looks good.
Reviewed-by: Li Guifu <blucerlee@gmail.com>
Thanks,

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 2/3] erofs-utils: resize image to the correct size
  2019-09-17  5:49   ` [PATCH 2/3] erofs-utils: resize image to the correct size Gao Xiang via Linux-erofs
@ 2019-09-17 15:15     ` Li Guifu
  0 siblings, 0 replies; 6+ messages in thread
From: Li Guifu @ 2019-09-17 15:15 UTC (permalink / raw)
  To: Gao Xiang, linux-erofs, bluce.liguifu, miaoxie, fangwei1



在 2019/9/17 13:49, Gao Xiang via Linux-erofs 写道:
> From: Gao Xiang <gaoxiang25@huawei.com>
> 
> In the end, it's necessary to resize image to
> the proper size since buffers could be dropped.
> 
> Signed-off-by: Gao Xiang <gaoxiang25@huawei.com>
> ---
It looks good.
Reviewed-by: Li Guifu <blucerlee@gmail.com>
Thanks,

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 3/3] erofs-utils: keep up with in-kernel ondisk format naming
  2019-09-17  5:49   ` [PATCH 3/3] erofs-utils: keep up with in-kernel ondisk format naming Gao Xiang via Linux-erofs
@ 2019-09-17 15:15     ` Li Guifu
  0 siblings, 0 replies; 6+ messages in thread
From: Li Guifu @ 2019-09-17 15:15 UTC (permalink / raw)
  To: Gao Xiang, linux-erofs, bluce.liguifu, miaoxie, fangwei1



在 2019/9/17 13:49, Gao Xiang via Linux-erofs 写道:
> From: Gao Xiang <gaoxiang25@huawei.com>
> 
> This patch adapts erofs-utils to the latest kernel ondisk definitions,
> especially the following kernel commits:
> 
> 4b66eb51d2c4 erofs: remove all the byte offset comments
> 60a49ba8fee1 erofs: on-disk format should have explicitly assigned numbers
> b6796abd3cc1 erofs: some macros are much more readable as a function
> ed34aa4a8a7d erofs: kill __packed for on-disk structures
> c39747f770be erofs: update erofs_inode_is_data_compressed helper
> 426a930891cf erofs: use feature_incompat rather than requirements
> 8a76568225de erofs: better naming for erofs inode related stuffs
> ea559e7b8451 erofs: update erofs_fs.h comments
> 
> Signed-off-by: Gao Xiang <gaoxiang25@huawei.com>
> ---
It looks good.
Reviewed-by: Li Guifu <blucerlee@gmail.com>
Thanks,

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, back to index

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <20190917054913.24187-1-hsiangkao.ref@aol.com>
2019-09-17  5:49 ` [PATCH 1/3] erofs-utils: complete special file support Gao Xiang via Linux-erofs
2019-09-17  5:49   ` [PATCH 2/3] erofs-utils: resize image to the correct size Gao Xiang via Linux-erofs
2019-09-17 15:15     ` Li Guifu
2019-09-17  5:49   ` [PATCH 3/3] erofs-utils: keep up with in-kernel ondisk format naming Gao Xiang via Linux-erofs
2019-09-17 15:15     ` Li Guifu
2019-09-17 15:15   ` [PATCH 1/3] erofs-utils: complete special file support Li Guifu

Linux-EROFS Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-erofs/0 linux-erofs/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-erofs linux-erofs/ https://lore.kernel.org/linux-erofs \
		linux-erofs@lists.ozlabs.org linux-erofs@ozlabs.org linux-erofs@archiver.kernel.org
	public-inbox-index linux-erofs

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.ozlabs.lists.linux-erofs


AGPL code for this site: git clone https://public-inbox.org/ public-inbox