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