Commit 9410e656 authored by Hirofumi Ogawa's avatar Hirofumi Ogawa Committed by Linus Torvalds

[PATCH] FAT: Use "struct fat_slot_info" for msdos_find()

The msdos_find() provide the "struct fat_slot_info". Then some cleanups.
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 9117711f
...@@ -137,11 +137,9 @@ static int msdos_format_name(const unsigned char *name, int len, ...@@ -137,11 +137,9 @@ static int msdos_format_name(const unsigned char *name, int len,
/***** Locates a directory entry. Uses unformatted name. */ /***** Locates a directory entry. Uses unformatted name. */
static int msdos_find(struct inode *dir, const unsigned char *name, int len, static int msdos_find(struct inode *dir, const unsigned char *name, int len,
struct buffer_head **bh, struct msdos_dir_entry **de, struct fat_slot_info *sinfo)
loff_t *i_pos)
{ {
struct msdos_sb_info *sbi = MSDOS_SB(dir->i_sb); struct msdos_sb_info *sbi = MSDOS_SB(dir->i_sb);
struct fat_slot_info sinfo;
unsigned char msdos_name[MSDOS_NAME]; unsigned char msdos_name[MSDOS_NAME];
int err; int err;
...@@ -149,22 +147,17 @@ static int msdos_find(struct inode *dir, const unsigned char *name, int len, ...@@ -149,22 +147,17 @@ static int msdos_find(struct inode *dir, const unsigned char *name, int len,
if (err) if (err)
return -ENOENT; return -ENOENT;
err = fat_scan(dir, msdos_name, &sinfo); err = fat_scan(dir, msdos_name, sinfo);
if (!err && sbi->options.dotsOK) { if (!err && sbi->options.dotsOK) {
if (name[0] == '.') { if (name[0] == '.') {
if (!(sinfo.de->attr & ATTR_HIDDEN)) if (!(sinfo->de->attr & ATTR_HIDDEN))
err = -ENOENT; err = -ENOENT;
} else { } else {
if (sinfo.de->attr & ATTR_HIDDEN) if (sinfo->de->attr & ATTR_HIDDEN)
err = -ENOENT; err = -ENOENT;
} }
if (err) if (err)
brelse(sinfo.bh); brelse(sinfo->bh);
}
if (!err) {
*i_pos = sinfo.i_pos;
*de = sinfo.de;
*bh = sinfo.bh;
} }
return err; return err;
} }
...@@ -228,22 +221,20 @@ static struct dentry *msdos_lookup(struct inode *dir, struct dentry *dentry, ...@@ -228,22 +221,20 @@ static struct dentry *msdos_lookup(struct inode *dir, struct dentry *dentry,
struct nameidata *nd) struct nameidata *nd)
{ {
struct super_block *sb = dir->i_sb; struct super_block *sb = dir->i_sb;
struct fat_slot_info sinfo;
struct inode *inode = NULL; struct inode *inode = NULL;
struct msdos_dir_entry *de;
struct buffer_head *bh = NULL;
loff_t i_pos;
int res; int res;
dentry->d_op = &msdos_dentry_operations; dentry->d_op = &msdos_dentry_operations;
lock_kernel(); lock_kernel();
res = msdos_find(dir, dentry->d_name.name, dentry->d_name.len, &bh, res = msdos_find(dir, dentry->d_name.name, dentry->d_name.len, &sinfo);
&de, &i_pos);
if (res == -ENOENT) if (res == -ENOENT)
goto add; goto add;
if (res < 0) if (res < 0)
goto out; goto out;
inode = fat_build_inode(sb, de, i_pos); inode = fat_build_inode(sb, sinfo.de, sinfo.i_pos);
brelse(sinfo.bh);
if (IS_ERR(inode)) { if (IS_ERR(inode)) {
res = PTR_ERR(inode); res = PTR_ERR(inode);
goto out; goto out;
...@@ -254,7 +245,6 @@ static struct dentry *msdos_lookup(struct inode *dir, struct dentry *dentry, ...@@ -254,7 +245,6 @@ static struct dentry *msdos_lookup(struct inode *dir, struct dentry *dentry,
if (dentry) if (dentry)
dentry->d_op = &msdos_dentry_operations; dentry->d_op = &msdos_dentry_operations;
out: out:
brelse(bh);
unlock_kernel(); unlock_kernel();
if (!res) if (!res)
return dentry; return dentry;
...@@ -341,39 +331,35 @@ static int msdos_create(struct inode *dir, struct dentry *dentry, int mode, ...@@ -341,39 +331,35 @@ static int msdos_create(struct inode *dir, struct dentry *dentry, int mode,
static int msdos_rmdir(struct inode *dir, struct dentry *dentry) static int msdos_rmdir(struct inode *dir, struct dentry *dentry)
{ {
struct inode *inode = dentry->d_inode; struct inode *inode = dentry->d_inode;
loff_t i_pos; struct fat_slot_info sinfo;
int res; int err;
struct buffer_head *bh;
struct msdos_dir_entry *de;
bh = NULL;
lock_kernel(); lock_kernel();
res = msdos_find(dir, dentry->d_name.name, dentry->d_name.len,
&bh, &de, &i_pos);
if (res < 0)
goto rmdir_done;
/* /*
* Check whether the directory is not in use, then check * Check whether the directory is not in use, then check
* whether it is empty. * whether it is empty.
*/ */
res = fat_dir_empty(inode); err = fat_dir_empty(inode);
if (res) if (err)
goto rmdir_done; goto out;
err = msdos_find(dir, dentry->d_name.name, dentry->d_name.len, &sinfo);
if (err)
goto out;
de->name[0] = DELETED_FLAG; sinfo.de->name[0] = DELETED_FLAG;
mark_buffer_dirty(bh); mark_buffer_dirty(sinfo.bh);
brelse(sinfo.bh);
fat_detach(inode); fat_detach(inode);
inode->i_nlink = 0; inode->i_nlink = 0;
inode->i_ctime = dir->i_ctime = dir->i_mtime = CURRENT_TIME_SEC; inode->i_ctime = dir->i_ctime = dir->i_mtime = CURRENT_TIME_SEC;
dir->i_nlink--;
mark_inode_dirty(inode); mark_inode_dirty(inode);
mark_inode_dirty(dir);
res = 0;
rmdir_done: dir->i_nlink--;
brelse(bh); mark_inode_dirty(dir);
out:
unlock_kernel(); unlock_kernel();
return res;
return err;
} }
/***** Make a directory */ /***** Make a directory */
...@@ -420,6 +406,7 @@ static int msdos_mkdir(struct inode *dir, struct dentry *dentry, int mode) ...@@ -420,6 +406,7 @@ static int msdos_mkdir(struct inode *dir, struct dentry *dentry, int mode)
if (res) if (res)
goto mkdir_error; goto mkdir_error;
brelse(bh); brelse(bh);
d_instantiate(dentry, inode); d_instantiate(dentry, inode);
res = 0; res = 0;
...@@ -445,30 +432,27 @@ static int msdos_mkdir(struct inode *dir, struct dentry *dentry, int mode) ...@@ -445,30 +432,27 @@ static int msdos_mkdir(struct inode *dir, struct dentry *dentry, int mode)
static int msdos_unlink(struct inode *dir, struct dentry *dentry) static int msdos_unlink(struct inode *dir, struct dentry *dentry)
{ {
struct inode *inode = dentry->d_inode; struct inode *inode = dentry->d_inode;
loff_t i_pos; struct fat_slot_info sinfo;
int res; int err;
struct buffer_head *bh;
struct msdos_dir_entry *de;
bh = NULL;
lock_kernel(); lock_kernel();
res = msdos_find(dir, dentry->d_name.name, dentry->d_name.len, err = msdos_find(dir, dentry->d_name.name, dentry->d_name.len, &sinfo);
&bh, &de, &i_pos); if (err)
if (res < 0)
goto unlink_done; goto unlink_done;
de->name[0] = DELETED_FLAG; sinfo.de->name[0] = DELETED_FLAG;
mark_buffer_dirty(bh); mark_buffer_dirty(sinfo.bh);
brelse(sinfo.bh);
fat_detach(inode); fat_detach(inode);
brelse(bh);
inode->i_nlink = 0; inode->i_nlink = 0;
inode->i_ctime = dir->i_ctime = dir->i_mtime = CURRENT_TIME_SEC; inode->i_ctime = dir->i_ctime = dir->i_mtime = CURRENT_TIME_SEC;
mark_inode_dirty(inode); mark_inode_dirty(inode);
mark_inode_dirty(dir); mark_inode_dirty(dir);
res = 0;
unlink_done: unlink_done:
unlock_kernel(); unlock_kernel();
return res;
return err;
} }
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,
......
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