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 v2 1/3] erofs-utils: lib: Add some comments about const-ness around iterate API
Date: Tue, 21 Dec 2021 17:49:16 -0800	[thread overview]
Message-ID: <20211222014917.265476-1-zhangkelvin@google.com> (raw)
In-Reply-To: <YcKDAILGEoYFE7K0@B-P7TQMD6M-0146.local>

The new iterate dir API has non-trivial const correctness requirements.
Document them in comment.

Signed-off-by: Kelvin Zhang <zhangkelvin@google.com>
---
 include/erofs/dir.h | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/include/erofs/dir.h b/include/erofs/dir.h
index 77656ca..59bd40d 100644
--- a/include/erofs/dir.h
+++ b/include/erofs/dir.h
@@ -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


  reply	other threads:[~2021-12-22  1:49 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 ` [PATCH v1 2/2] Add API to get on disk size of an inode Kelvin Zhang via Linux-erofs
2021-12-22  1:46   ` 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   ` Kelvin Zhang via Linux-erofs [this message]
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=20211222014917.265476-1-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.