[PATCH RFC v3 3/7] fs: Create sb_same_encoding() helper

André Almeida posted 7 patches 1 month, 3 weeks ago
There is a newer version of this series
[PATCH RFC v3 3/7] fs: Create sb_same_encoding() helper
Posted by André Almeida 1 month, 3 weeks ago
For cases where a file lookup can go to different mount points (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.

Signed-off-by: André Almeida <andrealmeid@igalia.com>
---
Changes from v2:
- Simplify the code. Instead of `if (cond) return true`, just do `return
  cond`;
---
 include/linux/fs.h | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)

diff --git a/include/linux/fs.h b/include/linux/fs.h
index db49a17376d124785b87dd7f35672fc6e5434f47..d1fe69f233c046a960a60072d5ac3f6286d32c17 100644
--- a/include/linux/fs.h
+++ b/include/linux/fs.h
@@ -3746,6 +3746,25 @@ static inline bool sb_has_encoding(const struct super_block *sb)
 #endif
 }
 
+/*
+ * 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 *);

-- 
2.50.1

Re: [PATCH RFC v3 3/7] fs: Create sb_same_encoding() helper
Posted by Amir Goldstein 1 month, 3 weeks ago
On Fri, Aug 8, 2025 at 10:59 PM André Almeida <andrealmeid@igalia.com> wrote:
>
> For cases where a file lookup can go to different mount points (like in

s/can go to different mount points/can look in different filesystems/

> overlayfs), both super blocks must have the same encoding and the same
> flags. To help with that, create a sb_same_encoding() function.
>
> Signed-off-by: André Almeida <andrealmeid@igalia.com>

With wording fixed feel free to add:

Reviewed-by: Amir Goldstein <amir73il@gmail.com>

Thanks,
Amir.

> ---
> Changes from v2:
> - Simplify the code. Instead of `if (cond) return true`, just do `return
>   cond`;
> ---
>  include/linux/fs.h | 19 +++++++++++++++++++
>  1 file changed, 19 insertions(+)
>
> diff --git a/include/linux/fs.h b/include/linux/fs.h
> index db49a17376d124785b87dd7f35672fc6e5434f47..d1fe69f233c046a960a60072d5ac3f6286d32c17 100644
> --- a/include/linux/fs.h
> +++ b/include/linux/fs.h
> @@ -3746,6 +3746,25 @@ static inline bool sb_has_encoding(const struct super_block *sb)
>  #endif
>  }
>
> +/*
> + * 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 *);
>
> --
> 2.50.1
>