truncate: new helpers
Introduce new truncate helpers truncate_pagecache and inode_newsize_ok. vmtruncate is also consolidated from mm/memory.c and mm/nommu.c and into mm/truncate.c. Reviewed-by: Christoph Hellwig <hch@lst.de> Signed-off-by: Nick Piggin <npiggin@suse.de> Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
This commit is contained in:
40
mm/nommu.c
40
mm/nommu.c
@@ -82,46 +82,6 @@ DECLARE_RWSEM(nommu_region_sem);
|
||||
struct vm_operations_struct generic_file_vm_ops = {
|
||||
};
|
||||
|
||||
/*
|
||||
* Handle all mappings that got truncated by a "truncate()"
|
||||
* system call.
|
||||
*
|
||||
* NOTE! We have to be ready to update the memory sharing
|
||||
* between the file and the memory map for a potential last
|
||||
* incomplete page. Ugly, but necessary.
|
||||
*/
|
||||
int vmtruncate(struct inode *inode, loff_t offset)
|
||||
{
|
||||
struct address_space *mapping = inode->i_mapping;
|
||||
unsigned long limit;
|
||||
|
||||
if (inode->i_size < offset)
|
||||
goto do_expand;
|
||||
i_size_write(inode, offset);
|
||||
|
||||
truncate_inode_pages(mapping, offset);
|
||||
goto out_truncate;
|
||||
|
||||
do_expand:
|
||||
limit = current->signal->rlim[RLIMIT_FSIZE].rlim_cur;
|
||||
if (limit != RLIM_INFINITY && offset > limit)
|
||||
goto out_sig;
|
||||
if (offset > inode->i_sb->s_maxbytes)
|
||||
goto out;
|
||||
i_size_write(inode, offset);
|
||||
|
||||
out_truncate:
|
||||
if (inode->i_op->truncate)
|
||||
inode->i_op->truncate(inode);
|
||||
return 0;
|
||||
out_sig:
|
||||
send_sig(SIGXFSZ, current, 0);
|
||||
out:
|
||||
return -EFBIG;
|
||||
}
|
||||
|
||||
EXPORT_SYMBOL(vmtruncate);
|
||||
|
||||
/*
|
||||
* Return the total memory allocated for this pointer, not
|
||||
* just what the caller asked for.
|
||||
|
Viittaa uudesa ongelmassa
Block a user