|
46 | 46 | #include <linux/maple_tree.h> |
47 | 47 | #include <linux/rw_hint.h> |
48 | 48 | #include <linux/file_ref.h> |
| 49 | +#include <linux/unicode.h> |
49 | 50 |
|
50 | 51 | #include <asm/byteorder.h> |
51 | 52 | #include <uapi/linux/fs.h> |
@@ -3479,6 +3480,54 @@ extern int generic_ci_match(const struct inode *parent, |
3479 | 3480 | const struct qstr *folded_name, |
3480 | 3481 | const u8 *de_name, u32 de_name_len); |
3481 | 3482 |
|
| 3483 | +#if IS_ENABLED(CONFIG_UNICODE) |
| 3484 | +int generic_ci_d_hash(const struct dentry *dentry, struct qstr *str); |
| 3485 | +int generic_ci_d_compare(const struct dentry *dentry, unsigned int len, |
| 3486 | + const char *str, const struct qstr *name); |
| 3487 | + |
| 3488 | +/** |
| 3489 | + * generic_ci_validate_strict_name - Check if a given name is suitable |
| 3490 | + * for a directory |
| 3491 | + * |
| 3492 | + * This functions checks if the proposed filename is valid for the |
| 3493 | + * parent directory. That means that only valid UTF-8 filenames will be |
| 3494 | + * accepted for casefold directories from filesystems created with the |
| 3495 | + * strict encoding flag. That also means that any name will be |
| 3496 | + * accepted for directories that doesn't have casefold enabled, or |
| 3497 | + * aren't being strict with the encoding. |
| 3498 | + * |
| 3499 | + * @dir: inode of the directory where the new file will be created |
| 3500 | + * @name: name of the new file |
| 3501 | + * |
| 3502 | + * Return: |
| 3503 | + * * True: if the filename is suitable for this directory. It can be |
| 3504 | + * true if a given name is not suitable for a strict encoding |
| 3505 | + * directory, but the directory being used isn't strict |
| 3506 | + * * False if the filename isn't suitable for this directory. This only |
| 3507 | + * happens when a directory is casefolded and the filesystem is strict |
| 3508 | + * about its encoding. |
| 3509 | + */ |
| 3510 | +static inline bool generic_ci_validate_strict_name(struct inode *dir, struct qstr *name) |
| 3511 | +{ |
| 3512 | + if (!IS_CASEFOLDED(dir) || !sb_has_strict_encoding(dir->i_sb)) |
| 3513 | + return true; |
| 3514 | + |
| 3515 | + /* |
| 3516 | + * A casefold dir must have a encoding set, unless the filesystem |
| 3517 | + * is corrupted |
| 3518 | + */ |
| 3519 | + if (WARN_ON_ONCE(!dir->i_sb->s_encoding)) |
| 3520 | + return true; |
| 3521 | + |
| 3522 | + return !utf8_validate(dir->i_sb->s_encoding, name); |
| 3523 | +} |
| 3524 | +#else |
| 3525 | +static inline bool generic_ci_validate_strict_name(struct inode *dir, struct qstr *name) |
| 3526 | +{ |
| 3527 | + return true; |
| 3528 | +} |
| 3529 | +#endif |
| 3530 | + |
3482 | 3531 | static inline bool sb_has_encoding(const struct super_block *sb) |
3483 | 3532 | { |
3484 | 3533 | #if IS_ENABLED(CONFIG_UNICODE) |
|
0 commit comments