diff -urN linux-2.6.19.old/fs/Kconfig linux-2.6.19.dev/fs/Kconfig --- linux-2.6.19.old/fs/Kconfig 2006-12-14 03:13:20.000000000 +0100 +++ linux-2.6.19.dev/fs/Kconfig 2006-12-14 03:14:03.000000000 +0100 @@ -468,6 +468,9 @@ This option will enlarge your kernel, but it allows debugging of ocfs2 filesystem issues. +config MINI_FO + tristate "Mini fanout overlay filesystem" + config MINIX_FS tristate "Minix fs support" help diff -urN linux-2.6.19.old/fs/Makefile linux-2.6.19.dev/fs/Makefile --- linux-2.6.19.old/fs/Makefile 2006-12-14 03:13:20.000000000 +0100 +++ linux-2.6.19.dev/fs/Makefile 2006-12-14 03:14:03.000000000 +0100 @@ -71,6 +71,7 @@ obj-$(CONFIG_RAMFS) += ramfs/ obj-$(CONFIG_HUGETLBFS) += hugetlbfs/ obj-$(CONFIG_CODA_FS) += coda/ +obj-$(CONFIG_MINI_FO) += mini_fo/ obj-$(CONFIG_MINIX_FS) += minix/ obj-$(CONFIG_FAT_FS) += fat/ obj-$(CONFIG_MSDOS_FS) += msdos/ diff -urN linux-2.6.19.old/fs/mini_fo/aux.c linux-2.6.19.dev/fs/mini_fo/aux.c --- linux-2.6.19.old/fs/mini_fo/aux.c 1970-01-01 01:00:00.000000000 +0100 +++ linux-2.6.19.dev/fs/mini_fo/aux.c 2006-12-14 03:14:03.000000000 +0100 @@ -0,0 +1,580 @@ +/* + * Copyright (c) 1997-2003 Erez Zadok + * Copyright (c) 2001-2003 Stony Brook University + * + * For specific licensing information, see the COPYING file distributed with + * this package, or get one from ftp://ftp.filesystems.org/pub/fist/COPYING. + * + * This Copyright notice must be kept intact and distributed with all + * fistgen sources INCLUDING sources generated by fistgen. + */ +/* + * Copyright (C) 2004, 2005 Markus Klotzbuecher + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version + * 2 of the License, or (at your option) any later version. + */ +/* + * $Id$ + */ + +#ifdef HAVE_CONFIG_H +# include +#endif + +#include "fist.h" +#include "mini_fo.h" + +/* check if file exists in storage */ +int exists_in_storage(dentry_t *dentry) +{ + check_mini_fo_dentry(dentry); + if(dtost(dentry) == MODIFIED || dtost(dentry) == CREATED || dtost(dentry) == DEL_REWRITTEN) + return 1; + return 0; +} + +/* check if dentry is in an existing state */ +int is_mini_fo_existant(dentry_t *dentry) +{ + check_mini_fo_dentry(dentry); + + if(dtost(dentry) == DELETED || dtost(dentry) == NON_EXISTANT) + return 0; + else + return 1; +} + +/* + * This function will create a negative storage dentry for + * dentry, what is required for many create like options. + * It will create the storage structure if necessary. + */ +int get_neg_sto_dentry(dentry_t *dentry) +{ + int err = 0; + unsigned int len; + const unsigned char *name; + + if(!dentry || + !dtopd(dentry) || + !(dtost(dentry) == UNMODIFIED || + dtost(dentry) == NON_EXISTANT || + dtost(dentry) == DELETED)) { + printk(KERN_CRIT "mini_fo: get_neg_sto_dentry: invalid dentry passed.\n"); + err = -1; + goto out; + } + /* Have we got a neg. dentry already? */ + if(dtohd2(dentry)) { + err = 0; + goto out; + } + if(dtost(dentry->d_parent) == UNMODIFIED) { + /* build sto struct */ + err = build_sto_structure(dentry->d_parent->d_parent, dentry->d_parent); + if(err || + dtost(dentry->d_parent) != MODIFIED) { + printk(KERN_CRIT "mini_fo: get_neg_sto_dentry: ERROR building sto structure.\n"); + err = -1; + goto out; + } + } + + len = dentry->d_name.len; + name = dentry->d_name.name; + + dtohd2(dentry) = + lookup_one_len(name, dtohd2(dentry->d_parent), len); + + out: + return err; +} + +int check_mini_fo_dentry(dentry_t *dentry) +{ + ASSERT(dentry != NULL); + ASSERT(dtopd(dentry) != NULL); + ASSERT((dtohd(dentry) != NULL) || (dtohd2(dentry) != NULL)); + +/* if(dtost(dentry) == MODIFIED) { */ +/* ASSERT(dentry->d_inode != NULL); */ +/* ASSERT(dtohd(dentry) != NULL); */ +/* ASSERT(dtohd(dentry)->d_inode != NULL); */ +/* ASSERT(dtohd2(dentry) != NULL); */ +/* ASSERT(dtohd2(dentry)->d_inode != NULL); */ +/* } */ +/* else if(dtost(dentry) == UNMODIFIED) { */ +/* ASSERT(dentry->d_inode != NULL); */ +/* ASSERT( */ +/* } */ + return 0; +} + +int check_mini_fo_file(file_t *file) +{ + ASSERT(file != NULL); + ASSERT(ftopd(file) != NULL); + ASSERT(file->f_dentry != NULL); + + /* violent checking, check depending of state and type + * if(S_ISDIR(file->f_dentry->d_inode->i_mode)) {} + */ + ASSERT((ftohf(file) != NULL) || (ftohf2(file) != NULL)); + return 0; +} + +int check_mini_fo_inode(inode_t *inode) +{ + ASSERT(inode != NULL); + ASSERT(itopd(inode) != NULL); + ASSERT((itohi(inode) != NULL) || (itohi2(inode) != NULL)); + return 0; +} + +/* + * will walk a base path as provided by get_mini_fo_bpath and return + * the (hopefully ;-) ) positive dentry of the renamed base dir. + * + * This does some work of path_init. + */ +dentry_t *bpath_walk(super_block_t *sb, char *bpath) +{ + int err; + struct nameidata nd; + + /* be paranoid */ + if(!bpath || bpath[0] != '/') { + printk(KERN_CRIT "mini_fo: bpath_walk: Invalid string.\n"); + return NULL; + } + if(!sb || !stopd(sb)) { + printk(KERN_CRIT "mini_fo: bpath_walk: Invalid sb.\n"); + return NULL; + } + + /* setup nd as path_init does */ + nd.last_type = LAST_ROOT; /* if there are only slashes... */ + nd.flags = LOOKUP_FOLLOW; + /* fix this: how do I reach this lock? + * read_lock(¤t->fs->lock); */ + nd.mnt = mntget(stopd(sb)->hidden_mnt); + nd.dentry = dget(stopd(sb)->base_dir_dentry); + /* read_unlock(¤t->fs->lock); */ + + err = path_walk(bpath+1, &nd); + + /* validate */ + if (err || !nd.dentry || !nd.dentry->d_inode) { + printk(KERN_CRIT "mini_fo: bpath_walk: path_walk failed.\n"); + return NULL; + } + return nd.dentry; +} + + +/* returns the full path of the basefile incl. its name */ +int get_mini_fo_bpath(dentry_t *dentry, char **bpath, int *bpath_len) +{ + char *buf_walker; + int len = 0; + dentry_t *sky_walker; + + if(!dentry || !dtohd(dentry)) { + printk(KERN_CRIT "mini_fo: get_mini_fo_bpath: invalid dentry passed.\n"); + return -1; + } + sky_walker = dtohd(dentry); + + do { + len += sky_walker->d_name.len + 1 ; /* 1 for '/' */ + sky_walker = sky_walker->d_parent; + } while(sky_walker != stopd(dentry->d_inode->i_sb)->base_dir_dentry); + + /* 1 to oil the loop */ + *bpath = (char*) kmalloc(len + 1, GFP_KERNEL); + if(!*bpath) { + printk(KERN_CRIT "mini_fo: get_mini_fo_bpath: out of mem.\n"); + return -1; + } + buf_walker = *bpath+len; /* put it on last char */ + *buf_walker = '\n'; + sky_walker = dtohd(dentry); + + do { + buf_walker -= sky_walker->d_name.len; + strncpy(buf_walker, + sky_walker->d_name.name, + sky_walker->d_name.len); + *(--buf_walker) = '/'; + sky_walker = sky_walker->d_parent; + } while(sky_walker != stopd(dentry->d_inode->i_sb)->base_dir_dentry); + + /* bpath_len doesn't count newline! */ + *bpath_len = len; + return 0; +} + +int mini_fo_cp_cont(dentry_t *tgt_dentry, struct vfsmount *tgt_mnt, + dentry_t *src_dentry, struct vfsmount *src_mnt) +{ + void *buf; + mm_segment_t old_fs; + file_t *tgt_file; + file_t *src_file; + int bytes, len, tmp, err; + err = 0; + + if(!(tgt_dentry->d_inode && src_dentry->d_inode)) { + printk(KERN_CRIT "mini_fo_cp_cont: ERROR, neg. dentry passed.\n"); + err = -EINVAL; + goto out; + } + + dget(tgt_dentry); + dget(src_dentry); + mntget(tgt_mnt); + mntget(src_mnt); + + /* open file write only */ + tgt_file = dentry_open(tgt_dentry, tgt_mnt, 0x1); + if(!tgt_file || IS_ERR(tgt_file)) { + printk(KERN_CRIT "mini_fo_cp_cont: ERROR opening target file.\n"); + err = PTR_ERR(tgt_file); + goto out_err; + } + + /* open file read only */ + src_file = dentry_open(src_dentry, src_mnt, 0x0); + if(!src_file || IS_ERR(src_file)) { + printk(KERN_CRIT "mini_fo_cp_cont: ERROR opening source file.\n"); + err = PTR_ERR(src_file); + + /* close target file */ + fput(tgt_file); + goto out_err; + } + + /* check if the filesystem(s) support read respective write */ + if(!src_file->f_op->read || !tgt_file->f_op->write) { + printk(KERN_CRIT "mini_fo_cp_cont: ERROR, no fs read or write support.\n"); + err = -EPERM; + goto out_close; + } + + /* allocate a page for transfering the data */ + buf = (void *) __get_free_page(GFP_KERNEL); + if(!buf) { + printk(KERN_CRIT "mini_fo_cp_cont: ERROR, out of kernel mem.\n"); + goto out_err; + } + + tgt_file->f_pos = 0; + src_file->f_pos = 0; + + old_fs = get_fs(); + set_fs(KERNEL_DS); + + /* Doing this I assume that a read operation will return a full + * buffer while there is still data to read, and a less than + * full buffer when all data has been read. + */ + bytes = len = PAGE_SIZE; + while(bytes == len) { + bytes = src_file->f_op->read(src_file, buf, len, + &src_file->f_pos); + tmp = tgt_file->f_op->write(tgt_file, buf, bytes, + &tgt_file->f_pos); + if(tmp != bytes) { + printk(KERN_CRIT "mini_fo_cp_cont: ERROR writing.\n"); + goto out_close_unset; + } + } + + free_page((unsigned long) buf); + set_fs(old_fs); + fput(tgt_file); + fput(src_file); + goto out; + + out_close_unset: + free_page((unsigned long) buf); + set_fs(old_fs); + + out_close: + fput(tgt_file); + fput(src_file); + + out_err: + dput(tgt_dentry); + dput(src_dentry); + + /* mk: not sure if this need to be done */ + mntput(tgt_mnt); + mntput(src_mnt); + + out: + return err; +} + +/* mk: + * ndl (no-duplicate list) stuff + * This is used in mini_fo_readdir, to save the storage directory contents + * and later when reading base, match them against the list in order + * to avoid duplicates. + */ + +/* add a file specified by name and len to the ndl + * Return values: 0 on success, <0 on failure. + */ +int ndl_add_entry(struct readdir_data *rd, const char *name, int len) +{ + struct ndl_entry *tmp_entry; + + tmp_entry = (struct ndl_entry *) + kmalloc(sizeof(struct ndl_entry), GFP_KERNEL); + if(!tmp_entry) { + printk(KERN_CRIT "mini_fo: ndl_add_entry: out of mem.\n"); + return -ENOMEM; + } + tmp_entry->name = (char*) kmalloc(len, GFP_KERNEL); + if(!tmp_entry->name) { + printk(KERN_CRIT "mini_fo: ndl_add_entry: out of mem.\n"); + return -ENOMEM; + } + strncpy(tmp_entry->name, name, len); + tmp_entry->len = len; + + list_add(&tmp_entry->list, &rd->ndl_list); + rd->ndl_size++; + return 0; +} + +/* delete all list entries and free memory */ +void ndl_put_list(struct readdir_data *rd) +{ + struct list_head *tmp; + struct ndl_entry *tmp_entry; + + if(rd->ndl_size <= 0) + return; + while(!list_empty(&rd->ndl_list)) { + tmp = rd->ndl_list.next; + list_del(tmp); + tmp_entry = list_entry(tmp, struct ndl_entry, list); + kfree(tmp_entry->name); + kfree(tmp_entry); + } + rd->ndl_size = 0; +} + +/* Check if a file specified by name and len is in the ndl + * Return value: 0 if not in list, 1 if file is found in ndl. + */ +int ndl_check_entry(struct readdir_data *rd, const char *name, int len) +{ + struct list_head *tmp; + struct ndl_entry *tmp_entry; + + if(rd->ndl_size <= 0) + return 0; + + list_for_each(tmp, &rd->ndl_list) { + tmp_entry = list_entry(tmp, struct ndl_entry, list); + if(tmp_entry->len != len) + continue; + if(!strncmp(tmp_entry->name, name, len)) + return 1; + } + return 0; +} + +/* mk: + * Recursive function to create corresponding directorys in the storage fs. + * The function will build the storage directorys up to dentry. + */ +int build_sto_structure(dentry_t *dir, dentry_t *dentry) +{ + int err; + dentry_t *hidden_sto_dentry; + dentry_t *hidden_sto_dir_dentry; + + if(dentry->d_parent != dir) { + printk(KERN_CRIT "mini_fo: build_sto_structure: invalid parameter or meta data corruption [1].\n"); + return 1; + } + + if(dtost(dir) != MODIFIED) { + err = build_sto_structure(dir->d_parent, dentry->d_parent); + if(err) + return err; + } + + /* ok, coming back again. */ + check_mini_fo_dentry(dentry); + hidden_sto_dentry = dtohd2(dentry); + + if(!hidden_sto_dentry) { + /* + * This is the case after creating the first + * hidden_sto_dentry. + * After one negative storage_dentry, all pointers to + * hidden_storage dentries are set to NULL. We need to + * create the negative dentry before we create the storage + * file. + */ + unsigned int len; + const unsigned char *name; + len = dtohd(dentry)->d_name.len; + name = dtohd(dentry)->d_name.name; + hidden_sto_dentry = lookup_one_len(name, dtohd2(dir), len); + dtohd2(dentry) = hidden_sto_dentry; + } + + /* was: hidden_sto_dir_dentry = lock_parent(hidden_sto_dentry); */ + hidden_sto_dir_dentry = dget(hidden_sto_dentry->d_parent); +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16) + mutex_lock(&hidden_sto_dir_dentry->d_inode->i_mutex); +#else + down(&hidden_sto_dir_dentry->d_inode->i_sem); +#endif + /* lets be safe */ + if(dtohd2(dir) != hidden_sto_dir_dentry) { + printk(KERN_CRIT "mini_fo: build_sto_structure: invalid parameter or meta data corruption [2].\n"); + return 1; + } + + /* check for errors in lock_parent */ + err = PTR_ERR(hidden_sto_dir_dentry); + if(IS_ERR(hidden_sto_dir_dentry)) { + printk(KERN_CRIT "mini_fo: build_sto_structure: lock_parent failed.\n"); + return err; + } + + err = vfs_mkdir(hidden_sto_dir_dentry->d_inode, + hidden_sto_dentry, + dir->d_inode->i_mode); + + if(err) { + printk(KERN_CRIT "mini_fo: build_sto_structure: failed to create storage dir [1].\n"); + /* was: unlock_dir(dir); */ +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16) + mutex_unlock(&dir->d_inode->i_mutex); +#else + up(&dir->d_inode->i_sem); +#endif + dput(dir); + return err; + } + + /* everything ok! */ + if(!dtohd2(dentry)->d_inode) { + printk(KERN_CRIT "mini_fo: build_sto_structure: failed to create storage dir [2].\n"); + /* was: unlock_dir(dir); */ +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16) + mutex_unlock(&dir->d_inode->i_mutex); +#else + up(&dir->d_inode->i_sem); +#endif + dput(dir); + return 1; + } + + /* interpose the new inode and set new state */ + itohi2(dentry->d_inode) = igrab(dtohd2(dentry)->d_inode); + dtopd(dentry)->state = MODIFIED; + + /* initalize the wol list */ + itopd(dentry->d_inode)->deleted_list_size = -1; + itopd(dentry->d_inode)->renamed_list_size = -1; + meta_build_lists(dentry); + + fist_copy_attr_all(dentry->d_inode, itohi2(dentry->d_inode)); + fist_copy_attr_timesizes(dir->d_inode, + hidden_sto_dir_dentry->d_inode); + dir->d_inode->i_nlink++; + /* was: unlock_dir(hidden_sto_dir_dentry); */ +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16) + mutex_unlock(&hidden_sto_dir_dentry->d_inode->i_mutex); +#else + up(&hidden_sto_dir_dentry->d_inode->i_sem); +#endif + dput(hidden_sto_dir_dentry); + return 0; +} + + +#if 0 /* unused */ + +/* + * Read "len" bytes from "filename" into "buf". + * "buf" is in kernel space. + */ +int +mini_fo_read_file(const char *filename, void *buf, int len) +{ + file_t *filp; + mm_segment_t oldfs; + int bytes; + /* Chroot? Maybe NULL isn't right here */ + filp = filp_open(filename, O_RDONLY, 0); + if (!filp || IS_ERR(filp)) { + printk("mini_fo_read_file err %d\n", (int) PTR_ERR(filp)); + return -1; /* or do something else */ + } + + if (!filp->f_op->read) + return -2; /* file(system) doesn't allow reads */ + + /* now read len bytes from offset 0 */ + filp->f_pos = 0; /* start offset */ + oldfs = get_fs(); + set_fs(KERNEL_DS); + bytes = filp->f_op->read(filp, buf, len, &filp->f_pos); + set_fs(oldfs); + + /* close the file */ + fput(filp); + + return bytes; +} + + + +/* + * Write "len" bytes from "buf" to "filename" + * "buf" is in kernel space. + */ +int +mini_fo_write_file(const char *filename, void *buf, int len) +{ + file_t *filp; + mm_segment_t oldfs; + int bytes; + /* Chroot? Maybe NULL isn't right here */ + filp = filp_open(filename, O_RDWR|O_CREAT, 0640); + if (!filp || IS_ERR(filp)) { + printk("mini_fo_write_file err %d\n", (int) PTR_ERR(filp)); + return -1; /* or do something else */ + } + + if (!filp->f_op->write) + return -2; /* file(system) doesn't allow writes */ + + /* now write len bytes from offset 0 */ + filp->f_pos = 0; /* start offset */ + oldfs = get_fs(); + set_fs(KERNEL_DS); + bytes = filp->f_op->write(filp, buf, len, &filp->f_pos); + set_fs(oldfs); + + /* close the file */ + fput(filp); + + return bytes; +} + +#endif /* unused */ + diff -urN linux-2.6.19.old/fs/mini_fo/ChangeLog linux-2.6.19.dev/fs/mini_fo/ChangeLog --- linux-2.6.19.old/fs/mini_fo/ChangeLog 1970-01-01 01:00:00.000000000 +0100 +++ linux-2.6.19.dev/fs/mini_fo/ChangeLog 2006-12-14 03:14:03.000000000 +0100 @@ -0,0 +1,281 @@ +2006-01-24 Markus Klotzbuecher + + * Add tons of ugly ifdefs to Ed L. Cashin's mutex patch to + retain backwards compatibility. + +2006-01-24 Ed L. Cashin + + * Support for the new mutex infrastructure + (7892f2f48d165a34b0b8130c8a195dfd807b8cb6) + +2005-10-15 Markus Klotzbuecher + + * Bugfix for a serious memory leak in mini_fo_follow_link. + +2005-09-21 Markus Klotzbuecher + + * new release 0.6.1 + + * fix of a compiler warning due to changes in 2.6.13 + +2005-09-21 Klaus Wenninger + + * file.c: readdir: fix for a bug that caused directory entries + to show up twice when using storage filesystems such as + minixfs or pramfs. + +2005-06-30 Eric Lammerts + + * fix for an oops when overwriting a binary thats beeing + executed. + +2005-06-09 + + * Renamed overlay to mini_fo-overlay. + + * Added mini_fo-merge script to allow merging of storage and base + after making modifications. + +2005-05-22 root + + * Added overlay script that allows to easily mount mini_fo ontop + of a given base directory + +2005-05-10 + + * inode.c: xattr functions return -EOPNOSUPP instead of + -ENOSUPP, what confuses "ls -l" + + * Changed license from LGPL to GPL. + +2005-05-08 root + + * Makefile: clean it up and added make install and make + uninstall. + +2005-05-06 + + * merged devel branch back to main. [v0-6-0-pre3] + + * removed unused files print.c and fist_ioctl. [devel-0-0-18] + + * ioctl: removed fist_ioctl stuff, that is not needed for + now. + +2005-05-03 + + * file.c: simplified mini_fo_open and mini_fo_setattr using + new state changing functions. [devel-0-0-17] + + * inode.c: Fixed getattr state bug (see below) in 2.4 function + mini_fo_inode revalidate. + + * inode.c: found an other bug in mini_fo_getattr. States are not + reliable in this function, as a file can be opened, unlinked and + the getattr function called. This results in a deleted dentry + with an inode. Fix is to ignore states and simply use the inode + available. + +2005-04-29 + + * file.c: Bugfix and cleanup in fasync and fsync. [devel-0-0-16] + + * file.c: do not use mini_fo_lock so the generic version is + used (I guess). + + * inode.c: getattr, never call getattr on lower files, as this + will cause the inum to change. + + * inode.c: rename_reg_file renamed to rename_nondir, as it + doesn't matter as long it't not a dir. Removed all + rename_dev_file etc. + + * tagged as devel-0-0-15 + + * inode.c: added support for chosing support for extended + attrs at compile time by XATTR define in mini_fo.h . + + * inode.c: fixed mini_fo_getattr to use mini_fo inode and not + lower again, what avoids inode number changes that confused + rm again. This is the proper solution. + +2005-04-24 + + * all files: updated Copyright notive to 2005. [devel-0-0-14] + + * inode.c: fixed mini_fo_getattr to not change the inode + number, even if lower files change. + + * super.c: fixed a bug that caused deleted base file to show + up suddenly after some time, or after creating a special + file. The problem was that after some time or after special + file creating sync_sb_inodes is called by the vfs, that + called our mini_fo_put_inode. There was (wrongly) called + __meta_put_lists, that nuked the lists, although the inode + was going to continue its life. Moving __meta_put_lists to + mini_fo_clear_inode, where an inode is really destroyed, + solved the problem. + + +2005-04-23 + + * state.c, aux.c: more cleaning up and + simplifications. [devel-0-0-13] + + * inode.c: implemented mini_fo_getattr, that was required for + 2.6 because inode_revalidate has been remove there, and the + old "du" bug returned. + + +2005-04-20 + + * aux.c: get_neg_sto_dentry(): allow to be called for dentries + in state UNMODIFIED, NON_EXISTANT _and_ DELETED. + +2005-04-19 + + * Fixed a bug under 2.6 that caused files deleted via mini_fo + not to be deleted properly and therefore the fs filled up + untill no memory was left. [devel-0-0-12] + + * Added basic hard link support. This means that creating + hardlinks will work, but existing ones will be treated as + individual files. [devel-0-0-11] + +2005-04-17 + + * Bugfixes + +2005-04-13 root + + * Added file state.c for the state transition + functions. Doesn't work very well yet, though... + +2005-04-12 + + * Porting to 2.6 started, which is easier than expected, also + due to Olivier previous work. + +2005-04-08 + + * Fixed the bug that caused du to return invalid sizes of + directory trees. The problem was that + mini_fo_inode_revalidate didn't always copy the attributes + from the base inode properly. + +2005-04-01 Markus Klotzbuecher + + * Merged devel branch back to main trunk and updated the + RELEASE notes. This will be 0-6-0-pre1. + +2005-03-31 Markus Klotzbuecher + + * Fixed some bugs in rename_reg_file, that only showed up in + the kernel compile test. Kernel compiles cleanly ontop of + mini_fo, now also make mrproper etc. work. Seems pretty stable. + +2005-03-28 Markus Klotzbuecher + + * Many, many directory renaming bugfixes and a lot of other + cleanup. Dir renaming seems to work relatively stable. + +2005-03-22 Markus Klotzbuecher + + * Finished implementing lightweight directory renaming. Some + basic testing indicates it works fine. + Next is to implement testcases for the testsuite and confirm + everything is really working ok. + +2005-03-18 Markus Klotzbuecher + + * Finished implementing meta.c stuff required for directory + renaming. + +2005-03-17 Markus Klotzbuecher + + * Fixed all compile warnings + an extremly old bug that + somehow crept in while reworking the wol stuff to the META + system. Turning on -Werror again... :-) + + * Fixed some bugs in the new rename_reg_file function. + + * Rewrote mini_fo rename and split it into several + subfunctions, that handle the different types + seperately. Rewrote the regular file function aswell, as it + was implemented somewhat inefficient. + +2005-03-16 Markus Klotzbuecher + + * Implemented new META subsystem, removed old WOL stuff in favor + if it. + + * After some basic testing everything seems ok... + +2005-03-11 Markus Klotzbuecher + + * Renaming a non regular file caused trouble because I always + tried to copy the contents. Now I only do this for regular + files. mini_fo_rename still isn't implemented properly, renaming + of device files, symlinks etc. results in a empty regular file + instead of the proper type. + + * Directory renaming suddenly works! What a surprise! I guess + this is because renaming is implemented as making a copy and + removing the original. Still this might not work + everywhere... + +2005-03-09 Markus Klotzbuecher + + * Bugfix, when a mini_fo directory that exists in storage + (state: MODIFIED, CREATED and DEL_REWRITTEN) is deleted, a + possibly existing WOL file contained in it needs to be + deleted too. + + * Starting cleanup: defined state names in order to get rid of + the state numbers. + +2005-03-08 Markus Klotzbuecher + + * Makefile fix, fist_ioctl was built against wrong sources if ARCH=um + + * Fixed a bug in dentry.c, mini_fo_d_hash. In state 4 = + DEL_REWRITTEN the hash was calculated from the base dentry, + which was wrong and and caused assertions in + __mini_fo_hidden_dentry to fail. + +2005-02-21 + + * Implemented directory deleting (inode.c) + + * main.c: made mini_fo_parse_options a little more robust. + +2004-12-22 + + * Makefile cleanup and uml stuff, removed unneccessary files + + * Created a new and hopefully more informative README + + * CHANGELOG: created a new CHANGELOG and added old entries reversely + + +2004-10-24 Gleb Natapov + + * Fix: owner and group where not correctly copied from base to + storage. + + +2004-10-05 Gleb Natapov + + * Implementation of fsync, fasync and lock mini_fo functions. + + +2004-09-29 Bob Lee + + * Fix of a serious pointer bug + + +2004-09-28 Gleb Natapov + + * Implementation of mini_fo_mknod and mini_fo_rename, support + for device files. + diff -urN linux-2.6.19.old/fs/mini_fo/dentry.c linux-2.6.19.dev/fs/mini_fo/dentry.c --- linux-2.6.19.old/fs/mini_fo/dentry.c 1970-01-01 01:00:00.000000000 +0100 +++ linux-2.6.19.dev/fs/mini_fo/dentry.c 2006-12-14 03:14:03.000000000 +0100 @@ -0,0 +1,244 @@ +/* + * Copyright (c) 1997-2003 Erez Zadok + * Copyright (c) 2001-2003 Stony Brook University + * + * For specific licensing information, see the COPYING file distributed with + * this package, or get one from ftp://ftp.filesystems.org/pub/fist/COPYING. + * + * This Copyright notice must be kept intact and distributed with all + * fistgen sources INCLUDING sources generated by fistgen. + */ +/* + * Copyright (C) 2004, 2005 Markus Klotzbuecher + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version + * 2 of the License, or (at your option) any later version. + */ + +/* + * $Id$ + */ + +#ifdef HAVE_CONFIG_H +# include +#endif + +#include "fist.h" +#include "mini_fo.h" + +/* + * THIS IS A BOOLEAN FUNCTION: returns 1 if valid, 0 otherwise. + */ +STATIC int +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0) +mini_fo_d_revalidate(dentry_t *dentry, struct nameidata *nd) +#else +mini_fo_d_revalidate(dentry_t *dentry, int flags) +#endif +{ + int err1 = 1; /* valid = 1, invalid = 0 */ + int err2 = 1; + dentry_t *hidden_dentry; + dentry_t *hidden_sto_dentry; + + + check_mini_fo_dentry(dentry); + + hidden_dentry = dtohd(dentry); + hidden_sto_dentry = dtohd2(dentry); + + if(hidden_dentry && + hidden_dentry->d_op && + hidden_dentry->d_op->d_revalidate) { +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0) + err1 = hidden_dentry->d_op->d_revalidate(hidden_dentry, nd); +#else + err1 = hidden_dentry->d_op->d_revalidate(hidden_dentry, flags); +#endif + } + if(hidden_sto_dentry && + hidden_sto_dentry->d_op && + hidden_sto_dentry->d_op->d_revalidate) { +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0) + err2 = hidden_sto_dentry->d_op->d_revalidate(hidden_sto_dentry, + nd); +#else + err2 = hidden_sto_dentry->d_op->d_revalidate(hidden_sto_dentry, + flags); +#endif + } + + /* mk: if one of the lower level dentries are valid, + * the mini_fo dentry is too. + */ + return (err1 || err2); +} + + +STATIC int +mini_fo_d_hash(dentry_t *dentry, qstr_t *name) +{ + int err = 0; + dentry_t *hidden_dentry; + dentry_t *hidden_sto_dentry; + + /* hidden_dentry = mini_fo_hidden_dentry(dentry); + * hidden_sto_dentry = mini_fo_hidden_sto_dentry(dentry); */ + + /* state 1, 3, 4, 5: build the hash for the storage dentry */ + if((dtopd(dentry)->state == MODIFIED) || + (dtopd(dentry)->state == CREATED) || + (dtopd(dentry)->state == DEL_REWRITTEN) || + (dtopd(dentry)->state == DELETED)) { + hidden_sto_dentry = dtohd2(dentry); + if(hidden_sto_dentry && + hidden_sto_dentry->d_op && + hidden_sto_dentry->d_op->d_hash) { + err = hidden_sto_dentry->d_op->d_hash(hidden_sto_dentry, name); + } + goto out; + } + /* state 2: build the hash for the base dentry */ + if(dtopd(dentry)->state == UNMODIFIED) { + hidden_dentry = dtohd(dentry); + if(hidden_dentry && + hidden_dentry->d_op && + hidden_dentry->d_op->d_hash) { + err = hidden_dentry->d_op->d_hash(hidden_dentry, name); + } + goto out; + } + /* state 6: build hash for the dentry that exists */ + if(dtopd(dentry)->state == NON_EXISTANT) { + hidden_sto_dentry = dtohd2(dentry); + if(hidden_sto_dentry && + hidden_sto_dentry->d_op && + hidden_sto_dentry->d_op->d_hash) { + err = hidden_sto_dentry->d_op->d_hash(hidden_sto_dentry, name); + goto out; + } + hidden_dentry = dtohd(dentry); + if(hidden_dentry && + hidden_dentry->d_op && + hidden_dentry->d_op->d_hash) { + err = hidden_dentry->d_op->d_hash(hidden_dentry, name); + goto out; + } + } + + printk(KERN_CRIT "mini_fo: d_hash: invalid state detected.\n"); + + out: + return err; +} + + +STATIC int +mini_fo_d_compare(dentry_t *dentry, qstr_t *a, qstr_t *b) +{ + int err; + dentry_t *hidden_dentry=NULL; + + /* hidden_dentry = mini_fo_hidden_dentry(dentry); */ + if(dtohd2(dentry)) + hidden_dentry = dtohd2(dentry); + else if(dtohd(dentry)) + hidden_dentry = dtohd(dentry); + + if (hidden_dentry && hidden_dentry->d_op && hidden_dentry->d_op->d_compare) { + err = hidden_dentry->d_op->d_compare(hidden_dentry, a, b); + } else { + err = ((a->len != b->len) || memcmp(a->name, b->name, b->len)); + } + + return err; +} + + +int +mini_fo_d_delete(dentry_t *dentry) +{ + dentry_t *hidden_dentry; + dentry_t *hidden_sto_dentry; + int err = 0; + + /* this could be a negative dentry, so check first */ + if (!dtopd(dentry)) { + printk(KERN_CRIT "mini_fo_d_delete: negative dentry passed.\n"); + goto out; + } + hidden_dentry = dtohd(dentry); + hidden_sto_dentry = dtohd2(dentry); + + if(hidden_dentry) { + if(hidden_dentry->d_op && + hidden_dentry->d_op->d_delete) { + err = hidden_dentry->d_op->d_delete(hidden_dentry); + } + } + if(hidden_sto_dentry) { + if(hidden_sto_dentry->d_op && + hidden_sto_dentry->d_op->d_delete) { + err = hidden_sto_dentry->d_op->d_delete(hidden_sto_dentry); + } + } + + out: + return err; +} + + +void +mini_fo_d_release(dentry_t *dentry) +{ + dentry_t *hidden_dentry; + dentry_t *hidden_sto_dentry; + + + /* this could be a negative dentry, so check first */ + if (!dtopd(dentry)) { + printk(KERN_CRIT "mini_fo_d_release: no private data.\n"); + goto out; + } + hidden_dentry = dtohd(dentry); + hidden_sto_dentry = dtohd2(dentry); + + if(hidden_dentry) { + /* decrement hidden dentry's counter and free its inode */ + dput(hidden_dentry); + } + if(hidden_sto_dentry) { + /* decrement hidden dentry's counter and free its inode */ + dput(hidden_sto_dentry); + } + + /* free private data (mini_fo_dentry_info) here */ + kfree(dtopd(dentry)); + __dtopd(dentry) = NULL; /* just to be safe */ + out: + return; +} + + +/* + * we don't really need mini_fo_d_iput, because dentry_iput will call iput() if + * mini_fo_d_iput is not defined. We left this implemented for ease of + * tracing/debugging. + */ +void +mini_fo_d_iput(dentry_t *dentry, inode_t *inode) +{ + iput(inode); +} + + +struct dentry_operations mini_fo_dops = { + d_revalidate: mini_fo_d_revalidate, + d_hash: mini_fo_d_hash, + d_compare: mini_fo_d_compare, + d_release: mini_fo_d_release, + d_delete: mini_fo_d_delete, + d_iput: mini_fo_d_iput, +}; diff -urN linux-2.6.19.old/fs/mini_fo/file.c linux-2.6.19.dev/fs/mini_fo/file.c --- linux-2.6.19.old/fs/mini_fo/file.c 1970-01-01 01:00:00.000000000 +0100 +++ linux-2.6.19.dev/fs/mini_fo/file.c 2006-12-14 03:14:03.000000000 +0100 @@ -0,0 +1,713 @@ +/* + * Copyright (c) 1997-2003 Erez Zadok + * Copyright (c) 2001-2003 Stony Brook University + * + * For specific licensing information, see the COPYING file distributed with + * this package, or get one from ftp://ftp.filesystems.org/pub/fist/COPYING. + * + * This Copyright notice must be kept intact and distributed with all + * fistgen sources INCLUDING sources generated by fistgen. + */ +/* + * Copyright (C) 2004, 2005 Markus Klotzbuecher + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version + * 2 of the License, or (at your option) any later version. + */ + +/* + * $Id$ + */ + +#ifdef HAVE_CONFIG_H +# include +#endif + +#include "fist.h" +#include "mini_fo.h" +#define ROUND_UP(x) (((x)+sizeof(long)-1) & ~(sizeof(long)-1)) + +/******************* + * File Operations * + *******************/ + +STATIC loff_t +mini_fo_llseek(file_t *file, loff_t offset, int origin) +{ + loff_t err; + file_t *hidden_file = NULL; + + if(S_ISDIR(file->f_dentry->d_inode->i_mode)) { + /* Check if trying to llseek from a directory */ + err = -EISDIR; + goto out; + } + if (ftopd(file) != NULL) { + if(ftohf2(file)) { + hidden_file = ftohf2(file); + } else { + hidden_file = ftohf(file); + } + } + + /* always set hidden position to this one */ + hidden_file->f_pos = file->f_pos; + +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0) + memcpy(&(hidden_file->f_ra), + &(file->f_ra), + sizeof(struct file_ra_state)); +#else + if (file->f_reada) { /* update readahead information if needed */ + hidden_file->f_reada = file->f_reada; + hidden_file->f_ramax = file->f_ramax; + hidden_file->f_raend = file->f_raend; + hidden_file->f_ralen = file->f_ralen; + hidden_file->f_rawin = file->f_rawin; + } +#endif + if (hidden_file->f_op && hidden_file->f_op->llseek) + err = hidden_file->f_op->llseek(hidden_file, offset, origin); + else + err = generic_file_llseek(hidden_file, offset, origin); + + if (err < 0) + goto out; + + if (err != file->f_pos) { + file->f_pos = err; + // ION maybe this? + // file->f_pos = hidden_file->f_pos; +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0) + file->f_reada = 0; +#endif + file->f_version++; + } + + out: + return err; +} + + +/* mk: fanout capable */ +STATIC ssize_t +mini_fo_read(file_t *file, char *buf, size_t count, loff_t *ppos) +{ + int err = -EINVAL; + file_t *hidden_file = NULL; + loff_t pos = *ppos; + + if(S_ISDIR(file->f_dentry->d_inode->i_mode)) { + /* Check if trying to read from a directory */ + /* printk(KERN_CRIT "mini_fo_read: ERROR: trying to read data from a directory.\n"); */ + err = -EISDIR; + goto out; + } + + if (ftopd(file) != NULL) { + if(ftohf2(file)) { + hidden_file = ftohf2(file); + } else { + hidden_file = ftohf(file); + } + } + + if (!hidden_file->f_op || !hidden_file->f_op->read) + goto out; + + err = hidden_file->f_op->read(hidden_file, buf, count, &pos); + *ppos = pos; + + if (err >= 0) { + /* atime should also be updated for reads of size zero or more */ + fist_copy_attr_atime(file->f_dentry->d_inode, + hidden_file->f_dentry->d_inode); + } + +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0) + /* + * MAJOR HACK + * because pread() does not have any way to tell us that it is + * our caller, then we don't know for sure if we have to update + * the file positions. This hack relies on read() having passed us + * the "real" pointer of its struct file's f_pos field. + */ + if (ppos == &file->f_pos) + hidden_file->f_pos = *ppos = pos; + if (hidden_file->f_reada) { /* update readahead information if needed */ + file->f_reada = hidden_file->f_reada; + file->f_ramax = hidden_file->f_ramax; + file->f_raend = hidden_file->f_raend; + file->f_ralen = hidden_file->f_ralen; + file->f_rawin = hidden_file->f_rawin; + } +#else + memcpy(&(file->f_ra),&(hidden_file->f_ra),sizeof(struct file_ra_state)); +#endif + + out: + return err; +} + + +/* this mini_fo_write() does not modify data pages! */ +STATIC ssize_t +mini_fo_write(file_t *file, const char *buf, size_t count, loff_t *ppos) +{ + int err = -EINVAL; + file_t *hidden_file = NULL; + inode_t *inode; + inode_t *hidden_inode; + loff_t pos = *ppos; + + /* mk: fan out: */ + if (ftopd(file) != NULL) { + if(ftohf2(file)) { + hidden_file = ftohf2(file); + } else { + /* This is bad! We have no storage file to write to. This + * should never happen because if a file is opened for + * writing, a copy should have been made earlier. + */ + printk(KERN_CRIT "mini_fo: write : ERROR, no storage file to write.\n"); + err = -EINVAL; + goto out; + } + } + + inode = file->f_dentry->d_inode; + hidden_inode = itohi2(inode); + if(!hidden_inode) { + printk(KERN_CRIT "mini_fo: write: no sto inode found, not good.\n"); + goto out; + } + + if (!hidden_file->f_op || !hidden_file->f_op->write) + goto out; + + /* adjust for append -- seek to the end of the file */ + if (file->f_flags & O_APPEND) + pos = inode->i_size; + + err = hidden_file->f_op->write(hidden_file, buf, count, &pos); + + /* + * copy ctime and mtime from lower layer attributes + * atime is unchanged for both layers + */ + if (err >= 0) + fist_copy_attr_times(inode, hidden_inode); + + *ppos = pos; +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0) + /* + * XXX: MAJOR HACK + * + * because pwrite() does not have any way to tell us that it is + * our caller, then we don't know for sure if we have to update + * the file positions. This hack relies on write() having passed us + * the "real" pointer of its struct file's f_pos field. + */ + if (ppos == &file->f_pos) + hidden_file->f_pos = *ppos = pos; +#endif + /* update this inode's size */ + if (pos > inode->i_size) + inode->i_size = pos; + + out: + return err; +} + +/* Global variable to hold a file_t pointer. + * This serves to allow mini_fo_filldir function to know which file is + * beeing read, which is required for two reasons: + * + * - be able to call wol functions in order to avoid listing deleted + * base files. + * - if we're reading a directory which is in state 1, we need to + * maintain a list (in mini_fo_filldir) of which files allready + * have been copied to userspace,to detect files existing in base + * and storage and not list them twice. + */ +filldir_t mini_fo_filldir_orig; +file_t *mini_fo_filldir_file; + +/* mainly copied from fs/readdir.c */ +STATIC int +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,18) +mini_fo_filldir(void * __buf, const char * name, int namlen, loff_t offset, + u64 ino, unsigned int d_type) +#else +mini_fo_filldir(void * __buf, const char * name, int namlen, loff_t offset, + ino_t ino, unsigned int d_type) +#endif +{ + struct getdents_callback * buf = (struct getdents_callback *) __buf; + file_t* file = mini_fo_filldir_file; + + /* In theses states we filter meta files in storage (WOL) */ + if(file && (dtopd(file->f_dentry)->state == MODIFIED || + dtopd(file->f_dentry)->state == CREATED || + dtopd(file->f_dentry)->state == DEL_REWRITTEN)) { + + int tmp = strlen(META_FILENAME); + if(tmp == namlen) { + if(!strncmp(name, META_FILENAME, namlen)) + return 0; + } + } + + /* check if we are merging the contents of storage and base */ + if(file && dtopd(file->f_dentry)->state == MODIFIED) { + /* check if we are still reading storage contents, if + * yes, we just save the name of the file for duplicate + * checking later. */ + + if(!ftopd(file)->rd.sto_done) { + /* put file into ndl list */ + if(ndl_add_entry(&ftopd(file)->rd, name, namlen)) + printk(KERN_CRIT "mini_fo_filldir: Error adding to ndl.\n"); + } else { + /* check if file has been deleted */ + if(meta_check_d_entry(file->f_dentry, name, namlen)) + return 0; + + /* do duplicate checking */ + if(ndl_check_entry(&ftopd(file)->rd, name, namlen)) + return 0; + } + } + + return mini_fo_filldir_orig(buf, name, namlen, offset, ino, d_type); +} + + +STATIC int +mini_fo_readdir(file_t *file, void *dirent, filldir_t filldir) +{ + int err = 0;/* mk: ??? -ENOTDIR; */ + file_t *hidden_file = NULL; + file_t *hidden_sto_file = NULL; + inode_t *inode; + struct getdents_callback *buf; + int oldcount; + +#if defined(FIST_FILTER_NAME) || defined(FIST_FILTER_SCA) + struct mini_fo_getdents_callback buf; +#endif /* FIST_FILTER_NAME || FIST_FILTER_SCA */ + + buf = (struct getdents_callback *) dirent; + oldcount = buf->count; + inode = file->f_dentry->d_inode; + mini_fo_filldir_file = file; + mini_fo_filldir_orig = filldir; + + ftopd(file)->rd.sto_done = 0; + do { + if (ftopd(file) != NULL) { + if(ftohf2(file)) { + hidden_sto_file = ftohf2(file); + err = vfs_readdir(hidden_sto_file, mini_fo_filldir, dirent); + file->f_pos = hidden_sto_file->f_pos; + if (err > 0) + fist_copy_attr_atime(inode, hidden_sto_file->f_dentry->d_inode); + /* not finshed yet, we'll be called again */ + if (buf->count != oldcount) + break; + } + + ftopd(file)->rd.sto_done = 1; + + if(ftohf(file)) { + hidden_file = ftohf(file); + err = vfs_readdir(hidden_file, mini_fo_filldir, dirent); + file->f_pos = hidden_file->f_pos; + if (err > 0) + fist_copy_attr_atime(inode, hidden_file->f_dentry->d_inode); + } + + } + } while (0); + + /* mk: + * we need to check if all the directory data has been copied to userspace, + * or if we will be called again by userspace to complete the operation. + */ + if(buf->count == oldcount) { + ndl_put_list(&ftopd(file)->rd); + } + + /* unset this, safe */ + mini_fo_filldir_file = NULL; + return err; +} + + +STATIC unsigned int +mini_fo_poll(file_t *file, poll_table *wait) +{ + unsigned int mask = DEFAULT_POLLMASK; + file_t *hidden_file = NULL; + + if (ftopd(file) != NULL) { + if(ftohf2(file)) { + hidden_file = ftohf2(file); + } else { + hidden_file = ftohf(file); + } + } + + if (!hidden_file->f_op || !hidden_file->f_op->poll) + goto out; + + mask = hidden_file->f_op->poll(hidden_file, wait); + + out: + return mask; +} + +/* FIST-LITE special version of mmap */ +STATIC int +mini_fo_mmap(file_t *file, vm_area_t *vma) +{ + int err = 0; + file_t *hidden_file = NULL; + + /* fanout capability */ + if (ftopd(file) != NULL) { + if(ftohf2(file)) { + hidden_file = ftohf2(file); + } else { + hidden_file = ftohf(file); + } + } + + ASSERT(hidden_file != NULL); + ASSERT(hidden_file->f_op != NULL); + ASSERT(hidden_file->f_op->mmap != NULL); + + vma->vm_file = hidden_file; + err = hidden_file->f_op->mmap(hidden_file, vma); + get_file(hidden_file); /* make sure it doesn't get freed on us */ + fput(file); /* no need to keep extra ref on ours */ + + return err; +} + + + +STATIC int +mini_fo_open(inode_t *inode, file_t *file) +{ + int err = 0; + int hidden_flags; + file_t *hidden_file = NULL; + dentry_t *hidden_dentry = NULL; + + /* fanout stuff */ + file_t *hidden_sto_file = NULL; + dentry_t *hidden_sto_dentry = NULL; + + __ftopd(file) = + kmalloc(sizeof(struct mini_fo_file_info), GFP_KERNEL); + if (!ftopd(file)) { + err = -ENOMEM; + goto out; + } + + /* init the readdir_helper structure */ + INIT_LIST_HEAD(&ftopd(file)->rd.ndl_list); + ftopd(file)->rd.ndl_size = 0; + + /* In certain paths this could stay uninitalized and cause trouble */ + ftohf(file) = NULL; + ftohf2(file) = NULL; + hidden_flags = file->f_flags; + + /* create storage files? */ + if(dtost(file->f_dentry) == UNMODIFIED) { + if(!IS_WRITE_FLAG(file->f_flags)) { + hidden_dentry = dtohd(file->f_dentry); + dget(hidden_dentry); + /* dentry_open will decrement mnt refcnt if err. + * otherwise fput() will do an mntput() for us upon file close. */ + mntget(stopd(inode->i_sb)->hidden_mnt); + hidden_file = dentry_open(hidden_dentry, + stopd(inode->i_sb)->hidden_mnt, + hidden_flags); + if (IS_ERR(hidden_file)) { + err = PTR_ERR(hidden_file); + dput(hidden_dentry); + goto out; + } + ftohf(file) = hidden_file; /* link two files */ + goto out; + } + else { + if(S_ISDIR(file->f_dentry->d_inode->i_mode)) { + err = dir_unmod_to_mod(file->f_dentry); + } else + err = nondir_unmod_to_mod(file->f_dentry, 1); + + if (err) { + printk("mini_fo_open: ERROR creating storage file.\n"); + goto out; + } + } + } + hidden_sto_dentry = dtohd2(file->f_dentry); + dget(hidden_sto_dentry); + + if(dtopd(file->f_dentry)->state == MODIFIED) { + /* Directorys are special, interpose on both lower level files */ + if(S_ISDIR(itohi(inode)->i_mode)) { + /* check for invalid file types of lower level files */ + if(!(S_ISDIR(itohi(inode)->i_mode) && S_ISDIR(itohi2(inode)->i_mode))) { + printk(KERN_CRIT "mini_fo_open: meta data corruption detected.\n"); + dput(hidden_sto_dentry); + err = -EINVAL; + goto out; + } + + /* lower level directorys are ok, open the base file */ + hidden_dentry = dtohd(file->f_dentry); + dget(hidden_dentry); + + mntget(stopd(inode->i_sb)->hidden_mnt); + hidden_file = dentry_open(hidden_dentry, + stopd(inode->i_sb)->hidden_mnt, + hidden_flags); + if (IS_ERR(hidden_file)) { + err = PTR_ERR(hidden_file); + dput(hidden_dentry); + dput(hidden_sto_dentry); + goto out; + } + ftohf(file) = hidden_file; /* link the two files */ + } + } + + if(!exists_in_storage(file->f_dentry)) { + printk(KERN_CRIT "mini_fo_open: invalid file state detected.\n"); + err = -EINVAL; + dput(hidden_sto_dentry); + + /* If the base file has been opened, we need to close it here */ + if(ftohf(file)) { + if (hidden_file->f_op && hidden_file->f_op->flush) +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,18) + hidden_file->f_op->flush(hidden_file, NULL); +#else + hidden_file->f_op->flush(hidden_file); +#endif + dput(hidden_dentry); + } + goto out; + } + + /* ok, now we can safely open the storage file */ + mntget(stopd(inode->i_sb)->hidden_mnt2); + hidden_sto_file = dentry_open(hidden_sto_dentry, + stopd(inode->i_sb)->hidden_mnt2, + hidden_flags); + + /* dentry_open dputs the dentry if it fails */ + if (IS_ERR(hidden_sto_file)) { + err = PTR_ERR(hidden_sto_file); + /* close base file if open */ + if(ftohf(file)) { + if (hidden_file->f_op && hidden_file->f_op->flush) +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,18) + hidden_file->f_op->flush(hidden_file, NULL); +#else + hidden_file->f_op->flush(hidden_file); +#endif + dput(hidden_dentry); + } + goto out; + } + ftohf2(file) = hidden_sto_file; /* link storage file */ + + out: + if (err < 0 && ftopd(file)) { + kfree(ftopd(file)); + } + return err; +} + +STATIC int +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,18) +mini_fo_flush(file_t *file, fl_owner_t id) +#else +mini_fo_flush(file_t *file) +#endif +{ + int err1 = 0; /* assume ok (see open.c:close_fp) */ + int err2 = 0; + file_t *hidden_file = NULL; + + check_mini_fo_file(file); + + /* mk: we don't do any state checking here, as its not worth the time. + * Just flush the lower level files if they exist. + */ + if(ftopd(file) != NULL) { + if(ftohf(file) != NULL) { + hidden_file = ftohf(file); + if (hidden_file->f_op && hidden_file->f_op->flush) +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,18) + err1 = hidden_file->f_op->flush(hidden_file, id); +#else + err1 = hidden_file->f_op->flush(hidden_file); +#endif + } + if(ftohf2(file) != NULL) { + hidden_file = ftohf2(file); + if (hidden_file->f_op && hidden_file->f_op->flush) +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,18) + err2 = hidden_file->f_op->flush(hidden_file, id); +#else + err2 = hidden_file->f_op->flush(hidden_file); +#endif + } + } + return (err1 | err2); +} + + +STATIC int +mini_fo_release(inode_t *inode, file_t *file) +{ + int err = 0; + file_t *hidden_file = NULL; + + if (ftopd(file) != NULL) { + if(ftohf(file)) { + hidden_file = ftohf(file); + fput(hidden_file); + } + if(ftohf2(file)) { + hidden_file = ftohf2(file); + fput(hidden_file); + } + kfree(ftopd(file)); + } + return err; +} + +STATIC int +mini_fo_fsync(file_t *file, dentry_t *dentry, int datasync) +{ + int err1 = 0; + int err2 = 0; + file_t *hidden_file = NULL; + dentry_t *hidden_dentry; + + check_mini_fo_file(file); + + if ((hidden_file = ftohf(file)) != NULL) { + hidden_dentry = dtohd(dentry); + if (hidden_file->f_op && hidden_file->f_op->fsync) { +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16) + mutex_lock(&hidden_dentry->d_inode->i_mutex); +#else + down(&hidden_dentry->d_inode->i_sem); +#endif + err1 = hidden_file->f_op->fsync(hidden_file, hidden_dentry, datasync); +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16) + mutex_unlock(&hidden_dentry->d_inode->i_mutex); +#else + up(&hidden_dentry->d_inode->i_sem); +#endif + } + } + + if ((hidden_file = ftohf2(file)) != NULL) { + hidden_dentry = dtohd2(dentry); + if (hidden_file->f_op && hidden_file->f_op->fsync) { +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16) + mutex_lock(&hidden_dentry->d_inode->i_mutex); +#else + down(&hidden_dentry->d_inode->i_sem); +#endif + err2 = hidden_file->f_op->fsync(hidden_file, hidden_dentry, datasync); +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16) + mutex_unlock(&hidden_dentry->d_inode->i_mutex); +#else + up(&hidden_dentry->d_inode->i_sem); +#endif + } + } + else + goto err; + +err: + return (err1 || err2); +} + + +STATIC int +mini_fo_fasync(int fd, file_t *file, int flag) +{ + int err1 = 0; + int err2 = 0; + + file_t *hidden_file = NULL; + + check_mini_fo_file(file); + + if((hidden_file = ftohf(file)) != NULL) { + err1 = hidden_file->f_op->fasync(fd, hidden_file, flag); + } + if((hidden_file = ftohf2(file)) != NULL) { + err2 = hidden_file->f_op->fasync(fd, hidden_file, flag); + } + + return (err1 || err2); +} + + + +struct file_operations mini_fo_dir_fops = + { + read: generic_read_dir, + write: mini_fo_write, + readdir: mini_fo_readdir, + poll: mini_fo_poll, + /* ioctl: mini_fo_ioctl, */ + mmap: mini_fo_mmap, + open: mini_fo_open, + flush: mini_fo_flush, + release: mini_fo_release, + fsync: mini_fo_fsync, + fasync: mini_fo_fasync, + /* not needed lock: mini_fo_lock, */ + /* not needed: readv */ + /* not needed: writev */ + /* not implemented: sendpage */ + /* not implemented: get_unmapped_area */ + }; + +struct file_operations mini_fo_main_fops = + { + llseek: mini_fo_llseek, + read: mini_fo_read, + write: mini_fo_write, + readdir: mini_fo_readdir, + poll: mini_fo_poll, + /* ioctl: mini_fo_ioctl, */ + mmap: mini_fo_mmap, + open: mini_fo_open, + flush: mini_fo_flush, + release: mini_fo_release, + fsync: mini_fo_fsync, + fasync: mini_fo_fasync, + /* not needed: lock: mini_fo_lock, */ + /* not needed: readv */ + /* not needed: writev */ + /* not implemented: sendpage */ + /* not implemented: get_unmapped_area */ + }; diff -urN linux-2.6.19.old/fs/mini_fo/fist.h linux-2.6.19.dev/fs/mini_fo/fist.h --- linux-2.6.19.old/fs/mini_fo/fist.h 1970-01-01 01:00:00.000000000 +0100 +++ linux-2.6.19.dev/fs/mini_fo/fist.h 2006-12-14 03:14:03.000000000 +0100 @@ -0,0 +1,252 @@ +/* + * Copyright (c) 1997-2003 Erez Zadok + * Copyright (c) 2001-2003 Stony Brook University + * + * For specific licensing information, see the COPYING file distributed with + * this package, or get one from ftp://ftp.filesystems.org/pub/fist/COPYING. + * + * This Copyright notice must be kept intact and distributed with all + * fistgen sources INCLUDING sources generated by fistgen. + */ +/* + * Copyright (C) 2004, 2005 Markus Klotzbuecher + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version + * 2 of the License, or (at your option) any later version. + */ + + +/* + * $Id$ + */ + +#ifndef __FIST_H_ +#define __FIST_H_ + +/* + * KERNEL ONLY CODE: + */ +#ifdef __KERNEL__ +#include +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,19) +#include +#else +#include +#endif +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0) +#ifdef CONFIG_MODVERSIONS +# define MODVERSIONS +# include +#endif /* CONFIG_MODVERSIONS */ +#endif /* KERNEL_VERSION < 2.6.0 */ +#include +#include +#include +#include +#include +#include +#include +#include +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0) +#include +#else +#include +#include +#include +#include +#include +#include +#include +#include +#endif +#include +#include +#include +#include +#include +#include +#include +#include + +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,20) +#include +#endif + +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0) +#include +#endif + +#include + +#include +#include +#include +#include + +/* + * MACROS: + */ + +/* those mapped to ATTR_* were copied from linux/fs.h */ +#define FA_MODE ATTR_MODE +#define FA_UID ATTR_UID +#define FA_GID ATTR_GID +#define FA_SIZE ATTR_SIZE +#define FA_ATIME ATTR_ATIME +#define FA_MTIME ATTR_MTIME +#define FA_CTIME ATTR_CTIME +#define FA_ATIME_SET ATTR_ATIME_SET +#define FA_MTIME_SET ATTR_MTIME_SET +#define FA_FORCE ATTR_FORCE +#define FA_ATTR_FLAGS ATTR_ATTR_FLAG + +/* must be greater than all other ATTR_* flags! */ +#define FA_NLINK 2048 +#define FA_BLKSIZE 4096 +#define FA_BLOCKS 8192 +#define FA_TIMES (FA_ATIME|FA_MTIME|FA_CTIME) +#define FA_ALL 0 + +/* macros to manage changes between kernels */ +#define INODE_DATA(i) (&(i)->i_data) + +#define MIN(x,y) ((x < y) ? (x) : (y)) +#define MAX(x,y) ((x > y) ? (x) : (y)) +#define MAXPATHLEN PATH_MAX + +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,4,5) +# define lookup_one_len(a,b,c) lookup_one(a,b) +#endif /* LINUX_VERSION_CODE < KERNEL_VERSION(2,4,5) */ + +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,4,8) +# define generic_file_llseek default_llseek +#endif /* LINUX_VERSION_CODE < KERNEL_VERSION(2,4,8) */ + +#ifndef SEEK_SET +# define SEEK_SET 0 +#endif /* not SEEK_SET */ + +#ifndef SEEK_CUR +# define SEEK_CUR 1 +#endif /* not SEEK_CUR */ + +#ifndef SEEK_END +# define SEEK_END 2 +#endif /* not SEEK_END */ + +#ifndef DEFAULT_POLLMASK +# define DEFAULT_POLLMASK (POLLIN | POLLOUT | POLLRDNORM | POLLWRNORM) +#endif /* not DEFAULT_POLLMASK */ + +/* XXX: fix this so fistgen generates kfree() code directly */ +#define kfree_s(a,b) kfree(a) + +/* + * TYPEDEFS: + */ +typedef struct dentry dentry_t; +typedef struct file file_t; +typedef struct inode inode_t; +typedef inode_t vnode_t; +typedef struct page page_t; +typedef struct qstr qstr_t; +typedef struct super_block super_block_t; +typedef super_block_t vfs_t; +typedef struct vm_area_struct vm_area_t; + + +/* + * EXTERNALS: + */ + +#define FPPF(str,page) printk("PPF %s 0x%x/%d: Lck:%d Err:%d Ref:%d Upd:%d Other::%d:%d:%d:%d:\n", \ + str, \ + (int) page, \ + (int) page->index, \ + (PageLocked(page) ? 1 : 0), \ + (PageError(page) ? 1 : 0), \ + (PageReferenced(page) ? 1 : 0), \ + (Page_Uptodate(page) ? 1 : 0), \ + (PageDecrAfter(page) ? 1 : 0), \ + (PageSlab(page) ? 1 : 0), \ + (PageSwapCache(page) ? 1 : 0), \ + (PageReserved(page) ? 1 : 0) \ + ) +#define EZKDBG printk("EZK %s:%d:%s\n",__FILE__,__LINE__,__FUNCTION__) +#if 0 +# define EZKDBG1 printk("EZK %s:%d\n",__FILE__,__LINE__) +#else +# define EZKDBG1 +#endif + +extern int fist_get_debug_value(void); +extern int fist_set_debug_value(int val); +#if 0 /* mini_fo doesn't need these */ +extern void fist_dprint_internal(int level, char *str,...); +extern void fist_print_dentry(char *str, const dentry_t *dentry); +extern void fist_print_inode(char *str, const inode_t *inode); +extern void fist_print_file(char *str, const file_t *file); +extern void fist_print_buffer_flags(char *str, struct buffer_head *buffer); +extern void fist_print_page_flags(char *str, page_t *page); +extern void fist_print_page_bytes(char *str, page_t *page); +extern void fist_print_pte_flags(char *str, const page_t *page); +extern void fist_checkinode(inode_t *inode, char *msg); +extern void fist_print_sb(char *str, const super_block_t *sb); + +/* ยง$% by mk: special debug functions */ +extern void fist_mk_print_dentry(char *str, const dentry_t *dentry); +extern void fist_mk_print_inode(char *str, const inode_t *inode); + +extern char *add_indent(void); +extern char *del_indent(void); +#endif/* mini_fo doesn't need these */ + + +#define STATIC +#define ASSERT(EX) \ +do { \ + if (!(EX)) { \ + printk(KERN_CRIT "ASSERTION FAILED: %s at %s:%d (%s)\n", #EX, \ + __FILE__, __LINE__, __FUNCTION__); \ + (*((char *)0))=0; \ + } \ +} while (0) +/* same ASSERT, but tell me who was the caller of the function */ +#define ASSERT2(EX) \ +do { \ + if (!(EX)) { \ + printk(KERN_CRIT "ASSERTION FAILED (caller): %s at %s:%d (%s)\n", #EX, \ + file, line, func); \ + (*((char *)0))=0; \ + } \ +} while (0) + +#if 0 /* mini_fo doesn't need these */ +#define dprintk(format, args...) printk(KERN_DEBUG format, ##args) +#define fist_dprint(level, str, args...) fist_dprint_internal(level, KERN_DEBUG str, ## args) +#define print_entry_location() fist_dprint(4, "%sIN: %s %s:%d\n", add_indent(), __FUNCTION__, __FILE__, __LINE__) +#define print_exit_location() fist_dprint(4, "%s OUT: %s %s:%d\n", del_indent(), __FUNCTION__, __FILE__, __LINE__) +#define print_exit_status(status) fist_dprint(4, "%s OUT: %s %s:%d, STATUS: %d\n", del_indent(), __FUNCTION__, __FILE__, __LINE__, status) +#define print_exit_pointer(status) \ +do { \ + if (IS_ERR(status)) \ + fist_dprint(4, "%s OUT: %s %s:%d, RESULT: %ld\n", del_indent(), __FUNCTION__, __FILE__, __LINE__, PTR_ERR(status)); \ + else \ + fist_dprint(4, "%s OUT: %s %s:%d, RESULT: 0x%x\n", del_indent(), __FUNCTION__, __FILE__, __LINE__, PTR_ERR(status)); \ +} while (0) +#endif/* mini_fo doesn't need these */ + +#endif /* __KERNEL__ */ + + +/* + * DEFINITIONS FOR USER AND KERNEL CODE: + * (Note: ioctl numbers 1--9 are reserved for fistgen, the rest + * are auto-generated automatically based on the user's .fist file.) + */ +# define FIST_IOCTL_GET_DEBUG_VALUE _IOR(0x15, 1, int) +# define FIST_IOCTL_SET_DEBUG_VALUE _IOW(0x15, 2, int) + +#endif /* not __FIST_H_ */ diff -urN linux-2.6.19.old/fs/mini_fo/inode.c linux-2.6.19.dev/fs/mini_fo/inode.c --- linux-2.6.19.old/fs/mini_fo/inode.c 1970-01-01 01:00:00.000000000 +0100 +++ linux-2.6.19.dev/fs/mini_fo/inode.c 2006-12-14 03:14:03.000000000 +0100 @@ -0,0 +1,1573 @@ +/* + * Copyright (c) 1997-2003 Erez Zadok + * Copyright (c) 2001-2003 Stony Brook University + * + * For specific licensing information, see the COPYING file distributed with + * this package, or get one from ftp://ftp.filesystems.org/pub/fist/COPYING. + * + * This Copyright notice must be kept intact and distributed with all + * fistgen sources INCLUDING sources generated by fistgen. + */ +/* + * Copyright (C) 2004, 2005 Markus Klotzbuecher + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version + * 2 of the License, or (at your option) any later version. + */ + +/* + * $Id$ + */ + +#ifdef HAVE_CONFIG_H +# include +#endif + +#include "fist.h" +#include "mini_fo.h" + +STATIC int +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0) +mini_fo_create(inode_t *dir, dentry_t *dentry, int mode, struct nameidata *nd) +#else +mini_fo_create(inode_t *dir, dentry_t *dentry, int mode) +#endif +{ + int err = 0; + + check_mini_fo_dentry(dentry); + +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0) + err = create_sto_reg_file(dentry, mode, nd); +#else + err = create_sto_reg_file(dentry, mode); +#endif + check_mini_fo_dentry(dentry); + return err; +} + + +STATIC dentry_t * +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0) +mini_fo_lookup(inode_t *dir, dentry_t *dentry, struct nameidata* nd) +#else +mini_fo_lookup(inode_t *dir, dentry_t *dentry) +#endif +{ + int err = 0; + dentry_t *hidden_dir_dentry; + dentry_t *hidden_dentry = NULL; + + dentry_t *hidden_sto_dir_dentry; + dentry_t *hidden_sto_dentry = NULL; + + /* whiteout flag */ + int del_flag = 0; + char *bpath = NULL; + + const char *name; + unsigned int namelen; + + /* Don't allow lookups of META-files */ + namelen = strlen(META_FILENAME); + if(namelen == dentry->d_name.len) { + if(!strncmp(dentry->d_name.name, META_FILENAME, namelen)) { + err = -ENOENT; + goto out; + } + } + + hidden_dir_dentry = dtohd(dentry->d_parent); + hidden_sto_dir_dentry = dtohd2(dentry->d_parent); + + name = dentry->d_name.name; + namelen = dentry->d_name.len; + + /* must initialize dentry operations */ + dentry->d_op = &mini_fo_dops; + + /* setup the del_flag */ + del_flag = __meta_check_d_entry(dir, name, namelen); + bpath = __meta_check_r_entry(dir, name, namelen); + + /* perform the lookups of base and storage files: + * + * This caused some serious trouble, as a lookup_one_len passing + * a negative dentry oopses. Solution is to only do the lookup + * if the dentry is positive, else we set it to NULL + * More trouble, who said a *_dir_dentry can't be NULL? + */ + if(bpath) { + /* Cross-Interposing (C), yeah! */ + hidden_dentry = bpath_walk(dir->i_sb, bpath); + if(!hidden_dentry || !hidden_dentry->d_inode) { + printk(KERN_CRIT "mini_fo_lookup: bpath_walk failed.\n"); + err= -EINVAL; + goto out; + } + + /* this can be set up safely without fear of spaghetti + * interposing as it is only used for copying times */ + hidden_dir_dentry = hidden_dentry->d_parent; + kfree(bpath); + } + else if(hidden_dir_dentry && hidden_dir_dentry->d_inode) + hidden_dentry = + lookup_one_len(name, hidden_dir_dentry, namelen); + else + hidden_dentry = NULL; + + if(hidden_sto_dir_dentry && hidden_sto_dir_dentry->d_inode) + hidden_sto_dentry = + lookup_one_len(name, hidden_sto_dir_dentry, namelen); + else + hidden_sto_dentry = NULL; + + /* catch error in lookup */ + if (IS_ERR(hidden_dentry) || IS_ERR(hidden_sto_dentry)) { + /* mk: we need to call dput on the dentry, whose + * lookup_one_len operation failed, in order to avoid + * unmount trouble. + */ + if(IS_ERR(hidden_dentry)) { + printk(KERN_CRIT "mini_fo_lookup: ERR from base dentry, lookup failed.\n"); + err = PTR_ERR(hidden_dentry); + } else { + dput(hidden_dentry); + } + if(IS_ERR(hidden_sto_dentry)) { + printk(KERN_CRIT "mini_fo_lookup: ERR from storage dentry, lookup failed.\n"); + err = PTR_ERR(hidden_sto_dentry); + } else { + dput(hidden_sto_dentry); + } + goto out; + } + + /* allocate dentry private data */ + __dtopd(dentry) = (struct mini_fo_dentry_info *) + kmalloc(sizeof(struct mini_fo_dentry_info), GFP_KERNEL); + + if (!dtopd(dentry)) { + err = -ENOMEM; + goto out_dput; + } + + /* check for different states of the mini_fo file to be looked up. */ + + /* state 1, file has been modified */ + if(hidden_dentry && hidden_sto_dentry && + hidden_dentry->d_inode && hidden_sto_dentry->d_inode && !del_flag) { + + /* update parent directory's atime */ + fist_copy_attr_atime(dir, hidden_sto_dir_dentry->d_inode); + + dtopd(dentry)->state = MODIFIED; + dtohd(dentry) = hidden_dentry; + dtohd2(dentry) = hidden_sto_dentry; + + err = mini_fo_tri_interpose(hidden_dentry, + hidden_sto_dentry, + dentry, dir->i_sb, 1); + if (err) { + printk(KERN_CRIT "mini_fo_lookup: error interposing (state1).\n"); + goto out_free; + } + goto out; + } + /* state 2, file is unmodified */ + if(hidden_dentry && hidden_dentry->d_inode && !del_flag) { + + fist_copy_attr_atime(dir, hidden_dir_dentry->d_inode); + + dtopd(dentry)->state = UNMODIFIED; + dtohd(dentry) = hidden_dentry; + dtohd2(dentry) = hidden_sto_dentry; /* could be negative */ + + err = mini_fo_tri_interpose(hidden_dentry