diff options
-rw-r--r-- | fs/attr.c | 24 | ||||
-rw-r--r-- | fs/exec.c | 2 | ||||
-rw-r--r-- | fs/namei.c | 2 | ||||
-rw-r--r-- | fs/open.c | 9 | ||||
-rw-r--r-- | include/linux/fs.h | 3 |
5 files changed, 17 insertions, 23 deletions
@@ -67,20 +67,12 @@ EXPORT_SYMBOL(inode_change_ok); | |||
67 | int inode_setattr(struct inode * inode, struct iattr * attr) | 67 | int inode_setattr(struct inode * inode, struct iattr * attr) |
68 | { | 68 | { |
69 | unsigned int ia_valid = attr->ia_valid; | 69 | unsigned int ia_valid = attr->ia_valid; |
70 | int error = 0; | 70 | |
71 | 71 | if (ia_valid & ATTR_SIZE && | |
72 | if (ia_valid & ATTR_SIZE) { | 72 | attr->ia_size != i_size_read(inode)) { |
73 | if (attr->ia_size != i_size_read(inode)) { | 73 | int error = vmtruncate(inode, attr->ia_size); |
74 | error = vmtruncate(inode, attr->ia_size); | 74 | if (error) |
75 | if (error || (ia_valid == ATTR_SIZE)) | 75 | return error; |
76 | goto out; | ||
77 | } else { | ||
78 | /* | ||
79 | * We skipped the truncate but must still update | ||
80 | * timestamps | ||
81 | */ | ||
82 | ia_valid |= ATTR_MTIME|ATTR_CTIME; | ||
83 | } | ||
84 | } | 76 | } |
85 | 77 | ||
86 | if (ia_valid & ATTR_UID) | 78 | if (ia_valid & ATTR_UID) |
@@ -104,8 +96,8 @@ int inode_setattr(struct inode * inode, struct iattr * attr) | |||
104 | inode->i_mode = mode; | 96 | inode->i_mode = mode; |
105 | } | 97 | } |
106 | mark_inode_dirty(inode); | 98 | mark_inode_dirty(inode); |
107 | out: | 99 | |
108 | return error; | 100 | return 0; |
109 | } | 101 | } |
110 | EXPORT_SYMBOL(inode_setattr); | 102 | EXPORT_SYMBOL(inode_setattr); |
111 | 103 | ||
@@ -1505,7 +1505,7 @@ int do_coredump(long signr, int exit_code, struct pt_regs * regs) | |||
1505 | goto close_fail; | 1505 | goto close_fail; |
1506 | if (!file->f_op->write) | 1506 | if (!file->f_op->write) |
1507 | goto close_fail; | 1507 | goto close_fail; |
1508 | if (do_truncate(file->f_dentry, 0, file) != 0) | 1508 | if (do_truncate(file->f_dentry, 0, 0, file) != 0) |
1509 | goto close_fail; | 1509 | goto close_fail; |
1510 | 1510 | ||
1511 | retval = binfmt->core_dump(signr, regs, file); | 1511 | retval = binfmt->core_dump(signr, regs, file); |
diff --git a/fs/namei.c b/fs/namei.c index 6dbbd42d8b95..300eae088d5f 100644 --- a/fs/namei.c +++ b/fs/namei.c | |||
@@ -1491,7 +1491,7 @@ int may_open(struct nameidata *nd, int acc_mode, int flag) | |||
1491 | if (!error) { | 1491 | if (!error) { |
1492 | DQUOT_INIT(inode); | 1492 | DQUOT_INIT(inode); |
1493 | 1493 | ||
1494 | error = do_truncate(dentry, 0, NULL); | 1494 | error = do_truncate(dentry, 0, ATTR_MTIME|ATTR_CTIME, NULL); |
1495 | } | 1495 | } |
1496 | put_write_access(inode); | 1496 | put_write_access(inode); |
1497 | if (error) | 1497 | if (error) |
@@ -194,7 +194,8 @@ out: | |||
194 | return error; | 194 | return error; |
195 | } | 195 | } |
196 | 196 | ||
197 | int do_truncate(struct dentry *dentry, loff_t length, struct file *filp) | 197 | int 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); |
322 | out_putf: | 323 | out_putf: |
323 | fput(file); | 324 | fput(file); |
324 | out: | 325 | out: |
diff --git a/include/linux/fs.h b/include/linux/fs.h index ef29500b5df8..74c01aabd4ab 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h | |||
@@ -1344,7 +1344,8 @@ static inline int break_lease(struct inode *inode, unsigned int mode) | |||
1344 | 1344 | ||
1345 | /* fs/open.c */ | 1345 | /* fs/open.c */ |
1346 | 1346 | ||
1347 | extern int do_truncate(struct dentry *, loff_t start, struct file *filp); | 1347 | extern int do_truncate(struct dentry *, loff_t start, unsigned int time_attrs, |
1348 | struct file *filp); | ||
1348 | extern long do_sys_open(const char __user *filename, int flags, int mode); | 1349 | extern long do_sys_open(const char __user *filename, int flags, int mode); |
1349 | extern struct file *filp_open(const char *, int, int); | 1350 | extern struct file *filp_open(const char *, int, int); |
1350 | extern struct file * dentry_open(struct dentry *, struct vfsmount *, int); | 1351 | extern struct file * dentry_open(struct dentry *, struct vfsmount *, int); |