Lines Matching +full:adc +full:- +full:res +full:- +full:names

1 // SPDX-License-Identifier: GPL-2.0-only
6 * Hidden files 1995 by Albert Cahalan <albert@ccs.neu.edu> <adc@coe.neu.edu>
14 /* Characters that are undesirable in an MS-DOS file name */
18 /***** Formats an MS-DOS file name. Rejects invalid names. */
20 unsigned char *res, struct fat_mount_options *opts) in msdos_format_name() argument
22 * name is the proposed name, len is its length, res is in msdos_format_name()
23 * the resulting name, opts->name_check is either (r)elaxed, in msdos_format_name()
24 * (n)ormal or (s)trict, opts->dotsOK allows dots at the in msdos_format_name()
33 if (opts->dotsOK) { in msdos_format_name()
34 /* Get rid of dot - test for it elsewhere */ in msdos_format_name()
36 len--; in msdos_format_name()
38 return -EINVAL; in msdos_format_name()
41 * disallow names that _really_ start with a dot in msdos_format_name()
45 for (walk = res; len && walk - res < 8; walk++) { in msdos_format_name()
47 len--; in msdos_format_name()
48 if (opts->name_check != 'r' && strchr(bad_chars, c)) in msdos_format_name()
49 return -EINVAL; in msdos_format_name()
50 if (opts->name_check == 's' && strchr(bad_if_strict, c)) in msdos_format_name()
51 return -EINVAL; in msdos_format_name()
52 if (c >= 'A' && c <= 'Z' && opts->name_check == 's') in msdos_format_name()
53 return -EINVAL; in msdos_format_name()
55 return -EINVAL; in msdos_format_name()
60 * It seems that Microsoft hacked DOS to support non-US in msdos_format_name()
64 if ((res == walk) && (c == 0xE5)) in msdos_format_name()
69 *walk = (!opts->nocase && c >= 'a' && c <= 'z') ? c - 32 : c; in msdos_format_name()
72 return -EINVAL; in msdos_format_name()
73 if (opts->name_check == 's' && len && c != '.') { in msdos_format_name()
75 len--; in msdos_format_name()
77 return -EINVAL; in msdos_format_name()
79 while (c != '.' && len--) in msdos_format_name()
82 while (walk - res < 8) in msdos_format_name()
84 while (len > 0 && walk - res < MSDOS_NAME) { in msdos_format_name()
86 len--; in msdos_format_name()
87 if (opts->name_check != 'r' && strchr(bad_chars, c)) in msdos_format_name()
88 return -EINVAL; in msdos_format_name()
89 if (opts->name_check == 's' && in msdos_format_name()
91 return -EINVAL; in msdos_format_name()
93 return -EINVAL; in msdos_format_name()
95 if (opts->name_check == 's') in msdos_format_name()
96 return -EINVAL; in msdos_format_name()
99 if (c >= 'A' && c <= 'Z' && opts->name_check == 's') in msdos_format_name()
100 return -EINVAL; in msdos_format_name()
102 if (!opts->nocase && c >= 'a' && c <= 'z') in msdos_format_name()
103 *walk++ = c - 32; in msdos_format_name()
108 return -EINVAL; in msdos_format_name()
109 if (opts->name_check == 's' && len) in msdos_format_name()
110 return -EINVAL; in msdos_format_name()
112 while (walk - res < MSDOS_NAME) in msdos_format_name()
122 struct msdos_sb_info *sbi = MSDOS_SB(dir->i_sb); in msdos_find()
126 err = msdos_format_name(name, len, msdos_name, &sbi->options); in msdos_find()
128 return -ENOENT; in msdos_find()
131 if (!err && sbi->options.dotsOK) { in msdos_find()
133 if (!(sinfo->de->attr & ATTR_HIDDEN)) in msdos_find()
134 err = -ENOENT; in msdos_find()
136 if (sinfo->de->attr & ATTR_HIDDEN) in msdos_find()
137 err = -ENOENT; in msdos_find()
140 brelse(sinfo->bh); in msdos_find()
153 struct fat_mount_options *options = &MSDOS_SB(dentry->d_sb)->options; in msdos_hash()
157 error = msdos_format_name(qstr->name, qstr->len, msdos_name, options); in msdos_hash()
159 qstr->hash = full_name_hash(dentry, msdos_name, MSDOS_NAME); in msdos_hash()
164 * Compare two msdos names. If either of the names are invalid,
170 struct fat_mount_options *options = &MSDOS_SB(dentry->d_sb)->options; in msdos_cmp()
174 error = msdos_format_name(name->name, name->len, a_msdos_name, options); in msdos_cmp()
186 if (name->len == len) in msdos_cmp()
187 error = memcmp(name->name, str, len); in msdos_cmp()
204 struct super_block *sb = dir->i_sb; in msdos_lookup()
209 mutex_lock(&MSDOS_SB(sb)->s_lock); in msdos_lookup()
210 err = msdos_find(dir, dentry->d_name.name, dentry->d_name.len, &sinfo); in msdos_lookup()
212 case -ENOENT: in msdos_lookup()
222 mutex_unlock(&MSDOS_SB(sb)->s_lock); in msdos_lookup()
231 struct msdos_sb_info *sbi = MSDOS_SB(dir->i_sb); in msdos_add_entry()
267 struct super_block *sb = dir->i_sb; in msdos_create()
274 mutex_lock(&MSDOS_SB(sb)->s_lock); in msdos_create()
276 err = msdos_format_name(dentry->d_name.name, dentry->d_name.len, in msdos_create()
277 msdos_name, &MSDOS_SB(sb)->options); in msdos_create()
280 is_hid = (dentry->d_name.name[0] == '.') && (msdos_name[0] != '.'); in msdos_create()
284 err = -EINVAL; in msdos_create()
303 mutex_unlock(&MSDOS_SB(sb)->s_lock); in msdos_create()
312 struct super_block *sb = dir->i_sb; in msdos_rmdir()
317 mutex_lock(&MSDOS_SB(sb)->s_lock); in msdos_rmdir()
321 err = msdos_find(dir, dentry->d_name.name, dentry->d_name.len, &sinfo); in msdos_rmdir()
334 mutex_unlock(&MSDOS_SB(sb)->s_lock); in msdos_rmdir()
345 struct super_block *sb = dir->i_sb; in msdos_mkdir()
352 mutex_lock(&MSDOS_SB(sb)->s_lock); in msdos_mkdir()
354 err = msdos_format_name(dentry->d_name.name, dentry->d_name.len, in msdos_mkdir()
355 msdos_name, &MSDOS_SB(sb)->options); in msdos_mkdir()
358 is_hid = (dentry->d_name.name[0] == '.') && (msdos_name[0] != '.'); in msdos_mkdir()
362 err = -EINVAL; in msdos_mkdir()
390 mutex_unlock(&MSDOS_SB(sb)->s_lock); in msdos_mkdir()
397 mutex_unlock(&MSDOS_SB(sb)->s_lock); in msdos_mkdir()
405 struct super_block *sb = inode->i_sb; in msdos_unlink()
409 mutex_lock(&MSDOS_SB(sb)->s_lock); in msdos_unlink()
410 err = msdos_find(dir, dentry->d_name.name, dentry->d_name.len, &sinfo); in msdos_unlink()
421 mutex_unlock(&MSDOS_SB(sb)->s_lock); in msdos_unlink()
447 err = -EIO; in do_msdos_rename()
451 is_dir = S_ISDIR(old_inode->i_mode); in do_msdos_rename()
455 err = -EIO; in do_msdos_rename()
460 old_attrs = MSDOS_I(old_inode)->i_attrs; in do_msdos_rename()
464 /* "foo" -> ".foo" case. just change the ATTR_HIDDEN */ in do_msdos_rename()
466 err = -EINVAL; in do_msdos_rename()
470 MSDOS_I(old_inode)->i_attrs |= ATTR_HIDDEN; in do_msdos_rename()
472 MSDOS_I(old_inode)->i_attrs &= ~ATTR_HIDDEN; in do_msdos_rename()
476 MSDOS_I(old_inode)->i_attrs = old_attrs; in do_msdos_rename()
501 new_i_pos = MSDOS_I(new_inode)->i_pos; in do_msdos_rename()
515 MSDOS_I(old_inode)->i_attrs |= ATTR_HIDDEN; in do_msdos_rename()
517 MSDOS_I(old_inode)->i_attrs &= ~ATTR_HIDDEN; in do_msdos_rename()
526 fat_set_start(dotdot_de, MSDOS_I(new_dir)->i_logstart); in do_msdos_rename()
566 fat_set_start(dotdot_de, MSDOS_I(old_dir)->i_logstart); in do_msdos_rename()
573 MSDOS_I(old_inode)->i_attrs = old_attrs; in do_msdos_rename()
589 fat_fs_error(new_dir->i_sb, in do_msdos_rename()
602 struct super_block *sb = old_dir->i_sb; in msdos_rename()
607 return -EINVAL; in msdos_rename()
609 mutex_lock(&MSDOS_SB(sb)->s_lock); in msdos_rename()
611 err = msdos_format_name(old_dentry->d_name.name, in msdos_rename()
612 old_dentry->d_name.len, old_msdos_name, in msdos_rename()
613 &MSDOS_SB(old_dir->i_sb)->options); in msdos_rename()
616 err = msdos_format_name(new_dentry->d_name.name, in msdos_rename()
617 new_dentry->d_name.len, new_msdos_name, in msdos_rename()
618 &MSDOS_SB(new_dir->i_sb)->options); in msdos_rename()
623 (new_dentry->d_name.name[0] == '.') && (new_msdos_name[0] != '.'); in msdos_rename()
628 mutex_unlock(&MSDOS_SB(sb)->s_lock); in msdos_rename()
648 MSDOS_SB(sb)->dir_ops = &msdos_dir_inode_operations; in setup()
649 sb->s_d_op = &msdos_dentry_operations; in setup()
650 sb->s_flags |= SB_NOATIME; in setup()
684 fc->ops = &msdos_context_ops; in msdos_init_fs_context()
710 MODULE_DESCRIPTION("MS-DOS filesystem support");