Skip to contentSkip to conversation

erofs-utils: introduce fuse implementation

PATCH Superseded Gao Xiang via Linux-erofs 1 participant 13 messages Nov 2, 2020 1 message not in the archive

Subsystems (2)

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

#1 lore raw

v3 cover erofs-utils: introduce fuse implementation

From: Gao Xiang <[email protected]>

v2: https://lore.kernel.org/r/[email protected]

background & v1:
https://lore.kernel.org/r/[email protected]

kill a lot of insane logic, and hopefully it can get into shape in the next iter.

Thanks,
Gao Xiang

Gao Xiang (9):
erofs-utils: fuse: refactor raw data logic
erofs-utils: fuse: kill sbk
erofs-utils: fuse: kill nid2addr, addr2nid
erofs-utils: fuse: kill erofs_get_root_nid()
erofs-utils: fuse: move erofs_init() to main.c
erofs-utils: fuse: move superblock logic into lib/
erofs-utils: fuse: kill getattr.c
erofs-utils: fuse: kill open.c
erofs-utils: fuse: kill incomplate dcache

Huang Jianan (2):
erofs-utils: fuse: add special file support
erofs-utils: fuse: add compressed file support

Li Guifu (1):
erofs-utils: introduce fuse implementation

 Makefile.am                |   2 +-
 README                     |  28 ++-
 configure.ac               |   3 +-
 fuse/Makefile.am           |  14 ++
 fuse/main.c                | 205 ++++++++++++++++++
 fuse/namei.c               | 237 +++++++++++++++++++++
 fuse/namei.h               |  17 ++
 fuse/read.c                | 173 +++++++++++++++
 fuse/read.h                |  17 ++
 fuse/readir.c              | 121 +++++++++++
 fuse/readir.h              |  17 ++
 fuse/zmap.c                | 417 +++++++++++++++++++++++++++++++++++++
 include/erofs/decompress.h |  35 ++++
 include/erofs/defs.h       |  16 ++
 include/erofs/internal.h   | 104 +++++++++
 include/erofs/io.h         |   1 +
 include/erofs_fs.h         |   4 +
 lib/Makefile.am            |   4 +-
 lib/data.c                 | 117 +++++++++++
 lib/decompress.c           |  87 ++++++++
 lib/io.c                   |  16 ++
 lib/super.c                |  79 +++++++
 22 files changed, 1709 insertions(+), 5 deletions(-)
 create mode 100644 fuse/Makefile.am
 create mode 100644 fuse/main.c
 create mode 100644 fuse/namei.c
 create mode 100644 fuse/namei.h
 create mode 100644 fuse/read.c
 create mode 100644 fuse/read.h
 create mode 100644 fuse/readir.c
 create mode 100644 fuse/readir.h
 create mode 100644 fuse/zmap.c
 create mode 100644 include/erofs/decompress.h
 create mode 100644 lib/data.c
 create mode 100644 lib/decompress.c
 create mode 100644 lib/super.c
Signature · 1 line
2.24.0
#2 lore raw

PATCH v3 1/12 erofs-utils: introduce fuse implementation

From: Li Guifu <[email protected]>

Let's add erofsfuse approach, and benefits are:

- images can be supported on various platforms;
- new unpack tool can be developed based on this;
- new on-disk features can be iterated, verified effectively.

This commit only aims at reading a regular file.
Other file (e.g. compressed file) support is out of scope for now.

---
 Makefile.am              |   2 +-
 README                   |  28 ++++-
 configure.ac             |   3 +-
 fuse/Makefile.am         |  14 +++
 fuse/dentry.c            | 130 ++++++++++++++++++++++
 fuse/dentry.h            |  42 ++++++++
 fuse/getattr.c           |  64 +++++++++++
 fuse/getattr.h           |  15 +++
 fuse/init.c              |  97 +++++++++++++++++
 fuse/init.h              |  22 ++++
 fuse/main.c              | 166 ++++++++++++++++++++++++++++
 fuse/namei.c             | 228 +++++++++++++++++++++++++++++++++++++++
 fuse/namei.h             |  22 ++++
 fuse/open.c              |  22 ++++
 fuse/open.h              |  15 +++
 fuse/read.c              | 113 +++++++++++++++++++
 fuse/read.h              |  16 +++
 fuse/readir.c            | 122 +++++++++++++++++++++
 fuse/readir.h            |  17 +++
 include/erofs/defs.h     |   3 +
 include/erofs/internal.h |  37 +++++++
 include/erofs/io.h       |   1 +
 lib/io.c                 |  16 +++
 23 files changed, 1192 insertions(+), 3 deletions(-)
 create mode 100644 fuse/Makefile.am
 create mode 100644 fuse/dentry.c
 create mode 100644 fuse/dentry.h
 create mode 100644 fuse/getattr.c
 create mode 100644 fuse/getattr.h
 create mode 100644 fuse/init.c
 create mode 100644 fuse/init.h
 create mode 100644 fuse/main.c
 create mode 100644 fuse/namei.c
 create mode 100644 fuse/namei.h
 create mode 100644 fuse/open.c
 create mode 100644 fuse/open.h
 create mode 100644 fuse/read.c
 create mode 100644 fuse/read.h
 create mode 100644 fuse/readir.c
 create mode 100644 fuse/readir.h
Makefile.am +1 -1
index 1d20577068c5..24f4a7b3d5ad 100644
@@ -3,4 +3,4 @@
 
 ACLOCAL_AMFLAGS = -I m4
 
-SUBDIRS = man lib mkfs
+SUBDIRS = man lib mkfs fuse
README +27 -1
index 5addd6b80e04..870858c48b7d 100644
@@ -2,7 +2,8 @@ erofs-utils
 ===========
 
 erofs-utils includes user-space tools for erofs filesystem images.
-Currently only mkfs.erofs is available.
+One is mkfs.erofs to create a image, the other is erofsfuse which
+is used to mount a image on a directory
 
 mkfs.erofs
 ----------
@@ -95,6 +96,31 @@ It may still be useful since new erofs-utils has not been widely used in
 commercial products. However, if that happens, please report bug to us
 as well.
 
+erofs-utils: erofsfuse
+----------------------
+erofsfuse mount a erofs filesystem image created by mkfs.erofs to a directory, and then
+It can be listed, read files and so on.
+
+Dependencies
+~~~~~~~~~~~~
+FUSE library version: 2.9.7
+fusermount version: 2.9.7
+using FUSE kernel interface version 7.19
+
+How to installed fuse
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+sudo apt-get update
+sudo apt-get install -y fuse libfuse-dev
+
+How to build erofsfuse
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+	$ ./autogen.sh
+	$ ./configure
+	$ make
+
+erofsfuse binary will be generated under fuse folder.
+
 Contribution
 ------------
 
configure.ac +2 -1
index 0f40a840cf4f..4194a77f1e36 100644
@@ -245,6 +245,7 @@ fi
 AC_CONFIG_FILES([Makefile
 		 man/Makefile
 		 lib/Makefile
-		 mkfs/Makefile])
+		 mkfs/Makefile
+		 fuse/Makefile])
 AC_OUTPUT
 
fuse/Makefile.am new file +14 -0
new file mode 100644
index 000000000000..4921a4363cbb
@@ -0,0 +1,14 @@
+# SPDX-License-Identifier: GPL-2.0+
+# Makefile.am
+
+AUTOMAKE_OPTIONS = foreign
+bin_PROGRAMS     = erofsfuse
+erofsfuse_SOURCES = main.c dentry.c getattr.c namei.c read.c init.c open.c readir.c
+erofsfuse_CFLAGS = -Wall -Werror \
+                   -I$(top_srcdir)/include \
+                   $(shell pkg-config fuse --cflags) \
+                   -DFUSE_USE_VERSION=26 \
+                   -std=gnu99
+LDFLAGS += $(shell pkg-config fuse --libs)
+erofsfuse_LDADD = $(top_builddir)/lib/liberofs.la -ldl
+
fuse/dentry.c new file +130 -0

130 lines not on this page · raw message

fuse/dentry.h new file +42 -0

42 lines not on this page · raw message

fuse/getattr.c new file +64 -0

64 lines not on this page · raw message

fuse/getattr.h new file +15 -0
new file mode 100644
index 000000000000..735529a91d5b
@@ -0,0 +1,15 @@
+/* SPDX-License-Identifier: GPL-2.0+ */
+/*
+ * erofs-utils/fuse/getattr.h
+ *
+ * Created by Li Guifu <[email protected]>
+ */
+#ifndef __EROFS_GETATTR_H
+#define __EROFS_GETATTR_H
+
+#include <fuse.h>
+#include <fuse_opt.h>
+
+int erofs_getattr(const char *path, struct stat *st);
+
+#endif
fuse/init.c new file +97 -0

97 lines not on this page · raw message

fuse/init.h new file +22 -0
new file mode 100644
index 000000000000..34085f2b548d
@@ -0,0 +1,22 @@
+/* SPDX-License-Identifier: GPL-2.0+ */
+/*
+ * erofs-utils/fuse/init.h
+ *
+ * Created by Li Guifu <[email protected]>
+ */
+#ifndef __EROFS_INIT_H
+#define __EROFS_INIT_H
+
+#include <fuse.h>
+#include <fuse_opt.h>
+#include "erofs/internal.h"
+
+#define BOOT_SECTOR_SIZE	0x400
+
+int erofs_init_super(void);
+erofs_nid_t erofs_get_root_nid(void);
+erofs_off_t nid2addr(erofs_nid_t nid);
+erofs_nid_t addr2nid(erofs_off_t addr);
+void *erofs_init(struct fuse_conn_info *info);
+
+#endif
fuse/main.c new file +166 -0

166 lines not on this page · raw message

fuse/namei.c new file +228 -0

228 lines not on this page · raw message

fuse/namei.h new file +22 -0
new file mode 100644
index 000000000000..1803a673daaf
@@ -0,0 +1,22 @@
+/* SPDX-License-Identifier: GPL-2.0+ */
+/*
+ * erofs-utils/fuse/inode.h
+ *
+ * Created by Li Guifu <[email protected]>
+ */
+#ifndef __INODE_H
+#define __INODE_H
+
+#include "erofs/internal.h"
+#include "erofs_fs.h"
+
+int inode_init(erofs_nid_t root);
+struct dcache_entry *get_cached_dentry(struct dcache_entry **parent,
+				       const char **path);
+int erofs_iget_by_path(const char *path, struct erofs_vnode *v);
+int erofs_iget_by_nid(erofs_nid_t nid, struct erofs_vnode *v);
+struct dcache_entry *disk_lookup(struct dcache_entry *parent, const char *name,
+		unsigned int name_len);
+int walk_path(const char *path, erofs_nid_t *out_nid);
+
+#endif
fuse/open.c new file +22 -0
new file mode 100644
index 000000000000..beb9a8615512
@@ -0,0 +1,22 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * erofs-utils/fuse/open.c
+ *
+ * Created by Li Guifu <[email protected]>
+ */
+#include "open.h"
+#include <asm-generic/errno-base.h>
+#include <fuse.h>
+#include <fuse_opt.h>
+#include "erofs/print.h"
+
+int erofs_open(const char *path, struct fuse_file_info *fi)
+{
+	erofs_info("open path=%s", path);
+
+	if ((fi->flags & O_ACCMODE) != O_RDONLY)
+		return -EACCES;
+
+	return 0;
+}
+
fuse/open.h new file +15 -0
new file mode 100644
index 000000000000..dfc8b3cdd515
@@ -0,0 +1,15 @@
+/* SPDX-License-Identifier: GPL-2.0+ */
+/*
+ * erofs-utils/fuse/open.h
+ *
+ * Created by Li Guifu <[email protected]>
+ */
+#ifndef __EROFS_OPEN_H
+#define __EROFS_OPEN_H
+
+#include <fuse.h>
+#include <fuse_opt.h>
+
+int erofs_open(const char *path, struct fuse_file_info *fi);
+
+#endif
fuse/read.c new file +113 -0

113 lines not on this page · raw message

fuse/read.h new file +16 -0
new file mode 100644
index 000000000000..3f4af1495510
@@ -0,0 +1,16 @@
+/* SPDX-License-Identifier: GPL-2.0+ */
+/*
+ * erofs-utils/fuse/read.h
+ *
+ * Created by Li Guifu <[email protected]>
+ */
+#ifndef __EROFS_READ_H
+#define __EROFS_READ_H
+
+#include <fuse.h>
+#include <fuse_opt.h>
+
+int erofs_read(const char *path, char *buffer, size_t size, off_t offset,
+	    struct fuse_file_info *fi);
+
+#endif
fuse/readir.c new file +122 -0

122 lines not on this page · raw message

fuse/readir.h new file +17 -0
new file mode 100644
index 000000000000..ee2ab8bdd0f0
@@ -0,0 +1,17 @@
+/* SPDX-License-Identifier: GPL-2.0+ */
+/*
+ * erofs-utils/fuse/readir.h
+ *
+ * Created by Li Guifu <[email protected]>
+ */
+#ifndef __EROFS_READDIR_H
+#define __EROFS_READDIR_H
+
+#include <fuse.h>
+#include <fuse_opt.h>
+
+int erofs_readdir(const char *path, void *buffer, fuse_fill_dir_t filler,
+	       off_t offset, struct fuse_file_info *fi);
+
+
+#endif
include/erofs/defs.h +3 -0
index 8dee661ab9f0..e97de36aa04b 100644
@@ -24,6 +24,9 @@
 #ifdef HAVE_LINUX_TYPES_H
 #include <linux/types.h>
 #endif
+#ifndef UNUSED
+#define UNUSED(_X)    ((void) _X)
+#endif
 
 /*
  * container_of - cast a member of a structure out to the containing structure
include/erofs/internal.h +37 -0
index cabb2faa0072..1e3c23ae88b6 100644
@@ -55,6 +55,8 @@ typedef u32 erofs_blk_t;
 #define blknr_to_addr(nr)       ((erofs_off_t)(nr) * EROFS_BLKSIZ)
 
 #define BLK_ROUND_UP(addr)	DIV_ROUND_UP(addr, EROFS_BLKSIZ)
+#define IS_SLOT_ALIGN(__ADDR)   (((__ADDR) % (EROFS_SLOTSIZE)) ? 0 : 1)
+#define IS_BLK_ALIGN(__ADDR)    (((__ADDR) % (EROFS_BLKSIZ)) ? 0 : 1)
 
 struct erofs_buffer_head;
 
@@ -132,11 +134,46 @@ struct erofs_inode {
 #endif
 };
 
+struct erofs_vnode {
+	uint8_t datalayout;
+
+	uint32_t i_size;
+	/* inline size in bytes */
+	uint16_t inode_isize;
+	uint16_t xattr_isize;
+
+	uint16_t xattr_shared_count;
+	char *xattr_shared_xattrs;
+
+	erofs_blk_t raw_blkaddr;
+	erofs_nid_t nid;
+	uint32_t i_ino;
+
+	uint16_t i_mode;
+	uint16_t i_uid;
+	uint16_t i_gid;
+	uint16_t i_nlink;
+
+	/* if file is inline read inline data witch inode */
+	char *idata;
+};
+
 static inline bool is_inode_layout_compression(struct erofs_inode *inode)
 {
 	return erofs_inode_is_data_compressed(inode->datalayout);
 }
 
+#define __inode_advise(x, bit, bits) \
+		(((x) >> (bit)) & ((1 << (bits)) - 1))
+
+#define __inode_version(advise)	\
+		__inode_advise(advise, EROFS_I_VERSION_BIT,	\
+			EROFS_I_VERSION_BITS)
+
+#define __inode_data_mapping(advise)	\
+	__inode_advise(advise, EROFS_I_DATALAYOUT_BIT,\
+		EROFS_I_DATALAYOUT_BITS)
+
 #define IS_ROOT(x)	((x) == (x)->i_parent)
 
 struct erofs_dentry {
include/erofs/io.h +1 -0
index a23de64541c6..557424578ece 100644
@@ -17,6 +17,7 @@
 #endif
 
 int dev_open(const char *devname);
+int dev_open_ro(const char *dev);
 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);
lib/io.c +16 -0
index 4f5d9a6edaa4..d835f34da50f 100644
@@ -108,6 +108,22 @@ int dev_open(const char *dev)
 	return 0;
 }
 
+/* XXX: temporary soluation. Disk I/O implementation needs to be refactored. */
+int dev_open_ro(const char *dev)
+{
+	int fd = open(dev, O_RDONLY | O_BINARY);
+
+	if (fd < 0) {
+		erofs_err("failed to open(%s).", dev);
+		return -errno;
+	}
+
+	erofs_devfd = fd;
+	erofs_devname = dev;
+	erofs_devsz = INT64_MAX;
+	return 0;
+}
+
 u64 dev_length(void)
 {
 	return erofs_devsz;
Signature · 1 line
2.24.0
#3 lore raw

PATCH v3 2/12 erofs-utils: fuse: add special file support

In reply to Gao Xiang via Linux-erofs

From: Huang Jianan <[email protected]>

---
 fuse/getattr.c           |  1 +
 fuse/main.c              |  1 +
 fuse/namei.c             | 14 ++++++++++----
 fuse/read.c              | 26 ++++++++++++++++++++++++++
 fuse/read.h              |  1 +
 include/erofs/internal.h |  1 +
 6 files changed, 40 insertions(+), 4 deletions(-)
fuse/getattr.c +1 -0
index 8426145a9231..4c5991e7e487 100644
@@ -56,6 +56,7 @@ int erofs_getattr(const char *path, struct stat *stbuf)
 	stbuf->st_blocks = stbuf->st_size / EROFS_BLKSIZ;
 	stbuf->st_uid = le16_to_cpu(v.i_uid);
 	stbuf->st_gid = le16_to_cpu(v.i_gid);
+	stbuf->st_rdev = le32_to_cpu(v.i_rdev);
 	stbuf->st_atime = super.build_time;
 	stbuf->st_mtime = super.build_time;
 	stbuf->st_ctime = super.build_time;
fuse/main.c +1 -0
index 6fb3f3e42df3..26f49f6fc299 100644
@@ -116,6 +116,7 @@ static void signal_handle_sigsegv(int signal)
 }
 
 static struct fuse_operations erofs_ops = {
+	.readlink = erofs_readlink,
 	.getattr = erofs_getattr,
 	.readdir = erofs_readdir,
 	.open = erofs_open,
fuse/namei.c +10 -4
index 1564d5853fe6..99e5ffa34858 100644
@@ -11,6 +11,7 @@
 #include <stdio.h>
 #include <errno.h>
 #include <sys/stat.h>
+#include <sys/sysmacros.h>
 
 #include "erofs/defs.h"
 #include "erofs/print.h"
@@ -39,6 +40,13 @@ static uint8_t get_path_token_len(const char *path)
 	return len;
 }
 
+static inline dev_t new_decode_dev(u32 dev)
+{
+	unsigned major = (dev & 0xfff00) >> 8;
+	unsigned minor = (dev & 0xff) | ((dev >> 12) & 0xfff00);
+	return makedev(major, minor);
+}
+
 int erofs_iget_by_nid(erofs_nid_t nid, struct erofs_vnode *vi)
 {
 	int ret;
@@ -65,13 +73,11 @@ int erofs_iget_by_nid(erofs_nid_t nid, struct erofs_vnode *vi)
 	switch (vi->i_mode & S_IFMT) {
 	case S_IFBLK:
 	case S_IFCHR:
-		/* fixme: add special devices support
-		 * vi->i_rdev = new_decode_dev(le32_to_cpu(v1->i_u.rdev));
-		 */
+		vi->i_rdev = new_decode_dev(le32_to_cpu(v1->i_u.rdev));
 		break;
 	case S_IFIFO:
 	case S_IFSOCK:
-		/*fixme: vi->i_rdev = 0; */
+		vi->i_rdev = 0;
 		break;
 	case S_IFREG:
 	case S_IFLNK:
fuse/read.c +26 -0
index 58b23783d083..eb771c75baa7 100644
@@ -111,3 +111,29 @@ int erofs_read(const char *path, char *buffer, size_t size, off_t offset,
 	}
 }
 
+int erofs_readlink(const char *path, char *buffer, size_t size)
+{
+	int ret;
+	erofs_nid_t nid;
+	size_t lnksz;
+	struct erofs_vnode v;
+
+	ret = walk_path(path, &nid);
+	if (ret)
+		return ret;
+
+	ret = erofs_iget_by_nid(nid, &v);
+	if (ret)
+		return ret;
+
+	lnksz = min((size_t)v.i_size, size - 1);
+
+	ret = erofs_read(path, buffer, lnksz, 0, NULL);
+	buffer[lnksz] = '\0';
+	if (ret != (int)lnksz)
+		return ret;
+
+	erofs_info("path:%s link=%s size=%llu", path, buffer, (unsigned long long)lnksz);
+	return 0;
+}
+
fuse/read.h +1 -0
index 3f4af1495510..e901c607dc91 100644
@@ -12,5 +12,6 @@
 
 int erofs_read(const char *path, char *buffer, size_t size, off_t offset,
 	    struct fuse_file_info *fi);
+int erofs_readlink(const char *path, char *buffer, size_t size);
 
 #endif
include/erofs/internal.h +1 -0
index 1e3c23ae88b6..e2769a6be4c9 100644
@@ -153,6 +153,7 @@ struct erofs_vnode {
 	uint16_t i_uid;
 	uint16_t i_gid;
 	uint16_t i_nlink;
+	uint32_t i_rdev;
 
 	/* if file is inline read inline data witch inode */
 	char *idata;
Signature · 1 line
2.24.0
#4 lore raw

PATCH v3 3/12 erofs-utils: fuse: add compressed file support

In reply to Gao Xiang via Linux-erofs

From: Huang Jianan <[email protected]>

---
 fuse/Makefile.am           |   4 +-
 fuse/dentry.h              |   5 +-
 fuse/init.c                |  22 ++
 fuse/namei.c               |  11 +-
 fuse/read.c                |  77 ++++++-
 fuse/zmap.c                | 418 +++++++++++++++++++++++++++++++++++++
 include/erofs/decompress.h |  35 ++++
 include/erofs/defs.h       |  13 ++
 include/erofs/internal.h   |  43 +++-
 include/erofs_fs.h         |   4 +
 lib/Makefile.am            |   4 +-
 lib/decompress.c           |  87 ++++++++
 12 files changed, 714 insertions(+), 9 deletions(-)
 create mode 100644 fuse/zmap.c
 create mode 100644 include/erofs/decompress.h
 create mode 100644 lib/decompress.c
fuse/Makefile.am +2 -2
index 4921a4363cbb..2b2608f57b03 100644
@@ -3,12 +3,12 @@
 
 AUTOMAKE_OPTIONS = foreign
 bin_PROGRAMS     = erofsfuse
-erofsfuse_SOURCES = main.c dentry.c getattr.c namei.c read.c init.c open.c readir.c
+erofsfuse_SOURCES = main.c dentry.c getattr.c namei.c read.c init.c open.c readir.c zmap.c
 erofsfuse_CFLAGS = -Wall -Werror \
                    -I$(top_srcdir)/include \
                    $(shell pkg-config fuse --cflags) \
                    -DFUSE_USE_VERSION=26 \
                    -std=gnu99
 LDFLAGS += $(shell pkg-config fuse --libs)
-erofsfuse_LDADD = $(top_builddir)/lib/liberofs.la -ldl
+erofsfuse_LDADD = $(top_builddir)/lib/liberofs.la -ldl ${LZ4_LIBS}
 
fuse/dentry.h +3 -2
index cb4d87972b2d..12f4cf6bafd9 100644
@@ -10,10 +10,11 @@
 #include <stdint.h>
 #include "erofs/internal.h"
 
+/* fixme: Deal with names that exceed the allocated size */
 #ifdef __64BITS
-#define DCACHE_ENTRY_NAME_LEN       40
+#define DCACHE_ENTRY_NAME_LEN       EROFS_NAME_LEN
 #else
-#define DCACHE_ENTRY_NAME_LEN       48
+#define DCACHE_ENTRY_NAME_LEN       EROFS_NAME_LEN
 #endif
 
 /* This struct declares a node of a k-tree.  Every node has a pointer to one of
fuse/init.c +22 -0
index 802771fc69a4..c6a3af697532 100644
@@ -18,7 +18,25 @@
 
 
 struct erofs_super_block super;
+/* XXX: sbk needs to be replaced with sbi */
 static struct erofs_super_block *sbk = &super;
+struct erofs_sb_info sbi;
+
+static bool check_layout_compatibility(struct erofs_sb_info *sbi,
+				       struct erofs_super_block *dsb)
+{
+	const unsigned int feature = le32_to_cpu(dsb->feature_incompat);
+
+	sbi->feature_incompat = feature;
+
+	/* check if current kernel meets all mandatory requirements */
+	if (feature & (~EROFS_ALL_FEATURE_INCOMPAT)) {
+		erofs_err("unidentified incompatible feature %x, please upgrade kernel version",
+			  feature & ~EROFS_ALL_FEATURE_INCOMPAT);
+		return false;
+	}
+	return true;
+}
 
 int erofs_init_super(void)
 {
@@ -41,6 +59,9 @@ int erofs_init_super(void)
 		return -EINVAL;
 	}
 
+	if (!check_layout_compatibility(&sbi, sb))
+		return -EINVAL;
+
 	sbk->checksum = le32_to_cpu(sb->checksum);
 	sbk->feature_compat = le32_to_cpu(sb->feature_compat);
 	sbk->blkszbits = sb->blkszbits;
@@ -56,6 +77,7 @@ int erofs_init_super(void)
 	sbk->root_nid = le16_to_cpu(sb->root_nid);
 
 	erofs_dump("%-15s:0x%X\n", STR(magic), SUPER_MEM(magic));
+	erofs_dump("%-15s:0x%X\n", STR(feature_incompat), sbi.feature_incompat);
 	erofs_dump("%-15s:0x%X\n", STR(feature_compat), SUPER_MEM(feature_compat));
 	erofs_dump("%-15s:%u\n",   STR(blkszbits), SUPER_MEM(blkszbits));
 	erofs_dump("%-15s:%u\n",   STR(root_nid), SUPER_MEM(root_nid));
fuse/namei.c +10 -1
index 99e5ffa34858..79273f89be1b 100644
@@ -49,7 +49,7 @@ static inline dev_t new_decode_dev(u32 dev)
 
 int erofs_iget_by_nid(erofs_nid_t nid, struct erofs_vnode *vi)
 {
-	int ret;
+	int ret, ifmt;
 	char buf[EROFS_BLKSIZ];
 	struct erofs_inode_compact *v1;
 	const erofs_off_t addr = nid2addr(nid);
@@ -60,6 +60,11 @@ int erofs_iget_by_nid(erofs_nid_t nid, struct erofs_vnode *vi)
 		return -EIO;
 
 	v1 = (struct erofs_inode_compact *)buf;
+	/* fixme: support extended inode */
+	ifmt = le16_to_cpu(v1->i_format);
+	if (__inode_version(ifmt) != EROFS_INODE_LAYOUT_COMPACT)
+		return -EOPNOTSUPP;
+
 	vi->datalayout = __inode_data_mapping(le16_to_cpu(v1->i_format));
 	vi->inode_isize = sizeof(struct erofs_inode_compact);
 	vi->xattr_isize = erofs_xattr_ibody_size(v1->i_xattr_icount);
@@ -88,6 +93,10 @@ int erofs_iget_by_nid(erofs_nid_t nid, struct erofs_vnode *vi)
 		return -EIO;
 	}
 
+	vi->z_inited = false;
+	if (erofs_inode_is_data_compressed(vi->datalayout))
+		z_erofs_fill_inode(vi);
+
 	return 0;
 }
 
fuse/read.c +76 -1

101 lines not on this page · raw message

fuse/zmap.c new file +418 -0

418 lines not on this page · raw message

include/erofs/decompress.h new file +35 -0
new file mode 100644
index 000000000000..beaac359b21f
@@ -0,0 +1,35 @@
+/* SPDX-License-Identifier: GPL-2.0+ */
+/*
+ * erofs-utils/include/erofs/decompress.h
+ *
+ * Copyright (C), 2008-2020, OPPO Mobile Comm Corp., Ltd.
+ * Created by Huang Jianan <[email protected]>
+ */
+#ifndef __EROFS_DECOMPRESS_H
+#define __EROFS_DECOMPRESS_H
+
+#include "internal.h"
+
+enum {
+	Z_EROFS_COMPRESSION_SHIFTED = Z_EROFS_COMPRESSION_MAX,
+	Z_EROFS_COMPRESSION_RUNTIME_MAX
+};
+
+struct z_erofs_decompress_req {
+	char *in, *out;
+
+	/*
+	 * initial decompressed bytes that need to be skipped
+	 * when finally copying to output buffer
+	 */
+	unsigned int decodedskip;
+	unsigned int inputsize, decodedlength;
+
+	/* indicate the algorithm will be used for decompression */
+	unsigned int alg;
+	bool partial_decoding;
+};
+
+int z_erofs_decompress(struct z_erofs_decompress_req *rq);
+
+#endif
include/erofs/defs.h +13 -0
index e97de36aa04b..c42ca401a8ee 100644
@@ -173,5 +173,18 @@ typedef int64_t         s64;
 #define __maybe_unused      __attribute__((__unused__))
 #endif
 
+struct __una_u32 { u32 x; } __packed;
+
+static inline u32 __get_unaligned_cpu32(const void *p)
+{
+	const struct __una_u32 *ptr = (const struct __una_u32 *)p;
+	return ptr->x;
+}
+
+static inline u32 get_unaligned_le32(const void *p)
+{
+	return __get_unaligned_cpu32((const u8 *)p);
+}
+
 #endif
 
include/erofs/internal.h +42 -1

66 lines not on this page · raw message

include/erofs_fs.h +4 -0
index 4cd79f01d820..a69f179a51a5 100644
@@ -279,6 +279,10 @@ struct z_erofs_vle_decompressed_index {
 	} di_u;
 };
 
+#define Z_EROFS_VLE_LEGACY_INDEX_ALIGN(size) \
+	(round_up(size, sizeof(struct z_erofs_vle_decompressed_index)) + \
+	 sizeof(struct z_erofs_map_header) + Z_EROFS_VLE_LEGACY_HEADER_PADDING)
+
 #define Z_EROFS_VLE_EXTENT_ALIGN(size) round_up(size, \
 	sizeof(struct z_erofs_vle_decompressed_index))
 
lib/Makefile.am +2 -2
index e4b51e65f053..c921a62a8b23 100644
@@ -2,8 +2,8 @@
 # Makefile.am
 
 noinst_LTLIBRARIES = liberofs.la
-liberofs_la_SOURCES = config.c io.c cache.c inode.c xattr.c \
-		      compress.c compressor.c exclude.c
+liberofs_la_SOURCES = config.c io.c cache.c inode.c xattr.c exclude.c \
+		      compress.c compressor.c decompress.c
 liberofs_la_CFLAGS = -Wall -Werror -I$(top_srcdir)/include
 if ENABLE_LZ4
 liberofs_la_CFLAGS += ${LZ4_CFLAGS}
lib/decompress.c new file +87 -0

87 lines not on this page · raw message

Signature · 1 line
2.24.0
#5 lore raw

PATCH v3 4/12 erofs-utils: fuse: refactor raw data logic

In reply to Gao Xiang via Linux-erofs

As a common logic and move into lib/
( will fold in to the original patch. )

---
 fuse/init.c              |   2 +
 fuse/read.c              |  76 ++++++-------------------
 include/erofs/internal.h |  19 ++++++-
 lib/Makefile.am          |   2 +-
 lib/data.c               | 117 +++++++++++++++++++++++++++++++++++++++
 5 files changed, 155 insertions(+), 61 deletions(-)
 create mode 100644 lib/data.c
fuse/init.c +2 -0
index c6a3af697532..09e7b1210006 100644
@@ -71,7 +71,9 @@ int erofs_init_super(void)
 	sbk->build_time_nsec = le32_to_cpu(sb->build_time_nsec);
 	sbk->blocks = le32_to_cpu(sb->blocks);
 	sbk->meta_blkaddr = le32_to_cpu(sb->meta_blkaddr);
+	sbi.meta_blkaddr = sbk->meta_blkaddr;
 	sbk->xattr_blkaddr = le32_to_cpu(sb->xattr_blkaddr);
+	sbi.islotbits = EROFS_ISLOTBITS;
 	memcpy(sbk->uuid, sb->uuid, 16);
 	memcpy(sbk->volume_name, sb->volume_name, 16);
 	sbk->root_nid = le16_to_cpu(sb->root_nid);
fuse/read.c +18 -58

92 lines not on this page · raw message

include/erofs/internal.h +17 -2
index 6c5fbd3c5d3c..54038071bf84 100644
@@ -70,12 +70,20 @@ struct erofs_sb_info {
 	u32 feature_incompat;
 	u64 build_time;
 	u32 build_time_nsec;
+
+	unsigned char islotbits;
+
 	u8 uuid[16];
 };
 
 /* global sbi */
 extern struct erofs_sb_info sbi;
 
+static inline erofs_off_t iloc(erofs_nid_t nid)
+{
+	return blknr_to_addr(sbi.meta_blkaddr) + (nid << sbi.islotbits);
+}
+
 #define EROFS_FEATURE_FUNCS(name, compat, feature) \
 static inline bool erofs_sb_has_##name(void) \
 { \
@@ -219,13 +227,16 @@ static inline const char *erofs_strerror(int err)
 }
 
 enum {
-	BH_Mapped ,
-	BH_Zipped ,
+	BH_Meta,
+	BH_Mapped,
+	BH_Zipped,
 	BH_FullMapped,
 };
 
 /* Has a disk mapping */
 #define EROFS_MAP_MAPPED	(1 << BH_Mapped)
+/* Located in metadata (could be copied from bd_inode) */
+#define EROFS_MAP_META		(1 << BH_Meta)
 /* The extent has been compressed */
 #define EROFS_MAP_ZIPPED	(1 << BH_Zipped)
 /* The length of extent is full */
@@ -241,6 +252,10 @@ struct erofs_map_blocks {
 	erofs_blk_t index;
 };
 
+/* data.h */
+int erofs_read_raw_data(struct erofs_inode *inode, char *buffer,
+			erofs_off_t offset, erofs_off_t size);
+
 /* zmap.c */
 int z_erofs_fill_inode(struct erofs_vnode *vi);
 int z_erofs_map_blocks_iter(struct erofs_vnode *vi,
lib/Makefile.am +1 -1
index c921a62a8b23..54c43897aa49 100644
@@ -3,7 +3,7 @@
 
 noinst_LTLIBRARIES = liberofs.la
 liberofs_la_SOURCES = config.c io.c cache.c inode.c xattr.c exclude.c \
-		      compress.c compressor.c decompress.c
+		      data.c compress.c compressor.c decompress.c
 liberofs_la_CFLAGS = -Wall -Werror -I$(top_srcdir)/include
 if ENABLE_LZ4
 liberofs_la_CFLAGS += ${LZ4_CFLAGS}
lib/data.c new file +117 -0

117 lines not on this page · raw message

Signature · 1 line
2.24.0
#6 lore raw

PATCH v3 5/12 erofs-utils: fuse: kill sbk

In reply to Gao Xiang via Linux-erofs

(will fold into the original patch.)

---
 fuse/init.c              | 78 +++++++++++++++++++---------------------
 fuse/init.h              |  2 +-
 fuse/main.c              |  2 +-
 include/erofs/internal.h |  7 ++++
 4 files changed, 45 insertions(+), 44 deletions(-)
fuse/init.c +36 -42
index 09e7b1210006..f3f7f9750468 100644
@@ -18,8 +18,6 @@
 
 
 struct erofs_super_block super;
-/* XXX: sbk needs to be replaced with sbi */
-static struct erofs_super_block *sbk = &super;
 struct erofs_sb_info sbi;
 
 static bool check_layout_compatibility(struct erofs_sb_info *sbi,
@@ -38,65 +36,61 @@ static bool check_layout_compatibility(struct erofs_sb_info *sbi,
 	return true;
 }
 
-int erofs_init_super(void)
+int erofs_read_superblock(void)
 {
+	char data[EROFS_BLKSIZ];
+	struct erofs_super_block *dsb;
+	unsigned int blkszbits;
 	int ret;
-	char buf[EROFS_BLKSIZ];
-	struct erofs_super_block *sb;
 
-	memset(buf, 0, sizeof(buf));
-	ret = blk_read(buf, 0, 1);
+	ret = blk_read(data, 0, 1);
 	if (ret < 0) {
-		erofs_err("Failed to read super block ret=%d", ret);
-		return -EINVAL;
+		erofs_err("cannot read erofs superblock: %d", ret);
+		return -EIO;
 	}
+	dsb = (struct erofs_super_block *)(data + EROFS_SUPER_OFFSET);
 
-	sb = (struct erofs_super_block *) (buf + BOOT_SECTOR_SIZE);
-	sbk->magic = le32_to_cpu(sb->magic);
-	if (sbk->magic != EROFS_SUPER_MAGIC_V1) {
-		erofs_err("EROFS magic[0x%X] NOT matched to [0x%X] ",
-			  super.magic, EROFS_SUPER_MAGIC_V1);
-		return -EINVAL;
+	ret = -EINVAL;
+	if (le32_to_cpu(dsb->magic) != EROFS_SUPER_MAGIC_V1) {
+		erofs_err("cannot find valid erofs superblock");
+		return ret;
 	}
 
-	if (!check_layout_compatibility(&sbi, sb))
-		return -EINVAL;
+	sbi.feature_compat = le32_to_cpu(dsb->feature_compat);
 
-	sbk->checksum = le32_to_cpu(sb->checksum);
-	sbk->feature_compat = le32_to_cpu(sb->feature_compat);
-	sbk->blkszbits = sb->blkszbits;
+	blkszbits = dsb->blkszbits;
+	/* 9(512 bytes) + LOG_SECTORS_PER_BLOCK == LOG_BLOCK_SIZE */
+	if (blkszbits != LOG_BLOCK_SIZE) {
+		erofs_err("blksize %u isn't supported on this platform",
+			  1 << blkszbits);
+		return ret;
+	}
+
+	if (!check_layout_compatibility(&sbi, dsb))
+		return ret;
 
-	sbk->inos = le64_to_cpu(sb->inos);
-	sbk->build_time = le64_to_cpu(sb->build_time);
-	sbk->build_time_nsec = le32_to_cpu(sb->build_time_nsec);
-	sbk->blocks = le32_to_cpu(sb->blocks);
-	sbk->meta_blkaddr = le32_to_cpu(sb->meta_blkaddr);
-	sbi.meta_blkaddr = sbk->meta_blkaddr;
-	sbk->xattr_blkaddr = le32_to_cpu(sb->xattr_blkaddr);
+	sbi.blocks = le32_to_cpu(dsb->blocks);
+	sbi.meta_blkaddr = le32_to_cpu(dsb->meta_blkaddr);
+	sbi.xattr_blkaddr = le32_to_cpu(dsb->xattr_blkaddr);
 	sbi.islotbits = EROFS_ISLOTBITS;
-	memcpy(sbk->uuid, sb->uuid, 16);
-	memcpy(sbk->volume_name, sb->volume_name, 16);
-	sbk->root_nid = le16_to_cpu(sb->root_nid);
-
-	erofs_dump("%-15s:0x%X\n", STR(magic), SUPER_MEM(magic));
-	erofs_dump("%-15s:0x%X\n", STR(feature_incompat), sbi.feature_incompat);
-	erofs_dump("%-15s:0x%X\n", STR(feature_compat), SUPER_MEM(feature_compat));
-	erofs_dump("%-15s:%u\n",   STR(blkszbits), SUPER_MEM(blkszbits));
-	erofs_dump("%-15s:%u\n",   STR(root_nid), SUPER_MEM(root_nid));
-	erofs_dump("%-15s:%llu\n",  STR(inos), (unsigned long long)SUPER_MEM(inos));
-	erofs_dump("%-15s:%d\n",   STR(meta_blkaddr), SUPER_MEM(meta_blkaddr));
-	erofs_dump("%-15s:%d\n",   STR(xattr_blkaddr), SUPER_MEM(xattr_blkaddr));
+	sbi.root_nid = le16_to_cpu(dsb->root_nid);
+	sbi.inos = le64_to_cpu(dsb->inos);
+
+	sbi.build_time = le64_to_cpu(dsb->build_time);
+	sbi.build_time_nsec = le32_to_cpu(dsb->build_time_nsec);
+
+	memcpy(&sbi.uuid, dsb->uuid, sizeof(dsb->uuid));
 	return 0;
 }
 
 erofs_nid_t erofs_get_root_nid(void)
 {
-	return sbk->root_nid;
+	return sbi.root_nid;
 }
 
 erofs_nid_t addr2nid(erofs_off_t addr)
 {
-	erofs_nid_t offset = (erofs_nid_t)sbk->meta_blkaddr * EROFS_BLKSIZ;
+	erofs_nid_t offset = (erofs_nid_t)sbi.meta_blkaddr * EROFS_BLKSIZ;
 
 	DBG_BUGON(!IS_SLOT_ALIGN(addr));
 	return (addr - offset) >> EROFS_ISLOTBITS;
@@ -104,7 +98,7 @@ erofs_nid_t addr2nid(erofs_off_t addr)
 
 erofs_off_t nid2addr(erofs_nid_t nid)
 {
-	erofs_off_t offset = (erofs_off_t)sbk->meta_blkaddr * EROFS_BLKSIZ;
+	erofs_off_t offset = (erofs_off_t)sbi.meta_blkaddr * EROFS_BLKSIZ;
 
 	return (nid <<  EROFS_ISLOTBITS) + offset;
 }
fuse/init.h +1 -1
index 34085f2b548d..062cd69f6e4d 100644
@@ -13,7 +13,7 @@
 
 #define BOOT_SECTOR_SIZE	0x400
 
-int erofs_init_super(void);
+int erofs_read_superblock(void);
 erofs_nid_t erofs_get_root_nid(void);
 erofs_off_t nid2addr(erofs_nid_t nid);
 erofs_nid_t addr2nid(erofs_off_t addr);
fuse/main.c +1 -1
index 26f49f6fc299..fed4488081d8 100644
@@ -147,7 +147,7 @@ int main(int argc, char *argv[])
 		goto exit;
 	}
 
-	if (erofs_init_super()) {
+	if (erofs_read_superblock()) {
 		fprintf(stderr, "Failed to read erofs super block\n");
 		goto exit_dev;
 	}
include/erofs/internal.h +7 -0
index 54038071bf84..306005dea2a7 100644
@@ -63,6 +63,8 @@ typedef u32 erofs_blk_t;
 struct erofs_buffer_head;
 
 struct erofs_sb_info {
+	u64 blocks;
+
 	erofs_blk_t meta_blkaddr;
 	erofs_blk_t xattr_blkaddr;
 
@@ -73,6 +75,11 @@ struct erofs_sb_info {
 
 	unsigned char islotbits;
 
+	/* what we really care is nid, rather than ino.. */
+	erofs_nid_t root_nid;
+	/* used for statfs, f_files - f_favail */
+	u64 inos;
+
 	u8 uuid[16];
 };
 
Signature · 1 line
2.24.0
#7 lore raw

PATCH v3 6/12 erofs-utils: fuse: kill nid2addr, addr2nid

In reply to Gao Xiang via Linux-erofs

(will fold into the original patch.)

---
 fuse/init.c   | 15 ---------------
 fuse/init.h   |  2 --
 fuse/namei.c  |  4 ++--
 fuse/readir.c |  2 +-
 fuse/zmap.c   |  6 +++---
 5 files changed, 6 insertions(+), 23 deletions(-)
fuse/init.c +0 -15
index f3f7f9750468..b4089a204409 100644
@@ -88,21 +88,6 @@ erofs_nid_t erofs_get_root_nid(void)
 	return sbi.root_nid;
 }
 
-erofs_nid_t addr2nid(erofs_off_t addr)
-{
-	erofs_nid_t offset = (erofs_nid_t)sbi.meta_blkaddr * EROFS_BLKSIZ;
-
-	DBG_BUGON(!IS_SLOT_ALIGN(addr));
-	return (addr - offset) >> EROFS_ISLOTBITS;
-}
-
-erofs_off_t nid2addr(erofs_nid_t nid)
-{
-	erofs_off_t offset = (erofs_off_t)sbi.meta_blkaddr * EROFS_BLKSIZ;
-
-	return (nid <<  EROFS_ISLOTBITS) + offset;
-}
-
 void *erofs_init(struct fuse_conn_info *info)
 {
 	erofs_info("Using FUSE protocol %d.%d", info->proto_major, info->proto_minor);
fuse/init.h +0 -2
index 062cd69f6e4d..4bd48d18b003 100644
@@ -15,8 +15,6 @@
 
 int erofs_read_superblock(void);
 erofs_nid_t erofs_get_root_nid(void);
-erofs_off_t nid2addr(erofs_nid_t nid);
-erofs_nid_t addr2nid(erofs_off_t addr);
 void *erofs_init(struct fuse_conn_info *info);
 
 #endif
fuse/namei.c +2 -2
index 79273f89be1b..c3766f9a9f02 100644
@@ -52,7 +52,7 @@ int erofs_iget_by_nid(erofs_nid_t nid, struct erofs_vnode *vi)
 	int ret, ifmt;
 	char buf[EROFS_BLKSIZ];
 	struct erofs_inode_compact *v1;
-	const erofs_off_t addr = nid2addr(nid);
+	const erofs_off_t addr = iloc(nid);
 	const size_t size = EROFS_BLKSIZ - erofs_blkoff(addr);
 
 	ret = dev_read(buf, addr, size);
@@ -173,7 +173,7 @@ struct dcache_entry *disk_lookup(struct dcache_entry *parent, const char *name,
 
 	if (v.datalayout == EROFS_INODE_FLAT_INLINE) {
 		uint32_t dir_off = erofs_blkoff(dirsize);
-		off_t dir_addr = nid2addr(dcache_get_nid(parent)) +
+		off_t dir_addr = iloc(dcache_get_nid(parent)) +
 			v.inode_isize + v.xattr_isize;
 
 		memset(buf, 0, sizeof(buf));
fuse/readir.c +1 -1
index 8111047803df..496f4e73a9c2 100644
@@ -108,7 +108,7 @@ int erofs_readdir(const char *path, void *buf, fuse_fill_dir_t filler,
 	if (v.datalayout == EROFS_INODE_FLAT_INLINE) {
 		off_t addr;
 
-		addr = nid2addr(nid) + v.inode_isize + v.xattr_isize;
+		addr = iloc(nid) + v.inode_isize + v.xattr_isize;
 
 		memset(dirsbuf, 0, sizeof(dirsbuf));
 		ret = dev_read(dirsbuf, addr, dir_off);
fuse/zmap.c +3 -3
index 9860b770362c..cb667da4e0c8 100644
@@ -40,7 +40,7 @@ static int z_erofs_fill_inode_lazy(struct erofs_vnode *vi)
 
 	DBG_BUGON(vi->datalayout == EROFS_INODE_FLAT_COMPRESSION_LEGACY);
 
-	pos = round_up(nid2addr(vi->nid) + vi->inode_isize + vi->xattr_isize, 8);
+	pos = round_up(iloc(vi->nid) + vi->inode_isize + vi->xattr_isize, 8);
 
 	ret = dev_read(buf, pos, 8);
 	if (ret < 0)
@@ -110,7 +110,7 @@ static int legacy_load_cluster_from_disk(struct z_erofs_maprecorder *m,
 					 unsigned long lcn)
 {
 	struct erofs_vnode *const vi = m->vnode;
-	const erofs_off_t ibase = nid2addr(vi->nid);
+	const erofs_off_t ibase = iloc(vi->nid);
 	const erofs_off_t pos =
 		Z_EROFS_VLE_LEGACY_INDEX_ALIGN(ibase + vi->inode_isize +
 					       vi->xattr_isize) +
@@ -228,7 +228,7 @@ static int compacted_load_cluster_from_disk(struct z_erofs_maprecorder *m,
 {
 	struct erofs_vnode *const vi = m->vnode;
 	const unsigned int lclusterbits = vi->z_logical_clusterbits;
-	const erofs_off_t ebase = round_up(nid2addr(vi->nid) + vi->inode_isize +
+	const erofs_off_t ebase = round_up(iloc(vi->nid) + vi->inode_isize +
 					   vi->xattr_isize, 8) +
 		sizeof(struct z_erofs_map_header);
 	const unsigned int totalidx = DIV_ROUND_UP(vi->i_size, EROFS_BLKSIZ);
Signature · 1 line
2.24.0
#8 lore raw

PATCH v3 7/12 erofs-utils: fuse: kill erofs_get_root_nid()

In reply to Gao Xiang via Linux-erofs

(will fold into the original patch.)

---
 fuse/init.c | 7 +------
 fuse/init.h | 1 -
 2 files changed, 1 insertion(+), 7 deletions(-)
fuse/init.c +1 -6
index b4089a204409..d67c7f0dd298 100644
@@ -83,16 +83,11 @@ int erofs_read_superblock(void)
 	return 0;
 }
 
-erofs_nid_t erofs_get_root_nid(void)
-{
-	return sbi.root_nid;
-}
-
 void *erofs_init(struct fuse_conn_info *info)
 {
 	erofs_info("Using FUSE protocol %d.%d", info->proto_major, info->proto_minor);
 
-	if (inode_init(erofs_get_root_nid()) != 0) {
+	if (inode_init(sbi.root_nid) != 0) {
 		erofs_err("inode initialization failed");
 		abort();
 	}
fuse/init.h +0 -1
index 4bd48d18b003..f0211707b5ff 100644
@@ -14,7 +14,6 @@
 #define BOOT_SECTOR_SIZE	0x400
 
 int erofs_read_superblock(void);
-erofs_nid_t erofs_get_root_nid(void);
 void *erofs_init(struct fuse_conn_info *info);
 
 #endif
Signature · 1 line
2.24.0
#9 lore raw

PATCH v3 8/12 erofs-utils: fuse: move erofs_init() to main.c

In reply to Gao Xiang via Linux-erofs

(will fold into the original patch.)

---
 fuse/init.c | 10 ----------
 fuse/main.c | 12 ++++++++++++
 2 files changed, 12 insertions(+), 10 deletions(-)
fuse/init.c +0 -10
index d67c7f0dd298..a5694beaf519 100644
@@ -83,13 +83,3 @@ int erofs_read_superblock(void)
 	return 0;
 }
 
-void *erofs_init(struct fuse_conn_info *info)
-{
-	erofs_info("Using FUSE protocol %d.%d", info->proto_major, info->proto_minor);
-
-	if (inode_init(sbi.root_nid) != 0) {
-		erofs_err("inode initialization failed");
-		abort();
-	}
-	return NULL;
-}
fuse/main.c +12 -0
index fed4488081d8..30e4839bdcb4 100644
@@ -13,6 +13,7 @@
 
 #include "erofs/print.h"
 #include "init.h"
+#include "namei.h"
 #include "read.h"
 #include "getattr.h"
 #include "open.h"
@@ -115,6 +116,17 @@ static void signal_handle_sigsegv(int signal)
 	abort();
 }
 
+void *erofs_init(struct fuse_conn_info *info)
+{
+	erofs_info("Using FUSE protocol %d.%d", info->proto_major, info->proto_minor);
+
+	if (inode_init(sbi.root_nid) != 0) {
+		erofs_err("inode initialization failed");
+		abort();
+	}
+	return NULL;
+}
+
 static struct fuse_operations erofs_ops = {
 	.readlink = erofs_readlink,
 	.getattr = erofs_getattr,
Signature · 1 line
2.24.0
#10 lore raw

PATCH v3 9/12 erofs-utils: fuse: move superblock logic into lib/

In reply to Gao Xiang via Linux-erofs

(will fold into the original patch.)

---
 fuse/Makefile.am           |  2 +-
 fuse/init.h                | 19 -------------------
 fuse/main.c                |  1 -
 fuse/namei.c               |  1 -
 fuse/read.c                |  1 -
 fuse/readir.c              |  1 -
 fuse/zmap.c                |  1 -
 include/erofs/internal.h   |  3 +++
 lib/Makefile.am            |  2 +-
 fuse/init.c => lib/super.c |  8 +-------
 10 files changed, 6 insertions(+), 33 deletions(-)
 delete mode 100644 fuse/init.h
 rename fuse/init.c => lib/super.c (94%)
fuse/Makefile.am +1 -1
index 2b2608f57b03..f54def7a1526 100644
@@ -3,7 +3,7 @@
 
 AUTOMAKE_OPTIONS = foreign
 bin_PROGRAMS     = erofsfuse
-erofsfuse_SOURCES = main.c dentry.c getattr.c namei.c read.c init.c open.c readir.c zmap.c
+erofsfuse_SOURCES = main.c dentry.c getattr.c namei.c read.c open.c readir.c zmap.c
 erofsfuse_CFLAGS = -Wall -Werror \
                    -I$(top_srcdir)/include \
                    $(shell pkg-config fuse --cflags) \
fuse/init.h deleted +0 -19
deleted file mode 100644
index f0211707b5ff..000000000000
@@ -1,19 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0+ */
-/*
- * erofs-utils/fuse/init.h
- *
- * Created by Li Guifu <[email protected]>
- */
-#ifndef __EROFS_INIT_H
-#define __EROFS_INIT_H
-
-#include <fuse.h>
-#include <fuse_opt.h>
-#include "erofs/internal.h"
-
-#define BOOT_SECTOR_SIZE	0x400
-
-int erofs_read_superblock(void);
-void *erofs_init(struct fuse_conn_info *info);
-
-#endif
fuse/main.c +0 -1
index 30e4839bdcb4..21f8b0451732 100644
@@ -12,7 +12,6 @@
 #include <stddef.h>
 
 #include "erofs/print.h"
-#include "init.h"
 #include "namei.h"
 #include "read.h"
 #include "getattr.h"
fuse/namei.c +0 -1
index c3766f9a9f02..4c428dbc59f6 100644
@@ -17,7 +17,6 @@
 #include "erofs/print.h"
 #include "erofs/io.h"
 #include "dentry.h"
-#include "init.h"
 
 #define IS_PATH_SEPARATOR(__c)      ((__c) == '/')
 #define MINORBITS	20
fuse/read.c +0 -1
index dc88b24eaae3..10a26d84c37c 100644
@@ -16,7 +16,6 @@
 #include "erofs/print.h"
 #include "namei.h"
 #include "erofs/io.h"
-#include "init.h"
 #include "erofs/decompress.h"
 
 size_t erofs_read_data_wrapper(struct erofs_vnode *vnode, char *buffer,
fuse/readir.c +0 -1
index 496f4e73a9c2..5281c8b80e59 100644
@@ -15,7 +15,6 @@
 #include "namei.h"
 #include "erofs/io.h"
 #include "erofs/print.h"
-#include "init.h"
 
 erofs_nid_t split_entry(char *entry, off_t ofs, char *end, char *name,
 			uint32_t dirend)
fuse/zmap.c +0 -1
index cb667da4e0c8..ba5c457278a8 100644
@@ -9,7 +9,6 @@
  * Created by Gao Xiang <[email protected]>
  * Modified by Huang Jianan <[email protected]>
  */
-#include "init.h"
 #include "erofs/io.h"
 #include "erofs/print.h"
 
include/erofs/internal.h +3 -0
index 306005dea2a7..e56fd1898f3e 100644
@@ -259,6 +259,9 @@ struct erofs_map_blocks {
 	erofs_blk_t index;
 };
 
+/* super.c */
+int erofs_read_superblock(void);
+
 /* data.h */
 int erofs_read_raw_data(struct erofs_inode *inode, char *buffer,
 			erofs_off_t offset, erofs_off_t size);
lib/Makefile.am +1 -1
index 54c43897aa49..487c4944479d 100644
@@ -2,7 +2,7 @@
 # Makefile.am
 
 noinst_LTLIBRARIES = liberofs.la
-liberofs_la_SOURCES = config.c io.c cache.c inode.c xattr.c exclude.c \
+liberofs_la_SOURCES = config.c io.c cache.c super.c inode.c xattr.c exclude.c \
 		      data.c compress.c compressor.c decompress.c
 liberofs_la_CFLAGS = -Wall -Werror -I$(top_srcdir)/include
 if ENABLE_LZ4
lib/super.c renamed from fuse/init.c +1 -7
similarity index 94%
rename from fuse/init.c
rename to lib/super.c
index a5694beaf519..6213585c085d 100644
@@ -1,22 +1,16 @@
 // SPDX-License-Identifier: GPL-2.0+
 /*
- * erofs-utils/fuse/init.c
+ * erofs-utils/lib/super.c
  *
  * Created by Li Guifu <[email protected]>
  */
-#include "init.h"
 #include <string.h>
 #include <stdlib.h>
 #include <asm-generic/errno-base.h>
 
-#include "namei.h"
 #include "erofs/io.h"
 #include "erofs/print.h"
 
-#define STR(_X) (#_X)
-#define SUPER_MEM(_X) (super._X)
-
-
 struct erofs_super_block super;
 struct erofs_sb_info sbi;
 
Signature · 1 line
2.24.0
#11 lore raw

PATCH v3 10/12 erofs-utils: fuse: kill getattr.c

(will fold into the original patch.)

---
 fuse/Makefile.am |  2 +-
 fuse/getattr.c   | 65 ------------------------------------------------
 fuse/getattr.h   | 15 -----------
 fuse/main.c      | 25 ++++++++++++++++++-
 4 files changed, 25 insertions(+), 82 deletions(-)
 delete mode 100644 fuse/getattr.c
 delete mode 100644 fuse/getattr.h
fuse/Makefile.am +1 -1
index f54def7a1526..6e639f33f664 100644
@@ -3,7 +3,7 @@
 
 AUTOMAKE_OPTIONS = foreign
 bin_PROGRAMS     = erofsfuse
-erofsfuse_SOURCES = main.c dentry.c getattr.c namei.c read.c open.c readir.c zmap.c
+erofsfuse_SOURCES = main.c dentry.c namei.c read.c open.c readir.c zmap.c
 erofsfuse_CFLAGS = -Wall -Werror \
                    -I$(top_srcdir)/include \
                    $(shell pkg-config fuse --cflags) \
fuse/getattr.c deleted +0 -65

65 lines not on this page · raw message

fuse/getattr.h deleted +0 -15
deleted file mode 100644
index 735529a91d5b..000000000000
@@ -1,15 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0+ */
-/*
- * erofs-utils/fuse/getattr.h
- *
- * Created by Li Guifu <[email protected]>
- */
-#ifndef __EROFS_GETATTR_H
-#define __EROFS_GETATTR_H
-
-#include <fuse.h>
-#include <fuse_opt.h>
-
-int erofs_getattr(const char *path, struct stat *st);
-
-#endif
fuse/main.c +24 -1
index 21f8b0451732..3842fedce8c1 100644
@@ -14,7 +14,6 @@
 #include "erofs/print.h"
 #include "namei.h"
 #include "read.h"
-#include "getattr.h"
 #include "open.h"
 #include "readir.h"
 #include "erofs/io.h"
@@ -126,6 +125,30 @@ void *erofs_init(struct fuse_conn_info *info)
 	return NULL;
 }
 
+int erofs_getattr(const char *path, struct stat *stbuf)
+{
+	struct erofs_vnode v;
+	int ret;
+
+	erofs_dbg("getattr(%s)", path);
+	memset(&v, 0, sizeof(v));
+	ret = erofs_iget_by_path(path, &v);
+	if (ret)
+		return -ENOENT;
+
+	stbuf->st_mode  = v.i_mode;
+	stbuf->st_nlink = v.i_nlink;
+	stbuf->st_size  = v.i_size;
+	stbuf->st_blocks = stbuf->st_size / EROFS_BLKSIZ;
+	stbuf->st_uid = v.i_uid;
+	stbuf->st_gid = v.i_gid;
+	stbuf->st_rdev = v.i_rdev;
+	stbuf->st_atime = sbi.build_time;
+	stbuf->st_mtime = sbi.build_time;
+	stbuf->st_ctime = sbi.build_time;
+	return 0;
+}
+
 static struct fuse_operations erofs_ops = {
 	.readlink = erofs_readlink,
 	.getattr = erofs_getattr,
Signature · 1 line
2.24.0
#12 lore raw

PATCH v3 11/12 erofs-utils: fuse: kill open.c

(will fold into the original patch.)

---
 fuse/Makefile.am |  2 +-
 fuse/main.c      | 11 ++++++++++-
 fuse/open.c      | 22 ----------------------
 fuse/open.h      | 15 ---------------
 4 files changed, 11 insertions(+), 39 deletions(-)
 delete mode 100644 fuse/open.c
 delete mode 100644 fuse/open.h
fuse/Makefile.am +1 -1
index 6e639f33f664..5ff0b4d0e6ab 100644
@@ -3,7 +3,7 @@
 
 AUTOMAKE_OPTIONS = foreign
 bin_PROGRAMS     = erofsfuse
-erofsfuse_SOURCES = main.c dentry.c namei.c read.c open.c readir.c zmap.c
+erofsfuse_SOURCES = main.c dentry.c namei.c read.c readir.c zmap.c
 erofsfuse_CFLAGS = -Wall -Werror \
                    -I$(top_srcdir)/include \
                    $(shell pkg-config fuse --cflags) \
fuse/main.c +10 -1
index 3842fedce8c1..e423312d9e1a 100644
@@ -14,7 +14,6 @@
 #include "erofs/print.h"
 #include "namei.h"
 #include "read.h"
-#include "open.h"
 #include "readir.h"
 #include "erofs/io.h"
 
@@ -125,6 +124,16 @@ void *erofs_init(struct fuse_conn_info *info)
 	return NULL;
 }
 
+int erofs_open(const char *path, struct fuse_file_info *fi)
+{
+	erofs_info("open path=%s", path);
+
+	if ((fi->flags & O_ACCMODE) != O_RDONLY)
+		return -EACCES;
+
+	return 0;
+}
+
 int erofs_getattr(const char *path, struct stat *stbuf)
 {
 	struct erofs_vnode v;
fuse/open.c deleted +0 -22
deleted file mode 100644
index beb9a8615512..000000000000
@@ -1,22 +0,0 @@
-// SPDX-License-Identifier: GPL-2.0+
-/*
- * erofs-utils/fuse/open.c
- *
- * Created by Li Guifu <[email protected]>
- */
-#include "open.h"
-#include <asm-generic/errno-base.h>
-#include <fuse.h>
-#include <fuse_opt.h>
-#include "erofs/print.h"
-
-int erofs_open(const char *path, struct fuse_file_info *fi)
-{
-	erofs_info("open path=%s", path);
-
-	if ((fi->flags & O_ACCMODE) != O_RDONLY)
-		return -EACCES;
-
-	return 0;
-}
-
fuse/open.h deleted +0 -15
deleted file mode 100644
index dfc8b3cdd515..000000000000
@@ -1,15 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0+ */
-/*
- * erofs-utils/fuse/open.h
- *
- * Created by Li Guifu <[email protected]>
- */
-#ifndef __EROFS_OPEN_H
-#define __EROFS_OPEN_H
-
-#include <fuse.h>
-#include <fuse_opt.h>
-
-int erofs_open(const char *path, struct fuse_file_info *fi);
-
-#endif
Signature · 1 line
2.24.0
#13 lore raw

PATCH v3 12/12 erofs-utils: fuse: kill incomplate dcache

In reply to Gao Xiang via Linux-erofs

useless at all, use simplist bare disk lookup way for now (also libfuse has an internal dcache, we can use it as well.
plus no need to introduce dcache for unpack tool.)

(will fold into the original patch.)

---
 fuse/Makefile.am |   2 +-
 fuse/dentry.c    | 130 ----------------------------------
 fuse/dentry.h    |  43 ------------
 fuse/main.c      |   5 --
 fuse/namei.c     | 179 +++++++++++++++++++++++------------------------
 fuse/namei.h     |   5 --
 6 files changed, 88 insertions(+), 276 deletions(-)
 delete mode 100644 fuse/dentry.c
 delete mode 100644 fuse/dentry.h
fuse/Makefile.am +1 -1
index 5ff0b4d0e6ab..84e5f834d6a4 100644
@@ -3,7 +3,7 @@
 
 AUTOMAKE_OPTIONS = foreign
 bin_PROGRAMS     = erofsfuse
-erofsfuse_SOURCES = main.c dentry.c namei.c read.c readir.c zmap.c
+erofsfuse_SOURCES = main.c namei.c read.c readir.c zmap.c
 erofsfuse_CFLAGS = -Wall -Werror \
                    -I$(top_srcdir)/include \
                    $(shell pkg-config fuse --cflags) \
fuse/dentry.c deleted +0 -130

130 lines not on this page · raw message

fuse/dentry.h deleted +0 -43

43 lines not on this page · raw message

fuse/main.c +0 -5
index e423312d9e1a..563b2c378952 100644
@@ -116,11 +116,6 @@ static void signal_handle_sigsegv(int signal)
 void *erofs_init(struct fuse_conn_info *info)
 {
 	erofs_info("Using FUSE protocol %d.%d", info->proto_major, info->proto_minor);
-
-	if (inode_init(sbi.root_nid) != 0) {
-		erofs_err("inode initialization failed");
-		abort();
-	}
 	return NULL;
 }
 
fuse/namei.c +87 -92

228 lines not on this page · raw message

fuse/namei.h +0 -5
index 1803a673daaf..2625ec58d434 100644
@@ -10,13 +10,8 @@
 #include "erofs/internal.h"
 #include "erofs_fs.h"
 
-int inode_init(erofs_nid_t root);
-struct dcache_entry *get_cached_dentry(struct dcache_entry **parent,
-				       const char **path);
 int erofs_iget_by_path(const char *path, struct erofs_vnode *v);
 int erofs_iget_by_nid(erofs_nid_t nid, struct erofs_vnode *v);
-struct dcache_entry *disk_lookup(struct dcache_entry *parent, const char *name,
-		unsigned int name_len);
 int walk_path(const char *path, erofs_nid_t *out_nid);
 
 #endif
Signature · 1 line
2.24.0