Add some comments about const-ness around iterate API
PATCH 1/2 Add some comments about const-ness around iterate API
--- include/erofs/dir.h | 8 ++++++++ 1 file changed, 8 insertions(+)
include/erofs/dir.h +8 -0
@@ -39,6 +39,14 @@ typedef int (*erofs_readdir_cb)(struct erofs_dir_context *);* the callback context. |de_namelen| is the exact dirent name length. */ struct erofs_dir_context { +/* During execution of |erofs_iterate_dir|, the function needs +* to read the values inside |erofs_inode* dir|. So it is important +* that the callback function does not modify stuct pointed by +* |dir|. It is OK to repoint |dir| to other objects. +* Unfortunately, it's not possible to enforce this restriction +* with const keyword, as |erofs_iterate_dir| needs to modify +* struct pointed by |dir|. +*/ struct erofs_inode *dir;erofs_readdir_cb cb;erofs_nid_t pnid;/* optional */
Signature · 1 line
2.34.1.307.g9b7440fafd-goog
PATCH 2/2 Add API to get on disk size of an inode
--- dump/main.c | 4 ++-- include/erofs/internal.h | 2 ++ lib/data.c | 21 +++++++++++++++++++++ 3 files changed, 25 insertions(+), 2 deletions(-)
dump/main.c +2 -2
@@ -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;
include/erofs/internal.h +2 -0
@@ -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,
lib/data.c +21 -0
@@ -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 ; +}
Signature · 1 line
2.34.1.307.g9b7440fafd-goog
Re: [PATCH v1 2/2] Add API to get on disk size of an inode
Quoted 2 lines · Kelvin Zhang
Change-Id I60fa9346737b14418bd3fa1d12f760aaf0a0cca5Signed-off-by Kelvin Zhang <[email protected]>
The same to the previous patch.
Also could we remove dump_get_occupied_size() entirely?
Thanks,
Gao Xiang
Quoted 72 lines
--- dump/main.c | 4 ++-- include/erofs/internal.h | 2 ++ lib/data.c | 21 +++++++++++++++++++++ 3 files changed, 25 insertions(+), 2 deletions(-)dump/main.c +2
-2@@ -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;include/erofs/internal.h +2
-0@@ -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,lib/data.c +21
-0@@ -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 ; +}Signature · 1 line
2.34.1.307.g9b7440fafd-goog
Re: [PATCH v1 2/2] Add API to get on disk size of an inode
Not really, dump_get_occupied_size() contains some custom logic for counting stats.
Quoted 84 lines · Gao Xiang
Quoted 2 lines · Kelvin Zhang
Change-Id I60fa9346737b14418bd3fa1d12f760aaf0a0cca5Signed-off-by Kelvin Zhang <[email protected]>The same to the previous patch.
Also could we remove
dump_get_occupied_size()entirely?Thanks,
Gao XiangQuoted 72 lines
--- dump/main.c | 4 ++-- include/erofs/internal.h | 2 ++ lib/data.c | 21 +++++++++++++++++++++ 3 files changed, 25 insertions(+), 2 deletions(-)dump/main.c +2
-2@@ -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;include/erofs/internal.h +2
-0@@ -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,lib/data.c +21
-1@@ -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
Signature · 3 lines
Sincerely, Kelvin Zhang
Re: [PATCH v1 2/2] Add API to get on disk size of an inode
Quoted 3 lines · Kelvin Zhang
Not really,
dump_get_occupied_size()contains some custom logic for counting stats.
Ok, thanks. maybe it would be better to rename as erofsdump_get_occupied_size().
Also we could "static inline" such API since it's simple.
Thanks,
Gao Xiang
PATCH v3 1/2 erofs-utils: lib: Add some comments about const-ness around iterate API
The new iterate dir API has non-trivial const correctness requirements. Document them in comment.
--- include/erofs/dir.h | 8 ++++++++ 1 file changed, 8 insertions(+)
include/erofs/dir.h +8 -0
@@ -39,6 +39,14 @@ typedef int (*erofs_readdir_cb)(struct erofs_dir_context *);* the callback context. |de_namelen| is the exact dirent name length. */ struct erofs_dir_context { +/* During execution of |erofs_iterate_dir|, the function needs +* to read the values inside |erofs_inode* dir|. So it is important +* that the callback function does not modify stuct pointed by +* |dir|. It is OK to repoint |dir| to other objects. +* Unfortunately, it's not possible to enforce this restriction +* with const keyword, as |erofs_iterate_dir| needs to modify +* struct pointed by |dir|. +*/ struct erofs_inode *dir;erofs_readdir_cb cb;erofs_nid_t pnid;/* optional */
Signature · 1 line
2.34.1.448.ga2b2bfdf31-goog
PATCH v3 2/2 erofs-utils: lib: Add API to get on disk size of an inode
Marginally improve code re-use. It's quite common for users to query for compressed size of an inode.
--- dump/main.c | 4 ++-- include/erofs/internal.h | 23 +++++++++++++++++++++++ 2 files changed, 25 insertions(+), 2 deletions(-)
dump/main.c +2 -2
@@ -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 erofsdump_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 =erofsdump_get_occupied_size (&inode, &occupied_size);if (err) {erofs_err ("get file size failed\n" );return err;
include/erofs/internal.h +23 -0
@@ -19,6 +19,7 @@ typedef unsigned short umode_t;#define __packed __attribute__((__packed__)) +#include "erofs/print.h" #include "erofs_fs.h" #include <fcntl.h>
@@ -320,6 +321,28 @@ 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 : +erofs_err ("unknown datalayout" ); +return -1 ; + } +return 0 ; +} +/* zmap.c */ int z_erofs_fill_inode (struct erofs_inode *vi); int z_erofs_map_blocks_iter(struct erofs_inode *vi,
Signature · 1 line
2.34.1.448.ga2b2bfdf31-goog
Hi Kelvin,
Quoted 2 lines · Kelvin Zhang
Change-Id I297a56ba14a37ef5eced95330a5b09109378ca44Signed-off-by Kelvin Zhang <[email protected]>
Would you mind add "erofs-utils: lib: " to the subject prefix, also drop the "Change-Id:" field so I could apply it.
Adding some commit message is better, even it's trivial and simple.
Thanks,
Gao Xiang
Quoted 25 lines
--- include/erofs/dir.h | 8 ++++++++ 1 file changed, 8 insertions(+)include/erofs/dir.h +8
-0@@ -39,6 +39,14 @@ typedef int (*erofs_readdir_cb)(struct erofs_dir_context *);* the callback context. |de_namelen| is the exact dirent name length. */ struct erofs_dir_context { +/* During execution of |erofs_iterate_dir|, the function needs +* to read the values inside |erofs_inode* dir|. So it is important +* that the callback function does not modify stuct pointed by +* |dir|. It is OK to repoint |dir| to other objects. +* Unfortunately, it's not possible to enforce this restriction +* with const keyword, as |erofs_iterate_dir| needs to modify +* struct pointed by |dir|. +*/ struct erofs_inode *dir;erofs_readdir_cb cb;erofs_nid_t pnid;/* optional */ Signature · 1 line
2.34.1.307.g9b7440fafd-goog
PATCH v2 1/3 erofs-utils: lib: Add some comments about const-ness around iterate API
The new iterate dir API has non-trivial const correctness requirements. Document them in comment.
--- include/erofs/dir.h | 8 ++++++++ 1 file changed, 8 insertions(+)
include/erofs/dir.h +8 -0
@@ -39,6 +39,14 @@ typedef int (*erofs_readdir_cb)(struct erofs_dir_context *);* the callback context. |de_namelen| is the exact dirent name length. */ struct erofs_dir_context { +/* During execution of |erofs_iterate_dir|, the function needs +* to read the values inside |erofs_inode* dir|. So it is important +* that the callback function does not modify stuct pointed by +* |dir|. It is OK to repoint |dir| to other objects. +* Unfortunately, it's not possible to enforce this restriction +* with const keyword, as |erofs_iterate_dir| needs to modify +* struct pointed by |dir|. +*/ struct erofs_inode *dir;erofs_readdir_cb cb;erofs_nid_t pnid;/* optional */
Signature · 1 line
2.34.1.448.ga2b2bfdf31-goog
PATCH v2 2/3 erofs-utils: lib: Add API to get on disk size of an inode
Marginally improve code re-use. It's quite common for users to query for compressed size of an inode.
--- dump/main.c | 4 ++-- include/erofs/internal.h | 2 ++ lib/data.c | 21 +++++++++++++++++++++ 3 files changed, 25 insertions(+), 2 deletions(-)
dump/main.c +2 -2
@@ -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;
include/erofs/internal.h +2 -0
@@ -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,
lib/data.c +21 -0
@@ -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 ; +}
Signature · 1 line
2.34.1.448.ga2b2bfdf31-goog
Re: [PATCH v2 1/3] erofs-utils: lib: Add some comments about const-ness around iterate API
In reply to Kelvin Zhang via Linux-erofsfriendly ping
Quoted 31 lines · Kelvin Zhang
The new iterate dir API has non-trivial const correctness requirements. Document them in comment.
Signed-off-by Kelvin Zhang <[email protected]>--- include/erofs/dir.h | 8 ++++++++ 1 file changed, 8 insertions(+)include/erofs/dir.h +8
-1@@ -39,6 +39,14 @@ typedef int (*erofs_readdir_cb)(struct erofs_dir_context *);* the callback context. |de_namelen| is the exact dirent name length. */ struct erofs_dir_context { +/* During execution of |erofs_iterate_dir|, the function needs +* to read the values inside |erofs_inode* dir|. So it is important +* that the callback function does not modify stuct pointed by +* |dir|. It is OK to repoint |dir| to other objects. +* Unfortunately, it's not possible to enforce this restriction +* with const keyword, as |erofs_iterate_dir| needs to modify +* struct pointed by |dir|. +*/ struct erofs_inode *dir;erofs_readdir_cb cb;erofs_nid_t pnid;/* optional */ --2.34.1.448.ga2b2bfdf31-goog
Signature · 3 lines
Sincerely, Kelvin Zhang
Re: [PATCH v2 1/3] erofs-utils: lib: Add some comments about const-ness around iterate API
Quoted 1 line · Kelvin Zhang
friendly ping
I already merged them, didn't I?
https://git.kernel.org/pub/scm/linux/kernel/git/xiang/erofs-utils.git/commit/?h=dev&id=2be280dc28ace9c3840aa5e6ca7ff90ef4212cd1
Thanks,
Gao Xiang
Quoted 1 line
Re: [PATCH v2 1/3] erofs-utils: lib: Add some comments about const-ness around iterate API
Ah, I see, thanks!
Quoted 11 lines · Gao Xiang
Quoted 1 line · Kelvin Zhang
friendly ping
I already merged them, didn't I?
https://git.kernel.org/pub/scm/linux/kernel/git/xiang/erofs-utils.git/commit/?h=dev&id=2be280dc28ace9c3840aa5e6ca7ff90ef4212cd1Thanks,
Gao XiangQuoted 1 line
Signature · 3 lines
Sincerely, Kelvin Zhang
Re: [PATCH v2 1/3] erofs-utils: lib: Add some comments about const-ness around iterate API
In reply to Kelvin Zhang via Linux-erofsQuoted 1 line · Kelvin Zhang
friendly ping
I already merged them. Didn't I?
https://git.kernel.org/pub/scm/linux/kernel/git/xiang/erofs-utils.git/commit/?h=dev&id=2be280dc28ace9c3840aa5e6ca7ff90ef4212cd1
Thanks,
Gao Xiang