Commit 165f1a6e authored by Al Viro's avatar Al Viro

udf_file_write_iter: reorder and simplify

it's easier to do generic_write_checks() first
Signed-off-by: default avatarAl Viro <viro@zeniv.linux.org.uk>
parent 6b775b18
...@@ -120,21 +120,27 @@ static ssize_t udf_file_write_iter(struct kiocb *iocb, struct iov_iter *from) ...@@ -120,21 +120,27 @@ static ssize_t udf_file_write_iter(struct kiocb *iocb, struct iov_iter *from)
ssize_t retval; ssize_t retval;
struct file *file = iocb->ki_filp; struct file *file = iocb->ki_filp;
struct inode *inode = file_inode(file); struct inode *inode = file_inode(file);
int err, pos;
size_t count = iov_iter_count(from); size_t count = iov_iter_count(from);
struct udf_inode_info *iinfo = UDF_I(inode); struct udf_inode_info *iinfo = UDF_I(inode);
int err;
mutex_lock(&inode->i_mutex); mutex_lock(&inode->i_mutex);
retval = generic_write_checks(file, &iocb->ki_pos, &count);
if (retval)
goto out;
if (count == 0)
goto out;
iov_iter_truncate(from, count);
down_write(&iinfo->i_data_sem); down_write(&iinfo->i_data_sem);
if (iinfo->i_alloc_type == ICBTAG_FLAG_AD_IN_ICB) { if (iinfo->i_alloc_type == ICBTAG_FLAG_AD_IN_ICB) {
if (file->f_flags & O_APPEND) loff_t end = iocb->ki_pos + iov_iter_count(from);
pos = inode->i_size;
else
pos = iocb->ki_pos;
if (inode->i_sb->s_blocksize < if (inode->i_sb->s_blocksize <
(udf_file_entry_alloc_offset(inode) + (udf_file_entry_alloc_offset(inode) + end)) {
pos + count)) {
err = udf_expand_file_adinicb(inode); err = udf_expand_file_adinicb(inode);
if (err) { if (err) {
mutex_unlock(&inode->i_mutex); mutex_unlock(&inode->i_mutex);
...@@ -142,24 +148,12 @@ static ssize_t udf_file_write_iter(struct kiocb *iocb, struct iov_iter *from) ...@@ -142,24 +148,12 @@ static ssize_t udf_file_write_iter(struct kiocb *iocb, struct iov_iter *from)
return err; return err;
} }
} else { } else {
if (pos + count > inode->i_size) iinfo->i_lenAlloc = max(end, inode->i_size);
iinfo->i_lenAlloc = pos + count;
else
iinfo->i_lenAlloc = inode->i_size;
up_write(&iinfo->i_data_sem); up_write(&iinfo->i_data_sem);
} }
} else } else
up_write(&iinfo->i_data_sem); up_write(&iinfo->i_data_sem);
retval = generic_write_checks(file, &iocb->ki_pos, &count);
if (retval)
goto out;
if (count == 0)
goto out;
iov_iter_truncate(from, count);
retval = __generic_file_write_iter(iocb, from); retval = __generic_file_write_iter(iocb, from);
out: out:
mutex_unlock(&inode->i_mutex); mutex_unlock(&inode->i_mutex);
......
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