All of lore.kernel.org
 help / color / mirror / Atom feed
From: Gao Xiang via Linux-erofs <linux-erofs@lists.ozlabs.org>
To: linux-erofs@lists.ozlabs.org
Cc: Zhang Shiming <zhangshiming@oppo.com>, Guo Weichao <guoweichao@oppo.com>
Subject: [WIP] [PATCH 02/12] erofs-utils: fuse: support read special file
Date: Sat, 17 Oct 2020 13:16:11 +0800	[thread overview]
Message-ID: <20201017051621.7810-3-hsiangkao@aol.com> (raw)
In-Reply-To: <20201017051621.7810-1-hsiangkao@aol.com>

From: Huang Jianan <huangjianan@oppo.com>

Signed-off-by: Huang Jianan <huangjianan@oppo.com>
Signed-off-by: Guo Weichao <guoweichao@oppo.com>
Signed-off-by: Gao Xiang <hsiangkao@aol.com>
---
 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(-)

diff --git a/fuse/getattr.c b/fuse/getattr.c
index 542cf35f6989..d2134f486e19 100644
--- a/fuse/getattr.c
+++ b/fuse/getattr.c
@@ -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;
diff --git a/fuse/main.c b/fuse/main.c
index fa9795ef1615..884101374bcf 100644
--- a/fuse/main.c
+++ b/fuse/main.c
@@ -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,
diff --git a/fuse/namei.c b/fuse/namei.c
index 3503a8d56e15..7ed1168fc14f 100644
--- a/fuse/namei.c
+++ b/fuse/namei.c
@@ -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:
diff --git a/fuse/read.c b/fuse/read.c
index ffe976e59a11..3ce5c4f2911e 100644
--- a/fuse/read.c
+++ b/fuse/read.c
@@ -112,3 +112,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;
+}
\ No newline at end of file
diff --git a/fuse/read.h b/fuse/read.h
index f2fcebec9d07..89d4b4cd600c 100644
--- a/fuse/read.h
+++ b/fuse/read.h
@@ -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
diff --git a/include/erofs/internal.h b/include/erofs/internal.h
index cba3ce4695d4..47ad96d0488c 100644
--- a/include/erofs/internal.h
+++ b/include/erofs/internal.h
@@ -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;
-- 
2.24.0


  parent reply	other threads:[~2020-10-17  5:17 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20201017051621.7810-1-hsiangkao.ref@aol.com>
2020-10-17  5:16 ` [WIP] [PATCH 00/12] erofs-utils: introduce fuse implementation Gao Xiang via Linux-erofs
2020-10-17  5:16   ` [WIP] [PATCH 01/12] " Gao Xiang via Linux-erofs
2020-10-17  5:16   ` Gao Xiang via Linux-erofs [this message]
2020-10-17  5:16   ` [WIP] [PATCH 03/12] erofs-utils: fuse: support read compressed file Gao Xiang via Linux-erofs
2020-10-17  5:16   ` [WIP] [PATCH 04/12] erofs-utils: fuse: adjust larger extent handling Gao Xiang via Linux-erofs
2020-10-19  3:13     ` 回复: " huangjianan
2020-10-19  3:32       ` Gao Xiang via Linux-erofs
2020-10-19  4:49         ` 回复: " Huang Jianan
2020-10-19  3:37     ` 回复: " Huang Jianan
2020-10-19  3:43       ` Gao Xiang via Linux-erofs
2020-10-17  5:16   ` [WIP] [PATCH 05/12] erofs-utils: fuse: use proper expression about inode size Gao Xiang via Linux-erofs
2020-10-17  5:16   ` [WIP] [PATCH 06/12] erofs-utils: fuse: drop ofs_out Gao Xiang via Linux-erofs
2020-10-17  5:16   ` [WIP] [PATCH 07/12] erofs-utils: fuse: refuse a undefined shifted cluster behavior Gao Xiang via Linux-erofs
2020-10-17  5:16   ` [WIP] [PATCH 08/12] erofs-utils: fuse: drop z_erofs_shifted_transform() Gao Xiang via Linux-erofs
2020-10-17  5:16   ` [WIP] [PATCH 09/12] erofs-utils: fuse: rename ofs_head and outputsize Gao Xiang via Linux-erofs
2020-10-17  5:16   ` [WIP] [PATCH 10/12] erofs-utils: fuse: cleanup erofs_read_data_compression() Gao Xiang via Linux-erofs
2020-10-17  5:16   ` [WIP] [PATCH 11/12] erofs-utils: fuse: move up mpage in struct erofs_map_blocks Gao Xiang via Linux-erofs
2020-10-17  5:16   ` [WIP] [PATCH 12/12] erofs-utils: fuse: fix up source headers Gao Xiang via Linux-erofs

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20201017051621.7810-3-hsiangkao@aol.com \
    --to=linux-erofs@lists.ozlabs.org \
    --cc=guoweichao@oppo.com \
    --cc=hsiangkao@aol.com \
    --cc=zhangshiming@oppo.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.