1 Index: linux-2.6.25.4/fs/Kconfig
2 ===================================================================
3 --- linux-2.6.25.4.orig/fs/Kconfig
4 +++ linux-2.6.25.4/fs/Kconfig
5 @@ -1449,6 +1449,9 @@ config VXFS_FS
6 To compile this as a module, choose M here: the module will be
7 called freevxfs. If unsure, say N.
10 + tristate "Mini fanout overlay filesystem"
13 tristate "Minix file system support"
15 Index: linux-2.6.25.4/fs/Makefile
16 ===================================================================
17 --- linux-2.6.25.4.orig/fs/Makefile
18 +++ linux-2.6.25.4/fs/Makefile
19 @@ -77,6 +77,7 @@ obj-$(CONFIG_SQUASHFS) += squashfs/
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.25.4/fs/mini_fo/aux.c
28 ===================================================================
30 +++ linux-2.6.25.4/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 vfsmount *mnt;
178 + struct nameidata nd;
181 + if(!bpath || bpath[0] != '/') {
182 + printk(KERN_CRIT "mini_fo: bpath_walk: Invalid string.\n");
185 + if(!sb || !stopd(sb)) {
186 + printk(KERN_CRIT "mini_fo: bpath_walk: Invalid sb.\n");
190 + /* fix this: how do I reach this lock?
191 + * read_lock(¤t->fs->lock); */
192 + mnt = mntget(stopd(sb)->hidden_mnt);
193 + /* read_unlock(¤t->fs->lock); */
195 + err = vfs_path_lookup(mnt->mnt_root, mnt, bpath+1, 0, &nd);
198 + if (err || !nd.dentry || !nd.dentry->d_inode) {
199 + printk(KERN_CRIT "mini_fo: bpath_walk: path_walk failed.\n");
206 +/* returns the full path of the basefile incl. its name */
207 +int get_mini_fo_bpath(dentry_t *dentry, char **bpath, int *bpath_len)
211 + dentry_t *sky_walker;
213 + if(!dentry || !dtohd(dentry)) {
214 + printk(KERN_CRIT "mini_fo: get_mini_fo_bpath: invalid dentry passed.\n");
217 + sky_walker = dtohd(dentry);
220 + len += sky_walker->d_name.len + 1 ; /* 1 for '/' */
221 + sky_walker = sky_walker->d_parent;
222 + } while(sky_walker != stopd(dentry->d_inode->i_sb)->base_dir_dentry);
224 + /* 1 to oil the loop */
225 + *bpath = (char*) kmalloc(len + 1, GFP_KERNEL);
227 + printk(KERN_CRIT "mini_fo: get_mini_fo_bpath: out of mem.\n");
230 + buf_walker = *bpath+len; /* put it on last char */
231 + *buf_walker = '\n';
232 + sky_walker = dtohd(dentry);
235 + buf_walker -= sky_walker->d_name.len;
236 + strncpy(buf_walker,
237 + sky_walker->d_name.name,
238 + sky_walker->d_name.len);
239 + *(--buf_walker) = '/';
240 + sky_walker = sky_walker->d_parent;
241 + } while(sky_walker != stopd(dentry->d_inode->i_sb)->base_dir_dentry);
243 + /* bpath_len doesn't count newline! */
248 +int mini_fo_cp_cont(dentry_t *tgt_dentry, struct vfsmount *tgt_mnt,
249 + dentry_t *src_dentry, struct vfsmount *src_mnt)
252 + mm_segment_t old_fs;
255 + int bytes, len, tmp, err;
258 + if(!(tgt_dentry->d_inode && src_dentry->d_inode)) {
259 + printk(KERN_CRIT "mini_fo_cp_cont: ERROR, neg. dentry passed.\n");
269 + /* open file write only */
270 + tgt_file = dentry_open(tgt_dentry, tgt_mnt, 0x1);
271 + if(!tgt_file || IS_ERR(tgt_file)) {
272 + printk(KERN_CRIT "mini_fo_cp_cont: ERROR opening target file.\n");
273 + err = PTR_ERR(tgt_file);
277 + /* open file read only */
278 + src_file = dentry_open(src_dentry, src_mnt, 0x0);
279 + if(!src_file || IS_ERR(src_file)) {
280 + printk(KERN_CRIT "mini_fo_cp_cont: ERROR opening source file.\n");
281 + err = PTR_ERR(src_file);
283 + /* close target file */
288 + /* check if the filesystem(s) support read respective write */
289 + if(!src_file->f_op->read || !tgt_file->f_op->write) {
290 + printk(KERN_CRIT "mini_fo_cp_cont: ERROR, no fs read or write support.\n");
295 + /* allocate a page for transfering the data */
296 + buf = (void *) __get_free_page(GFP_KERNEL);
298 + printk(KERN_CRIT "mini_fo_cp_cont: ERROR, out of kernel mem.\n");
302 + tgt_file->f_pos = 0;
303 + src_file->f_pos = 0;
308 + /* Doing this I assume that a read operation will return a full
309 + * buffer while there is still data to read, and a less than
310 + * full buffer when all data has been read.
312 + bytes = len = PAGE_SIZE;
313 + while(bytes == len) {
314 + bytes = src_file->f_op->read(src_file, buf, len,
316 + tmp = tgt_file->f_op->write(tgt_file, buf, bytes,
319 + printk(KERN_CRIT "mini_fo_cp_cont: ERROR writing.\n");
320 + goto out_close_unset;
324 + free_page((unsigned long) buf);
331 + free_page((unsigned long) buf);
342 + /* mk: not sure if this need to be done */
351 + * ndl (no-duplicate list) stuff
352 + * This is used in mini_fo_readdir, to save the storage directory contents
353 + * and later when reading base, match them against the list in order
354 + * to avoid duplicates.
357 +/* add a file specified by name and len to the ndl
358 + * Return values: 0 on success, <0 on failure.
360 +int ndl_add_entry(struct readdir_data *rd, const char *name, int len)
362 + struct ndl_entry *tmp_entry;
364 + tmp_entry = (struct ndl_entry *)
365 + kmalloc(sizeof(struct ndl_entry), GFP_KERNEL);
367 + printk(KERN_CRIT "mini_fo: ndl_add_entry: out of mem.\n");
370 + tmp_entry->name = (char*) kmalloc(len, GFP_KERNEL);
371 + if(!tmp_entry->name) {
372 + printk(KERN_CRIT "mini_fo: ndl_add_entry: out of mem.\n");
375 + strncpy(tmp_entry->name, name, len);
376 + tmp_entry->len = len;
378 + list_add(&tmp_entry->list, &rd->ndl_list);
383 +/* delete all list entries and free memory */
384 +void ndl_put_list(struct readdir_data *rd)
386 + struct list_head *tmp;
387 + struct ndl_entry *tmp_entry;
389 + if(rd->ndl_size <= 0)
391 + while(!list_empty(&rd->ndl_list)) {
392 + tmp = rd->ndl_list.next;
394 + tmp_entry = list_entry(tmp, struct ndl_entry, list);
395 + kfree(tmp_entry->name);
401 +/* Check if a file specified by name and len is in the ndl
402 + * Return value: 0 if not in list, 1 if file is found in ndl.
404 +int ndl_check_entry(struct readdir_data *rd, const char *name, int len)
406 + struct list_head *tmp;
407 + struct ndl_entry *tmp_entry;
409 + if(rd->ndl_size <= 0)
412 + list_for_each(tmp, &rd->ndl_list) {
413 + tmp_entry = list_entry(tmp, struct ndl_entry, list);
414 + if(tmp_entry->len != len)
416 + if(!strncmp(tmp_entry->name, name, len))
423 + * Recursive function to create corresponding directorys in the storage fs.
424 + * The function will build the storage directorys up to dentry.
426 +int build_sto_structure(dentry_t *dir, dentry_t *dentry)
429 + dentry_t *hidden_sto_dentry;
430 + dentry_t *hidden_sto_dir_dentry;
432 + if(dentry->d_parent != dir) {
433 + printk(KERN_CRIT "mini_fo: build_sto_structure: invalid parameter or meta data corruption [1].\n");
437 + if(dtost(dir) != MODIFIED) {
438 + err = build_sto_structure(dir->d_parent, dentry->d_parent);
443 + /* ok, coming back again. */
444 + check_mini_fo_dentry(dentry);
445 + hidden_sto_dentry = dtohd2(dentry);
447 + if(!hidden_sto_dentry) {
449 + * This is the case after creating the first
450 + * hidden_sto_dentry.
451 + * After one negative storage_dentry, all pointers to
452 + * hidden_storage dentries are set to NULL. We need to
453 + * create the negative dentry before we create the storage
457 + const unsigned char *name;
458 + len = dtohd(dentry)->d_name.len;
459 + name = dtohd(dentry)->d_name.name;
460 + hidden_sto_dentry = lookup_one_len(name, dtohd2(dir), len);
461 + dtohd2(dentry) = hidden_sto_dentry;
464 + /* was: hidden_sto_dir_dentry = lock_parent(hidden_sto_dentry); */
465 + hidden_sto_dir_dentry = dget(hidden_sto_dentry->d_parent);
466 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
467 + mutex_lock(&hidden_sto_dir_dentry->d_inode->i_mutex);
469 + down(&hidden_sto_dir_dentry->d_inode->i_sem);
472 + if(dtohd2(dir) != hidden_sto_dir_dentry) {
473 + printk(KERN_CRIT "mini_fo: build_sto_structure: invalid parameter or meta data corruption [2].\n");
477 + /* check for errors in lock_parent */
478 + err = PTR_ERR(hidden_sto_dir_dentry);
479 + if(IS_ERR(hidden_sto_dir_dentry)) {
480 + printk(KERN_CRIT "mini_fo: build_sto_structure: lock_parent failed.\n");
484 + err = vfs_mkdir(hidden_sto_dir_dentry->d_inode,
486 + dir->d_inode->i_mode);
489 + printk(KERN_CRIT "mini_fo: build_sto_structure: failed to create storage dir [1].\n");
490 + /* was: unlock_dir(dir); */
491 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
492 + mutex_unlock(&dir->d_inode->i_mutex);
494 + up(&dir->d_inode->i_sem);
500 + /* everything ok! */
501 + if(!dtohd2(dentry)->d_inode) {
502 + printk(KERN_CRIT "mini_fo: build_sto_structure: failed to create storage dir [2].\n");
503 + /* was: unlock_dir(dir); */
504 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
505 + mutex_unlock(&dir->d_inode->i_mutex);
507 + up(&dir->d_inode->i_sem);
513 + /* interpose the new inode and set new state */
514 + itohi2(dentry->d_inode) = igrab(dtohd2(dentry)->d_inode);
515 + dtopd(dentry)->state = MODIFIED;
517 + /* initalize the wol list */
518 + itopd(dentry->d_inode)->deleted_list_size = -1;
519 + itopd(dentry->d_inode)->renamed_list_size = -1;
520 + meta_build_lists(dentry);
522 + fist_copy_attr_all(dentry->d_inode, itohi2(dentry->d_inode));
523 + fist_copy_attr_timesizes(dir->d_inode,
524 + hidden_sto_dir_dentry->d_inode);
525 + dir->d_inode->i_nlink++;
526 + /* was: unlock_dir(hidden_sto_dir_dentry); */
527 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
528 + mutex_unlock(&hidden_sto_dir_dentry->d_inode->i_mutex);
530 + up(&hidden_sto_dir_dentry->d_inode->i_sem);
532 + dput(hidden_sto_dir_dentry);
540 + * Read "len" bytes from "filename" into "buf".
541 + * "buf" is in kernel space.
544 +mini_fo_read_file(const char *filename, void *buf, int len)
547 + mm_segment_t oldfs;
549 + /* Chroot? Maybe NULL isn't right here */
550 + filp = filp_open(filename, O_RDONLY, 0);
551 + if (!filp || IS_ERR(filp)) {
552 + printk("mini_fo_read_file err %d\n", (int) PTR_ERR(filp));
553 + return -1; /* or do something else */
556 + if (!filp->f_op->read)
557 + return -2; /* file(system) doesn't allow reads */
559 + /* now read len bytes from offset 0 */
560 + filp->f_pos = 0; /* start offset */
563 + bytes = filp->f_op->read(filp, buf, len, &filp->f_pos);
566 + /* close the file */
575 + * Write "len" bytes from "buf" to "filename"
576 + * "buf" is in kernel space.
579 +mini_fo_write_file(const char *filename, void *buf, int len)
582 + mm_segment_t oldfs;
584 + /* Chroot? Maybe NULL isn't right here */
585 + filp = filp_open(filename, O_RDWR|O_CREAT, 0640);
586 + if (!filp || IS_ERR(filp)) {
587 + printk("mini_fo_write_file err %d\n", (int) PTR_ERR(filp));
588 + return -1; /* or do something else */
591 + if (!filp->f_op->write)
592 + return -2; /* file(system) doesn't allow writes */
594 + /* now write len bytes from offset 0 */
595 + filp->f_pos = 0; /* start offset */
598 + bytes = filp->f_op->write(filp, buf, len, &filp->f_pos);
601 + /* close the file */
609 Index: linux-2.6.25.4/fs/mini_fo/ChangeLog
610 ===================================================================
612 +++ linux-2.6.25.4/fs/mini_fo/ChangeLog
614 +2006-01-24 Markus Klotzbuecher <mk@mary.denx.de>
616 + * Add tons of ugly ifdefs to Ed L. Cashin's mutex patch to
617 + retain backwards compatibility.
619 +2006-01-24 Ed L. Cashin <ecashin@coraid.com>
621 + * Support for the new mutex infrastructure
622 + (7892f2f48d165a34b0b8130c8a195dfd807b8cb6)
624 +2005-10-15 Markus Klotzbuecher <mk@localhost.localdomain>
626 + * Bugfix for a serious memory leak in mini_fo_follow_link.
628 +2005-09-21 Markus Klotzbuecher <mk@mary>
630 + * new release 0.6.1
632 + * fix of a compiler warning due to changes in 2.6.13
634 +2005-09-21 Klaus Wenninger <klaus.wenninger@siemens.com>
636 + * file.c: readdir: fix for a bug that caused directory entries
637 + to show up twice when using storage filesystems such as
640 +2005-06-30 Eric Lammerts <eric@lammerts.org>
642 + * fix for an oops when overwriting a binary thats beeing
645 +2005-06-09 <mk@mary>
647 + * Renamed overlay to mini_fo-overlay.
649 + * Added mini_fo-merge script to allow merging of storage and base
650 + after making modifications.
652 +2005-05-22 root <mk@mary>
654 + * Added overlay script that allows to easily mount mini_fo ontop
655 + of a given base directory
657 +2005-05-10 <mk@mary>
659 + * inode.c: xattr functions return -EOPNOSUPP instead of
660 + -ENOSUPP, what confuses "ls -l"
662 + * Changed license from LGPL to GPL.
664 +2005-05-08 root <mk@mary>
666 + * Makefile: clean it up and added make install and make
669 +2005-05-06 <mk@mary>
671 + * merged devel branch back to main. [v0-6-0-pre3]
673 + * removed unused files print.c and fist_ioctl. [devel-0-0-18]
675 + * ioctl: removed fist_ioctl stuff, that is not needed for
678 +2005-05-03 <mk@mary>
680 + * file.c: simplified mini_fo_open and mini_fo_setattr using
681 + new state changing functions. [devel-0-0-17]
683 + * inode.c: Fixed getattr state bug (see below) in 2.4 function
684 + mini_fo_inode revalidate.
686 + * inode.c: found an other bug in mini_fo_getattr. States are not
687 + reliable in this function, as a file can be opened, unlinked and
688 + the getattr function called. This results in a deleted dentry
689 + with an inode. Fix is to ignore states and simply use the inode
692 +2005-04-29 <mk@mary>
694 + * file.c: Bugfix and cleanup in fasync and fsync. [devel-0-0-16]
696 + * file.c: do not use mini_fo_lock so the generic version is
699 + * inode.c: getattr, never call getattr on lower files, as this
700 + will cause the inum to change.
702 + * inode.c: rename_reg_file renamed to rename_nondir, as it
703 + doesn't matter as long it't not a dir. Removed all
704 + rename_dev_file etc.
706 + * tagged as devel-0-0-15
708 + * inode.c: added support for chosing support for extended
709 + attrs at compile time by XATTR define in mini_fo.h .
711 + * inode.c: fixed mini_fo_getattr to use mini_fo inode and not
712 + lower again, what avoids inode number changes that confused
713 + rm again. This is the proper solution.
715 +2005-04-24 <mk@mary>
717 + * all files: updated Copyright notive to 2005. [devel-0-0-14]
719 + * inode.c: fixed mini_fo_getattr to not change the inode
720 + number, even if lower files change.
722 + * super.c: fixed a bug that caused deleted base file to show
723 + up suddenly after some time, or after creating a special
724 + file. The problem was that after some time or after special
725 + file creating sync_sb_inodes is called by the vfs, that
726 + called our mini_fo_put_inode. There was (wrongly) called
727 + __meta_put_lists, that nuked the lists, although the inode
728 + was going to continue its life. Moving __meta_put_lists to
729 + mini_fo_clear_inode, where an inode is really destroyed,
730 + solved the problem.
733 +2005-04-23 <mk@mary>
735 + * state.c, aux.c: more cleaning up and
736 + simplifications. [devel-0-0-13]
738 + * inode.c: implemented mini_fo_getattr, that was required for
739 + 2.6 because inode_revalidate has been remove there, and the
740 + old "du" bug returned.
743 +2005-04-20 <mk@mary>
745 + * aux.c: get_neg_sto_dentry(): allow to be called for dentries
746 + in state UNMODIFIED, NON_EXISTANT _and_ DELETED.
748 +2005-04-19 <mk@mary>
750 + * Fixed a bug under 2.6 that caused files deleted via mini_fo
751 + not to be deleted properly and therefore the fs filled up
752 + untill no memory was left. [devel-0-0-12]
754 + * Added basic hard link support. This means that creating
755 + hardlinks will work, but existing ones will be treated as
756 + individual files. [devel-0-0-11]
758 +2005-04-17 <mk@mary>
762 +2005-04-13 root <mk@mary>
764 + * Added file state.c for the state transition
765 + functions. Doesn't work very well yet, though...
767 +2005-04-12 <mk@mary>
769 + * Porting to 2.6 started, which is easier than expected, also
770 + due to Olivier previous work.
772 +2005-04-08 <mk@mary>
774 + * Fixed the bug that caused du to return invalid sizes of
775 + directory trees. The problem was that
776 + mini_fo_inode_revalidate didn't always copy the attributes
777 + from the base inode properly.
779 +2005-04-01 Markus Klotzbuecher <mk@chasey>
781 + * Merged devel branch back to main trunk and updated the
782 + RELEASE notes. This will be 0-6-0-pre1.
784 +2005-03-31 Markus Klotzbuecher <mk@chasey>
786 + * Fixed some bugs in rename_reg_file, that only showed up in
787 + the kernel compile test. Kernel compiles cleanly ontop of
788 + mini_fo, now also make mrproper etc. work. Seems pretty stable.
790 +2005-03-28 Markus Klotzbuecher <mk@chasey>
792 + * Many, many directory renaming bugfixes and a lot of other
793 + cleanup. Dir renaming seems to work relatively stable.
795 +2005-03-22 Markus Klotzbuecher <mk@chasey>
797 + * Finished implementing lightweight directory renaming. Some
798 + basic testing indicates it works fine.
799 + Next is to implement testcases for the testsuite and confirm
800 + everything is really working ok.
802 +2005-03-18 Markus Klotzbuecher <mk@chasey>
804 + * Finished implementing meta.c stuff required for directory
807 +2005-03-17 Markus Klotzbuecher <mk@chasey>
809 + * Fixed all compile warnings + an extremly old bug that
810 + somehow crept in while reworking the wol stuff to the META
811 + system. Turning on -Werror again... :-)
813 + * Fixed some bugs in the new rename_reg_file function.
815 + * Rewrote mini_fo rename and split it into several
816 + subfunctions, that handle the different types
817 + seperately. Rewrote the regular file function aswell, as it
818 + was implemented somewhat inefficient.
820 +2005-03-16 Markus Klotzbuecher <mk@chasey>
822 + * Implemented new META subsystem, removed old WOL stuff in favor
825 + * After some basic testing everything seems ok...
827 +2005-03-11 Markus Klotzbuecher <mk@chasey>
829 + * Renaming a non regular file caused trouble because I always
830 + tried to copy the contents. Now I only do this for regular
831 + files. mini_fo_rename still isn't implemented properly, renaming
832 + of device files, symlinks etc. results in a empty regular file
833 + instead of the proper type.
835 + * Directory renaming suddenly works! What a surprise! I guess
836 + this is because renaming is implemented as making a copy and
837 + removing the original. Still this might not work
840 +2005-03-09 Markus Klotzbuecher <mk@chasey>
842 + * Bugfix, when a mini_fo directory that exists in storage
843 + (state: MODIFIED, CREATED and DEL_REWRITTEN) is deleted, a
844 + possibly existing WOL file contained in it needs to be
847 + * Starting cleanup: defined state names in order to get rid of
850 +2005-03-08 Markus Klotzbuecher <mk@chasey>
852 + * Makefile fix, fist_ioctl was built against wrong sources if ARCH=um
854 + * Fixed a bug in dentry.c, mini_fo_d_hash. In state 4 =
855 + DEL_REWRITTEN the hash was calculated from the base dentry,
856 + which was wrong and and caused assertions in
857 + __mini_fo_hidden_dentry to fail.
859 +2005-02-21 <mk@mary>
861 + * Implemented directory deleting (inode.c)
863 + * main.c: made mini_fo_parse_options a little more robust.
865 +2004-12-22 <mk@mary>
867 + * Makefile cleanup and uml stuff, removed unneccessary files
869 + * Created a new and hopefully more informative README
871 + * CHANGELOG: created a new CHANGELOG and added old entries reversely
874 +2004-10-24 Gleb Natapov <gleb@nbase.co.il>
876 + * Fix: owner and group where not correctly copied from base to
880 +2004-10-05 Gleb Natapov <gleb@nbase.co.il>
882 + * Implementation of fsync, fasync and lock mini_fo functions.
885 +2004-09-29 Bob Lee <bob@pantasys.com>
887 + * Fix of a serious pointer bug
890 +2004-09-28 Gleb Natapov <gleb@nbase.co.il>
892 + * Implementation of mini_fo_mknod and mini_fo_rename, support
895 Index: linux-2.6.25.4/fs/mini_fo/dentry.c
896 ===================================================================
898 +++ linux-2.6.25.4/fs/mini_fo/dentry.c
901 + * Copyright (c) 1997-2003 Erez Zadok
902 + * Copyright (c) 2001-2003 Stony Brook University
904 + * For specific licensing information, see the COPYING file distributed with
905 + * this package, or get one from ftp://ftp.filesystems.org/pub/fist/COPYING.
907 + * This Copyright notice must be kept intact and distributed with all
908 + * fistgen sources INCLUDING sources generated by fistgen.
911 + * Copyright (C) 2004, 2005 Markus Klotzbuecher <mk@creamnet.de>
913 + * This program is free software; you can redistribute it and/or
914 + * modify it under the terms of the GNU General Public License
915 + * as published by the Free Software Foundation; either version
916 + * 2 of the License, or (at your option) any later version.
923 +#ifdef HAVE_CONFIG_H
924 +# include <config.h>
928 +#include "mini_fo.h"
931 + * THIS IS A BOOLEAN FUNCTION: returns 1 if valid, 0 otherwise.
934 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
935 +mini_fo_d_revalidate(dentry_t *dentry, struct nameidata *nd)
937 +mini_fo_d_revalidate(dentry_t *dentry, int flags)
940 + int err1 = 1; /* valid = 1, invalid = 0 */
942 + dentry_t *hidden_dentry;
943 + dentry_t *hidden_sto_dentry;
946 + check_mini_fo_dentry(dentry);
948 + hidden_dentry = dtohd(dentry);
949 + hidden_sto_dentry = dtohd2(dentry);
951 + if(hidden_dentry &&
952 + hidden_dentry->d_op &&
953 + hidden_dentry->d_op->d_revalidate) {
954 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
955 + err1 = hidden_dentry->d_op->d_revalidate(hidden_dentry, nd);
957 + err1 = hidden_dentry->d_op->d_revalidate(hidden_dentry, flags);
960 + if(hidden_sto_dentry &&
961 + hidden_sto_dentry->d_op &&
962 + hidden_sto_dentry->d_op->d_revalidate) {
963 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
964 + err2 = hidden_sto_dentry->d_op->d_revalidate(hidden_sto_dentry,
967 + err2 = hidden_sto_dentry->d_op->d_revalidate(hidden_sto_dentry,
972 + /* mk: if one of the lower level dentries are valid,
973 + * the mini_fo dentry is too.
975 + return (err1 || err2);
980 +mini_fo_d_hash(dentry_t *dentry, qstr_t *name)
983 + dentry_t *hidden_dentry;
984 + dentry_t *hidden_sto_dentry;
986 + /* hidden_dentry = mini_fo_hidden_dentry(dentry);
987 + * hidden_sto_dentry = mini_fo_hidden_sto_dentry(dentry); */
989 + /* state 1, 3, 4, 5: build the hash for the storage dentry */
990 + if((dtopd(dentry)->state == MODIFIED) ||
991 + (dtopd(dentry)->state == CREATED) ||
992 + (dtopd(dentry)->state == DEL_REWRITTEN) ||
993 + (dtopd(dentry)->state == DELETED)) {
994 + hidden_sto_dentry = dtohd2(dentry);
995 + if(hidden_sto_dentry &&
996 + hidden_sto_dentry->d_op &&
997 + hidden_sto_dentry->d_op->d_hash) {
998 + err = hidden_sto_dentry->d_op->d_hash(hidden_sto_dentry, name);
1002 + /* state 2: build the hash for the base dentry */
1003 + if(dtopd(dentry)->state == UNMODIFIED) {
1004 + hidden_dentry = dtohd(dentry);
1005 + if(hidden_dentry &&
1006 + hidden_dentry->d_op &&
1007 + hidden_dentry->d_op->d_hash) {
1008 + err = hidden_dentry->d_op->d_hash(hidden_dentry, name);
1012 + /* state 6: build hash for the dentry that exists */
1013 + if(dtopd(dentry)->state == NON_EXISTANT) {
1014 + hidden_sto_dentry = dtohd2(dentry);
1015 + if(hidden_sto_dentry &&
1016 + hidden_sto_dentry->d_op &&
1017 + hidden_sto_dentry->d_op->d_hash) {
1018 + err = hidden_sto_dentry->d_op->d_hash(hidden_sto_dentry, name);
1021 + hidden_dentry = dtohd(dentry);
1022 + if(hidden_dentry &&
1023 + hidden_dentry->d_op &&
1024 + hidden_dentry->d_op->d_hash) {
1025 + err = hidden_dentry->d_op->d_hash(hidden_dentry, name);
1030 + printk(KERN_CRIT "mini_fo: d_hash: invalid state detected.\n");
1038 +mini_fo_d_compare(dentry_t *dentry, qstr_t *a, qstr_t *b)
1041 + dentry_t *hidden_dentry=NULL;
1043 + /* hidden_dentry = mini_fo_hidden_dentry(dentry); */
1044 + if(dtohd2(dentry))
1045 + hidden_dentry = dtohd2(dentry);
1046 + else if(dtohd(dentry))
1047 + hidden_dentry = dtohd(dentry);
1049 + if (hidden_dentry && hidden_dentry->d_op && hidden_dentry->d_op->d_compare) {
1050 + err = hidden_dentry->d_op->d_compare(hidden_dentry, a, b);
1052 + err = ((a->len != b->len) || memcmp(a->name, b->name, b->len));
1060 +mini_fo_d_delete(dentry_t *dentry)
1062 + dentry_t *hidden_dentry;
1063 + dentry_t *hidden_sto_dentry;
1066 + /* this could be a negative dentry, so check first */
1067 + if (!dtopd(dentry)) {
1068 + printk(KERN_CRIT "mini_fo_d_delete: negative dentry passed.\n");
1071 + hidden_dentry = dtohd(dentry);
1072 + hidden_sto_dentry = dtohd2(dentry);
1074 + if(hidden_dentry) {
1075 + if(hidden_dentry->d_op &&
1076 + hidden_dentry->d_op->d_delete) {
1077 + err = hidden_dentry->d_op->d_delete(hidden_dentry);
1080 + if(hidden_sto_dentry) {
1081 + if(hidden_sto_dentry->d_op &&
1082 + hidden_sto_dentry->d_op->d_delete) {
1083 + err = hidden_sto_dentry->d_op->d_delete(hidden_sto_dentry);
1093 +mini_fo_d_release(dentry_t *dentry)
1095 + dentry_t *hidden_dentry;
1096 + dentry_t *hidden_sto_dentry;
1099 + /* this could be a negative dentry, so check first */
1100 + if (!dtopd(dentry)) {
1101 + printk(KERN_CRIT "mini_fo_d_release: no private data.\n");
1104 + hidden_dentry = dtohd(dentry);
1105 + hidden_sto_dentry = dtohd2(dentry);
1107 + if(hidden_dentry) {
1108 + /* decrement hidden dentry's counter and free its inode */
1109 + dput(hidden_dentry);
1111 + if(hidden_sto_dentry) {
1112 + /* decrement hidden dentry's counter and free its inode */
1113 + dput(hidden_sto_dentry);
1116 + /* free private data (mini_fo_dentry_info) here */
1117 + kfree(dtopd(dentry));
1118 + __dtopd(dentry) = NULL; /* just to be safe */
1125 + * we don't really need mini_fo_d_iput, because dentry_iput will call iput() if
1126 + * mini_fo_d_iput is not defined. We left this implemented for ease of
1127 + * tracing/debugging.
1130 +mini_fo_d_iput(dentry_t *dentry, inode_t *inode)
1136 +struct dentry_operations mini_fo_dops = {
1137 + d_revalidate: mini_fo_d_revalidate,
1138 + d_hash: mini_fo_d_hash,
1139 + d_compare: mini_fo_d_compare,
1140 + d_release: mini_fo_d_release,
1141 + d_delete: mini_fo_d_delete,
1142 + d_iput: mini_fo_d_iput,
1144 Index: linux-2.6.25.4/fs/mini_fo/file.c
1145 ===================================================================
1147 +++ linux-2.6.25.4/fs/mini_fo/file.c
1150 + * Copyright (c) 1997-2003 Erez Zadok
1151 + * Copyright (c) 2001-2003 Stony Brook University
1153 + * For specific licensing information, see the COPYING file distributed with
1154 + * this package, or get one from ftp://ftp.filesystems.org/pub/fist/COPYING.
1156 + * This Copyright notice must be kept intact and distributed with all
1157 + * fistgen sources INCLUDING sources generated by fistgen.
1160 + * Copyright (C) 2004, 2005 Markus Klotzbuecher <mk@creamnet.de>
1162 + * This program is free software; you can redistribute it and/or
1163 + * modify it under the terms of the GNU General Public License
1164 + * as published by the Free Software Foundation; either version
1165 + * 2 of the License, or (at your option) any later version.
1172 +#ifdef HAVE_CONFIG_H
1173 +# include <config.h>
1177 +#include "mini_fo.h"
1178 +#define ROUND_UP(x) (((x)+sizeof(long)-1) & ~(sizeof(long)-1))
1180 +/*******************
1181 + * File Operations *
1182 + *******************/
1185 +mini_fo_llseek(file_t *file, loff_t offset, int origin)
1188 + file_t *hidden_file = NULL;
1190 + if(S_ISDIR(file->f_dentry->d_inode->i_mode)) {
1191 + /* Check if trying to llseek from a directory */
1195 + if (ftopd(file) != NULL) {
1196 + if(ftohf2(file)) {
1197 + hidden_file = ftohf2(file);
1199 + hidden_file = ftohf(file);
1203 + /* always set hidden position to this one */
1204 + hidden_file->f_pos = file->f_pos;
1206 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
1207 + memcpy(&(hidden_file->f_ra),
1209 + sizeof(struct file_ra_state));
1211 + if (file->f_reada) { /* update readahead information if needed */
1212 + hidden_file->f_reada = file->f_reada;
1213 + hidden_file->f_ramax = file->f_ramax;
1214 + hidden_file->f_raend = file->f_raend;
1215 + hidden_file->f_ralen = file->f_ralen;
1216 + hidden_file->f_rawin = file->f_rawin;
1219 + if (hidden_file->f_op && hidden_file->f_op->llseek)
1220 + err = hidden_file->f_op->llseek(hidden_file, offset, origin);
1222 + err = generic_file_llseek(hidden_file, offset, origin);
1227 + if (err != file->f_pos) {
1228 + file->f_pos = err;
1229 + // ION maybe this?
1230 + // file->f_pos = hidden_file->f_pos;
1231 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
1232 + file->f_reada = 0;
1234 + file->f_version++;
1242 +/* mk: fanout capable */
1244 +mini_fo_read(file_t *file, char *buf, size_t count, loff_t *ppos)
1246 + int err = -EINVAL;
1247 + file_t *hidden_file = NULL;
1248 + loff_t pos = *ppos;
1250 + if(S_ISDIR(file->f_dentry->d_inode->i_mode)) {
1251 + /* Check if trying to read from a directory */
1252 + /* printk(KERN_CRIT "mini_fo_read: ERROR: trying to read data from a directory.\n"); */
1257 + if (ftopd(file) != NULL) {
1258 + if(ftohf2(file)) {
1259 + hidden_file = ftohf2(file);
1261 + hidden_file = ftohf(file);
1265 + if (!hidden_file->f_op || !hidden_file->f_op->read)
1268 + err = hidden_file->f_op->read(hidden_file, buf, count, &pos);
1272 + /* atime should also be updated for reads of size zero or more */
1273 + fist_copy_attr_atime(file->f_dentry->d_inode,
1274 + hidden_file->f_dentry->d_inode);
1277 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
1280 + * because pread() does not have any way to tell us that it is
1281 + * our caller, then we don't know for sure if we have to update
1282 + * the file positions. This hack relies on read() having passed us
1283 + * the "real" pointer of its struct file's f_pos field.
1285 + if (ppos == &file->f_pos)
1286 + hidden_file->f_pos = *ppos = pos;
1287 + if (hidden_file->f_reada) { /* update readahead information if needed */
1288 + file->f_reada = hidden_file->f_reada;
1289 + file->f_ramax = hidden_file->f_ramax;
1290 + file->f_raend = hidden_file->f_raend;
1291 + file->f_ralen = hidden_file->f_ralen;
1292 + file->f_rawin = hidden_file->f_rawin;
1295 + memcpy(&(file->f_ra),&(hidden_file->f_ra),sizeof(struct file_ra_state));
1303 +/* this mini_fo_write() does not modify data pages! */
1305 +mini_fo_write(file_t *file, const char *buf, size_t count, loff_t *ppos)
1307 + int err = -EINVAL;
1308 + file_t *hidden_file = NULL;
1310 + inode_t *hidden_inode;
1311 + loff_t pos = *ppos;
1313 + /* mk: fan out: */
1314 + if (ftopd(file) != NULL) {
1315 + if(ftohf2(file)) {
1316 + hidden_file = ftohf2(file);
1318 + /* This is bad! We have no storage file to write to. This
1319 + * should never happen because if a file is opened for
1320 + * writing, a copy should have been made earlier.
1322 + printk(KERN_CRIT "mini_fo: write : ERROR, no storage file to write.\n");
1328 + inode = file->f_dentry->d_inode;
1329 + hidden_inode = itohi2(inode);
1330 + if(!hidden_inode) {
1331 + printk(KERN_CRIT "mini_fo: write: no sto inode found, not good.\n");
1335 + if (!hidden_file->f_op || !hidden_file->f_op->write)
1338 + /* adjust for append -- seek to the end of the file */
1339 + if (file->f_flags & O_APPEND)
1340 + pos = inode->i_size;
1342 + err = hidden_file->f_op->write(hidden_file, buf, count, &pos);
1345 + * copy ctime and mtime from lower layer attributes
1346 + * atime is unchanged for both layers
1349 + fist_copy_attr_times(inode, hidden_inode);
1352 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
1356 + * because pwrite() does not have any way to tell us that it is
1357 + * our caller, then we don't know for sure if we have to update
1358 + * the file positions. This hack relies on write() having passed us
1359 + * the "real" pointer of its struct file's f_pos field.
1361 + if (ppos == &file->f_pos)
1362 + hidden_file->f_pos = *ppos = pos;
1364 + /* update this inode's size */
1365 + if (pos > inode->i_size)
1366 + inode->i_size = pos;
1372 +/* Global variable to hold a file_t pointer.
1373 + * This serves to allow mini_fo_filldir function to know which file is
1374 + * beeing read, which is required for two reasons:
1376 + * - be able to call wol functions in order to avoid listing deleted
1378 + * - if we're reading a directory which is in state 1, we need to
1379 + * maintain a list (in mini_fo_filldir) of which files allready
1380 + * have been copied to userspace,to detect files existing in base
1381 + * and storage and not list them twice.
1383 +filldir_t mini_fo_filldir_orig;
1384 +file_t *mini_fo_filldir_file;
1386 +/* mainly copied from fs/readdir.c */
1388 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,18)
1389 +mini_fo_filldir(void * __buf, const char * name, int namlen, loff_t offset,
1390 + u64 ino, unsigned int d_type)
1392 +mini_fo_filldir(void * __buf, const char * name, int namlen, loff_t offset,
1393 + ino_t ino, unsigned int d_type)
1396 + struct getdents_callback * buf = (struct getdents_callback *) __buf;
1397 + file_t* file = mini_fo_filldir_file;
1399 + /* In theses states we filter meta files in storage (WOL) */
1400 + if(file && (dtopd(file->f_dentry)->state == MODIFIED ||
1401 + dtopd(file->f_dentry)->state == CREATED ||
1402 + dtopd(file->f_dentry)->state == DEL_REWRITTEN)) {
1404 + int tmp = strlen(META_FILENAME);
1405 + if(tmp == namlen) {
1406 + if(!strncmp(name, META_FILENAME, namlen))
1411 + /* check if we are merging the contents of storage and base */
1412 + if(file && dtopd(file->f_dentry)->state == MODIFIED) {
1413 + /* check if we are still reading storage contents, if
1414 + * yes, we just save the name of the file for duplicate
1415 + * checking later. */
1417 + if(!ftopd(file)->rd.sto_done) {
1418 + /* put file into ndl list */
1419 + if(ndl_add_entry(&ftopd(file)->rd, name, namlen))
1420 + printk(KERN_CRIT "mini_fo_filldir: Error adding to ndl.\n");
1422 + /* check if file has been deleted */
1423 + if(meta_check_d_entry(file->f_dentry, name, namlen))
1426 + /* do duplicate checking */
1427 + if(ndl_check_entry(&ftopd(file)->rd, name, namlen))
1432 + return mini_fo_filldir_orig(buf, name, namlen, offset, ino, d_type);
1437 +mini_fo_readdir(file_t *file, void *dirent, filldir_t filldir)
1439 + int err = 0;/* mk: ??? -ENOTDIR; */
1440 + file_t *hidden_file = NULL;
1441 + file_t *hidden_sto_file = NULL;
1443 + struct getdents_callback *buf;
1446 +#if defined(FIST_FILTER_NAME) || defined(FIST_FILTER_SCA)
1447 + struct mini_fo_getdents_callback buf;
1448 +#endif /* FIST_FILTER_NAME || FIST_FILTER_SCA */
1450 + buf = (struct getdents_callback *) dirent;
1451 + oldcount = buf->count;
1452 + inode = file->f_dentry->d_inode;
1453 + mini_fo_filldir_file = file;
1454 + mini_fo_filldir_orig = filldir;
1456 + ftopd(file)->rd.sto_done = 0;
1458 + if (ftopd(file) != NULL) {
1459 + if(ftohf2(file)) {
1460 + hidden_sto_file = ftohf2(file);
1461 + err = vfs_readdir(hidden_sto_file, mini_fo_filldir, dirent);
1462 + file->f_pos = hidden_sto_file->f_pos;
1464 + fist_copy_attr_atime(inode, hidden_sto_file->f_dentry->d_inode);
1465 + /* not finshed yet, we'll be called again */
1466 + if (buf->count != oldcount)
1470 + ftopd(file)->rd.sto_done = 1;
1473 + hidden_file = ftohf(file);
1474 + err = vfs_readdir(hidden_file, mini_fo_filldir, dirent);
1475 + file->f_pos = hidden_file->f_pos;
1477 + fist_copy_attr_atime(inode, hidden_file->f_dentry->d_inode);
1484 + * we need to check if all the directory data has been copied to userspace,
1485 + * or if we will be called again by userspace to complete the operation.
1487 + if(buf->count == oldcount) {
1488 + ndl_put_list(&ftopd(file)->rd);
1491 + /* unset this, safe */
1492 + mini_fo_filldir_file = NULL;
1497 +STATIC unsigned int
1498 +mini_fo_poll(file_t *file, poll_table *wait)
1500 + unsigned int mask = DEFAULT_POLLMASK;
1501 + file_t *hidden_file = NULL;
1503 + if (ftopd(file) != NULL) {
1504 + if(ftohf2(file)) {
1505 + hidden_file = ftohf2(file);
1507 + hidden_file = ftohf(file);
1511 + if (!hidden_file->f_op || !hidden_file->f_op->poll)
1514 + mask = hidden_file->f_op->poll(hidden_file, wait);
1520 +/* FIST-LITE special version of mmap */
1522 +mini_fo_mmap(file_t *file, vm_area_t *vma)
1525 + file_t *hidden_file = NULL;
1527 + /* fanout capability */
1528 + if (ftopd(file) != NULL) {
1529 + if(ftohf2(file)) {
1530 + hidden_file = ftohf2(file);
1532 + hidden_file = ftohf(file);
1536 + ASSERT(hidden_file != NULL);
1537 + ASSERT(hidden_file->f_op != NULL);
1538 + ASSERT(hidden_file->f_op->mmap != NULL);
1540 + vma->vm_file = hidden_file;
1541 + err = hidden_file->f_op->mmap(hidden_file, vma);
1542 + get_file(hidden_file); /* make sure it doesn't get freed on us */
1543 + fput(file); /* no need to keep extra ref on ours */
1551 +mini_fo_open(inode_t *inode, file_t *file)
1555 + file_t *hidden_file = NULL;
1556 + dentry_t *hidden_dentry = NULL;
1558 + /* fanout stuff */
1559 + file_t *hidden_sto_file = NULL;
1560 + dentry_t *hidden_sto_dentry = NULL;
1563 + kmalloc(sizeof(struct mini_fo_file_info), GFP_KERNEL);
1564 + if (!ftopd(file)) {
1569 + /* init the readdir_helper structure */
1570 + INIT_LIST_HEAD(&ftopd(file)->rd.ndl_list);
1571 + ftopd(file)->rd.ndl_size = 0;
1573 + /* In certain paths this could stay uninitalized and cause trouble */
1574 + ftohf(file) = NULL;
1575 + ftohf2(file) = NULL;
1576 + hidden_flags = file->f_flags;
1578 + /* create storage files? */
1579 + if(dtost(file->f_dentry) == UNMODIFIED) {
1580 + if(!IS_WRITE_FLAG(file->f_flags)) {
1581 + hidden_dentry = dtohd(file->f_dentry);
1582 + dget(hidden_dentry);
1583 + /* dentry_open will decrement mnt refcnt if err.
1584 + * otherwise fput() will do an mntput() for us upon file close. */
1585 + mntget(stopd(inode->i_sb)->hidden_mnt);
1586 + hidden_file = dentry_open(hidden_dentry,
1587 + stopd(inode->i_sb)->hidden_mnt,
1589 + if (IS_ERR(hidden_file)) {
1590 + err = PTR_ERR(hidden_file);
1591 + dput(hidden_dentry);
1594 + ftohf(file) = hidden_file; /* link two files */
1598 + if(S_ISDIR(file->f_dentry->d_inode->i_mode)) {
1599 + err = dir_unmod_to_mod(file->f_dentry);
1601 + err = nondir_unmod_to_mod(file->f_dentry, 1);
1604 + printk("mini_fo_open: ERROR creating storage file.\n");
1609 + hidden_sto_dentry = dtohd2(file->f_dentry);
1610 + dget(hidden_sto_dentry);
1612 + if(dtopd(file->f_dentry)->state == MODIFIED) {
1613 + /* Directorys are special, interpose on both lower level files */
1614 + if(S_ISDIR(itohi(inode)->i_mode)) {
1615 + /* check for invalid file types of lower level files */
1616 + if(!(S_ISDIR(itohi(inode)->i_mode) && S_ISDIR(itohi2(inode)->i_mode))) {
1617 + printk(KERN_CRIT "mini_fo_open: meta data corruption detected.\n");
1618 + dput(hidden_sto_dentry);
1623 + /* lower level directorys are ok, open the base file */
1624 + hidden_dentry = dtohd(file->f_dentry);
1625 + dget(hidden_dentry);
1627 + mntget(stopd(inode->i_sb)->hidden_mnt);
1628 + hidden_file = dentry_open(hidden_dentry,
1629 + stopd(inode->i_sb)->hidden_mnt,
1631 + if (IS_ERR(hidden_file)) {
1632 + err = PTR_ERR(hidden_file);
1633 + dput(hidden_dentry);
1634 + dput(hidden_sto_dentry);
1637 + ftohf(file) = hidden_file; /* link the two files */
1641 + if(!exists_in_storage(file->f_dentry)) {
1642 + printk(KERN_CRIT "mini_fo_open: invalid file state detected.\n");
1644 + dput(hidden_sto_dentry);
1646 + /* If the base file has been opened, we need to close it here */
1648 + if (hidden_file->f_op && hidden_file->f_op->flush)
1649 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,18)
1650 + hidden_file->f_op->flush(hidden_file, NULL);
1652 + hidden_file->f_op->flush(hidden_file);
1654 + dput(hidden_dentry);
1659 + /* ok, now we can safely open the storage file */
1660 + mntget(stopd(inode->i_sb)->hidden_mnt2);
1661 + hidden_sto_file = dentry_open(hidden_sto_dentry,
1662 + stopd(inode->i_sb)->hidden_mnt2,
1665 + /* dentry_open dputs the dentry if it fails */
1666 + if (IS_ERR(hidden_sto_file)) {
1667 + err = PTR_ERR(hidden_sto_file);
1668 + /* close base file if open */
1670 + if (hidden_file->f_op && hidden_file->f_op->flush)
1671 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,18)
1672 + hidden_file->f_op->flush(hidden_file, NULL);
1674 + hidden_file->f_op->flush(hidden_file);
1676 + dput(hidden_dentry);
1680 + ftohf2(file) = hidden_sto_file; /* link storage file */
1683 + if (err < 0 && ftopd(file)) {
1684 + kfree(ftopd(file));
1690 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,18)
1691 +mini_fo_flush(file_t *file, fl_owner_t id)
1693 +mini_fo_flush(file_t *file)
1696 + int err1 = 0; /* assume ok (see open.c:close_fp) */
1698 + file_t *hidden_file = NULL;
1700 + check_mini_fo_file(file);
1702 + /* mk: we don't do any state checking here, as its not worth the time.
1703 + * Just flush the lower level files if they exist.
1705 + if(ftopd(file) != NULL) {
1706 + if(ftohf(file) != NULL) {
1707 + hidden_file = ftohf(file);
1708 + if (hidden_file->f_op && hidden_file->f_op->flush)
1709 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,18)
1710 + err1 = hidden_file->f_op->flush(hidden_file, id);
1712 + err1 = hidden_file->f_op->flush(hidden_file);
1715 + if(ftohf2(file) != NULL) {
1716 + hidden_file = ftohf2(file);
1717 + if (hidden_file->f_op && hidden_file->f_op->flush)
1718 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,18)
1719 + err2 = hidden_file->f_op->flush(hidden_file, id);
1721 + err2 = hidden_file->f_op->flush(hidden_file);
1725 + return (err1 | err2);
1730 +mini_fo_release(inode_t *inode, file_t *file)
1733 + file_t *hidden_file = NULL;
1735 + if (ftopd(file) != NULL) {
1737 + hidden_file = ftohf(file);
1738 + fput(hidden_file);
1740 + if(ftohf2(file)) {
1741 + hidden_file = ftohf2(file);
1742 + fput(hidden_file);
1744 + kfree(ftopd(file));
1750 +mini_fo_fsync(file_t *file, dentry_t *dentry, int datasync)
1754 + file_t *hidden_file = NULL;
1755 + dentry_t *hidden_dentry;
1757 + check_mini_fo_file(file);
1759 + if ((hidden_file = ftohf(file)) != NULL) {
1760 + hidden_dentry = dtohd(dentry);
1761 + if (hidden_file->f_op && hidden_file->f_op->fsync) {
1762 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
1763 + mutex_lock(&hidden_dentry->d_inode->i_mutex);
1765 + down(&hidden_dentry->d_inode->i_sem);
1767 + err1 = hidden_file->f_op->fsync(hidden_file, hidden_dentry, datasync);
1768 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
1769 + mutex_unlock(&hidden_dentry->d_inode->i_mutex);
1771 + up(&hidden_dentry->d_inode->i_sem);
1776 + if ((hidden_file = ftohf2(file)) != NULL) {
1777 + hidden_dentry = dtohd2(dentry);
1778 + if (hidden_file->f_op && hidden_file->f_op->fsync) {
1779 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
1780 + mutex_lock(&hidden_dentry->d_inode->i_mutex);
1782 + down(&hidden_dentry->d_inode->i_sem);
1784 + err2 = hidden_file->f_op->fsync(hidden_file, hidden_dentry, datasync);
1785 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
1786 + mutex_unlock(&hidden_dentry->d_inode->i_mutex);
1788 + up(&hidden_dentry->d_inode->i_sem);
1796 + return (err1 || err2);
1801 +mini_fo_fasync(int fd, file_t *file, int flag)
1806 + file_t *hidden_file = NULL;
1808 + check_mini_fo_file(file);
1810 + if((hidden_file = ftohf(file)) != NULL) {
1811 + err1 = hidden_file->f_op->fasync(fd, hidden_file, flag);
1813 + if((hidden_file = ftohf2(file)) != NULL) {
1814 + err2 = hidden_file->f_op->fasync(fd, hidden_file, flag);
1817 + return (err1 || err2);
1822 +struct file_operations mini_fo_dir_fops =
1824 + read: generic_read_dir,
1825 + write: mini_fo_write,
1826 + readdir: mini_fo_readdir,
1827 + poll: mini_fo_poll,
1828 + /* ioctl: mini_fo_ioctl, */
1829 + mmap: mini_fo_mmap,
1830 + open: mini_fo_open,
1831 + flush: mini_fo_flush,
1832 + release: mini_fo_release,
1833 + fsync: mini_fo_fsync,
1834 + fasync: mini_fo_fasync,
1835 + /* not needed lock: mini_fo_lock, */
1836 + /* not needed: readv */
1837 + /* not needed: writev */
1838 + /* not implemented: sendpage */
1839 + /* not implemented: get_unmapped_area */
1842 +struct file_operations mini_fo_main_fops =
1844 + llseek: mini_fo_llseek,
1845 + read: mini_fo_read,
1846 + write: mini_fo_write,
1847 + readdir: mini_fo_readdir,
1848 + poll: mini_fo_poll,
1849 + /* ioctl: mini_fo_ioctl, */
1850 + mmap: mini_fo_mmap,
1851 + open: mini_fo_open,
1852 + flush: mini_fo_flush,
1853 + release: mini_fo_release,
1854 + fsync: mini_fo_fsync,
1855 + fasync: mini_fo_fasync,
1856 + /* not needed: lock: mini_fo_lock, */
1857 + /* not needed: readv */
1858 + /* not needed: writev */
1859 + /* not implemented: sendpage */
1860 + /* not implemented: get_unmapped_area */
1862 Index: linux-2.6.25.4/fs/mini_fo/fist.h
1863 ===================================================================
1865 +++ linux-2.6.25.4/fs/mini_fo/fist.h
1868 + * Copyright (c) 1997-2003 Erez Zadok
1869 + * Copyright (c) 2001-2003 Stony Brook University
1871 + * For specific licensing information, see the COPYING file distributed with
1872 + * this package, or get one from ftp://ftp.filesystems.org/pub/fist/COPYING.
1874 + * This Copyright notice must be kept intact and distributed with all
1875 + * fistgen sources INCLUDING sources generated by fistgen.
1878 + * Copyright (C) 2004, 2005 Markus Klotzbuecher <mk@creamnet.de>
1880 + * This program is free software; you can redistribute it and/or
1881 + * modify it under the terms of the GNU General Public License
1882 + * as published by the Free Software Foundation; either version
1883 + * 2 of the License, or (at your option) any later version.
1895 + * KERNEL ONLY CODE:
1898 +#include <linux/version.h>
1899 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,19)
1900 +#include <linux/autoconf.h>
1902 +#include <linux/config.h>
1904 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
1905 +#ifdef CONFIG_MODVERSIONS
1906 +# define MODVERSIONS
1907 +# include <linux/modversions.h>
1908 +#endif /* CONFIG_MODVERSIONS */
1909 +#endif /* KERNEL_VERSION < 2.6.0 */
1910 +#include <linux/sched.h>
1911 +#include <linux/kernel.h>
1912 +#include <linux/mm.h>
1913 +#include <linux/string.h>
1914 +#include <linux/stat.h>
1915 +#include <linux/errno.h>
1916 +#include <linux/wait.h>
1917 +#include <linux/limits.h>
1918 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
1919 +#include <linux/locks.h>
1921 +#include <linux/buffer_head.h>
1922 +#include <linux/pagemap.h>
1923 +#include <linux/namei.h>
1924 +#include <linux/module.h>
1925 +#include <linux/mount.h>
1926 +#include <linux/page-flags.h>
1927 +#include <linux/writeback.h>
1928 +#include <linux/statfs.h>
1930 +#include <linux/smp.h>
1931 +#include <linux/smp_lock.h>
1932 +#include <linux/file.h>
1933 +#include <linux/slab.h>
1934 +#include <linux/vmalloc.h>
1935 +#include <linux/poll.h>
1936 +#include <linux/list.h>
1937 +#include <linux/init.h>
1939 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,20)
1940 +#include <linux/xattr.h>
1943 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
1944 +#include <linux/security.h>
1947 +#include <linux/swap.h>
1949 +#include <asm/system.h>
1950 +/* #include <asm/segment.h> */
1951 +#include <asm/mman.h>
1952 +#include <linux/seq_file.h>
1958 +/* those mapped to ATTR_* were copied from linux/fs.h */
1959 +#define FA_MODE ATTR_MODE
1960 +#define FA_UID ATTR_UID
1961 +#define FA_GID ATTR_GID
1962 +#define FA_SIZE ATTR_SIZE
1963 +#define FA_ATIME ATTR_ATIME
1964 +#define FA_MTIME ATTR_MTIME
1965 +#define FA_CTIME ATTR_CTIME
1966 +#define FA_ATIME_SET ATTR_ATIME_SET
1967 +#define FA_MTIME_SET ATTR_MTIME_SET
1968 +#define FA_FORCE ATTR_FORCE
1969 +#define FA_ATTR_FLAGS ATTR_ATTR_FLAG
1971 +/* must be greater than all other ATTR_* flags! */
1972 +#define FA_NLINK 2048
1973 +#define FA_BLKSIZE 4096
1974 +#define FA_BLOCKS 8192
1975 +#define FA_TIMES (FA_ATIME|FA_MTIME|FA_CTIME)
1978 +/* macros to manage changes between kernels */
1979 +#define INODE_DATA(i) (&(i)->i_data)
1981 +#define MIN(x,y) ((x < y) ? (x) : (y))
1982 +#define MAX(x,y) ((x > y) ? (x) : (y))
1983 +#define MAXPATHLEN PATH_MAX
1985 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,4,5)
1986 +# define lookup_one_len(a,b,c) lookup_one(a,b)
1987 +#endif /* LINUX_VERSION_CODE < KERNEL_VERSION(2,4,5) */
1989 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,4,8)
1990 +# define generic_file_llseek default_llseek
1991 +#endif /* LINUX_VERSION_CODE < KERNEL_VERSION(2,4,8) */
1994 +# define SEEK_SET 0
1995 +#endif /* not SEEK_SET */
1998 +# define SEEK_CUR 1
1999 +#endif /* not SEEK_CUR */
2002 +# define SEEK_END 2
2003 +#endif /* not SEEK_END */
2005 +#ifndef DEFAULT_POLLMASK
2006 +# define DEFAULT_POLLMASK (POLLIN | POLLOUT | POLLRDNORM | POLLWRNORM)
2007 +#endif /* not DEFAULT_POLLMASK */
2009 +/* XXX: fix this so fistgen generates kfree() code directly */
2010 +#define kfree_s(a,b) kfree(a)
2015 +typedef struct dentry dentry_t;
2016 +typedef struct file file_t;
2017 +typedef struct inode inode_t;
2018 +typedef inode_t vnode_t;
2019 +typedef struct page page_t;
2020 +typedef struct qstr qstr_t;
2021 +typedef struct super_block super_block_t;
2022 +typedef super_block_t vfs_t;
2023 +typedef struct vm_area_struct vm_area_t;
2030 +#define FPPF(str,page) printk("PPF %s 0x%x/%d: Lck:%d Err:%d Ref:%d Upd:%d Other::%d:%d:%d:%d:\n", \
2033 + (int) page->index, \
2034 + (PageLocked(page) ? 1 : 0), \
2035 + (PageError(page) ? 1 : 0), \
2036 + (PageReferenced(page) ? 1 : 0), \
2037 + (Page_Uptodate(page) ? 1 : 0), \
2038 + (PageDecrAfter(page) ? 1 : 0), \
2039 + (PageSlab(page) ? 1 : 0), \
2040 + (PageSwapCache(page) ? 1 : 0), \
2041 + (PageReserved(page) ? 1 : 0) \
2043 +#define EZKDBG printk("EZK %s:%d:%s\n",__FILE__,__LINE__,__FUNCTION__)
2045 +# define EZKDBG1 printk("EZK %s:%d\n",__FILE__,__LINE__)
2050 +extern int fist_get_debug_value(void);
2051 +extern int fist_set_debug_value(int val);
2052 +#if 0 /* mini_fo doesn't need these */
2053 +extern void fist_dprint_internal(int level, char *str,...);
2054 +extern void fist_print_dentry(char *str, const dentry_t *dentry);
2055 +extern void fist_print_inode(char *str, const inode_t *inode);
2056 +extern void fist_print_file(char *str, const file_t *file);
2057 +extern void fist_print_buffer_flags(char *str, struct buffer_head *buffer);
2058 +extern void fist_print_page_flags(char *str, page_t *page);
2059 +extern void fist_print_page_bytes(char *str, page_t *page);
2060 +extern void fist_print_pte_flags(char *str, const page_t *page);
2061 +extern void fist_checkinode(inode_t *inode, char *msg);
2062 +extern void fist_print_sb(char *str, const super_block_t *sb);
2064 +/* §$% by mk: special debug functions */
2065 +extern void fist_mk_print_dentry(char *str, const dentry_t *dentry);
2066 +extern void fist_mk_print_inode(char *str, const inode_t *inode);
2068 +extern char *add_indent(void);
2069 +extern char *del_indent(void);
2070 +#endif/* mini_fo doesn't need these */
2074 +#define ASSERT(EX) \
2077 + printk(KERN_CRIT "ASSERTION FAILED: %s at %s:%d (%s)\n", #EX, \
2078 + __FILE__, __LINE__, __FUNCTION__); \
2079 + (*((char *)0))=0; \
2082 +/* same ASSERT, but tell me who was the caller of the function */
2083 +#define ASSERT2(EX) \
2086 + printk(KERN_CRIT "ASSERTION FAILED (caller): %s at %s:%d (%s)\n", #EX, \
2087 + file, line, func); \
2088 + (*((char *)0))=0; \
2092 +#if 0 /* mini_fo doesn't need these */
2093 +#define dprintk(format, args...) printk(KERN_DEBUG format, ##args)
2094 +#define fist_dprint(level, str, args...) fist_dprint_internal(level, KERN_DEBUG str, ## args)
2095 +#define print_entry_location() fist_dprint(4, "%sIN: %s %s:%d\n", add_indent(), __FUNCTION__, __FILE__, __LINE__)
2096 +#define print_exit_location() fist_dprint(4, "%s OUT: %s %s:%d\n", del_indent(), __FUNCTION__, __FILE__, __LINE__)
2097 +#define print_exit_status(status) fist_dprint(4, "%s OUT: %s %s:%d, STATUS: %d\n", del_indent(), __FUNCTION__, __FILE__, __LINE__, status)
2098 +#define print_exit_pointer(status) \
2100 + if (IS_ERR(status)) \
2101 + fist_dprint(4, "%s OUT: %s %s:%d, RESULT: %ld\n", del_indent(), __FUNCTION__, __FILE__, __LINE__, PTR_ERR(status)); \
2103 + fist_dprint(4, "%s OUT: %s %s:%d, RESULT: 0x%x\n", del_indent(), __FUNCTION__, __FILE__, __LINE__, PTR_ERR(status)); \
2105 +#endif/* mini_fo doesn't need these */
2107 +#endif /* __KERNEL__ */
2111 + * DEFINITIONS FOR USER AND KERNEL CODE:
2112 + * (Note: ioctl numbers 1--9 are reserved for fistgen, the rest
2113 + * are auto-generated automatically based on the user's .fist file.)
2115 +# define FIST_IOCTL_GET_DEBUG_VALUE _IOR(0x15, 1, int)
2116 +# define FIST_IOCTL_SET_DEBUG_VALUE _IOW(0x15, 2, int)
2118 +#endif /* not __FIST_H_ */
2119 Index: linux-2.6.25.4/fs/mini_fo/inode.c
2120 ===================================================================
2122 +++ linux-2.6.25.4/fs/mini_fo/inode.c
2125 + * Copyright (c) 1997-2003 Erez Zadok
2126 + * Copyright (c) 2001-2003 Stony Brook University
2128 + * For specific licensing information, see the COPYING file distributed with
2129 + * this package, or get one from ftp://ftp.filesystems.org/pub/fist/COPYING.
2131 + * This Copyright notice must be kept intact and distributed with all
2132 + * fistgen sources INCLUDING sources generated by fistgen.
2135 + * Copyright (C) 2004, 2005 Markus Klotzbuecher <mk@creamnet.de>
2137 + * This program is free software; you can redistribute it and/or
2138 + * modify it under the terms of the GNU General Public License
2139 + * as published by the Free Software Foundation; either version
2140 + * 2 of the License, or (at your option) any later version.
2147 +#ifdef HAVE_CONFIG_H
2148 +# include <config.h>
2152 +#include "mini_fo.h"
2155 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
2156 +mini_fo_create(inode_t *dir, dentry_t *dentry, int mode, struct nameidata *nd)
2158 +mini_fo_create(inode_t *dir, dentry_t *dentry, int mode)
2163 + check_mini_fo_dentry(dentry);
2165 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
2166 + err = create_sto_reg_file(dentry, mode, nd);
2168 + err = create_sto_reg_file(dentry, mode);
2170 + check_mini_fo_dentry(dentry);
2176 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
2177 +mini_fo_lookup(inode_t *dir, dentry_t *dentry, struct nameidata* nd)
2179 +mini_fo_lookup(inode_t *dir, dentry_t *dentry)
2183 + dentry_t *hidden_dir_dentry;
2184 + dentry_t *hidden_dentry = NULL;
2186 + dentry_t *hidden_sto_dir_dentry;
2187 + dentry_t *hidden_sto_dentry = NULL;
2189 + /* whiteout flag */
2191 + char *bpath = NULL;
2194 + unsigned int namelen;
2196 + /* Don't allow lookups of META-files */
2197 + namelen = strlen(META_FILENAME);
2198 + if(namelen == dentry->d_name.len) {
2199 + if(!strncmp(dentry->d_name.name, META_FILENAME, namelen)) {
2205 + hidden_dir_dentry = dtohd(dentry->d_parent);
2206 + hidden_sto_dir_dentry = dtohd2(dentry->d_parent);
2208 + name = dentry->d_name.name;
2209 + namelen = dentry->d_name.len;
2211 + /* must initialize dentry operations */
2212 + dentry->d_op = &mini_fo_dops;
2214 + /* setup the del_flag */
2215 + del_flag = __meta_check_d_entry(dir, name, namelen);
2216 + bpath = __meta_check_r_entry(dir, name, namelen);
2218 + /* perform the lookups of base and storage files:
2220 + * This caused some serious trouble, as a lookup_one_len passing
2221 + * a negative dentry oopses. Solution is to only do the lookup
2222 + * if the dentry is positive, else we set it to NULL
2223 + * More trouble, who said a *_dir_dentry can't be NULL?
2226 + /* Cross-Interposing (C), yeah! */
2227 + hidden_dentry = bpath_walk(dir->i_sb, bpath);
2228 + if(!hidden_dentry || !hidden_dentry->d_inode) {
2229 + printk(KERN_CRIT "mini_fo_lookup: bpath_walk failed.\n");
2234 + /* this can be set up safely without fear of spaghetti
2235 + * interposing as it is only used for copying times */
2236 + hidden_dir_dentry = hidden_dentry->d_parent;
2239 + else if(hidden_dir_dentry && hidden_dir_dentry->d_inode)
2241 + lookup_one_len(name, hidden_dir_dentry, namelen);
2243 + hidden_dentry = NULL;
2245 + if(hidden_sto_dir_dentry && hidden_sto_dir_dentry->d_inode)
2246 + hidden_sto_dentry =
2247 + lookup_one_len(name, hidden_sto_dir_dentry, namelen);
2249 + hidden_sto_dentry = NULL;
2251 + /* catch error in lookup */
2252 + if (IS_ERR(hidden_dentry) || IS_ERR(hidden_sto_dentry)) {
2253 + /* mk: we need to call dput on the dentry, whose
2254 + * lookup_one_len operation failed, in order to avoid
2255 + * unmount trouble.
2257 + if(IS_ERR(hidden_dentry)) {
2258 + printk(KERN_CRIT "mini_fo_lookup: ERR from base dentry, lookup failed.\n");
2259 + err = PTR_ERR(hidden_dentry);
2261 + dput(hidden_dentry);
2263 + if(IS_ERR(hidden_sto_dentry)) {
2264 + printk(KERN_CRIT "mini_fo_lookup: ERR from storage dentry, lookup failed.\n");
2265 + err = PTR_ERR(hidden_sto_dentry);
2267 + dput(hidden_sto_dentry);
2272 + /* allocate dentry private data */
2273 + __dtopd(dentry) = (struct mini_fo_dentry_info *)
2274 + kmalloc(sizeof(struct mini_fo_dentry_info), GFP_KERNEL);
2276 + if (!dtopd(dentry)) {
2281 + /* check for different states of the mini_fo file to be looked up. */
2283 + /* state 1, file has been modified */
2284 + if(hidden_dentry && hidden_sto_dentry &&
2285 + hidden_dentry->d_inode && hidden_sto_dentry->d_inode && !del_flag) {
2287 + /* update parent directory's atime */
2288 + fist_copy_attr_atime(dir, hidden_sto_dir_dentry->d_inode);
2290 + dtopd(dentry)->state = MODIFIED;
2291 + dtohd(dentry) = hidden_dentry;
2292 + dtohd2(dentry) = hidden_sto_dentry;
2294 + err = mini_fo_tri_interpose(hidden_dentry,
2295 + hidden_sto_dentry,
2296 + dentry, dir->i_sb, 1);
2298 + printk(KERN_CRIT "mini_fo_lookup: error interposing (state1).\n");
2303 + /* state 2, file is unmodified */
2304 + if(hidden_dentry && hidden_dentry->d_inode && !del_flag) {
2306 + fist_copy_attr_atime(dir, hidden_dir_dentry->d_inode);
2308 + dtopd(dentry)->state = UNMODIFIED;
2309 + dtohd(dentry) = hidden_dentry;
2310 + dtohd2(dentry) = hidden_sto_dentry; /* could be negative */
2312 + err = mini_fo_tri_interpose(hidden_dentry,
2313 + hidden_sto_dentry,
2314 + dentry, dir->i_sb, 1);
2316 + printk(KERN_CRIT "mini_fo_lookup: error interposing (state2).\n");
2321 + /* state 3, file has been newly created */
2322 + if(hidden_sto_dentry && hidden_sto_dentry->d_inode && !del_flag) {
2324 + fist_copy_attr_atime(dir, hidden_sto_dir_dentry->d_inode);
2325 + dtopd(dentry)->state = CREATED;
2326 + dtohd(dentry) = hidden_dentry; /* could be negative */
2327 + dtohd2(dentry) = hidden_sto_dentry;
2329 + err = mini_fo_tri_interpose(hidden_dentry,
2330 + hidden_sto_dentry,
2331 + dentry, dir->i_sb, 1);
2333 + printk(KERN_CRIT "mini_fo_lookup: error interposing (state3).\n");
2339 + /* state 4, file has deleted and created again. */
2340 + if(hidden_dentry && hidden_sto_dentry &&
2341 + hidden_dentry->d_inode &&
2342 + hidden_sto_dentry->d_inode && del_flag) {
2344 + fist_copy_attr_atime(dir, hidden_sto_dir_dentry->d_inode);
2345 + dtopd(dentry)->state = DEL_REWRITTEN;
2346 + dtohd(dentry) = NULL;
2347 + dtohd2(dentry) = hidden_sto_dentry;
2349 + err = mini_fo_tri_interpose(NULL,
2350 + hidden_sto_dentry,
2351 + dentry, dir->i_sb, 1);
2353 + printk(KERN_CRIT "mini_fo_lookup: error interposing (state4).\n");
2356 + /* We will never need this dentry again, as the file has been
2357 + * deleted from base */
2358 + dput(hidden_dentry);
2361 + /* state 5, file has been deleted in base */
2362 + if(hidden_dentry && hidden_sto_dentry &&
2363 + hidden_dentry->d_inode &&
2364 + !hidden_sto_dentry->d_inode && del_flag) {
2366 + /* check which parents atime we need for updating */
2367 + if(hidden_sto_dir_dentry->d_inode)
2368 + fist_copy_attr_atime(dir,
2369 + hidden_sto_dir_dentry->d_inode);
2371 + fist_copy_attr_atime(dir,
2372 + hidden_dir_dentry->d_inode);
2374 + dtopd(dentry)->state = DELETED;
2375 + dtohd(dentry) = NULL;
2376 + dtohd2(dentry) = hidden_sto_dentry;
2378 + /* add negative dentry to dcache to speed up lookups */
2379 + d_add(dentry, NULL);
2380 + dput(hidden_dentry);
2383 + /* state 6, file does not exist */
2384 + if(((hidden_dentry && !hidden_dentry->d_inode) ||
2385 + (hidden_sto_dentry && !hidden_sto_dentry->d_inode)) && !del_flag)
2387 + /* check which parents atime we need for updating */
2388 + if(hidden_sto_dir_dentry && hidden_sto_dir_dentry->d_inode)
2389 + fist_copy_attr_atime(dir, hidden_sto_dir_dentry->d_inode);
2391 + fist_copy_attr_atime(dir, hidden_dir_dentry->d_inode);
2393 + dtopd(dentry)->state = NON_EXISTANT;
2394 + dtohd(dentry) = hidden_dentry;
2395 + dtohd2(dentry) = hidden_sto_dentry;
2396 + d_add(dentry, NULL);
2400 + /* if we get to here, were in an invalid state. bad. */
2401 + printk(KERN_CRIT "mini_fo_lookup: ERROR, meta data corruption detected.\n");
2403 + /* end state checking */
2405 + d_drop(dentry); /* so that our bad dentry will get destroyed */
2406 + kfree(dtopd(dentry));
2407 + __dtopd(dentry) = NULL; /* be safe */
2411 + dput(hidden_dentry);
2412 + if(hidden_sto_dentry)
2413 + dput(hidden_sto_dentry); /* drops usage count and marks for release */
2416 + /* initalize wol if file exists and is directory */
2417 + if(dentry->d_inode) {
2418 + if(S_ISDIR(dentry->d_inode->i_mode)) {
2419 + itopd(dentry->d_inode)->deleted_list_size = -1;
2420 + itopd(dentry->d_inode)->renamed_list_size = -1;
2421 + meta_build_lists(dentry);
2424 + return ERR_PTR(err);
2429 +mini_fo_link(dentry_t *old_dentry, inode_t *dir, dentry_t *new_dentry)
2432 + dentry_t *hidden_old_dentry;
2433 + dentry_t *hidden_new_dentry;
2434 + dentry_t *hidden_dir_dentry;
2437 + check_mini_fo_dentry(old_dentry);
2438 + check_mini_fo_dentry(new_dentry);
2439 + check_mini_fo_inode(dir);
2441 + /* no links to directorys and existing targets target allowed */
2442 + if(S_ISDIR(old_dentry->d_inode->i_mode) ||
2443 + is_mini_fo_existant(new_dentry)) {
2448 + /* bring it directly from unmod to del_rew */
2449 + if(dtost(old_dentry) == UNMODIFIED) {
2450 + err = nondir_unmod_to_mod(old_dentry, 1);
2455 + err = meta_add_d_entry(old_dentry->d_parent,
2456 + old_dentry->d_name.name,
2457 + old_dentry->d_name.len);
2462 + dput(dtohd(old_dentry));
2463 + dtohd(old_dentry) = NULL;
2464 + dtost(old_dentry) = DEL_REWRITTEN;
2467 + err = get_neg_sto_dentry(new_dentry);
2473 + hidden_old_dentry = dtohd2(old_dentry);
2474 + hidden_new_dentry = dtohd2(new_dentry);
2476 + dget(hidden_old_dentry);
2477 + dget(hidden_new_dentry);
2479 + /* was: hidden_dir_dentry = lock_parent(hidden_new_dentry); */
2480 + hidden_dir_dentry = dget(hidden_new_dentry->d_parent);
2481 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
2482 + mutex_lock(&hidden_dir_dentry->d_inode->i_mutex);
2484 + down(&hidden_dir_dentry->d_inode->i_sem);
2487 + err = vfs_link(hidden_old_dentry,
2488 + hidden_dir_dentry->d_inode,
2489 + hidden_new_dentry);
2490 + if (err || !hidden_new_dentry->d_inode)
2493 + dtost(new_dentry) = CREATED;
2494 + err = mini_fo_tri_interpose(NULL, hidden_new_dentry, new_dentry, dir->i_sb, 0);
2498 + fist_copy_attr_timesizes(dir, hidden_new_dentry->d_inode);
2499 + /* propagate number of hard-links */
2500 + old_dentry->d_inode->i_nlink = itohi2(old_dentry->d_inode)->i_nlink;
2503 + /* was: unlock_dir(hidden_dir_dentry); */
2504 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
2505 + mutex_unlock(&hidden_dir_dentry->d_inode->i_mutex);
2507 + up(&hidden_dir_dentry->d_inode->i_sem);
2509 + dput(hidden_dir_dentry);
2511 + dput(hidden_new_dentry);
2512 + dput(hidden_old_dentry);
2513 + if (!new_dentry->d_inode)
2514 + d_drop(new_dentry);
2522 +mini_fo_unlink(inode_t *dir, dentry_t *dentry)
2527 + if(dtopd(dentry)->state == MODIFIED) {
2528 + err = nondir_mod_to_del(dentry);
2531 + else if(dtopd(dentry)->state == UNMODIFIED) {
2532 + err = nondir_unmod_to_del(dentry);
2535 + else if(dtopd(dentry)->state == CREATED) {
2536 + err = nondir_creat_to_del(dentry);
2539 + else if(dtopd(dentry)->state == DEL_REWRITTEN) {
2540 + err = nondir_del_rew_to_del(dentry);
2544 + printk(KERN_CRIT "mini_fo_unlink: ERROR, invalid state detected.\n");
2547 + fist_copy_attr_times(dir, itohi2(dentry->d_parent->d_inode));
2550 + /* is this causing my pain? d_delete(dentry); */
2560 +mini_fo_symlink(inode_t *dir, dentry_t *dentry, const char *symname)
2563 + dentry_t *hidden_sto_dentry;
2564 + dentry_t *hidden_sto_dir_dentry;
2565 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
2569 + /* Fail if the symlink file exists */
2570 + if(!(dtost(dentry) == DELETED ||
2571 + dtost(dentry) == NON_EXISTANT)) {
2576 + err = get_neg_sto_dentry(dentry);
2581 + hidden_sto_dentry = dtohd2(dentry);
2583 + dget(hidden_sto_dentry);
2584 + /* was: hidden_sto_dir_dentry = lock_parent(hidden_sto_dentry); */
2585 + hidden_sto_dir_dentry = dget(hidden_sto_dentry->d_parent);
2586 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
2587 + mutex_lock(&hidden_sto_dir_dentry->d_inode->i_mutex);
2589 + down(&hidden_sto_dir_dentry->d_inode->i_sem);
2592 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
2594 + err = vfs_symlink(hidden_sto_dir_dentry->d_inode,
2595 + hidden_sto_dentry, symname, mode);
2597 + err = vfs_symlink(hidden_sto_dir_dentry->d_inode,
2598 + hidden_sto_dentry,
2601 + if (err || !hidden_sto_dentry->d_inode)
2604 + if(dtost(dentry) == DELETED) {
2605 + dtost(dentry) = DEL_REWRITTEN;
2606 + err = mini_fo_tri_interpose(NULL, hidden_sto_dentry, dentry, dir->i_sb, 0);
2609 + } else if(dtost(dentry) == NON_EXISTANT) {
2610 + dtost(dentry) = CREATED;
2611 + err = mini_fo_tri_interpose(dtohd(dentry), hidden_sto_dentry, dentry, dir->i_sb, 0);
2615 + fist_copy_attr_timesizes(dir, hidden_sto_dir_dentry->d_inode);
2618 + /* was: unlock_dir(hidden_sto_dir_dentry); */
2619 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
2620 + mutex_unlock(&hidden_sto_dir_dentry->d_inode->i_mutex);
2622 + up(&hidden_sto_dir_dentry->d_inode->i_sem);
2624 + dput(hidden_sto_dir_dentry);
2626 + dput(hidden_sto_dentry);
2627 + if (!dentry->d_inode)
2634 +mini_fo_mkdir(inode_t *dir, dentry_t *dentry, int mode)
2638 + err = create_sto_dir(dentry, mode);
2640 + check_mini_fo_dentry(dentry);
2647 +mini_fo_rmdir(inode_t *dir, dentry_t *dentry)
2651 + dentry_t *hidden_sto_dentry;
2652 + dentry_t *hidden_sto_dir_dentry;
2653 + dentry_t *meta_dentry;
2654 + inode_t *hidden_sto_dir = NULL;
2656 + check_mini_fo_dentry(dentry);
2657 + check_mini_fo_inode(dir);
2660 + if(dtopd(dentry)->state == MODIFIED) {
2661 + /* XXX: disabled, because it does not bother to check files on
2662 + * the original filesystem - just a hack, but better than simply
2663 + * removing it without testing */
2667 + hidden_sto_dir = itohi2(dir);
2668 + hidden_sto_dentry = dtohd2(dentry);
2670 + /* was:hidden_sto_dir_dentry = lock_parent(hidden_sto_dentry); */
2671 + hidden_sto_dir_dentry = dget(hidden_sto_dentry->d_parent);
2672 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
2673 + mutex_lock(&hidden_sto_dir_dentry->d_inode->i_mutex);
2675 + down(&hidden_sto_dir_dentry->d_inode->i_sem);
2678 + /* Delete an old WOL file contained in the storage dir */
2679 + meta_dentry = lookup_one_len(META_FILENAME,
2680 + hidden_sto_dentry,
2681 + strlen(META_FILENAME));
2682 + if(meta_dentry->d_inode) {
2683 + err = vfs_unlink(hidden_sto_dentry->d_inode, meta_dentry);
2684 + dput(meta_dentry);
2686 + d_delete(meta_dentry);
2689 + err = vfs_rmdir(hidden_sto_dir, hidden_sto_dentry);
2690 + dput(hidden_sto_dentry);
2692 + d_delete(hidden_sto_dentry);
2694 + /* propagate number of hard-links */
2695 + dentry->d_inode->i_nlink = itohi2(dentry->d_inode)->i_nlink;
2697 + dput(dtohd(dentry));
2699 + dtohd(dentry) = NULL;
2700 + dtopd(dentry)->state = DELETED;
2702 + /* carefull with R files */
2703 + if( __meta_is_r_entry(dir,
2704 + dentry->d_name.name,
2705 + dentry->d_name.len) == 1) {
2706 + err = meta_remove_r_entry(dentry->d_parent,
2707 + dentry->d_name.name,
2708 + dentry->d_name.len);
2710 + printk(KERN_CRIT "mini_fo: rmdir: meta_remove_r_entry failed.\n");
2715 + /* ok, add deleted file to META */
2716 + meta_add_d_entry(dentry->d_parent,
2717 + dentry->d_name.name,
2718 + dentry->d_name.len);
2720 + /* was: unlock_dir(hidden_sto_dir_dentry); */
2721 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
2722 + mutex_unlock(&hidden_sto_dir_dentry->d_inode->i_mutex);
2724 + up(&hidden_sto_dir_dentry->d_inode->i_sem);
2726 + dput(hidden_sto_dir_dentry);
2729 + else if(dtopd(dentry)->state == UNMODIFIED) {
2730 + /* XXX: simply adding it to the delete list here is fscking dangerous!
2731 + * as a temporary hack, i will disable rmdir on unmodified directories
2737 + err = get_neg_sto_dentry(dentry);
2743 + /* dput base dentry, this will relase the inode and free the
2744 + * dentry, as we will never need it again. */
2745 + dput(dtohd(dentry));
2746 + dtohd(dentry) = NULL;
2747 + dtopd(dentry)->state = DELETED;
2749 + /* add deleted file to META-file */
2750 + meta_add_d_entry(dentry->d_parent,
2751 + dentry->d_name.name,
2752 + dentry->d_name.len);
2755 + else if(dtopd(dentry)->state == CREATED) {
2756 + hidden_sto_dir = itohi2(dir);
2757 + hidden_sto_dentry = dtohd2(dentry);
2759 + /* was: hidden_sto_dir_dentry = lock_parent(hidden_sto_dentry);*/
2760 + hidden_sto_dir_dentry = dget(hidden_sto_dentry->d_parent);
2762 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
2763 + mutex_lock(&hidden_sto_dir_dentry->d_inode->i_mutex);
2765 + down(&hidden_sto_dir_dentry->d_inode->i_sem);
2768 + /* Delete an old WOL file contained in the storage dir */
2769 + meta_dentry = lookup_one_len(META_FILENAME,
2770 + hidden_sto_dentry,
2771 + strlen(META_FILENAME));
2772 + if(meta_dentry->d_inode) {
2773 + /* is this necessary? dget(meta_dentry); */
2774 + err = vfs_unlink(hidden_sto_dentry->d_inode,
2776 + dput(meta_dentry);
2778 + d_delete(meta_dentry);
2781 + err = vfs_rmdir(hidden_sto_dir, hidden_sto_dentry);
2782 + dput(hidden_sto_dentry);
2784 + d_delete(hidden_sto_dentry);
2786 + /* propagate number of hard-links */
2787 + dentry->d_inode->i_nlink = itohi2(dentry->d_inode)->i_nlink;
2788 + dtopd(dentry)->state = NON_EXISTANT;
2790 + /* was: unlock_dir(hidden_sto_dir_dentry); */
2791 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
2792 + mutex_unlock(&hidden_sto_dir_dentry->d_inode->i_mutex);
2794 + up(&hidden_sto_dir_dentry->d_inode->i_sem);
2796 + dput(hidden_sto_dir_dentry);
2800 + else if(dtopd(dentry)->state == DEL_REWRITTEN) {
2801 + hidden_sto_dir = itohi2(dir);
2802 + hidden_sto_dentry = dtohd2(dentry);
2804 + /* was: hidden_sto_dir_dentry = lock_parent(hidden_sto_dentry);*/
2805 + hidden_sto_dir_dentry = dget(hidden_sto_dentry->d_parent);
2807 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
2808 + mutex_lock(&hidden_sto_dir_dentry->d_inode->i_mutex);
2810 + down(&hidden_sto_dir_dentry->d_inode->i_sem);
2813 + /* Delete an old WOL file contained in the storage dir */
2814 + meta_dentry = lookup_one_len(META_FILENAME,
2815 + hidden_sto_dentry,
2816 + strlen(META_FILENAME));
2817 + if(meta_dentry->d_inode) {
2818 + /* is this necessary? dget(meta_dentry); */
2819 + err = vfs_unlink(hidden_sto_dentry->d_inode,
2821 + dput(meta_dentry);
2823 + d_delete(meta_dentry);
2826 + err = vfs_rmdir(hidden_sto_dir, hidden_sto_dentry);
2827 + dput(hidden_sto_dentry);
2829 + d_delete(hidden_sto_dentry);
2831 + /* propagate number of hard-links */
2832 + dentry->d_inode->i_nlink = itohi2(dentry->d_inode)->i_nlink;
2833 + dtopd(dentry)->state = DELETED;
2834 + /* was: unlock_dir(hidden_sto_dir_dentry); */
2836 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
2837 + mutex_unlock(&hidden_sto_dir_dentry->d_inode->i_mutex);
2839 + up(&hidden_sto_dir_dentry->d_inode->i_sem);
2841 + dput(hidden_sto_dir_dentry);
2845 + printk(KERN_CRIT "mini_fo_rmdir: ERROR, invalid state detected.\n");
2852 + fist_copy_attr_times(dir, itohi2(dentry->d_parent->d_inode));
2860 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
2861 +mini_fo_mknod(inode_t *dir, dentry_t *dentry, int mode, dev_t dev)
2863 +mini_fo_mknod(inode_t *dir, dentry_t *dentry, int mode, int dev)
2868 + check_mini_fo_dentry(dentry);
2870 + err = create_sto_nod(dentry, mode, dev);
2872 + printk(KERN_CRIT "mini_fo_mknod: creating sto nod failed.\n");
2876 + check_mini_fo_dentry(dentry);
2882 +mini_fo_rename(inode_t *old_dir, dentry_t *old_dentry,
2883 + inode_t *new_dir, dentry_t *new_dentry)
2886 + if(S_ISDIR(old_dentry->d_inode->i_mode))
2887 + return rename_directory(old_dir, old_dentry, new_dir, new_dentry);
2888 + return rename_nondir(old_dir, old_dentry, new_dir, new_dentry);
2892 +int rename_directory(inode_t *old_dir, dentry_t *old_dentry,
2893 + inode_t *new_dir, dentry_t *new_dentry)
2895 + int err, bpath_len;
2898 + dentry_t *hidden_old_dentry;
2899 + dentry_t *hidden_new_dentry;
2900 + dentry_t *hidden_old_dir_dentry;
2901 + dentry_t *hidden_new_dir_dentry;
2907 + /* this is a test, chuck out if it works */
2908 + if(!(dtopd(new_dentry)->state == DELETED ||
2909 + dtopd(new_dentry)->state == NON_EXISTANT)) {
2910 + printk(KERN_CRIT "mini_fo: rename_directory: \
2911 + uh, ah, new_dentry not negative.\n");
2915 + /* state = UNMODIFIED */
2916 + if(dtopd(old_dentry)->state == UNMODIFIED) {
2917 + err = dir_unmod_to_mod(old_dentry);
2922 + /* state = MODIFIED */
2923 + if(dtopd(old_dentry)->state == MODIFIED) {
2924 + bpath = meta_check_r_entry(old_dentry->d_parent,
2925 + old_dentry->d_name.name,
2926 + old_dentry->d_name.len);
2928 + err = meta_remove_r_entry(old_dentry->d_parent,
2929 + old_dentry->d_name.name,
2930 + old_dentry->d_name.len);
2932 + printk(KERN_CRIT "mini_fo: rename_directory:\
2933 + meta_remove_r_entry \
2937 + err = meta_add_r_entry(new_dentry->d_parent,
2940 + new_dentry->d_name.name,
2941 + new_dentry->d_name.len);
2944 + else {/* wol it */
2945 + err = meta_add_d_entry(old_dentry->d_parent,
2946 + old_dentry->d_name.name,
2947 + old_dentry->d_name.len);
2950 + /* put it on rename list */
2951 + err = get_mini_fo_bpath(old_dentry,
2956 + err = meta_add_r_entry(new_dentry->d_parent,
2958 + new_dentry->d_name.name,
2959 + new_dentry->d_name.len);
2963 + /* no state change, MODIFIED stays MODIFIED */
2965 + /* state = CREATED */
2966 + if(dtopd(old_dentry)->state == CREATED ||
2967 + dtopd(old_dentry)->state == DEL_REWRITTEN) {
2968 + if(dtohd(old_dentry))
2969 + dput(dtohd(old_dentry));
2971 + if(dtopd(new_dentry)->state == DELETED) {
2972 + dtopd(old_dentry)->state = DEL_REWRITTEN;
2973 + dtohd(old_dentry) = NULL;
2975 + else if(dtopd(new_dentry)->state == NON_EXISTANT) {
2976 + dtopd(old_dentry)->state = CREATED;
2977 + /* steal new dentry's neg. base dentry */
2978 + dtohd(old_dentry) = dtohd(new_dentry);
2979 + dtohd(new_dentry) = NULL;
2982 + if(dtopd(new_dentry)->state == UNMODIFIED ||
2983 + dtopd(new_dentry)->state == NON_EXISTANT) {
2984 + err = get_neg_sto_dentry(new_dentry);
2989 + /* now move sto file */
2990 + hidden_old_dentry = dtohd2(old_dentry);
2991 + hidden_new_dentry = dtohd2(new_dentry);
2993 + dget(hidden_old_dentry);
2994 + dget(hidden_new_dentry);
2996 + hidden_old_dir_dentry = dget(hidden_old_dentry->d_parent);
2997 + hidden_new_dir_dentry = dget(hidden_new_dentry->d_parent);
2998 + double_lock(hidden_old_dir_dentry, hidden_new_dir_dentry);
3000 + err = vfs_rename(hidden_old_dir_dentry->d_inode, hidden_old_dentry,
3001 + hidden_new_dir_dentry->d_inode, hidden_new_dentry);
3005 + fist_copy_attr_all(new_dir, hidden_new_dir_dentry->d_inode);
3006 + if (new_dir != old_dir)
3007 + fist_copy_attr_all(old_dir,
3008 + hidden_old_dir_dentry->d_inode);
3011 + /* double_unlock will dput the new/old parent dentries
3012 + * whose refcnts were incremented via get_parent above. */
3013 + double_unlock(hidden_old_dir_dentry, hidden_new_dir_dentry);
3014 + dput(hidden_new_dentry);
3015 + dput(hidden_old_dentry);
3021 +int rename_nondir(inode_t *old_dir, dentry_t *old_dentry,
3022 + inode_t *new_dir, dentry_t *new_dentry)
3026 + check_mini_fo_dentry(old_dentry);
3027 + check_mini_fo_dentry(new_dentry);
3028 + check_mini_fo_inode(old_dir);
3029 + check_mini_fo_inode(new_dir);
3031 + /* state: UNMODIFIED */
3032 + if(dtost(old_dentry) == UNMODIFIED) {
3033 + err = nondir_unmod_to_mod(old_dentry, 1);
3040 + /* the easy states */
3041 + if(exists_in_storage(old_dentry)) {
3043 + dentry_t *hidden_old_dentry;
3044 + dentry_t *hidden_new_dentry;
3045 + dentry_t *hidden_old_dir_dentry;
3046 + dentry_t *hidden_new_dir_dentry;
3048 + /* if old file is MODIFIED, add it to the deleted_list */
3049 + if(dtopd(old_dentry)->state == MODIFIED) {
3050 + meta_add_d_entry(old_dentry->d_parent,
3051 + old_dentry->d_name.name,
3052 + old_dentry->d_name.len);
3054 + dput(dtohd(old_dentry));
3056 + /* if old file is CREATED, we only release the base dentry */
3057 + if(dtopd(old_dentry)->state == CREATED) {
3058 + if(dtohd(old_dentry))
3059 + dput(dtohd(old_dentry));
3062 + /* now setup the new states (depends on new_dentry state) */
3063 + /* new dentry state = MODIFIED */
3064 + if(dtopd(new_dentry)->state == MODIFIED) {
3065 + meta_add_d_entry(new_dentry->d_parent,
3066 + new_dentry->d_name.name,
3067 + new_dentry->d_name.len);
3069 + /* new dentry will be d_put'ed later by the vfs
3070 + * so don't do it here
3071 + * dput(dtohd(new_dentry));
3073 + dtohd(old_dentry) = NULL;
3074 + dtopd(old_dentry)->state = DEL_REWRITTEN;
3076 + /* new dentry state = UNMODIFIED */
3077 + else if(dtopd(new_dentry)->state == UNMODIFIED) {
3078 + if(get_neg_sto_dentry(new_dentry))
3081 + meta_add_d_entry(new_dentry->d_parent,
3082 + new_dentry->d_name.name,
3083 + new_dentry->d_name.len);
3085 + /* is this right??? */
3086 + /*dput(dtohd(new_dentry));*/
3087 + dtohd(old_dentry) = NULL;
3088 + dtopd(old_dentry)->state = DEL_REWRITTEN;
3090 + /* new dentry state = CREATED */
3091 + else if(dtopd(new_dentry)->state == CREATED) {
3092 + /* we keep the neg. base dentry (if exists) */
3093 + dtohd(old_dentry) = dtohd(new_dentry);
3094 + /* ...and set it to Null, or we'll get
3095 + * dcache.c:345 if it gets dput twice... */
3096 + dtohd(new_dentry) = NULL;
3097 + dtopd(old_dentry)->state = CREATED;
3099 + /* new dentry state = NON_EXISTANT */
3100 + else if(dtopd(new_dentry)->state == NON_EXISTANT) {
3101 + if(get_neg_sto_dentry(new_dentry))
3104 + /* we keep the neg. base dentry (if exists) */
3105 + dtohd(old_dentry) = dtohd(new_dentry);
3106 + /* ...and set it to Null, or we'll get
3107 + * Dr. dcache.c:345 if it gets dput twice... */
3108 + dtohd(new_dentry) = NULL;
3109 + dtopd(old_dentry)->state = CREATED;
3111 + /* new dentry state = DEL_REWRITTEN or DELETED */
3112 + else if(dtopd(new_dentry)->state == DEL_REWRITTEN ||
3113 + dtopd(new_dentry)->state == DELETED) {
3114 + dtohd(old_dentry) = NULL;
3115 + dtopd(old_dentry)->state = DEL_REWRITTEN;
3117 + else { /* not possible, uhh, ahh */
3119 + "mini_fo: rename_reg_file: invalid state detected [1].\n");
3123 + /* now we definitely have a sto file */
3124 + hidden_old_dentry = dtohd2(old_dentry);
3125 + hidden_new_dentry = dtohd2(new_dentry);
3127 + dget(hidden_old_dentry);
3128 + dget(hidden_new_dentry);
3130 + hidden_old_dir_dentry = dget(hidden_old_dentry->d_parent);
3131 + hidden_new_dir_dentry = dget(hidden_new_dentry->d_parent);
3132 + double_lock(hidden_old_dir_dentry, hidden_new_dir_dentry);
3134 + err = vfs_rename(hidden_old_dir_dentry->d_inode,
3135 + hidden_old_dentry,
3136 + hidden_new_dir_dentry->d_inode,
3137 + hidden_new_dentry);
3141 + fist_copy_attr_all(new_dir, hidden_new_dir_dentry->d_inode);
3142 + if (new_dir != old_dir)
3143 + fist_copy_attr_all(old_dir, hidden_old_dir_dentry->d_inode);
3146 + /* double_unlock will dput the new/old parent dentries
3147 + * whose refcnts were incremented via get_parent above.
3149 + double_unlock(hidden_old_dir_dentry, hidden_new_dir_dentry);
3150 + dput(hidden_new_dentry);
3151 + dput(hidden_old_dentry);
3155 + else { /* invalid state */
3156 + printk(KERN_CRIT "mini_fo: rename_reg_file: ERROR: invalid state detected [2].\n");
3163 +mini_fo_readlink(dentry_t *dentry, char *buf, int bufsiz)
3166 + dentry_t *hidden_dentry = NULL;
3168 + if(dtohd2(dentry) && dtohd2(dentry)->d_inode) {
3169 + hidden_dentry = dtohd2(dentry);
3170 + } else if(dtohd(dentry) && dtohd(dentry)->d_inode) {
3171 + hidden_dentry = dtohd(dentry);
3176 + if (!hidden_dentry->d_inode->i_op ||
3177 + !hidden_dentry->d_inode->i_op->readlink) {
3178 + err = -EINVAL; goto out;
3181 + err = hidden_dentry->d_inode->i_op->readlink(hidden_dentry,
3185 + fist_copy_attr_atime(dentry->d_inode, hidden_dentry->d_inode);
3192 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,13)
3193 +static int mini_fo_follow_link(dentry_t *dentry, struct nameidata *nd)
3195 +static void* mini_fo_follow_link(dentry_t *dentry, struct nameidata *nd)
3199 + int len = PAGE_SIZE, err;
3200 + mm_segment_t old_fs;
3202 + /* in 2.6 this is freed by mini_fo_put_link called by __do_follow_link */
3203 + buf = kmalloc(len, GFP_KERNEL);
3209 + /* read the symlink, and then we will follow it */
3210 + old_fs = get_fs();
3211 + set_fs(KERNEL_DS);
3212 + err = dentry->d_inode->i_op->readlink(dentry, buf, len);
3220 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
3221 + nd_set_link(nd, buf);
3224 + err = vfs_follow_link(nd, buf);
3228 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
3232 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,13)
3235 + return ERR_PTR(err);
3240 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
3241 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,13)
3242 +void mini_fo_put_link(struct dentry *dentry, struct nameidata *nd)
3244 +void mini_fo_put_link(struct dentry *dentry, struct nameidata *nd, void *cookie)
3248 + link = nd_get_link(nd);
3254 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
3255 +mini_fo_permission(inode_t *inode, int mask, struct nameidata *nd)
3257 +mini_fo_permission(inode_t *inode, int mask)
3260 + inode_t *hidden_inode;
3264 + if(itohi2(inode)) {
3265 + hidden_inode = itohi2(inode);
3267 + hidden_inode = itohi(inode);
3269 + mode = inode->i_mode;
3271 + /* not really needed, as permission handles everything:
3272 + * err = vfs_permission(inode, mask);
3277 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
3278 + err = permission(hidden_inode, mask, nd);
3280 + err = permission(hidden_inode, mask);
3287 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
3289 +mini_fo_inode_revalidate(dentry_t *dentry)
3292 + dentry_t *hidden_dentry;
3293 + inode_t *hidden_inode;
3295 + ASSERT(dentry->d_inode);
3296 + ASSERT(itopd(dentry->d_inode));
3298 + if(itohi2(dentry->d_inode)) {
3299 + hidden_dentry = dtohd2(dentry);
3300 + hidden_inode = hidden_dentry->d_inode;
3301 + } else if(itohi(dentry->d_inode)) {
3302 + hidden_dentry = dtohd(dentry);
3303 + hidden_inode = hidden_dentry->d_inode;
3305 + printk(KERN_CRIT "mini_fo_inode_revalidate: ERROR, invalid state detected.\n");
3309 + if (hidden_inode && hidden_inode->i_op && hidden_inode->i_op->revalidate){
3310 + err = hidden_inode->i_op->revalidate(hidden_dentry);
3314 + fist_copy_attr_all(dentry->d_inode, hidden_inode);
3321 +mini_fo_setattr(dentry_t *dentry, struct iattr *ia)
3325 + check_mini_fo_dentry(dentry);
3327 + if(!is_mini_fo_existant(dentry)) {
3328 + printk(KERN_CRIT "mini_fo_setattr: ERROR, invalid state detected [1].\n");
3332 + if(dtost(dentry) == UNMODIFIED) {
3333 + if(!IS_COPY_FLAG(ia->ia_valid))
3334 + goto out; /* we ignore these changes to base */
3336 + if(S_ISDIR(dentry->d_inode->i_mode)) {
3337 + err = dir_unmod_to_mod(dentry);
3339 + /* we copy contents if file is not beeing truncated */
3340 + if(S_ISREG(dentry->d_inode->i_mode) &&
3341 + !(ia->ia_size == 0 && (ia->ia_valid & ATTR_SIZE))) {
3342 + err = nondir_unmod_to_mod(dentry, 1);
3344 + err = nondir_unmod_to_mod(dentry, 0);
3348 + printk(KERN_CRIT "mini_fo_setattr: ERROR changing states.\n");
3352 + if(!exists_in_storage(dentry)) {
3353 + printk(KERN_CRIT "mini_fo_setattr: ERROR, invalid state detected [2].\n");
3357 + ASSERT(dentry->d_inode);
3358 + ASSERT(dtohd2(dentry));
3359 + ASSERT(itopd(dentry->d_inode));
3360 + ASSERT(itohi2(dentry->d_inode));
3362 + err = notify_change(dtohd2(dentry), ia);
3363 + fist_copy_attr_all(dentry->d_inode, itohi2(dentry->d_inode));
3368 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
3370 +mini_fo_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
3373 + dentry_t *hidden_dentry;
3375 + ASSERT(dentry->d_inode);
3376 + ASSERT(itopd(dentry->d_inode));
3378 + if(itohi2(dentry->d_inode)) {
3379 + hidden_dentry = dtohd2(dentry);
3380 + } else if(itohi(dentry->d_inode)) {
3381 + hidden_dentry = dtohd(dentry);
3383 + printk(KERN_CRIT "mini_fo_getattr: ERROR, invalid state detected.\n");
3387 + fist_copy_attr_all(dentry->d_inode, hidden_dentry->d_inode);
3389 + ASSERT(hidden_dentry);
3390 + ASSERT(hidden_dentry->d_inode);
3391 + ASSERT(hidden_dentry->d_inode->i_op);
3393 + generic_fillattr(dentry->d_inode, stat);
3394 + if (!stat->blksize) {
3395 + struct super_block *s = hidden_dentry->d_inode->i_sb;
3397 + blocks = (stat->size+s->s_blocksize-1) >> s->s_blocksize_bits;
3398 + stat->blocks = (s->s_blocksize / 512) * blocks;
3399 + stat->blksize = s->s_blocksize;
3406 +#if defined(XATTR) && (LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,20))
3407 +#if 0 /* no xattr_alloc() and xattr_free() */
3408 +/* This is lifted from fs/xattr.c */
3410 +xattr_alloc(size_t size, size_t limit)
3415 + return ERR_PTR(-E2BIG);
3417 + if (!size) /* size request, no buffer is needed */
3419 + else if (size <= PAGE_SIZE)
3420 + ptr = kmalloc((unsigned long) size, GFP_KERNEL);
3422 + ptr = vmalloc((unsigned long) size);
3424 + return ERR_PTR(-ENOMEM);
3429 +xattr_free(void *ptr, size_t size)
3431 + if (!size) /* size request, no buffer was needed */
3433 + else if (size <= PAGE_SIZE)
3438 +#endif /* no xattr_alloc() and xattr_free() */
3440 +/* BKL held by caller.
3441 + * dentry->d_inode->i_sem down
3444 +mini_fo_getxattr(struct dentry *dentry, const char *name, void *value, size_t size) {
3445 + struct dentry *hidden_dentry = NULL;
3446 + int err = -EOPNOTSUPP;
3447 + /* Define these anyway so we don't need as much ifdef'ed code. */
3448 + char *encoded_name = NULL;
3449 + char *encoded_value = NULL;
3451 + check_mini_fo_dentry(dentry);
3453 + if(exists_in_storage(dentry))
3454 + hidden_dentry = dtohd2(dentry);
3456 + hidden_dentry = dtohd(dentry);
3458 + ASSERT(hidden_dentry);
3459 + ASSERT(hidden_dentry->d_inode);
3460 + ASSERT(hidden_dentry->d_inode->i_op);
3462 + if (hidden_dentry->d_inode->i_op->getxattr) {
3463 + encoded_name = (char *)name;
3464 + encoded_value = (char *)value;
3466 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
3467 + mutex_lock(&hidden_dentry->d_inode->i_mutex);
3469 + down(&hidden_dentry->d_inode->i_sem);
3471 + /* lock_kernel() already done by caller. */
3472 + err = hidden_dentry->d_inode->i_op->getxattr(hidden_dentry, encoded_name, encoded_value, size);
3473 + /* unlock_kernel() will be done by caller. */
3474 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
3475 + mutex_lock(&hidden_dentry->d_inode->i_mutex);
3477 + up(&hidden_dentry->d_inode->i_sem);
3483 +/* BKL held by caller.
3484 + * dentry->d_inode->i_sem down
3487 +#if ((LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,21) \
3488 + && LINUX_VERSION_CODE <= KERNEL_VERSION(2,4,23)) \
3489 + || LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0))
3490 +mini_fo_setxattr(struct dentry *dentry, const char *name,
3491 + const void *value, size_t size, int flags)
3493 +mini_fo_setxattr(struct dentry *dentry, const char *name,
3494 + void *value, size_t size, int flags)
3498 + struct dentry *hidden_dentry = NULL;
3499 + int err = -EOPNOTSUPP;
3501 + /* Define these anyway, so we don't have as much ifdef'ed code. */
3502 + char *encoded_value = NULL;
3503 + char *encoded_name = NULL;
3505 + check_mini_fo_dentry(dentry);
3507 + if(exists_in_storage(dentry))
3508 + hidden_dentry = dtohd2(dentry);
3510 + hidden_dentry = dtohd(dentry);
3512 + ASSERT(hidden_dentry);
3513 + ASSERT(hidden_dentry->d_inode);
3514 + ASSERT(hidden_dentry->d_inode->i_op);
3516 + if (hidden_dentry->d_inode->i_op->setxattr) {
3517 + encoded_name = (char *)name;
3518 + encoded_value = (char *)value;
3520 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
3521 + mutex_lock(&hidden_dentry->d_inode->i_mutex);
3523 + down(&hidden_dentry->d_inode->i_sem);
3525 + /* lock_kernel() already done by caller. */
3526 + err = hidden_dentry->d_inode->i_op->setxattr(hidden_dentry, encoded_name, encoded_value, size, flags);
3527 + /* unlock_kernel() will be done by caller. */
3528 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
3529 + mutex_unlock(&hidden_dentry->d_inode->i_mutex);
3531 + up(&hidden_dentry->d_inode->i_sem);
3537 +/* BKL held by caller.
3538 + * dentry->d_inode->i_sem down
3541 +mini_fo_removexattr(struct dentry *dentry, const char *name) {
3542 + struct dentry *hidden_dentry = NULL;
3543 + int err = -EOPNOTSUPP;
3544 + char *encoded_name;
3546 + check_mini_fo_dentry(dentry);
3548 + if(exists_in_storage(dentry))
3549 + hidden_dentry = dtohd2(dentry);
3551 + hidden_dentry = dtohd(dentry);
3553 + ASSERT(hidden_dentry);
3554 + ASSERT(hidden_dentry->d_inode);
3555 + ASSERT(hidden_dentry->d_inode->i_op);
3557 + if (hidden_dentry->d_inode->i_op->removexattr) {
3558 + encoded_name = (char *)name;
3560 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
3561 + mutex_lock(&hidden_dentry->d_inode->i_mutex);
3563 + down(&hidden_dentry->d_inode->i_sem);
3565 + /* lock_kernel() already done by caller. */
3566 + err = hidden_dentry->d_inode->i_op->removexattr(hidden_dentry, encoded_name);
3567 + /* unlock_kernel() will be done by caller. */
3568 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
3569 + mutex_unlock(&hidden_dentry->d_inode->i_mutex);
3571 + up(&hidden_dentry->d_inode->i_sem);
3577 +/* BKL held by caller.
3578 + * dentry->d_inode->i_sem down
3581 +mini_fo_listxattr(struct dentry *dentry, char *list, size_t size) {
3582 + struct dentry *hidden_dentry = NULL;
3583 + int err = -EOPNOTSUPP;
3584 + char *encoded_list = NULL;
3586 + check_mini_fo_dentry(dentry);
3588 + if(exists_in_storage(dentry))
3589 + hidden_dentry = dtohd2(dentry);
3591 + hidden_dentry = dtohd(dentry);
3593 + ASSERT(hidden_dentry);
3594 + ASSERT(hidden_dentry->d_inode);
3595 + ASSERT(hidden_dentry->d_inode->i_op);
3597 + if (hidden_dentry->d_inode->i_op->listxattr) {
3598 + encoded_list = list;
3600 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
3601 + mutex_lock(&hidden_dentry->d_inode->i_mutex);
3603 + down(&hidden_dentry->d_inode->i_sem);
3605 + /* lock_kernel() already done by caller. */
3606 + err = hidden_dentry->d_inode->i_op->listxattr(hidden_dentry, encoded_list, size);
3607 + /* unlock_kernel() will be done by caller. */
3608 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
3609 + mutex_unlock(&hidden_dentry->d_inode->i_mutex);
3611 + up(&hidden_dentry->d_inode->i_sem);
3616 +# endif /* defined(XATTR) && (LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,20)) */
3618 +struct inode_operations mini_fo_symlink_iops =
3620 + readlink: mini_fo_readlink,
3621 + follow_link: mini_fo_follow_link,
3622 + /* mk: permission: mini_fo_permission, */
3623 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
3624 + revalidate: mini_fo_inode_revalidate,
3626 + setattr: mini_fo_setattr,
3627 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
3628 + getattr: mini_fo_getattr,
3629 + put_link: mini_fo_put_link,
3632 +#if defined(XATTR) && (LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,20))
3633 + setxattr: mini_fo_setxattr,
3634 + getxattr: mini_fo_getxattr,
3635 + listxattr: mini_fo_listxattr,
3636 + removexattr: mini_fo_removexattr
3637 +# endif /* defined(XATTR) && (LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,20)) */
3640 +struct inode_operations mini_fo_dir_iops =
3642 + create: mini_fo_create,
3643 + lookup: mini_fo_lookup,
3644 + link: mini_fo_link,
3645 + unlink: mini_fo_unlink,
3646 + symlink: mini_fo_symlink,
3647 + mkdir: mini_fo_mkdir,
3648 + rmdir: mini_fo_rmdir,
3649 + mknod: mini_fo_mknod,
3650 + rename: mini_fo_rename,
3651 + /* no readlink/follow_link for non-symlinks */
3652 + // off because we have setattr
3653 + // truncate: mini_fo_truncate,
3654 + /* mk:permission: mini_fo_permission, */
3655 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
3656 + revalidate: mini_fo_inode_revalidate,
3658 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
3659 + getattr: mini_fo_getattr,
3661 + setattr: mini_fo_setattr,
3662 +#if defined(XATTR) && (LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,20))
3663 + setxattr: mini_fo_setxattr,
3664 + getxattr: mini_fo_getxattr,
3665 + listxattr: mini_fo_listxattr,
3666 + removexattr: mini_fo_removexattr
3667 +# endif /* XATTR && LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,20) */
3670 +struct inode_operations mini_fo_main_iops =
3672 + /* permission: mini_fo_permission, */
3673 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
3674 + revalidate: mini_fo_inode_revalidate,
3676 + setattr: mini_fo_setattr,
3678 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
3679 + getattr: mini_fo_getattr,
3681 +#if defined(XATTR) && (LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,20))
3682 + setxattr: mini_fo_setxattr,
3683 + getxattr: mini_fo_getxattr,
3684 + listxattr: mini_fo_listxattr,
3685 + removexattr: mini_fo_removexattr
3686 +# endif /* XATTR && LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,20) */
3688 Index: linux-2.6.25.4/fs/mini_fo/main.c
3689 ===================================================================
3691 +++ linux-2.6.25.4/fs/mini_fo/main.c
3694 + * Copyright (c) 1997-2003 Erez Zadok
3695 + * Copyright (c) 2001-2003 Stony Brook University
3697 + * For specific licensing information, see the COPYING file distributed with
3698 + * this package, or get one from ftp://ftp.filesystems.org/pub/fist/COPYING.
3700 + * This Copyright notice must be kept intact and distributed with all
3701 + * fistgen sources INCLUDING sources generated by fistgen.
3704 + * Copyright (C) 2004, 2005 Markus Klotzbuecher <mk@creamnet.de>
3706 + * This program is free software; you can redistribute it and/or
3707 + * modify it under the terms of the GNU General Public License
3708 + * as published by the Free Software Foundation; either version
3709 + * 2 of the License, or (at your option) any later version.
3716 +#ifdef HAVE_CONFIG_H
3717 +# include <config.h>
3721 +#include "mini_fo.h"
3722 +#include <linux/module.h>
3724 +/* This definition must only appear after we include <linux/module.h> */
3725 +#ifndef MODULE_LICENSE
3726 +# define MODULE_LICENSE(bison)
3727 +#endif /* not MODULE_LICENSE */
3730 + * This is the mini_fo tri interpose function, which extends the
3731 + * functionality of the regular interpose by interposing a higher
3732 + * level inode on top of two lower level ones: the base filesystem
3733 + * inode and the storage filesystem inode.
3735 + * sb we pass is mini_fo's super_block
3738 +mini_fo_tri_interpose(dentry_t *hidden_dentry,
3739 + dentry_t *hidden_sto_dentry,
3740 + dentry_t *dentry, super_block_t *sb, int flag)
3742 + inode_t *hidden_inode = NULL;
3743 + inode_t *hidden_sto_inode = NULL; /* store corresponding storage inode */
3747 + /* Pointer to hidden_sto_inode if exists, else to hidden_inode.
3748 + * This is used to copy the attributes of the correct inode. */
3749 + inode_t *master_inode;
3752 + hidden_inode = hidden_dentry->d_inode;
3753 + if(hidden_sto_dentry)
3754 + hidden_sto_inode = hidden_sto_dentry->d_inode;
3756 + ASSERT(dentry->d_inode == NULL);
3758 + /* mk: One of the inodes associated with the dentrys is likely to
3759 + * be NULL, so carefull:
3761 + ASSERT((hidden_inode != NULL) || (hidden_sto_inode != NULL));
3763 + if(hidden_sto_inode)
3764 + master_inode = hidden_sto_inode;
3766 + master_inode = hidden_inode;
3769 + * We allocate our new inode below, by calling iget.
3770 + * iget will call our read_inode which will initialize some
3771 + * of the new inode's fields
3775 + * original: inode = iget(sb, hidden_inode->i_ino);
3777 + inode = iget(sb, iunique(sb, 25));
3779 + err = -EACCES; /* should be impossible??? */
3784 + * interpose the inode if not already interposed
3785 + * this is possible if the inode is being reused
3786 + * XXX: what happens if we get_empty_inode() but there's another already?
3787 + * for now, ASSERT() that this can't happen; fix later.
3789 + if (itohi(inode) != NULL) {
3790 + printk(KERN_CRIT "mini_fo_tri_interpose: itohi(inode) != NULL.\n");
3792 + if (itohi2(inode) != NULL) {
3793 + printk(KERN_CRIT "mini_fo_tri_interpose: itohi2(inode) != NULL.\n");
3796 + /* mk: Carefull, igrab can't handle NULL inodes (ok, why should it?), so
3797 + * we need to check here:
3800 + itohi(inode) = igrab(hidden_inode);
3802 + itohi(inode) = NULL;
3804 + if(hidden_sto_inode)
3805 + itohi2(inode) = igrab(hidden_sto_inode);
3807 + itohi2(inode) = NULL;
3810 + /* Use different set of inode ops for symlinks & directories*/
3811 + if (S_ISLNK(master_inode->i_mode))
3812 + inode->i_op = &mini_fo_symlink_iops;
3813 + else if (S_ISDIR(master_inode->i_mode))
3814 + inode->i_op = &mini_fo_dir_iops;
3816 + /* Use different set of file ops for directories */
3817 + if (S_ISDIR(master_inode->i_mode))
3818 + inode->i_fop = &mini_fo_dir_fops;
3820 + /* properly initialize special inodes */
3821 + if (S_ISBLK(master_inode->i_mode) || S_ISCHR(master_inode->i_mode) ||
3822 + S_ISFIFO(master_inode->i_mode) || S_ISSOCK(master_inode->i_mode)) {
3823 + init_special_inode(inode, master_inode->i_mode, master_inode->i_rdev);
3826 + /* Fix our inode's address operations to that of the lower inode */
3827 + if (inode->i_mapping->a_ops != master_inode->i_mapping->a_ops) {
3828 + inode->i_mapping->a_ops = master_inode->i_mapping->a_ops;
3831 + /* only (our) lookup wants to do a d_add */
3833 + d_add(dentry, inode);
3835 + d_instantiate(dentry, inode);
3837 + ASSERT(dtopd(dentry) != NULL);
3839 + /* all well, copy inode attributes */
3840 + fist_copy_attr_all(inode, master_inode);
3846 +/* parse mount options "base=" and "sto=" */
3848 +mini_fo_parse_options(super_block_t *sb, char *options)
3850 + dentry_t *hidden_root = ERR_PTR(-EINVAL);
3851 + dentry_t *hidden_root2 = ERR_PTR(-EINVAL);
3852 + struct nameidata nd, nd2;
3853 + char *name, *tmp, *end;
3856 + /* We don't want to go off the end of our arguments later on. */
3857 + for (end = options; *end; end++);
3859 + while (options < end) {
3861 + while (*tmp && *tmp != ',')
3864 + if (!strncmp("base=", options, 5)) {
3865 + name = options + 5;
3866 + printk(KERN_INFO "mini_fo: using base directory: %s\n", name);
3868 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
3869 + if (path_init(name, LOOKUP_FOLLOW, &nd))
3870 + err = path_walk(name, &nd);
3872 + err = path_lookup(name, LOOKUP_FOLLOW, &nd);
3875 + printk(KERN_CRIT "mini_fo: error accessing hidden directory '%s'\n", name);
3876 + hidden_root = ERR_PTR(err);
3879 + hidden_root = nd.dentry;
3880 + stopd(sb)->base_dir_dentry = nd.dentry;
3881 + stopd(sb)->hidden_mnt = nd.mnt;
3883 + } else if(!strncmp("sto=", options, 4)) {
3884 + /* parse the storage dir */
3885 + name = options + 4;
3886 + printk(KERN_INFO "mini_fo: using storage directory: %s\n", name);
3887 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
3888 + if(path_init(name, LOOKUP_FOLLOW, &nd2))
3889 + err = path_walk(name, &nd2);
3891 + err = path_lookup(name, LOOKUP_FOLLOW, &nd2);
3894 + printk(KERN_CRIT "mini_fo: error accessing hidden storage directory '%s'\n", name);
3896 + hidden_root2 = ERR_PTR(err);
3899 + hidden_root2 = nd2.dentry;
3900 + stopd(sb)->storage_dir_dentry = nd2.dentry;
3901 + stopd(sb)->hidden_mnt2 = nd2.mnt;
3902 + stohs2(sb) = hidden_root2->d_sb;
3904 + /* validate storage dir, this is done in
3905 + * mini_fo_read_super for the base directory.
3907 + if (IS_ERR(hidden_root2)) {
3908 + printk(KERN_WARNING "mini_fo_parse_options: storage dentry lookup failed (err = %ld)\n", PTR_ERR(hidden_root2));
3911 + if (!hidden_root2->d_inode) {
3912 + printk(KERN_WARNING "mini_fo_parse_options: no storage dir to interpose on.\n");
3915 + stohs2(sb) = hidden_root2->d_sb;
3917 + printk(KERN_WARNING "mini_fo: unrecognized option '%s'\n", options);
3918 + hidden_root = ERR_PTR(-EINVAL);
3921 + options = tmp + 1;
3925 + if(IS_ERR(hidden_root2))
3926 + return hidden_root2;
3927 + return hidden_root;
3931 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
3936 +mini_fo_read_super(super_block_t *sb, void *raw_data, int silent)
3938 + dentry_t *hidden_root;
3942 + printk(KERN_WARNING "mini_fo_read_super: missing argument\n");
3947 + * Allocate superblock private data
3949 + __stopd(sb) = kmalloc(sizeof(struct mini_fo_sb_info), GFP_KERNEL);
3951 + printk(KERN_WARNING "%s: out of memory\n", __FUNCTION__);
3957 + hidden_root = mini_fo_parse_options(sb, raw_data);
3958 + if (IS_ERR(hidden_root)) {
3959 + printk(KERN_WARNING "mini_fo_read_super: lookup_dentry failed (err = %ld)\n", PTR_ERR(hidden_root));
3960 + err = PTR_ERR(hidden_root);
3963 + if (!hidden_root->d_inode) {
3964 + printk(KERN_WARNING "mini_fo_read_super: no directory to interpose on\n");
3967 + stohs(sb) = hidden_root->d_sb;
3970 + * Linux 2.4.2-ac3 and beyond has code in
3971 + * mm/filemap.c:generic_file_write() that requires sb->s_maxbytes
3972 + * to be populated. If not set, all write()s under that sb will
3975 + * Linux 2.4.4+ automatically sets s_maxbytes to MAX_NON_LFS;
3976 + * the filesystem should override it only if it supports LFS.
3978 + /* non-SCA code is good to go with LFS */
3979 + sb->s_maxbytes = hidden_root->d_sb->s_maxbytes;
3981 + sb->s_op = &mini_fo_sops;
3983 + * we can't use d_alloc_root if we want to use
3984 + * our own interpose function unchanged,
3985 + * so we simply replicate *most* of the code in d_alloc_root here
3987 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
3988 + sb->s_root = d_alloc(NULL, &(const struct qstr) { "/", 1, 0 });
3990 + sb->s_root = d_alloc(NULL, &(const struct qstr){hash: 0, name: "/", len : 1});
3992 + if (IS_ERR(sb->s_root)) {
3993 + printk(KERN_WARNING "mini_fo_read_super: d_alloc failed\n");
3998 + sb->s_root->d_op = &mini_fo_dops;
3999 + sb->s_root->d_sb = sb;
4000 + sb->s_root->d_parent = sb->s_root;
4002 + /* link the upper and lower dentries */
4003 + __dtopd(sb->s_root) = (struct mini_fo_dentry_info *)
4004 + kmalloc(sizeof(struct mini_fo_dentry_info), GFP_KERNEL);
4005 + if (!dtopd(sb->s_root)) {
4009 + dtopd(sb->s_root)->state = MODIFIED;
4010 + dtohd(sb->s_root) = hidden_root;
4012 + /* fanout relevant, interpose on storage root dentry too */
4013 + dtohd2(sb->s_root) = stopd(sb)->storage_dir_dentry;
4015 + /* ...and call tri-interpose to interpose root dir inodes
4016 + * if (mini_fo_interpose(hidden_root, sb->s_root, sb, 0))
4018 + if(mini_fo_tri_interpose(hidden_root, dtohd2(sb->s_root), sb->s_root, sb, 0))
4021 + /* initalize the wol list */
4022 + itopd(sb->s_root->d_inode)->deleted_list_size = -1;
4023 + itopd(sb->s_root->d_inode)->renamed_list_size = -1;
4024 + meta_build_lists(sb->s_root);
4031 + dput(hidden_root);
4032 + dput(dtohd2(sb->s_root)); /* release the hidden_sto_dentry too */
4035 + __stopd(sb) = NULL;
4038 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
4042 + return ERR_PTR(err);
4049 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
4050 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,18)
4051 +static int mini_fo_get_sb(struct file_system_type *fs_type,
4052 + int flags, const char *dev_name,
4053 + void *raw_data, struct vfsmount *mnt)
4055 + return get_sb_nodev(fs_type, flags, raw_data, mini_fo_read_super, mnt);
4058 +static struct super_block *mini_fo_get_sb(struct file_system_type *fs_type,
4059 + int flags, const char *dev_name,
4062 + return get_sb_nodev(fs_type, flags, raw_data, mini_fo_read_super);
4066 +void mini_fo_kill_block_super(struct super_block *sb)
4068 + generic_shutdown_super(sb);
4070 + * XXX: BUG: Halcrow: Things get unstable sometime after this point:
4071 + * lib/rwsem-spinlock.c:127: spin_is_locked on uninitialized
4072 + * fs/fs-writeback.c:402: spin_lock(fs/super.c:a0381828) already
4073 + * locked by fs/fs-writeback.c/402
4075 + * Apparently, someone's not releasing a lock on sb_lock...
4079 +static struct file_system_type mini_fo_fs_type = {
4080 + .owner = THIS_MODULE,
4081 + .name = "mini_fo",
4082 + .get_sb = mini_fo_get_sb,
4083 + .kill_sb = mini_fo_kill_block_super,
4089 +static DECLARE_FSTYPE(mini_fo_fs_type, "mini_fo", mini_fo_read_super, 0);
4092 +static int __init init_mini_fo_fs(void)
4094 + printk("Registering mini_fo version $Id$\n");
4095 + return register_filesystem(&mini_fo_fs_type);
4097 +static void __exit exit_mini_fo_fs(void)
4099 + printk("Unregistering mini_fo version $Id$\n");
4100 + unregister_filesystem(&mini_fo_fs_type);
4103 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
4107 +MODULE_AUTHOR("Erez Zadok <ezk@cs.sunysb.edu>");
4108 +MODULE_DESCRIPTION("FiST-generated mini_fo filesystem");
4109 +MODULE_LICENSE("GPL");
4111 +/* MODULE_PARM(fist_debug_var, "i"); */
4112 +/* MODULE_PARM_DESC(fist_debug_var, "Debug level"); */
4114 +module_init(init_mini_fo_fs)
4115 +module_exit(exit_mini_fo_fs)
4116 Index: linux-2.6.25.4/fs/mini_fo/Makefile
4117 ===================================================================
4119 +++ linux-2.6.25.4/fs/mini_fo/Makefile
4122 +# Makefile for mini_fo 2.4 and 2.6 Linux kernels
4124 +# Copyright (C) 2004, 2005 Markus Klotzbuecher <mk@creamnet.de>
4126 +# This program is free software; you can redistribute it and/or
4127 +# modify it under the terms of the GNU General Public License
4128 +# as published by the Free Software Foundation; either version
4129 +# 2 of the License, or (at your option) any later version.
4132 +obj-$(CONFIG_MINI_FO) := mini_fo.o
4133 +mini_fo-objs := meta.o dentry.o file.o inode.o main.o super.o state.o aux.o
4136 +${mini_fo-objs}: mini_fo.h fist.h
4138 Index: linux-2.6.25.4/fs/mini_fo/meta.c
4139 ===================================================================
4141 +++ linux-2.6.25.4/fs/mini_fo/meta.c
4144 + * Copyright (C) 2004, 2005 Markus Klotzbuecher <mk@creamnet.de>
4146 + * This program is free software; you can redistribute it and/or
4147 + * modify it under the terms of the GNU General Public License
4148 + * as published by the Free Software Foundation; either version
4149 + * 2 of the License, or (at your option) any later version.
4152 +#ifdef HAVE_CONFIG_H
4153 +# include <config.h>
4154 +#endif /* HAVE_CONFIG_H */
4156 +#include "mini_fo.h"
4158 +int meta_build_lists(dentry_t *dentry)
4160 + struct mini_fo_inode_info *inode_info;
4162 + dentry_t *meta_dentry = 0;
4163 + file_t *meta_file = 0;
4164 + mm_segment_t old_fs;
4168 + struct vfsmount *meta_mnt;
4171 + inode_info = itopd(dentry->d_inode);
4172 + if(!(inode_info->deleted_list_size == -1 &&
4173 + inode_info->renamed_list_size == -1)) {
4174 + printk(KERN_CRIT "mini_fo: meta_build_lists: \
4175 + Error, list(s) not virgin.\n");
4179 + /* init our meta lists */
4180 + INIT_LIST_HEAD(&inode_info->deleted_list);
4181 + inode_info->deleted_list_size = 0;
4183 + INIT_LIST_HEAD(&inode_info->renamed_list);
4184 + inode_info->renamed_list_size = 0;
4186 + /* might there be a META-file? */
4187 + if(dtohd2(dentry) && dtohd2(dentry)->d_inode) {
4188 + meta_dentry = lookup_one_len(META_FILENAME,
4190 + strlen(META_FILENAME));
4191 + if(!meta_dentry->d_inode) {
4192 + dput(meta_dentry);
4195 + /* $%& err, is this correct? */
4196 + meta_mnt = stopd(dentry->d_inode->i_sb)->hidden_mnt2;
4200 + /* open META-file for reading */
4201 + meta_file = dentry_open(meta_dentry, meta_mnt, 0x0);
4202 + if(!meta_file || IS_ERR(meta_file)) {
4203 + printk(KERN_CRIT "mini_fo: meta_build_lists: \
4204 + ERROR opening META file.\n");
4208 + /* check if fs supports reading */
4209 + if(!meta_file->f_op->read) {
4210 + printk(KERN_CRIT "mini_fo: meta_build_lists: \
4211 + ERROR, fs does not support reading.\n");
4212 + goto out_err_close;
4215 + /* allocate a page for transfering the data */
4216 + buf = (void *) __get_free_page(GFP_KERNEL);
4218 + printk(KERN_CRIT "mini_fo: meta_build_lists: \
4219 + ERROR, out of mem.\n");
4220 + goto out_err_close;
4222 + meta_file->f_pos = 0;
4223 + old_fs = get_fs();
4224 + set_fs(KERNEL_DS);
4227 + bytes = meta_file->f_op->read(meta_file, buf, PAGE_SIZE, &meta_file->f_pos);
4228 + if(bytes == PAGE_SIZE) {
4229 + /* trim a cut off filename and adjust f_pos to get it next time */
4230 + for(c = (char*) buf+PAGE_SIZE;
4232 + c--, bytes--, meta_file->f_pos--);
4234 + entry = (char *) buf;
4235 + while(entry < (char *) buf+bytes) {
4239 + int old_len, new_len;
4241 + /* len without '\n'*/
4242 + len = (int) (strchr(entry, '\n') - entry);
4245 + /* format: "D filename" */
4246 + meta_list_add_d_entry(dentry,
4251 + /* format: "R path/xy/dir newDir" */
4252 + old_path = entry+2;
4253 + dir_name = strchr(old_path, ' ') + 1;
4254 + old_len = dir_name - old_path - 1;
4255 + new_len = ((int) entry) + len - ((int ) dir_name);
4256 + meta_list_add_r_entry(dentry,
4263 + /* unknown entry type detected */
4269 + } while(meta_file->f_pos < meta_dentry->d_inode->i_size);
4271 + free_page((unsigned long) buf);
4281 + dput(meta_dentry);
4284 + return 1; /* check this!!! inode_info->wol_size; */
4287 +/* cleanups up all lists and free's the mem by dentry */
4288 +int meta_put_lists(dentry_t *dentry)
4290 + if(!dentry || !dentry->d_inode) {
4291 + printk("mini_fo: meta_put_lists: invalid dentry passed.\n");
4294 + return __meta_put_lists(dentry->d_inode);
4297 +/* cleanups up all lists and free's the mem by inode */
4298 +int __meta_put_lists(inode_t *inode)
4301 + if(!inode || !itopd(inode)) {
4302 + printk("mini_fo: __meta_put_lists: invalid inode passed.\n");
4305 + err = __meta_put_d_list(inode);
4306 + err |= __meta_put_r_list(inode);
4310 +int meta_sync_lists(dentry_t *dentry)
4313 + if(!dentry || !dentry->d_inode) {
4314 + printk("mini_fo: meta_sync_lists: \
4315 + invalid dentry passed.\n");
4318 + err = meta_sync_d_list(dentry, 0);
4319 + err |= meta_sync_r_list(dentry, 1);
4324 +/* remove all D entries from the renamed list and free the mem */
4325 +int __meta_put_d_list(inode_t *inode)
4327 + struct list_head *tmp;
4328 + struct deleted_entry *del_entry;
4329 + struct mini_fo_inode_info *inode_info;
4331 + if(!inode || !itopd(inode)) {
4332 + printk(KERN_CRIT "mini_fo: __meta_put_d_list: \
4333 + invalid inode passed.\n");
4336 + inode_info = itopd(inode);
4338 + /* nuke the DELETED-list */
4339 + if(inode_info->deleted_list_size <= 0)
4342 + while(!list_empty(&inode_info->deleted_list)) {
4343 + tmp = inode_info->deleted_list.next;
4345 + del_entry = list_entry(tmp, struct deleted_entry, list);
4346 + kfree(del_entry->name);
4349 + inode_info->deleted_list_size = 0;
4354 +/* remove all R entries from the renamed list and free the mem */
4355 +int __meta_put_r_list(inode_t *inode)
4357 + struct list_head *tmp;
4358 + struct renamed_entry *ren_entry;
4359 + struct mini_fo_inode_info *inode_info;
4361 + if(!inode || !itopd(inode)) {
4362 + printk(KERN_CRIT "mini_fo: meta_put_r_list: invalid inode.\n");
4365 + inode_info = itopd(inode);
4367 + /* nuke the RENAMED-list */
4368 + if(inode_info->renamed_list_size <= 0)
4371 + while(!list_empty(&inode_info->renamed_list)) {
4372 + tmp = inode_info->renamed_list.next;
4374 + ren_entry = list_entry(tmp, struct renamed_entry, list);
4375 + kfree(ren_entry->new_name);
4376 + kfree(ren_entry->old_name);
4379 + inode_info->renamed_list_size = 0;
4384 +int meta_add_d_entry(dentry_t *dentry, const char *name, int len)
4387 + err = meta_list_add_d_entry(dentry, name, len);
4388 + err |= meta_write_d_entry(dentry,name,len);
4392 +/* add a D entry to the deleted list */
4393 +int meta_list_add_d_entry(dentry_t *dentry, const char *name, int len)
4395 + struct deleted_entry *del_entry;
4396 + struct mini_fo_inode_info *inode_info;
4398 + if(!dentry || !dentry->d_inode) {
4399 + printk(KERN_CRIT "mini_fo: meta_list_add_d_entry: \
4400 + invalid dentry passed.\n");
4403 + inode_info = itopd(dentry->d_inode);
4405 + if(inode_info->deleted_list_size < 0)
4408 + del_entry = (struct deleted_entry *)
4409 + kmalloc(sizeof(struct deleted_entry), GFP_KERNEL);
4410 + del_entry->name = (char*) kmalloc(len, GFP_KERNEL);
4411 + if(!del_entry || !del_entry->name) {
4412 + printk(KERN_CRIT "mini_fo: meta_list_add_d_entry: \
4414 + kfree(del_entry->name);
4419 + strncpy(del_entry->name, name, len);
4420 + del_entry->len = len;
4422 + list_add(&del_entry->list, &inode_info->deleted_list);
4423 + inode_info->deleted_list_size++;
4427 +int meta_add_r_entry(dentry_t *dentry,
4428 + const char *old_name, int old_len,
4429 + const char *new_name, int new_len)
4432 + err = meta_list_add_r_entry(dentry,
4433 + old_name, old_len,
4434 + new_name, new_len);
4435 + err |= meta_write_r_entry(dentry,
4436 + old_name, old_len,
4437 + new_name, new_len);
4441 +/* add a R entry to the renamed list */
4442 +int meta_list_add_r_entry(dentry_t *dentry,
4443 + const char *old_name, int old_len,
4444 + const char *new_name, int new_len)
4446 + struct renamed_entry *ren_entry;
4447 + struct mini_fo_inode_info *inode_info;
4449 + if(!dentry || !dentry->d_inode) {
4450 + printk(KERN_CRIT "mini_fo: meta_list_add_r_entry: \
4451 + invalid dentry passed.\n");
4454 + inode_info = itopd(dentry->d_inode);
4456 + if(inode_info->renamed_list_size < 0)
4459 + ren_entry = (struct renamed_entry *)
4460 + kmalloc(sizeof(struct renamed_entry), GFP_KERNEL);
4461 + ren_entry->old_name = (char*) kmalloc(old_len, GFP_KERNEL);
4462 + ren_entry->new_name = (char*) kmalloc(new_len, GFP_KERNEL);
4464 + if(!ren_entry || !ren_entry->old_name || !ren_entry->new_name) {
4465 + printk(KERN_CRIT "mini_fo: meta_list_add_r_entry: \
4467 + kfree(ren_entry->new_name);
4468 + kfree(ren_entry->old_name);
4473 + strncpy(ren_entry->old_name, old_name, old_len);
4474 + ren_entry->old_len = old_len;
4475 + strncpy(ren_entry->new_name, new_name, new_len);
4476 + ren_entry->new_len = new_len;
4478 + list_add(&ren_entry->list, &inode_info->renamed_list);
4479 + inode_info->renamed_list_size++;
4484 +int meta_remove_r_entry(dentry_t *dentry, const char *name, int len)
4487 + if(!dentry || !dentry->d_inode) {
4489 + "mini_fo: meta_remove_r_entry: \
4490 + invalid dentry passed.\n");
4494 + err = meta_list_remove_r_entry(dentry, name, len);
4495 + err |= meta_sync_lists(dentry);
4499 +int meta_list_remove_r_entry(dentry_t *dentry, const char *name, int len)
4501 + if(!dentry || !dentry->d_inode) {
4503 + "mini_fo: meta_list_remove_r_entry: \
4504 + invalid dentry passed.\n");
4507 + return __meta_list_remove_r_entry(dentry->d_inode, name, len);
4510 +int __meta_list_remove_r_entry(inode_t *inode, const char *name, int len)
4512 + struct list_head *tmp;
4513 + struct renamed_entry *ren_entry;
4514 + struct mini_fo_inode_info *inode_info;
4516 + if(!inode || !itopd(inode))
4518 + "mini_fo: __meta_list_remove_r_entry: \
4519 + invalid inode passed.\n");
4520 + inode_info = itopd(inode);
4522 + if(inode_info->renamed_list_size < 0)
4524 + if(inode_info->renamed_list_size == 0)
4527 + list_for_each(tmp, &inode_info->renamed_list) {
4528 + ren_entry = list_entry(tmp, struct renamed_entry, list);
4529 + if(ren_entry->new_len != len)
4532 + if(!strncmp(ren_entry->new_name, name, len)) {
4534 + kfree(ren_entry->new_name);
4535 + kfree(ren_entry->old_name);
4537 + inode_info->renamed_list_size--;
4545 +/* append a single D entry to the meta file */
4546 +int meta_write_d_entry(dentry_t *dentry, const char *name, int len)
4548 + dentry_t *meta_dentry = 0;
4549 + file_t *meta_file = 0;
4550 + mm_segment_t old_fs;
4553 + struct vfsmount *meta_mnt = 0;
4558 + if(itopd(dentry->d_inode)->deleted_list_size < 0) {
4563 + if(dtopd(dentry)->state == UNMODIFIED) {
4564 + err = build_sto_structure(dentry->d_parent, dentry);
4566 + printk(KERN_CRIT "mini_fo: meta_write_d_entry: \
4567 + build_sto_structure failed.\n");
4571 + meta_dentry = lookup_one_len(META_FILENAME,
4572 + dtohd2(dentry), strlen (META_FILENAME));
4574 + /* We need to create a META-file */
4575 + if(!meta_dentry->d_inode) {
4576 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
4577 + vfs_create(dtohd2(dentry)->d_inode,
4579 + S_IRUSR | S_IWUSR,
4582 + vfs_create(dtohd2(dentry)->d_inode,
4584 + S_IRUSR | S_IWUSR);
4587 + /* open META-file for writing */
4588 + meta_file = dentry_open(meta_dentry, meta_mnt, 0x1);
4589 + if(!meta_file || IS_ERR(meta_file)) {
4590 + printk(KERN_CRIT "mini_fo: meta_write_d_entry: \
4591 + ERROR opening meta file.\n");
4592 + mntput(meta_mnt); /* $%& is this necessary? */
4593 + dput(meta_dentry);
4598 + /* check if fs supports writing */
4599 + if(!meta_file->f_op->write) {
4600 + printk(KERN_CRIT "mini_fo: meta_write_d_entry: \
4601 + ERROR, fs does not support writing.\n");
4602 + goto out_err_close;
4605 + meta_file->f_pos = meta_dentry->d_inode->i_size; /* append */
4606 + old_fs = get_fs();
4607 + set_fs(KERNEL_DS);
4609 + /* size: len for name, 1 for \n and 2 for "D " */
4610 + buf = (char *) kmalloc(len+3, GFP_KERNEL);
4612 + printk(KERN_CRIT "mini_fo: meta_write_d_entry: \
4619 + strncpy(buf+2, name, len);
4620 + buf[len+2] = '\n';
4621 + bytes = meta_file->f_op->write(meta_file, buf, len+3,
4622 + &meta_file->f_pos);
4623 + if(bytes != len+3) {
4624 + printk(KERN_CRIT "mini_fo: meta_write_d_entry: \
4625 + ERROR writing.\n");
4637 +/* append a single R entry to the meta file */
4638 +int meta_write_r_entry(dentry_t *dentry,
4639 + const char *old_name, int old_len,
4640 + const char *new_name, int new_len)
4642 + dentry_t *meta_dentry = 0;
4643 + file_t *meta_file = 0;
4644 + mm_segment_t old_fs;
4646 + int bytes, err, buf_len;
4647 + struct vfsmount *meta_mnt = 0;
4653 + if(itopd(dentry->d_inode)->renamed_list_size < 0) {
4658 + /* build the storage structure? */
4659 + if(dtopd(dentry)->state == UNMODIFIED) {
4660 + err = build_sto_structure(dentry->d_parent, dentry);
4662 + printk(KERN_CRIT "mini_fo: meta_write_r_entry: \
4663 + build_sto_structure failed.\n");
4667 + meta_dentry = lookup_one_len(META_FILENAME,
4669 + strlen (META_FILENAME));
4670 + if(!meta_dentry->d_inode) {
4671 + /* We need to create a META-file */
4672 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
4673 + vfs_create(dtohd2(dentry)->d_inode,
4674 + meta_dentry, S_IRUSR | S_IWUSR, NULL);
4676 + vfs_create(dtohd2(dentry)->d_inode,
4677 + meta_dentry, S_IRUSR | S_IWUSR);
4680 + /* open META-file for writing */
4681 + meta_file = dentry_open(meta_dentry, meta_mnt, 0x1);
4682 + if(!meta_file || IS_ERR(meta_file)) {
4683 + printk(KERN_CRIT "mini_fo: meta_write_r_entry: \
4684 + ERROR opening meta file.\n");
4686 + dput(meta_dentry);
4691 + /* check if fs supports writing */
4692 + if(!meta_file->f_op->write) {
4693 + printk(KERN_CRIT "mini_fo: meta_write_r_entry: \
4694 + ERROR, fs does not support writing.\n");
4695 + goto out_err_close;
4698 + meta_file->f_pos = meta_dentry->d_inode->i_size; /* append */
4699 + old_fs = get_fs();
4700 + set_fs(KERNEL_DS);
4702 + /* size: 2 for "R ", old_len+new_len for names, 1 blank+1 \n */
4703 + buf_len = old_len + new_len + 4;
4704 + buf = (char *) kmalloc(buf_len, GFP_KERNEL);
4706 + printk(KERN_CRIT "mini_fo: meta_write_r_entry: out of mem.\n");
4712 + strncpy(buf + 2, old_name, old_len);
4713 + buf[old_len + 2] = ' ';
4714 + strncpy(buf + old_len + 3, new_name, new_len);
4715 + buf[buf_len -1] = '\n';
4716 + bytes = meta_file->f_op->write(meta_file, buf, buf_len, &meta_file->f_pos);
4717 + if(bytes != buf_len) {
4718 + printk(KERN_CRIT "mini_fo: meta_write_r_entry: ERROR writing.\n");
4731 +/* sync D list to disk, append data if app_flag is 1 */
4732 +/* check the meta_mnt, which seems not to be used (properly) */
4734 +int meta_sync_d_list(dentry_t *dentry, int app_flag)
4736 + dentry_t *meta_dentry;
4737 + file_t *meta_file;
4738 + mm_segment_t old_fs;
4741 + struct vfsmount *meta_mnt;
4744 + struct list_head *tmp;
4745 + struct deleted_entry *del_entry;
4746 + struct mini_fo_inode_info *inode_info;
4752 + if(!dentry || !dentry->d_inode) {
4753 + printk(KERN_CRIT "mini_fo: meta_sync_d_list: \
4754 + invalid inode passed.\n");
4758 + inode_info = itopd(dentry->d_inode);
4760 + if(inode_info->deleted_list_size < 0) {
4765 + /* ok, there is something to sync */
4767 + /* build the storage structure? */
4768 + if(!dtohd2(dentry) && !itohi2(dentry->d_inode)) {
4769 + err = build_sto_structure(dentry->d_parent, dentry);
4771 + printk(KERN_CRIT "mini_fo: meta_sync_d_list: \
4772 + build_sto_structure failed.\n");
4776 + meta_dentry = lookup_one_len(META_FILENAME,
4778 + strlen(META_FILENAME));
4779 + if(!meta_dentry->d_inode) {
4780 + /* We need to create a META-file */
4781 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
4782 + vfs_create(dtohd2(dentry)->d_inode,
4783 + meta_dentry, S_IRUSR | S_IWUSR, NULL);
4785 + vfs_create(dtohd2(dentry)->d_inode,
4786 + meta_dentry, S_IRUSR | S_IWUSR);
4790 + /* need we truncate the meta file? */
4792 + struct iattr newattrs;
4793 + newattrs.ia_size = 0;
4794 + newattrs.ia_valid = ATTR_SIZE | ATTR_CTIME;
4796 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
4797 + mutex_lock(&meta_dentry->d_inode->i_mutex);
4799 + down(&meta_dentry->d_inode->i_sem);
4801 + err = notify_change(meta_dentry, &newattrs);
4803 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
4804 + mutex_unlock(&meta_dentry->d_inode->i_mutex);
4806 + up(&meta_dentry->d_inode->i_sem);
4809 + if(err || meta_dentry->d_inode->i_size != 0) {
4810 + printk(KERN_CRIT "mini_fo: meta_sync_d_list: \
4811 + ERROR truncating meta file.\n");
4812 + goto out_err_close;
4816 + /* open META-file for writing */
4817 + meta_file = dentry_open(meta_dentry, meta_mnt, 0x1);
4818 + if(!meta_file || IS_ERR(meta_file)) {
4819 + printk(KERN_CRIT "mini_fo: meta_sync_d_list: \
4820 + ERROR opening meta file.\n");
4821 + /* we don't mntget so we dont't mntput (for now)
4822 + * mntput(meta_mnt);
4824 + dput(meta_dentry);
4829 + /* check if fs supports writing */
4830 + if(!meta_file->f_op->write) {
4831 + printk(KERN_CRIT "mini_fo: meta_sync_d_list: \
4832 + ERROR, fs does not support writing.\n");
4833 + goto out_err_close;
4836 + meta_file->f_pos = meta_dentry->d_inode->i_size; /* append */
4837 + old_fs = get_fs();
4838 + set_fs(KERNEL_DS);
4840 + /* here we go... */
4841 + list_for_each(tmp, &inode_info->deleted_list) {
4842 + del_entry = list_entry(tmp, struct deleted_entry, list);
4844 + /* size: len for name, 1 for \n and 2 for "D " */
4845 + buf = (char *) kmalloc(del_entry->len+3, GFP_KERNEL);
4847 + printk(KERN_CRIT "mini_fo: meta_sync_d_list: \
4854 + strncpy(buf+2, del_entry->name, del_entry->len);
4855 + buf[del_entry->len+2] = '\n';
4856 + bytes = meta_file->f_op->write(meta_file, buf,
4858 + &meta_file->f_pos);
4859 + if(bytes != del_entry->len+3) {
4860 + printk(KERN_CRIT "mini_fo: meta_sync_d_list: \
4861 + ERROR writing.\n");
4875 +int meta_sync_r_list(dentry_t *dentry, int app_flag)
4877 + dentry_t *meta_dentry;
4878 + file_t *meta_file;
4879 + mm_segment_t old_fs;
4881 + int bytes, err, buf_len;
4882 + struct vfsmount *meta_mnt;
4885 + struct list_head *tmp;
4886 + struct renamed_entry *ren_entry;
4887 + struct mini_fo_inode_info *inode_info;
4893 + if(!dentry || !dentry->d_inode) {
4894 + printk(KERN_CRIT "mini_fo: meta_sync_r_list: \
4895 + invalid dentry passed.\n");
4899 + inode_info = itopd(dentry->d_inode);
4901 + if(inode_info->deleted_list_size < 0) {
4906 + /* ok, there is something to sync */
4908 + /* build the storage structure? */
4909 + if(!dtohd2(dentry) && !itohi2(dentry->d_inode)) {
4910 + err = build_sto_structure(dentry->d_parent, dentry);
4912 + printk(KERN_CRIT "mini_fo: meta_sync_r_list: \
4913 + build_sto_structure failed.\n");
4917 + meta_dentry = lookup_one_len(META_FILENAME,
4919 + strlen(META_FILENAME));
4920 + if(!meta_dentry->d_inode) {
4921 + /* We need to create a META-file */
4922 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
4923 + vfs_create(dtohd2(dentry)->d_inode,
4924 + meta_dentry, S_IRUSR | S_IWUSR, NULL);
4926 + vfs_create(dtohd2(dentry)->d_inode,
4927 + meta_dentry, S_IRUSR | S_IWUSR);
4931 + /* need we truncate the meta file? */
4933 + struct iattr newattrs;
4934 + newattrs.ia_size = 0;
4935 + newattrs.ia_valid = ATTR_SIZE | ATTR_CTIME;
4937 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
4938 + mutex_lock(&meta_dentry->d_inode->i_mutex);
4940 + down(&meta_dentry->d_inode->i_sem);
4942 + err = notify_change(meta_dentry, &newattrs);
4944 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
4945 + mutex_unlock(&meta_dentry->d_inode->i_mutex);
4947 + up(&meta_dentry->d_inode->i_sem);
4949 + if(err || meta_dentry->d_inode->i_size != 0) {
4950 + printk(KERN_CRIT "mini_fo: meta_sync_r_list: \
4951 + ERROR truncating meta file.\n");
4952 + goto out_err_close;
4956 + /* open META-file for writing */
4957 + meta_file = dentry_open(meta_dentry, meta_mnt, 0x1);
4958 + if(!meta_file || IS_ERR(meta_file)) {
4959 + printk(KERN_CRIT "mini_fo: meta_sync_r_list: \
4960 + ERROR opening meta file.\n");
4961 + /* we don't mntget so we dont't mntput (for now)
4962 + * mntput(meta_mnt);
4964 + dput(meta_dentry);
4969 + /* check if fs supports writing */
4970 + if(!meta_file->f_op->write) {
4971 + printk(KERN_CRIT "mini_fo: meta_sync_r_list: \
4972 + ERROR, fs does not support writing.\n");
4973 + goto out_err_close;
4976 + meta_file->f_pos = meta_dentry->d_inode->i_size; /* append */
4977 + old_fs = get_fs();
4978 + set_fs(KERNEL_DS);
4980 + /* here we go... */
4981 + list_for_each(tmp, &inode_info->renamed_list) {
4982 + ren_entry = list_entry(tmp, struct renamed_entry, list);
4984 + * 2 for "R ", old_len+new_len for names, 1 blank+1 \n */
4985 + buf_len = ren_entry->old_len + ren_entry->new_len + 4;
4986 + buf = (char *) kmalloc(buf_len, GFP_KERNEL);
4988 + printk(KERN_CRIT "mini_fo: meta_sync_r_list: \
4994 + strncpy(buf + 2, ren_entry->old_name, ren_entry->old_len);
4995 + buf[ren_entry->old_len + 2] = ' ';
4996 + strncpy(buf + ren_entry->old_len + 3,
4997 + ren_entry->new_name, ren_entry->new_len);
4998 + buf[buf_len - 1] = '\n';
4999 + bytes = meta_file->f_op->write(meta_file, buf,
5000 + buf_len, &meta_file->f_pos);
5001 + if(bytes != buf_len) {
5002 + printk(KERN_CRIT "mini_fo: meta_sync_r_list: \
5003 + ERROR writing.\n");
5016 +int meta_check_d_entry(dentry_t *dentry, const char *name, int len)
5018 + if(!dentry || !dentry->d_inode)
5019 + printk(KERN_CRIT "mini_fo: meta_check_d_dentry: \
5020 + invalid dentry passed.\n");
5021 + return __meta_check_d_entry(dentry->d_inode, name, len);
5024 +int __meta_check_d_entry(inode_t *inode, const char *name, int len)
5026 + struct list_head *tmp;
5027 + struct deleted_entry *del_entry;
5028 + struct mini_fo_inode_info *inode_info;
5030 + if(!inode || !itopd(inode))
5031 + printk(KERN_CRIT "mini_fo: __meta_check_d_dentry: \
5032 + invalid inode passed.\n");
5034 + inode_info = itopd(inode);
5036 + if(inode_info->deleted_list_size <= 0)
5039 + list_for_each(tmp, &inode_info->deleted_list) {
5040 + del_entry = list_entry(tmp, struct deleted_entry, list);
5041 + if(del_entry->len != len)
5044 + if(!strncmp(del_entry->name, name, len))
5051 + * check if file has been renamed and return path to orig. base dir.
5052 + * Implements no error return values so far, what of course sucks.
5053 + * String is null terminated.'
5055 +char* meta_check_r_entry(dentry_t *dentry, const char *name, int len)
5057 + if(!dentry || !dentry->d_inode) {
5058 + printk(KERN_CRIT "mini_fo: meta_check_r_dentry: \
5059 + invalid dentry passed.\n");
5062 + return __meta_check_r_entry(dentry->d_inode, name, len);
5065 +char* __meta_check_r_entry(inode_t *inode, const char *name, int len)
5067 + struct list_head *tmp;
5068 + struct renamed_entry *ren_entry;
5069 + struct mini_fo_inode_info *inode_info;
5072 + if(!inode || !itopd(inode)) {
5073 + printk(KERN_CRIT "mini_fo: meta_check_r_dentry: \
5074 + invalid inode passed.\n");
5077 + inode_info = itopd(inode);
5079 + if(inode_info->renamed_list_size <= 0)
5082 + list_for_each(tmp, &inode_info->renamed_list) {
5083 + ren_entry = list_entry(tmp, struct renamed_entry, list);
5084 + if(ren_entry->new_len != len)
5087 + if(!strncmp(ren_entry->new_name, name, len)) {
5088 + old_path = (char *)
5089 + kmalloc(ren_entry->old_len+1, GFP_KERNEL);
5091 + ren_entry->old_name,
5092 + ren_entry->old_len);
5093 + old_path[ren_entry->old_len]='\0';
5101 + * This version only checks if entry exists and return:
5106 +int meta_is_r_entry(dentry_t *dentry, const char *name, int len)
5108 + if(!dentry || !dentry->d_inode) {
5109 + printk(KERN_CRIT "mini_fo: meta_check_r_dentry [2]: \
5110 + invalid dentry passed.\n");
5113 + return __meta_is_r_entry(dentry->d_inode, name, len);
5116 +int __meta_is_r_entry(inode_t *inode, const char *name, int len)
5118 + struct list_head *tmp;
5119 + struct renamed_entry *ren_entry;
5120 + struct mini_fo_inode_info *inode_info;
5122 + if(!inode || !itopd(inode)) {
5123 + printk(KERN_CRIT "mini_fo: meta_check_r_dentry [2]: \
5124 + invalid inode passed.\n");
5127 + inode_info = itopd(inode);
5129 + if(inode_info->renamed_list_size <= 0)
5132 + list_for_each(tmp, &inode_info->renamed_list) {
5133 + ren_entry = list_entry(tmp, struct renamed_entry, list);
5134 + if(ren_entry->new_len != len)
5137 + if(!strncmp(ren_entry->new_name, name, len))
5143 Index: linux-2.6.25.4/fs/mini_fo/mini_fo.h
5144 ===================================================================
5146 +++ linux-2.6.25.4/fs/mini_fo/mini_fo.h
5149 + * Copyright (c) 1997-2003 Erez Zadok
5150 + * Copyright (c) 2001-2003 Stony Brook University
5152 + * For specific licensing information, see the COPYING file distributed with
5153 + * this package, or get one from ftp://ftp.filesystems.org/pub/fist/COPYING.
5155 + * This Copyright notice must be kept intact and distributed with all
5156 + * fistgen sources INCLUDING sources generated by fistgen.
5159 + * Copyright (C) 2004, 2005 Markus Klotzbuecher <mk@creamnet.de>
5161 + * This program is free software; you can redistribute it and/or
5162 + * modify it under the terms of the GNU General Public License
5163 + * as published by the Free Software Foundation; either version
5164 + * 2 of the License, or (at your option) any later version.
5171 +#ifndef __MINI_FO_H_
5172 +#define __MINI_FO_H_
5177 +#define META_FILENAME "META_dAfFgHE39ktF3HD2sr"
5182 +/* File attributes that when changed, result in a file beeing copied to storage */
5183 +#define COPY_FLAGS ATTR_MODE | ATTR_UID | ATTR_GID | ATTR_SIZE
5186 + * mini_fo filestates
5189 +#define UNMODIFIED 2
5191 +#define DEL_REWRITTEN 4
5193 +#define NON_EXISTANT 6
5195 +/* fist file systems superblock magic */
5196 +# define MINI_FO_SUPER_MAGIC 0xf15f
5202 +/* mini_fo inode data in memory */
5203 +struct mini_fo_inode_info {
5204 + inode_t *wii_inode;
5205 + inode_t *wii_inode2; /* pointer to storage inode */
5207 + /* META-data lists */
5208 + /* deleted list, ex wol */
5209 + struct list_head deleted_list;
5210 + int deleted_list_size;
5212 + /* renamed list */
5213 + struct list_head renamed_list;
5214 + int renamed_list_size;
5216 + /* add other lists here ... */
5219 +/* mini_fo dentry data in memory */
5220 +struct mini_fo_dentry_info {
5221 + dentry_t *wdi_dentry;
5222 + dentry_t *wdi_dentry2; /* pointer to storage dentry */
5223 + unsigned int state; /* state of the mini_fo dentry */
5227 +/* mini_fo super-block data in memory */
5228 +struct mini_fo_sb_info {
5229 + super_block_t *wsi_sb, *wsi_sb2; /* mk: might point to the same sb */
5230 + struct vfsmount *hidden_mnt, *hidden_mnt2;
5231 + dentry_t *base_dir_dentry;
5232 + dentry_t *storage_dir_dentry;
5236 +/* readdir_data, readdir helper struct */
5237 +struct readdir_data {
5238 + struct list_head ndl_list; /* linked list head ptr */
5239 + int ndl_size; /* list size */
5240 + int sto_done; /* flag to show that the storage dir entries have
5241 + * all been read an now follow base entries */
5244 +/* file private data. */
5245 +struct mini_fo_file_info {
5246 + struct file *wfi_file;
5247 + struct file *wfi_file2; /* pointer to storage file */
5248 + struct readdir_data rd;
5251 +/* struct ndl_entry */
5253 + struct list_head list;
5258 +/********************************
5259 + * META-data structures
5260 + ********************************/
5262 +/* deleted entry */
5263 +struct deleted_entry {
5264 + struct list_head list;
5269 +/* renamed entry */
5270 +struct renamed_entry {
5271 + struct list_head list;
5272 + char *old_name; /* old directory with full path */
5273 + int old_len; /* length of above string */
5274 + char *new_name; /* new directory name */
5275 + int new_len; /* length of above string */
5278 +/* attr_change entry */
5279 +struct attr_change_entry {
5280 + struct list_head list;
5286 +struct link_entry {
5287 + struct list_head list;
5292 + int weird_name_len;
5296 +/* Some other stuff required for mini_fo_filldir64, copied from
5300 +#define ROUND_UP64(x) (((x)+sizeof(u64)-1) & ~(sizeof(u64)-1))
5301 +#define NAME_OFFSET(de) ((int) ((de)->d_name - (char *) (de)))
5304 +struct linux_dirent64 {
5307 + unsigned short d_reclen;
5308 + unsigned char d_type;
5313 +struct getdents_callback64 {
5314 + struct linux_dirent64 * current_dir;
5315 + struct linux_dirent64 * previous;
5320 +struct linux_dirent {
5321 + unsigned long d_ino;
5322 + unsigned long d_off;
5323 + unsigned short d_reclen;
5327 +struct getdents_callback {
5328 + struct linux_dirent * current_dir;
5329 + struct linux_dirent * previous;
5339 +/* file TO private_data */
5340 +# define ftopd(file) ((struct mini_fo_file_info *)((file)->private_data))
5341 +# define __ftopd(file) ((file)->private_data)
5342 +/* file TO hidden_file */
5343 +# define ftohf(file) ((ftopd(file))->wfi_file)
5344 +# define ftohf2(file) ((ftopd(file))->wfi_file2)
5346 +/* inode TO private_data */
5347 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,18)
5348 +# define itopd(ino) ((struct mini_fo_inode_info *)(ino)->i_private)
5349 +# define __itopd(ino) ((ino)->i_private)
5351 +# define itopd(ino) ((struct mini_fo_inode_info *)(ino)->u.generic_ip)
5352 +# define __itopd(ino) ((ino)->u.generic_ip)
5354 +/* inode TO hidden_inode */
5355 +# define itohi(ino) (itopd(ino)->wii_inode)
5356 +# define itohi2(ino) (itopd(ino)->wii_inode2)
5358 +/* superblock TO private_data */
5359 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
5360 +# define stopd(super) ((struct mini_fo_sb_info *)(super)->s_fs_info)
5361 +# define __stopd(super) ((super)->s_fs_info)
5363 +# define stopd(super) ((struct mini_fo_sb_info *)(super)->u.generic_sbp)
5364 +# define __stopd(super) ((super)->u.generic_sbp)
5367 +/* unused? # define vfs2priv stopd */
5368 +/* superblock TO hidden_superblock */
5370 +# define stohs(super) (stopd(super)->wsi_sb)
5371 +# define stohs2(super) (stopd(super)->wsi_sb2)
5373 +/* dentry TO private_data */
5374 +# define dtopd(dentry) ((struct mini_fo_dentry_info *)(dentry)->d_fsdata)
5375 +# define __dtopd(dentry) ((dentry)->d_fsdata)
5376 +/* dentry TO hidden_dentry */
5377 +# define dtohd(dent) (dtopd(dent)->wdi_dentry)
5378 +# define dtohd2(dent) (dtopd(dent)->wdi_dentry2)
5380 +/* dentry to state */
5381 +# define dtost(dent) (dtopd(dent)->state)
5382 +# define sbt(sb) ((sb)->s_type->name)
5384 +#define IS_WRITE_FLAG(flag) (flag & (O_RDWR | O_WRONLY | O_APPEND))
5385 +#define IS_COPY_FLAG(flag) (flag & (COPY_FLAGS))
5387 +/* macros to simplify non-SCA code */
5388 +# define MALLOC_PAGE_POINTERS(hidden_pages, num_hidden_pages)
5389 +# define MALLOC_PAGEDATA_POINTERS(hidden_pages_data, num_hidden_pages)
5390 +# define FREE_PAGE_POINTERS(hidden_pages, num)
5391 +# define FREE_PAGEDATA_POINTERS(hidden_pages_data, num)
5392 +# define FOR_EACH_PAGE
5393 +# define CURRENT_HIDDEN_PAGE hidden_page
5394 +# define CURRENT_HIDDEN_PAGEDATA hidden_page_data
5395 +# define CURRENT_HIDDEN_PAGEINDEX page->index
5400 +extern struct file_operations mini_fo_main_fops;
5401 +extern struct file_operations mini_fo_dir_fops;
5402 +extern struct inode_operations mini_fo_main_iops;
5403 +extern struct inode_operations mini_fo_dir_iops;
5404 +extern struct inode_operations mini_fo_symlink_iops;
5405 +extern struct super_operations mini_fo_sops;
5406 +extern struct dentry_operations mini_fo_dops;
5407 +extern struct vm_operations_struct mini_fo_shared_vmops;
5408 +extern struct vm_operations_struct mini_fo_private_vmops;
5409 +extern struct address_space_operations mini_fo_aops;
5411 +#if 0 /* unused by mini_fo */
5412 +extern int mini_fo_interpose(dentry_t *hidden_dentry, dentry_t *this_dentry, super_block_t *sb, int flag);
5413 +#if defined(FIST_FILTER_DATA) || defined(FIST_FILTER_SCA)
5414 +extern page_t *mini_fo_get1page(file_t *file, int index);
5415 +extern int mini_fo_fill_zeros(file_t *file, page_t *page, unsigned from);
5416 +# endif /* FIST_FILTER_DATA || FIST_FILTER_SCA */
5419 +# define mini_fo_hidden_dentry(d) __mini_fo_hidden_dentry(__FILE__,__FUNCTION__,__LINE__,(d))
5420 +# define mini_fo_hidden_sto_dentry(d) __mini_fo_hidden_sto_dentry(__FILE__,__FUNCTION__,__LINE__,(d))
5422 +extern dentry_t *__mini_fo_hidden_dentry(char *file, char *func, int line, dentry_t *this_dentry);
5423 +extern dentry_t *__mini_fo_hidden_sto_dentry(char *file, char *func, int line, dentry_t *this_dentry);
5425 +extern int mini_fo_read_file(const char *filename, void *buf, int len);
5426 +extern int mini_fo_write_file(const char *filename, void *buf, int len);
5427 +extern dentry_t *fist_lookup(dentry_t *dir, const char *name, vnode_t **out, uid_t uid, gid_t gid);
5428 +#endif /* unused by mini_fo */
5430 +/* state transition functions */
5431 +extern int nondir_unmod_to_mod(dentry_t *dentry, int cp_flag);
5432 +extern int nondir_del_rew_to_del(dentry_t *dentry);
5433 +extern int nondir_creat_to_del(dentry_t *dentry);
5434 +extern int nondir_mod_to_del(dentry_t *dentry);
5435 +extern int nondir_unmod_to_del(dentry_t *dentry);
5437 +extern int dir_unmod_to_mod(dentry_t *dentry);
5439 +/* rename specials */
5440 +extern int rename_directory(inode_t *old_dir, dentry_t *old_dentry, inode_t *new_dir, dentry_t *new_dentry);
5441 +extern int rename_nondir(inode_t *old_dir, dentry_t *old_dentry, inode_t *new_dir, dentry_t *new_dentry);
5444 +extern int mini_fo_tri_interpose(dentry_t *hidden_dentry,
5445 + dentry_t *hidden_sto_dentry,
5447 + super_block_t *sb, int flag);
5449 +extern int mini_fo_cp_cont(dentry_t *tgt_dentry, struct vfsmount *tgt_mnt,
5450 + dentry_t *src_dentry, struct vfsmount *src_mnt);
5452 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
5453 +extern int mini_fo_create(inode_t *dir, dentry_t *dentry, int mode, struct nameidata *nd);
5455 +extern int create_sto_nod(dentry_t *dentry, int mode, dev_t dev);
5456 +extern int create_sto_reg_file(dentry_t *dentry, int mode, struct nameidata *nd);
5458 +extern int mini_fo_create(inode_t *dir, dentry_t *dentry, int mode);
5460 +extern int create_sto_nod(dentry_t *dentry, int mode, int dev);
5461 +extern int create_sto_reg_file(dentry_t *dentry, int mode);
5464 +extern int create_sto_dir(dentry_t *dentry, int mode);
5466 +extern int exists_in_storage(dentry_t *dentry);
5467 +extern int is_mini_fo_existant(dentry_t *dentry);
5468 +extern int get_neg_sto_dentry(dentry_t *dentry);
5469 +extern int build_sto_structure(dentry_t *dir, dentry_t *dentry);
5470 +extern int get_mini_fo_bpath(dentry_t *dentry, char **bpath, int *bpath_len);
5471 +extern dentry_t *bpath_walk(super_block_t *sb, char *bpath);
5472 +extern int bpath_put(dentry_t *dentry);
5474 +/* check_mini_fo types functions */
5475 +extern int check_mini_fo_dentry(dentry_t *dentry);
5476 +extern int check_mini_fo_file(file_t *file);
5477 +extern int check_mini_fo_inode(inode_t *inode);
5479 +/* General meta functions, can be called from outside of meta.c */
5480 +extern int meta_build_lists(dentry_t *dentry);
5481 +extern int meta_put_lists(dentry_t *dentry);
5482 +extern int __meta_put_lists(inode_t *inode);
5484 +extern int meta_add_d_entry(dentry_t *dentry, const char *name, int len);
5485 +extern int meta_add_r_entry(dentry_t *dentry,
5486 + const char *old_name, int old_len,
5487 + const char *new_name, int new_len);
5489 +extern int meta_remove_r_entry(dentry_t *dentry, const char *name, int len);
5491 +extern int meta_check_d_entry(dentry_t *dentry, const char *name, int len);
5492 +extern int __meta_check_d_entry(inode_t *inode, const char *name, int len);
5494 +extern char* meta_check_r_entry(dentry_t *dentry, const char *name, int len);
5495 +extern char* __meta_check_r_entry(inode_t *inode, const char *name, int len);
5496 +extern int meta_is_r_entry(dentry_t *dentry, const char *name, int len);
5497 +extern int __meta_is_r_entry(inode_t *inode, const char *name, int len);
5499 +/* Specific meta functions, should be called only inside meta.c */
5500 +extern int __meta_put_d_list(inode_t *inode);
5501 +extern int __meta_put_r_list(inode_t *inode);
5503 +extern int meta_list_add_d_entry(dentry_t *dentry,
5504 + const char *name, int len);
5505 +extern int meta_list_add_r_entry(dentry_t *dentry,
5506 + const char *old_name, int old_len,
5507 + const char *new_name, int new_len);
5509 +extern int meta_list_remove_r_entry(dentry_t *dentry,
5510 + const char *name, int len);
5512 +extern int __meta_list_remove_r_entry(inode_t *inode,
5513 + const char *name, int len);
5515 +extern int meta_write_d_entry(dentry_t *dentry, const char *name, int len);
5516 +extern int meta_write_r_entry(dentry_t *dentry,
5517 + const char *old_name, int old_len,
5518 + const char *new_name, int new_len);
5520 +extern int meta_sync_lists(dentry_t *dentry);
5521 +extern int meta_sync_d_list(dentry_t *dentry, int app_flag);
5522 +extern int meta_sync_r_list(dentry_t *dentry, int app_flag);
5525 +extern int ndl_add_entry(struct readdir_data *rd, const char *name, int len);
5526 +extern void ndl_put_list(struct readdir_data *rd);
5527 +extern int ndl_check_entry(struct readdir_data *rd,
5528 + const char *name, int len);
5531 +# define copy_inode_size(dst, src) \
5532 + dst->i_size = src->i_size; \
5533 + dst->i_blocks = src->i_blocks;
5536 +fist_copy_attr_atime(inode_t *dest, const inode_t *src)
5538 + ASSERT(dest != NULL);
5539 + ASSERT(src != NULL);
5540 + dest->i_atime = src->i_atime;
5543 +fist_copy_attr_times(inode_t *dest, const inode_t *src)
5545 + ASSERT(dest != NULL);
5546 + ASSERT(src != NULL);
5547 + dest->i_atime = src->i_atime;
5548 + dest->i_mtime = src->i_mtime;
5549 + dest->i_ctime = src->i_ctime;
5552 +fist_copy_attr_timesizes(inode_t *dest, const inode_t *src)
5554 + ASSERT(dest != NULL);
5555 + ASSERT(src != NULL);
5556 + dest->i_atime = src->i_atime;
5557 + dest->i_mtime = src->i_mtime;
5558 + dest->i_ctime = src->i_ctime;
5559 + copy_inode_size(dest, src);
5562 +fist_copy_attr_all(inode_t *dest, const inode_t *src)
5564 + ASSERT(dest != NULL);
5565 + ASSERT(src != NULL);
5566 + dest->i_mode = src->i_mode;
5567 + dest->i_nlink = src->i_nlink;
5568 + dest->i_uid = src->i_uid;
5569 + dest->i_gid = src->i_gid;
5570 + dest->i_rdev = src->i_rdev;
5571 + dest->i_atime = src->i_atime;
5572 + dest->i_mtime = src->i_mtime;
5573 + dest->i_ctime = src->i_ctime;
5574 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,19)
5575 + dest->i_blksize = src->i_blksize;
5577 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,12)
5578 + dest->i_blkbits = src->i_blkbits;
5579 +# endif /* linux 2.4.12 and newer */
5580 + copy_inode_size(dest, src);
5581 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
5582 + dest->i_attr_flags = src->i_attr_flags;
5584 + dest->i_flags = src->i_flags;
5588 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
5589 +/* copied from linux/fs.h */
5590 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
5591 +static inline void double_lock(struct dentry *d1, struct dentry *d2)
5593 + struct mutex *m1 = &d1->d_inode->i_mutex;
5594 + struct mutex *m2 = &d2->d_inode->i_mutex;
5596 + if ((unsigned long) m1 < (unsigned long) m2) {
5597 + struct mutex *tmp = m2;
5598 + m2 = m1; m1 = tmp;
5605 +static inline void double_unlock(struct dentry *d1, struct dentry *d2)
5607 + struct mutex *m1 = &d1->d_inode->i_mutex;
5608 + struct mutex *m2 = &d2->d_inode->i_mutex;
5617 +static inline void double_down(struct semaphore *s1, struct semaphore *s2)
5620 + if ((unsigned long) s1 < (unsigned long) s2) {
5621 + struct semaphore *tmp = s2;
5622 + s2 = s1; s1 = tmp;
5629 +static inline void double_up(struct semaphore *s1, struct semaphore *s2)
5636 +static inline void double_lock(struct dentry *d1, struct dentry *d2)
5638 + double_down(&d1->d_inode->i_sem, &d2->d_inode->i_sem);
5641 +static inline void double_unlock(struct dentry *d1, struct dentry *d2)
5643 + double_up(&d1->d_inode->i_sem,&d2->d_inode->i_sem);
5647 +#endif /* if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16) */
5648 +#endif /* if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0) */
5649 +#endif /* __KERNEL__ */
5652 + * Definitions for user and kernel code
5657 +#endif /* not __MINI_FO_H_ */
5658 Index: linux-2.6.25.4/fs/mini_fo/mini_fo-merge
5659 ===================================================================
5661 +++ linux-2.6.25.4/fs/mini_fo/mini_fo-merge
5665 +# Copyright (C) 2005 Markus Klotzbuecher <mk@creamnet.de>
5666 +# This program is free software; you can redistribute it and/or
5667 +# modify it under the terms of the GNU General Public License
5668 +# as published by the Free Software Foundation; either version
5669 +# 2 of the License, or (at your option) any later version.
5678 +META_NAME="META_dAfFgHE39ktF3HD2sr"
5679 +SKIP_DEL_LIST="skip-delete-list.mini_fo-merge"
5684 + if [ x$DRYRUN == "xset" ]; then
5685 + echo " would run: $COMMAND"
5686 + elif ! [ x$DRYRUN == "xset" ]; then
5687 + if [ x$VERBOSE == "xset" ]; then
5688 + echo " running: $COMMAND"
5698 +USAGE: $0 -b <base dir> -s <storage dir>
5701 +This script merges the contents of a mini_fo storage file system back
5702 +to the base file system.
5704 +!!! Warning: This will modify the base filesystem and can destroy data
5709 + the directory of the base file system.
5712 + the directory of the storage file system.
5714 + -d dry run, will not change anything and print the commands that
5715 + would be executed.
5717 + -t tmp dir for storing temporary file. default: $TMP
5719 + -v show what operations are performed.
5721 + -h displays this message.
5727 +while getopts hdvt:b:s: OPTS
5732 + v) VERBOSE="set";;
5733 + b) BASE="$OPTARG";;
5734 + s) STO="$OPTARG";;
5735 + t) TMP="$OPTARG";;
5741 +if [ "x$HELP" == "xset" ]; then
5746 +if ! [ -d "$BASE" ] || ! [ -d "$STO" ]; then
5747 + echo -e "$0:\n Error, -s and/or -b argument missing. type $0 -h for help."
5752 +pushd $STO; STO=`pwd`; popd
5753 +pushd $BASE; BASE=`pwd`; popd
5758 +###############################################################################
5762 +# storage dir: $STO
5763 +# meta filename: $META_NAME
5765 +# verbose: $VERBOSE
5767 +###############################################################################
5771 +rm $TMP/$SKIP_DEL_LIST
5773 +# first process all renamed dirs
5774 +echo "Merging renamed directories..."
5775 +pushd $STO &> /dev/null
5776 +find . -name $META_NAME -type f -print0 | xargs -0 -e grep -e '^R ' | tr -s ':R' ' ' | while read ENTRY; do
5777 + echo "entry: $ENTRY"
5778 + META_FILE=`echo $ENTRY | cut -d ' ' -f 1`
5779 + OLD_B_DIR=`echo $ENTRY | cut -d ' ' -f 2 | sed -e 's/\///'`
5780 + NEW_NAME=`echo $ENTRY | cut -d ' ' -f 3`
5781 + NEW_B_DIR=`echo $META_FILE | sed -e "s/$META_NAME/$NEW_NAME/" | sed -e 's/^\.\///'`
5782 + echo "META_FILE: $META_FILE"
5783 + echo "OLD_B_DIR: $OLD_B_DIR"
5784 + echo "NEW_NAME: $NEW_NAME"
5785 + echo "NEW_B_DIR: $NEW_B_DIR"
5787 + pushd $BASE &> /dev/null
5788 + # remove an existing dir in storage
5789 + COMMAND="rm -rf $NEW_B_DIR"; exec_command
5790 + COMMAND="cp -R $OLD_B_DIR $NEW_B_DIR"; exec_command
5794 + # remember this dir to exclude it from deleting later
5795 + echo $NEW_B_DIR >> $TMP/$SKIP_DEL_LIST
5798 +# delete all whiteouted files from base
5799 +echo -e "\nDeleting whiteout'ed files from base file system..."
5800 +find . -name $META_NAME -type f -print0 | xargs -0 -e grep -e '^D ' | sed -e 's/:D//' | while read ENTRY; do
5801 + META_FILE=`echo $ENTRY | cut -d ' ' -f 1`
5802 + DEL_NAME=`echo $ENTRY | cut -d ' ' -f 2`
5803 + DEL_FILE=`echo $META_FILE | sed -e "s/$META_NAME/$DEL_NAME/" | sed -e 's/^\.\///'`
5804 + grep -x $DEL_FILE $TMP/$SKIP_DEL_LIST &> /dev/null
5805 + if [ $? -ne 0 ]; then
5806 + pushd $BASE &> /dev/null
5807 + COMMAND="rm -rf $DEL_FILE"; exec_command
5810 + echo " excluding: $DEL_FILE as in skip-del-list."
5814 +# create all dirs and update permissions
5815 +echo -e "\nSetting up directory structures in base file system..."
5816 +find . -type d | sed -e 's/^\.\///' | while read DIR; do
5817 + PERMS=`stat -c %a $DIR`
5818 + DIR_UID=`stat -c %u $DIR`
5819 + DIR_GID=`stat -c %g $DIR`
5820 + pushd $BASE &> /dev/null
5821 + if ! [ -d $DIR ]; then
5822 + COMMAND="mkdir -p $DIR"; exec_command
5824 + COMMAND="chmod $PERMS $DIR"; exec_command
5825 + COMMAND="chown $DIR_UID:$DIR_GID $DIR"; exec_command
5829 +# merge all non-directory files
5830 +echo -e "\nMerging all non-directory files...."
5831 +for i in b c p f l s; do
5832 + find . -type $i | sed -e 's/^\.\///' | grep -v "$META_NAME" | while read FILE; do
5833 + pushd $BASE #&> /dev/null
5834 + COMMAND="cp -df $STO/$FILE $BASE/$FILE"; exec_command
5840 +#rm $TMP/$SKIP_DEL_LIST
5843 Index: linux-2.6.25.4/fs/mini_fo/mini_fo-overlay
5844 ===================================================================
5846 +++ linux-2.6.25.4/fs/mini_fo/mini_fo-overlay
5850 +# Copyright (C) 2005 Markus Klotzbuecher <mk@creamnet.de>
5851 +# This program is free software; you can redistribute it and/or
5852 +# modify it under the terms of the GNU General Public License
5853 +# as published by the Free Software Foundation; either version
5854 +# 2 of the License, or (at your option) any later version.
5869 +Usage: $0 [-s suffix] [-d sto_dir_dir] [-m mount point] base_dir
5872 +This script overlays the given base directory using the mini_fo file
5873 +system. If only the base directory base_dir is given, $0
5874 +will use a storage directory called "sto-<base_dir_name>" in $STO_DIR,
5875 +and mount point "mini_fo-<base_dir_dir>" in $MNT_DIR.
5879 + add given suffix to storage directory and the mount
5880 + point. This is usefull for overlaying one base directory
5881 + several times and avoiding conflicts with storage directory
5882 + names and mount points.
5885 + change the directory in which the storage directory will be
5886 + created (default is currently "$STO_DIR".
5889 + use an alternative directory to create the mini_fo
5890 + mountpoint (default is currently "$MNT_DIR".
5892 + -h displays this message.
5898 +while getopts hm:s:d: OPTS
5901 + s) SUFF="$OPTARG";;
5902 + d) STO_DIR="$OPTARG";;
5903 + m) MNT_DIR="$OPTARG";;
5909 +shift $(($OPTIND - 1))
5913 +if [ "x$HELP" == "xset" ]; then
5919 +if [ "x$SUFF" != "x" ]; then
5923 +# kill trailing slashes
5924 +MNT_DIR=${MNT_DIR%/}
5925 +STO_DIR=${STO_DIR%/}
5929 +if ! [ -d "$BASE" ]; then
5930 + echo "invalid base dir $BASE, run $0 -h for help."
5935 +if ! [ -d "$MNT_DIR" ]; then
5936 + echo "invalid mount dir $MNT_DIR, run $0 -h for help."
5940 +if ! [ -d "$STO_DIR" ]; then
5941 + echo "invalid sto_dir_dir $STO_DIR, run $0 -h for help."
5945 +MNTP="$MNT_DIR/mini_fo-`basename $BASE`$SUFF"
5946 +STO="$STO_DIR/sto-`basename $BASE`$SUFF"
5948 +# create the mount point if it doesn't exist
5950 +if [ $? -ne 0 ]; then
5951 + echo "Error, failed to create mount point $MNTP"
5955 +if [ $? -ne 0 ]; then
5956 + echo "Error, failed to create storage dir $STO"
5959 +# check if fs is already mounted
5960 +mount | grep mini_fo | grep $MNTP &> /dev/null
5961 +if [ $? -eq 0 ]; then
5962 + echo "Error, existing mini_fo mount at $MNTP."
5966 +mount | grep mini_fo | grep $STO &> /dev/null
5967 +if [ $? -eq 0 ]; then
5968 + echo "Error, $STO seems to be used already."
5973 +mount -t mini_fo -o base=$BASE,sto=$STO $BASE $MNTP
5975 +if [ $? -ne 0 ]; then
5976 + echo "Error, mounting failed, maybe no permisson to mount?"
5978 Index: linux-2.6.25.4/fs/mini_fo/mmap.c
5979 ===================================================================
5981 +++ linux-2.6.25.4/fs/mini_fo/mmap.c
5984 + * Copyright (c) 1997-2003 Erez Zadok
5985 + * Copyright (c) 2001-2003 Stony Brook University
5987 + * For specific licensing information, see the COPYING file distributed with
5988 + * this package, or get one from ftp://ftp.filesystems.org/pub/fist/COPYING.
5990 + * This Copyright notice must be kept intact and distributed with all
5991 + * fistgen sources INCLUDING sources generated by fistgen.
5994 + * Copyright (C) 2004, 2005 Markus Klotzbuecher <mk@creamnet.de>
5996 + * This program is free software; you can redistribute it and/or
5997 + * modify it under the terms of the GNU General Public License
5998 + * as published by the Free Software Foundation; either version
5999 + * 2 of the License, or (at your option) any later version.
6006 +#ifdef HAVE_CONFIG_H
6007 +# include <config.h>
6008 +#endif /* HAVE_CONFIG_H */
6011 +#include "mini_fo.h"
6014 +#ifdef FIST_COUNT_WRITES
6015 +/* for counting writes in the middle vs. regular writes */
6016 +unsigned long count_writes = 0, count_writes_middle = 0;
6017 +#endif /* FIST_COUNT_WRITES */
6019 +/* forward declaration of commit write and prepare write */
6020 +STATIC int mini_fo_commit_write(file_t *file, page_t *page, unsigned from, unsigned to);
6021 +STATIC int mini_fo_prepare_write(file_t *file, page_t *page, unsigned from, unsigned to);
6025 + * Function for handling creation of holes when lseek-ing past the
6026 + * end of the file and then writing some data.
6029 +mini_fo_fill_zeros(file_t* file, page_t *page, unsigned from)
6032 + dentry_t *dentry = file->f_dentry;
6033 + inode_t *inode = dentry->d_inode;
6037 + print_entry_location();
6039 + for (index = inode->i_size >> PAGE_CACHE_SHIFT; index < page->index; index++) {
6040 + tmp_page = mini_fo_get1page(file, index);
6041 + if (IS_ERR(tmp_page)) {
6042 + err = PTR_ERR(tmp_page);
6047 + * zero out rest of the contents of the page between the appropriate
6050 + memset((char*)page_address(tmp_page) + (inode->i_size & ~PAGE_CACHE_MASK), 0, PAGE_CACHE_SIZE - (inode->i_size & ~PAGE_CACHE_MASK));
6052 + if (! (err = mini_fo_prepare_write(file, tmp_page, 0, PAGE_CACHE_SIZE)))
6053 + err = mini_fo_commit_write(file, tmp_page, 0, PAGE_CACHE_SIZE);
6055 + page_cache_release(tmp_page);
6058 + if (current->need_resched)
6062 + /* zero out appropriate parts of last page */
6065 + * if the encoding type is block, then adjust the 'from' (where the
6066 + * zeroing will start) offset appropriately
6068 + from = from & (~(FIST_ENCODING_BLOCKSIZE - 1));
6070 + if ((from - (inode->i_size & ~PAGE_CACHE_MASK)) > 0) {
6072 + memset((char*)page_address(page) + (inode->i_size & ~PAGE_CACHE_MASK), 0, from - (inode->i_size & ~PAGE_CACHE_MASK));
6073 + if (! (err = mini_fo_prepare_write(file, page, 0, PAGE_CACHE_SIZE)))
6074 + err = mini_fo_commit_write(file, page, 0, PAGE_CACHE_SIZE);
6078 + if (current->need_resched)
6083 + print_exit_status(err);
6090 +mini_fo_writepage(page_t *page)
6094 + inode_t *hidden_inode;
6095 + page_t *hidden_page;
6096 + char *kaddr, *hidden_kaddr;
6098 + print_entry_location();
6100 + inode = page->mapping->host;
6101 + hidden_inode = itohi(inode);
6104 + * writepage is called when shared mmap'ed files need to write
6105 + * their pages, while prepare/commit_write are called from the
6106 + * non-paged write() interface. (However, in 2.3 the two interfaces
6107 + * share the same cache, while in 2.2 they didn't.)
6109 + * So we pretty much have to duplicate much of what commit_write does.
6112 + /* find lower page (returns a locked page) */
6113 + hidden_page = grab_cache_page(hidden_inode->i_mapping, page->index);
6117 + /* get page address, and encode it */
6118 + kaddr = (char *) kmap(page);
6119 + hidden_kaddr = (char*) kmap(hidden_page);
6120 + mini_fo_encode_block(kaddr, hidden_kaddr, PAGE_CACHE_SIZE, inode, inode->i_sb, page->index);
6121 + /* if encode_block could fail, then return error */
6123 + kunmap(hidden_page);
6125 + /* call lower writepage (expects locked page) */
6126 + err = hidden_inode->i_mapping->a_ops->writepage(hidden_page);
6129 + * update mtime and ctime of lower level file system
6130 + * mini_fo' mtime and ctime are updated by generic_file_write
6132 + hidden_inode->i_mtime = hidden_inode->i_ctime = CURRENT_TIME;
6134 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,4,1)
6135 + UnlockPage(hidden_page); /* b/c grab_cache_page locked it */
6136 +# endif /* kernel older than 2.4.1 */
6137 + page_cache_release(hidden_page); /* b/c grab_cache_page increased refcnt */
6140 + ClearPageUptodate(page);
6142 + SetPageUptodate(page);
6144 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,1)
6146 +# endif /* kernel 2.4.1 and newer */
6147 + print_exit_status(err);
6153 + * get one page from cache or lower f/s, return error otherwise.
6154 + * returns unlocked, up-to-date page (if ok), with increased refcnt.
6157 +mini_fo_get1page(file_t *file, int index)
6162 + struct address_space *mapping;
6165 + print_entry_location();
6167 + dentry = file->f_dentry; /* CPW: Moved below print_entry_location */
6168 + inode = dentry->d_inode;
6169 + mapping = inode->i_mapping;
6171 + fist_dprint(8, "%s: read page index %d pid %d\n", __FUNCTION__, index, current->pid);
6173 + printk("%s BUG: index=%d\n", __FUNCTION__, index);
6174 + page = ERR_PTR(-EIO);
6177 + page = read_cache_page(mapping,
6179 + (filler_t *) mapping->a_ops->readpage,
6183 + wait_on_page(page);
6184 + if (!Page_Uptodate(page)) {
6186 + err = mapping->a_ops->readpage(file, page);
6188 + page = ERR_PTR(err);
6191 + wait_on_page(page);
6192 + if (!Page_Uptodate(page)) {
6193 + page = ERR_PTR(-EIO);
6199 + print_exit_pointer(page);
6205 + * get one page from cache or lower f/s, return error otherwise.
6206 + * similar to get1page, but doesn't guarantee that it will return
6207 + * an unlocked page.
6210 +mini_fo_get1page_cached(file_t *file, int index)
6215 + struct address_space *mapping;
6218 + print_entry_location();
6220 + dentry = file->f_dentry; /* CPW: Moved below print_entry_location */
6221 + inode = dentry->d_inode;
6222 + mapping = inode->i_mapping;
6224 + fist_dprint(8, "%s: read page index %d pid %d\n", __FUNCTION__, index, current->pid);
6226 + printk("%s BUG: index=%d\n", __FUNCTION__, index);
6227 + page = ERR_PTR(-EIO);
6230 + page = read_cache_page(mapping,
6232 + (filler_t *) mapping->a_ops->readpage,
6238 + print_exit_pointer(page);
6244 + * readpage is called from generic_page_read and the fault handler.
6245 + * If your file system uses generic_page_read for the read op, it
6246 + * must implement readpage.
6248 + * Readpage expects a locked page, and must unlock it.
6251 +mini_fo_do_readpage(file_t *file, page_t *page)
6255 + file_t *hidden_file = NULL;
6256 + dentry_t *hidden_dentry;
6258 + inode_t *hidden_inode;
6260 + page_t *hidden_page;
6261 + char *hidden_page_data;
6264 + print_entry_location();
6266 + dentry = file->f_dentry; /* CPW: Moved below print_entry_location */
6267 + if (ftopd(file) != NULL)
6268 + hidden_file = ftohf(file);
6269 + hidden_dentry = dtohd(dentry);
6270 + inode = dentry->d_inode;
6271 + hidden_inode = itohi(inode);
6273 + fist_dprint(7, "%s: requesting page %d from file %s\n", __FUNCTION__, page->index, dentry->d_name.name);
6275 + MALLOC_PAGE_POINTERS(hidden_pages, num_hidden_pages);
6276 + MALLOC_PAGEDATA_POINTERS(hidden_pages_data, num_hidden_pages);
6278 + CURRENT_HIDDEN_PAGE = NULL;
6280 + /* find lower page (returns a locked page) */
6282 + fist_dprint(8, "%s: Current page index = %d\n", __FUNCTION__, CURRENT_HIDDEN_PAGEINDEX);
6283 + CURRENT_HIDDEN_PAGE = read_cache_page(hidden_inode->i_mapping,
6284 + CURRENT_HIDDEN_PAGEINDEX,
6285 + (filler_t *) hidden_inode->i_mapping->a_ops->readpage,
6286 + (void *) hidden_file);
6287 + if (IS_ERR(CURRENT_HIDDEN_PAGE)) {
6288 + err = PTR_ERR(CURRENT_HIDDEN_PAGE);
6289 + CURRENT_HIDDEN_PAGE = NULL;
6295 + * wait for the page data to show up
6296 + * (signaled by readpage as unlocking the page)
6299 + wait_on_page(CURRENT_HIDDEN_PAGE);
6300 + if (!Page_Uptodate(CURRENT_HIDDEN_PAGE)) {
6302 + * call readpage() again if we returned from wait_on_page with a
6303 + * page that's not up-to-date; that can happen when a partial
6304 + * page has a few buffers which are ok, but not the whole
6307 + lock_page(CURRENT_HIDDEN_PAGE);
6308 + err = hidden_inode->i_mapping->a_ops->readpage(hidden_file,
6309 + CURRENT_HIDDEN_PAGE);
6311 + CURRENT_HIDDEN_PAGE = NULL;
6314 + wait_on_page(CURRENT_HIDDEN_PAGE);
6315 + if (!Page_Uptodate(CURRENT_HIDDEN_PAGE)) {
6322 + /* map pages, get their addresses */
6323 + page_data = (char *) kmap(page);
6325 + CURRENT_HIDDEN_PAGEDATA = (char *) kmap(CURRENT_HIDDEN_PAGE);
6327 + /* if decode_block could fail, then return error */
6329 + real_size = hidden_inode->i_size - (page->index << PAGE_CACHE_SHIFT);
6330 + if (real_size <= 0)
6331 + memset(page_data, 0, PAGE_CACHE_SIZE);
6332 + else if (real_size < PAGE_CACHE_SIZE) {
6333 + mini_fo_decode_block(hidden_page_data, page_data, real_size, inode, inode->i_sb, page->index);
6334 + memset(page_data + real_size, 0, PAGE_CACHE_SIZE - real_size);
6336 + mini_fo_decode_block(hidden_page_data, page_data, PAGE_CACHE_SIZE, inode, inode->i_sb, page->index);
6339 + kunmap(CURRENT_HIDDEN_PAGE);
6344 + if (CURRENT_HIDDEN_PAGE)
6345 + page_cache_release(CURRENT_HIDDEN_PAGE); /* undo read_cache_page */
6347 + FREE_PAGE_POINTERS(hidden_pages, num_hidden_pages);
6348 + FREE_PAGEDATA_POINTERS(hidden_pages_data, num_hidden_pages);
6352 + SetPageUptodate(page);
6354 + ClearPageUptodate(page);
6356 + print_exit_status(err);
6362 +mini_fo_readpage(file_t *file, page_t *page)
6365 + print_entry_location();
6367 + err = mini_fo_do_readpage(file, page);
6370 + * we have to unlock our page, b/c we _might_ have gotten a locked page.
6371 + * but we no longer have to wakeup on our page here, b/c UnlockPage does
6376 + print_exit_status(err);
6382 +mini_fo_prepare_write(file_t *file, page_t *page, unsigned from, unsigned to)
6386 + print_entry_location();
6389 + * we call kmap(page) only here, and do the kunmap
6390 + * and the actual downcalls, including unlockpage and uncache
6391 + * in commit_write.
6395 + /* fast path for whole page writes */
6396 + if (from == 0 && to == PAGE_CACHE_SIZE)
6398 + /* read the page to "revalidate" our data */
6399 + /* call the helper function which doesn't unlock the page */
6400 + if (!Page_Uptodate(page))
6401 + err = mini_fo_do_readpage(file, page);
6404 + print_exit_status(err);
6411 +mini_fo_commit_write(file_t *file, page_t *page, unsigned from, unsigned to)
6413 + int err = -ENOMEM;
6415 + inode_t *hidden_inode;
6416 + page_t *hidden_page;
6417 + file_t *hidden_file = NULL;
6419 + unsigned bytes = to - from;
6420 + unsigned hidden_from, hidden_to, hidden_bytes;
6422 + print_entry_location();
6424 + inode = page->mapping->host; /* CPW: Moved below print_entry_location */
6425 + hidden_inode = itohi(inode);
6427 + ASSERT(file != NULL);
6429 + * here we have a kmapped page, with data from the user copied
6430 + * into it. we need to encode_block it, and then call the lower
6431 + * commit_write. We also need to simulate same behavior of
6432 + * generic_file_write, and call prepare_write on the lower f/s first.
6434 +#ifdef FIST_COUNT_WRITES
6436 +# endif /* FIST_COUNT_WRITES */
6438 + /* this is append and/or extend -- we can't have holes so fill them in */
6439 + if (page->index > (hidden_inode->i_size >> PAGE_CACHE_SHIFT)) {
6442 + for (index = hidden_inode->i_size >> PAGE_CACHE_SHIFT; index < page->index; index++) {
6443 + tmp_page = mini_fo_get1page(file, index);
6444 + if (IS_ERR(tmp_page)) {
6445 + err = PTR_ERR(tmp_page);
6448 + /* zero out the contents of the page at the appropriate offsets */
6449 + memset((char*)page_address(tmp_page) + (inode->i_size & ~PAGE_CACHE_MASK), 0, PAGE_CACHE_SIZE - (inode->i_size & ~PAGE_CACHE_MASK));
6450 + if (!(err = mini_fo_prepare_write(file, tmp_page, 0, PAGE_CACHE_SIZE)))
6451 + err = mini_fo_commit_write(file, tmp_page, 0, PAGE_CACHE_SIZE);
6452 + page_cache_release(tmp_page);
6455 + if (current->need_resched)
6460 + if (ftopd(file) != NULL)
6461 + hidden_file = ftohf(file);
6463 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
6464 + mutex_lock(&hidden_inode->i_mutex);
6466 + down(&hidden_inode->i_sem);
6468 + /* find lower page (returns a locked page) */
6469 + hidden_page = grab_cache_page(hidden_inode->i_mapping, page->index);
6473 +#if FIST_ENCODING_BLOCKSIZE > 1
6474 +# error encoding_blocksize greater than 1 is not yet supported
6475 +# endif /* FIST_ENCODING_BLOCKSIZE > 1 */
6477 + hidden_from = from & (~(FIST_ENCODING_BLOCKSIZE - 1));
6478 + hidden_to = ((to + FIST_ENCODING_BLOCKSIZE - 1) & (~(FIST_ENCODING_BLOCKSIZE - 1)));
6479 + if ((page->index << PAGE_CACHE_SHIFT) + to > hidden_inode->i_size) {
6482 + * if this call to commit_write had introduced holes and the code
6483 + * for handling holes was invoked, then the beginning of this page
6484 + * must be zeroed out
6485 + * zero out bytes from 'size_of_file%pagesize' to 'from'.
6487 + if ((hidden_from - (inode->i_size & ~PAGE_CACHE_MASK)) > 0)
6488 + memset((char*)page_address(page) + (inode->i_size & ~PAGE_CACHE_MASK), 0, hidden_from - (inode->i_size & ~PAGE_CACHE_MASK));
6491 + hidden_bytes = hidden_to - hidden_from;
6493 + /* call lower prepare_write */
6495 + if (hidden_inode->i_mapping &&
6496 + hidden_inode->i_mapping->a_ops &&
6497 + hidden_inode->i_mapping->a_ops->prepare_write)
6498 + err = hidden_inode->i_mapping->a_ops->prepare_write(hidden_file,
6503 + /* don't leave locked pages behind, esp. on an ENOSPC */
6506 + fist_dprint(8, "%s: encoding %d bytes\n", __FUNCTION__, hidden_bytes);
6507 + 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);
6508 + /* if encode_block could fail, then goto unlock and return error */
6510 + /* call lower commit_write */
6511 + err = hidden_inode->i_mapping->a_ops->commit_write(hidden_file,
6519 + err = bytes; /* convert error to no. of bytes */
6521 + inode->i_blocks = hidden_inode->i_blocks;
6522 + /* we may have to update i_size */
6523 + pos = (page->index << PAGE_CACHE_SHIFT) + to;
6524 + if (pos > inode->i_size)
6525 + inode->i_size = pos;
6528 + * update mtime and ctime of lower level file system
6529 + * mini_fo' mtime and ctime are updated by generic_file_write
6531 + hidden_inode->i_mtime = hidden_inode->i_ctime = CURRENT_TIME;
6533 + mark_inode_dirty_sync(inode);
6536 + UnlockPage(hidden_page);
6537 + page_cache_release(hidden_page);
6538 + kunmap(page); /* kmap was done in prepare_write */
6540 + /* we must set our page as up-to-date */
6542 + ClearPageUptodate(page);
6544 + SetPageUptodate(page);
6546 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
6547 + mutex_unlock(&hidden_inode->i_mutex);
6549 + up(&hidden_inode->i_sem);
6551 + print_exit_status(err);
6552 + return err; /* assume all is ok */
6557 +mini_fo_bmap(struct address_space *mapping, long block)
6561 + inode_t *hidden_inode;
6563 + print_entry_location();
6565 + inode = (inode_t *) mapping->host;
6566 + hidden_inode = itohi(inode);
6568 + if (hidden_inode->i_mapping->a_ops->bmap)
6569 + err = hidden_inode->i_mapping->a_ops->bmap(hidden_inode->i_mapping, block);
6570 + print_exit_location();
6576 + * This function is copied verbatim from mm/filemap.c.
6577 + * XXX: It should be simply moved to some header file instead -- bug Al about it!
6579 +static inline int sync_page(struct page *page)
6581 + struct address_space *mapping = page->mapping;
6583 + if (mapping && mapping->a_ops && mapping->a_ops->sync_page)
6584 + return mapping->a_ops->sync_page(page);
6590 + * XXX: we may not need this function if not FIST_FILTER_DATA.
6591 + * FIXME: for FIST_FILTER_SCA, get all lower pages and sync them each.
6594 +mini_fo_sync_page(page_t *page)
6598 + inode_t *hidden_inode;
6599 + page_t *hidden_page;
6601 + print_entry_location();
6603 + inode = page->mapping->host; /* CPW: Moved below print_entry_location */
6604 + hidden_inode = itohi(inode);
6606 + /* find lower page (returns a locked page) */
6607 + hidden_page = grab_cache_page(hidden_inode->i_mapping, page->index);
6611 + err = sync_page(hidden_page);
6613 + UnlockPage(hidden_page); /* b/c grab_cache_page locked it */
6614 + page_cache_release(hidden_page); /* b/c grab_cache_page increased refcnt */
6617 + print_exit_status(err);
6620 Index: linux-2.6.25.4/fs/mini_fo/README
6621 ===================================================================
6623 +++ linux-2.6.25.4/fs/mini_fo/README
6625 +README for the mini_fo overlay file system
6626 +=========================================
6632 +mini_fo is a virtual kernel file system that can make read-only
6633 +file systems writable. This is done by redirecting modifying operations
6634 +to a writeable location called "storage directory", and leaving the
6635 +original data in the "base directory" untouched. When reading, the
6636 +file system merges the modifed and original data so that only the
6637 +newest versions will appear. This occurs transparently to the user,
6638 +who can access the data like on any other read-write file system.
6640 +Base and storage directories may be located on the same or on
6641 +different partitions and may be of different file system types. While
6642 +the storage directory obviously needs to be writable, the base may or
6643 +may not be writable, what doesn't matter as it will no be modified
6650 +The primary purpose of the mini_fo file system is to allow easy
6651 +software updates to embedded systems, that often store their root
6652 +file system in a read-only flash file system, but there are many
6653 +more as for example sandboxing, or for allowing live-cds to
6654 +permanently store information.
6659 +This should be simple. Adjust the Makefile to point to the correct
6660 +kernel headers you want to build the module for. Then:
6664 +should build "mini_fo.o" for a 2.4 kernel or "mini_fo.ko" for a 2.6
6667 +If you are building the module for you current kernel, you can install
6668 +the module (as root):
6677 +USING THE FILE SYSTEM
6678 +--------------------
6680 +the general mount syntax is:
6682 + mount -t mini_fo -o base=<base directory>,sto=<storage directory>\
6683 + <base directory> <mount point>
6687 +You have mounted a cdrom to /mnt/cdrom and want to modifiy some files
6690 +load the module (as root)
6692 + # insmod mini_fo.o for a 2.4 kernel or
6694 + # insmod mini_fo.ko for a 2.6 kernel
6697 +create a storage dir in tmp and a mountpoint for mini_fo:
6700 + # mkdir /mnt/mini_fo
6702 +and mount the mini_fo file system:
6704 + # mount -t mini_fo -o base=/mnt/cdrom,sto=/tmp/sto /mnt/cdrom /mnt/mini_fo
6707 +Now the data stored on the cd can be accessed via the mini_fo
6708 +mountpoint just like any read-write file system, files can be modified
6709 +and deleted, new ones can be created and so on. When done unmount the
6712 + # unmount /mnt/mini_fo
6714 +Note that if the file system is mounted again using the same storage
6715 +file system, of course it will appear in the modified state again. If
6716 +you remount it using an new empty storage directory, it will be
6717 +unmodified. Therefore by executing:
6722 +you can nuke all the changes you made to the original file system. But
6723 + remember NEVER do this while the mini_fo file system is mounted!
6726 +Alternatively you can use the mini_fo-overlay bash script, that
6727 +simplifies managing mini_fo mounts. See TOOLS Section.
6733 +mini_fo-merge (experimental):
6735 +This is a bash script that will merge changes contained in the storage
6736 +directory back to the base directory. This allows mini_fo to function
6737 +as a cache file system by overlaying a slow (network, ...) file system
6738 +and using a fast (ramdisk, ...) as storage. When done, changes can be
6739 +merged back to the (slow) base with mini_fo-merge. See "mini_fo-merge
6742 +It can be usefull for merging changes back after a successfull test
6743 +(patches, software updates...)
6748 +This bash script simplifies managing one or more mini_fo mounts. For
6749 +overlaying a directory called "basedir1", you can just call:
6751 + # mini_fo-overlay basedir1
6753 +This will mount mini_fo with "basedir1" as base, "/tmp/sto-basedir1/"
6754 +as storage to "/mnt/mini_fo-basedir1/". It has more options though,
6755 +type "mini_fo-overlay -h" for details.
6758 +DOCUMENTATION, REPORTING BUGS, GETTING HELP
6759 +-------------------------------------------
6761 +Please visit the mini_fo project page at:
6763 +http://www.denx.de/twiki/bin/view/Know/MiniFOHome
6769 +Never modify the base or the storage directorys while the mini_fo
6770 +file system is mounted, or you might crash you system. Simply accessing
6771 +and reading should not cause any trouble.
6773 +Exporting a mini_fo mount point via NFS has not been tested, and may
6776 +Check the RELEASE_NOTES for details on bugs and features.
6780 +Copyright (C) 2004, 2005 Markus Klotzbuecher <mk@creamnet.de>
6782 +This program is free software; you can redistribute it and/or
6783 +modify it under the terms of the GNU General Public License
6784 +as published by the Free Software Foundation; either version
6785 +2 of the License, or (at your option) any later version.
6788 Index: linux-2.6.25.4/fs/mini_fo/RELEASE_NOTES
6789 ===================================================================
6791 +++ linux-2.6.25.4/fs/mini_fo/RELEASE_NOTES
6793 +Release: mini_fo-0.6.1 (v0-6-1)
6801 +- bugfixes (see ChangeLog)
6803 +- two helper scripts "mini_fo_merge" and "mini_fo_overlay" (see
6804 + README for details).
6808 +- Support for 2.4 and 2.6 (see Makefile)
6810 +- Partial hard link support (creating works as expected, but already
6811 + existing links in the base file system will be treated as if they
6812 + were individual files).
6814 +- Various bugfixes and cleanups.
6819 +- This is mini_fo-0-6-0-pre1! This release is a complete rewrite of
6820 + many vital mini_fo parts such as the old whiteout list code which
6821 + has been replaced by the new META subsystem.
6823 +- Light weight directory renaming implemented. This means if a
6824 + directory is renamed via the mini_fo filesystem this will no longer
6825 + result in a complete copy in storage, instead only one empty
6826 + directory will be created. All base filed contained in the original
6827 + directory stay there until modified.
6829 +- Special files (creating, renaming, deleting etc.) now working.
6831 +- Many bugfixes and cleanup, mini_fo is now a lot more stable.
6836 +- Final release of the 0-5-* versions. Next will be a complete rewrite
6837 + of many features. This release contains several bugfixes related to
6838 + directory renaming.
6843 +- Lots of cleanup and several bugfixes related to directory deleting
6845 +- Directory renaming suddenly works, what is most likely due to the
6846 + fact tha that "mv" is smart: if the classic rename doesn't work it
6847 + will assume that source and target file are on different fs and will
6848 + copy the directory and try to remove the source directory. Until
6849 + directory removing wasn't implemented, it would fail to do this and
6851 + So, directory renaming works for now, but it doesn't yet do what you
6852 + would expect from a overlay fs, so use with care.
6857 +- implemented directory deleting
6858 +- made parsing of mount options more stable
6859 +- New format of mount options! (See README)
6860 +- I can't reproduce the unknown panic with 2.4.25 anymore, so I'll
6861 + happily assume it never existed!
6864 +Implemented features:
6865 +---------------------
6867 +- creating hard links (see BUGS on already existing hard links)
6868 +- lightweight directory renaming
6869 +- renaming device files, pipes, sockets, etc.
6870 +- creating, renaming, deleting of special files
6871 +- deleting directorys
6872 +- general directory reading (simple "ls" )
6873 +- creating files in existing directorys
6874 +- creating directorys
6876 +- reading and writing files (involves opening)
6877 +- appending to files (creates copy in storage)
6879 +- llseek works too, what allows editors to work
6880 +- persistency (a deleted file stay deleted over remounts)
6881 +- use of symbolic links
6882 +- creating of device files
6885 +Not (yet) implemented features:
6886 +-------------------------------
6888 +- full hard link support.
6895 +Hard links in the base file system will be treated as individual
6896 +files, not as links to one inode.
6898 +The main problem with hard links isn't allowing to create them, but
6899 +their pure existence. If you modify a base hard link, the changes made
6900 +will only show up on this link, the other link will remain in the
6901 +original state. I hope to fix this someday. Please note that this does
6902 +not effect the special hard links '.' and '..', that are handled
6903 +seperately by the lower fs.
6904 Index: linux-2.6.25.4/fs/mini_fo/state.c
6905 ===================================================================
6907 +++ linux-2.6.25.4/fs/mini_fo/state.c
6910 + * Copyright (C) 2005 Markus Klotzbuecher <mk@creamnet.de>
6912 + * This program is free software; you can redistribute it and/or
6913 + * modify it under the terms of the GNU General Public License
6914 + * as published by the Free Software Foundation; either version
6915 + * 2 of the License, or (at your option) any later version.
6918 +#ifdef HAVE_CONFIG_H
6919 +# include <config.h>
6920 +#endif /* HAVE_CONFIG_H */
6923 +#include "mini_fo.h"
6926 +/* create the storage file, setup new states */
6927 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
6928 +int create_sto_reg_file(dentry_t *dentry, int mode, struct nameidata *nd)
6930 +int create_sto_reg_file(dentry_t *dentry, int mode)
6935 + dentry_t *hidden_sto_dentry;
6936 + dentry_t *hidden_sto_dir_dentry;
6938 + if(exists_in_storage(dentry)) {
6939 + printk(KERN_CRIT "mini_fo: create_sto_file: wrong type or state.\n");
6943 + err = get_neg_sto_dentry(dentry);
6946 + printk(KERN_CRIT "mini_fo: create_sto_file: ERROR getting neg. sto dentry.\n");
6950 + dir = dentry->d_parent->d_inode;
6951 + hidden_sto_dentry = dtohd2(dentry);
6954 + hidden_sto_dir_dentry = dget(hidden_sto_dentry->d_parent);
6956 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
6957 + mutex_lock(&hidden_sto_dir_dentry->d_inode->i_mutex);
6959 + down(&hidden_sto_dir_dentry->d_inode->i_sem);
6962 + err = PTR_ERR(hidden_sto_dir_dentry);
6963 + if (IS_ERR(hidden_sto_dir_dentry))
6966 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
6967 + err = vfs_create(hidden_sto_dir_dentry->d_inode,
6968 + hidden_sto_dentry,
6971 + err = vfs_create(hidden_sto_dir_dentry->d_inode,
6972 + hidden_sto_dentry,
6976 + printk(KERN_CRIT "mini_fo: create_sto_file: ERROR creating sto file.\n");
6980 + if(!dtohd2(dentry)->d_inode) {
6981 + printk(KERN_CRIT "mini_fo: create_sto_file: ERROR creating sto file [2].\n");
6986 + /* interpose the new inode */
6987 + if(dtost(dentry) == DELETED) {
6988 + dtost(dentry) = DEL_REWRITTEN;
6989 + err = mini_fo_tri_interpose(NULL, hidden_sto_dentry, dentry, dir->i_sb, 0);
6993 + else if(dtost(dentry) == NON_EXISTANT) {
6994 + dtost(dentry) = CREATED;
6995 + err = mini_fo_tri_interpose(dtohd(dentry), hidden_sto_dentry, dentry, dir->i_sb, 0);
6999 + else if(dtost(dentry) == UNMODIFIED) {
7000 + dtost(dentry) = MODIFIED;
7001 + /* interpose on new inode */
7002 + if(itohi2(dentry->d_inode) != NULL) {
7003 + printk(KERN_CRIT "mini_fo: create_sto_file: invalid inode detected.\n");
7007 + itohi2(dentry->d_inode) = igrab(dtohd2(dentry)->d_inode);
7009 + fist_copy_attr_timesizes(dentry->d_parent->d_inode,
7010 + hidden_sto_dir_dentry->d_inode);
7013 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
7014 + mutex_unlock(&hidden_sto_dir_dentry->d_inode->i_mutex);
7016 + up(&hidden_sto_dir_dentry->d_inode->i_sem);
7018 + dput(hidden_sto_dir_dentry);
7023 +/* create the sto dir, setup states */
7024 +int create_sto_dir(dentry_t *dentry, int mode)
7028 + dentry_t *hidden_sto_dentry;
7029 + dentry_t *hidden_sto_dir_dentry;
7031 + /* had to take the "!S_ISDIR(mode))" check out, because it failed */
7032 + if(exists_in_storage(dentry)) {
7033 + printk(KERN_CRIT "mini_fo: create_sto_dir: wrong type or state.\\
7039 + err = get_neg_sto_dentry(dentry);
7045 + dir = dentry->d_parent->d_inode;
7046 + hidden_sto_dentry = dtohd2(dentry);
7048 + /* was: hidden_sto_dir_dentry = lock_parent(hidden_sto_dentry); */
7049 + hidden_sto_dir_dentry = dget(hidden_sto_dentry->d_parent);
7051 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
7052 + mutex_lock(&hidden_sto_dir_dentry->d_inode->i_mutex);
7054 + down(&hidden_sto_dir_dentry->d_inode->i_sem);
7057 + err = PTR_ERR(hidden_sto_dir_dentry);
7058 + if (IS_ERR(hidden_sto_dir_dentry))
7061 + err = vfs_mkdir(hidden_sto_dir_dentry->d_inode,
7062 + hidden_sto_dentry,
7065 + printk(KERN_CRIT "mini_fo: create_sto_dir: ERROR creating sto dir.\n");
7069 + if(!dtohd2(dentry)->d_inode) {
7070 + printk(KERN_CRIT "mini_fo: create_sto_dir: ERROR creating sto dir [2].\n");
7075 + /* interpose the new inode */
7076 + if(dtost(dentry) == DELETED) {
7077 + dtost(dentry) = DEL_REWRITTEN;
7078 + err = mini_fo_tri_interpose(NULL, hidden_sto_dentry, dentry, dir->i_sb, 0);
7082 + else if(dtopd(dentry)->state == NON_EXISTANT) {
7083 + dtopd(dentry)->state = CREATED;
7084 + err = mini_fo_tri_interpose(dtohd(dentry), hidden_sto_dentry, dentry, dir->i_sb, 0);
7088 + else if(dtopd(dentry)->state == UNMODIFIED) {
7089 + dtopd(dentry)->state = MODIFIED;
7090 + /* interpose on new inode */
7091 + if(itohi2(dentry->d_inode) != NULL) {
7092 + printk(KERN_CRIT "mini_fo: create_sto_dir: ERROR, invalid inode detected.\n");
7096 + itohi2(dentry->d_inode) = igrab(dtohd2(dentry)->d_inode);
7099 + fist_copy_attr_timesizes(dir, hidden_sto_dir_dentry->d_inode);
7101 + /* initalize the wol list */
7102 + itopd(dentry->d_inode)->deleted_list_size = -1;
7103 + itopd(dentry->d_inode)->renamed_list_size = -1;
7104 + meta_build_lists(dentry);
7108 + /* was: unlock_dir(hidden_sto_dir_dentry); */
7109 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
7110 + mutex_unlock(&hidden_sto_dir_dentry->d_inode->i_mutex);
7112 + up(&hidden_sto_dir_dentry->d_inode->i_sem);
7114 + dput(hidden_sto_dir_dentry);
7119 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
7120 +int create_sto_nod(dentry_t *dentry, int mode, dev_t dev)
7122 +int create_sto_nod(dentry_t *dentry, int mode, int dev)
7127 + dentry_t *hidden_sto_dentry;
7128 + dentry_t *hidden_sto_dir_dentry;
7130 + if(exists_in_storage(dentry)) {
7134 + err = get_neg_sto_dentry(dentry);
7137 + printk(KERN_CRIT "mini_fo: create_sto_nod: ERROR getting neg. sto dentry.\n");
7141 + dir = dentry->d_parent->d_inode;
7142 + hidden_sto_dentry = dtohd2(dentry);
7145 + hidden_sto_dir_dentry = dget(hidden_sto_dentry->d_parent);
7147 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
7148 + mutex_lock(&hidden_sto_dir_dentry->d_inode->i_mutex);
7150 + down(&hidden_sto_dir_dentry->d_inode->i_sem);
7153 + err = PTR_ERR(hidden_sto_dir_dentry);
7154 + if (IS_ERR(hidden_sto_dir_dentry))
7157 + err = vfs_mknod(hidden_sto_dir_dentry->d_inode, hidden_sto_dentry, mode, dev);
7161 + if(!dtohd2(dentry)->d_inode) {
7162 + printk(KERN_CRIT "mini_fo: create_sto_nod: creating storage inode failed [1].\n");
7163 + err = -EINVAL; /* return something indicating failure */
7167 + /* interpose the new inode */
7168 + if(dtost(dentry) == DELETED) {
7169 + dtost(dentry) = DEL_REWRITTEN;
7170 + err = mini_fo_tri_interpose(NULL, hidden_sto_dentry, dentry, dir->i_sb, 0);
7174 + else if(dtost(dentry) == NON_EXISTANT) {
7175 + dtost(dentry) = CREATED;
7176 + err = mini_fo_tri_interpose(dtohd(dentry), hidden_sto_dentry, dentry, dir->i_sb, 0);
7180 + else if(dtost(dentry) == UNMODIFIED) {
7181 + dtost(dentry) = MODIFIED;
7182 + /* interpose on new inode */
7183 + if(itohi2(dentry->d_inode) != NULL) {
7184 + printk(KERN_CRIT "mini_fo: create_sto_nod: error, invalid inode detected.\n");
7188 + itohi2(dentry->d_inode) = igrab(dtohd2(dentry)->d_inode);
7191 + fist_copy_attr_timesizes(dir, hidden_sto_dir_dentry->d_inode);
7194 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
7195 + mutex_unlock(&hidden_sto_dir_dentry->d_inode->i_mutex);
7197 + up(&hidden_sto_dir_dentry->d_inode->i_sem);
7199 + dput(hidden_sto_dir_dentry);
7205 +/* unimplemented (and possibly not usefull):
7207 + nondir-del_to_del_rew
7208 + nondir-non_exist_to_creat
7213 + dir-del_rew_to_del
7214 + dir-del_to_del_rew
7215 + dir-non_exist_to_creat
7219 +/* bring a file of any type from state UNMODIFIED to MODIFIED */
7220 +int nondir_unmod_to_mod(dentry_t *dentry, int cp_flag)
7223 + struct vfsmount *tgt_mnt;
7224 + struct vfsmount *src_mnt;
7225 + dentry_t *tgt_dentry;
7226 + dentry_t *src_dentry;
7227 + dentry_t *hidden_sto_dentry;
7228 + dentry_t *hidden_sto_dir_dentry;
7230 + check_mini_fo_dentry(dentry);
7232 + if((dtost(dentry) != UNMODIFIED) ||
7233 + S_ISDIR(dentry->d_inode->i_mode)) {
7234 + printk(KERN_CRIT "mini_fo: nondir_unmod_to_mod: \
7235 + wrong type or state.\n");
7239 + err = get_neg_sto_dentry(dentry);
7242 + printk(KERN_CRIT "mini_fo: nondir_unmod_to_mod: \
7243 + ERROR getting neg. sto dentry.\n");
7247 + /* create sto file */
7248 + hidden_sto_dentry = dtohd2(dentry);
7251 + hidden_sto_dir_dentry = dget(hidden_sto_dentry->d_parent);
7253 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
7254 + mutex_lock(&hidden_sto_dir_dentry->d_inode->i_mutex);
7256 + down(&hidden_sto_dir_dentry->d_inode->i_sem);
7259 + err = PTR_ERR(hidden_sto_dir_dentry);
7260 + if (IS_ERR(hidden_sto_dir_dentry))
7263 + /* handle different types of nondirs */
7264 + if(S_ISCHR(dentry->d_inode->i_mode) ||
7265 + S_ISBLK(dentry->d_inode->i_mode)) {
7266 + err = vfs_mknod(hidden_sto_dir_dentry->d_inode,
7267 + hidden_sto_dentry,
7268 + dtohd(dentry)->d_inode->i_mode,
7269 + dtohd(dentry)->d_inode->i_rdev);
7272 + else if(S_ISREG(dentry->d_inode->i_mode)) {
7274 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
7275 + err = vfs_create(hidden_sto_dir_dentry->d_inode,
7276 + hidden_sto_dentry,
7277 + dtohd(dentry)->d_inode->i_mode, NULL);
7279 + err = vfs_create(hidden_sto_dir_dentry->d_inode,
7280 + hidden_sto_dentry,
7281 + dtohd(dentry)->d_inode->i_mode);
7285 + printk(KERN_CRIT "mini_fo: nondir_unmod_to_mod: \
7286 + ERROR creating sto file.\n");
7290 + /* interpose on new inode */
7291 + if(itohi2(dentry->d_inode) != NULL) {
7292 + printk(KERN_CRIT "mini_fo: nondir_unmod_to_mod: \
7293 + ERROR, invalid inode detected.\n");
7298 + itohi2(dentry->d_inode) = igrab(dtohd2(dentry)->d_inode);
7300 + fist_copy_attr_timesizes(dentry->d_parent->d_inode,
7301 + hidden_sto_dir_dentry->d_inode);
7302 + dtost(dentry) = MODIFIED;
7304 + /* copy contents if regular file and cp_flag = 1 */
7305 + if((cp_flag == 1) && S_ISREG(dentry->d_inode->i_mode)) {
7307 + /* unlock first */
7308 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
7309 + mutex_unlock(&hidden_sto_dir_dentry->d_inode->i_mutex);
7311 + up(&hidden_sto_dir_dentry->d_inode->i_sem);
7314 + dput(hidden_sto_dir_dentry);
7316 + tgt_dentry = dtohd2(dentry);
7317 + tgt_mnt = stopd(dentry->d_inode->i_sb)->hidden_mnt2;
7318 + src_dentry = dtohd(dentry);
7319 + src_mnt = stopd(dentry->d_inode->i_sb)->hidden_mnt;
7321 + err = mini_fo_cp_cont(tgt_dentry, tgt_mnt,
7322 + src_dentry, src_mnt);
7324 + printk(KERN_CRIT "mini_fo: nondir_unmod_to_mod: \
7325 + ERROR copying contents.\n");
7331 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
7332 + mutex_unlock(&hidden_sto_dir_dentry->d_inode->i_mutex);
7334 + up(&hidden_sto_dir_dentry->d_inode->i_sem);
7336 + dput(hidden_sto_dir_dentry);
7341 +/* this function is currently identical to nondir_creat_to_del */
7342 +int nondir_del_rew_to_del(dentry_t *dentry)
7344 + return nondir_creat_to_del(dentry);
7347 +int nondir_creat_to_del(dentry_t *dentry)
7351 + inode_t *hidden_sto_dir_inode;
7352 + dentry_t *hidden_sto_dir_dentry;
7353 + dentry_t *hidden_sto_dentry;
7355 + check_mini_fo_dentry(dentry);
7357 + /* for now this function serves for both state DEL_REWRITTEN and
7359 + if(!(dtost(dentry) == CREATED || (dtost(dentry) == DEL_REWRITTEN)) ||
7360 + S_ISDIR(dentry->d_inode->i_mode)) {
7361 + printk(KERN_CRIT "mini_fo: nondir_mod_to_del/del_rew_to_del: \
7362 + wrong type or state.\n");
7367 + hidden_sto_dir_inode = itohi2(dentry->d_parent->d_inode);
7368 + hidden_sto_dentry = dtohd2(dentry);
7370 + /* was: hidden_sto_dir_dentry = lock_parent(hidden_sto_dentry);*/
7371 + hidden_sto_dir_dentry = dget(hidden_sto_dentry->d_parent);
7373 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
7374 + mutex_lock(&hidden_sto_dir_dentry->d_inode->i_mutex);
7376 + down(&hidden_sto_dir_dentry->d_inode->i_sem);
7379 + /* avoid destroying the hidden inode if the file is in use */
7380 + dget(hidden_sto_dentry);
7381 + err = vfs_unlink(hidden_sto_dir_inode, hidden_sto_dentry);
7382 + dput(hidden_sto_dentry);
7384 + d_delete(hidden_sto_dentry);
7386 + /* propagate number of hard-links */
7387 + dentry->d_inode->i_nlink = itohi2(dentry->d_inode)->i_nlink;
7389 + dtost(dentry) = NON_EXISTANT;
7391 + /* was: unlock_dir(hidden_sto_dir_dentry); */
7392 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
7393 + mutex_unlock(&hidden_sto_dir_dentry->d_inode->i_mutex);
7395 + up(&hidden_sto_dir_dentry->d_inode->i_sem);
7397 + dput(hidden_sto_dir_dentry);
7403 +int nondir_mod_to_del(dentry_t *dentry)
7406 + dentry_t *hidden_sto_dentry;
7407 + inode_t *hidden_sto_dir_inode;
7408 + dentry_t *hidden_sto_dir_dentry;
7410 + check_mini_fo_dentry(dentry);
7412 + if(dtost(dentry) != MODIFIED ||
7413 + S_ISDIR(dentry->d_inode->i_mode)) {
7414 + printk(KERN_CRIT "mini_fo: nondir_mod_to_del: \
7415 + wrong type or state.\n");
7420 + hidden_sto_dir_inode = itohi2(dentry->d_parent->d_inode);
7421 + hidden_sto_dentry = dtohd2(dentry);
7423 + /* was hidden_sto_dir_dentry = lock_parent(hidden_sto_dentry); */
7424 + hidden_sto_dir_dentry = dget(hidden_sto_dentry->d_parent);
7426 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
7427 + mutex_lock(&hidden_sto_dir_dentry->d_inode->i_mutex);
7429 + down(&hidden_sto_dir_dentry->d_inode->i_sem);
7432 + /* avoid destroying the hidden inode if the file is in use */
7433 + dget(hidden_sto_dentry);
7434 + err = vfs_unlink(hidden_sto_dir_inode, hidden_sto_dentry);
7435 + dput(hidden_sto_dentry);
7437 + d_delete(hidden_sto_dentry);
7439 + /* propagate number of hard-links */
7440 + dentry->d_inode->i_nlink = itohi2(dentry->d_inode)->i_nlink;
7442 + /* dput base dentry, this will relase the inode and free the
7443 + * dentry, as we will never need it again. */
7444 + dput(dtohd(dentry));
7445 + dtohd(dentry) = NULL;
7446 + dtost(dentry) = DELETED;
7448 + /* add deleted file to META-file */
7449 + meta_add_d_entry(dentry->d_parent,
7450 + dentry->d_name.name,
7451 + dentry->d_name.len);
7453 + /* was: unlock_dir(hidden_sto_dir_dentry); */
7454 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
7455 + mutex_unlock(&hidden_sto_dir_dentry->d_inode->i_mutex);
7457 + up(&hidden_sto_dir_dentry->d_inode->i_sem);
7459 + dput(hidden_sto_dir_dentry);
7465 +int nondir_unmod_to_del(dentry_t *dentry)
7469 + check_mini_fo_dentry(dentry);
7471 + if(dtost(dentry) != UNMODIFIED ||
7472 + S_ISDIR(dentry->d_inode->i_mode)) {
7473 + printk(KERN_CRIT "mini_fo: nondir_unmod_to_del: \
7474 + wrong type or state.\n");
7479 + /* next we have to get a negative dentry for the storage file */
7480 + err = get_neg_sto_dentry(dentry);
7485 + /* add deleted file to META lists */
7486 + err = meta_add_d_entry(dentry->d_parent,
7487 + dentry->d_name.name,
7488 + dentry->d_name.len);
7493 + /* dput base dentry, this will relase the inode and free the
7494 + * dentry, as we will never need it again. */
7495 + dput(dtohd(dentry));
7496 + dtohd(dentry) = NULL;
7497 + dtost(dentry) = DELETED;
7503 +/* bring a dir from state UNMODIFIED to MODIFIED */
7504 +int dir_unmod_to_mod(dentry_t *dentry)
7508 + check_mini_fo_dentry(dentry);
7510 + if(dtost(dentry) != UNMODIFIED ||
7511 + !S_ISDIR(dentry->d_inode->i_mode)) {
7512 + printk(KERN_CRIT "mini_fo: dir_unmod_to_mod: \
7513 + wrong type or state.\n");
7518 + /* this creates our dir incl. sto. structure */
7519 + err = build_sto_structure(dentry->d_parent, dentry);
7521 + printk(KERN_CRIT "mini_fo: dir_unmod_to_mod: \
7522 + build_sto_structure failed.\n");
7529 Index: linux-2.6.25.4/fs/mini_fo/super.c
7530 ===================================================================
7532 +++ linux-2.6.25.4/fs/mini_fo/super.c
7535 + * Copyright (c) 1997-2003 Erez Zadok
7536 + * Copyright (c) 2001-2003 Stony Brook University
7538 + * For specific licensing information, see the COPYING file distributed with
7539 + * this package, or get one from ftp://ftp.filesystems.org/pub/fist/COPYING.
7541 + * This Copyright notice must be kept intact and distributed with all
7542 + * fistgen sources INCLUDING sources generated by fistgen.
7545 + * Copyright (C) 2004, 2005 Markus Klotzbuecher <mk@creamnet.de>
7547 + * This program is free software; you can redistribute it and/or
7548 + * modify it under the terms of the GNU General Public License
7549 + * as published by the Free Software Foundation; either version
7550 + * 2 of the License, or (at your option) any later version.
7557 +#ifdef HAVE_CONFIG_H
7558 +# include <config.h>
7562 +#include "mini_fo.h"
7566 +mini_fo_read_inode(inode_t *inode)
7568 + static struct address_space_operations mini_fo_empty_aops;
7570 + __itopd(inode) = kmalloc(sizeof(struct mini_fo_inode_info), GFP_KERNEL);
7571 + if (!itopd(inode)) {
7572 + printk("<0>%s:%s:%d: No kernel memory!\n", __FILE__, __FUNCTION__, __LINE__);
7575 + itohi(inode) = NULL;
7576 + itohi2(inode) = NULL;
7578 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
7579 + inode->i_version++;
7581 + inode->i_version = ++event; /* increment inode version */
7583 + inode->i_op = &mini_fo_main_iops;
7584 + inode->i_fop = &mini_fo_main_fops;
7587 + * XXX: To export a file system via NFS, it has to have the
7588 + * FS_REQUIRES_DEV flag, so turn it on. But should we inherit it from
7589 + * the lower file system, or can we allow our file system to be exported
7590 + * even if the lower one cannot be natively exported.
7592 + inode->i_sb->s_type->fs_flags |= FS_REQUIRES_DEV;
7594 + * OK, the above was a hack, which is now turned off because it may
7595 + * cause a panic/oops on some systems. The correct way to export a
7596 + * "nodev" filesystem is via using nfs-utils > 1.0 and the "fsid=" export
7597 + * parameter, which requires 2.4.20 or later.
7600 + /* I don't think ->a_ops is ever allowed to be NULL */
7601 + inode->i_mapping->a_ops = &mini_fo_empty_aops;
7605 +#if defined(FIST_DEBUG) || defined(FIST_FILTER_SCA)
7607 + * No need to call write_inode() on the lower inode, as it
7608 + * will have been marked 'dirty' anyway. But we might need
7609 + * to write some of our own stuff to disk.
7612 +mini_fo_write_inode(inode_t *inode, int sync)
7614 + print_entry_location();
7615 + print_exit_location();
7617 +#endif /* defined(FIST_DEBUG) || defined(FIST_FILTER_SCA) */
7621 +mini_fo_put_inode(inode_t *inode)
7624 + * This is really funky stuff:
7625 + * Basically, if i_count == 1, iput will then decrement it and this inode will be destroyed.
7626 + * It is currently holding a reference to the hidden inode.
7627 + * Therefore, it needs to release that reference by calling iput on the hidden inode.
7628 + * iput() _will_ do it for us (by calling our clear_inode), but _only_ if i_nlink == 0.
7629 + * The problem is, NFS keeps i_nlink == 1 for silly_rename'd files.
7630 + * So we must for our i_nlink to 0 here to trick iput() into calling our clear_inode.
7632 + if (atomic_read(&inode->i_count) == 1)
7633 + inode->i_nlink = 0;
7637 +#if defined(FIST_DEBUG) || defined(FIST_FILTER_SCA)
7639 + * we now define delete_inode, because there are two VFS paths that may
7640 + * destroy an inode: one of them calls clear inode before doing everything
7641 + * else that's needed, and the other is fine. This way we truncate the inode
7642 + * size (and its pages) and then clear our own inode, which will do an iput
7643 + * on our and the lower inode.
7646 +mini_fo_delete_inode(inode_t *inode)
7648 + print_entry_location();
7650 + fist_checkinode(inode, "mini_fo_delete_inode IN");
7651 + inode->i_size = 0; /* every f/s seems to do that */
7652 + clear_inode(inode);
7654 + print_exit_location();
7656 +#endif /* defined(FIST_DEBUG) || defined(FIST_FILTER_SCA) */
7659 +/* final actions when unmounting a file system */
7661 +mini_fo_put_super(super_block_t *sb)
7664 + mntput(stopd(sb)->hidden_mnt);
7665 + mntput(stopd(sb)->hidden_mnt2);
7667 + /* mk: no! dput(stopd(sb)->base_dir_dentry);
7668 + dput(stopd(sb)->storage_dir_dentry); */
7671 + __stopd(sb) = NULL;
7678 + * This is called in do_umount before put_super.
7679 + * The superblock lock is not held yet.
7680 + * We probably do not need to define this or call write_super
7681 + * on the hidden_sb, because sync_supers() will get to hidden_sb
7682 + * sooner or later. But it is also called from file_fsync()...
7685 +mini_fo_write_super(super_block_t *sb)
7689 +#endif /* NOT_NEEDED */
7693 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,18)
7694 +mini_fo_statfs(struct dentry *d, struct kstatfs *buf)
7695 +#elif LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
7696 +mini_fo_statfs(super_block_t *sb, struct kstatfs *buf)
7698 +mini_fo_statfs(super_block_t *sb, struct statfs *buf)
7702 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,18)
7703 + struct dentry *hidden_d;
7705 + hidden_d = dtohd(d);
7706 + err = vfs_statfs(hidden_d, buf);
7708 + super_block_t *hidden_sb;
7710 + hidden_sb = stohs(sb);
7711 + err = vfs_statfs(hidden_sb, buf);
7719 + * XXX: not implemented. This is not allowed yet.
7720 + * Should we call this on the hidden_sb? Probably not.
7723 +mini_fo_remount_fs(super_block_t *sb, int *flags, char *data)
7725 + //printk(KERN_CRIT "mini_fo_remount_fs: WARNING, this function is umimplemented.\n");
7731 + * Called by iput() when the inode reference count reached zero
7732 + * and the inode is not hashed anywhere. Used to clear anything
7733 + * that needs to be, before the inode is completely destroyed and put
7734 + * on the inode free list.
7737 +mini_fo_clear_inode(inode_t *inode)
7740 + * Decrement a reference to a hidden_inode, which was incremented
7741 + * by our read_inode when it was created initially.
7744 + /* release the wol_list */
7745 + if(S_ISDIR(inode->i_mode)) {
7746 + __meta_put_lists(inode);
7749 + /* mk: fan out fun */
7751 + iput(itohi(inode));
7753 + iput(itohi2(inode));
7755 + // XXX: why this assertion fails?
7756 + // because it doesn't like us
7757 + // ASSERT((inode->i_state & I_DIRTY) == 0);
7758 + kfree(itopd(inode));
7759 + __itopd(inode) = NULL;
7764 + * Called in do_umount() if the MNT_FORCE flag was used and this
7765 + * function is defined. See comment in linux/fs/super.c:do_umount().
7766 + * Used only in nfs, to kill any pending RPC tasks, so that subsequent
7767 + * code can actually succeed and won't leave tasks that need handling.
7769 + * PS. I wonder if this is somehow useful to undo damage that was
7770 + * left in the kernel after a user level file server (such as amd)
7774 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,18)
7775 +mini_fo_umount_begin(struct vfsmount *mnt, int flags)
7777 + struct vfsmount *hidden_mnt;
7779 + hidden_mnt = stopd(mnt->mnt_sb)->hidden_mnt;
7781 + if (hidden_mnt->mnt_sb->s_op->umount_begin)
7782 + hidden_mnt->mnt_sb->s_op->umount_begin(hidden_mnt, flags);
7786 +mini_fo_umount_begin(super_block_t *sb)
7788 + super_block_t *hidden_sb;
7790 + hidden_sb = stohs(sb);
7792 + if (hidden_sb->s_op->umount_begin)
7793 + hidden_sb->s_op->umount_begin(hidden_sb);
7799 +struct super_operations mini_fo_sops =
7801 + read_inode: mini_fo_read_inode,
7802 +#if defined(FIST_DEBUG) || defined(FIST_FILTER_SCA)
7803 + write_inode: mini_fo_write_inode,
7804 +#endif /* defined(FIST_DEBUG) || defined(FIST_FILTER_SCA) */
7805 + put_inode: mini_fo_put_inode,
7806 +#if defined(FIST_DEBUG) || defined(FIST_FILTER_SCA)
7807 + delete_inode: mini_fo_delete_inode,
7808 +#endif /* defined(FIST_DEBUG) || defined(FIST_FILTER_SCA) */
7809 + put_super: mini_fo_put_super,
7810 + statfs: mini_fo_statfs,
7811 + remount_fs: mini_fo_remount_fs,
7812 + clear_inode: mini_fo_clear_inode,
7813 + umount_begin: mini_fo_umount_begin,