1 diff -urN linux-2.6.21.1.old/fs/Kconfig linux-2.6.21.1.dev/fs/Kconfig
2 --- linux-2.6.21.1.old/fs/Kconfig 2007-05-26 19:03:45.497714200 +0200
3 +++ linux-2.6.21.1.dev/fs/Kconfig 2007-05-26 21:01:26.154331240 +0200
5 This option will enlarge your kernel, but it allows debugging of
6 ocfs2 filesystem issues.
9 + tristate "Mini fanout overlay filesystem"
12 tristate "Minix fs support"
14 diff -urN linux-2.6.21.1.old/fs/Makefile linux-2.6.21.1.dev/fs/Makefile
15 --- linux-2.6.21.1.old/fs/Makefile 2007-05-26 19:03:45.497714200 +0200
16 +++ linux-2.6.21.1.dev/fs/Makefile 2007-05-26 21:01:26.160330328 +0200
18 obj-$(CONFIG_RAMFS) += ramfs/
19 obj-$(CONFIG_HUGETLBFS) += hugetlbfs/
20 obj-$(CONFIG_CODA_FS) += coda/
21 +obj-$(CONFIG_MINI_FO) += mini_fo/
22 obj-$(CONFIG_MINIX_FS) += minix/
23 obj-$(CONFIG_FAT_FS) += fat/
24 obj-$(CONFIG_MSDOS_FS) += msdos/
25 diff -urN linux-2.6.21.1.old/fs/mini_fo/aux.c linux-2.6.21.1.dev/fs/mini_fo/aux.c
26 --- linux-2.6.21.1.old/fs/mini_fo/aux.c 1970-01-01 01:00:00.000000000 +0100
27 +++ linux-2.6.21.1.dev/fs/mini_fo/aux.c 2007-05-26 21:01:26.160330328 +0200
30 + * Copyright (c) 1997-2003 Erez Zadok
31 + * Copyright (c) 2001-2003 Stony Brook University
33 + * For specific licensing information, see the COPYING file distributed with
34 + * this package, or get one from ftp://ftp.filesystems.org/pub/fist/COPYING.
36 + * This Copyright notice must be kept intact and distributed with all
37 + * fistgen sources INCLUDING sources generated by fistgen.
40 + * Copyright (C) 2004, 2005 Markus Klotzbuecher <mk@creamnet.de>
42 + * This program is free software; you can redistribute it and/or
43 + * modify it under the terms of the GNU General Public License
44 + * as published by the Free Software Foundation; either version
45 + * 2 of the License, or (at your option) any later version.
58 +/* check if file exists in storage */
59 +int exists_in_storage(dentry_t *dentry)
61 + check_mini_fo_dentry(dentry);
62 + if(dtost(dentry) == MODIFIED || dtost(dentry) == CREATED || dtost(dentry) == DEL_REWRITTEN)
67 +/* check if dentry is in an existing state */
68 +int is_mini_fo_existant(dentry_t *dentry)
70 + check_mini_fo_dentry(dentry);
72 + if(dtost(dentry) == DELETED || dtost(dentry) == NON_EXISTANT)
79 + * This function will create a negative storage dentry for
80 + * dentry, what is required for many create like options.
81 + * It will create the storage structure if necessary.
83 +int get_neg_sto_dentry(dentry_t *dentry)
87 + const unsigned char *name;
91 + !(dtost(dentry) == UNMODIFIED ||
92 + dtost(dentry) == NON_EXISTANT ||
93 + dtost(dentry) == DELETED)) {
94 + printk(KERN_CRIT "mini_fo: get_neg_sto_dentry: invalid dentry passed.\n");
98 + /* Have we got a neg. dentry already? */
99 + if(dtohd2(dentry)) {
103 + if(dtost(dentry->d_parent) == UNMODIFIED) {
104 + /* build sto struct */
105 + err = build_sto_structure(dentry->d_parent->d_parent, dentry->d_parent);
107 + dtost(dentry->d_parent) != MODIFIED) {
108 + printk(KERN_CRIT "mini_fo: get_neg_sto_dentry: ERROR building sto structure.\n");
114 + len = dentry->d_name.len;
115 + name = dentry->d_name.name;
118 + lookup_one_len(name, dtohd2(dentry->d_parent), len);
124 +int check_mini_fo_dentry(dentry_t *dentry)
126 + ASSERT(dentry != NULL);
127 + ASSERT(dtopd(dentry) != NULL);
128 + ASSERT((dtohd(dentry) != NULL) || (dtohd2(dentry) != NULL));
130 +/* if(dtost(dentry) == MODIFIED) { */
131 +/* ASSERT(dentry->d_inode != NULL); */
132 +/* ASSERT(dtohd(dentry) != NULL); */
133 +/* ASSERT(dtohd(dentry)->d_inode != NULL); */
134 +/* ASSERT(dtohd2(dentry) != NULL); */
135 +/* ASSERT(dtohd2(dentry)->d_inode != NULL); */
137 +/* else if(dtost(dentry) == UNMODIFIED) { */
138 +/* ASSERT(dentry->d_inode != NULL); */
144 +int check_mini_fo_file(file_t *file)
146 + ASSERT(file != NULL);
147 + ASSERT(ftopd(file) != NULL);
148 + ASSERT(file->f_dentry != NULL);
150 + /* violent checking, check depending of state and type
151 + * if(S_ISDIR(file->f_dentry->d_inode->i_mode)) {}
153 + ASSERT((ftohf(file) != NULL) || (ftohf2(file) != NULL));
157 +int check_mini_fo_inode(inode_t *inode)
159 + ASSERT(inode != NULL);
160 + ASSERT(itopd(inode) != NULL);
161 + ASSERT((itohi(inode) != NULL) || (itohi2(inode) != NULL));
166 + * will walk a base path as provided by get_mini_fo_bpath and return
167 + * the (hopefully ;-) ) positive dentry of the renamed base dir.
169 + * This does some work of path_init.
171 +dentry_t *bpath_walk(super_block_t *sb, char *bpath)
174 + struct nameidata nd;
177 + if(!bpath || bpath[0] != '/') {
178 + printk(KERN_CRIT "mini_fo: bpath_walk: Invalid string.\n");
181 + if(!sb || !stopd(sb)) {
182 + printk(KERN_CRIT "mini_fo: bpath_walk: Invalid sb.\n");
186 + /* setup nd as path_init does */
187 + nd.last_type = LAST_ROOT; /* if there are only slashes... */
188 + nd.flags = LOOKUP_FOLLOW;
189 + /* fix this: how do I reach this lock?
190 + * read_lock(¤t->fs->lock); */
191 + nd.mnt = mntget(stopd(sb)->hidden_mnt);
192 + nd.dentry = dget(stopd(sb)->base_dir_dentry);
193 + /* read_unlock(¤t->fs->lock); */
195 + err = path_walk(bpath+1, &nd);
198 + if (err || !nd.dentry || !nd.dentry->d_inode) {
199 + printk(KERN_CRIT "mini_fo: bpath_walk: path_walk failed.\n");
206 +/* returns the full path of the basefile incl. its name */
207 +int get_mini_fo_bpath(dentry_t *dentry, char **bpath, int *bpath_len)
211 + dentry_t *sky_walker;
213 + if(!dentry || !dtohd(dentry)) {
214 + printk(KERN_CRIT "mini_fo: get_mini_fo_bpath: invalid dentry passed.\n");
217 + sky_walker = dtohd(dentry);
220 + len += sky_walker->d_name.len + 1 ; /* 1 for '/' */
221 + sky_walker = sky_walker->d_parent;
222 + } while(sky_walker != stopd(dentry->d_inode->i_sb)->base_dir_dentry);
224 + /* 1 to oil the loop */
225 + *bpath = (char*) kmalloc(len + 1, GFP_KERNEL);
227 + printk(KERN_CRIT "mini_fo: get_mini_fo_bpath: out of mem.\n");
230 + buf_walker = *bpath+len; /* put it on last char */
231 + *buf_walker = '\n';
232 + sky_walker = dtohd(dentry);
235 + buf_walker -= sky_walker->d_name.len;
236 + strncpy(buf_walker,
237 + sky_walker->d_name.name,
238 + sky_walker->d_name.len);
239 + *(--buf_walker) = '/';
240 + sky_walker = sky_walker->d_parent;
241 + } while(sky_walker != stopd(dentry->d_inode->i_sb)->base_dir_dentry);
243 + /* bpath_len doesn't count newline! */
248 +int mini_fo_cp_cont(dentry_t *tgt_dentry, struct vfsmount *tgt_mnt,
249 + dentry_t *src_dentry, struct vfsmount *src_mnt)
252 + mm_segment_t old_fs;
255 + int bytes, len, tmp, err;
258 + if(!(tgt_dentry->d_inode && src_dentry->d_inode)) {
259 + printk(KERN_CRIT "mini_fo_cp_cont: ERROR, neg. dentry passed.\n");
269 + /* open file write only */
270 + tgt_file = dentry_open(tgt_dentry, tgt_mnt, 0x1);
271 + if(!tgt_file || IS_ERR(tgt_file)) {
272 + printk(KERN_CRIT "mini_fo_cp_cont: ERROR opening target file.\n");
273 + err = PTR_ERR(tgt_file);
277 + /* open file read only */
278 + src_file = dentry_open(src_dentry, src_mnt, 0x0);
279 + if(!src_file || IS_ERR(src_file)) {
280 + printk(KERN_CRIT "mini_fo_cp_cont: ERROR opening source file.\n");
281 + err = PTR_ERR(src_file);
283 + /* close target file */
288 + /* check if the filesystem(s) support read respective write */
289 + if(!src_file->f_op->read || !tgt_file->f_op->write) {
290 + printk(KERN_CRIT "mini_fo_cp_cont: ERROR, no fs read or write support.\n");
295 + /* allocate a page for transfering the data */
296 + buf = (void *) __get_free_page(GFP_KERNEL);
298 + printk(KERN_CRIT "mini_fo_cp_cont: ERROR, out of kernel mem.\n");
302 + tgt_file->f_pos = 0;
303 + src_file->f_pos = 0;
308 + /* Doing this I assume that a read operation will return a full
309 + * buffer while there is still data to read, and a less than
310 + * full buffer when all data has been read.
312 + bytes = len = PAGE_SIZE;
313 + while(bytes == len) {
314 + bytes = src_file->f_op->read(src_file, buf, len,
316 + tmp = tgt_file->f_op->write(tgt_file, buf, bytes,
319 + printk(KERN_CRIT "mini_fo_cp_cont: ERROR writing.\n");
320 + goto out_close_unset;
324 + free_page((unsigned long) buf);
331 + free_page((unsigned long) buf);
342 + /* mk: not sure if this need to be done */
351 + * ndl (no-duplicate list) stuff
352 + * This is used in mini_fo_readdir, to save the storage directory contents
353 + * and later when reading base, match them against the list in order
354 + * to avoid duplicates.
357 +/* add a file specified by name and len to the ndl
358 + * Return values: 0 on success, <0 on failure.
360 +int ndl_add_entry(struct readdir_data *rd, const char *name, int len)
362 + struct ndl_entry *tmp_entry;
364 + tmp_entry = (struct ndl_entry *)
365 + kmalloc(sizeof(struct ndl_entry), GFP_KERNEL);
367 + printk(KERN_CRIT "mini_fo: ndl_add_entry: out of mem.\n");
370 + tmp_entry->name = (char*) kmalloc(len, GFP_KERNEL);
371 + if(!tmp_entry->name) {
372 + printk(KERN_CRIT "mini_fo: ndl_add_entry: out of mem.\n");
375 + strncpy(tmp_entry->name, name, len);
376 + tmp_entry->len = len;
378 + list_add(&tmp_entry->list, &rd->ndl_list);
383 +/* delete all list entries and free memory */
384 +void ndl_put_list(struct readdir_data *rd)
386 + struct list_head *tmp;
387 + struct ndl_entry *tmp_entry;
389 + if(rd->ndl_size <= 0)
391 + while(!list_empty(&rd->ndl_list)) {
392 + tmp = rd->ndl_list.next;
394 + tmp_entry = list_entry(tmp, struct ndl_entry, list);
395 + kfree(tmp_entry->name);
401 +/* Check if a file specified by name and len is in the ndl
402 + * Return value: 0 if not in list, 1 if file is found in ndl.
404 +int ndl_check_entry(struct readdir_data *rd, const char *name, int len)
406 + struct list_head *tmp;
407 + struct ndl_entry *tmp_entry;
409 + if(rd->ndl_size <= 0)
412 + list_for_each(tmp, &rd->ndl_list) {
413 + tmp_entry = list_entry(tmp, struct ndl_entry, list);
414 + if(tmp_entry->len != len)
416 + if(!strncmp(tmp_entry->name, name, len))
423 + * Recursive function to create corresponding directorys in the storage fs.
424 + * The function will build the storage directorys up to dentry.
426 +int build_sto_structure(dentry_t *dir, dentry_t *dentry)
429 + dentry_t *hidden_sto_dentry;
430 + dentry_t *hidden_sto_dir_dentry;
432 + if(dentry->d_parent != dir) {
433 + printk(KERN_CRIT "mini_fo: build_sto_structure: invalid parameter or meta data corruption [1].\n");
437 + if(dtost(dir) != MODIFIED) {
438 + err = build_sto_structure(dir->d_parent, dentry->d_parent);
443 + /* ok, coming back again. */
444 + check_mini_fo_dentry(dentry);
445 + hidden_sto_dentry = dtohd2(dentry);
447 + if(!hidden_sto_dentry) {
449 + * This is the case after creating the first
450 + * hidden_sto_dentry.
451 + * After one negative storage_dentry, all pointers to
452 + * hidden_storage dentries are set to NULL. We need to
453 + * create the negative dentry before we create the storage
457 + const unsigned char *name;
458 + len = dtohd(dentry)->d_name.len;
459 + name = dtohd(dentry)->d_name.name;
460 + hidden_sto_dentry = lookup_one_len(name, dtohd2(dir), len);
461 + dtohd2(dentry) = hidden_sto_dentry;
464 + /* was: hidden_sto_dir_dentry = lock_parent(hidden_sto_dentry); */
465 + hidden_sto_dir_dentry = dget(hidden_sto_dentry->d_parent);
466 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
467 + mutex_lock(&hidden_sto_dir_dentry->d_inode->i_mutex);
469 + down(&hidden_sto_dir_dentry->d_inode->i_sem);
472 + if(dtohd2(dir) != hidden_sto_dir_dentry) {
473 + printk(KERN_CRIT "mini_fo: build_sto_structure: invalid parameter or meta data corruption [2].\n");
477 + /* check for errors in lock_parent */
478 + err = PTR_ERR(hidden_sto_dir_dentry);
479 + if(IS_ERR(hidden_sto_dir_dentry)) {
480 + printk(KERN_CRIT "mini_fo: build_sto_structure: lock_parent failed.\n");
484 + err = vfs_mkdir(hidden_sto_dir_dentry->d_inode,
486 + dir->d_inode->i_mode);
489 + printk(KERN_CRIT "mini_fo: build_sto_structure: failed to create storage dir [1].\n");
490 + /* was: unlock_dir(dir); */
491 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
492 + mutex_unlock(&dir->d_inode->i_mutex);
494 + up(&dir->d_inode->i_sem);
500 + /* everything ok! */
501 + if(!dtohd2(dentry)->d_inode) {
502 + printk(KERN_CRIT "mini_fo: build_sto_structure: failed to create storage dir [2].\n");
503 + /* was: unlock_dir(dir); */
504 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
505 + mutex_unlock(&dir->d_inode->i_mutex);
507 + up(&dir->d_inode->i_sem);
513 + /* interpose the new inode and set new state */
514 + itohi2(dentry->d_inode) = igrab(dtohd2(dentry)->d_inode);
515 + dtopd(dentry)->state = MODIFIED;
517 + /* initalize the wol list */
518 + itopd(dentry->d_inode)->deleted_list_size = -1;
519 + itopd(dentry->d_inode)->renamed_list_size = -1;
520 + meta_build_lists(dentry);
522 + fist_copy_attr_all(dentry->d_inode, itohi2(dentry->d_inode));
523 + fist_copy_attr_timesizes(dir->d_inode,
524 + hidden_sto_dir_dentry->d_inode);
525 + dir->d_inode->i_nlink++;
526 + /* was: unlock_dir(hidden_sto_dir_dentry); */
527 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
528 + mutex_unlock(&hidden_sto_dir_dentry->d_inode->i_mutex);
530 + up(&hidden_sto_dir_dentry->d_inode->i_sem);
532 + dput(hidden_sto_dir_dentry);
540 + * Read "len" bytes from "filename" into "buf".
541 + * "buf" is in kernel space.
544 +mini_fo_read_file(const char *filename, void *buf, int len)
547 + mm_segment_t oldfs;
549 + /* Chroot? Maybe NULL isn't right here */
550 + filp = filp_open(filename, O_RDONLY, 0);
551 + if (!filp || IS_ERR(filp)) {
552 + printk("mini_fo_read_file err %d\n", (int) PTR_ERR(filp));
553 + return -1; /* or do something else */
556 + if (!filp->f_op->read)
557 + return -2; /* file(system) doesn't allow reads */
559 + /* now read len bytes from offset 0 */
560 + filp->f_pos = 0; /* start offset */
563 + bytes = filp->f_op->read(filp, buf, len, &filp->f_pos);
566 + /* close the file */
575 + * Write "len" bytes from "buf" to "filename"
576 + * "buf" is in kernel space.
579 +mini_fo_write_file(const char *filename, void *buf, int len)
582 + mm_segment_t oldfs;
584 + /* Chroot? Maybe NULL isn't right here */
585 + filp = filp_open(filename, O_RDWR|O_CREAT, 0640);
586 + if (!filp || IS_ERR(filp)) {
587 + printk("mini_fo_write_file err %d\n", (int) PTR_ERR(filp));
588 + return -1; /* or do something else */
591 + if (!filp->f_op->write)
592 + return -2; /* file(system) doesn't allow writes */
594 + /* now write len bytes from offset 0 */
595 + filp->f_pos = 0; /* start offset */
598 + bytes = filp->f_op->write(filp, buf, len, &filp->f_pos);
601 + /* close the file */
609 diff -urN linux-2.6.21.1.old/fs/mini_fo/ChangeLog linux-2.6.21.1.dev/fs/mini_fo/ChangeLog
610 --- linux-2.6.21.1.old/fs/mini_fo/ChangeLog 1970-01-01 01:00:00.000000000 +0100
611 +++ linux-2.6.21.1.dev/fs/mini_fo/ChangeLog 2007-05-26 21:01:26.161330176 +0200
613 +2006-01-24 Markus Klotzbuecher <mk@mary.denx.de>
615 + * Add tons of ugly ifdefs to Ed L. Cashin's mutex patch to
616 + retain backwards compatibility.
618 +2006-01-24 Ed L. Cashin <ecashin@coraid.com>
620 + * Support for the new mutex infrastructure
621 + (7892f2f48d165a34b0b8130c8a195dfd807b8cb6)
623 +2005-10-15 Markus Klotzbuecher <mk@localhost.localdomain>
625 + * Bugfix for a serious memory leak in mini_fo_follow_link.
627 +2005-09-21 Markus Klotzbuecher <mk@mary>
629 + * new release 0.6.1
631 + * fix of a compiler warning due to changes in 2.6.13
633 +2005-09-21 Klaus Wenninger <klaus.wenninger@siemens.com>
635 + * file.c: readdir: fix for a bug that caused directory entries
636 + to show up twice when using storage filesystems such as
639 +2005-06-30 Eric Lammerts <eric@lammerts.org>
641 + * fix for an oops when overwriting a binary thats beeing
644 +2005-06-09 <mk@mary>
646 + * Renamed overlay to mini_fo-overlay.
648 + * Added mini_fo-merge script to allow merging of storage and base
649 + after making modifications.
651 +2005-05-22 root <mk@mary>
653 + * Added overlay script that allows to easily mount mini_fo ontop
654 + of a given base directory
656 +2005-05-10 <mk@mary>
658 + * inode.c: xattr functions return -EOPNOSUPP instead of
659 + -ENOSUPP, what confuses "ls -l"
661 + * Changed license from LGPL to GPL.
663 +2005-05-08 root <mk@mary>
665 + * Makefile: clean it up and added make install and make
668 +2005-05-06 <mk@mary>
670 + * merged devel branch back to main. [v0-6-0-pre3]
672 + * removed unused files print.c and fist_ioctl. [devel-0-0-18]
674 + * ioctl: removed fist_ioctl stuff, that is not needed for
677 +2005-05-03 <mk@mary>
679 + * file.c: simplified mini_fo_open and mini_fo_setattr using
680 + new state changing functions. [devel-0-0-17]
682 + * inode.c: Fixed getattr state bug (see below) in 2.4 function
683 + mini_fo_inode revalidate.
685 + * inode.c: found an other bug in mini_fo_getattr. States are not
686 + reliable in this function, as a file can be opened, unlinked and
687 + the getattr function called. This results in a deleted dentry
688 + with an inode. Fix is to ignore states and simply use the inode
691 +2005-04-29 <mk@mary>
693 + * file.c: Bugfix and cleanup in fasync and fsync. [devel-0-0-16]
695 + * file.c: do not use mini_fo_lock so the generic version is
698 + * inode.c: getattr, never call getattr on lower files, as this
699 + will cause the inum to change.
701 + * inode.c: rename_reg_file renamed to rename_nondir, as it
702 + doesn't matter as long it't not a dir. Removed all
703 + rename_dev_file etc.
705 + * tagged as devel-0-0-15
707 + * inode.c: added support for chosing support for extended
708 + attrs at compile time by XATTR define in mini_fo.h .
710 + * inode.c: fixed mini_fo_getattr to use mini_fo inode and not
711 + lower again, what avoids inode number changes that confused
712 + rm again. This is the proper solution.
714 +2005-04-24 <mk@mary>
716 + * all files: updated Copyright notive to 2005. [devel-0-0-14]
718 + * inode.c: fixed mini_fo_getattr to not change the inode
719 + number, even if lower files change.
721 + * super.c: fixed a bug that caused deleted base file to show
722 + up suddenly after some time, or after creating a special
723 + file. The problem was that after some time or after special
724 + file creating sync_sb_inodes is called by the vfs, that
725 + called our mini_fo_put_inode. There was (wrongly) called
726 + __meta_put_lists, that nuked the lists, although the inode
727 + was going to continue its life. Moving __meta_put_lists to
728 + mini_fo_clear_inode, where an inode is really destroyed,
729 + solved the problem.
732 +2005-04-23 <mk@mary>
734 + * state.c, aux.c: more cleaning up and
735 + simplifications. [devel-0-0-13]
737 + * inode.c: implemented mini_fo_getattr, that was required for
738 + 2.6 because inode_revalidate has been remove there, and the
739 + old "du" bug returned.
742 +2005-04-20 <mk@mary>
744 + * aux.c: get_neg_sto_dentry(): allow to be called for dentries
745 + in state UNMODIFIED, NON_EXISTANT _and_ DELETED.
747 +2005-04-19 <mk@mary>
749 + * Fixed a bug under 2.6 that caused files deleted via mini_fo
750 + not to be deleted properly and therefore the fs filled up
751 + untill no memory was left. [devel-0-0-12]
753 + * Added basic hard link support. This means that creating
754 + hardlinks will work, but existing ones will be treated as
755 + individual files. [devel-0-0-11]
757 +2005-04-17 <mk@mary>
761 +2005-04-13 root <mk@mary>
763 + * Added file state.c for the state transition
764 + functions. Doesn't work very well yet, though...
766 +2005-04-12 <mk@mary>
768 + * Porting to 2.6 started, which is easier than expected, also
769 + due to Olivier previous work.
771 +2005-04-08 <mk@mary>
773 + * Fixed the bug that caused du to return invalid sizes of
774 + directory trees. The problem was that
775 + mini_fo_inode_revalidate didn't always copy the attributes
776 + from the base inode properly.
778 +2005-04-01 Markus Klotzbuecher <mk@chasey>
780 + * Merged devel branch back to main trunk and updated the
781 + RELEASE notes. This will be 0-6-0-pre1.
783 +2005-03-31 Markus Klotzbuecher <mk@chasey>
785 + * Fixed some bugs in rename_reg_file, that only showed up in
786 + the kernel compile test. Kernel compiles cleanly ontop of
787 + mini_fo, now also make mrproper etc. work. Seems pretty stable.
789 +2005-03-28 Markus Klotzbuecher <mk@chasey>
791 + * Many, many directory renaming bugfixes and a lot of other
792 + cleanup. Dir renaming seems to work relatively stable.
794 +2005-03-22 Markus Klotzbuecher <mk@chasey>
796 + * Finished implementing lightweight directory renaming. Some
797 + basic testing indicates it works fine.
798 + Next is to implement testcases for the testsuite and confirm
799 + everything is really working ok.
801 +2005-03-18 Markus Klotzbuecher <mk@chasey>
803 + * Finished implementing meta.c stuff required for directory
806 +2005-03-17 Markus Klotzbuecher <mk@chasey>
808 + * Fixed all compile warnings + an extremly old bug that
809 + somehow crept in while reworking the wol stuff to the META
810 + system. Turning on -Werror again... :-)
812 + * Fixed some bugs in the new rename_reg_file function.
814 + * Rewrote mini_fo rename and split it into several
815 + subfunctions, that handle the different types
816 + seperately. Rewrote the regular file function aswell, as it
817 + was implemented somewhat inefficient.
819 +2005-03-16 Markus Klotzbuecher <mk@chasey>
821 + * Implemented new META subsystem, removed old WOL stuff in favor
824 + * After some basic testing everything seems ok...
826 +2005-03-11 Markus Klotzbuecher <mk@chasey>
828 + * Renaming a non regular file caused trouble because I always
829 + tried to copy the contents. Now I only do this for regular
830 + files. mini_fo_rename still isn't implemented properly, renaming
831 + of device files, symlinks etc. results in a empty regular file
832 + instead of the proper type.
834 + * Directory renaming suddenly works! What a surprise! I guess
835 + this is because renaming is implemented as making a copy and
836 + removing the original. Still this might not work
839 +2005-03-09 Markus Klotzbuecher <mk@chasey>
841 + * Bugfix, when a mini_fo directory that exists in storage
842 + (state: MODIFIED, CREATED and DEL_REWRITTEN) is deleted, a
843 + possibly existing WOL file contained in it needs to be
846 + * Starting cleanup: defined state names in order to get rid of
849 +2005-03-08 Markus Klotzbuecher <mk@chasey>
851 + * Makefile fix, fist_ioctl was built against wrong sources if ARCH=um
853 + * Fixed a bug in dentry.c, mini_fo_d_hash. In state 4 =
854 + DEL_REWRITTEN the hash was calculated from the base dentry,
855 + which was wrong and and caused assertions in
856 + __mini_fo_hidden_dentry to fail.
858 +2005-02-21 <mk@mary>
860 + * Implemented directory deleting (inode.c)
862 + * main.c: made mini_fo_parse_options a little more robust.
864 +2004-12-22 <mk@mary>
866 + * Makefile cleanup and uml stuff, removed unneccessary files
868 + * Created a new and hopefully more informative README
870 + * CHANGELOG: created a new CHANGELOG and added old entries reversely
873 +2004-10-24 Gleb Natapov <gleb@nbase.co.il>
875 + * Fix: owner and group where not correctly copied from base to
879 +2004-10-05 Gleb Natapov <gleb@nbase.co.il>
881 + * Implementation of fsync, fasync and lock mini_fo functions.
884 +2004-09-29 Bob Lee <bob@pantasys.com>
886 + * Fix of a serious pointer bug
889 +2004-09-28 Gleb Natapov <gleb@nbase.co.il>
891 + * Implementation of mini_fo_mknod and mini_fo_rename, support
894 diff -urN linux-2.6.21.1.old/fs/mini_fo/dentry.c linux-2.6.21.1.dev/fs/mini_fo/dentry.c
895 --- linux-2.6.21.1.old/fs/mini_fo/dentry.c 1970-01-01 01:00:00.000000000 +0100
896 +++ linux-2.6.21.1.dev/fs/mini_fo/dentry.c 2007-05-26 21:01:26.161330176 +0200
899 + * Copyright (c) 1997-2003 Erez Zadok
900 + * Copyright (c) 2001-2003 Stony Brook University
902 + * For specific licensing information, see the COPYING file distributed with
903 + * this package, or get one from ftp://ftp.filesystems.org/pub/fist/COPYING.
905 + * This Copyright notice must be kept intact and distributed with all
906 + * fistgen sources INCLUDING sources generated by fistgen.
909 + * Copyright (C) 2004, 2005 Markus Klotzbuecher <mk@creamnet.de>
911 + * This program is free software; you can redistribute it and/or
912 + * modify it under the terms of the GNU General Public License
913 + * as published by the Free Software Foundation; either version
914 + * 2 of the License, or (at your option) any later version.
921 +#ifdef HAVE_CONFIG_H
922 +# include <config.h>
926 +#include "mini_fo.h"
929 + * THIS IS A BOOLEAN FUNCTION: returns 1 if valid, 0 otherwise.
932 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
933 +mini_fo_d_revalidate(dentry_t *dentry, struct nameidata *nd)
935 +mini_fo_d_revalidate(dentry_t *dentry, int flags)
938 + int err1 = 1; /* valid = 1, invalid = 0 */
940 + dentry_t *hidden_dentry;
941 + dentry_t *hidden_sto_dentry;
944 + check_mini_fo_dentry(dentry);
946 + hidden_dentry = dtohd(dentry);
947 + hidden_sto_dentry = dtohd2(dentry);
949 + if(hidden_dentry &&
950 + hidden_dentry->d_op &&
951 + hidden_dentry->d_op->d_revalidate) {
952 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
953 + err1 = hidden_dentry->d_op->d_revalidate(hidden_dentry, nd);
955 + err1 = hidden_dentry->d_op->d_revalidate(hidden_dentry, flags);
958 + if(hidden_sto_dentry &&
959 + hidden_sto_dentry->d_op &&
960 + hidden_sto_dentry->d_op->d_revalidate) {
961 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
962 + err2 = hidden_sto_dentry->d_op->d_revalidate(hidden_sto_dentry,
965 + err2 = hidden_sto_dentry->d_op->d_revalidate(hidden_sto_dentry,
970 + /* mk: if one of the lower level dentries are valid,
971 + * the mini_fo dentry is too.
973 + return (err1 || err2);
978 +mini_fo_d_hash(dentry_t *dentry, qstr_t *name)
981 + dentry_t *hidden_dentry;
982 + dentry_t *hidden_sto_dentry;
984 + /* hidden_dentry = mini_fo_hidden_dentry(dentry);
985 + * hidden_sto_dentry = mini_fo_hidden_sto_dentry(dentry); */
987 + /* state 1, 3, 4, 5: build the hash for the storage dentry */
988 + if((dtopd(dentry)->state == MODIFIED) ||
989 + (dtopd(dentry)->state == CREATED) ||
990 + (dtopd(dentry)->state == DEL_REWRITTEN) ||
991 + (dtopd(dentry)->state == DELETED)) {
992 + hidden_sto_dentry = dtohd2(dentry);
993 + if(hidden_sto_dentry &&
994 + hidden_sto_dentry->d_op &&
995 + hidden_sto_dentry->d_op->d_hash) {
996 + err = hidden_sto_dentry->d_op->d_hash(hidden_sto_dentry, name);
1000 + /* state 2: build the hash for the base dentry */
1001 + if(dtopd(dentry)->state == UNMODIFIED) {
1002 + hidden_dentry = dtohd(dentry);
1003 + if(hidden_dentry &&
1004 + hidden_dentry->d_op &&
1005 + hidden_dentry->d_op->d_hash) {
1006 + err = hidden_dentry->d_op->d_hash(hidden_dentry, name);
1010 + /* state 6: build hash for the dentry that exists */
1011 + if(dtopd(dentry)->state == NON_EXISTANT) {
1012 + hidden_sto_dentry = dtohd2(dentry);
1013 + if(hidden_sto_dentry &&
1014 + hidden_sto_dentry->d_op &&
1015 + hidden_sto_dentry->d_op->d_hash) {
1016 + err = hidden_sto_dentry->d_op->d_hash(hidden_sto_dentry, name);
1019 + hidden_dentry = dtohd(dentry);
1020 + if(hidden_dentry &&
1021 + hidden_dentry->d_op &&
1022 + hidden_dentry->d_op->d_hash) {
1023 + err = hidden_dentry->d_op->d_hash(hidden_dentry, name);
1028 + printk(KERN_CRIT "mini_fo: d_hash: invalid state detected.\n");
1036 +mini_fo_d_compare(dentry_t *dentry, qstr_t *a, qstr_t *b)
1039 + dentry_t *hidden_dentry=NULL;
1041 + /* hidden_dentry = mini_fo_hidden_dentry(dentry); */
1042 + if(dtohd2(dentry))
1043 + hidden_dentry = dtohd2(dentry);
1044 + else if(dtohd(dentry))
1045 + hidden_dentry = dtohd(dentry);
1047 + if (hidden_dentry && hidden_dentry->d_op && hidden_dentry->d_op->d_compare) {
1048 + err = hidden_dentry->d_op->d_compare(hidden_dentry, a, b);
1050 + err = ((a->len != b->len) || memcmp(a->name, b->name, b->len));
1058 +mini_fo_d_delete(dentry_t *dentry)
1060 + dentry_t *hidden_dentry;
1061 + dentry_t *hidden_sto_dentry;
1064 + /* this could be a negative dentry, so check first */
1065 + if (!dtopd(dentry)) {
1066 + printk(KERN_CRIT "mini_fo_d_delete: negative dentry passed.\n");
1069 + hidden_dentry = dtohd(dentry);
1070 + hidden_sto_dentry = dtohd2(dentry);
1072 + if(hidden_dentry) {
1073 + if(hidden_dentry->d_op &&
1074 + hidden_dentry->d_op->d_delete) {
1075 + err = hidden_dentry->d_op->d_delete(hidden_dentry);
1078 + if(hidden_sto_dentry) {
1079 + if(hidden_sto_dentry->d_op &&
1080 + hidden_sto_dentry->d_op->d_delete) {
1081 + err = hidden_sto_dentry->d_op->d_delete(hidden_sto_dentry);
1091 +mini_fo_d_release(dentry_t *dentry)
1093 + dentry_t *hidden_dentry;
1094 + dentry_t *hidden_sto_dentry;
1097 + /* this could be a negative dentry, so check first */
1098 + if (!dtopd(dentry)) {
1099 + printk(KERN_CRIT "mini_fo_d_release: no private data.\n");
1102 + hidden_dentry = dtohd(dentry);
1103 + hidden_sto_dentry = dtohd2(dentry);
1105 + if(hidden_dentry) {
1106 + /* decrement hidden dentry's counter and free its inode */
1107 + dput(hidden_dentry);
1109 + if(hidden_sto_dentry) {
1110 + /* decrement hidden dentry's counter and free its inode */
1111 + dput(hidden_sto_dentry);
1114 + /* free private data (mini_fo_dentry_info) here */
1115 + kfree(dtopd(dentry));
1116 + __dtopd(dentry) = NULL; /* just to be safe */
1123 + * we don't really need mini_fo_d_iput, because dentry_iput will call iput() if
1124 + * mini_fo_d_iput is not defined. We left this implemented for ease of
1125 + * tracing/debugging.
1128 +mini_fo_d_iput(dentry_t *dentry, inode_t *inode)
1134 +struct dentry_operations mini_fo_dops = {
1135 + d_revalidate: mini_fo_d_revalidate,
1136 + d_hash: mini_fo_d_hash,
1137 + d_compare: mini_fo_d_compare,
1138 + d_release: mini_fo_d_release,
1139 + d_delete: mini_fo_d_delete,
1140 + d_iput: mini_fo_d_iput,
1142 diff -urN linux-2.6.21.1.old/fs/mini_fo/file.c linux-2.6.21.1.dev/fs/mini_fo/file.c
1143 --- linux-2.6.21.1.old/fs/mini_fo/file.c 1970-01-01 01:00:00.000000000 +0100
1144 +++ linux-2.6.21.1.dev/fs/mini_fo/file.c 2007-05-26 21:01:26.162330024 +0200
1147 + * Copyright (c) 1997-2003 Erez Zadok
1148 + * Copyright (c) 2001-2003 Stony Brook University
1150 + * For specific licensing information, see the COPYING file distributed with
1151 + * this package, or get one from ftp://ftp.filesystems.org/pub/fist/COPYING.
1153 + * This Copyright notice must be kept intact and distributed with all
1154 + * fistgen sources INCLUDING sources generated by fistgen.
1157 + * Copyright (C) 2004, 2005 Markus Klotzbuecher <mk@creamnet.de>
1159 + * This program is free software; you can redistribute it and/or
1160 + * modify it under the terms of the GNU General Public License
1161 + * as published by the Free Software Foundation; either version
1162 + * 2 of the License, or (at your option) any later version.
1169 +#ifdef HAVE_CONFIG_H
1170 +# include <config.h>
1174 +#include "mini_fo.h"
1175 +#define ROUND_UP(x) (((x)+sizeof(long)-1) & ~(sizeof(long)-1))
1177 +/*******************
1178 + * File Operations *
1179 + *******************/
1182 +mini_fo_llseek(file_t *file, loff_t offset, int origin)
1185 + file_t *hidden_file = NULL;
1187 + if(S_ISDIR(file->f_dentry->d_inode->i_mode)) {
1188 + /* Check if trying to llseek from a directory */
1192 + if (ftopd(file) != NULL) {
1193 + if(ftohf2(file)) {
1194 + hidden_file = ftohf2(file);
1196 + hidden_file = ftohf(file);
1200 + /* always set hidden position to this one */
1201 + hidden_file->f_pos = file->f_pos;
1203 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
1204 + memcpy(&(hidden_file->f_ra),
1206 + sizeof(struct file_ra_state));
1208 + if (file->f_reada) { /* update readahead information if needed */
1209 + hidden_file->f_reada = file->f_reada;
1210 + hidden_file->f_ramax = file->f_ramax;
1211 + hidden_file->f_raend = file->f_raend;
1212 + hidden_file->f_ralen = file->f_ralen;
1213 + hidden_file->f_rawin = file->f_rawin;
1216 + if (hidden_file->f_op && hidden_file->f_op->llseek)
1217 + err = hidden_file->f_op->llseek(hidden_file, offset, origin);
1219 + err = generic_file_llseek(hidden_file, offset, origin);
1224 + if (err != file->f_pos) {
1225 + file->f_pos = err;
1226 + // ION maybe this?
1227 + // file->f_pos = hidden_file->f_pos;
1228 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
1229 + file->f_reada = 0;
1231 + file->f_version++;
1239 +/* mk: fanout capable */
1241 +mini_fo_read(file_t *file, char *buf, size_t count, loff_t *ppos)
1243 + int err = -EINVAL;
1244 + file_t *hidden_file = NULL;
1245 + loff_t pos = *ppos;
1247 + if(S_ISDIR(file->f_dentry->d_inode->i_mode)) {
1248 + /* Check if trying to read from a directory */
1249 + /* printk(KERN_CRIT "mini_fo_read: ERROR: trying to read data from a directory.\n"); */
1254 + if (ftopd(file) != NULL) {
1255 + if(ftohf2(file)) {
1256 + hidden_file = ftohf2(file);
1258 + hidden_file = ftohf(file);
1262 + if (!hidden_file->f_op || !hidden_file->f_op->read)
1265 + err = hidden_file->f_op->read(hidden_file, buf, count, &pos);
1269 + /* atime should also be updated for reads of size zero or more */
1270 + fist_copy_attr_atime(file->f_dentry->d_inode,
1271 + hidden_file->f_dentry->d_inode);
1274 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
1277 + * because pread() does not have any way to tell us that it is
1278 + * our caller, then we don't know for sure if we have to update
1279 + * the file positions. This hack relies on read() having passed us
1280 + * the "real" pointer of its struct file's f_pos field.
1282 + if (ppos == &file->f_pos)
1283 + hidden_file->f_pos = *ppos = pos;
1284 + if (hidden_file->f_reada) { /* update readahead information if needed */
1285 + file->f_reada = hidden_file->f_reada;
1286 + file->f_ramax = hidden_file->f_ramax;
1287 + file->f_raend = hidden_file->f_raend;
1288 + file->f_ralen = hidden_file->f_ralen;
1289 + file->f_rawin = hidden_file->f_rawin;
1292 + memcpy(&(file->f_ra),&(hidden_file->f_ra),sizeof(struct file_ra_state));
1300 +/* this mini_fo_write() does not modify data pages! */
1302 +mini_fo_write(file_t *file, const char *buf, size_t count, loff_t *ppos)
1304 + int err = -EINVAL;
1305 + file_t *hidden_file = NULL;
1307 + inode_t *hidden_inode;
1308 + loff_t pos = *ppos;
1310 + /* mk: fan out: */
1311 + if (ftopd(file) != NULL) {
1312 + if(ftohf2(file)) {
1313 + hidden_file = ftohf2(file);
1315 + /* This is bad! We have no storage file to write to. This
1316 + * should never happen because if a file is opened for
1317 + * writing, a copy should have been made earlier.
1319 + printk(KERN_CRIT "mini_fo: write : ERROR, no storage file to write.\n");
1325 + inode = file->f_dentry->d_inode;
1326 + hidden_inode = itohi2(inode);
1327 + if(!hidden_inode) {
1328 + printk(KERN_CRIT "mini_fo: write: no sto inode found, not good.\n");
1332 + if (!hidden_file->f_op || !hidden_file->f_op->write)
1335 + /* adjust for append -- seek to the end of the file */
1336 + if (file->f_flags & O_APPEND)
1337 + pos = inode->i_size;
1339 + err = hidden_file->f_op->write(hidden_file, buf, count, &pos);
1342 + * copy ctime and mtime from lower layer attributes
1343 + * atime is unchanged for both layers
1346 + fist_copy_attr_times(inode, hidden_inode);
1349 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
1353 + * because pwrite() does not have any way to tell us that it is
1354 + * our caller, then we don't know for sure if we have to update
1355 + * the file positions. This hack relies on write() having passed us
1356 + * the "real" pointer of its struct file's f_pos field.
1358 + if (ppos == &file->f_pos)
1359 + hidden_file->f_pos = *ppos = pos;
1361 + /* update this inode's size */
1362 + if (pos > inode->i_size)
1363 + inode->i_size = pos;
1369 +/* Global variable to hold a file_t pointer.
1370 + * This serves to allow mini_fo_filldir function to know which file is
1371 + * beeing read, which is required for two reasons:
1373 + * - be able to call wol functions in order to avoid listing deleted
1375 + * - if we're reading a directory which is in state 1, we need to
1376 + * maintain a list (in mini_fo_filldir) of which files allready
1377 + * have been copied to userspace,to detect files existing in base
1378 + * and storage and not list them twice.
1380 +filldir_t mini_fo_filldir_orig;
1381 +file_t *mini_fo_filldir_file;
1383 +/* mainly copied from fs/readdir.c */
1385 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,18)
1386 +mini_fo_filldir(void * __buf, const char * name, int namlen, loff_t offset,
1387 + u64 ino, unsigned int d_type)
1389 +mini_fo_filldir(void * __buf, const char * name, int namlen, loff_t offset,
1390 + ino_t ino, unsigned int d_type)
1393 + struct getdents_callback * buf = (struct getdents_callback *) __buf;
1394 + file_t* file = mini_fo_filldir_file;
1396 + /* In theses states we filter meta files in storage (WOL) */
1397 + if(file && (dtopd(file->f_dentry)->state == MODIFIED ||
1398 + dtopd(file->f_dentry)->state == CREATED ||
1399 + dtopd(file->f_dentry)->state == DEL_REWRITTEN)) {
1401 + int tmp = strlen(META_FILENAME);
1402 + if(tmp == namlen) {
1403 + if(!strncmp(name, META_FILENAME, namlen))
1408 + /* check if we are merging the contents of storage and base */
1409 + if(file && dtopd(file->f_dentry)->state == MODIFIED) {
1410 + /* check if we are still reading storage contents, if
1411 + * yes, we just save the name of the file for duplicate
1412 + * checking later. */
1414 + if(!ftopd(file)->rd.sto_done) {
1415 + /* put file into ndl list */
1416 + if(ndl_add_entry(&ftopd(file)->rd, name, namlen))
1417 + printk(KERN_CRIT "mini_fo_filldir: Error adding to ndl.\n");
1419 + /* check if file has been deleted */
1420 + if(meta_check_d_entry(file->f_dentry, name, namlen))
1423 + /* do duplicate checking */
1424 + if(ndl_check_entry(&ftopd(file)->rd, name, namlen))
1429 + return mini_fo_filldir_orig(buf, name, namlen, offset, ino, d_type);
1434 +mini_fo_readdir(file_t *file, void *dirent, filldir_t filldir)
1436 + int err = 0;/* mk: ??? -ENOTDIR; */
1437 + file_t *hidden_file = NULL;
1438 + file_t *hidden_sto_file = NULL;
1440 + struct getdents_callback *buf;
1443 +#if defined(FIST_FILTER_NAME) || defined(FIST_FILTER_SCA)
1444 + struct mini_fo_getdents_callback buf;
1445 +#endif /* FIST_FILTER_NAME || FIST_FILTER_SCA */
1447 + buf = (struct getdents_callback *) dirent;
1448 + oldcount = buf->count;
1449 + inode = file->f_dentry->d_inode;
1450 + mini_fo_filldir_file = file;
1451 + mini_fo_filldir_orig = filldir;
1453 + ftopd(file)->rd.sto_done = 0;
1455 + if (ftopd(file) != NULL) {
1456 + if(ftohf2(file)) {
1457 + hidden_sto_file = ftohf2(file);
1458 + err = vfs_readdir(hidden_sto_file, mini_fo_filldir, dirent);
1459 + file->f_pos = hidden_sto_file->f_pos;
1461 + fist_copy_attr_atime(inode, hidden_sto_file->f_dentry->d_inode);
1462 + /* not finshed yet, we'll be called again */
1463 + if (buf->count != oldcount)
1467 + ftopd(file)->rd.sto_done = 1;
1470 + hidden_file = ftohf(file);
1471 + err = vfs_readdir(hidden_file, mini_fo_filldir, dirent);
1472 + file->f_pos = hidden_file->f_pos;
1474 + fist_copy_attr_atime(inode, hidden_file->f_dentry->d_inode);
1481 + * we need to check if all the directory data has been copied to userspace,
1482 + * or if we will be called again by userspace to complete the operation.
1484 + if(buf->count == oldcount) {
1485 + ndl_put_list(&ftopd(file)->rd);
1488 + /* unset this, safe */
1489 + mini_fo_filldir_file = NULL;
1494 +STATIC unsigned int
1495 +mini_fo_poll(file_t *file, poll_table *wait)
1497 + unsigned int mask = DEFAULT_POLLMASK;
1498 + file_t *hidden_file = NULL;
1500 + if (ftopd(file) != NULL) {
1501 + if(ftohf2(file)) {
1502 + hidden_file = ftohf2(file);
1504 + hidden_file = ftohf(file);
1508 + if (!hidden_file->f_op || !hidden_file->f_op->poll)
1511 + mask = hidden_file->f_op->poll(hidden_file, wait);
1517 +/* FIST-LITE special version of mmap */
1519 +mini_fo_mmap(file_t *file, vm_area_t *vma)
1522 + file_t *hidden_file = NULL;
1524 + /* fanout capability */
1525 + if (ftopd(file) != NULL) {
1526 + if(ftohf2(file)) {
1527 + hidden_file = ftohf2(file);
1529 + hidden_file = ftohf(file);
1533 + ASSERT(hidden_file != NULL);
1534 + ASSERT(hidden_file->f_op != NULL);
1535 + ASSERT(hidden_file->f_op->mmap != NULL);
1537 + vma->vm_file = hidden_file;
1538 + err = hidden_file->f_op->mmap(hidden_file, vma);
1539 + get_file(hidden_file); /* make sure it doesn't get freed on us */
1540 + fput(file); /* no need to keep extra ref on ours */
1548 +mini_fo_open(inode_t *inode, file_t *file)
1552 + file_t *hidden_file = NULL;
1553 + dentry_t *hidden_dentry = NULL;
1555 + /* fanout stuff */
1556 + file_t *hidden_sto_file = NULL;
1557 + dentry_t *hidden_sto_dentry = NULL;
1560 + kmalloc(sizeof(struct mini_fo_file_info), GFP_KERNEL);
1561 + if (!ftopd(file)) {
1566 + /* init the readdir_helper structure */
1567 + INIT_LIST_HEAD(&ftopd(file)->rd.ndl_list);
1568 + ftopd(file)->rd.ndl_size = 0;
1570 + /* In certain paths this could stay uninitalized and cause trouble */
1571 + ftohf(file) = NULL;
1572 + ftohf2(file) = NULL;
1573 + hidden_flags = file->f_flags;
1575 + /* create storage files? */
1576 + if(dtost(file->f_dentry) == UNMODIFIED) {
1577 + if(!IS_WRITE_FLAG(file->f_flags)) {
1578 + hidden_dentry = dtohd(file->f_dentry);
1579 + dget(hidden_dentry);
1580 + /* dentry_open will decrement mnt refcnt if err.
1581 + * otherwise fput() will do an mntput() for us upon file close. */
1582 + mntget(stopd(inode->i_sb)->hidden_mnt);
1583 + hidden_file = dentry_open(hidden_dentry,
1584 + stopd(inode->i_sb)->hidden_mnt,
1586 + if (IS_ERR(hidden_file)) {
1587 + err = PTR_ERR(hidden_file);
1588 + dput(hidden_dentry);
1591 + ftohf(file) = hidden_file; /* link two files */
1595 + if(S_ISDIR(file->f_dentry->d_inode->i_mode)) {
1596 + err = dir_unmod_to_mod(file->f_dentry);
1598 + err = nondir_unmod_to_mod(file->f_dentry, 1);
1601 + printk("mini_fo_open: ERROR creating storage file.\n");
1606 + hidden_sto_dentry = dtohd2(file->f_dentry);
1607 + dget(hidden_sto_dentry);
1609 + if(dtopd(file->f_dentry)->state == MODIFIED) {
1610 + /* Directorys are special, interpose on both lower level files */
1611 + if(S_ISDIR(itohi(inode)->i_mode)) {
1612 + /* check for invalid file types of lower level files */
1613 + if(!(S_ISDIR(itohi(inode)->i_mode) && S_ISDIR(itohi2(inode)->i_mode))) {
1614 + printk(KERN_CRIT "mini_fo_open: meta data corruption detected.\n");
1615 + dput(hidden_sto_dentry);
1620 + /* lower level directorys are ok, open the base file */
1621 + hidden_dentry = dtohd(file->f_dentry);
1622 + dget(hidden_dentry);
1624 + mntget(stopd(inode->i_sb)->hidden_mnt);
1625 + hidden_file = dentry_open(hidden_dentry,
1626 + stopd(inode->i_sb)->hidden_mnt,
1628 + if (IS_ERR(hidden_file)) {
1629 + err = PTR_ERR(hidden_file);
1630 + dput(hidden_dentry);
1631 + dput(hidden_sto_dentry);
1634 + ftohf(file) = hidden_file; /* link the two files */
1638 + if(!exists_in_storage(file->f_dentry)) {
1639 + printk(KERN_CRIT "mini_fo_open: invalid file state detected.\n");
1641 + dput(hidden_sto_dentry);
1643 + /* If the base file has been opened, we need to close it here */
1645 + if (hidden_file->f_op && hidden_file->f_op->flush)
1646 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,18)
1647 + hidden_file->f_op->flush(hidden_file, NULL);
1649 + hidden_file->f_op->flush(hidden_file);
1651 + dput(hidden_dentry);
1656 + /* ok, now we can safely open the storage file */
1657 + mntget(stopd(inode->i_sb)->hidden_mnt2);
1658 + hidden_sto_file = dentry_open(hidden_sto_dentry,
1659 + stopd(inode->i_sb)->hidden_mnt2,
1662 + /* dentry_open dputs the dentry if it fails */
1663 + if (IS_ERR(hidden_sto_file)) {
1664 + err = PTR_ERR(hidden_sto_file);
1665 + /* close base file if open */
1667 + if (hidden_file->f_op && hidden_file->f_op->flush)
1668 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,18)
1669 + hidden_file->f_op->flush(hidden_file, NULL);
1671 + hidden_file->f_op->flush(hidden_file);
1673 + dput(hidden_dentry);
1677 + ftohf2(file) = hidden_sto_file; /* link storage file */
1680 + if (err < 0 && ftopd(file)) {
1681 + kfree(ftopd(file));
1687 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,18)
1688 +mini_fo_flush(file_t *file, fl_owner_t id)
1690 +mini_fo_flush(file_t *file)
1693 + int err1 = 0; /* assume ok (see open.c:close_fp) */
1695 + file_t *hidden_file = NULL;
1697 + check_mini_fo_file(file);
1699 + /* mk: we don't do any state checking here, as its not worth the time.
1700 + * Just flush the lower level files if they exist.
1702 + if(ftopd(file) != NULL) {
1703 + if(ftohf(file) != NULL) {
1704 + hidden_file = ftohf(file);
1705 + if (hidden_file->f_op && hidden_file->f_op->flush)
1706 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,18)
1707 + err1 = hidden_file->f_op->flush(hidden_file, id);
1709 + err1 = hidden_file->f_op->flush(hidden_file);
1712 + if(ftohf2(file) != NULL) {
1713 + hidden_file = ftohf2(file);
1714 + if (hidden_file->f_op && hidden_file->f_op->flush)
1715 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,18)
1716 + err2 = hidden_file->f_op->flush(hidden_file, id);
1718 + err2 = hidden_file->f_op->flush(hidden_file);
1722 + return (err1 | err2);
1727 +mini_fo_release(inode_t *inode, file_t *file)
1730 + file_t *hidden_file = NULL;
1732 + if (ftopd(file) != NULL) {
1734 + hidden_file = ftohf(file);
1735 + fput(hidden_file);
1737 + if(ftohf2(file)) {
1738 + hidden_file = ftohf2(file);
1739 + fput(hidden_file);
1741 + kfree(ftopd(file));
1747 +mini_fo_fsync(file_t *file, dentry_t *dentry, int datasync)
1751 + file_t *hidden_file = NULL;
1752 + dentry_t *hidden_dentry;
1754 + check_mini_fo_file(file);
1756 + if ((hidden_file = ftohf(file)) != NULL) {
1757 + hidden_dentry = dtohd(dentry);
1758 + if (hidden_file->f_op && hidden_file->f_op->fsync) {
1759 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
1760 + mutex_lock(&hidden_dentry->d_inode->i_mutex);
1762 + down(&hidden_dentry->d_inode->i_sem);
1764 + err1 = hidden_file->f_op->fsync(hidden_file, hidden_dentry, datasync);
1765 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
1766 + mutex_unlock(&hidden_dentry->d_inode->i_mutex);
1768 + up(&hidden_dentry->d_inode->i_sem);
1773 + if ((hidden_file = ftohf2(file)) != NULL) {
1774 + hidden_dentry = dtohd2(dentry);
1775 + if (hidden_file->f_op && hidden_file->f_op->fsync) {
1776 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
1777 + mutex_lock(&hidden_dentry->d_inode->i_mutex);
1779 + down(&hidden_dentry->d_inode->i_sem);
1781 + err2 = hidden_file->f_op->fsync(hidden_file, hidden_dentry, datasync);
1782 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
1783 + mutex_unlock(&hidden_dentry->d_inode->i_mutex);
1785 + up(&hidden_dentry->d_inode->i_sem);
1793 + return (err1 || err2);
1798 +mini_fo_fasync(int fd, file_t *file, int flag)
1803 + file_t *hidden_file = NULL;
1805 + check_mini_fo_file(file);
1807 + if((hidden_file = ftohf(file)) != NULL) {
1808 + err1 = hidden_file->f_op->fasync(fd, hidden_file, flag);
1810 + if((hidden_file = ftohf2(file)) != NULL) {
1811 + err2 = hidden_file->f_op->fasync(fd, hidden_file, flag);
1814 + return (err1 || err2);
1819 +struct file_operations mini_fo_dir_fops =
1821 + read: generic_read_dir,
1822 + write: mini_fo_write,
1823 + readdir: mini_fo_readdir,
1824 + poll: mini_fo_poll,
1825 + /* ioctl: mini_fo_ioctl, */
1826 + mmap: mini_fo_mmap,
1827 + open: mini_fo_open,
1828 + flush: mini_fo_flush,
1829 + release: mini_fo_release,
1830 + fsync: mini_fo_fsync,
1831 + fasync: mini_fo_fasync,
1832 + /* not needed lock: mini_fo_lock, */
1833 + /* not needed: readv */
1834 + /* not needed: writev */
1835 + /* not implemented: sendpage */
1836 + /* not implemented: get_unmapped_area */
1839 +struct file_operations mini_fo_main_fops =
1841 + llseek: mini_fo_llseek,
1842 + read: mini_fo_read,
1843 + write: mini_fo_write,
1844 + readdir: mini_fo_readdir,
1845 + poll: mini_fo_poll,
1846 + /* ioctl: mini_fo_ioctl, */
1847 + mmap: mini_fo_mmap,
1848 + open: mini_fo_open,
1849 + flush: mini_fo_flush,
1850 + release: mini_fo_release,
1851 + fsync: mini_fo_fsync,
1852 + fasync: mini_fo_fasync,
1853 + /* not needed: lock: mini_fo_lock, */
1854 + /* not needed: readv */
1855 + /* not needed: writev */
1856 + /* not implemented: sendpage */
1857 + /* not implemented: get_unmapped_area */
1859 diff -urN linux-2.6.21.1.old/fs/mini_fo/fist.h linux-2.6.21.1.dev/fs/mini_fo/fist.h
1860 --- linux-2.6.21.1.old/fs/mini_fo/fist.h 1970-01-01 01:00:00.000000000 +0100
1861 +++ linux-2.6.21.1.dev/fs/mini_fo/fist.h 2007-05-26 21:01:26.162330024 +0200
1864 + * Copyright (c) 1997-2003 Erez Zadok
1865 + * Copyright (c) 2001-2003 Stony Brook University
1867 + * For specific licensing information, see the COPYING file distributed with
1868 + * this package, or get one from ftp://ftp.filesystems.org/pub/fist/COPYING.
1870 + * This Copyright notice must be kept intact and distributed with all
1871 + * fistgen sources INCLUDING sources generated by fistgen.
1874 + * Copyright (C) 2004, 2005 Markus Klotzbuecher <mk@creamnet.de>
1876 + * This program is free software; you can redistribute it and/or
1877 + * modify it under the terms of the GNU General Public License
1878 + * as published by the Free Software Foundation; either version
1879 + * 2 of the License, or (at your option) any later version.
1891 + * KERNEL ONLY CODE:
1894 +#include <linux/version.h>
1895 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,19)
1896 +#include <linux/autoconf.h>
1898 +#include <linux/config.h>
1900 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
1901 +#ifdef CONFIG_MODVERSIONS
1902 +# define MODVERSIONS
1903 +# include <linux/modversions.h>
1904 +#endif /* CONFIG_MODVERSIONS */
1905 +#endif /* KERNEL_VERSION < 2.6.0 */
1906 +#include <linux/sched.h>
1907 +#include <linux/kernel.h>
1908 +#include <linux/mm.h>
1909 +#include <linux/string.h>
1910 +#include <linux/stat.h>
1911 +#include <linux/errno.h>
1912 +#include <linux/wait.h>
1913 +#include <linux/limits.h>
1914 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
1915 +#include <linux/locks.h>
1917 +#include <linux/buffer_head.h>
1918 +#include <linux/pagemap.h>
1919 +#include <linux/namei.h>
1920 +#include <linux/module.h>
1921 +#include <linux/mount.h>
1922 +#include <linux/page-flags.h>
1923 +#include <linux/writeback.h>
1924 +#include <linux/statfs.h>
1926 +#include <linux/smp.h>
1927 +#include <linux/smp_lock.h>
1928 +#include <linux/file.h>
1929 +#include <linux/slab.h>
1930 +#include <linux/vmalloc.h>
1931 +#include <linux/poll.h>
1932 +#include <linux/list.h>
1933 +#include <linux/init.h>
1935 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,20)
1936 +#include <linux/xattr.h>
1939 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
1940 +#include <linux/security.h>
1943 +#include <linux/swap.h>
1945 +#include <asm/system.h>
1946 +#include <asm/segment.h>
1947 +#include <asm/mman.h>
1948 +#include <linux/seq_file.h>
1954 +/* those mapped to ATTR_* were copied from linux/fs.h */
1955 +#define FA_MODE ATTR_MODE
1956 +#define FA_UID ATTR_UID
1957 +#define FA_GID ATTR_GID
1958 +#define FA_SIZE ATTR_SIZE
1959 +#define FA_ATIME ATTR_ATIME
1960 +#define FA_MTIME ATTR_MTIME
1961 +#define FA_CTIME ATTR_CTIME
1962 +#define FA_ATIME_SET ATTR_ATIME_SET
1963 +#define FA_MTIME_SET ATTR_MTIME_SET
1964 +#define FA_FORCE ATTR_FORCE
1965 +#define FA_ATTR_FLAGS ATTR_ATTR_FLAG
1967 +/* must be greater than all other ATTR_* flags! */
1968 +#define FA_NLINK 2048
1969 +#define FA_BLKSIZE 4096
1970 +#define FA_BLOCKS 8192
1971 +#define FA_TIMES (FA_ATIME|FA_MTIME|FA_CTIME)
1974 +/* macros to manage changes between kernels */
1975 +#define INODE_DATA(i) (&(i)->i_data)
1977 +#define MIN(x,y) ((x < y) ? (x) : (y))
1978 +#define MAX(x,y) ((x > y) ? (x) : (y))
1979 +#define MAXPATHLEN PATH_MAX
1981 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,4,5)
1982 +# define lookup_one_len(a,b,c) lookup_one(a,b)
1983 +#endif /* LINUX_VERSION_CODE < KERNEL_VERSION(2,4,5) */
1985 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,4,8)
1986 +# define generic_file_llseek default_llseek
1987 +#endif /* LINUX_VERSION_CODE < KERNEL_VERSION(2,4,8) */
1990 +# define SEEK_SET 0
1991 +#endif /* not SEEK_SET */
1994 +# define SEEK_CUR 1
1995 +#endif /* not SEEK_CUR */
1998 +# define SEEK_END 2
1999 +#endif /* not SEEK_END */
2001 +#ifndef DEFAULT_POLLMASK
2002 +# define DEFAULT_POLLMASK (POLLIN | POLLOUT | POLLRDNORM | POLLWRNORM)
2003 +#endif /* not DEFAULT_POLLMASK */
2005 +/* XXX: fix this so fistgen generates kfree() code directly */
2006 +#define kfree_s(a,b) kfree(a)
2011 +typedef struct dentry dentry_t;
2012 +typedef struct file file_t;
2013 +typedef struct inode inode_t;
2014 +typedef inode_t vnode_t;
2015 +typedef struct page page_t;
2016 +typedef struct qstr qstr_t;
2017 +typedef struct super_block super_block_t;
2018 +typedef super_block_t vfs_t;
2019 +typedef struct vm_area_struct vm_area_t;
2026 +#define FPPF(str,page) printk("PPF %s 0x%x/%d: Lck:%d Err:%d Ref:%d Upd:%d Other::%d:%d:%d:%d:\n", \
2029 + (int) page->index, \
2030 + (PageLocked(page) ? 1 : 0), \
2031 + (PageError(page) ? 1 : 0), \
2032 + (PageReferenced(page) ? 1 : 0), \
2033 + (Page_Uptodate(page) ? 1 : 0), \
2034 + (PageDecrAfter(page) ? 1 : 0), \
2035 + (PageSlab(page) ? 1 : 0), \
2036 + (PageSwapCache(page) ? 1 : 0), \
2037 + (PageReserved(page) ? 1 : 0) \
2039 +#define EZKDBG printk("EZK %s:%d:%s\n",__FILE__,__LINE__,__FUNCTION__)
2041 +# define EZKDBG1 printk("EZK %s:%d\n",__FILE__,__LINE__)
2046 +extern int fist_get_debug_value(void);
2047 +extern int fist_set_debug_value(int val);
2048 +#if 0 /* mini_fo doesn't need these */
2049 +extern void fist_dprint_internal(int level, char *str,...);
2050 +extern void fist_print_dentry(char *str, const dentry_t *dentry);
2051 +extern void fist_print_inode(char *str, const inode_t *inode);
2052 +extern void fist_print_file(char *str, const file_t *file);
2053 +extern void fist_print_buffer_flags(char *str, struct buffer_head *buffer);
2054 +extern void fist_print_page_flags(char *str, page_t *page);
2055 +extern void fist_print_page_bytes(char *str, page_t *page);
2056 +extern void fist_print_pte_flags(char *str, const page_t *page);
2057 +extern void fist_checkinode(inode_t *inode, char *msg);
2058 +extern void fist_print_sb(char *str, const super_block_t *sb);
2060 +/* §$% by mk: special debug functions */
2061 +extern void fist_mk_print_dentry(char *str, const dentry_t *dentry);
2062 +extern void fist_mk_print_inode(char *str, const inode_t *inode);
2064 +extern char *add_indent(void);
2065 +extern char *del_indent(void);
2066 +#endif/* mini_fo doesn't need these */
2070 +#define ASSERT(EX) \
2073 + printk(KERN_CRIT "ASSERTION FAILED: %s at %s:%d (%s)\n", #EX, \
2074 + __FILE__, __LINE__, __FUNCTION__); \
2075 + (*((char *)0))=0; \
2078 +/* same ASSERT, but tell me who was the caller of the function */
2079 +#define ASSERT2(EX) \
2082 + printk(KERN_CRIT "ASSERTION FAILED (caller): %s at %s:%d (%s)\n", #EX, \
2083 + file, line, func); \
2084 + (*((char *)0))=0; \
2088 +#if 0 /* mini_fo doesn't need these */
2089 +#define dprintk(format, args...) printk(KERN_DEBUG format, ##args)
2090 +#define fist_dprint(level, str, args...) fist_dprint_internal(level, KERN_DEBUG str, ## args)
2091 +#define print_entry_location() fist_dprint(4, "%sIN: %s %s:%d\n", add_indent(), __FUNCTION__, __FILE__, __LINE__)
2092 +#define print_exit_location() fist_dprint(4, "%s OUT: %s %s:%d\n", del_indent(), __FUNCTION__, __FILE__, __LINE__)
2093 +#define print_exit_status(status) fist_dprint(4, "%s OUT: %s %s:%d, STATUS: %d\n", del_indent(), __FUNCTION__, __FILE__, __LINE__, status)
2094 +#define print_exit_pointer(status) \
2096 + if (IS_ERR(status)) \
2097 + fist_dprint(4, "%s OUT: %s %s:%d, RESULT: %ld\n", del_indent(), __FUNCTION__, __FILE__, __LINE__, PTR_ERR(status)); \
2099 + fist_dprint(4, "%s OUT: %s %s:%d, RESULT: 0x%x\n", del_indent(), __FUNCTION__, __FILE__, __LINE__, PTR_ERR(status)); \
2101 +#endif/* mini_fo doesn't need these */
2103 +#endif /* __KERNEL__ */
2107 + * DEFINITIONS FOR USER AND KERNEL CODE:
2108 + * (Note: ioctl numbers 1--9 are reserved for fistgen, the rest
2109 + * are auto-generated automatically based on the user's .fist file.)
2111 +# define FIST_IOCTL_GET_DEBUG_VALUE _IOR(0x15, 1, int)
2112 +# define FIST_IOCTL_SET_DEBUG_VALUE _IOW(0x15, 2, int)
2114 +#endif /* not __FIST_H_ */
2115 diff -urN linux-2.6.21.1.old/fs/mini_fo/inode.c linux-2.6.21.1.dev/fs/mini_fo/inode.c
2116 --- linux-2.6.21.1.old/fs/mini_fo/inode.c 1970-01-01 01:00:00.000000000 +0100
2117 +++ linux-2.6.21.1.dev/fs/mini_fo/inode.c 2007-05-26 21:01:26.164329720 +0200
2120 + * Copyright (c) 1997-2003 Erez Zadok
2121 + * Copyright (c) 2001-2003 Stony Brook University
2123 + * For specific licensing information, see the COPYING file distributed with
2124 + * this package, or get one from ftp://ftp.filesystems.org/pub/fist/COPYING.
2126 + * This Copyright notice must be kept intact and distributed with all
2127 + * fistgen sources INCLUDING sources generated by fistgen.
2130 + * Copyright (C) 2004, 2005 Markus Klotzbuecher <mk@creamnet.de>
2132 + * This program is free software; you can redistribute it and/or
2133 + * modify it under the terms of the GNU General Public License
2134 + * as published by the Free Software Foundation; either version
2135 + * 2 of the License, or (at your option) any later version.
2142 +#ifdef HAVE_CONFIG_H
2143 +# include <config.h>
2147 +#include "mini_fo.h"
2150 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
2151 +mini_fo_create(inode_t *dir, dentry_t *dentry, int mode, struct nameidata *nd)
2153 +mini_fo_create(inode_t *dir, dentry_t *dentry, int mode)
2158 + check_mini_fo_dentry(dentry);
2160 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
2161 + err = create_sto_reg_file(dentry, mode, nd);
2163 + err = create_sto_reg_file(dentry, mode);
2165 + check_mini_fo_dentry(dentry);
2171 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
2172 +mini_fo_lookup(inode_t *dir, dentry_t *dentry, struct nameidata* nd)
2174 +mini_fo_lookup(inode_t *dir, dentry_t *dentry)
2178 + dentry_t *hidden_dir_dentry;
2179 + dentry_t *hidden_dentry = NULL;
2181 + dentry_t *hidden_sto_dir_dentry;
2182 + dentry_t *hidden_sto_dentry = NULL;
2184 + /* whiteout flag */
2186 + char *bpath = NULL;
2189 + unsigned int namelen;
2191 + /* Don't allow lookups of META-files */
2192 + namelen = strlen(META_FILENAME);
2193 + if(namelen == dentry->d_name.len) {
2194 + if(!strncmp(dentry->d_name.name, META_FILENAME, namelen)) {
2200 + hidden_dir_dentry = dtohd(dentry->d_parent);
2201 + hidden_sto_dir_dentry = dtohd2(dentry->d_parent);
2203 + name = dentry->d_name.name;
2204 + namelen = dentry->d_name.len;
2206 + /* must initialize dentry operations */
2207 + dentry->d_op = &mini_fo_dops;
2209 + /* setup the del_flag */
2210 + del_flag = __meta_check_d_entry(dir, name, namelen);
2211 + bpath = __meta_check_r_entry(dir, name, namelen);
2213 + /* perform the lookups of base and storage files:
2215 + * This caused some serious trouble, as a lookup_one_len passing
2216 + * a negative dentry oopses. Solution is to only do the lookup
2217 + * if the dentry is positive, else we set it to NULL
2218 + * More trouble, who said a *_dir_dentry can't be NULL?
2221 + /* Cross-Interposing (C), yeah! */
2222 + hidden_dentry = bpath_walk(dir->i_sb, bpath);
2223 + if(!hidden_dentry || !hidden_dentry->d_inode) {
2224 + printk(KERN_CRIT "mini_fo_lookup: bpath_walk failed.\n");
2229 + /* this can be set up safely without fear of spaghetti
2230 + * interposing as it is only used for copying times */
2231 + hidden_dir_dentry = hidden_dentry->d_parent;
2234 + else if(hidden_dir_dentry && hidden_dir_dentry->d_inode)
2236 + lookup_one_len(name, hidden_dir_dentry, namelen);
2238 + hidden_dentry = NULL;
2240 + if(hidden_sto_dir_dentry && hidden_sto_dir_dentry->d_inode)
2241 + hidden_sto_dentry =
2242 + lookup_one_len(name, hidden_sto_dir_dentry, namelen);
2244 + hidden_sto_dentry = NULL;
2246 + /* catch error in lookup */
2247 + if (IS_ERR(hidden_dentry) || IS_ERR(hidden_sto_dentry)) {
2248 + /* mk: we need to call dput on the dentry, whose
2249 + * lookup_one_len operation failed, in order to avoid
2250 + * unmount trouble.
2252 + if(IS_ERR(hidden_dentry)) {
2253 + printk(KERN_CRIT "mini_fo_lookup: ERR from base dentry, lookup failed.\n");
2254 + err = PTR_ERR(hidden_dentry);
2256 + dput(hidden_dentry);
2258 + if(IS_ERR(hidden_sto_dentry)) {
2259 + printk(KERN_CRIT "mini_fo_lookup: ERR from storage dentry, lookup failed.\n");
2260 + err = PTR_ERR(hidden_sto_dentry);
2262 + dput(hidden_sto_dentry);
2267 + /* allocate dentry private data */
2268 + __dtopd(dentry) = (struct mini_fo_dentry_info *)
2269 + kmalloc(sizeof(struct mini_fo_dentry_info), GFP_KERNEL);
2271 + if (!dtopd(dentry)) {
2276 + /* check for different states of the mini_fo file to be looked up. */
2278 + /* state 1, file has been modified */
2279 + if(hidden_dentry && hidden_sto_dentry &&
2280 + hidden_dentry->d_inode && hidden_sto_dentry->d_inode && !del_flag) {
2282 + /* update parent directory's atime */
2283 + fist_copy_attr_atime(dir, hidden_sto_dir_dentry->d_inode);
2285 + dtopd(dentry)->state = MODIFIED;
2286 + dtohd(dentry) = hidden_dentry;
2287 + dtohd2(dentry) = hidden_sto_dentry;
2289 + err = mini_fo_tri_interpose(hidden_dentry,
2290 + hidden_sto_dentry,
2291 + dentry, dir->i_sb, 1);
2293 + printk(KERN_CRIT "mini_fo_lookup: error interposing (state1).\n");
2298 + /* state 2, file is unmodified */
2299 + if(hidden_dentry && hidden_dentry->d_inode && !del_flag) {
2301 + fist_copy_attr_atime(dir, hidden_dir_dentry->d_inode);
2303 + dtopd(dentry)->state = UNMODIFIED;
2304 + dtohd(dentry) = hidden_dentry;
2305 + dtohd2(dentry) = hidden_sto_dentry; /* could be negative */
2307 + err = mini_fo_tri_interpose(hidden_dentry,
2308 + hidden_sto_dentry,
2309 + dentry, dir->i_sb, 1);
2311 + printk(KERN_CRIT "mini_fo_lookup: error interposing (state2).\n");
2316 + /* state 3, file has been newly created */
2317 + if(hidden_sto_dentry && hidden_sto_dentry->d_inode && !del_flag) {
2319 + fist_copy_attr_atime(dir, hidden_sto_dir_dentry->d_inode);
2320 + dtopd(dentry)->state = CREATED;
2321 + dtohd(dentry) = hidden_dentry; /* could be negative */
2322 + dtohd2(dentry) = hidden_sto_dentry;
2324 + err = mini_fo_tri_interpose(hidden_dentry,
2325 + hidden_sto_dentry,
2326 + dentry, dir->i_sb, 1);
2328 + printk(KERN_CRIT "mini_fo_lookup: error interposing (state3).\n");
2334 + /* state 4, file has deleted and created again. */
2335 + if(hidden_dentry && hidden_sto_dentry &&
2336 + hidden_dentry->d_inode &&
2337 + hidden_sto_dentry->d_inode && del_flag) {
2339 + fist_copy_attr_atime(dir, hidden_sto_dir_dentry->d_inode);
2340 + dtopd(dentry)->state = DEL_REWRITTEN;
2341 + dtohd(dentry) = NULL;
2342 + dtohd2(dentry) = hidden_sto_dentry;
2344 + err = mini_fo_tri_interpose(NULL,
2345 + hidden_sto_dentry,
2346 + dentry, dir->i_sb, 1);
2348 + printk(KERN_CRIT "mini_fo_lookup: error interposing (state4).\n");
2351 + /* We will never need this dentry again, as the file has been
2352 + * deleted from base */
2353 + dput(hidden_dentry);
2356 + /* state 5, file has been deleted in base */
2357 + if(hidden_dentry && hidden_sto_dentry &&
2358 + hidden_dentry->d_inode &&
2359 + !hidden_sto_dentry->d_inode && del_flag) {
2361 + /* check which parents atime we need for updating */
2362 + if(hidden_sto_dir_dentry->d_inode)
2363 + fist_copy_attr_atime(dir,
2364 + hidden_sto_dir_dentry->d_inode);
2366 + fist_copy_attr_atime(dir,
2367 + hidden_dir_dentry->d_inode);
2369 + dtopd(dentry)->state = DELETED;
2370 + dtohd(dentry) = NULL;
2371 + dtohd2(dentry) = hidden_sto_dentry;
2373 + /* add negative dentry to dcache to speed up lookups */
2374 + d_add(dentry, NULL);
2375 + dput(hidden_dentry);
2378 + /* state 6, file does not exist */
2379 + if(((hidden_dentry && !hidden_dentry->d_inode) ||
2380 + (hidden_sto_dentry && !hidden_sto_dentry->d_inode)) && !del_flag)
2382 + /* check which parents atime we need for updating */
2383 + if(hidden_sto_dir_dentry && hidden_sto_dir_dentry->d_inode)
2384 + fist_copy_attr_atime(dir, hidden_sto_dir_dentry->d_inode);
2386 + fist_copy_attr_atime(dir, hidden_dir_dentry->d_inode);
2388 + dtopd(dentry)->state = NON_EXISTANT;
2389 + dtohd(dentry) = hidden_dentry;
2390 + dtohd2(dentry) = hidden_sto_dentry;
2391 + d_add(dentry, NULL);
2395 + /* if we get to here, were in an invalid state. bad. */
2396 + printk(KERN_CRIT "mini_fo_lookup: ERROR, meta data corruption detected.\n");
2398 + /* end state checking */
2400 + d_drop(dentry); /* so that our bad dentry will get destroyed */
2401 + kfree(dtopd(dentry));
2402 + __dtopd(dentry) = NULL; /* be safe */
2406 + dput(hidden_dentry);
2407 + if(hidden_sto_dentry)
2408 + dput(hidden_sto_dentry); /* drops usage count and marks for release */
2411 + /* initalize wol if file exists and is directory */
2412 + if(dentry->d_inode) {
2413 + if(S_ISDIR(dentry->d_inode->i_mode)) {
2414 + itopd(dentry->d_inode)->deleted_list_size = -1;
2415 + itopd(dentry->d_inode)->renamed_list_size = -1;
2416 + meta_build_lists(dentry);
2419 + return ERR_PTR(err);
2424 +mini_fo_link(dentry_t *old_dentry, inode_t *dir, dentry_t *new_dentry)
2427 + dentry_t *hidden_old_dentry;
2428 + dentry_t *hidden_new_dentry;
2429 + dentry_t *hidden_dir_dentry;
2432 + check_mini_fo_dentry(old_dentry);
2433 + check_mini_fo_dentry(new_dentry);
2434 + check_mini_fo_inode(dir);
2436 + /* no links to directorys and existing targets target allowed */
2437 + if(S_ISDIR(old_dentry->d_inode->i_mode) ||
2438 + is_mini_fo_existant(new_dentry)) {
2443 + /* bring it directly from unmod to del_rew */
2444 + if(dtost(old_dentry) == UNMODIFIED) {
2445 + err = nondir_unmod_to_mod(old_dentry, 1);
2450 + err = meta_add_d_entry(old_dentry->d_parent,
2451 + old_dentry->d_name.name,
2452 + old_dentry->d_name.len);
2457 + dput(dtohd(old_dentry));
2458 + dtohd(old_dentry) = NULL;
2459 + dtost(old_dentry) = DEL_REWRITTEN;
2462 + err = get_neg_sto_dentry(new_dentry);
2468 + hidden_old_dentry = dtohd2(old_dentry);
2469 + hidden_new_dentry = dtohd2(new_dentry);
2471 + dget(hidden_old_dentry);
2472 + dget(hidden_new_dentry);
2474 + /* was: hidden_dir_dentry = lock_parent(hidden_new_dentry); */
2475 + hidden_dir_dentry = dget(hidden_new_dentry->d_parent);
2476 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
2477 + mutex_lock(&hidden_dir_dentry->d_inode->i_mutex);
2479 + down(&hidden_dir_dentry->d_inode->i_sem);
2482 + err = vfs_link(hidden_old_dentry,
2483 + hidden_dir_dentry->d_inode,
2484 + hidden_new_dentry);
2485 + if (err || !hidden_new_dentry->d_inode)
2488 + dtost(new_dentry) = CREATED;
2489 + err = mini_fo_tri_interpose(NULL, hidden_new_dentry, new_dentry, dir->i_sb, 0);
2493 + fist_copy_attr_timesizes(dir, hidden_new_dentry->d_inode);
2494 + /* propagate number of hard-links */
2495 + old_dentry->d_inode->i_nlink = itohi2(old_dentry->d_inode)->i_nlink;
2498 + /* was: unlock_dir(hidden_dir_dentry); */
2499 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
2500 + mutex_unlock(&hidden_dir_dentry->d_inode->i_mutex);
2502 + up(&hidden_dir_dentry->d_inode->i_sem);
2504 + dput(hidden_dir_dentry);
2506 + dput(hidden_new_dentry);
2507 + dput(hidden_old_dentry);
2508 + if (!new_dentry->d_inode)
2509 + d_drop(new_dentry);
2517 +mini_fo_unlink(inode_t *dir, dentry_t *dentry)
2522 + if(dtopd(dentry)->state == MODIFIED) {
2523 + err = nondir_mod_to_del(dentry);
2526 + else if(dtopd(dentry)->state == UNMODIFIED) {
2527 + err = nondir_unmod_to_del(dentry);
2530 + else if(dtopd(dentry)->state == CREATED) {
2531 + err = nondir_creat_to_del(dentry);
2534 + else if(dtopd(dentry)->state == DEL_REWRITTEN) {
2535 + err = nondir_del_rew_to_del(dentry);
2539 + printk(KERN_CRIT "mini_fo_unlink: ERROR, invalid state detected.\n");
2542 + fist_copy_attr_times(dir, itohi2(dentry->d_parent->d_inode));
2545 + /* is this causing my pain? d_delete(dentry); */
2555 +mini_fo_symlink(inode_t *dir, dentry_t *dentry, const char *symname)
2558 + dentry_t *hidden_sto_dentry;
2559 + dentry_t *hidden_sto_dir_dentry;
2560 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
2564 + /* Fail if the symlink file exists */
2565 + if(!(dtost(dentry) == DELETED ||
2566 + dtost(dentry) == NON_EXISTANT)) {
2571 + err = get_neg_sto_dentry(dentry);
2576 + hidden_sto_dentry = dtohd2(dentry);
2578 + dget(hidden_sto_dentry);
2579 + /* was: hidden_sto_dir_dentry = lock_parent(hidden_sto_dentry); */
2580 + hidden_sto_dir_dentry = dget(hidden_sto_dentry->d_parent);
2581 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
2582 + mutex_lock(&hidden_sto_dir_dentry->d_inode->i_mutex);
2584 + down(&hidden_sto_dir_dentry->d_inode->i_sem);
2587 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
2589 + err = vfs_symlink(hidden_sto_dir_dentry->d_inode,
2590 + hidden_sto_dentry, symname, mode);
2592 + err = vfs_symlink(hidden_sto_dir_dentry->d_inode,
2593 + hidden_sto_dentry,
2596 + if (err || !hidden_sto_dentry->d_inode)
2599 + if(dtost(dentry) == DELETED) {
2600 + dtost(dentry) = DEL_REWRITTEN;
2601 + err = mini_fo_tri_interpose(NULL, hidden_sto_dentry, dentry, dir->i_sb, 0);
2604 + } else if(dtost(dentry) == NON_EXISTANT) {
2605 + dtost(dentry) = CREATED;
2606 + err = mini_fo_tri_interpose(dtohd(dentry), hidden_sto_dentry, dentry, dir->i_sb, 0);
2610 + fist_copy_attr_timesizes(dir, hidden_sto_dir_dentry->d_inode);
2613 + /* was: unlock_dir(hidden_sto_dir_dentry); */
2614 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
2615 + mutex_unlock(&hidden_sto_dir_dentry->d_inode->i_mutex);
2617 + up(&hidden_sto_dir_dentry->d_inode->i_sem);
2619 + dput(hidden_sto_dir_dentry);
2621 + dput(hidden_sto_dentry);
2622 + if (!dentry->d_inode)
2629 +mini_fo_mkdir(inode_t *dir, dentry_t *dentry, int mode)
2633 + err = create_sto_dir(dentry, mode);
2635 + check_mini_fo_dentry(dentry);
2642 +mini_fo_rmdir(inode_t *dir, dentry_t *dentry)
2646 + dentry_t *hidden_sto_dentry;
2647 + dentry_t *hidden_sto_dir_dentry;
2648 + dentry_t *meta_dentry;
2649 + inode_t *hidden_sto_dir = NULL;
2651 + check_mini_fo_dentry(dentry);
2652 + check_mini_fo_inode(dir);
2655 + if(dtopd(dentry)->state == MODIFIED) {
2656 + /* XXX: disabled, because it does not bother to check files on
2657 + * the original filesystem - just a hack, but better than simply
2658 + * removing it without testing */
2662 + hidden_sto_dir = itohi2(dir);
2663 + hidden_sto_dentry = dtohd2(dentry);
2665 + /* was:hidden_sto_dir_dentry = lock_parent(hidden_sto_dentry); */
2666 + hidden_sto_dir_dentry = dget(hidden_sto_dentry->d_parent);
2667 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
2668 + mutex_lock(&hidden_sto_dir_dentry->d_inode->i_mutex);
2670 + down(&hidden_sto_dir_dentry->d_inode->i_sem);
2673 + /* avoid destroying the hidden inode if the file is in use */
2674 + dget(hidden_sto_dentry);
2676 + /* Delete an old WOL file contained in the storage dir */
2677 + meta_dentry = lookup_one_len(META_FILENAME,
2678 + hidden_sto_dentry,
2679 + strlen(META_FILENAME));
2680 + if(meta_dentry->d_inode) {
2681 + err = vfs_unlink(hidden_sto_dentry->d_inode, meta_dentry);
2682 + dput(meta_dentry);
2684 + d_delete(meta_dentry);
2687 + err = vfs_rmdir(hidden_sto_dir, hidden_sto_dentry);
2688 + dput(hidden_sto_dentry);
2690 + d_delete(hidden_sto_dentry);
2692 + /* propagate number of hard-links */
2693 + dentry->d_inode->i_nlink = itohi2(dentry->d_inode)->i_nlink;
2695 + dput(dtohd(dentry));
2697 + dtohd(dentry) = NULL;
2698 + dtopd(dentry)->state = DELETED;
2700 + /* carefull with R files */
2701 + if( __meta_is_r_entry(dir,
2702 + dentry->d_name.name,
2703 + dentry->d_name.len) == 1) {
2704 + err = meta_remove_r_entry(dentry->d_parent,
2705 + dentry->d_name.name,
2706 + dentry->d_name.len);
2708 + printk(KERN_CRIT "mini_fo: rmdir: meta_remove_r_entry failed.\n");
2713 + /* ok, add deleted file to META */
2714 + meta_add_d_entry(dentry->d_parent,
2715 + dentry->d_name.name,
2716 + dentry->d_name.len);
2718 + /* was: unlock_dir(hidden_sto_dir_dentry); */
2719 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
2720 + mutex_unlock(&hidden_sto_dir_dentry->d_inode->i_mutex);
2722 + up(&hidden_sto_dir_dentry->d_inode->i_sem);
2724 + dput(hidden_sto_dir_dentry);
2727 + else if(dtopd(dentry)->state == UNMODIFIED) {
2728 + /* XXX: simply adding it to the delete list here is fscking dangerous!
2729 + * as a temporary hack, i will disable rmdir on unmodified directories
2735 + err = get_neg_sto_dentry(dentry);
2741 + /* dput base dentry, this will relase the inode and free the
2742 + * dentry, as we will never need it again. */
2743 + dput(dtohd(dentry));
2744 + dtohd(dentry) = NULL;
2745 + dtopd(dentry)->state = DELETED;
2747 + /* add deleted file to META-file */
2748 + meta_add_d_entry(dentry->d_parent,
2749 + dentry->d_name.name,
2750 + dentry->d_name.len);
2753 + else if(dtopd(dentry)->state == CREATED) {
2754 + hidden_sto_dir = itohi2(dir);
2755 + hidden_sto_dentry = dtohd2(dentry);
2757 + /* was: hidden_sto_dir_dentry = lock_parent(hidden_sto_dentry);*/
2758 + hidden_sto_dir_dentry = dget(hidden_sto_dentry->d_parent);
2760 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
2761 + mutex_lock(&hidden_sto_dir_dentry->d_inode->i_mutex);
2763 + down(&hidden_sto_dir_dentry->d_inode->i_sem);
2766 + /* avoid destroying the hidden inode if the file is in use */
2767 + dget(hidden_sto_dentry);
2769 + /* Delete an old WOL file contained in the storage dir */
2770 + meta_dentry = lookup_one_len(META_FILENAME,
2771 + hidden_sto_dentry,
2772 + strlen(META_FILENAME));
2773 + if(meta_dentry->d_inode) {
2774 + /* is this necessary? dget(meta_dentry); */
2775 + err = vfs_unlink(hidden_sto_dentry->d_inode,
2777 + dput(meta_dentry);
2779 + d_delete(meta_dentry);
2782 + err = vfs_rmdir(hidden_sto_dir, hidden_sto_dentry);
2783 + dput(hidden_sto_dentry);
2785 + d_delete(hidden_sto_dentry);
2787 + /* propagate number of hard-links */
2788 + dentry->d_inode->i_nlink = itohi2(dentry->d_inode)->i_nlink;
2789 + dtopd(dentry)->state = NON_EXISTANT;
2791 + /* was: unlock_dir(hidden_sto_dir_dentry); */
2792 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
2793 + mutex_unlock(&hidden_sto_dir_dentry->d_inode->i_mutex);
2795 + up(&hidden_sto_dir_dentry->d_inode->i_sem);
2797 + dput(hidden_sto_dir_dentry);
2801 + else if(dtopd(dentry)->state == DEL_REWRITTEN) {
2802 + hidden_sto_dir = itohi2(dir);
2803 + hidden_sto_dentry = dtohd2(dentry);
2805 + /* was: hidden_sto_dir_dentry = lock_parent(hidden_sto_dentry);*/
2806 + hidden_sto_dir_dentry = dget(hidden_sto_dentry->d_parent);
2808 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
2809 + mutex_lock(&hidden_sto_dir_dentry->d_inode->i_mutex);
2811 + down(&hidden_sto_dir_dentry->d_inode->i_sem);
2814 + /* avoid destroying the hidden inode if the file is in use */
2815 + dget(hidden_sto_dentry);
2817 + /* Delete an old WOL file contained in the storage dir */
2818 + meta_dentry = lookup_one_len(META_FILENAME,
2819 + hidden_sto_dentry,
2820 + strlen(META_FILENAME));
2821 + if(meta_dentry->d_inode) {
2822 + /* is this necessary? dget(meta_dentry); */
2823 + err = vfs_unlink(hidden_sto_dentry->d_inode,
2825 + dput(meta_dentry);
2827 + d_delete(meta_dentry);
2830 + err = vfs_rmdir(hidden_sto_dir, hidden_sto_dentry);
2831 + dput(hidden_sto_dentry);
2833 + d_delete(hidden_sto_dentry);
2835 + /* propagate number of hard-links */
2836 + dentry->d_inode->i_nlink = itohi2(dentry->d_inode)->i_nlink;
2837 + dtopd(dentry)->state = DELETED;
2838 + /* was: unlock_dir(hidden_sto_dir_dentry); */
2840 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
2841 + mutex_unlock(&hidden_sto_dir_dentry->d_inode->i_mutex);
2843 + up(&hidden_sto_dir_dentry->d_inode->i_sem);
2845 + dput(hidden_sto_dir_dentry);
2849 + printk(KERN_CRIT "mini_fo_rmdir: ERROR, invalid state detected.\n");
2856 + fist_copy_attr_times(dir, itohi2(dentry->d_parent->d_inode));
2864 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
2865 +mini_fo_mknod(inode_t *dir, dentry_t *dentry, int mode, dev_t dev)
2867 +mini_fo_mknod(inode_t *dir, dentry_t *dentry, int mode, int dev)
2872 + check_mini_fo_dentry(dentry);
2874 + err = create_sto_nod(dentry, mode, dev);
2876 + printk(KERN_CRIT "mini_fo_mknod: creating sto nod failed.\n");
2880 + check_mini_fo_dentry(dentry);
2886 +mini_fo_rename(inode_t *old_dir, dentry_t *old_dentry,
2887 + inode_t *new_dir, dentry_t *new_dentry)
2890 + if(S_ISDIR(old_dentry->d_inode->i_mode))
2891 + return rename_directory(old_dir, old_dentry, new_dir, new_dentry);
2892 + return rename_nondir(old_dir, old_dentry, new_dir, new_dentry);
2896 +int rename_directory(inode_t *old_dir, dentry_t *old_dentry,
2897 + inode_t *new_dir, dentry_t *new_dentry)
2899 + int err, bpath_len;
2902 + dentry_t *hidden_old_dentry;
2903 + dentry_t *hidden_new_dentry;
2904 + dentry_t *hidden_old_dir_dentry;
2905 + dentry_t *hidden_new_dir_dentry;
2911 + /* this is a test, chuck out if it works */
2912 + if(!(dtopd(new_dentry)->state == DELETED ||
2913 + dtopd(new_dentry)->state == NON_EXISTANT)) {
2914 + printk(KERN_CRIT "mini_fo: rename_directory: \
2915 + uh, ah, new_dentry not negative.\n");
2919 + /* state = UNMODIFIED */
2920 + if(dtopd(old_dentry)->state == UNMODIFIED) {
2921 + err = dir_unmod_to_mod(old_dentry);
2926 + /* state = MODIFIED */
2927 + if(dtopd(old_dentry)->state == MODIFIED) {
2928 + bpath = meta_check_r_entry(old_dentry->d_parent,
2929 + old_dentry->d_name.name,
2930 + old_dentry->d_name.len);
2932 + err = meta_remove_r_entry(old_dentry->d_parent,
2933 + old_dentry->d_name.name,
2934 + old_dentry->d_name.len);
2936 + printk(KERN_CRIT "mini_fo: rename_directory:\
2937 + meta_remove_r_entry \
2941 + err = meta_add_r_entry(new_dentry->d_parent,
2944 + new_dentry->d_name.name,
2945 + new_dentry->d_name.len);
2948 + else {/* wol it */
2949 + err = meta_add_d_entry(old_dentry->d_parent,
2950 + old_dentry->d_name.name,
2951 + old_dentry->d_name.len);
2954 + /* put it on rename list */
2955 + err = get_mini_fo_bpath(old_dentry,
2960 + err = meta_add_r_entry(new_dentry->d_parent,
2962 + new_dentry->d_name.name,
2963 + new_dentry->d_name.len);
2967 + /* no state change, MODIFIED stays MODIFIED */
2969 + /* state = CREATED */
2970 + if(dtopd(old_dentry)->state == CREATED ||
2971 + dtopd(old_dentry)->state == DEL_REWRITTEN) {
2972 + if(dtohd(old_dentry))
2973 + dput(dtohd(old_dentry));
2975 + if(dtopd(new_dentry)->state == DELETED) {
2976 + dtopd(old_dentry)->state = DEL_REWRITTEN;
2977 + dtohd(old_dentry) = NULL;
2979 + else if(dtopd(new_dentry)->state == NON_EXISTANT) {
2980 + dtopd(old_dentry)->state = CREATED;
2981 + /* steal new dentry's neg. base dentry */
2982 + dtohd(old_dentry) = dtohd(new_dentry);
2983 + dtohd(new_dentry) = NULL;
2986 + if(dtopd(new_dentry)->state == UNMODIFIED ||
2987 + dtopd(new_dentry)->state == NON_EXISTANT) {
2988 + err = get_neg_sto_dentry(new_dentry);
2993 + /* now move sto file */
2994 + hidden_old_dentry = dtohd2(old_dentry);
2995 + hidden_new_dentry = dtohd2(new_dentry);
2997 + dget(hidden_old_dentry);
2998 + dget(hidden_new_dentry);
3000 + hidden_old_dir_dentry = dget(hidden_old_dentry->d_parent);
3001 + hidden_new_dir_dentry = dget(hidden_new_dentry->d_parent);
3002 + double_lock(hidden_old_dir_dentry, hidden_new_dir_dentry);
3004 + err = vfs_rename(hidden_old_dir_dentry->d_inode, hidden_old_dentry,
3005 + hidden_new_dir_dentry->d_inode, hidden_new_dentry);
3009 + fist_copy_attr_all(new_dir, hidden_new_dir_dentry->d_inode);
3010 + if (new_dir != old_dir)
3011 + fist_copy_attr_all(old_dir,
3012 + hidden_old_dir_dentry->d_inode);
3015 + /* double_unlock will dput the new/old parent dentries
3016 + * whose refcnts were incremented via get_parent above. */
3017 + double_unlock(hidden_old_dir_dentry, hidden_new_dir_dentry);
3018 + dput(hidden_new_dentry);
3019 + dput(hidden_old_dentry);
3025 +int rename_nondir(inode_t *old_dir, dentry_t *old_dentry,
3026 + inode_t *new_dir, dentry_t *new_dentry)
3030 + check_mini_fo_dentry(old_dentry);
3031 + check_mini_fo_dentry(new_dentry);
3032 + check_mini_fo_inode(old_dir);
3033 + check_mini_fo_inode(new_dir);
3035 + /* state: UNMODIFIED */
3036 + if(dtost(old_dentry) == UNMODIFIED) {
3037 + err = nondir_unmod_to_mod(old_dentry, 1);
3044 + /* the easy states */
3045 + if(exists_in_storage(old_dentry)) {
3047 + dentry_t *hidden_old_dentry;
3048 + dentry_t *hidden_new_dentry;
3049 + dentry_t *hidden_old_dir_dentry;
3050 + dentry_t *hidden_new_dir_dentry;
3052 + /* if old file is MODIFIED, add it to the deleted_list */
3053 + if(dtopd(old_dentry)->state == MODIFIED) {
3054 + meta_add_d_entry(old_dentry->d_parent,
3055 + old_dentry->d_name.name,
3056 + old_dentry->d_name.len);
3058 + dput(dtohd(old_dentry));
3060 + /* if old file is CREATED, we only release the base dentry */
3061 + if(dtopd(old_dentry)->state == CREATED) {
3062 + if(dtohd(old_dentry))
3063 + dput(dtohd(old_dentry));
3066 + /* now setup the new states (depends on new_dentry state) */
3067 + /* new dentry state = MODIFIED */
3068 + if(dtopd(new_dentry)->state == MODIFIED) {
3069 + meta_add_d_entry(new_dentry->d_parent,
3070 + new_dentry->d_name.name,
3071 + new_dentry->d_name.len);
3073 + /* new dentry will be d_put'ed later by the vfs
3074 + * so don't do it here
3075 + * dput(dtohd(new_dentry));
3077 + dtohd(old_dentry) = NULL;
3078 + dtopd(old_dentry)->state = DEL_REWRITTEN;
3080 + /* new dentry state = UNMODIFIED */
3081 + else if(dtopd(new_dentry)->state == UNMODIFIED) {
3082 + if(get_neg_sto_dentry(new_dentry))
3085 + meta_add_d_entry(new_dentry->d_parent,
3086 + new_dentry->d_name.name,
3087 + new_dentry->d_name.len);
3089 + /* is this right??? */
3090 + /*dput(dtohd(new_dentry));*/
3091 + dtohd(old_dentry) = NULL;
3092 + dtopd(old_dentry)->state = DEL_REWRITTEN;
3094 + /* new dentry state = CREATED */
3095 + else if(dtopd(new_dentry)->state == CREATED) {
3096 + /* we keep the neg. base dentry (if exists) */
3097 + dtohd(old_dentry) = dtohd(new_dentry);
3098 + /* ...and set it to Null, or we'll get
3099 + * dcache.c:345 if it gets dput twice... */
3100 + dtohd(new_dentry) = NULL;
3101 + dtopd(old_dentry)->state = CREATED;
3103 + /* new dentry state = NON_EXISTANT */
3104 + else if(dtopd(new_dentry)->state == NON_EXISTANT) {
3105 + if(get_neg_sto_dentry(new_dentry))
3108 + /* we keep the neg. base dentry (if exists) */
3109 + dtohd(old_dentry) = dtohd(new_dentry);
3110 + /* ...and set it to Null, or we'll get
3111 + * Dr. dcache.c:345 if it gets dput twice... */
3112 + dtohd(new_dentry) = NULL;
3113 + dtopd(old_dentry)->state = CREATED;
3115 + /* new dentry state = DEL_REWRITTEN or DELETED */
3116 + else if(dtopd(new_dentry)->state == DEL_REWRITTEN ||
3117 + dtopd(new_dentry)->state == DELETED) {
3118 + dtohd(old_dentry) = NULL;
3119 + dtopd(old_dentry)->state = DEL_REWRITTEN;
3121 + else { /* not possible, uhh, ahh */
3123 + "mini_fo: rename_reg_file: invalid state detected [1].\n");
3127 + /* now we definitely have a sto file */
3128 + hidden_old_dentry = dtohd2(old_dentry);
3129 + hidden_new_dentry = dtohd2(new_dentry);
3131 + dget(hidden_old_dentry);
3132 + dget(hidden_new_dentry);
3134 + hidden_old_dir_dentry = dget(hidden_old_dentry->d_parent);
3135 + hidden_new_dir_dentry = dget(hidden_new_dentry->d_parent);
3136 + double_lock(hidden_old_dir_dentry, hidden_new_dir_dentry);
3138 + err = vfs_rename(hidden_old_dir_dentry->d_inode,
3139 + hidden_old_dentry,
3140 + hidden_new_dir_dentry->d_inode,
3141 + hidden_new_dentry);
3145 + fist_copy_attr_all(new_dir, hidden_new_dir_dentry->d_inode);
3146 + if (new_dir != old_dir)
3147 + fist_copy_attr_all(old_dir, hidden_old_dir_dentry->d_inode);
3150 + /* double_unlock will dput the new/old parent dentries
3151 + * whose refcnts were incremented via get_parent above.
3153 + double_unlock(hidden_old_dir_dentry, hidden_new_dir_dentry);
3154 + dput(hidden_new_dentry);
3155 + dput(hidden_old_dentry);
3159 + else { /* invalid state */
3160 + printk(KERN_CRIT "mini_fo: rename_reg_file: ERROR: invalid state detected [2].\n");
3167 +mini_fo_readlink(dentry_t *dentry, char *buf, int bufsiz)
3170 + dentry_t *hidden_dentry = NULL;
3172 + if(dtohd2(dentry) && dtohd2(dentry)->d_inode) {
3173 + hidden_dentry = dtohd2(dentry);
3174 + } else if(dtohd(dentry) && dtohd(dentry)->d_inode) {
3175 + hidden_dentry = dtohd(dentry);
3180 + if (!hidden_dentry->d_inode->i_op ||
3181 + !hidden_dentry->d_inode->i_op->readlink) {
3182 + err = -EINVAL; goto out;
3185 + err = hidden_dentry->d_inode->i_op->readlink(hidden_dentry,
3189 + fist_copy_attr_atime(dentry->d_inode, hidden_dentry->d_inode);
3196 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,13)
3197 +static int mini_fo_follow_link(dentry_t *dentry, struct nameidata *nd)
3199 +static void* mini_fo_follow_link(dentry_t *dentry, struct nameidata *nd)
3203 + int len = PAGE_SIZE, err;
3204 + mm_segment_t old_fs;
3206 + /* in 2.6 this is freed by mini_fo_put_link called by __do_follow_link */
3207 + buf = kmalloc(len, GFP_KERNEL);
3213 + /* read the symlink, and then we will follow it */
3214 + old_fs = get_fs();
3215 + set_fs(KERNEL_DS);
3216 + err = dentry->d_inode->i_op->readlink(dentry, buf, len);
3224 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
3225 + nd_set_link(nd, buf);
3228 + err = vfs_follow_link(nd, buf);
3232 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
3236 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,13)
3239 + return ERR_PTR(err);
3244 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
3245 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,13)
3246 +void mini_fo_put_link(struct dentry *dentry, struct nameidata *nd)
3248 +void mini_fo_put_link(struct dentry *dentry, struct nameidata *nd, void *cookie)
3252 + link = nd_get_link(nd);
3258 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
3259 +mini_fo_permission(inode_t *inode, int mask, struct nameidata *nd)
3261 +mini_fo_permission(inode_t *inode, int mask)
3264 + inode_t *hidden_inode;
3268 + if(itohi2(inode)) {
3269 + hidden_inode = itohi2(inode);
3271 + hidden_inode = itohi(inode);
3273 + mode = inode->i_mode;
3275 + /* not really needed, as permission handles everything:
3276 + * err = vfs_permission(inode, mask);
3281 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
3282 + err = permission(hidden_inode, mask, nd);
3284 + err = permission(hidden_inode, mask);
3291 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
3293 +mini_fo_inode_revalidate(dentry_t *dentry)
3296 + dentry_t *hidden_dentry;
3297 + inode_t *hidden_inode;
3299 + ASSERT(dentry->d_inode);
3300 + ASSERT(itopd(dentry->d_inode));
3302 + if(itohi2(dentry->d_inode)) {
3303 + hidden_dentry = dtohd2(dentry);
3304 + hidden_inode = hidden_dentry->d_inode;
3305 + } else if(itohi(dentry->d_inode)) {
3306 + hidden_dentry = dtohd(dentry);
3307 + hidden_inode = hidden_dentry->d_inode;
3309 + printk(KERN_CRIT "mini_fo_inode_revalidate: ERROR, invalid state detected.\n");
3313 + if (hidden_inode && hidden_inode->i_op && hidden_inode->i_op->revalidate){
3314 + err = hidden_inode->i_op->revalidate(hidden_dentry);
3318 + fist_copy_attr_all(dentry->d_inode, hidden_inode);
3325 +mini_fo_setattr(dentry_t *dentry, struct iattr *ia)
3329 + check_mini_fo_dentry(dentry);
3331 + if(!is_mini_fo_existant(dentry)) {
3332 + printk(KERN_CRIT "mini_fo_setattr: ERROR, invalid state detected [1].\n");
3336 + if(dtost(dentry) == UNMODIFIED) {
3337 + if(!IS_COPY_FLAG(ia->ia_valid))
3338 + goto out; /* we ignore these changes to base */
3340 + if(S_ISDIR(dentry->d_inode->i_mode)) {
3341 + err = dir_unmod_to_mod(dentry);
3343 + /* we copy contents if file is not beeing truncated */
3344 + if(S_ISREG(dentry->d_inode->i_mode) &&
3345 + !(ia->ia_size == 0 && (ia->ia_valid & ATTR_SIZE))) {
3346 + err = nondir_unmod_to_mod(dentry, 1);
3348 + err = nondir_unmod_to_mod(dentry, 0);
3352 + printk(KERN_CRIT "mini_fo_setattr: ERROR changing states.\n");
3356 + if(!exists_in_storage(dentry)) {
3357 + printk(KERN_CRIT "mini_fo_setattr: ERROR, invalid state detected [2].\n");
3361 + ASSERT(dentry->d_inode);
3362 + ASSERT(dtohd2(dentry));
3363 + ASSERT(itopd(dentry->d_inode));
3364 + ASSERT(itohi2(dentry->d_inode));
3366 + err = notify_change(dtohd2(dentry), ia);
3367 + fist_copy_attr_all(dentry->d_inode, itohi2(dentry->d_inode));
3372 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
3374 +mini_fo_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
3377 + dentry_t *hidden_dentry;
3379 + ASSERT(dentry->d_inode);
3380 + ASSERT(itopd(dentry->d_inode));
3382 + if(itohi2(dentry->d_inode)) {
3383 + hidden_dentry = dtohd2(dentry);
3384 + } else if(itohi(dentry->d_inode)) {
3385 + hidden_dentry = dtohd(dentry);
3387 + printk(KERN_CRIT "mini_fo_getattr: ERROR, invalid state detected.\n");
3391 + fist_copy_attr_all(dentry->d_inode, hidden_dentry->d_inode);
3393 + ASSERT(hidden_dentry);
3394 + ASSERT(hidden_dentry->d_inode);
3395 + ASSERT(hidden_dentry->d_inode->i_op);
3397 + generic_fillattr(dentry->d_inode, stat);
3398 + if (!stat->blksize) {
3399 + struct super_block *s = hidden_dentry->d_inode->i_sb;
3401 + blocks = (stat->size+s->s_blocksize-1) >> s->s_blocksize_bits;
3402 + stat->blocks = (s->s_blocksize / 512) * blocks;
3403 + stat->blksize = s->s_blocksize;
3410 +#if defined(XATTR) && (LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,20))
3411 +#if 0 /* no xattr_alloc() and xattr_free() */
3412 +/* This is lifted from fs/xattr.c */
3414 +xattr_alloc(size_t size, size_t limit)
3419 + return ERR_PTR(-E2BIG);
3421 + if (!size) /* size request, no buffer is needed */
3423 + else if (size <= PAGE_SIZE)
3424 + ptr = kmalloc((unsigned long) size, GFP_KERNEL);
3426 + ptr = vmalloc((unsigned long) size);
3428 + return ERR_PTR(-ENOMEM);
3433 +xattr_free(void *ptr, size_t size)
3435 + if (!size) /* size request, no buffer was needed */
3437 + else if (size <= PAGE_SIZE)
3442 +#endif /* no xattr_alloc() and xattr_free() */
3444 +/* BKL held by caller.
3445 + * dentry->d_inode->i_sem down
3448 +mini_fo_getxattr(struct dentry *dentry, const char *name, void *value, size_t size) {
3449 + struct dentry *hidden_dentry = NULL;
3450 + int err = -EOPNOTSUPP;
3451 + /* Define these anyway so we don't need as much ifdef'ed code. */
3452 + char *encoded_name = NULL;
3453 + char *encoded_value = NULL;
3455 + check_mini_fo_dentry(dentry);
3457 + if(exists_in_storage(dentry))
3458 + hidden_dentry = dtohd2(dentry);
3460 + hidden_dentry = dtohd(dentry);
3462 + ASSERT(hidden_dentry);
3463 + ASSERT(hidden_dentry->d_inode);
3464 + ASSERT(hidden_dentry->d_inode->i_op);
3466 + if (hidden_dentry->d_inode->i_op->getxattr) {
3467 + encoded_name = (char *)name;
3468 + encoded_value = (char *)value;
3470 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
3471 + mutex_lock(&hidden_dentry->d_inode->i_mutex);
3473 + down(&hidden_dentry->d_inode->i_sem);
3475 + /* lock_kernel() already done by caller. */
3476 + err = hidden_dentry->d_inode->i_op->getxattr(hidden_dentry, encoded_name, encoded_value, size);
3477 + /* unlock_kernel() will be done by caller. */
3478 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
3479 + mutex_lock(&hidden_dentry->d_inode->i_mutex);
3481 + up(&hidden_dentry->d_inode->i_sem);
3487 +/* BKL held by caller.
3488 + * dentry->d_inode->i_sem down
3491 +#if ((LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,21) \
3492 + && LINUX_VERSION_CODE <= KERNEL_VERSION(2,4,23)) \
3493 + || LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0))
3494 +mini_fo_setxattr(struct dentry *dentry, const char *name,
3495 + const void *value, size_t size, int flags)
3497 +mini_fo_setxattr(struct dentry *dentry, const char *name,
3498 + void *value, size_t size, int flags)
3502 + struct dentry *hidden_dentry = NULL;
3503 + int err = -EOPNOTSUPP;
3505 + /* Define these anyway, so we don't have as much ifdef'ed code. */
3506 + char *encoded_value = NULL;
3507 + char *encoded_name = NULL;
3509 + check_mini_fo_dentry(dentry);
3511 + if(exists_in_storage(dentry))
3512 + hidden_dentry = dtohd2(dentry);
3514 + hidden_dentry = dtohd(dentry);
3516 + ASSERT(hidden_dentry);
3517 + ASSERT(hidden_dentry->d_inode);
3518 + ASSERT(hidden_dentry->d_inode->i_op);
3520 + if (hidden_dentry->d_inode->i_op->setxattr) {
3521 + encoded_name = (char *)name;
3522 + encoded_value = (char *)value;
3524 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
3525 + mutex_lock(&hidden_dentry->d_inode->i_mutex);
3527 + down(&hidden_dentry->d_inode->i_sem);
3529 + /* lock_kernel() already done by caller. */
3530 + err = hidden_dentry->d_inode->i_op->setxattr(hidden_dentry, encoded_name, encoded_value, size, flags);
3531 + /* unlock_kernel() will be done by caller. */
3532 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
3533 + mutex_unlock(&hidden_dentry->d_inode->i_mutex);
3535 + up(&hidden_dentry->d_inode->i_sem);
3541 +/* BKL held by caller.
3542 + * dentry->d_inode->i_sem down
3545 +mini_fo_removexattr(struct dentry *dentry, const char *name) {
3546 + struct dentry *hidden_dentry = NULL;
3547 + int err = -EOPNOTSUPP;
3548 + char *encoded_name;
3550 + check_mini_fo_dentry(dentry);
3552 + if(exists_in_storage(dentry))
3553 + hidden_dentry = dtohd2(dentry);
3555 + hidden_dentry = dtohd(dentry);
3557 + ASSERT(hidden_dentry);
3558 + ASSERT(hidden_dentry->d_inode);
3559 + ASSERT(hidden_dentry->d_inode->i_op);
3561 + if (hidden_dentry->d_inode->i_op->removexattr) {
3562 + encoded_name = (char *)name;
3564 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
3565 + mutex_lock(&hidden_dentry->d_inode->i_mutex);
3567 + down(&hidden_dentry->d_inode->i_sem);
3569 + /* lock_kernel() already done by caller. */
3570 + err = hidden_dentry->d_inode->i_op->removexattr(hidden_dentry, encoded_name);
3571 + /* unlock_kernel() will be done by caller. */
3572 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
3573 + mutex_unlock(&hidden_dentry->d_inode->i_mutex);
3575 + up(&hidden_dentry->d_inode->i_sem);
3581 +/* BKL held by caller.
3582 + * dentry->d_inode->i_sem down
3585 +mini_fo_listxattr(struct dentry *dentry, char *list, size_t size) {
3586 + struct dentry *hidden_dentry = NULL;
3587 + int err = -EOPNOTSUPP;
3588 + char *encoded_list = NULL;
3590 + check_mini_fo_dentry(dentry);
3592 + if(exists_in_storage(dentry))
3593 + hidden_dentry = dtohd2(dentry);
3595 + hidden_dentry = dtohd(dentry);
3597 + ASSERT(hidden_dentry);
3598 + ASSERT(hidden_dentry->d_inode);
3599 + ASSERT(hidden_dentry->d_inode->i_op);
3601 + if (hidden_dentry->d_inode->i_op->listxattr) {
3602 + encoded_list = list;
3604 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
3605 + mutex_lock(&hidden_dentry->d_inode->i_mutex);
3607 + down(&hidden_dentry->d_inode->i_sem);
3609 + /* lock_kernel() already done by caller. */
3610 + err = hidden_dentry->d_inode->i_op->listxattr(hidden_dentry, encoded_list, size);
3611 + /* unlock_kernel() will be done by caller. */
3612 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
3613 + mutex_unlock(&hidden_dentry->d_inode->i_mutex);
3615 + up(&hidden_dentry->d_inode->i_sem);
3620 +# endif /* defined(XATTR) && (LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,20)) */
3622 +struct inode_operations mini_fo_symlink_iops =
3624 + readlink: mini_fo_readlink,
3625 + follow_link: mini_fo_follow_link,
3626 + /* mk: permission: mini_fo_permission, */
3627 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
3628 + revalidate: mini_fo_inode_revalidate,
3630 + setattr: mini_fo_setattr,
3631 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
3632 + getattr: mini_fo_getattr,
3633 + put_link: mini_fo_put_link,
3636 +#if defined(XATTR) && (LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,20))
3637 + setxattr: mini_fo_setxattr,
3638 + getxattr: mini_fo_getxattr,
3639 + listxattr: mini_fo_listxattr,
3640 + removexattr: mini_fo_removexattr
3641 +# endif /* defined(XATTR) && (LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,20)) */
3644 +struct inode_operations mini_fo_dir_iops =
3646 + create: mini_fo_create,
3647 + lookup: mini_fo_lookup,
3648 + link: mini_fo_link,
3649 + unlink: mini_fo_unlink,
3650 + symlink: mini_fo_symlink,
3651 + mkdir: mini_fo_mkdir,
3652 + rmdir: mini_fo_rmdir,
3653 + mknod: mini_fo_mknod,
3654 + rename: mini_fo_rename,
3655 + /* no readlink/follow_link for non-symlinks */
3656 + // off because we have setattr
3657 + // truncate: mini_fo_truncate,
3658 + /* mk:permission: mini_fo_permission, */
3659 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
3660 + revalidate: mini_fo_inode_revalidate,
3662 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
3663 + getattr: mini_fo_getattr,
3665 + setattr: mini_fo_setattr,
3666 +#if defined(XATTR) && (LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,20))
3667 + setxattr: mini_fo_setxattr,
3668 + getxattr: mini_fo_getxattr,
3669 + listxattr: mini_fo_listxattr,
3670 + removexattr: mini_fo_removexattr
3671 +# endif /* XATTR && LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,20) */
3674 +struct inode_operations mini_fo_main_iops =
3676 + /* permission: mini_fo_permission, */
3677 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
3678 + revalidate: mini_fo_inode_revalidate,
3680 + setattr: mini_fo_setattr,
3682 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
3683 + getattr: mini_fo_getattr,
3685 +#if defined(XATTR) && (LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,20))
3686 + setxattr: mini_fo_setxattr,
3687 + getxattr: mini_fo_getxattr,
3688 + listxattr: mini_fo_listxattr,
3689 + removexattr: mini_fo_removexattr
3690 +# endif /* XATTR && LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,20) */
3692 diff -urN linux-2.6.21.1.old/fs/mini_fo/main.c linux-2.6.21.1.dev/fs/mini_fo/main.c
3693 --- linux-2.6.21.1.old/fs/mini_fo/main.c 1970-01-01 01:00:00.000000000 +0100
3694 +++ linux-2.6.21.1.dev/fs/mini_fo/main.c 2007-05-26 21:01:26.164329720 +0200
3697 + * Copyright (c) 1997-2003 Erez Zadok
3698 + * Copyright (c) 2001-2003 Stony Brook University
3700 + * For specific licensing information, see the COPYING file distributed with
3701 + * this package, or get one from ftp://ftp.filesystems.org/pub/fist/COPYING.
3703 + * This Copyright notice must be kept intact and distributed with all
3704 + * fistgen sources INCLUDING sources generated by fistgen.
3707 + * Copyright (C) 2004, 2005 Markus Klotzbuecher <mk@creamnet.de>
3709 + * This program is free software; you can redistribute it and/or
3710 + * modify it under the terms of the GNU General Public License
3711 + * as published by the Free Software Foundation; either version
3712 + * 2 of the License, or (at your option) any later version.
3719 +#ifdef HAVE_CONFIG_H
3720 +# include <config.h>
3724 +#include "mini_fo.h"
3725 +#include <linux/module.h>
3727 +/* This definition must only appear after we include <linux/module.h> */
3728 +#ifndef MODULE_LICENSE
3729 +# define MODULE_LICENSE(bison)
3730 +#endif /* not MODULE_LICENSE */
3733 + * This is the mini_fo tri interpose function, which extends the
3734 + * functionality of the regular interpose by interposing a higher
3735 + * level inode on top of two lower level ones: the base filesystem
3736 + * inode and the storage filesystem inode.
3738 + * sb we pass is mini_fo's super_block
3741 +mini_fo_tri_interpose(dentry_t *hidden_dentry,
3742 + dentry_t *hidden_sto_dentry,
3743 + dentry_t *dentry, super_block_t *sb, int flag)
3745 + inode_t *hidden_inode = NULL;
3746 + inode_t *hidden_sto_inode = NULL; /* store corresponding storage inode */
3750 + /* Pointer to hidden_sto_inode if exists, else to hidden_inode.
3751 + * This is used to copy the attributes of the correct inode. */
3752 + inode_t *master_inode;
3755 + hidden_inode = hidden_dentry->d_inode;
3756 + if(hidden_sto_dentry)
3757 + hidden_sto_inode = hidden_sto_dentry->d_inode;
3759 + ASSERT(dentry->d_inode == NULL);
3761 + /* mk: One of the inodes associated with the dentrys is likely to
3762 + * be NULL, so carefull:
3764 + ASSERT((hidden_inode != NULL) || (hidden_sto_inode != NULL));
3766 + if(hidden_sto_inode)
3767 + master_inode = hidden_sto_inode;
3769 + master_inode = hidden_inode;
3772 + * We allocate our new inode below, by calling iget.
3773 + * iget will call our read_inode which will initialize some
3774 + * of the new inode's fields
3778 + * original: inode = iget(sb, hidden_inode->i_ino);
3780 + inode = iget(sb, iunique(sb, 25));
3782 + err = -EACCES; /* should be impossible??? */
3787 + * interpose the inode if not already interposed
3788 + * this is possible if the inode is being reused
3789 + * XXX: what happens if we get_empty_inode() but there's another already?
3790 + * for now, ASSERT() that this can't happen; fix later.
3792 + if (itohi(inode) != NULL) {
3793 + printk(KERN_CRIT "mini_fo_tri_interpose: itohi(inode) != NULL.\n");
3795 + if (itohi2(inode) != NULL) {
3796 + printk(KERN_CRIT "mini_fo_tri_interpose: itohi2(inode) != NULL.\n");
3799 + /* mk: Carefull, igrab can't handle NULL inodes (ok, why should it?), so
3800 + * we need to check here:
3803 + itohi(inode) = igrab(hidden_inode);
3805 + itohi(inode) = NULL;
3807 + if(hidden_sto_inode)
3808 + itohi2(inode) = igrab(hidden_sto_inode);
3810 + itohi2(inode) = NULL;
3813 + /* Use different set of inode ops for symlinks & directories*/
3814 + if (S_ISLNK(master_inode->i_mode))
3815 + inode->i_op = &mini_fo_symlink_iops;
3816 + else if (S_ISDIR(master_inode->i_mode))
3817 + inode->i_op = &mini_fo_dir_iops;
3819 + /* Use different set of file ops for directories */
3820 + if (S_ISDIR(master_inode->i_mode))
3821 + inode->i_fop = &mini_fo_dir_fops;
3823 + /* properly initialize special inodes */
3824 + if (S_ISBLK(master_inode->i_mode) || S_ISCHR(master_inode->i_mode) ||
3825 + S_ISFIFO(master_inode->i_mode) || S_ISSOCK(master_inode->i_mode)) {
3826 + init_special_inode(inode, master_inode->i_mode, master_inode->i_rdev);
3829 + /* Fix our inode's address operations to that of the lower inode */
3830 + if (inode->i_mapping->a_ops != master_inode->i_mapping->a_ops) {
3831 + inode->i_mapping->a_ops = master_inode->i_mapping->a_ops;
3834 + /* only (our) lookup wants to do a d_add */
3836 + d_add(dentry, inode);
3838 + d_instantiate(dentry, inode);
3840 + ASSERT(dtopd(dentry) != NULL);
3842 + /* all well, copy inode attributes */
3843 + fist_copy_attr_all(inode, master_inode);
3849 +/* parse mount options "base=" and "sto=" */
3851 +mini_fo_parse_options(super_block_t *sb, char *options)
3853 + dentry_t *hidden_root = ERR_PTR(-EINVAL);
3854 + dentry_t *hidden_root2 = ERR_PTR(-EINVAL);
3855 + struct nameidata nd, nd2;
3856 + char *name, *tmp, *end;
3859 + /* We don't want to go off the end of our arguments later on. */
3860 + for (end = options; *end; end++);
3862 + while (options < end) {
3864 + while (*tmp && *tmp != ',')
3867 + if (!strncmp("base=", options, 5)) {
3868 + name = options + 5;
3869 + printk(KERN_INFO "mini_fo: using base directory: %s\n", name);
3871 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
3872 + if (path_init(name, LOOKUP_FOLLOW, &nd))
3873 + err = path_walk(name, &nd);
3875 + err = path_lookup(name, LOOKUP_FOLLOW, &nd);
3878 + printk(KERN_CRIT "mini_fo: error accessing hidden directory '%s'\n", name);
3879 + hidden_root = ERR_PTR(err);
3882 + hidden_root = nd.dentry;
3883 + stopd(sb)->base_dir_dentry = nd.dentry;
3884 + stopd(sb)->hidden_mnt = nd.mnt;
3886 + } else if(!strncmp("sto=", options, 4)) {
3887 + /* parse the storage dir */
3888 + name = options + 4;
3889 + printk(KERN_INFO "mini_fo: using storage directory: %s\n", name);
3890 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
3891 + if(path_init(name, LOOKUP_FOLLOW, &nd2))
3892 + err = path_walk(name, &nd2);
3894 + err = path_lookup(name, LOOKUP_FOLLOW, &nd2);
3897 + printk(KERN_CRIT "mini_fo: error accessing hidden storage directory '%s'\n", name);
3899 + hidden_root2 = ERR_PTR(err);
3902 + hidden_root2 = nd2.dentry;
3903 + stopd(sb)->storage_dir_dentry = nd2.dentry;
3904 + stopd(sb)->hidden_mnt2 = nd2.mnt;
3905 + stohs2(sb) = hidden_root2->d_sb;
3907 + /* validate storage dir, this is done in
3908 + * mini_fo_read_super for the base directory.
3910 + if (IS_ERR(hidden_root2)) {
3911 + printk(KERN_WARNING "mini_fo_parse_options: storage dentry lookup failed (err = %ld)\n", PTR_ERR(hidden_root2));
3914 + if (!hidden_root2->d_inode) {
3915 + printk(KERN_WARNING "mini_fo_parse_options: no storage dir to interpose on.\n");
3918 + stohs2(sb) = hidden_root2->d_sb;
3920 + printk(KERN_WARNING "mini_fo: unrecognized option '%s'\n", options);
3921 + hidden_root = ERR_PTR(-EINVAL);
3924 + options = tmp + 1;
3928 + if(IS_ERR(hidden_root2))
3929 + return hidden_root2;
3930 + return hidden_root;
3934 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
3939 +mini_fo_read_super(super_block_t *sb, void *raw_data, int silent)
3941 + dentry_t *hidden_root;
3945 + printk(KERN_WARNING "mini_fo_read_super: missing argument\n");
3950 + * Allocate superblock private data
3952 + __stopd(sb) = kmalloc(sizeof(struct mini_fo_sb_info), GFP_KERNEL);
3954 + printk(KERN_WARNING "%s: out of memory\n", __FUNCTION__);
3960 + hidden_root = mini_fo_parse_options(sb, raw_data);
3961 + if (IS_ERR(hidden_root)) {
3962 + printk(KERN_WARNING "mini_fo_read_super: lookup_dentry failed (err = %ld)\n", PTR_ERR(hidden_root));
3963 + err = PTR_ERR(hidden_root);
3966 + if (!hidden_root->d_inode) {
3967 + printk(KERN_WARNING "mini_fo_read_super: no directory to interpose on\n");
3970 + stohs(sb) = hidden_root->d_sb;
3973 + * Linux 2.4.2-ac3 and beyond has code in
3974 + * mm/filemap.c:generic_file_write() that requires sb->s_maxbytes
3975 + * to be populated. If not set, all write()s under that sb will
3978 + * Linux 2.4.4+ automatically sets s_maxbytes to MAX_NON_LFS;
3979 + * the filesystem should override it only if it supports LFS.
3981 + /* non-SCA code is good to go with LFS */
3982 + sb->s_maxbytes = hidden_root->d_sb->s_maxbytes;
3984 + sb->s_op = &mini_fo_sops;
3986 + * we can't use d_alloc_root if we want to use
3987 + * our own interpose function unchanged,
3988 + * so we simply replicate *most* of the code in d_alloc_root here
3990 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
3991 + sb->s_root = d_alloc(NULL, &(const struct qstr) { "/", 1, 0 });
3993 + sb->s_root = d_alloc(NULL, &(const struct qstr){hash: 0, name: "/", len : 1});
3995 + if (IS_ERR(sb->s_root)) {
3996 + printk(KERN_WARNING "mini_fo_read_super: d_alloc failed\n");
4001 + sb->s_root->d_op = &mini_fo_dops;
4002 + sb->s_root->d_sb = sb;
4003 + sb->s_root->d_parent = sb->s_root;
4005 + /* link the upper and lower dentries */
4006 + __dtopd(sb->s_root) = (struct mini_fo_dentry_info *)
4007 + kmalloc(sizeof(struct mini_fo_dentry_info), GFP_KERNEL);
4008 + if (!dtopd(sb->s_root)) {
4012 + dtopd(sb->s_root)->state = MODIFIED;
4013 + dtohd(sb->s_root) = hidden_root;
4015 + /* fanout relevant, interpose on storage root dentry too */
4016 + dtohd2(sb->s_root) = stopd(sb)->storage_dir_dentry;
4018 + /* ...and call tri-interpose to interpose root dir inodes
4019 + * if (mini_fo_interpose(hidden_root, sb->s_root, sb, 0))
4021 + if(mini_fo_tri_interpose(hidden_root, dtohd2(sb->s_root), sb->s_root, sb, 0))
4024 + /* initalize the wol list */
4025 + itopd(sb->s_root->d_inode)->deleted_list_size = -1;
4026 + itopd(sb->s_root->d_inode)->renamed_list_size = -1;
4027 + meta_build_lists(sb->s_root);
4034 + dput(hidden_root);
4035 + dput(dtohd2(sb->s_root)); /* release the hidden_sto_dentry too */
4038 + __stopd(sb) = NULL;
4041 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
4045 + return ERR_PTR(err);
4052 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
4053 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,18)
4054 +static int mini_fo_get_sb(struct file_system_type *fs_type,
4055 + int flags, const char *dev_name,
4056 + void *raw_data, struct vfsmount *mnt)
4058 + return get_sb_nodev(fs_type, flags, raw_data, mini_fo_read_super, mnt);
4061 +static struct super_block *mini_fo_get_sb(struct file_system_type *fs_type,
4062 + int flags, const char *dev_name,
4065 + return get_sb_nodev(fs_type, flags, raw_data, mini_fo_read_super);
4069 +void mini_fo_kill_block_super(struct super_block *sb)
4071 + generic_shutdown_super(sb);
4073 + * XXX: BUG: Halcrow: Things get unstable sometime after this point:
4074 + * lib/rwsem-spinlock.c:127: spin_is_locked on uninitialized
4075 + * fs/fs-writeback.c:402: spin_lock(fs/super.c:a0381828) already
4076 + * locked by fs/fs-writeback.c/402
4078 + * Apparently, someone's not releasing a lock on sb_lock...
4082 +static struct file_system_type mini_fo_fs_type = {
4083 + .owner = THIS_MODULE,
4084 + .name = "mini_fo",
4085 + .get_sb = mini_fo_get_sb,
4086 + .kill_sb = mini_fo_kill_block_super,
4092 +static DECLARE_FSTYPE(mini_fo_fs_type, "mini_fo", mini_fo_read_super, 0);
4095 +static int __init init_mini_fo_fs(void)
4097 + printk("Registering mini_fo version $Id$\n");
4098 + return register_filesystem(&mini_fo_fs_type);
4100 +static void __exit exit_mini_fo_fs(void)
4102 + printk("Unregistering mini_fo version $Id$\n");
4103 + unregister_filesystem(&mini_fo_fs_type);
4106 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
4110 +MODULE_AUTHOR("Erez Zadok <ezk@cs.sunysb.edu>");
4111 +MODULE_DESCRIPTION("FiST-generated mini_fo filesystem");
4112 +MODULE_LICENSE("GPL");
4114 +/* MODULE_PARM(fist_debug_var, "i"); */
4115 +/* MODULE_PARM_DESC(fist_debug_var, "Debug level"); */
4117 +module_init(init_mini_fo_fs)
4118 +module_exit(exit_mini_fo_fs)
4119 diff -urN linux-2.6.21.1.old/fs/mini_fo/Makefile linux-2.6.21.1.dev/fs/mini_fo/Makefile
4120 --- linux-2.6.21.1.old/fs/mini_fo/Makefile 1970-01-01 01:00:00.000000000 +0100
4121 +++ linux-2.6.21.1.dev/fs/mini_fo/Makefile 2007-05-26 21:01:26.164329720 +0200
4124 +# Makefile for mini_fo 2.4 and 2.6 Linux kernels
4126 +# Copyright (C) 2004, 2005 Markus Klotzbuecher <mk@creamnet.de>
4128 +# This program is free software; you can redistribute it and/or
4129 +# modify it under the terms of the GNU General Public License
4130 +# as published by the Free Software Foundation; either version
4131 +# 2 of the License, or (at your option) any later version.
4134 +obj-$(CONFIG_MINI_FO) := mini_fo.o
4135 +mini_fo-objs := meta.o dentry.o file.o inode.o main.o super.o state.o aux.o
4138 +${mini_fo-objs}: mini_fo.h fist.h
4140 diff -urN linux-2.6.21.1.old/fs/mini_fo/meta.c linux-2.6.21.1.dev/fs/mini_fo/meta.c
4141 --- linux-2.6.21.1.old/fs/mini_fo/meta.c 1970-01-01 01:00:00.000000000 +0100
4142 +++ linux-2.6.21.1.dev/fs/mini_fo/meta.c 2007-05-26 21:01:26.166329416 +0200
4145 + * Copyright (C) 2004, 2005 Markus Klotzbuecher <mk@creamnet.de>
4147 + * This program is free software; you can redistribute it and/or
4148 + * modify it under the terms of the GNU General Public License
4149 + * as published by the Free Software Foundation; either version
4150 + * 2 of the License, or (at your option) any later version.
4153 +#ifdef HAVE_CONFIG_H
4154 +# include <config.h>
4155 +#endif /* HAVE_CONFIG_H */
4157 +#include "mini_fo.h"
4159 +int meta_build_lists(dentry_t *dentry)
4161 + struct mini_fo_inode_info *inode_info;
4163 + dentry_t *meta_dentry = 0;
4164 + file_t *meta_file = 0;
4165 + mm_segment_t old_fs;
4169 + struct vfsmount *meta_mnt;
4172 + inode_info = itopd(dentry->d_inode);
4173 + if(!(inode_info->deleted_list_size == -1 &&
4174 + inode_info->renamed_list_size == -1)) {
4175 + printk(KERN_CRIT "mini_fo: meta_build_lists: \
4176 + Error, list(s) not virgin.\n");
4180 + /* init our meta lists */
4181 + INIT_LIST_HEAD(&inode_info->deleted_list);
4182 + inode_info->deleted_list_size = 0;
4184 + INIT_LIST_HEAD(&inode_info->renamed_list);
4185 + inode_info->renamed_list_size = 0;
4187 + /* might there be a META-file? */
4188 + if(dtohd2(dentry) && dtohd2(dentry)->d_inode) {
4189 + meta_dentry = lookup_one_len(META_FILENAME,
4191 + strlen(META_FILENAME));
4192 + if(!meta_dentry->d_inode) {
4193 + dput(meta_dentry);
4196 + /* $%& err, is this correct? */
4197 + meta_mnt = stopd(dentry->d_inode->i_sb)->hidden_mnt2;
4201 + /* open META-file for reading */
4202 + meta_file = dentry_open(meta_dentry, meta_mnt, 0x0);
4203 + if(!meta_file || IS_ERR(meta_file)) {
4204 + printk(KERN_CRIT "mini_fo: meta_build_lists: \
4205 + ERROR opening META file.\n");
4209 + /* check if fs supports reading */
4210 + if(!meta_file->f_op->read) {
4211 + printk(KERN_CRIT "mini_fo: meta_build_lists: \
4212 + ERROR, fs does not support reading.\n");
4213 + goto out_err_close;
4216 + /* allocate a page for transfering the data */
4217 + buf = (void *) __get_free_page(GFP_KERNEL);
4219 + printk(KERN_CRIT "mini_fo: meta_build_lists: \
4220 + ERROR, out of mem.\n");
4221 + goto out_err_close;
4223 + meta_file->f_pos = 0;
4224 + old_fs = get_fs();
4225 + set_fs(KERNEL_DS);
4228 + bytes = meta_file->f_op->read(meta_file, buf, PAGE_SIZE, &meta_file->f_pos);
4229 + if(bytes == PAGE_SIZE) {
4230 + /* trim a cut off filename and adjust f_pos to get it next time */
4231 + for(c = (char*) buf+PAGE_SIZE;
4233 + c--, bytes--, meta_file->f_pos--);
4235 + entry = (char *) buf;
4236 + while(entry < (char *) buf+bytes) {
4240 + int old_len, new_len;
4242 + /* len without '\n'*/
4243 + len = (int) (strchr(entry, '\n') - entry);
4246 + /* format: "D filename" */
4247 + meta_list_add_d_entry(dentry,
4252 + /* format: "R path/xy/dir newDir" */
4253 + old_path = entry+2;
4254 + dir_name = strchr(old_path, ' ') + 1;
4255 + old_len = dir_name - old_path - 1;
4256 + new_len = ((int) entry) + len - ((int ) dir_name);
4257 + meta_list_add_r_entry(dentry,
4264 + /* unknown entry type detected */
4270 + } while(meta_file->f_pos < meta_dentry->d_inode->i_size);
4272 + free_page((unsigned long) buf);
4282 + dput(meta_dentry);
4285 + return 1; /* check this!!! inode_info->wol_size; */
4288 +/* cleanups up all lists and free's the mem by dentry */
4289 +int meta_put_lists(dentry_t *dentry)
4291 + if(!dentry || !dentry->d_inode) {
4292 + printk("mini_fo: meta_put_lists: invalid dentry passed.\n");
4295 + return __meta_put_lists(dentry->d_inode);
4298 +/* cleanups up all lists and free's the mem by inode */
4299 +int __meta_put_lists(inode_t *inode)
4302 + if(!inode || !itopd(inode)) {
4303 + printk("mini_fo: __meta_put_lists: invalid inode passed.\n");
4306 + err = __meta_put_d_list(inode);
4307 + err |= __meta_put_r_list(inode);
4311 +int meta_sync_lists(dentry_t *dentry)
4314 + if(!dentry || !dentry->d_inode) {
4315 + printk("mini_fo: meta_sync_lists: \
4316 + invalid dentry passed.\n");
4319 + err = meta_sync_d_list(dentry, 0);
4320 + err |= meta_sync_r_list(dentry, 1);
4325 +/* remove all D entries from the renamed list and free the mem */
4326 +int __meta_put_d_list(inode_t *inode)
4328 + struct list_head *tmp;
4329 + struct deleted_entry *del_entry;
4330 + struct mini_fo_inode_info *inode_info;
4332 + if(!inode || !itopd(inode)) {
4333 + printk(KERN_CRIT "mini_fo: __meta_put_d_list: \
4334 + invalid inode passed.\n");
4337 + inode_info = itopd(inode);
4339 + /* nuke the DELETED-list */
4340 + if(inode_info->deleted_list_size <= 0)
4343 + while(!list_empty(&inode_info->deleted_list)) {
4344 + tmp = inode_info->deleted_list.next;
4346 + del_entry = list_entry(tmp, struct deleted_entry, list);
4347 + kfree(del_entry->name);
4350 + inode_info->deleted_list_size = 0;
4355 +/* remove all R entries from the renamed list and free the mem */
4356 +int __meta_put_r_list(inode_t *inode)
4358 + struct list_head *tmp;
4359 + struct renamed_entry *ren_entry;
4360 + struct mini_fo_inode_info *inode_info;
4362 + if(!inode || !itopd(inode)) {
4363 + printk(KERN_CRIT "mini_fo: meta_put_r_list: invalid inode.\n");
4366 + inode_info = itopd(inode);
4368 + /* nuke the RENAMED-list */
4369 + if(inode_info->renamed_list_size <= 0)
4372 + while(!list_empty(&inode_info->renamed_list)) {
4373 + tmp = inode_info->renamed_list.next;
4375 + ren_entry = list_entry(tmp, struct renamed_entry, list);
4376 + kfree(ren_entry->new_name);
4377 + kfree(ren_entry->old_name);
4380 + inode_info->renamed_list_size = 0;
4385 +int meta_add_d_entry(dentry_t *dentry, const char *name, int len)
4388 + err = meta_list_add_d_entry(dentry, name, len);
4389 + err |= meta_write_d_entry(dentry,name,len);
4393 +/* add a D entry to the deleted list */
4394 +int meta_list_add_d_entry(dentry_t *dentry, const char *name, int len)
4396 + struct deleted_entry *del_entry;
4397 + struct mini_fo_inode_info *inode_info;
4399 + if(!dentry || !dentry->d_inode) {
4400 + printk(KERN_CRIT "mini_fo: meta_list_add_d_entry: \
4401 + invalid dentry passed.\n");
4404 + inode_info = itopd(dentry->d_inode);
4406 + if(inode_info->deleted_list_size < 0)
4409 + del_entry = (struct deleted_entry *)
4410 + kmalloc(sizeof(struct deleted_entry), GFP_KERNEL);
4411 + del_entry->name = (char*) kmalloc(len, GFP_KERNEL);
4412 + if(!del_entry || !del_entry->name) {
4413 + printk(KERN_CRIT "mini_fo: meta_list_add_d_entry: \
4415 + kfree(del_entry->name);
4420 + strncpy(del_entry->name, name, len);
4421 + del_entry->len = len;
4423 + list_add(&del_entry->list, &inode_info->deleted_list);
4424 + inode_info->deleted_list_size++;
4428 +int meta_add_r_entry(dentry_t *dentry,
4429 + const char *old_name, int old_len,
4430 + const char *new_name, int new_len)
4433 + err = meta_list_add_r_entry(dentry,
4434 + old_name, old_len,
4435 + new_name, new_len);
4436 + err |= meta_write_r_entry(dentry,
4437 + old_name, old_len,
4438 + new_name, new_len);
4442 +/* add a R entry to the renamed list */
4443 +int meta_list_add_r_entry(dentry_t *dentry,
4444 + const char *old_name, int old_len,
4445 + const char *new_name, int new_len)
4447 + struct renamed_entry *ren_entry;
4448 + struct mini_fo_inode_info *inode_info;
4450 + if(!dentry || !dentry->d_inode) {
4451 + printk(KERN_CRIT "mini_fo: meta_list_add_r_entry: \
4452 + invalid dentry passed.\n");
4455 + inode_info = itopd(dentry->d_inode);
4457 + if(inode_info->renamed_list_size < 0)
4460 + ren_entry = (struct renamed_entry *)
4461 + kmalloc(sizeof(struct renamed_entry), GFP_KERNEL);
4462 + ren_entry->old_name = (char*) kmalloc(old_len, GFP_KERNEL);
4463 + ren_entry->new_name = (char*) kmalloc(new_len, GFP_KERNEL);
4465 + if(!ren_entry || !ren_entry->old_name || !ren_entry->new_name) {
4466 + printk(KERN_CRIT "mini_fo: meta_list_add_r_entry: \
4468 + kfree(ren_entry->new_name);
4469 + kfree(ren_entry->old_name);
4474 + strncpy(ren_entry->old_name, old_name, old_len);
4475 + ren_entry->old_len = old_len;
4476 + strncpy(ren_entry->new_name, new_name, new_len);
4477 + ren_entry->new_len = new_len;
4479 + list_add(&ren_entry->list, &inode_info->renamed_list);
4480 + inode_info->renamed_list_size++;
4485 +int meta_remove_r_entry(dentry_t *dentry, const char *name, int len)
4488 + if(!dentry || !dentry->d_inode) {
4490 + "mini_fo: meta_remove_r_entry: \
4491 + invalid dentry passed.\n");
4495 + err = meta_list_remove_r_entry(dentry, name, len);
4496 + err |= meta_sync_lists(dentry);
4500 +int meta_list_remove_r_entry(dentry_t *dentry, const char *name, int len)
4502 + if(!dentry || !dentry->d_inode) {
4504 + "mini_fo: meta_list_remove_r_entry: \
4505 + invalid dentry passed.\n");
4508 + return __meta_list_remove_r_entry(dentry->d_inode, name, len);
4511 +int __meta_list_remove_r_entry(inode_t *inode, const char *name, int len)
4513 + struct list_head *tmp;
4514 + struct renamed_entry *ren_entry;
4515 + struct mini_fo_inode_info *inode_info;
4517 + if(!inode || !itopd(inode))
4519 + "mini_fo: __meta_list_remove_r_entry: \
4520 + invalid inode passed.\n");
4521 + inode_info = itopd(inode);
4523 + if(inode_info->renamed_list_size < 0)
4525 + if(inode_info->renamed_list_size == 0)
4528 + list_for_each(tmp, &inode_info->renamed_list) {
4529 + ren_entry = list_entry(tmp, struct renamed_entry, list);
4530 + if(ren_entry->new_len != len)
4533 + if(!strncmp(ren_entry->new_name, name, len)) {
4535 + kfree(ren_entry->new_name);
4536 + kfree(ren_entry->old_name);
4538 + inode_info->renamed_list_size--;
4546 +/* append a single D entry to the meta file */
4547 +int meta_write_d_entry(dentry_t *dentry, const char *name, int len)
4549 + dentry_t *meta_dentry = 0;
4550 + file_t *meta_file = 0;
4551 + mm_segment_t old_fs;
4554 + struct vfsmount *meta_mnt = 0;
4559 + if(itopd(dentry->d_inode)->deleted_list_size < 0) {
4564 + if(dtopd(dentry)->state == UNMODIFIED) {
4565 + err = build_sto_structure(dentry->d_parent, dentry);
4567 + printk(KERN_CRIT "mini_fo: meta_write_d_entry: \
4568 + build_sto_structure failed.\n");
4572 + meta_dentry = lookup_one_len(META_FILENAME,
4573 + dtohd2(dentry), strlen (META_FILENAME));
4575 + /* We need to create a META-file */
4576 + if(!meta_dentry->d_inode) {
4577 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
4578 + vfs_create(dtohd2(dentry)->d_inode,
4580 + S_IRUSR | S_IWUSR,
4583 + vfs_create(dtohd2(dentry)->d_inode,
4585 + S_IRUSR | S_IWUSR);
4588 + /* open META-file for writing */
4589 + meta_file = dentry_open(meta_dentry, meta_mnt, 0x1);
4590 + if(!meta_file || IS_ERR(meta_file)) {
4591 + printk(KERN_CRIT "mini_fo: meta_write_d_entry: \
4592 + ERROR opening meta file.\n");
4593 + mntput(meta_mnt); /* $%& is this necessary? */
4594 + dput(meta_dentry);
4599 + /* check if fs supports writing */
4600 + if(!meta_file->f_op->write) {
4601 + printk(KERN_CRIT "mini_fo: meta_write_d_entry: \
4602 + ERROR, fs does not support writing.\n");
4603 + goto out_err_close;
4606 + meta_file->f_pos = meta_dentry->d_inode->i_size; /* append */
4607 + old_fs = get_fs();
4608 + set_fs(KERNEL_DS);
4610 + /* size: len for name, 1 for \n and 2 for "D " */
4611 + buf = (char *) kmalloc(len+3, GFP_KERNEL);
4613 + printk(KERN_CRIT "mini_fo: meta_write_d_entry: \
4620 + strncpy(buf+2, name, len);
4621 + buf[len+2] = '\n';
4622 + bytes = meta_file->f_op->write(meta_file, buf, len+3,
4623 + &meta_file->f_pos);
4624 + if(bytes != len+3) {
4625 + printk(KERN_CRIT "mini_fo: meta_write_d_entry: \
4626 + ERROR writing.\n");
4638 +/* append a single R entry to the meta file */
4639 +int meta_write_r_entry(dentry_t *dentry,
4640 + const char *old_name, int old_len,
4641 + const char *new_name, int new_len)
4643 + dentry_t *meta_dentry = 0;
4644 + file_t *meta_file = 0;
4645 + mm_segment_t old_fs;
4647 + int bytes, err, buf_len;
4648 + struct vfsmount *meta_mnt = 0;
4654 + if(itopd(dentry->d_inode)->renamed_list_size < 0) {
4659 + /* build the storage structure? */
4660 + if(dtopd(dentry)->state == UNMODIFIED) {
4661 + err = build_sto_structure(dentry->d_parent, dentry);
4663 + printk(KERN_CRIT "mini_fo: meta_write_r_entry: \
4664 + build_sto_structure failed.\n");
4668 + meta_dentry = lookup_one_len(META_FILENAME,
4670 + strlen (META_FILENAME));
4671 + if(!meta_dentry->d_inode) {
4672 + /* We need to create a META-file */
4673 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
4674 + vfs_create(dtohd2(dentry)->d_inode,
4675 + meta_dentry, S_IRUSR | S_IWUSR, NULL);
4677 + vfs_create(dtohd2(dentry)->d_inode,
4678 + meta_dentry, S_IRUSR | S_IWUSR);
4681 + /* open META-file for writing */
4682 + meta_file = dentry_open(meta_dentry, meta_mnt, 0x1);
4683 + if(!meta_file || IS_ERR(meta_file)) {
4684 + printk(KERN_CRIT "mini_fo: meta_write_r_entry: \
4685 + ERROR opening meta file.\n");
4687 + dput(meta_dentry);
4692 + /* check if fs supports writing */
4693 + if(!meta_file->f_op->write) {
4694 + printk(KERN_CRIT "mini_fo: meta_write_r_entry: \
4695 + ERROR, fs does not support writing.\n");
4696 + goto out_err_close;
4699 + meta_file->f_pos = meta_dentry->d_inode->i_size; /* append */
4700 + old_fs = get_fs();
4701 + set_fs(KERNEL_DS);
4703 + /* size: 2 for "R ", old_len+new_len for names, 1 blank+1 \n */
4704 + buf_len = old_len + new_len + 4;
4705 + buf = (char *) kmalloc(buf_len, GFP_KERNEL);
4707 + printk(KERN_CRIT "mini_fo: meta_write_r_entry: out of mem.\n");
4713 + strncpy(buf + 2, old_name, old_len);
4714 + buf[old_len + 2] = ' ';
4715 + strncpy(buf + old_len + 3, new_name, new_len);
4716 + buf[buf_len -1] = '\n';
4717 + bytes = meta_file->f_op->write(meta_file, buf, buf_len, &meta_file->f_pos);
4718 + if(bytes != buf_len) {
4719 + printk(KERN_CRIT "mini_fo: meta_write_r_entry: ERROR writing.\n");
4732 +/* sync D list to disk, append data if app_flag is 1 */
4733 +/* check the meta_mnt, which seems not to be used (properly) */
4735 +int meta_sync_d_list(dentry_t *dentry, int app_flag)
4737 + dentry_t *meta_dentry;
4738 + file_t *meta_file;
4739 + mm_segment_t old_fs;
4742 + struct vfsmount *meta_mnt;
4745 + struct list_head *tmp;
4746 + struct deleted_entry *del_entry;
4747 + struct mini_fo_inode_info *inode_info;
4753 + if(!dentry || !dentry->d_inode) {
4754 + printk(KERN_CRIT "mini_fo: meta_sync_d_list: \
4755 + invalid inode passed.\n");
4759 + inode_info = itopd(dentry->d_inode);
4761 + if(inode_info->deleted_list_size < 0) {
4766 + /* ok, there is something to sync */
4768 + /* build the storage structure? */
4769 + if(!dtohd2(dentry) && !itohi2(dentry->d_inode)) {
4770 + err = build_sto_structure(dentry->d_parent, dentry);
4772 + printk(KERN_CRIT "mini_fo: meta_sync_d_list: \
4773 + build_sto_structure failed.\n");
4777 + meta_dentry = lookup_one_len(META_FILENAME,
4779 + strlen(META_FILENAME));
4780 + if(!meta_dentry->d_inode) {
4781 + /* We need to create a META-file */
4782 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
4783 + vfs_create(dtohd2(dentry)->d_inode,
4784 + meta_dentry, S_IRUSR | S_IWUSR, NULL);
4786 + vfs_create(dtohd2(dentry)->d_inode,
4787 + meta_dentry, S_IRUSR | S_IWUSR);
4791 + /* need we truncate the meta file? */
4793 + struct iattr newattrs;
4794 + newattrs.ia_size = 0;
4795 + newattrs.ia_valid = ATTR_SIZE | ATTR_CTIME;
4797 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
4798 + mutex_lock(&meta_dentry->d_inode->i_mutex);
4800 + down(&meta_dentry->d_inode->i_sem);
4802 + err = notify_change(meta_dentry, &newattrs);
4804 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
4805 + mutex_unlock(&meta_dentry->d_inode->i_mutex);
4807 + up(&meta_dentry->d_inode->i_sem);
4810 + if(err || meta_dentry->d_inode->i_size != 0) {
4811 + printk(KERN_CRIT "mini_fo: meta_sync_d_list: \
4812 + ERROR truncating meta file.\n");
4813 + goto out_err_close;
4817 + /* open META-file for writing */
4818 + meta_file = dentry_open(meta_dentry, meta_mnt, 0x1);
4819 + if(!meta_file || IS_ERR(meta_file)) {
4820 + printk(KERN_CRIT "mini_fo: meta_sync_d_list: \
4821 + ERROR opening meta file.\n");
4822 + /* we don't mntget so we dont't mntput (for now)
4823 + * mntput(meta_mnt);
4825 + dput(meta_dentry);
4830 + /* check if fs supports writing */
4831 + if(!meta_file->f_op->write) {
4832 + printk(KERN_CRIT "mini_fo: meta_sync_d_list: \
4833 + ERROR, fs does not support writing.\n");
4834 + goto out_err_close;
4837 + meta_file->f_pos = meta_dentry->d_inode->i_size; /* append */
4838 + old_fs = get_fs();
4839 + set_fs(KERNEL_DS);
4841 + /* here we go... */
4842 + list_for_each(tmp, &inode_info->deleted_list) {
4843 + del_entry = list_entry(tmp, struct deleted_entry, list);
4845 + /* size: len for name, 1 for \n and 2 for "D " */
4846 + buf = (char *) kmalloc(del_entry->len+3, GFP_KERNEL);
4848 + printk(KERN_CRIT "mini_fo: meta_sync_d_list: \
4855 + strncpy(buf+2, del_entry->name, del_entry->len);
4856 + buf[del_entry->len+2] = '\n';
4857 + bytes = meta_file->f_op->write(meta_file, buf,
4859 + &meta_file->f_pos);
4860 + if(bytes != del_entry->len+3) {
4861 + printk(KERN_CRIT "mini_fo: meta_sync_d_list: \
4862 + ERROR writing.\n");
4876 +int meta_sync_r_list(dentry_t *dentry, int app_flag)
4878 + dentry_t *meta_dentry;
4879 + file_t *meta_file;
4880 + mm_segment_t old_fs;
4882 + int bytes, err, buf_len;
4883 + struct vfsmount *meta_mnt;
4886 + struct list_head *tmp;
4887 + struct renamed_entry *ren_entry;
4888 + struct mini_fo_inode_info *inode_info;
4894 + if(!dentry || !dentry->d_inode) {
4895 + printk(KERN_CRIT "mini_fo: meta_sync_r_list: \
4896 + invalid dentry passed.\n");
4900 + inode_info = itopd(dentry->d_inode);
4902 + if(inode_info->deleted_list_size < 0) {
4907 + /* ok, there is something to sync */
4909 + /* build the storage structure? */
4910 + if(!dtohd2(dentry) && !itohi2(dentry->d_inode)) {
4911 + err = build_sto_structure(dentry->d_parent, dentry);
4913 + printk(KERN_CRIT "mini_fo: meta_sync_r_list: \
4914 + build_sto_structure failed.\n");
4918 + meta_dentry = lookup_one_len(META_FILENAME,
4920 + strlen(META_FILENAME));
4921 + if(!meta_dentry->d_inode) {
4922 + /* We need to create a META-file */
4923 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
4924 + vfs_create(dtohd2(dentry)->d_inode,
4925 + meta_dentry, S_IRUSR | S_IWUSR, NULL);
4927 + vfs_create(dtohd2(dentry)->d_inode,
4928 + meta_dentry, S_IRUSR | S_IWUSR);
4932 + /* need we truncate the meta file? */
4934 + struct iattr newattrs;
4935 + newattrs.ia_size = 0;
4936 + newattrs.ia_valid = ATTR_SIZE | ATTR_CTIME;
4938 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
4939 + mutex_lock(&meta_dentry->d_inode->i_mutex);
4941 + down(&meta_dentry->d_inode->i_sem);
4943 + err = notify_change(meta_dentry, &newattrs);
4945 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
4946 + mutex_unlock(&meta_dentry->d_inode->i_mutex);
4948 + up(&meta_dentry->d_inode->i_sem);
4950 + if(err || meta_dentry->d_inode->i_size != 0) {
4951 + printk(KERN_CRIT "mini_fo: meta_sync_r_list: \
4952 + ERROR truncating meta file.\n");
4953 + goto out_err_close;
4957 + /* open META-file for writing */
4958 + meta_file = dentry_open(meta_dentry, meta_mnt, 0x1);
4959 + if(!meta_file || IS_ERR(meta_file)) {
4960 + printk(KERN_CRIT "mini_fo: meta_sync_r_list: \
4961 + ERROR opening meta file.\n");
4962 + /* we don't mntget so we dont't mntput (for now)
4963 + * mntput(meta_mnt);
4965 + dput(meta_dentry);
4970 + /* check if fs supports writing */
4971 + if(!meta_file->f_op->write) {
4972 + printk(KERN_CRIT "mini_fo: meta_sync_r_list: \
4973 + ERROR, fs does not support writing.\n");
4974 + goto out_err_close;
4977 + meta_file->f_pos = meta_dentry->d_inode->i_size; /* append */
4978 + old_fs = get_fs();
4979 + set_fs(KERNEL_DS);
4981 + /* here we go... */
4982 + list_for_each(tmp, &inode_info->renamed_list) {
4983 + ren_entry = list_entry(tmp, struct renamed_entry, list);
4985 + * 2 for "R ", old_len+new_len for names, 1 blank+1 \n */
4986 + buf_len = ren_entry->old_len + ren_entry->new_len + 4;
4987 + buf = (char *) kmalloc(buf_len, GFP_KERNEL);
4989 + printk(KERN_CRIT "mini_fo: meta_sync_r_list: \
4995 + strncpy(buf + 2, ren_entry->old_name, ren_entry->old_len);
4996 + buf[ren_entry->old_len + 2] = ' ';
4997 + strncpy(buf + ren_entry->old_len + 3,
4998 + ren_entry->new_name, ren_entry->new_len);
4999 + buf[buf_len - 1] = '\n';
5000 + bytes = meta_file->f_op->write(meta_file, buf,
5001 + buf_len, &meta_file->f_pos);
5002 + if(bytes != buf_len) {
5003 + printk(KERN_CRIT "mini_fo: meta_sync_r_list: \
5004 + ERROR writing.\n");
5017 +int meta_check_d_entry(dentry_t *dentry, const char *name, int len)
5019 + if(!dentry || !dentry->d_inode)
5020 + printk(KERN_CRIT "mini_fo: meta_check_d_dentry: \
5021 + invalid dentry passed.\n");
5022 + return __meta_check_d_entry(dentry->d_inode, name, len);
5025 +int __meta_check_d_entry(inode_t *inode, const char *name, int len)
5027 + struct list_head *tmp;
5028 + struct deleted_entry *del_entry;
5029 + struct mini_fo_inode_info *inode_info;
5031 + if(!inode || !itopd(inode))
5032 + printk(KERN_CRIT "mini_fo: __meta_check_d_dentry: \
5033 + invalid inode passed.\n");
5035 + inode_info = itopd(inode);
5037 + if(inode_info->deleted_list_size <= 0)
5040 + list_for_each(tmp, &inode_info->deleted_list) {
5041 + del_entry = list_entry(tmp, struct deleted_entry, list);
5042 + if(del_entry->len != len)
5045 + if(!strncmp(del_entry->name, name, len))
5052 + * check if file has been renamed and return path to orig. base dir.
5053 + * Implements no error return values so far, what of course sucks.
5054 + * String is null terminated.'
5056 +char* meta_check_r_entry(dentry_t *dentry, const char *name, int len)
5058 + if(!dentry || !dentry->d_inode) {
5059 + printk(KERN_CRIT "mini_fo: meta_check_r_dentry: \
5060 + invalid dentry passed.\n");
5063 + return __meta_check_r_entry(dentry->d_inode, name, len);
5066 +char* __meta_check_r_entry(inode_t *inode, const char *name, int len)
5068 + struct list_head *tmp;
5069 + struct renamed_entry *ren_entry;
5070 + struct mini_fo_inode_info *inode_info;
5073 + if(!inode || !itopd(inode)) {
5074 + printk(KERN_CRIT "mini_fo: meta_check_r_dentry: \
5075 + invalid inode passed.\n");
5078 + inode_info = itopd(inode);
5080 + if(inode_info->renamed_list_size <= 0)
5083 + list_for_each(tmp, &inode_info->renamed_list) {
5084 + ren_entry = list_entry(tmp, struct renamed_entry, list);
5085 + if(ren_entry->new_len != len)
5088 + if(!strncmp(ren_entry->new_name, name, len)) {
5089 + old_path = (char *)
5090 + kmalloc(ren_entry->old_len+1, GFP_KERNEL);
5092 + ren_entry->old_name,
5093 + ren_entry->old_len);
5094 + old_path[ren_entry->old_len]='\0';
5102 + * This version only checks if entry exists and return:
5107 +int meta_is_r_entry(dentry_t *dentry, const char *name, int len)
5109 + if(!dentry || !dentry->d_inode) {
5110 + printk(KERN_CRIT "mini_fo: meta_check_r_dentry [2]: \
5111 + invalid dentry passed.\n");
5114 + return __meta_is_r_entry(dentry->d_inode, name, len);
5117 +int __meta_is_r_entry(inode_t *inode, const char *name, int len)
5119 + struct list_head *tmp;
5120 + struct renamed_entry *ren_entry;
5121 + struct mini_fo_inode_info *inode_info;
5123 + if(!inode || !itopd(inode)) {
5124 + printk(KERN_CRIT "mini_fo: meta_check_r_dentry [2]: \
5125 + invalid inode passed.\n");
5128 + inode_info = itopd(inode);
5130 + if(inode_info->renamed_list_size <= 0)
5133 + list_for_each(tmp, &inode_info->renamed_list) {
5134 + ren_entry = list_entry(tmp, struct renamed_entry, list);
5135 + if(ren_entry->new_len != len)
5138 + if(!strncmp(ren_entry->new_name, name, len))
5144 diff -urN linux-2.6.21.1.old/fs/mini_fo/mini_fo.h linux-2.6.21.1.dev/fs/mini_fo/mini_fo.h
5145 --- linux-2.6.21.1.old/fs/mini_fo/mini_fo.h 1970-01-01 01:00:00.000000000 +0100
5146 +++ linux-2.6.21.1.dev/fs/mini_fo/mini_fo.h 2007-05-26 21:01:26.167329264 +0200
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 diff -urN linux-2.6.21.1.old/fs/mini_fo/mini_fo-merge linux-2.6.21.1.dev/fs/mini_fo/mini_fo-merge
5659 --- linux-2.6.21.1.old/fs/mini_fo/mini_fo-merge 1970-01-01 01:00:00.000000000 +0100
5660 +++ linux-2.6.21.1.dev/fs/mini_fo/mini_fo-merge 2007-05-26 21:01:26.167329264 +0200
5664 +# Copyright (C) 2005 Markus Klotzbuecher <mk@creamnet.de>
5665 +# This program is free software; you can redistribute it and/or
5666 +# modify it under the terms of the GNU General Public License
5667 +# as published by the Free Software Foundation; either version
5668 +# 2 of the License, or (at your option) any later version.
5677 +META_NAME="META_dAfFgHE39ktF3HD2sr"
5678 +SKIP_DEL_LIST="skip-delete-list.mini_fo-merge"
5683 + if [ x$DRYRUN == "xset" ]; then
5684 + echo " would run: $COMMAND"
5685 + elif ! [ x$DRYRUN == "xset" ]; then
5686 + if [ x$VERBOSE == "xset" ]; then
5687 + echo " running: $COMMAND"
5697 +USAGE: $0 -b <base dir> -s <storage dir>
5700 +This script merges the contents of a mini_fo storage file system back
5701 +to the base file system.
5703 +!!! Warning: This will modify the base filesystem and can destroy data
5708 + the directory of the base file system.
5711 + the directory of the storage file system.
5713 + -d dry run, will not change anything and print the commands that
5714 + would be executed.
5716 + -t tmp dir for storing temporary file. default: $TMP
5718 + -v show what operations are performed.
5720 + -h displays this message.
5726 +while getopts hdvt:b:s: OPTS
5731 + v) VERBOSE="set";;
5732 + b) BASE="$OPTARG";;
5733 + s) STO="$OPTARG";;
5734 + t) TMP="$OPTARG";;
5740 +if [ "x$HELP" == "xset" ]; then
5745 +if ! [ -d "$BASE" ] || ! [ -d "$STO" ]; then
5746 + echo -e "$0:\n Error, -s and/or -b argument missing. type $0 -h for help."
5751 +pushd $STO; STO=`pwd`; popd
5752 +pushd $BASE; BASE=`pwd`; popd
5757 +###############################################################################
5761 +# storage dir: $STO
5762 +# meta filename: $META_NAME
5764 +# verbose: $VERBOSE
5766 +###############################################################################
5770 +rm $TMP/$SKIP_DEL_LIST
5772 +# first process all renamed dirs
5773 +echo "Merging renamed directories..."
5774 +pushd $STO &> /dev/null
5775 +find . -name $META_NAME -type f -print0 | xargs -0 -e grep -e '^R ' | tr -s ':R' ' ' | while read ENTRY; do
5776 + echo "entry: $ENTRY"
5777 + META_FILE=`echo $ENTRY | cut -d ' ' -f 1`
5778 + OLD_B_DIR=`echo $ENTRY | cut -d ' ' -f 2 | sed -e 's/\///'`
5779 + NEW_NAME=`echo $ENTRY | cut -d ' ' -f 3`
5780 + NEW_B_DIR=`echo $META_FILE | sed -e "s/$META_NAME/$NEW_NAME/" | sed -e 's/^\.\///'`
5781 + echo "META_FILE: $META_FILE"
5782 + echo "OLD_B_DIR: $OLD_B_DIR"
5783 + echo "NEW_NAME: $NEW_NAME"
5784 + echo "NEW_B_DIR: $NEW_B_DIR"
5786 + pushd $BASE &> /dev/null
5787 + # remove an existing dir in storage
5788 + COMMAND="rm -rf $NEW_B_DIR"; exec_command
5789 + COMMAND="cp -R $OLD_B_DIR $NEW_B_DIR"; exec_command
5793 + # remember this dir to exclude it from deleting later
5794 + echo $NEW_B_DIR >> $TMP/$SKIP_DEL_LIST
5797 +# delete all whiteouted files from base
5798 +echo -e "\nDeleting whiteout'ed files from base file system..."
5799 +find . -name $META_NAME -type f -print0 | xargs -0 -e grep -e '^D ' | sed -e 's/:D//' | while read ENTRY; do
5800 + META_FILE=`echo $ENTRY | cut -d ' ' -f 1`
5801 + DEL_NAME=`echo $ENTRY | cut -d ' ' -f 2`
5802 + DEL_FILE=`echo $META_FILE | sed -e "s/$META_NAME/$DEL_NAME/" | sed -e 's/^\.\///'`
5803 + grep -x $DEL_FILE $TMP/$SKIP_DEL_LIST &> /dev/null
5804 + if [ $? -ne 0 ]; then
5805 + pushd $BASE &> /dev/null
5806 + COMMAND="rm -rf $DEL_FILE"; exec_command
5809 + echo " excluding: $DEL_FILE as in skip-del-list."
5813 +# create all dirs and update permissions
5814 +echo -e "\nSetting up directory structures in base file system..."
5815 +find . -type d | sed -e 's/^\.\///' | while read DIR; do
5816 + PERMS=`stat -c %a $DIR`
5817 + DIR_UID=`stat -c %u $DIR`
5818 + DIR_GID=`stat -c %g $DIR`
5819 + pushd $BASE &> /dev/null
5820 + if ! [ -d $DIR ]; then
5821 + COMMAND="mkdir -p $DIR"; exec_command
5823 + COMMAND="chmod $PERMS $DIR"; exec_command
5824 + COMMAND="chown $DIR_UID:$DIR_GID $DIR"; exec_command
5828 +# merge all non-directory files
5829 +echo -e "\nMerging all non-directory files...."
5830 +for i in b c p f l s; do
5831 + find . -type $i | sed -e 's/^\.\///' | grep -v "$META_NAME" | while read FILE; do
5832 + pushd $BASE #&> /dev/null
5833 + COMMAND="cp -df $STO/$FILE $BASE/$FILE"; exec_command
5839 +#rm $TMP/$SKIP_DEL_LIST
5842 diff -urN linux-2.6.21.1.old/fs/mini_fo/mini_fo-overlay linux-2.6.21.1.dev/fs/mini_fo/mini_fo-overlay
5843 --- linux-2.6.21.1.old/fs/mini_fo/mini_fo-overlay 1970-01-01 01:00:00.000000000 +0100
5844 +++ linux-2.6.21.1.dev/fs/mini_fo/mini_fo-overlay 2007-05-26 21:01:26.167329264 +0200
5848 +# Copyright (C) 2005 Markus Klotzbuecher <mk@creamnet.de>
5849 +# This program is free software; you can redistribute it and/or
5850 +# modify it under the terms of the GNU General Public License
5851 +# as published by the Free Software Foundation; either version
5852 +# 2 of the License, or (at your option) any later version.
5867 +Usage: $0 [-s suffix] [-d sto_dir_dir] [-m mount point] base_dir
5870 +This script overlays the given base directory using the mini_fo file
5871 +system. If only the base directory base_dir is given, $0
5872 +will use a storage directory called "sto-<base_dir_name>" in $STO_DIR,
5873 +and mount point "mini_fo-<base_dir_dir>" in $MNT_DIR.
5877 + add given suffix to storage directory and the mount
5878 + point. This is usefull for overlaying one base directory
5879 + several times and avoiding conflicts with storage directory
5880 + names and mount points.
5883 + change the directory in which the storage directory will be
5884 + created (default is currently "$STO_DIR".
5887 + use an alternative directory to create the mini_fo
5888 + mountpoint (default is currently "$MNT_DIR".
5890 + -h displays this message.
5896 +while getopts hm:s:d: OPTS
5899 + s) SUFF="$OPTARG";;
5900 + d) STO_DIR="$OPTARG";;
5901 + m) MNT_DIR="$OPTARG";;
5907 +shift $(($OPTIND - 1))
5911 +if [ "x$HELP" == "xset" ]; then
5917 +if [ "x$SUFF" != "x" ]; then
5921 +# kill trailing slashes
5922 +MNT_DIR=${MNT_DIR%/}
5923 +STO_DIR=${STO_DIR%/}
5927 +if ! [ -d "$BASE" ]; then
5928 + echo "invalid base dir $BASE, run $0 -h for help."
5933 +if ! [ -d "$MNT_DIR" ]; then
5934 + echo "invalid mount dir $MNT_DIR, run $0 -h for help."
5938 +if ! [ -d "$STO_DIR" ]; then
5939 + echo "invalid sto_dir_dir $STO_DIR, run $0 -h for help."
5943 +MNTP="$MNT_DIR/mini_fo-`basename $BASE`$SUFF"
5944 +STO="$STO_DIR/sto-`basename $BASE`$SUFF"
5946 +# create the mount point if it doesn't exist
5948 +if [ $? -ne 0 ]; then
5949 + echo "Error, failed to create mount point $MNTP"
5953 +if [ $? -ne 0 ]; then
5954 + echo "Error, failed to create storage dir $STO"
5957 +# check if fs is already mounted
5958 +mount | grep mini_fo | grep $MNTP &> /dev/null
5959 +if [ $? -eq 0 ]; then
5960 + echo "Error, existing mini_fo mount at $MNTP."
5964 +mount | grep mini_fo | grep $STO &> /dev/null
5965 +if [ $? -eq 0 ]; then
5966 + echo "Error, $STO seems to be used already."
5971 +mount -t mini_fo -o base=$BASE,sto=$STO $BASE $MNTP
5973 +if [ $? -ne 0 ]; then
5974 + echo "Error, mounting failed, maybe no permisson to mount?"
5976 diff -urN linux-2.6.21.1.old/fs/mini_fo/mmap.c linux-2.6.21.1.dev/fs/mini_fo/mmap.c
5977 --- linux-2.6.21.1.old/fs/mini_fo/mmap.c 1970-01-01 01:00:00.000000000 +0100
5978 +++ linux-2.6.21.1.dev/fs/mini_fo/mmap.c 2007-05-26 21:01:26.168329112 +0200
5981 + * Copyright (c) 1997-2003 Erez Zadok
5982 + * Copyright (c) 2001-2003 Stony Brook University
5984 + * For specific licensing information, see the COPYING file distributed with
5985 + * this package, or get one from ftp://ftp.filesystems.org/pub/fist/COPYING.
5987 + * This Copyright notice must be kept intact and distributed with all
5988 + * fistgen sources INCLUDING sources generated by fistgen.
5991 + * Copyright (C) 2004, 2005 Markus Klotzbuecher <mk@creamnet.de>
5993 + * This program is free software; you can redistribute it and/or
5994 + * modify it under the terms of the GNU General Public License
5995 + * as published by the Free Software Foundation; either version
5996 + * 2 of the License, or (at your option) any later version.
6003 +#ifdef HAVE_CONFIG_H
6004 +# include <config.h>
6005 +#endif /* HAVE_CONFIG_H */
6008 +#include "mini_fo.h"
6011 +#ifdef FIST_COUNT_WRITES
6012 +/* for counting writes in the middle vs. regular writes */
6013 +unsigned long count_writes = 0, count_writes_middle = 0;
6014 +#endif /* FIST_COUNT_WRITES */
6016 +/* forward declaration of commit write and prepare write */
6017 +STATIC int mini_fo_commit_write(file_t *file, page_t *page, unsigned from, unsigned to);
6018 +STATIC int mini_fo_prepare_write(file_t *file, page_t *page, unsigned from, unsigned to);
6022 + * Function for handling creation of holes when lseek-ing past the
6023 + * end of the file and then writing some data.
6026 +mini_fo_fill_zeros(file_t* file, page_t *page, unsigned from)
6029 + dentry_t *dentry = file->f_dentry;
6030 + inode_t *inode = dentry->d_inode;
6034 + print_entry_location();
6036 + for (index = inode->i_size >> PAGE_CACHE_SHIFT; index < page->index; index++) {
6037 + tmp_page = mini_fo_get1page(file, index);
6038 + if (IS_ERR(tmp_page)) {
6039 + err = PTR_ERR(tmp_page);
6044 + * zero out rest of the contents of the page between the appropriate
6047 + memset((char*)page_address(tmp_page) + (inode->i_size & ~PAGE_CACHE_MASK), 0, PAGE_CACHE_SIZE - (inode->i_size & ~PAGE_CACHE_MASK));
6049 + if (! (err = mini_fo_prepare_write(file, tmp_page, 0, PAGE_CACHE_SIZE)))
6050 + err = mini_fo_commit_write(file, tmp_page, 0, PAGE_CACHE_SIZE);
6052 + page_cache_release(tmp_page);
6055 + if (current->need_resched)
6059 + /* zero out appropriate parts of last page */
6062 + * if the encoding type is block, then adjust the 'from' (where the
6063 + * zeroing will start) offset appropriately
6065 + from = from & (~(FIST_ENCODING_BLOCKSIZE - 1));
6067 + if ((from - (inode->i_size & ~PAGE_CACHE_MASK)) > 0) {
6069 + memset((char*)page_address(page) + (inode->i_size & ~PAGE_CACHE_MASK), 0, from - (inode->i_size & ~PAGE_CACHE_MASK));
6070 + if (! (err = mini_fo_prepare_write(file, page, 0, PAGE_CACHE_SIZE)))
6071 + err = mini_fo_commit_write(file, page, 0, PAGE_CACHE_SIZE);
6075 + if (current->need_resched)
6080 + print_exit_status(err);
6087 +mini_fo_writepage(page_t *page)
6091 + inode_t *hidden_inode;
6092 + page_t *hidden_page;
6093 + char *kaddr, *hidden_kaddr;
6095 + print_entry_location();
6097 + inode = page->mapping->host;
6098 + hidden_inode = itohi(inode);
6101 + * writepage is called when shared mmap'ed files need to write
6102 + * their pages, while prepare/commit_write are called from the
6103 + * non-paged write() interface. (However, in 2.3 the two interfaces
6104 + * share the same cache, while in 2.2 they didn't.)
6106 + * So we pretty much have to duplicate much of what commit_write does.
6109 + /* find lower page (returns a locked page) */
6110 + hidden_page = grab_cache_page(hidden_inode->i_mapping, page->index);
6114 + /* get page address, and encode it */
6115 + kaddr = (char *) kmap(page);
6116 + hidden_kaddr = (char*) kmap(hidden_page);
6117 + mini_fo_encode_block(kaddr, hidden_kaddr, PAGE_CACHE_SIZE, inode, inode->i_sb, page->index);
6118 + /* if encode_block could fail, then return error */
6120 + kunmap(hidden_page);
6122 + /* call lower writepage (expects locked page) */
6123 + err = hidden_inode->i_mapping->a_ops->writepage(hidden_page);
6126 + * update mtime and ctime of lower level file system
6127 + * mini_fo' mtime and ctime are updated by generic_file_write
6129 + hidden_inode->i_mtime = hidden_inode->i_ctime = CURRENT_TIME;
6131 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,4,1)
6132 + UnlockPage(hidden_page); /* b/c grab_cache_page locked it */
6133 +# endif /* kernel older than 2.4.1 */
6134 + page_cache_release(hidden_page); /* b/c grab_cache_page increased refcnt */
6137 + ClearPageUptodate(page);
6139 + SetPageUptodate(page);
6141 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,1)
6143 +# endif /* kernel 2.4.1 and newer */
6144 + print_exit_status(err);
6150 + * get one page from cache or lower f/s, return error otherwise.
6151 + * returns unlocked, up-to-date page (if ok), with increased refcnt.
6154 +mini_fo_get1page(file_t *file, int index)
6159 + struct address_space *mapping;
6162 + print_entry_location();
6164 + dentry = file->f_dentry; /* CPW: Moved below print_entry_location */
6165 + inode = dentry->d_inode;
6166 + mapping = inode->i_mapping;
6168 + fist_dprint(8, "%s: read page index %d pid %d\n", __FUNCTION__, index, current->pid);
6170 + printk("%s BUG: index=%d\n", __FUNCTION__, index);
6171 + page = ERR_PTR(-EIO);
6174 + page = read_cache_page(mapping,
6176 + (filler_t *) mapping->a_ops->readpage,
6180 + wait_on_page(page);
6181 + if (!Page_Uptodate(page)) {
6183 + err = mapping->a_ops->readpage(file, page);
6185 + page = ERR_PTR(err);
6188 + wait_on_page(page);
6189 + if (!Page_Uptodate(page)) {
6190 + page = ERR_PTR(-EIO);
6196 + print_exit_pointer(page);
6202 + * get one page from cache or lower f/s, return error otherwise.
6203 + * similar to get1page, but doesn't guarantee that it will return
6204 + * an unlocked page.
6207 +mini_fo_get1page_cached(file_t *file, int index)
6212 + struct address_space *mapping;
6215 + print_entry_location();
6217 + dentry = file->f_dentry; /* CPW: Moved below print_entry_location */
6218 + inode = dentry->d_inode;
6219 + mapping = inode->i_mapping;
6221 + fist_dprint(8, "%s: read page index %d pid %d\n", __FUNCTION__, index, current->pid);
6223 + printk("%s BUG: index=%d\n", __FUNCTION__, index);
6224 + page = ERR_PTR(-EIO);
6227 + page = read_cache_page(mapping,
6229 + (filler_t *) mapping->a_ops->readpage,
6235 + print_exit_pointer(page);
6241 + * readpage is called from generic_page_read and the fault handler.
6242 + * If your file system uses generic_page_read for the read op, it
6243 + * must implement readpage.
6245 + * Readpage expects a locked page, and must unlock it.
6248 +mini_fo_do_readpage(file_t *file, page_t *page)
6252 + file_t *hidden_file = NULL;
6253 + dentry_t *hidden_dentry;
6255 + inode_t *hidden_inode;
6257 + page_t *hidden_page;
6258 + char *hidden_page_data;
6261 + print_entry_location();
6263 + dentry = file->f_dentry; /* CPW: Moved below print_entry_location */
6264 + if (ftopd(file) != NULL)
6265 + hidden_file = ftohf(file);
6266 + hidden_dentry = dtohd(dentry);
6267 + inode = dentry->d_inode;
6268 + hidden_inode = itohi(inode);
6270 + fist_dprint(7, "%s: requesting page %d from file %s\n", __FUNCTION__, page->index, dentry->d_name.name);
6272 + MALLOC_PAGE_POINTERS(hidden_pages, num_hidden_pages);
6273 + MALLOC_PAGEDATA_POINTERS(hidden_pages_data, num_hidden_pages);
6275 + CURRENT_HIDDEN_PAGE = NULL;
6277 + /* find lower page (returns a locked page) */
6279 + fist_dprint(8, "%s: Current page index = %d\n", __FUNCTION__, CURRENT_HIDDEN_PAGEINDEX);
6280 + CURRENT_HIDDEN_PAGE = read_cache_page(hidden_inode->i_mapping,
6281 + CURRENT_HIDDEN_PAGEINDEX,
6282 + (filler_t *) hidden_inode->i_mapping->a_ops->readpage,
6283 + (void *) hidden_file);
6284 + if (IS_ERR(CURRENT_HIDDEN_PAGE)) {
6285 + err = PTR_ERR(CURRENT_HIDDEN_PAGE);
6286 + CURRENT_HIDDEN_PAGE = NULL;
6292 + * wait for the page data to show up
6293 + * (signaled by readpage as unlocking the page)
6296 + wait_on_page(CURRENT_HIDDEN_PAGE);
6297 + if (!Page_Uptodate(CURRENT_HIDDEN_PAGE)) {
6299 + * call readpage() again if we returned from wait_on_page with a
6300 + * page that's not up-to-date; that can happen when a partial
6301 + * page has a few buffers which are ok, but not the whole
6304 + lock_page(CURRENT_HIDDEN_PAGE);
6305 + err = hidden_inode->i_mapping->a_ops->readpage(hidden_file,
6306 + CURRENT_HIDDEN_PAGE);
6308 + CURRENT_HIDDEN_PAGE = NULL;
6311 + wait_on_page(CURRENT_HIDDEN_PAGE);
6312 + if (!Page_Uptodate(CURRENT_HIDDEN_PAGE)) {
6319 + /* map pages, get their addresses */
6320 + page_data = (char *) kmap(page);
6322 + CURRENT_HIDDEN_PAGEDATA = (char *) kmap(CURRENT_HIDDEN_PAGE);
6324 + /* if decode_block could fail, then return error */
6326 + real_size = hidden_inode->i_size - (page->index << PAGE_CACHE_SHIFT);
6327 + if (real_size <= 0)
6328 + memset(page_data, 0, PAGE_CACHE_SIZE);
6329 + else if (real_size < PAGE_CACHE_SIZE) {
6330 + mini_fo_decode_block(hidden_page_data, page_data, real_size, inode, inode->i_sb, page->index);
6331 + memset(page_data + real_size, 0, PAGE_CACHE_SIZE - real_size);
6333 + mini_fo_decode_block(hidden_page_data, page_data, PAGE_CACHE_SIZE, inode, inode->i_sb, page->index);
6336 + kunmap(CURRENT_HIDDEN_PAGE);
6341 + if (CURRENT_HIDDEN_PAGE)
6342 + page_cache_release(CURRENT_HIDDEN_PAGE); /* undo read_cache_page */
6344 + FREE_PAGE_POINTERS(hidden_pages, num_hidden_pages);
6345 + FREE_PAGEDATA_POINTERS(hidden_pages_data, num_hidden_pages);
6349 + SetPageUptodate(page);
6351 + ClearPageUptodate(page);
6353 + print_exit_status(err);
6359 +mini_fo_readpage(file_t *file, page_t *page)
6362 + print_entry_location();
6364 + err = mini_fo_do_readpage(file, page);
6367 + * we have to unlock our page, b/c we _might_ have gotten a locked page.
6368 + * but we no longer have to wakeup on our page here, b/c UnlockPage does
6373 + print_exit_status(err);
6379 +mini_fo_prepare_write(file_t *file, page_t *page, unsigned from, unsigned to)
6383 + print_entry_location();
6386 + * we call kmap(page) only here, and do the kunmap
6387 + * and the actual downcalls, including unlockpage and uncache
6388 + * in commit_write.
6392 + /* fast path for whole page writes */
6393 + if (from == 0 && to == PAGE_CACHE_SIZE)
6395 + /* read the page to "revalidate" our data */
6396 + /* call the helper function which doesn't unlock the page */
6397 + if (!Page_Uptodate(page))
6398 + err = mini_fo_do_readpage(file, page);
6401 + print_exit_status(err);
6408 +mini_fo_commit_write(file_t *file, page_t *page, unsigned from, unsigned to)
6410 + int err = -ENOMEM;
6412 + inode_t *hidden_inode;
6413 + page_t *hidden_page;
6414 + file_t *hidden_file = NULL;
6416 + unsigned bytes = to - from;
6417 + unsigned hidden_from, hidden_to, hidden_bytes;
6419 + print_entry_location();
6421 + inode = page->mapping->host; /* CPW: Moved below print_entry_location */
6422 + hidden_inode = itohi(inode);
6424 + ASSERT(file != NULL);
6426 + * here we have a kmapped page, with data from the user copied
6427 + * into it. we need to encode_block it, and then call the lower
6428 + * commit_write. We also need to simulate same behavior of
6429 + * generic_file_write, and call prepare_write on the lower f/s first.
6431 +#ifdef FIST_COUNT_WRITES
6433 +# endif /* FIST_COUNT_WRITES */
6435 + /* this is append and/or extend -- we can't have holes so fill them in */
6436 + if (page->index > (hidden_inode->i_size >> PAGE_CACHE_SHIFT)) {
6439 + for (index = hidden_inode->i_size >> PAGE_CACHE_SHIFT; index < page->index; index++) {
6440 + tmp_page = mini_fo_get1page(file, index);
6441 + if (IS_ERR(tmp_page)) {
6442 + err = PTR_ERR(tmp_page);
6445 + /* zero out the contents of the page at the appropriate offsets */
6446 + memset((char*)page_address(tmp_page) + (inode->i_size & ~PAGE_CACHE_MASK), 0, PAGE_CACHE_SIZE - (inode->i_size & ~PAGE_CACHE_MASK));
6447 + if (!(err = mini_fo_prepare_write(file, tmp_page, 0, PAGE_CACHE_SIZE)))
6448 + err = mini_fo_commit_write(file, tmp_page, 0, PAGE_CACHE_SIZE);
6449 + page_cache_release(tmp_page);
6452 + if (current->need_resched)
6457 + if (ftopd(file) != NULL)
6458 + hidden_file = ftohf(file);
6460 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
6461 + mutex_lock(&hidden_inode->i_mutex);
6463 + down(&hidden_inode->i_sem);
6465 + /* find lower page (returns a locked page) */
6466 + hidden_page = grab_cache_page(hidden_inode->i_mapping, page->index);
6470 +#if FIST_ENCODING_BLOCKSIZE > 1
6471 +# error encoding_blocksize greater than 1 is not yet supported
6472 +# endif /* FIST_ENCODING_BLOCKSIZE > 1 */
6474 + hidden_from = from & (~(FIST_ENCODING_BLOCKSIZE - 1));
6475 + hidden_to = ((to + FIST_ENCODING_BLOCKSIZE - 1) & (~(FIST_ENCODING_BLOCKSIZE - 1)));
6476 + if ((page->index << PAGE_CACHE_SHIFT) + to > hidden_inode->i_size) {
6479 + * if this call to commit_write had introduced holes and the code
6480 + * for handling holes was invoked, then the beginning of this page
6481 + * must be zeroed out
6482 + * zero out bytes from 'size_of_file%pagesize' to 'from'.
6484 + if ((hidden_from - (inode->i_size & ~PAGE_CACHE_MASK)) > 0)
6485 + memset((char*)page_address(page) + (inode->i_size & ~PAGE_CACHE_MASK), 0, hidden_from - (inode->i_size & ~PAGE_CACHE_MASK));
6488 + hidden_bytes = hidden_to - hidden_from;
6490 + /* call lower prepare_write */
6492 + if (hidden_inode->i_mapping &&
6493 + hidden_inode->i_mapping->a_ops &&
6494 + hidden_inode->i_mapping->a_ops->prepare_write)
6495 + err = hidden_inode->i_mapping->a_ops->prepare_write(hidden_file,
6500 + /* don't leave locked pages behind, esp. on an ENOSPC */
6503 + fist_dprint(8, "%s: encoding %d bytes\n", __FUNCTION__, hidden_bytes);
6504 + 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);
6505 + /* if encode_block could fail, then goto unlock and return error */
6507 + /* call lower commit_write */
6508 + err = hidden_inode->i_mapping->a_ops->commit_write(hidden_file,
6516 + err = bytes; /* convert error to no. of bytes */
6518 + inode->i_blocks = hidden_inode->i_blocks;
6519 + /* we may have to update i_size */
6520 + pos = (page->index << PAGE_CACHE_SHIFT) + to;
6521 + if (pos > inode->i_size)
6522 + inode->i_size = pos;
6525 + * update mtime and ctime of lower level file system
6526 + * mini_fo' mtime and ctime are updated by generic_file_write
6528 + hidden_inode->i_mtime = hidden_inode->i_ctime = CURRENT_TIME;
6530 + mark_inode_dirty_sync(inode);
6533 + UnlockPage(hidden_page);
6534 + page_cache_release(hidden_page);
6535 + kunmap(page); /* kmap was done in prepare_write */
6537 + /* we must set our page as up-to-date */
6539 + ClearPageUptodate(page);
6541 + SetPageUptodate(page);
6543 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
6544 + mutex_unlock(&hidden_inode->i_mutex);
6546 + up(&hidden_inode->i_sem);
6548 + print_exit_status(err);
6549 + return err; /* assume all is ok */
6554 +mini_fo_bmap(struct address_space *mapping, long block)
6558 + inode_t *hidden_inode;
6560 + print_entry_location();
6562 + inode = (inode_t *) mapping->host;
6563 + hidden_inode = itohi(inode);
6565 + if (hidden_inode->i_mapping->a_ops->bmap)
6566 + err = hidden_inode->i_mapping->a_ops->bmap(hidden_inode->i_mapping, block);
6567 + print_exit_location();
6573 + * This function is copied verbatim from mm/filemap.c.
6574 + * XXX: It should be simply moved to some header file instead -- bug Al about it!
6576 +static inline int sync_page(struct page *page)
6578 + struct address_space *mapping = page->mapping;
6580 + if (mapping && mapping->a_ops && mapping->a_ops->sync_page)
6581 + return mapping->a_ops->sync_page(page);
6587 + * XXX: we may not need this function if not FIST_FILTER_DATA.
6588 + * FIXME: for FIST_FILTER_SCA, get all lower pages and sync them each.
6591 +mini_fo_sync_page(page_t *page)
6595 + inode_t *hidden_inode;
6596 + page_t *hidden_page;
6598 + print_entry_location();
6600 + inode = page->mapping->host; /* CPW: Moved below print_entry_location */
6601 + hidden_inode = itohi(inode);
6603 + /* find lower page (returns a locked page) */
6604 + hidden_page = grab_cache_page(hidden_inode->i_mapping, page->index);
6608 + err = sync_page(hidden_page);
6610 + UnlockPage(hidden_page); /* b/c grab_cache_page locked it */
6611 + page_cache_release(hidden_page); /* b/c grab_cache_page increased refcnt */
6614 + print_exit_status(err);
6617 diff -urN linux-2.6.21.1.old/fs/mini_fo/README linux-2.6.21.1.dev/fs/mini_fo/README
6618 --- linux-2.6.21.1.old/fs/mini_fo/README 1970-01-01 01:00:00.000000000 +0100
6619 +++ linux-2.6.21.1.dev/fs/mini_fo/README 2007-05-26 21:01:26.168329112 +0200
6621 +README for the mini_fo overlay file system
6622 +=========================================
6628 +mini_fo is a virtual kernel file system that can make read-only
6629 +file systems writable. This is done by redirecting modifying operations
6630 +to a writeable location called "storage directory", and leaving the
6631 +original data in the "base directory" untouched. When reading, the
6632 +file system merges the modifed and original data so that only the
6633 +newest versions will appear. This occurs transparently to the user,
6634 +who can access the data like on any other read-write file system.
6636 +Base and storage directories may be located on the same or on
6637 +different partitions and may be of different file system types. While
6638 +the storage directory obviously needs to be writable, the base may or
6639 +may not be writable, what doesn't matter as it will no be modified
6646 +The primary purpose of the mini_fo file system is to allow easy
6647 +software updates to embedded systems, that often store their root
6648 +file system in a read-only flash file system, but there are many
6649 +more as for example sandboxing, or for allowing live-cds to
6650 +permanently store information.
6655 +This should be simple. Adjust the Makefile to point to the correct
6656 +kernel headers you want to build the module for. Then:
6660 +should build "mini_fo.o" for a 2.4 kernel or "mini_fo.ko" for a 2.6
6663 +If you are building the module for you current kernel, you can install
6664 +the module (as root):
6673 +USING THE FILE SYSTEM
6674 +--------------------
6676 +the general mount syntax is:
6678 + mount -t mini_fo -o base=<base directory>,sto=<storage directory>\
6679 + <base directory> <mount point>
6683 +You have mounted a cdrom to /mnt/cdrom and want to modifiy some files
6686 +load the module (as root)
6688 + # insmod mini_fo.o for a 2.4 kernel or
6690 + # insmod mini_fo.ko for a 2.6 kernel
6693 +create a storage dir in tmp and a mountpoint for mini_fo:
6696 + # mkdir /mnt/mini_fo
6698 +and mount the mini_fo file system:
6700 + # mount -t mini_fo -o base=/mnt/cdrom,sto=/tmp/sto /mnt/cdrom /mnt/mini_fo
6703 +Now the data stored on the cd can be accessed via the mini_fo
6704 +mountpoint just like any read-write file system, files can be modified
6705 +and deleted, new ones can be created and so on. When done unmount the
6708 + # unmount /mnt/mini_fo
6710 +Note that if the file system is mounted again using the same storage
6711 +file system, of course it will appear in the modified state again. If
6712 +you remount it using an new empty storage directory, it will be
6713 +unmodified. Therefore by executing:
6718 +you can nuke all the changes you made to the original file system. But
6719 + remember NEVER do this while the mini_fo file system is mounted!
6722 +Alternatively you can use the mini_fo-overlay bash script, that
6723 +simplifies managing mini_fo mounts. See TOOLS Section.
6729 +mini_fo-merge (experimental):
6731 +This is a bash script that will merge changes contained in the storage
6732 +directory back to the base directory. This allows mini_fo to function
6733 +as a cache file system by overlaying a slow (network, ...) file system
6734 +and using a fast (ramdisk, ...) as storage. When done, changes can be
6735 +merged back to the (slow) base with mini_fo-merge. See "mini_fo-merge
6738 +It can be usefull for merging changes back after a successfull test
6739 +(patches, software updates...)
6744 +This bash script simplifies managing one or more mini_fo mounts. For
6745 +overlaying a directory called "basedir1", you can just call:
6747 + # mini_fo-overlay basedir1
6749 +This will mount mini_fo with "basedir1" as base, "/tmp/sto-basedir1/"
6750 +as storage to "/mnt/mini_fo-basedir1/". It has more options though,
6751 +type "mini_fo-overlay -h" for details.
6754 +DOCUMENTATION, REPORTING BUGS, GETTING HELP
6755 +-------------------------------------------
6757 +Please visit the mini_fo project page at:
6759 +http://www.denx.de/twiki/bin/view/Know/MiniFOHome
6765 +Never modify the base or the storage directorys while the mini_fo
6766 +file system is mounted, or you might crash you system. Simply accessing
6767 +and reading should not cause any trouble.
6769 +Exporting a mini_fo mount point via NFS has not been tested, and may
6772 +Check the RELEASE_NOTES for details on bugs and features.
6776 +Copyright (C) 2004, 2005 Markus Klotzbuecher <mk@creamnet.de>
6778 +This program is free software; you can redistribute it and/or
6779 +modify it under the terms of the GNU General Public License
6780 +as published by the Free Software Foundation; either version
6781 +2 of the License, or (at your option) any later version.
6784 diff -urN linux-2.6.21.1.old/fs/mini_fo/RELEASE_NOTES linux-2.6.21.1.dev/fs/mini_fo/RELEASE_NOTES
6785 --- linux-2.6.21.1.old/fs/mini_fo/RELEASE_NOTES 1970-01-01 01:00:00.000000000 +0100
6786 +++ linux-2.6.21.1.dev/fs/mini_fo/RELEASE_NOTES 2007-05-26 21:01:26.168329112 +0200
6788 +Release: mini_fo-0.6.1 (v0-6-1)
6796 +- bugfixes (see ChangeLog)
6798 +- two helper scripts "mini_fo_merge" and "mini_fo_overlay" (see
6799 + README for details).
6803 +- Support for 2.4 and 2.6 (see Makefile)
6805 +- Partial hard link support (creating works as expected, but already
6806 + existing links in the base file system will be treated as if they
6807 + were individual files).
6809 +- Various bugfixes and cleanups.
6814 +- This is mini_fo-0-6-0-pre1! This release is a complete rewrite of
6815 + many vital mini_fo parts such as the old whiteout list code which
6816 + has been replaced by the new META subsystem.
6818 +- Light weight directory renaming implemented. This means if a
6819 + directory is renamed via the mini_fo filesystem this will no longer
6820 + result in a complete copy in storage, instead only one empty
6821 + directory will be created. All base filed contained in the original
6822 + directory stay there until modified.
6824 +- Special files (creating, renaming, deleting etc.) now working.
6826 +- Many bugfixes and cleanup, mini_fo is now a lot more stable.
6831 +- Final release of the 0-5-* versions. Next will be a complete rewrite
6832 + of many features. This release contains several bugfixes related to
6833 + directory renaming.
6838 +- Lots of cleanup and several bugfixes related to directory deleting
6840 +- Directory renaming suddenly works, what is most likely due to the
6841 + fact tha that "mv" is smart: if the classic rename doesn't work it
6842 + will assume that source and target file are on different fs and will
6843 + copy the directory and try to remove the source directory. Until
6844 + directory removing wasn't implemented, it would fail to do this and
6846 + So, directory renaming works for now, but it doesn't yet do what you
6847 + would expect from a overlay fs, so use with care.
6852 +- implemented directory deleting
6853 +- made parsing of mount options more stable
6854 +- New format of mount options! (See README)
6855 +- I can't reproduce the unknown panic with 2.4.25 anymore, so I'll
6856 + happily assume it never existed!
6859 +Implemented features:
6860 +---------------------
6862 +- creating hard links (see BUGS on already existing hard links)
6863 +- lightweight directory renaming
6864 +- renaming device files, pipes, sockets, etc.
6865 +- creating, renaming, deleting of special files
6866 +- deleting directorys
6867 +- general directory reading (simple "ls" )
6868 +- creating files in existing directorys
6869 +- creating directorys
6871 +- reading and writing files (involves opening)
6872 +- appending to files (creates copy in storage)
6874 +- llseek works too, what allows editors to work
6875 +- persistency (a deleted file stay deleted over remounts)
6876 +- use of symbolic links
6877 +- creating of device files
6880 +Not (yet) implemented features:
6881 +-------------------------------
6883 +- full hard link support.
6890 +Hard links in the base file system will be treated as individual
6891 +files, not as links to one inode.
6893 +The main problem with hard links isn't allowing to create them, but
6894 +their pure existence. If you modify a base hard link, the changes made
6895 +will only show up on this link, the other link will remain in the
6896 +original state. I hope to fix this someday. Please note that this does
6897 +not effect the special hard links '.' and '..', that are handled
6898 +seperately by the lower fs.
6899 diff -urN linux-2.6.21.1.old/fs/mini_fo/state.c linux-2.6.21.1.dev/fs/mini_fo/state.c
6900 --- linux-2.6.21.1.old/fs/mini_fo/state.c 1970-01-01 01:00:00.000000000 +0100
6901 +++ linux-2.6.21.1.dev/fs/mini_fo/state.c 2007-05-26 21:01:26.169328960 +0200
6904 + * Copyright (C) 2005 Markus Klotzbuecher <mk@creamnet.de>
6906 + * This program is free software; you can redistribute it and/or
6907 + * modify it under the terms of the GNU General Public License
6908 + * as published by the Free Software Foundation; either version
6909 + * 2 of the License, or (at your option) any later version.
6912 +#ifdef HAVE_CONFIG_H
6913 +# include <config.h>
6914 +#endif /* HAVE_CONFIG_H */
6917 +#include "mini_fo.h"
6920 +/* create the storage file, setup new states */
6921 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
6922 +int create_sto_reg_file(dentry_t *dentry, int mode, struct nameidata *nd)
6924 +int create_sto_reg_file(dentry_t *dentry, int mode)
6929 + dentry_t *hidden_sto_dentry;
6930 + dentry_t *hidden_sto_dir_dentry;
6932 + if(exists_in_storage(dentry)) {
6933 + printk(KERN_CRIT "mini_fo: create_sto_file: wrong type or state.\n");
6937 + err = get_neg_sto_dentry(dentry);
6940 + printk(KERN_CRIT "mini_fo: create_sto_file: ERROR getting neg. sto dentry.\n");
6944 + dir = dentry->d_parent->d_inode;
6945 + hidden_sto_dentry = dtohd2(dentry);
6948 + hidden_sto_dir_dentry = dget(hidden_sto_dentry->d_parent);
6950 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
6951 + mutex_lock(&hidden_sto_dir_dentry->d_inode->i_mutex);
6953 + down(&hidden_sto_dir_dentry->d_inode->i_sem);
6956 + err = PTR_ERR(hidden_sto_dir_dentry);
6957 + if (IS_ERR(hidden_sto_dir_dentry))
6960 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
6961 + err = vfs_create(hidden_sto_dir_dentry->d_inode,
6962 + hidden_sto_dentry,
6965 + err = vfs_create(hidden_sto_dir_dentry->d_inode,
6966 + hidden_sto_dentry,
6970 + printk(KERN_CRIT "mini_fo: create_sto_file: ERROR creating sto file.\n");
6974 + if(!dtohd2(dentry)->d_inode) {
6975 + printk(KERN_CRIT "mini_fo: create_sto_file: ERROR creating sto file [2].\n");
6980 + /* interpose the new inode */
6981 + if(dtost(dentry) == DELETED) {
6982 + dtost(dentry) = DEL_REWRITTEN;
6983 + err = mini_fo_tri_interpose(NULL, hidden_sto_dentry, dentry, dir->i_sb, 0);
6987 + else if(dtost(dentry) == NON_EXISTANT) {
6988 + dtost(dentry) = CREATED;
6989 + err = mini_fo_tri_interpose(dtohd(dentry), hidden_sto_dentry, dentry, dir->i_sb, 0);
6993 + else if(dtost(dentry) == UNMODIFIED) {
6994 + dtost(dentry) = MODIFIED;
6995 + /* interpose on new inode */
6996 + if(itohi2(dentry->d_inode) != NULL) {
6997 + printk(KERN_CRIT "mini_fo: create_sto_file: invalid inode detected.\n");
7001 + itohi2(dentry->d_inode) = igrab(dtohd2(dentry)->d_inode);
7003 + fist_copy_attr_timesizes(dentry->d_parent->d_inode,
7004 + hidden_sto_dir_dentry->d_inode);
7007 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
7008 + mutex_unlock(&hidden_sto_dir_dentry->d_inode->i_mutex);
7010 + up(&hidden_sto_dir_dentry->d_inode->i_sem);
7012 + dput(hidden_sto_dir_dentry);
7017 +/* create the sto dir, setup states */
7018 +int create_sto_dir(dentry_t *dentry, int mode)
7022 + dentry_t *hidden_sto_dentry;
7023 + dentry_t *hidden_sto_dir_dentry;
7025 + /* had to take the "!S_ISDIR(mode))" check out, because it failed */
7026 + if(exists_in_storage(dentry)) {
7027 + printk(KERN_CRIT "mini_fo: create_sto_dir: wrong type or state.\\
7033 + err = get_neg_sto_dentry(dentry);
7039 + dir = dentry->d_parent->d_inode;
7040 + hidden_sto_dentry = dtohd2(dentry);
7042 + /* was: hidden_sto_dir_dentry = lock_parent(hidden_sto_dentry); */
7043 + hidden_sto_dir_dentry = dget(hidden_sto_dentry->d_parent);
7045 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
7046 + mutex_lock(&hidden_sto_dir_dentry->d_inode->i_mutex);
7048 + down(&hidden_sto_dir_dentry->d_inode->i_sem);
7051 + err = PTR_ERR(hidden_sto_dir_dentry);
7052 + if (IS_ERR(hidden_sto_dir_dentry))
7055 + err = vfs_mkdir(hidden_sto_dir_dentry->d_inode,
7056 + hidden_sto_dentry,
7059 + printk(KERN_CRIT "mini_fo: create_sto_dir: ERROR creating sto dir.\n");
7063 + if(!dtohd2(dentry)->d_inode) {
7064 + printk(KERN_CRIT "mini_fo: create_sto_dir: ERROR creating sto dir [2].\n");
7069 + /* interpose the new inode */
7070 + if(dtost(dentry) == DELETED) {
7071 + dtost(dentry) = DEL_REWRITTEN;
7072 + err = mini_fo_tri_interpose(NULL, hidden_sto_dentry, dentry, dir->i_sb, 0);
7076 + else if(dtopd(dentry)->state == NON_EXISTANT) {
7077 + dtopd(dentry)->state = CREATED;
7078 + err = mini_fo_tri_interpose(dtohd(dentry), hidden_sto_dentry, dentry, dir->i_sb, 0);
7082 + else if(dtopd(dentry)->state == UNMODIFIED) {
7083 + dtopd(dentry)->state = MODIFIED;
7084 + /* interpose on new inode */
7085 + if(itohi2(dentry->d_inode) != NULL) {
7086 + printk(KERN_CRIT "mini_fo: create_sto_dir: ERROR, invalid inode detected.\n");
7090 + itohi2(dentry->d_inode) = igrab(dtohd2(dentry)->d_inode);
7093 + fist_copy_attr_timesizes(dir, hidden_sto_dir_dentry->d_inode);
7095 + /* initalize the wol list */
7096 + itopd(dentry->d_inode)->deleted_list_size = -1;
7097 + itopd(dentry->d_inode)->renamed_list_size = -1;
7098 + meta_build_lists(dentry);
7102 + /* was: unlock_dir(hidden_sto_dir_dentry); */
7103 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
7104 + mutex_unlock(&hidden_sto_dir_dentry->d_inode->i_mutex);
7106 + up(&hidden_sto_dir_dentry->d_inode->i_sem);
7108 + dput(hidden_sto_dir_dentry);
7113 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
7114 +int create_sto_nod(dentry_t *dentry, int mode, dev_t dev)
7116 +int create_sto_nod(dentry_t *dentry, int mode, int dev)
7121 + dentry_t *hidden_sto_dentry;
7122 + dentry_t *hidden_sto_dir_dentry;
7124 + if(exists_in_storage(dentry)) {
7128 + err = get_neg_sto_dentry(dentry);
7131 + printk(KERN_CRIT "mini_fo: create_sto_nod: ERROR getting neg. sto dentry.\n");
7135 + dir = dentry->d_parent->d_inode;
7136 + hidden_sto_dentry = dtohd2(dentry);
7139 + hidden_sto_dir_dentry = dget(hidden_sto_dentry->d_parent);
7141 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
7142 + mutex_lock(&hidden_sto_dir_dentry->d_inode->i_mutex);
7144 + down(&hidden_sto_dir_dentry->d_inode->i_sem);
7147 + err = PTR_ERR(hidden_sto_dir_dentry);
7148 + if (IS_ERR(hidden_sto_dir_dentry))
7151 + err = vfs_mknod(hidden_sto_dir_dentry->d_inode, hidden_sto_dentry, mode, dev);
7155 + if(!dtohd2(dentry)->d_inode) {
7156 + printk(KERN_CRIT "mini_fo: create_sto_nod: creating storage inode failed [1].\n");
7157 + err = -EINVAL; /* return something indicating failure */
7161 + /* interpose the new inode */
7162 + if(dtost(dentry) == DELETED) {
7163 + dtost(dentry) = DEL_REWRITTEN;
7164 + err = mini_fo_tri_interpose(NULL, hidden_sto_dentry, dentry, dir->i_sb, 0);
7168 + else if(dtost(dentry) == NON_EXISTANT) {
7169 + dtost(dentry) = CREATED;
7170 + err = mini_fo_tri_interpose(dtohd(dentry), hidden_sto_dentry, dentry, dir->i_sb, 0);
7174 + else if(dtost(dentry) == UNMODIFIED) {
7175 + dtost(dentry) = MODIFIED;
7176 + /* interpose on new inode */
7177 + if(itohi2(dentry->d_inode) != NULL) {
7178 + printk(KERN_CRIT "mini_fo: create_sto_nod: error, invalid inode detected.\n");
7182 + itohi2(dentry->d_inode) = igrab(dtohd2(dentry)->d_inode);
7185 + fist_copy_attr_timesizes(dir, hidden_sto_dir_dentry->d_inode);
7188 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
7189 + mutex_unlock(&hidden_sto_dir_dentry->d_inode->i_mutex);
7191 + up(&hidden_sto_dir_dentry->d_inode->i_sem);
7193 + dput(hidden_sto_dir_dentry);
7199 +/* unimplemented (and possibly not usefull):
7201 + nondir-del_to_del_rew
7202 + nondir-non_exist_to_creat
7207 + dir-del_rew_to_del
7208 + dir-del_to_del_rew
7209 + dir-non_exist_to_creat
7213 +/* bring a file of any type from state UNMODIFIED to MODIFIED */
7214 +int nondir_unmod_to_mod(dentry_t *dentry, int cp_flag)
7217 + struct vfsmount *tgt_mnt;
7218 + struct vfsmount *src_mnt;
7219 + dentry_t *tgt_dentry;
7220 + dentry_t *src_dentry;
7221 + dentry_t *hidden_sto_dentry;
7222 + dentry_t *hidden_sto_dir_dentry;
7224 + check_mini_fo_dentry(dentry);
7226 + if((dtost(dentry) != UNMODIFIED) ||
7227 + S_ISDIR(dentry->d_inode->i_mode)) {
7228 + printk(KERN_CRIT "mini_fo: nondir_unmod_to_mod: \
7229 + wrong type or state.\n");
7233 + err = get_neg_sto_dentry(dentry);
7236 + printk(KERN_CRIT "mini_fo: nondir_unmod_to_mod: \
7237 + ERROR getting neg. sto dentry.\n");
7241 + /* create sto file */
7242 + hidden_sto_dentry = dtohd2(dentry);
7245 + hidden_sto_dir_dentry = dget(hidden_sto_dentry->d_parent);
7247 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
7248 + mutex_lock(&hidden_sto_dir_dentry->d_inode->i_mutex);
7250 + down(&hidden_sto_dir_dentry->d_inode->i_sem);
7253 + err = PTR_ERR(hidden_sto_dir_dentry);
7254 + if (IS_ERR(hidden_sto_dir_dentry))
7257 + /* handle different types of nondirs */
7258 + if(S_ISCHR(dentry->d_inode->i_mode) ||
7259 + S_ISBLK(dentry->d_inode->i_mode)) {
7260 + err = vfs_mknod(hidden_sto_dir_dentry->d_inode,
7261 + hidden_sto_dentry,
7262 + dtohd(dentry)->d_inode->i_mode,
7263 + dtohd(dentry)->d_inode->i_rdev);
7266 + else if(S_ISREG(dentry->d_inode->i_mode)) {
7268 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
7269 + err = vfs_create(hidden_sto_dir_dentry->d_inode,
7270 + hidden_sto_dentry,
7271 + dtohd(dentry)->d_inode->i_mode, NULL);
7273 + err = vfs_create(hidden_sto_dir_dentry->d_inode,
7274 + hidden_sto_dentry,
7275 + dtohd(dentry)->d_inode->i_mode);
7279 + printk(KERN_CRIT "mini_fo: nondir_unmod_to_mod: \
7280 + ERROR creating sto file.\n");
7284 + /* interpose on new inode */
7285 + if(itohi2(dentry->d_inode) != NULL) {
7286 + printk(KERN_CRIT "mini_fo: nondir_unmod_to_mod: \
7287 + ERROR, invalid inode detected.\n");
7292 + itohi2(dentry->d_inode) = igrab(dtohd2(dentry)->d_inode);
7294 + fist_copy_attr_timesizes(dentry->d_parent->d_inode,
7295 + hidden_sto_dir_dentry->d_inode);
7296 + dtost(dentry) = MODIFIED;
7298 + /* copy contents if regular file and cp_flag = 1 */
7299 + if((cp_flag == 1) && S_ISREG(dentry->d_inode->i_mode)) {
7301 + /* unlock first */
7302 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
7303 + mutex_unlock(&hidden_sto_dir_dentry->d_inode->i_mutex);
7305 + up(&hidden_sto_dir_dentry->d_inode->i_sem);
7308 + dput(hidden_sto_dir_dentry);
7310 + tgt_dentry = dtohd2(dentry);
7311 + tgt_mnt = stopd(dentry->d_inode->i_sb)->hidden_mnt2;
7312 + src_dentry = dtohd(dentry);
7313 + src_mnt = stopd(dentry->d_inode->i_sb)->hidden_mnt;
7315 + err = mini_fo_cp_cont(tgt_dentry, tgt_mnt,
7316 + src_dentry, src_mnt);
7318 + printk(KERN_CRIT "mini_fo: nondir_unmod_to_mod: \
7319 + ERROR copying contents.\n");
7325 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
7326 + mutex_unlock(&hidden_sto_dir_dentry->d_inode->i_mutex);
7328 + up(&hidden_sto_dir_dentry->d_inode->i_sem);
7330 + dput(hidden_sto_dir_dentry);
7335 +/* this function is currently identical to nondir_creat_to_del */
7336 +int nondir_del_rew_to_del(dentry_t *dentry)
7338 + return nondir_creat_to_del(dentry);
7341 +int nondir_creat_to_del(dentry_t *dentry)
7345 + inode_t *hidden_sto_dir_inode;
7346 + dentry_t *hidden_sto_dir_dentry;
7347 + dentry_t *hidden_sto_dentry;
7349 + check_mini_fo_dentry(dentry);
7351 + /* for now this function serves for both state DEL_REWRITTEN and
7353 + if(!(dtost(dentry) == CREATED || (dtost(dentry) == DEL_REWRITTEN)) ||
7354 + S_ISDIR(dentry->d_inode->i_mode)) {
7355 + printk(KERN_CRIT "mini_fo: nondir_mod_to_del/del_rew_to_del: \
7356 + wrong type or state.\n");
7361 + hidden_sto_dir_inode = itohi2(dentry->d_parent->d_inode);
7362 + hidden_sto_dentry = dtohd2(dentry);
7364 + /* was: hidden_sto_dir_dentry = lock_parent(hidden_sto_dentry);*/
7365 + hidden_sto_dir_dentry = dget(hidden_sto_dentry->d_parent);
7367 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
7368 + mutex_lock(&hidden_sto_dir_dentry->d_inode->i_mutex);
7370 + down(&hidden_sto_dir_dentry->d_inode->i_sem);
7373 + /* avoid destroying the hidden inode if the file is in use */
7374 + dget(hidden_sto_dentry);
7375 + err = vfs_unlink(hidden_sto_dir_inode, hidden_sto_dentry);
7376 + dput(hidden_sto_dentry);
7378 + d_delete(hidden_sto_dentry);
7380 + /* propagate number of hard-links */
7381 + dentry->d_inode->i_nlink = itohi2(dentry->d_inode)->i_nlink;
7383 + dtost(dentry) = NON_EXISTANT;
7385 + /* was: unlock_dir(hidden_sto_dir_dentry); */
7386 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
7387 + mutex_unlock(&hidden_sto_dir_dentry->d_inode->i_mutex);
7389 + up(&hidden_sto_dir_dentry->d_inode->i_sem);
7391 + dput(hidden_sto_dir_dentry);
7397 +int nondir_mod_to_del(dentry_t *dentry)
7400 + dentry_t *hidden_sto_dentry;
7401 + inode_t *hidden_sto_dir_inode;
7402 + dentry_t *hidden_sto_dir_dentry;
7404 + check_mini_fo_dentry(dentry);
7406 + if(dtost(dentry) != MODIFIED ||
7407 + S_ISDIR(dentry->d_inode->i_mode)) {
7408 + printk(KERN_CRIT "mini_fo: nondir_mod_to_del: \
7409 + wrong type or state.\n");
7414 + hidden_sto_dir_inode = itohi2(dentry->d_parent->d_inode);
7415 + hidden_sto_dentry = dtohd2(dentry);
7417 + /* was hidden_sto_dir_dentry = lock_parent(hidden_sto_dentry); */
7418 + hidden_sto_dir_dentry = dget(hidden_sto_dentry->d_parent);
7420 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
7421 + mutex_lock(&hidden_sto_dir_dentry->d_inode->i_mutex);
7423 + down(&hidden_sto_dir_dentry->d_inode->i_sem);
7426 + /* avoid destroying the hidden inode if the file is in use */
7427 + dget(hidden_sto_dentry);
7428 + err = vfs_unlink(hidden_sto_dir_inode, hidden_sto_dentry);
7429 + dput(hidden_sto_dentry);
7431 + d_delete(hidden_sto_dentry);
7433 + /* propagate number of hard-links */
7434 + dentry->d_inode->i_nlink = itohi2(dentry->d_inode)->i_nlink;
7436 + /* dput base dentry, this will relase the inode and free the
7437 + * dentry, as we will never need it again. */
7438 + dput(dtohd(dentry));
7439 + dtohd(dentry) = NULL;
7440 + dtost(dentry) = DELETED;
7442 + /* add deleted file to META-file */
7443 + meta_add_d_entry(dentry->d_parent,
7444 + dentry->d_name.name,
7445 + dentry->d_name.len);
7447 + /* was: unlock_dir(hidden_sto_dir_dentry); */
7448 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
7449 + mutex_unlock(&hidden_sto_dir_dentry->d_inode->i_mutex);
7451 + up(&hidden_sto_dir_dentry->d_inode->i_sem);
7453 + dput(hidden_sto_dir_dentry);
7459 +int nondir_unmod_to_del(dentry_t *dentry)
7463 + check_mini_fo_dentry(dentry);
7465 + if(dtost(dentry) != UNMODIFIED ||
7466 + S_ISDIR(dentry->d_inode->i_mode)) {
7467 + printk(KERN_CRIT "mini_fo: nondir_unmod_to_del: \
7468 + wrong type or state.\n");
7473 + /* next we have to get a negative dentry for the storage file */
7474 + err = get_neg_sto_dentry(dentry);
7479 + /* add deleted file to META lists */
7480 + err = meta_add_d_entry(dentry->d_parent,
7481 + dentry->d_name.name,
7482 + dentry->d_name.len);
7487 + /* dput base dentry, this will relase the inode and free the
7488 + * dentry, as we will never need it again. */
7489 + dput(dtohd(dentry));
7490 + dtohd(dentry) = NULL;
7491 + dtost(dentry) = DELETED;
7497 +/* bring a dir from state UNMODIFIED to MODIFIED */
7498 +int dir_unmod_to_mod(dentry_t *dentry)
7502 + check_mini_fo_dentry(dentry);
7504 + if(dtost(dentry) != UNMODIFIED ||
7505 + !S_ISDIR(dentry->d_inode->i_mode)) {
7506 + printk(KERN_CRIT "mini_fo: dir_unmod_to_mod: \
7507 + wrong type or state.\n");
7512 + /* this creates our dir incl. sto. structure */
7513 + err = build_sto_structure(dentry->d_parent, dentry);
7515 + printk(KERN_CRIT "mini_fo: dir_unmod_to_mod: \
7516 + build_sto_structure failed.\n");
7523 diff -urN linux-2.6.21.1.old/fs/mini_fo/super.c linux-2.6.21.1.dev/fs/mini_fo/super.c
7524 --- linux-2.6.21.1.old/fs/mini_fo/super.c 1970-01-01 01:00:00.000000000 +0100
7525 +++ linux-2.6.21.1.dev/fs/mini_fo/super.c 2007-05-26 21:01:26.169328960 +0200
7528 + * Copyright (c) 1997-2003 Erez Zadok
7529 + * Copyright (c) 2001-2003 Stony Brook University
7531 + * For specific licensing information, see the COPYING file distributed with
7532 + * this package, or get one from ftp://ftp.filesystems.org/pub/fist/COPYING.
7534 + * This Copyright notice must be kept intact and distributed with all
7535 + * fistgen sources INCLUDING sources generated by fistgen.
7538 + * Copyright (C) 2004, 2005 Markus Klotzbuecher <mk@creamnet.de>
7540 + * This program is free software; you can redistribute it and/or
7541 + * modify it under the terms of the GNU General Public License
7542 + * as published by the Free Software Foundation; either version
7543 + * 2 of the License, or (at your option) any later version.
7550 +#ifdef HAVE_CONFIG_H
7551 +# include <config.h>
7555 +#include "mini_fo.h"
7559 +mini_fo_read_inode(inode_t *inode)
7561 + static struct address_space_operations mini_fo_empty_aops;
7563 + __itopd(inode) = kmalloc(sizeof(struct mini_fo_inode_info), GFP_KERNEL);
7564 + if (!itopd(inode)) {
7565 + printk("<0>%s:%s:%d: No kernel memory!\n", __FILE__, __FUNCTION__, __LINE__);
7568 + itohi(inode) = NULL;
7569 + itohi2(inode) = NULL;
7571 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
7572 + inode->i_version++;
7574 + inode->i_version = ++event; /* increment inode version */
7576 + inode->i_op = &mini_fo_main_iops;
7577 + inode->i_fop = &mini_fo_main_fops;
7580 + * XXX: To export a file system via NFS, it has to have the
7581 + * FS_REQUIRES_DEV flag, so turn it on. But should we inherit it from
7582 + * the lower file system, or can we allow our file system to be exported
7583 + * even if the lower one cannot be natively exported.
7585 + inode->i_sb->s_type->fs_flags |= FS_REQUIRES_DEV;
7587 + * OK, the above was a hack, which is now turned off because it may
7588 + * cause a panic/oops on some systems. The correct way to export a
7589 + * "nodev" filesystem is via using nfs-utils > 1.0 and the "fsid=" export
7590 + * parameter, which requires 2.4.20 or later.
7593 + /* I don't think ->a_ops is ever allowed to be NULL */
7594 + inode->i_mapping->a_ops = &mini_fo_empty_aops;
7598 +#if defined(FIST_DEBUG) || defined(FIST_FILTER_SCA)
7600 + * No need to call write_inode() on the lower inode, as it
7601 + * will have been marked 'dirty' anyway. But we might need
7602 + * to write some of our own stuff to disk.
7605 +mini_fo_write_inode(inode_t *inode, int sync)
7607 + print_entry_location();
7608 + print_exit_location();
7610 +#endif /* defined(FIST_DEBUG) || defined(FIST_FILTER_SCA) */
7614 +mini_fo_put_inode(inode_t *inode)
7617 + * This is really funky stuff:
7618 + * Basically, if i_count == 1, iput will then decrement it and this inode will be destroyed.
7619 + * It is currently holding a reference to the hidden inode.
7620 + * Therefore, it needs to release that reference by calling iput on the hidden inode.
7621 + * iput() _will_ do it for us (by calling our clear_inode), but _only_ if i_nlink == 0.
7622 + * The problem is, NFS keeps i_nlink == 1 for silly_rename'd files.
7623 + * So we must for our i_nlink to 0 here to trick iput() into calling our clear_inode.
7625 + if (atomic_read(&inode->i_count) == 1)
7626 + inode->i_nlink = 0;
7630 +#if defined(FIST_DEBUG) || defined(FIST_FILTER_SCA)
7632 + * we now define delete_inode, because there are two VFS paths that may
7633 + * destroy an inode: one of them calls clear inode before doing everything
7634 + * else that's needed, and the other is fine. This way we truncate the inode
7635 + * size (and its pages) and then clear our own inode, which will do an iput
7636 + * on our and the lower inode.
7639 +mini_fo_delete_inode(inode_t *inode)
7641 + print_entry_location();
7643 + fist_checkinode(inode, "mini_fo_delete_inode IN");
7644 + inode->i_size = 0; /* every f/s seems to do that */
7645 + clear_inode(inode);
7647 + print_exit_location();
7649 +#endif /* defined(FIST_DEBUG) || defined(FIST_FILTER_SCA) */
7652 +/* final actions when unmounting a file system */
7654 +mini_fo_put_super(super_block_t *sb)
7657 + mntput(stopd(sb)->hidden_mnt);
7658 + mntput(stopd(sb)->hidden_mnt2);
7660 + /* mk: no! dput(stopd(sb)->base_dir_dentry);
7661 + dput(stopd(sb)->storage_dir_dentry); */
7664 + __stopd(sb) = NULL;
7671 + * This is called in do_umount before put_super.
7672 + * The superblock lock is not held yet.
7673 + * We probably do not need to define this or call write_super
7674 + * on the hidden_sb, because sync_supers() will get to hidden_sb
7675 + * sooner or later. But it is also called from file_fsync()...
7678 +mini_fo_write_super(super_block_t *sb)
7682 +#endif /* NOT_NEEDED */
7686 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,18)
7687 +mini_fo_statfs(struct dentry *d, struct kstatfs *buf)
7688 +#elif LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
7689 +mini_fo_statfs(super_block_t *sb, struct kstatfs *buf)
7691 +mini_fo_statfs(super_block_t *sb, struct statfs *buf)
7695 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,18)
7696 + struct dentry *hidden_d;
7698 + hidden_d = dtohd(d);
7699 + err = vfs_statfs(hidden_d, buf);
7701 + super_block_t *hidden_sb;
7703 + hidden_sb = stohs(sb);
7704 + err = vfs_statfs(hidden_sb, buf);
7712 + * XXX: not implemented. This is not allowed yet.
7713 + * Should we call this on the hidden_sb? Probably not.
7716 +mini_fo_remount_fs(super_block_t *sb, int *flags, char *data)
7718 + //printk(KERN_CRIT "mini_fo_remount_fs: WARNING, this function is umimplemented.\n");
7724 + * Called by iput() when the inode reference count reached zero
7725 + * and the inode is not hashed anywhere. Used to clear anything
7726 + * that needs to be, before the inode is completely destroyed and put
7727 + * on the inode free list.
7730 +mini_fo_clear_inode(inode_t *inode)
7733 + * Decrement a reference to a hidden_inode, which was incremented
7734 + * by our read_inode when it was created initially.
7737 + /* release the wol_list */
7738 + if(S_ISDIR(inode->i_mode)) {
7739 + __meta_put_lists(inode);
7742 + /* mk: fan out fun */
7744 + iput(itohi(inode));
7746 + iput(itohi2(inode));
7748 + // XXX: why this assertion fails?
7749 + // because it doesn't like us
7750 + // ASSERT((inode->i_state & I_DIRTY) == 0);
7751 + kfree(itopd(inode));
7752 + __itopd(inode) = NULL;
7757 + * Called in do_umount() if the MNT_FORCE flag was used and this
7758 + * function is defined. See comment in linux/fs/super.c:do_umount().
7759 + * Used only in nfs, to kill any pending RPC tasks, so that subsequent
7760 + * code can actually succeed and won't leave tasks that need handling.
7762 + * PS. I wonder if this is somehow useful to undo damage that was
7763 + * left in the kernel after a user level file server (such as amd)
7767 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,18)
7768 +mini_fo_umount_begin(struct vfsmount *mnt, int flags)
7770 + struct vfsmount *hidden_mnt;
7772 + hidden_mnt = stopd(mnt->mnt_sb)->hidden_mnt;
7774 + if (hidden_mnt->mnt_sb->s_op->umount_begin)
7775 + hidden_mnt->mnt_sb->s_op->umount_begin(hidden_mnt, flags);
7779 +mini_fo_umount_begin(super_block_t *sb)
7781 + super_block_t *hidden_sb;
7783 + hidden_sb = stohs(sb);
7785 + if (hidden_sb->s_op->umount_begin)
7786 + hidden_sb->s_op->umount_begin(hidden_sb);
7792 +struct super_operations mini_fo_sops =
7794 + read_inode: mini_fo_read_inode,
7795 +#if defined(FIST_DEBUG) || defined(FIST_FILTER_SCA)
7796 + write_inode: mini_fo_write_inode,
7797 +#endif /* defined(FIST_DEBUG) || defined(FIST_FILTER_SCA) */
7798 + put_inode: mini_fo_put_inode,
7799 +#if defined(FIST_DEBUG) || defined(FIST_FILTER_SCA)
7800 + delete_inode: mini_fo_delete_inode,
7801 +#endif /* defined(FIST_DEBUG) || defined(FIST_FILTER_SCA) */
7802 + put_super: mini_fo_put_super,
7803 + statfs: mini_fo_statfs,
7804 + remount_fs: mini_fo_remount_fs,
7805 + clear_inode: mini_fo_clear_inode,
7806 + umount_begin: mini_fo_umount_begin,