1 diff -urN linux.old/fs/Kconfig linux.dev/fs/Kconfig
2 --- linux.old/fs/Kconfig 2006-11-17 03:10:00.000000000 +0100
3 +++ linux.dev/fs/Kconfig 2006-11-17 03:12:36.000000000 +0100
6 - readpages / writepages (not user visible)
9 + tristate "Mini fanout overlay filesystem"
12 tristate "Minix fs support"
14 diff -urN linux.old/fs/Makefile linux.dev/fs/Makefile
15 --- linux.old/fs/Makefile 2006-11-17 03:10:00.000000000 +0100
16 +++ linux.dev/fs/Makefile 2006-11-17 03:13:05.000000000 +0100
18 obj-$(CONFIG_RAMFS) += ramfs/
19 obj-$(CONFIG_HUGETLBFS) += hugetlbfs/
20 obj-$(CONFIG_CODA_FS) += coda/
21 +obj-$(CONFIG_MINI_FO) += mini_fo/
22 obj-$(CONFIG_MINIX_FS) += minix/
23 obj-$(CONFIG_FAT_FS) += fat/
24 obj-$(CONFIG_MSDOS_FS) += msdos/
25 diff -urN linux.old/fs/mini_fo/aux.c linux.dev/fs/mini_fo/aux.c
26 --- linux.old/fs/mini_fo/aux.c 1970-01-01 01:00:00.000000000 +0100
27 +++ linux.dev/fs/mini_fo/aux.c 2006-11-17 03:11:48.000000000 +0100
30 + * Copyright (c) 1997-2003 Erez Zadok
31 + * Copyright (c) 2001-2003 Stony Brook University
33 + * For specific licensing information, see the COPYING file distributed with
34 + * this package, or get one from ftp://ftp.filesystems.org/pub/fist/COPYING.
36 + * This Copyright notice must be kept intact and distributed with all
37 + * fistgen sources INCLUDING sources generated by fistgen.
40 + * Copyright (C) 2004, 2005 Markus Klotzbuecher <mk@creamnet.de>
42 + * This program is free software; you can redistribute it and/or
43 + * modify it under the terms of the GNU General Public License
44 + * as published by the Free Software Foundation; either version
45 + * 2 of the License, or (at your option) any later version.
58 +/* check if file exists in storage */
59 +int exists_in_storage(dentry_t *dentry)
61 + check_mini_fo_dentry(dentry);
62 + if(dtost(dentry) == MODIFIED || dtost(dentry) == CREATED || dtost(dentry) == DEL_REWRITTEN)
67 +/* check if dentry is in an existing state */
68 +int is_mini_fo_existant(dentry_t *dentry)
70 + check_mini_fo_dentry(dentry);
72 + if(dtost(dentry) == DELETED || dtost(dentry) == NON_EXISTANT)
79 + * This function will create a negative storage dentry for
80 + * dentry, what is required for many create like options.
81 + * It will create the storage structure if necessary.
83 +int get_neg_sto_dentry(dentry_t *dentry)
87 + const unsigned char *name;
91 + !(dtost(dentry) == UNMODIFIED ||
92 + dtost(dentry) == NON_EXISTANT ||
93 + dtost(dentry) == DELETED)) {
94 + printk(KERN_CRIT "mini_fo: get_neg_sto_dentry: invalid dentry passed.\n");
98 + /* Have we got a neg. dentry already? */
99 + if(dtohd2(dentry)) {
103 + if(dtost(dentry->d_parent) == UNMODIFIED) {
104 + /* build sto struct */
105 + err = build_sto_structure(dentry->d_parent->d_parent, dentry->d_parent);
107 + dtost(dentry->d_parent) != MODIFIED) {
108 + printk(KERN_CRIT "mini_fo: get_neg_sto_dentry: ERROR building sto structure.\n");
114 + len = dentry->d_name.len;
115 + name = dentry->d_name.name;
118 + lookup_one_len(name, dtohd2(dentry->d_parent), len);
124 +int check_mini_fo_dentry(dentry_t *dentry)
126 + ASSERT(dentry != NULL);
127 + ASSERT(dtopd(dentry) != NULL);
128 + ASSERT((dtohd(dentry) != NULL) || (dtohd2(dentry) != NULL));
130 +/* if(dtost(dentry) == MODIFIED) { */
131 +/* ASSERT(dentry->d_inode != NULL); */
132 +/* ASSERT(dtohd(dentry) != NULL); */
133 +/* ASSERT(dtohd(dentry)->d_inode != NULL); */
134 +/* ASSERT(dtohd2(dentry) != NULL); */
135 +/* ASSERT(dtohd2(dentry)->d_inode != NULL); */
137 +/* else if(dtost(dentry) == UNMODIFIED) { */
138 +/* ASSERT(dentry->d_inode != NULL); */
144 +int check_mini_fo_file(file_t *file)
146 + ASSERT(file != NULL);
147 + ASSERT(ftopd(file) != NULL);
148 + ASSERT(file->f_dentry != NULL);
150 + /* violent checking, check depending of state and type
151 + * if(S_ISDIR(file->f_dentry->d_inode->i_mode)) {}
153 + ASSERT((ftohf(file) != NULL) || (ftohf2(file) != NULL));
157 +int check_mini_fo_inode(inode_t *inode)
159 + ASSERT(inode != NULL);
160 + ASSERT(itopd(inode) != NULL);
161 + ASSERT((itohi(inode) != NULL) || (itohi2(inode) != NULL));
166 + * will walk a base path as provided by get_mini_fo_bpath and return
167 + * the (hopefully ;-) ) positive dentry of the renamed base dir.
169 + * This does some work of path_init.
171 +dentry_t *bpath_walk(super_block_t *sb, char *bpath)
174 + struct nameidata nd;
177 + if(!bpath || bpath[0] != '/') {
178 + printk(KERN_CRIT "mini_fo: bpath_walk: Invalid string.\n");
181 + if(!sb || !stopd(sb)) {
182 + printk(KERN_CRIT "mini_fo: bpath_walk: Invalid sb.\n");
186 + /* setup nd as path_init does */
187 + nd.last_type = LAST_ROOT; /* if there are only slashes... */
188 + nd.flags = LOOKUP_FOLLOW;
189 + /* fix this: how do I reach this lock?
190 + * read_lock(¤t->fs->lock); */
191 + nd.mnt = mntget(stopd(sb)->hidden_mnt);
192 + nd.dentry = dget(stopd(sb)->base_dir_dentry);
193 + /* read_unlock(¤t->fs->lock); */
195 + err = path_walk(bpath+1, &nd);
198 + if (err || !nd.dentry || !nd.dentry->d_inode) {
199 + printk(KERN_CRIT "mini_fo: bpath_walk: path_walk failed.\n");
206 +/* returns the full path of the basefile incl. its name */
207 +int get_mini_fo_bpath(dentry_t *dentry, char **bpath, int *bpath_len)
211 + dentry_t *sky_walker;
213 + if(!dentry || !dtohd(dentry)) {
214 + printk(KERN_CRIT "mini_fo: get_mini_fo_bpath: invalid dentry passed.\n");
217 + sky_walker = dtohd(dentry);
220 + len += sky_walker->d_name.len + 1 ; /* 1 for '/' */
221 + sky_walker = sky_walker->d_parent;
222 + } while(sky_walker != stopd(dentry->d_inode->i_sb)->base_dir_dentry);
224 + /* 1 to oil the loop */
225 + *bpath = (char*) kmalloc(len + 1, GFP_KERNEL);
227 + printk(KERN_CRIT "mini_fo: get_mini_fo_bpath: out of mem.\n");
230 + buf_walker = *bpath+len; /* put it on last char */
231 + *buf_walker = '\n';
232 + sky_walker = dtohd(dentry);
235 + buf_walker -= sky_walker->d_name.len;
236 + strncpy(buf_walker,
237 + sky_walker->d_name.name,
238 + sky_walker->d_name.len);
239 + *(--buf_walker) = '/';
240 + sky_walker = sky_walker->d_parent;
241 + } while(sky_walker != stopd(dentry->d_inode->i_sb)->base_dir_dentry);
243 + /* bpath_len doesn't count newline! */
248 +int mini_fo_cp_cont(dentry_t *tgt_dentry, struct vfsmount *tgt_mnt,
249 + dentry_t *src_dentry, struct vfsmount *src_mnt)
252 + mm_segment_t old_fs;
255 + int bytes, len, tmp, err;
258 + if(!(tgt_dentry->d_inode && src_dentry->d_inode)) {
259 + printk(KERN_CRIT "mini_fo_cp_cont: ERROR, neg. dentry passed.\n");
269 + /* open file write only */
270 + tgt_file = dentry_open(tgt_dentry, tgt_mnt, 0x1);
271 + if(!tgt_file || IS_ERR(tgt_file)) {
272 + printk(KERN_CRIT "mini_fo_cp_cont: ERROR opening target file.\n");
273 + err = PTR_ERR(tgt_file);
277 + /* open file read only */
278 + src_file = dentry_open(src_dentry, src_mnt, 0x0);
279 + if(!src_file || IS_ERR(src_file)) {
280 + printk(KERN_CRIT "mini_fo_cp_cont: ERROR opening source file.\n");
281 + err = PTR_ERR(src_file);
283 + /* close target file */
288 + /* check if the filesystem(s) support read respective write */
289 + if(!src_file->f_op->read || !tgt_file->f_op->write) {
290 + printk(KERN_CRIT "mini_fo_cp_cont: ERROR, no fs read or write support.\n");
295 + /* allocate a page for transfering the data */
296 + buf = (void *) __get_free_page(GFP_KERNEL);
298 + printk(KERN_CRIT "mini_fo_cp_cont: ERROR, out of kernel mem.\n");
302 + tgt_file->f_pos = 0;
303 + src_file->f_pos = 0;
308 + /* Doing this I assume that a read operation will return a full
309 + * buffer while there is still data to read, and a less than
310 + * full buffer when all data has been read.
312 + bytes = len = PAGE_SIZE;
313 + while(bytes == len) {
314 + bytes = src_file->f_op->read(src_file, buf, len,
316 + tmp = tgt_file->f_op->write(tgt_file, buf, bytes,
319 + printk(KERN_CRIT "mini_fo_cp_cont: ERROR writing.\n");
320 + goto out_close_unset;
324 + free_page((unsigned long) buf);
331 + free_page((unsigned long) buf);
342 + /* mk: not sure if this need to be done */
351 + * ndl (no-duplicate list) stuff
352 + * This is used in mini_fo_readdir, to save the storage directory contents
353 + * and later when reading base, match them against the list in order
354 + * to avoid duplicates.
357 +/* add a file specified by name and len to the ndl
358 + * Return values: 0 on success, <0 on failure.
360 +int ndl_add_entry(struct readdir_data *rd, const char *name, int len)
362 + struct ndl_entry *tmp_entry;
364 + tmp_entry = (struct ndl_entry *)
365 + kmalloc(sizeof(struct ndl_entry), GFP_KERNEL);
367 + printk(KERN_CRIT "mini_fo: ndl_add_entry: out of mem.\n");
370 + tmp_entry->name = (char*) kmalloc(len, GFP_KERNEL);
371 + if(!tmp_entry->name) {
372 + printk(KERN_CRIT "mini_fo: ndl_add_entry: out of mem.\n");
375 + strncpy(tmp_entry->name, name, len);
376 + tmp_entry->len = len;
378 + list_add(&tmp_entry->list, &rd->ndl_list);
383 +/* delete all list entries and free memory */
384 +void ndl_put_list(struct readdir_data *rd)
386 + struct list_head *tmp;
387 + struct ndl_entry *tmp_entry;
389 + if(rd->ndl_size <= 0)
391 + while(!list_empty(&rd->ndl_list)) {
392 + tmp = rd->ndl_list.next;
394 + tmp_entry = list_entry(tmp, struct ndl_entry, list);
395 + kfree(tmp_entry->name);
401 +/* Check if a file specified by name and len is in the ndl
402 + * Return value: 0 if not in list, 1 if file is found in ndl.
404 +int ndl_check_entry(struct readdir_data *rd, const char *name, int len)
406 + struct list_head *tmp;
407 + struct ndl_entry *tmp_entry;
409 + if(rd->ndl_size <= 0)
412 + list_for_each(tmp, &rd->ndl_list) {
413 + tmp_entry = list_entry(tmp, struct ndl_entry, list);
414 + if(tmp_entry->len != len)
416 + if(!strncmp(tmp_entry->name, name, len))
423 + * Recursive function to create corresponding directorys in the storage fs.
424 + * The function will build the storage directorys up to dentry.
426 +int build_sto_structure(dentry_t *dir, dentry_t *dentry)
429 + dentry_t *hidden_sto_dentry;
430 + dentry_t *hidden_sto_dir_dentry;
432 + if(dentry->d_parent != dir) {
433 + printk(KERN_CRIT "mini_fo: build_sto_structure: invalid parameter or meta data corruption [1].\n");
437 + if(dtost(dir) != MODIFIED) {
438 + err = build_sto_structure(dir->d_parent, dentry->d_parent);
443 + /* ok, coming back again. */
444 + check_mini_fo_dentry(dentry);
445 + hidden_sto_dentry = dtohd2(dentry);
447 + if(!hidden_sto_dentry) {
449 + * This is the case after creating the first
450 + * hidden_sto_dentry.
451 + * After one negative storage_dentry, all pointers to
452 + * hidden_storage dentries are set to NULL. We need to
453 + * create the negative dentry before we create the storage
457 + const unsigned char *name;
458 + len = dtohd(dentry)->d_name.len;
459 + name = dtohd(dentry)->d_name.name;
460 + hidden_sto_dentry = lookup_one_len(name, dtohd2(dir), len);
461 + dtohd2(dentry) = hidden_sto_dentry;
464 + /* was: hidden_sto_dir_dentry = lock_parent(hidden_sto_dentry); */
465 + hidden_sto_dir_dentry = dget(hidden_sto_dentry->d_parent);
466 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
467 + mutex_lock(&hidden_sto_dir_dentry->d_inode->i_mutex);
469 + down(&hidden_sto_dir_dentry->d_inode->i_sem);
472 + if(dtohd2(dir) != hidden_sto_dir_dentry) {
473 + printk(KERN_CRIT "mini_fo: build_sto_structure: invalid parameter or meta data corruption [2].\n");
477 + /* check for errors in lock_parent */
478 + err = PTR_ERR(hidden_sto_dir_dentry);
479 + if(IS_ERR(hidden_sto_dir_dentry)) {
480 + printk(KERN_CRIT "mini_fo: build_sto_structure: lock_parent failed.\n");
484 + err = vfs_mkdir(hidden_sto_dir_dentry->d_inode,
486 + dir->d_inode->i_mode);
489 + printk(KERN_CRIT "mini_fo: build_sto_structure: failed to create storage dir [1].\n");
490 + /* was: unlock_dir(dir); */
491 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
492 + mutex_unlock(&dir->d_inode->i_mutex);
494 + up(&dir->d_inode->i_sem);
500 + /* everything ok! */
501 + if(!dtohd2(dentry)->d_inode) {
502 + printk(KERN_CRIT "mini_fo: build_sto_structure: failed to create storage dir [2].\n");
503 + /* was: unlock_dir(dir); */
504 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
505 + mutex_unlock(&dir->d_inode->i_mutex);
507 + up(&dir->d_inode->i_sem);
513 + /* interpose the new inode and set new state */
514 + itohi2(dentry->d_inode) = igrab(dtohd2(dentry)->d_inode);
515 + dtopd(dentry)->state = MODIFIED;
517 + /* initalize the wol list */
518 + itopd(dentry->d_inode)->deleted_list_size = -1;
519 + itopd(dentry->d_inode)->renamed_list_size = -1;
520 + meta_build_lists(dentry);
522 + fist_copy_attr_all(dentry->d_inode, itohi2(dentry->d_inode));
523 + fist_copy_attr_timesizes(dir->d_inode,
524 + hidden_sto_dir_dentry->d_inode);
525 + dir->d_inode->i_nlink++;
526 + /* was: unlock_dir(hidden_sto_dir_dentry); */
527 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
528 + mutex_unlock(&hidden_sto_dir_dentry->d_inode->i_mutex);
530 + up(&hidden_sto_dir_dentry->d_inode->i_sem);
532 + dput(hidden_sto_dir_dentry);
540 + * Read "len" bytes from "filename" into "buf".
541 + * "buf" is in kernel space.
544 +mini_fo_read_file(const char *filename, void *buf, int len)
547 + mm_segment_t oldfs;
549 + /* Chroot? Maybe NULL isn't right here */
550 + filp = filp_open(filename, O_RDONLY, 0);
551 + if (!filp || IS_ERR(filp)) {
552 + printk("mini_fo_read_file err %d\n", (int) PTR_ERR(filp));
553 + return -1; /* or do something else */
556 + if (!filp->f_op->read)
557 + return -2; /* file(system) doesn't allow reads */
559 + /* now read len bytes from offset 0 */
560 + filp->f_pos = 0; /* start offset */
563 + bytes = filp->f_op->read(filp, buf, len, &filp->f_pos);
566 + /* close the file */
575 + * Write "len" bytes from "buf" to "filename"
576 + * "buf" is in kernel space.
579 +mini_fo_write_file(const char *filename, void *buf, int len)
582 + mm_segment_t oldfs;
584 + /* Chroot? Maybe NULL isn't right here */
585 + filp = filp_open(filename, O_RDWR|O_CREAT, 0640);
586 + if (!filp || IS_ERR(filp)) {
587 + printk("mini_fo_write_file err %d\n", (int) PTR_ERR(filp));
588 + return -1; /* or do something else */
591 + if (!filp->f_op->write)
592 + return -2; /* file(system) doesn't allow writes */
594 + /* now write len bytes from offset 0 */
595 + filp->f_pos = 0; /* start offset */
598 + bytes = filp->f_op->write(filp, buf, len, &filp->f_pos);
601 + /* close the file */
609 diff -urN linux.old/fs/mini_fo/ChangeLog linux.dev/fs/mini_fo/ChangeLog
610 --- linux.old/fs/mini_fo/ChangeLog 1970-01-01 01:00:00.000000000 +0100
611 +++ linux.dev/fs/mini_fo/ChangeLog 2006-11-17 03:11:48.000000000 +0100
613 +2006-01-24 Markus Klotzbuecher <mk@mary.denx.de>
615 + * Add tons of ugly ifdefs to Ed L. Cashin's mutex patch to
616 + retain backwards compatibility.
618 +2006-01-24 Ed L. Cashin <ecashin@coraid.com>
620 + * Support for the new mutex infrastructure
621 + (7892f2f48d165a34b0b8130c8a195dfd807b8cb6)
623 +2005-10-15 Markus Klotzbuecher <mk@localhost.localdomain>
625 + * Bugfix for a serious memory leak in mini_fo_follow_link.
627 +2005-09-21 Markus Klotzbuecher <mk@mary>
629 + * new release 0.6.1
631 + * fix of a compiler warning due to changes in 2.6.13
633 +2005-09-21 Klaus Wenninger <klaus.wenninger@siemens.com>
635 + * file.c: readdir: fix for a bug that caused directory entries
636 + to show up twice when using storage filesystems such as
639 +2005-06-30 Eric Lammerts <eric@lammerts.org>
641 + * fix for an oops when overwriting a binary thats beeing
644 +2005-06-09 <mk@mary>
646 + * Renamed overlay to mini_fo-overlay.
648 + * Added mini_fo-merge script to allow merging of storage and base
649 + after making modifications.
651 +2005-05-22 root <mk@mary>
653 + * Added overlay script that allows to easily mount mini_fo ontop
654 + of a given base directory
656 +2005-05-10 <mk@mary>
658 + * inode.c: xattr functions return -EOPNOSUPP instead of
659 + -ENOSUPP, what confuses "ls -l"
661 + * Changed license from LGPL to GPL.
663 +2005-05-08 root <mk@mary>
665 + * Makefile: clean it up and added make install and make
668 +2005-05-06 <mk@mary>
670 + * merged devel branch back to main. [v0-6-0-pre3]
672 + * removed unused files print.c and fist_ioctl. [devel-0-0-18]
674 + * ioctl: removed fist_ioctl stuff, that is not needed for
677 +2005-05-03 <mk@mary>
679 + * file.c: simplified mini_fo_open and mini_fo_setattr using
680 + new state changing functions. [devel-0-0-17]
682 + * inode.c: Fixed getattr state bug (see below) in 2.4 function
683 + mini_fo_inode revalidate.
685 + * inode.c: found an other bug in mini_fo_getattr. States are not
686 + reliable in this function, as a file can be opened, unlinked and
687 + the getattr function called. This results in a deleted dentry
688 + with an inode. Fix is to ignore states and simply use the inode
691 +2005-04-29 <mk@mary>
693 + * file.c: Bugfix and cleanup in fasync and fsync. [devel-0-0-16]
695 + * file.c: do not use mini_fo_lock so the generic version is
698 + * inode.c: getattr, never call getattr on lower files, as this
699 + will cause the inum to change.
701 + * inode.c: rename_reg_file renamed to rename_nondir, as it
702 + doesn't matter as long it't not a dir. Removed all
703 + rename_dev_file etc.
705 + * tagged as devel-0-0-15
707 + * inode.c: added support for chosing support for extended
708 + attrs at compile time by XATTR define in mini_fo.h .
710 + * inode.c: fixed mini_fo_getattr to use mini_fo inode and not
711 + lower again, what avoids inode number changes that confused
712 + rm again. This is the proper solution.
714 +2005-04-24 <mk@mary>
716 + * all files: updated Copyright notive to 2005. [devel-0-0-14]
718 + * inode.c: fixed mini_fo_getattr to not change the inode
719 + number, even if lower files change.
721 + * super.c: fixed a bug that caused deleted base file to show
722 + up suddenly after some time, or after creating a special
723 + file. The problem was that after some time or after special
724 + file creating sync_sb_inodes is called by the vfs, that
725 + called our mini_fo_put_inode. There was (wrongly) called
726 + __meta_put_lists, that nuked the lists, although the inode
727 + was going to continue its life. Moving __meta_put_lists to
728 + mini_fo_clear_inode, where an inode is really destroyed,
729 + solved the problem.
732 +2005-04-23 <mk@mary>
734 + * state.c, aux.c: more cleaning up and
735 + simplifications. [devel-0-0-13]
737 + * inode.c: implemented mini_fo_getattr, that was required for
738 + 2.6 because inode_revalidate has been remove there, and the
739 + old "du" bug returned.
742 +2005-04-20 <mk@mary>
744 + * aux.c: get_neg_sto_dentry(): allow to be called for dentries
745 + in state UNMODIFIED, NON_EXISTANT _and_ DELETED.
747 +2005-04-19 <mk@mary>
749 + * Fixed a bug under 2.6 that caused files deleted via mini_fo
750 + not to be deleted properly and therefore the fs filled up
751 + untill no memory was left. [devel-0-0-12]
753 + * Added basic hard link support. This means that creating
754 + hardlinks will work, but existing ones will be treated as
755 + individual files. [devel-0-0-11]
757 +2005-04-17 <mk@mary>
761 +2005-04-13 root <mk@mary>
763 + * Added file state.c for the state transition
764 + functions. Doesn't work very well yet, though...
766 +2005-04-12 <mk@mary>
768 + * Porting to 2.6 started, which is easier than expected, also
769 + due to Olivier previous work.
771 +2005-04-08 <mk@mary>
773 + * Fixed the bug that caused du to return invalid sizes of
774 + directory trees. The problem was that
775 + mini_fo_inode_revalidate didn't always copy the attributes
776 + from the base inode properly.
778 +2005-04-01 Markus Klotzbuecher <mk@chasey>
780 + * Merged devel branch back to main trunk and updated the
781 + RELEASE notes. This will be 0-6-0-pre1.
783 +2005-03-31 Markus Klotzbuecher <mk@chasey>
785 + * Fixed some bugs in rename_reg_file, that only showed up in
786 + the kernel compile test. Kernel compiles cleanly ontop of
787 + mini_fo, now also make mrproper etc. work. Seems pretty stable.
789 +2005-03-28 Markus Klotzbuecher <mk@chasey>
791 + * Many, many directory renaming bugfixes and a lot of other
792 + cleanup. Dir renaming seems to work relatively stable.
794 +2005-03-22 Markus Klotzbuecher <mk@chasey>
796 + * Finished implementing lightweight directory renaming. Some
797 + basic testing indicates it works fine.
798 + Next is to implement testcases for the testsuite and confirm
799 + everything is really working ok.
801 +2005-03-18 Markus Klotzbuecher <mk@chasey>
803 + * Finished implementing meta.c stuff required for directory
806 +2005-03-17 Markus Klotzbuecher <mk@chasey>
808 + * Fixed all compile warnings + an extremly old bug that
809 + somehow crept in while reworking the wol stuff to the META
810 + system. Turning on -Werror again... :-)
812 + * Fixed some bugs in the new rename_reg_file function.
814 + * Rewrote mini_fo rename and split it into several
815 + subfunctions, that handle the different types
816 + seperately. Rewrote the regular file function aswell, as it
817 + was implemented somewhat inefficient.
819 +2005-03-16 Markus Klotzbuecher <mk@chasey>
821 + * Implemented new META subsystem, removed old WOL stuff in favor
824 + * After some basic testing everything seems ok...
826 +2005-03-11 Markus Klotzbuecher <mk@chasey>
828 + * Renaming a non regular file caused trouble because I always
829 + tried to copy the contents. Now I only do this for regular
830 + files. mini_fo_rename still isn't implemented properly, renaming
831 + of device files, symlinks etc. results in a empty regular file
832 + instead of the proper type.
834 + * Directory renaming suddenly works! What a surprise! I guess
835 + this is because renaming is implemented as making a copy and
836 + removing the original. Still this might not work
839 +2005-03-09 Markus Klotzbuecher <mk@chasey>
841 + * Bugfix, when a mini_fo directory that exists in storage
842 + (state: MODIFIED, CREATED and DEL_REWRITTEN) is deleted, a
843 + possibly existing WOL file contained in it needs to be
846 + * Starting cleanup: defined state names in order to get rid of
849 +2005-03-08 Markus Klotzbuecher <mk@chasey>
851 + * Makefile fix, fist_ioctl was built against wrong sources if ARCH=um
853 + * Fixed a bug in dentry.c, mini_fo_d_hash. In state 4 =
854 + DEL_REWRITTEN the hash was calculated from the base dentry,
855 + which was wrong and and caused assertions in
856 + __mini_fo_hidden_dentry to fail.
858 +2005-02-21 <mk@mary>
860 + * Implemented directory deleting (inode.c)
862 + * main.c: made mini_fo_parse_options a little more robust.
864 +2004-12-22 <mk@mary>
866 + * Makefile cleanup and uml stuff, removed unneccessary files
868 + * Created a new and hopefully more informative README
870 + * CHANGELOG: created a new CHANGELOG and added old entries reversely
873 +2004-10-24 Gleb Natapov <gleb@nbase.co.il>
875 + * Fix: owner and group where not correctly copied from base to
879 +2004-10-05 Gleb Natapov <gleb@nbase.co.il>
881 + * Implementation of fsync, fasync and lock mini_fo functions.
884 +2004-09-29 Bob Lee <bob@pantasys.com>
886 + * Fix of a serious pointer bug
889 +2004-09-28 Gleb Natapov <gleb@nbase.co.il>
891 + * Implementation of mini_fo_mknod and mini_fo_rename, support
894 diff -urN linux.old/fs/mini_fo/dentry.c linux.dev/fs/mini_fo/dentry.c
895 --- linux.old/fs/mini_fo/dentry.c 1970-01-01 01:00:00.000000000 +0100
896 +++ linux.dev/fs/mini_fo/dentry.c 2006-11-17 03:11:48.000000000 +0100
899 + * Copyright (c) 1997-2003 Erez Zadok
900 + * Copyright (c) 2001-2003 Stony Brook University
902 + * For specific licensing information, see the COPYING file distributed with
903 + * this package, or get one from ftp://ftp.filesystems.org/pub/fist/COPYING.
905 + * This Copyright notice must be kept intact and distributed with all
906 + * fistgen sources INCLUDING sources generated by fistgen.
909 + * Copyright (C) 2004, 2005 Markus Klotzbuecher <mk@creamnet.de>
911 + * This program is free software; you can redistribute it and/or
912 + * modify it under the terms of the GNU General Public License
913 + * as published by the Free Software Foundation; either version
914 + * 2 of the License, or (at your option) any later version.
921 +#ifdef HAVE_CONFIG_H
922 +# include <config.h>
926 +#include "mini_fo.h"
929 + * THIS IS A BOOLEAN FUNCTION: returns 1 if valid, 0 otherwise.
932 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
933 +mini_fo_d_revalidate(dentry_t *dentry, struct nameidata *nd)
935 +mini_fo_d_revalidate(dentry_t *dentry, int flags)
938 + int err1 = 1; /* valid = 1, invalid = 0 */
940 + dentry_t *hidden_dentry;
941 + dentry_t *hidden_sto_dentry;
944 + check_mini_fo_dentry(dentry);
946 + hidden_dentry = dtohd(dentry);
947 + hidden_sto_dentry = dtohd2(dentry);
949 + if(hidden_dentry &&
950 + hidden_dentry->d_op &&
951 + hidden_dentry->d_op->d_revalidate) {
952 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
953 + err1 = hidden_dentry->d_op->d_revalidate(hidden_dentry, nd);
955 + err1 = hidden_dentry->d_op->d_revalidate(hidden_dentry, flags);
958 + if(hidden_sto_dentry &&
959 + hidden_sto_dentry->d_op &&
960 + hidden_sto_dentry->d_op->d_revalidate) {
961 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
962 + err2 = hidden_sto_dentry->d_op->d_revalidate(hidden_sto_dentry,
965 + err2 = hidden_sto_dentry->d_op->d_revalidate(hidden_sto_dentry,
970 + /* mk: if one of the lower level dentries are valid,
971 + * the mini_fo dentry is too.
973 + return (err1 || err2);
978 +mini_fo_d_hash(dentry_t *dentry, qstr_t *name)
981 + dentry_t *hidden_dentry;
982 + dentry_t *hidden_sto_dentry;
984 + /* hidden_dentry = mini_fo_hidden_dentry(dentry);
985 + * hidden_sto_dentry = mini_fo_hidden_sto_dentry(dentry); */
987 + /* state 1, 3, 4, 5: build the hash for the storage dentry */
988 + if((dtopd(dentry)->state == MODIFIED) ||
989 + (dtopd(dentry)->state == CREATED) ||
990 + (dtopd(dentry)->state == DEL_REWRITTEN) ||
991 + (dtopd(dentry)->state == DELETED)) {
992 + hidden_sto_dentry = dtohd2(dentry);
993 + if(hidden_sto_dentry &&
994 + hidden_sto_dentry->d_op &&
995 + hidden_sto_dentry->d_op->d_hash) {
996 + err = hidden_sto_dentry->d_op->d_hash(hidden_sto_dentry, name);
1000 + /* state 2: build the hash for the base dentry */
1001 + if(dtopd(dentry)->state == UNMODIFIED) {
1002 + hidden_dentry = dtohd(dentry);
1003 + if(hidden_dentry &&
1004 + hidden_dentry->d_op &&
1005 + hidden_dentry->d_op->d_hash) {
1006 + err = hidden_dentry->d_op->d_hash(hidden_dentry, name);
1010 + /* state 6: build hash for the dentry that exists */
1011 + if(dtopd(dentry)->state == NON_EXISTANT) {
1012 + hidden_sto_dentry = dtohd2(dentry);
1013 + if(hidden_sto_dentry &&
1014 + hidden_sto_dentry->d_op &&
1015 + hidden_sto_dentry->d_op->d_hash) {
1016 + err = hidden_sto_dentry->d_op->d_hash(hidden_sto_dentry, name);
1019 + hidden_dentry = dtohd(dentry);
1020 + if(hidden_dentry &&
1021 + hidden_dentry->d_op &&
1022 + hidden_dentry->d_op->d_hash) {
1023 + err = hidden_dentry->d_op->d_hash(hidden_dentry, name);
1028 + printk(KERN_CRIT "mini_fo: d_hash: invalid state detected.\n");
1036 +mini_fo_d_compare(dentry_t *dentry, qstr_t *a, qstr_t *b)
1039 + dentry_t *hidden_dentry=NULL;
1041 + /* hidden_dentry = mini_fo_hidden_dentry(dentry); */
1042 + if(dtohd2(dentry))
1043 + hidden_dentry = dtohd2(dentry);
1044 + else if(dtohd(dentry))
1045 + hidden_dentry = dtohd(dentry);
1047 + if (hidden_dentry && hidden_dentry->d_op && hidden_dentry->d_op->d_compare) {
1048 + err = hidden_dentry->d_op->d_compare(hidden_dentry, a, b);
1050 + err = ((a->len != b->len) || memcmp(a->name, b->name, b->len));
1058 +mini_fo_d_delete(dentry_t *dentry)
1060 + dentry_t *hidden_dentry;
1061 + dentry_t *hidden_sto_dentry;
1064 + /* this could be a negative dentry, so check first */
1065 + if (!dtopd(dentry)) {
1066 + printk(KERN_CRIT "mini_fo_d_delete: negative dentry passed.\n");
1069 + hidden_dentry = dtohd(dentry);
1070 + hidden_sto_dentry = dtohd2(dentry);
1072 + if(hidden_dentry) {
1073 + if(hidden_dentry->d_op &&
1074 + hidden_dentry->d_op->d_delete) {
1075 + err = hidden_dentry->d_op->d_delete(hidden_dentry);
1078 + if(hidden_sto_dentry) {
1079 + if(hidden_sto_dentry->d_op &&
1080 + hidden_sto_dentry->d_op->d_delete) {
1081 + err = hidden_sto_dentry->d_op->d_delete(hidden_sto_dentry);
1091 +mini_fo_d_release(dentry_t *dentry)
1093 + dentry_t *hidden_dentry;
1094 + dentry_t *hidden_sto_dentry;
1097 + /* this could be a negative dentry, so check first */
1098 + if (!dtopd(dentry)) {
1099 + printk(KERN_CRIT "mini_fo_d_release: no private data.\n");
1102 + hidden_dentry = dtohd(dentry);
1103 + hidden_sto_dentry = dtohd2(dentry);
1105 + if(hidden_dentry) {
1106 + /* decrement hidden dentry's counter and free its inode */
1107 + dput(hidden_dentry);
1109 + if(hidden_sto_dentry) {
1110 + /* decrement hidden dentry's counter and free its inode */
1111 + dput(hidden_sto_dentry);
1114 + /* free private data (mini_fo_dentry_info) here */
1115 + kfree(dtopd(dentry));
1116 + __dtopd(dentry) = NULL; /* just to be safe */
1123 + * we don't really need mini_fo_d_iput, because dentry_iput will call iput() if
1124 + * mini_fo_d_iput is not defined. We left this implemented for ease of
1125 + * tracing/debugging.
1128 +mini_fo_d_iput(dentry_t *dentry, inode_t *inode)
1134 +struct dentry_operations mini_fo_dops = {
1135 + d_revalidate: mini_fo_d_revalidate,
1136 + d_hash: mini_fo_d_hash,
1137 + d_compare: mini_fo_d_compare,
1138 + d_release: mini_fo_d_release,
1139 + d_delete: mini_fo_d_delete,
1140 + d_iput: mini_fo_d_iput,
1142 diff -urN linux.old/fs/mini_fo/file.c linux.dev/fs/mini_fo/file.c
1143 --- linux.old/fs/mini_fo/file.c 1970-01-01 01:00:00.000000000 +0100
1144 +++ linux.dev/fs/mini_fo/file.c 2006-11-17 03:11:48.000000000 +0100
1147 + * Copyright (c) 1997-2003 Erez Zadok
1148 + * Copyright (c) 2001-2003 Stony Brook University
1150 + * For specific licensing information, see the COPYING file distributed with
1151 + * this package, or get one from ftp://ftp.filesystems.org/pub/fist/COPYING.
1153 + * This Copyright notice must be kept intact and distributed with all
1154 + * fistgen sources INCLUDING sources generated by fistgen.
1157 + * Copyright (C) 2004, 2005 Markus Klotzbuecher <mk@creamnet.de>
1159 + * This program is free software; you can redistribute it and/or
1160 + * modify it under the terms of the GNU General Public License
1161 + * as published by the Free Software Foundation; either version
1162 + * 2 of the License, or (at your option) any later version.
1169 +#ifdef HAVE_CONFIG_H
1170 +# include <config.h>
1174 +#include "mini_fo.h"
1175 +#define ROUND_UP(x) (((x)+sizeof(long)-1) & ~(sizeof(long)-1))
1177 +/*******************
1178 + * File Operations *
1179 + *******************/
1182 +mini_fo_llseek(file_t *file, loff_t offset, int origin)
1185 + file_t *hidden_file = NULL;
1187 + if(S_ISDIR(file->f_dentry->d_inode->i_mode)) {
1188 + /* Check if trying to llseek from a directory */
1192 + if (ftopd(file) != NULL) {
1193 + if(ftohf2(file)) {
1194 + hidden_file = ftohf2(file);
1196 + hidden_file = ftohf(file);
1200 + /* always set hidden position to this one */
1201 + hidden_file->f_pos = file->f_pos;
1203 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
1204 + memcpy(&(hidden_file->f_ra),
1206 + sizeof(struct file_ra_state));
1208 + if (file->f_reada) { /* update readahead information if needed */
1209 + hidden_file->f_reada = file->f_reada;
1210 + hidden_file->f_ramax = file->f_ramax;
1211 + hidden_file->f_raend = file->f_raend;
1212 + hidden_file->f_ralen = file->f_ralen;
1213 + hidden_file->f_rawin = file->f_rawin;
1216 + if (hidden_file->f_op && hidden_file->f_op->llseek)
1217 + err = hidden_file->f_op->llseek(hidden_file, offset, origin);
1219 + err = generic_file_llseek(hidden_file, offset, origin);
1224 + if (err != file->f_pos) {
1225 + file->f_pos = err;
1226 + // ION maybe this?
1227 + // file->f_pos = hidden_file->f_pos;
1228 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
1229 + file->f_reada = 0;
1231 + file->f_version++;
1239 +/* mk: fanout capable */
1241 +mini_fo_read(file_t *file, char *buf, size_t count, loff_t *ppos)
1243 + int err = -EINVAL;
1244 + file_t *hidden_file = NULL;
1245 + loff_t pos = *ppos;
1247 + if(S_ISDIR(file->f_dentry->d_inode->i_mode)) {
1248 + /* Check if trying to read from a directory */
1249 + /* printk(KERN_CRIT "mini_fo_read: ERROR: trying to read data from a directory.\n"); */
1254 + if (ftopd(file) != NULL) {
1255 + if(ftohf2(file)) {
1256 + hidden_file = ftohf2(file);
1258 + hidden_file = ftohf(file);
1262 + if (!hidden_file->f_op || !hidden_file->f_op->read)
1265 + err = hidden_file->f_op->read(hidden_file, buf, count, &pos);
1269 + /* atime should also be updated for reads of size zero or more */
1270 + fist_copy_attr_atime(file->f_dentry->d_inode,
1271 + hidden_file->f_dentry->d_inode);
1274 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
1277 + * because pread() does not have any way to tell us that it is
1278 + * our caller, then we don't know for sure if we have to update
1279 + * the file positions. This hack relies on read() having passed us
1280 + * the "real" pointer of its struct file's f_pos field.
1282 + if (ppos == &file->f_pos)
1283 + hidden_file->f_pos = *ppos = pos;
1284 + if (hidden_file->f_reada) { /* update readahead information if needed */
1285 + file->f_reada = hidden_file->f_reada;
1286 + file->f_ramax = hidden_file->f_ramax;
1287 + file->f_raend = hidden_file->f_raend;
1288 + file->f_ralen = hidden_file->f_ralen;
1289 + file->f_rawin = hidden_file->f_rawin;
1292 + memcpy(&(file->f_ra),&(hidden_file->f_ra),sizeof(struct file_ra_state));
1300 +/* this mini_fo_write() does not modify data pages! */
1302 +mini_fo_write(file_t *file, const char *buf, size_t count, loff_t *ppos)
1304 + int err = -EINVAL;
1305 + file_t *hidden_file = NULL;
1307 + inode_t *hidden_inode;
1308 + loff_t pos = *ppos;
1310 + /* mk: fan out: */
1311 + if (ftopd(file) != NULL) {
1312 + if(ftohf2(file)) {
1313 + hidden_file = ftohf2(file);
1315 + /* This is bad! We have no storage file to write to. This
1316 + * should never happen because if a file is opened for
1317 + * writing, a copy should have been made earlier.
1319 + printk(KERN_CRIT "mini_fo: write : ERROR, no storage file to write.\n");
1325 + inode = file->f_dentry->d_inode;
1326 + hidden_inode = itohi2(inode);
1327 + if(!hidden_inode) {
1328 + printk(KERN_CRIT "mini_fo: write: no sto inode found, not good.\n");
1332 + if (!hidden_file->f_op || !hidden_file->f_op->write)
1335 + /* adjust for append -- seek to the end of the file */
1336 + if (file->f_flags & O_APPEND)
1337 + pos = inode->i_size;
1339 + err = hidden_file->f_op->write(hidden_file, buf, count, &pos);
1342 + * copy ctime and mtime from lower layer attributes
1343 + * atime is unchanged for both layers
1346 + fist_copy_attr_times(inode, hidden_inode);
1349 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
1353 + * because pwrite() does not have any way to tell us that it is
1354 + * our caller, then we don't know for sure if we have to update
1355 + * the file positions. This hack relies on write() having passed us
1356 + * the "real" pointer of its struct file's f_pos field.
1358 + if (ppos == &file->f_pos)
1359 + hidden_file->f_pos = *ppos = pos;
1361 + /* update this inode's size */
1362 + if (pos > inode->i_size)
1363 + inode->i_size = pos;
1369 +/* Global variable to hold a file_t pointer.
1370 + * This serves to allow mini_fo_filldir function to know which file is
1371 + * beeing read, which is required for two reasons:
1373 + * - be able to call wol functions in order to avoid listing deleted
1375 + * - if we're reading a directory which is in state 1, we need to
1376 + * maintain a list (in mini_fo_filldir) of which files allready
1377 + * have been copied to userspace,to detect files existing in base
1378 + * and storage and not list them twice.
1380 +filldir_t mini_fo_filldir_orig;
1381 +file_t *mini_fo_filldir_file;
1383 +/* mainly copied from fs/readdir.c */
1385 +mini_fo_filldir(void * __buf, const char * name, int namlen, loff_t offset,
1386 + ino_t ino, unsigned int d_type)
1388 + struct linux_dirent *dirent, d;
1389 + struct getdents_callback * buf = (struct getdents_callback *) __buf;
1391 + file_t* file = mini_fo_filldir_file;
1393 + /* In theses states we filter meta files in storage (WOL) */
1394 + if(file && (dtopd(file->f_dentry)->state == MODIFIED ||
1395 + dtopd(file->f_dentry)->state == CREATED ||
1396 + dtopd(file->f_dentry)->state == DEL_REWRITTEN)) {
1398 + int tmp = strlen(META_FILENAME);
1399 + if(tmp == namlen) {
1400 + if(!strncmp(name, META_FILENAME, namlen))
1405 + /* check if we are merging the contents of storage and base */
1406 + if(file && dtopd(file->f_dentry)->state == MODIFIED) {
1407 + /* check if we are still reading storage contents, if
1408 + * yes, we just save the name of the file for duplicate
1409 + * checking later. */
1411 + if(!ftopd(file)->rd.sto_done) {
1412 + /* put file into ndl list */
1413 + if(ndl_add_entry(&ftopd(file)->rd, name, namlen))
1414 + printk(KERN_CRIT "mini_fo_filldir: Error adding to ndl.\n");
1416 + /* check if file has been deleted */
1417 + if(meta_check_d_entry(file->f_dentry, name, namlen))
1420 + /* do duplicate checking */
1421 + if(ndl_check_entry(&ftopd(file)->rd, name, namlen))
1426 + return mini_fo_filldir_orig(buf, name, namlen, offset, ino, d_type);
1431 +mini_fo_readdir(file_t *file, void *dirent, filldir_t filldir)
1433 + int err = 0;/* mk: ??? -ENOTDIR; */
1434 + file_t *hidden_file = NULL;
1435 + file_t *hidden_sto_file = NULL;
1437 + struct getdents_callback *buf;
1440 +#if defined(FIST_FILTER_NAME) || defined(FIST_FILTER_SCA)
1441 + struct mini_fo_getdents_callback buf;
1442 +#endif /* FIST_FILTER_NAME || FIST_FILTER_SCA */
1444 + buf = (struct getdents_callback *) dirent;
1445 + oldcount = buf->count;
1446 + inode = file->f_dentry->d_inode;
1447 + mini_fo_filldir_file = file;
1448 + mini_fo_filldir_orig = filldir;
1450 + ftopd(file)->rd.sto_done = 0;
1452 + if (ftopd(file) != NULL) {
1453 + if(ftohf2(file)) {
1454 + hidden_sto_file = ftohf2(file);
1455 + err = vfs_readdir(hidden_sto_file, mini_fo_filldir, dirent);
1456 + file->f_pos = hidden_sto_file->f_pos;
1458 + fist_copy_attr_atime(inode, hidden_sto_file->f_dentry->d_inode);
1459 + /* not finshed yet, we'll be called again */
1460 + if (buf->count != oldcount)
1464 + ftopd(file)->rd.sto_done = 1;
1467 + hidden_file = ftohf(file);
1468 + err = vfs_readdir(hidden_file, mini_fo_filldir, dirent);
1469 + file->f_pos = hidden_file->f_pos;
1471 + fist_copy_attr_atime(inode, hidden_file->f_dentry->d_inode);
1478 + * we need to check if all the directory data has been copied to userspace,
1479 + * or if we will be called again by userspace to complete the operation.
1481 + if(buf->count == oldcount) {
1482 + ndl_put_list(&ftopd(file)->rd);
1485 + /* unset this, safe */
1486 + mini_fo_filldir_file = NULL;
1491 +STATIC unsigned int
1492 +mini_fo_poll(file_t *file, poll_table *wait)
1494 + unsigned int mask = DEFAULT_POLLMASK;
1495 + file_t *hidden_file = NULL;
1497 + if (ftopd(file) != NULL) {
1498 + if(ftohf2(file)) {
1499 + hidden_file = ftohf2(file);
1501 + hidden_file = ftohf(file);
1505 + if (!hidden_file->f_op || !hidden_file->f_op->poll)
1508 + mask = hidden_file->f_op->poll(hidden_file, wait);
1514 +/* FIST-LITE special version of mmap */
1516 +mini_fo_mmap(file_t *file, vm_area_t *vma)
1519 + file_t *hidden_file = NULL;
1521 + /* fanout capability */
1522 + if (ftopd(file) != NULL) {
1523 + if(ftohf2(file)) {
1524 + hidden_file = ftohf2(file);
1526 + hidden_file = ftohf(file);
1530 + ASSERT(hidden_file != NULL);
1531 + ASSERT(hidden_file->f_op != NULL);
1532 + ASSERT(hidden_file->f_op->mmap != NULL);
1534 + vma->vm_file = hidden_file;
1535 + err = hidden_file->f_op->mmap(hidden_file, vma);
1536 + get_file(hidden_file); /* make sure it doesn't get freed on us */
1537 + fput(file); /* no need to keep extra ref on ours */
1545 +mini_fo_open(inode_t *inode, file_t *file)
1549 + file_t *hidden_file = NULL;
1550 + dentry_t *hidden_dentry = NULL;
1552 + /* fanout stuff */
1553 + file_t *hidden_sto_file = NULL;
1554 + dentry_t *hidden_sto_dentry = NULL;
1557 + kmalloc(sizeof(struct mini_fo_file_info), GFP_KERNEL);
1558 + if (!ftopd(file)) {
1563 + /* init the readdir_helper structure */
1564 + INIT_LIST_HEAD(&ftopd(file)->rd.ndl_list);
1565 + ftopd(file)->rd.ndl_size = 0;
1567 + /* In certain paths this could stay uninitalized and cause trouble */
1568 + ftohf(file) = NULL;
1569 + ftohf2(file) = NULL;
1570 + hidden_flags = file->f_flags;
1572 + /* create storage files? */
1573 + if(dtost(file->f_dentry) == UNMODIFIED) {
1574 + if(!IS_WRITE_FLAG(file->f_flags)) {
1575 + hidden_dentry = dtohd(file->f_dentry);
1576 + dget(hidden_dentry);
1577 + /* dentry_open will decrement mnt refcnt if err.
1578 + * otherwise fput() will do an mntput() for us upon file close. */
1579 + mntget(stopd(inode->i_sb)->hidden_mnt);
1580 + hidden_file = dentry_open(hidden_dentry,
1581 + stopd(inode->i_sb)->hidden_mnt,
1583 + if (IS_ERR(hidden_file)) {
1584 + err = PTR_ERR(hidden_file);
1585 + dput(hidden_dentry);
1588 + ftohf(file) = hidden_file; /* link two files */
1592 + if(S_ISDIR(file->f_dentry->d_inode->i_mode)) {
1593 + err = dir_unmod_to_mod(file->f_dentry);
1595 + err = nondir_unmod_to_mod(file->f_dentry, 1);
1598 + printk("mini_fo_open: ERROR creating storage file.\n");
1603 + hidden_sto_dentry = dtohd2(file->f_dentry);
1604 + dget(hidden_sto_dentry);
1606 + if(dtopd(file->f_dentry)->state == MODIFIED) {
1607 + /* Directorys are special, interpose on both lower level files */
1608 + if(S_ISDIR(itohi(inode)->i_mode)) {
1609 + /* check for invalid file types of lower level files */
1610 + if(!(S_ISDIR(itohi(inode)->i_mode) && S_ISDIR(itohi2(inode)->i_mode))) {
1611 + printk(KERN_CRIT "mini_fo_open: meta data corruption detected.\n");
1612 + dput(hidden_sto_dentry);
1617 + /* lower level directorys are ok, open the base file */
1618 + hidden_dentry = dtohd(file->f_dentry);
1619 + dget(hidden_dentry);
1621 + mntget(stopd(inode->i_sb)->hidden_mnt);
1622 + hidden_file = dentry_open(hidden_dentry,
1623 + stopd(inode->i_sb)->hidden_mnt,
1625 + if (IS_ERR(hidden_file)) {
1626 + err = PTR_ERR(hidden_file);
1627 + dput(hidden_dentry);
1628 + dput(hidden_sto_dentry);
1631 + ftohf(file) = hidden_file; /* link the two files */
1635 + if(!exists_in_storage(file->f_dentry)) {
1636 + printk(KERN_CRIT "mini_fo_open: invalid file state detected.\n");
1638 + dput(hidden_sto_dentry);
1640 + /* If the base file has been opened, we need to close it here */
1642 + if (hidden_file->f_op && hidden_file->f_op->flush)
1643 + hidden_file->f_op->flush(hidden_file);
1644 + dput(hidden_dentry);
1649 + /* ok, now we can safely open the storage file */
1650 + mntget(stopd(inode->i_sb)->hidden_mnt2);
1651 + hidden_sto_file = dentry_open(hidden_sto_dentry,
1652 + stopd(inode->i_sb)->hidden_mnt2,
1655 + /* dentry_open dputs the dentry if it fails */
1656 + if (IS_ERR(hidden_sto_file)) {
1657 + err = PTR_ERR(hidden_sto_file);
1658 + /* close base file if open */
1660 + if (hidden_file->f_op && hidden_file->f_op->flush)
1661 + hidden_file->f_op->flush(hidden_file);
1662 + dput(hidden_dentry);
1666 + ftohf2(file) = hidden_sto_file; /* link storage file */
1669 + if (err < 0 && ftopd(file)) {
1670 + kfree(ftopd(file));
1676 +mini_fo_flush(file_t *file)
1678 + int err1 = 0; /* assume ok (see open.c:close_fp) */
1680 + file_t *hidden_file = NULL;
1682 + check_mini_fo_file(file);
1684 + /* mk: we don't do any state checking here, as its not worth the time.
1685 + * Just flush the lower level files if they exist.
1687 + if(ftopd(file) != NULL) {
1688 + if(ftohf(file) != NULL) {
1689 + hidden_file = ftohf(file);
1690 + if (hidden_file->f_op && hidden_file->f_op->flush)
1691 + err1 = hidden_file->f_op->flush(hidden_file);
1693 + if(ftohf2(file) != NULL) {
1694 + hidden_file = ftohf2(file);
1695 + if (hidden_file->f_op && hidden_file->f_op->flush)
1696 + err2 = hidden_file->f_op->flush(hidden_file);
1699 + return (err1 | err2);
1704 +mini_fo_release(inode_t *inode, file_t *file)
1707 + file_t *hidden_file = NULL;
1709 + if (ftopd(file) != NULL) {
1711 + hidden_file = ftohf(file);
1712 + fput(hidden_file);
1714 + if(ftohf2(file)) {
1715 + hidden_file = ftohf2(file);
1716 + fput(hidden_file);
1718 + kfree(ftopd(file));
1724 +mini_fo_fsync(file_t *file, dentry_t *dentry, int datasync)
1728 + file_t *hidden_file = NULL;
1729 + dentry_t *hidden_dentry;
1731 + check_mini_fo_file(file);
1733 + if ((hidden_file = ftohf(file)) != NULL) {
1734 + hidden_dentry = dtohd(dentry);
1735 + if (hidden_file->f_op && hidden_file->f_op->fsync) {
1736 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
1737 + mutex_lock(&hidden_dentry->d_inode->i_mutex);
1739 + down(&hidden_dentry->d_inode->i_sem);
1741 + err1 = hidden_file->f_op->fsync(hidden_file, hidden_dentry, datasync);
1742 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
1743 + mutex_unlock(&hidden_dentry->d_inode->i_mutex);
1745 + up(&hidden_dentry->d_inode->i_sem);
1750 + if ((hidden_file = ftohf2(file)) != NULL) {
1751 + hidden_dentry = dtohd2(dentry);
1752 + if (hidden_file->f_op && hidden_file->f_op->fsync) {
1753 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
1754 + mutex_lock(&hidden_dentry->d_inode->i_mutex);
1756 + down(&hidden_dentry->d_inode->i_sem);
1758 + err2 = hidden_file->f_op->fsync(hidden_file, hidden_dentry, datasync);
1759 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
1760 + mutex_unlock(&hidden_dentry->d_inode->i_mutex);
1762 + up(&hidden_dentry->d_inode->i_sem);
1770 + return (err1 || err2);
1775 +mini_fo_fasync(int fd, file_t *file, int flag)
1780 + file_t *hidden_file = NULL;
1782 + check_mini_fo_file(file);
1784 + if((hidden_file = ftohf(file)) != NULL) {
1785 + err1 = hidden_file->f_op->fasync(fd, hidden_file, flag);
1787 + if((hidden_file = ftohf2(file)) != NULL) {
1788 + err2 = hidden_file->f_op->fasync(fd, hidden_file, flag);
1791 + return (err1 || err2);
1796 +struct file_operations mini_fo_dir_fops =
1798 + read: generic_read_dir,
1799 + write: mini_fo_write,
1800 + readdir: mini_fo_readdir,
1801 + poll: mini_fo_poll,
1802 + /* ioctl: mini_fo_ioctl, */
1803 + mmap: mini_fo_mmap,
1804 + open: mini_fo_open,
1805 + flush: mini_fo_flush,
1806 + release: mini_fo_release,
1807 + fsync: mini_fo_fsync,
1808 + fasync: mini_fo_fasync,
1809 + /* not needed lock: mini_fo_lock, */
1810 + /* not needed: readv */
1811 + /* not needed: writev */
1812 + /* not implemented: sendpage */
1813 + /* not implemented: get_unmapped_area */
1816 +struct file_operations mini_fo_main_fops =
1818 + llseek: mini_fo_llseek,
1819 + read: mini_fo_read,
1820 + write: mini_fo_write,
1821 + readdir: mini_fo_readdir,
1822 + poll: mini_fo_poll,
1823 + /* ioctl: mini_fo_ioctl, */
1824 + mmap: mini_fo_mmap,
1825 + open: mini_fo_open,
1826 + flush: mini_fo_flush,
1827 + release: mini_fo_release,
1828 + fsync: mini_fo_fsync,
1829 + fasync: mini_fo_fasync,
1830 + /* not needed: lock: mini_fo_lock, */
1831 + /* not needed: readv */
1832 + /* not needed: writev */
1833 + /* not implemented: sendpage */
1834 + /* not implemented: get_unmapped_area */
1836 diff -urN linux.old/fs/mini_fo/fist.h linux.dev/fs/mini_fo/fist.h
1837 --- linux.old/fs/mini_fo/fist.h 1970-01-01 01:00:00.000000000 +0100
1838 +++ linux.dev/fs/mini_fo/fist.h 2006-11-17 03:11:48.000000000 +0100
1841 + * Copyright (c) 1997-2003 Erez Zadok
1842 + * Copyright (c) 2001-2003 Stony Brook University
1844 + * For specific licensing information, see the COPYING file distributed with
1845 + * this package, or get one from ftp://ftp.filesystems.org/pub/fist/COPYING.
1847 + * This Copyright notice must be kept intact and distributed with all
1848 + * fistgen sources INCLUDING sources generated by fistgen.
1851 + * Copyright (C) 2004, 2005 Markus Klotzbuecher <mk@creamnet.de>
1853 + * This program is free software; you can redistribute it and/or
1854 + * modify it under the terms of the GNU General Public License
1855 + * as published by the Free Software Foundation; either version
1856 + * 2 of the License, or (at your option) any later version.
1868 + * KERNEL ONLY CODE:
1871 +#include <linux/config.h>
1872 +#include <linux/version.h>
1873 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
1874 +#ifdef CONFIG_MODVERSIONS
1875 +# define MODVERSIONS
1876 +# include <linux/modversions.h>
1877 +#endif /* CONFIG_MODVERSIONS */
1878 +#endif /* KERNEL_VERSION < 2.6.0 */
1879 +#include <linux/sched.h>
1880 +#include <linux/kernel.h>
1881 +#include <linux/mm.h>
1882 +#include <linux/string.h>
1883 +#include <linux/stat.h>
1884 +#include <linux/errno.h>
1885 +#include <linux/wait.h>
1886 +#include <linux/limits.h>
1887 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
1888 +#include <linux/locks.h>
1890 +#include <linux/buffer_head.h>
1891 +#include <linux/pagemap.h>
1892 +#include <linux/namei.h>
1893 +#include <linux/module.h>
1894 +#include <linux/mount.h>
1895 +#include <linux/page-flags.h>
1896 +#include <linux/writeback.h>
1897 +#include <linux/statfs.h>
1899 +#include <linux/smp.h>
1900 +#include <linux/smp_lock.h>
1901 +#include <linux/file.h>
1902 +#include <linux/slab.h>
1903 +#include <linux/vmalloc.h>
1904 +#include <linux/poll.h>
1905 +#include <linux/list.h>
1906 +#include <linux/init.h>
1908 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,20)
1909 +#include <linux/xattr.h>
1912 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
1913 +#include <linux/security.h>
1916 +#include <linux/swap.h>
1918 +#include <asm/system.h>
1919 +#include <asm/segment.h>
1920 +#include <asm/mman.h>
1921 +#include <linux/seq_file.h>
1927 +/* those mapped to ATTR_* were copied from linux/fs.h */
1928 +#define FA_MODE ATTR_MODE
1929 +#define FA_UID ATTR_UID
1930 +#define FA_GID ATTR_GID
1931 +#define FA_SIZE ATTR_SIZE
1932 +#define FA_ATIME ATTR_ATIME
1933 +#define FA_MTIME ATTR_MTIME
1934 +#define FA_CTIME ATTR_CTIME
1935 +#define FA_ATIME_SET ATTR_ATIME_SET
1936 +#define FA_MTIME_SET ATTR_MTIME_SET
1937 +#define FA_FORCE ATTR_FORCE
1938 +#define FA_ATTR_FLAGS ATTR_ATTR_FLAG
1940 +/* must be greater than all other ATTR_* flags! */
1941 +#define FA_NLINK 2048
1942 +#define FA_BLKSIZE 4096
1943 +#define FA_BLOCKS 8192
1944 +#define FA_TIMES (FA_ATIME|FA_MTIME|FA_CTIME)
1947 +/* macros to manage changes between kernels */
1948 +#define INODE_DATA(i) (&(i)->i_data)
1950 +#define MIN(x,y) ((x < y) ? (x) : (y))
1951 +#define MAX(x,y) ((x > y) ? (x) : (y))
1952 +#define MAXPATHLEN PATH_MAX
1954 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,4,5)
1955 +# define lookup_one_len(a,b,c) lookup_one(a,b)
1956 +#endif /* LINUX_VERSION_CODE < KERNEL_VERSION(2,4,5) */
1958 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,4,8)
1959 +# define generic_file_llseek default_llseek
1960 +#endif /* LINUX_VERSION_CODE < KERNEL_VERSION(2,4,8) */
1963 +# define SEEK_SET 0
1964 +#endif /* not SEEK_SET */
1967 +# define SEEK_CUR 1
1968 +#endif /* not SEEK_CUR */
1971 +# define SEEK_END 2
1972 +#endif /* not SEEK_END */
1974 +#ifndef DEFAULT_POLLMASK
1975 +# define DEFAULT_POLLMASK (POLLIN | POLLOUT | POLLRDNORM | POLLWRNORM)
1976 +#endif /* not DEFAULT_POLLMASK */
1978 +/* XXX: fix this so fistgen generates kfree() code directly */
1979 +#define kfree_s(a,b) kfree(a)
1984 +typedef struct dentry dentry_t;
1985 +typedef struct file file_t;
1986 +typedef struct inode inode_t;
1987 +typedef inode_t vnode_t;
1988 +typedef struct page page_t;
1989 +typedef struct qstr qstr_t;
1990 +typedef struct super_block super_block_t;
1991 +typedef super_block_t vfs_t;
1992 +typedef struct vm_area_struct vm_area_t;
1999 +#define FPPF(str,page) printk("PPF %s 0x%x/%d: Lck:%d Err:%d Ref:%d Upd:%d Other::%d:%d:%d:%d:\n", \
2002 + (int) page->index, \
2003 + (PageLocked(page) ? 1 : 0), \
2004 + (PageError(page) ? 1 : 0), \
2005 + (PageReferenced(page) ? 1 : 0), \
2006 + (Page_Uptodate(page) ? 1 : 0), \
2007 + (PageDecrAfter(page) ? 1 : 0), \
2008 + (PageSlab(page) ? 1 : 0), \
2009 + (PageSwapCache(page) ? 1 : 0), \
2010 + (PageReserved(page) ? 1 : 0) \
2012 +#define EZKDBG printk("EZK %s:%d:%s\n",__FILE__,__LINE__,__FUNCTION__)
2014 +# define EZKDBG1 printk("EZK %s:%d\n",__FILE__,__LINE__)
2019 +extern int fist_get_debug_value(void);
2020 +extern int fist_set_debug_value(int val);
2021 +#if 0 /* mini_fo doesn't need these */
2022 +extern void fist_dprint_internal(int level, char *str,...);
2023 +extern void fist_print_dentry(char *str, const dentry_t *dentry);
2024 +extern void fist_print_inode(char *str, const inode_t *inode);
2025 +extern void fist_print_file(char *str, const file_t *file);
2026 +extern void fist_print_buffer_flags(char *str, struct buffer_head *buffer);
2027 +extern void fist_print_page_flags(char *str, page_t *page);
2028 +extern void fist_print_page_bytes(char *str, page_t *page);
2029 +extern void fist_print_pte_flags(char *str, const page_t *page);
2030 +extern void fist_checkinode(inode_t *inode, char *msg);
2031 +extern void fist_print_sb(char *str, const super_block_t *sb);
2033 +/* §$% by mk: special debug functions */
2034 +extern void fist_mk_print_dentry(char *str, const dentry_t *dentry);
2035 +extern void fist_mk_print_inode(char *str, const inode_t *inode);
2037 +extern char *add_indent(void);
2038 +extern char *del_indent(void);
2039 +#endif/* mini_fo doesn't need these */
2043 +#define ASSERT(EX) \
2046 + printk(KERN_CRIT "ASSERTION FAILED: %s at %s:%d (%s)\n", #EX, \
2047 + __FILE__, __LINE__, __FUNCTION__); \
2048 + (*((char *)0))=0; \
2051 +/* same ASSERT, but tell me who was the caller of the function */
2052 +#define ASSERT2(EX) \
2055 + printk(KERN_CRIT "ASSERTION FAILED (caller): %s at %s:%d (%s)\n", #EX, \
2056 + file, line, func); \
2057 + (*((char *)0))=0; \
2061 +#if 0 /* mini_fo doesn't need these */
2062 +#define dprintk(format, args...) printk(KERN_DEBUG format, ##args)
2063 +#define fist_dprint(level, str, args...) fist_dprint_internal(level, KERN_DEBUG str, ## args)
2064 +#define print_entry_location() fist_dprint(4, "%sIN: %s %s:%d\n", add_indent(), __FUNCTION__, __FILE__, __LINE__)
2065 +#define print_exit_location() fist_dprint(4, "%s OUT: %s %s:%d\n", del_indent(), __FUNCTION__, __FILE__, __LINE__)
2066 +#define print_exit_status(status) fist_dprint(4, "%s OUT: %s %s:%d, STATUS: %d\n", del_indent(), __FUNCTION__, __FILE__, __LINE__, status)
2067 +#define print_exit_pointer(status) \
2069 + if (IS_ERR(status)) \
2070 + fist_dprint(4, "%s OUT: %s %s:%d, RESULT: %ld\n", del_indent(), __FUNCTION__, __FILE__, __LINE__, PTR_ERR(status)); \
2072 + fist_dprint(4, "%s OUT: %s %s:%d, RESULT: 0x%x\n", del_indent(), __FUNCTION__, __FILE__, __LINE__, PTR_ERR(status)); \
2074 +#endif/* mini_fo doesn't need these */
2076 +#endif /* __KERNEL__ */
2080 + * DEFINITIONS FOR USER AND KERNEL CODE:
2081 + * (Note: ioctl numbers 1--9 are reserved for fistgen, the rest
2082 + * are auto-generated automatically based on the user's .fist file.)
2084 +# define FIST_IOCTL_GET_DEBUG_VALUE _IOR(0x15, 1, int)
2085 +# define FIST_IOCTL_SET_DEBUG_VALUE _IOW(0x15, 2, int)
2087 +#endif /* not __FIST_H_ */
2088 diff -urN linux.old/fs/mini_fo/inode.c linux.dev/fs/mini_fo/inode.c
2089 --- linux.old/fs/mini_fo/inode.c 1970-01-01 01:00:00.000000000 +0100
2090 +++ linux.dev/fs/mini_fo/inode.c 2006-11-17 03:11:48.000000000 +0100
2093 + * Copyright (c) 1997-2003 Erez Zadok
2094 + * Copyright (c) 2001-2003 Stony Brook University
2096 + * For specific licensing information, see the COPYING file distributed with
2097 + * this package, or get one from ftp://ftp.filesystems.org/pub/fist/COPYING.
2099 + * This Copyright notice must be kept intact and distributed with all
2100 + * fistgen sources INCLUDING sources generated by fistgen.
2103 + * Copyright (C) 2004, 2005 Markus Klotzbuecher <mk@creamnet.de>
2105 + * This program is free software; you can redistribute it and/or
2106 + * modify it under the terms of the GNU General Public License
2107 + * as published by the Free Software Foundation; either version
2108 + * 2 of the License, or (at your option) any later version.
2115 +#ifdef HAVE_CONFIG_H
2116 +# include <config.h>
2120 +#include "mini_fo.h"
2123 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
2124 +mini_fo_create(inode_t *dir, dentry_t *dentry, int mode, struct nameidata *nd)
2126 +mini_fo_create(inode_t *dir, dentry_t *dentry, int mode)
2131 + check_mini_fo_dentry(dentry);
2133 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
2134 + err = create_sto_reg_file(dentry, mode, nd);
2136 + err = create_sto_reg_file(dentry, mode);
2138 + check_mini_fo_dentry(dentry);
2144 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
2145 +mini_fo_lookup(inode_t *dir, dentry_t *dentry, struct nameidata* nd)
2147 +mini_fo_lookup(inode_t *dir, dentry_t *dentry)
2151 + dentry_t *hidden_dir_dentry;
2152 + dentry_t *hidden_dentry = NULL;
2154 + dentry_t *hidden_sto_dir_dentry;
2155 + dentry_t *hidden_sto_dentry = NULL;
2157 + /* whiteout flag */
2159 + char *bpath = NULL;
2162 + unsigned int namelen;
2164 + /* Don't allow lookups of META-files */
2165 + namelen = strlen(META_FILENAME);
2166 + if(namelen == dentry->d_name.len) {
2167 + if(!strncmp(dentry->d_name.name, META_FILENAME, namelen)) {
2173 + hidden_dir_dentry = dtohd(dentry->d_parent);
2174 + hidden_sto_dir_dentry = dtohd2(dentry->d_parent);
2176 + name = dentry->d_name.name;
2177 + namelen = dentry->d_name.len;
2179 + /* must initialize dentry operations */
2180 + dentry->d_op = &mini_fo_dops;
2182 + /* setup the del_flag */
2183 + del_flag = __meta_check_d_entry(dir, name, namelen);
2184 + bpath = __meta_check_r_entry(dir, name, namelen);
2186 + /* perform the lookups of base and storage files:
2188 + * This caused some serious trouble, as a lookup_one_len passing
2189 + * a negative dentry oopses. Solution is to only do the lookup
2190 + * if the dentry is positive, else we set it to NULL
2191 + * More trouble, who said a *_dir_dentry can't be NULL?
2194 + /* Cross-Interposing (C), yeah! */
2195 + hidden_dentry = bpath_walk(dir->i_sb, bpath);
2196 + if(!hidden_dentry || !hidden_dentry->d_inode) {
2197 + printk(KERN_CRIT "mini_fo_lookup: bpath_walk failed.\n");
2202 + /* this can be set up safely without fear of spaghetti
2203 + * interposing as it is only used for copying times */
2204 + hidden_dir_dentry = hidden_dentry->d_parent;
2207 + else if(hidden_dir_dentry && hidden_dir_dentry->d_inode)
2209 + lookup_one_len(name, hidden_dir_dentry, namelen);
2211 + hidden_dentry = NULL;
2213 + if(hidden_sto_dir_dentry && hidden_sto_dir_dentry->d_inode)
2214 + hidden_sto_dentry =
2215 + lookup_one_len(name, hidden_sto_dir_dentry, namelen);
2217 + hidden_sto_dentry = NULL;
2219 + /* catch error in lookup */
2220 + if (IS_ERR(hidden_dentry) || IS_ERR(hidden_sto_dentry)) {
2221 + /* mk: we need to call dput on the dentry, whose
2222 + * lookup_one_len operation failed, in order to avoid
2223 + * unmount trouble.
2225 + if(IS_ERR(hidden_dentry)) {
2226 + printk(KERN_CRIT "mini_fo_lookup: ERR from base dentry, lookup failed.\n");
2227 + err = PTR_ERR(hidden_dentry);
2229 + dput(hidden_dentry);
2231 + if(IS_ERR(hidden_sto_dentry)) {
2232 + printk(KERN_CRIT "mini_fo_lookup: ERR from storage dentry, lookup failed.\n");
2233 + err = PTR_ERR(hidden_sto_dentry);
2235 + dput(hidden_sto_dentry);
2240 + /* allocate dentry private data */
2241 + __dtopd(dentry) = (struct mini_fo_dentry_info *)
2242 + kmalloc(sizeof(struct mini_fo_dentry_info), GFP_KERNEL);
2244 + if (!dtopd(dentry)) {
2249 + /* check for different states of the mini_fo file to be looked up. */
2251 + /* state 1, file has been modified */
2252 + if(hidden_dentry && hidden_sto_dentry &&
2253 + hidden_dentry->d_inode && hidden_sto_dentry->d_inode && !del_flag) {
2255 + /* update parent directory's atime */
2256 + fist_copy_attr_atime(dir, hidden_sto_dir_dentry->d_inode);
2258 + dtopd(dentry)->state = MODIFIED;
2259 + dtohd(dentry) = hidden_dentry;
2260 + dtohd2(dentry) = hidden_sto_dentry;
2262 + err = mini_fo_tri_interpose(hidden_dentry,
2263 + hidden_sto_dentry,
2264 + dentry, dir->i_sb, 1);
2266 + printk(KERN_CRIT "mini_fo_lookup: error interposing (state1).\n");
2271 + /* state 2, file is unmodified */
2272 + if(hidden_dentry && hidden_dentry->d_inode && !del_flag) {
2274 + fist_copy_attr_atime(dir, hidden_dir_dentry->d_inode);
2276 + dtopd(dentry)->state = UNMODIFIED;
2277 + dtohd(dentry) = hidden_dentry;
2278 + dtohd2(dentry) = hidden_sto_dentry; /* could be negative */
2280 + err = mini_fo_tri_interpose(hidden_dentry,
2281 + hidden_sto_dentry,
2282 + dentry, dir->i_sb, 1);
2284 + printk(KERN_CRIT "mini_fo_lookup: error interposing (state2).\n");
2289 + /* state 3, file has been newly created */
2290 + if(hidden_sto_dentry && hidden_sto_dentry->d_inode && !del_flag) {
2292 + fist_copy_attr_atime(dir, hidden_sto_dir_dentry->d_inode);
2293 + dtopd(dentry)->state = CREATED;
2294 + dtohd(dentry) = hidden_dentry; /* could be negative */
2295 + dtohd2(dentry) = hidden_sto_dentry;
2297 + err = mini_fo_tri_interpose(hidden_dentry,
2298 + hidden_sto_dentry,
2299 + dentry, dir->i_sb, 1);
2301 + printk(KERN_CRIT "mini_fo_lookup: error interposing (state3).\n");
2307 + /* state 4, file has deleted and created again. */
2308 + if(hidden_dentry && hidden_sto_dentry &&
2309 + hidden_dentry->d_inode &&
2310 + hidden_sto_dentry->d_inode && del_flag) {
2312 + fist_copy_attr_atime(dir, hidden_sto_dir_dentry->d_inode);
2313 + dtopd(dentry)->state = DEL_REWRITTEN;
2314 + dtohd(dentry) = NULL;
2315 + dtohd2(dentry) = hidden_sto_dentry;
2317 + err = mini_fo_tri_interpose(NULL,
2318 + hidden_sto_dentry,
2319 + dentry, dir->i_sb, 1);
2321 + printk(KERN_CRIT "mini_fo_lookup: error interposing (state4).\n");
2324 + /* We will never need this dentry again, as the file has been
2325 + * deleted from base */
2326 + dput(hidden_dentry);
2329 + /* state 5, file has been deleted in base */
2330 + if(hidden_dentry && hidden_sto_dentry &&
2331 + hidden_dentry->d_inode &&
2332 + !hidden_sto_dentry->d_inode && del_flag) {
2334 + /* check which parents atime we need for updating */
2335 + if(hidden_sto_dir_dentry->d_inode)
2336 + fist_copy_attr_atime(dir,
2337 + hidden_sto_dir_dentry->d_inode);
2339 + fist_copy_attr_atime(dir,
2340 + hidden_dir_dentry->d_inode);
2342 + dtopd(dentry)->state = DELETED;
2343 + dtohd(dentry) = NULL;
2344 + dtohd2(dentry) = hidden_sto_dentry;
2346 + /* add negative dentry to dcache to speed up lookups */
2347 + d_add(dentry, NULL);
2348 + dput(hidden_dentry);
2351 + /* state 6, file does not exist */
2352 + if(((hidden_dentry && !hidden_dentry->d_inode) ||
2353 + (hidden_sto_dentry && !hidden_sto_dentry->d_inode)) && !del_flag)
2355 + /* check which parents atime we need for updating */
2356 + if(hidden_sto_dir_dentry && hidden_sto_dir_dentry->d_inode)
2357 + fist_copy_attr_atime(dir, hidden_sto_dir_dentry->d_inode);
2359 + fist_copy_attr_atime(dir, hidden_dir_dentry->d_inode);
2361 + dtopd(dentry)->state = NON_EXISTANT;
2362 + dtohd(dentry) = hidden_dentry;
2363 + dtohd2(dentry) = hidden_sto_dentry;
2364 + d_add(dentry, NULL);
2368 + /* if we get to here, were in an invalid state. bad. */
2369 + printk(KERN_CRIT "mini_fo_lookup: ERROR, meta data corruption detected.\n");
2371 + /* end state checking */
2373 + d_drop(dentry); /* so that our bad dentry will get destroyed */
2374 + kfree(dtopd(dentry));
2375 + __dtopd(dentry) = NULL; /* be safe */
2379 + dput(hidden_dentry);
2380 + if(hidden_sto_dentry)
2381 + dput(hidden_sto_dentry); /* drops usage count and marks for release */
2384 + /* initalize wol if file exists and is directory */
2385 + if(dentry->d_inode) {
2386 + if(S_ISDIR(dentry->d_inode->i_mode)) {
2387 + itopd(dentry->d_inode)->deleted_list_size = -1;
2388 + itopd(dentry->d_inode)->renamed_list_size = -1;
2389 + meta_build_lists(dentry);
2392 + return ERR_PTR(err);
2397 +mini_fo_link(dentry_t *old_dentry, inode_t *dir, dentry_t *new_dentry)
2400 + dentry_t *hidden_old_dentry;
2401 + dentry_t *hidden_new_dentry;
2402 + dentry_t *hidden_dir_dentry;
2405 + check_mini_fo_dentry(old_dentry);
2406 + check_mini_fo_dentry(new_dentry);
2407 + check_mini_fo_inode(dir);
2409 + /* no links to directorys and existing targets target allowed */
2410 + if(S_ISDIR(old_dentry->d_inode->i_mode) ||
2411 + is_mini_fo_existant(new_dentry)) {
2416 + /* bring it directly from unmod to del_rew */
2417 + if(dtost(old_dentry) == UNMODIFIED) {
2418 + err = nondir_unmod_to_mod(old_dentry, 1);
2423 + err = meta_add_d_entry(old_dentry->d_parent,
2424 + old_dentry->d_name.name,
2425 + old_dentry->d_name.len);
2430 + dput(dtohd(old_dentry));
2431 + dtohd(old_dentry) = NULL;
2432 + dtost(old_dentry) = DEL_REWRITTEN;
2435 + err = get_neg_sto_dentry(new_dentry);
2441 + hidden_old_dentry = dtohd2(old_dentry);
2442 + hidden_new_dentry = dtohd2(new_dentry);
2444 + dget(hidden_old_dentry);
2445 + dget(hidden_new_dentry);
2447 + /* was: hidden_dir_dentry = lock_parent(hidden_new_dentry); */
2448 + hidden_dir_dentry = dget(hidden_new_dentry->d_parent);
2449 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
2450 + mutex_lock(&hidden_dir_dentry->d_inode->i_mutex);
2452 + down(&hidden_dir_dentry->d_inode->i_sem);
2455 + err = vfs_link(hidden_old_dentry,
2456 + hidden_dir_dentry->d_inode,
2457 + hidden_new_dentry);
2458 + if (err || !hidden_new_dentry->d_inode)
2461 + dtost(new_dentry) = CREATED;
2462 + err = mini_fo_tri_interpose(NULL, hidden_new_dentry, new_dentry, dir->i_sb, 0);
2466 + fist_copy_attr_timesizes(dir, hidden_new_dentry->d_inode);
2467 + /* propagate number of hard-links */
2468 + old_dentry->d_inode->i_nlink = itohi2(old_dentry->d_inode)->i_nlink;
2471 + /* was: unlock_dir(hidden_dir_dentry); */
2472 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
2473 + mutex_unlock(&hidden_dir_dentry->d_inode->i_mutex);
2475 + up(&hidden_dir_dentry->d_inode->i_sem);
2477 + dput(hidden_dir_dentry);
2479 + dput(hidden_new_dentry);
2480 + dput(hidden_old_dentry);
2481 + if (!new_dentry->d_inode)
2482 + d_drop(new_dentry);
2490 +mini_fo_unlink(inode_t *dir, dentry_t *dentry)
2495 + if(dtopd(dentry)->state == MODIFIED) {
2496 + err = nondir_mod_to_del(dentry);
2499 + else if(dtopd(dentry)->state == UNMODIFIED) {
2500 + err = nondir_unmod_to_del(dentry);
2503 + else if(dtopd(dentry)->state == CREATED) {
2504 + err = nondir_creat_to_del(dentry);
2507 + else if(dtopd(dentry)->state == DEL_REWRITTEN) {
2508 + err = nondir_del_rew_to_del(dentry);
2512 + printk(KERN_CRIT "mini_fo_unlink: ERROR, invalid state detected.\n");
2515 + fist_copy_attr_times(dir, itohi2(dentry->d_parent->d_inode));
2518 + /* is this causing my pain? d_delete(dentry); */
2528 +mini_fo_symlink(inode_t *dir, dentry_t *dentry, const char *symname)
2531 + dentry_t *hidden_sto_dentry;
2532 + dentry_t *hidden_sto_dir_dentry;
2533 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
2537 + /* Fail if the symlink file exists */
2538 + if(!(dtost(dentry) == DELETED ||
2539 + dtost(dentry) == NON_EXISTANT)) {
2544 + err = get_neg_sto_dentry(dentry);
2549 + hidden_sto_dentry = dtohd2(dentry);
2551 + dget(hidden_sto_dentry);
2552 + /* was: hidden_sto_dir_dentry = lock_parent(hidden_sto_dentry); */
2553 + hidden_sto_dir_dentry = dget(hidden_sto_dentry->d_parent);
2554 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
2555 + mutex_lock(&hidden_sto_dir_dentry->d_inode->i_mutex);
2557 + down(&hidden_sto_dir_dentry->d_inode->i_sem);
2560 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
2562 + err = vfs_symlink(hidden_sto_dir_dentry->d_inode,
2563 + hidden_sto_dentry, symname, mode);
2565 + err = vfs_symlink(hidden_sto_dir_dentry->d_inode,
2566 + hidden_sto_dentry,
2569 + if (err || !hidden_sto_dentry->d_inode)
2572 + if(dtost(dentry) == DELETED) {
2573 + dtost(dentry) = DEL_REWRITTEN;
2574 + err = mini_fo_tri_interpose(NULL, hidden_sto_dentry, dentry, dir->i_sb, 0);
2577 + } else if(dtost(dentry) == NON_EXISTANT) {
2578 + dtost(dentry) = CREATED;
2579 + err = mini_fo_tri_interpose(dtohd(dentry), hidden_sto_dentry, dentry, dir->i_sb, 0);
2583 + fist_copy_attr_timesizes(dir, hidden_sto_dir_dentry->d_inode);
2586 + /* was: unlock_dir(hidden_sto_dir_dentry); */
2587 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
2588 + mutex_unlock(&hidden_sto_dir_dentry->d_inode->i_mutex);
2590 + up(&hidden_sto_dir_dentry->d_inode->i_sem);
2592 + dput(hidden_sto_dir_dentry);
2594 + dput(hidden_sto_dentry);
2595 + if (!dentry->d_inode)
2602 +mini_fo_mkdir(inode_t *dir, dentry_t *dentry, int mode)
2606 + err = create_sto_dir(dentry, mode);
2608 + check_mini_fo_dentry(dentry);
2615 +mini_fo_rmdir(inode_t *dir, dentry_t *dentry)
2619 + dentry_t *hidden_sto_dentry;
2620 + dentry_t *hidden_sto_dir_dentry;
2621 + dentry_t *meta_dentry;
2622 + inode_t *hidden_sto_dir = NULL;
2624 + check_mini_fo_dentry(dentry);
2625 + check_mini_fo_inode(dir);
2628 + if(dtopd(dentry)->state == MODIFIED) {
2629 + /* XXX: disabled, because it does not bother to check files on
2630 + * the original filesystem - just a hack, but better than simply
2631 + * removing it without testing */
2635 + hidden_sto_dir = itohi2(dir);
2636 + hidden_sto_dentry = dtohd2(dentry);
2638 + /* was:hidden_sto_dir_dentry = lock_parent(hidden_sto_dentry); */
2639 + hidden_sto_dir_dentry = dget(hidden_sto_dentry->d_parent);
2640 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
2641 + mutex_lock(&hidden_sto_dir_dentry->d_inode->i_mutex);
2643 + down(&hidden_sto_dir_dentry->d_inode->i_sem);
2646 + /* avoid destroying the hidden inode if the file is in use */
2647 + dget(hidden_sto_dentry);
2649 + /* Delete an old WOL file contained in the storage dir */
2650 + meta_dentry = lookup_one_len(META_FILENAME,
2651 + hidden_sto_dentry,
2652 + strlen(META_FILENAME));
2653 + if(meta_dentry->d_inode) {
2654 + err = vfs_unlink(hidden_sto_dentry->d_inode, meta_dentry);
2655 + dput(meta_dentry);
2657 + d_delete(meta_dentry);
2660 + err = vfs_rmdir(hidden_sto_dir, hidden_sto_dentry);
2661 + dput(hidden_sto_dentry);
2663 + d_delete(hidden_sto_dentry);
2665 + /* propagate number of hard-links */
2666 + dentry->d_inode->i_nlink = itohi2(dentry->d_inode)->i_nlink;
2668 + dput(dtohd(dentry));
2670 + dtohd(dentry) = NULL;
2671 + dtopd(dentry)->state = DELETED;
2673 + /* carefull with R files */
2674 + if( __meta_is_r_entry(dir,
2675 + dentry->d_name.name,
2676 + dentry->d_name.len) == 1) {
2677 + err = meta_remove_r_entry(dentry->d_parent,
2678 + dentry->d_name.name,
2679 + dentry->d_name.len);
2681 + printk(KERN_CRIT "mini_fo: rmdir: meta_remove_r_entry failed.\n");
2686 + /* ok, add deleted file to META */
2687 + meta_add_d_entry(dentry->d_parent,
2688 + dentry->d_name.name,
2689 + dentry->d_name.len);
2691 + /* was: unlock_dir(hidden_sto_dir_dentry); */
2692 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
2693 + mutex_unlock(&hidden_sto_dir_dentry->d_inode->i_mutex);
2695 + up(&hidden_sto_dir_dentry->d_inode->i_sem);
2697 + dput(hidden_sto_dir_dentry);
2700 + else if(dtopd(dentry)->state == UNMODIFIED) {
2701 + /* XXX: simply adding it to the delete list here is fscking dangerous!
2702 + * as a temporary hack, i will disable rmdir on unmodified directories
2708 + err = get_neg_sto_dentry(dentry);
2714 + /* dput base dentry, this will relase the inode and free the
2715 + * dentry, as we will never need it again. */
2716 + dput(dtohd(dentry));
2717 + dtohd(dentry) = NULL;
2718 + dtopd(dentry)->state = DELETED;
2720 + /* add deleted file to META-file */
2721 + meta_add_d_entry(dentry->d_parent,
2722 + dentry->d_name.name,
2723 + dentry->d_name.len);
2726 + else if(dtopd(dentry)->state == CREATED) {
2727 + hidden_sto_dir = itohi2(dir);
2728 + hidden_sto_dentry = dtohd2(dentry);
2730 + /* was: hidden_sto_dir_dentry = lock_parent(hidden_sto_dentry);*/
2731 + hidden_sto_dir_dentry = dget(hidden_sto_dentry->d_parent);
2733 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
2734 + mutex_lock(&hidden_sto_dir_dentry->d_inode->i_mutex);
2736 + down(&hidden_sto_dir_dentry->d_inode->i_sem);
2739 + /* avoid destroying the hidden inode if the file is in use */
2740 + dget(hidden_sto_dentry);
2742 + /* Delete an old WOL file contained in the storage dir */
2743 + meta_dentry = lookup_one_len(META_FILENAME,
2744 + hidden_sto_dentry,
2745 + strlen(META_FILENAME));
2746 + if(meta_dentry->d_inode) {
2747 + /* is this necessary? dget(meta_dentry); */
2748 + err = vfs_unlink(hidden_sto_dentry->d_inode,
2750 + dput(meta_dentry);
2752 + d_delete(meta_dentry);
2755 + err = vfs_rmdir(hidden_sto_dir, hidden_sto_dentry);
2756 + dput(hidden_sto_dentry);
2758 + d_delete(hidden_sto_dentry);
2760 + /* propagate number of hard-links */
2761 + dentry->d_inode->i_nlink = itohi2(dentry->d_inode)->i_nlink;
2762 + dtopd(dentry)->state = NON_EXISTANT;
2764 + /* was: unlock_dir(hidden_sto_dir_dentry); */
2765 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
2766 + mutex_unlock(&hidden_sto_dir_dentry->d_inode->i_mutex);
2768 + up(&hidden_sto_dir_dentry->d_inode->i_sem);
2770 + dput(hidden_sto_dir_dentry);
2774 + else if(dtopd(dentry)->state == DEL_REWRITTEN) {
2775 + hidden_sto_dir = itohi2(dir);
2776 + hidden_sto_dentry = dtohd2(dentry);
2778 + /* was: hidden_sto_dir_dentry = lock_parent(hidden_sto_dentry);*/
2779 + hidden_sto_dir_dentry = dget(hidden_sto_dentry->d_parent);
2781 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
2782 + mutex_lock(&hidden_sto_dir_dentry->d_inode->i_mutex);
2784 + down(&hidden_sto_dir_dentry->d_inode->i_sem);
2787 + /* avoid destroying the hidden inode if the file is in use */
2788 + dget(hidden_sto_dentry);
2790 + /* Delete an old WOL file contained in the storage dir */
2791 + meta_dentry = lookup_one_len(META_FILENAME,
2792 + hidden_sto_dentry,
2793 + strlen(META_FILENAME));
2794 + if(meta_dentry->d_inode) {
2795 + /* is this necessary? dget(meta_dentry); */
2796 + err = vfs_unlink(hidden_sto_dentry->d_inode,
2798 + dput(meta_dentry);
2800 + d_delete(meta_dentry);
2803 + err = vfs_rmdir(hidden_sto_dir, hidden_sto_dentry);
2804 + dput(hidden_sto_dentry);
2806 + d_delete(hidden_sto_dentry);
2808 + /* propagate number of hard-links */
2809 + dentry->d_inode->i_nlink = itohi2(dentry->d_inode)->i_nlink;
2810 + dtopd(dentry)->state = DELETED;
2811 + /* was: unlock_dir(hidden_sto_dir_dentry); */
2813 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
2814 + mutex_unlock(&hidden_sto_dir_dentry->d_inode->i_mutex);
2816 + up(&hidden_sto_dir_dentry->d_inode->i_sem);
2818 + dput(hidden_sto_dir_dentry);
2822 + printk(KERN_CRIT "mini_fo_rmdir: ERROR, invalid state detected.\n");
2829 + fist_copy_attr_times(dir, itohi2(dentry->d_parent->d_inode));
2837 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
2838 +mini_fo_mknod(inode_t *dir, dentry_t *dentry, int mode, dev_t dev)
2840 +mini_fo_mknod(inode_t *dir, dentry_t *dentry, int mode, int dev)
2845 + check_mini_fo_dentry(dentry);
2847 + err = create_sto_nod(dentry, mode, dev);
2849 + printk(KERN_CRIT "mini_fo_mknod: creating sto nod failed.\n");
2853 + check_mini_fo_dentry(dentry);
2859 +mini_fo_rename(inode_t *old_dir, dentry_t *old_dentry,
2860 + inode_t *new_dir, dentry_t *new_dentry)
2863 + if(S_ISDIR(old_dentry->d_inode->i_mode))
2864 + return rename_directory(old_dir, old_dentry, new_dir, new_dentry);
2865 + return rename_nondir(old_dir, old_dentry, new_dir, new_dentry);
2869 +int rename_directory(inode_t *old_dir, dentry_t *old_dentry,
2870 + inode_t *new_dir, dentry_t *new_dentry)
2872 + int err, bpath_len;
2875 + dentry_t *hidden_old_dentry;
2876 + dentry_t *hidden_new_dentry;
2877 + dentry_t *hidden_old_dir_dentry;
2878 + dentry_t *hidden_new_dir_dentry;
2884 + /* this is a test, chuck out if it works */
2885 + if(!(dtopd(new_dentry)->state == DELETED ||
2886 + dtopd(new_dentry)->state == NON_EXISTANT)) {
2887 + printk(KERN_CRIT "mini_fo: rename_directory: \
2888 + uh, ah, new_dentry not negative.\n");
2892 + /* state = UNMODIFIED */
2893 + if(dtopd(old_dentry)->state == UNMODIFIED) {
2894 + err = dir_unmod_to_mod(old_dentry);
2899 + /* state = MODIFIED */
2900 + if(dtopd(old_dentry)->state == MODIFIED) {
2901 + bpath = meta_check_r_entry(old_dentry->d_parent,
2902 + old_dentry->d_name.name,
2903 + old_dentry->d_name.len);
2905 + err = meta_remove_r_entry(old_dentry->d_parent,
2906 + old_dentry->d_name.name,
2907 + old_dentry->d_name.len);
2909 + printk(KERN_CRIT "mini_fo: rename_directory:\
2910 + meta_remove_r_entry \
2914 + err = meta_add_r_entry(new_dentry->d_parent,
2917 + new_dentry->d_name.name,
2918 + new_dentry->d_name.len);
2921 + else {/* wol it */
2922 + err = meta_add_d_entry(old_dentry->d_parent,
2923 + old_dentry->d_name.name,
2924 + old_dentry->d_name.len);
2927 + /* put it on rename list */
2928 + err = get_mini_fo_bpath(old_dentry,
2933 + err = meta_add_r_entry(new_dentry->d_parent,
2935 + new_dentry->d_name.name,
2936 + new_dentry->d_name.len);
2940 + /* no state change, MODIFIED stays MODIFIED */
2942 + /* state = CREATED */
2943 + if(dtopd(old_dentry)->state == CREATED ||
2944 + dtopd(old_dentry)->state == DEL_REWRITTEN) {
2945 + if(dtohd(old_dentry))
2946 + dput(dtohd(old_dentry));
2948 + if(dtopd(new_dentry)->state == DELETED) {
2949 + dtopd(old_dentry)->state = DEL_REWRITTEN;
2950 + dtohd(old_dentry) = NULL;
2952 + else if(dtopd(new_dentry)->state == NON_EXISTANT) {
2953 + dtopd(old_dentry)->state = CREATED;
2954 + /* steal new dentry's neg. base dentry */
2955 + dtohd(old_dentry) = dtohd(new_dentry);
2956 + dtohd(new_dentry) = NULL;
2959 + if(dtopd(new_dentry)->state == UNMODIFIED ||
2960 + dtopd(new_dentry)->state == NON_EXISTANT) {
2961 + err = get_neg_sto_dentry(new_dentry);
2966 + /* now move sto file */
2967 + hidden_old_dentry = dtohd2(old_dentry);
2968 + hidden_new_dentry = dtohd2(new_dentry);
2970 + dget(hidden_old_dentry);
2971 + dget(hidden_new_dentry);
2973 + hidden_old_dir_dentry = dget(hidden_old_dentry->d_parent);
2974 + hidden_new_dir_dentry = dget(hidden_new_dentry->d_parent);
2975 + double_lock(hidden_old_dir_dentry, hidden_new_dir_dentry);
2977 + err = vfs_rename(hidden_old_dir_dentry->d_inode, hidden_old_dentry,
2978 + hidden_new_dir_dentry->d_inode, hidden_new_dentry);
2982 + fist_copy_attr_all(new_dir, hidden_new_dir_dentry->d_inode);
2983 + if (new_dir != old_dir)
2984 + fist_copy_attr_all(old_dir,
2985 + hidden_old_dir_dentry->d_inode);
2988 + /* double_unlock will dput the new/old parent dentries
2989 + * whose refcnts were incremented via get_parent above. */
2990 + double_unlock(hidden_old_dir_dentry, hidden_new_dir_dentry);
2991 + dput(hidden_new_dentry);
2992 + dput(hidden_old_dentry);
2998 +int rename_nondir(inode_t *old_dir, dentry_t *old_dentry,
2999 + inode_t *new_dir, dentry_t *new_dentry)
3003 + check_mini_fo_dentry(old_dentry);
3004 + check_mini_fo_dentry(new_dentry);
3005 + check_mini_fo_inode(old_dir);
3006 + check_mini_fo_inode(new_dir);
3008 + /* state: UNMODIFIED */
3009 + if(dtost(old_dentry) == UNMODIFIED) {
3010 + err = nondir_unmod_to_mod(old_dentry, 1);
3017 + /* the easy states */
3018 + if(exists_in_storage(old_dentry)) {
3020 + dentry_t *hidden_old_dentry;
3021 + dentry_t *hidden_new_dentry;
3022 + dentry_t *hidden_old_dir_dentry;
3023 + dentry_t *hidden_new_dir_dentry;
3025 + /* if old file is MODIFIED, add it to the deleted_list */
3026 + if(dtopd(old_dentry)->state == MODIFIED) {
3027 + meta_add_d_entry(old_dentry->d_parent,
3028 + old_dentry->d_name.name,
3029 + old_dentry->d_name.len);
3031 + dput(dtohd(old_dentry));
3033 + /* if old file is CREATED, we only release the base dentry */
3034 + if(dtopd(old_dentry)->state == CREATED) {
3035 + if(dtohd(old_dentry))
3036 + dput(dtohd(old_dentry));
3039 + /* now setup the new states (depends on new_dentry state) */
3040 + /* new dentry state = MODIFIED */
3041 + if(dtopd(new_dentry)->state == MODIFIED) {
3042 + meta_add_d_entry(new_dentry->d_parent,
3043 + new_dentry->d_name.name,
3044 + new_dentry->d_name.len);
3046 + /* new dentry will be d_put'ed later by the vfs
3047 + * so don't do it here
3048 + * dput(dtohd(new_dentry));
3050 + dtohd(old_dentry) = NULL;
3051 + dtopd(old_dentry)->state = DEL_REWRITTEN;
3053 + /* new dentry state = UNMODIFIED */
3054 + else if(dtopd(new_dentry)->state == UNMODIFIED) {
3055 + if(get_neg_sto_dentry(new_dentry))
3058 + meta_add_d_entry(new_dentry->d_parent,
3059 + new_dentry->d_name.name,
3060 + new_dentry->d_name.len);
3062 + /* is this right??? */
3063 + /*dput(dtohd(new_dentry));*/
3064 + dtohd(old_dentry) = NULL;
3065 + dtopd(old_dentry)->state = DEL_REWRITTEN;
3067 + /* new dentry state = CREATED */
3068 + else if(dtopd(new_dentry)->state == CREATED) {
3069 + /* we keep the neg. base dentry (if exists) */
3070 + dtohd(old_dentry) = dtohd(new_dentry);
3071 + /* ...and set it to Null, or we'll get
3072 + * dcache.c:345 if it gets dput twice... */
3073 + dtohd(new_dentry) = NULL;
3074 + dtopd(old_dentry)->state = CREATED;
3076 + /* new dentry state = NON_EXISTANT */
3077 + else if(dtopd(new_dentry)->state == NON_EXISTANT) {
3078 + if(get_neg_sto_dentry(new_dentry))
3081 + /* we keep the neg. base dentry (if exists) */
3082 + dtohd(old_dentry) = dtohd(new_dentry);
3083 + /* ...and set it to Null, or we'll get
3084 + * Dr. dcache.c:345 if it gets dput twice... */
3085 + dtohd(new_dentry) = NULL;
3086 + dtopd(old_dentry)->state = CREATED;
3088 + /* new dentry state = DEL_REWRITTEN or DELETED */
3089 + else if(dtopd(new_dentry)->state == DEL_REWRITTEN ||
3090 + dtopd(new_dentry)->state == DELETED) {
3091 + dtohd(old_dentry) = NULL;
3092 + dtopd(old_dentry)->state = DEL_REWRITTEN;
3094 + else { /* not possible, uhh, ahh */
3096 + "mini_fo: rename_reg_file: invalid state detected [1].\n");
3100 + /* now we definitely have a sto file */
3101 + hidden_old_dentry = dtohd2(old_dentry);
3102 + hidden_new_dentry = dtohd2(new_dentry);
3104 + dget(hidden_old_dentry);
3105 + dget(hidden_new_dentry);
3107 + hidden_old_dir_dentry = dget(hidden_old_dentry->d_parent);
3108 + hidden_new_dir_dentry = dget(hidden_new_dentry->d_parent);
3109 + double_lock(hidden_old_dir_dentry, hidden_new_dir_dentry);
3111 + err = vfs_rename(hidden_old_dir_dentry->d_inode,
3112 + hidden_old_dentry,
3113 + hidden_new_dir_dentry->d_inode,
3114 + hidden_new_dentry);
3118 + fist_copy_attr_all(new_dir, hidden_new_dir_dentry->d_inode);
3119 + if (new_dir != old_dir)
3120 + fist_copy_attr_all(old_dir, hidden_old_dir_dentry->d_inode);
3123 + /* double_unlock will dput the new/old parent dentries
3124 + * whose refcnts were incremented via get_parent above.
3126 + double_unlock(hidden_old_dir_dentry, hidden_new_dir_dentry);
3127 + dput(hidden_new_dentry);
3128 + dput(hidden_old_dentry);
3132 + else { /* invalid state */
3133 + printk(KERN_CRIT "mini_fo: rename_reg_file: ERROR: invalid state detected [2].\n");
3140 +mini_fo_readlink(dentry_t *dentry, char *buf, int bufsiz)
3143 + dentry_t *hidden_dentry = NULL;
3145 + if(dtohd2(dentry) && dtohd2(dentry)->d_inode) {
3146 + hidden_dentry = dtohd2(dentry);
3147 + } else if(dtohd(dentry) && dtohd(dentry)->d_inode) {
3148 + hidden_dentry = dtohd(dentry);
3153 + if (!hidden_dentry->d_inode->i_op ||
3154 + !hidden_dentry->d_inode->i_op->readlink) {
3155 + err = -EINVAL; goto out;
3158 + err = hidden_dentry->d_inode->i_op->readlink(hidden_dentry,
3162 + fist_copy_attr_atime(dentry->d_inode, hidden_dentry->d_inode);
3169 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,13)
3170 +static int mini_fo_follow_link(dentry_t *dentry, struct nameidata *nd)
3172 +static void* mini_fo_follow_link(dentry_t *dentry, struct nameidata *nd)
3176 + int len = PAGE_SIZE, err;
3177 + mm_segment_t old_fs;
3179 + /* in 2.6 this is freed by mini_fo_put_link called by __do_follow_link */
3180 + buf = kmalloc(len, GFP_KERNEL);
3186 + /* read the symlink, and then we will follow it */
3187 + old_fs = get_fs();
3188 + set_fs(KERNEL_DS);
3189 + err = dentry->d_inode->i_op->readlink(dentry, buf, len);
3197 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
3198 + nd_set_link(nd, buf);
3201 + err = vfs_follow_link(nd, buf);
3205 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
3209 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,13)
3212 + return ERR_PTR(err);
3217 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
3218 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,13)
3219 +void mini_fo_put_link(struct dentry *dentry, struct nameidata *nd)
3221 +void mini_fo_put_link(struct dentry *dentry, struct nameidata *nd, void *cookie)
3225 + link = nd_get_link(nd);
3231 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
3232 +mini_fo_permission(inode_t *inode, int mask, struct nameidata *nd)
3234 +mini_fo_permission(inode_t *inode, int mask)
3237 + inode_t *hidden_inode;
3241 + if(itohi2(inode)) {
3242 + hidden_inode = itohi2(inode);
3244 + hidden_inode = itohi(inode);
3246 + mode = inode->i_mode;
3248 + /* not really needed, as permission handles everything:
3249 + * err = vfs_permission(inode, mask);
3254 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
3255 + err = permission(hidden_inode, mask, nd);
3257 + err = permission(hidden_inode, mask);
3264 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
3266 +mini_fo_inode_revalidate(dentry_t *dentry)
3269 + dentry_t *hidden_dentry;
3270 + inode_t *hidden_inode;
3272 + ASSERT(dentry->d_inode);
3273 + ASSERT(itopd(dentry->d_inode));
3275 + if(itohi2(dentry->d_inode)) {
3276 + hidden_dentry = dtohd2(dentry);
3277 + hidden_inode = hidden_dentry->d_inode;
3278 + } else if(itohi(dentry->d_inode)) {
3279 + hidden_dentry = dtohd(dentry);
3280 + hidden_inode = hidden_dentry->d_inode;
3282 + printk(KERN_CRIT "mini_fo_inode_revalidate: ERROR, invalid state detected.\n");
3286 + if (hidden_inode && hidden_inode->i_op && hidden_inode->i_op->revalidate){
3287 + err = hidden_inode->i_op->revalidate(hidden_dentry);
3291 + fist_copy_attr_all(dentry->d_inode, hidden_inode);
3298 +mini_fo_setattr(dentry_t *dentry, struct iattr *ia)
3302 + check_mini_fo_dentry(dentry);
3304 + if(!is_mini_fo_existant(dentry)) {
3305 + printk(KERN_CRIT "mini_fo_setattr: ERROR, invalid state detected [1].\n");
3309 + if(dtost(dentry) == UNMODIFIED) {
3310 + if(!IS_COPY_FLAG(ia->ia_valid))
3311 + goto out; /* we ignore these changes to base */
3313 + if(S_ISDIR(dentry->d_inode->i_mode)) {
3314 + err = dir_unmod_to_mod(dentry);
3316 + /* we copy contents if file is not beeing truncated */
3317 + if(S_ISREG(dentry->d_inode->i_mode) &&
3318 + !(ia->ia_size == 0 && (ia->ia_valid & ATTR_SIZE))) {
3319 + err = nondir_unmod_to_mod(dentry, 1);
3321 + err = nondir_unmod_to_mod(dentry, 0);
3325 + printk(KERN_CRIT "mini_fo_setattr: ERROR changing states.\n");
3329 + if(!exists_in_storage(dentry)) {
3330 + printk(KERN_CRIT "mini_fo_setattr: ERROR, invalid state detected [2].\n");
3334 + ASSERT(dentry->d_inode);
3335 + ASSERT(dtohd2(dentry));
3336 + ASSERT(itopd(dentry->d_inode));
3337 + ASSERT(itohi2(dentry->d_inode));
3339 + err = notify_change(dtohd2(dentry), ia);
3340 + fist_copy_attr_all(dentry->d_inode, itohi2(dentry->d_inode));
3345 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
3347 +mini_fo_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
3350 + dentry_t *hidden_dentry;
3352 + ASSERT(dentry->d_inode);
3353 + ASSERT(itopd(dentry->d_inode));
3355 + if(itohi2(dentry->d_inode)) {
3356 + hidden_dentry = dtohd2(dentry);
3357 + } else if(itohi(dentry->d_inode)) {
3358 + hidden_dentry = dtohd(dentry);
3360 + printk(KERN_CRIT "mini_fo_getattr: ERROR, invalid state detected.\n");
3364 + fist_copy_attr_all(dentry->d_inode, hidden_dentry->d_inode);
3366 + ASSERT(hidden_dentry);
3367 + ASSERT(hidden_dentry->d_inode);
3368 + ASSERT(hidden_dentry->d_inode->i_op);
3370 + generic_fillattr(dentry->d_inode, stat);
3371 + if (!stat->blksize) {
3372 + struct super_block *s = hidden_dentry->d_inode->i_sb;
3374 + blocks = (stat->size+s->s_blocksize-1) >> s->s_blocksize_bits;
3375 + stat->blocks = (s->s_blocksize / 512) * blocks;
3376 + stat->blksize = s->s_blocksize;
3383 +#if defined(XATTR) && (LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,20))
3384 +#if 0 /* no xattr_alloc() and xattr_free() */
3385 +/* This is lifted from fs/xattr.c */
3387 +xattr_alloc(size_t size, size_t limit)
3392 + return ERR_PTR(-E2BIG);
3394 + if (!size) /* size request, no buffer is needed */
3396 + else if (size <= PAGE_SIZE)
3397 + ptr = kmalloc((unsigned long) size, GFP_KERNEL);
3399 + ptr = vmalloc((unsigned long) size);
3401 + return ERR_PTR(-ENOMEM);
3406 +xattr_free(void *ptr, size_t size)
3408 + if (!size) /* size request, no buffer was needed */
3410 + else if (size <= PAGE_SIZE)
3415 +#endif /* no xattr_alloc() and xattr_free() */
3417 +/* BKL held by caller.
3418 + * dentry->d_inode->i_sem down
3421 +mini_fo_getxattr(struct dentry *dentry, const char *name, void *value, size_t size) {
3422 + struct dentry *hidden_dentry = NULL;
3423 + int err = -EOPNOTSUPP;
3424 + /* Define these anyway so we don't need as much ifdef'ed code. */
3425 + char *encoded_name = NULL;
3426 + char *encoded_value = NULL;
3428 + check_mini_fo_dentry(dentry);
3430 + if(exists_in_storage(dentry))
3431 + hidden_dentry = dtohd2(dentry);
3433 + hidden_dentry = dtohd(dentry);
3435 + ASSERT(hidden_dentry);
3436 + ASSERT(hidden_dentry->d_inode);
3437 + ASSERT(hidden_dentry->d_inode->i_op);
3439 + if (hidden_dentry->d_inode->i_op->getxattr) {
3440 + encoded_name = (char *)name;
3441 + encoded_value = (char *)value;
3443 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
3444 + mutex_lock(&hidden_dentry->d_inode->i_mutex);
3446 + down(&hidden_dentry->d_inode->i_sem);
3448 + /* lock_kernel() already done by caller. */
3449 + err = hidden_dentry->d_inode->i_op->getxattr(hidden_dentry, encoded_name, encoded_value, size);
3450 + /* unlock_kernel() will be done by caller. */
3451 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
3452 + mutex_lock(&hidden_dentry->d_inode->i_mutex);
3454 + up(&hidden_dentry->d_inode->i_sem);
3460 +/* BKL held by caller.
3461 + * dentry->d_inode->i_sem down
3464 +#if ((LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,21) \
3465 + && LINUX_VERSION_CODE <= KERNEL_VERSION(2,4,23)) \
3466 + || LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0))
3467 +mini_fo_setxattr(struct dentry *dentry, const char *name,
3468 + const void *value, size_t size, int flags)
3470 +mini_fo_setxattr(struct dentry *dentry, const char *name,
3471 + void *value, size_t size, int flags)
3475 + struct dentry *hidden_dentry = NULL;
3476 + int err = -EOPNOTSUPP;
3478 + /* Define these anyway, so we don't have as much ifdef'ed code. */
3479 + char *encoded_value = NULL;
3480 + char *encoded_name = NULL;
3482 + check_mini_fo_dentry(dentry);
3484 + if(exists_in_storage(dentry))
3485 + hidden_dentry = dtohd2(dentry);
3487 + hidden_dentry = dtohd(dentry);
3489 + ASSERT(hidden_dentry);
3490 + ASSERT(hidden_dentry->d_inode);
3491 + ASSERT(hidden_dentry->d_inode->i_op);
3493 + if (hidden_dentry->d_inode->i_op->setxattr) {
3494 + encoded_name = (char *)name;
3495 + encoded_value = (char *)value;
3497 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
3498 + mutex_lock(&hidden_dentry->d_inode->i_mutex);
3500 + down(&hidden_dentry->d_inode->i_sem);
3502 + /* lock_kernel() already done by caller. */
3503 + err = hidden_dentry->d_inode->i_op->setxattr(hidden_dentry, encoded_name, encoded_value, size, flags);
3504 + /* unlock_kernel() will be done by caller. */
3505 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
3506 + mutex_unlock(&hidden_dentry->d_inode->i_mutex);
3508 + up(&hidden_dentry->d_inode->i_sem);
3514 +/* BKL held by caller.
3515 + * dentry->d_inode->i_sem down
3518 +mini_fo_removexattr(struct dentry *dentry, const char *name) {
3519 + struct dentry *hidden_dentry = NULL;
3520 + int err = -EOPNOTSUPP;
3521 + char *encoded_name;
3523 + check_mini_fo_dentry(dentry);
3525 + if(exists_in_storage(dentry))
3526 + hidden_dentry = dtohd2(dentry);
3528 + hidden_dentry = dtohd(dentry);
3530 + ASSERT(hidden_dentry);
3531 + ASSERT(hidden_dentry->d_inode);
3532 + ASSERT(hidden_dentry->d_inode->i_op);
3534 + if (hidden_dentry->d_inode->i_op->removexattr) {
3535 + encoded_name = (char *)name;
3537 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
3538 + mutex_lock(&hidden_dentry->d_inode->i_mutex);
3540 + down(&hidden_dentry->d_inode->i_sem);
3542 + /* lock_kernel() already done by caller. */
3543 + err = hidden_dentry->d_inode->i_op->removexattr(hidden_dentry, encoded_name);
3544 + /* unlock_kernel() will be done by caller. */
3545 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
3546 + mutex_unlock(&hidden_dentry->d_inode->i_mutex);
3548 + up(&hidden_dentry->d_inode->i_sem);
3554 +/* BKL held by caller.
3555 + * dentry->d_inode->i_sem down
3558 +mini_fo_listxattr(struct dentry *dentry, char *list, size_t size) {
3559 + struct dentry *hidden_dentry = NULL;
3560 + int err = -EOPNOTSUPP;
3561 + char *encoded_list = NULL;
3563 + check_mini_fo_dentry(dentry);
3565 + if(exists_in_storage(dentry))
3566 + hidden_dentry = dtohd2(dentry);
3568 + hidden_dentry = dtohd(dentry);
3570 + ASSERT(hidden_dentry);
3571 + ASSERT(hidden_dentry->d_inode);
3572 + ASSERT(hidden_dentry->d_inode->i_op);
3574 + if (hidden_dentry->d_inode->i_op->listxattr) {
3575 + encoded_list = list;
3577 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
3578 + mutex_lock(&hidden_dentry->d_inode->i_mutex);
3580 + down(&hidden_dentry->d_inode->i_sem);
3582 + /* lock_kernel() already done by caller. */
3583 + err = hidden_dentry->d_inode->i_op->listxattr(hidden_dentry, encoded_list, size);
3584 + /* unlock_kernel() will be done by caller. */
3585 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
3586 + mutex_unlock(&hidden_dentry->d_inode->i_mutex);
3588 + up(&hidden_dentry->d_inode->i_sem);
3593 +# endif /* defined(XATTR) && (LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,20)) */
3595 +struct inode_operations mini_fo_symlink_iops =
3597 + readlink: mini_fo_readlink,
3598 + follow_link: mini_fo_follow_link,
3599 + /* mk: permission: mini_fo_permission, */
3600 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
3601 + revalidate: mini_fo_inode_revalidate,
3603 + setattr: mini_fo_setattr,
3604 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
3605 + getattr: mini_fo_getattr,
3606 + put_link: mini_fo_put_link,
3609 +#if defined(XATTR) && (LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,20))
3610 + setxattr: mini_fo_setxattr,
3611 + getxattr: mini_fo_getxattr,
3612 + listxattr: mini_fo_listxattr,
3613 + removexattr: mini_fo_removexattr
3614 +# endif /* defined(XATTR) && (LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,20)) */
3617 +struct inode_operations mini_fo_dir_iops =
3619 + create: mini_fo_create,
3620 + lookup: mini_fo_lookup,
3621 + link: mini_fo_link,
3622 + unlink: mini_fo_unlink,
3623 + symlink: mini_fo_symlink,
3624 + mkdir: mini_fo_mkdir,
3625 + rmdir: mini_fo_rmdir,
3626 + mknod: mini_fo_mknod,
3627 + rename: mini_fo_rename,
3628 + /* no readlink/follow_link for non-symlinks */
3629 + // off because we have setattr
3630 + // truncate: mini_fo_truncate,
3631 + /* mk:permission: mini_fo_permission, */
3632 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
3633 + revalidate: mini_fo_inode_revalidate,
3635 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
3636 + getattr: mini_fo_getattr,
3638 + setattr: mini_fo_setattr,
3639 +#if defined(XATTR) && (LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,20))
3640 + setxattr: mini_fo_setxattr,
3641 + getxattr: mini_fo_getxattr,
3642 + listxattr: mini_fo_listxattr,
3643 + removexattr: mini_fo_removexattr
3644 +# endif /* XATTR && LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,20) */
3647 +struct inode_operations mini_fo_main_iops =
3649 + /* permission: mini_fo_permission, */
3650 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
3651 + revalidate: mini_fo_inode_revalidate,
3653 + setattr: mini_fo_setattr,
3655 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
3656 + getattr: mini_fo_getattr,
3658 +#if defined(XATTR) && (LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,20))
3659 + setxattr: mini_fo_setxattr,
3660 + getxattr: mini_fo_getxattr,
3661 + listxattr: mini_fo_listxattr,
3662 + removexattr: mini_fo_removexattr
3663 +# endif /* XATTR && LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,20) */
3665 diff -urN linux.old/fs/mini_fo/main.c linux.dev/fs/mini_fo/main.c
3666 --- linux.old/fs/mini_fo/main.c 1970-01-01 01:00:00.000000000 +0100
3667 +++ linux.dev/fs/mini_fo/main.c 2006-11-17 03:11:48.000000000 +0100
3670 + * Copyright (c) 1997-2003 Erez Zadok
3671 + * Copyright (c) 2001-2003 Stony Brook University
3673 + * For specific licensing information, see the COPYING file distributed with
3674 + * this package, or get one from ftp://ftp.filesystems.org/pub/fist/COPYING.
3676 + * This Copyright notice must be kept intact and distributed with all
3677 + * fistgen sources INCLUDING sources generated by fistgen.
3680 + * Copyright (C) 2004, 2005 Markus Klotzbuecher <mk@creamnet.de>
3682 + * This program is free software; you can redistribute it and/or
3683 + * modify it under the terms of the GNU General Public License
3684 + * as published by the Free Software Foundation; either version
3685 + * 2 of the License, or (at your option) any later version.
3692 +#ifdef HAVE_CONFIG_H
3693 +# include <config.h>
3697 +#include "mini_fo.h"
3698 +#include <linux/module.h>
3700 +/* This definition must only appear after we include <linux/module.h> */
3701 +#ifndef MODULE_LICENSE
3702 +# define MODULE_LICENSE(bison)
3703 +#endif /* not MODULE_LICENSE */
3706 + * This is the mini_fo tri interpose function, which extends the
3707 + * functionality of the regular interpose by interposing a higher
3708 + * level inode on top of two lower level ones: the base filesystem
3709 + * inode and the storage filesystem inode.
3711 + * sb we pass is mini_fo's super_block
3714 +mini_fo_tri_interpose(dentry_t *hidden_dentry,
3715 + dentry_t *hidden_sto_dentry,
3716 + dentry_t *dentry, super_block_t *sb, int flag)
3718 + inode_t *hidden_inode = NULL;
3719 + inode_t *hidden_sto_inode = NULL; /* store corresponding storage inode */
3723 + /* Pointer to hidden_sto_inode if exists, else to hidden_inode.
3724 + * This is used to copy the attributes of the correct inode. */
3725 + inode_t *master_inode;
3728 + hidden_inode = hidden_dentry->d_inode;
3729 + if(hidden_sto_dentry)
3730 + hidden_sto_inode = hidden_sto_dentry->d_inode;
3732 + ASSERT(dentry->d_inode == NULL);
3734 + /* mk: One of the inodes associated with the dentrys is likely to
3735 + * be NULL, so carefull:
3737 + ASSERT((hidden_inode != NULL) || (hidden_sto_inode != NULL));
3739 + if(hidden_sto_inode)
3740 + master_inode = hidden_sto_inode;
3742 + master_inode = hidden_inode;
3745 + * We allocate our new inode below, by calling iget.
3746 + * iget will call our read_inode which will initialize some
3747 + * of the new inode's fields
3751 + * original: inode = iget(sb, hidden_inode->i_ino);
3753 + inode = iget(sb, iunique(sb, 25));
3755 + err = -EACCES; /* should be impossible??? */
3760 + * interpose the inode if not already interposed
3761 + * this is possible if the inode is being reused
3762 + * XXX: what happens if we get_empty_inode() but there's another already?
3763 + * for now, ASSERT() that this can't happen; fix later.
3765 + if (itohi(inode) != NULL) {
3766 + printk(KERN_CRIT "mini_fo_tri_interpose: itohi(inode) != NULL.\n");
3768 + if (itohi2(inode) != NULL) {
3769 + printk(KERN_CRIT "mini_fo_tri_interpose: itohi2(inode) != NULL.\n");
3772 + /* mk: Carefull, igrab can't handle NULL inodes (ok, why should it?), so
3773 + * we need to check here:
3776 + itohi(inode) = igrab(hidden_inode);
3778 + itohi(inode) = NULL;
3780 + if(hidden_sto_inode)
3781 + itohi2(inode) = igrab(hidden_sto_inode);
3783 + itohi2(inode) = NULL;
3786 + /* Use different set of inode ops for symlinks & directories*/
3787 + if (S_ISLNK(master_inode->i_mode))
3788 + inode->i_op = &mini_fo_symlink_iops;
3789 + else if (S_ISDIR(master_inode->i_mode))
3790 + inode->i_op = &mini_fo_dir_iops;
3792 + /* Use different set of file ops for directories */
3793 + if (S_ISDIR(master_inode->i_mode))
3794 + inode->i_fop = &mini_fo_dir_fops;
3796 + /* properly initialize special inodes */
3797 + if (S_ISBLK(master_inode->i_mode) || S_ISCHR(master_inode->i_mode) ||
3798 + S_ISFIFO(master_inode->i_mode) || S_ISSOCK(master_inode->i_mode)) {
3799 + init_special_inode(inode, master_inode->i_mode, master_inode->i_rdev);
3802 + /* Fix our inode's address operations to that of the lower inode */
3803 + if (inode->i_mapping->a_ops != master_inode->i_mapping->a_ops) {
3804 + inode->i_mapping->a_ops = master_inode->i_mapping->a_ops;
3807 + /* only (our) lookup wants to do a d_add */
3809 + d_add(dentry, inode);
3811 + d_instantiate(dentry, inode);
3813 + ASSERT(dtopd(dentry) != NULL);
3815 + /* all well, copy inode attributes */
3816 + fist_copy_attr_all(inode, master_inode);
3822 +/* parse mount options "base=" and "sto=" */
3824 +mini_fo_parse_options(super_block_t *sb, char *options)
3826 + dentry_t *hidden_root = ERR_PTR(-EINVAL);
3827 + dentry_t *hidden_root2 = ERR_PTR(-EINVAL);
3828 + struct nameidata nd, nd2;
3829 + char *name, *tmp, *end;
3832 + /* We don't want to go off the end of our arguments later on. */
3833 + for (end = options; *end; end++);
3835 + while (options < end) {
3837 + while (*tmp && *tmp != ',')
3840 + if (!strncmp("base=", options, 5)) {
3841 + name = options + 5;
3842 + printk(KERN_INFO "mini_fo: using base directory: %s\n", name);
3844 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
3845 + if (path_init(name, LOOKUP_FOLLOW, &nd))
3846 + err = path_walk(name, &nd);
3848 + err = path_lookup(name, LOOKUP_FOLLOW, &nd);
3851 + printk(KERN_CRIT "mini_fo: error accessing hidden directory '%s'\n", name);
3852 + hidden_root = ERR_PTR(err);
3855 + hidden_root = nd.dentry;
3856 + stopd(sb)->base_dir_dentry = nd.dentry;
3857 + stopd(sb)->hidden_mnt = nd.mnt;
3859 + } else if(!strncmp("sto=", options, 4)) {
3860 + /* parse the storage dir */
3861 + name = options + 4;
3862 + printk(KERN_INFO "mini_fo: using storage directory: %s\n", name);
3863 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
3864 + if(path_init(name, LOOKUP_FOLLOW, &nd2))
3865 + err = path_walk(name, &nd2);
3867 + err = path_lookup(name, LOOKUP_FOLLOW, &nd2);
3870 + printk(KERN_CRIT "mini_fo: error accessing hidden storage directory '%s'\n", name);
3872 + hidden_root2 = ERR_PTR(err);
3875 + hidden_root2 = nd2.dentry;
3876 + stopd(sb)->storage_dir_dentry = nd2.dentry;
3877 + stopd(sb)->hidden_mnt2 = nd2.mnt;
3878 + stohs2(sb) = hidden_root2->d_sb;
3880 + /* validate storage dir, this is done in
3881 + * mini_fo_read_super for the base directory.
3883 + if (IS_ERR(hidden_root2)) {
3884 + printk(KERN_WARNING "mini_fo_parse_options: storage dentry lookup failed (err = %ld)\n", PTR_ERR(hidden_root2));
3887 + if (!hidden_root2->d_inode) {
3888 + printk(KERN_WARNING "mini_fo_parse_options: no storage dir to interpose on.\n");
3891 + stohs2(sb) = hidden_root2->d_sb;
3893 + printk(KERN_WARNING "mini_fo: unrecognized option '%s'\n", options);
3894 + hidden_root = ERR_PTR(-EINVAL);
3897 + options = tmp + 1;
3901 + if(IS_ERR(hidden_root2))
3902 + return hidden_root2;
3903 + return hidden_root;
3907 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
3912 +mini_fo_read_super(super_block_t *sb, void *raw_data, int silent)
3914 + dentry_t *hidden_root;
3918 + printk(KERN_WARNING "mini_fo_read_super: missing argument\n");
3923 + * Allocate superblock private data
3925 + __stopd(sb) = kmalloc(sizeof(struct mini_fo_sb_info), GFP_KERNEL);
3927 + printk(KERN_WARNING "%s: out of memory\n", __FUNCTION__);
3933 + hidden_root = mini_fo_parse_options(sb, raw_data);
3934 + if (IS_ERR(hidden_root)) {
3935 + printk(KERN_WARNING "mini_fo_read_super: lookup_dentry failed (err = %ld)\n", PTR_ERR(hidden_root));
3936 + err = PTR_ERR(hidden_root);
3939 + if (!hidden_root->d_inode) {
3940 + printk(KERN_WARNING "mini_fo_read_super: no directory to interpose on\n");
3943 + stohs(sb) = hidden_root->d_sb;
3946 + * Linux 2.4.2-ac3 and beyond has code in
3947 + * mm/filemap.c:generic_file_write() that requires sb->s_maxbytes
3948 + * to be populated. If not set, all write()s under that sb will
3951 + * Linux 2.4.4+ automatically sets s_maxbytes to MAX_NON_LFS;
3952 + * the filesystem should override it only if it supports LFS.
3954 + /* non-SCA code is good to go with LFS */
3955 + sb->s_maxbytes = hidden_root->d_sb->s_maxbytes;
3957 + sb->s_op = &mini_fo_sops;
3959 + * we can't use d_alloc_root if we want to use
3960 + * our own interpose function unchanged,
3961 + * so we simply replicate *most* of the code in d_alloc_root here
3963 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
3964 + sb->s_root = d_alloc(NULL, &(const struct qstr) { "/", 1, 0 });
3966 + sb->s_root = d_alloc(NULL, &(const struct qstr){hash: 0, name: "/", len : 1});
3968 + if (IS_ERR(sb->s_root)) {
3969 + printk(KERN_WARNING "mini_fo_read_super: d_alloc failed\n");
3974 + sb->s_root->d_op = &mini_fo_dops;
3975 + sb->s_root->d_sb = sb;
3976 + sb->s_root->d_parent = sb->s_root;
3978 + /* link the upper and lower dentries */
3979 + __dtopd(sb->s_root) = (struct mini_fo_dentry_info *)
3980 + kmalloc(sizeof(struct mini_fo_dentry_info), GFP_KERNEL);
3981 + if (!dtopd(sb->s_root)) {
3985 + dtopd(sb->s_root)->state = MODIFIED;
3986 + dtohd(sb->s_root) = hidden_root;
3988 + /* fanout relevant, interpose on storage root dentry too */
3989 + dtohd2(sb->s_root) = stopd(sb)->storage_dir_dentry;
3991 + /* ...and call tri-interpose to interpose root dir inodes
3992 + * if (mini_fo_interpose(hidden_root, sb->s_root, sb, 0))
3994 + if(mini_fo_tri_interpose(hidden_root, dtohd2(sb->s_root), sb->s_root, sb, 0))
3997 + /* initalize the wol list */
3998 + itopd(sb->s_root->d_inode)->deleted_list_size = -1;
3999 + itopd(sb->s_root->d_inode)->renamed_list_size = -1;
4000 + meta_build_lists(sb->s_root);
4007 + dput(hidden_root);
4008 + dput(dtohd2(sb->s_root)); /* release the hidden_sto_dentry too */
4011 + __stopd(sb) = NULL;
4014 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
4018 + return ERR_PTR(err);
4025 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
4026 +static struct super_block *mini_fo_get_sb(struct file_system_type *fs_type,
4027 + int flags, const char *dev_name,
4030 + return get_sb_nodev(fs_type, flags, raw_data, mini_fo_read_super);
4033 +void mini_fo_kill_block_super(struct super_block *sb)
4035 + generic_shutdown_super(sb);
4037 + * XXX: BUG: Halcrow: Things get unstable sometime after this point:
4038 + * lib/rwsem-spinlock.c:127: spin_is_locked on uninitialized
4039 + * fs/fs-writeback.c:402: spin_lock(fs/super.c:a0381828) already
4040 + * locked by fs/fs-writeback.c/402
4042 + * Apparently, someone's not releasing a lock on sb_lock...
4046 +static struct file_system_type mini_fo_fs_type = {
4047 + .owner = THIS_MODULE,
4048 + .name = "mini_fo",
4049 + .get_sb = mini_fo_get_sb,
4050 + .kill_sb = mini_fo_kill_block_super,
4056 +static DECLARE_FSTYPE(mini_fo_fs_type, "mini_fo", mini_fo_read_super, 0);
4059 +static int __init init_mini_fo_fs(void)
4061 + printk("Registering mini_fo version $Id$\n");
4062 + return register_filesystem(&mini_fo_fs_type);
4064 +static void __exit exit_mini_fo_fs(void)
4066 + printk("Unregistering mini_fo version $Id$\n");
4067 + unregister_filesystem(&mini_fo_fs_type);
4070 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
4074 +MODULE_AUTHOR("Erez Zadok <ezk@cs.sunysb.edu>");
4075 +MODULE_DESCRIPTION("FiST-generated mini_fo filesystem");
4076 +MODULE_LICENSE("GPL");
4078 +/* MODULE_PARM(fist_debug_var, "i"); */
4079 +/* MODULE_PARM_DESC(fist_debug_var, "Debug level"); */
4081 +module_init(init_mini_fo_fs)
4082 +module_exit(exit_mini_fo_fs)
4083 diff -urN linux.old/fs/mini_fo/Makefile linux.dev/fs/mini_fo/Makefile
4084 --- linux.old/fs/mini_fo/Makefile 1970-01-01 01:00:00.000000000 +0100
4085 +++ linux.dev/fs/mini_fo/Makefile 2006-11-17 03:11:48.000000000 +0100
4088 +# Makefile for mini_fo 2.4 and 2.6 Linux kernels
4090 +# Copyright (C) 2004, 2005 Markus Klotzbuecher <mk@creamnet.de>
4092 +# This program is free software; you can redistribute it and/or
4093 +# modify it under the terms of the GNU General Public License
4094 +# as published by the Free Software Foundation; either version
4095 +# 2 of the License, or (at your option) any later version.
4098 +obj-$(CONFIG_MINI_FO) := mini_fo.o
4099 +mini_fo-objs := meta.o dentry.o file.o inode.o main.o super.o state.o aux.o
4102 +${mini_fo-objs}: mini_fo.h fist.h
4104 diff -urN linux.old/fs/mini_fo/meta.c linux.dev/fs/mini_fo/meta.c
4105 --- linux.old/fs/mini_fo/meta.c 1970-01-01 01:00:00.000000000 +0100
4106 +++ linux.dev/fs/mini_fo/meta.c 2006-11-17 03:11:48.000000000 +0100
4109 + * Copyright (C) 2004, 2005 Markus Klotzbuecher <mk@creamnet.de>
4111 + * This program is free software; you can redistribute it and/or
4112 + * modify it under the terms of the GNU General Public License
4113 + * as published by the Free Software Foundation; either version
4114 + * 2 of the License, or (at your option) any later version.
4117 +#ifdef HAVE_CONFIG_H
4118 +# include <config.h>
4119 +#endif /* HAVE_CONFIG_H */
4121 +#include "mini_fo.h"
4123 +int meta_build_lists(dentry_t *dentry)
4125 + struct mini_fo_inode_info *inode_info;
4127 + dentry_t *meta_dentry = 0;
4128 + file_t *meta_file = 0;
4129 + mm_segment_t old_fs;
4133 + struct vfsmount *meta_mnt;
4136 + inode_info = itopd(dentry->d_inode);
4137 + if(!(inode_info->deleted_list_size == -1 &&
4138 + inode_info->renamed_list_size == -1)) {
4139 + printk(KERN_CRIT "mini_fo: meta_build_lists: \
4140 + Error, list(s) not virgin.\n");
4144 + /* init our meta lists */
4145 + INIT_LIST_HEAD(&inode_info->deleted_list);
4146 + inode_info->deleted_list_size = 0;
4148 + INIT_LIST_HEAD(&inode_info->renamed_list);
4149 + inode_info->renamed_list_size = 0;
4151 + /* might there be a META-file? */
4152 + if(dtohd2(dentry) && dtohd2(dentry)->d_inode) {
4153 + meta_dentry = lookup_one_len(META_FILENAME,
4155 + strlen(META_FILENAME));
4156 + if(!meta_dentry->d_inode) {
4157 + dput(meta_dentry);
4160 + /* $%& err, is this correct? */
4161 + meta_mnt = stopd(dentry->d_inode->i_sb)->hidden_mnt2;
4165 + /* open META-file for reading */
4166 + meta_file = dentry_open(meta_dentry, meta_mnt, 0x0);
4167 + if(!meta_file || IS_ERR(meta_file)) {
4168 + printk(KERN_CRIT "mini_fo: meta_build_lists: \
4169 + ERROR opening META file.\n");
4173 + /* check if fs supports reading */
4174 + if(!meta_file->f_op->read) {
4175 + printk(KERN_CRIT "mini_fo: meta_build_lists: \
4176 + ERROR, fs does not support reading.\n");
4177 + goto out_err_close;
4180 + /* allocate a page for transfering the data */
4181 + buf = (void *) __get_free_page(GFP_KERNEL);
4183 + printk(KERN_CRIT "mini_fo: meta_build_lists: \
4184 + ERROR, out of mem.\n");
4185 + goto out_err_close;
4187 + meta_file->f_pos = 0;
4188 + old_fs = get_fs();
4189 + set_fs(KERNEL_DS);
4192 + bytes = meta_file->f_op->read(meta_file, buf, PAGE_SIZE, &meta_file->f_pos);
4193 + if(bytes == PAGE_SIZE) {
4194 + /* trim a cut off filename and adjust f_pos to get it next time */
4195 + for(c = (char*) buf+PAGE_SIZE;
4197 + c--, bytes--, meta_file->f_pos--);
4199 + entry = (char *) buf;
4200 + while(entry < (char *) buf+bytes) {
4204 + int old_len, new_len;
4206 + /* len without '\n'*/
4207 + len = (int) (strchr(entry, '\n') - entry);
4210 + /* format: "D filename" */
4211 + meta_list_add_d_entry(dentry,
4216 + /* format: "R path/xy/dir newDir" */
4217 + old_path = entry+2;
4218 + dir_name = strchr(old_path, ' ') + 1;
4219 + old_len = dir_name - old_path - 1;
4220 + new_len = ((int) entry) + len - ((int ) dir_name);
4221 + meta_list_add_r_entry(dentry,
4228 + /* unknown entry type detected */
4234 + } while(meta_file->f_pos < meta_dentry->d_inode->i_size);
4236 + free_page((unsigned long) buf);
4246 + dput(meta_dentry);
4249 + return 1; /* check this!!! inode_info->wol_size; */
4252 +/* cleanups up all lists and free's the mem by dentry */
4253 +int meta_put_lists(dentry_t *dentry)
4255 + if(!dentry || !dentry->d_inode) {
4256 + printk("mini_fo: meta_put_lists: invalid dentry passed.\n");
4259 + return __meta_put_lists(dentry->d_inode);
4262 +/* cleanups up all lists and free's the mem by inode */
4263 +int __meta_put_lists(inode_t *inode)
4266 + if(!inode || !itopd(inode)) {
4267 + printk("mini_fo: __meta_put_lists: invalid inode passed.\n");
4270 + err = __meta_put_d_list(inode);
4271 + err |= __meta_put_r_list(inode);
4275 +int meta_sync_lists(dentry_t *dentry)
4278 + if(!dentry || !dentry->d_inode) {
4279 + printk("mini_fo: meta_sync_lists: \
4280 + invalid dentry passed.\n");
4283 + err = meta_sync_d_list(dentry, 0);
4284 + err |= meta_sync_r_list(dentry, 1);
4289 +/* remove all D entries from the renamed list and free the mem */
4290 +int __meta_put_d_list(inode_t *inode)
4292 + struct list_head *tmp;
4293 + struct deleted_entry *del_entry;
4294 + struct mini_fo_inode_info *inode_info;
4296 + if(!inode || !itopd(inode)) {
4297 + printk(KERN_CRIT "mini_fo: __meta_put_d_list: \
4298 + invalid inode passed.\n");
4301 + inode_info = itopd(inode);
4303 + /* nuke the DELETED-list */
4304 + if(inode_info->deleted_list_size <= 0)
4307 + while(!list_empty(&inode_info->deleted_list)) {
4308 + tmp = inode_info->deleted_list.next;
4310 + del_entry = list_entry(tmp, struct deleted_entry, list);
4311 + kfree(del_entry->name);
4314 + inode_info->deleted_list_size = 0;
4319 +/* remove all R entries from the renamed list and free the mem */
4320 +int __meta_put_r_list(inode_t *inode)
4322 + struct list_head *tmp;
4323 + struct renamed_entry *ren_entry;
4324 + struct mini_fo_inode_info *inode_info;
4326 + if(!inode || !itopd(inode)) {
4327 + printk(KERN_CRIT "mini_fo: meta_put_r_list: invalid inode.\n");
4330 + inode_info = itopd(inode);
4332 + /* nuke the RENAMED-list */
4333 + if(inode_info->renamed_list_size <= 0)
4336 + while(!list_empty(&inode_info->renamed_list)) {
4337 + tmp = inode_info->renamed_list.next;
4339 + ren_entry = list_entry(tmp, struct renamed_entry, list);
4340 + kfree(ren_entry->new_name);
4341 + kfree(ren_entry->old_name);
4344 + inode_info->renamed_list_size = 0;
4349 +int meta_add_d_entry(dentry_t *dentry, const char *name, int len)
4352 + err = meta_list_add_d_entry(dentry, name, len);
4353 + err |= meta_write_d_entry(dentry,name,len);
4357 +/* add a D entry to the deleted list */
4358 +int meta_list_add_d_entry(dentry_t *dentry, const char *name, int len)
4360 + struct deleted_entry *del_entry;
4361 + struct mini_fo_inode_info *inode_info;
4363 + if(!dentry || !dentry->d_inode) {
4364 + printk(KERN_CRIT "mini_fo: meta_list_add_d_entry: \
4365 + invalid dentry passed.\n");
4368 + inode_info = itopd(dentry->d_inode);
4370 + if(inode_info->deleted_list_size < 0)
4373 + del_entry = (struct deleted_entry *)
4374 + kmalloc(sizeof(struct deleted_entry), GFP_KERNEL);
4375 + del_entry->name = (char*) kmalloc(len, GFP_KERNEL);
4376 + if(!del_entry || !del_entry->name) {
4377 + printk(KERN_CRIT "mini_fo: meta_list_add_d_entry: \
4379 + kfree(del_entry->name);
4384 + strncpy(del_entry->name, name, len);
4385 + del_entry->len = len;
4387 + list_add(&del_entry->list, &inode_info->deleted_list);
4388 + inode_info->deleted_list_size++;
4392 +int meta_add_r_entry(dentry_t *dentry,
4393 + const char *old_name, int old_len,
4394 + const char *new_name, int new_len)
4397 + err = meta_list_add_r_entry(dentry,
4398 + old_name, old_len,
4399 + new_name, new_len);
4400 + err |= meta_write_r_entry(dentry,
4401 + old_name, old_len,
4402 + new_name, new_len);
4406 +/* add a R entry to the renamed list */
4407 +int meta_list_add_r_entry(dentry_t *dentry,
4408 + const char *old_name, int old_len,
4409 + const char *new_name, int new_len)
4411 + struct renamed_entry *ren_entry;
4412 + struct mini_fo_inode_info *inode_info;
4414 + if(!dentry || !dentry->d_inode) {
4415 + printk(KERN_CRIT "mini_fo: meta_list_add_r_entry: \
4416 + invalid dentry passed.\n");
4419 + inode_info = itopd(dentry->d_inode);
4421 + if(inode_info->renamed_list_size < 0)
4424 + ren_entry = (struct renamed_entry *)
4425 + kmalloc(sizeof(struct renamed_entry), GFP_KERNEL);
4426 + ren_entry->old_name = (char*) kmalloc(old_len, GFP_KERNEL);
4427 + ren_entry->new_name = (char*) kmalloc(new_len, GFP_KERNEL);
4429 + if(!ren_entry || !ren_entry->old_name || !ren_entry->new_name) {
4430 + printk(KERN_CRIT "mini_fo: meta_list_add_r_entry: \
4432 + kfree(ren_entry->new_name);
4433 + kfree(ren_entry->old_name);
4438 + strncpy(ren_entry->old_name, old_name, old_len);
4439 + ren_entry->old_len = old_len;
4440 + strncpy(ren_entry->new_name, new_name, new_len);
4441 + ren_entry->new_len = new_len;
4443 + list_add(&ren_entry->list, &inode_info->renamed_list);
4444 + inode_info->renamed_list_size++;
4449 +int meta_remove_r_entry(dentry_t *dentry, const char *name, int len)
4452 + if(!dentry || !dentry->d_inode) {
4454 + "mini_fo: meta_remove_r_entry: \
4455 + invalid dentry passed.\n");
4459 + err = meta_list_remove_r_entry(dentry, name, len);
4460 + err |= meta_sync_lists(dentry);
4464 +int meta_list_remove_r_entry(dentry_t *dentry, const char *name, int len)
4466 + if(!dentry || !dentry->d_inode) {
4468 + "mini_fo: meta_list_remove_r_entry: \
4469 + invalid dentry passed.\n");
4472 + return __meta_list_remove_r_entry(dentry->d_inode, name, len);
4475 +int __meta_list_remove_r_entry(inode_t *inode, const char *name, int len)
4477 + struct list_head *tmp;
4478 + struct renamed_entry *ren_entry;
4479 + struct mini_fo_inode_info *inode_info;
4481 + if(!inode || !itopd(inode))
4483 + "mini_fo: __meta_list_remove_r_entry: \
4484 + invalid inode passed.\n");
4485 + inode_info = itopd(inode);
4487 + if(inode_info->renamed_list_size < 0)
4489 + if(inode_info->renamed_list_size == 0)
4492 + list_for_each(tmp, &inode_info->renamed_list) {
4493 + ren_entry = list_entry(tmp, struct renamed_entry, list);
4494 + if(ren_entry->new_len != len)
4497 + if(!strncmp(ren_entry->new_name, name, len)) {
4499 + kfree(ren_entry->new_name);
4500 + kfree(ren_entry->old_name);
4502 + inode_info->renamed_list_size--;
4510 +/* append a single D entry to the meta file */
4511 +int meta_write_d_entry(dentry_t *dentry, const char *name, int len)
4513 + dentry_t *meta_dentry = 0;
4514 + file_t *meta_file = 0;
4515 + mm_segment_t old_fs;
4518 + struct vfsmount *meta_mnt = 0;
4523 + if(itopd(dentry->d_inode)->deleted_list_size < 0) {
4528 + if(dtopd(dentry)->state == UNMODIFIED) {
4529 + err = build_sto_structure(dentry->d_parent, dentry);
4531 + printk(KERN_CRIT "mini_fo: meta_write_d_entry: \
4532 + build_sto_structure failed.\n");
4536 + meta_dentry = lookup_one_len(META_FILENAME,
4537 + dtohd2(dentry), strlen (META_FILENAME));
4539 + /* We need to create a META-file */
4540 + if(!meta_dentry->d_inode) {
4541 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
4542 + vfs_create(dtohd2(dentry)->d_inode,
4544 + S_IRUSR | S_IWUSR,
4547 + vfs_create(dtohd2(dentry)->d_inode,
4549 + S_IRUSR | S_IWUSR);
4552 + /* open META-file for writing */
4553 + meta_file = dentry_open(meta_dentry, meta_mnt, 0x1);
4554 + if(!meta_file || IS_ERR(meta_file)) {
4555 + printk(KERN_CRIT "mini_fo: meta_write_d_entry: \
4556 + ERROR opening meta file.\n");
4557 + mntput(meta_mnt); /* $%& is this necessary? */
4558 + dput(meta_dentry);
4563 + /* check if fs supports writing */
4564 + if(!meta_file->f_op->write) {
4565 + printk(KERN_CRIT "mini_fo: meta_write_d_entry: \
4566 + ERROR, fs does not support writing.\n");
4567 + goto out_err_close;
4570 + meta_file->f_pos = meta_dentry->d_inode->i_size; /* append */
4571 + old_fs = get_fs();
4572 + set_fs(KERNEL_DS);
4574 + /* size: len for name, 1 for \n and 2 for "D " */
4575 + buf = (char *) kmalloc(len+3, GFP_KERNEL);
4577 + printk(KERN_CRIT "mini_fo: meta_write_d_entry: \
4584 + strncpy(buf+2, name, len);
4585 + buf[len+2] = '\n';
4586 + bytes = meta_file->f_op->write(meta_file, buf, len+3,
4587 + &meta_file->f_pos);
4588 + if(bytes != len+3) {
4589 + printk(KERN_CRIT "mini_fo: meta_write_d_entry: \
4590 + ERROR writing.\n");
4602 +/* append a single R entry to the meta file */
4603 +int meta_write_r_entry(dentry_t *dentry,
4604 + const char *old_name, int old_len,
4605 + const char *new_name, int new_len)
4607 + dentry_t *meta_dentry = 0;
4608 + file_t *meta_file = 0;
4609 + mm_segment_t old_fs;
4611 + int bytes, err, buf_len;
4612 + struct vfsmount *meta_mnt = 0;
4618 + if(itopd(dentry->d_inode)->renamed_list_size < 0) {
4623 + /* build the storage structure? */
4624 + if(dtopd(dentry)->state == UNMODIFIED) {
4625 + err = build_sto_structure(dentry->d_parent, dentry);
4627 + printk(KERN_CRIT "mini_fo: meta_write_r_entry: \
4628 + build_sto_structure failed.\n");
4632 + meta_dentry = lookup_one_len(META_FILENAME,
4634 + strlen (META_FILENAME));
4635 + if(!meta_dentry->d_inode) {
4636 + /* We need to create a META-file */
4637 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
4638 + vfs_create(dtohd2(dentry)->d_inode,
4639 + meta_dentry, S_IRUSR | S_IWUSR, NULL);
4641 + vfs_create(dtohd2(dentry)->d_inode,
4642 + meta_dentry, S_IRUSR | S_IWUSR);
4645 + /* open META-file for writing */
4646 + meta_file = dentry_open(meta_dentry, meta_mnt, 0x1);
4647 + if(!meta_file || IS_ERR(meta_file)) {
4648 + printk(KERN_CRIT "mini_fo: meta_write_r_entry: \
4649 + ERROR opening meta file.\n");
4651 + dput(meta_dentry);
4656 + /* check if fs supports writing */
4657 + if(!meta_file->f_op->write) {
4658 + printk(KERN_CRIT "mini_fo: meta_write_r_entry: \
4659 + ERROR, fs does not support writing.\n");
4660 + goto out_err_close;
4663 + meta_file->f_pos = meta_dentry->d_inode->i_size; /* append */
4664 + old_fs = get_fs();
4665 + set_fs(KERNEL_DS);
4667 + /* size: 2 for "R ", old_len+new_len for names, 1 blank+1 \n */
4668 + buf_len = old_len + new_len + 4;
4669 + buf = (char *) kmalloc(buf_len, GFP_KERNEL);
4671 + printk(KERN_CRIT "mini_fo: meta_write_r_entry: out of mem.\n");
4677 + strncpy(buf + 2, old_name, old_len);
4678 + buf[old_len + 2] = ' ';
4679 + strncpy(buf + old_len + 3, new_name, new_len);
4680 + buf[buf_len -1] = '\n';
4681 + bytes = meta_file->f_op->write(meta_file, buf, buf_len, &meta_file->f_pos);
4682 + if(bytes != buf_len) {
4683 + printk(KERN_CRIT "mini_fo: meta_write_r_entry: ERROR writing.\n");
4696 +/* sync D list to disk, append data if app_flag is 1 */
4697 +/* check the meta_mnt, which seems not to be used (properly) */
4699 +int meta_sync_d_list(dentry_t *dentry, int app_flag)
4701 + dentry_t *meta_dentry;
4702 + file_t *meta_file;
4703 + mm_segment_t old_fs;
4706 + struct vfsmount *meta_mnt;
4709 + struct list_head *tmp;
4710 + struct deleted_entry *del_entry;
4711 + struct mini_fo_inode_info *inode_info;
4717 + if(!dentry || !dentry->d_inode) {
4718 + printk(KERN_CRIT "mini_fo: meta_sync_d_list: \
4719 + invalid inode passed.\n");
4723 + inode_info = itopd(dentry->d_inode);
4725 + if(inode_info->deleted_list_size < 0) {
4730 + /* ok, there is something to sync */
4732 + /* build the storage structure? */
4733 + if(!dtohd2(dentry) && !itohi2(dentry->d_inode)) {
4734 + err = build_sto_structure(dentry->d_parent, dentry);
4736 + printk(KERN_CRIT "mini_fo: meta_sync_d_list: \
4737 + build_sto_structure failed.\n");
4741 + meta_dentry = lookup_one_len(META_FILENAME,
4743 + strlen(META_FILENAME));
4744 + if(!meta_dentry->d_inode) {
4745 + /* We need to create a META-file */
4746 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
4747 + vfs_create(dtohd2(dentry)->d_inode,
4748 + meta_dentry, S_IRUSR | S_IWUSR, NULL);
4750 + vfs_create(dtohd2(dentry)->d_inode,
4751 + meta_dentry, S_IRUSR | S_IWUSR);
4755 + /* need we truncate the meta file? */
4757 + struct iattr newattrs;
4758 + newattrs.ia_size = 0;
4759 + newattrs.ia_valid = ATTR_SIZE | ATTR_CTIME;
4761 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
4762 + mutex_lock(&meta_dentry->d_inode->i_mutex);
4764 + down(&meta_dentry->d_inode->i_sem);
4766 + err = notify_change(meta_dentry, &newattrs);
4768 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
4769 + mutex_unlock(&meta_dentry->d_inode->i_mutex);
4771 + up(&meta_dentry->d_inode->i_sem);
4774 + if(err || meta_dentry->d_inode->i_size != 0) {
4775 + printk(KERN_CRIT "mini_fo: meta_sync_d_list: \
4776 + ERROR truncating meta file.\n");
4777 + goto out_err_close;
4781 + /* open META-file for writing */
4782 + meta_file = dentry_open(meta_dentry, meta_mnt, 0x1);
4783 + if(!meta_file || IS_ERR(meta_file)) {
4784 + printk(KERN_CRIT "mini_fo: meta_sync_d_list: \
4785 + ERROR opening meta file.\n");
4786 + /* we don't mntget so we dont't mntput (for now)
4787 + * mntput(meta_mnt);
4789 + dput(meta_dentry);
4794 + /* check if fs supports writing */
4795 + if(!meta_file->f_op->write) {
4796 + printk(KERN_CRIT "mini_fo: meta_sync_d_list: \
4797 + ERROR, fs does not support writing.\n");
4798 + goto out_err_close;
4801 + meta_file->f_pos = meta_dentry->d_inode->i_size; /* append */
4802 + old_fs = get_fs();
4803 + set_fs(KERNEL_DS);
4805 + /* here we go... */
4806 + list_for_each(tmp, &inode_info->deleted_list) {
4807 + del_entry = list_entry(tmp, struct deleted_entry, list);
4809 + /* size: len for name, 1 for \n and 2 for "D " */
4810 + buf = (char *) kmalloc(del_entry->len+3, GFP_KERNEL);
4812 + printk(KERN_CRIT "mini_fo: meta_sync_d_list: \
4819 + strncpy(buf+2, del_entry->name, del_entry->len);
4820 + buf[del_entry->len+2] = '\n';
4821 + bytes = meta_file->f_op->write(meta_file, buf,
4823 + &meta_file->f_pos);
4824 + if(bytes != del_entry->len+3) {
4825 + printk(KERN_CRIT "mini_fo: meta_sync_d_list: \
4826 + ERROR writing.\n");
4840 +int meta_sync_r_list(dentry_t *dentry, int app_flag)
4842 + dentry_t *meta_dentry;
4843 + file_t *meta_file;
4844 + mm_segment_t old_fs;
4846 + int bytes, err, buf_len;
4847 + struct vfsmount *meta_mnt;
4850 + struct list_head *tmp;
4851 + struct renamed_entry *ren_entry;
4852 + struct mini_fo_inode_info *inode_info;
4858 + if(!dentry || !dentry->d_inode) {
4859 + printk(KERN_CRIT "mini_fo: meta_sync_r_list: \
4860 + invalid dentry passed.\n");
4864 + inode_info = itopd(dentry->d_inode);
4866 + if(inode_info->deleted_list_size < 0) {
4871 + /* ok, there is something to sync */
4873 + /* build the storage structure? */
4874 + if(!dtohd2(dentry) && !itohi2(dentry->d_inode)) {
4875 + err = build_sto_structure(dentry->d_parent, dentry);
4877 + printk(KERN_CRIT "mini_fo: meta_sync_r_list: \
4878 + build_sto_structure failed.\n");
4882 + meta_dentry = lookup_one_len(META_FILENAME,
4884 + strlen(META_FILENAME));
4885 + if(!meta_dentry->d_inode) {
4886 + /* We need to create a META-file */
4887 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
4888 + vfs_create(dtohd2(dentry)->d_inode,
4889 + meta_dentry, S_IRUSR | S_IWUSR, NULL);
4891 + vfs_create(dtohd2(dentry)->d_inode,
4892 + meta_dentry, S_IRUSR | S_IWUSR);
4896 + /* need we truncate the meta file? */
4898 + struct iattr newattrs;
4899 + newattrs.ia_size = 0;
4900 + newattrs.ia_valid = ATTR_SIZE | ATTR_CTIME;
4902 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
4903 + mutex_lock(&meta_dentry->d_inode->i_mutex);
4905 + down(&meta_dentry->d_inode->i_sem);
4907 + err = notify_change(meta_dentry, &newattrs);
4909 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
4910 + mutex_unlock(&meta_dentry->d_inode->i_mutex);
4912 + up(&meta_dentry->d_inode->i_sem);
4914 + if(err || meta_dentry->d_inode->i_size != 0) {
4915 + printk(KERN_CRIT "mini_fo: meta_sync_r_list: \
4916 + ERROR truncating meta file.\n");
4917 + goto out_err_close;
4921 + /* open META-file for writing */
4922 + meta_file = dentry_open(meta_dentry, meta_mnt, 0x1);
4923 + if(!meta_file || IS_ERR(meta_file)) {
4924 + printk(KERN_CRIT "mini_fo: meta_sync_r_list: \
4925 + ERROR opening meta file.\n");
4926 + /* we don't mntget so we dont't mntput (for now)
4927 + * mntput(meta_mnt);
4929 + dput(meta_dentry);
4934 + /* check if fs supports writing */
4935 + if(!meta_file->f_op->write) {
4936 + printk(KERN_CRIT "mini_fo: meta_sync_r_list: \
4937 + ERROR, fs does not support writing.\n");
4938 + goto out_err_close;
4941 + meta_file->f_pos = meta_dentry->d_inode->i_size; /* append */
4942 + old_fs = get_fs();
4943 + set_fs(KERNEL_DS);
4945 + /* here we go... */
4946 + list_for_each(tmp, &inode_info->renamed_list) {
4947 + ren_entry = list_entry(tmp, struct renamed_entry, list);
4949 + * 2 for "R ", old_len+new_len for names, 1 blank+1 \n */
4950 + buf_len = ren_entry->old_len + ren_entry->new_len + 4;
4951 + buf = (char *) kmalloc(buf_len, GFP_KERNEL);
4953 + printk(KERN_CRIT "mini_fo: meta_sync_r_list: \
4959 + strncpy(buf + 2, ren_entry->old_name, ren_entry->old_len);
4960 + buf[ren_entry->old_len + 2] = ' ';
4961 + strncpy(buf + ren_entry->old_len + 3,
4962 + ren_entry->new_name, ren_entry->new_len);
4963 + buf[buf_len - 1] = '\n';
4964 + bytes = meta_file->f_op->write(meta_file, buf,
4965 + buf_len, &meta_file->f_pos);
4966 + if(bytes != buf_len) {
4967 + printk(KERN_CRIT "mini_fo: meta_sync_r_list: \
4968 + ERROR writing.\n");
4981 +int meta_check_d_entry(dentry_t *dentry, const char *name, int len)
4983 + if(!dentry || !dentry->d_inode)
4984 + printk(KERN_CRIT "mini_fo: meta_check_d_dentry: \
4985 + invalid dentry passed.\n");
4986 + return __meta_check_d_entry(dentry->d_inode, name, len);
4989 +int __meta_check_d_entry(inode_t *inode, const char *name, int len)
4991 + struct list_head *tmp;
4992 + struct deleted_entry *del_entry;
4993 + struct mini_fo_inode_info *inode_info;
4995 + if(!inode || !itopd(inode))
4996 + printk(KERN_CRIT "mini_fo: __meta_check_d_dentry: \
4997 + invalid inode passed.\n");
4999 + inode_info = itopd(inode);
5001 + if(inode_info->deleted_list_size <= 0)
5004 + list_for_each(tmp, &inode_info->deleted_list) {
5005 + del_entry = list_entry(tmp, struct deleted_entry, list);
5006 + if(del_entry->len != len)
5009 + if(!strncmp(del_entry->name, name, len))
5016 + * check if file has been renamed and return path to orig. base dir.
5017 + * Implements no error return values so far, what of course sucks.
5018 + * String is null terminated.'
5020 +char* meta_check_r_entry(dentry_t *dentry, const char *name, int len)
5022 + if(!dentry || !dentry->d_inode) {
5023 + printk(KERN_CRIT "mini_fo: meta_check_r_dentry: \
5024 + invalid dentry passed.\n");
5027 + return __meta_check_r_entry(dentry->d_inode, name, len);
5030 +char* __meta_check_r_entry(inode_t *inode, const char *name, int len)
5032 + struct list_head *tmp;
5033 + struct renamed_entry *ren_entry;
5034 + struct mini_fo_inode_info *inode_info;
5037 + if(!inode || !itopd(inode)) {
5038 + printk(KERN_CRIT "mini_fo: meta_check_r_dentry: \
5039 + invalid inode passed.\n");
5042 + inode_info = itopd(inode);
5044 + if(inode_info->renamed_list_size <= 0)
5047 + list_for_each(tmp, &inode_info->renamed_list) {
5048 + ren_entry = list_entry(tmp, struct renamed_entry, list);
5049 + if(ren_entry->new_len != len)
5052 + if(!strncmp(ren_entry->new_name, name, len)) {
5053 + old_path = (char *)
5054 + kmalloc(ren_entry->old_len+1, GFP_KERNEL);
5056 + ren_entry->old_name,
5057 + ren_entry->old_len);
5058 + old_path[ren_entry->old_len]='\0';
5066 + * This version only checks if entry exists and return:
5071 +int meta_is_r_entry(dentry_t *dentry, const char *name, int len)
5073 + if(!dentry || !dentry->d_inode) {
5074 + printk(KERN_CRIT "mini_fo: meta_check_r_dentry [2]: \
5075 + invalid dentry passed.\n");
5078 + return __meta_is_r_entry(dentry->d_inode, name, len);
5081 +int __meta_is_r_entry(inode_t *inode, const char *name, int len)
5083 + struct list_head *tmp;
5084 + struct renamed_entry *ren_entry;
5085 + struct mini_fo_inode_info *inode_info;
5087 + if(!inode || !itopd(inode)) {
5088 + printk(KERN_CRIT "mini_fo: meta_check_r_dentry [2]: \
5089 + invalid inode passed.\n");
5092 + inode_info = itopd(inode);
5094 + if(inode_info->renamed_list_size <= 0)
5097 + list_for_each(tmp, &inode_info->renamed_list) {
5098 + ren_entry = list_entry(tmp, struct renamed_entry, list);
5099 + if(ren_entry->new_len != len)
5102 + if(!strncmp(ren_entry->new_name, name, len))
5108 diff -urN linux.old/fs/mini_fo/mini_fo.h linux.dev/fs/mini_fo/mini_fo.h
5109 --- linux.old/fs/mini_fo/mini_fo.h 1970-01-01 01:00:00.000000000 +0100
5110 +++ linux.dev/fs/mini_fo/mini_fo.h 2006-11-17 03:11:48.000000000 +0100
5113 + * Copyright (c) 1997-2003 Erez Zadok
5114 + * Copyright (c) 2001-2003 Stony Brook University
5116 + * For specific licensing information, see the COPYING file distributed with
5117 + * this package, or get one from ftp://ftp.filesystems.org/pub/fist/COPYING.
5119 + * This Copyright notice must be kept intact and distributed with all
5120 + * fistgen sources INCLUDING sources generated by fistgen.
5123 + * Copyright (C) 2004, 2005 Markus Klotzbuecher <mk@creamnet.de>
5125 + * This program is free software; you can redistribute it and/or
5126 + * modify it under the terms of the GNU General Public License
5127 + * as published by the Free Software Foundation; either version
5128 + * 2 of the License, or (at your option) any later version.
5135 +#ifndef __MINI_FO_H_
5136 +#define __MINI_FO_H_
5141 +#define META_FILENAME "META_dAfFgHE39ktF3HD2sr"
5146 +/* File attributes that when changed, result in a file beeing copied to storage */
5147 +#define COPY_FLAGS ATTR_MODE | ATTR_UID | ATTR_GID | ATTR_SIZE
5150 + * mini_fo filestates
5153 +#define UNMODIFIED 2
5155 +#define DEL_REWRITTEN 4
5157 +#define NON_EXISTANT 6
5159 +/* fist file systems superblock magic */
5160 +# define MINI_FO_SUPER_MAGIC 0xf15f
5166 +/* mini_fo inode data in memory */
5167 +struct mini_fo_inode_info {
5168 + inode_t *wii_inode;
5169 + inode_t *wii_inode2; /* pointer to storage inode */
5171 + /* META-data lists */
5172 + /* deleted list, ex wol */
5173 + struct list_head deleted_list;
5174 + int deleted_list_size;
5176 + /* renamed list */
5177 + struct list_head renamed_list;
5178 + int renamed_list_size;
5180 + /* add other lists here ... */
5183 +/* mini_fo dentry data in memory */
5184 +struct mini_fo_dentry_info {
5185 + dentry_t *wdi_dentry;
5186 + dentry_t *wdi_dentry2; /* pointer to storage dentry */
5187 + unsigned int state; /* state of the mini_fo dentry */
5191 +/* mini_fo super-block data in memory */
5192 +struct mini_fo_sb_info {
5193 + super_block_t *wsi_sb, *wsi_sb2; /* mk: might point to the same sb */
5194 + struct vfsmount *hidden_mnt, *hidden_mnt2;
5195 + dentry_t *base_dir_dentry;
5196 + dentry_t *storage_dir_dentry;
5200 +/* readdir_data, readdir helper struct */
5201 +struct readdir_data {
5202 + struct list_head ndl_list; /* linked list head ptr */
5203 + int ndl_size; /* list size */
5204 + int sto_done; /* flag to show that the storage dir entries have
5205 + * all been read an now follow base entries */
5208 +/* file private data. */
5209 +struct mini_fo_file_info {
5210 + struct file *wfi_file;
5211 + struct file *wfi_file2; /* pointer to storage file */
5212 + struct readdir_data rd;
5215 +/* struct ndl_entry */
5217 + struct list_head list;
5222 +/********************************
5223 + * META-data structures
5224 + ********************************/
5226 +/* deleted entry */
5227 +struct deleted_entry {
5228 + struct list_head list;
5233 +/* renamed entry */
5234 +struct renamed_entry {
5235 + struct list_head list;
5236 + char *old_name; /* old directory with full path */
5237 + int old_len; /* length of above string */
5238 + char *new_name; /* new directory name */
5239 + int new_len; /* length of above string */
5242 +/* attr_change entry */
5243 +struct attr_change_entry {
5244 + struct list_head list;
5250 +struct link_entry {
5251 + struct list_head list;
5256 + int weird_name_len;
5260 +/* Some other stuff required for mini_fo_filldir64, copied from
5264 +#define ROUND_UP64(x) (((x)+sizeof(u64)-1) & ~(sizeof(u64)-1))
5265 +#define NAME_OFFSET(de) ((int) ((de)->d_name - (char *) (de)))
5268 +struct linux_dirent64 {
5271 + unsigned short d_reclen;
5272 + unsigned char d_type;
5277 +struct getdents_callback64 {
5278 + struct linux_dirent64 * current_dir;
5279 + struct linux_dirent64 * previous;
5284 +struct linux_dirent {
5285 + unsigned long d_ino;
5286 + unsigned long d_off;
5287 + unsigned short d_reclen;
5291 +struct getdents_callback {
5292 + struct linux_dirent * current_dir;
5293 + struct linux_dirent * previous;
5303 +/* file TO private_data */
5304 +# define ftopd(file) ((struct mini_fo_file_info *)((file)->private_data))
5305 +# define __ftopd(file) ((file)->private_data)
5306 +/* file TO hidden_file */
5307 +# define ftohf(file) ((ftopd(file))->wfi_file)
5308 +# define ftohf2(file) ((ftopd(file))->wfi_file2)
5310 +/* inode TO private_data */
5311 +# define itopd(ino) ((struct mini_fo_inode_info *)(ino)->u.generic_ip)
5312 +# define __itopd(ino) ((ino)->u.generic_ip)
5313 +/* inode TO hidden_inode */
5314 +# define itohi(ino) (itopd(ino)->wii_inode)
5315 +# define itohi2(ino) (itopd(ino)->wii_inode2)
5317 +/* superblock TO private_data */
5318 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
5319 +# define stopd(super) ((struct mini_fo_sb_info *)(super)->s_fs_info)
5320 +# define __stopd(super) ((super)->s_fs_info)
5322 +# define stopd(super) ((struct mini_fo_sb_info *)(super)->u.generic_sbp)
5323 +# define __stopd(super) ((super)->u.generic_sbp)
5326 +/* unused? # define vfs2priv stopd */
5327 +/* superblock TO hidden_superblock */
5329 +# define stohs(super) (stopd(super)->wsi_sb)
5330 +# define stohs2(super) (stopd(super)->wsi_sb2)
5332 +/* dentry TO private_data */
5333 +# define dtopd(dentry) ((struct mini_fo_dentry_info *)(dentry)->d_fsdata)
5334 +# define __dtopd(dentry) ((dentry)->d_fsdata)
5335 +/* dentry TO hidden_dentry */
5336 +# define dtohd(dent) (dtopd(dent)->wdi_dentry)
5337 +# define dtohd2(dent) (dtopd(dent)->wdi_dentry2)
5339 +/* dentry to state */
5340 +# define dtost(dent) (dtopd(dent)->state)
5341 +# define sbt(sb) ((sb)->s_type->name)
5343 +#define IS_WRITE_FLAG(flag) (flag & (O_RDWR | O_WRONLY | O_APPEND))
5344 +#define IS_COPY_FLAG(flag) (flag & (COPY_FLAGS))
5346 +/* macros to simplify non-SCA code */
5347 +# define MALLOC_PAGE_POINTERS(hidden_pages, num_hidden_pages)
5348 +# define MALLOC_PAGEDATA_POINTERS(hidden_pages_data, num_hidden_pages)
5349 +# define FREE_PAGE_POINTERS(hidden_pages, num)
5350 +# define FREE_PAGEDATA_POINTERS(hidden_pages_data, num)
5351 +# define FOR_EACH_PAGE
5352 +# define CURRENT_HIDDEN_PAGE hidden_page
5353 +# define CURRENT_HIDDEN_PAGEDATA hidden_page_data
5354 +# define CURRENT_HIDDEN_PAGEINDEX page->index
5359 +extern struct file_operations mini_fo_main_fops;
5360 +extern struct file_operations mini_fo_dir_fops;
5361 +extern struct inode_operations mini_fo_main_iops;
5362 +extern struct inode_operations mini_fo_dir_iops;
5363 +extern struct inode_operations mini_fo_symlink_iops;
5364 +extern struct super_operations mini_fo_sops;
5365 +extern struct dentry_operations mini_fo_dops;
5366 +extern struct vm_operations_struct mini_fo_shared_vmops;
5367 +extern struct vm_operations_struct mini_fo_private_vmops;
5368 +extern struct address_space_operations mini_fo_aops;
5370 +#if 0 /* unused by mini_fo */
5371 +extern int mini_fo_interpose(dentry_t *hidden_dentry, dentry_t *this_dentry, super_block_t *sb, int flag);
5372 +#if defined(FIST_FILTER_DATA) || defined(FIST_FILTER_SCA)
5373 +extern page_t *mini_fo_get1page(file_t *file, int index);
5374 +extern int mini_fo_fill_zeros(file_t *file, page_t *page, unsigned from);
5375 +# endif /* FIST_FILTER_DATA || FIST_FILTER_SCA */
5378 +# define mini_fo_hidden_dentry(d) __mini_fo_hidden_dentry(__FILE__,__FUNCTION__,__LINE__,(d))
5379 +# define mini_fo_hidden_sto_dentry(d) __mini_fo_hidden_sto_dentry(__FILE__,__FUNCTION__,__LINE__,(d))
5381 +extern dentry_t *__mini_fo_hidden_dentry(char *file, char *func, int line, dentry_t *this_dentry);
5382 +extern dentry_t *__mini_fo_hidden_sto_dentry(char *file, char *func, int line, dentry_t *this_dentry);
5384 +extern int mini_fo_read_file(const char *filename, void *buf, int len);
5385 +extern int mini_fo_write_file(const char *filename, void *buf, int len);
5386 +extern dentry_t *fist_lookup(dentry_t *dir, const char *name, vnode_t **out, uid_t uid, gid_t gid);
5387 +#endif /* unused by mini_fo */
5389 +/* state transition functions */
5390 +extern int nondir_unmod_to_mod(dentry_t *dentry, int cp_flag);
5391 +extern int nondir_del_rew_to_del(dentry_t *dentry);
5392 +extern int nondir_creat_to_del(dentry_t *dentry);
5393 +extern int nondir_mod_to_del(dentry_t *dentry);
5394 +extern int nondir_unmod_to_del(dentry_t *dentry);
5396 +extern int dir_unmod_to_mod(dentry_t *dentry);
5398 +/* rename specials */
5399 +extern int rename_directory(inode_t *old_dir, dentry_t *old_dentry, inode_t *new_dir, dentry_t *new_dentry);
5400 +extern int rename_nondir(inode_t *old_dir, dentry_t *old_dentry, inode_t *new_dir, dentry_t *new_dentry);
5403 +extern int mini_fo_tri_interpose(dentry_t *hidden_dentry,
5404 + dentry_t *hidden_sto_dentry,
5406 + super_block_t *sb, int flag);
5408 +extern int mini_fo_cp_cont(dentry_t *tgt_dentry, struct vfsmount *tgt_mnt,
5409 + dentry_t *src_dentry, struct vfsmount *src_mnt);
5411 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
5412 +extern int mini_fo_create(inode_t *dir, dentry_t *dentry, int mode, struct nameidata *nd);
5414 +extern int create_sto_nod(dentry_t *dentry, int mode, dev_t dev);
5415 +extern int create_sto_reg_file(dentry_t *dentry, int mode, struct nameidata *nd);
5417 +extern int mini_fo_create(inode_t *dir, dentry_t *dentry, int mode);
5419 +extern int create_sto_nod(dentry_t *dentry, int mode, int dev);
5420 +extern int create_sto_reg_file(dentry_t *dentry, int mode);
5423 +extern int create_sto_dir(dentry_t *dentry, int mode);
5425 +extern int exists_in_storage(dentry_t *dentry);
5426 +extern int is_mini_fo_existant(dentry_t *dentry);
5427 +extern int get_neg_sto_dentry(dentry_t *dentry);
5428 +extern int build_sto_structure(dentry_t *dir, dentry_t *dentry);
5429 +extern int get_mini_fo_bpath(dentry_t *dentry, char **bpath, int *bpath_len);
5430 +extern dentry_t *bpath_walk(super_block_t *sb, char *bpath);
5431 +extern int bpath_put(dentry_t *dentry);
5433 +/* check_mini_fo types functions */
5434 +extern int check_mini_fo_dentry(dentry_t *dentry);
5435 +extern int check_mini_fo_file(file_t *file);
5436 +extern int check_mini_fo_inode(inode_t *inode);
5438 +/* General meta functions, can be called from outside of meta.c */
5439 +extern int meta_build_lists(dentry_t *dentry);
5440 +extern int meta_put_lists(dentry_t *dentry);
5441 +extern int __meta_put_lists(inode_t *inode);
5443 +extern int meta_add_d_entry(dentry_t *dentry, const char *name, int len);
5444 +extern int meta_add_r_entry(dentry_t *dentry,
5445 + const char *old_name, int old_len,
5446 + const char *new_name, int new_len);
5448 +extern int meta_remove_r_entry(dentry_t *dentry, const char *name, int len);
5450 +extern int meta_check_d_entry(dentry_t *dentry, const char *name, int len);
5451 +extern int __meta_check_d_entry(inode_t *inode, const char *name, int len);
5453 +extern char* meta_check_r_entry(dentry_t *dentry, const char *name, int len);
5454 +extern char* __meta_check_r_entry(inode_t *inode, const char *name, int len);
5455 +extern int meta_is_r_entry(dentry_t *dentry, const char *name, int len);
5456 +extern int __meta_is_r_entry(inode_t *inode, const char *name, int len);
5458 +/* Specific meta functions, should be called only inside meta.c */
5459 +extern int __meta_put_d_list(inode_t *inode);
5460 +extern int __meta_put_r_list(inode_t *inode);
5462 +extern int meta_list_add_d_entry(dentry_t *dentry,
5463 + const char *name, int len);
5464 +extern int meta_list_add_r_entry(dentry_t *dentry,
5465 + const char *old_name, int old_len,
5466 + const char *new_name, int new_len);
5468 +extern int meta_list_remove_r_entry(dentry_t *dentry,
5469 + const char *name, int len);
5471 +extern int __meta_list_remove_r_entry(inode_t *inode,
5472 + const char *name, int len);
5474 +extern int meta_write_d_entry(dentry_t *dentry, const char *name, int len);
5475 +extern int meta_write_r_entry(dentry_t *dentry,
5476 + const char *old_name, int old_len,
5477 + const char *new_name, int new_len);
5479 +extern int meta_sync_lists(dentry_t *dentry);
5480 +extern int meta_sync_d_list(dentry_t *dentry, int app_flag);
5481 +extern int meta_sync_r_list(dentry_t *dentry, int app_flag);
5484 +extern int ndl_add_entry(struct readdir_data *rd, const char *name, int len);
5485 +extern void ndl_put_list(struct readdir_data *rd);
5486 +extern int ndl_check_entry(struct readdir_data *rd,
5487 + const char *name, int len);
5490 +# define copy_inode_size(dst, src) \
5491 + dst->i_size = src->i_size; \
5492 + dst->i_blocks = src->i_blocks;
5495 +fist_copy_attr_atime(inode_t *dest, const inode_t *src)
5497 + ASSERT(dest != NULL);
5498 + ASSERT(src != NULL);
5499 + dest->i_atime = src->i_atime;
5502 +fist_copy_attr_times(inode_t *dest, const inode_t *src)
5504 + ASSERT(dest != NULL);
5505 + ASSERT(src != NULL);
5506 + dest->i_atime = src->i_atime;
5507 + dest->i_mtime = src->i_mtime;
5508 + dest->i_ctime = src->i_ctime;
5511 +fist_copy_attr_timesizes(inode_t *dest, const inode_t *src)
5513 + ASSERT(dest != NULL);
5514 + ASSERT(src != NULL);
5515 + dest->i_atime = src->i_atime;
5516 + dest->i_mtime = src->i_mtime;
5517 + dest->i_ctime = src->i_ctime;
5518 + copy_inode_size(dest, src);
5521 +fist_copy_attr_all(inode_t *dest, const inode_t *src)
5523 + ASSERT(dest != NULL);
5524 + ASSERT(src != NULL);
5525 + dest->i_mode = src->i_mode;
5526 + dest->i_nlink = src->i_nlink;
5527 + dest->i_uid = src->i_uid;
5528 + dest->i_gid = src->i_gid;
5529 + dest->i_rdev = src->i_rdev;
5530 + dest->i_atime = src->i_atime;
5531 + dest->i_mtime = src->i_mtime;
5532 + dest->i_ctime = src->i_ctime;
5533 + dest->i_blksize = src->i_blksize;
5534 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,12)
5535 + dest->i_blkbits = src->i_blkbits;
5536 +# endif /* linux 2.4.12 and newer */
5537 + copy_inode_size(dest, src);
5538 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
5539 + dest->i_attr_flags = src->i_attr_flags;
5541 + dest->i_flags = src->i_flags;
5545 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
5546 +/* copied from linux/fs.h */
5547 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
5548 +static inline void double_lock(struct dentry *d1, struct dentry *d2)
5550 + struct mutex *m1 = &d1->d_inode->i_mutex;
5551 + struct mutex *m2 = &d2->d_inode->i_mutex;
5553 + if ((unsigned long) m1 < (unsigned long) m2) {
5554 + struct mutex *tmp = m2;
5555 + m2 = m1; m1 = tmp;
5562 +static inline void double_unlock(struct dentry *d1, struct dentry *d2)
5564 + struct mutex *m1 = &d1->d_inode->i_mutex;
5565 + struct mutex *m2 = &d2->d_inode->i_mutex;
5574 +static inline void double_down(struct semaphore *s1, struct semaphore *s2)
5577 + if ((unsigned long) s1 < (unsigned long) s2) {
5578 + struct semaphore *tmp = s2;
5579 + s2 = s1; s1 = tmp;
5586 +static inline void double_up(struct semaphore *s1, struct semaphore *s2)
5593 +static inline void double_lock(struct dentry *d1, struct dentry *d2)
5595 + double_down(&d1->d_inode->i_sem, &d2->d_inode->i_sem);
5598 +static inline void double_unlock(struct dentry *d1, struct dentry *d2)
5600 + double_up(&d1->d_inode->i_sem,&d2->d_inode->i_sem);
5604 +#endif /* if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16) */
5605 +#endif /* if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0) */
5606 +#endif /* __KERNEL__ */
5609 + * Definitions for user and kernel code
5614 +#endif /* not __MINI_FO_H_ */
5615 diff -urN linux.old/fs/mini_fo/mini_fo-merge linux.dev/fs/mini_fo/mini_fo-merge
5616 --- linux.old/fs/mini_fo/mini_fo-merge 1970-01-01 01:00:00.000000000 +0100
5617 +++ linux.dev/fs/mini_fo/mini_fo-merge 2006-11-17 03:11:48.000000000 +0100
5621 +# Copyright (C) 2005 Markus Klotzbuecher <mk@creamnet.de>
5622 +# This program is free software; you can redistribute it and/or
5623 +# modify it under the terms of the GNU General Public License
5624 +# as published by the Free Software Foundation; either version
5625 +# 2 of the License, or (at your option) any later version.
5634 +META_NAME="META_dAfFgHE39ktF3HD2sr"
5635 +SKIP_DEL_LIST="skip-delete-list.mini_fo-merge"
5640 + if [ x$DRYRUN == "xset" ]; then
5641 + echo " would run: $COMMAND"
5642 + elif ! [ x$DRYRUN == "xset" ]; then
5643 + if [ x$VERBOSE == "xset" ]; then
5644 + echo " running: $COMMAND"
5654 +USAGE: $0 -b <base dir> -s <storage dir>
5657 +This script merges the contents of a mini_fo storage file system back
5658 +to the base file system.
5660 +!!! Warning: This will modify the base filesystem and can destroy data
5665 + the directory of the base file system.
5668 + the directory of the storage file system.
5670 + -d dry run, will not change anything and print the commands that
5671 + would be executed.
5673 + -t tmp dir for storing temporary file. default: $TMP
5675 + -v show what operations are performed.
5677 + -h displays this message.
5683 +while getopts hdvt:b:s: OPTS
5688 + v) VERBOSE="set";;
5689 + b) BASE="$OPTARG";;
5690 + s) STO="$OPTARG";;
5691 + t) TMP="$OPTARG";;
5697 +if [ "x$HELP" == "xset" ]; then
5702 +if ! [ -d "$BASE" ] || ! [ -d "$STO" ]; then
5703 + echo -e "$0:\n Error, -s and/or -b argument missing. type $0 -h for help."
5708 +pushd $STO; STO=`pwd`; popd
5709 +pushd $BASE; BASE=`pwd`; popd
5714 +###############################################################################
5718 +# storage dir: $STO
5719 +# meta filename: $META_NAME
5721 +# verbose: $VERBOSE
5723 +###############################################################################
5727 +rm $TMP/$SKIP_DEL_LIST
5729 +# first process all renamed dirs
5730 +echo "Merging renamed directories..."
5731 +pushd $STO &> /dev/null
5732 +find . -name $META_NAME -type f -print0 | xargs -0 -e grep -e '^R ' | tr -s ':R' ' ' | while read ENTRY; do
5733 + echo "entry: $ENTRY"
5734 + META_FILE=`echo $ENTRY | cut -d ' ' -f 1`
5735 + OLD_B_DIR=`echo $ENTRY | cut -d ' ' -f 2 | sed -e 's/\///'`
5736 + NEW_NAME=`echo $ENTRY | cut -d ' ' -f 3`
5737 + NEW_B_DIR=`echo $META_FILE | sed -e "s/$META_NAME/$NEW_NAME/" | sed -e 's/^\.\///'`
5738 + echo "META_FILE: $META_FILE"
5739 + echo "OLD_B_DIR: $OLD_B_DIR"
5740 + echo "NEW_NAME: $NEW_NAME"
5741 + echo "NEW_B_DIR: $NEW_B_DIR"
5743 + pushd $BASE &> /dev/null
5744 + # remove an existing dir in storage
5745 + COMMAND="rm -rf $NEW_B_DIR"; exec_command
5746 + COMMAND="cp -R $OLD_B_DIR $NEW_B_DIR"; exec_command
5750 + # remember this dir to exclude it from deleting later
5751 + echo $NEW_B_DIR >> $TMP/$SKIP_DEL_LIST
5754 +# delete all whiteouted files from base
5755 +echo -e "\nDeleting whiteout'ed files from base file system..."
5756 +find . -name $META_NAME -type f -print0 | xargs -0 -e grep -e '^D ' | sed -e 's/:D//' | while read ENTRY; do
5757 + META_FILE=`echo $ENTRY | cut -d ' ' -f 1`
5758 + DEL_NAME=`echo $ENTRY | cut -d ' ' -f 2`
5759 + DEL_FILE=`echo $META_FILE | sed -e "s/$META_NAME/$DEL_NAME/" | sed -e 's/^\.\///'`
5760 + grep -x $DEL_FILE $TMP/$SKIP_DEL_LIST &> /dev/null
5761 + if [ $? -ne 0 ]; then
5762 + pushd $BASE &> /dev/null
5763 + COMMAND="rm -rf $DEL_FILE"; exec_command
5766 + echo " excluding: $DEL_FILE as in skip-del-list."
5770 +# create all dirs and update permissions
5771 +echo -e "\nSetting up directory structures in base file system..."
5772 +find . -type d | sed -e 's/^\.\///' | while read DIR; do
5773 + PERMS=`stat -c %a $DIR`
5774 + DIR_UID=`stat -c %u $DIR`
5775 + DIR_GID=`stat -c %g $DIR`
5776 + pushd $BASE &> /dev/null
5777 + if ! [ -d $DIR ]; then
5778 + COMMAND="mkdir -p $DIR"; exec_command
5780 + COMMAND="chmod $PERMS $DIR"; exec_command
5781 + COMMAND="chown $DIR_UID:$DIR_GID $DIR"; exec_command
5785 +# merge all non-directory files
5786 +echo -e "\nMerging all non-directory files...."
5787 +for i in b c p f l s; do
5788 + find . -type $i | sed -e 's/^\.\///' | grep -v "$META_NAME" | while read FILE; do
5789 + pushd $BASE #&> /dev/null
5790 + COMMAND="cp -df $STO/$FILE $BASE/$FILE"; exec_command
5796 +#rm $TMP/$SKIP_DEL_LIST
5799 diff -urN linux.old/fs/mini_fo/mini_fo-overlay linux.dev/fs/mini_fo/mini_fo-overlay
5800 --- linux.old/fs/mini_fo/mini_fo-overlay 1970-01-01 01:00:00.000000000 +0100
5801 +++ linux.dev/fs/mini_fo/mini_fo-overlay 2006-11-17 03:11:48.000000000 +0100
5805 +# Copyright (C) 2005 Markus Klotzbuecher <mk@creamnet.de>
5806 +# This program is free software; you can redistribute it and/or
5807 +# modify it under the terms of the GNU General Public License
5808 +# as published by the Free Software Foundation; either version
5809 +# 2 of the License, or (at your option) any later version.
5824 +Usage: $0 [-s suffix] [-d sto_dir_dir] [-m mount point] base_dir
5827 +This script overlays the given base directory using the mini_fo file
5828 +system. If only the base directory base_dir is given, $0
5829 +will use a storage directory called "sto-<base_dir_name>" in $STO_DIR,
5830 +and mount point "mini_fo-<base_dir_dir>" in $MNT_DIR.
5834 + add given suffix to storage directory and the mount
5835 + point. This is usefull for overlaying one base directory
5836 + several times and avoiding conflicts with storage directory
5837 + names and mount points.
5840 + change the directory in which the storage directory will be
5841 + created (default is currently "$STO_DIR".
5844 + use an alternative directory to create the mini_fo
5845 + mountpoint (default is currently "$MNT_DIR".
5847 + -h displays this message.
5853 +while getopts hm:s:d: OPTS
5856 + s) SUFF="$OPTARG";;
5857 + d) STO_DIR="$OPTARG";;
5858 + m) MNT_DIR="$OPTARG";;
5864 +shift $(($OPTIND - 1))
5868 +if [ "x$HELP" == "xset" ]; then
5874 +if [ "x$SUFF" != "x" ]; then
5878 +# kill trailing slashes
5879 +MNT_DIR=${MNT_DIR%/}
5880 +STO_DIR=${STO_DIR%/}
5884 +if ! [ -d "$BASE" ]; then
5885 + echo "invalid base dir $BASE, run $0 -h for help."
5890 +if ! [ -d "$MNT_DIR" ]; then
5891 + echo "invalid mount dir $MNT_DIR, run $0 -h for help."
5895 +if ! [ -d "$STO_DIR" ]; then
5896 + echo "invalid sto_dir_dir $STO_DIR, run $0 -h for help."
5900 +MNTP="$MNT_DIR/mini_fo-`basename $BASE`$SUFF"
5901 +STO="$STO_DIR/sto-`basename $BASE`$SUFF"
5903 +# create the mount point if it doesn't exist
5905 +if [ $? -ne 0 ]; then
5906 + echo "Error, failed to create mount point $MNTP"
5910 +if [ $? -ne 0 ]; then
5911 + echo "Error, failed to create storage dir $STO"
5914 +# check if fs is already mounted
5915 +mount | grep mini_fo | grep $MNTP &> /dev/null
5916 +if [ $? -eq 0 ]; then
5917 + echo "Error, existing mini_fo mount at $MNTP."
5921 +mount | grep mini_fo | grep $STO &> /dev/null
5922 +if [ $? -eq 0 ]; then
5923 + echo "Error, $STO seems to be used already."
5928 +mount -t mini_fo -o base=$BASE,sto=$STO $BASE $MNTP
5930 +if [ $? -ne 0 ]; then
5931 + echo "Error, mounting failed, maybe no permisson to mount?"
5933 diff -urN linux.old/fs/mini_fo/mmap.c linux.dev/fs/mini_fo/mmap.c
5934 --- linux.old/fs/mini_fo/mmap.c 1970-01-01 01:00:00.000000000 +0100
5935 +++ linux.dev/fs/mini_fo/mmap.c 2006-11-17 03:11:48.000000000 +0100
5938 + * Copyright (c) 1997-2003 Erez Zadok
5939 + * Copyright (c) 2001-2003 Stony Brook University
5941 + * For specific licensing information, see the COPYING file distributed with
5942 + * this package, or get one from ftp://ftp.filesystems.org/pub/fist/COPYING.
5944 + * This Copyright notice must be kept intact and distributed with all
5945 + * fistgen sources INCLUDING sources generated by fistgen.
5948 + * Copyright (C) 2004, 2005 Markus Klotzbuecher <mk@creamnet.de>
5950 + * This program is free software; you can redistribute it and/or
5951 + * modify it under the terms of the GNU General Public License
5952 + * as published by the Free Software Foundation; either version
5953 + * 2 of the License, or (at your option) any later version.
5960 +#ifdef HAVE_CONFIG_H
5961 +# include <config.h>
5962 +#endif /* HAVE_CONFIG_H */
5965 +#include "mini_fo.h"
5968 +#ifdef FIST_COUNT_WRITES
5969 +/* for counting writes in the middle vs. regular writes */
5970 +unsigned long count_writes = 0, count_writes_middle = 0;
5971 +#endif /* FIST_COUNT_WRITES */
5973 +/* forward declaration of commit write and prepare write */
5974 +STATIC int mini_fo_commit_write(file_t *file, page_t *page, unsigned from, unsigned to);
5975 +STATIC int mini_fo_prepare_write(file_t *file, page_t *page, unsigned from, unsigned to);
5979 + * Function for handling creation of holes when lseek-ing past the
5980 + * end of the file and then writing some data.
5983 +mini_fo_fill_zeros(file_t* file, page_t *page, unsigned from)
5986 + dentry_t *dentry = file->f_dentry;
5987 + inode_t *inode = dentry->d_inode;
5991 + print_entry_location();
5993 + for (index = inode->i_size >> PAGE_CACHE_SHIFT; index < page->index; index++) {
5994 + tmp_page = mini_fo_get1page(file, index);
5995 + if (IS_ERR(tmp_page)) {
5996 + err = PTR_ERR(tmp_page);
6001 + * zero out rest of the contents of the page between the appropriate
6004 + memset((char*)page_address(tmp_page) + (inode->i_size & ~PAGE_CACHE_MASK), 0, PAGE_CACHE_SIZE - (inode->i_size & ~PAGE_CACHE_MASK));
6006 + if (! (err = mini_fo_prepare_write(file, tmp_page, 0, PAGE_CACHE_SIZE)))
6007 + err = mini_fo_commit_write(file, tmp_page, 0, PAGE_CACHE_SIZE);
6009 + page_cache_release(tmp_page);
6012 + if (current->need_resched)
6016 + /* zero out appropriate parts of last page */
6019 + * if the encoding type is block, then adjust the 'from' (where the
6020 + * zeroing will start) offset appropriately
6022 + from = from & (~(FIST_ENCODING_BLOCKSIZE - 1));
6024 + if ((from - (inode->i_size & ~PAGE_CACHE_MASK)) > 0) {
6026 + memset((char*)page_address(page) + (inode->i_size & ~PAGE_CACHE_MASK), 0, from - (inode->i_size & ~PAGE_CACHE_MASK));
6027 + if (! (err = mini_fo_prepare_write(file, page, 0, PAGE_CACHE_SIZE)))
6028 + err = mini_fo_commit_write(file, page, 0, PAGE_CACHE_SIZE);
6032 + if (current->need_resched)
6037 + print_exit_status(err);
6044 +mini_fo_writepage(page_t *page)
6048 + inode_t *hidden_inode;
6049 + page_t *hidden_page;
6050 + char *kaddr, *hidden_kaddr;
6052 + print_entry_location();
6054 + inode = page->mapping->host;
6055 + hidden_inode = itohi(inode);
6058 + * writepage is called when shared mmap'ed files need to write
6059 + * their pages, while prepare/commit_write are called from the
6060 + * non-paged write() interface. (However, in 2.3 the two interfaces
6061 + * share the same cache, while in 2.2 they didn't.)
6063 + * So we pretty much have to duplicate much of what commit_write does.
6066 + /* find lower page (returns a locked page) */
6067 + hidden_page = grab_cache_page(hidden_inode->i_mapping, page->index);
6071 + /* get page address, and encode it */
6072 + kaddr = (char *) kmap(page);
6073 + hidden_kaddr = (char*) kmap(hidden_page);
6074 + mini_fo_encode_block(kaddr, hidden_kaddr, PAGE_CACHE_SIZE, inode, inode->i_sb, page->index);
6075 + /* if encode_block could fail, then return error */
6077 + kunmap(hidden_page);
6079 + /* call lower writepage (expects locked page) */
6080 + err = hidden_inode->i_mapping->a_ops->writepage(hidden_page);
6083 + * update mtime and ctime of lower level file system
6084 + * mini_fo' mtime and ctime are updated by generic_file_write
6086 + hidden_inode->i_mtime = hidden_inode->i_ctime = CURRENT_TIME;
6088 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,4,1)
6089 + UnlockPage(hidden_page); /* b/c grab_cache_page locked it */
6090 +# endif /* kernel older than 2.4.1 */
6091 + page_cache_release(hidden_page); /* b/c grab_cache_page increased refcnt */
6094 + ClearPageUptodate(page);
6096 + SetPageUptodate(page);
6098 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,1)
6100 +# endif /* kernel 2.4.1 and newer */
6101 + print_exit_status(err);
6107 + * get one page from cache or lower f/s, return error otherwise.
6108 + * returns unlocked, up-to-date page (if ok), with increased refcnt.
6111 +mini_fo_get1page(file_t *file, int index)
6116 + struct address_space *mapping;
6119 + print_entry_location();
6121 + dentry = file->f_dentry; /* CPW: Moved below print_entry_location */
6122 + inode = dentry->d_inode;
6123 + mapping = inode->i_mapping;
6125 + fist_dprint(8, "%s: read page index %d pid %d\n", __FUNCTION__, index, current->pid);
6127 + printk("%s BUG: index=%d\n", __FUNCTION__, index);
6128 + page = ERR_PTR(-EIO);
6131 + page = read_cache_page(mapping,
6133 + (filler_t *) mapping->a_ops->readpage,
6137 + wait_on_page(page);
6138 + if (!Page_Uptodate(page)) {
6140 + err = mapping->a_ops->readpage(file, page);
6142 + page = ERR_PTR(err);
6145 + wait_on_page(page);
6146 + if (!Page_Uptodate(page)) {
6147 + page = ERR_PTR(-EIO);
6153 + print_exit_pointer(page);
6159 + * get one page from cache or lower f/s, return error otherwise.
6160 + * similar to get1page, but doesn't guarantee that it will return
6161 + * an unlocked page.
6164 +mini_fo_get1page_cached(file_t *file, int index)
6169 + struct address_space *mapping;
6172 + print_entry_location();
6174 + dentry = file->f_dentry; /* CPW: Moved below print_entry_location */
6175 + inode = dentry->d_inode;
6176 + mapping = inode->i_mapping;
6178 + fist_dprint(8, "%s: read page index %d pid %d\n", __FUNCTION__, index, current->pid);
6180 + printk("%s BUG: index=%d\n", __FUNCTION__, index);
6181 + page = ERR_PTR(-EIO);
6184 + page = read_cache_page(mapping,
6186 + (filler_t *) mapping->a_ops->readpage,
6192 + print_exit_pointer(page);
6198 + * readpage is called from generic_page_read and the fault handler.
6199 + * If your file system uses generic_page_read for the read op, it
6200 + * must implement readpage.
6202 + * Readpage expects a locked page, and must unlock it.
6205 +mini_fo_do_readpage(file_t *file, page_t *page)
6209 + file_t *hidden_file = NULL;
6210 + dentry_t *hidden_dentry;
6212 + inode_t *hidden_inode;
6214 + page_t *hidden_page;
6215 + char *hidden_page_data;
6218 + print_entry_location();
6220 + dentry = file->f_dentry; /* CPW: Moved below print_entry_location */
6221 + if (ftopd(file) != NULL)
6222 + hidden_file = ftohf(file);
6223 + hidden_dentry = dtohd(dentry);
6224 + inode = dentry->d_inode;
6225 + hidden_inode = itohi(inode);
6227 + fist_dprint(7, "%s: requesting page %d from file %s\n", __FUNCTION__, page->index, dentry->d_name.name);
6229 + MALLOC_PAGE_POINTERS(hidden_pages, num_hidden_pages);
6230 + MALLOC_PAGEDATA_POINTERS(hidden_pages_data, num_hidden_pages);
6232 + CURRENT_HIDDEN_PAGE = NULL;
6234 + /* find lower page (returns a locked page) */
6236 + fist_dprint(8, "%s: Current page index = %d\n", __FUNCTION__, CURRENT_HIDDEN_PAGEINDEX);
6237 + CURRENT_HIDDEN_PAGE = read_cache_page(hidden_inode->i_mapping,
6238 + CURRENT_HIDDEN_PAGEINDEX,
6239 + (filler_t *) hidden_inode->i_mapping->a_ops->readpage,
6240 + (void *) hidden_file);
6241 + if (IS_ERR(CURRENT_HIDDEN_PAGE)) {
6242 + err = PTR_ERR(CURRENT_HIDDEN_PAGE);
6243 + CURRENT_HIDDEN_PAGE = NULL;
6249 + * wait for the page data to show up
6250 + * (signaled by readpage as unlocking the page)
6253 + wait_on_page(CURRENT_HIDDEN_PAGE);
6254 + if (!Page_Uptodate(CURRENT_HIDDEN_PAGE)) {
6256 + * call readpage() again if we returned from wait_on_page with a
6257 + * page that's not up-to-date; that can happen when a partial
6258 + * page has a few buffers which are ok, but not the whole
6261 + lock_page(CURRENT_HIDDEN_PAGE);
6262 + err = hidden_inode->i_mapping->a_ops->readpage(hidden_file,
6263 + CURRENT_HIDDEN_PAGE);
6265 + CURRENT_HIDDEN_PAGE = NULL;
6268 + wait_on_page(CURRENT_HIDDEN_PAGE);
6269 + if (!Page_Uptodate(CURRENT_HIDDEN_PAGE)) {
6276 + /* map pages, get their addresses */
6277 + page_data = (char *) kmap(page);
6279 + CURRENT_HIDDEN_PAGEDATA = (char *) kmap(CURRENT_HIDDEN_PAGE);
6281 + /* if decode_block could fail, then return error */
6283 + real_size = hidden_inode->i_size - (page->index << PAGE_CACHE_SHIFT);
6284 + if (real_size <= 0)
6285 + memset(page_data, 0, PAGE_CACHE_SIZE);
6286 + else if (real_size < PAGE_CACHE_SIZE) {
6287 + mini_fo_decode_block(hidden_page_data, page_data, real_size, inode, inode->i_sb, page->index);
6288 + memset(page_data + real_size, 0, PAGE_CACHE_SIZE - real_size);
6290 + mini_fo_decode_block(hidden_page_data, page_data, PAGE_CACHE_SIZE, inode, inode->i_sb, page->index);
6293 + kunmap(CURRENT_HIDDEN_PAGE);
6298 + if (CURRENT_HIDDEN_PAGE)
6299 + page_cache_release(CURRENT_HIDDEN_PAGE); /* undo read_cache_page */
6301 + FREE_PAGE_POINTERS(hidden_pages, num_hidden_pages);
6302 + FREE_PAGEDATA_POINTERS(hidden_pages_data, num_hidden_pages);
6306 + SetPageUptodate(page);
6308 + ClearPageUptodate(page);
6310 + print_exit_status(err);
6316 +mini_fo_readpage(file_t *file, page_t *page)
6319 + print_entry_location();
6321 + err = mini_fo_do_readpage(file, page);
6324 + * we have to unlock our page, b/c we _might_ have gotten a locked page.
6325 + * but we no longer have to wakeup on our page here, b/c UnlockPage does
6330 + print_exit_status(err);
6336 +mini_fo_prepare_write(file_t *file, page_t *page, unsigned from, unsigned to)
6340 + print_entry_location();
6343 + * we call kmap(page) only here, and do the kunmap
6344 + * and the actual downcalls, including unlockpage and uncache
6345 + * in commit_write.
6349 + /* fast path for whole page writes */
6350 + if (from == 0 && to == PAGE_CACHE_SIZE)
6352 + /* read the page to "revalidate" our data */
6353 + /* call the helper function which doesn't unlock the page */
6354 + if (!Page_Uptodate(page))
6355 + err = mini_fo_do_readpage(file, page);
6358 + print_exit_status(err);
6365 +mini_fo_commit_write(file_t *file, page_t *page, unsigned from, unsigned to)
6367 + int err = -ENOMEM;
6369 + inode_t *hidden_inode;
6370 + page_t *hidden_page;
6371 + file_t *hidden_file = NULL;
6373 + unsigned bytes = to - from;
6374 + unsigned hidden_from, hidden_to, hidden_bytes;
6376 + print_entry_location();
6378 + inode = page->mapping->host; /* CPW: Moved below print_entry_location */
6379 + hidden_inode = itohi(inode);
6381 + ASSERT(file != NULL);
6383 + * here we have a kmapped page, with data from the user copied
6384 + * into it. we need to encode_block it, and then call the lower
6385 + * commit_write. We also need to simulate same behavior of
6386 + * generic_file_write, and call prepare_write on the lower f/s first.
6388 +#ifdef FIST_COUNT_WRITES
6390 +# endif /* FIST_COUNT_WRITES */
6392 + /* this is append and/or extend -- we can't have holes so fill them in */
6393 + if (page->index > (hidden_inode->i_size >> PAGE_CACHE_SHIFT)) {
6396 + for (index = hidden_inode->i_size >> PAGE_CACHE_SHIFT; index < page->index; index++) {
6397 + tmp_page = mini_fo_get1page(file, index);
6398 + if (IS_ERR(tmp_page)) {
6399 + err = PTR_ERR(tmp_page);
6402 + /* zero out the contents of the page at the appropriate offsets */
6403 + memset((char*)page_address(tmp_page) + (inode->i_size & ~PAGE_CACHE_MASK), 0, PAGE_CACHE_SIZE - (inode->i_size & ~PAGE_CACHE_MASK));
6404 + if (!(err = mini_fo_prepare_write(file, tmp_page, 0, PAGE_CACHE_SIZE)))
6405 + err = mini_fo_commit_write(file, tmp_page, 0, PAGE_CACHE_SIZE);
6406 + page_cache_release(tmp_page);
6409 + if (current->need_resched)
6414 + if (ftopd(file) != NULL)
6415 + hidden_file = ftohf(file);
6417 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
6418 + mutex_lock(&hidden_inode->i_mutex);
6420 + down(&hidden_inode->i_sem);
6422 + /* find lower page (returns a locked page) */
6423 + hidden_page = grab_cache_page(hidden_inode->i_mapping, page->index);
6427 +#if FIST_ENCODING_BLOCKSIZE > 1
6428 +# error encoding_blocksize greater than 1 is not yet supported
6429 +# endif /* FIST_ENCODING_BLOCKSIZE > 1 */
6431 + hidden_from = from & (~(FIST_ENCODING_BLOCKSIZE - 1));
6432 + hidden_to = ((to + FIST_ENCODING_BLOCKSIZE - 1) & (~(FIST_ENCODING_BLOCKSIZE - 1)));
6433 + if ((page->index << PAGE_CACHE_SHIFT) + to > hidden_inode->i_size) {
6436 + * if this call to commit_write had introduced holes and the code
6437 + * for handling holes was invoked, then the beginning of this page
6438 + * must be zeroed out
6439 + * zero out bytes from 'size_of_file%pagesize' to 'from'.
6441 + if ((hidden_from - (inode->i_size & ~PAGE_CACHE_MASK)) > 0)
6442 + memset((char*)page_address(page) + (inode->i_size & ~PAGE_CACHE_MASK), 0, hidden_from - (inode->i_size & ~PAGE_CACHE_MASK));
6445 + hidden_bytes = hidden_to - hidden_from;
6447 + /* call lower prepare_write */
6449 + if (hidden_inode->i_mapping &&
6450 + hidden_inode->i_mapping->a_ops &&
6451 + hidden_inode->i_mapping->a_ops->prepare_write)
6452 + err = hidden_inode->i_mapping->a_ops->prepare_write(hidden_file,
6457 + /* don't leave locked pages behind, esp. on an ENOSPC */
6460 + fist_dprint(8, "%s: encoding %d bytes\n", __FUNCTION__, hidden_bytes);
6461 + mini_fo_encode_block((char *) page_address(page) + hidden_from, (char*) page_address(hidden_page) + hidden_from, hidden_bytes, inode, inode->i_sb, page->index);
6462 + /* if encode_block could fail, then goto unlock and return error */
6464 + /* call lower commit_write */
6465 + err = hidden_inode->i_mapping->a_ops->commit_write(hidden_file,
6473 + err = bytes; /* convert error to no. of bytes */
6475 + inode->i_blocks = hidden_inode->i_blocks;
6476 + /* we may have to update i_size */
6477 + pos = (page->index << PAGE_CACHE_SHIFT) + to;
6478 + if (pos > inode->i_size)
6479 + inode->i_size = pos;
6482 + * update mtime and ctime of lower level file system
6483 + * mini_fo' mtime and ctime are updated by generic_file_write
6485 + hidden_inode->i_mtime = hidden_inode->i_ctime = CURRENT_TIME;
6487 + mark_inode_dirty_sync(inode);
6490 + UnlockPage(hidden_page);
6491 + page_cache_release(hidden_page);
6492 + kunmap(page); /* kmap was done in prepare_write */
6494 + /* we must set our page as up-to-date */
6496 + ClearPageUptodate(page);
6498 + SetPageUptodate(page);
6500 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
6501 + mutex_unlock(&hidden_inode->i_mutex);
6503 + up(&hidden_inode->i_sem);
6505 + print_exit_status(err);
6506 + return err; /* assume all is ok */
6511 +mini_fo_bmap(struct address_space *mapping, long block)
6515 + inode_t *hidden_inode;
6517 + print_entry_location();
6519 + inode = (inode_t *) mapping->host;
6520 + hidden_inode = itohi(inode);
6522 + if (hidden_inode->i_mapping->a_ops->bmap)
6523 + err = hidden_inode->i_mapping->a_ops->bmap(hidden_inode->i_mapping, block);
6524 + print_exit_location();
6530 + * This function is copied verbatim from mm/filemap.c.
6531 + * XXX: It should be simply moved to some header file instead -- bug Al about it!
6533 +static inline int sync_page(struct page *page)
6535 + struct address_space *mapping = page->mapping;
6537 + if (mapping && mapping->a_ops && mapping->a_ops->sync_page)
6538 + return mapping->a_ops->sync_page(page);
6544 + * XXX: we may not need this function if not FIST_FILTER_DATA.
6545 + * FIXME: for FIST_FILTER_SCA, get all lower pages and sync them each.
6548 +mini_fo_sync_page(page_t *page)
6552 + inode_t *hidden_inode;
6553 + page_t *hidden_page;
6555 + print_entry_location();
6557 + inode = page->mapping->host; /* CPW: Moved below print_entry_location */
6558 + hidden_inode = itohi(inode);
6560 + /* find lower page (returns a locked page) */
6561 + hidden_page = grab_cache_page(hidden_inode->i_mapping, page->index);
6565 + err = sync_page(hidden_page);
6567 + UnlockPage(hidden_page); /* b/c grab_cache_page locked it */
6568 + page_cache_release(hidden_page); /* b/c grab_cache_page increased refcnt */
6571 + print_exit_status(err);
6574 diff -urN linux.old/fs/mini_fo/README linux.dev/fs/mini_fo/README
6575 --- linux.old/fs/mini_fo/README 1970-01-01 01:00:00.000000000 +0100
6576 +++ linux.dev/fs/mini_fo/README 2006-11-17 03:11:48.000000000 +0100
6578 +README for the mini_fo overlay file system
6579 +=========================================
6585 +mini_fo is a virtual kernel file system that can make read-only
6586 +file systems writable. This is done by redirecting modifying operations
6587 +to a writeable location called "storage directory", and leaving the
6588 +original data in the "base directory" untouched. When reading, the
6589 +file system merges the modifed and original data so that only the
6590 +newest versions will appear. This occurs transparently to the user,
6591 +who can access the data like on any other read-write file system.
6593 +Base and storage directories may be located on the same or on
6594 +different partitions and may be of different file system types. While
6595 +the storage directory obviously needs to be writable, the base may or
6596 +may not be writable, what doesn't matter as it will no be modified
6603 +The primary purpose of the mini_fo file system is to allow easy
6604 +software updates to embedded systems, that often store their root
6605 +file system in a read-only flash file system, but there are many
6606 +more as for example sandboxing, or for allowing live-cds to
6607 +permanently store information.
6612 +This should be simple. Adjust the Makefile to point to the correct
6613 +kernel headers you want to build the module for. Then:
6617 +should build "mini_fo.o" for a 2.4 kernel or "mini_fo.ko" for a 2.6
6620 +If you are building the module for you current kernel, you can install
6621 +the module (as root):
6630 +USING THE FILE SYSTEM
6631 +--------------------
6633 +the general mount syntax is:
6635 + mount -t mini_fo -o base=<base directory>,sto=<storage directory>\
6636 + <base directory> <mount point>
6640 +You have mounted a cdrom to /mnt/cdrom and want to modifiy some files
6643 +load the module (as root)
6645 + # insmod mini_fo.o for a 2.4 kernel or
6647 + # insmod mini_fo.ko for a 2.6 kernel
6650 +create a storage dir in tmp and a mountpoint for mini_fo:
6653 + # mkdir /mnt/mini_fo
6655 +and mount the mini_fo file system:
6657 + # mount -t mini_fo -o base=/mnt/cdrom,sto=/tmp/sto /mnt/cdrom /mnt/mini_fo
6660 +Now the data stored on the cd can be accessed via the mini_fo
6661 +mountpoint just like any read-write file system, files can be modified
6662 +and deleted, new ones can be created and so on. When done unmount the
6665 + # unmount /mnt/mini_fo
6667 +Note that if the file system is mounted again using the same storage
6668 +file system, of course it will appear in the modified state again. If
6669 +you remount it using an new empty storage directory, it will be
6670 +unmodified. Therefore by executing:
6675 +you can nuke all the changes you made to the original file system. But
6676 + remember NEVER do this while the mini_fo file system is mounted!
6679 +Alternatively you can use the mini_fo-overlay bash script, that
6680 +simplifies managing mini_fo mounts. See TOOLS Section.
6686 +mini_fo-merge (experimental):
6688 +This is a bash script that will merge changes contained in the storage
6689 +directory back to the base directory. This allows mini_fo to function
6690 +as a cache file system by overlaying a slow (network, ...) file system
6691 +and using a fast (ramdisk, ...) as storage. When done, changes can be
6692 +merged back to the (slow) base with mini_fo-merge. See "mini_fo-merge
6695 +It can be usefull for merging changes back after a successfull test
6696 +(patches, software updates...)
6701 +This bash script simplifies managing one or more mini_fo mounts. For
6702 +overlaying a directory called "basedir1", you can just call:
6704 + # mini_fo-overlay basedir1
6706 +This will mount mini_fo with "basedir1" as base, "/tmp/sto-basedir1/"
6707 +as storage to "/mnt/mini_fo-basedir1/". It has more options though,
6708 +type "mini_fo-overlay -h" for details.
6711 +DOCUMENTATION, REPORTING BUGS, GETTING HELP
6712 +-------------------------------------------
6714 +Please visit the mini_fo project page at:
6716 +http://www.denx.de/twiki/bin/view/Know/MiniFOHome
6722 +Never modify the base or the storage directorys while the mini_fo
6723 +file system is mounted, or you might crash you system. Simply accessing
6724 +and reading should not cause any trouble.
6726 +Exporting a mini_fo mount point via NFS has not been tested, and may
6729 +Check the RELEASE_NOTES for details on bugs and features.
6733 +Copyright (C) 2004, 2005 Markus Klotzbuecher <mk@creamnet.de>
6735 +This program is free software; you can redistribute it and/or
6736 +modify it under the terms of the GNU General Public License
6737 +as published by the Free Software Foundation; either version
6738 +2 of the License, or (at your option) any later version.
6741 diff -urN linux.old/fs/mini_fo/RELEASE_NOTES linux.dev/fs/mini_fo/RELEASE_NOTES
6742 --- linux.old/fs/mini_fo/RELEASE_NOTES 1970-01-01 01:00:00.000000000 +0100
6743 +++ linux.dev/fs/mini_fo/RELEASE_NOTES 2006-11-17 03:11:48.000000000 +0100
6745 +Release: mini_fo-0.6.1 (v0-6-1)
6753 +- bugfixes (see ChangeLog)
6755 +- two helper scripts "mini_fo_merge" and "mini_fo_overlay" (see
6756 + README for details).
6760 +- Support for 2.4 and 2.6 (see Makefile)
6762 +- Partial hard link support (creating works as expected, but already
6763 + existing links in the base file system will be treated as if they
6764 + were individual files).
6766 +- Various bugfixes and cleanups.
6771 +- This is mini_fo-0-6-0-pre1! This release is a complete rewrite of
6772 + many vital mini_fo parts such as the old whiteout list code which
6773 + has been replaced by the new META subsystem.
6775 +- Light weight directory renaming implemented. This means if a
6776 + directory is renamed via the mini_fo filesystem this will no longer
6777 + result in a complete copy in storage, instead only one empty
6778 + directory will be created. All base filed contained in the original
6779 + directory stay there until modified.
6781 +- Special files (creating, renaming, deleting etc.) now working.
6783 +- Many bugfixes and cleanup, mini_fo is now a lot more stable.
6788 +- Final release of the 0-5-* versions. Next will be a complete rewrite
6789 + of many features. This release contains several bugfixes related to
6790 + directory renaming.
6795 +- Lots of cleanup and several bugfixes related to directory deleting
6797 +- Directory renaming suddenly works, what is most likely due to the
6798 + fact tha that "mv" is smart: if the classic rename doesn't work it
6799 + will assume that source and target file are on different fs and will
6800 + copy the directory and try to remove the source directory. Until
6801 + directory removing wasn't implemented, it would fail to do this and
6803 + So, directory renaming works for now, but it doesn't yet do what you
6804 + would expect from a overlay fs, so use with care.
6809 +- implemented directory deleting
6810 +- made parsing of mount options more stable
6811 +- New format of mount options! (See README)
6812 +- I can't reproduce the unknown panic with 2.4.25 anymore, so I'll
6813 + happily assume it never existed!
6816 +Implemented features:
6817 +---------------------
6819 +- creating hard links (see BUGS on already existing hard links)
6820 +- lightweight directory renaming
6821 +- renaming device files, pipes, sockets, etc.
6822 +- creating, renaming, deleting of special files
6823 +- deleting directorys
6824 +- general directory reading (simple "ls" )
6825 +- creating files in existing directorys
6826 +- creating directorys
6828 +- reading and writing files (involves opening)
6829 +- appending to files (creates copy in storage)
6831 +- llseek works too, what allows editors to work
6832 +- persistency (a deleted file stay deleted over remounts)
6833 +- use of symbolic links
6834 +- creating of device files
6837 +Not (yet) implemented features:
6838 +-------------------------------
6840 +- full hard link support.
6847 +Hard links in the base file system will be treated as individual
6848 +files, not as links to one inode.
6850 +The main problem with hard links isn't allowing to create them, but
6851 +their pure existence. If you modify a base hard link, the changes made
6852 +will only show up on this link, the other link will remain in the
6853 +original state. I hope to fix this someday. Please note that this does
6854 +not effect the special hard links '.' and '..', that are handled
6855 +seperately by the lower fs.
6856 diff -urN linux.old/fs/mini_fo/state.c linux.dev/fs/mini_fo/state.c
6857 --- linux.old/fs/mini_fo/state.c 1970-01-01 01:00:00.000000000 +0100
6858 +++ linux.dev/fs/mini_fo/state.c 2006-11-17 03:11:48.000000000 +0100
6861 + * Copyright (C) 2005 Markus Klotzbuecher <mk@creamnet.de>
6863 + * This program is free software; you can redistribute it and/or
6864 + * modify it under the terms of the GNU General Public License
6865 + * as published by the Free Software Foundation; either version
6866 + * 2 of the License, or (at your option) any later version.
6869 +#ifdef HAVE_CONFIG_H
6870 +# include <config.h>
6871 +#endif /* HAVE_CONFIG_H */
6874 +#include "mini_fo.h"
6877 +/* create the storage file, setup new states */
6878 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
6879 +int create_sto_reg_file(dentry_t *dentry, int mode, struct nameidata *nd)
6881 +int create_sto_reg_file(dentry_t *dentry, int mode)
6886 + dentry_t *hidden_sto_dentry;
6887 + dentry_t *hidden_sto_dir_dentry;
6889 + if(exists_in_storage(dentry)) {
6890 + printk(KERN_CRIT "mini_fo: create_sto_file: wrong type or state.\n");
6894 + err = get_neg_sto_dentry(dentry);
6897 + printk(KERN_CRIT "mini_fo: create_sto_file: ERROR getting neg. sto dentry.\n");
6901 + dir = dentry->d_parent->d_inode;
6902 + hidden_sto_dentry = dtohd2(dentry);
6905 + hidden_sto_dir_dentry = dget(hidden_sto_dentry->d_parent);
6907 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
6908 + mutex_lock(&hidden_sto_dir_dentry->d_inode->i_mutex);
6910 + down(&hidden_sto_dir_dentry->d_inode->i_sem);
6913 + err = PTR_ERR(hidden_sto_dir_dentry);
6914 + if (IS_ERR(hidden_sto_dir_dentry))
6917 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
6918 + err = vfs_create(hidden_sto_dir_dentry->d_inode,
6919 + hidden_sto_dentry,
6922 + err = vfs_create(hidden_sto_dir_dentry->d_inode,
6923 + hidden_sto_dentry,
6927 + printk(KERN_CRIT "mini_fo: create_sto_file: ERROR creating sto file.\n");
6931 + if(!dtohd2(dentry)->d_inode) {
6932 + printk(KERN_CRIT "mini_fo: create_sto_file: ERROR creating sto file [2].\n");
6937 + /* interpose the new inode */
6938 + if(dtost(dentry) == DELETED) {
6939 + dtost(dentry) = DEL_REWRITTEN;
6940 + err = mini_fo_tri_interpose(NULL, hidden_sto_dentry, dentry, dir->i_sb, 0);
6944 + else if(dtost(dentry) == NON_EXISTANT) {
6945 + dtost(dentry) = CREATED;
6946 + err = mini_fo_tri_interpose(dtohd(dentry), hidden_sto_dentry, dentry, dir->i_sb, 0);
6950 + else if(dtost(dentry) == UNMODIFIED) {
6951 + dtost(dentry) = MODIFIED;
6952 + /* interpose on new inode */
6953 + if(itohi2(dentry->d_inode) != NULL) {
6954 + printk(KERN_CRIT "mini_fo: create_sto_file: invalid inode detected.\n");
6958 + itohi2(dentry->d_inode) = igrab(dtohd2(dentry)->d_inode);
6960 + fist_copy_attr_timesizes(dentry->d_parent->d_inode,
6961 + hidden_sto_dir_dentry->d_inode);
6964 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
6965 + mutex_unlock(&hidden_sto_dir_dentry->d_inode->i_mutex);
6967 + up(&hidden_sto_dir_dentry->d_inode->i_sem);
6969 + dput(hidden_sto_dir_dentry);
6974 +/* create the sto dir, setup states */
6975 +int create_sto_dir(dentry_t *dentry, int mode)
6979 + dentry_t *hidden_sto_dentry;
6980 + dentry_t *hidden_sto_dir_dentry;
6982 + /* had to take the "!S_ISDIR(mode))" check out, because it failed */
6983 + if(exists_in_storage(dentry)) {
6984 + printk(KERN_CRIT "mini_fo: create_sto_dir: wrong type or state.\\
6990 + err = get_neg_sto_dentry(dentry);
6996 + dir = dentry->d_parent->d_inode;
6997 + hidden_sto_dentry = dtohd2(dentry);
6999 + /* was: hidden_sto_dir_dentry = lock_parent(hidden_sto_dentry); */
7000 + hidden_sto_dir_dentry = dget(hidden_sto_dentry->d_parent);
7002 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
7003 + mutex_lock(&hidden_sto_dir_dentry->d_inode->i_mutex);
7005 + down(&hidden_sto_dir_dentry->d_inode->i_sem);
7008 + err = PTR_ERR(hidden_sto_dir_dentry);
7009 + if (IS_ERR(hidden_sto_dir_dentry))
7012 + err = vfs_mkdir(hidden_sto_dir_dentry->d_inode,
7013 + hidden_sto_dentry,
7016 + printk(KERN_CRIT "mini_fo: create_sto_dir: ERROR creating sto dir.\n");
7020 + if(!dtohd2(dentry)->d_inode) {
7021 + printk(KERN_CRIT "mini_fo: create_sto_dir: ERROR creating sto dir [2].\n");
7026 + /* interpose the new inode */
7027 + if(dtost(dentry) == DELETED) {
7028 + dtost(dentry) = DEL_REWRITTEN;
7029 + err = mini_fo_tri_interpose(NULL, hidden_sto_dentry, dentry, dir->i_sb, 0);
7033 + else if(dtopd(dentry)->state == NON_EXISTANT) {
7034 + dtopd(dentry)->state = CREATED;
7035 + err = mini_fo_tri_interpose(dtohd(dentry), hidden_sto_dentry, dentry, dir->i_sb, 0);
7039 + else if(dtopd(dentry)->state == UNMODIFIED) {
7040 + dtopd(dentry)->state = MODIFIED;
7041 + /* interpose on new inode */
7042 + if(itohi2(dentry->d_inode) != NULL) {
7043 + printk(KERN_CRIT "mini_fo: create_sto_dir: ERROR, invalid inode detected.\n");
7047 + itohi2(dentry->d_inode) = igrab(dtohd2(dentry)->d_inode);
7050 + fist_copy_attr_timesizes(dir, hidden_sto_dir_dentry->d_inode);
7052 + /* initalize the wol list */
7053 + itopd(dentry->d_inode)->deleted_list_size = -1;
7054 + itopd(dentry->d_inode)->renamed_list_size = -1;
7055 + meta_build_lists(dentry);
7059 + /* was: unlock_dir(hidden_sto_dir_dentry); */
7060 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
7061 + mutex_unlock(&hidden_sto_dir_dentry->d_inode->i_mutex);
7063 + up(&hidden_sto_dir_dentry->d_inode->i_sem);
7065 + dput(hidden_sto_dir_dentry);
7070 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
7071 +int create_sto_nod(dentry_t *dentry, int mode, dev_t dev)
7073 +int create_sto_nod(dentry_t *dentry, int mode, int dev)
7078 + dentry_t *hidden_sto_dentry;
7079 + dentry_t *hidden_sto_dir_dentry;
7081 + if(exists_in_storage(dentry)) {
7085 + err = get_neg_sto_dentry(dentry);
7088 + printk(KERN_CRIT "mini_fo: create_sto_nod: ERROR getting neg. sto dentry.\n");
7092 + dir = dentry->d_parent->d_inode;
7093 + hidden_sto_dentry = dtohd2(dentry);
7096 + hidden_sto_dir_dentry = dget(hidden_sto_dentry->d_parent);
7098 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
7099 + mutex_lock(&hidden_sto_dir_dentry->d_inode->i_mutex);
7101 + down(&hidden_sto_dir_dentry->d_inode->i_sem);
7104 + err = PTR_ERR(hidden_sto_dir_dentry);
7105 + if (IS_ERR(hidden_sto_dir_dentry))
7108 + err = vfs_mknod(hidden_sto_dir_dentry->d_inode, hidden_sto_dentry, mode, dev);
7112 + if(!dtohd2(dentry)->d_inode) {
7113 + printk(KERN_CRIT "mini_fo: create_sto_nod: creating storage inode failed [1].\n");
7114 + err = -EINVAL; /* return something indicating failure */
7118 + /* interpose the new inode */
7119 + if(dtost(dentry) == DELETED) {
7120 + dtost(dentry) = DEL_REWRITTEN;
7121 + err = mini_fo_tri_interpose(NULL, hidden_sto_dentry, dentry, dir->i_sb, 0);
7125 + else if(dtost(dentry) == NON_EXISTANT) {
7126 + dtost(dentry) = CREATED;
7127 + err = mini_fo_tri_interpose(dtohd(dentry), hidden_sto_dentry, dentry, dir->i_sb, 0);
7131 + else if(dtost(dentry) == UNMODIFIED) {
7132 + dtost(dentry) = MODIFIED;
7133 + /* interpose on new inode */
7134 + if(itohi2(dentry->d_inode) != NULL) {
7135 + printk(KERN_CRIT "mini_fo: create_sto_nod: error, invalid inode detected.\n");
7139 + itohi2(dentry->d_inode) = igrab(dtohd2(dentry)->d_inode);
7142 + fist_copy_attr_timesizes(dir, hidden_sto_dir_dentry->d_inode);
7145 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
7146 + mutex_unlock(&hidden_sto_dir_dentry->d_inode->i_mutex);
7148 + up(&hidden_sto_dir_dentry->d_inode->i_sem);
7150 + dput(hidden_sto_dir_dentry);
7156 +/* unimplemented (and possibly not usefull):
7158 + nondir-del_to_del_rew
7159 + nondir-non_exist_to_creat
7164 + dir-del_rew_to_del
7165 + dir-del_to_del_rew
7166 + dir-non_exist_to_creat
7170 +/* bring a file of any type from state UNMODIFIED to MODIFIED */
7171 +int nondir_unmod_to_mod(dentry_t *dentry, int cp_flag)
7174 + struct vfsmount *tgt_mnt;
7175 + struct vfsmount *src_mnt;
7176 + dentry_t *tgt_dentry;
7177 + dentry_t *src_dentry;
7178 + dentry_t *hidden_sto_dentry;
7179 + dentry_t *hidden_sto_dir_dentry;
7181 + check_mini_fo_dentry(dentry);
7183 + if((dtost(dentry) != UNMODIFIED) ||
7184 + S_ISDIR(dentry->d_inode->i_mode)) {
7185 + printk(KERN_CRIT "mini_fo: nondir_unmod_to_mod: \
7186 + wrong type or state.\n");
7190 + err = get_neg_sto_dentry(dentry);
7193 + printk(KERN_CRIT "mini_fo: nondir_unmod_to_mod: \
7194 + ERROR getting neg. sto dentry.\n");
7198 + /* create sto file */
7199 + hidden_sto_dentry = dtohd2(dentry);
7202 + hidden_sto_dir_dentry = dget(hidden_sto_dentry->d_parent);
7204 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
7205 + mutex_lock(&hidden_sto_dir_dentry->d_inode->i_mutex);
7207 + down(&hidden_sto_dir_dentry->d_inode->i_sem);
7210 + err = PTR_ERR(hidden_sto_dir_dentry);
7211 + if (IS_ERR(hidden_sto_dir_dentry))
7214 + /* handle different types of nondirs */
7215 + if(S_ISCHR(dentry->d_inode->i_mode) ||
7216 + S_ISBLK(dentry->d_inode->i_mode)) {
7217 + err = vfs_mknod(hidden_sto_dir_dentry->d_inode,
7218 + hidden_sto_dentry,
7219 + dtohd(dentry)->d_inode->i_mode,
7220 + dtohd(dentry)->d_inode->i_rdev);
7223 + else if(S_ISREG(dentry->d_inode->i_mode)) {
7225 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
7226 + err = vfs_create(hidden_sto_dir_dentry->d_inode,
7227 + hidden_sto_dentry,
7228 + dtohd(dentry)->d_inode->i_mode, NULL);
7230 + err = vfs_create(hidden_sto_dir_dentry->d_inode,
7231 + hidden_sto_dentry,
7232 + dtohd(dentry)->d_inode->i_mode);
7236 + printk(KERN_CRIT "mini_fo: nondir_unmod_to_mod: \
7237 + ERROR creating sto file.\n");
7241 + /* interpose on new inode */
7242 + if(itohi2(dentry->d_inode) != NULL) {
7243 + printk(KERN_CRIT "mini_fo: nondir_unmod_to_mod: \
7244 + ERROR, invalid inode detected.\n");
7249 + itohi2(dentry->d_inode) = igrab(dtohd2(dentry)->d_inode);
7251 + fist_copy_attr_timesizes(dentry->d_parent->d_inode,
7252 + hidden_sto_dir_dentry->d_inode);
7253 + dtost(dentry) = MODIFIED;
7255 + /* copy contents if regular file and cp_flag = 1 */
7256 + if((cp_flag == 1) && S_ISREG(dentry->d_inode->i_mode)) {
7258 + /* unlock first */
7259 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
7260 + mutex_unlock(&hidden_sto_dir_dentry->d_inode->i_mutex);
7262 + up(&hidden_sto_dir_dentry->d_inode->i_sem);
7265 + dput(hidden_sto_dir_dentry);
7267 + tgt_dentry = dtohd2(dentry);
7268 + tgt_mnt = stopd(dentry->d_inode->i_sb)->hidden_mnt2;
7269 + src_dentry = dtohd(dentry);
7270 + src_mnt = stopd(dentry->d_inode->i_sb)->hidden_mnt;
7272 + err = mini_fo_cp_cont(tgt_dentry, tgt_mnt,
7273 + src_dentry, src_mnt);
7275 + printk(KERN_CRIT "mini_fo: nondir_unmod_to_mod: \
7276 + ERROR copying contents.\n");
7282 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
7283 + mutex_unlock(&hidden_sto_dir_dentry->d_inode->i_mutex);
7285 + up(&hidden_sto_dir_dentry->d_inode->i_sem);
7287 + dput(hidden_sto_dir_dentry);
7292 +/* this function is currently identical to nondir_creat_to_del */
7293 +int nondir_del_rew_to_del(dentry_t *dentry)
7295 + return nondir_creat_to_del(dentry);
7298 +int nondir_creat_to_del(dentry_t *dentry)
7302 + inode_t *hidden_sto_dir_inode;
7303 + dentry_t *hidden_sto_dir_dentry;
7304 + dentry_t *hidden_sto_dentry;
7306 + check_mini_fo_dentry(dentry);
7308 + /* for now this function serves for both state DEL_REWRITTEN and
7310 + if(!(dtost(dentry) == CREATED || (dtost(dentry) == DEL_REWRITTEN)) ||
7311 + S_ISDIR(dentry->d_inode->i_mode)) {
7312 + printk(KERN_CRIT "mini_fo: nondir_mod_to_del/del_rew_to_del: \
7313 + wrong type or state.\n");
7318 + hidden_sto_dir_inode = itohi2(dentry->d_parent->d_inode);
7319 + hidden_sto_dentry = dtohd2(dentry);
7321 + /* was: hidden_sto_dir_dentry = lock_parent(hidden_sto_dentry);*/
7322 + hidden_sto_dir_dentry = dget(hidden_sto_dentry->d_parent);
7324 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
7325 + mutex_lock(&hidden_sto_dir_dentry->d_inode->i_mutex);
7327 + down(&hidden_sto_dir_dentry->d_inode->i_sem);
7330 + /* avoid destroying the hidden inode if the file is in use */
7331 + dget(hidden_sto_dentry);
7332 + err = vfs_unlink(hidden_sto_dir_inode, hidden_sto_dentry);
7333 + dput(hidden_sto_dentry);
7335 + d_delete(hidden_sto_dentry);
7337 + /* propagate number of hard-links */
7338 + dentry->d_inode->i_nlink = itohi2(dentry->d_inode)->i_nlink;
7340 + dtost(dentry) = NON_EXISTANT;
7342 + /* was: unlock_dir(hidden_sto_dir_dentry); */
7343 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
7344 + mutex_unlock(&hidden_sto_dir_dentry->d_inode->i_mutex);
7346 + up(&hidden_sto_dir_dentry->d_inode->i_sem);
7348 + dput(hidden_sto_dir_dentry);
7354 +int nondir_mod_to_del(dentry_t *dentry)
7357 + dentry_t *hidden_sto_dentry;
7358 + inode_t *hidden_sto_dir_inode;
7359 + dentry_t *hidden_sto_dir_dentry;
7361 + check_mini_fo_dentry(dentry);
7363 + if(dtost(dentry) != MODIFIED ||
7364 + S_ISDIR(dentry->d_inode->i_mode)) {
7365 + printk(KERN_CRIT "mini_fo: nondir_mod_to_del: \
7366 + wrong type or state.\n");
7371 + hidden_sto_dir_inode = itohi2(dentry->d_parent->d_inode);
7372 + hidden_sto_dentry = dtohd2(dentry);
7374 + /* was hidden_sto_dir_dentry = lock_parent(hidden_sto_dentry); */
7375 + hidden_sto_dir_dentry = dget(hidden_sto_dentry->d_parent);
7377 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
7378 + mutex_lock(&hidden_sto_dir_dentry->d_inode->i_mutex);
7380 + down(&hidden_sto_dir_dentry->d_inode->i_sem);
7383 + /* avoid destroying the hidden inode if the file is in use */
7384 + dget(hidden_sto_dentry);
7385 + err = vfs_unlink(hidden_sto_dir_inode, hidden_sto_dentry);
7386 + dput(hidden_sto_dentry);
7388 + d_delete(hidden_sto_dentry);
7390 + /* propagate number of hard-links */
7391 + dentry->d_inode->i_nlink = itohi2(dentry->d_inode)->i_nlink;
7393 + /* dput base dentry, this will relase the inode and free the
7394 + * dentry, as we will never need it again. */
7395 + dput(dtohd(dentry));
7396 + dtohd(dentry) = NULL;
7397 + dtost(dentry) = DELETED;
7399 + /* add deleted file to META-file */
7400 + meta_add_d_entry(dentry->d_parent,
7401 + dentry->d_name.name,
7402 + dentry->d_name.len);
7404 + /* was: unlock_dir(hidden_sto_dir_dentry); */
7405 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
7406 + mutex_unlock(&hidden_sto_dir_dentry->d_inode->i_mutex);
7408 + up(&hidden_sto_dir_dentry->d_inode->i_sem);
7410 + dput(hidden_sto_dir_dentry);
7416 +int nondir_unmod_to_del(dentry_t *dentry)
7420 + check_mini_fo_dentry(dentry);
7422 + if(dtost(dentry) != UNMODIFIED ||
7423 + S_ISDIR(dentry->d_inode->i_mode)) {
7424 + printk(KERN_CRIT "mini_fo: nondir_unmod_to_del: \
7425 + wrong type or state.\n");
7430 + /* next we have to get a negative dentry for the storage file */
7431 + err = get_neg_sto_dentry(dentry);
7436 + /* add deleted file to META lists */
7437 + err = meta_add_d_entry(dentry->d_parent,
7438 + dentry->d_name.name,
7439 + dentry->d_name.len);
7444 + /* dput base dentry, this will relase the inode and free the
7445 + * dentry, as we will never need it again. */
7446 + dput(dtohd(dentry));
7447 + dtohd(dentry) = NULL;
7448 + dtost(dentry) = DELETED;
7454 +/* bring a dir from state UNMODIFIED to MODIFIED */
7455 +int dir_unmod_to_mod(dentry_t *dentry)
7459 + check_mini_fo_dentry(dentry);
7461 + if(dtost(dentry) != UNMODIFIED ||
7462 + !S_ISDIR(dentry->d_inode->i_mode)) {
7463 + printk(KERN_CRIT "mini_fo: dir_unmod_to_mod: \
7464 + wrong type or state.\n");
7469 + /* this creates our dir incl. sto. structure */
7470 + err = build_sto_structure(dentry->d_parent, dentry);
7472 + printk(KERN_CRIT "mini_fo: dir_unmod_to_mod: \
7473 + build_sto_structure failed.\n");
7480 diff -urN linux.old/fs/mini_fo/super.c linux.dev/fs/mini_fo/super.c
7481 --- linux.old/fs/mini_fo/super.c 1970-01-01 01:00:00.000000000 +0100
7482 +++ linux.dev/fs/mini_fo/super.c 2006-11-17 03:11:48.000000000 +0100
7485 + * Copyright (c) 1997-2003 Erez Zadok
7486 + * Copyright (c) 2001-2003 Stony Brook University
7488 + * For specific licensing information, see the COPYING file distributed with
7489 + * this package, or get one from ftp://ftp.filesystems.org/pub/fist/COPYING.
7491 + * This Copyright notice must be kept intact and distributed with all
7492 + * fistgen sources INCLUDING sources generated by fistgen.
7495 + * Copyright (C) 2004, 2005 Markus Klotzbuecher <mk@creamnet.de>
7497 + * This program is free software; you can redistribute it and/or
7498 + * modify it under the terms of the GNU General Public License
7499 + * as published by the Free Software Foundation; either version
7500 + * 2 of the License, or (at your option) any later version.
7507 +#ifdef HAVE_CONFIG_H
7508 +# include <config.h>
7512 +#include "mini_fo.h"
7516 +mini_fo_read_inode(inode_t *inode)
7518 + static struct address_space_operations mini_fo_empty_aops;
7520 + __itopd(inode) = kmalloc(sizeof(struct mini_fo_inode_info), GFP_KERNEL);
7521 + if (!itopd(inode)) {
7522 + printk("<0>%s:%s:%d: No kernel memory!\n", __FILE__, __FUNCTION__, __LINE__);
7525 + itohi(inode) = NULL;
7526 + itohi2(inode) = NULL;
7528 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
7529 + inode->i_version++;
7531 + inode->i_version = ++event; /* increment inode version */
7533 + inode->i_op = &mini_fo_main_iops;
7534 + inode->i_fop = &mini_fo_main_fops;
7537 + * XXX: To export a file system via NFS, it has to have the
7538 + * FS_REQUIRES_DEV flag, so turn it on. But should we inherit it from
7539 + * the lower file system, or can we allow our file system to be exported
7540 + * even if the lower one cannot be natively exported.
7542 + inode->i_sb->s_type->fs_flags |= FS_REQUIRES_DEV;
7544 + * OK, the above was a hack, which is now turned off because it may
7545 + * cause a panic/oops on some systems. The correct way to export a
7546 + * "nodev" filesystem is via using nfs-utils > 1.0 and the "fsid=" export
7547 + * parameter, which requires 2.4.20 or later.
7550 + /* I don't think ->a_ops is ever allowed to be NULL */
7551 + inode->i_mapping->a_ops = &mini_fo_empty_aops;
7555 +#if defined(FIST_DEBUG) || defined(FIST_FILTER_SCA)
7557 + * No need to call write_inode() on the lower inode, as it
7558 + * will have been marked 'dirty' anyway. But we might need
7559 + * to write some of our own stuff to disk.
7562 +mini_fo_write_inode(inode_t *inode, int sync)
7564 + print_entry_location();
7565 + print_exit_location();
7567 +#endif /* defined(FIST_DEBUG) || defined(FIST_FILTER_SCA) */
7571 +mini_fo_put_inode(inode_t *inode)
7574 + * This is really funky stuff:
7575 + * Basically, if i_count == 1, iput will then decrement it and this inode will be destroyed.
7576 + * It is currently holding a reference to the hidden inode.
7577 + * Therefore, it needs to release that reference by calling iput on the hidden inode.
7578 + * iput() _will_ do it for us (by calling our clear_inode), but _only_ if i_nlink == 0.
7579 + * The problem is, NFS keeps i_nlink == 1 for silly_rename'd files.
7580 + * So we must for our i_nlink to 0 here to trick iput() into calling our clear_inode.
7582 + if (atomic_read(&inode->i_count) == 1)
7583 + inode->i_nlink = 0;
7587 +#if defined(FIST_DEBUG) || defined(FIST_FILTER_SCA)
7589 + * we now define delete_inode, because there are two VFS paths that may
7590 + * destroy an inode: one of them calls clear inode before doing everything
7591 + * else that's needed, and the other is fine. This way we truncate the inode
7592 + * size (and its pages) and then clear our own inode, which will do an iput
7593 + * on our and the lower inode.
7596 +mini_fo_delete_inode(inode_t *inode)
7598 + print_entry_location();
7600 + fist_checkinode(inode, "mini_fo_delete_inode IN");
7601 + inode->i_size = 0; /* every f/s seems to do that */
7602 + clear_inode(inode);
7604 + print_exit_location();
7606 +#endif /* defined(FIST_DEBUG) || defined(FIST_FILTER_SCA) */
7609 +/* final actions when unmounting a file system */
7611 +mini_fo_put_super(super_block_t *sb)
7614 + mntput(stopd(sb)->hidden_mnt);
7615 + mntput(stopd(sb)->hidden_mnt2);
7617 + /* mk: no! dput(stopd(sb)->base_dir_dentry);
7618 + dput(stopd(sb)->storage_dir_dentry); */
7621 + __stopd(sb) = NULL;
7628 + * This is called in do_umount before put_super.
7629 + * The superblock lock is not held yet.
7630 + * We probably do not need to define this or call write_super
7631 + * on the hidden_sb, because sync_supers() will get to hidden_sb
7632 + * sooner or later. But it is also called from file_fsync()...
7635 +mini_fo_write_super(super_block_t *sb)
7639 +#endif /* NOT_NEEDED */
7643 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
7644 +mini_fo_statfs(super_block_t *sb, struct kstatfs *buf)
7646 +mini_fo_statfs(super_block_t *sb, struct statfs *buf)
7650 + super_block_t *hidden_sb;
7652 + hidden_sb = stohs(sb);
7653 + err = vfs_statfs(hidden_sb, buf);
7660 + * XXX: not implemented. This is not allowed yet.
7661 + * Should we call this on the hidden_sb? Probably not.
7664 +mini_fo_remount_fs(super_block_t *sb, int *flags, char *data)
7666 + //printk(KERN_CRIT "mini_fo_remount_fs: WARNING, this function is umimplemented.\n");
7672 + * Called by iput() when the inode reference count reached zero
7673 + * and the inode is not hashed anywhere. Used to clear anything
7674 + * that needs to be, before the inode is completely destroyed and put
7675 + * on the inode free list.
7678 +mini_fo_clear_inode(inode_t *inode)
7681 + * Decrement a reference to a hidden_inode, which was incremented
7682 + * by our read_inode when it was created initially.
7685 + /* release the wol_list */
7686 + if(S_ISDIR(inode->i_mode)) {
7687 + __meta_put_lists(inode);
7690 + /* mk: fan out fun */
7692 + iput(itohi(inode));
7694 + iput(itohi2(inode));
7696 + // XXX: why this assertion fails?
7697 + // because it doesn't like us
7698 + // ASSERT((inode->i_state & I_DIRTY) == 0);
7699 + kfree(itopd(inode));
7700 + __itopd(inode) = NULL;
7705 + * Called in do_umount() if the MNT_FORCE flag was used and this
7706 + * function is defined. See comment in linux/fs/super.c:do_umount().
7707 + * Used only in nfs, to kill any pending RPC tasks, so that subsequent
7708 + * code can actually succeed and won't leave tasks that need handling.
7710 + * PS. I wonder if this is somehow useful to undo damage that was
7711 + * left in the kernel after a user level file server (such as amd)
7715 +mini_fo_umount_begin(super_block_t *sb)
7717 + super_block_t *hidden_sb;
7719 + hidden_sb = stohs(sb);
7721 + if (hidden_sb->s_op->umount_begin)
7722 + hidden_sb->s_op->umount_begin(hidden_sb);
7727 +struct super_operations mini_fo_sops =
7729 + read_inode: mini_fo_read_inode,
7730 +#if defined(FIST_DEBUG) || defined(FIST_FILTER_SCA)
7731 + write_inode: mini_fo_write_inode,
7732 +#endif /* defined(FIST_DEBUG) || defined(FIST_FILTER_SCA) */
7733 + put_inode: mini_fo_put_inode,
7734 +#if defined(FIST_DEBUG) || defined(FIST_FILTER_SCA)
7735 + delete_inode: mini_fo_delete_inode,
7736 +#endif /* defined(FIST_DEBUG) || defined(FIST_FILTER_SCA) */
7737 + put_super: mini_fo_put_super,
7738 + statfs: mini_fo_statfs,
7739 + remount_fs: mini_fo_remount_fs,
7740 + clear_inode: mini_fo_clear_inode,
7741 + umount_begin: mini_fo_umount_begin,