Commit d2be51cb authored by Al Viro's avatar Al Viro Committed by Jan Kara

udf: merge the pieces inserting a new non-directory object into directory

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: default avatarAl Viro <viro@zeniv.linux.org.uk>
Signed-off-by: default avatarJan Kara <jack@suse.cz>
parent 470cca56
...@@ -548,31 +548,16 @@ static int udf_delete_entry(struct inode *inode, struct fileIdentDesc *fi, ...@@ -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); return udf_write_fi(inode, cfi, fi, fibh, NULL, NULL);
} }
static int udf_create(struct inode *dir, struct dentry *dentry, umode_t mode, static int udf_add_nondir(struct dentry *dentry, struct inode *inode)
bool excl)
{ {
struct udf_inode_info *iinfo = UDF_I(inode);
struct inode *dir = dentry->d_parent->d_inode;
struct udf_fileident_bh fibh; struct udf_fileident_bh fibh;
struct inode *inode;
struct fileIdentDesc cfi, *fi; struct fileIdentDesc cfi, *fi;
int err; 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); fi = udf_add_entry(dir, dentry, &fibh, &cfi, &err);
if (!fi) { if (unlikely(!fi)) {
inode_dec_link_count(inode); inode_dec_link_count(inode);
iput(inode); iput(inode);
return err; return err;
...@@ -592,6 +577,28 @@ static int udf_create(struct inode *dir, struct dentry *dentry, umode_t mode, ...@@ -592,6 +577,28 @@ static int udf_create(struct inode *dir, struct dentry *dentry, umode_t mode,
return 0; 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) static int udf_tmpfile(struct inode *dir, struct dentry *dentry, umode_t mode)
{ {
struct inode *inode; struct inode *inode;
...@@ -619,10 +626,7 @@ static int udf_mknod(struct inode *dir, struct dentry *dentry, umode_t mode, ...@@ -619,10 +626,7 @@ static int udf_mknod(struct inode *dir, struct dentry *dentry, umode_t mode,
dev_t rdev) dev_t rdev)
{ {
struct inode *inode; struct inode *inode;
struct udf_fileident_bh fibh;
struct fileIdentDesc cfi, *fi;
int err; int err;
struct udf_inode_info *iinfo;
if (!old_valid_dev(rdev)) if (!old_valid_dev(rdev))
return -EINVAL; return -EINVAL;
...@@ -630,33 +634,10 @@ static int udf_mknod(struct inode *dir, struct dentry *dentry, umode_t mode, ...@@ -630,33 +634,10 @@ static int udf_mknod(struct inode *dir, struct dentry *dentry, umode_t mode,
err = -EIO; err = -EIO;
inode = udf_new_inode(dir, mode, &err); inode = udf_new_inode(dir, mode, &err);
if (!inode) 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; 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: init_special_inode(inode, mode, rdev);
return err; return udf_add_nondir(dentry, inode);
} }
static int udf_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode) static int udf_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode)
...@@ -877,11 +858,8 @@ static int udf_symlink(struct inode *dir, struct dentry *dentry, ...@@ -877,11 +858,8 @@ static int udf_symlink(struct inode *dir, struct dentry *dentry,
struct inode *inode; struct inode *inode;
struct pathComponent *pc; struct pathComponent *pc;
const char *compstart; const char *compstart;
struct udf_fileident_bh fibh;
struct extent_position epos = {}; struct extent_position epos = {};
int eoffset, elen = 0; int eoffset, elen = 0;
struct fileIdentDesc *fi;
struct fileIdentDesc cfi;
uint8_t *ea; uint8_t *ea;
int err; int err;
int block; int block;
...@@ -1010,31 +988,13 @@ static int udf_symlink(struct inode *dir, struct dentry *dentry, ...@@ -1010,31 +988,13 @@ static int udf_symlink(struct inode *dir, struct dentry *dentry,
mark_inode_dirty(inode); mark_inode_dirty(inode);
up_write(&iinfo->i_data_sem); up_write(&iinfo->i_data_sem);
fi = udf_add_entry(dir, dentry, &fibh, &cfi, &err); err = udf_add_nondir(dentry, inode);
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;
out: out:
kfree(name); kfree(name);
return err; return err;
out_no_entry: out_no_entry:
up_write(&iinfo->i_data_sem); up_write(&iinfo->i_data_sem);
out_fail:
inode_dec_link_count(inode); inode_dec_link_count(inode);
iput(inode); iput(inode);
goto out; goto out;
......
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