9 #include <linux/module.h>
10 #include <linux/time.h>
15 static unsigned char bad_chars[] =
"*?<>|\"";
16 static unsigned char bad_if_strict[] =
"+=,; ";
19 static int msdos_format_name(
const unsigned char *
name,
int len,
45 for (walk = res; len && walk - res < 8; walk++) {
52 if (c >=
'A' && c <= 'Z' && opts->name_check ==
's')
54 if (c <
' ' || c ==
':' || c ==
'\\')
64 if ((res == walk) && (c == 0xE5))
69 *walk = (!opts->
nocase && c >=
'a' && c <=
'z') ? c - 32 : c;
73 if (opts->
name_check ==
's' && len && c !=
'.') {
79 while (c !=
'.' && len--)
82 while (walk - res < 8)
92 if (c <
' ' || c ==
':' || c ==
'\\')
99 if (c >=
'A' && c <= 'Z' && opts->name_check ==
's')
102 if (!opts->
nocase && c >=
'a' && c <=
'z')
119 static int msdos_find(
struct inode *dir,
const unsigned char *name,
int len,
126 err = msdos_format_name(name, len, msdos_name, &sbi->
options);
130 err =
fat_scan(dir, msdos_name, sinfo);
131 if (!err && sbi->
options.dotsOK) {
132 if (name[0] ==
'.') {
158 error = msdos_format_name(qstr->
name, qstr->len, msdos_name, options);
168 static int msdos_cmp(
const struct dentry *parent,
const struct inode *pinode,
169 const struct dentry *dentry,
const struct inode *inode,
170 unsigned int len,
const char *
str,
const struct qstr *name)
176 error = msdos_format_name(name->
name, name->len, a_msdos_name, options);
179 error = msdos_format_name(str, len, b_msdos_name, options);
188 if (name->len == len)
194 .d_hash = msdos_hash,
195 .d_compare = msdos_cmp,
203 static struct dentry *msdos_lookup(
struct inode *dir,
struct dentry *dentry,
212 err = msdos_find(dir, dentry->
d_name.name, dentry->
d_name.len, &sinfo);
222 inode = ERR_PTR(err);
229 static int msdos_add_entry(
struct inode *dir,
const unsigned char *name,
230 int is_dir,
int is_hid,
int cluster,
244 de.cdate = de.adate = 0;
249 fat_set_start(&de, cluster);
260 mark_inode_dirty(dir);
266 static int msdos_create(
struct inode *dir,
struct dentry *dentry,
umode_t mode,
270 struct inode *inode =
NULL;
278 err = msdos_format_name(dentry->
d_name.name, dentry->
d_name.len,
279 msdos_name, &MSDOS_SB(sb)->options);
282 is_hid = (dentry->
d_name.name[0] ==
'.') && (msdos_name[0] !=
'.');
284 if (!
fat_scan(dir, msdos_name, &sinfo)) {
291 err = msdos_add_entry(dir, msdos_name, 0, is_hid, 0, &ts, &sinfo);
297 err = PTR_ERR(inode);
312 static int msdos_rmdir(
struct inode *dir,
struct dentry *dentry)
315 struct inode *inode = dentry->
d_inode;
327 err = msdos_find(dir, dentry->
d_name.name, dentry->
d_name.len, &sinfo);
348 static int msdos_mkdir(
struct inode *dir,
struct dentry *dentry,
umode_t mode)
359 err = msdos_format_name(dentry->
d_name.name, dentry->
d_name.len,
360 msdos_name, &MSDOS_SB(sb)->options);
363 is_hid = (dentry->
d_name.name[0] ==
'.') && (msdos_name[0] !=
'.');
365 if (!
fat_scan(dir, msdos_name, &sinfo)) {
377 err = msdos_add_entry(dir, msdos_name, 1, is_hid, cluster, &ts, &sinfo);
385 err = PTR_ERR(inode);
407 static int msdos_unlink(
struct inode *dir,
struct dentry *dentry)
409 struct inode *inode = dentry->
d_inode;
415 err = msdos_find(dir, dentry->
d_name.name, dentry->
d_name.len, &sinfo);
433 static int do_msdos_rename(
struct inode *old_dir,
unsigned char *old_name,
434 struct dentry *old_dentry,
435 struct inode *new_dir,
unsigned char *new_name,
436 struct dentry *new_dentry,
int is_hid)
438 struct buffer_head *dotdot_bh;
444 int err, old_attrs, is_dir, update_dotdot, corrupt = 0;
446 old_sinfo.bh = sinfo.
bh = dotdot_bh =
NULL;
447 old_inode = old_dentry->
d_inode;
448 new_inode = new_dentry->
d_inode;
450 err =
fat_scan(old_dir, old_name, &old_sinfo);
457 update_dotdot = (is_dir && old_dir != new_dir);
465 old_attrs = MSDOS_I(old_inode)->i_attrs;
466 err =
fat_scan(new_dir, new_name, &sinfo);
470 if (sinfo.
de != old_sinfo.de) {
481 MSDOS_I(old_inode)->i_attrs = old_attrs;
485 mark_inode_dirty(old_inode);
492 mark_inode_dirty(old_dir);
506 new_i_pos = MSDOS_I(new_inode)->i_pos;
509 err = msdos_add_entry(new_dir, new_name, is_dir, is_hid, 0,
513 new_i_pos = sinfo.
i_pos;
528 mark_inode_dirty(old_inode);
531 fat_set_start(dotdot_de, MSDOS_I(new_dir)->i_logstart);
552 mark_inode_dirty(old_dir);
563 brelse(old_sinfo.bh);
571 fat_set_start(dotdot_de, MSDOS_I(old_dir)->i_logstart);
578 MSDOS_I(old_inode)->i_attrs = old_attrs;
595 "%s: Filesystem corrupted (i_pos %lld)",
596 __func__, sinfo.
i_pos);
602 static int msdos_rename(
struct inode *old_dir,
struct dentry *old_dentry,
603 struct inode *new_dir,
struct dentry *new_dentry)
611 err = msdos_format_name(old_dentry->
d_name.name,
612 old_dentry->
d_name.len, old_msdos_name,
613 &MSDOS_SB(old_dir->
i_sb)->options);
616 err = msdos_format_name(new_dentry->
d_name.name,
617 new_dentry->
d_name.len, new_msdos_name,
618 &MSDOS_SB(new_dir->
i_sb)->options);
623 (new_dentry->
d_name.name[0] ==
'.') && (new_msdos_name[0] !=
'.');
625 err = do_msdos_rename(old_dir, old_msdos_name, old_dentry,
626 new_dir, new_msdos_name, new_dentry, is_hid);
635 .create = msdos_create,
636 .lookup = msdos_lookup,
637 .unlink = msdos_unlink,
638 .mkdir = msdos_mkdir,
639 .rmdir = msdos_rmdir,
640 .rename = msdos_rename,
647 MSDOS_SB(sb)->dir_ops = &msdos_dir_inode_operations;
648 sb->
s_d_op = &msdos_dentry_operations;
652 static int msdos_fill_super(
struct super_block *sb,
void *
data,
int silent)
658 int flags,
const char *dev_name,
661 return mount_bdev(fs_type, flags, dev_name, data, msdos_fill_super);
667 .mount = msdos_mount,
672 static int __init init_msdos_fs(
void)
677 static void __exit exit_msdos_fs(
void)