2 * Copyright (c) 2003 Silicon Graphics, Inc. All Rights Reserved.
4 * Mostly shameless copied from Linus Torvalds' ramfs and thus
5 * Copyright (C) 2000 Linus Torvalds.
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of version 2 of the GNU General Public License as
10 * published by the Free Software Foundation.
12 * This program is distributed in the hope that it would be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16 * Further, this software is distributed without any warranty that it is
17 * free of the rightful claim of any third person regarding infringement
18 * or the like. Any license provided herein, whether implied or
19 * otherwise, applies only to this software file. Patent licenses, if
20 * any, provided herein do not apply to combinations of this program with
21 * other software, or any other product whatsoever.
23 * You should have received a copy of the GNU General Public License along
24 * with this program; if not, write the Free Software Foundation, Inc., 59
25 * Temple Place - Suite 330, Boston MA 02111-1307, USA.
27 * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
28 * Mountain View, CA 94043, or:
32 * For further information regarding this notice, see:
34 * http://oss.sgi.com/projects/GenInfo/SGIGPLNoticeExplan/
37 #include <linux/module.h>
38 #include <linux/backing-dev.h>
40 #include <linux/pagemap.h>
41 #include <linux/init.h>
42 #include <linux/string.h>
43 #include <asm/uaccess.h>
45 /* some random number */
46 #define HWGFS_MAGIC 0x12061983
48 static struct super_operations hwgfs_ops;
49 static struct address_space_operations hwgfs_aops;
50 static struct file_operations hwgfs_file_operations;
51 static struct inode_operations hwgfs_file_inode_operations;
52 static struct inode_operations hwgfs_dir_inode_operations;
54 static struct backing_dev_info hwgfs_backing_dev_info = {
55 .ra_pages = 0, /* No readahead */
56 .memory_backed = 1, /* Does not contribute to dirty memory */
59 struct inode *hwgfs_get_inode(struct super_block *sb, int mode, dev_t dev)
61 struct inode * inode = new_inode(sb);
65 inode->i_uid = current->fsuid;
66 inode->i_gid = current->fsgid;
67 inode->i_blksize = PAGE_CACHE_SIZE;
69 inode->i_rdev = NODEV;
70 inode->i_mapping->a_ops = &hwgfs_aops;
71 inode->i_mapping->backing_dev_info = &hwgfs_backing_dev_info;
72 inode->i_atime = inode->i_mtime = inode->i_ctime = CURRENT_TIME;
73 switch (mode & S_IFMT) {
75 init_special_inode(inode, mode, dev);
78 inode->i_op = &hwgfs_file_inode_operations;
79 inode->i_fop = &hwgfs_file_operations;
82 inode->i_op = &hwgfs_dir_inode_operations;
83 inode->i_fop = &simple_dir_operations;
87 inode->i_op = &page_symlink_inode_operations;
94 static int hwgfs_mknod(struct inode *dir, struct dentry *dentry, int mode, dev_t dev)
96 struct inode * inode = hwgfs_get_inode(dir->i_sb, mode, dev);
100 d_instantiate(dentry, inode);
101 dget(dentry); /* Extra count - pin the dentry in core */
107 static int hwgfs_mkdir(struct inode * dir, struct dentry * dentry, int mode)
109 return hwgfs_mknod(dir, dentry, mode | S_IFDIR, 0);
112 static int hwgfs_create(struct inode *dir, struct dentry *dentry, int mode)
114 return hwgfs_mknod(dir, dentry, mode | S_IFREG, 0);
117 static int hwgfs_symlink(struct inode * dir, struct dentry *dentry, const char * symname)
122 inode = hwgfs_get_inode(dir->i_sb, S_IFLNK|S_IRWXUGO, 0);
124 int l = strlen(symname)+1;
125 error = page_symlink(inode, symname, l);
127 d_instantiate(dentry, inode);
135 static struct address_space_operations hwgfs_aops = {
136 .readpage = simple_readpage,
137 .prepare_write = simple_prepare_write,
138 .commit_write = simple_commit_write
141 static struct file_operations hwgfs_file_operations = {
142 .read = generic_file_read,
143 .write = generic_file_write,
144 .mmap = generic_file_mmap,
145 .fsync = simple_sync_file,
146 .sendfile = generic_file_sendfile,
149 static struct inode_operations hwgfs_file_inode_operations = {
150 .getattr = simple_getattr,
153 static struct inode_operations hwgfs_dir_inode_operations = {
154 .create = hwgfs_create,
155 .lookup = simple_lookup,
157 .unlink = simple_unlink,
158 .symlink = hwgfs_symlink,
159 .mkdir = hwgfs_mkdir,
160 .rmdir = simple_rmdir,
161 .mknod = hwgfs_mknod,
162 .rename = simple_rename,
165 static struct super_operations hwgfs_ops = {
166 .statfs = simple_statfs,
167 .drop_inode = generic_delete_inode,
170 static int hwgfs_fill_super(struct super_block * sb, void * data, int silent)
172 struct inode * inode;
173 struct dentry * root;
175 sb->s_blocksize = PAGE_CACHE_SIZE;
176 sb->s_blocksize_bits = PAGE_CACHE_SHIFT;
177 sb->s_magic = HWGFS_MAGIC;
178 sb->s_op = &hwgfs_ops;
179 inode = hwgfs_get_inode(sb, S_IFDIR | 0755, 0);
183 root = d_alloc_root(inode);
192 static struct super_block *hwgfs_get_sb(struct file_system_type *fs_type,
193 int flags, char *dev_name, void *data)
195 return get_sb_single(fs_type, flags, data, hwgfs_fill_super);
198 static struct file_system_type hwgfs_fs_type = {
199 .owner = THIS_MODULE,
201 .get_sb = hwgfs_get_sb,
202 .kill_sb = kill_litter_super,
205 struct vfsmount *hwgfs_vfsmount;
207 int __init init_hwgfs_fs(void)
211 error = register_filesystem(&hwgfs_fs_type);
215 hwgfs_vfsmount = kern_mount(&hwgfs_fs_type);
216 if (IS_ERR(hwgfs_vfsmount))
221 unregister_filesystem(&hwgfs_fs_type);
222 return PTR_ERR(hwgfs_vfsmount);
225 static void __exit exit_hwgfs_fs(void)
227 unregister_filesystem(&hwgfs_fs_type);
230 MODULE_LICENSE("GPL");
232 module_init(init_hwgfs_fs)
233 module_exit(exit_hwgfs_fs)