diff --recursive --unified --new-file linux-2.4.21/fs/Config.in linux-2.4.21-hellofs/fs/Config.in --- linux-2.4.21/fs/Config.in Thu Nov 28 18:53:15 2002 +++ linux-2.4.21-hellofs/fs/Config.in Tue Sep 23 23:11:02 2003 @@ -47,6 +47,7 @@ int 'JFFS2 debugging verbosity (0 = quiet, 2 = noisy)' CONFIG_JFFS2_FS_DEBUG 0 fi tristate 'Compressed ROM file system support' CONFIG_CRAMFS +tristate 'Hello World file system support' CONFIG_HELLOFS bool 'Virtual memory file system support (former shm fs)' CONFIG_TMPFS define_bool CONFIG_RAMFS y diff --recursive --unified --new-file linux-2.4.21/fs/Makefile linux-2.4.21-hellofs/fs/Makefile --- linux-2.4.21/fs/Makefile Thu Nov 28 18:53:15 2002 +++ linux-2.4.21-hellofs/fs/Makefile Tue Sep 23 23:11:02 2003 @@ -30,6 +30,7 @@ subdir-$(CONFIG_JBD) += jbd subdir-$(CONFIG_EXT2_FS) += ext2 subdir-$(CONFIG_CRAMFS) += cramfs +subdir-$(CONFIG_HELLOFS) += hellofs subdir-$(CONFIG_RAMFS) += ramfs subdir-$(CONFIG_CODA_FS) += coda subdir-$(CONFIG_INTERMEZZO_FS) += intermezzo diff --recursive --unified --new-file linux-2.4.21/fs/hellofs/Makefile linux-2.4.21-hellofs/fs/hellofs/Makefile --- linux-2.4.21/fs/hellofs/Makefile Wed Dec 31 19:00:00 1969 +++ linux-2.4.21-hellofs/fs/hellofs/Makefile Tue Sep 23 23:11:02 2003 @@ -0,0 +1,11 @@ +# +# Makefile for the linux hellofs routines. +# + +O_TARGET := hellofs.o + +obj-y := inode.o + +obj-m := $(O_TARGET) + +include $(TOPDIR)/Rules.make diff --recursive --unified --new-file linux-2.4.21/fs/hellofs/README linux-2.4.21-hellofs/fs/hellofs/README --- linux-2.4.21/fs/hellofs/README Wed Dec 31 19:00:00 1969 +++ linux-2.4.21-hellofs/fs/hellofs/README Tue Sep 23 23:11:02 2003 @@ -0,0 +1,5 @@ +Notes on File System +---------- + +A HelloFS filesystem consists of a single file named "hello.txt". The contents +of this file is "Hello World!\n". diff --recursive --unified --new-file linux-2.4.21/fs/hellofs/inode.c linux-2.4.21-hellofs/fs/hellofs/inode.c --- linux-2.4.21/fs/hellofs/inode.c Wed Dec 31 19:00:00 1969 +++ linux-2.4.21-hellofs/fs/hellofs/inode.c Tue Sep 23 23:11:02 2003 @@ -0,0 +1,213 @@ +/* + * HelloFS - The Hello World File System + * David Manura, 2003-09 + * + * Based on CramFS (Copyright (C) 1999 Linus Torvalds). + * + * This file is released under the GPL. + * + * TODO: + * FIX: writing to file causes file to clear + */ + + +#include +#include +#include +#include +#include +#include + +#include + +/** callbacks */ +static struct super_operations hellofs_ops; +static struct inode_operations hellofs_dir_inode_operations; +static struct file_operations hellofs_directory_operations; +static struct address_space_operations hellofs_aops; + + +/* + * create new inode object + */ +static struct inode *get_hellofs_inode(struct super_block *sb, int is_dir) +{ + struct inode * inode = new_inode(sb); + // printk(KERN_INFO "\n"); + printk(KERN_DEBUG "get_hellofs_inode\n"); + + if (inode) { + inode->i_mode = is_dir ? 040444 : 0100444; + inode->i_uid = 0; + inode->i_size = 13; + inode->i_blocks = 1; + inode->i_blksize = PAGE_CACHE_SIZE; + inode->i_gid = 0; + inode->i_ino = is_dir ? 0 : 1; + /* inode->i_nlink is left 1 - arguably wrong for directories, + but it's the best we can do without reading the directory + contents. 1 yields the right result in GNU find, even + without -noleaf option. */ + insert_inode_hash(inode); + if (S_ISREG(inode->i_mode)) { + printk(KERN_DEBUG "dir\n"); + inode->i_fop = &generic_ro_fops; + inode->i_data.a_ops = &hellofs_aops; + } else if (S_ISDIR(inode->i_mode)) { + inode->i_op = &hellofs_dir_inode_operations; + inode->i_fop = &hellofs_directory_operations; + } + } + return inode; +} + +/* + * populate superblock object + */ +static struct super_block * hellofs_read_super(struct super_block *sb, void *data, int silent) +{ + int i; + struct hellofs_super super; + struct super_block * retval = NULL; + + printk(KERN_DEBUG "hellofs_read_super\n"); + + set_blocksize(sb->s_dev, PAGE_CACHE_SIZE); + sb->s_blocksize = PAGE_CACHE_SIZE; + sb->s_blocksize_bits = PAGE_CACHE_SHIFT; + + + /* Set it all up.. */ + sb->s_op = &hellofs_ops; + sb->s_root = d_alloc_root(get_hellofs_inode(sb, 1)); + retval = sb; +out: + return retval; +} + +/* + * Get mount stats + */ +static int hellofs_statfs(struct super_block *sb, struct statfs *buf) +{ + printk(KERN_DEBUG "hellofs_statfs\n"); + + buf->f_type = 0x31412171; /* random number */ + buf->f_bsize = PAGE_CACHE_SIZE; + buf->f_blocks = 2; + buf->f_bfree = 0; + buf->f_bavail = 0; + buf->f_files = 1; + buf->f_ffree = 0; + buf->f_namelen = 20; + return 0; +} + +/* + * Read a hellofs directory entry. + */ +static int hellofs_readdir(struct file *filp, void *dirent, filldir_t filldir) +{ + int error; + + unsigned int offset = filp->f_pos; + + const char* name = "hello.txt"; + const ino_t ino = 1; + const int namelen = strlen(name); + + struct hellofs_inode *de; + + if(offset > 0) return 0; + + + error = filldir(dirent, name, namelen, offset, ino, 0x1FF); + + offset += namelen + sizeof(*de); + + filp->f_pos = offset; + + return 0; +} + +/* + * Lookup and fill in the inode data.. + */ +static struct dentry * hellofs_lookup(struct inode *dir, struct dentry *dentry) +{ + int retval; + + printk(KERN_DEBUG "hellofs_lookup\n"); + + retval = memcmp(dentry->d_name.name, "hello.txt", 9); + if(!retval) { + d_add(dentry, get_hellofs_inode(dir->i_sb, 0)); + } + else { + d_add(dentry, NULL); + } + return NULL; +} + +/** + * Read page from file + */ +static int hellofs_readpage(struct file *file, struct page * page) +{ + void *pgdata; + + printk(KERN_DEBUG "hellofs_readpage\n"); + + pgdata = kmap(page); + + memcpy(pgdata, "Hello World!\n", 13); + memset(pgdata + 13, 'x', PAGE_CACHE_SIZE - 13); + kunmap(page); + flush_dcache_page(page); + SetPageUptodate(page); + UnlockPage(page); + + return 0; +} + +static struct address_space_operations hellofs_aops = { + readpage: hellofs_readpage +}; + + +/* + * A directory can only readdir + */ +static struct file_operations hellofs_directory_operations = { + read: generic_read_dir, + readdir: hellofs_readdir, +}; + +static struct inode_operations hellofs_dir_inode_operations = { + lookup: hellofs_lookup, +}; + +static struct super_operations hellofs_ops = { + statfs: hellofs_statfs, +}; + +static DECLARE_FSTYPE_DEV(hellofs_fs_type, "hellofs", hellofs_read_super); + +static int __init init_hellofs_fs(void) +{ + return register_filesystem(&hellofs_fs_type); +} + +static void __exit exit_hellofs_fs(void) +{ + unregister_filesystem(&hellofs_fs_type); +} + +/* declare module entry point */ +module_init(init_hellofs_fs) + +/* declare module exist point */ +module_exit(exit_hellofs_fs) + +/* declare license type */ +MODULE_LICENSE("GPL"); diff --recursive --unified --new-file linux-2.4.21/include/linux/fs.h linux-2.4.21-hellofs/include/linux/fs.h --- linux-2.4.21/include/linux/fs.h Fri Jun 13 10:51:38 2003 +++ linux-2.4.21-hellofs/include/linux/fs.h Tue Sep 23 23:11:02 2003 @@ -704,6 +704,7 @@ #include #include #include +#include #include extern struct list_head super_blocks; @@ -763,6 +764,7 @@ struct usbdev_sb_info usbdevfs_sb; struct jffs2_sb_info jffs2_sb; struct cramfs_sb_info cramfs_sb; + struct hellofs_sb_info hellofs_sb; void *generic_sbp; } u; /* diff --recursive --unified --new-file linux-2.4.21/include/linux/hellofs_fs.h linux-2.4.21-hellofs/include/linux/hellofs_fs.h --- linux-2.4.21/include/linux/hellofs_fs.h Wed Dec 31 19:00:00 1969 +++ linux-2.4.21-hellofs/include/linux/hellofs_fs.h Tue Sep 23 23:11:02 2003 @@ -0,0 +1,43 @@ +#ifndef __HELLOFS_H +#define __HELLOFS_H + +#ifndef __KERNEL__ + +typedef unsigned char u8; +typedef unsigned short u16; +typedef unsigned int u32; + +#endif + + +/* + * Reasonably terse representation of the inode data. + */ +struct hellofs_inode { + +}; + +struct hellofs_info { + u32 crc; + u32 edition; + u32 blocks; + u32 files; +}; + +/* + * Superblock information at the beginning of the FS. + */ +struct hellofs_super { + u32 magic; /* 0x28cd3d45 - random number */ + u32 size; /* length in bytes */ + u32 flags; /* feature flags */ + u32 future; /* reserved for future use */ + u8 signature[16]; /* "Compressed ROMFS" */ + struct hellofs_info fsid; /* unique filesystem info */ + u8 name[16]; /* user-defined name */ + struct hellofs_inode root; /* root inode data */ +}; + + + +#endif diff --recursive --unified --new-file linux-2.4.21/include/linux/hellofs_fs_sb.h linux-2.4.21-hellofs/include/linux/hellofs_fs_sb.h --- linux-2.4.21/include/linux/hellofs_fs_sb.h Wed Dec 31 19:00:00 1969 +++ linux-2.4.21-hellofs/include/linux/hellofs_fs_sb.h Tue Sep 23 23:11:02 2003 @@ -0,0 +1,15 @@ +#ifndef _HELLOFS_FS_SB +#define _HELLOFS_FS_SB + +/* + * cramfs super-block data in memory + */ +struct hellofs_sb_info { + unsigned long magic; + unsigned long size; + unsigned long blocks; + unsigned long files; + unsigned long flags; +}; + +#endif