[PATCH 10/13] xfs_scrub: reduce size of struct name_entry

Darrick J. Wong
2023-12-31T22:47:39Z

libicu doesn't support processing strings longer than 2GB in length, and
we never feed the unicrash code a name longer than about 300 bytes.
Rearrange the structure to reduce the head structure size from 56 bytes
to 44 bytes.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
---
scrub/unicrash.c | 16 ++++++++++++----
1 file changed, 12 insertions(+), 4 deletions(-)

diff --git a/scrub/unicrash.c b/scrub/unicrash.c
index 25f562b0a36..dfa798b09b0 100644
--- a/scrub/unicrash.c
+++ b/scrub/unicrash.c
@@ -57,18 +57,20 @@
* In other words, skel = remove_invisible(nfd(remap_confusables(nfd(name)))).
*/

-typedef unsigned int __bitwise badname_t;
+typedef uint16_t __bitwise badname_t;

struct name_entry {
struct name_entry *next;

/* NFKC normalized name */
UChar *normstr;
- size_t normstrlen;

/* Unicode skeletonized name */
UChar *skelstr;
- size_t skelstrlen;
+
+ /* Lengths for normstr and skelstr */
+ int32_t normstrlen;
+ int32_t skelstrlen;

xfs_ino_t ino;

@@ -76,7 +78,7 @@ struct name_entry {
badname_t badflags;

/* Raw dirent name */
- size_t namelen;
+ uint16_t namelen;
char name[0];
};
#define NAME_ENTRY_SZ(nl) (sizeof(struct name_entry) + 1 + \
@@ -343,6 +345,12 @@ name_entry_create(
struct name_entry *new_entry;
size_t namelen = strlen(name);

+ /* should never happen */
+ if (namelen > UINT16_MAX) {
+ ASSERT(namelen <= UINT16_MAX);
+ return false;
+ }
+
/* Create new entry */
new_entry = calloc(NAME_ENTRY_SZ(namelen), 1);
if (!new_entry)