Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 347822
b: refs/heads/master
c: a02de96
h: refs/heads/master
v: v3
  • Loading branch information
David Howells committed Dec 20, 2012
1 parent 062035b commit 475e1d2
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 24 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: ef778e7ae67cd426c30cad43378b908f5eb0bad5
refs/heads/master: a02de9608595c8ef649ef03ae735b0b45e3d4396
50 changes: 27 additions & 23 deletions trunk/fs/open.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,33 +61,22 @@ int do_truncate(struct dentry *dentry, loff_t length, unsigned int time_attrs,
return ret;
}

static long do_sys_truncate(const char __user *pathname, loff_t length)
long vfs_truncate(struct path *path, loff_t length)
{
struct path path;
struct inode *inode;
int error;

error = -EINVAL;
if (length < 0) /* sorry, but loff_t says... */
goto out;
long error;

error = user_path(pathname, &path);
if (error)
goto out;
inode = path.dentry->d_inode;
inode = path->dentry->d_inode;

/* For directories it's -EISDIR, for other non-regulars - -EINVAL */
error = -EISDIR;
if (S_ISDIR(inode->i_mode))
goto dput_and_out;

error = -EINVAL;
return -EISDIR;
if (!S_ISREG(inode->i_mode))
goto dput_and_out;
return -EINVAL;

error = mnt_want_write(path.mnt);
error = mnt_want_write(path->mnt);
if (error)
goto dput_and_out;
goto out;

error = inode_permission(inode, MAY_WRITE);
if (error)
Expand All @@ -111,19 +100,34 @@ static long do_sys_truncate(const char __user *pathname, loff_t length)

error = locks_verify_truncate(inode, NULL, length);
if (!error)
error = security_path_truncate(&path);
error = security_path_truncate(path);
if (!error)
error = do_truncate(path.dentry, length, 0, NULL);
error = do_truncate(path->dentry, length, 0, NULL);

put_write_and_out:
put_write_access(inode);
mnt_drop_write_and_out:
mnt_drop_write(path.mnt);
dput_and_out:
path_put(&path);
mnt_drop_write(path->mnt);
out:
return error;
}
EXPORT_SYMBOL_GPL(vfs_truncate);

static long do_sys_truncate(const char __user *pathname, loff_t length)
{
struct path path;
int error;

if (length < 0) /* sorry, but loff_t says... */
return -EINVAL;

error = user_path(pathname, &path);
if (!error) {
error = vfs_truncate(&path, length);
path_put(&path);
}
return error;
}

SYSCALL_DEFINE2(truncate, const char __user *, path, long, length)
{
Expand Down
1 change: 1 addition & 0 deletions trunk/include/linux/fs.h
Original file line number Diff line number Diff line change
Expand Up @@ -1999,6 +1999,7 @@ struct filename {
bool separate; /* should "name" be freed? */
};

extern long vfs_truncate(struct path *, loff_t);
extern int do_truncate(struct dentry *, loff_t start, unsigned int time_attrs,
struct file *filp);
extern int do_fallocate(struct file *file, int mode, loff_t offset,
Expand Down

0 comments on commit 475e1d2

Please sign in to comment.