[WIP] [PATCH v4 08/12] erofs-utils: fuse: kill read.c

Gao Xiang hsiangkao at aol.com
Sun Nov 15 05:25:13 AEDT 2020


Signed-off-by: Gao Xiang <hsiangkao at aol.com>
---
 fuse/Makefile.am         |  2 +-
 fuse/main.c              | 34 +++++++++++++++++++++--
 fuse/read.c              | 59 ----------------------------------------
 fuse/read.h              | 17 ------------
 include/erofs/internal.h |  6 ++--
 lib/data.c               | 24 +++++++++++++---
 lib/namei.c              |  2 +-
 7 files changed, 55 insertions(+), 89 deletions(-)
 delete mode 100644 fuse/read.c
 delete mode 100644 fuse/read.h

diff --git a/fuse/Makefile.am b/fuse/Makefile.am
index f37069ff7f12..21a1ee975141 100644
--- a/fuse/Makefile.am
+++ b/fuse/Makefile.am
@@ -3,7 +3,7 @@
 
 AUTOMAKE_OPTIONS = foreign
 bin_PROGRAMS     = erofsfuse
-erofsfuse_SOURCES = main.c read.c readir.c
+erofsfuse_SOURCES = main.c readir.c
 erofsfuse_CFLAGS = -Wall -Werror \
                    -I$(top_srcdir)/include \
                    $(shell pkg-config fuse --cflags) \
diff --git a/fuse/main.c b/fuse/main.c
index fee90154a251..9ac8149c88d9 100644
--- a/fuse/main.c
+++ b/fuse/main.c
@@ -12,7 +12,6 @@
 #include <stddef.h>
 
 #include "erofs/print.h"
-#include "read.h"
 #include "readir.h"
 #include "erofs/io.h"
 
@@ -151,12 +150,41 @@ int erofs_getattr(const char *path, struct stat *stbuf)
 	return 0;
 }
 
+static int erofsfuse_read(const char *path, char *buffer,
+			  size_t size, off_t offset,
+			  struct fuse_file_info *fi)
+{
+	int ret;
+	struct erofs_inode vi;
+
+	UNUSED(fi);
+	erofs_info("path:%s size=%zd offset=%llu", path, size, (long long)offset);
+
+	ret = erofs_ilookup(path, &vi);
+	if (ret)
+		return ret;
+
+	ret = erofs_pread(&vi, buffer, size, offset);
+	if (ret)
+		return ret;
+	return size;
+}
+
+static int erofsfuse_readlink(const char *path, char *buffer, size_t size)
+{
+	int ret = erofsfuse_read(path, buffer, size, 0, NULL);
+
+	if (ret < 0)
+		return ret;
+	return 0;
+}
+
 static struct fuse_operations erofs_ops = {
-	.readlink = erofs_readlink,
+	.readlink = erofsfuse_readlink,
 	.getattr = erofs_getattr,
 	.readdir = erofs_readdir,
 	.open = erofs_open,
-	.read = erofs_read,
+	.read = erofsfuse_read,
 	.init = erofs_init,
 };
 
diff --git a/fuse/read.c b/fuse/read.c
deleted file mode 100644
index 2ef979ddba63..000000000000
--- a/fuse/read.c
+++ /dev/null
@@ -1,59 +0,0 @@
-// SPDX-License-Identifier: GPL-2.0+
-/*
- * erofs-utils/fuse/read.c
- *
- * Created by Li Guifu <blucerlee at gmail.com>
- * Compression support by Huang Jianan <huangjianan at oppo.com>
- */
-#include "read.h"
-#include <errno.h>
-#include <linux/fs.h>
-#include <sys/stat.h>
-#include <string.h>
-
-#include "erofs/defs.h"
-#include "erofs/internal.h"
-#include "erofs/print.h"
-#include "erofs/io.h"
-#include "erofs/decompress.h"
-
-int erofs_read(const char *path, char *buffer, size_t size, off_t offset,
-	       struct fuse_file_info *fi)
-{
-	int ret;
-	struct erofs_inode vi;
-
-	UNUSED(fi);
-	erofs_info("path:%s size=%zd offset=%llu", path, size, (long long)offset);
-
-	ret = erofs_ilookup(path, &vi);
-	if (ret)
-		return ret;
-
-	erofs_info("path:%s nid=%llu mode=%u", path, vi.nid | 0ULL, vi.datalayout);
-	switch (vi.datalayout) {
-	case EROFS_INODE_FLAT_PLAIN:
-	case EROFS_INODE_FLAT_INLINE:
-		ret = erofs_read_raw_data(&vi, buffer, offset, size);
-		break;
-	case EROFS_INODE_FLAT_COMPRESSION_LEGACY:
-	case EROFS_INODE_FLAT_COMPRESSION:
-		ret = z_erofs_read_data(&vi, buffer, offset, size);
-		break;
-
-	default:
-		return -EINVAL;
-	}
-
-	return ret ? ret : size;
-}
-
-int erofs_readlink(const char *path, char *buffer, size_t size)
-{
-	int ret = erofs_read(path, buffer, size, 0, NULL);
-
-	if (ret < 0)
-		return ret;
-	return 0;
-}
-
diff --git a/fuse/read.h b/fuse/read.h
deleted file mode 100644
index e901c607dc91..000000000000
--- a/fuse/read.h
+++ /dev/null
@@ -1,17 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0+ */
-/*
- * erofs-utils/fuse/read.h
- *
- * Created by Li Guifu <blucerlee at gmail.com>
- */
-#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);
-int erofs_readlink(const char *path, char *buffer, size_t size);
-
-#endif
diff --git a/include/erofs/internal.h b/include/erofs/internal.h
index 7357ed75e3f8..13420a8e7733 100644
--- a/include/erofs/internal.h
+++ b/include/erofs/internal.h
@@ -245,10 +245,8 @@ int erofs_read_superblock(void);
 int erofs_ilookup(const char *path, struct erofs_inode *vi);
 
 /* data.c */
-int erofs_read_raw_data(struct erofs_inode *inode, char *buffer,
-			erofs_off_t offset, erofs_off_t size);
-int z_erofs_read_data(struct erofs_inode *inode, char *buffer,
-		      erofs_off_t size, erofs_off_t offset);
+int erofs_pread(struct erofs_inode *inode, char *buf,
+		erofs_off_t count, erofs_off_t offset);
 /* zmap.c */
 int z_erofs_fill_inode(struct erofs_inode *vi);
 int z_erofs_map_blocks_iter(struct erofs_inode *vi,
diff --git a/lib/data.c b/lib/data.c
index 62fd057185ee..34811e49512f 100644
--- a/lib/data.c
+++ b/lib/data.c
@@ -70,8 +70,8 @@ err_out:
 	return err;
 }
 
-int erofs_read_raw_data(struct erofs_inode *inode, char *buffer,
-			erofs_off_t offset, erofs_off_t size)
+static int erofs_read_raw_data(struct erofs_inode *inode, char *buffer,
+			       erofs_off_t size, erofs_off_t offset)
 {
 	struct erofs_map_blocks map = {
 		.index = UINT_MAX,
@@ -117,8 +117,8 @@ int erofs_read_raw_data(struct erofs_inode *inode, char *buffer,
 	return 0;
 }
 
-int z_erofs_read_data(struct erofs_inode *inode, char *buffer,
-		      erofs_off_t offset, erofs_off_t size)
+static int z_erofs_read_data(struct erofs_inode *inode, char *buffer,
+			     erofs_off_t size, erofs_off_t offset)
 {
 	int ret;
 	erofs_off_t end, length, skip;
@@ -188,3 +188,19 @@ int z_erofs_read_data(struct erofs_inode *inode, char *buffer,
 	return 0;
 }
 
+int erofs_pread(struct erofs_inode *inode, char *buf,
+		erofs_off_t count, erofs_off_t offset)
+{
+	switch (inode->datalayout) {
+	case EROFS_INODE_FLAT_PLAIN:
+	case EROFS_INODE_FLAT_INLINE:
+		return erofs_read_raw_data(inode, buf, count, offset);
+	case EROFS_INODE_FLAT_COMPRESSION_LEGACY:
+	case EROFS_INODE_FLAT_COMPRESSION:
+		return z_erofs_read_data(inode, buf, count, offset);
+	default:
+		break;
+	}
+	return -EINVAL;
+}
+
diff --git a/lib/namei.c b/lib/namei.c
index 2e024d88d93e..4e6aceb90df1 100644
--- a/lib/namei.c
+++ b/lib/namei.c
@@ -136,7 +136,7 @@ int erofs_namei(struct nameidata *nd,
 		struct erofs_dirent *de = (void *)buf;
 		unsigned int nameoff;
 
-		ret = erofs_read_raw_data(&vi, buf, offset, maxsize);
+		ret = erofs_pread(&vi, buf, maxsize, offset);
 		if (ret)
 			return ret;
 
-- 
2.24.0



More information about the Linux-erofs mailing list