From: npiggin@suse.de
To: Andrew Morton <akpm@linux-foundation.org>
Cc: linux-fsdevel@vger.kernel.org, Christoph Hellwig <hch@lst.de>,
Jan Kara <jack@suse.cz>
Subject: [patch 10/11] udf: convert to use the new truncate convention.
Date: Fri, 21 Aug 2009 02:35:14 +1000 [thread overview]
Message-ID: <20090820164051.879013051@suse.de> (raw)
In-Reply-To: 20090820163504.131529718@suse.de
[-- Attachment #1: udf-new-truncate.patch --]
[-- Type: text/plain, Size: 4419 bytes --]
Cc: Jan Kara <jack@suse.cz>
Cc: Christoph Hellwig <hch@lst.de>
Signed-off-by: Nick Piggin <npiggin@suse.de>
---
fs/udf/file.c | 3 +-
fs/udf/inode.c | 73 +++++++++++++++++++++++++++++++++++++++++++++++++++----
fs/udf/udfdecl.h | 2 -
3 files changed, 71 insertions(+), 7 deletions(-)
Index: linux-2.6/fs/udf/inode.c
===================================================================
--- linux-2.6.orig/fs/udf/inode.c
+++ linux-2.6/fs/udf/inode.c
@@ -67,6 +67,7 @@ static void udf_update_extents(struct in
struct extent_position *);
static int udf_get_block(struct inode *, sector_t, struct buffer_head *, int);
+static void udf_truncate_blocks(struct inode *inode);
void udf_delete_inode(struct inode *inode)
{
@@ -76,7 +77,7 @@ void udf_delete_inode(struct inode *inod
goto no_delete;
inode->i_size = 0;
- udf_truncate(inode);
+ udf_truncate_blocks(inode);
lock_kernel();
udf_update_inode(inode, IS_SYNC(inode));
@@ -127,9 +128,34 @@ static int udf_write_begin(struct file *
loff_t pos, unsigned len, unsigned flags,
struct page **pagep, void **fsdata)
{
+ int ret;
+
*pagep = NULL;
- return block_write_begin(file, mapping, pos, len, flags, pagep, fsdata,
+ ret = block_write_begin(file, mapping, pos, len, flags, pagep, fsdata,
udf_get_block);
+ if (ret < 0) {
+ struct inode *inode = mapping->host;
+ loff_t isize = inode->i_size;
+ if (pos + len > isize)
+ udf_truncate_blocks(inode);
+ }
+ return ret;
+}
+
+static int udf_write_end(struct file *file, struct address_space *mapping,
+ loff_t pos, unsigned len, unsigned copied,
+ struct page *page, void *fsdata)
+{
+ int ret;
+
+ ret = generic_write_end(file, mapping, pos, len, copied, page, fsdata);
+ if (ret < len) {
+ struct inode *inode = mapping->host;
+ loff_t isize = inode->i_size;
+ if (pos + len > isize)
+ udf_truncate_blocks(inode);
+ }
+ return ret;
}
static sector_t udf_bmap(struct address_space *mapping, sector_t block)
@@ -141,8 +167,8 @@ const struct address_space_operations ud
.readpage = udf_readpage,
.writepage = udf_writepage,
.sync_page = block_sync_page,
- .write_begin = udf_write_begin,
- .write_end = generic_write_end,
+ .write_begin = udf_write_begin,
+ .write_end = udf_write_end,
.bmap = udf_bmap,
};
@@ -1011,7 +1037,7 @@ struct buffer_head *udf_bread(struct ino
return NULL;
}
-void udf_truncate(struct inode *inode)
+static void udf_truncate_blocks(struct inode *inode)
{
int offset;
int err;
@@ -1057,6 +1083,43 @@ void udf_truncate(struct inode *inode)
unlock_kernel();
}
+static int udf_setsize(struct inode *inode, loff_t newsize)
+{
+ loff_t oldsize;
+ int error;
+
+ error = inode_newsize_ok(inode, newsize);
+ if (error)
+ return error;
+
+ oldsize = inode->i_size;
+ i_size_write(inode, newsize);
+ truncate_pagecache(inode, oldsize, newsize);
+
+ udf_truncate_blocks(inode);
+
+ return error;
+}
+
+int udf_setattr(struct dentry *dentry, struct iattr *attr)
+{
+ struct inode *inode = dentry->d_inode;
+ int error;
+
+ if (attr->ia_valid & ATTR_SIZE) {
+ error = udf_setsize(inode, attr->ia_size);
+ if (error)
+ return error;
+ }
+
+ error = simple_setattr(dentry, attr);
+ if (error)
+ return error;
+
+ mark_inode_dirty(inode);
+ return error;
+}
+
static void __udf_read_inode(struct inode *inode)
{
struct buffer_head *bh = NULL;
Index: linux-2.6/fs/udf/udfdecl.h
===================================================================
--- linux-2.6.orig/fs/udf/udfdecl.h
+++ linux-2.6/fs/udf/udfdecl.h
@@ -138,7 +138,7 @@ extern int udf_sync_inode(struct inode *
extern void udf_expand_file_adinicb(struct inode *, int, int *);
extern struct buffer_head *udf_expand_dir_adinicb(struct inode *, int *, int *);
extern struct buffer_head *udf_bread(struct inode *, int, int, int *);
-extern void udf_truncate(struct inode *);
+extern int udf_setattr(struct dentry *, struct iattr *);
extern void udf_read_inode(struct inode *);
extern void udf_delete_inode(struct inode *);
extern void udf_clear_inode(struct inode *);
Index: linux-2.6/fs/udf/file.c
===================================================================
--- linux-2.6.orig/fs/udf/file.c
+++ linux-2.6/fs/udf/file.c
@@ -215,5 +215,6 @@ const struct file_operations udf_file_op
};
const struct inode_operations udf_file_inode_operations = {
- .truncate = udf_truncate,
+ .new_truncate = 1,
+ .setattr = udf_setattr,
};
next prev parent reply other threads:[~2009-08-20 16:42 UTC|newest]
Thread overview: 38+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-08-20 16:35 [patch 00/11] new truncate sequence npiggin
2009-08-20 16:35 ` [patch 01/11] fs: new truncate helpers npiggin
2009-08-26 7:38 ` Artem Bityutskiy
2009-09-07 7:33 ` Nick Piggin
2009-09-07 7:48 ` Artem Bityutskiy
2009-08-20 16:35 ` [patch 02/11] fs: use " npiggin
2009-08-20 16:35 ` npiggin-l3A5Bk7waGM
2009-08-20 16:35 ` [patch 03/11] fs: introduce new truncate sequence npiggin
2009-08-26 7:40 ` Artem Bityutskiy
2009-08-20 16:35 ` [patch 04/11] fs: convert simple fs to new truncate npiggin
2009-08-20 16:35 ` [patch 05/11] tmpfs: convert to use the new truncate convention npiggin
2009-08-20 16:35 ` [patch 06/11] ext2: " npiggin
2009-08-21 13:42 ` Jan Kara
2009-08-21 14:06 ` Jan Kara
2009-08-24 5:30 ` [patch] ext2: convert to use the new truncate convention fix Nick Piggin
2009-08-20 16:35 ` [patch 07/11] fat: convert to use the new truncate convention npiggin
2009-08-20 16:35 ` [patch 08/11] btrfs: " npiggin
2009-08-20 16:35 ` npiggin
2009-08-20 16:35 ` [patch 09/11] jfs: " npiggin
2009-08-20 16:35 ` npiggin [this message]
2009-08-21 14:22 ` [patch 10/11] udf: " Jan Kara
2009-08-24 5:33 ` Nick Piggin
2009-08-20 16:35 ` [patch 11/11] minix: " npiggin
2009-09-09 7:11 ` [patch 00/11] new truncate sequence Artem Bityutskiy
2009-09-22 15:04 ` Al Viro
2009-09-22 20:00 ` Christoph Hellwig
2009-09-22 21:51 ` Al Viro
2009-09-22 23:27 ` Al Viro
2009-09-22 23:58 ` Al Viro
2009-09-23 2:29 ` Al Viro
2009-09-27 19:50 ` Nick Piggin
2009-12-07 12:49 ` Nick Piggin
2009-12-07 22:46 ` Tyler Hicks
2009-09-22 20:53 ` [PATCH 12/n] kill spurious reference to vmtruncate Christoph Hellwig
2009-09-22 20:54 ` [PATCH 13/n] xfs: new truncate sequence Christoph Hellwig
2009-09-22 20:54 ` Christoph Hellwig
2009-09-22 20:55 ` [PATCH 14/n] sysv: " Christoph Hellwig
2009-09-22 20:56 ` [PATCH 15/n] ntfs: " Christoph Hellwig
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20090820164051.879013051@suse.de \
--to=npiggin@suse.de \
--cc=akpm@linux-foundation.org \
--cc=hch@lst.de \
--cc=jack@suse.cz \
--cc=linux-fsdevel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.