summaryrefslogtreecommitdiffstats
path: root/fs/udf/file.c
diff options
context:
space:
mode:
authorAl Viro <viro@zeniv.linux.org.uk>2015-04-07 15:26:36 -0400
committerAl Viro <viro@zeniv.linux.org.uk>2015-04-11 22:29:50 -0400
commit165f1a6e300d5a1ffb57cf9a9c8762de731228f2 (patch)
treefadc5427bf20e6b335d157c725d60374300794bd /fs/udf/file.c
parent6b775b18eecf60b8a44723e05f8eb6251b71a7a9 (diff)
downloadlinux-165f1a6e300d5a1ffb57cf9a9c8762de731228f2.tar.gz
linux-165f1a6e300d5a1ffb57cf9a9c8762de731228f2.tar.bz2
linux-165f1a6e300d5a1ffb57cf9a9c8762de731228f2.zip
udf_file_write_iter: reorder and simplify
it's easier to do generic_write_checks() first Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
Diffstat (limited to 'fs/udf/file.c')
-rw-r--r--fs/udf/file.c34
1 files changed, 14 insertions, 20 deletions
diff --git a/fs/udf/file.c b/fs/udf/file.c
index 6834509a7e5a..ccab8b78e363 100644
--- a/fs/udf/file.c
+++ b/fs/udf/file.c
@@ -120,21 +120,27 @@ static ssize_t udf_file_write_iter(struct kiocb *iocb, struct iov_iter *from)
ssize_t retval;
struct file *file = iocb->ki_filp;
struct inode *inode = file_inode(file);
- int err, pos;
size_t count = iov_iter_count(from);
struct udf_inode_info *iinfo = UDF_I(inode);
+ int err;
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);
if (iinfo->i_alloc_type == ICBTAG_FLAG_AD_IN_ICB) {
- if (file->f_flags & O_APPEND)
- pos = inode->i_size;
- else
- pos = iocb->ki_pos;
+ loff_t end = iocb->ki_pos + iov_iter_count(from);
if (inode->i_sb->s_blocksize <
- (udf_file_entry_alloc_offset(inode) +
- pos + count)) {
+ (udf_file_entry_alloc_offset(inode) + end)) {
err = udf_expand_file_adinicb(inode);
if (err) {
mutex_unlock(&inode->i_mutex);
@@ -142,24 +148,12 @@ static ssize_t udf_file_write_iter(struct kiocb *iocb, struct iov_iter *from)
return err;
}
} else {
- if (pos + count > inode->i_size)
- iinfo->i_lenAlloc = pos + count;
- else
- iinfo->i_lenAlloc = inode->i_size;
+ iinfo->i_lenAlloc = max(end, inode->i_size);
up_write(&iinfo->i_data_sem);
}
} else
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);
out:
mutex_unlock(&inode->i_mutex);