]> git.ipfire.org Git - thirdparty/kernel/linux.git/commit
readdir: Introduce dirent_size()
authorChristophe Leroy (CS GROUP) <chleroy@kernel.org>
Tue, 24 Mar 2026 11:41:15 +0000 (12:41 +0100)
committerChristian Brauner <brauner@kernel.org>
Tue, 24 Mar 2026 13:44:02 +0000 (14:44 +0100)
commit4bf798e027d35e4fd9a31b32e6bc2d33a73c0041
tree82e511d4b1d07ecf206dbc96b91d609aea0471e4
parentf30186b0c7829841744a40f7345e6cc9865f8a67
readdir: Introduce dirent_size()

In several places in readdir.c there are calculations of the total size
of a dirent, which contains a few fixed fields plus a name field with
variable size. To add fun every dirent is of a slightly different type:
- struct old_linux_dirent
- struct linux_dirent
- struct linux_dirent64
- struct compat_old_linux_dirent
- struct compat_linux_dirent

Replace ugly size calculation by a macro called dirent_size() which
calculates the size of the structure based on the pointed type and
the name field len.

Suggested-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Christophe Leroy (CS GROUP) <chleroy@kernel.org>
Link: https://patch.msgid.link/c20d2f8f6817a39401155cfc80f0dff88df116e0.1774350128.git.chleroy@kernel.org
Reviewed-by: David Laight <david.laight.linux@gmail.com>
Signed-off-by: Christian Brauner <brauner@kernel.org>
fs/readdir.c