1 Index: linux-2.6.21.7/fs/Kconfig
2 ===================================================================
3 --- linux-2.6.21.7.orig/fs/Kconfig
4 +++ linux-2.6.21.7/fs/Kconfig
5 @@ -461,6 +461,9 @@ config OCFS2_DEBUG_MASKLOG
6 This option will enlarge your kernel, but it allows debugging of
7 ocfs2 filesystem issues.
10 + tristate "Mini fanout overlay filesystem"
13 tristate "Minix fs support"
15 Index: linux-2.6.21.7/fs/Makefile
16 ===================================================================
17 --- linux-2.6.21.7.orig/fs/Makefile
18 +++ linux-2.6.21.7/fs/Makefile
19 @@ -72,6 +72,7 @@ obj-$(CONFIG_SQUASHFS) += squashfs/
20 obj-$(CONFIG_RAMFS) += ramfs/
21 obj-$(CONFIG_HUGETLBFS) += hugetlbfs/
22 obj-$(CONFIG_CODA_FS) += coda/
23 +obj-$(CONFIG_MINI_FO) += mini_fo/
24 obj-$(CONFIG_MINIX_FS) += minix/
25 obj-$(CONFIG_FAT_FS) += fat/
26 obj-$(CONFIG_MSDOS_FS) += msdos/
27 Index: linux-2.6.21.7/fs/mini_fo/aux.c
28 ===================================================================
30 +++ linux-2.6.21.7/fs/mini_fo/aux.c
33 + * Copyright (c) 1997-2003 Erez Zadok
34 + * Copyright (c) 2001-2003 Stony Brook University
36 + * For specific licensing information, see the COPYING file distributed with
37 + * this package, or get one from ftp://ftp.filesystems.org/pub/fist/COPYING.
39 + * This Copyright notice must be kept intact and distributed with all
40 + * fistgen sources INCLUDING sources generated by fistgen.
43 + * Copyright (C) 2004, 2005 Markus Klotzbuecher <mk@creamnet.de>
45 + * This program is free software; you can redistribute it and/or
46 + * modify it under the terms of the GNU General Public License
47 + * as published by the Free Software Foundation; either version
48 + * 2 of the License, or (at your option) any later version.
61 +/* check if file exists in storage */
62 +int exists_in_storage(dentry_t *dentry)
64 + check_mini_fo_dentry(dentry);
65 + if(dtost(dentry) == MODIFIED || dtost(dentry) == CREATED || dtost(dentry) == DEL_REWRITTEN)
70 +/* check if dentry is in an existing state */
71 +int is_mini_fo_existant(dentry_t *dentry)
73 + check_mini_fo_dentry(dentry);
75 + if(dtost(dentry) == DELETED || dtost(dentry) == NON_EXISTANT)
82 + * This function will create a negative storage dentry for
83 + * dentry, what is required for many create like options.
84 + * It will create the storage structure if necessary.
86 +int get_neg_sto_dentry(dentry_t *dentry)
90 + const unsigned char *name;
94 + !(dtost(dentry) == UNMODIFIED ||
95 + dtost(dentry) == NON_EXISTANT ||
96 + dtost(dentry) == DELETED)) {
97 + printk(KERN_CRIT "mini_fo: get_neg_sto_dentry: invalid dentry passed.\n");
101 + /* Have we got a neg. dentry already? */
102 + if(dtohd2(dentry)) {
106 + if(dtost(dentry->d_parent) == UNMODIFIED) {
107 + /* build sto struct */
108 + err = build_sto_structure(dentry->d_parent->d_parent, dentry->d_parent);
110 + dtost(dentry->d_parent) != MODIFIED) {
111 + printk(KERN_CRIT "mini_fo: get_neg_sto_dentry: ERROR building sto structure.\n");
117 + len = dentry->d_name.len;
118 + name = dentry->d_name.name;
121 + lookup_one_len(name, dtohd2(dentry->d_parent), len);
127 +int check_mini_fo_dentry(dentry_t *dentry)
129 + ASSERT(dentry != NULL);
130 + ASSERT(dtopd(dentry) != NULL);
131 + ASSERT((dtohd(dentry) != NULL) || (dtohd2(dentry) != NULL));
133 +/* if(dtost(dentry) == MODIFIED) { */
134 +/* ASSERT(dentry->d_inode != NULL); */
135 +/* ASSERT(dtohd(dentry) != NULL); */
136 +/* ASSERT(dtohd(dentry)->d_inode != NULL); */
137 +/* ASSERT(dtohd2(dentry) != NULL); */
138 +/* ASSERT(dtohd2(dentry)->d_inode != NULL); */
140 +/* else if(dtost(dentry) == UNMODIFIED) { */
141 +/* ASSERT(dentry->d_inode != NULL); */
147 +int check_mini_fo_file(file_t *file)
149 + ASSERT(file != NULL);
150 + ASSERT(ftopd(file) != NULL);
151 + ASSERT(file->f_dentry != NULL);
153 + /* violent checking, check depending of state and type
154 + * if(S_ISDIR(file->f_dentry->d_inode->i_mode)) {}
156 + ASSERT((ftohf(file) != NULL) || (ftohf2(file) != NULL));
160 +int check_mini_fo_inode(inode_t *inode)
162 + ASSERT(inode != NULL);
163 + ASSERT(itopd(inode) != NULL);
164 + ASSERT((itohi(inode) != NULL) || (itohi2(inode) != NULL));
169 + * will walk a base path as provided by get_mini_fo_bpath and return
170 + * the (hopefully ;-) ) positive dentry of the renamed base dir.
172 + * This does some work of path_init.
174 +dentry_t *bpath_walk(super_block_t *sb, char *bpath)
177 + struct nameidata nd;
180 + if(!bpath || bpath[0] != '/') {
181 + printk(KERN_CRIT "mini_fo: bpath_walk: Invalid string.\n");
184 + if(!sb || !stopd(sb)) {
185 + printk(KERN_CRIT "mini_fo: bpath_walk: Invalid sb.\n");
189 + /* setup nd as path_init does */
190 + nd.last_type = LAST_ROOT; /* if there are only slashes... */
191 + nd.flags = LOOKUP_FOLLOW;
192 + /* fix this: how do I reach this lock?
193 + * read_lock(¤t->fs->lock); */
194 + nd.mnt = mntget(stopd(sb)->hidden_mnt);
195 + nd.dentry = dget(stopd(sb)->base_dir_dentry);
196 + /* read_unlock(¤t->fs->lock); */
198 + err = path_walk(bpath+1, &nd);
201 + if (err || !nd.dentry || !nd.dentry->d_inode) {
202 + printk(KERN_CRIT "mini_fo: bpath_walk: path_walk failed.\n");
209 +/* returns the full path of the basefile incl. its name */
210 +int get_mini_fo_bpath(dentry_t *dentry, char **bpath, int *bpath_len)
214 + dentry_t *sky_walker;
216 + if(!dentry || !dtohd(dentry)) {
217 + printk(KERN_CRIT "mini_fo: get_mini_fo_bpath: invalid dentry passed.\n");
220 + sky_walker = dtohd(dentry);
223 + len += sky_walker->d_name.len + 1 ; /* 1 for '/' */
224 + sky_walker = sky_walker->d_parent;
225 + } while(sky_walker != stopd(dentry->d_inode->i_sb)->base_dir_dentry);
227 + /* 1 to oil the loop */
228 + *bpath = (char*) kmalloc(len + 1, GFP_KERNEL);
230 + printk(KERN_CRIT "mini_fo: get_mini_fo_bpath: out of mem.\n");
233 + buf_walker = *bpath+len; /* put it on last char */
234 + *buf_walker = '\n';
235 + sky_walker = dtohd(dentry);
238 + buf_walker -= sky_walker->d_name.len;
239 + strncpy(buf_walker,
240 + sky_walker->d_name.name,
241 + sky_walker->d_name.len);
242 + *(--buf_walker) = '/';
243 + sky_walker = sky_walker->d_parent;
244 + } while(sky_walker != stopd(dentry->d_inode->i_sb)->base_dir_dentry);
246 + /* bpath_len doesn't count newline! */
251 +int mini_fo_cp_cont(dentry_t *tgt_dentry, struct vfsmount *tgt_mnt,
252 + dentry_t *src_dentry, struct vfsmount *src_mnt)
255 + mm_segment_t old_fs;
258 + int bytes, len, tmp, err;
261 + if(!(tgt_dentry->d_inode && src_dentry->d_inode)) {
262 + printk(KERN_CRIT "mini_fo_cp_cont: ERROR, neg. dentry passed.\n");
272 + /* open file write only */
273 + tgt_file = dentry_open(tgt_dentry, tgt_mnt, 0x1);
274 + if(!tgt_file || IS_ERR(tgt_file)) {
275 + printk(KERN_CRIT "mini_fo_cp_cont: ERROR opening target file.\n");
276 + err = PTR_ERR(tgt_file);
280 + /* open file read only */
281 + src_file = dentry_open(src_dentry, src_mnt, 0x0);
282 + if(!src_file || IS_ERR(src_file)) {
283 + printk(KERN_CRIT "mini_fo_cp_cont: ERROR opening source file.\n");
284 + err = PTR_ERR(src_file);
286 + /* close target file */
291 + /* check if the filesystem(s) support read respective write */
292 + if(!src_file->f_op->read || !tgt_file->f_op->write) {
293 + printk(KERN_CRIT "mini_fo_cp_cont: ERROR, no fs read or write support.\n");
298 + /* allocate a page for transfering the data */
299 + buf = (void *) __get_free_page(GFP_KERNEL);
301 + printk(KERN_CRIT "mini_fo_cp_cont: ERROR, out of kernel mem.\n");
305 + tgt_file->f_pos = 0;
306 + src_file->f_pos = 0;
311 + /* Doing this I assume that a read operation will return a full
312 + * buffer while there is still data to read, and a less than
313 + * full buffer when all data has been read.
315 + bytes = len = PAGE_SIZE;
316 + while(bytes == len) {
317 + bytes = src_file->f_op->read(src_file, buf, len,
319 + tmp = tgt_file->f_op->write(tgt_file, buf, bytes,
322 + printk(KERN_CRIT "mini_fo_cp_cont: ERROR writing.\n");
323 + goto out_close_unset;
327 + free_page((unsigned long) buf);
334 + free_page((unsigned long) buf);
345 + /* mk: not sure if this need to be done */
354 + * ndl (no-duplicate list) stuff
355 + * This is used in mini_fo_readdir, to save the storage directory contents
356 + * and later when reading base, match them against the list in order
357 + * to avoid duplicates.
360 +/* add a file specified by name and len to the ndl
361 + * Return values: 0 on success, <0 on failure.
363 +int ndl_add_entry(struct readdir_data *rd, const char *name, int len)
365 + struct ndl_entry *tmp_entry;
367 + tmp_entry = (struct ndl_entry *)
368 + kmalloc(sizeof(struct ndl_entry), GFP_KERNEL);
370 + printk(KERN_CRIT "mini_fo: ndl_add_entry: out of mem.\n");
373 + tmp_entry->name = (char*) kmalloc(len, GFP_KERNEL);
374 + if(!tmp_entry->name) {
375 + printk(KERN_CRIT "mini_fo: ndl_add_entry: out of mem.\n");
378 + strncpy(tmp_entry->name, name, len);
379 + tmp_entry->len = len;
381 + list_add(&tmp_entry->list, &rd->ndl_list);
386 +/* delete all list entries and free memory */
387 +void ndl_put_list(struct readdir_data *rd)
389 + struct list_head *tmp;
390 + struct ndl_entry *tmp_entry;
392 + if(rd->ndl_size <= 0)
394 + while(!list_empty(&rd->ndl_list)) {
395 + tmp = rd->ndl_list.next;
397 + tmp_entry = list_entry(tmp, struct ndl_entry, list);
398 + kfree(tmp_entry->name);
404 +/* Check if a file specified by name and len is in the ndl
405 + * Return value: 0 if not in list, 1 if file is found in ndl.
407 +int ndl_check_entry(struct readdir_data *rd, const char *name, int len)
409 + struct list_head *tmp;
410 + struct ndl_entry *tmp_entry;
412 + if(rd->ndl_size <= 0)
415 + list_for_each(tmp, &rd->ndl_list) {
416 + tmp_entry = list_entry(tmp, struct ndl_entry, list);
417 + if(tmp_entry->len != len)
419 + if(!strncmp(tmp_entry->name, name, len))
426 + * Recursive function to create corresponding directorys in the storage fs.
427 + * The function will build the storage directorys up to dentry.
429 +int build_sto_structure(dentry_t *dir, dentry_t *dentry)
432 + dentry_t *hidden_sto_dentry;
433 + dentry_t *hidden_sto_dir_dentry;
435 + if(dentry->d_parent != dir) {
436 + printk(KERN_CRIT "mini_fo: build_sto_structure: invalid parameter or meta data corruption [1].\n");
440 + if(dtost(dir) != MODIFIED) {
441 + err = build_sto_structure(dir->d_parent, dentry->d_parent);
446 + /* ok, coming back again. */
447 + check_mini_fo_dentry(dentry);
448 + hidden_sto_dentry = dtohd2(dentry);
450 + if(!hidden_sto_dentry) {
452 + * This is the case after creating the first
453 + * hidden_sto_dentry.
454 + * After one negative storage_dentry, all pointers to
455 + * hidden_storage dentries are set to NULL. We need to
456 + * create the negative dentry before we create the storage
460 + const unsigned char *name;
461 + len = dtohd(dentry)->d_name.len;
462 + name = dtohd(dentry)->d_name.name;
463 + hidden_sto_dentry = lookup_one_len(name, dtohd2(dir), len);
464 + dtohd2(dentry) = hidden_sto_dentry;
467 + /* was: hidden_sto_dir_dentry = lock_parent(hidden_sto_dentry); */
468 + hidden_sto_dir_dentry = dget(hidden_sto_dentry->d_parent);
469 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
470 + mutex_lock(&hidden_sto_dir_dentry->d_inode->i_mutex);
472 + down(&hidden_sto_dir_dentry->d_inode->i_sem);
475 + if(dtohd2(dir) != hidden_sto_dir_dentry) {
476 + printk(KERN_CRIT "mini_fo: build_sto_structure: invalid parameter or meta data corruption [2].\n");
480 + /* check for errors in lock_parent */
481 + err = PTR_ERR(hidden_sto_dir_dentry);
482 + if(IS_ERR(hidden_sto_dir_dentry)) {
483 + printk(KERN_CRIT "mini_fo: build_sto_structure: lock_parent failed.\n");
487 + err = vfs_mkdir(hidden_sto_dir_dentry->d_inode,
489 + dir->d_inode->i_mode);
492 + printk(KERN_CRIT "mini_fo: build_sto_structure: failed to create storage dir [1].\n");
493 + /* was: unlock_dir(dir); */
494 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
495 + mutex_unlock(&dir->d_inode->i_mutex);
497 + up(&dir->d_inode->i_sem);
503 + /* everything ok! */
504 + if(!dtohd2(dentry)->d_inode) {
505 + printk(KERN_CRIT "mini_fo: build_sto_structure: failed to create storage dir [2].\n");
506 + /* was: unlock_dir(dir); */
507 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
508 + mutex_unlock(&dir->d_inode->i_mutex);
510 + up(&dir->d_inode->i_sem);
516 + /* interpose the new inode and set new state */
517 + itohi2(dentry->d_inode) = igrab(dtohd2(dentry)->d_inode);
518 + dtopd(dentry)->state = MODIFIED;
520 + /* initalize the wol list */
521 + itopd(dentry->d_inode)->deleted_list_size = -1;
522 + itopd(dentry->d_inode)->renamed_list_size = -1;
523 + meta_build_lists(dentry);
525 + fist_copy_attr_all(dentry->d_inode, itohi2(dentry->d_inode));
526 + fist_copy_attr_timesizes(dir->d_inode,
527 + hidden_sto_dir_dentry->d_inode);
528 + dir->d_inode->i_nlink++;
529 + /* was: unlock_dir(hidden_sto_dir_dentry); */
530 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
531 + mutex_unlock(&hidden_sto_dir_dentry->d_inode->i_mutex);
533 + up(&hidden_sto_dir_dentry->d_inode->i_sem);
535 + dput(hidden_sto_dir_dentry);
543 + * Read "len" bytes from "filename" into "buf".
544 + * "buf" is in kernel space.
547 +mini_fo_read_file(const char *filename, void *buf, int len)
550 + mm_segment_t oldfs;
552 + /* Chroot? Maybe NULL isn't right here */
553 + filp = filp_open(filename, O_RDONLY, 0);
554 + if (!filp || IS_ERR(filp)) {
555 + printk("mini_fo_read_file err %d\n", (int) PTR_ERR(filp));
556 + return -1; /* or do something else */
559 + if (!filp->f_op->read)
560 + return -2; /* file(system) doesn't allow reads */
562 + /* now read len bytes from offset 0 */
563 + filp->f_pos = 0; /* start offset */
566 + bytes = filp->f_op->read(filp, buf, len, &filp->f_pos);
569 + /* close the file */
578 + * Write "len" bytes from "buf" to "filename"
579 + * "buf" is in kernel space.
582 +mini_fo_write_file(const char *filename, void *buf, int len)
585 + mm_segment_t oldfs;
587 + /* Chroot? Maybe NULL isn't right here */
588 + filp = filp_open(filename, O_RDWR|O_CREAT, 0640);
589 + if (!filp || IS_ERR(filp)) {
590 + printk("mini_fo_write_file err %d\n", (int) PTR_ERR(filp));
591 + return -1; /* or do something else */
594 + if (!filp->f_op->write)
595 + return -2; /* file(system) doesn't allow writes */
597 + /* now write len bytes from offset 0 */
598 + filp->f_pos = 0; /* start offset */
601 + bytes = filp->f_op->write(filp, buf, len, &filp->f_pos);
604 + /* close the file */
612 Index: linux-2.6.21.7/fs/mini_fo/ChangeLog
613 ===================================================================
615 +++ linux-2.6.21.7/fs/mini_fo/ChangeLog
617 +2006-01-24 Markus Klotzbuecher <mk@mary.denx.de>
619 + * Add tons of ugly ifdefs to Ed L. Cashin's mutex patch to
620 + retain backwards compatibility.
622 +2006-01-24 Ed L. Cashin <ecashin@coraid.com>
624 + * Support for the new mutex infrastructure
625 + (7892f2f48d165a34b0b8130c8a195dfd807b8cb6)
627 +2005-10-15 Markus Klotzbuecher <mk@localhost.localdomain>
629 + * Bugfix for a serious memory leak in mini_fo_follow_link.
631 +2005-09-21 Markus Klotzbuecher <mk@mary>
633 + * new release 0.6.1
635 + * fix of a compiler warning due to changes in 2.6.13
637 +2005-09-21 Klaus Wenninger <klaus.wenninger@siemens.com>
639 + * file.c: readdir: fix for a bug that caused directory entries
640 + to show up twice when using storage filesystems such as
643 +2005-06-30 Eric Lammerts <eric@lammerts.org>
645 + * fix for an oops when overwriting a binary thats beeing
648 +2005-06-09 <mk@mary>
650 + * Renamed overlay to mini_fo-overlay.
652 + * Added mini_fo-merge script to allow merging of storage and base
653 + after making modifications.
655 +2005-05-22 root <mk@mary>
657 + * Added overlay script that allows to easily mount mini_fo ontop
658 + of a given base directory
660 +2005-05-10 <mk@mary>
662 + * inode.c: xattr functions return -EOPNOSUPP instead of
663 + -ENOSUPP, what confuses "ls -l"
665 + * Changed license from LGPL to GPL.
667 +2005-05-08 root <mk@mary>
669 + * Makefile: clean it up and added make install and make
672 +2005-05-06 <mk@mary>
674 + * merged devel branch back to main. [v0-6-0-pre3]
676 + * removed unused files print.c and fist_ioctl. [devel-0-0-18]
678 + * ioctl: removed fist_ioctl stuff, that is not needed for
681 +2005-05-03 <mk@mary>
683 + * file.c: simplified mini_fo_open and mini_fo_setattr using
684 + new state changing functions. [devel-0-0-17]
686 + * inode.c: Fixed getattr state bug (see below) in 2.4 function
687 + mini_fo_inode revalidate.
689 + * inode.c: found an other bug in mini_fo_getattr. States are not
690 + reliable in this function, as a file can be opened, unlinked and
691 + the getattr function called. This results in a deleted dentry
692 + with an inode. Fix is to ignore states and simply use the inode
695 +2005-04-29 <mk@mary>
697 + * file.c: Bugfix and cleanup in fasync and fsync. [devel-0-0-16]
699 + * file.c: do not use mini_fo_lock so the generic version is
702 + * inode.c: getattr, never call getattr on lower files, as this
703 + will cause the inum to change.
705 + * inode.c: rename_reg_file renamed to rename_nondir, as it
706 + doesn't matter as long it't not a dir. Removed all
707 + rename_dev_file etc.
709 + * tagged as devel-0-0-15
711 + * inode.c: added support for chosing support for extended
712 + attrs at compile time by XATTR define in mini_fo.h .
714 + * inode.c: fixed mini_fo_getattr to use mini_fo inode and not
715 + lower again, what avoids inode number changes that confused
716 + rm again. This is the proper solution.
718 +2005-04-24 <mk@mary>
720 + * all files: updated Copyright notive to 2005. [devel-0-0-14]
722 + * inode.c: fixed mini_fo_getattr to not change the inode
723 + number, even if lower files change.
725 + * super.c: fixed a bug that caused deleted base file to show
726 + up suddenly after some time, or after creating a special
727 + file. The problem was that after some time or after special
728 + file creating sync_sb_inodes is called by the vfs, that
729 + called our mini_fo_put_inode. There was (wrongly) called
730 + __meta_put_lists, that nuked the lists, although the inode
731 + was going to continue its life. Moving __meta_put_lists to
732 + mini_fo_clear_inode, where an inode is really destroyed,
733 + solved the problem.
736 +2005-04-23 <mk@mary>
738 + * state.c, aux.c: more cleaning up and
739 + simplifications. [devel-0-0-13]
741 + * inode.c: implemented mini_fo_getattr, that was required for
742 + 2.6 because inode_revalidate has been remove there, and the
743 + old "du" bug returned.
746 +2005-04-20 <mk@mary>
748 + * aux.c: get_neg_sto_dentry(): allow to be called for dentries
749 + in state UNMODIFIED, NON_EXISTANT _and_ DELETED.
751 +2005-04-19 <mk@mary>
753 + * Fixed a bug under 2.6 that caused files deleted via mini_fo
754 + not to be deleted properly and therefore the fs filled up
755 + untill no memory was left. [devel-0-0-12]
757 + * Added basic hard link support. This means that creating
758 + hardlinks will work, but existing ones will be treated as
759 + individual files. [devel-0-0-11]
761 +2005-04-17 <mk@mary>
765 +2005-04-13 root <mk@mary>
767 + * Added file state.c for the state transition
768 + functions. Doesn't work very well yet, though...
770 +2005-04-12 <mk@mary>
772 + * Porting to 2.6 started, which is easier than expected, also
773 + due to Olivier previous work.
775 +2005-04-08 <mk@mary>
777 + * Fixed the bug that caused du to return invalid sizes of
778 + directory trees. The problem was that
779 + mini_fo_inode_revalidate didn't always copy the attributes
780 + from the base inode properly.
782 +2005-04-01 Markus Klotzbuecher <mk@chasey>
784 + * Merged devel branch back to main trunk and updated the
785 + RELEASE notes. This will be 0-6-0-pre1.
787 +2005-03-31 Markus Klotzbuecher <mk@chasey>
789 + * Fixed some bugs in rename_reg_file, that only showed up in
790 + the kernel compile test. Kernel compiles cleanly ontop of
791 + mini_fo, now also make mrproper etc. work. Seems pretty stable.
793 +2005-03-28 Markus Klotzbuecher <mk@chasey>
795 + * Many, many directory renaming bugfixes and a lot of other
796 + cleanup. Dir renaming seems to work relatively stable.
798 +2005-03-22 Markus Klotzbuecher <mk@chasey>
800 + * Finished implementing lightweight directory renaming. Some
801 + basic testing indicates it works fine.
802 + Next is to implement testcases for the testsuite and confirm
803 + everything is really working ok.
805 +2005-03-18 Markus Klotzbuecher <mk@chasey>
807 + * Finished implementing meta.c stuff required for directory
810 +2005-03-17 Markus Klotzbuecher <mk@chasey>
812 + * Fixed all compile warnings + an extremly old bug that
813 + somehow crept in while reworking the wol stuff to the META
814 + system. Turning on -Werror again... :-)
816 + * Fixed some bugs in the new rename_reg_file function.
818 + * Rewrote mini_fo rename and split it into several
819 + subfunctions, that handle the different types
820 + seperately. Rewrote the regular file function aswell, as it
821 + was implemented somewhat inefficient.
823 +2005-03-16 Markus Klotzbuecher <mk@chasey>
825 + * Implemented new META subsystem, removed old WOL stuff in favor
828 + * After some basic testing everything seems ok...
830 +2005-03-11 Markus Klotzbuecher <mk@chasey>
832 + * Renaming a non regular file caused trouble because I always
833 + tried to copy the contents. Now I only do this for regular
834 + files. mini_fo_rename still isn't implemented properly, renaming
835 + of device files, symlinks etc. results in a empty regular file
836 + instead of the proper type.
838 + * Directory renaming suddenly works! What a surprise! I guess
839 + this is because renaming is implemented as making a copy and
840 + removing the original. Still this might not work
843 +2005-03-09 Markus Klotzbuecher <mk@chasey>
845 + * Bugfix, when a mini_fo directory that exists in storage
846 + (state: MODIFIED, CREATED and DEL_REWRITTEN) is deleted, a
847 + possibly existing WOL file contained in it needs to be
850 + * Starting cleanup: defined state names in order to get rid of
853 +2005-03-08 Markus Klotzbuecher <mk@chasey>
855 + * Makefile fix, fist_ioctl was built against wrong sources if ARCH=um
857 + * Fixed a bug in dentry.c, mini_fo_d_hash. In state 4 =
858 + DEL_REWRITTEN the hash was calculated from the base dentry,
859 + which was wrong and and caused assertions in
860 + __mini_fo_hidden_dentry to fail.
862 +2005-02-21 <mk@mary>
864 + * Implemented directory deleting (inode.c)
866 + * main.c: made mini_fo_parse_options a little more robust.
868 +2004-12-22 <mk@mary>
870 + * Makefile cleanup and uml stuff, removed unneccessary files
872 + * Created a new and hopefully more informative README
874 + * CHANGELOG: created a new CHANGELOG and added old entries reversely
877 +2004-10-24 Gleb Natapov <gleb@nbase.co.il>
879 + * Fix: owner and group where not correctly copied from base to
883 +2004-10-05 Gleb Natapov <gleb@nbase.co.il>
885 + * Implementation of fsync, fasync and lock mini_fo functions.
888 +2004-09-29 Bob Lee <bob@pantasys.com>
890 + * Fix of a serious pointer bug
893 +2004-09-28 Gleb Natapov <gleb@nbase.co.il>
895 + * Implementation of mini_fo_mknod and mini_fo_rename, support
898 Index: linux-2.6.21.7/fs/mini_fo/dentry.c
899 ===================================================================
901 +++ linux-2.6.21.7/fs/mini_fo/dentry.c
904 + * Copyright (c) 1997-2003 Erez Zadok
905 + * Copyright (c) 2001-2003 Stony Brook University
907 + * For specific licensing information, see the COPYING file distributed with
908 + * this package, or get one from ftp://ftp.filesystems.org/pub/fist/COPYING.
910 + * This Copyright notice must be kept intact and distributed with all
911 + * fistgen sources INCLUDING sources generated by fistgen.
914 + * Copyright (C) 2004, 2005 Markus Klotzbuecher <mk@creamnet.de>
916 + * This program is free software; you can redistribute it and/or
917 + * modify it under the terms of the GNU General Public License
918 + * as published by the Free Software Foundation; either version
919 + * 2 of the License, or (at your option) any later version.
926 +#ifdef HAVE_CONFIG_H
927 +# include <config.h>
931 +#include "mini_fo.h"
934 + * THIS IS A BOOLEAN FUNCTION: returns 1 if valid, 0 otherwise.
937 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
938 +mini_fo_d_revalidate(dentry_t *dentry, struct nameidata *nd)
940 +mini_fo_d_revalidate(dentry_t *dentry, int flags)
943 + int err1 = 1; /* valid = 1, invalid = 0 */
945 + dentry_t *hidden_dentry;
946 + dentry_t *hidden_sto_dentry;
949 + check_mini_fo_dentry(dentry);
951 + hidden_dentry = dtohd(dentry);
952 + hidden_sto_dentry = dtohd2(dentry);
954 + if(hidden_dentry &&
955 + hidden_dentry->d_op &&
956 + hidden_dentry->d_op->d_revalidate) {
957 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
958 + err1 = hidden_dentry->d_op->d_revalidate(hidden_dentry, nd);
960 + err1 = hidden_dentry->d_op->d_revalidate(hidden_dentry, flags);
963 + if(hidden_sto_dentry &&
964 + hidden_sto_dentry->d_op &&
965 + hidden_sto_dentry->d_op->d_revalidate) {
966 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
967 + err2 = hidden_sto_dentry->d_op->d_revalidate(hidden_sto_dentry,
970 + err2 = hidden_sto_dentry->d_op->d_revalidate(hidden_sto_dentry,
975 + /* mk: if one of the lower level dentries are valid,
976 + * the mini_fo dentry is too.
978 + return (err1 || err2);
983 +mini_fo_d_hash(dentry_t *dentry, qstr_t *name)
986 + dentry_t *hidden_dentry;
987 + dentry_t *hidden_sto_dentry;
989 + /* hidden_dentry = mini_fo_hidden_dentry(dentry);
990 + * hidden_sto_dentry = mini_fo_hidden_sto_dentry(dentry); */
992 + /* state 1, 3, 4, 5: build the hash for the storage dentry */
993 + if((dtopd(dentry)->state == MODIFIED) ||
994 + (dtopd(dentry)->state == CREATED) ||
995 + (dtopd(dentry)->state == DEL_REWRITTEN) ||
996 + (dtopd(dentry)->state == DELETED)) {
997 + hidden_sto_dentry = dtohd2(dentry);
998 + if(hidden_sto_dentry &&
999 + hidden_sto_dentry->d_op &&
1000 + hidden_sto_dentry->d_op->d_hash) {
1001 + err = hidden_sto_dentry->d_op->d_hash(hidden_sto_dentry, name);
1005 + /* state 2: build the hash for the base dentry */
1006 + if(dtopd(dentry)->state == UNMODIFIED) {
1007 + hidden_dentry = dtohd(dentry);
1008 + if(hidden_dentry &&
1009 + hidden_dentry->d_op &&
1010 + hidden_dentry->d_op->d_hash) {
1011 + err = hidden_dentry->d_op->d_hash(hidden_dentry, name);
1015 + /* state 6: build hash for the dentry that exists */
1016 + if(dtopd(dentry)->state == NON_EXISTANT) {
1017 + hidden_sto_dentry = dtohd2(dentry);
1018 + if(hidden_sto_dentry &&
1019 + hidden_sto_dentry->d_op &&
1020 + hidden_sto_dentry->d_op->d_hash) {
1021 + err = hidden_sto_dentry->d_op->d_hash(hidden_sto_dentry, name);
1024 + hidden_dentry = dtohd(dentry);
1025 + if(hidden_dentry &&
1026 + hidden_dentry->d_op &&
1027 + hidden_dentry->d_op->d_hash) {
1028 + err = hidden_dentry->d_op->d_hash(hidden_dentry, name);
1033 + printk(KERN_CRIT "mini_fo: d_hash: invalid state detected.\n");
1041 +mini_fo_d_compare(dentry_t *dentry, qstr_t *a, qstr_t *b)
1044 + dentry_t *hidden_dentry=NULL;
1046 + /* hidden_dentry = mini_fo_hidden_dentry(dentry); */
1047 + if(dtohd2(dentry))
1048 + hidden_dentry = dtohd2(dentry);
1049 + else if(dtohd(dentry))
1050 + hidden_dentry = dtohd(dentry);
1052 + if (hidden_dentry && hidden_dentry->d_op && hidden_dentry->d_op->d_compare) {
1053 + err = hidden_dentry->d_op->d_compare(hidden_dentry, a, b);
1055 + err = ((a->len != b->len) || memcmp(a->name, b->name, b->len));
1063 +mini_fo_d_delete(dentry_t *dentry)
1065 + dentry_t *hidden_dentry;
1066 + dentry_t *hidden_sto_dentry;
1069 + /* this could be a negative dentry, so check first */
1070 + if (!dtopd(dentry)) {
1071 + printk(KERN_CRIT "mini_fo_d_delete: negative dentry passed.\n");
1074 + hidden_dentry = dtohd(dentry);
1075 + hidden_sto_dentry = dtohd2(dentry);
1077 + if(hidden_dentry) {
1078 + if(hidden_dentry->d_op &&
1079 + hidden_dentry->d_op->d_delete) {
1080 + err = hidden_dentry->d_op->d_delete(hidden_dentry);
1083 + if(hidden_sto_dentry) {
1084 + if(hidden_sto_dentry->d_op &&
1085 + hidden_sto_dentry->d_op->d_delete) {
1086 + err = hidden_sto_dentry->d_op->d_delete(hidden_sto_dentry);
1096 +mini_fo_d_release(dentry_t *dentry)
1098 + dentry_t *hidden_dentry;
1099 + dentry_t *hidden_sto_dentry;
1102 + /* this could be a negative dentry, so check first */
1103 + if (!dtopd(dentry)) {
1104 + printk(KERN_CRIT "mini_fo_d_release: no private data.\n");
1107 + hidden_dentry = dtohd(dentry);
1108 + hidden_sto_dentry = dtohd2(dentry);
1110 + if(hidden_dentry) {
1111 + /* decrement hidden dentry's counter and free its inode */
1112 + dput(hidden_dentry);
1114 + if(hidden_sto_dentry) {
1115 + /* decrement hidden dentry's counter and free its inode */
1116 + dput(hidden_sto_dentry);
1119 + /* free private data (mini_fo_dentry_info) here */
1120 + kfree(dtopd(dentry));
1121 + __dtopd(dentry) = NULL; /* just to be safe */
1128 + * we don't really need mini_fo_d_iput, because dentry_iput will call iput() if
1129 + * mini_fo_d_iput is not defined. We left this implemented for ease of
1130 + * tracing/debugging.
1133 +mini_fo_d_iput(dentry_t *dentry, inode_t *inode)
1139 +struct dentry_operations mini_fo_dops = {
1140 + d_revalidate: mini_fo_d_revalidate,
1141 + d_hash: mini_fo_d_hash,
1142 + d_compare: mini_fo_d_compare,
1143 + d_release: mini_fo_d_release,
1144 + d_delete: mini_fo_d_delete,
1145 + d_iput: mini_fo_d_iput,
1147 Index: linux-2.6.21.7/fs/mini_fo/file.c
1148 ===================================================================
1150 +++ linux-2.6.21.7/fs/mini_fo/file.c
1153 + * Copyright (c) 1997-2003 Erez Zadok
1154 + * Copyright (c) 2001-2003 Stony Brook University
1156 + * For specific licensing information, see the COPYING file distributed with
1157 + * this package, or get one from ftp://ftp.filesystems.org/pub/fist/COPYING.
1159 + * This Copyright notice must be kept intact and distributed with all
1160 + * fistgen sources INCLUDING sources generated by fistgen.
1163 + * Copyright (C) 2004, 2005 Markus Klotzbuecher <mk@creamnet.de>
1165 + * This program is free software; you can redistribute it and/or
1166 + * modify it under the terms of the GNU General Public License
1167 + * as published by the Free Software Foundation; either version
1168 + * 2 of the License, or (at your option) any later version.
1175 +#ifdef HAVE_CONFIG_H
1176 +# include <config.h>
1180 +#include "mini_fo.h"
1181 +#define ROUND_UP(x) (((x)+sizeof(long)-1) & ~(sizeof(long)-1))
1183 +/*******************
1184 + * File Operations *
1185 + *******************/
1188 +mini_fo_llseek(file_t *file, loff_t offset, int origin)
1191 + file_t *hidden_file = NULL;
1193 + if(S_ISDIR(file->f_dentry->d_inode->i_mode)) {
1194 + /* Check if trying to llseek from a directory */
1198 + if (ftopd(file) != NULL) {
1199 + if(ftohf2(file)) {
1200 + hidden_file = ftohf2(file);
1202 + hidden_file = ftohf(file);
1206 + /* always set hidden position to this one */
1207 + hidden_file->f_pos = file->f_pos;
1209 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
1210 + memcpy(&(hidden_file->f_ra),
1212 + sizeof(struct file_ra_state));
1214 + if (file->f_reada) { /* update readahead information if needed */
1215 + hidden_file->f_reada = file->f_reada;
1216 + hidden_file->f_ramax = file->f_ramax;
1217 + hidden_file->f_raend = file->f_raend;
1218 + hidden_file->f_ralen = file->f_ralen;
1219 + hidden_file->f_rawin = file->f_rawin;
1222 + if (hidden_file->f_op && hidden_file->f_op->llseek)
1223 + err = hidden_file->f_op->llseek(hidden_file, offset, origin);
1225 + err = generic_file_llseek(hidden_file, offset, origin);
1230 + if (err != file->f_pos) {
1231 + file->f_pos = err;
1232 + // ION maybe this?
1233 + // file->f_pos = hidden_file->f_pos;
1234 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
1235 + file->f_reada = 0;
1237 + file->f_version++;
1245 +/* mk: fanout capable */
1247 +mini_fo_read(file_t *file, char *buf, size_t count, loff_t *ppos)
1249 + int err = -EINVAL;
1250 + file_t *hidden_file = NULL;
1251 + loff_t pos = *ppos;
1253 + if(S_ISDIR(file->f_dentry->d_inode->i_mode)) {
1254 + /* Check if trying to read from a directory */
1255 + /* printk(KERN_CRIT "mini_fo_read: ERROR: trying to read data from a directory.\n"); */
1260 + if (ftopd(file) != NULL) {
1261 + if(ftohf2(file)) {
1262 + hidden_file = ftohf2(file);
1264 + hidden_file = ftohf(file);
1268 + if (!hidden_file->f_op || !hidden_file->f_op->read)
1271 + err = hidden_file->f_op->read(hidden_file, buf, count, &pos);
1275 + /* atime should also be updated for reads of size zero or more */
1276 + fist_copy_attr_atime(file->f_dentry->d_inode,
1277 + hidden_file->f_dentry->d_inode);
1280 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
1283 + * because pread() does not have any way to tell us that it is
1284 + * our caller, then we don't know for sure if we have to update
1285 + * the file positions. This hack relies on read() having passed us
1286 + * the "real" pointer of its struct file's f_pos field.
1288 + if (ppos == &file->f_pos)
1289 + hidden_file->f_pos = *ppos = pos;
1290 + if (hidden_file->f_reada) { /* update readahead information if needed */
1291 + file->f_reada = hidden_file->f_reada;
1292 + file->f_ramax = hidden_file->f_ramax;
1293 + file->f_raend = hidden_file->f_raend;
1294 + file->f_ralen = hidden_file->f_ralen;
1295 + file->f_rawin = hidden_file->f_rawin;
1298 + memcpy(&(file->f_ra),&(hidden_file->f_ra),sizeof(struct file_ra_state));
1306 +/* this mini_fo_write() does not modify data pages! */
1308 +mini_fo_write(file_t *file, const char *buf, size_t count, loff_t *ppos)
1310 + int err = -EINVAL;
1311 + file_t *hidden_file = NULL;
1313 + inode_t *hidden_inode;
1314 + loff_t pos = *ppos;
1316 + /* mk: fan out: */
1317 + if (ftopd(file) != NULL) {
1318 + if(ftohf2(file)) {
1319 + hidden_file = ftohf2(file);
1321 + /* This is bad! We have no storage file to write to. This
1322 + * should never happen because if a file is opened for
1323 + * writing, a copy should have been made earlier.
1325 + printk(KERN_CRIT "mini_fo: write : ERROR, no storage file to write.\n");
1331 + inode = file->f_dentry->d_inode;
1332 + hidden_inode = itohi2(inode);
1333 + if(!hidden_inode) {
1334 + printk(KERN_CRIT "mini_fo: write: no sto inode found, not good.\n");
1338 + if (!hidden_file->f_op || !hidden_file->f_op->write)
1341 + /* adjust for append -- seek to the end of the file */
1342 + if (file->f_flags & O_APPEND)
1343 + pos = inode->i_size;
1345 + err = hidden_file->f_op->write(hidden_file, buf, count, &pos);
1348 + * copy ctime and mtime from lower layer attributes
1349 + * atime is unchanged for both layers
1352 + fist_copy_attr_times(inode, hidden_inode);
1355 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
1359 + * because pwrite() does not have any way to tell us that it is
1360 + * our caller, then we don't know for sure if we have to update
1361 + * the file positions. This hack relies on write() having passed us
1362 + * the "real" pointer of its struct file's f_pos field.
1364 + if (ppos == &file->f_pos)
1365 + hidden_file->f_pos = *ppos = pos;
1367 + /* update this inode's size */
1368 + if (pos > inode->i_size)
1369 + inode->i_size = pos;
1375 +/* Global variable to hold a file_t pointer.
1376 + * This serves to allow mini_fo_filldir function to know which file is
1377 + * beeing read, which is required for two reasons:
1379 + * - be able to call wol functions in order to avoid listing deleted
1381 + * - if we're reading a directory which is in state 1, we need to
1382 + * maintain a list (in mini_fo_filldir) of which files allready
1383 + * have been copied to userspace,to detect files existing in base
1384 + * and storage and not list them twice.
1386 +filldir_t mini_fo_filldir_orig;
1387 +file_t *mini_fo_filldir_file;
1389 +/* mainly copied from fs/readdir.c */
1391 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,18)
1392 +mini_fo_filldir(void * __buf, const char * name, int namlen, loff_t offset,
1393 + u64 ino, unsigned int d_type)
1395 +mini_fo_filldir(void * __buf, const char * name, int namlen, loff_t offset,
1396 + ino_t ino, unsigned int d_type)
1399 + struct getdents_callback * buf = (struct getdents_callback *) __buf;
1400 + file_t* file = mini_fo_filldir_file;
1402 + /* In theses states we filter meta files in storage (WOL) */
1403 + if(file && (dtopd(file->f_dentry)->state == MODIFIED ||
1404 + dtopd(file->f_dentry)->state == CREATED ||
1405 + dtopd(file->f_dentry)->state == DEL_REWRITTEN)) {
1407 + int tmp = strlen(META_FILENAME);
1408 + if(tmp == namlen) {
1409 + if(!strncmp(name, META_FILENAME, namlen))
1414 + /* check if we are merging the contents of storage and base */
1415 + if(file && dtopd(file->f_dentry)->state == MODIFIED) {
1416 + /* check if we are still reading storage contents, if
1417 + * yes, we just save the name of the file for duplicate
1418 + * checking later. */
1420 + if(!ftopd(file)->rd.sto_done) {
1421 + /* put file into ndl list */
1422 + if(ndl_add_entry(&ftopd(file)->rd, name, namlen))
1423 + printk(KERN_CRIT "mini_fo_filldir: Error adding to ndl.\n");
1425 + /* check if file has been deleted */
1426 + if(meta_check_d_entry(file->f_dentry, name, namlen))
1429 + /* do duplicate checking */
1430 + if(ndl_check_entry(&ftopd(file)->rd, name, namlen))
1435 + return mini_fo_filldir_orig(buf, name, namlen, offset, ino, d_type);
1440 +mini_fo_readdir(file_t *file, void *dirent, filldir_t filldir)
1442 + int err = 0;/* mk: ??? -ENOTDIR; */
1443 + file_t *hidden_file = NULL;
1444 + file_t *hidden_sto_file = NULL;
1446 + struct getdents_callback *buf;
1449 +#if defined(FIST_FILTER_NAME) || defined(FIST_FILTER_SCA)
1450 + struct mini_fo_getdents_callback buf;
1451 +#endif /* FIST_FILTER_NAME || FIST_FILTER_SCA */
1453 + buf = (struct getdents_callback *) dirent;
1454 + oldcount = buf->count;
1455 + inode = file->f_dentry->d_inode;
1456 + mini_fo_filldir_file = file;
1457 + mini_fo_filldir_orig = filldir;
1459 + ftopd(file)->rd.sto_done = 0;
1461 + if (ftopd(file) != NULL) {
1462 + if(ftohf2(file)) {
1463 + hidden_sto_file = ftohf2(file);
1464 + err = vfs_readdir(hidden_sto_file, mini_fo_filldir, dirent);
1465 + file->f_pos = hidden_sto_file->f_pos;
1467 + fist_copy_attr_atime(inode, hidden_sto_file->f_dentry->d_inode);
1468 + /* not finshed yet, we'll be called again */
1469 + if (buf->count != oldcount)
1473 + ftopd(file)->rd.sto_done = 1;
1476 + hidden_file = ftohf(file);
1477 + err = vfs_readdir(hidden_file, mini_fo_filldir, dirent);
1478 + file->f_pos = hidden_file->f_pos;
1480 + fist_copy_attr_atime(inode, hidden_file->f_dentry->d_inode);
1487 + * we need to check if all the directory data has been copied to userspace,
1488 + * or if we will be called again by userspace to complete the operation.
1490 + if(buf->count == oldcount) {
1491 + ndl_put_list(&ftopd(file)->rd);
1494 + /* unset this, safe */
1495 + mini_fo_filldir_file = NULL;
1500 +STATIC unsigned int
1501 +mini_fo_poll(file_t *file, poll_table *wait)
1503 + unsigned int mask = DEFAULT_POLLMASK;
1504 + file_t *hidden_file = NULL;
1506 + if (ftopd(file) != NULL) {
1507 + if(ftohf2(file)) {
1508 + hidden_file = ftohf2(file);
1510 + hidden_file = ftohf(file);
1514 + if (!hidden_file->f_op || !hidden_file->f_op->poll)
1517 + mask = hidden_file->f_op->poll(hidden_file, wait);
1523 +/* FIST-LITE special version of mmap */
1525 +mini_fo_mmap(file_t *file, vm_area_t *vma)
1528 + file_t *hidden_file = NULL;
1530 + /* fanout capability */
1531 + if (ftopd(file) != NULL) {
1532 + if(ftohf2(file)) {
1533 + hidden_file = ftohf2(file);
1535 + hidden_file = ftohf(file);
1539 + ASSERT(hidden_file != NULL);
1540 + ASSERT(hidden_file->f_op != NULL);
1541 + ASSERT(hidden_file->f_op->mmap != NULL);
1543 + vma->vm_file = hidden_file;
1544 + err = hidden_file->f_op->mmap(hidden_file, vma);
1545 + get_file(hidden_file); /* make sure it doesn't get freed on us */
1546 + fput(file); /* no need to keep extra ref on ours */
1554 +mini_fo_open(inode_t *inode, file_t *file)
1558 + file_t *hidden_file = NULL;
1559 + dentry_t *hidden_dentry = NULL;
1561 + /* fanout stuff */
1562 + file_t *hidden_sto_file = NULL;
1563 + dentry_t *hidden_sto_dentry = NULL;
1566 + kmalloc(sizeof(struct mini_fo_file_info), GFP_KERNEL);
1567 + if (!ftopd(file)) {
1572 + /* init the readdir_helper structure */
1573 + INIT_LIST_HEAD(&ftopd(file)->rd.ndl_list);
1574 + ftopd(file)->rd.ndl_size = 0;
1576 + /* In certain paths this could stay uninitalized and cause trouble */
1577 + ftohf(file) = NULL;
1578 + ftohf2(file) = NULL;
1579 + hidden_flags = file->f_flags;
1581 + /* create storage files? */
1582 + if(dtost(file->f_dentry) == UNMODIFIED) {
1583 + if(!IS_WRITE_FLAG(file->f_flags)) {
1584 + hidden_dentry = dtohd(file->f_dentry);
1585 + dget(hidden_dentry);
1586 + /* dentry_open will decrement mnt refcnt if err.
1587 + * otherwise fput() will do an mntput() for us upon file close. */
1588 + mntget(stopd(inode->i_sb)->hidden_mnt);
1589 + hidden_file = dentry_open(hidden_dentry,
1590 + stopd(inode->i_sb)->hidden_mnt,
1592 + if (IS_ERR(hidden_file)) {
1593 + err = PTR_ERR(hidden_file);
1594 + dput(hidden_dentry);
1597 + ftohf(file) = hidden_file; /* link two files */
1601 + if(S_ISDIR(file->f_dentry->d_inode->i_mode)) {
1602 + err = dir_unmod_to_mod(file->f_dentry);
1604 + err = nondir_unmod_to_mod(file->f_dentry, 1);
1607 + printk("mini_fo_open: ERROR creating storage file.\n");
1612 + hidden_sto_dentry = dtohd2(file->f_dentry);
1613 + dget(hidden_sto_dentry);
1615 + if(dtopd(file->f_dentry)->state == MODIFIED) {
1616 + /* Directorys are special, interpose on both lower level files */
1617 + if(S_ISDIR(itohi(inode)->i_mode)) {
1618 + /* check for invalid file types of lower level files */
1619 + if(!(S_ISDIR(itohi(inode)->i_mode) && S_ISDIR(itohi2(inode)->i_mode))) {
1620 + printk(KERN_CRIT "mini_fo_open: meta data corruption detected.\n");
1621 + dput(hidden_sto_dentry);
1626 + /* lower level directorys are ok, open the base file */
1627 + hidden_dentry = dtohd(file->f_dentry);
1628 + dget(hidden_dentry);
1630 + mntget(stopd(inode->i_sb)->hidden_mnt);
1631 + hidden_file = dentry_open(hidden_dentry,
1632 + stopd(inode->i_sb)->hidden_mnt,
1634 + if (IS_ERR(hidden_file)) {
1635 + err = PTR_ERR(hidden_file);
1636 + dput(hidden_dentry);
1637 + dput(hidden_sto_dentry);
1640 + ftohf(file) = hidden_file; /* link the two files */
1644 + if(!exists_in_storage(file->f_dentry)) {
1645 + printk(KERN_CRIT "mini_fo_open: invalid file state detected.\n");
1647 + dput(hidden_sto_dentry);
1649 + /* If the base file has been opened, we need to close it here */
1651 + if (hidden_file->f_op && hidden_file->f_op->flush)
1652 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,18)
1653 + hidden_file->f_op->flush(hidden_file, NULL);
1655 + hidden_file->f_op->flush(hidden_file);
1657 + dput(hidden_dentry);
1662 + /* ok, now we can safely open the storage file */
1663 + mntget(stopd(inode->i_sb)->hidden_mnt2);
1664 + hidden_sto_file = dentry_open(hidden_sto_dentry,
1665 + stopd(inode->i_sb)->hidden_mnt2,
1668 + /* dentry_open dputs the dentry if it fails */
1669 + if (IS_ERR(hidden_sto_file)) {
1670 + err = PTR_ERR(hidden_sto_file);
1671 + /* close base file if open */
1673 + if (hidden_file->f_op && hidden_file->f_op->flush)
1674 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,18)
1675 + hidden_file->f_op->flush(hidden_file, NULL);
1677 + hidden_file->f_op->flush(hidden_file);
1679 + dput(hidden_dentry);
1683 + ftohf2(file) = hidden_sto_file; /* link storage file */
1686 + if (err < 0 && ftopd(file)) {
1687 + kfree(ftopd(file));
1693 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,18)
1694 +mini_fo_flush(file_t *file, fl_owner_t id)
1696 +mini_fo_flush(file_t *file)
1699 + int err1 = 0; /* assume ok (see open.c:close_fp) */
1701 + file_t *hidden_file = NULL;
1703 + check_mini_fo_file(file);
1705 + /* mk: we don't do any state checking here, as its not worth the time.
1706 + * Just flush the lower level files if they exist.
1708 + if(ftopd(file) != NULL) {
1709 + if(ftohf(file) != NULL) {
1710 + hidden_file = ftohf(file);
1711 + if (hidden_file->f_op && hidden_file->f_op->flush)
1712 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,18)
1713 + err1 = hidden_file->f_op->flush(hidden_file, id);
1715 + err1 = hidden_file->f_op->flush(hidden_file);
1718 + if(ftohf2(file) != NULL) {
1719 + hidden_file = ftohf2(file);
1720 + if (hidden_file->f_op && hidden_file->f_op->flush)
1721 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,18)
1722 + err2 = hidden_file->f_op->flush(hidden_file, id);
1724 + err2 = hidden_file->f_op->flush(hidden_file);
1728 + return (err1 | err2);
1733 +mini_fo_release(inode_t *inode, file_t *file)
1736 + file_t *hidden_file = NULL;
1738 + if (ftopd(file) != NULL) {
1740 + hidden_file = ftohf(file);
1741 + fput(hidden_file);
1743 + if(ftohf2(file)) {
1744 + hidden_file = ftohf2(file);
1745 + fput(hidden_file);
1747 + kfree(ftopd(file));
1753 +mini_fo_fsync(file_t *file, dentry_t *dentry, int datasync)
1757 + file_t *hidden_file = NULL;
1758 + dentry_t *hidden_dentry;
1760 + check_mini_fo_file(file);
1762 + if ((hidden_file = ftohf(file)) != NULL) {
1763 + hidden_dentry = dtohd(dentry);
1764 + if (hidden_file->f_op && hidden_file->f_op->fsync) {
1765 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
1766 + mutex_lock(&hidden_dentry->d_inode->i_mutex);
1768 + down(&hidden_dentry->d_inode->i_sem);
1770 + err1 = hidden_file->f_op->fsync(hidden_file, hidden_dentry, datasync);
1771 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
1772 + mutex_unlock(&hidden_dentry->d_inode->i_mutex);
1774 + up(&hidden_dentry->d_inode->i_sem);
1779 + if ((hidden_file = ftohf2(file)) != NULL) {
1780 + hidden_dentry = dtohd2(dentry);
1781 + if (hidden_file->f_op && hidden_file->f_op->fsync) {
1782 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
1783 + mutex_lock(&hidden_dentry->d_inode->i_mutex);
1785 + down(&hidden_dentry->d_inode->i_sem);
1787 + err2 = hidden_file->f_op->fsync(hidden_file, hidden_dentry, datasync);
1788 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
1789 + mutex_unlock(&hidden_dentry->d_inode->i_mutex);
1791 + up(&hidden_dentry->d_inode->i_sem);
1799 + return (err1 || err2);
1804 +mini_fo_fasync(int fd, file_t *file, int flag)
1809 + file_t *hidden_file = NULL;
1811 + check_mini_fo_file(file);
1813 + if((hidden_file = ftohf(file)) != NULL) {
1814 + err1 = hidden_file->f_op->fasync(fd, hidden_file, flag);
1816 + if((hidden_file = ftohf2(file)) != NULL) {
1817 + err2 = hidden_file->f_op->fasync(fd, hidden_file, flag);
1820 + return (err1 || err2);
1825 +struct file_operations mini_fo_dir_fops =
1827 + read: generic_read_dir,
1828 + write: mini_fo_write,
1829 + readdir: mini_fo_readdir,
1830 + poll: mini_fo_poll,
1831 + /* ioctl: mini_fo_ioctl, */
1832 + mmap: mini_fo_mmap,
1833 + open: mini_fo_open,
1834 + flush: mini_fo_flush,
1835 + release: mini_fo_release,
1836 + fsync: mini_fo_fsync,
1837 + fasync: mini_fo_fasync,
1838 + /* not needed lock: mini_fo_lock, */
1839 + /* not needed: readv */
1840 + /* not needed: writev */
1841 + /* not implemented: sendpage */
1842 + /* not implemented: get_unmapped_area */
1845 +struct file_operations mini_fo_main_fops =
1847 + llseek: mini_fo_llseek,
1848 + read: mini_fo_read,
1849 + write: mini_fo_write,
1850 + readdir: mini_fo_readdir,
1851 + poll: mini_fo_poll,
1852 + /* ioctl: mini_fo_ioctl, */
1853 + mmap: mini_fo_mmap,
1854 + open: mini_fo_open,
1855 + flush: mini_fo_flush,
1856 + release: mini_fo_release,
1857 + fsync: mini_fo_fsync,
1858 + fasync: mini_fo_fasync,
1859 + /* not needed: lock: mini_fo_lock, */
1860 + /* not needed: readv */
1861 + /* not needed: writev */
1862 + /* not implemented: sendpage */
1863 + /* not implemented: get_unmapped_area */
1865 Index: linux-2.6.21.7/fs/mini_fo/fist.h
1866 ===================================================================
1868 +++ linux-2.6.21.7/fs/mini_fo/fist.h
1871 + * Copyright (c) 1997-2003 Erez Zadok
1872 + * Copyright (c) 2001-2003 Stony Brook University
1874 + * For specific licensing information, see the COPYING file distributed with
1875 + * this package, or get one from ftp://ftp.filesystems.org/pub/fist/COPYING.
1877 + * This Copyright notice must be kept intact and distributed with all
1878 + * fistgen sources INCLUDING sources generated by fistgen.
1881 + * Copyright (C) 2004, 2005 Markus Klotzbuecher <mk@creamnet.de>
1883 + * This program is free software; you can redistribute it and/or
1884 + * modify it under the terms of the GNU General Public License
1885 + * as published by the Free Software Foundation; either version
1886 + * 2 of the License, or (at your option) any later version.
1898 + * KERNEL ONLY CODE:
1901 +#include <linux/version.h>
1902 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,19)
1903 +#include <linux/autoconf.h>
1905 +#include <linux/config.h>
1907 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
1908 +#ifdef CONFIG_MODVERSIONS
1909 +# define MODVERSIONS
1910 +# include <linux/modversions.h>
1911 +#endif /* CONFIG_MODVERSIONS */
1912 +#endif /* KERNEL_VERSION < 2.6.0 */
1913 +#include <linux/sched.h>
1914 +#include <linux/kernel.h>
1915 +#include <linux/mm.h>
1916 +#include <linux/string.h>
1917 +#include <linux/stat.h>
1918 +#include <linux/errno.h>
1919 +#include <linux/wait.h>
1920 +#include <linux/limits.h>
1921 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
1922 +#include <linux/locks.h>
1924 +#include <linux/buffer_head.h>
1925 +#include <linux/pagemap.h>
1926 +#include <linux/namei.h>
1927 +#include <linux/module.h>
1928 +#include <linux/mount.h>
1929 +#include <linux/page-flags.h>
1930 +#include <linux/writeback.h>
1931 +#include <linux/statfs.h>
1933 +#include <linux/smp.h>
1934 +#include <linux/smp_lock.h>
1935 +#include <linux/file.h>
1936 +#include <linux/slab.h>
1937 +#include <linux/vmalloc.h>
1938 +#include <linux/poll.h>
1939 +#include <linux/list.h>
1940 +#include <linux/init.h>
1942 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,20)
1943 +#include <linux/xattr.h>
1946 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
1947 +#include <linux/security.h>
1950 +#include <linux/swap.h>
1952 +#include <asm/system.h>
1953 +/* #include <asm/segment.h> */
1954 +#include <asm/mman.h>
1955 +#include <linux/seq_file.h>
1961 +/* those mapped to ATTR_* were copied from linux/fs.h */
1962 +#define FA_MODE ATTR_MODE
1963 +#define FA_UID ATTR_UID
1964 +#define FA_GID ATTR_GID
1965 +#define FA_SIZE ATTR_SIZE
1966 +#define FA_ATIME ATTR_ATIME
1967 +#define FA_MTIME ATTR_MTIME
1968 +#define FA_CTIME ATTR_CTIME
1969 +#define FA_ATIME_SET ATTR_ATIME_SET
1970 +#define FA_MTIME_SET ATTR_MTIME_SET
1971 +#define FA_FORCE ATTR_FORCE
1972 +#define FA_ATTR_FLAGS ATTR_ATTR_FLAG
1974 +/* must be greater than all other ATTR_* flags! */
1975 +#define FA_NLINK 2048
1976 +#define FA_BLKSIZE 4096
1977 +#define FA_BLOCKS 8192
1978 +#define FA_TIMES (FA_ATIME|FA_MTIME|FA_CTIME)
1981 +/* macros to manage changes between kernels */
1982 +#define INODE_DATA(i) (&(i)->i_data)
1984 +#define MIN(x,y) ((x < y) ? (x) : (y))
1985 +#define MAX(x,y) ((x > y) ? (x) : (y))
1986 +#define MAXPATHLEN PATH_MAX
1988 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,4,5)
1989 +# define lookup_one_len(a,b,c) lookup_one(a,b)
1990 +#endif /* LINUX_VERSION_CODE < KERNEL_VERSION(2,4,5) */
1992 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,4,8)
1993 +# define generic_file_llseek default_llseek
1994 +#endif /* LINUX_VERSION_CODE < KERNEL_VERSION(2,4,8) */
1997 +# define SEEK_SET 0
1998 +#endif /* not SEEK_SET */
2001 +# define SEEK_CUR 1
2002 +#endif /* not SEEK_CUR */
2005 +# define SEEK_END 2
2006 +#endif /* not SEEK_END */
2008 +#ifndef DEFAULT_POLLMASK
2009 +# define DEFAULT_POLLMASK (POLLIN | POLLOUT | POLLRDNORM | POLLWRNORM)
2010 +#endif /* not DEFAULT_POLLMASK */
2012 +/* XXX: fix this so fistgen generates kfree() code directly */
2013 +#define kfree_s(a,b) kfree(a)
2018 +typedef struct dentry dentry_t;
2019 +typedef struct file file_t;
2020 +typedef struct inode inode_t;
2021 +typedef inode_t vnode_t;
2022 +typedef struct page page_t;
2023 +typedef struct qstr qstr_t;
2024 +typedef struct super_block super_block_t;
2025 +typedef super_block_t vfs_t;
2026 +typedef struct vm_area_struct vm_area_t;
2033 +#define FPPF(str,page) printk("PPF %s 0x%x/%d: Lck:%d Err:%d Ref:%d Upd:%d Other::%d:%d:%d:%d:\n", \
2036 + (int) page->index, \
2037 + (PageLocked(page) ? 1 : 0), \
2038 + (PageError(page) ? 1 : 0), \
2039 + (PageReferenced(page) ? 1 : 0), \
2040 + (Page_Uptodate(page) ? 1 : 0), \
2041 + (PageDecrAfter(page) ? 1 : 0), \
2042 + (PageSlab(page) ? 1 : 0), \
2043 + (PageSwapCache(page) ? 1 : 0), \
2044 + (PageReserved(page) ? 1 : 0) \
2046 +#define EZKDBG printk("EZK %s:%d:%s\n",__FILE__,__LINE__,__FUNCTION__)
2048 +# define EZKDBG1 printk("EZK %s:%d\n",__FILE__,__LINE__)
2053 +extern int fist_get_debug_value(void);
2054 +extern int fist_set_debug_value(int val);
2055 +#if 0 /* mini_fo doesn't need these */
2056 +extern void fist_dprint_internal(int level, char *str,...);
2057 +extern void fist_print_dentry(char *str, const dentry_t *dentry);
2058 +extern void fist_print_inode(char *str, const inode_t *inode);
2059 +extern void fist_print_file(char *str, const file_t *file);
2060 +extern void fist_print_buffer_flags(char *str, struct buffer_head *buffer);
2061 +extern void fist_print_page_flags(char *str, page_t *page);
2062 +extern void fist_print_page_bytes(char *str, page_t *page);
2063 +extern void fist_print_pte_flags(char *str, const page_t *page);
2064 +extern void fist_checkinode(inode_t *inode, char *msg);
2065 +extern void fist_print_sb(char *str, const super_block_t *sb);
2067 +/* §$% by mk: special debug functions */
2068 +extern void fist_mk_print_dentry(char *str, const dentry_t *dentry);
2069 +extern void fist_mk_print_inode(char *str, const inode_t *inode);
2071 +extern char *add_indent(void);
2072 +extern char *del_indent(void);
2073 +#endif/* mini_fo doesn't need these */
2077 +#define ASSERT(EX) \
2080 + printk(KERN_CRIT "ASSERTION FAILED: %s at %s:%d (%s)\n", #EX, \
2081 + __FILE__, __LINE__, __FUNCTION__); \
2082 + (*((char *)0))=0; \
2085 +/* same ASSERT, but tell me who was the caller of the function */
2086 +#define ASSERT2(EX) \
2089 + printk(KERN_CRIT "ASSERTION FAILED (caller): %s at %s:%d (%s)\n", #EX, \
2090 + file, line, func); \
2091 + (*((char *)0))=0; \
2095 +#if 0 /* mini_fo doesn't need these */
2096 +#define dprintk(format, args...) printk(KERN_DEBUG format, ##args)
2097 +#define fist_dprint(level, str, args...) fist_dprint_internal(level, KERN_DEBUG str, ## args)
2098 +#define print_entry_location() fist_dprint(4, "%sIN: %s %s:%d\n", add_indent(), __FUNCTION__, __FILE__, __LINE__)
2099 +#define print_exit_location() fist_dprint(4, "%s OUT: %s %s:%d\n", del_indent(), __FUNCTION__, __FILE__, __LINE__)
2100 +#define print_exit_status(status) fist_dprint(4, "%s OUT: %s %s:%d, STATUS: %d\n", del_indent(), __FUNCTION__, __FILE__, __LINE__, status)
2101 +#define print_exit_pointer(status) \
2103 + if (IS_ERR(status)) \
2104 + fist_dprint(4, "%s OUT: %s %s:%d, RESULT: %ld\n", del_indent(), __FUNCTION__, __FILE__, __LINE__, PTR_ERR(status)); \
2106 + fist_dprint(4, "%s OUT: %s %s:%d, RESULT: 0x%x\n", del_indent(), __FUNCTION__, __FILE__, __LINE__, PTR_ERR(status)); \
2108 +#endif/* mini_fo doesn't need these */
2110 +#endif /* __KERNEL__ */
2114 + * DEFINITIONS FOR USER AND KERNEL CODE:
2115 + * (Note: ioctl numbers 1--9 are reserved for fistgen, the rest
2116 + * are auto-generated automatically based on the user's .fist file.)
2118 +# define FIST_IOCTL_GET_DEBUG_VALUE _IOR(0x15, 1, int)
2119 +# define FIST_IOCTL_SET_DEBUG_VALUE _IOW(0x15, 2, int)
2121 +#endif /* not __FIST_H_ */
2122 Index: linux-2.6.21.7/fs/mini_fo/inode.c
2123 ===================================================================
2125 +++ linux-2.6.21.7/fs/mini_fo/inode.c
2128 + * Copyright (c) 1997-2003 Erez Zadok
2129 + * Copyright (c) 2001-2003 Stony Brook University
2131 + * For specific licensing information, see the COPYING file distributed with
2132 + * this package, or get one from ftp://ftp.filesystems.org/pub/fist/COPYING.
2134 + * This Copyright notice must be kept intact and distributed with all
2135 + * fistgen sources INCLUDING sources generated by fistgen.
2138 + * Copyright (C) 2004, 2005 Markus Klotzbuecher <mk@creamnet.de>
2140 + * This program is free software; you can redistribute it and/or
2141 + * modify it under the terms of the GNU General Public License
2142 + * as published by the Free Software Foundation; either version
2143 + * 2 of the License, or (at your option) any later version.
2150 +#ifdef HAVE_CONFIG_H
2151 +# include <config.h>
2155 +#include "mini_fo.h"
2158 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
2159 +mini_fo_create(inode_t *dir, dentry_t *dentry, int mode, struct nameidata *nd)
2161 +mini_fo_create(inode_t *dir, dentry_t *dentry, int mode)
2166 + check_mini_fo_dentry(dentry);
2168 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
2169 + err = create_sto_reg_file(dentry, mode, nd);
2171 + err = create_sto_reg_file(dentry, mode);
2173 + check_mini_fo_dentry(dentry);
2179 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
2180 +mini_fo_lookup(inode_t *dir, dentry_t *dentry, struct nameidata* nd)
2182 +mini_fo_lookup(inode_t *dir, dentry_t *dentry)
2186 + dentry_t *hidden_dir_dentry;
2187 + dentry_t *hidden_dentry = NULL;
2189 + dentry_t *hidden_sto_dir_dentry;
2190 + dentry_t *hidden_sto_dentry = NULL;
2192 + /* whiteout flag */
2194 + char *bpath = NULL;
2197 + unsigned int namelen;
2199 + /* Don't allow lookups of META-files */
2200 + namelen = strlen(META_FILENAME);
2201 + if(namelen == dentry->d_name.len) {
2202 + if(!strncmp(dentry->d_name.name, META_FILENAME, namelen)) {
2208 + hidden_dir_dentry = dtohd(dentry->d_parent);
2209 + hidden_sto_dir_dentry = dtohd2(dentry->d_parent);
2211 + name = dentry->d_name.name;
2212 + namelen = dentry->d_name.len;
2214 + /* must initialize dentry operations */
2215 + dentry->d_op = &mini_fo_dops;
2217 + /* setup the del_flag */
2218 + del_flag = __meta_check_d_entry(dir, name, namelen);
2219 + bpath = __meta_check_r_entry(dir, name, namelen);
2221 + /* perform the lookups of base and storage files:
2223 + * This caused some serious trouble, as a lookup_one_len passing
2224 + * a negative dentry oopses. Solution is to only do the lookup
2225 + * if the dentry is positive, else we set it to NULL
2226 + * More trouble, who said a *_dir_dentry can't be NULL?
2229 + /* Cross-Interposing (C), yeah! */
2230 + hidden_dentry = bpath_walk(dir->i_sb, bpath);
2231 + if(!hidden_dentry || !hidden_dentry->d_inode) {
2232 + printk(KERN_CRIT "mini_fo_lookup: bpath_walk failed.\n");
2237 + /* this can be set up safely without fear of spaghetti
2238 + * interposing as it is only used for copying times */
2239 + hidden_dir_dentry = hidden_dentry->d_parent;
2242 + else if(hidden_dir_dentry && hidden_dir_dentry->d_inode)
2244 + lookup_one_len(name, hidden_dir_dentry, namelen);
2246 + hidden_dentry = NULL;
2248 + if(hidden_sto_dir_dentry && hidden_sto_dir_dentry->d_inode)
2249 + hidden_sto_dentry =
2250 + lookup_one_len(name, hidden_sto_dir_dentry, namelen);
2252 + hidden_sto_dentry = NULL;
2254 + /* catch error in lookup */
2255 + if (IS_ERR(hidden_dentry) || IS_ERR(hidden_sto_dentry)) {
2256 + /* mk: we need to call dput on the dentry, whose
2257 + * lookup_one_len operation failed, in order to avoid
2258 + * unmount trouble.
2260 + if(IS_ERR(hidden_dentry)) {
2261 + printk(KERN_CRIT "mini_fo_lookup: ERR from base dentry, lookup failed.\n");
2262 + err = PTR_ERR(hidden_dentry);
2264 + dput(hidden_dentry);
2266 + if(IS_ERR(hidden_sto_dentry)) {
2267 + printk(KERN_CRIT "mini_fo_lookup: ERR from storage dentry, lookup failed.\n");
2268 + err = PTR_ERR(hidden_sto_dentry);
2270 + dput(hidden_sto_dentry);
2275 + /* allocate dentry private data */
2276 + __dtopd(dentry) = (struct mini_fo_dentry_info *)
2277 + kmalloc(sizeof(struct mini_fo_dentry_info), GFP_KERNEL);
2279 + if (!dtopd(dentry)) {
2284 + /* check for different states of the mini_fo file to be looked up. */
2286 + /* state 1, file has been modified */
2287 + if(hidden_dentry && hidden_sto_dentry &&
2288 + hidden_dentry->d_inode && hidden_sto_dentry->d_inode && !del_flag) {
2290 + /* update parent directory's atime */
2291 + fist_copy_attr_atime(dir, hidden_sto_dir_dentry->d_inode);
2293 + dtopd(dentry)->state = MODIFIED;
2294 + dtohd(dentry) = hidden_dentry;
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 (state1).\n");
2306 + /* state 2, file is unmodified */
2307 + if(hidden_dentry && hidden_dentry->d_inode && !del_flag) {
2309 + fist_copy_attr_atime(dir, hidden_dir_dentry->d_inode);
2311 + dtopd(dentry)->state = UNMODIFIED;
2312 + dtohd(dentry) = hidden_dentry;
2313 + dtohd2(dentry) = hidden_sto_dentry; /* could be negative */
2315 + err = mini_fo_tri_interpose(hidden_dentry,
2316 + hidden_sto_dentry,
2317 + dentry, dir->i_sb, 1);
2319 + printk(KERN_CRIT "mini_fo_lookup: error interposing (state2).\n");
2324 + /* state 3, file has been newly created */
2325 + if(hidden_sto_dentry && hidden_sto_dentry->d_inode && !del_flag) {
2327 + fist_copy_attr_atime(dir, hidden_sto_dir_dentry->d_inode);
2328 + dtopd(dentry)->state = CREATED;
2329 + dtohd(dentry) = hidden_dentry; /* could be negative */
2330 + dtohd2(dentry) = hidden_sto_dentry;
2332 + err = mini_fo_tri_interpose(hidden_dentry,
2333 + hidden_sto_dentry,
2334 + dentry, dir->i_sb, 1);
2336 + printk(KERN_CRIT "mini_fo_lookup: error interposing (state3).\n");
2342 + /* state 4, file has deleted and created again. */
2343 + if(hidden_dentry && hidden_sto_dentry &&
2344 + hidden_dentry->d_inode &&
2345 + hidden_sto_dentry->d_inode && del_flag) {
2347 + fist_copy_attr_atime(dir, hidden_sto_dir_dentry->d_inode);
2348 + dtopd(dentry)->state = DEL_REWRITTEN;
2349 + dtohd(dentry) = NULL;
2350 + dtohd2(dentry) = hidden_sto_dentry;
2352 + err = mini_fo_tri_interpose(NULL,
2353 + hidden_sto_dentry,
2354 + dentry, dir->i_sb, 1);
2356 + printk(KERN_CRIT "mini_fo_lookup: error interposing (state4).\n");
2359 + /* We will never need this dentry again, as the file has been
2360 + * deleted from base */
2361 + dput(hidden_dentry);
2364 + /* state 5, file has been deleted in base */
2365 + if(hidden_dentry && hidden_sto_dentry &&
2366 + hidden_dentry->d_inode &&
2367 + !hidden_sto_dentry->d_inode && del_flag) {
2369 + /* check which parents atime we need for updating */
2370 + if(hidden_sto_dir_dentry->d_inode)
2371 + fist_copy_attr_atime(dir,
2372 + hidden_sto_dir_dentry->d_inode);
2374 + fist_copy_attr_atime(dir,
2375 + hidden_dir_dentry->d_inode);
2377 + dtopd(dentry)->state = DELETED;
2378 + dtohd(dentry) = NULL;
2379 + dtohd2(dentry) = hidden_sto_dentry;
2381 + /* add negative dentry to dcache to speed up lookups */
2382 + d_add(dentry, NULL);
2383 + dput(hidden_dentry);
2386 + /* state 6, file does not exist */
2387 + if(((hidden_dentry && !hidden_dentry->d_inode) ||
2388 + (hidden_sto_dentry && !hidden_sto_dentry->d_inode)) && !del_flag)
2390 + /* check which parents atime we need for updating */
2391 + if(hidden_sto_dir_dentry && hidden_sto_dir_dentry->d_inode)
2392 + fist_copy_attr_atime(dir, hidden_sto_dir_dentry->d_inode);
2394 + fist_copy_attr_atime(dir, hidden_dir_dentry->d_inode);
2396 + dtopd(dentry)->state = NON_EXISTANT;
2397 + dtohd(dentry) = hidden_dentry;
2398 + dtohd2(dentry) = hidden_sto_dentry;
2399 + d_add(dentry, NULL);
2403 + /* if we get to here, were in an invalid state. bad. */
2404 + printk(KERN_CRIT "mini_fo_lookup: ERROR, meta data corruption detected.\n");
2406 + /* end state checking */
2408 + d_drop(dentry); /* so that our bad dentry will get destroyed */
2409 + kfree(dtopd(dentry));
2410 + __dtopd(dentry) = NULL; /* be safe */
2414 + dput(hidden_dentry);
2415 + if(hidden_sto_dentry)
2416 + dput(hidden_sto_dentry); /* drops usage count and marks for release */
2419 + /* initalize wol if file exists and is directory */
2420 + if(dentry->d_inode) {
2421 + if(S_ISDIR(dentry->d_inode->i_mode)) {
2422 + itopd(dentry->d_inode)->deleted_list_size = -1;
2423 + itopd(dentry->d_inode)->renamed_list_size = -1;
2424 + meta_build_lists(dentry);
2427 + return ERR_PTR(err);
2432 +mini_fo_link(dentry_t *old_dentry, inode_t *dir, dentry_t *new_dentry)
2435 + dentry_t *hidden_old_dentry;
2436 + dentry_t *hidden_new_dentry;
2437 + dentry_t *hidden_dir_dentry;
2440 + check_mini_fo_dentry(old_dentry);
2441 + check_mini_fo_dentry(new_dentry);
2442 + check_mini_fo_inode(dir);
2444 + /* no links to directorys and existing targets target allowed */
2445 + if(S_ISDIR(old_dentry->d_inode->i_mode) ||
2446 + is_mini_fo_existant(new_dentry)) {
2451 + /* bring it directly from unmod to del_rew */
2452 + if(dtost(old_dentry) == UNMODIFIED) {
2453 + err = nondir_unmod_to_mod(old_dentry, 1);
2458 + err = meta_add_d_entry(old_dentry->d_parent,
2459 + old_dentry->d_name.name,
2460 + old_dentry->d_name.len);
2465 + dput(dtohd(old_dentry));
2466 + dtohd(old_dentry) = NULL;
2467 + dtost(old_dentry) = DEL_REWRITTEN;
2470 + err = get_neg_sto_dentry(new_dentry);
2476 + hidden_old_dentry = dtohd2(old_dentry);
2477 + hidden_new_dentry = dtohd2(new_dentry);
2479 + dget(hidden_old_dentry);
2480 + dget(hidden_new_dentry);
2482 + /* was: hidden_dir_dentry = lock_parent(hidden_new_dentry); */
2483 + hidden_dir_dentry = dget(hidden_new_dentry->d_parent);
2484 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
2485 + mutex_lock(&hidden_dir_dentry->d_inode->i_mutex);
2487 + down(&hidden_dir_dentry->d_inode->i_sem);
2490 + err = vfs_link(hidden_old_dentry,
2491 + hidden_dir_dentry->d_inode,
2492 + hidden_new_dentry);
2493 + if (err || !hidden_new_dentry->d_inode)
2496 + dtost(new_dentry) = CREATED;
2497 + err = mini_fo_tri_interpose(NULL, hidden_new_dentry, new_dentry, dir->i_sb, 0);
2501 + fist_copy_attr_timesizes(dir, hidden_new_dentry->d_inode);
2502 + /* propagate number of hard-links */
2503 + old_dentry->d_inode->i_nlink = itohi2(old_dentry->d_inode)->i_nlink;
2506 + /* was: unlock_dir(hidden_dir_dentry); */
2507 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
2508 + mutex_unlock(&hidden_dir_dentry->d_inode->i_mutex);
2510 + up(&hidden_dir_dentry->d_inode->i_sem);
2512 + dput(hidden_dir_dentry);
2514 + dput(hidden_new_dentry);
2515 + dput(hidden_old_dentry);
2516 + if (!new_dentry->d_inode)
2517 + d_drop(new_dentry);
2525 +mini_fo_unlink(inode_t *dir, dentry_t *dentry)
2530 + if(dtopd(dentry)->state == MODIFIED) {
2531 + err = nondir_mod_to_del(dentry);
2534 + else if(dtopd(dentry)->state == UNMODIFIED) {
2535 + err = nondir_unmod_to_del(dentry);
2538 + else if(dtopd(dentry)->state == CREATED) {
2539 + err = nondir_creat_to_del(dentry);
2542 + else if(dtopd(dentry)->state == DEL_REWRITTEN) {
2543 + err = nondir_del_rew_to_del(dentry);
2547 + printk(KERN_CRIT "mini_fo_unlink: ERROR, invalid state detected.\n");
2550 + fist_copy_attr_times(dir, itohi2(dentry->d_parent->d_inode));
2553 + /* is this causing my pain? d_delete(dentry); */
2563 +mini_fo_symlink(inode_t *dir, dentry_t *dentry, const char *symname)
2566 + dentry_t *hidden_sto_dentry;
2567 + dentry_t *hidden_sto_dir_dentry;
2568 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
2572 + /* Fail if the symlink file exists */
2573 + if(!(dtost(dentry) == DELETED ||
2574 + dtost(dentry) == NON_EXISTANT)) {
2579 + err = get_neg_sto_dentry(dentry);
2584 + hidden_sto_dentry = dtohd2(dentry);
2586 + dget(hidden_sto_dentry);
2587 + /* was: hidden_sto_dir_dentry = lock_parent(hidden_sto_dentry); */
2588 + hidden_sto_dir_dentry = dget(hidden_sto_dentry->d_parent);
2589 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
2590 + mutex_lock(&hidden_sto_dir_dentry->d_inode->i_mutex);
2592 + down(&hidden_sto_dir_dentry->d_inode->i_sem);
2595 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
2597 + err = vfs_symlink(hidden_sto_dir_dentry->d_inode,
2598 + hidden_sto_dentry, symname, mode);
2600 + err = vfs_symlink(hidden_sto_dir_dentry->d_inode,
2601 + hidden_sto_dentry,
2604 + if (err || !hidden_sto_dentry->d_inode)
2607 + if(dtost(dentry) == DELETED) {
2608 + dtost(dentry) = DEL_REWRITTEN;
2609 + err = mini_fo_tri_interpose(NULL, hidden_sto_dentry, dentry, dir->i_sb, 0);
2612 + } else if(dtost(dentry) == NON_EXISTANT) {
2613 + dtost(dentry) = CREATED;
2614 + err = mini_fo_tri_interpose(dtohd(dentry), hidden_sto_dentry, dentry, dir->i_sb, 0);
2618 + fist_copy_attr_timesizes(dir, hidden_sto_dir_dentry->d_inode);
2621 + /* was: unlock_dir(hidden_sto_dir_dentry); */
2622 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
2623 + mutex_unlock(&hidden_sto_dir_dentry->d_inode->i_mutex);
2625 + up(&hidden_sto_dir_dentry->d_inode->i_sem);
2627 + dput(hidden_sto_dir_dentry);
2629 + dput(hidden_sto_dentry);
2630 + if (!dentry->d_inode)
2637 +mini_fo_mkdir(inode_t *dir, dentry_t *dentry, int mode)
2641 + err = create_sto_dir(dentry, mode);
2643 + check_mini_fo_dentry(dentry);
2650 +mini_fo_rmdir(inode_t *dir, dentry_t *dentry)
2654 + dentry_t *hidden_sto_dentry;
2655 + dentry_t *hidden_sto_dir_dentry;
2656 + dentry_t *meta_dentry;
2657 + inode_t *hidden_sto_dir = NULL;
2659 + check_mini_fo_dentry(dentry);
2660 + check_mini_fo_inode(dir);
2663 + if(dtopd(dentry)->state == MODIFIED) {
2664 + /* XXX: disabled, because it does not bother to check files on
2665 + * the original filesystem - just a hack, but better than simply
2666 + * removing it without testing */
2670 + hidden_sto_dir = itohi2(dir);
2671 + hidden_sto_dentry = dtohd2(dentry);
2673 + /* was:hidden_sto_dir_dentry = lock_parent(hidden_sto_dentry); */
2674 + hidden_sto_dir_dentry = dget(hidden_sto_dentry->d_parent);
2675 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
2676 + mutex_lock(&hidden_sto_dir_dentry->d_inode->i_mutex);
2678 + down(&hidden_sto_dir_dentry->d_inode->i_sem);
2681 + /* Delete an old WOL file contained in the storage dir */
2682 + meta_dentry = lookup_one_len(META_FILENAME,
2683 + hidden_sto_dentry,
2684 + strlen(META_FILENAME));
2685 + if(meta_dentry->d_inode) {
2686 + err = vfs_unlink(hidden_sto_dentry->d_inode, meta_dentry);
2687 + dput(meta_dentry);
2689 + d_delete(meta_dentry);
2692 + err = vfs_rmdir(hidden_sto_dir, hidden_sto_dentry);
2693 + dput(hidden_sto_dentry);
2695 + d_delete(hidden_sto_dentry);
2697 + /* propagate number of hard-links */
2698 + dentry->d_inode->i_nlink = itohi2(dentry->d_inode)->i_nlink;
2700 + dput(dtohd(dentry));
2702 + dtohd(dentry) = NULL;
2703 + dtopd(dentry)->state = DELETED;
2705 + /* carefull with R files */
2706 + if( __meta_is_r_entry(dir,
2707 + dentry->d_name.name,
2708 + dentry->d_name.len) == 1) {
2709 + err = meta_remove_r_entry(dentry->d_parent,
2710 + dentry->d_name.name,
2711 + dentry->d_name.len);
2713 + printk(KERN_CRIT "mini_fo: rmdir: meta_remove_r_entry failed.\n");
2718 + /* ok, add deleted file to META */
2719 + meta_add_d_entry(dentry->d_parent,
2720 + dentry->d_name.name,
2721 + dentry->d_name.len);
2723 + /* was: unlock_dir(hidden_sto_dir_dentry); */
2724 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
2725 + mutex_unlock(&hidden_sto_dir_dentry->d_inode->i_mutex);
2727 + up(&hidden_sto_dir_dentry->d_inode->i_sem);
2729 + dput(hidden_sto_dir_dentry);
2732 + else if(dtopd(dentry)->state == UNMODIFIED) {
2733 + /* XXX: simply adding it to the delete list here is fscking dangerous!
2734 + * as a temporary hack, i will disable rmdir on unmodified directories
2740 + err = get_neg_sto_dentry(dentry);
2746 + /* dput base dentry, this will relase the inode and free the
2747 + * dentry, as we will never need it again. */
2748 + dput(dtohd(dentry));
2749 + dtohd(dentry) = NULL;
2750 + dtopd(dentry)->state = DELETED;
2752 + /* add deleted file to META-file */
2753 + meta_add_d_entry(dentry->d_parent,
2754 + dentry->d_name.name,
2755 + dentry->d_name.len);
2758 + else if(dtopd(dentry)->state == CREATED) {
2759 + hidden_sto_dir = itohi2(dir);
2760 + hidden_sto_dentry = dtohd2(dentry);
2762 + /* was: hidden_sto_dir_dentry = lock_parent(hidden_sto_dentry);*/
2763 + hidden_sto_dir_dentry = dget(hidden_sto_dentry->d_parent);
2765 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
2766 + mutex_lock(&hidden_sto_dir_dentry->d_inode->i_mutex);
2768 + down(&hidden_sto_dir_dentry->d_inode->i_sem);
2771 + /* Delete an old WOL file contained in the storage dir */
2772 + meta_dentry = lookup_one_len(META_FILENAME,
2773 + hidden_sto_dentry,
2774 + strlen(META_FILENAME));
2775 + if(meta_dentry->d_inode) {
2776 + /* is this necessary? dget(meta_dentry); */
2777 + err = vfs_unlink(hidden_sto_dentry->d_inode,
2779 + dput(meta_dentry);
2781 + d_delete(meta_dentry);
2784 + err = vfs_rmdir(hidden_sto_dir, hidden_sto_dentry);
2785 + dput(hidden_sto_dentry);
2787 + d_delete(hidden_sto_dentry);
2789 + /* propagate number of hard-links */
2790 + dentry->d_inode->i_nlink = itohi2(dentry->d_inode)->i_nlink;
2791 + dtopd(dentry)->state = NON_EXISTANT;
2793 + /* was: unlock_dir(hidden_sto_dir_dentry); */
2794 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
2795 + mutex_unlock(&hidden_sto_dir_dentry->d_inode->i_mutex);
2797 + up(&hidden_sto_dir_dentry->d_inode->i_sem);
2799 + dput(hidden_sto_dir_dentry);
2803 + else if(dtopd(dentry)->state == DEL_REWRITTEN) {
2804 + hidden_sto_dir = itohi2(dir);
2805 + hidden_sto_dentry = dtohd2(dentry);
2807 + /* was: hidden_sto_dir_dentry = lock_parent(hidden_sto_dentry);*/
2808 + hidden_sto_dir_dentry = dget(hidden_sto_dentry->d_parent);
2810 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
2811 + mutex_lock(&hidden_sto_dir_dentry->d_inode->i_mutex);
2813 + down(&hidden_sto_dir_dentry->d_inode->i_sem);
2816 + /* Delete an old WOL file contained in the storage dir */
2817 + meta_dentry = lookup_one_len(META_FILENAME,
2818 + hidden_sto_dentry,
2819 + strlen(META_FILENAME));
2820 + if(meta_dentry->d_inode) {
2821 + /* is this necessary? dget(meta_dentry); */
2822 + err = vfs_unlink(hidden_sto_dentry->d_inode,
2824 + dput(meta_dentry);
2826 + d_delete(meta_dentry);
2829 + err = vfs_rmdir(hidden_sto_dir, hidden_sto_dentry);
2830 + dput(hidden_sto_dentry);
2832 + d_delete(hidden_sto_dentry);
2834 + /* propagate number of hard-links */
2835 + dentry->d_inode->i_nlink = itohi2(dentry->d_inode)->i_nlink;
2836 + dtopd(dentry)->state = DELETED;
2837 + /* was: unlock_dir(hidden_sto_dir_dentry); */
2839 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
2840 + mutex_unlock(&hidden_sto_dir_dentry->d_inode->i_mutex);
2842 + up(&hidden_sto_dir_dentry->d_inode->i_sem);
2844 + dput(hidden_sto_dir_dentry);
2848 + printk(KERN_CRIT "mini_fo_rmdir: ERROR, invalid state detected.\n");
2855 + fist_copy_attr_times(dir, itohi2(dentry->d_parent->d_inode));
2863 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
2864 +mini_fo_mknod(inode_t *dir, dentry_t *dentry, int mode, dev_t dev)
2866 +mini_fo_mknod(inode_t *dir, dentry_t *dentry, int mode, int dev)
2871 + check_mini_fo_dentry(dentry);
2873 + err = create_sto_nod(dentry, mode, dev);
2875 + printk(KERN_CRIT "mini_fo_mknod: creating sto nod failed.\n");
2879 + check_mini_fo_dentry(dentry);
2885 +mini_fo_rename(inode_t *old_dir, dentry_t *old_dentry,
2886 + inode_t *new_dir, dentry_t *new_dentry)
2889 + if(S_ISDIR(old_dentry->d_inode->i_mode))
2890 + return rename_directory(old_dir, old_dentry, new_dir, new_dentry);
2891 + return rename_nondir(old_dir, old_dentry, new_dir, new_dentry);
2895 +int rename_directory(inode_t *old_dir, dentry_t *old_dentry,
2896 + inode_t *new_dir, dentry_t *new_dentry)
2898 + int err, bpath_len;
2901 + dentry_t *hidden_old_dentry;
2902 + dentry_t *hidden_new_dentry;
2903 + dentry_t *hidden_old_dir_dentry;
2904 + dentry_t *hidden_new_dir_dentry;
2910 + /* this is a test, chuck out if it works */
2911 + if(!(dtopd(new_dentry)->state == DELETED ||
2912 + dtopd(new_dentry)->state == NON_EXISTANT)) {
2913 + printk(KERN_CRIT "mini_fo: rename_directory: \
2914 + uh, ah, new_dentry not negative.\n");
2918 + /* state = UNMODIFIED */
2919 + if(dtopd(old_dentry)->state == UNMODIFIED) {
2920 + err = dir_unmod_to_mod(old_dentry);
2925 + /* state = MODIFIED */
2926 + if(dtopd(old_dentry)->state == MODIFIED) {
2927 + bpath = meta_check_r_entry(old_dentry->d_parent,
2928 + old_dentry->d_name.name,
2929 + old_dentry->d_name.len);
2931 + err = meta_remove_r_entry(old_dentry->d_parent,
2932 + old_dentry->d_name.name,
2933 + old_dentry->d_name.len);
2935 + printk(KERN_CRIT "mini_fo: rename_directory:\
2936 + meta_remove_r_entry \
2940 + err = meta_add_r_entry(new_dentry->d_parent,
2943 + new_dentry->d_name.name,
2944 + new_dentry->d_name.len);
2947 + else {/* wol it */
2948 + err = meta_add_d_entry(old_dentry->d_parent,
2949 + old_dentry->d_name.name,
2950 + old_dentry->d_name.len);
2953 + /* put it on rename list */
2954 + err = get_mini_fo_bpath(old_dentry,
2959 + err = meta_add_r_entry(new_dentry->d_parent,
2961 + new_dentry->d_name.name,
2962 + new_dentry->d_name.len);
2966 + /* no state change, MODIFIED stays MODIFIED */
2968 + /* state = CREATED */
2969 + if(dtopd(old_dentry)->state == CREATED ||
2970 + dtopd(old_dentry)->state == DEL_REWRITTEN) {
2971 + if(dtohd(old_dentry))
2972 + dput(dtohd(old_dentry));
2974 + if(dtopd(new_dentry)->state == DELETED) {
2975 + dtopd(old_dentry)->state = DEL_REWRITTEN;
2976 + dtohd(old_dentry) = NULL;
2978 + else if(dtopd(new_dentry)->state == NON_EXISTANT) {
2979 + dtopd(old_dentry)->state = CREATED;
2980 + /* steal new dentry's neg. base dentry */
2981 + dtohd(old_dentry) = dtohd(new_dentry);
2982 + dtohd(new_dentry) = NULL;
2985 + if(dtopd(new_dentry)->state == UNMODIFIED ||
2986 + dtopd(new_dentry)->state == NON_EXISTANT) {
2987 + err = get_neg_sto_dentry(new_dentry);
2992 + /* now move sto file */
2993 + hidden_old_dentry = dtohd2(old_dentry);
2994 + hidden_new_dentry = dtohd2(new_dentry);
2996 + dget(hidden_old_dentry);
2997 + dget(hidden_new_dentry);
2999 + hidden_old_dir_dentry = dget(hidden_old_dentry->d_parent);
3000 + hidden_new_dir_dentry = dget(hidden_new_dentry->d_parent);
3001 + double_lock(hidden_old_dir_dentry, hidden_new_dir_dentry);
3003 + err = vfs_rename(hidden_old_dir_dentry->d_inode, hidden_old_dentry,
3004 + hidden_new_dir_dentry->d_inode, hidden_new_dentry);
3008 + fist_copy_attr_all(new_dir, hidden_new_dir_dentry->d_inode);
3009 + if (new_dir != old_dir)
3010 + fist_copy_attr_all(old_dir,
3011 + hidden_old_dir_dentry->d_inode);
3014 + /* double_unlock will dput the new/old parent dentries
3015 + * whose refcnts were incremented via get_parent above. */
3016 + double_unlock(hidden_old_dir_dentry, hidden_new_dir_dentry);
3017 + dput(hidden_new_dentry);
3018 + dput(hidden_old_dentry);
3024 +int rename_nondir(inode_t *old_dir, dentry_t *old_dentry,
3025 + inode_t *new_dir, dentry_t *new_dentry)
3029 + check_mini_fo_dentry(old_dentry);
3030 + check_mini_fo_dentry(new_dentry);
3031 + check_mini_fo_inode(old_dir);
3032 + check_mini_fo_inode(new_dir);
3034 + /* state: UNMODIFIED */
3035 + if(dtost(old_dentry) == UNMODIFIED) {
3036 + err = nondir_unmod_to_mod(old_dentry, 1);
3043 + /* the easy states */
3044 + if(exists_in_storage(old_dentry)) {
3046 + dentry_t *hidden_old_dentry;
3047 + dentry_t *hidden_new_dentry;
3048 + dentry_t *hidden_old_dir_dentry;
3049 + dentry_t *hidden_new_dir_dentry;
3051 + /* if old file is MODIFIED, add it to the deleted_list */
3052 + if(dtopd(old_dentry)->state == MODIFIED) {
3053 + meta_add_d_entry(old_dentry->d_parent,
3054 + old_dentry->d_name.name,
3055 + old_dentry->d_name.len);
3057 + dput(dtohd(old_dentry));
3059 + /* if old file is CREATED, we only release the base dentry */
3060 + if(dtopd(old_dentry)->state == CREATED) {
3061 + if(dtohd(old_dentry))
3062 + dput(dtohd(old_dentry));
3065 + /* now setup the new states (depends on new_dentry state) */
3066 + /* new dentry state = MODIFIED */
3067 + if(dtopd(new_dentry)->state == MODIFIED) {
3068 + meta_add_d_entry(new_dentry->d_parent,
3069 + new_dentry->d_name.name,
3070 + new_dentry->d_name.len);
3072 + /* new dentry will be d_put'ed later by the vfs
3073 + * so don't do it here
3074 + * dput(dtohd(new_dentry));
3076 + dtohd(old_dentry) = NULL;
3077 + dtopd(old_dentry)->state = DEL_REWRITTEN;
3079 + /* new dentry state = UNMODIFIED */
3080 + else if(dtopd(new_dentry)->state == UNMODIFIED) {
3081 + if(get_neg_sto_dentry(new_dentry))
3084 + meta_add_d_entry(new_dentry->d_parent,
3085 + new_dentry->d_name.name,
3086 + new_dentry->d_name.len);
3088 + /* is this right??? */
3089 + /*dput(dtohd(new_dentry));*/
3090 + dtohd(old_dentry) = NULL;
3091 + dtopd(old_dentry)->state = DEL_REWRITTEN;
3093 + /* new dentry state = CREATED */
3094 + else if(dtopd(new_dentry)->state == CREATED) {
3095 + /* we keep the neg. base dentry (if exists) */
3096 + dtohd(old_dentry) = dtohd(new_dentry);
3097 + /* ...and set it to Null, or we'll get
3098 + * dcache.c:345 if it gets dput twice... */
3099 + dtohd(new_dentry) = NULL;
3100 + dtopd(old_dentry)->state = CREATED;
3102 + /* new dentry state = NON_EXISTANT */
3103 + else if(dtopd(new_dentry)->state == NON_EXISTANT) {
3104 + if(get_neg_sto_dentry(new_dentry))
3107 + /* we keep the neg. base dentry (if exists) */
3108 + dtohd(old_dentry) = dtohd(new_dentry);
3109 + /* ...and set it to Null, or we'll get
3110 + * Dr. dcache.c:345 if it gets dput twice... */
3111 + dtohd(new_dentry) = NULL;
3112 + dtopd(old_dentry)->state = CREATED;
3114 + /* new dentry state = DEL_REWRITTEN or DELETED */
3115 + else if(dtopd(new_dentry)->state == DEL_REWRITTEN ||
3116 + dtopd(new_dentry)->state == DELETED) {
3117 + dtohd(old_dentry) = NULL;
3118 + dtopd(old_dentry)->state = DEL_REWRITTEN;
3120 + else { /* not possible, uhh, ahh */
3122 + "mini_fo: rename_reg_file: invalid state detected [1].\n");
3126 + /* now we definitely have a sto file */
3127 + hidden_old_dentry = dtohd2(old_dentry);
3128 + hidden_new_dentry = dtohd2(new_dentry);
3130 + dget(hidden_old_dentry);
3131 + dget(hidden_new_dentry);
3133 + hidden_old_dir_dentry = dget(hidden_old_dentry->d_parent);
3134 + hidden_new_dir_dentry = dget(hidden_new_dentry->d_parent);
3135 + double_lock(hidden_old_dir_dentry, hidden_new_dir_dentry);
3137 + err = vfs_rename(hidden_old_dir_dentry->d_inode,
3138 + hidden_old_dentry,
3139 + hidden_new_dir_dentry->d_inode,
3140 + hidden_new_dentry);
3144 + fist_copy_attr_all(new_dir, hidden_new_dir_dentry->d_inode);
3145 + if (new_dir != old_dir)
3146 + fist_copy_attr_all(old_dir, hidden_old_dir_dentry->d_inode);
3149 + /* double_unlock will dput the new/old parent dentries
3150 + * whose refcnts were incremented via get_parent above.
3152 + double_unlock(hidden_old_dir_dentry, hidden_new_dir_dentry);
3153 + dput(hidden_new_dentry);
3154 + dput(hidden_old_dentry);
3158 + else { /* invalid state */
3159 + printk(KERN_CRIT "mini_fo: rename_reg_file: ERROR: invalid state detected [2].\n");
3166 +mini_fo_readlink(dentry_t *dentry, char *buf, int bufsiz)
3169 + dentry_t *hidden_dentry = NULL;
3171 + if(dtohd2(dentry) && dtohd2(dentry)->d_inode) {
3172 + hidden_dentry = dtohd2(dentry);
3173 + } else if(dtohd(dentry) && dtohd(dentry)->d_inode) {
3174 + hidden_dentry = dtohd(dentry);
3179 + if (!hidden_dentry->d_inode->i_op ||
3180 + !hidden_dentry->d_inode->i_op->readlink) {
3181 + err = -EINVAL; goto out;
3184 + err = hidden_dentry->d_inode->i_op->readlink(hidden_dentry,
3188 + fist_copy_attr_atime(dentry->d_inode, hidden_dentry->d_inode);
3195 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,13)
3196 +static int mini_fo_follow_link(dentry_t *dentry, struct nameidata *nd)
3198 +static void* mini_fo_follow_link(dentry_t *dentry, struct nameidata *nd)
3202 + int len = PAGE_SIZE, err;
3203 + mm_segment_t old_fs;
3205 + /* in 2.6 this is freed by mini_fo_put_link called by __do_follow_link */
3206 + buf = kmalloc(len, GFP_KERNEL);
3212 + /* read the symlink, and then we will follow it */
3213 + old_fs = get_fs();
3214 + set_fs(KERNEL_DS);
3215 + err = dentry->d_inode->i_op->readlink(dentry, buf, len);
3223 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
3224 + nd_set_link(nd, buf);
3227 + err = vfs_follow_link(nd, buf);
3231 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
3235 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,13)
3238 + return ERR_PTR(err);
3243 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
3244 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,13)
3245 +void mini_fo_put_link(struct dentry *dentry, struct nameidata *nd)
3247 +void mini_fo_put_link(struct dentry *dentry, struct nameidata *nd, void *cookie)
3251 + link = nd_get_link(nd);
3257 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
3258 +mini_fo_permission(inode_t *inode, int mask, struct nameidata *nd)
3260 +mini_fo_permission(inode_t *inode, int mask)
3263 + inode_t *hidden_inode;
3267 + if(itohi2(inode)) {
3268 + hidden_inode = itohi2(inode);
3270 + hidden_inode = itohi(inode);
3272 + mode = inode->i_mode;
3274 + /* not really needed, as permission handles everything:
3275 + * err = vfs_permission(inode, mask);
3280 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
3281 + err = permission(hidden_inode, mask, nd);
3283 + err = permission(hidden_inode, mask);
3290 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
3292 +mini_fo_inode_revalidate(dentry_t *dentry)
3295 + dentry_t *hidden_dentry;
3296 + inode_t *hidden_inode;
3298 + ASSERT(dentry->d_inode);
3299 + ASSERT(itopd(dentry->d_inode));
3301 + if(itohi2(dentry->d_inode)) {
3302 + hidden_dentry = dtohd2(dentry);
3303 + hidden_inode = hidden_dentry->d_inode;
3304 + } else if(itohi(dentry->d_inode)) {
3305 + hidden_dentry = dtohd(dentry);
3306 + hidden_inode = hidden_dentry->d_inode;
3308 + printk(KERN_CRIT "mini_fo_inode_revalidate: ERROR, invalid state detected.\n");
3312 + if (hidden_inode && hidden_inode->i_op && hidden_inode->i_op->revalidate){
3313 + err = hidden_inode->i_op->revalidate(hidden_dentry);
3317 + fist_copy_attr_all(dentry->d_inode, hidden_inode);
3324 +mini_fo_setattr(dentry_t *dentry, struct iattr *ia)
3328 + check_mini_fo_dentry(dentry);
3330 + if(!is_mini_fo_existant(dentry)) {
3331 + printk(KERN_CRIT "mini_fo_setattr: ERROR, invalid state detected [1].\n");
3335 + if(dtost(dentry) == UNMODIFIED) {
3336 + if(!IS_COPY_FLAG(ia->ia_valid))
3337 + goto out; /* we ignore these changes to base */
3339 + if(S_ISDIR(dentry->d_inode->i_mode)) {
3340 + err = dir_unmod_to_mod(dentry);
3342 + /* we copy contents if file is not beeing truncated */
3343 + if(S_ISREG(dentry->d_inode->i_mode) &&
3344 + !(ia->ia_size == 0 && (ia->ia_valid & ATTR_SIZE))) {
3345 + err = nondir_unmod_to_mod(dentry, 1);
3347 + err = nondir_unmod_to_mod(dentry, 0);
3351 + printk(KERN_CRIT "mini_fo_setattr: ERROR changing states.\n");
3355 + if(!exists_in_storage(dentry)) {
3356 + printk(KERN_CRIT "mini_fo_setattr: ERROR, invalid state detected [2].\n");
3360 + ASSERT(dentry->d_inode);
3361 + ASSERT(dtohd2(dentry));
3362 + ASSERT(itopd(dentry->d_inode));
3363 + ASSERT(itohi2(dentry->d_inode));
3365 + err = notify_change(dtohd2(dentry), ia);
3366 + fist_copy_attr_all(dentry->d_inode, itohi2(dentry->d_inode));
3371 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
3373 +mini_fo_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
3376 + dentry_t *hidden_dentry;
3378 + ASSERT(dentry->d_inode);
3379 + ASSERT(itopd(dentry->d_inode));
3381 + if(itohi2(dentry->d_inode)) {
3382 + hidden_dentry = dtohd2(dentry);
3383 + } else if(itohi(dentry->d_inode)) {
3384 + hidden_dentry = dtohd(dentry);
3386 + printk(KERN_CRIT "mini_fo_getattr: ERROR, invalid state detected.\n");
3390 + fist_copy_attr_all(dentry->d_inode, hidden_dentry->d_inode);
3392 + ASSERT(hidden_dentry);
3393 + ASSERT(hidden_dentry->d_inode);
3394 + ASSERT(hidden_dentry->d_inode->i_op);
3396 + generic_fillattr(dentry->d_inode, stat);
3397 + if (!stat->blksize) {
3398 + struct super_block *s = hidden_dentry->d_inode->i_sb;
3400 + blocks = (stat->size+s->s_blocksize-1) >> s->s_blocksize_bits;
3401 + stat->blocks = (s->s_blocksize / 512) * blocks;
3402 + stat->blksize = s->s_blocksize;
3409 +#if defined(XATTR) && (LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,20))
3410 +#if 0 /* no xattr_alloc() and xattr_free() */
3411 +/* This is lifted from fs/xattr.c */
3413 +xattr_alloc(size_t size, size_t limit)
3418 + return ERR_PTR(-E2BIG);
3420 + if (!size) /* size request, no buffer is needed */
3422 + else if (size <= PAGE_SIZE)
3423 + ptr = kmalloc((unsigned long) size, GFP_KERNEL);
3425 + ptr = vmalloc((unsigned long) size);
3427 + return ERR_PTR(-ENOMEM);
3432 +xattr_free(void *ptr, size_t size)
3434 + if (!size) /* size request, no buffer was needed */
3436 + else if (size <= PAGE_SIZE)
3441 +#endif /* no xattr_alloc() and xattr_free() */
3443 +/* BKL held by caller.
3444 + * dentry->d_inode->i_sem down
3447 +mini_fo_getxattr(struct dentry *dentry, const char *name, void *value, size_t size) {
3448 + struct dentry *hidden_dentry = NULL;
3449 + int err = -EOPNOTSUPP;
3450 + /* Define these anyway so we don't need as much ifdef'ed code. */
3451 + char *encoded_name = NULL;
3452 + char *encoded_value = NULL;
3454 + check_mini_fo_dentry(dentry);
3456 + if(exists_in_storage(dentry))
3457 + hidden_dentry = dtohd2(dentry);
3459 + hidden_dentry = dtohd(dentry);
3461 + ASSERT(hidden_dentry);
3462 + ASSERT(hidden_dentry->d_inode);
3463 + ASSERT(hidden_dentry->d_inode->i_op);
3465 + if (hidden_dentry->d_inode->i_op->getxattr) {
3466 + encoded_name = (char *)name;
3467 + encoded_value = (char *)value;
3469 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
3470 + mutex_lock(&hidden_dentry->d_inode->i_mutex);
3472 + down(&hidden_dentry->d_inode->i_sem);
3474 + /* lock_kernel() already done by caller. */
3475 + err = hidden_dentry->d_inode->i_op->getxattr(hidden_dentry, encoded_name, encoded_value, size);
3476 + /* unlock_kernel() will be done by caller. */
3477 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
3478 + mutex_lock(&hidden_dentry->d_inode->i_mutex);
3480 + up(&hidden_dentry->d_inode->i_sem);
3486 +/* BKL held by caller.
3487 + * dentry->d_inode->i_sem down
3490 +#if ((LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,21) \
3491 + && LINUX_VERSION_CODE <= KERNEL_VERSION(2,4,23)) \
3492 + || LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0))
3493 +mini_fo_setxattr(struct dentry *dentry, const char *name,
3494 + const void *value, size_t size, int flags)
3496 +mini_fo_setxattr(struct dentry *dentry, const char *name,
3497 + void *value, size_t size, int flags)
3501 + struct dentry *hidden_dentry = NULL;
3502 + int err = -EOPNOTSUPP;
3504 + /* Define these anyway, so we don't have as much ifdef'ed code. */
3505 + char *encoded_value = NULL;
3506 + char *encoded_name = NULL;
3508 + check_mini_fo_dentry(dentry);
3510 + if(exists_in_storage(dentry))
3511 + hidden_dentry = dtohd2(dentry);
3513 + hidden_dentry = dtohd(dentry);
3515 + ASSERT(hidden_dentry);
3516 + ASSERT(hidden_dentry->d_inode);
3517 + ASSERT(hidden_dentry->d_inode->i_op);
3519 + if (hidden_dentry->d_inode->i_op->setxattr) {
3520 + encoded_name = (char *)name;
3521 + encoded_value = (char *)value;
3523 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
3524 + mutex_lock(&hidden_dentry->d_inode->i_mutex);
3526 + down(&hidden_dentry->d_inode->i_sem);
3528 + /* lock_kernel() already done by caller. */
3529 + err = hidden_dentry->d_inode->i_op->setxattr(hidden_dentry, encoded_name, encoded_value, size, flags);
3530 + /* unlock_kernel() will be done by caller. */
3531 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
3532 + mutex_unlock(&hidden_dentry->d_inode->i_mutex);
3534 + up(&hidden_dentry->d_inode->i_sem);
3540 +/* BKL held by caller.
3541 + * dentry->d_inode->i_sem down
3544 +mini_fo_removexattr(struct dentry *dentry, const char *name) {
3545 + struct dentry *hidden_dentry = NULL;
3546 + int err = -EOPNOTSUPP;
3547 + char *encoded_name;
3549 + check_mini_fo_dentry(dentry);
3551 + if(exists_in_storage(dentry))
3552 + hidden_dentry = dtohd2(dentry);
3554 + hidden_dentry = dtohd(dentry);
3556 + ASSERT(hidden_dentry);
3557 + ASSERT(hidden_dentry->d_inode);
3558 + ASSERT(hidden_dentry->d_inode->i_op);
3560 + if (hidden_dentry->d_inode->i_op->removexattr) {
3561 + encoded_name = (char *)name;
3563 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
3564 + mutex_lock(&hidden_dentry->d_inode->i_mutex);
3566 + down(&hidden_dentry->d_inode->i_sem);
3568 + /* lock_kernel() already done by caller. */
3569 + err = hidden_dentry->d_inode->i_op->removexattr(hidden_dentry, encoded_name);
3570 + /* unlock_kernel() will be done by caller. */
3571 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
3572 + mutex_unlock(&hidden_dentry->d_inode->i_mutex);
3574 + up(&hidden_dentry->d_inode->i_sem);
3580 +/* BKL held by caller.
3581 + * dentry->d_inode->i_sem down
3584 +mini_fo_listxattr(struct dentry *dentry, char *list, size_t size) {
3585 + struct dentry *hidden_dentry = NULL;
3586 + int err = -EOPNOTSUPP;
3587 + char *encoded_list = NULL;
3589 + check_mini_fo_dentry(dentry);
3591 + if(exists_in_storage(dentry))
3592 + hidden_dentry = dtohd2(dentry);
3594 + hidden_dentry = dtohd(dentry);
3596 + ASSERT(hidden_dentry);
3597 + ASSERT(hidden_dentry->d_inode);
3598 + ASSERT(hidden_dentry->d_inode->i_op);
3600 + if (hidden_dentry->d_inode->i_op->listxattr) {
3601 + encoded_list = list;
3603 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
3604 + mutex_lock(&hidden_dentry->d_inode->i_mutex);
3606 + down(&hidden_dentry->d_inode->i_sem);
3608 + /* lock_kernel() already done by caller. */
3609 + err = hidden_dentry->d_inode->i_op->listxattr(hidden_dentry, encoded_list, size);
3610 + /* unlock_kernel() will be done by caller. */
3611 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
3612 + mutex_unlock(&hidden_dentry->d_inode->i_mutex);
3614 + up(&hidden_dentry->d_inode->i_sem);
3619 +# endif /* defined(XATTR) && (LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,20)) */
3621 +struct inode_operations mini_fo_symlink_iops =
3623 + readlink: mini_fo_readlink,
3624 + follow_link: mini_fo_follow_link,
3625 + /* mk: permission: mini_fo_permission, */
3626 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
3627 + revalidate: mini_fo_inode_revalidate,
3629 + setattr: mini_fo_setattr,
3630 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
3631 + getattr: mini_fo_getattr,
3632 + put_link: mini_fo_put_link,
3635 +#if defined(XATTR) && (LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,20))
3636 + setxattr: mini_fo_setxattr,
3637 + getxattr: mini_fo_getxattr,
3638 + listxattr: mini_fo_listxattr,
3639 + removexattr: mini_fo_removexattr
3640 +# endif /* defined(XATTR) && (LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,20)) */
3643 +struct inode_operations mini_fo_dir_iops =
3645 + create: mini_fo_create,
3646 + lookup: mini_fo_lookup,
3647 + link: mini_fo_link,
3648 + unlink: mini_fo_unlink,
3649 + symlink: mini_fo_symlink,
3650 + mkdir: mini_fo_mkdir,
3651 + rmdir: mini_fo_rmdir,
3652 + mknod: mini_fo_mknod,
3653 + rename: mini_fo_rename,
3654 + /* no readlink/follow_link for non-symlinks */
3655 + // off because we have setattr
3656 + // truncate: mini_fo_truncate,
3657 + /* mk:permission: mini_fo_permission, */
3658 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
3659 + revalidate: mini_fo_inode_revalidate,
3661 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
3662 + getattr: mini_fo_getattr,
3664 + setattr: mini_fo_setattr,
3665 +#if defined(XATTR) && (LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,20))
3666 + setxattr: mini_fo_setxattr,
3667 + getxattr: mini_fo_getxattr,
3668 + listxattr: mini_fo_listxattr,
3669 + removexattr: mini_fo_removexattr
3670 +# endif /* XATTR && LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,20) */
3673 +struct inode_operations mini_fo_main_iops =
3675 + /* permission: mini_fo_permission, */
3676 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
3677 + revalidate: mini_fo_inode_revalidate,
3679 + setattr: mini_fo_setattr,
3681 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
3682 + getattr: mini_fo_getattr,
3684 +#if defined(XATTR) && (LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,20))
3685 + setxattr: mini_fo_setxattr,
3686 + getxattr: mini_fo_getxattr,
3687 + listxattr: mini_fo_listxattr,
3688 + removexattr: mini_fo_removexattr
3689 +# endif /* XATTR && LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,20) */
3691 Index: linux-2.6.21.7/fs/mini_fo/main.c
3692 ===================================================================
3694 +++ linux-2.6.21.7/fs/mini_fo/main.c
3697 + * Copyright (c) 1997-2003 Erez Zadok
3698 + * Copyright (c) 2001-2003 Stony Brook University
3700 + * For specific licensing information, see the COPYING file distributed with
3701 + * this package, or get one from ftp://ftp.filesystems.org/pub/fist/COPYING.
3703 + * This Copyright notice must be kept intact and distributed with all
3704 + * fistgen sources INCLUDING sources generated by fistgen.
3707 + * Copyright (C) 2004, 2005 Markus Klotzbuecher <mk@creamnet.de>
3709 + * This program is free software; you can redistribute it and/or
3710 + * modify it under the terms of the GNU General Public License
3711 + * as published by the Free Software Foundation; either version
3712 + * 2 of the License, or (at your option) any later version.
3719 +#ifdef HAVE_CONFIG_H
3720 +# include <config.h>
3724 +#include "mini_fo.h"
3725 +#include <linux/module.h>
3727 +/* This definition must only appear after we include <linux/module.h> */
3728 +#ifndef MODULE_LICENSE
3729 +# define MODULE_LICENSE(bison)
3730 +#endif /* not MODULE_LICENSE */
3733 + * This is the mini_fo tri interpose function, which extends the
3734 + * functionality of the regular interpose by interposing a higher
3735 + * level inode on top of two lower level ones: the base filesystem
3736 + * inode and the storage filesystem inode.
3738 + * sb we pass is mini_fo's super_block
3741 +mini_fo_tri_interpose(dentry_t *hidden_dentry,
3742 + dentry_t *hidden_sto_dentry,
3743 + dentry_t *dentry, super_block_t *sb, int flag)
3745 + inode_t *hidden_inode = NULL;
3746 + inode_t *hidden_sto_inode = NULL; /* store corresponding storage inode */
3750 + /* Pointer to hidden_sto_inode if exists, else to hidden_inode.
3751 + * This is used to copy the attributes of the correct inode. */
3752 + inode_t *master_inode;
3755 + hidden_inode = hidden_dentry->d_inode;
3756 + if(hidden_sto_dentry)
3757 + hidden_sto_inode = hidden_sto_dentry->d_inode;
3759 + ASSERT(dentry->d_inode == NULL);
3761 + /* mk: One of the inodes associated with the dentrys is likely to
3762 + * be NULL, so carefull:
3764 + ASSERT((hidden_inode != NULL) || (hidden_sto_inode != NULL));
3766 + if(hidden_sto_inode)
3767 + master_inode = hidden_sto_inode;
3769 + master_inode = hidden_inode;
3772 + * We allocate our new inode below, by calling iget.
3773 + * iget will call our read_inode which will initialize some
3774 + * of the new inode's fields
3778 + * original: inode = iget(sb, hidden_inode->i_ino);
3780 + inode = iget(sb, iunique(sb, 25));
3782 + err = -EACCES; /* should be impossible??? */
3787 + * interpose the inode if not already interposed
3788 + * this is possible if the inode is being reused
3789 + * XXX: what happens if we get_empty_inode() but there's another already?
3790 + * for now, ASSERT() that this can't happen; fix later.
3792 + if (itohi(inode) != NULL) {
3793 + printk(KERN_CRIT "mini_fo_tri_interpose: itohi(inode) != NULL.\n");
3795 + if (itohi2(inode) != NULL) {
3796 + printk(KERN_CRIT "mini_fo_tri_interpose: itohi2(inode) != NULL.\n");
3799 + /* mk: Carefull, igrab can't handle NULL inodes (ok, why should it?), so
3800 + * we need to check here:
3803 + itohi(inode) = igrab(hidden_inode);
3805 + itohi(inode) = NULL;
3807 + if(hidden_sto_inode)
3808 + itohi2(inode) = igrab(hidden_sto_inode);
3810 + itohi2(inode) = NULL;
3813 + /* Use different set of inode ops for symlinks & directories*/
3814 + if (S_ISLNK(master_inode->i_mode))
3815 + inode->i_op = &mini_fo_symlink_iops;
3816 + else if (S_ISDIR(master_inode->i_mode))
3817 + inode->i_op = &mini_fo_dir_iops;
3819 + /* Use different set of file ops for directories */
3820 + if (S_ISDIR(master_inode->i_mode))
3821 + inode->i_fop = &mini_fo_dir_fops;
3823 + /* properly initialize special inodes */
3824 + if (S_ISBLK(master_inode->i_mode) || S_ISCHR(master_inode->i_mode) ||
3825 + S_ISFIFO(master_inode->i_mode) || S_ISSOCK(master_inode->i_mode)) {
3826 + init_special_inode(inode, master_inode->i_mode, master_inode->i_rdev);
3829 + /* Fix our inode's address operations to that of the lower inode */
3830 + if (inode->i_mapping->a_ops != master_inode->i_mapping->a_ops) {
3831 + inode->i_mapping->a_ops = master_inode->i_mapping->a_ops;
3834 + /* only (our) lookup wants to do a d_add */
3836 + d_add(dentry, inode);
3838 + d_instantiate(dentry, inode);
3840 + ASSERT(dtopd(dentry) != NULL);
3842 + /* all well, copy inode attributes */
3843 + fist_copy_attr_all(inode, master_inode);
3849 +/* parse mount options "base=" and "sto=" */
3851 +mini_fo_parse_options(super_block_t *sb, char *options)
3853 + dentry_t *hidden_root = ERR_PTR(-EINVAL);
3854 + dentry_t *hidden_root2 = ERR_PTR(-EINVAL);
3855 + struct nameidata nd, nd2;
3856 + char *name, *tmp, *end;
3859 + /* We don't want to go off the end of our arguments later on. */
3860 + for (end = options; *end; end++);
3862 + while (options < end) {
3864 + while (*tmp && *tmp != ',')
3867 + if (!strncmp("base=", options, 5)) {
3868 + name = options + 5;
3869 + printk(KERN_INFO "mini_fo: using base directory: %s\n", name);
3871 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
3872 + if (path_init(name, LOOKUP_FOLLOW, &nd))
3873 + err = path_walk(name, &nd);
3875 + err = path_lookup(name, LOOKUP_FOLLOW, &nd);
3878 + printk(KERN_CRIT "mini_fo: error accessing hidden directory '%s'\n", name);
3879 + hidden_root = ERR_PTR(err);
3882 + hidden_root = nd.dentry;
3883 + stopd(sb)->base_dir_dentry = nd.dentry;
3884 + stopd(sb)->hidden_mnt = nd.mnt;
3886 + } else if(!strncmp("sto=", options, 4)) {
3887 + /* parse the storage dir */
3888 + name = options + 4;
3889 + printk(KERN_INFO "mini_fo: using storage directory: %s\n", name);
3890 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
3891 + if(path_init(name, LOOKUP_FOLLOW, &nd2))
3892 + err = path_walk(name, &nd2);
3894 + err = path_lookup(name, LOOKUP_FOLLOW, &nd2);
3897 + printk(KERN_CRIT "mini_fo: error accessing hidden storage directory '%s'\n", name);
3899 + hidden_root2 = ERR_PTR(err);
3902 + hidden_root2 = nd2.dentry;
3903 + stopd(sb)->storage_dir_dentry = nd2.dentry;
3904 + stopd(sb)->hidden_mnt2 = nd2.mnt;
3905 + stohs2(sb) = hidden_root2->d_sb;
3907 + /* validate storage dir, this is done in
3908 + * mini_fo_read_super for the base directory.
3910 + if (IS_ERR(hidden_root2)) {
3911 + printk(KERN_WARNING "mini_fo_parse_options: storage dentry lookup failed (err = %ld)\n", PTR_ERR(hidden_root2));
3914 + if (!hidden_root2->d_inode) {
3915 + printk(KERN_WARNING "mini_fo_parse_options: no storage dir to interpose on.\n");
3918 + stohs2(sb) = hidden_root2->d_sb;
3920 + printk(KERN_WARNING "mini_fo: unrecognized option '%s'\n", options);
3921 + hidden_root = ERR_PTR(-EINVAL);
3924 + options = tmp + 1;
3928 + if(IS_ERR(hidden_root2))
3929 + return hidden_root2;
3930 + return hidden_root;
3934 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
3939 +mini_fo_read_super(super_block_t *sb, void *raw_data, int silent)
3941 + dentry_t *hidden_root;
3945 + printk(KERN_WARNING "mini_fo_read_super: missing argument\n");
3950 + * Allocate superblock private data
3952 + __stopd(sb) = kmalloc(sizeof(struct mini_fo_sb_info), GFP_KERNEL);
3954 + printk(KERN_WARNING "%s: out of memory\n", __FUNCTION__);
3960 + hidden_root = mini_fo_parse_options(sb, raw_data);
3961 + if (IS_ERR(hidden_root)) {
3962 + printk(KERN_WARNING "mini_fo_read_super: lookup_dentry failed (err = %ld)\n", PTR_ERR(hidden_root));
3963 + err = PTR_ERR(hidden_root);
3966 + if (!hidden_root->d_inode) {
3967 + printk(KERN_WARNING "mini_fo_read_super: no directory to interpose on\n");
3970 + stohs(sb) = hidden_root->d_sb;
3973 + * Linux 2.4.2-ac3 and beyond has code in
3974 + * mm/filemap.c:generic_file_write() that requires sb->s_maxbytes
3975 + * to be populated. If not set, all write()s under that sb will
3978 + * Linux 2.4.4+ automatically sets s_maxbytes to MAX_NON_LFS;
3979 + * the filesystem should override it only if it supports LFS.
3981 + /* non-SCA code is good to go with LFS */
3982 + sb->s_maxbytes = hidden_root->d_sb->s_maxbytes;
3984 + sb->s_op = &mini_fo_sops;
3986 + * we can't use d_alloc_root if we want to use
3987 + * our own interpose function unchanged,
3988 + * so we simply replicate *most* of the code in d_alloc_root here
3990 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
3991 + sb->s_root = d_alloc(NULL, &(const struct qstr) { "/", 1, 0 });
3993 + sb->s_root = d_alloc(NULL, &(const struct qstr){hash: 0, name: "/", len : 1});
3995 + if (IS_ERR(sb->s_root)) {
3996 + printk(KERN_WARNING "mini_fo_read_super: d_alloc failed\n");
4001 + sb->s_root->d_op = &mini_fo_dops;
4002 + sb->s_root->d_sb = sb;
4003 + sb->s_root->d_parent = sb->s_root;
4005 + /* link the upper and lower dentries */
4006 + __dtopd(sb->s_root) = (struct mini_fo_dentry_info *)
4007 + kmalloc(sizeof(struct mini_fo_dentry_info), GFP_KERNEL);
4008 + if (!dtopd(sb->s_root)) {
4012 + dtopd(sb->s_root)->state = MODIFIED;
4013 + dtohd(sb->s_root) = hidden_root;
4015 + /* fanout relevant, interpose on storage root dentry too */
4016 + dtohd2(sb->s_root) = stopd(sb)->storage_dir_dentry;
4018 + /* ...and call tri-interpose to interpose root dir inodes
4019 + * if (mini_fo_interpose(hidden_root, sb->s_root, sb, 0))
4021 + if(mini_fo_tri_interpose(hidden_root, dtohd2(sb->s_root), sb->s_root, sb, 0))
4024 + /* initalize the wol list */
4025 + itopd(sb->s_root->d_inode)->deleted_list_size = -1;
4026 + itopd(sb->s_root->d_inode)->renamed_list_size = -1;
4027 + meta_build_lists(sb->s_root);
4034 + dput(hidden_root);
4035 + dput(dtohd2(sb->s_root)); /* release the hidden_sto_dentry too */
4038 + __stopd(sb) = NULL;
4041 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
4045 + return ERR_PTR(err);
4052 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
4053 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,18)
4054 +static int mini_fo_get_sb(struct file_system_type *fs_type,
4055 + int flags, const char *dev_name,
4056 + void *raw_data, struct vfsmount *mnt)
4058 + return get_sb_nodev(fs_type, flags, raw_data, mini_fo_read_super, mnt);
4061 +static struct super_block *mini_fo_get_sb(struct file_system_type *fs_type,
4062 + int flags, const char *dev_name,
4065 + return get_sb_nodev(fs_type, flags, raw_data, mini_fo_read_super);
4069 +void mini_fo_kill_block_super(struct super_block *sb)
4071 + generic_shutdown_super(sb);
4073 + * XXX: BUG: Halcrow: Things get unstable sometime after this point:
4074 + * lib/rwsem-spinlock.c:127: spin_is_locked on uninitialized
4075 + * fs/fs-writeback.c:402: spin_lock(fs/super.c:a0381828) already
4076 + * locked by fs/fs-writeback.c/402
4078 + * Apparently, someone's not releasing a lock on sb_lock...
4082 +static struct file_system_type mini_fo_fs_type = {
4083 + .owner = THIS_MODULE,
4084 + .name = "mini_fo",
4085 + .get_sb = mini_fo_get_sb,
4086 + .kill_sb = mini_fo_kill_block_super,
4092 +static DECLARE_FSTYPE(mini_fo_fs_type, "mini_fo", mini_fo_read_super, 0);
4095 +static int __init init_mini_fo_fs(void)
4097 + printk("Registering mini_fo version $Id$\n");
4098 + return register_filesystem(&mini_fo_fs_type);
4100 +static void __exit exit_mini_fo_fs(void)
4102 + printk("Unregistering mini_fo version $Id$\n");
4103 + unregister_filesystem(&mini_fo_fs_type);
4106 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
4110 +MODULE_AUTHOR("Erez Zadok <ezk@cs.sunysb.edu>");
4111 +MODULE_DESCRIPTION("FiST-generated mini_fo filesystem");
4112 +MODULE_LICENSE("GPL");
4114 +/* MODULE_PARM(fist_debug_var, "i"); */
4115 +/* MODULE_PARM_DESC(fist_debug_var, "Debug level"); */
4117 +module_init(init_mini_fo_fs)
4118 +module_exit(exit_mini_fo_fs)
4119 Index: linux-2.6.21.7/fs/mini_fo/Makefile
4120 ===================================================================
4122 +++ linux-2.6.21.7/fs/mini_fo/Makefile
4125 +# Makefile for mini_fo 2.4 and 2.6 Linux kernels
4127 +# Copyright (C) 2004, 2005 Markus Klotzbuecher <mk@creamnet.de>
4129 +# This program is free software; you can redistribute it and/or
4130 +# modify it under the terms of the GNU General Public License
4131 +# as published by the Free Software Foundation; either version
4132 +# 2 of the License, or (at your option) any later version.
4135 +obj-$(CONFIG_MINI_FO) := mini_fo.o
4136 +mini_fo-objs := meta.o dentry.o file.o inode.o main.o super.o state.o aux.o
4139 +${mini_fo-objs}: mini_fo.h fist.h
4141 Index: linux-2.6.21.7/fs/mini_fo/meta.c
4142 ===================================================================
4144 +++ linux-2.6.21.7/fs/mini_fo/meta.c
4147 + * Copyright (C) 2004, 2005 Markus Klotzbuecher <mk@creamnet.de>
4149 + * This program is free software; you can redistribute it and/or
4150 + * modify it under the terms of the GNU General Public License
4151 + * as published by the Free Software Foundation; either version
4152 + * 2 of the License, or (at your option) any later version.
4155 +#ifdef HAVE_CONFIG_H
4156 +# include <config.h>
4157 +#endif /* HAVE_CONFIG_H */
4159 +#include "mini_fo.h"
4161 +int meta_build_lists(dentry_t *dentry)
4163 + struct mini_fo_inode_info *inode_info;
4165 + dentry_t *meta_dentry = 0;
4166 + file_t *meta_file = 0;
4167 + mm_segment_t old_fs;
4171 + struct vfsmount *meta_mnt;
4174 + inode_info = itopd(dentry->d_inode);
4175 + if(!(inode_info->deleted_list_size == -1 &&
4176 + inode_info->renamed_list_size == -1)) {
4177 + printk(KERN_CRIT "mini_fo: meta_build_lists: \
4178 + Error, list(s) not virgin.\n");
4182 + /* init our meta lists */
4183 + INIT_LIST_HEAD(&inode_info->deleted_list);
4184 + inode_info->deleted_list_size = 0;
4186 + INIT_LIST_HEAD(&inode_info->renamed_list);
4187 + inode_info->renamed_list_size = 0;
4189 + /* might there be a META-file? */
4190 + if(dtohd2(dentry) && dtohd2(dentry)->d_inode) {
4191 + meta_dentry = lookup_one_len(META_FILENAME,
4193 + strlen(META_FILENAME));
4194 + if(!meta_dentry->d_inode) {
4195 + dput(meta_dentry);
4198 + /* $%& err, is this correct? */
4199 + meta_mnt = stopd(dentry->d_inode->i_sb)->hidden_mnt2;
4203 + /* open META-file for reading */
4204 + meta_file = dentry_open(meta_dentry, meta_mnt, 0x0);
4205 + if(!meta_file || IS_ERR(meta_file)) {
4206 + printk(KERN_CRIT "mini_fo: meta_build_lists: \
4207 + ERROR opening META file.\n");
4211 + /* check if fs supports reading */
4212 + if(!meta_file->f_op->read) {
4213 + printk(KERN_CRIT "mini_fo: meta_build_lists: \
4214 + ERROR, fs does not support reading.\n");
4215 + goto out_err_close;
4218 + /* allocate a page for transfering the data */
4219 + buf = (void *) __get_free_page(GFP_KERNEL);
4221 + printk(KERN_CRIT "mini_fo: meta_build_lists: \
4222 + ERROR, out of mem.\n");
4223 + goto out_err_close;
4225 + meta_file->f_pos = 0;
4226 + old_fs = get_fs();
4227 + set_fs(KERNEL_DS);
4230 + bytes = meta_file->f_op->read(meta_file, buf, PAGE_SIZE, &meta_file->f_pos);
4231 + if(bytes == PAGE_SIZE) {
4232 + /* trim a cut off filename and adjust f_pos to get it next time */
4233 + for(c = (char*) buf+PAGE_SIZE;
4235 + c--, bytes--, meta_file->f_pos--);
4237 + entry = (char *) buf;
4238 + while(entry < (char *) buf+bytes) {
4242 + int old_len, new_len;
4244 + /* len without '\n'*/
4245 + len = (int) (strchr(entry, '\n') - entry);
4248 + /* format: "D filename" */
4249 + meta_list_add_d_entry(dentry,
4254 + /* format: "R path/xy/dir newDir" */
4255 + old_path = entry+2;
4256 + dir_name = strchr(old_path, ' ') + 1;
4257 + old_len = dir_name - old_path - 1;
4258 + new_len = ((int) entry) + len - ((int ) dir_name);
4259 + meta_list_add_r_entry(dentry,
4266 + /* unknown entry type detected */
4272 + } while(meta_file->f_pos < meta_dentry->d_inode->i_size);
4274 + free_page((unsigned long) buf);
4284 + dput(meta_dentry);
4287 + return 1; /* check this!!! inode_info->wol_size; */
4290 +/* cleanups up all lists and free's the mem by dentry */
4291 +int meta_put_lists(dentry_t *dentry)
4293 + if(!dentry || !dentry->d_inode) {
4294 + printk("mini_fo: meta_put_lists: invalid dentry passed.\n");
4297 + return __meta_put_lists(dentry->d_inode);
4300 +/* cleanups up all lists and free's the mem by inode */
4301 +int __meta_put_lists(inode_t *inode)
4304 + if(!inode || !itopd(inode)) {
4305 + printk("mini_fo: __meta_put_lists: invalid inode passed.\n");
4308 + err = __meta_put_d_list(inode);
4309 + err |= __meta_put_r_list(inode);
4313 +int meta_sync_lists(dentry_t *dentry)
4316 + if(!dentry || !dentry->d_inode) {
4317 + printk("mini_fo: meta_sync_lists: \
4318 + invalid dentry passed.\n");
4321 + err = meta_sync_d_list(dentry, 0);
4322 + err |= meta_sync_r_list(dentry, 1);
4327 +/* remove all D entries from the renamed list and free the mem */
4328 +int __meta_put_d_list(inode_t *inode)
4330 + struct list_head *tmp;
4331 + struct deleted_entry *del_entry;
4332 + struct mini_fo_inode_info *inode_info;
4334 + if(!inode || !itopd(inode)) {
4335 + printk(KERN_CRIT "mini_fo: __meta_put_d_list: \
4336 + invalid inode passed.\n");
4339 + inode_info = itopd(inode);
4341 + /* nuke the DELETED-list */
4342 + if(inode_info->deleted_list_size <= 0)
4345 + while(!list_empty(&inode_info->deleted_list)) {
4346 + tmp = inode_info->deleted_list.next;
4348 + del_entry = list_entry(tmp, struct deleted_entry, list);
4349 + kfree(del_entry->name);
4352 + inode_info->deleted_list_size = 0;
4357 +/* remove all R entries from the renamed list and free the mem */
4358 +int __meta_put_r_list(inode_t *inode)
4360 + struct list_head *tmp;
4361 + struct renamed_entry *ren_entry;
4362 + struct mini_fo_inode_info *inode_info;
4364 + if(!inode || !itopd(inode)) {
4365 + printk(KERN_CRIT "mini_fo: meta_put_r_list: invalid inode.\n");
4368 + inode_info = itopd(inode);
4370 + /* nuke the RENAMED-list */
4371 + if(inode_info->renamed_list_size <= 0)
4374 + while(!list_empty(&inode_info->renamed_list)) {
4375 + tmp = inode_info->renamed_list.next;
4377 + ren_entry = list_entry(tmp, struct renamed_entry, list);
4378 + kfree(ren_entry->new_name);
4379 + kfree(ren_entry->old_name);
4382 + inode_info->renamed_list_size = 0;
4387 +int meta_add_d_entry(dentry_t *dentry, const char *name, int len)
4390 + err = meta_list_add_d_entry(dentry, name, len);
4391 + err |= meta_write_d_entry(dentry,name,len);
4395 +/* add a D entry to the deleted list */
4396 +int meta_list_add_d_entry(dentry_t *dentry, const char *name, int len)
4398 + struct deleted_entry *del_entry;
4399 + struct mini_fo_inode_info *inode_info;
4401 + if(!dentry || !dentry->d_inode) {
4402 + printk(KERN_CRIT "mini_fo: meta_list_add_d_entry: \
4403 + invalid dentry passed.\n");
4406 + inode_info = itopd(dentry->d_inode);
4408 + if(inode_info->deleted_list_size < 0)
4411 + del_entry = (struct deleted_entry *)
4412 + kmalloc(sizeof(struct deleted_entry), GFP_KERNEL);
4413 + del_entry->name = (char*) kmalloc(len, GFP_KERNEL);
4414 + if(!del_entry || !del_entry->name) {
4415 + printk(KERN_CRIT "mini_fo: meta_list_add_d_entry: \
4417 + kfree(del_entry->name);
4422 + strncpy(del_entry->name, name, len);
4423 + del_entry->len = len;
4425 + list_add(&del_entry->list, &inode_info->deleted_list);
4426 + inode_info->deleted_list_size++;
4430 +int meta_add_r_entry(dentry_t *dentry,
4431 + const char *old_name, int old_len,
4432 + const char *new_name, int new_len)
4435 + err = meta_list_add_r_entry(dentry,
4436 + old_name, old_len,
4437 + new_name, new_len);
4438 + err |= meta_write_r_entry(dentry,
4439 + old_name, old_len,
4440 + new_name, new_len);
4444 +/* add a R entry to the renamed list */
4445 +int meta_list_add_r_entry(dentry_t *dentry,
4446 + const char *old_name, int old_len,
4447 + const char *new_name, int new_len)
4449 + struct renamed_entry *ren_entry;
4450 + struct mini_fo_inode_info *inode_info;
4452 + if(!dentry || !dentry->d_inode) {
4453 + printk(KERN_CRIT "mini_fo: meta_list_add_r_entry: \
4454 + invalid dentry passed.\n");
4457 + inode_info = itopd(dentry->d_inode);
4459 + if(inode_info->renamed_list_size < 0)
4462 + ren_entry = (struct renamed_entry *)
4463 + kmalloc(sizeof(struct renamed_entry), GFP_KERNEL);
4464 + ren_entry->old_name = (char*) kmalloc(old_len, GFP_KERNEL);
4465 + ren_entry->new_name = (char*) kmalloc(new_len, GFP_KERNEL);
4467 + if(!ren_entry || !ren_entry->old_name || !ren_entry->new_name) {
4468 + printk(KERN_CRIT "mini_fo: meta_list_add_r_entry: \
4470 + kfree(ren_entry->new_name);
4471 + kfree(ren_entry->old_name);
4476 + strncpy(ren_entry->old_name, old_name, old_len);
4477 + ren_entry->old_len = old_len;
4478 + strncpy(ren_entry->new_name, new_name, new_len);
4479 + ren_entry->new_len = new_len;
4481 + list_add(&ren_entry->list, &inode_info->renamed_list);
4482 + inode_info->renamed_list_size++;
4487 +int meta_remove_r_entry(dentry_t *dentry, const char *name, int len)
4490 + if(!dentry || !dentry->d_inode) {
4492 + "mini_fo: meta_remove_r_entry: \
4493 + invalid dentry passed.\n");
4497 + err = meta_list_remove_r_entry(dentry, name, len);
4498 + err |= meta_sync_lists(dentry);
4502 +int meta_list_remove_r_entry(dentry_t *dentry, const char *name, int len)
4504 + if(!dentry || !dentry->d_inode) {
4506 + "mini_fo: meta_list_remove_r_entry: \
4507 + invalid dentry passed.\n");
4510 + return __meta_list_remove_r_entry(dentry->d_inode, name, len);
4513 +int __meta_list_remove_r_entry(inode_t *inode, const char *name, int len)
4515 + struct list_head *tmp;
4516 + struct renamed_entry *ren_entry;
4517 + struct mini_fo_inode_info *inode_info;
4519 + if(!inode || !itopd(inode))
4521 + "mini_fo: __meta_list_remove_r_entry: \
4522 + invalid inode passed.\n");
4523 + inode_info = itopd(inode);
4525 + if(inode_info->renamed_list_size < 0)
4527 + if(inode_info->renamed_list_size == 0)
4530 + list_for_each(tmp, &inode_info->renamed_list) {
4531 + ren_entry = list_entry(tmp, struct renamed_entry, list);
4532 + if(ren_entry->new_len != len)
4535 + if(!strncmp(ren_entry->new_name, name, len)) {
4537 + kfree(ren_entry->new_name);
4538 + kfree(ren_entry->old_name);
4540 + inode_info->renamed_list_size--;
4548 +/* append a single D entry to the meta file */
4549 +int meta_write_d_entry(dentry_t *dentry, const char *name, int len)
4551 + dentry_t *meta_dentry = 0;
4552 + file_t *meta_file = 0;
4553 + mm_segment_t old_fs;
4556 + struct vfsmount *meta_mnt = 0;
4561 + if(itopd(dentry->d_inode)->deleted_list_size < 0) {
4566 + if(dtopd(dentry)->state == UNMODIFIED) {
4567 + err = build_sto_structure(dentry->d_parent, dentry);
4569 + printk(KERN_CRIT "mini_fo: meta_write_d_entry: \
4570 + build_sto_structure failed.\n");
4574 + meta_dentry = lookup_one_len(META_FILENAME,
4575 + dtohd2(dentry), strlen (META_FILENAME));
4577 + /* We need to create a META-file */
4578 + if(!meta_dentry->d_inode) {
4579 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
4580 + vfs_create(dtohd2(dentry)->d_inode,
4582 + S_IRUSR | S_IWUSR,
4585 + vfs_create(dtohd2(dentry)->d_inode,
4587 + S_IRUSR | S_IWUSR);
4590 + /* open META-file for writing */
4591 + meta_file = dentry_open(meta_dentry, meta_mnt, 0x1);
4592 + if(!meta_file || IS_ERR(meta_file)) {
4593 + printk(KERN_CRIT "mini_fo: meta_write_d_entry: \
4594 + ERROR opening meta file.\n");
4595 + mntput(meta_mnt); /* $%& is this necessary? */
4596 + dput(meta_dentry);
4601 + /* check if fs supports writing */
4602 + if(!meta_file->f_op->write) {
4603 + printk(KERN_CRIT "mini_fo: meta_write_d_entry: \
4604 + ERROR, fs does not support writing.\n");
4605 + goto out_err_close;
4608 + meta_file->f_pos = meta_dentry->d_inode->i_size; /* append */
4609 + old_fs = get_fs();
4610 + set_fs(KERNEL_DS);
4612 + /* size: len for name, 1 for \n and 2 for "D " */
4613 + buf = (char *) kmalloc(len+3, GFP_KERNEL);
4615 + printk(KERN_CRIT "mini_fo: meta_write_d_entry: \
4622 + strncpy(buf+2, name, len);
4623 + buf[len+2] = '\n';
4624 + bytes = meta_file->f_op->write(meta_file, buf, len+3,
4625 + &meta_file->f_pos);
4626 + if(bytes != len+3) {
4627 + printk(KERN_CRIT "mini_fo: meta_write_d_entry: \
4628 + ERROR writing.\n");
4640 +/* append a single R entry to the meta file */
4641 +int meta_write_r_entry(dentry_t *dentry,
4642 + const char *old_name, int old_len,
4643 + const char *new_name, int new_len)
4645 + dentry_t *meta_dentry = 0;
4646 + file_t *meta_file = 0;
4647 + mm_segment_t old_fs;
4649 + int bytes, err, buf_len;
4650 + struct vfsmount *meta_mnt = 0;
4656 + if(itopd(dentry->d_inode)->renamed_list_size < 0) {
4661 + /* build the storage structure? */
4662 + if(dtopd(dentry)->state == UNMODIFIED) {
4663 + err = build_sto_structure(dentry->d_parent, dentry);
4665 + printk(KERN_CRIT "mini_fo: meta_write_r_entry: \
4666 + build_sto_structure failed.\n");
4670 + meta_dentry = lookup_one_len(META_FILENAME,
4672 + strlen (META_FILENAME));
4673 + if(!meta_dentry->d_inode) {
4674 + /* We need to create a META-file */
4675 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
4676 + vfs_create(dtohd2(dentry)->d_inode,
4677 + meta_dentry, S_IRUSR | S_IWUSR, NULL);
4679 + vfs_create(dtohd2(dentry)->d_inode,
4680 + meta_dentry, S_IRUSR | S_IWUSR);
4683 + /* open META-file for writing */
4684 + meta_file = dentry_open(meta_dentry, meta_mnt, 0x1);
4685 + if(!meta_file || IS_ERR(meta_file)) {
4686 + printk(KERN_CRIT "mini_fo: meta_write_r_entry: \
4687 + ERROR opening meta file.\n");
4689 + dput(meta_dentry);
4694 + /* check if fs supports writing */
4695 + if(!meta_file->f_op->write) {
4696 + printk(KERN_CRIT "mini_fo: meta_write_r_entry: \
4697 + ERROR, fs does not support writing.\n");
4698 + goto out_err_close;
4701 + meta_file->f_pos = meta_dentry->d_inode->i_size; /* append */
4702 + old_fs = get_fs();
4703 + set_fs(KERNEL_DS);
4705 + /* size: 2 for "R ", old_len+new_len for names, 1 blank+1 \n */
4706 + buf_len = old_len + new_len + 4;
4707 + buf = (char *) kmalloc(buf_len, GFP_KERNEL);
4709 + printk(KERN_CRIT "mini_fo: meta_write_r_entry: out of mem.\n");
4715 + strncpy(buf + 2, old_name, old_len);
4716 + buf[old_len + 2] = ' ';
4717 + strncpy(buf + old_len + 3, new_name, new_len);
4718 + buf[buf_len -1] = '\n';
4719 + bytes = meta_file->f_op->write(meta_file, buf, buf_len, &meta_file->f_pos);
4720 + if(bytes != buf_len) {
4721 + printk(KERN_CRIT "mini_fo: meta_write_r_entry: ERROR writing.\n");
4734 +/* sync D list to disk, append data if app_flag is 1 */
4735 +/* check the meta_mnt, which seems not to be used (properly) */
4737 +int meta_sync_d_list(dentry_t *dentry, int app_flag)
4739 + dentry_t *meta_dentry;
4740 + file_t *meta_file;
4741 + mm_segment_t old_fs;
4744 + struct vfsmount *meta_mnt;
4747 + struct list_head *tmp;
4748 + struct deleted_entry *del_entry;
4749 + struct mini_fo_inode_info *inode_info;
4755 + if(!dentry || !dentry->d_inode) {
4756 + printk(KERN_CRIT "mini_fo: meta_sync_d_list: \
4757 + invalid inode passed.\n");
4761 + inode_info = itopd(dentry->d_inode);
4763 + if(inode_info->deleted_list_size < 0) {
4768 + /* ok, there is something to sync */
4770 + /* build the storage structure? */
4771 + if(!dtohd2(dentry) && !itohi2(dentry->d_inode)) {
4772 + err = build_sto_structure(dentry->d_parent, dentry);
4774 + printk(KERN_CRIT "mini_fo: meta_sync_d_list: \
4775 + build_sto_structure failed.\n");
4779 + meta_dentry = lookup_one_len(META_FILENAME,
4781 + strlen(META_FILENAME));
4782 + if(!meta_dentry->d_inode) {
4783 + /* We need to create a META-file */
4784 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
4785 + vfs_create(dtohd2(dentry)->d_inode,
4786 + meta_dentry, S_IRUSR | S_IWUSR, NULL);
4788 + vfs_create(dtohd2(dentry)->d_inode,
4789 + meta_dentry, S_IRUSR | S_IWUSR);
4793 + /* need we truncate the meta file? */
4795 + struct iattr newattrs;
4796 + newattrs.ia_size = 0;
4797 + newattrs.ia_valid = ATTR_SIZE | ATTR_CTIME;
4799 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
4800 + mutex_lock(&meta_dentry->d_inode->i_mutex);
4802 + down(&meta_dentry->d_inode->i_sem);
4804 + err = notify_change(meta_dentry, &newattrs);
4806 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
4807 + mutex_unlock(&meta_dentry->d_inode->i_mutex);
4809 + up(&meta_dentry->d_inode->i_sem);
4812 + if(err || meta_dentry->d_inode->i_size != 0) {
4813 + printk(KERN_CRIT "mini_fo: meta_sync_d_list: \
4814 + ERROR truncating meta file.\n");
4815 + goto out_err_close;
4819 + /* open META-file for writing */
4820 + meta_file = dentry_open(meta_dentry, meta_mnt, 0x1);
4821 + if(!meta_file || IS_ERR(meta_file)) {
4822 + printk(KERN_CRIT "mini_fo: meta_sync_d_list: \
4823 + ERROR opening meta file.\n");
4824 + /* we don't mntget so we dont't mntput (for now)
4825 + * mntput(meta_mnt);
4827 + dput(meta_dentry);
4832 + /* check if fs supports writing */
4833 + if(!meta_file->f_op->write) {
4834 + printk(KERN_CRIT "mini_fo: meta_sync_d_list: \
4835 + ERROR, fs does not support writing.\n");
4836 + goto out_err_close;
4839 + meta_file->f_pos = meta_dentry->d_inode->i_size; /* append */
4840 + old_fs = get_fs();
4841 + set_fs(KERNEL_DS);
4843 + /* here we go... */
4844 + list_for_each(tmp, &inode_info->deleted_list) {
4845 + del_entry = list_entry(tmp, struct deleted_entry, list);
4847 + /* size: len for name, 1 for \n and 2 for "D " */
4848 + buf = (char *) kmalloc(del_entry->len+3, GFP_KERNEL);
4850 + printk(KERN_CRIT "mini_fo: meta_sync_d_list: \
4857 + strncpy(buf+2, del_entry->name, del_entry->len);
4858 + buf[del_entry->len+2] = '\n';
4859 + bytes = meta_file->f_op->write(meta_file, buf,
4861 + &meta_file->f_pos);
4862 + if(bytes != del_entry->len+3) {
4863 + printk(KERN_CRIT "mini_fo: meta_sync_d_list: \
4864 + ERROR writing.\n");
4878 +int meta_sync_r_list(dentry_t *dentry, int app_flag)
4880 + dentry_t *meta_dentry;
4881 + file_t *meta_file;
4882 + mm_segment_t old_fs;
4884 + int bytes, err, buf_len;
4885 + struct vfsmount *meta_mnt;
4888 + struct list_head *tmp;
4889 + struct renamed_entry *ren_entry;
4890 + struct mini_fo_inode_info *inode_info;
4896 + if(!dentry || !dentry->d_inode) {
4897 + printk(KERN_CRIT "mini_fo: meta_sync_r_list: \
4898 + invalid dentry passed.\n");
4902 + inode_info = itopd(dentry->d_inode);
4904 + if(inode_info->deleted_list_size < 0) {
4909 + /* ok, there is something to sync */
4911 + /* build the storage structure? */
4912 + if(!dtohd2(dentry) && !itohi2(dentry->d_inode)) {
4913 + err = build_sto_structure(dentry->d_parent, dentry);
4915 + printk(KERN_CRIT "mini_fo: meta_sync_r_list: \
4916 + build_sto_structure failed.\n");
4920 + meta_dentry = lookup_one_len(META_FILENAME,
4922 + strlen(META_FILENAME));
4923 + if(!meta_dentry->d_inode) {
4924 + /* We need to create a META-file */
4925 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
4926 + vfs_create(dtohd2(dentry)->d_inode,
4927 + meta_dentry, S_IRUSR | S_IWUSR, NULL);
4929 + vfs_create(dtohd2(dentry)->d_inode,
4930 + meta_dentry, S_IRUSR | S_IWUSR);
4934 + /* need we truncate the meta file? */
4936 + struct iattr newattrs;
4937 + newattrs.ia_size = 0;
4938 + newattrs.ia_valid = ATTR_SIZE | ATTR_CTIME;
4940 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
4941 + mutex_lock(&meta_dentry->d_inode->i_mutex);
4943 + down(&meta_dentry->d_inode->i_sem);
4945 + err = notify_change(meta_dentry, &newattrs);
4947 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
4948 + mutex_unlock(&meta_dentry->d_inode->i_mutex);
4950 + up(&meta_dentry->d_inode->i_sem);
4952 + if(err || meta_dentry->d_inode->i_size != 0) {
4953 + printk(KERN_CRIT "mini_fo: meta_sync_r_list: \
4954 + ERROR truncating meta file.\n");
4955 + goto out_err_close;
4959 + /* open META-file for writing */
4960 + meta_file = dentry_open(meta_dentry, meta_mnt, 0x1);
4961 + if(!meta_file || IS_ERR(meta_file)) {
4962 + printk(KERN_CRIT "mini_fo: meta_sync_r_list: \
4963 + ERROR opening meta file.\n");
4964 + /* we don't mntget so we dont't mntput (for now)
4965 + * mntput(meta_mnt);
4967 + dput(meta_dentry);
4972 + /* check if fs supports writing */
4973 + if(!meta_file->f_op->write) {
4974 + printk(KERN_CRIT "mini_fo: meta_sync_r_list: \
4975 + ERROR, fs does not support writing.\n");
4976 + goto out_err_close;
4979 + meta_file->f_pos = meta_dentry->d_inode->i_size; /* append */
4980 + old_fs = get_fs();
4981 + set_fs(KERNEL_DS);
4983 + /* here we go... */
4984 + list_for_each(tmp, &inode_info->renamed_list) {
4985 + ren_entry = list_entry(tmp, struct renamed_entry, list);
4987 + * 2 for "R ", old_len+new_len for names, 1 blank+1 \n */
4988 + buf_len = ren_entry->old_len + ren_entry->new_len + 4;
4989 + buf = (char *) kmalloc(buf_len, GFP_KERNEL);
4991 + printk(KERN_CRIT "mini_fo: meta_sync_r_list: \
4997 + strncpy(buf + 2, ren_entry->old_name, ren_entry->old_len);
4998 + buf[ren_entry->old_len + 2] = ' ';
4999 + strncpy(buf + ren_entry->old_len + 3,
5000 + ren_entry->new_name, ren_entry->new_len);
5001 + buf[buf_len - 1] = '\n';
5002 + bytes = meta_file->f_op->write(meta_file, buf,
5003 + buf_len, &meta_file->f_pos);
5004 + if(bytes != buf_len) {
5005 + printk(KERN_CRIT "mini_fo: meta_sync_r_list: \
5006 + ERROR writing.\n");
5019 +int meta_check_d_entry(dentry_t *dentry, const char *name, int len)
5021 + if(!dentry || !dentry->d_inode)
5022 + printk(KERN_CRIT "mini_fo: meta_check_d_dentry: \
5023 + invalid dentry passed.\n");
5024 + return __meta_check_d_entry(dentry->d_inode, name, len);
5027 +int __meta_check_d_entry(inode_t *inode, const char *name, int len)
5029 + struct list_head *tmp;
5030 + struct deleted_entry *del_entry;
5031 + struct mini_fo_inode_info *inode_info;
5033 + if(!inode || !itopd(inode))
5034 + printk(KERN_CRIT "mini_fo: __meta_check_d_dentry: \
5035 + invalid inode passed.\n");
5037 + inode_info = itopd(inode);
5039 + if(inode_info->deleted_list_size <= 0)
5042 + list_for_each(tmp, &inode_info->deleted_list) {
5043 + del_entry = list_entry(tmp, struct deleted_entry, list);
5044 + if(del_entry->len != len)
5047 + if(!strncmp(del_entry->name, name, len))
5054 + * check if file has been renamed and return path to orig. base dir.
5055 + * Implements no error return values so far, what of course sucks.
5056 + * String is null terminated.'
5058 +char* meta_check_r_entry(dentry_t *dentry, const char *name, int len)
5060 + if(!dentry || !dentry->d_inode) {
5061 + printk(KERN_CRIT "mini_fo: meta_check_r_dentry: \
5062 + invalid dentry passed.\n");
5065 + return __meta_check_r_entry(dentry->d_inode, name, len);
5068 +char* __meta_check_r_entry(inode_t *inode, const char *name, int len)
5070 + struct list_head *tmp;
5071 + struct renamed_entry *ren_entry;
5072 + struct mini_fo_inode_info *inode_info;
5075 + if(!inode || !itopd(inode)) {
5076 + printk(KERN_CRIT "mini_fo: meta_check_r_dentry: \
5077 + invalid inode passed.\n");
5080 + inode_info = itopd(inode);
5082 + if(inode_info->renamed_list_size <= 0)
5085 + list_for_each(tmp, &inode_info->renamed_list) {
5086 + ren_entry = list_entry(tmp, struct renamed_entry, list);
5087 + if(ren_entry->new_len != len)
5090 + if(!strncmp(ren_entry->new_name, name, len)) {
5091 + old_path = (char *)
5092 + kmalloc(ren_entry->old_len+1, GFP_KERNEL);
5094 + ren_entry->old_name,
5095 + ren_entry->old_len);
5096 + old_path[ren_entry->old_len]='\0';
5104 + * This version only checks if entry exists and return:
5109 +int meta_is_r_entry(dentry_t *dentry, const char *name, int len)
5111 + if(!dentry || !dentry->d_inode) {
5112 + printk(KERN_CRIT "mini_fo: meta_check_r_dentry [2]: \
5113 + invalid dentry passed.\n");
5116 + return __meta_is_r_entry(dentry->d_inode, name, len);
5119 +int __meta_is_r_entry(inode_t *inode, const char *name, int len)
5121 + struct list_head *tmp;
5122 + struct renamed_entry *ren_entry;
5123 + struct mini_fo_inode_info *inode_info;
5125 + if(!inode || !itopd(inode)) {
5126 + printk(KERN_CRIT "mini_fo: meta_check_r_dentry [2]: \
5127 + invalid inode passed.\n");
5130 + inode_info = itopd(inode);
5132 + if(inode_info->renamed_list_size <= 0)
5135 + list_for_each(tmp, &inode_info->renamed_list) {
5136 + ren_entry = list_entry(tmp, struct renamed_entry, list);
5137 + if(ren_entry->new_len != len)
5140 + if(!strncmp(ren_entry->new_name, name, len))
5146 Index: linux-2.6.21.7/fs/mini_fo/mini_fo.h
5147 ===================================================================
5149 +++ linux-2.6.21.7/fs/mini_fo/mini_fo.h
5152 + * Copyright (c) 1997-2003 Erez Zadok
5153 + * Copyright (c) 2001-2003 Stony Brook University
5155 + * For specific licensing information, see the COPYING file distributed with
5156 + * this package, or get one from ftp://ftp.filesystems.org/pub/fist/COPYING.
5158 + * This Copyright notice must be kept intact and distributed with all
5159 + * fistgen sources INCLUDING sources generated by fistgen.
5162 + * Copyright (C) 2004, 2005 Markus Klotzbuecher <mk@creamnet.de>
5164 + * This program is free software; you can redistribute it and/or
5165 + * modify it under the terms of the GNU General Public License
5166 + * as published by the Free Software Foundation; either version
5167 + * 2 of the License, or (at your option) any later version.
5174 +#ifndef __MINI_FO_H_
5175 +#define __MINI_FO_H_
5180 +#define META_FILENAME "META_dAfFgHE39ktF3HD2sr"
5185 +/* File attributes that when changed, result in a file beeing copied to storage */
5186 +#define COPY_FLAGS ATTR_MODE | ATTR_UID | ATTR_GID | ATTR_SIZE
5189 + * mini_fo filestates
5192 +#define UNMODIFIED 2
5194 +#define DEL_REWRITTEN 4
5196 +#define NON_EXISTANT 6
5198 +/* fist file systems superblock magic */
5199 +# define MINI_FO_SUPER_MAGIC 0xf15f
5205 +/* mini_fo inode data in memory */
5206 +struct mini_fo_inode_info {
5207 + inode_t *wii_inode;
5208 + inode_t *wii_inode2; /* pointer to storage inode */
5210 + /* META-data lists */
5211 + /* deleted list, ex wol */
5212 + struct list_head deleted_list;
5213 + int deleted_list_size;
5215 + /* renamed list */
5216 + struct list_head renamed_list;
5217 + int renamed_list_size;
5219 + /* add other lists here ... */
5222 +/* mini_fo dentry data in memory */
5223 +struct mini_fo_dentry_info {
5224 + dentry_t *wdi_dentry;
5225 + dentry_t *wdi_dentry2; /* pointer to storage dentry */
5226 + unsigned int state; /* state of the mini_fo dentry */
5230 +/* mini_fo super-block data in memory */
5231 +struct mini_fo_sb_info {
5232 + super_block_t *wsi_sb, *wsi_sb2; /* mk: might point to the same sb */
5233 + struct vfsmount *hidden_mnt, *hidden_mnt2;
5234 + dentry_t *base_dir_dentry;
5235 + dentry_t *storage_dir_dentry;
5239 +/* readdir_data, readdir helper struct */
5240 +struct readdir_data {
5241 + struct list_head ndl_list; /* linked list head ptr */
5242 + int ndl_size; /* list size */
5243 + int sto_done; /* flag to show that the storage dir entries have
5244 + * all been read an now follow base entries */
5247 +/* file private data. */
5248 +struct mini_fo_file_info {
5249 + struct file *wfi_file;
5250 + struct file *wfi_file2; /* pointer to storage file */
5251 + struct readdir_data rd;
5254 +/* struct ndl_entry */
5256 + struct list_head list;
5261 +/********************************
5262 + * META-data structures
5263 + ********************************/
5265 +/* deleted entry */
5266 +struct deleted_entry {
5267 + struct list_head list;
5272 +/* renamed entry */
5273 +struct renamed_entry {
5274 + struct list_head list;
5275 + char *old_name; /* old directory with full path */
5276 + int old_len; /* length of above string */
5277 + char *new_name; /* new directory name */
5278 + int new_len; /* length of above string */
5281 +/* attr_change entry */
5282 +struct attr_change_entry {
5283 + struct list_head list;
5289 +struct link_entry {
5290 + struct list_head list;
5295 + int weird_name_len;
5299 +/* Some other stuff required for mini_fo_filldir64, copied from
5303 +#define ROUND_UP64(x) (((x)+sizeof(u64)-1) & ~(sizeof(u64)-1))
5304 +#define NAME_OFFSET(de) ((int) ((de)->d_name - (char *) (de)))
5307 +struct linux_dirent64 {
5310 + unsigned short d_reclen;
5311 + unsigned char d_type;
5316 +struct getdents_callback64 {
5317 + struct linux_dirent64 * current_dir;
5318 + struct linux_dirent64 * previous;
5323 +struct linux_dirent {
5324 + unsigned long d_ino;
5325 + unsigned long d_off;
5326 + unsigned short d_reclen;
5330 +struct getdents_callback {
5331 + struct linux_dirent * current_dir;
5332 + struct linux_dirent * previous;
5342 +/* file TO private_data */
5343 +# define ftopd(file) ((struct mini_fo_file_info *)((file)->private_data))
5344 +# define __ftopd(file) ((file)->private_data)
5345 +/* file TO hidden_file */
5346 +# define ftohf(file) ((ftopd(file))->wfi_file)
5347 +# define ftohf2(file) ((ftopd(file))->wfi_file2)
5349 +/* inode TO private_data */
5350 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,18)
5351 +# define itopd(ino) ((struct mini_fo_inode_info *)(ino)->i_private)
5352 +# define __itopd(ino) ((ino)->i_private)
5354 +# define itopd(ino) ((struct mini_fo_inode_info *)(ino)->u.generic_ip)
5355 +# define __itopd(ino) ((ino)->u.generic_ip)
5357 +/* inode TO hidden_inode */
5358 +# define itohi(ino) (itopd(ino)->wii_inode)
5359 +# define itohi2(ino) (itopd(ino)->wii_inode2)
5361 +/* superblock TO private_data */
5362 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
5363 +# define stopd(super) ((struct mini_fo_sb_info *)(super)->s_fs_info)
5364 +# define __stopd(super) ((super)->s_fs_info)
5366 +# define stopd(super) ((struct mini_fo_sb_info *)(super)->u.generic_sbp)
5367 +# define __stopd(super) ((super)->u.generic_sbp)
5370 +/* unused? # define vfs2priv stopd */
5371 +/* superblock TO hidden_superblock */
5373 +# define stohs(super) (stopd(super)->wsi_sb)
5374 +# define stohs2(super) (stopd(super)->wsi_sb2)
5376 +/* dentry TO private_data */
5377 +# define dtopd(dentry) ((struct mini_fo_dentry_info *)(dentry)->d_fsdata)
5378 +# define __dtopd(dentry) ((dentry)->d_fsdata)
5379 +/* dentry TO hidden_dentry */
5380 +# define dtohd(dent) (dtopd(dent)->wdi_dentry)
5381 +# define dtohd2(dent) (dtopd(dent)->wdi_dentry2)
5383 +/* dentry to state */
5384 +# define dtost(dent) (dtopd(dent)->state)
5385 +# define sbt(sb) ((sb)->s_type->name)
5387 +#define IS_WRITE_FLAG(flag) (flag & (O_RDWR | O_WRONLY | O_APPEND))
5388 +#define IS_COPY_FLAG(flag) (flag & (COPY_FLAGS))
5390 +/* macros to simplify non-SCA code */
5391 +# define MALLOC_PAGE_POINTERS(hidden_pages, num_hidden_pages)
5392 +# define MALLOC_PAGEDATA_POINTERS(hidden_pages_data, num_hidden_pages)
5393 +# define FREE_PAGE_POINTERS(hidden_pages, num)
5394 +# define FREE_PAGEDATA_POINTERS(hidden_pages_data, num)
5395 +# define FOR_EACH_PAGE
5396 +# define CURRENT_HIDDEN_PAGE hidden_page
5397 +# define CURRENT_HIDDEN_PAGEDATA hidden_page_data
5398 +# define CURRENT_HIDDEN_PAGEINDEX page->index
5403 +extern struct file_operations mini_fo_main_fops;
5404 +extern struct file_operations mini_fo_dir_fops;
5405 +extern struct inode_operations mini_fo_main_iops;
5406 +extern struct inode_operations mini_fo_dir_iops;
5407 +extern struct inode_operations mini_fo_symlink_iops;
5408 +extern struct super_operations mini_fo_sops;
5409 +extern struct dentry_operations mini_fo_dops;
5410 +extern struct vm_operations_struct mini_fo_shared_vmops;
5411 +extern struct vm_operations_struct mini_fo_private_vmops;
5412 +extern struct address_space_operations mini_fo_aops;
5414 +#if 0 /* unused by mini_fo */
5415 +extern int mini_fo_interpose(dentry_t *hidden_dentry, dentry_t *this_dentry, super_block_t *sb, int flag);
5416 +#if defined(FIST_FILTER_DATA) || defined(FIST_FILTER_SCA)
5417 +extern page_t *mini_fo_get1page(file_t *file, int index);
5418 +extern int mini_fo_fill_zeros(file_t *file, page_t *page, unsigned from);
5419 +# endif /* FIST_FILTER_DATA || FIST_FILTER_SCA */
5422 +# define mini_fo_hidden_dentry(d) __mini_fo_hidden_dentry(__FILE__,__FUNCTION__,__LINE__,(d))
5423 +# define mini_fo_hidden_sto_dentry(d) __mini_fo_hidden_sto_dentry(__FILE__,__FUNCTION__,__LINE__,(d))
5425 +extern dentry_t *__mini_fo_hidden_dentry(char *file, char *func, int line, dentry_t *this_dentry);
5426 +extern dentry_t *__mini_fo_hidden_sto_dentry(char *file, char *func, int line, dentry_t *this_dentry);
5428 +extern int mini_fo_read_file(const char *filename, void *buf, int len);
5429 +extern int mini_fo_write_file(const char *filename, void *buf, int len);
5430 +extern dentry_t *fist_lookup(dentry_t *dir, const char *name, vnode_t **out, uid_t uid, gid_t gid);
5431 +#endif /* unused by mini_fo */
5433 +/* state transition functions */
5434 +extern int nondir_unmod_to_mod(dentry_t *dentry, int cp_flag);
5435 +extern int nondir_del_rew_to_del(dentry_t *dentry);
5436 +extern int nondir_creat_to_del(dentry_t *dentry);
5437 +extern int nondir_mod_to_del(dentry_t *dentry);
5438 +extern int nondir_unmod_to_del(dentry_t *dentry);
5440 +extern int dir_unmod_to_mod(dentry_t *dentry);
5442 +/* rename specials */
5443 +extern int rename_directory(inode_t *old_dir, dentry_t *old_dentry, inode_t *new_dir, dentry_t *new_dentry);
5444 +extern int rename_nondir(inode_t *old_dir, dentry_t *old_dentry, inode_t *new_dir, dentry_t *new_dentry);
5447 +extern int mini_fo_tri_interpose(dentry_t *hidden_dentry,
5448 + dentry_t *hidden_sto_dentry,
5450 + super_block_t *sb, int flag);
5452 +extern int mini_fo_cp_cont(dentry_t *tgt_dentry, struct vfsmount *tgt_mnt,
5453 + dentry_t *src_dentry, struct vfsmount *src_mnt);
5455 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
5456 +extern int mini_fo_create(inode_t *dir, dentry_t *dentry, int mode, struct nameidata *nd);
5458 +extern int create_sto_nod(dentry_t *dentry, int mode, dev_t dev);
5459 +extern int create_sto_reg_file(dentry_t *dentry, int mode, struct nameidata *nd);
5461 +extern int mini_fo_create(inode_t *dir, dentry_t *dentry, int mode);
5463 +extern int create_sto_nod(dentry_t *dentry, int mode, int dev);
5464 +extern int create_sto_reg_file(dentry_t *dentry, int mode);
5467 +extern int create_sto_dir(dentry_t *dentry, int mode);
5469 +extern int exists_in_storage(dentry_t *dentry);
5470 +extern int is_mini_fo_existant(dentry_t *dentry);
5471 +extern int get_neg_sto_dentry(dentry_t *dentry);
5472 +extern int build_sto_structure(dentry_t *dir, dentry_t *dentry);
5473 +extern int get_mini_fo_bpath(dentry_t *dentry, char **bpath, int *bpath_len);
5474 +extern dentry_t *bpath_walk(super_block_t *sb, char *bpath);
5475 +extern int bpath_put(dentry_t *dentry);
5477 +/* check_mini_fo types functions */
5478 +extern int check_mini_fo_dentry(dentry_t *dentry);
5479 +extern int check_mini_fo_file(file_t *file);
5480 +extern int check_mini_fo_inode(inode_t *inode);
5482 +/* General meta functions, can be called from outside of meta.c */
5483 +extern int meta_build_lists(dentry_t *dentry);
5484 +extern int meta_put_lists(dentry_t *dentry);
5485 +extern int __meta_put_lists(inode_t *inode);
5487 +extern int meta_add_d_entry(dentry_t *dentry, const char *name, int len);
5488 +extern int meta_add_r_entry(dentry_t *dentry,
5489 + const char *old_name, int old_len,
5490 + const char *new_name, int new_len);
5492 +extern int meta_remove_r_entry(dentry_t *dentry, const char *name, int len);
5494 +extern int meta_check_d_entry(dentry_t *dentry, const char *name, int len);
5495 +extern int __meta_check_d_entry(inode_t *inode, const char *name, int len);
5497 +extern char* meta_check_r_entry(dentry_t *dentry, const char *name, int len);
5498 +extern char* __meta_check_r_entry(inode_t *inode, const char *name, int len);
5499 +extern int meta_is_r_entry(dentry_t *dentry, const char *name, int len);
5500 +extern int __meta_is_r_entry(inode_t *inode, const char *name, int len);
5502 +/* Specific meta functions, should be called only inside meta.c */
5503 +extern int __meta_put_d_list(inode_t *inode);
5504 +extern int __meta_put_r_list(inode_t *inode);
5506 +extern int meta_list_add_d_entry(dentry_t *dentry,
5507 + const char *name, int len);
5508 +extern int meta_list_add_r_entry(dentry_t *dentry,
5509 + const char *old_name, int old_len,
5510 + const char *new_name, int new_len);
5512 +extern int meta_list_remove_r_entry(dentry_t *dentry,
5513 + const char *name, int len);
5515 +extern int __meta_list_remove_r_entry(inode_t *inode,
5516 + const char *name, int len);
5518 +extern int meta_write_d_entry(dentry_t *dentry, const char *name, int len);
5519 +extern int meta_write_r_entry(dentry_t *dentry,
5520 + const char *old_name, int old_len,
5521 + const char *new_name, int new_len);
5523 +extern int meta_sync_lists(dentry_t *dentry);
5524 +extern int meta_sync_d_list(dentry_t *dentry, int app_flag);
5525 +extern int meta_sync_r_list(dentry_t *dentry, int app_flag);
5528 +extern int ndl_add_entry(struct readdir_data *rd, const char *name, int len);
5529 +extern void ndl_put_list(struct readdir_data *rd);
5530 +extern int ndl_check_entry(struct readdir_data *rd,
5531 + const char *name, int len);
5534 +# define copy_inode_size(dst, src) \
5535 + dst->i_size = src->i_size; \
5536 + dst->i_blocks = src->i_blocks;
5539 +fist_copy_attr_atime(inode_t *dest, const inode_t *src)
5541 + ASSERT(dest != NULL);
5542 + ASSERT(src != NULL);
5543 + dest->i_atime = src->i_atime;
5546 +fist_copy_attr_times(inode_t *dest, const inode_t *src)
5548 + ASSERT(dest != NULL);
5549 + ASSERT(src != NULL);
5550 + dest->i_atime = src->i_atime;
5551 + dest->i_mtime = src->i_mtime;
5552 + dest->i_ctime = src->i_ctime;
5555 +fist_copy_attr_timesizes(inode_t *dest, const inode_t *src)
5557 + ASSERT(dest != NULL);
5558 + ASSERT(src != NULL);
5559 + dest->i_atime = src->i_atime;
5560 + dest->i_mtime = src->i_mtime;
5561 + dest->i_ctime = src->i_ctime;
5562 + copy_inode_size(dest, src);
5565 +fist_copy_attr_all(inode_t *dest, const inode_t *src)
5567 + ASSERT(dest != NULL);
5568 + ASSERT(src != NULL);
5569 + dest->i_mode = src->i_mode;
5570 + dest->i_nlink = src->i_nlink;
5571 + dest->i_uid = src->i_uid;
5572 + dest->i_gid = src->i_gid;
5573 + dest->i_rdev = src->i_rdev;
5574 + dest->i_atime = src->i_atime;
5575 + dest->i_mtime = src->i_mtime;
5576 + dest->i_ctime = src->i_ctime;
5577 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,19)
5578 + dest->i_blksize = src->i_blksize;
5580 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,12)
5581 + dest->i_blkbits = src->i_blkbits;
5582 +# endif /* linux 2.4.12 and newer */
5583 + copy_inode_size(dest, src);
5584 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
5585 + dest->i_attr_flags = src->i_attr_flags;
5587 + dest->i_flags = src->i_flags;
5591 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
5592 +/* copied from linux/fs.h */
5593 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
5594 +static inline void double_lock(struct dentry *d1, struct dentry *d2)
5596 + struct mutex *m1 = &d1->d_inode->i_mutex;
5597 + struct mutex *m2 = &d2->d_inode->i_mutex;
5599 + if ((unsigned long) m1 < (unsigned long) m2) {
5600 + struct mutex *tmp = m2;
5601 + m2 = m1; m1 = tmp;
5608 +static inline void double_unlock(struct dentry *d1, struct dentry *d2)
5610 + struct mutex *m1 = &d1->d_inode->i_mutex;
5611 + struct mutex *m2 = &d2->d_inode->i_mutex;
5620 +static inline void double_down(struct semaphore *s1, struct semaphore *s2)
5623 + if ((unsigned long) s1 < (unsigned long) s2) {
5624 + struct semaphore *tmp = s2;
5625 + s2 = s1; s1 = tmp;
5632 +static inline void double_up(struct semaphore *s1, struct semaphore *s2)
5639 +static inline void double_lock(struct dentry *d1, struct dentry *d2)
5641 + double_down(&d1->d_inode->i_sem, &d2->d_inode->i_sem);
5644 +static inline void double_unlock(struct dentry *d1, struct dentry *d2)
5646 + double_up(&d1->d_inode->i_sem,&d2->d_inode->i_sem);
5650 +#endif /* if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16) */
5651 +#endif /* if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0) */
5652 +#endif /* __KERNEL__ */
5655 + * Definitions for user and kernel code
5660 +#endif /* not __MINI_FO_H_ */
5661 Index: linux-2.6.21.7/fs/mini_fo/mini_fo-merge
5662 ===================================================================
5664 +++ linux-2.6.21.7/fs/mini_fo/mini_fo-merge
5668 +# Copyright (C) 2005 Markus Klotzbuecher <mk@creamnet.de>
5669 +# This program is free software; you can redistribute it and/or
5670 +# modify it under the terms of the GNU General Public License
5671 +# as published by the Free Software Foundation; either version
5672 +# 2 of the License, or (at your option) any later version.
5681 +META_NAME="META_dAfFgHE39ktF3HD2sr"
5682 +SKIP_DEL_LIST="skip-delete-list.mini_fo-merge"
5687 + if [ x$DRYRUN == "xset" ]; then
5688 + echo " would run: $COMMAND"
5689 + elif ! [ x$DRYRUN == "xset" ]; then
5690 + if [ x$VERBOSE == "xset" ]; then
5691 + echo " running: $COMMAND"
5701 +USAGE: $0 -b <base dir> -s <storage dir>
5704 +This script merges the contents of a mini_fo storage file system back
5705 +to the base file system.
5707 +!!! Warning: This will modify the base filesystem and can destroy data
5712 + the directory of the base file system.
5715 + the directory of the storage file system.
5717 + -d dry run, will not change anything and print the commands that
5718 + would be executed.
5720 + -t tmp dir for storing temporary file. default: $TMP
5722 + -v show what operations are performed.
5724 + -h displays this message.
5730 +while getopts hdvt:b:s: OPTS
5735 + v) VERBOSE="set";;
5736 + b) BASE="$OPTARG";;
5737 + s) STO="$OPTARG";;
5738 + t) TMP="$OPTARG";;
5744 +if [ "x$HELP" == "xset" ]; then
5749 +if ! [ -d "$BASE" ] || ! [ -d "$STO" ]; then
5750 + echo -e "$0:\n Error, -s and/or -b argument missing. type $0 -h for help."
5755 +pushd $STO; STO=`pwd`; popd
5756 +pushd $BASE; BASE=`pwd`; popd
5761 +###############################################################################
5765 +# storage dir: $STO
5766 +# meta filename: $META_NAME
5768 +# verbose: $VERBOSE
5770 +###############################################################################
5774 +rm $TMP/$SKIP_DEL_LIST
5776 +# first process all renamed dirs
5777 +echo "Merging renamed directories..."
5778 +pushd $STO &> /dev/null
5779 +find . -name $META_NAME -type f -print0 | xargs -0 -e grep -e '^R ' | tr -s ':R' ' ' | while read ENTRY; do
5780 + echo "entry: $ENTRY"
5781 + META_FILE=`echo $ENTRY | cut -d ' ' -f 1`
5782 + OLD_B_DIR=`echo $ENTRY | cut -d ' ' -f 2 | sed -e 's/\///'`
5783 + NEW_NAME=`echo $ENTRY | cut -d ' ' -f 3`
5784 + NEW_B_DIR=`echo $META_FILE | sed -e "s/$META_NAME/$NEW_NAME/" | sed -e 's/^\.\///'`
5785 + echo "META_FILE: $META_FILE"
5786 + echo "OLD_B_DIR: $OLD_B_DIR"
5787 + echo "NEW_NAME: $NEW_NAME"
5788 + echo "NEW_B_DIR: $NEW_B_DIR"
5790 + pushd $BASE &> /dev/null
5791 + # remove an existing dir in storage
5792 + COMMAND="rm -rf $NEW_B_DIR"; exec_command
5793 + COMMAND="cp -R $OLD_B_DIR $NEW_B_DIR"; exec_command
5797 + # remember this dir to exclude it from deleting later
5798 + echo $NEW_B_DIR >> $TMP/$SKIP_DEL_LIST
5801 +# delete all whiteouted files from base
5802 +echo -e "\nDeleting whiteout'ed files from base file system..."
5803 +find . -name $META_NAME -type f -print0 | xargs -0 -e grep -e '^D ' | sed -e 's/:D//' | while read ENTRY; do
5804 + META_FILE=`echo $ENTRY | cut -d ' ' -f 1`
5805 + DEL_NAME=`echo $ENTRY | cut -d ' ' -f 2`
5806 + DEL_FILE=`echo $META_FILE | sed -e "s/$META_NAME/$DEL_NAME/" | sed -e 's/^\.\///'`
5807 + grep -x $DEL_FILE $TMP/$SKIP_DEL_LIST &> /dev/null
5808 + if [ $? -ne 0 ]; then
5809 + pushd $BASE &> /dev/null
5810 + COMMAND="rm -rf $DEL_FILE"; exec_command
5813 + echo " excluding: $DEL_FILE as in skip-del-list."
5817 +# create all dirs and update permissions
5818 +echo -e "\nSetting up directory structures in base file system..."
5819 +find . -type d | sed -e 's/^\.\///' | while read DIR; do
5820 + PERMS=`stat -c %a $DIR`
5821 + DIR_UID=`stat -c %u $DIR`
5822 + DIR_GID=`stat -c %g $DIR`
5823 + pushd $BASE &> /dev/null
5824 + if ! [ -d $DIR ]; then
5825 + COMMAND="mkdir -p $DIR"; exec_command
5827 + COMMAND="chmod $PERMS $DIR"; exec_command
5828 + COMMAND="chown $DIR_UID:$DIR_GID $DIR"; exec_command
5832 +# merge all non-directory files
5833 +echo -e "\nMerging all non-directory files...."
5834 +for i in b c p f l s; do
5835 + find . -type $i | sed -e 's/^\.\///' | grep -v "$META_NAME" | while read FILE; do
5836 + pushd $BASE #&> /dev/null
5837 + COMMAND="cp -df $STO/$FILE $BASE/$FILE"; exec_command
5843 +#rm $TMP/$SKIP_DEL_LIST
5846 Index: linux-2.6.21.7/fs/mini_fo/mini_fo-overlay
5847 ===================================================================
5849 +++ linux-2.6.21.7/fs/mini_fo/mini_fo-overlay
5853 +# Copyright (C) 2005 Markus Klotzbuecher <mk@creamnet.de>
5854 +# This program is free software; you can redistribute it and/or
5855 +# modify it under the terms of the GNU General Public License
5856 +# as published by the Free Software Foundation; either version
5857 +# 2 of the License, or (at your option) any later version.
5872 +Usage: $0 [-s suffix] [-d sto_dir_dir] [-m mount point] base_dir
5875 +This script overlays the given base directory using the mini_fo file
5876 +system. If only the base directory base_dir is given, $0
5877 +will use a storage directory called "sto-<base_dir_name>" in $STO_DIR,
5878 +and mount point "mini_fo-<base_dir_dir>" in $MNT_DIR.
5882 + add given suffix to storage directory and the mount
5883 + point. This is usefull for overlaying one base directory
5884 + several times and avoiding conflicts with storage directory
5885 + names and mount points.
5888 + change the directory in which the storage directory will be
5889 + created (default is currently "$STO_DIR".
5892 + use an alternative directory to create the mini_fo
5893 + mountpoint (default is currently "$MNT_DIR".
5895 + -h displays this message.
5901 +while getopts hm:s:d: OPTS
5904 + s) SUFF="$OPTARG";;
5905 + d) STO_DIR="$OPTARG";;
5906 + m) MNT_DIR="$OPTARG";;
5912 +shift $(($OPTIND - 1))
5916 +if [ "x$HELP" == "xset" ]; then
5922 +if [ "x$SUFF" != "x" ]; then
5926 +# kill trailing slashes
5927 +MNT_DIR=${MNT_DIR%/}
5928 +STO_DIR=${STO_DIR%/}
5932 +if ! [ -d "$BASE" ]; then
5933 + echo "invalid base dir $BASE, run $0 -h for help."
5938 +if ! [ -d "$MNT_DIR" ]; then
5939 + echo "invalid mount dir $MNT_DIR, run $0 -h for help."
5943 +if ! [ -d "$STO_DIR" ]; then
5944 + echo "invalid sto_dir_dir $STO_DIR, run $0 -h for help."
5948 +MNTP="$MNT_DIR/mini_fo-`basename $BASE`$SUFF"
5949 +STO="$STO_DIR/sto-`basename $BASE`$SUFF"
5951 +# create the mount point if it doesn't exist
5953 +if [ $? -ne 0 ]; then
5954 + echo "Error, failed to create mount point $MNTP"
5958 +if [ $? -ne 0 ]; then
5959 + echo "Error, failed to create storage dir $STO"
5962 +# check if fs is already mounted
5963 +mount | grep mini_fo | grep $MNTP &> /dev/null
5964 +if [ $? -eq 0 ]; then
5965 + echo "Error, existing mini_fo mount at $MNTP."
5969 +mount | grep mini_fo | grep $STO &> /dev/null
5970 +if [ $? -eq 0 ]; then
5971 + echo "Error, $STO seems to be used already."
5976 +mount -t mini_fo -o base=$BASE,sto=$STO $BASE $MNTP
5978 +if [ $? -ne 0 ]; then
5979 + echo "Error, mounting failed, maybe no permisson to mount?"
5981 Index: linux-2.6.21.7/fs/mini_fo/mmap.c
5982 ===================================================================
5984 +++ linux-2.6.21.7/fs/mini_fo/mmap.c
5987 + * Copyright (c) 1997-2003 Erez Zadok
5988 + * Copyright (c) 2001-2003 Stony Brook University
5990 + * For specific licensing information, see the COPYING file distributed with
5991 + * this package, or get one from ftp://ftp.filesystems.org/pub/fist/COPYING.
5993 + * This Copyright notice must be kept intact and distributed with all
5994 + * fistgen sources INCLUDING sources generated by fistgen.
5997 + * Copyright (C) 2004, 2005 Markus Klotzbuecher <mk@creamnet.de>
5999 + * This program is free software; you can redistribute it and/or
6000 + * modify it under the terms of the GNU General Public License
6001 + * as published by the Free Software Foundation; either version
6002 + * 2 of the License, or (at your option) any later version.
6009 +#ifdef HAVE_CONFIG_H
6010 +# include <config.h>
6011 +#endif /* HAVE_CONFIG_H */
6014 +#include "mini_fo.h"
6017 +#ifdef FIST_COUNT_WRITES
6018 +/* for counting writes in the middle vs. regular writes */
6019 +unsigned long count_writes = 0, count_writes_middle = 0;
6020 +#endif /* FIST_COUNT_WRITES */
6022 +/* forward declaration of commit write and prepare write */
6023 +STATIC int mini_fo_commit_write(file_t *file, page_t *page, unsigned from, unsigned to);
6024 +STATIC int mini_fo_prepare_write(file_t *file, page_t *page, unsigned from, unsigned to);
6028 + * Function for handling creation of holes when lseek-ing past the
6029 + * end of the file and then writing some data.
6032 +mini_fo_fill_zeros(file_t* file, page_t *page, unsigned from)
6035 + dentry_t *dentry = file->f_dentry;
6036 + inode_t *inode = dentry->d_inode;
6040 + print_entry_location();
6042 + for (index = inode->i_size >> PAGE_CACHE_SHIFT; index < page->index; index++) {
6043 + tmp_page = mini_fo_get1page(file, index);
6044 + if (IS_ERR(tmp_page)) {
6045 + err = PTR_ERR(tmp_page);
6050 + * zero out rest of the contents of the page between the appropriate
6053 + memset((char*)page_address(tmp_page) + (inode->i_size & ~PAGE_CACHE_MASK), 0, PAGE_CACHE_SIZE - (inode->i_size & ~PAGE_CACHE_MASK));
6055 + if (! (err = mini_fo_prepare_write(file, tmp_page, 0, PAGE_CACHE_SIZE)))
6056 + err = mini_fo_commit_write(file, tmp_page, 0, PAGE_CACHE_SIZE);
6058 + page_cache_release(tmp_page);
6061 + if (current->need_resched)
6065 + /* zero out appropriate parts of last page */
6068 + * if the encoding type is block, then adjust the 'from' (where the
6069 + * zeroing will start) offset appropriately
6071 + from = from & (~(FIST_ENCODING_BLOCKSIZE - 1));
6073 + if ((from - (inode->i_size & ~PAGE_CACHE_MASK)) > 0) {
6075 + memset((char*)page_address(page) + (inode->i_size & ~PAGE_CACHE_MASK), 0, from - (inode->i_size & ~PAGE_CACHE_MASK));
6076 + if (! (err = mini_fo_prepare_write(file, page, 0, PAGE_CACHE_SIZE)))
6077 + err = mini_fo_commit_write(file, page, 0, PAGE_CACHE_SIZE);
6081 + if (current->need_resched)
6086 + print_exit_status(err);
6093 +mini_fo_writepage(page_t *page)
6097 + inode_t *hidden_inode;
6098 + page_t *hidden_page;
6099 + char *kaddr, *hidden_kaddr;
6101 + print_entry_location();
6103 + inode = page->mapping->host;
6104 + hidden_inode = itohi(inode);
6107 + * writepage is called when shared mmap'ed files need to write
6108 + * their pages, while prepare/commit_write are called from the
6109 + * non-paged write() interface. (However, in 2.3 the two interfaces
6110 + * share the same cache, while in 2.2 they didn't.)
6112 + * So we pretty much have to duplicate much of what commit_write does.
6115 + /* find lower page (returns a locked page) */
6116 + hidden_page = grab_cache_page(hidden_inode->i_mapping, page->index);
6120 + /* get page address, and encode it */
6121 + kaddr = (char *) kmap(page);
6122 + hidden_kaddr = (char*) kmap(hidden_page);
6123 + mini_fo_encode_block(kaddr, hidden_kaddr, PAGE_CACHE_SIZE, inode, inode->i_sb, page->index);
6124 + /* if encode_block could fail, then return error */
6126 + kunmap(hidden_page);
6128 + /* call lower writepage (expects locked page) */
6129 + err = hidden_inode->i_mapping->a_ops->writepage(hidden_page);
6132 + * update mtime and ctime of lower level file system
6133 + * mini_fo' mtime and ctime are updated by generic_file_write
6135 + hidden_inode->i_mtime = hidden_inode->i_ctime = CURRENT_TIME;
6137 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,4,1)
6138 + UnlockPage(hidden_page); /* b/c grab_cache_page locked it */
6139 +# endif /* kernel older than 2.4.1 */
6140 + page_cache_release(hidden_page); /* b/c grab_cache_page increased refcnt */
6143 + ClearPageUptodate(page);
6145 + SetPageUptodate(page);
6147 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,1)
6149 +# endif /* kernel 2.4.1 and newer */
6150 + print_exit_status(err);
6156 + * get one page from cache or lower f/s, return error otherwise.
6157 + * returns unlocked, up-to-date page (if ok), with increased refcnt.
6160 +mini_fo_get1page(file_t *file, int index)
6165 + struct address_space *mapping;
6168 + print_entry_location();
6170 + dentry = file->f_dentry; /* CPW: Moved below print_entry_location */
6171 + inode = dentry->d_inode;
6172 + mapping = inode->i_mapping;
6174 + fist_dprint(8, "%s: read page index %d pid %d\n", __FUNCTION__, index, current->pid);
6176 + printk("%s BUG: index=%d\n", __FUNCTION__, index);
6177 + page = ERR_PTR(-EIO);
6180 + page = read_cache_page(mapping,
6182 + (filler_t *) mapping->a_ops->readpage,
6186 + wait_on_page(page);
6187 + if (!Page_Uptodate(page)) {
6189 + err = mapping->a_ops->readpage(file, page);
6191 + page = ERR_PTR(err);
6194 + wait_on_page(page);
6195 + if (!Page_Uptodate(page)) {
6196 + page = ERR_PTR(-EIO);
6202 + print_exit_pointer(page);
6208 + * get one page from cache or lower f/s, return error otherwise.
6209 + * similar to get1page, but doesn't guarantee that it will return
6210 + * an unlocked page.
6213 +mini_fo_get1page_cached(file_t *file, int index)
6218 + struct address_space *mapping;
6221 + print_entry_location();
6223 + dentry = file->f_dentry; /* CPW: Moved below print_entry_location */
6224 + inode = dentry->d_inode;
6225 + mapping = inode->i_mapping;
6227 + fist_dprint(8, "%s: read page index %d pid %d\n", __FUNCTION__, index, current->pid);
6229 + printk("%s BUG: index=%d\n", __FUNCTION__, index);
6230 + page = ERR_PTR(-EIO);
6233 + page = read_cache_page(mapping,
6235 + (filler_t *) mapping->a_ops->readpage,
6241 + print_exit_pointer(page);
6247 + * readpage is called from generic_page_read and the fault handler.
6248 + * If your file system uses generic_page_read for the read op, it
6249 + * must implement readpage.
6251 + * Readpage expects a locked page, and must unlock it.
6254 +mini_fo_do_readpage(file_t *file, page_t *page)
6258 + file_t *hidden_file = NULL;
6259 + dentry_t *hidden_dentry;
6261 + inode_t *hidden_inode;
6263 + page_t *hidden_page;
6264 + char *hidden_page_data;
6267 + print_entry_location();
6269 + dentry = file->f_dentry; /* CPW: Moved below print_entry_location */
6270 + if (ftopd(file) != NULL)
6271 + hidden_file = ftohf(file);
6272 + hidden_dentry = dtohd(dentry);
6273 + inode = dentry->d_inode;
6274 + hidden_inode = itohi(inode);
6276 + fist_dprint(7, "%s: requesting page %d from file %s\n", __FUNCTION__, page->index, dentry->d_name.name);
6278 + MALLOC_PAGE_POINTERS(hidden_pages, num_hidden_pages);
6279 + MALLOC_PAGEDATA_POINTERS(hidden_pages_data, num_hidden_pages);
6281 + CURRENT_HIDDEN_PAGE = NULL;
6283 + /* find lower page (returns a locked page) */
6285 + fist_dprint(8, "%s: Current page index = %d\n", __FUNCTION__, CURRENT_HIDDEN_PAGEINDEX);
6286 + CURRENT_HIDDEN_PAGE = read_cache_page(hidden_inode->i_mapping,
6287 + CURRENT_HIDDEN_PAGEINDEX,
6288 + (filler_t *) hidden_inode->i_mapping->a_ops->readpage,
6289 + (void *) hidden_file);
6290 + if (IS_ERR(CURRENT_HIDDEN_PAGE)) {
6291 + err = PTR_ERR(CURRENT_HIDDEN_PAGE);
6292 + CURRENT_HIDDEN_PAGE = NULL;
6298 + * wait for the page data to show up
6299 + * (signaled by readpage as unlocking the page)
6302 + wait_on_page(CURRENT_HIDDEN_PAGE);
6303 + if (!Page_Uptodate(CURRENT_HIDDEN_PAGE)) {
6305 + * call readpage() again if we returned from wait_on_page with a
6306 + * page that's not up-to-date; that can happen when a partial
6307 + * page has a few buffers which are ok, but not the whole
6310 + lock_page(CURRENT_HIDDEN_PAGE);
6311 + err = hidden_inode->i_mapping->a_ops->readpage(hidden_file,
6312 + CURRENT_HIDDEN_PAGE);
6314 + CURRENT_HIDDEN_PAGE = NULL;
6317 + wait_on_page(CURRENT_HIDDEN_PAGE);
6318 + if (!Page_Uptodate(CURRENT_HIDDEN_PAGE)) {
6325 + /* map pages, get their addresses */
6326 + page_data = (char *) kmap(page);
6328 + CURRENT_HIDDEN_PAGEDATA = (char *) kmap(CURRENT_HIDDEN_PAGE);
6330 + /* if decode_block could fail, then return error */
6332 + real_size = hidden_inode->i_size - (page->index << PAGE_CACHE_SHIFT);
6333 + if (real_size <= 0)
6334 + memset(page_data, 0, PAGE_CACHE_SIZE);
6335 + else if (real_size < PAGE_CACHE_SIZE) {
6336 + mini_fo_decode_block(hidden_page_data, page_data, real_size, inode, inode->i_sb, page->index);
6337 + memset(page_data + real_size, 0, PAGE_CACHE_SIZE - real_size);
6339 + mini_fo_decode_block(hidden_page_data, page_data, PAGE_CACHE_SIZE, inode, inode->i_sb, page->index);
6342 + kunmap(CURRENT_HIDDEN_PAGE);
6347 + if (CURRENT_HIDDEN_PAGE)
6348 + page_cache_release(CURRENT_HIDDEN_PAGE); /* undo read_cache_page */
6350 + FREE_PAGE_POINTERS(hidden_pages, num_hidden_pages);
6351 + FREE_PAGEDATA_POINTERS(hidden_pages_data, num_hidden_pages);
6355 + SetPageUptodate(page);
6357 + ClearPageUptodate(page);
6359 + print_exit_status(err);
6365 +mini_fo_readpage(file_t *file, page_t *page)
6368 + print_entry_location();
6370 + err = mini_fo_do_readpage(file, page);
6373 + * we have to unlock our page, b/c we _might_ have gotten a locked page.
6374 + * but we no longer have to wakeup on our page here, b/c UnlockPage does
6379 + print_exit_status(err);
6385 +mini_fo_prepare_write(file_t *file, page_t *page, unsigned from, unsigned to)
6389 + print_entry_location();
6392 + * we call kmap(page) only here, and do the kunmap
6393 + * and the actual downcalls, including unlockpage and uncache
6394 + * in commit_write.
6398 + /* fast path for whole page writes */
6399 + if (from == 0 && to == PAGE_CACHE_SIZE)
6401 + /* read the page to "revalidate" our data */
6402 + /* call the helper function which doesn't unlock the page */
6403 + if (!Page_Uptodate(page))
6404 + err = mini_fo_do_readpage(file, page);
6407 + print_exit_status(err);
6414 +mini_fo_commit_write(file_t *file, page_t *page, unsigned from, unsigned to)
6416 + int err = -ENOMEM;
6418 + inode_t *hidden_inode;
6419 + page_t *hidden_page;
6420 + file_t *hidden_file = NULL;
6422 + unsigned bytes = to - from;
6423 + unsigned hidden_from, hidden_to, hidden_bytes;
6425 + print_entry_location();
6427 + inode = page->mapping->host; /* CPW: Moved below print_entry_location */
6428 + hidden_inode = itohi(inode);
6430 + ASSERT(file != NULL);
6432 + * here we have a kmapped page, with data from the user copied
6433 + * into it. we need to encode_block it, and then call the lower
6434 + * commit_write. We also need to simulate same behavior of
6435 + * generic_file_write, and call prepare_write on the lower f/s first.
6437 +#ifdef FIST_COUNT_WRITES
6439 +# endif /* FIST_COUNT_WRITES */
6441 + /* this is append and/or extend -- we can't have holes so fill them in */
6442 + if (page->index > (hidden_inode->i_size >> PAGE_CACHE_SHIFT)) {
6445 + for (index = hidden_inode->i_size >> PAGE_CACHE_SHIFT; index < page->index; index++) {
6446 + tmp_page = mini_fo_get1page(file, index);
6447 + if (IS_ERR(tmp_page)) {
6448 + err = PTR_ERR(tmp_page);
6451 + /* zero out the contents of the page at the appropriate offsets */
6452 + memset((char*)page_address(tmp_page) + (inode->i_size & ~PAGE_CACHE_MASK), 0, PAGE_CACHE_SIZE - (inode->i_size & ~PAGE_CACHE_MASK));
6453 + if (!(err = mini_fo_prepare_write(file, tmp_page, 0, PAGE_CACHE_SIZE)))
6454 + err = mini_fo_commit_write(file, tmp_page, 0, PAGE_CACHE_SIZE);
6455 + page_cache_release(tmp_page);
6458 + if (current->need_resched)
6463 + if (ftopd(file) != NULL)
6464 + hidden_file = ftohf(file);
6466 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
6467 + mutex_lock(&hidden_inode->i_mutex);
6469 + down(&hidden_inode->i_sem);
6471 + /* find lower page (returns a locked page) */
6472 + hidden_page = grab_cache_page(hidden_inode->i_mapping, page->index);
6476 +#if FIST_ENCODING_BLOCKSIZE > 1
6477 +# error encoding_blocksize greater than 1 is not yet supported
6478 +# endif /* FIST_ENCODING_BLOCKSIZE > 1 */
6480 + hidden_from = from & (~(FIST_ENCODING_BLOCKSIZE - 1));
6481 + hidden_to = ((to + FIST_ENCODING_BLOCKSIZE - 1) & (~(FIST_ENCODING_BLOCKSIZE - 1)));
6482 + if ((page->index << PAGE_CACHE_SHIFT) + to > hidden_inode->i_size) {
6485 + * if this call to commit_write had introduced holes and the code
6486 + * for handling holes was invoked, then the beginning of this page
6487 + * must be zeroed out
6488 + * zero out bytes from 'size_of_file%pagesize' to 'from'.
6490 + if ((hidden_from - (inode->i_size & ~PAGE_CACHE_MASK)) > 0)
6491 + memset((char*)page_address(page) + (inode->i_size & ~PAGE_CACHE_MASK), 0, hidden_from - (inode->i_size & ~PAGE_CACHE_MASK));
6494 + hidden_bytes = hidden_to - hidden_from;
6496 + /* call lower prepare_write */
6498 + if (hidden_inode->i_mapping &&
6499 + hidden_inode->i_mapping->a_ops &&
6500 + hidden_inode->i_mapping->a_ops->prepare_write)
6501 + err = hidden_inode->i_mapping->a_ops->prepare_write(hidden_file,
6506 + /* don't leave locked pages behind, esp. on an ENOSPC */
6509 + fist_dprint(8, "%s: encoding %d bytes\n", __FUNCTION__, hidden_bytes);
6510 + 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);
6511 + /* if encode_block could fail, then goto unlock and return error */
6513 + /* call lower commit_write */
6514 + err = hidden_inode->i_mapping->a_ops->commit_write(hidden_file,
6522 + err = bytes; /* convert error to no. of bytes */
6524 + inode->i_blocks = hidden_inode->i_blocks;
6525 + /* we may have to update i_size */
6526 + pos = (page->index << PAGE_CACHE_SHIFT) + to;
6527 + if (pos > inode->i_size)
6528 + inode->i_size = pos;
6531 + * update mtime and ctime of lower level file system
6532 + * mini_fo' mtime and ctime are updated by generic_file_write
6534 + hidden_inode->i_mtime = hidden_inode->i_ctime = CURRENT_TIME;
6536 + mark_inode_dirty_sync(inode);
6539 + UnlockPage(hidden_page);
6540 + page_cache_release(hidden_page);
6541 + kunmap(page); /* kmap was done in prepare_write */
6543 + /* we must set our page as up-to-date */
6545 + ClearPageUptodate(page);
6547 + SetPageUptodate(page);
6549 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
6550 + mutex_unlock(&hidden_inode->i_mutex);
6552 + up(&hidden_inode->i_sem);
6554 + print_exit_status(err);
6555 + return err; /* assume all is ok */
6560 +mini_fo_bmap(struct address_space *mapping, long block)
6564 + inode_t *hidden_inode;
6566 + print_entry_location();
6568 + inode = (inode_t *) mapping->host;
6569 + hidden_inode = itohi(inode);
6571 + if (hidden_inode->i_mapping->a_ops->bmap)
6572 + err = hidden_inode->i_mapping->a_ops->bmap(hidden_inode->i_mapping, block);
6573 + print_exit_location();
6579 + * This function is copied verbatim from mm/filemap.c.
6580 + * XXX: It should be simply moved to some header file instead -- bug Al about it!
6582 +static inline int sync_page(struct page *page)
6584 + struct address_space *mapping = page->mapping;
6586 + if (mapping && mapping->a_ops && mapping->a_ops->sync_page)
6587 + return mapping->a_ops->sync_page(page);
6593 + * XXX: we may not need this function if not FIST_FILTER_DATA.
6594 + * FIXME: for FIST_FILTER_SCA, get all lower pages and sync them each.
6597 +mini_fo_sync_page(page_t *page)
6601 + inode_t *hidden_inode;
6602 + page_t *hidden_page;
6604 + print_entry_location();
6606 + inode = page->mapping->host; /* CPW: Moved below print_entry_location */
6607 + hidden_inode = itohi(inode);
6609 + /* find lower page (returns a locked page) */
6610 + hidden_page = grab_cache_page(hidden_inode->i_mapping, page->index);
6614 + err = sync_page(hidden_page);
6616 + UnlockPage(hidden_page); /* b/c grab_cache_page locked it */
6617 + page_cache_release(hidden_page); /* b/c grab_cache_page increased refcnt */
6620 + print_exit_status(err);
6623 Index: linux-2.6.21.7/fs/mini_fo/README
6624 ===================================================================
6626 +++ linux-2.6.21.7/fs/mini_fo/README
6628 +README for the mini_fo overlay file system
6629 +=========================================
6635 +mini_fo is a virtual kernel file system that can make read-only
6636 +file systems writable. This is done by redirecting modifying operations
6637 +to a writeable location called "storage directory", and leaving the
6638 +original data in the "base directory" untouched. When reading, the
6639 +file system merges the modifed and original data so that only the
6640 +newest versions will appear. This occurs transparently to the user,
6641 +who can access the data like on any other read-write file system.
6643 +Base and storage directories may be located on the same or on
6644 +different partitions and may be of different file system types. While
6645 +the storage directory obviously needs to be writable, the base may or
6646 +may not be writable, what doesn't matter as it will no be modified
6653 +The primary purpose of the mini_fo file system is to allow easy
6654 +software updates to embedded systems, that often store their root
6655 +file system in a read-only flash file system, but there are many
6656 +more as for example sandboxing, or for allowing live-cds to
6657 +permanently store information.
6662 +This should be simple. Adjust the Makefile to point to the correct
6663 +kernel headers you want to build the module for. Then:
6667 +should build "mini_fo.o" for a 2.4 kernel or "mini_fo.ko" for a 2.6
6670 +If you are building the module for you current kernel, you can install
6671 +the module (as root):
6680 +USING THE FILE SYSTEM
6681 +--------------------
6683 +the general mount syntax is:
6685 + mount -t mini_fo -o base=<base directory>,sto=<storage directory>\
6686 + <base directory> <mount point>
6690 +You have mounted a cdrom to /mnt/cdrom and want to modifiy some files
6693 +load the module (as root)
6695 + # insmod mini_fo.o for a 2.4 kernel or
6697 + # insmod mini_fo.ko for a 2.6 kernel
6700 +create a storage dir in tmp and a mountpoint for mini_fo:
6703 + # mkdir /mnt/mini_fo
6705 +and mount the mini_fo file system:
6707 + # mount -t mini_fo -o base=/mnt/cdrom,sto=/tmp/sto /mnt/cdrom /mnt/mini_fo
6710 +Now the data stored on the cd can be accessed via the mini_fo
6711 +mountpoint just like any read-write file system, files can be modified
6712 +and deleted, new ones can be created and so on. When done unmount the
6715 + # unmount /mnt/mini_fo
6717 +Note that if the file system is mounted again using the same storage
6718 +file system, of course it will appear in the modified state again. If
6719 +you remount it using an new empty storage directory, it will be
6720 +unmodified. Therefore by executing:
6725 +you can nuke all the changes you made to the original file system. But
6726 + remember NEVER do this while the mini_fo file system is mounted!
6729 +Alternatively you can use the mini_fo-overlay bash script, that
6730 +simplifies managing mini_fo mounts. See TOOLS Section.
6736 +mini_fo-merge (experimental):
6738 +This is a bash script that will merge changes contained in the storage
6739 +directory back to the base directory. This allows mini_fo to function
6740 +as a cache file system by overlaying a slow (network, ...) file system
6741 +and using a fast (ramdisk, ...) as storage. When done, changes can be
6742 +merged back to the (slow) base with mini_fo-merge. See "mini_fo-merge
6745 +It can be usefull for merging changes back after a successfull test
6746 +(patches, software updates...)
6751 +This bash script simplifies managing one or more mini_fo mounts. For
6752 +overlaying a directory called "basedir1", you can just call:
6754 + # mini_fo-overlay basedir1
6756 +This will mount mini_fo with "basedir1" as base, "/tmp/sto-basedir1/"
6757 +as storage to "/mnt/mini_fo-basedir1/". It has more options though,
6758 +type "mini_fo-overlay -h" for details.
6761 +DOCUMENTATION, REPORTING BUGS, GETTING HELP
6762 +-------------------------------------------
6764 +Please visit the mini_fo project page at:
6766 +http://www.denx.de/twiki/bin/view/Know/MiniFOHome
6772 +Never modify the base or the storage directorys while the mini_fo
6773 +file system is mounted, or you might crash you system. Simply accessing
6774 +and reading should not cause any trouble.
6776 +Exporting a mini_fo mount point via NFS has not been tested, and may
6779 +Check the RELEASE_NOTES for details on bugs and features.
6783 +Copyright (C) 2004, 2005 Markus Klotzbuecher <mk@creamnet.de>
6785 +This program is free software; you can redistribute it and/or
6786 +modify it under the terms of the GNU General Public License
6787 +as published by the Free Software Foundation; either version
6788 +2 of the License, or (at your option) any later version.
6791 Index: linux-2.6.21.7/fs/mini_fo/RELEASE_NOTES
6792 ===================================================================
6794 +++ linux-2.6.21.7/fs/mini_fo/RELEASE_NOTES
6796 +Release: mini_fo-0.6.1 (v0-6-1)
6804 +- bugfixes (see ChangeLog)
6806 +- two helper scripts "mini_fo_merge" and "mini_fo_overlay" (see
6807 + README for details).
6811 +- Support for 2.4 and 2.6 (see Makefile)
6813 +- Partial hard link support (creating works as expected, but already
6814 + existing links in the base file system will be treated as if they
6815 + were individual files).
6817 +- Various bugfixes and cleanups.
6822 +- This is mini_fo-0-6-0-pre1! This release is a complete rewrite of
6823 + many vital mini_fo parts such as the old whiteout list code which
6824 + has been replaced by the new META subsystem.
6826 +- Light weight directory renaming implemented. This means if a
6827 + directory is renamed via the mini_fo filesystem this will no longer
6828 + result in a complete copy in storage, instead only one empty
6829 + directory will be created. All base filed contained in the original
6830 + directory stay there until modified.
6832 +- Special files (creating, renaming, deleting etc.) now working.
6834 +- Many bugfixes and cleanup, mini_fo is now a lot more stable.
6839 +- Final release of the 0-5-* versions. Next will be a complete rewrite
6840 + of many features. This release contains several bugfixes related to
6841 + directory renaming.
6846 +- Lots of cleanup and several bugfixes related to directory deleting
6848 +- Directory renaming suddenly works, what is most likely due to the
6849 + fact tha that "mv" is smart: if the classic rename doesn't work it
6850 + will assume that source and target file are on different fs and will
6851 + copy the directory and try to remove the source directory. Until
6852 + directory removing wasn't implemented, it would fail to do this and
6854 + So, directory renaming works for now, but it doesn't yet do what you
6855 + would expect from a overlay fs, so use with care.
6860 +- implemented directory deleting
6861 +- made parsing of mount options more stable
6862 +- New format of mount options! (See README)
6863 +- I can't reproduce the unknown panic with 2.4.25 anymore, so I'll
6864 + happily assume it never existed!
6867 +Implemented features:
6868 +---------------------
6870 +- creating hard links (see BUGS on already existing hard links)
6871 +- lightweight directory renaming
6872 +- renaming device files, pipes, sockets, etc.
6873 +- creating, renaming, deleting of special files
6874 +- deleting directorys
6875 +- general directory reading (simple "ls" )
6876 +- creating files in existing directorys
6877 +- creating directorys
6879 +- reading and writing files (involves opening)
6880 +- appending to files (creates copy in storage)
6882 +- llseek works too, what allows editors to work
6883 +- persistency (a deleted file stay deleted over remounts)
6884 +- use of symbolic links
6885 +- creating of device files
6888 +Not (yet) implemented features:
6889 +-------------------------------
6891 +- full hard link support.
6898 +Hard links in the base file system will be treated as individual
6899 +files, not as links to one inode.
6901 +The main problem with hard links isn't allowing to create them, but
6902 +their pure existence. If you modify a base hard link, the changes made
6903 +will only show up on this link, the other link will remain in the
6904 +original state. I hope to fix this someday. Please note that this does
6905 +not effect the special hard links '.' and '..', that are handled
6906 +seperately by the lower fs.
6907 Index: linux-2.6.21.7/fs/mini_fo/state.c
6908 ===================================================================
6910 +++ linux-2.6.21.7/fs/mini_fo/state.c
6913 + * Copyright (C) 2005 Markus Klotzbuecher <mk@creamnet.de>
6915 + * This program is free software; you can redistribute it and/or
6916 + * modify it under the terms of the GNU General Public License
6917 + * as published by the Free Software Foundation; either version
6918 + * 2 of the License, or (at your option) any later version.
6921 +#ifdef HAVE_CONFIG_H
6922 +# include <config.h>
6923 +#endif /* HAVE_CONFIG_H */
6926 +#include "mini_fo.h"
6929 +/* create the storage file, setup new states */
6930 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
6931 +int create_sto_reg_file(dentry_t *dentry, int mode, struct nameidata *nd)
6933 +int create_sto_reg_file(dentry_t *dentry, int mode)
6938 + dentry_t *hidden_sto_dentry;
6939 + dentry_t *hidden_sto_dir_dentry;
6941 + if(exists_in_storage(dentry)) {
6942 + printk(KERN_CRIT "mini_fo: create_sto_file: wrong type or state.\n");
6946 + err = get_neg_sto_dentry(dentry);
6949 + printk(KERN_CRIT "mini_fo: create_sto_file: ERROR getting neg. sto dentry.\n");
6953 + dir = dentry->d_parent->d_inode;
6954 + hidden_sto_dentry = dtohd2(dentry);
6957 + hidden_sto_dir_dentry = dget(hidden_sto_dentry->d_parent);
6959 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
6960 + mutex_lock(&hidden_sto_dir_dentry->d_inode->i_mutex);
6962 + down(&hidden_sto_dir_dentry->d_inode->i_sem);
6965 + err = PTR_ERR(hidden_sto_dir_dentry);
6966 + if (IS_ERR(hidden_sto_dir_dentry))
6969 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
6970 + err = vfs_create(hidden_sto_dir_dentry->d_inode,
6971 + hidden_sto_dentry,
6974 + err = vfs_create(hidden_sto_dir_dentry->d_inode,
6975 + hidden_sto_dentry,
6979 + printk(KERN_CRIT "mini_fo: create_sto_file: ERROR creating sto file.\n");
6983 + if(!dtohd2(dentry)->d_inode) {
6984 + printk(KERN_CRIT "mini_fo: create_sto_file: ERROR creating sto file [2].\n");
6989 + /* interpose the new inode */
6990 + if(dtost(dentry) == DELETED) {
6991 + dtost(dentry) = DEL_REWRITTEN;
6992 + err = mini_fo_tri_interpose(NULL, hidden_sto_dentry, dentry, dir->i_sb, 0);
6996 + else if(dtost(dentry) == NON_EXISTANT) {
6997 + dtost(dentry) = CREATED;
6998 + err = mini_fo_tri_interpose(dtohd(dentry), hidden_sto_dentry, dentry, dir->i_sb, 0);
7002 + else if(dtost(dentry) == UNMODIFIED) {
7003 + dtost(dentry) = MODIFIED;
7004 + /* interpose on new inode */
7005 + if(itohi2(dentry->d_inode) != NULL) {
7006 + printk(KERN_CRIT "mini_fo: create_sto_file: invalid inode detected.\n");
7010 + itohi2(dentry->d_inode) = igrab(dtohd2(dentry)->d_inode);
7012 + fist_copy_attr_timesizes(dentry->d_parent->d_inode,
7013 + hidden_sto_dir_dentry->d_inode);
7016 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
7017 + mutex_unlock(&hidden_sto_dir_dentry->d_inode->i_mutex);
7019 + up(&hidden_sto_dir_dentry->d_inode->i_sem);
7021 + dput(hidden_sto_dir_dentry);
7026 +/* create the sto dir, setup states */
7027 +int create_sto_dir(dentry_t *dentry, int mode)
7031 + dentry_t *hidden_sto_dentry;
7032 + dentry_t *hidden_sto_dir_dentry;
7034 + /* had to take the "!S_ISDIR(mode))" check out, because it failed */
7035 + if(exists_in_storage(dentry)) {
7036 + printk(KERN_CRIT "mini_fo: create_sto_dir: wrong type or state.\\
7042 + err = get_neg_sto_dentry(dentry);
7048 + dir = dentry->d_parent->d_inode;
7049 + hidden_sto_dentry = dtohd2(dentry);
7051 + /* was: hidden_sto_dir_dentry = lock_parent(hidden_sto_dentry); */
7052 + hidden_sto_dir_dentry = dget(hidden_sto_dentry->d_parent);
7054 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
7055 + mutex_lock(&hidden_sto_dir_dentry->d_inode->i_mutex);
7057 + down(&hidden_sto_dir_dentry->d_inode->i_sem);
7060 + err = PTR_ERR(hidden_sto_dir_dentry);
7061 + if (IS_ERR(hidden_sto_dir_dentry))
7064 + err = vfs_mkdir(hidden_sto_dir_dentry->d_inode,
7065 + hidden_sto_dentry,
7068 + printk(KERN_CRIT "mini_fo: create_sto_dir: ERROR creating sto dir.\n");
7072 + if(!dtohd2(dentry)->d_inode) {
7073 + printk(KERN_CRIT "mini_fo: create_sto_dir: ERROR creating sto dir [2].\n");
7078 + /* interpose the new inode */
7079 + if(dtost(dentry) == DELETED) {
7080 + dtost(dentry) = DEL_REWRITTEN;
7081 + err = mini_fo_tri_interpose(NULL, hidden_sto_dentry, dentry, dir->i_sb, 0);
7085 + else if(dtopd(dentry)->state == NON_EXISTANT) {
7086 + dtopd(dentry)->state = CREATED;
7087 + err = mini_fo_tri_interpose(dtohd(dentry), hidden_sto_dentry, dentry, dir->i_sb, 0);
7091 + else if(dtopd(dentry)->state == UNMODIFIED) {
7092 + dtopd(dentry)->state = MODIFIED;
7093 + /* interpose on new inode */
7094 + if(itohi2(dentry->d_inode) != NULL) {
7095 + printk(KERN_CRIT "mini_fo: create_sto_dir: ERROR, invalid inode detected.\n");
7099 + itohi2(dentry->d_inode) = igrab(dtohd2(dentry)->d_inode);
7102 + fist_copy_attr_timesizes(dir, hidden_sto_dir_dentry->d_inode);
7104 + /* initalize the wol list */
7105 + itopd(dentry->d_inode)->deleted_list_size = -1;
7106 + itopd(dentry->d_inode)->renamed_list_size = -1;
7107 + meta_build_lists(dentry);
7111 + /* was: unlock_dir(hidden_sto_dir_dentry); */
7112 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
7113 + mutex_unlock(&hidden_sto_dir_dentry->d_inode->i_mutex);
7115 + up(&hidden_sto_dir_dentry->d_inode->i_sem);
7117 + dput(hidden_sto_dir_dentry);
7122 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
7123 +int create_sto_nod(dentry_t *dentry, int mode, dev_t dev)
7125 +int create_sto_nod(dentry_t *dentry, int mode, int dev)
7130 + dentry_t *hidden_sto_dentry;
7131 + dentry_t *hidden_sto_dir_dentry;
7133 + if(exists_in_storage(dentry)) {
7137 + err = get_neg_sto_dentry(dentry);
7140 + printk(KERN_CRIT "mini_fo: create_sto_nod: ERROR getting neg. sto dentry.\n");
7144 + dir = dentry->d_parent->d_inode;
7145 + hidden_sto_dentry = dtohd2(dentry);
7148 + hidden_sto_dir_dentry = dget(hidden_sto_dentry->d_parent);
7150 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
7151 + mutex_lock(&hidden_sto_dir_dentry->d_inode->i_mutex);
7153 + down(&hidden_sto_dir_dentry->d_inode->i_sem);
7156 + err = PTR_ERR(hidden_sto_dir_dentry);
7157 + if (IS_ERR(hidden_sto_dir_dentry))
7160 + err = vfs_mknod(hidden_sto_dir_dentry->d_inode, hidden_sto_dentry, mode, dev);
7164 + if(!dtohd2(dentry)->d_inode) {
7165 + printk(KERN_CRIT "mini_fo: create_sto_nod: creating storage inode failed [1].\n");
7166 + err = -EINVAL; /* return something indicating failure */
7170 + /* interpose the new inode */
7171 + if(dtost(dentry) == DELETED) {
7172 + dtost(dentry) = DEL_REWRITTEN;
7173 + err = mini_fo_tri_interpose(NULL, hidden_sto_dentry, dentry, dir->i_sb, 0);
7177 + else if(dtost(dentry) == NON_EXISTANT) {
7178 + dtost(dentry) = CREATED;
7179 + err = mini_fo_tri_interpose(dtohd(dentry), hidden_sto_dentry, dentry, dir->i_sb, 0);
7183 + else if(dtost(dentry) == UNMODIFIED) {
7184 + dtost(dentry) = MODIFIED;
7185 + /* interpose on new inode */
7186 + if(itohi2(dentry->d_inode) != NULL) {
7187 + printk(KERN_CRIT "mini_fo: create_sto_nod: error, invalid inode detected.\n");
7191 + itohi2(dentry->d_inode) = igrab(dtohd2(dentry)->d_inode);
7194 + fist_copy_attr_timesizes(dir, hidden_sto_dir_dentry->d_inode);
7197 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
7198 + mutex_unlock(&hidden_sto_dir_dentry->d_inode->i_mutex);
7200 + up(&hidden_sto_dir_dentry->d_inode->i_sem);
7202 + dput(hidden_sto_dir_dentry);
7208 +/* unimplemented (and possibly not usefull):
7210 + nondir-del_to_del_rew
7211 + nondir-non_exist_to_creat
7216 + dir-del_rew_to_del
7217 + dir-del_to_del_rew
7218 + dir-non_exist_to_creat
7222 +/* bring a file of any type from state UNMODIFIED to MODIFIED */
7223 +int nondir_unmod_to_mod(dentry_t *dentry, int cp_flag)
7226 + struct vfsmount *tgt_mnt;
7227 + struct vfsmount *src_mnt;
7228 + dentry_t *tgt_dentry;
7229 + dentry_t *src_dentry;
7230 + dentry_t *hidden_sto_dentry;
7231 + dentry_t *hidden_sto_dir_dentry;
7233 + check_mini_fo_dentry(dentry);
7235 + if((dtost(dentry) != UNMODIFIED) ||
7236 + S_ISDIR(dentry->d_inode->i_mode)) {
7237 + printk(KERN_CRIT "mini_fo: nondir_unmod_to_mod: \
7238 + wrong type or state.\n");
7242 + err = get_neg_sto_dentry(dentry);
7245 + printk(KERN_CRIT "mini_fo: nondir_unmod_to_mod: \
7246 + ERROR getting neg. sto dentry.\n");
7250 + /* create sto file */
7251 + hidden_sto_dentry = dtohd2(dentry);
7254 + hidden_sto_dir_dentry = dget(hidden_sto_dentry->d_parent);
7256 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
7257 + mutex_lock(&hidden_sto_dir_dentry->d_inode->i_mutex);
7259 + down(&hidden_sto_dir_dentry->d_inode->i_sem);
7262 + err = PTR_ERR(hidden_sto_dir_dentry);
7263 + if (IS_ERR(hidden_sto_dir_dentry))
7266 + /* handle different types of nondirs */
7267 + if(S_ISCHR(dentry->d_inode->i_mode) ||
7268 + S_ISBLK(dentry->d_inode->i_mode)) {
7269 + err = vfs_mknod(hidden_sto_dir_dentry->d_inode,
7270 + hidden_sto_dentry,
7271 + dtohd(dentry)->d_inode->i_mode,
7272 + dtohd(dentry)->d_inode->i_rdev);
7275 + else if(S_ISREG(dentry->d_inode->i_mode)) {
7277 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
7278 + err = vfs_create(hidden_sto_dir_dentry->d_inode,
7279 + hidden_sto_dentry,
7280 + dtohd(dentry)->d_inode->i_mode, NULL);
7282 + err = vfs_create(hidden_sto_dir_dentry->d_inode,
7283 + hidden_sto_dentry,
7284 + dtohd(dentry)->d_inode->i_mode);
7288 + printk(KERN_CRIT "mini_fo: nondir_unmod_to_mod: \
7289 + ERROR creating sto file.\n");
7293 + /* interpose on new inode */
7294 + if(itohi2(dentry->d_inode) != NULL) {
7295 + printk(KERN_CRIT "mini_fo: nondir_unmod_to_mod: \
7296 + ERROR, invalid inode detected.\n");
7301 + itohi2(dentry->d_inode) = igrab(dtohd2(dentry)->d_inode);
7303 + fist_copy_attr_timesizes(dentry->d_parent->d_inode,
7304 + hidden_sto_dir_dentry->d_inode);
7305 + dtost(dentry) = MODIFIED;
7307 + /* copy contents if regular file and cp_flag = 1 */
7308 + if((cp_flag == 1) && S_ISREG(dentry->d_inode->i_mode)) {
7310 + /* unlock first */
7311 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
7312 + mutex_unlock(&hidden_sto_dir_dentry->d_inode->i_mutex);
7314 + up(&hidden_sto_dir_dentry->d_inode->i_sem);
7317 + dput(hidden_sto_dir_dentry);
7319 + tgt_dentry = dtohd2(dentry);
7320 + tgt_mnt = stopd(dentry->d_inode->i_sb)->hidden_mnt2;
7321 + src_dentry = dtohd(dentry);
7322 + src_mnt = stopd(dentry->d_inode->i_sb)->hidden_mnt;
7324 + err = mini_fo_cp_cont(tgt_dentry, tgt_mnt,
7325 + src_dentry, src_mnt);
7327 + printk(KERN_CRIT "mini_fo: nondir_unmod_to_mod: \
7328 + ERROR copying contents.\n");
7334 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
7335 + mutex_unlock(&hidden_sto_dir_dentry->d_inode->i_mutex);
7337 + up(&hidden_sto_dir_dentry->d_inode->i_sem);
7339 + dput(hidden_sto_dir_dentry);
7344 +/* this function is currently identical to nondir_creat_to_del */
7345 +int nondir_del_rew_to_del(dentry_t *dentry)
7347 + return nondir_creat_to_del(dentry);
7350 +int nondir_creat_to_del(dentry_t *dentry)
7354 + inode_t *hidden_sto_dir_inode;
7355 + dentry_t *hidden_sto_dir_dentry;
7356 + dentry_t *hidden_sto_dentry;
7358 + check_mini_fo_dentry(dentry);
7360 + /* for now this function serves for both state DEL_REWRITTEN and
7362 + if(!(dtost(dentry) == CREATED || (dtost(dentry) == DEL_REWRITTEN)) ||
7363 + S_ISDIR(dentry->d_inode->i_mode)) {
7364 + printk(KERN_CRIT "mini_fo: nondir_mod_to_del/del_rew_to_del: \
7365 + wrong type or state.\n");
7370 + hidden_sto_dir_inode = itohi2(dentry->d_parent->d_inode);
7371 + hidden_sto_dentry = dtohd2(dentry);
7373 + /* was: hidden_sto_dir_dentry = lock_parent(hidden_sto_dentry);*/
7374 + hidden_sto_dir_dentry = dget(hidden_sto_dentry->d_parent);
7376 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
7377 + mutex_lock(&hidden_sto_dir_dentry->d_inode->i_mutex);
7379 + down(&hidden_sto_dir_dentry->d_inode->i_sem);
7382 + /* avoid destroying the hidden inode if the file is in use */
7383 + dget(hidden_sto_dentry);
7384 + err = vfs_unlink(hidden_sto_dir_inode, hidden_sto_dentry);
7385 + dput(hidden_sto_dentry);
7387 + d_delete(hidden_sto_dentry);
7389 + /* propagate number of hard-links */
7390 + dentry->d_inode->i_nlink = itohi2(dentry->d_inode)->i_nlink;
7392 + dtost(dentry) = NON_EXISTANT;
7394 + /* was: unlock_dir(hidden_sto_dir_dentry); */
7395 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
7396 + mutex_unlock(&hidden_sto_dir_dentry->d_inode->i_mutex);
7398 + up(&hidden_sto_dir_dentry->d_inode->i_sem);
7400 + dput(hidden_sto_dir_dentry);
7406 +int nondir_mod_to_del(dentry_t *dentry)
7409 + dentry_t *hidden_sto_dentry;
7410 + inode_t *hidden_sto_dir_inode;
7411 + dentry_t *hidden_sto_dir_dentry;
7413 + check_mini_fo_dentry(dentry);
7415 + if(dtost(dentry) != MODIFIED ||
7416 + S_ISDIR(dentry->d_inode->i_mode)) {
7417 + printk(KERN_CRIT "mini_fo: nondir_mod_to_del: \
7418 + wrong type or state.\n");
7423 + hidden_sto_dir_inode = itohi2(dentry->d_parent->d_inode);
7424 + hidden_sto_dentry = dtohd2(dentry);
7426 + /* was hidden_sto_dir_dentry = lock_parent(hidden_sto_dentry); */
7427 + hidden_sto_dir_dentry = dget(hidden_sto_dentry->d_parent);
7429 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
7430 + mutex_lock(&hidden_sto_dir_dentry->d_inode->i_mutex);
7432 + down(&hidden_sto_dir_dentry->d_inode->i_sem);
7435 + /* avoid destroying the hidden inode if the file is in use */
7436 + dget(hidden_sto_dentry);
7437 + err = vfs_unlink(hidden_sto_dir_inode, hidden_sto_dentry);
7438 + dput(hidden_sto_dentry);
7440 + d_delete(hidden_sto_dentry);
7442 + /* propagate number of hard-links */
7443 + dentry->d_inode->i_nlink = itohi2(dentry->d_inode)->i_nlink;
7445 + /* dput base dentry, this will relase the inode and free the
7446 + * dentry, as we will never need it again. */
7447 + dput(dtohd(dentry));
7448 + dtohd(dentry) = NULL;
7449 + dtost(dentry) = DELETED;
7451 + /* add deleted file to META-file */
7452 + meta_add_d_entry(dentry->d_parent,
7453 + dentry->d_name.name,
7454 + dentry->d_name.len);
7456 + /* was: unlock_dir(hidden_sto_dir_dentry); */
7457 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
7458 + mutex_unlock(&hidden_sto_dir_dentry->d_inode->i_mutex);
7460 + up(&hidden_sto_dir_dentry->d_inode->i_sem);
7462 + dput(hidden_sto_dir_dentry);
7468 +int nondir_unmod_to_del(dentry_t *dentry)
7472 + check_mini_fo_dentry(dentry);
7474 + if(dtost(dentry) != UNMODIFIED ||
7475 + S_ISDIR(dentry->d_inode->i_mode)) {
7476 + printk(KERN_CRIT "mini_fo: nondir_unmod_to_del: \
7477 + wrong type or state.\n");
7482 + /* next we have to get a negative dentry for the storage file */
7483 + err = get_neg_sto_dentry(dentry);
7488 + /* add deleted file to META lists */
7489 + err = meta_add_d_entry(dentry->d_parent,
7490 + dentry->d_name.name,
7491 + dentry->d_name.len);
7496 + /* dput base dentry, this will relase the inode and free the
7497 + * dentry, as we will never need it again. */
7498 + dput(dtohd(dentry));
7499 + dtohd(dentry) = NULL;
7500 + dtost(dentry) = DELETED;
7506 +/* bring a dir from state UNMODIFIED to MODIFIED */
7507 +int dir_unmod_to_mod(dentry_t *dentry)
7511 + check_mini_fo_dentry(dentry);
7513 + if(dtost(dentry) != UNMODIFIED ||
7514 + !S_ISDIR(dentry->d_inode->i_mode)) {
7515 + printk(KERN_CRIT "mini_fo: dir_unmod_to_mod: \
7516 + wrong type or state.\n");
7521 + /* this creates our dir incl. sto. structure */
7522 + err = build_sto_structure(dentry->d_parent, dentry);
7524 + printk(KERN_CRIT "mini_fo: dir_unmod_to_mod: \
7525 + build_sto_structure failed.\n");
7532 Index: linux-2.6.21.7/fs/mini_fo/super.c
7533 ===================================================================
7535 +++ linux-2.6.21.7/fs/mini_fo/super.c
7538 + * Copyright (c) 1997-2003 Erez Zadok
7539 + * Copyright (c) 2001-2003 Stony Brook University
7541 + * For specific licensing information, see the COPYING file distributed with
7542 + * this package, or get one from ftp://ftp.filesystems.org/pub/fist/COPYING.
7544 + * This Copyright notice must be kept intact and distributed with all
7545 + * fistgen sources INCLUDING sources generated by fistgen.
7548 + * Copyright (C) 2004, 2005 Markus Klotzbuecher <mk@creamnet.de>
7550 + * This program is free software; you can redistribute it and/or
7551 + * modify it under the terms of the GNU General Public License
7552 + * as published by the Free Software Foundation; either version
7553 + * 2 of the License, or (at your option) any later version.
7560 +#ifdef HAVE_CONFIG_H
7561 +# include <config.h>
7565 +#include "mini_fo.h"
7569 +mini_fo_read_inode(inode_t *inode)
7571 + static struct address_space_operations mini_fo_empty_aops;
7573 + __itopd(inode) = kmalloc(sizeof(struct mini_fo_inode_info), GFP_KERNEL);
7574 + if (!itopd(inode)) {
7575 + printk("<0>%s:%s:%d: No kernel memory!\n", __FILE__, __FUNCTION__, __LINE__);
7578 + itohi(inode) = NULL;
7579 + itohi2(inode) = NULL;
7581 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
7582 + inode->i_version++;
7584 + inode->i_version = ++event; /* increment inode version */
7586 + inode->i_op = &mini_fo_main_iops;
7587 + inode->i_fop = &mini_fo_main_fops;
7590 + * XXX: To export a file system via NFS, it has to have the
7591 + * FS_REQUIRES_DEV flag, so turn it on. But should we inherit it from
7592 + * the lower file system, or can we allow our file system to be exported
7593 + * even if the lower one cannot be natively exported.
7595 + inode->i_sb->s_type->fs_flags |= FS_REQUIRES_DEV;
7597 + * OK, the above was a hack, which is now turned off because it may
7598 + * cause a panic/oops on some systems. The correct way to export a
7599 + * "nodev" filesystem is via using nfs-utils > 1.0 and the "fsid=" export
7600 + * parameter, which requires 2.4.20 or later.
7603 + /* I don't think ->a_ops is ever allowed to be NULL */
7604 + inode->i_mapping->a_ops = &mini_fo_empty_aops;
7608 +#if defined(FIST_DEBUG) || defined(FIST_FILTER_SCA)
7610 + * No need to call write_inode() on the lower inode, as it
7611 + * will have been marked 'dirty' anyway. But we might need
7612 + * to write some of our own stuff to disk.
7615 +mini_fo_write_inode(inode_t *inode, int sync)
7617 + print_entry_location();
7618 + print_exit_location();
7620 +#endif /* defined(FIST_DEBUG) || defined(FIST_FILTER_SCA) */
7624 +mini_fo_put_inode(inode_t *inode)
7627 + * This is really funky stuff:
7628 + * Basically, if i_count == 1, iput will then decrement it and this inode will be destroyed.
7629 + * It is currently holding a reference to the hidden inode.
7630 + * Therefore, it needs to release that reference by calling iput on the hidden inode.
7631 + * iput() _will_ do it for us (by calling our clear_inode), but _only_ if i_nlink == 0.
7632 + * The problem is, NFS keeps i_nlink == 1 for silly_rename'd files.
7633 + * So we must for our i_nlink to 0 here to trick iput() into calling our clear_inode.
7635 + if (atomic_read(&inode->i_count) == 1)
7636 + inode->i_nlink = 0;
7640 +#if defined(FIST_DEBUG) || defined(FIST_FILTER_SCA)
7642 + * we now define delete_inode, because there are two VFS paths that may
7643 + * destroy an inode: one of them calls clear inode before doing everything
7644 + * else that's needed, and the other is fine. This way we truncate the inode
7645 + * size (and its pages) and then clear our own inode, which will do an iput
7646 + * on our and the lower inode.
7649 +mini_fo_delete_inode(inode_t *inode)
7651 + print_entry_location();
7653 + fist_checkinode(inode, "mini_fo_delete_inode IN");
7654 + inode->i_size = 0; /* every f/s seems to do that */
7655 + clear_inode(inode);
7657 + print_exit_location();
7659 +#endif /* defined(FIST_DEBUG) || defined(FIST_FILTER_SCA) */
7662 +/* final actions when unmounting a file system */
7664 +mini_fo_put_super(super_block_t *sb)
7667 + mntput(stopd(sb)->hidden_mnt);
7668 + mntput(stopd(sb)->hidden_mnt2);
7670 + /* mk: no! dput(stopd(sb)->base_dir_dentry);
7671 + dput(stopd(sb)->storage_dir_dentry); */
7674 + __stopd(sb) = NULL;
7681 + * This is called in do_umount before put_super.
7682 + * The superblock lock is not held yet.
7683 + * We probably do not need to define this or call write_super
7684 + * on the hidden_sb, because sync_supers() will get to hidden_sb
7685 + * sooner or later. But it is also called from file_fsync()...
7688 +mini_fo_write_super(super_block_t *sb)
7692 +#endif /* NOT_NEEDED */
7696 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,18)
7697 +mini_fo_statfs(struct dentry *d, struct kstatfs *buf)
7698 +#elif LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
7699 +mini_fo_statfs(super_block_t *sb, struct kstatfs *buf)
7701 +mini_fo_statfs(super_block_t *sb, struct statfs *buf)
7705 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,18)
7706 + struct dentry *hidden_d;
7708 + hidden_d = dtohd(d);
7709 + err = vfs_statfs(hidden_d, buf);
7711 + super_block_t *hidden_sb;
7713 + hidden_sb = stohs(sb);
7714 + err = vfs_statfs(hidden_sb, buf);
7722 + * XXX: not implemented. This is not allowed yet.
7723 + * Should we call this on the hidden_sb? Probably not.
7726 +mini_fo_remount_fs(super_block_t *sb, int *flags, char *data)
7728 + //printk(KERN_CRIT "mini_fo_remount_fs: WARNING, this function is umimplemented.\n");
7734 + * Called by iput() when the inode reference count reached zero
7735 + * and the inode is not hashed anywhere. Used to clear anything
7736 + * that needs to be, before the inode is completely destroyed and put
7737 + * on the inode free list.
7740 +mini_fo_clear_inode(inode_t *inode)
7743 + * Decrement a reference to a hidden_inode, which was incremented
7744 + * by our read_inode when it was created initially.
7747 + /* release the wol_list */
7748 + if(S_ISDIR(inode->i_mode)) {
7749 + __meta_put_lists(inode);
7752 + /* mk: fan out fun */
7754 + iput(itohi(inode));
7756 + iput(itohi2(inode));
7758 + // XXX: why this assertion fails?
7759 + // because it doesn't like us
7760 + // ASSERT((inode->i_state & I_DIRTY) == 0);
7761 + kfree(itopd(inode));
7762 + __itopd(inode) = NULL;
7767 + * Called in do_umount() if the MNT_FORCE flag was used and this
7768 + * function is defined. See comment in linux/fs/super.c:do_umount().
7769 + * Used only in nfs, to kill any pending RPC tasks, so that subsequent
7770 + * code can actually succeed and won't leave tasks that need handling.
7772 + * PS. I wonder if this is somehow useful to undo damage that was
7773 + * left in the kernel after a user level file server (such as amd)
7777 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,18)
7778 +mini_fo_umount_begin(struct vfsmount *mnt, int flags)
7780 + struct vfsmount *hidden_mnt;
7782 + hidden_mnt = stopd(mnt->mnt_sb)->hidden_mnt;
7784 + if (hidden_mnt->mnt_sb->s_op->umount_begin)
7785 + hidden_mnt->mnt_sb->s_op->umount_begin(hidden_mnt, flags);
7789 +mini_fo_umount_begin(super_block_t *sb)
7791 + super_block_t *hidden_sb;
7793 + hidden_sb = stohs(sb);
7795 + if (hidden_sb->s_op->umount_begin)
7796 + hidden_sb->s_op->umount_begin(hidden_sb);
7802 +struct super_operations mini_fo_sops =
7804 + read_inode: mini_fo_read_inode,
7805 +#if defined(FIST_DEBUG) || defined(FIST_FILTER_SCA)
7806 + write_inode: mini_fo_write_inode,
7807 +#endif /* defined(FIST_DEBUG) || defined(FIST_FILTER_SCA) */
7808 + put_inode: mini_fo_put_inode,
7809 +#if defined(FIST_DEBUG) || defined(FIST_FILTER_SCA)
7810 + delete_inode: mini_fo_delete_inode,
7811 +#endif /* defined(FIST_DEBUG) || defined(FIST_FILTER_SCA) */
7812 + put_super: mini_fo_put_super,
7813 + statfs: mini_fo_statfs,
7814 + remount_fs: mini_fo_remount_fs,
7815 + clear_inode: mini_fo_clear_inode,
7816 + umount_begin: mini_fo_umount_begin,