aboutsummaryrefslogtreecommitdiffstats
path: root/fs/libfs.c
diff options
context:
space:
mode:
Diffstat (limited to 'fs/libfs.c')
-rw-r--r--fs/libfs.c143
1 files changed, 133 insertions, 10 deletions
diff --git a/fs/libfs.c b/fs/libfs.c
index ea9a6cc9b35c..09e1016eb774 100644
--- a/fs/libfs.c
+++ b/fs/libfs.c
@@ -8,6 +8,7 @@
8#include <linux/slab.h> 8#include <linux/slab.h>
9#include <linux/mount.h> 9#include <linux/mount.h>
10#include <linux/vfs.h> 10#include <linux/vfs.h>
11#include <linux/quotaops.h>
11#include <linux/mutex.h> 12#include <linux/mutex.h>
12#include <linux/exportfs.h> 13#include <linux/exportfs.h>
13#include <linux/writeback.h> 14#include <linux/writeback.h>
@@ -58,11 +59,6 @@ struct dentry *simple_lookup(struct inode *dir, struct dentry *dentry, struct na
58 return NULL; 59 return NULL;
59} 60}
60 61
61int simple_sync_file(struct file * file, struct dentry *dentry, int datasync)
62{
63 return 0;
64}
65
66int dcache_dir_open(struct inode *inode, struct file *file) 62int dcache_dir_open(struct inode *inode, struct file *file)
67{ 63{
68 static struct qstr cursor_name = {.len = 1, .name = "."}; 64 static struct qstr cursor_name = {.len = 1, .name = "."};
@@ -190,7 +186,7 @@ const struct file_operations simple_dir_operations = {
190 .llseek = dcache_dir_lseek, 186 .llseek = dcache_dir_lseek,
191 .read = generic_read_dir, 187 .read = generic_read_dir,
192 .readdir = dcache_readdir, 188 .readdir = dcache_readdir,
193 .fsync = simple_sync_file, 189 .fsync = noop_fsync,
194}; 190};
195 191
196const struct inode_operations simple_dir_inode_operations = { 192const struct inode_operations simple_dir_inode_operations = {
@@ -330,6 +326,81 @@ int simple_rename(struct inode *old_dir, struct dentry *old_dentry,
330 return 0; 326 return 0;
331} 327}
332 328
329/**
330 * simple_setsize - handle core mm and vfs requirements for file size change
331 * @inode: inode
332 * @newsize: new file size
333 *
334 * Returns 0 on success, -error on failure.
335 *
336 * simple_setsize must be called with inode_mutex held.
337 *
338 * simple_setsize will check that the requested new size is OK (see
339 * inode_newsize_ok), and then will perform the necessary i_size update
340 * and pagecache truncation (if necessary). It will be typically be called
341 * from the filesystem's setattr function when ATTR_SIZE is passed in.
342 *
343 * The inode itself must have correct permissions and attributes to allow
344 * i_size to be changed, this function then just checks that the new size
345 * requested is valid.
346 *
347 * In the case of simple in-memory filesystems with inodes stored solely
348 * in the inode cache, and file data in the pagecache, nothing more needs
349 * to be done to satisfy a truncate request. Filesystems with on-disk
350 * blocks for example will need to free them in the case of truncate, in
351 * that case it may be easier not to use simple_setsize (but each of its
352 * components will likely be required at some point to update pagecache
353 * and inode etc).
354 */
355int simple_setsize(struct inode *inode, loff_t newsize)
356{
357 loff_t oldsize;
358 int error;
359
360 error = inode_newsize_ok(inode, newsize);
361 if (error)
362 return error;
363
364 oldsize = inode->i_size;
365 i_size_write(inode, newsize);
366 truncate_pagecache(inode, oldsize, newsize);
367
368 return error;
369}
370EXPORT_SYMBOL(simple_setsize);
371
372/**
373 * simple_setattr - setattr for simple in-memory filesystem
374 * @dentry: dentry
375 * @iattr: iattr structure
376 *
377 * Returns 0 on success, -error on failure.
378 *
379 * simple_setattr implements setattr for an in-memory filesystem which
380 * does not store its own file data or metadata (eg. uses the page cache
381 * and inode cache as its data store).
382 */
383int simple_setattr(struct dentry *dentry, struct iattr *iattr)
384{
385 struct inode *inode = dentry->d_inode;
386 int error;
387
388 error = inode_change_ok(inode, iattr);
389 if (error)
390 return error;
391
392 if (iattr->ia_valid & ATTR_SIZE) {
393 error = simple_setsize(inode, iattr->ia_size);
394 if (error)
395 return error;
396 }
397
398 generic_setattr(inode, iattr);
399
400 return error;
401}
402EXPORT_SYMBOL(simple_setattr);
403
333int simple_readpage(struct file *file, struct page *page) 404int simple_readpage(struct file *file, struct page *page)
334{ 405{
335 clear_highpage(page); 406 clear_highpage(page);
@@ -547,6 +618,40 @@ ssize_t simple_read_from_buffer(void __user *to, size_t count, loff_t *ppos,
547} 618}
548 619
549/** 620/**
621 * simple_write_to_buffer - copy data from user space to the buffer
622 * @to: the buffer to write to
623 * @available: the size of the buffer
624 * @ppos: the current position in the buffer
625 * @from: the user space buffer to read from
626 * @count: the maximum number of bytes to read
627 *
628 * The simple_write_to_buffer() function reads up to @count bytes from the user
629 * space address starting at @from into the buffer @to at offset @ppos.
630 *
631 * On success, the number of bytes written is returned and the offset @ppos is
632 * advanced by this number, or negative value is returned on error.
633 **/
634ssize_t simple_write_to_buffer(void *to, size_t available, loff_t *ppos,
635 const void __user *from, size_t count)
636{
637 loff_t pos = *ppos;
638 size_t res;
639
640 if (pos < 0)
641 return -EINVAL;
642 if (pos >= available || !count)
643 return 0;
644 if (count > available - pos)
645 count = available - pos;
646 res = copy_from_user(to + pos, from, count);
647 if (res == count)
648 return -EFAULT;
649 count -= res;
650 *ppos = pos + count;
651 return count;
652}
653
654/**
550 * memory_read_from_buffer - copy data from the buffer 655 * memory_read_from_buffer - copy data from the buffer
551 * @to: the kernel space buffer to read to 656 * @to: the kernel space buffer to read to
552 * @count: the maximum number of bytes to read 657 * @count: the maximum number of bytes to read
@@ -817,13 +922,22 @@ struct dentry *generic_fh_to_parent(struct super_block *sb, struct fid *fid,
817} 922}
818EXPORT_SYMBOL_GPL(generic_fh_to_parent); 923EXPORT_SYMBOL_GPL(generic_fh_to_parent);
819 924
820int simple_fsync(struct file *file, struct dentry *dentry, int datasync) 925/**
926 * generic_file_fsync - generic fsync implementation for simple filesystems
927 * @file: file to synchronize
928 * @datasync: only synchronize essential metadata if true
929 *
930 * This is a generic implementation of the fsync method for simple
931 * filesystems which track all non-inode metadata in the buffers list
932 * hanging off the address_space structure.
933 */
934int generic_file_fsync(struct file *file, int datasync)
821{ 935{
822 struct writeback_control wbc = { 936 struct writeback_control wbc = {
823 .sync_mode = WB_SYNC_ALL, 937 .sync_mode = WB_SYNC_ALL,
824 .nr_to_write = 0, /* metadata-only; caller takes care of data */ 938 .nr_to_write = 0, /* metadata-only; caller takes care of data */
825 }; 939 };
826 struct inode *inode = dentry->d_inode; 940 struct inode *inode = file->f_mapping->host;
827 int err; 941 int err;
828 int ret; 942 int ret;
829 943
@@ -838,7 +952,15 @@ int simple_fsync(struct file *file, struct dentry *dentry, int datasync)
838 ret = err; 952 ret = err;
839 return ret; 953 return ret;
840} 954}
841EXPORT_SYMBOL(simple_fsync); 955EXPORT_SYMBOL(generic_file_fsync);
956
957/*
958 * No-op implementation of ->fsync for in-memory filesystems.
959 */
960int noop_fsync(struct file *file, int datasync)
961{
962 return 0;
963}
842 964
843EXPORT_SYMBOL(dcache_dir_close); 965EXPORT_SYMBOL(dcache_dir_close);
844EXPORT_SYMBOL(dcache_dir_lseek); 966EXPORT_SYMBOL(dcache_dir_lseek);
@@ -861,9 +983,10 @@ EXPORT_SYMBOL(simple_release_fs);
861EXPORT_SYMBOL(simple_rename); 983EXPORT_SYMBOL(simple_rename);
862EXPORT_SYMBOL(simple_rmdir); 984EXPORT_SYMBOL(simple_rmdir);
863EXPORT_SYMBOL(simple_statfs); 985EXPORT_SYMBOL(simple_statfs);
864EXPORT_SYMBOL(simple_sync_file); 986EXPORT_SYMBOL(noop_fsync);
865EXPORT_SYMBOL(simple_unlink); 987EXPORT_SYMBOL(simple_unlink);
866EXPORT_SYMBOL(simple_read_from_buffer); 988EXPORT_SYMBOL(simple_read_from_buffer);
989EXPORT_SYMBOL(simple_write_to_buffer);
867EXPORT_SYMBOL(memory_read_from_buffer); 990EXPORT_SYMBOL(memory_read_from_buffer);
868EXPORT_SYMBOL(simple_transaction_set); 991EXPORT_SYMBOL(simple_transaction_set);
869EXPORT_SYMBOL(simple_transaction_get); 992EXPORT_SYMBOL(simple_transaction_get);