]> www.infradead.org Git - users/hch/misc.git/commitdiff
fs: Create sb_same_encoding() helper
authorAndré Almeida <andrealmeid@igalia.com>
Thu, 14 Aug 2025 17:22:13 +0000 (14:22 -0300)
committerAmir Goldstein <amir73il@gmail.com>
Tue, 23 Sep 2025 10:28:57 +0000 (12:28 +0200)
For cases where a file lookup can look in different filesystems (like in
overlayfs), both super blocks must have the same encoding and the same
flags. To help with that, create a sb_same_encoding() function.

Reviewed-by: Amir Goldstein <amir73il@gmail.com>
Signed-off-by: André Almeida <andrealmeid@igalia.com>
Reviewed-by: Gabriel Krisman Bertazi <gabriel@krisman.be>
Signed-off-by: Amir Goldstein <amir73il@gmail.com>
include/linux/fs.h

index 43b3a7cf6750d3db3e5350908c95bc8a729db41a..ec867f112fd5fce7c1cceeb8598979972688d220 100644 (file)
@@ -3754,6 +3754,24 @@ static inline bool sb_has_encoding(const struct super_block *sb)
        return !!sb_encoding(sb);
 }
 
+/*
+ * Compare if two super blocks have the same encoding and flags
+ */
+static inline bool sb_same_encoding(const struct super_block *sb1,
+                                   const struct super_block *sb2)
+{
+#if IS_ENABLED(CONFIG_UNICODE)
+       if (sb1->s_encoding == sb2->s_encoding)
+               return true;
+
+       return (sb1->s_encoding && sb2->s_encoding &&
+              (sb1->s_encoding->version == sb2->s_encoding->version) &&
+              (sb1->s_encoding_flags == sb2->s_encoding_flags));
+#else
+       return true;
+#endif
+}
+
 int may_setattr(struct mnt_idmap *idmap, struct inode *inode,
                unsigned int ia_valid);
 int setattr_prepare(struct mnt_idmap *, struct dentry *, struct iattr *);