2 * tiny-shmem.c: simple shmemfs and tmpfs using ramfs code
4 * Matt Mackall <mpm@selenic.com> January, 2004
5 * derived from mm/shmem.c and fs/ramfs/inode.c
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.
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>
20 #include <linux/module.h>
21 #include <linux/swap.h>
22 #include <linux/ramfs.h>
24 static struct file_system_type tmpfs_fs_type
= {
26 .get_sb
= ramfs_get_sb
,
27 .kill_sb
= kill_litter_super
,
30 static struct vfsmount
*shm_mnt
;
32 static int __init
init_tmpfs(void)
34 register_filesystem(&tmpfs_fs_type
);
38 shm_mnt
= kern_mount(&tmpfs_fs_type
);
41 module_init(init_tmpfs
)
44 * shmem_file_setup - get an unlinked file living in tmpfs
46 * @name: name for dentry (to be seen in /proc/<pid>/maps
47 * @size: size to be set for the file
50 struct file
*shmem_file_setup(char *name
, loff_t size
, unsigned long flags
)
55 struct dentry
*dentry
, *root
;
59 return (void *)shm_mnt
;
63 this.len
= strlen(name
);
64 this.hash
= 0; /* will go */
65 root
= shm_mnt
->mnt_root
;
66 dentry
= d_alloc(root
, &this);
71 file
= get_empty_filp();
76 inode
= ramfs_get_inode(root
->d_sb
, S_IFREG
| S_IRWXUGO
, 0);
80 d_instantiate(dentry
, inode
);
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
;
95 return ERR_PTR(error
);
99 * shmem_zero_setup - setup a shared anonymous mapping
101 * @vma: the vma to be mmapped is prepared by do_mmap_pgoff
103 int shmem_zero_setup(struct vm_area_struct
*vma
)
106 loff_t size
= vma
->vm_end
- vma
->vm_start
;
108 file
= shmem_file_setup("dev/zero", size
, vma
->vm_flags
);
110 return PTR_ERR(file
);
115 vma
->vm_ops
= &generic_file_vm_ops
;
119 int shmem_unuse(swp_entry_t entry
, struct page
*page
)