Skip to content

Commit

Permalink
udf: merge the pieces inserting a new non-directory object into direc…
Browse files Browse the repository at this point in the history
…tory

boilerplate code in udf_{create,mknod,symlink} taken to new helper

symlink case converted to unique id calculated by udf_new_inode() - no
point finding a new one.

Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
Signed-off-by: Jan Kara <jack@suse.cz>
  • Loading branch information
Al Viro authored and Jan Kara committed Sep 4, 2014
1 parent 470cca5 commit d2be51c
Showing 1 changed file with 29 additions and 69 deletions.
98 changes: 29 additions & 69 deletions fs/udf/namei.c
Original file line number Diff line number Diff line change
Expand Up @@ -548,31 +548,16 @@ static int udf_delete_entry(struct inode *inode, struct fileIdentDesc *fi,
return udf_write_fi(inode, cfi, fi, fibh, NULL, NULL);
}

static int udf_create(struct inode *dir, struct dentry *dentry, umode_t mode,
bool excl)
static int udf_add_nondir(struct dentry *dentry, struct inode *inode)
{
struct udf_inode_info *iinfo = UDF_I(inode);
struct inode *dir = dentry->d_parent->d_inode;
struct udf_fileident_bh fibh;
struct inode *inode;
struct fileIdentDesc cfi, *fi;
int err;
struct udf_inode_info *iinfo;

inode = udf_new_inode(dir, mode, &err);
if (!inode) {
return err;
}

iinfo = UDF_I(inode);
if (iinfo->i_alloc_type == ICBTAG_FLAG_AD_IN_ICB)
inode->i_data.a_ops = &udf_adinicb_aops;
else
inode->i_data.a_ops = &udf_aops;
inode->i_op = &udf_file_inode_operations;
inode->i_fop = &udf_file_operations;
mark_inode_dirty(inode);

fi = udf_add_entry(dir, dentry, &fibh, &cfi, &err);
if (!fi) {
if (unlikely(!fi)) {
inode_dec_link_count(inode);
iput(inode);
return err;
Expand All @@ -592,6 +577,28 @@ static int udf_create(struct inode *dir, struct dentry *dentry, umode_t mode,
return 0;
}

static int udf_create(struct inode *dir, struct dentry *dentry, umode_t mode,
bool excl)
{
struct inode *inode;
int err;

inode = udf_new_inode(dir, mode, &err);
if (!inode) {
return err;
}

if (UDF_I(inode)->i_alloc_type == ICBTAG_FLAG_AD_IN_ICB)
inode->i_data.a_ops = &udf_adinicb_aops;
else
inode->i_data.a_ops = &udf_aops;
inode->i_op = &udf_file_inode_operations;
inode->i_fop = &udf_file_operations;
mark_inode_dirty(inode);

return udf_add_nondir(dentry, inode);
}

static int udf_tmpfile(struct inode *dir, struct dentry *dentry, umode_t mode)
{
struct inode *inode;
Expand Down Expand Up @@ -619,44 +626,18 @@ static int udf_mknod(struct inode *dir, struct dentry *dentry, umode_t mode,
dev_t rdev)
{
struct inode *inode;
struct udf_fileident_bh fibh;
struct fileIdentDesc cfi, *fi;
int err;
struct udf_inode_info *iinfo;

if (!old_valid_dev(rdev))
return -EINVAL;

err = -EIO;
inode = udf_new_inode(dir, mode, &err);
if (!inode)
goto out;

iinfo = UDF_I(inode);
init_special_inode(inode, mode, rdev);
fi = udf_add_entry(dir, dentry, &fibh, &cfi, &err);
if (!fi) {
inode_dec_link_count(inode);
iput(inode);
return err;
}
cfi.icb.extLength = cpu_to_le32(inode->i_sb->s_blocksize);
cfi.icb.extLocation = cpu_to_lelb(iinfo->i_location);
*(__le32 *)((struct allocDescImpUse *)cfi.icb.impUse)->impUse =
cpu_to_le32(iinfo->i_unique & 0x00000000FFFFFFFFUL);
udf_write_fi(dir, &cfi, fi, &fibh, NULL, NULL);
if (UDF_I(dir)->i_alloc_type == ICBTAG_FLAG_AD_IN_ICB)
mark_inode_dirty(dir);
mark_inode_dirty(inode);

if (fibh.sbh != fibh.ebh)
brelse(fibh.ebh);
brelse(fibh.sbh);
d_instantiate(dentry, inode);
err = 0;

out:
return err;
init_special_inode(inode, mode, rdev);
return udf_add_nondir(dentry, inode);
}

static int udf_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode)
Expand Down Expand Up @@ -877,11 +858,8 @@ static int udf_symlink(struct inode *dir, struct dentry *dentry,
struct inode *inode;
struct pathComponent *pc;
const char *compstart;
struct udf_fileident_bh fibh;
struct extent_position epos = {};
int eoffset, elen = 0;
struct fileIdentDesc *fi;
struct fileIdentDesc cfi;
uint8_t *ea;
int err;
int block;
Expand Down Expand Up @@ -1010,31 +988,13 @@ static int udf_symlink(struct inode *dir, struct dentry *dentry,
mark_inode_dirty(inode);
up_write(&iinfo->i_data_sem);

fi = udf_add_entry(dir, dentry, &fibh, &cfi, &err);
if (!fi)
goto out_fail;
cfi.icb.extLength = cpu_to_le32(sb->s_blocksize);
cfi.icb.extLocation = cpu_to_lelb(iinfo->i_location);
if (UDF_SB(inode->i_sb)->s_lvid_bh) {
*(__le32 *)((struct allocDescImpUse *)cfi.icb.impUse)->impUse =
cpu_to_le32(lvid_get_unique_id(sb));
}
udf_write_fi(dir, &cfi, fi, &fibh, NULL, NULL);
if (UDF_I(dir)->i_alloc_type == ICBTAG_FLAG_AD_IN_ICB)
mark_inode_dirty(dir);
if (fibh.sbh != fibh.ebh)
brelse(fibh.ebh);
brelse(fibh.sbh);
d_instantiate(dentry, inode);
err = 0;

err = udf_add_nondir(dentry, inode);
out:
kfree(name);
return err;

out_no_entry:
up_write(&iinfo->i_data_sem);
out_fail:
inode_dec_link_count(inode);
iput(inode);
goto out;
Expand Down

0 comments on commit d2be51c

Please sign in to comment.