#include #include #include #include static ssize_t read_hello_world(struct file *, char *, size_t , loff_t *); static struct super_operations superblock_ops = { .statfs = simple_statfs, .drop_inode = generic_delete_inode, }; static struct file_operations file_ops = { .read = read_hello_world, }; static ssize_t read_hello_world(struct file *instanz, char *buf, size_t tocopy, loff_t *offset) { char *text = "hello world\n"; int c, len=strlen(text)+1; if( tocopyi_mode = mode; ret->i_uid = ret->i_gid = 0; ret->i_blksize = PAGE_CACHE_SIZE; ret->i_blocks = 0; ret->i_atime = ret->i_mtime = ret->i_ctime = CURRENT_TIME; } return ret; } static struct dentry *create_file(struct super_block *sb, struct dentry *parent, char *name) { struct qstr qname; struct inode *inode; struct dentry *dentry; inode = make_new_inode(sb, S_IFREG | 0644); if( !inode ) return 0; inode->i_fop = &file_ops; inode->i_size = 14; // strlen("hello world\n")+1; qname.name = name; qname.len = strlen(name); qname.hash = full_name_hash(name, qname.len); dentry = d_alloc(parent, &qname); if( !dentry ) { iput( inode ); return 0; } d_add(dentry, inode); return dentry; } static int fill_superblock(struct super_block *sb, void *data, int silent) { struct inode *root; struct dentry *root_dentry; sb->s_blocksize = PAGE_CACHE_SIZE; sb->s_blocksize_bits = PAGE_CACHE_SHIFT; sb->s_magic = 0x20040804; sb->s_op = &superblock_ops; // Inode fuer das Root-Verzeichnis anlegen... root = make_new_inode(sb, S_IFDIR | 0755); if( !root ) return -ENOMEM; root->i_op = &simple_dir_inode_operations; root->i_fop = &simple_dir_operations; root_dentry = d_alloc_root(root); printk("root_dentry->name: %s\n", root_dentry->d_iname ); if( !root_dentry ) { iput( root ); return -ENOMEM; } sb->s_root = root_dentry; create_file( sb, root_dentry, "hello" ); return 0; } static struct super_block *get_superblock(struct file_system_type *fst, int flags, const char *devname, void *data) { printk("get_superblock (%s, %s)...\n", fst->name, devname); return get_sb_single(fst, flags, data, fill_superblock); } struct file_system_type hello={ .owner = THIS_MODULE, .name = "hello", .get_sb = get_superblock, .kill_sb = kill_litter_super }; static int __init mod_init(void) { return register_filesystem(&hello); } static void __exit mod_exit(void) { unregister_filesystem(&hello); } module_init( mod_init ); module_exit( mod_exit ); MODULE_LICENSE("GPL");