From: Gao Xiang <xiang@kernel.org>
To: linux-erofs@lists.ozlabs.org
Cc: Kelvin Zhang <zhangkelvin@google.com>,
Gao Xiang <hsiangkao@linux.alibaba.com>
Subject: [PATCH v4] erofs-utils: lib: Add API to get on disk size of an inode
Date: Wed, 22 Dec 2021 10:08:22 +0800 [thread overview]
Message-ID: <20211222020822.14156-1-xiang@kernel.org> (raw)
From: Kelvin Zhang <zhangkelvin@google.com>
Marginally improve code re-use. It's quite common for users to query for
compressed size of an inode.
Signed-off-by: Kelvin Zhang <zhangkelvin@google.com>
Signed-off-by: Gao Xiang <hsiangkao@linux.alibaba.com>
---
Hi Kelvin,
I've removed the print message of API, and return -ENOTSUP instead.
Please check out if it's fine with you.
Thanks,
Gao Xiang
dump/main.c | 6 +++---
include/erofs/internal.h | 21 +++++++++++++++++++++
2 files changed, 24 insertions(+), 3 deletions(-)
diff --git a/dump/main.c b/dump/main.c
index 97c8750d40f1..9d05d89b4436 100644
--- a/dump/main.c
+++ b/dump/main.c
@@ -176,7 +176,7 @@ static int erofsdump_parse_options_cfg(int argc, char **argv)
return 0;
}
-static int erofs_get_occupied_size(struct erofs_inode *inode,
+static int erofsdump_get_occupied_size(struct erofs_inode *inode,
erofs_off_t *size)
{
*size = 0;
@@ -194,7 +194,7 @@ static int erofs_get_occupied_size(struct erofs_inode *inode,
break;
default:
erofs_err("unknown datalayout");
- return -1;
+ return -ENOTSUP;
}
return 0;
}
@@ -270,7 +270,7 @@ static int erofsdump_readdir(struct erofs_dir_context *ctx)
stats.files++;
stats.file_category_stat[erofs_mode_to_ftype(vi.i_mode)]++;
- err = erofs_get_occupied_size(&vi, &occupied_size);
+ err = erofsdump_get_occupied_size(&vi, &occupied_size);
if (err) {
erofs_err("get file size failed");
return err;
diff --git a/include/erofs/internal.h b/include/erofs/internal.h
index d2adf57d8ae2..2c7b611e811f 100644
--- a/include/erofs/internal.h
+++ b/include/erofs/internal.h
@@ -320,6 +320,27 @@ int erofs_pread(struct erofs_inode *inode, char *buf,
int erofs_map_blocks(struct erofs_inode *inode,
struct erofs_map_blocks *map, int flags);
int erofs_map_dev(struct erofs_sb_info *sbi, struct erofs_map_dev *map);
+
+static inline int erofs_get_occupied_size(const struct erofs_inode *inode,
+ erofs_off_t *size)
+{
+ *size = 0;
+ switch (inode->datalayout) {
+ case EROFS_INODE_FLAT_INLINE:
+ case EROFS_INODE_FLAT_PLAIN:
+ case EROFS_INODE_CHUNK_BASED:
+ *size = inode->i_size;
+ break;
+ case EROFS_INODE_FLAT_COMPRESSION_LEGACY:
+ case EROFS_INODE_FLAT_COMPRESSION:
+ *size = inode->u.i_blocks * EROFS_BLKSIZ;
+ break;
+ default:
+ return -ENOTSUP;
+ }
+ return 0;
+}
+
/* zmap.c */
int z_erofs_fill_inode(struct erofs_inode *vi);
int z_erofs_map_blocks_iter(struct erofs_inode *vi,
--
2.20.1
reply other threads:[~2021-12-22 2:09 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20211222020822.14156-1-xiang@kernel.org \
--to=xiang@kernel.org \
--cc=hsiangkao@linux.alibaba.com \
--cc=linux-erofs@lists.ozlabs.org \
--cc=zhangkelvin@google.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.