2 * This file is subject to the terms and conditions of the GNU General Public
3 * License. See the file "COPYING" in the main directory of this archive
6 * Copyright (c) 2003 Silicon Graphics, Inc. All Rights Reserved.
8 * Mostly shameless copied from Linus Torvalds' ramfs and thus
9 * Copyright (C) 2000 Linus Torvalds.
10 * 2000 Transmeta Corp.
13 #include <linux/module.h>
14 #include <linux/backing-dev.h>
16 #include <linux/pagemap.h>
17 #include <linux/init.h>
18 #include <linux/string.h>
19 #include <asm/uaccess.h>
21 /* some random number */
22 #define HWGFS_MAGIC 0x12061983
24 static struct super_operations hwgfs_ops;
25 static struct address_space_operations hwgfs_aops;
26 static struct file_operations hwgfs_file_operations;
27 static struct inode_operations hwgfs_file_inode_operations;
28 static struct inode_operations hwgfs_dir_inode_operations;
30 static struct backing_dev_info hwgfs_backing_dev_info = {
31 .ra_pages = 0, /* No readahead */
32 .memory_backed = 1, /* Does not contribute to dirty memory */
35 static struct inode *hwgfs_get_inode(struct super_block *sb, int mode, dev_t dev)
37 struct inode * inode = new_inode(sb);
41 inode->i_uid = current->fsuid;
42 inode->i_gid = current->fsgid;
43 inode->i_blksize = PAGE_CACHE_SIZE;
45 inode->i_mapping->a_ops = &hwgfs_aops;
46 inode->i_mapping->backing_dev_info = &hwgfs_backing_dev_info;
47 inode->i_atime = inode->i_mtime = inode->i_ctime = CURRENT_TIME;
48 switch (mode & S_IFMT) {
50 init_special_inode(inode, mode, dev);
53 inode->i_op = &hwgfs_file_inode_operations;
54 inode->i_fop = &hwgfs_file_operations;
57 inode->i_op = &hwgfs_dir_inode_operations;
58 inode->i_fop = &simple_dir_operations;
62 inode->i_op = &page_symlink_inode_operations;
69 static int hwgfs_mknod(struct inode *dir, struct dentry *dentry, int mode, dev_t dev)
71 struct inode * inode = hwgfs_get_inode(dir->i_sb, mode, dev);
75 d_instantiate(dentry, inode);
76 dget(dentry); /* Extra count - pin the dentry in core */
82 static int hwgfs_mkdir(struct inode * dir, struct dentry * dentry, int mode)
84 return hwgfs_mknod(dir, dentry, mode | S_IFDIR, 0);
87 static int hwgfs_create(struct inode *dir, struct dentry *dentry, int mode, struct nameidata *unused)
89 return hwgfs_mknod(dir, dentry, mode | S_IFREG, 0);
92 static int hwgfs_symlink(struct inode * dir, struct dentry *dentry, const char * symname)
97 inode = hwgfs_get_inode(dir->i_sb, S_IFLNK|S_IRWXUGO, 0);
99 int l = strlen(symname)+1;
100 error = page_symlink(inode, symname, l);
102 d_instantiate(dentry, inode);
110 static struct address_space_operations hwgfs_aops = {
111 .readpage = simple_readpage,
112 .prepare_write = simple_prepare_write,
113 .commit_write = simple_commit_write
116 static struct file_operations hwgfs_file_operations = {
117 .read = generic_file_read,
118 .write = generic_file_write,
119 .mmap = generic_file_mmap,
120 .fsync = simple_sync_file,
121 .sendfile = generic_file_sendfile,
124 static struct inode_operations hwgfs_file_inode_operations = {
125 .getattr = simple_getattr,
128 static struct inode_operations hwgfs_dir_inode_operations = {
129 .create = hwgfs_create,
130 .lookup = simple_lookup,
132 .unlink = simple_unlink,
133 .symlink = hwgfs_symlink,
134 .mkdir = hwgfs_mkdir,
135 .rmdir = simple_rmdir,
136 .mknod = hwgfs_mknod,
137 .rename = simple_rename,
140 static struct super_operations hwgfs_ops = {
141 .statfs = simple_statfs,
142 .drop_inode = generic_delete_inode,
145 static int hwgfs_fill_super(struct super_block * sb, void * data, int silent)
147 struct inode * inode;
148 struct dentry * root;
150 sb->s_blocksize = PAGE_CACHE_SIZE;
151 sb->s_blocksize_bits = PAGE_CACHE_SHIFT;
152 sb->s_magic = HWGFS_MAGIC;
153 sb->s_op = &hwgfs_ops;
154 inode = hwgfs_get_inode(sb, S_IFDIR | 0755, 0);
158 root = d_alloc_root(inode);
167 static struct super_block *hwgfs_get_sb(struct file_system_type *fs_type,
168 int flags, const char *dev_name, void *data)
170 return get_sb_single(fs_type, flags, data, hwgfs_fill_super);
173 static struct file_system_type hwgfs_fs_type = {
174 .owner = THIS_MODULE,
176 .get_sb = hwgfs_get_sb,
177 .kill_sb = kill_litter_super,
180 struct vfsmount *hwgfs_vfsmount;
182 int __init init_hwgfs_fs(void)
186 error = register_filesystem(&hwgfs_fs_type);
190 hwgfs_vfsmount = kern_mount(&hwgfs_fs_type);
191 if (IS_ERR(hwgfs_vfsmount))
196 unregister_filesystem(&hwgfs_fs_type);
197 return PTR_ERR(hwgfs_vfsmount);
200 static void __exit exit_hwgfs_fs(void)
202 unregister_filesystem(&hwgfs_fs_type);
205 MODULE_LICENSE("GPL");
207 module_init(init_hwgfs_fs)
208 module_exit(exit_hwgfs_fs)