1 #include <linux/module.h>
3 #include <linux/pagemap.h>
4 #include <linux/highmem.h>
5 #include <linux/time.h>
6 #include <linux/init.h>
7 #include <linux/string.h>
8 #include <linux/smp_lock.h>
9 #include <linux/backing-dev.h>
12 #define BTRFS_SUPER_MAGIC 0x9123682E
14 /* some random number */
16 static struct super_operations ramfs_ops
;
17 static struct inode_operations ramfs_dir_inode_operations
;
19 static struct backing_dev_info ramfs_backing_dev_info
= {
20 .ra_pages
= 0, /* No readahead */
21 .capabilities
= BDI_CAP_NO_ACCT_DIRTY
| BDI_CAP_NO_WRITEBACK
|
22 BDI_CAP_MAP_DIRECT
| BDI_CAP_MAP_COPY
|
23 BDI_CAP_READ_MAP
| BDI_CAP_WRITE_MAP
| BDI_CAP_EXEC_MAP
,
26 struct inode
*ramfs_get_inode(struct super_block
*sb
, int mode
, dev_t dev
)
28 struct inode
* inode
= new_inode(sb
);
32 inode
->i_uid
= current
->fsuid
;
33 inode
->i_gid
= current
->fsgid
;
35 inode
->i_mapping
->a_ops
= &ramfs_aops
;
36 inode
->i_mapping
->backing_dev_info
= &ramfs_backing_dev_info
;
37 inode
->i_atime
= inode
->i_mtime
= inode
->i_ctime
= CURRENT_TIME
;
38 switch (mode
& S_IFMT
) {
40 init_special_inode(inode
, mode
, dev
);
43 inode
->i_op
= &ramfs_file_inode_operations
;
44 inode
->i_fop
= &ramfs_file_operations
;
47 inode
->i_op
= &ramfs_dir_inode_operations
;
48 inode
->i_fop
= &simple_dir_operations
;
50 /* directory inodes start off with i_nlink == 2 (for "." entry) */
54 inode
->i_op
= &page_symlink_inode_operations
;
62 * File creation. Allocate an inode, and we're done..
66 ramfs_mknod(struct inode
*dir
, struct dentry
*dentry
, int mode
, dev_t dev
)
68 struct inode
* inode
= ramfs_get_inode(dir
->i_sb
, mode
, dev
);
72 if (dir
->i_mode
& S_ISGID
) {
73 inode
->i_gid
= dir
->i_gid
;
75 inode
->i_mode
|= S_ISGID
;
77 d_instantiate(dentry
, inode
);
78 dget(dentry
); /* Extra count - pin the dentry in core */
80 dir
->i_mtime
= dir
->i_ctime
= CURRENT_TIME
;
85 static int ramfs_mkdir(struct inode
* dir
, struct dentry
* dentry
, int mode
)
87 int retval
= ramfs_mknod(dir
, dentry
, mode
| S_IFDIR
, 0);
93 static int ramfs_create(struct inode
*dir
, struct dentry
*dentry
, int mode
, struct nameidata
*nd
)
95 return ramfs_mknod(dir
, dentry
, mode
| S_IFREG
, 0);
98 static int ramfs_symlink(struct inode
* dir
, struct dentry
*dentry
, const char * symname
)
103 inode
= ramfs_get_inode(dir
->i_sb
, S_IFLNK
|S_IRWXUGO
, 0);
105 int l
= strlen(symname
)+1;
106 error
= page_symlink(inode
, symname
, l
);
108 if (dir
->i_mode
& S_ISGID
)
109 inode
->i_gid
= dir
->i_gid
;
110 d_instantiate(dentry
, inode
);
112 dir
->i_mtime
= dir
->i_ctime
= CURRENT_TIME
;
119 static struct inode_operations ramfs_dir_inode_operations
= {
120 .create
= ramfs_create
,
121 .lookup
= simple_lookup
,
123 .unlink
= simple_unlink
,
124 .symlink
= ramfs_symlink
,
125 .mkdir
= ramfs_mkdir
,
126 .rmdir
= simple_rmdir
,
127 .mknod
= ramfs_mknod
,
128 .rename
= simple_rename
,
132 struct inode
*btrfs_get_inode(struct super_block
*sb
, int mode
, dev_t dev
)
134 struct inode
* inode
= new_inode(sb
);
137 inode
->i_mode
= mode
;
138 inode
->i_uid
= current
->fsuid
;
139 inode
->i_gid
= current
->fsgid
;
141 inode
->i_atime
= inode
->i_mtime
= inode
->i_ctime
= CURRENT_TIME
;
146 static struct super_operations btrfs_ops
= {
147 .statfs
= simple_statfs
,
148 .drop_inode
= generic_delete_inode
,
151 static int btrfs_fill_super(struct super_block
* sb
, void * data
, int silent
)
153 struct inode
* inode
;
154 struct dentry
* root
;
156 sb
->s_maxbytes
= MAX_LFS_FILESIZE
;
157 sb
->s_blocksize
= PAGE_CACHE_SIZE
;
158 sb
->s_blocksize_bits
= PAGE_CACHE_SHIFT
;
159 sb
->s_magic
= BTRFS_SUPER_MAGIC
;
160 sb
->s_op
= &btrfs_ops
;
162 inode
= btrfs_get_inode(sb
, S_IFDIR
| 0755, 0);
166 root
= d_alloc_root(inode
);
175 static int btrfs_get_sb(struct file_system_type
*fs_type
,
176 int flags
, const char *dev_name
, void *data
, struct vfsmount
*mnt
)
178 return get_sb_bdev(fs_type
, flags
, dev_name
, data
,
179 btrfs_fill_super
, mnt
);
182 static struct file_system_type btrfs_fs_type
= {
183 .owner
= THIS_MODULE
,
185 .get_sb
= btrfs_get_sb
,
186 .kill_sb
= kill_block_super
,
187 .fs_flags
= FS_REQUIRES_DEV
,
190 static int __init
init_btrfs_fs(void)
192 printk("btrfs loaded!\n");
193 return register_filesystem(&btrfs_fs_type
);
196 static void __exit
exit_btrfs_fs(void)
198 unregister_filesystem(&btrfs_fs_type
);
199 printk("btrfs unloaded\n");
202 module_init(init_btrfs_fs
)
203 module_exit(exit_btrfs_fs
)
205 MODULE_LICENSE("GPL");