aboutsummaryrefslogtreecommitdiffstats
path: root/fs/libfs.c
diff options
context:
space:
mode:
Diffstat (limited to 'fs/libfs.c')
-rw-r--r--fs/libfs.c122
1 files changed, 87 insertions, 35 deletions
diff --git a/fs/libfs.c b/fs/libfs.c
index 3a3a9b53bf5a..5de06947ba5e 100644
--- a/fs/libfs.c
+++ b/fs/libfs.c
@@ -10,6 +10,7 @@
10#include <linux/vfs.h> 10#include <linux/vfs.h>
11#include <linux/quotaops.h> 11#include <linux/quotaops.h>
12#include <linux/mutex.h> 12#include <linux/mutex.h>
13#include <linux/namei.h>
13#include <linux/exportfs.h> 14#include <linux/exportfs.h>
14#include <linux/writeback.h> 15#include <linux/writeback.h>
15#include <linux/buffer_head.h> /* sync_mapping_buffers */ 16#include <linux/buffer_head.h> /* sync_mapping_buffers */
@@ -31,6 +32,7 @@ int simple_getattr(struct vfsmount *mnt, struct dentry *dentry,
31 stat->blocks = inode->i_mapping->nrpages << (PAGE_CACHE_SHIFT - 9); 32 stat->blocks = inode->i_mapping->nrpages << (PAGE_CACHE_SHIFT - 9);
32 return 0; 33 return 0;
33} 34}
35EXPORT_SYMBOL(simple_getattr);
34 36
35int simple_statfs(struct dentry *dentry, struct kstatfs *buf) 37int simple_statfs(struct dentry *dentry, struct kstatfs *buf)
36{ 38{
@@ -39,6 +41,7 @@ int simple_statfs(struct dentry *dentry, struct kstatfs *buf)
39 buf->f_namelen = NAME_MAX; 41 buf->f_namelen = NAME_MAX;
40 return 0; 42 return 0;
41} 43}
44EXPORT_SYMBOL(simple_statfs);
42 45
43/* 46/*
44 * Retaining negative dentries for an in-memory filesystem just wastes 47 * Retaining negative dentries for an in-memory filesystem just wastes
@@ -66,6 +69,7 @@ struct dentry *simple_lookup(struct inode *dir, struct dentry *dentry, unsigned
66 d_add(dentry, NULL); 69 d_add(dentry, NULL);
67 return NULL; 70 return NULL;
68} 71}
72EXPORT_SYMBOL(simple_lookup);
69 73
70int dcache_dir_open(struct inode *inode, struct file *file) 74int dcache_dir_open(struct inode *inode, struct file *file)
71{ 75{
@@ -75,12 +79,14 @@ int dcache_dir_open(struct inode *inode, struct file *file)
75 79
76 return file->private_data ? 0 : -ENOMEM; 80 return file->private_data ? 0 : -ENOMEM;
77} 81}
82EXPORT_SYMBOL(dcache_dir_open);
78 83
79int dcache_dir_close(struct inode *inode, struct file *file) 84int dcache_dir_close(struct inode *inode, struct file *file)
80{ 85{
81 dput(file->private_data); 86 dput(file->private_data);
82 return 0; 87 return 0;
83} 88}
89EXPORT_SYMBOL(dcache_dir_close);
84 90
85loff_t dcache_dir_lseek(struct file *file, loff_t offset, int whence) 91loff_t dcache_dir_lseek(struct file *file, loff_t offset, int whence)
86{ 92{
@@ -123,6 +129,7 @@ loff_t dcache_dir_lseek(struct file *file, loff_t offset, int whence)
123 mutex_unlock(&dentry->d_inode->i_mutex); 129 mutex_unlock(&dentry->d_inode->i_mutex);
124 return offset; 130 return offset;
125} 131}
132EXPORT_SYMBOL(dcache_dir_lseek);
126 133
127/* Relationship between i_mode and the DT_xxx types */ 134/* Relationship between i_mode and the DT_xxx types */
128static inline unsigned char dt_type(struct inode *inode) 135static inline unsigned char dt_type(struct inode *inode)
@@ -172,11 +179,13 @@ int dcache_readdir(struct file *file, struct dir_context *ctx)
172 spin_unlock(&dentry->d_lock); 179 spin_unlock(&dentry->d_lock);
173 return 0; 180 return 0;
174} 181}
182EXPORT_SYMBOL(dcache_readdir);
175 183
176ssize_t generic_read_dir(struct file *filp, char __user *buf, size_t siz, loff_t *ppos) 184ssize_t generic_read_dir(struct file *filp, char __user *buf, size_t siz, loff_t *ppos)
177{ 185{
178 return -EISDIR; 186 return -EISDIR;
179} 187}
188EXPORT_SYMBOL(generic_read_dir);
180 189
181const struct file_operations simple_dir_operations = { 190const struct file_operations simple_dir_operations = {
182 .open = dcache_dir_open, 191 .open = dcache_dir_open,
@@ -186,10 +195,12 @@ const struct file_operations simple_dir_operations = {
186 .iterate = dcache_readdir, 195 .iterate = dcache_readdir,
187 .fsync = noop_fsync, 196 .fsync = noop_fsync,
188}; 197};
198EXPORT_SYMBOL(simple_dir_operations);
189 199
190const struct inode_operations simple_dir_inode_operations = { 200const struct inode_operations simple_dir_inode_operations = {
191 .lookup = simple_lookup, 201 .lookup = simple_lookup,
192}; 202};
203EXPORT_SYMBOL(simple_dir_inode_operations);
193 204
194static const struct super_operations simple_super_operations = { 205static const struct super_operations simple_super_operations = {
195 .statfs = simple_statfs, 206 .statfs = simple_statfs,
@@ -244,6 +255,7 @@ Enomem:
244 deactivate_locked_super(s); 255 deactivate_locked_super(s);
245 return ERR_PTR(-ENOMEM); 256 return ERR_PTR(-ENOMEM);
246} 257}
258EXPORT_SYMBOL(mount_pseudo);
247 259
248int simple_open(struct inode *inode, struct file *file) 260int simple_open(struct inode *inode, struct file *file)
249{ 261{
@@ -251,6 +263,7 @@ int simple_open(struct inode *inode, struct file *file)
251 file->private_data = inode->i_private; 263 file->private_data = inode->i_private;
252 return 0; 264 return 0;
253} 265}
266EXPORT_SYMBOL(simple_open);
254 267
255int simple_link(struct dentry *old_dentry, struct inode *dir, struct dentry *dentry) 268int simple_link(struct dentry *old_dentry, struct inode *dir, struct dentry *dentry)
256{ 269{
@@ -263,6 +276,7 @@ int simple_link(struct dentry *old_dentry, struct inode *dir, struct dentry *den
263 d_instantiate(dentry, inode); 276 d_instantiate(dentry, inode);
264 return 0; 277 return 0;
265} 278}
279EXPORT_SYMBOL(simple_link);
266 280
267int simple_empty(struct dentry *dentry) 281int simple_empty(struct dentry *dentry)
268{ 282{
@@ -283,6 +297,7 @@ out:
283 spin_unlock(&dentry->d_lock); 297 spin_unlock(&dentry->d_lock);
284 return ret; 298 return ret;
285} 299}
300EXPORT_SYMBOL(simple_empty);
286 301
287int simple_unlink(struct inode *dir, struct dentry *dentry) 302int simple_unlink(struct inode *dir, struct dentry *dentry)
288{ 303{
@@ -293,6 +308,7 @@ int simple_unlink(struct inode *dir, struct dentry *dentry)
293 dput(dentry); 308 dput(dentry);
294 return 0; 309 return 0;
295} 310}
311EXPORT_SYMBOL(simple_unlink);
296 312
297int simple_rmdir(struct inode *dir, struct dentry *dentry) 313int simple_rmdir(struct inode *dir, struct dentry *dentry)
298{ 314{
@@ -304,6 +320,7 @@ int simple_rmdir(struct inode *dir, struct dentry *dentry)
304 drop_nlink(dir); 320 drop_nlink(dir);
305 return 0; 321 return 0;
306} 322}
323EXPORT_SYMBOL(simple_rmdir);
307 324
308int simple_rename(struct inode *old_dir, struct dentry *old_dentry, 325int simple_rename(struct inode *old_dir, struct dentry *old_dentry,
309 struct inode *new_dir, struct dentry *new_dentry) 326 struct inode *new_dir, struct dentry *new_dentry)
@@ -330,6 +347,7 @@ int simple_rename(struct inode *old_dir, struct dentry *old_dentry,
330 347
331 return 0; 348 return 0;
332} 349}
350EXPORT_SYMBOL(simple_rename);
333 351
334/** 352/**
335 * simple_setattr - setattr for simple filesystem 353 * simple_setattr - setattr for simple filesystem
@@ -370,6 +388,7 @@ int simple_readpage(struct file *file, struct page *page)
370 unlock_page(page); 388 unlock_page(page);
371 return 0; 389 return 0;
372} 390}
391EXPORT_SYMBOL(simple_readpage);
373 392
374int simple_write_begin(struct file *file, struct address_space *mapping, 393int simple_write_begin(struct file *file, struct address_space *mapping,
375 loff_t pos, unsigned len, unsigned flags, 394 loff_t pos, unsigned len, unsigned flags,
@@ -393,6 +412,7 @@ int simple_write_begin(struct file *file, struct address_space *mapping,
393 } 412 }
394 return 0; 413 return 0;
395} 414}
415EXPORT_SYMBOL(simple_write_begin);
396 416
397/** 417/**
398 * simple_write_end - .write_end helper for non-block-device FSes 418 * simple_write_end - .write_end helper for non-block-device FSes
@@ -444,6 +464,7 @@ int simple_write_end(struct file *file, struct address_space *mapping,
444 464
445 return copied; 465 return copied;
446} 466}
467EXPORT_SYMBOL(simple_write_end);
447 468
448/* 469/*
449 * the inodes created here are not hashed. If you use iunique to generate 470 * the inodes created here are not hashed. If you use iunique to generate
@@ -512,6 +533,7 @@ out:
512 dput(root); 533 dput(root);
513 return -ENOMEM; 534 return -ENOMEM;
514} 535}
536EXPORT_SYMBOL(simple_fill_super);
515 537
516static DEFINE_SPINLOCK(pin_fs_lock); 538static DEFINE_SPINLOCK(pin_fs_lock);
517 539
@@ -534,6 +556,7 @@ int simple_pin_fs(struct file_system_type *type, struct vfsmount **mount, int *c
534 mntput(mnt); 556 mntput(mnt);
535 return 0; 557 return 0;
536} 558}
559EXPORT_SYMBOL(simple_pin_fs);
537 560
538void simple_release_fs(struct vfsmount **mount, int *count) 561void simple_release_fs(struct vfsmount **mount, int *count)
539{ 562{
@@ -545,6 +568,7 @@ void simple_release_fs(struct vfsmount **mount, int *count)
545 spin_unlock(&pin_fs_lock); 568 spin_unlock(&pin_fs_lock);
546 mntput(mnt); 569 mntput(mnt);
547} 570}
571EXPORT_SYMBOL(simple_release_fs);
548 572
549/** 573/**
550 * simple_read_from_buffer - copy data from the buffer to user space 574 * simple_read_from_buffer - copy data from the buffer to user space
@@ -579,6 +603,7 @@ ssize_t simple_read_from_buffer(void __user *to, size_t count, loff_t *ppos,
579 *ppos = pos + count; 603 *ppos = pos + count;
580 return count; 604 return count;
581} 605}
606EXPORT_SYMBOL(simple_read_from_buffer);
582 607
583/** 608/**
584 * simple_write_to_buffer - copy data from user space to the buffer 609 * simple_write_to_buffer - copy data from user space to the buffer
@@ -613,6 +638,7 @@ ssize_t simple_write_to_buffer(void *to, size_t available, loff_t *ppos,
613 *ppos = pos + count; 638 *ppos = pos + count;
614 return count; 639 return count;
615} 640}
641EXPORT_SYMBOL(simple_write_to_buffer);
616 642
617/** 643/**
618 * memory_read_from_buffer - copy data from the buffer 644 * memory_read_from_buffer - copy data from the buffer
@@ -644,6 +670,7 @@ ssize_t memory_read_from_buffer(void *to, size_t count, loff_t *ppos,
644 670
645 return count; 671 return count;
646} 672}
673EXPORT_SYMBOL(memory_read_from_buffer);
647 674
648/* 675/*
649 * Transaction based IO. 676 * Transaction based IO.
@@ -665,6 +692,7 @@ void simple_transaction_set(struct file *file, size_t n)
665 smp_mb(); 692 smp_mb();
666 ar->size = n; 693 ar->size = n;
667} 694}
695EXPORT_SYMBOL(simple_transaction_set);
668 696
669char *simple_transaction_get(struct file *file, const char __user *buf, size_t size) 697char *simple_transaction_get(struct file *file, const char __user *buf, size_t size)
670{ 698{
@@ -696,6 +724,7 @@ char *simple_transaction_get(struct file *file, const char __user *buf, size_t s
696 724
697 return ar->data; 725 return ar->data;
698} 726}
727EXPORT_SYMBOL(simple_transaction_get);
699 728
700ssize_t simple_transaction_read(struct file *file, char __user *buf, size_t size, loff_t *pos) 729ssize_t simple_transaction_read(struct file *file, char __user *buf, size_t size, loff_t *pos)
701{ 730{
@@ -705,12 +734,14 @@ ssize_t simple_transaction_read(struct file *file, char __user *buf, size_t size
705 return 0; 734 return 0;
706 return simple_read_from_buffer(buf, size, pos, ar->data, ar->size); 735 return simple_read_from_buffer(buf, size, pos, ar->data, ar->size);
707} 736}
737EXPORT_SYMBOL(simple_transaction_read);
708 738
709int simple_transaction_release(struct inode *inode, struct file *file) 739int simple_transaction_release(struct inode *inode, struct file *file)
710{ 740{
711 free_page((unsigned long)file->private_data); 741 free_page((unsigned long)file->private_data);
712 return 0; 742 return 0;
713} 743}
744EXPORT_SYMBOL(simple_transaction_release);
714 745
715/* Simple attribute files */ 746/* Simple attribute files */
716 747
@@ -746,12 +777,14 @@ int simple_attr_open(struct inode *inode, struct file *file,
746 777
747 return nonseekable_open(inode, file); 778 return nonseekable_open(inode, file);
748} 779}
780EXPORT_SYMBOL_GPL(simple_attr_open);
749 781
750int simple_attr_release(struct inode *inode, struct file *file) 782int simple_attr_release(struct inode *inode, struct file *file)
751{ 783{
752 kfree(file->private_data); 784 kfree(file->private_data);
753 return 0; 785 return 0;
754} 786}
787EXPORT_SYMBOL_GPL(simple_attr_release); /* GPL-only? This? Really? */
755 788
756/* read from the buffer that is filled with the get function */ 789/* read from the buffer that is filled with the get function */
757ssize_t simple_attr_read(struct file *file, char __user *buf, 790ssize_t simple_attr_read(struct file *file, char __user *buf,
@@ -787,6 +820,7 @@ out:
787 mutex_unlock(&attr->mutex); 820 mutex_unlock(&attr->mutex);
788 return ret; 821 return ret;
789} 822}
823EXPORT_SYMBOL_GPL(simple_attr_read);
790 824
791/* interpret the buffer as a number to call the set function with */ 825/* interpret the buffer as a number to call the set function with */
792ssize_t simple_attr_write(struct file *file, const char __user *buf, 826ssize_t simple_attr_write(struct file *file, const char __user *buf,
@@ -819,6 +853,7 @@ out:
819 mutex_unlock(&attr->mutex); 853 mutex_unlock(&attr->mutex);
820 return ret; 854 return ret;
821} 855}
856EXPORT_SYMBOL_GPL(simple_attr_write);
822 857
823/** 858/**
824 * generic_fh_to_dentry - generic helper for the fh_to_dentry export operation 859 * generic_fh_to_dentry - generic helper for the fh_to_dentry export operation
@@ -957,39 +992,56 @@ int noop_fsync(struct file *file, loff_t start, loff_t end, int datasync)
957{ 992{
958 return 0; 993 return 0;
959} 994}
960
961EXPORT_SYMBOL(dcache_dir_close);
962EXPORT_SYMBOL(dcache_dir_lseek);
963EXPORT_SYMBOL(dcache_dir_open);
964EXPORT_SYMBOL(dcache_readdir);
965EXPORT_SYMBOL(generic_read_dir);
966EXPORT_SYMBOL(mount_pseudo);
967EXPORT_SYMBOL(simple_write_begin);
968EXPORT_SYMBOL(simple_write_end);
969EXPORT_SYMBOL(simple_dir_inode_operations);
970EXPORT_SYMBOL(simple_dir_operations);
971EXPORT_SYMBOL(simple_empty);
972EXPORT_SYMBOL(simple_fill_super);
973EXPORT_SYMBOL(simple_getattr);
974EXPORT_SYMBOL(simple_open);
975EXPORT_SYMBOL(simple_link);
976EXPORT_SYMBOL(simple_lookup);
977EXPORT_SYMBOL(simple_pin_fs);
978EXPORT_SYMBOL(simple_readpage);
979EXPORT_SYMBOL(simple_release_fs);
980EXPORT_SYMBOL(simple_rename);
981EXPORT_SYMBOL(simple_rmdir);
982EXPORT_SYMBOL(simple_statfs);
983EXPORT_SYMBOL(noop_fsync); 995EXPORT_SYMBOL(noop_fsync);
984EXPORT_SYMBOL(simple_unlink); 996
985EXPORT_SYMBOL(simple_read_from_buffer); 997void kfree_put_link(struct dentry *dentry, struct nameidata *nd,
986EXPORT_SYMBOL(simple_write_to_buffer); 998 void *cookie)
987EXPORT_SYMBOL(memory_read_from_buffer); 999{
988EXPORT_SYMBOL(simple_transaction_set); 1000 char *s = nd_get_link(nd);
989EXPORT_SYMBOL(simple_transaction_get); 1001 if (!IS_ERR(s))
990EXPORT_SYMBOL(simple_transaction_read); 1002 kfree(s);
991EXPORT_SYMBOL(simple_transaction_release); 1003}
992EXPORT_SYMBOL_GPL(simple_attr_open); 1004EXPORT_SYMBOL(kfree_put_link);
993EXPORT_SYMBOL_GPL(simple_attr_release); 1005
994EXPORT_SYMBOL_GPL(simple_attr_read); 1006/*
995EXPORT_SYMBOL_GPL(simple_attr_write); 1007 * nop .set_page_dirty method so that people can use .page_mkwrite on
1008 * anon inodes.
1009 */
1010static int anon_set_page_dirty(struct page *page)
1011{
1012 return 0;
1013};
1014
1015/*
1016 * A single inode exists for all anon_inode files. Contrary to pipes,
1017 * anon_inode inodes have no associated per-instance data, so we need
1018 * only allocate one of them.
1019 */
1020struct inode *alloc_anon_inode(struct super_block *s)
1021{
1022 static const struct address_space_operations anon_aops = {
1023 .set_page_dirty = anon_set_page_dirty,
1024 };
1025 struct inode *inode = new_inode_pseudo(s);
1026
1027 if (!inode)
1028 return ERR_PTR(-ENOMEM);
1029
1030 inode->i_ino = get_next_ino();
1031 inode->i_mapping->a_ops = &anon_aops;
1032
1033 /*
1034 * Mark the inode dirty from the very beginning,
1035 * that way it will never be moved to the dirty
1036 * list because mark_inode_dirty() will think
1037 * that it already _is_ on the dirty list.
1038 */
1039 inode->i_state = I_DIRTY;
1040 inode->i_mode = S_IRUSR | S_IWUSR;
1041 inode->i_uid = current_fsuid();
1042 inode->i_gid = current_fsgid();
1043 inode->i_flags |= S_PRIVATE;
1044 inode->i_atime = inode->i_mtime = inode->i_ctime = CURRENT_TIME;
1045 return inode;
1046}
1047EXPORT_SYMBOL(alloc_anon_inode);