author: David Howells <dhowells@redhat.com> 2020-12-23 10:39:57 +0000
committer: David Howells <dhowells@redhat.com> 2021-01-04 12:25:19 +0000
commit: 366911cd762db02c2dd32fad1be96b72a66f205d
parent: 26982a89cad77c0efc1c0c79bee0e3d75e9281d4
Commit Summary:
Diffstat:
1 file changed, 13 insertions, 1 deletion
diff --git a/fs/afs/xdr_fs.h b/fs/afs/xdr_fs.h
index c926430fd08a..8ca868164507 100644
--- a/fs/afs/xdr_fs.h
+++ b/fs/afs/xdr_fs.h
@@ -58,7 +58,8 @@ union afs_xdr_dirent {
/* When determining the number of dirent slots needed to
* represent a directory entry, name should be assumed to be 16
* bytes, due to a now-standardised (mis)calculation, but it is
- * in fact 20 bytes in size.
+ * in fact 20 bytes in size. afs_dir_calc_slots() should be
+ * used for this.
*
* For names longer than (16 or) 20 bytes, extra slots should
* be annexed to this one using the extended_name format.
@@ -101,4 +102,15 @@ struct afs_xdr_dir_page {
union afs_xdr_dir_block blocks[AFS_DIR_BLOCKS_PER_PAGE];
};
+/*
+ * Calculate the number of dirent slots required for any given name length.
+ * The calculation is made assuming the part of the name in the first slot is
+ * 16 bytes, rather than 20, but this miscalculation is now standardised.
+ */
+static inline unsigned int afs_dir_calc_slots(size_t name_len)
+{
+ name_len++; /* NUL-terminated */
+ return 1 + ((name_len + 15) / AFS_DIR_DIRENT_SIZE);
+}
+
#endif /* XDR_FS_H */