msdos_create() and msdos_mkdir() both format the new name, figure out whether it's hidden and refuse it if it clashes with an existing entry because of foo vs. .foo. Move that into msdos_format_new_name(). The msdos O_TMPFILE support in the following patches uses it as well. No functional changes. Suggested-by: OGAWA Hirofumi Signed-off-by: Christian Brauner (Amutable) --- fs/fat/namei_msdos.c | 40 ++++++++++++++++++++++------------------ 1 file changed, 22 insertions(+), 18 deletions(-) diff --git a/fs/fat/namei_msdos.c b/fs/fat/namei_msdos.c index 5a43d042eb01f..36e6a14f1b134 100644 --- a/fs/fat/namei_msdos.c +++ b/fs/fat/namei_msdos.c @@ -262,6 +262,26 @@ static int msdos_add_entry(struct inode *dir, const unsigned char *name, return 0; } +/***** Formats the name of a new entry. Rejects foo vs. .foo clashes. */ +static int msdos_format_new_name(struct inode *dir, struct dentry *dentry, + unsigned char *msdos_name, int *is_hid) +{ + struct fat_slot_info sinfo; + int err; + + err = msdos_format_name(dentry->d_name.name, dentry->d_name.len, + msdos_name, &MSDOS_SB(dir->i_sb)->options); + if (err) + return err; + *is_hid = (dentry->d_name.name[0] == '.') && (msdos_name[0] != '.'); + /* Have to do it due to foo vs. .foo conflicts */ + if (!fat_scan(dir, msdos_name, &sinfo)) { + brelse(sinfo.bh); + return -EINVAL; + } + return 0; +} + /***** Create a file */ static int msdos_create(const struct mnt_idmap *idmap, struct inode *dir, struct dentry *dentry, umode_t mode) @@ -275,17 +295,9 @@ static int msdos_create(const struct mnt_idmap *idmap, struct inode *dir, mutex_lock(&MSDOS_SB(sb)->s_lock); - err = msdos_format_name(dentry->d_name.name, dentry->d_name.len, - msdos_name, &MSDOS_SB(sb)->options); + err = msdos_format_new_name(dir, dentry, msdos_name, &is_hid); if (err) goto out; - is_hid = (dentry->d_name.name[0] == '.') && (msdos_name[0] != '.'); - /* Have to do it due to foo vs. .foo conflicts */ - if (!fat_scan(dir, msdos_name, &sinfo)) { - brelse(sinfo.bh); - err = -EINVAL; - goto out; - } ts = current_time(dir); err = msdos_add_entry(dir, msdos_name, 0, is_hid, 0, &ts, &sinfo); @@ -358,17 +370,9 @@ static struct dentry *msdos_mkdir(const struct mnt_idmap *idmap, struct inode *d mutex_lock(&MSDOS_SB(sb)->s_lock); - err = msdos_format_name(dentry->d_name.name, dentry->d_name.len, - msdos_name, &MSDOS_SB(sb)->options); + err = msdos_format_new_name(dir, dentry, msdos_name, &is_hid); if (err) goto out; - is_hid = (dentry->d_name.name[0] == '.') && (msdos_name[0] != '.'); - /* foo vs .foo situation */ - if (!fat_scan(dir, msdos_name, &sinfo)) { - brelse(sinfo.bh); - err = -EINVAL; - goto out; - } ts = current_time(dir); cluster = fat_alloc_new_dir(dir, &ts); -- 2.53.0