Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

libfs: Create the helper function generic_ci_validate_strict_name()

Create a helper function for filesystems do the checks required for
casefold directories and strict encoding.

Suggested-by: Gabriel Krisman Bertazi <krisman@suse.de>
Reviewed-by: Gabriel Krisman Bertazi <gabriel@krisman.be>
Signed-off-by: André Almeida <andrealmeid@igalia.com>
Link: https://lore.kernel.org/r/20241021-tonyk-tmpfs-v8-1-f443d5814194@igalia.com
Signed-off-by: Christian Brauner <brauner@kernel.org>

authored by

André Almeida and committed by
Christian Brauner
0e152beb 42f7652d

+45
+45
include/linux/fs.h
··· 45 45 #include <linux/slab.h> 46 46 #include <linux/maple_tree.h> 47 47 #include <linux/rw_hint.h> 48 + #include <linux/unicode.h> 48 49 49 50 #include <asm/byteorder.h> 50 51 #include <uapi/linux/fs.h> ··· 3456 3455 const struct qstr *name, 3457 3456 const struct qstr *folded_name, 3458 3457 const u8 *de_name, u32 de_name_len); 3458 + 3459 + #if IS_ENABLED(CONFIG_UNICODE) 3460 + /** 3461 + * generic_ci_validate_strict_name - Check if a given name is suitable 3462 + * for a directory 3463 + * 3464 + * This functions checks if the proposed filename is valid for the 3465 + * parent directory. That means that only valid UTF-8 filenames will be 3466 + * accepted for casefold directories from filesystems created with the 3467 + * strict encoding flag. That also means that any name will be 3468 + * accepted for directories that doesn't have casefold enabled, or 3469 + * aren't being strict with the encoding. 3470 + * 3471 + * @dir: inode of the directory where the new file will be created 3472 + * @name: name of the new file 3473 + * 3474 + * Return: 3475 + * * True if the filename is suitable for this directory. It can be 3476 + * true if a given name is not suitable for a strict encoding 3477 + * directory, but the directory being used isn't strict 3478 + * * False if the filename isn't suitable for this directory. This only 3479 + * happens when a directory is casefolded and the filesystem is strict 3480 + * about its encoding. 3481 + */ 3482 + static inline bool generic_ci_validate_strict_name(struct inode *dir, struct qstr *name) 3483 + { 3484 + if (!IS_CASEFOLDED(dir) || !sb_has_strict_encoding(dir->i_sb)) 3485 + return true; 3486 + 3487 + /* 3488 + * A casefold dir must have a encoding set, unless the filesystem 3489 + * is corrupted 3490 + */ 3491 + if (WARN_ON_ONCE(!dir->i_sb->s_encoding)) 3492 + return true; 3493 + 3494 + return !utf8_validate(dir->i_sb->s_encoding, name); 3495 + } 3496 + #else 3497 + static inline bool generic_ci_validate_strict_name(struct inode *dir, struct qstr *name) 3498 + { 3499 + return true; 3500 + } 3501 + #endif 3459 3502 3460 3503 static inline bool sb_has_encoding(const struct super_block *sb) 3461 3504 {