Commit be3a386a authored by Hirofumi Ogawa's avatar Hirofumi Ogawa Committed by Linus Torvalds

[PATCH] FAT: msdos_rename() cleanup

Cleans up the msdos_rename(). (use the logic similar to vfat_rename().)
Signed-off-by: default avatarOGAWA Hirofumi <hirofumi@mail.parknet.co.jp>
Signed-off-by: default avatarAndrew Morton <akpm@osdl.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@osdl.org>
parent 262adc81
...@@ -458,146 +458,149 @@ static int msdos_unlink(struct inode *dir, struct dentry *dentry) ...@@ -458,146 +458,149 @@ static int msdos_unlink(struct inode *dir, struct dentry *dentry)
static int do_msdos_rename(struct inode *old_dir, unsigned char *old_name, static int do_msdos_rename(struct inode *old_dir, unsigned char *old_name,
struct dentry *old_dentry, struct dentry *old_dentry,
struct inode *new_dir, unsigned char *new_name, struct inode *new_dir, unsigned char *new_name,
struct dentry *new_dentry, struct dentry *new_dentry, int is_hid)
struct buffer_head *old_bh,
struct msdos_dir_entry *old_de, loff_t old_i_pos,
int is_hid)
{ {
struct fat_slot_info sinfo; struct buffer_head *dotdot_bh;
struct buffer_head *new_bh = NULL, *dotdot_bh = NULL; struct msdos_dir_entry *dotdot_de;
struct msdos_dir_entry *new_de, *dotdot_de; loff_t dotdot_i_pos;
struct inode *old_inode, *new_inode; struct inode *old_inode, *new_inode;
loff_t new_i_pos, dotdot_i_pos; struct fat_slot_info old_sinfo, sinfo;
int error; int err, is_dir;
int is_dir;
old_sinfo.bh = dotdot_bh = NULL;
old_inode = old_dentry->d_inode; old_inode = old_dentry->d_inode;
new_inode = new_dentry->d_inode; new_inode = new_dentry->d_inode;
is_dir = S_ISDIR(old_inode->i_mode);
error = fat_scan(new_dir, new_name, &sinfo); err = fat_scan(old_dir, old_name, &old_sinfo);
if (!error) { if (err) {
new_i_pos = sinfo.i_pos; err = -EIO;
new_bh = sinfo.bh; goto out;
new_de = sinfo.de;
if (!new_inode)
goto degenerate_case;
} }
is_dir = S_ISDIR(old_inode->i_mode);
if (is_dir) { if (is_dir) {
if (new_inode) {
error = fat_dir_empty(new_inode);
if (error)
goto out;
}
if (fat_get_dotdot_entry(old_inode, &dotdot_bh, &dotdot_de, if (fat_get_dotdot_entry(old_inode, &dotdot_bh, &dotdot_de,
&dotdot_i_pos) < 0) { &dotdot_i_pos) < 0) {
error = -EIO; err = -EIO;
goto out; goto out;
} }
} }
if (!new_bh) {
error = msdos_add_entry(new_dir, new_name, &new_bh, &new_de, err = fat_scan(new_dir, new_name, &sinfo);
&new_i_pos, is_dir, is_hid); if (!err) {
if (error) brelse(sinfo.bh);
if (!new_inode) {
/* "foo" -> ".foo" case. just change the ATTR_HIDDEN */
if (sinfo.de != old_sinfo.de) {
err = -EINVAL;
goto out;
}
if (is_hid)
MSDOS_I(old_inode)->i_attrs |= ATTR_HIDDEN;
else
MSDOS_I(old_inode)->i_attrs &= ~ATTR_HIDDEN;
mark_inode_dirty(old_inode);
old_dir->i_version++;
old_dir->i_ctime = old_dir->i_mtime = CURRENT_TIME_SEC;
mark_inode_dirty(old_dir);
goto out; goto out;
}
} }
new_dir->i_version++; if (new_inode) {
if (err)
/* There we go */ goto out;
if (MSDOS_I(new_inode)->i_pos != sinfo.i_pos) {
/* WTF??? Cry and fail. */
printk(KERN_WARNING "msdos_rename: fs corrupted\n");
goto out;
}
if (new_inode) if (is_dir) {
err = fat_dir_empty(new_inode);
if (err)
goto out;
}
fat_detach(new_inode); fat_detach(new_inode);
old_de->name[0] = DELETED_FLAG; } else {
mark_buffer_dirty(old_bh); err = msdos_add_entry(new_dir, new_name, &sinfo.bh, &sinfo.de,
&sinfo.i_pos, is_dir, is_hid);
if (err)
goto out;
brelse(sinfo.bh);
}
new_dir->i_version++;
old_sinfo.de->name[0] = DELETED_FLAG;
mark_buffer_dirty(old_sinfo.bh);
brelse(old_sinfo.bh);
old_sinfo.bh = NULL;
if (is_dir)
old_dir->i_nlink--;
fat_detach(old_inode); fat_detach(old_inode);
fat_attach(old_inode, new_i_pos); fat_attach(old_inode, sinfo.i_pos);
if (is_hid) if (is_hid)
MSDOS_I(old_inode)->i_attrs |= ATTR_HIDDEN; MSDOS_I(old_inode)->i_attrs |= ATTR_HIDDEN;
else else
MSDOS_I(old_inode)->i_attrs &= ~ATTR_HIDDEN; MSDOS_I(old_inode)->i_attrs &= ~ATTR_HIDDEN;
mark_inode_dirty(old_inode); mark_inode_dirty(old_inode);
old_dir->i_version++; old_dir->i_version++;
old_dir->i_ctime = old_dir->i_mtime = CURRENT_TIME_SEC; old_dir->i_ctime = old_dir->i_mtime = CURRENT_TIME_SEC;
mark_inode_dirty(old_dir); mark_inode_dirty(old_dir);
if (new_inode) { if (new_inode) {
new_inode->i_nlink--; new_inode->i_nlink--;
new_inode->i_ctime = CURRENT_TIME_SEC; new_inode->i_ctime = CURRENT_TIME_SEC;
mark_inode_dirty(new_inode); mark_inode_dirty(new_inode);
} }
if (dotdot_bh) { if (is_dir) {
dotdot_de->start = cpu_to_le16(MSDOS_I(new_dir)->i_logstart); int start = MSDOS_I(new_dir)->i_logstart;
dotdot_de->starthi = dotdot_de->start = cpu_to_le16(start);
cpu_to_le16((MSDOS_I(new_dir)->i_logstart) >> 16); dotdot_de->starthi = cpu_to_le16(start >> 16);
mark_buffer_dirty(dotdot_bh); mark_buffer_dirty(dotdot_bh);
old_dir->i_nlink--;
mark_inode_dirty(old_dir);
if (new_inode) { if (new_inode) {
new_inode->i_nlink--; new_inode->i_nlink--;
mark_inode_dirty(new_inode);
} else { } else {
new_dir->i_nlink++; new_dir->i_nlink++;
mark_inode_dirty(new_dir); mark_inode_dirty(new_dir);
} }
} }
error = 0;
out: out:
brelse(new_bh);
brelse(dotdot_bh); brelse(dotdot_bh);
return error; brelse(old_sinfo.bh);
return err;
degenerate_case:
error = -EINVAL;
if (new_de != old_de)
goto out;
brelse(new_bh);
if (is_hid)
MSDOS_I(old_inode)->i_attrs |= ATTR_HIDDEN;
else
MSDOS_I(old_inode)->i_attrs &= ~ATTR_HIDDEN;
mark_inode_dirty(old_inode);
old_dir->i_version++;
old_dir->i_ctime = old_dir->i_mtime = CURRENT_TIME_SEC;
mark_inode_dirty(old_dir);
return 0;
} }
/***** Rename, a wrapper for rename_same_dir & rename_diff_dir */ /***** Rename, a wrapper for rename_same_dir & rename_diff_dir */
static int msdos_rename(struct inode *old_dir, struct dentry *old_dentry, static int msdos_rename(struct inode *old_dir, struct dentry *old_dentry,
struct inode *new_dir, struct dentry *new_dentry) struct inode *new_dir, struct dentry *new_dentry)
{ {
struct fat_slot_info sinfo;
int error, is_hid, old_hid; /* if new file and old file are hidden */
unsigned char old_msdos_name[MSDOS_NAME], new_msdos_name[MSDOS_NAME]; unsigned char old_msdos_name[MSDOS_NAME], new_msdos_name[MSDOS_NAME];
int err, is_hid;
lock_kernel(); lock_kernel();
error = msdos_format_name(old_dentry->d_name.name,
old_dentry->d_name.len, old_msdos_name, err = msdos_format_name(old_dentry->d_name.name,
&MSDOS_SB(old_dir->i_sb)->options); old_dentry->d_name.len, old_msdos_name,
if (error < 0) &MSDOS_SB(old_dir->i_sb)->options);
goto rename_done; if (err)
error = msdos_format_name(new_dentry->d_name.name, goto out;
new_dentry->d_name.len, new_msdos_name, err = msdos_format_name(new_dentry->d_name.name,
&MSDOS_SB(new_dir->i_sb)->options); new_dentry->d_name.len, new_msdos_name,
if (error < 0) &MSDOS_SB(new_dir->i_sb)->options);
goto rename_done; if (err)
goto out;
is_hid = is_hid =
(new_dentry->d_name.name[0] == '.') && (new_msdos_name[0] != '.'); (new_dentry->d_name.name[0] == '.') && (new_msdos_name[0] != '.');
old_hid =
(old_dentry->d_name.name[0] == '.') && (old_msdos_name[0] != '.');
error = fat_scan(old_dir, old_msdos_name, &sinfo);
if (error < 0)
goto rename_done;
error = do_msdos_rename(old_dir, old_msdos_name, old_dentry,
new_dir, new_msdos_name, new_dentry,
sinfo.bh, sinfo.de, sinfo.i_pos, is_hid);
brelse(sinfo.bh);
rename_done: err = do_msdos_rename(old_dir, old_msdos_name, old_dentry,
new_dir, new_msdos_name, new_dentry, is_hid);
out:
unlock_kernel(); unlock_kernel();
return error; return err;
} }
static struct inode_operations msdos_dir_inode_operations = { static struct inode_operations msdos_dir_inode_operations = {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment