aboutsummaryrefslogtreecommitdiffstats
path: root/mm/tiny-shmem.c
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@ppc970.osdl.org>2005-04-16 18:20:36 -0400
committerLinus Torvalds <torvalds@ppc970.osdl.org>2005-04-16 18:20:36 -0400
commit1da177e4c3f41524e886b7f1b8a0c1fc7321cac2 (patch)
tree0bba044c4ce775e45a88a51686b5d9f90697ea9d /mm/tiny-shmem.c
Linux-2.6.12-rc2v2.6.12-rc2
Initial git repository build. I'm not bothering with the full history, even though we have it. We can create a separate "historical" git archive of that later if we want to, and in the meantime it's about 3.2GB when imported into git - space that would just make the early git days unnecessarily complicated, when we don't have a lot of good infrastructure for it. Let it rip!
Diffstat (limited to 'mm/tiny-shmem.c')
-rw-r--r--mm/tiny-shmem.c122
1 files changed, 122 insertions, 0 deletions
diff --git a/mm/tiny-shmem.c b/mm/tiny-shmem.c
new file mode 100644
index 000000000000..c13a2161bca2
--- /dev/null
+++ b/mm/tiny-shmem.c
@@ -0,0 +1,122 @@
1/*
2 * tiny-shmem.c: simple shmemfs and tmpfs using ramfs code
3 *
4 * Matt Mackall <mpm@selenic.com> January, 2004
5 * derived from mm/shmem.c and fs/ramfs/inode.c
6 *
7 * This is intended for small system where the benefits of the full
8 * shmem code (swap-backed and resource-limited) are outweighed by
9 * their complexity. On systems without swap this code should be
10 * effectively equivalent, but much lighter weight.
11 */
12
13#include <linux/fs.h>
14#include <linux/init.h>
15#include <linux/devfs_fs_kernel.h>
16#include <linux/vfs.h>
17#include <linux/mount.h>
18#include <linux/file.h>
19#include <linux/mm.h>
20#include <linux/module.h>
21#include <linux/swap.h>
22#include <linux/ramfs.h>
23
24static struct file_system_type tmpfs_fs_type = {
25 .name = "tmpfs",
26 .get_sb = ramfs_get_sb,
27 .kill_sb = kill_litter_super,
28};
29
30static struct vfsmount *shm_mnt;
31
32static int __init init_tmpfs(void)
33{
34 register_filesystem(&tmpfs_fs_type);
35#ifdef CONFIG_TMPFS
36 devfs_mk_dir("shm");
37#endif
38 shm_mnt = kern_mount(&tmpfs_fs_type);
39 return 0;
40}
41module_init(init_tmpfs)
42
43/*
44 * shmem_file_setup - get an unlinked file living in tmpfs
45 *
46 * @name: name for dentry (to be seen in /proc/<pid>/maps
47 * @size: size to be set for the file
48 *
49 */
50struct file *shmem_file_setup(char *name, loff_t size, unsigned long flags)
51{
52 int error;
53 struct file *file;
54 struct inode *inode;
55 struct dentry *dentry, *root;
56 struct qstr this;
57
58 if (IS_ERR(shm_mnt))
59 return (void *)shm_mnt;
60
61 error = -ENOMEM;
62 this.name = name;
63 this.len = strlen(name);
64 this.hash = 0; /* will go */
65 root = shm_mnt->mnt_root;
66 dentry = d_alloc(root, &this);
67 if (!dentry)
68 goto put_memory;
69
70 error = -ENFILE;
71 file = get_empty_filp();
72 if (!file)
73 goto put_dentry;
74
75 error = -ENOSPC;
76 inode = ramfs_get_inode(root->d_sb, S_IFREG | S_IRWXUGO, 0);
77 if (!inode)
78 goto close_file;
79
80 d_instantiate(dentry, inode);
81 inode->i_size = size;
82 inode->i_nlink = 0; /* It is unlinked */
83 file->f_vfsmnt = mntget(shm_mnt);
84 file->f_dentry = dentry;
85 file->f_mapping = inode->i_mapping;
86 file->f_op = &ramfs_file_operations;
87 file->f_mode = FMODE_WRITE | FMODE_READ;
88 return file;
89
90close_file:
91 put_filp(file);
92put_dentry:
93 dput(dentry);
94put_memory:
95 return ERR_PTR(error);
96}
97
98/*
99 * shmem_zero_setup - setup a shared anonymous mapping
100 *
101 * @vma: the vma to be mmapped is prepared by do_mmap_pgoff
102 */
103int shmem_zero_setup(struct vm_area_struct *vma)
104{
105 struct file *file;
106 loff_t size = vma->vm_end - vma->vm_start;
107
108 file = shmem_file_setup("dev/zero", size, vma->vm_flags);
109 if (IS_ERR(file))
110 return PTR_ERR(file);
111
112 if (vma->vm_file)
113 fput(vma->vm_file);
114 vma->vm_file = file;
115 vma->vm_ops = &generic_file_vm_ops;
116 return 0;
117}
118
119int shmem_unuse(swp_entry_t entry, struct page *page)
120{
121 return 0;
122}