erofs-utils: introduce fuse implementation
Subsystems (2)
A message that is not in the archive (sent off-list or not yet received): [email protected]
v2 cover erofs-utils: introduce fuse implementation
background & v1:
https://lore.kernel.org/r/[email protected]
changes since v1:
- fold in incremental patches in v1;
- get rid of "-Wextra" to adapt common erofs-utils code;
- get rid of duplicated logging code since fprintf is MT-safe for POSIX;
TODO:
- move fuse common code to liberofs;
- make fuse code MT-safe;
- minor cleanup.
Thanks,
Gao Xiang
Gao Xiang (2):
erofs-utils: fuse: drop "-Wextra" and "-Wno-implicit-fallthrough"
erofs-utils: fuse: get rid of duplicated logging code
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 | 17 ++ fuse/decompress.c | 83 ++++++++ fuse/decompress.h | 42 ++++ fuse/dentry.c | 130 ++++++++++++ fuse/dentry.h | 43 ++++ fuse/disk_io.c | 72 +++++++ fuse/disk_io.h | 21 ++ fuse/getattr.c | 65 ++++++ fuse/getattr.h | 15 ++ fuse/init.c | 117 +++++++++++ fuse/init.h | 24 +++ fuse/main.c | 167 ++++++++++++++++ fuse/namei.c | 242 +++++++++++++++++++++++ fuse/namei.h | 22 +++ fuse/open.c | 22 +++ fuse/open.h | 15 ++ fuse/read.c | 213 ++++++++++++++++++++ fuse/read.h | 17 ++ fuse/readir.c | 122 ++++++++++++ fuse/readir.h | 17 ++ fuse/zmap.c | 418 +++++++++++++++++++++++++++++++++++++++ include/erofs/defs.h | 16 ++ include/erofs/internal.h | 79 ++++++++ include/erofs_fs.h | 4 + 27 files changed, 2013 insertions(+), 3 deletions(-) create mode 100644 fuse/Makefile.am create mode 100644 fuse/decompress.c create mode 100644 fuse/decompress.h create mode 100644 fuse/dentry.c create mode 100644 fuse/dentry.h create mode 100644 fuse/disk_io.c create mode 100644 fuse/disk_io.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 create mode 100644 fuse/zmap.c
Signature · 1 line
2.24.0
PATCH v2 1/5 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 | 129 ++++++++++++++++++++++ fuse/dentry.h | 42 ++++++++ fuse/disk_io.c | 72 +++++++++++++ fuse/disk_io.h | 21 ++++ fuse/getattr.c | 64 +++++++++++ fuse/getattr.h | 15 +++ fuse/init.c | 98 +++++++++++++++++ fuse/init.h | 22 ++++ fuse/logging.c | 81 ++++++++++++++ fuse/logging.h | 55 ++++++++++ fuse/main.c | 170 +++++++++++++++++++++++++++++ fuse/namei.c | 227 +++++++++++++++++++++++++++++++++++++++ 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 +++++++ 25 files changed, 1407 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/disk_io.c create mode 100644 fuse/disk_io.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/logging.c create mode 100644 fuse/logging.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
@@ -3,4 +3,4 @@ ACLOCAL_AMFLAGS = -I m4 -SUBDIRS = man lib mkfs +SUBDIRS = man lib mkfs fuse
README +27 -1
@@ -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
@@ -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
@@ -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 logging.c namei.c read.c disk_io.c init.c open.c readir.c +erofsfuse_CFLAGS = -Wall -Werror -Wextra \ + -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 +129 -0
129 lines not on this page · raw message
fuse/dentry.h new file +42 -0
42 lines not on this page · raw message
fuse/disk_io.c new file +72 -0
72 lines not on this page · raw message
fuse/disk_io.h new file +21 -0
@@ -0,0 +1,21 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ +/* +* erofs-utils/fuse/disk_io.h +* +* Created by Li Guifu <[email protected]> +*/ +#ifndef __DISK_IO_H +#define __DISK_IO_H + +#include "erofs/defs.h" +#include "erofs/internal.h" + +int dev_open (const char *path); +void dev_close (void ); +int dev_read (void *buf,size_t count,off_t offset); + +static inline int dev_read_blk (void *buf,uint32_t nr) +{ +return dev_read (buf,EROFS_BLKSIZ ,blknr_to_addr (nr)); +} +#endif
fuse/getattr.c new file +64 -0
64 lines not on this page · raw message
fuse/getattr.h new file +15 -0
@@ -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 +98 -0
98 lines not on this page · raw message
fuse/init.h new file +22 -0
@@ -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/logging.c new file +81 -0
81 lines not on this page · raw message
fuse/logging.h new file +55 -0
55 lines not on this page · raw message
fuse/main.c new file +170 -0
170 lines not on this page · raw message
fuse/namei.c new file +227 -0
227 lines not on this page · raw message
fuse/namei.h new file +22 -0
@@ -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
@@ -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 "logging.h" + +int erofs_open (const char *path,struct fuse_file_info *fi) +{ +logi ("open path=%s" , path); + +if ((fi->flags &O_ACCMODE ) !=O_RDONLY ) +return -EACCES ; + +return 0 ; +} +
fuse/open.h new file +15 -0
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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 {
Signature · 1 line
2.24.0
PATCH v2 2/5 erofs-utils: fuse: add special file support
In reply to Gao Xiang via Linux-erofsFrom: 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
@@ -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
@@ -113,6 +113,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
@@ -11,6 +11,7 @@#include <stdio.h> #include <errno.h> #include <sys/stat.h> +#include <sys/sysmacros.h> #include "erofs/defs.h" #include "logging.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
@@ -111,3 +111,29 @@ int erofs_read(const char *path, char *buffer, size_t size, off_t offset,return -EINVAL ; } } + +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; + +logi ("path:%s link=%s size=%llu" , path, buffer, lnksz); +return 0 ; +}
fuse/read.h +1 -0
@@ -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
@@ -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
PATCH v2 3/5 erofs-utils: fuse: add compressed file support
In reply to Gao Xiang via Linux-erofsFrom: Huang Jianan <[email protected]>
--- fuse/Makefile.am | 8 +- fuse/decompress.c | 84 ++++++++ fuse/decompress.h | 42 ++++ fuse/dentry.h | 5 +- fuse/init.c | 22 ++- fuse/init.h | 2 + fuse/namei.c | 11 +- fuse/read.c | 78 +++++++- fuse/zmap.c | 417 +++++++++++++++++++++++++++++++++++++++ include/erofs/defs.h | 13 ++ include/erofs/internal.h | 43 +++- include/erofs_fs.h | 4 + 12 files changed, 720 insertions(+), 9 deletions(-) create mode 100644 fuse/decompress.c create mode 100644 fuse/decompress.h create mode 100644 fuse/zmap.c
fuse/Makefile.am +6 -2
@@ -3,12 +3,16 @@ AUTOMAKE_OPTIONS = foreign bin_PROGRAMS = erofsfuse -erofsfuse_SOURCES = main.c dentry.c getattr.c logging.c namei.c read.c disk_io.c init.c open.c readir.c +erofsfuse_SOURCES = main.c dentry.c getattr.c logging.c namei.c read.c disk_io.c init.c open.c readir.c zmap.c +if ENABLE_LZ4 +erofsfuse_SOURCES += decompress.c +endif erofsfuse_CFLAGS = -Wall -Werror -Wextra \ + -Wno-implicit-fallthrough \ -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/decompress.c new file +84 -0
84 lines not on this page · raw message
fuse/decompress.h new file +42 -0
42 lines not on this page · raw message
fuse/dentry.h +3 -2
@@ -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 +21 -1
@@ -17,7 +17,23 @@struct erofs_super_block super; -static struct erofs_super_block *sbk = &super; +struct erofs_super_block *sbk = &super; + +static bool check_layout_compatibility (struct erofs_super_block *sb, +struct erofs_super_block *dsb) +{ +const unsigned int feature =le32_to_cpu (dsb->feature_incompat); + + sb->feature_incompat = feature; + +/* check if current kernel meets all mandatory requirements */ +if (feature & (~EROFS_ALL_FEATURE_INCOMPAT )) { +loge ("unidentified incompatible feature %x, please upgrade kernel version" , + feature & ~EROFS_ALL_FEATURE_INCOMPAT ); +return false; + } +return true; +}int erofs_init_super (void ) {
@@ -40,6 +56,9 @@ int erofs_init_super(void)return -EINVAL ; } +if (!check_layout_compatibility (sbk, 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 +75,7 @@ int erofs_init_super(void) sbk->root_nid =le16_to_cpu (sb->root_nid);logp ("%-15s:0x%X" ,STR (magic),SUPER_MEM (magic)); +logp ("%-15s:0x%X" ,STR (feature_incompat),SUPER_MEM (feature_incompat));logp ("%-15s:0x%X" ,STR (feature_compat),SUPER_MEM (feature_compat));logp ("%-15s:%u" ,STR (blkszbits),SUPER_MEM (blkszbits));logp ("%-15s:%u" ,STR (root_nid),SUPER_MEM (root_nid));
fuse/init.h +2 -0
@@ -13,6 +13,8 @@#define BOOT_SECTOR_SIZE 0x400 +extern struct erofs_super_block *sbk; +int erofs_init_super (void );erofs_nid_t erofs_get_root_nid (void );erofs_off_t nid2addr (erofs_nid_t nid);
fuse/namei.c +10 -1
@@ -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 -2
106 lines not on this page · raw message
fuse/zmap.c new file +417 -0
417 lines not on this page · raw message
include/erofs/defs.h +13 -0
@@ -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
@@ -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))
Signature · 1 line
2.24.0
PATCH v2 4/5 erofs-utils: fuse: drop "-Wextra" and "-Wno-implicit-fallthrough"
In reply to Gao Xiang via Linux-erofs[ will be folded to the original patch. ]
--- fuse/Makefile.am | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
fuse/Makefile.am +1 -2
@@ -7,8 +7,7 @@ erofsfuse_SOURCES = main.c dentry.c getattr.c logging.c namei.c read.c disk_io.c if ENABLE_LZ4 erofsfuse_SOURCES += decompress.c endif -erofsfuse_CFLAGS = -Wall -Werror -Wextra \ - -Wno-implicit-fallthrough \ +erofsfuse_CFLAGS = -Wall -Werror \ -I$(top_srcdir)/include \ $(shell pkg-config fuse --cflags) \ -DFUSE_USE_VERSION=26 \
Signature · 1 line
2.24.0
PATCH v2 5/5 erofs-utils: fuse: get rid of duplicated logging code
In reply to Gao Xiang via Linux-erofs[ will be folded to the original patch. ]
--- fuse/Makefile.am | 2 +- fuse/decompress.c | 1 - fuse/dentry.c | 7 ++-- fuse/disk_io.c | 10 +++--- fuse/getattr.c | 4 +-- fuse/init.c | 39 +++++++++++------------ fuse/logging.c | 81 ----------------------------------------------- fuse/logging.h | 55 -------------------------------- fuse/main.c | 52 ++++++++++++++---------------- fuse/namei.c | 6 ++-- fuse/open.c | 4 +-- fuse/read.c | 22 ++++++------- fuse/readir.c | 8 ++--- fuse/zmap.c | 35 ++++++++++---------- 14 files changed, 93 insertions(+), 233 deletions(-) delete mode 100644 fuse/logging.c delete mode 100644 fuse/logging.h
fuse/Makefile.am +1 -1
@@ -3,7 +3,7 @@ AUTOMAKE_OPTIONS = foreign bin_PROGRAMS = erofsfuse -erofsfuse_SOURCES = main.c dentry.c getattr.c logging.c namei.c read.c disk_io.c init.c open.c readir.c zmap.c +erofsfuse_SOURCES = main.c dentry.c getattr.c namei.c read.c disk_io.c init.c open.c readir.c zmap.c if ENABLE_LZ4 erofsfuse_SOURCES += decompress.c endif
fuse/decompress.c +0 -1
@@ -11,7 +11,6 @@#include "erofs/internal.h" #include "erofs/err.h" #include "decompress.h" -#include "logging.h" #include "init.h" static int z_erofs_decompress_generic (struct z_erofs_decompress_req *rq)
fuse/dentry.c +4 -3
@@ -4,9 +4,10 @@* * Created by Li Guifu <[email protected]> */ +#include <stdlib.h> #include "dentry.h" #include "erofs/internal.h" -#include "logging.h" +#include "erofs/print.h" #define DCACHE_ENTRY_CALLOC () calloc(1, sizeof(struct dcache_entry))#define DCACHE_ENTRY_LIFE 8
@@ -21,7 +22,7 @@ int dcache_init_root(uint32_t nid)/* Root entry doesn't need most of the fields. Namely, it only uses the * nid field and the subdirs pointer. */ -logi ("Initializing root_entry dcache entry" ); +erofs_info ("Initializing root_entry dcache entry" ); root_entry.nid = nid; root_entry.subdirs =NULL ; root_entry.siblings =NULL ;
@@ -44,7 +45,7 @@ struct dcache_entry *dcache_insert(struct dcache_entry *parent, {struct dcache_entry *new_entry; -logd ("Inserting %s,%d to dcache" , name, namelen); +erofs_dbg ("Inserting %s,%d to dcache" , name, namelen);/* TODO: Deal with names that exceed the allocated size */ if (namelen +1 >DCACHE_ENTRY_NAME_LEN )
fuse/disk_io.c +5 -5
@@ -14,7 +14,7 @@#include <pthread.h> #include <errno.h> -#include "logging.h" +#include "erofs/print.h" #ifdef __FreeBSD__#include <string.h>
@@ -47,18 +47,18 @@ int dev_read(void *buf, size_t count, off_t offset)ssize_t pread_ret;int lerrno; -ASSERT (erofs_devfd >=0 ); +DBG_BUGON (erofs_devfd <0 );pthread_mutex_lock (&read_lock); pread_ret =pread_wrapper (erofs_devfd, buf, count, offset); lerrno = errno; -logd ("Disk Read: offset[0x%jx] count[%zd] pread_ret=%zd %s" , +erofs_dbg ("Disk Read: offset[0x%jx] count[%zd] pread_ret=%zd %s" , offset, count, pread_ret,strerror (lerrno));pthread_mutex_unlock (&read_lock);if (count ==0 ) -logw ("Read operation with 0 size" ); +erofs_warn ("Read operation with 0 size" ); -ASSERT ((size_t )pread_ret == count); +DBG_BUGON ((size_t )pread_ret != count);return pread_ret; }
fuse/getattr.c +2 -2
@@ -14,8 +14,8 @@#include "erofs/defs.h" #include "erofs/internal.h" #include "erofs_fs.h" +#include "erofs/print.h" -#include "logging.h" #include "namei.h" extern struct erofs_super_block super;
@@ -44,7 +44,7 @@ int erofs_getattr(const char *path, struct stat *stbuf)struct erofs_vnode v;int ret; -logd ("getattr(%s)" , path); +erofs_dbg ("getattr(%s)" , path);memset (&v,0 ,sizeof (v)); ret =erofs_iget_by_path (path, &v);if (ret)
fuse/init.c +19 -20
@@ -6,11 +6,12 @@*/ #include "init.h" #include <string.h> +#include <stdlib.h> #include <asm-generic/errno-base.h> #include "namei.h" #include "disk_io.h" -#include "logging.h" +#include "erofs/print.h" #define STR (_X) (#_X)#define SUPER_MEM (_X) (super._X)
@@ -28,8 +29,8 @@ static bool check_layout_compatibility(struct erofs_super_block *sb,/* check if current kernel meets all mandatory requirements */ if (feature & (~EROFS_ALL_FEATURE_INCOMPAT )) { -loge ("unidentified incompatible feature %x, please upgrade kernel version" , - feature & ~EROFS_ALL_FEATURE_INCOMPAT ); +erofs_err ("unidentified incompatible feature %x, please upgrade kernel version" , + feature & ~EROFS_ALL_FEATURE_INCOMPAT );return false; }return true;
@@ -44,15 +45,15 @@ int erofs_init_super(void)memset (buf,0 ,sizeof (buf)); ret =dev_read_blk (buf,0 );if (ret !=EROFS_BLKSIZ ) { -logi ("Failed to read super block ret=%d" , ret); +erofs_err ("Failed to read super block ret=%d" , ret);return -EINVAL ; } sb = (struct erofs_super_block *) (buf +BOOT_SECTOR_SIZE ); sbk->magic =le32_to_cpu (sb->magic);if (sbk->magic !=EROFS_SUPER_MAGIC_V1 ) { -logi ("EROFS magic[0x%X] NOT matched to [0x%X] " , - super.magic,EROFS_SUPER_MAGIC_V1 ); +erofs_err ("EROFS magic[0x%X] NOT matched to [0x%X] " , + super.magic,EROFS_SUPER_MAGIC_V1 );return -EINVAL ; }
@@ -62,7 +63,6 @@ int erofs_init_super(void) sbk->checksum =le32_to_cpu (sb->checksum); sbk->feature_compat =le32_to_cpu (sb->feature_compat); sbk->blkszbits = sb->blkszbits; -ASSERT (sbk->blkszbits !=32 ); sbk->inos =le64_to_cpu (sb->inos); sbk->build_time =le64_to_cpu (sb->build_time);
@@ -74,15 +74,14 @@ int erofs_init_super(void)memcpy (sbk->volume_name, sb->volume_name,16 ); sbk->root_nid =le16_to_cpu (sb->root_nid); -logp ("%-15s:0x%X" ,STR (magic),SUPER_MEM (magic)); -logp ("%-15s:0x%X" ,STR (feature_incompat),SUPER_MEM (feature_incompat)); -logp ("%-15s:0x%X" ,STR (feature_compat),SUPER_MEM (feature_compat)); -logp ("%-15s:%u" ,STR (blkszbits),SUPER_MEM (blkszbits)); -logp ("%-15s:%u" ,STR (root_nid),SUPER_MEM (root_nid)); -logp ("%-15s:%ul" ,STR (inos),SUPER_MEM (inos)); -logp ("%-15s:%d" ,STR (meta_blkaddr),SUPER_MEM (meta_blkaddr)); -logp ("%-15s:%d" ,STR (xattr_blkaddr),SUPER_MEM (xattr_blkaddr)); - +erofs_dump ("%-15s:0x%X\n" ,STR (magic),SUPER_MEM (magic)); +erofs_dump ("%-15s:0x%X\n" ,STR (feature_incompat),SUPER_MEM (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));return 0 ; }
@@ -95,7 +94,7 @@ erofs_nid_t addr2nid(erofs_off_t addr) {erofs_nid_t offset = (erofs_nid_t )sbk->meta_blkaddr *EROFS_BLKSIZ ; -ASSERT (IS_SLOT_ALIGN (addr)); +DBG_BUGON (!IS_SLOT_ALIGN (addr));return (addr - offset) >>EROFS_ISLOTBITS ; }
@@ -108,11 +107,11 @@ erofs_off_t nid2addr(erofs_nid_t nid)void *erofs_init (struct fuse_conn_info *info) { -logi ("Using FUSE protocol %d.%d" , info->proto_major, info->proto_minor); +erofs_info ("Using FUSE protocol %d.%d" , info->proto_major, info->proto_minor);if (inode_init (erofs_get_root_nid ()) !=0 ) { - loge("inode initialization failed") -ABORT (); +erofs_err ("inode initialization failed" ); +abort (); }return NULL ; }
fuse/logging.c deleted +0 -81
81 lines not on this page · raw message
fuse/logging.h deleted +0 -55
55 lines not on this page · raw message
fuse/main.c +24 -28
118 lines not on this page · raw message
fuse/namei.c +3 -3
@@ -14,7 +14,7 @@#include <sys/sysmacros.h> #include "erofs/defs.h" -#include "logging.h" +#include "erofs/print.h" #include "disk_io.h" #include "dentry.h" #include "init.h"
@@ -125,7 +125,7 @@ struct dcache_entry *list_name(const char *buf, struct dcache_entry *parent,memcpy (debug, d_name, name_len); debug[name_len] ='\0' ; - logi("list entry: %s nid=%u", debug, nid); + erofs_info("list entry: %s nid=%u", debug, nid); }#endif
@@ -214,7 +214,7 @@ int walk_path(const char *_path, erofs_nid_t *out_nid)if (!ret)return -ENOENT ; -logd ("find path = %s nid=%u" , _path, ret->nid); +erofs_dbg ("find path = %s nid=%u" , _path, ret->nid); *out_nid = ret->nid;return 0 ;
fuse/open.c +2 -2
@@ -8,11 +8,11 @@#include <asm-generic/errno-base.h> #include <fuse.h> #include <fuse_opt.h> -#include "logging.h" +#include "erofs/print.h" int erofs_open (const char *path,struct fuse_file_info *fi) { -logi ("open path=%s" , path); +erofs_info ("open path=%s" , path);if ((fi->flags &O_ACCMODE ) !=O_RDONLY )return -EACCES ;
fuse/read.c +11 -11
@@ -13,7 +13,7 @@#include "erofs/defs.h" #include "erofs/internal.h" -#include "logging.h" +#include "erofs/print.h" #include "namei.h" #include "disk_io.h" #include "init.h"
@@ -37,8 +37,8 @@ size_t erofs_read_data(struct erofs_vnode *vnode, char *buffer, rdsz += count; } -logi ("nid:%u size=%zd offset=%llu realsize=%zd done" , - vnode->nid, size, (long long )offset, rdsz); +erofs_info ("nid:%llu size=%zd offset=%llu realsize=%zd done" , + (unsigned long long )vnode->nid, size, (long long )offset, rdsz);return rdsz; }
@@ -73,8 +73,8 @@ size_t erofs_read_data_inline(struct erofs_vnode *vnode, char *buffer, rdsz += suminline; finished: -logi ("nid:%u size=%zd suminline=%u offset=%llu realsize=%zd done" , - vnode->nid, size, suminline, (long long )offset, rdsz); +erofs_info ("nid:%llu size=%zd suminline=%u offset=%llu realsize=%zd done" , + (unsigned long long )vnode->nid, size, (unsigned )suminline, (long long )offset, rdsz);return rdsz; }
@@ -120,7 +120,7 @@ size_t erofs_read_data_compression(struct erofs_vnode *vnode, char *buffer, length = end - map.m_la; partial = true; }else { -ASSERT (end == map.m_la + map.m_llen); +DBG_BUGON (end != map.m_la + map.m_llen); length = map.m_llen; partial = !(map.m_flags &EROFS_MAP_FULL_MAPPED ); }
@@ -146,8 +146,8 @@ size_t erofs_read_data_compression(struct erofs_vnode *vnode, char *buffer,return ret; } -logi ("nid:%u size=%zd offset=%llu done" , - vnode->nid, size, (long long )offset); +erofs_info ("nid:%llu size=%zd offset=%llu done" , + (unsigned long long )vnode->nid, size, (long long )offset);return size; }
@@ -159,7 +159,7 @@ int erofs_read(const char *path, char *buffer, size_t size, off_t offset,struct erofs_vnode v;UNUSED (fi); -logi ("path:%s size=%zd offset=%llu" , path, size, (long long )offset); +erofs_info ("path:%s size=%zd offset=%llu" , path, size, (long long )offset); ret =walk_path (path, &nid);if (ret)
@@ -169,7 +169,7 @@ int erofs_read(const char *path, char *buffer, size_t size, off_t offset,if (ret)return ret; -logi ("path:%s nid=%llu mode=%u" , path, nid, v.datalayout); +erofs_info ("path:%s nid=%llu mode=%u" , path, (unsigned long long )nid, v.datalayout);switch (v.datalayout) {case EROFS_INODE_FLAT_PLAIN :return erofs_read_data (&v, buffer, size, offset);
@@ -208,6 +208,6 @@ int erofs_readlink(const char *path, char *buffer, size_t size)if (ret != (int )lnksz)return ret; -logi ("path:%s link=%s size=%llu" , path, buffer, lnksz); +erofs_info ("path:%s link=%s size=%llu" , path, buffer, (unsigned long long )lnksz);return 0 ; }
fuse/readir.c +4 -4
@@ -14,7 +14,7 @@#include "erofs_fs.h" #include "namei.h" #include "disk_io.h" -#include "logging.h" +#include "erofs/print.h" #include "init.h" erofs_nid_t split_entry(char *entry, off_t ofs, char *end, char *name,
@@ -72,14 +72,14 @@ int erofs_readdir(const char *path, void *buf, fuse_fill_dir_t filler,char dirsbuf[EROFS_BLKSIZ ];uint32_t dir_nr, dir_off, nr_cnt; -logd ("readdir:%s offset=%llu" , path, (long long )offset); +erofs_dbg ("readdir:%s offset=%llu" , path, (long long )offset);UNUSED (fi); ret =walk_path (path, &nid);if (ret)return ret; -logd ("path=%s nid = %u" , path, nid); +erofs_dbg ("path=%s nid = %llu" , path, (unsigned long long )nid); ret =erofs_iget_by_nid (nid, &v);if (ret)return ret;
@@ -94,7 +94,7 @@ int erofs_readdir(const char *path, void *buf, fuse_fill_dir_t filler, dir_off =erofs_blkoff (v.i_size); nr_cnt =0 ; -logd ("dir_size=%u dir_nr = %u dir_off=%u" , v.i_size, dir_nr, dir_off); +erofs_dbg ("dir_size=%u dir_nr = %u dir_off=%u" , v.i_size, dir_nr, dir_off);while (nr_cnt < dir_nr) {memset (dirsbuf,0 ,sizeof (dirsbuf));
fuse/zmap.c +18 -17
@@ -11,7 +11,7 @@*/ #include "init.h" #include "disk_io.h" -#include "logging.h" +#include "erofs/print.h" int z_erofs_fill_inode (struct erofs_vnode *vi) {
@@ -52,8 +52,8 @@ static int z_erofs_fill_inode_lazy(struct erofs_vnode *vi) vi->z_algorithmtype[1 ] = h->h_algorithmtype >>4 ;if (vi->z_algorithmtype[0 ] >=Z_EROFS_COMPRESSION_MAX ) { -loge ("unknown compression format %u for nid %llu" , - vi->z_algorithmtype[0 ], vi->nid); +erofs_err ("unknown compression format %u for nid %llu" , + vi->z_algorithmtype[0 ], (unsigned long long )vi->nid);return -EOPNOTSUPP ; }
@@ -62,8 +62,8 @@ static int z_erofs_fill_inode_lazy(struct erofs_vnode *vi) ((h->h_clusterbits >>3 ) &3 );if (vi->z_physical_clusterbits[0 ] !=LOG_BLOCK_SIZE ) { -loge ("unsupported physical clusterbits %u for nid %llu" , - vi->z_physical_clusterbits[0 ], vi->nid); +erofs_err ("unsupported physical clusterbits %u for nid %llu" , + vi->z_physical_clusterbits[0 ], (unsigned long long )vi->nid);return -EOPNOTSUPP ; }
@@ -301,7 +301,8 @@ static int z_erofs_extent_lookback(struct z_erofs_maprecorder *m,int err;if (lcn < lookback_distance) { -loge ("bogus lookback distance @ nid %llu" , vi->nid); +erofs_err ("bogus lookback distance @ nid %llu" , + (unsigned long long )vi->nid);DBG_BUGON (1 );return -EFSCORRUPTED ; }
@@ -315,8 +316,8 @@ static int z_erofs_extent_lookback(struct z_erofs_maprecorder *m,switch (m->type) {case Z_EROFS_VLE_CLUSTER_TYPE_NONHEAD :if (!m->delta[0 ]) { -loge ("invalid lookback distance 0 @ nid %llu" , - vi->nid); +erofs_err ("invalid lookback distance 0 @ nid %llu" , + (unsigned long long )vi->nid);DBG_BUGON (1 );return -EFSCORRUPTED ; }
@@ -327,8 +328,8 @@ static int z_erofs_extent_lookback(struct z_erofs_maprecorder *m, map->m_la = (lcn << lclusterbits) | m->clusterofs;break ;default : -loge ("unknown type %u @ lcn %lu of nid %llu" , - m->type, lcn, vi->nid); +erofs_err ("unknown type %u @ lcn %lu of nid %llu" , + m->type, lcn, (unsigned long long )vi->nid);DBG_BUGON (1 );return -EOPNOTSUPP ; }
@@ -381,8 +382,8 @@ int z_erofs_map_blocks_iter(struct erofs_vnode *vi, }/* m.lcn should be >= 1 if endoff < m.clusterofs */ if (!m.lcn) { -loge ("invalid logical cluster 0 at nid %llu" , - vi->nid); +erofs_err ("invalid logical cluster 0 at nid %llu" , + (unsigned long long )vi->nid); err = -EFSCORRUPTED ; goto out; }
@@ -396,8 +397,8 @@ int z_erofs_map_blocks_iter(struct erofs_vnode *vi, goto out;break ;default : -loge ("unknown type %u @ offset %llu of nid %llu" , - m.type, ofs, vi->nid); +erofs_err ("unknown type %u @ offset %llu of nid %llu" , + m.type, ofs, (unsigned long long )vi->nid); err = -EOPNOTSUPP ; goto out; }
@@ -408,9 +409,9 @@ int z_erofs_map_blocks_iter(struct erofs_vnode *vi, map->m_flags |=EROFS_MAP_MAPPED ; out: -logd ("m_la %llu m_pa %llu m_llen %llu m_plen %llu m_flags 0%o" , - map->m_la, map->m_pa, - map->m_llen, map->m_plen, map->m_flags); +erofs_dbg ("m_la %" PRIu64" m_pa %" PRIu64" m_llen %" PRIu64" m_plen %" PRIu64" m_flags 0%o" , + map->m_la, map->m_pa, + map->m_llen, map->m_plen, map->m_flags);DBG_BUGON (err <0 && err != -ENOMEM );return err;
Signature · 1 line
2.24.0
[WIP] [PATCH 6/5] erofs-utils: fuse: get rid of duplicated I/O ops
[ will be folded to the original patch. ]
--- fuse/Makefile.am | 2 +- fuse/disk_io.c | 72 ---------------------------------------------- fuse/disk_io.h | 21 -------------- fuse/init.c | 6 ++-- fuse/main.c | 4 +-- fuse/namei.c | 13 +++++---- fuse/read.c | 18 ++++++------ fuse/readir.c | 10 +++---- fuse/zmap.c | 10 +++---- include/erofs/io.h | 1 + lib/io.c | 16 +++++++++++ 11 files changed, 49 insertions(+), 124 deletions(-) delete mode 100644 fuse/disk_io.c delete mode 100644 fuse/disk_io.h
fuse/Makefile.am +1 -1
@@ -3,7 +3,7 @@ AUTOMAKE_OPTIONS = foreign bin_PROGRAMS = erofsfuse -erofsfuse_SOURCES = main.c dentry.c getattr.c namei.c read.c disk_io.c init.c open.c readir.c zmap.c +erofsfuse_SOURCES = main.c dentry.c getattr.c namei.c read.c init.c open.c readir.c zmap.c if ENABLE_LZ4 erofsfuse_SOURCES += decompress.c endif
fuse/disk_io.c deleted +0 -72
72 lines not on this page · raw message
fuse/disk_io.h deleted +0 -21
@@ -1,21 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0+ */ -/* -* erofs-utils/fuse/disk_io.h -* -* Created by Li Guifu <[email protected]> -*/ -#ifndef __DISK_IO_H -#define __DISK_IO_H - -#include "erofs/defs.h" -#include "erofs/internal.h" - -int dev_open (const char *path); -void dev_close (void ); -int dev_read (void *buf,size_t count,off_t offset); - -static inline int dev_read_blk (void *buf,uint32_t nr) -{ -return dev_read (buf,EROFS_BLKSIZ ,blknr_to_addr (nr)); -} -#endif
fuse/init.c +3 -3
@@ -10,7 +10,7 @@#include <asm-generic/errno-base.h> #include "namei.h" -#include "disk_io.h" +#include "erofs/io.h" #include "erofs/print.h" #define STR (_X) (#_X)
@@ -43,8 +43,8 @@ int erofs_init_super(void)struct erofs_super_block *sb;memset (buf,0 ,sizeof (buf)); - ret =dev_read_blk (buf,0 ); -if (ret !=EROFS_BLKSIZ ) { + ret =blk_read (buf,0 ,1 ); +if (ret <0 ) {erofs_err ("Failed to read super block ret=%d" , ret);return -EINVAL ; }
fuse/main.c +2 -2
@@ -17,7 +17,7 @@#include "getattr.h" #include "open.h" #include "readir.h" -#include "disk_io.h" +#include "erofs/io.h" /* XXX: after liberofs is linked in, it should be removed */ struct erofs_configure cfg;
@@ -142,7 +142,7 @@ int main(int argc, char *argv[]) cfg.c_dbg_lvl = fusecfg.debug_lvl; -if (dev_open (fusecfg.disk) <0 ) { +if (dev_open_ro (fusecfg.disk) <0 ) {fprintf (stderr,"Failed to open disk:%s\n" , fusecfg.disk); goto exit; }
fuse/namei.c +7 -6
@@ -15,7 +15,7 @@#include "erofs/defs.h" #include "erofs/print.h" -#include "disk_io.h" +#include "erofs/io.h" #include "dentry.h" #include "init.h"
@@ -55,8 +55,8 @@ int erofs_iget_by_nid(erofs_nid_t nid, struct erofs_vnode *vi)const erofs_off_t addr =nid2addr (nid);const size_t size =EROFS_BLKSIZ -erofs_blkoff (addr); - ret =dev_read (buf, size, addr); -if (ret != (int )size) + ret =dev_read (buf, addr, size); +if (ret <0 )return -EIO ; v1 = (struct erofs_inode_compact *)buf;
@@ -160,7 +160,8 @@ struct dcache_entry *disk_lookup(struct dcache_entry *parent, const char *name, nr_cnt =0 ;while (nr_cnt < dir_nr) { -if (dev_read_blk (buf, blkno + nr_cnt) !=EROFS_BLKSIZ ) + ret =blk_read (buf, blkno + nr_cnt,1 ); +if (ret <0 )return NULL ; entry =list_name (buf, parent, name, name_len,EROFS_BLKSIZ );
@@ -176,8 +177,8 @@ struct dcache_entry *disk_lookup(struct dcache_entry *parent, const char *name, v.inode_isize + v.xattr_isize;memset (buf,0 ,sizeof (buf)); - ret =dev_read (buf, dir_off, dir_addr); -if (ret <0 && (uint32_t )ret != dir_off) + ret =dev_read (buf, dir_addr, dir_off); +if (ret <0 )return NULL ; entry =list_name (buf, parent, name, name_len, dir_off);
fuse/read.c +9 -9
@@ -15,7 +15,7 @@#include "erofs/internal.h" #include "erofs/print.h" #include "namei.h" -#include "disk_io.h" +#include "erofs/io.h" #include "init.h" #include "decompress.h"
@@ -31,8 +31,8 @@ size_t erofs_read_data(struct erofs_vnode *vnode, char *buffer,while (rdsz < sum) {size_t count =min (EROFS_BLKSIZ , (uint32_t )(sum - rdsz)); - ret =dev_read (buffer + rdsz, count, addr + rdsz); -if (ret <0 || (size_t )ret != count) + ret =dev_read (buffer + rdsz, addr + rdsz, count); +if (ret <0 )return -EIO ; rdsz += count; }
@@ -57,8 +57,8 @@ size_t erofs_read_data_inline(struct erofs_vnode *vnode, char *buffer,while (rdsz < sum) {size_t count =min (EROFS_BLKSIZ , (uint32_t )(sum - rdsz)); - ret =dev_read (buffer + rdsz, count, addr + rdsz); -if (ret <0 || (uint32_t )ret != count) + ret =dev_read (buffer + rdsz, addr + rdsz, count); +if (ret <0 )return -EIO ; rdsz += count; }
@@ -67,8 +67,8 @@ size_t erofs_read_data_inline(struct erofs_vnode *vnode, char *buffer, goto finished; addr =nid2addr (vnode->nid) + vnode->inode_isize + vnode->xattr_isize; - ret =dev_read (buffer + rdsz, suminline, addr); -if (ret <0 || (size_t )ret != suminline) + ret =dev_read (buffer + rdsz, addr, suminline); +if (ret <0 )return -EIO ; rdsz += suminline;
@@ -104,8 +104,8 @@ size_t erofs_read_data_compression(struct erofs_vnode *vnode, char *buffer,continue ; } - ret =dev_read (raw,EROFS_BLKSIZ , map.m_pa); -if (ret <0 || (size_t )ret !=EROFS_BLKSIZ ) + ret =dev_read (raw, map.m_pa,EROFS_BLKSIZ ); +if (ret <0 )return -EIO ; algorithmformat = map.m_flags & EROFS_MAP_ZIPPED ?
fuse/readir.c +5 -5
@@ -13,7 +13,7 @@#include "erofs/internal.h" #include "erofs_fs.h" #include "namei.h" -#include "disk_io.h" +#include "erofs/io.h" #include "erofs/print.h" #include "init.h"
@@ -98,8 +98,8 @@ int erofs_readdir(const char *path, void *buf, fuse_fill_dir_t filler,while (nr_cnt < dir_nr) {memset (dirsbuf,0 ,sizeof (dirsbuf)); - ret =dev_read_blk (dirsbuf, v.raw_blkaddr + nr_cnt); -if (ret !=EROFS_BLKSIZ ) + ret =blk_read (dirsbuf, v.raw_blkaddr + nr_cnt,1 ); +if (ret <0 )return -EIO ;fill_dir (dirsbuf, filler, buf,EROFS_BLKSIZ ); ++nr_cnt;
@@ -111,8 +111,8 @@ int erofs_readdir(const char *path, void *buf, fuse_fill_dir_t filler, addr =nid2addr (nid) + v.inode_isize + v.xattr_isize;memset (dirsbuf,0 ,sizeof (dirsbuf)); - ret =dev_read (dirsbuf, dir_off, addr); -if (ret <0 || (uint32_t )ret != dir_off) + ret =dev_read (dirsbuf, addr, dir_off); +if (ret <0 )return -EIO ;fill_dir (dirsbuf, filler, buf, dir_off); }
fuse/zmap.c +5 -5
@@ -10,7 +10,7 @@* Modified by Huang Jianan <[email protected]> */ #include "init.h" -#include "disk_io.h" +#include "erofs/io.h" #include "erofs/print.h" int z_erofs_fill_inode (struct erofs_vnode *vi)
@@ -42,8 +42,8 @@ static int z_erofs_fill_inode_lazy(struct erofs_vnode *vi) pos =round_up (nid2addr (vi->nid) + vi->inode_isize + vi->xattr_isize,8 ); - ret =dev_read (buf,8 , pos); -if (ret <0 && (uint32_t )ret !=8 ) + ret =dev_read (buf, pos,8 ); +if (ret <0 )return -EIO ; h = (struct z_erofs_map_header *)buf;
@@ -97,8 +97,8 @@ static int z_erofs_reload_indexes(struct z_erofs_maprecorder *m,if (map->index == eblk)return 0 ; - ret =dev_read (mpage,EROFS_BLKSIZ ,blknr_to_addr (eblk)); -if (ret <0 && (uint32_t )ret !=EROFS_BLKSIZ ) + ret =blk_read (mpage, eblk,1 ); +if (ret <0 )return -EIO ; map->index = eblk;
include/erofs/io.h +1 -0
@@ -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
@@ -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
[WIP] [PATCH 7/5] erofs-utils: fuse: move feature_incompat to sbi
In preparation to move decompress.c to lib/,
move feature_incompat to sbi only.
Laterly, sbk needs to be completely dropped.
--- fuse/decompress.c | 2 +- fuse/init.c | 12 +++++++----- fuse/init.h | 2 -- 3 files changed, 8 insertions(+), 8 deletions(-)
fuse/decompress.c +1 -1
@@ -22,7 +22,7 @@ static int z_erofs_decompress_generic(struct z_erofs_decompress_req *rq)bool support_0padding = false;unsigned int inputmargin =0 ; -if (sbk->feature_incompat &EROFS_FEATURE_INCOMPAT_LZ4_0PADDING ) { +if (erofs_sb_has_lz4_0padding ()) { support_0padding = true;while (!src[inputmargin & ~PAGE_MASK ])
fuse/init.c +7 -5
@@ -18,14 +18,16 @@struct erofs_super_block super; -struct erofs_super_block *sbk = &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_super_block *sb, +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); - sb->feature_incompat = feature; + sbi->feature_incompat = feature;/* check if current kernel meets all mandatory requirements */ if (feature & (~EROFS_ALL_FEATURE_INCOMPAT )) {
@@ -57,7 +59,7 @@ int erofs_init_super(void)return -EINVAL ; } -if (!check_layout_compatibility (sbk, sb)) +if (!check_layout_compatibility (&sbi, sb))return -EINVAL ; sbk->checksum =le32_to_cpu (sb->checksum);
@@ -75,7 +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),SUPER_MEM (feature_incompat)); +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/init.h +0 -2
@@ -13,8 +13,6 @@#define BOOT_SECTOR_SIZE 0x400 -extern struct erofs_super_block *sbk; -int erofs_init_super (void );erofs_nid_t erofs_get_root_nid (void );erofs_off_t nid2addr (erofs_nid_t nid);
Signature · 1 line
2.24.0
[WIP] [PATCH 8/5] erofs-utils: fuse: move decompress backend to lib
In reply to Gao Xiang via Linux-erofs---
fuse/Makefile.am | 3 ---
fuse/read.c | 2 +-
{fuse => include/erofs}/decompress.h | 11 ++---------
lib/Makefile.am | 4 ++--
{fuse => lib}/decompress.c | 16 ++++++++++------
5 files changed, 15 insertions(+), 21 deletions(-)
rename {fuse => include/erofs}/decompress.h (80%)
rename {fuse => lib}/decompress.c (84%)fuse/Makefile.am +0 -3
@@ -4,9 +4,6 @@ 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 -if ENABLE_LZ4 -erofsfuse_SOURCES += decompress.c -endif erofsfuse_CFLAGS = -Wall -Werror \ -I$(top_srcdir)/include \ $(shell pkg-config fuse --cflags) \
fuse/read.c +1 -1
@@ -17,7 +17,7 @@#include "namei.h" #include "erofs/io.h" #include "init.h" -#include "decompress.h" +#include "erofs/decompress.h" size_t erofs_read_data (struct erofs_vnode *vnode,char *buffer,size_t size,off_t offset)
include/erofs/decompress.h renamed from fuse/decompress.h +2 -9
@@ -1,6 +1,6 @@/* SPDX-License-Identifier: GPL-2.0+ */ /* -* erofs-utils/fuse/decompress.h +* erofs-utils/include/erofs/decompress.h * * Copyright (C), 2008-2020, OPPO Mobile Comm Corp., Ltd. * Created by Huang Jianan <[email protected]>
@@ -8,7 +8,7 @@#ifndef __EROFS_DECOMPRESS_H#define __EROFS_DECOMPRESS_H -#include "erofs/internal.h" +#include "internal.h" enum { Z_EROFS_COMPRESSION_SHIFTED = Z_EROFS_COMPRESSION_MAX,
@@ -30,13 +30,6 @@ struct z_erofs_decompress_req { bool partial_decoding; }; -#ifdef LZ4_ENABLED int z_erofs_decompress (struct z_erofs_decompress_req *rq); -#else -int z_erofs_decompress (struct z_erofs_decompress_req *rq) -{ -return -EOPNOTSUPP ; -} -#endif #endif
lib/Makefile.am +2 -2
@@ -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 renamed from fuse/decompress.c +10 -6
@@ -1,6 +1,6 @@// SPDX-License-Identifier: GPL-2.0+ /* -* erofs-utils/fuse/decompress.c +* erofs-utils/lib/decompress.c * * Copyright (C), 2008-2020, OPPO Mobile Comm Corp., Ltd. * Created by Huang Jianan <[email protected]>
@@ -8,12 +8,11 @@#include <stdlib.h> #include <lz4.h> -#include "erofs/internal.h" +#include "erofs/decompress.h" #include "erofs/err.h" -#include "decompress.h" -#include "init.h" -static int z_erofs_decompress_generic (struct z_erofs_decompress_req *rq) +#ifdef LZ4_ENABLED +static int z_erofs_decompress_lz4 (struct z_erofs_decompress_req *rq) {int ret =0 ;char *dest = rq->out;
@@ -64,6 +63,7 @@ out: return ret; } +#endif int z_erofs_decompress (struct z_erofs_decompress_req *rq) {
@@ -79,5 +79,9 @@ int z_erofs_decompress(struct z_erofs_decompress_req *rq)return 0 ; } -return z_erofs_decompress_generic (rq); +#ifdef LZ4_ENABLED +if (rq->alg ==Z_EROFS_COMPRESSION_LZ4 ) +return z_erofs_decompress_lz4 (rq); +#endif +return -EOPNOTSUPP ; }
Signature · 1 line
2.24.0