All of lore.kernel.org
 help / color / mirror / Atom feed
From: Kelvin Zhang via Linux-erofs <linux-erofs@lists.ozlabs.org>
To: linux-erofs mailing list <linux-erofs@lists.ozlabs.org>,
	Miao Xie <miaoxie@huawei.com>, Fang Wei <fangwei1@huawei.com>
Cc: Kelvin Zhang <zhangkelvin@google.com>
Subject: [PATCH v1 2/2] Add API to get on disk size of an inode
Date: Tue, 21 Dec 2021 06:28:29 -0800	[thread overview]
Message-ID: <20211221142829.4123631-2-zhangkelvin@google.com> (raw)
In-Reply-To: <20211221142829.4123631-1-zhangkelvin@google.com>

Change-Id: I60fa9346737b14418bd3fa1d12f760aaf0a0cca5
Signed-off-by: Kelvin Zhang <zhangkelvin@google.com>
---
 dump/main.c              |  4 ++--
 include/erofs/internal.h |  2 ++
 lib/data.c               | 21 +++++++++++++++++++++
 3 files changed, 25 insertions(+), 2 deletions(-)

diff --git a/dump/main.c b/dump/main.c
index 71b44b4..cdde561 100644
--- a/dump/main.c
+++ b/dump/main.c
@@ -175,7 +175,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 dump_get_occupied_size(struct erofs_inode *inode,
 		erofs_off_t *size)
 {
 	*size = 0;
@@ -291,7 +291,7 @@ static int erofs_read_dirent(struct erofs_dirent *de,
 		return err;
 	}
 
-	err = erofs_get_occupied_size(&inode, &occupied_size);
+	err = dump_get_occupied_size(&inode, &occupied_size);
 	if (err) {
 		erofs_err("get file size failed\n");
 		return err;
diff --git a/include/erofs/internal.h b/include/erofs/internal.h
index 947304f..8f13e69 100644
--- a/include/erofs/internal.h
+++ b/include/erofs/internal.h
@@ -320,6 +320,8 @@ 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);
+int erofs_get_occupied_size(const struct erofs_inode *inode,
+			    erofs_off_t *size);
 /* 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 27710f9..92e54b5 100644
--- a/lib/data.c
+++ b/lib/data.c
@@ -320,3 +320,24 @@ int erofs_pread(struct erofs_inode *inode, char *buf,
 	}
 	return -EINVAL;
 }
+
+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:
+		erofs_err("unknown datalayout");
+		return -1;
+	}
+	return 0;
+}
-- 
2.34.1.307.g9b7440fafd-goog


  reply	other threads:[~2021-12-21 14:28 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-12-21 14:28 [PATCH v1 1/2] Add some comments about const-ness around iterate API Kelvin Zhang via Linux-erofs
2021-12-21 14:28 ` Kelvin Zhang via Linux-erofs [this message]
2021-12-22  1:46   ` [PATCH v1 2/2] Add API to get on disk size of an inode Gao Xiang
2021-12-22  1:46     ` Kelvin Zhang via Linux-erofs
2021-12-22  1:50       ` Gao Xiang
2021-12-22  1:54         ` [PATCH v3 1/2] erofs-utils: lib: Add some comments about const-ness around iterate API Kelvin Zhang via Linux-erofs
2021-12-22  1:54           ` [PATCH v3 2/2] erofs-utils: lib: Add API to get on disk size of an inode Kelvin Zhang via Linux-erofs
2021-12-22  1:44 ` [PATCH v1 1/2] Add some comments about const-ness around iterate API Gao Xiang
2021-12-22  1:49   ` [PATCH v2 1/3] erofs-utils: lib: " Kelvin Zhang via Linux-erofs
2021-12-22  1:49     ` [PATCH v2 2/3] erofs-utils: lib: Add API to get on disk size of an inode Kelvin Zhang via Linux-erofs
2022-01-04 23:37     ` [PATCH v2 1/3] erofs-utils: lib: Add some comments about const-ness around iterate API Kelvin Zhang via Linux-erofs
2022-01-05  0:23       ` Gao Xiang
2022-01-05  0:24         ` Kelvin Zhang via Linux-erofs
2022-01-05  0:51       ` Gao Xiang

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=20211221142829.4123631-2-zhangkelvin@google.com \
    --to=linux-erofs@lists.ozlabs.org \
    --cc=fangwei1@huawei.com \
    --cc=miaoxie@huawei.com \
    --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.