aboutsummaryrefslogtreecommitdiffstats
path: root/fs/btrfs/super.c
diff options
context:
space:
mode:
authorChris Mason <chris.mason@oracle.com>2007-03-21 11:12:56 -0400
committerDavid Woodhouse <dwmw2@hera.kernel.org>2007-03-21 11:12:56 -0400
commit2e635a278354a1a7951e16cfea4c247d6d0e7c99 (patch)
tree4b94d54ddcd7cb184681260738b68caef4edee81 /fs/btrfs/super.c
parent1261ec42b3d3a3ad878bd172144940e3ac710749 (diff)
Btrfs: initial move to kernel module land
Signed-off-by: Chris Mason <chris.mason@oracle.com>
Diffstat (limited to 'fs/btrfs/super.c')
-rw-r--r--fs/btrfs/super.c205
1 files changed, 205 insertions, 0 deletions
diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c
new file mode 100644
index 000000000000..4ae76044aeab
--- /dev/null
+++ b/fs/btrfs/super.c
@@ -0,0 +1,205 @@
1#include <linux/module.h>
2#include <linux/fs.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>
10#include "ctree.h"
11
12#define BTRFS_SUPER_MAGIC 0x9123682E
13#if 0
14/* some random number */
15
16static struct super_operations ramfs_ops;
17static struct inode_operations ramfs_dir_inode_operations;
18
19static 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,
24};
25
26struct inode *ramfs_get_inode(struct super_block *sb, int mode, dev_t dev)
27{
28 struct inode * inode = new_inode(sb);
29
30 if (inode) {
31 inode->i_mode = mode;
32 inode->i_uid = current->fsuid;
33 inode->i_gid = current->fsgid;
34 inode->i_blocks = 0;
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) {
39 default:
40 init_special_inode(inode, mode, dev);
41 break;
42 case S_IFREG:
43 inode->i_op = &ramfs_file_inode_operations;
44 inode->i_fop = &ramfs_file_operations;
45 break;
46 case S_IFDIR:
47 inode->i_op = &ramfs_dir_inode_operations;
48 inode->i_fop = &simple_dir_operations;
49
50 /* directory inodes start off with i_nlink == 2 (for "." entry) */
51 inc_nlink(inode);
52 break;
53 case S_IFLNK:
54 inode->i_op = &page_symlink_inode_operations;
55 break;
56 }
57 }
58 return inode;
59}
60
61/*
62 * File creation. Allocate an inode, and we're done..
63 */
64/* SMP-safe */
65static int
66ramfs_mknod(struct inode *dir, struct dentry *dentry, int mode, dev_t dev)
67{
68 struct inode * inode = ramfs_get_inode(dir->i_sb, mode, dev);
69 int error = -ENOSPC;
70
71 if (inode) {
72 if (dir->i_mode & S_ISGID) {
73 inode->i_gid = dir->i_gid;
74 if (S_ISDIR(mode))
75 inode->i_mode |= S_ISGID;
76 }
77 d_instantiate(dentry, inode);
78 dget(dentry); /* Extra count - pin the dentry in core */
79 error = 0;
80 dir->i_mtime = dir->i_ctime = CURRENT_TIME;
81 }
82 return error;
83}
84
85static int ramfs_mkdir(struct inode * dir, struct dentry * dentry, int mode)
86{
87 int retval = ramfs_mknod(dir, dentry, mode | S_IFDIR, 0);
88 if (!retval)
89 inc_nlink(dir);
90 return retval;
91}
92
93static int ramfs_create(struct inode *dir, struct dentry *dentry, int mode, struct nameidata *nd)
94{
95 return ramfs_mknod(dir, dentry, mode | S_IFREG, 0);
96}
97
98static int ramfs_symlink(struct inode * dir, struct dentry *dentry, const char * symname)
99{
100 struct inode *inode;
101 int error = -ENOSPC;
102
103 inode = ramfs_get_inode(dir->i_sb, S_IFLNK|S_IRWXUGO, 0);
104 if (inode) {
105 int l = strlen(symname)+1;
106 error = page_symlink(inode, symname, l);
107 if (!error) {
108 if (dir->i_mode & S_ISGID)
109 inode->i_gid = dir->i_gid;
110 d_instantiate(dentry, inode);
111 dget(dentry);
112 dir->i_mtime = dir->i_ctime = CURRENT_TIME;
113 } else
114 iput(inode);
115 }
116 return error;
117}
118
119static struct inode_operations ramfs_dir_inode_operations = {
120 .create = ramfs_create,
121 .lookup = simple_lookup,
122 .link = simple_link,
123 .unlink = simple_unlink,
124 .symlink = ramfs_symlink,
125 .mkdir = ramfs_mkdir,
126 .rmdir = simple_rmdir,
127 .mknod = ramfs_mknod,
128 .rename = simple_rename,
129};
130#endif
131
132struct inode *btrfs_get_inode(struct super_block *sb, int mode, dev_t dev)
133{
134 struct inode * inode = new_inode(sb);
135
136 if (inode) {
137 inode->i_mode = mode;
138 inode->i_uid = current->fsuid;
139 inode->i_gid = current->fsgid;
140 inode->i_blocks = 0;
141 inode->i_atime = inode->i_mtime = inode->i_ctime = CURRENT_TIME;
142 }
143 return inode;
144}
145
146static struct super_operations btrfs_ops = {
147 .statfs = simple_statfs,
148 .drop_inode = generic_delete_inode,
149};
150
151static int btrfs_fill_super(struct super_block * sb, void * data, int silent)
152{
153 struct inode * inode;
154 struct dentry * root;
155
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;
161 sb->s_time_gran = 1;
162 inode = btrfs_get_inode(sb, S_IFDIR | 0755, 0);
163 if (!inode)
164 return -ENOMEM;
165
166 root = d_alloc_root(inode);
167 if (!root) {
168 iput(inode);
169 return -ENOMEM;
170 }
171 sb->s_root = root;
172 return 0;
173}
174
175static int btrfs_get_sb(struct file_system_type *fs_type,
176 int flags, const char *dev_name, void *data, struct vfsmount *mnt)
177{
178 return get_sb_bdev(fs_type, flags, dev_name, data,
179 btrfs_fill_super, mnt);
180}
181
182static struct file_system_type btrfs_fs_type = {
183 .owner = THIS_MODULE,
184 .name = "btrfs",
185 .get_sb = btrfs_get_sb,
186 .kill_sb = kill_block_super,
187 .fs_flags = FS_REQUIRES_DEV,
188};
189
190static int __init init_btrfs_fs(void)
191{
192 printk("btrfs loaded!\n");
193 return register_filesystem(&btrfs_fs_type);
194}
195
196static void __exit exit_btrfs_fs(void)
197{
198 unregister_filesystem(&btrfs_fs_type);
199 printk("btrfs unloaded\n");
200}
201
202module_init(init_btrfs_fs)
203module_exit(exit_btrfs_fs)
204
205MODULE_LICENSE("GPL");