aboutsummaryrefslogtreecommitdiffstats
path: root/fs/open.c
diff options
context:
space:
mode:
authorNeilBrown <neilb@suse.de>2006-01-08 04:02:39 -0500
committerLinus Torvalds <torvalds@g5.osdl.org>2006-01-08 23:13:52 -0500
commit4a30131e7dbb17e5fec6958bfac9da9aff1fa29b (patch)
tree2ff6139b393a9a413e2ea4db4dd2d15eec2201f8 /fs/open.c
parent788540141f4549637e89aadca6e25cf25eb53383 (diff)
[PATCH] Fix some problems with truncate and mtime semantics.
SUS requires that when truncating a file to the size that it currently is: truncate and ftruncate should NOT modify ctime or mtime O_TRUNC SHOULD modify ctime and mtime. Currently mtime and ctime are always modified on most local filesystems (side effect of ->truncate) or never modified (on NFS). With this patch: ATTR_CTIME|ATTR_MTIME are sent with ATTR_SIZE precisely when an update of these times is required whether size changes or not (via a new argument to do_truncate). This allows NFS to do the right thing for O_TRUNC. inode_setattr nolonger forces ATTR_MTIME|ATTR_CTIME when the ATTR_SIZE sets the size to it's current value. This allows local filesystems to do the right thing for f?truncate. Also, the logic in inode_setattr is changed a bit so there are two return points. One returns the error from vmtruncate if it failed, the other returns 0 (there can be no other failure). Finally, if vmtruncate succeeds, and ATTR_SIZE is the only change requested, we now fall-through and mark_inode_dirty. If a filesystem did not have a ->truncate function, then vmtruncate will have changed i_size, without marking the inode as 'dirty', and I think this is wrong. Signed-off-by: Neil Brown <neilb@suse.de> Cc: Christoph Hellwig <hch@lst.de> Cc: Trond Myklebust <trond.myklebust@fys.uio.no> Signed-off-by: Andrew Morton <akpm@osdl.org> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Diffstat (limited to 'fs/open.c')
-rw-r--r--fs/open.c9
1 files changed, 5 insertions, 4 deletions
diff --git a/fs/open.c b/fs/open.c
index f53a5b9ffb7d..94968cb3afca 100644
--- a/fs/open.c
+++ b/fs/open.c
@@ -194,7 +194,8 @@ out:
194 return error; 194 return error;
195} 195}
196 196
197int do_truncate(struct dentry *dentry, loff_t length, struct file *filp) 197int do_truncate(struct dentry *dentry, loff_t length, unsigned int time_attrs,
198 struct file *filp)
198{ 199{
199 int err; 200 int err;
200 struct iattr newattrs; 201 struct iattr newattrs;
@@ -204,7 +205,7 @@ int do_truncate(struct dentry *dentry, loff_t length, struct file *filp)
204 return -EINVAL; 205 return -EINVAL;
205 206
206 newattrs.ia_size = length; 207 newattrs.ia_size = length;
207 newattrs.ia_valid = ATTR_SIZE | ATTR_CTIME; 208 newattrs.ia_valid = ATTR_SIZE | time_attrs;
208 if (filp) { 209 if (filp) {
209 newattrs.ia_file = filp; 210 newattrs.ia_file = filp;
210 newattrs.ia_valid |= ATTR_FILE; 211 newattrs.ia_valid |= ATTR_FILE;
@@ -266,7 +267,7 @@ static inline long do_sys_truncate(const char __user * path, loff_t length)
266 error = locks_verify_truncate(inode, NULL, length); 267 error = locks_verify_truncate(inode, NULL, length);
267 if (!error) { 268 if (!error) {
268 DQUOT_INIT(inode); 269 DQUOT_INIT(inode);
269 error = do_truncate(nd.dentry, length, NULL); 270 error = do_truncate(nd.dentry, length, 0, NULL);
270 } 271 }
271 put_write_access(inode); 272 put_write_access(inode);
272 273
@@ -318,7 +319,7 @@ static inline long do_sys_ftruncate(unsigned int fd, loff_t length, int small)
318 319
319 error = locks_verify_truncate(inode, file, length); 320 error = locks_verify_truncate(inode, file, length);
320 if (!error) 321 if (!error)
321 error = do_truncate(dentry, length, file); 322 error = do_truncate(dentry, length, 0, file);
322out_putf: 323out_putf:
323 fput(file); 324 fput(file);
324out: 325out: