1 Index: linux-2.6.23/fs/Kconfig
2 ===================================================================
3 --- linux-2.6.23.orig/fs/Kconfig 2007-10-10 13:52:14.000000000 +0800
4 +++ linux-2.6.23/fs/Kconfig 2007-10-10 13:53:23.000000000 +0800
6 This option will enlarge your kernel, but it allows debugging of
7 ocfs2 filesystem issues.
10 + tristate "Mini fanout overlay filesystem"
13 tristate "Minix fs support"
15 Index: linux-2.6.23/fs/Makefile
16 ===================================================================
17 --- linux-2.6.23.orig/fs/Makefile 2007-10-10 13:52:14.000000000 +0800
18 +++ linux-2.6.23/fs/Makefile 2007-10-10 13:53:23.000000000 +0800
20 obj-$(CONFIG_RAMFS) += ramfs/
21 obj-$(CONFIG_HUGETLBFS) += hugetlbfs/
22 obj-$(CONFIG_CODA_FS) += coda/
23 +obj-$(CONFIG_MINI_FO) += mini_fo/
24 obj-$(CONFIG_MINIX_FS) += minix/
25 obj-$(CONFIG_FAT_FS) += fat/
26 obj-$(CONFIG_MSDOS_FS) += msdos/
27 Index: linux-2.6.23/fs/mini_fo/aux.c
28 ===================================================================
29 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
30 +++ linux-2.6.23/fs/mini_fo/aux.c 2007-10-10 13:53:23.000000000 +0800
33 + * Copyright (c) 1997-2003 Erez Zadok
34 + * Copyright (c) 2001-2003 Stony Brook University
36 + * For specific licensing information, see the COPYING file distributed with
37 + * this package, or get one from ftp://ftp.filesystems.org/pub/fist/COPYING.
39 + * This Copyright notice must be kept intact and distributed with all
40 + * fistgen sources INCLUDING sources generated by fistgen.
43 + * Copyright (C) 2004, 2005 Markus Klotzbuecher <mk@creamnet.de>
45 + * This program is free software; you can redistribute it and/or
46 + * modify it under the terms of the GNU General Public License
47 + * as published by the Free Software Foundation; either version
48 + * 2 of the License, or (at your option) any later version.
61 +/* check if file exists in storage */
62 +int exists_in_storage(dentry_t *dentry)
64 + check_mini_fo_dentry(dentry);
65 + if(dtost(dentry) == MODIFIED || dtost(dentry) == CREATED || dtost(dentry) == DEL_REWRITTEN)
70 +/* check if dentry is in an existing state */
71 +int is_mini_fo_existant(dentry_t *dentry)
73 + check_mini_fo_dentry(dentry);
75 + if(dtost(dentry) == DELETED || dtost(dentry) == NON_EXISTANT)
82 + * This function will create a negative storage dentry for
83 + * dentry, what is required for many create like options.
84 + * It will create the storage structure if necessary.
86 +int get_neg_sto_dentry(dentry_t *dentry)
90 + const unsigned char *name;
94 + !(dtost(dentry) == UNMODIFIED ||
95 + dtost(dentry) == NON_EXISTANT ||
96 + dtost(dentry) == DELETED)) {
97 + printk(KERN_CRIT "mini_fo: get_neg_sto_dentry: invalid dentry passed.\n");
101 + /* Have we got a neg. dentry already? */
102 + if(dtohd2(dentry)) {
106 + if(dtost(dentry->d_parent) == UNMODIFIED) {
107 + /* build sto struct */
108 + err = build_sto_structure(dentry->d_parent->d_parent, dentry->d_parent);
110 + dtost(dentry->d_parent) != MODIFIED) {
111 + printk(KERN_CRIT "mini_fo: get_neg_sto_dentry: ERROR building sto structure.\n");
117 + len = dentry->d_name.len;
118 + name = dentry->d_name.name;
121 + lookup_one_len(name, dtohd2(dentry->d_parent), len);
127 +int check_mini_fo_dentry(dentry_t *dentry)
129 + ASSERT(dentry != NULL);
130 + ASSERT(dtopd(dentry) != NULL);
131 + ASSERT((dtohd(dentry) != NULL) || (dtohd2(dentry) != NULL));
133 +/* if(dtost(dentry) == MODIFIED) { */
134 +/* ASSERT(dentry->d_inode != NULL); */
135 +/* ASSERT(dtohd(dentry) != NULL); */
136 +/* ASSERT(dtohd(dentry)->d_inode != NULL); */
137 +/* ASSERT(dtohd2(dentry) != NULL); */
138 +/* ASSERT(dtohd2(dentry)->d_inode != NULL); */
140 +/* else if(dtost(dentry) == UNMODIFIED) { */
141 +/* ASSERT(dentry->d_inode != NULL); */
147 +int check_mini_fo_file(file_t *file)
149 + ASSERT(file != NULL);
150 + ASSERT(ftopd(file) != NULL);
151 + ASSERT(file->f_dentry != NULL);
153 + /* violent checking, check depending of state and type
154 + * if(S_ISDIR(file->f_dentry->d_inode->i_mode)) {}
156 + ASSERT((ftohf(file) != NULL) || (ftohf2(file) != NULL));
160 +int check_mini_fo_inode(inode_t *inode)
162 + ASSERT(inode != NULL);
163 + ASSERT(itopd(inode) != NULL);
164 + ASSERT((itohi(inode) != NULL) || (itohi2(inode) != NULL));
169 + * will walk a base path as provided by get_mini_fo_bpath and return
170 + * the (hopefully ;-) ) positive dentry of the renamed base dir.
172 + * This does some work of path_init.
174 +dentry_t *bpath_walk(super_block_t *sb, char *bpath)
177 + struct vfsmount *mnt;
178 + struct nameidata nd;
181 + if(!bpath || bpath[0] != '/') {
182 + printk(KERN_CRIT "mini_fo: bpath_walk: Invalid string.\n");
185 + if(!sb || !stopd(sb)) {
186 + printk(KERN_CRIT "mini_fo: bpath_walk: Invalid sb.\n");
190 + /* fix this: how do I reach this lock?
191 + * read_lock(¤t->fs->lock); */
192 + mnt = mntget(stopd(sb)->hidden_mnt);
193 + /* read_unlock(¤t->fs->lock); */
195 + err = vfs_path_lookup(mnt->mnt_root, mnt, bpath+1, 0, &nd);
198 + if (err || !nd.dentry || !nd.dentry->d_inode) {
199 + printk(KERN_CRIT "mini_fo: bpath_walk: path_walk failed.\n");
206 +/* returns the full path of the basefile incl. its name */
207 +int get_mini_fo_bpath(dentry_t *dentry, char **bpath, int *bpath_len)
211 + dentry_t *sky_walker;
213 + if(!dentry || !dtohd(dentry)) {
214 + printk(KERN_CRIT "mini_fo: get_mini_fo_bpath: invalid dentry passed.\n");
217 + sky_walker = dtohd(dentry);
220 + len += sky_walker->d_name.len + 1 ; /* 1 for '/' */
221 + sky_walker = sky_walker->d_parent;
222 + } while(sky_walker != stopd(dentry->d_inode->i_sb)->base_dir_dentry);
224 + /* 1 to oil the loop */
225 + *bpath = (char*) kmalloc(len + 1, GFP_KERNEL);
227 + printk(KERN_CRIT "mini_fo: get_mini_fo_bpath: out of mem.\n");
230 + buf_walker = *bpath+len; /* put it on last char */
231 + *buf_walker = '\n';
232 + sky_walker = dtohd(dentry);
235 + buf_walker -= sky_walker->d_name.len;
236 + strncpy(buf_walker,
237 + sky_walker->d_name.name,
238 + sky_walker->d_name.len);
239 + *(--buf_walker) = '/';
240 + sky_walker = sky_walker->d_parent;
241 + } while(sky_walker != stopd(dentry->d_inode->i_sb)->base_dir_dentry);
243 + /* bpath_len doesn't count newline! */
248 +int mini_fo_cp_cont(dentry_t *tgt_dentry, struct vfsmount *tgt_mnt,
249 + dentry_t *src_dentry, struct vfsmount *src_mnt)
252 + mm_segment_t old_fs;
255 + int bytes, len, tmp, err;
258 + if(!(tgt_dentry->d_inode && src_dentry->d_inode)) {
259 + printk(KERN_CRIT "mini_fo_cp_cont: ERROR, neg. dentry passed.\n");
269 + /* open file write only */
270 + tgt_file = dentry_open(tgt_dentry, tgt_mnt, 0x1);
271 + if(!tgt_file || IS_ERR(tgt_file)) {
272 + printk(KERN_CRIT "mini_fo_cp_cont: ERROR opening target file.\n");
273 + err = PTR_ERR(tgt_file);
277 + /* open file read only */
278 + src_file = dentry_open(src_dentry, src_mnt, 0x0);
279 + if(!src_file || IS_ERR(src_file)) {
280 + printk(KERN_CRIT "mini_fo_cp_cont: ERROR opening source file.\n");
281 + err = PTR_ERR(src_file);
283 + /* close target file */
288 + /* check if the filesystem(s) support read respective write */
289 + if(!src_file->f_op->read || !tgt_file->f_op->write) {
290 + printk(KERN_CRIT "mini_fo_cp_cont: ERROR, no fs read or write support.\n");
295 + /* allocate a page for transfering the data */
296 + buf = (void *) __get_free_page(GFP_KERNEL);
298 + printk(KERN_CRIT "mini_fo_cp_cont: ERROR, out of kernel mem.\n");
302 + tgt_file->f_pos = 0;
303 + src_file->f_pos = 0;
308 + /* Doing this I assume that a read operation will return a full
309 + * buffer while there is still data to read, and a less than
310 + * full buffer when all data has been read.
312 + bytes = len = PAGE_SIZE;
313 + while(bytes == len) {
314 + bytes = src_file->f_op->read(src_file, buf, len,
316 + tmp = tgt_file->f_op->write(tgt_file, buf, bytes,
319 + printk(KERN_CRIT "mini_fo_cp_cont: ERROR writing.\n");
320 + goto out_close_unset;
324 + free_page((unsigned long) buf);
331 + free_page((unsigned long) buf);
342 + /* mk: not sure if this need to be done */
351 + * ndl (no-duplicate list) stuff
352 + * This is used in mini_fo_readdir, to save the storage directory contents
353 + * and later when reading base, match them against the list in order
354 + * to avoid duplicates.
357 +/* add a file specified by name and len to the ndl
358 + * Return values: 0 on success, <0 on failure.
360 +int ndl_add_entry(struct readdir_data *rd, const char *name, int len)
362 + struct ndl_entry *tmp_entry;
364 + tmp_entry = (struct ndl_entry *)
365 + kmalloc(sizeof(struct ndl_entry), GFP_KERNEL);
367 + printk(KERN_CRIT "mini_fo: ndl_add_entry: out of mem.\n");
370 + tmp_entry->name = (char*) kmalloc(len, GFP_KERNEL);
371 + if(!tmp_entry->name) {
372 + printk(KERN_CRIT "mini_fo: ndl_add_entry: out of mem.\n");
375 + strncpy(tmp_entry->name, name, len);
376 + tmp_entry->len = len;
378 + list_add(&tmp_entry->list, &rd->ndl_list);
383 +/* delete all list entries and free memory */
384 +void ndl_put_list(struct readdir_data *rd)
386 + struct list_head *tmp;
387 + struct ndl_entry *tmp_entry;
389 + if(rd->ndl_size <= 0)
391 + while(!list_empty(&rd->ndl_list)) {
392 + tmp = rd->ndl_list.next;
394 + tmp_entry = list_entry(tmp, struct ndl_entry, list);
395 + kfree(tmp_entry->name);
401 +/* Check if a file specified by name and len is in the ndl
402 + * Return value: 0 if not in list, 1 if file is found in ndl.
404 +int ndl_check_entry(struct readdir_data *rd, const char *name, int len)
406 + struct list_head *tmp;
407 + struct ndl_entry *tmp_entry;
409 + if(rd->ndl_size <= 0)
412 + list_for_each(tmp, &rd->ndl_list) {
413 + tmp_entry = list_entry(tmp, struct ndl_entry, list);
414 + if(tmp_entry->len != len)
416 + if(!strncmp(tmp_entry->name, name, len))
423 + * Recursive function to create corresponding directorys in the storage fs.
424 + * The function will build the storage directorys up to dentry.
426 +int build_sto_structure(dentry_t *dir, dentry_t *dentry)
429 + dentry_t *hidden_sto_dentry;
430 + dentry_t *hidden_sto_dir_dentry;
432 + if(dentry->d_parent != dir) {
433 + printk(KERN_CRIT "mini_fo: build_sto_structure: invalid parameter or meta data corruption [1].\n");
437 + if(dtost(dir) != MODIFIED) {
438 + err = build_sto_structure(dir->d_parent, dentry->d_parent);
443 + /* ok, coming back again. */
444 + check_mini_fo_dentry(dentry);
445 + hidden_sto_dentry = dtohd2(dentry);
447 + if(!hidden_sto_dentry) {
449 + * This is the case after creating the first
450 + * hidden_sto_dentry.
451 + * After one negative storage_dentry, all pointers to
452 + * hidden_storage dentries are set to NULL. We need to
453 + * create the negative dentry before we create the storage
457 + const unsigned char *name;
458 + len = dtohd(dentry)->d_name.len;
459 + name = dtohd(dentry)->d_name.name;
460 + hidden_sto_dentry = lookup_one_len(name, dtohd2(dir), len);
461 + dtohd2(dentry) = hidden_sto_dentry;
464 + /* was: hidden_sto_dir_dentry = lock_parent(hidden_sto_dentry); */
465 + hidden_sto_dir_dentry = dget(hidden_sto_dentry->d_parent);
466 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
467 + mutex_lock(&hidden_sto_dir_dentry->d_inode->i_mutex);
469 + down(&hidden_sto_dir_dentry->d_inode->i_sem);
472 + if(dtohd2(dir) != hidden_sto_dir_dentry) {
473 + printk(KERN_CRIT "mini_fo: build_sto_structure: invalid parameter or meta data corruption [2].\n");
477 + /* check for errors in lock_parent */
478 + err = PTR_ERR(hidden_sto_dir_dentry);
479 + if(IS_ERR(hidden_sto_dir_dentry)) {
480 + printk(KERN_CRIT "mini_fo: build_sto_structure: lock_parent failed.\n");
484 + err = vfs_mkdir(hidden_sto_dir_dentry->d_inode,
486 + dir->d_inode->i_mode);
489 + printk(KERN_CRIT "mini_fo: build_sto_structure: failed to create storage dir [1].\n");
490 + /* was: unlock_dir(dir); */
491 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
492 + mutex_unlock(&dir->d_inode->i_mutex);
494 + up(&dir->d_inode->i_sem);
500 + /* everything ok! */
501 + if(!dtohd2(dentry)->d_inode) {
502 + printk(KERN_CRIT "mini_fo: build_sto_structure: failed to create storage dir [2].\n");
503 + /* was: unlock_dir(dir); */
504 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
505 + mutex_unlock(&dir->d_inode->i_mutex);
507 + up(&dir->d_inode->i_sem);
513 + /* interpose the new inode and set new state */
514 + itohi2(dentry->d_inode) = igrab(dtohd2(dentry)->d_inode);
515 + dtopd(dentry)->state = MODIFIED;
517 + /* initalize the wol list */
518 + itopd(dentry->d_inode)->deleted_list_size = -1;
519 + itopd(dentry->d_inode)->renamed_list_size = -1;
520 + meta_build_lists(dentry);
522 + fist_copy_attr_all(dentry->d_inode, itohi2(dentry->d_inode));
523 + fist_copy_attr_timesizes(dir->d_inode,
524 + hidden_sto_dir_dentry->d_inode);
525 + dir->d_inode->i_nlink++;
526 + /* was: unlock_dir(hidden_sto_dir_dentry); */
527 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
528 + mutex_unlock(&hidden_sto_dir_dentry->d_inode->i_mutex);
530 + up(&hidden_sto_dir_dentry->d_inode->i_sem);
532 + dput(hidden_sto_dir_dentry);
540 + * Read "len" bytes from "filename" into "buf".
541 + * "buf" is in kernel space.
544 +mini_fo_read_file(const char *filename, void *buf, int len)
547 + mm_segment_t oldfs;
549 + /* Chroot? Maybe NULL isn't right here */
550 + filp = filp_open(filename, O_RDONLY, 0);
551 + if (!filp || IS_ERR(filp)) {
552 + printk("mini_fo_read_file err %d\n", (int) PTR_ERR(filp));
553 + return -1; /* or do something else */
556 + if (!filp->f_op->read)
557 + return -2; /* file(system) doesn't allow reads */
559 + /* now read len bytes from offset 0 */
560 + filp->f_pos = 0; /* start offset */
563 + bytes = filp->f_op->read(filp, buf, len, &filp->f_pos);
566 + /* close the file */
575 + * Write "len" bytes from "buf" to "filename"
576 + * "buf" is in kernel space.
579 +mini_fo_write_file(const char *filename, void *buf, int len)
582 + mm_segment_t oldfs;
584 + /* Chroot? Maybe NULL isn't right here */
585 + filp = filp_open(filename, O_RDWR|O_CREAT, 0640);
586 + if (!filp || IS_ERR(filp)) {
587 + printk("mini_fo_write_file err %d\n", (int) PTR_ERR(filp));
588 + return -1; /* or do something else */
591 + if (!filp->f_op->write)
592 + return -2; /* file(system) doesn't allow writes */
594 + /* now write len bytes from offset 0 */
595 + filp->f_pos = 0; /* start offset */
598 + bytes = filp->f_op->write(filp, buf, len, &filp->f_pos);
601 + /* close the file */
609 Index: linux-2.6.23/fs/mini_fo/ChangeLog
610 ===================================================================
611 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
612 +++ linux-2.6.23/fs/mini_fo/ChangeLog 2007-10-10 13:53:23.000000000 +0800
614 +2006-01-24 Markus Klotzbuecher <mk@mary.denx.de>
616 + * Add tons of ugly ifdefs to Ed L. Cashin's mutex patch to
617 + retain backwards compatibility.
619 +2006-01-24 Ed L. Cashin <ecashin@coraid.com>
621 + * Support for the new mutex infrastructure
622 + (7892f2f48d165a34b0b8130c8a195dfd807b8cb6)
624 +2005-10-15 Markus Klotzbuecher <mk@localhost.localdomain>
626 + * Bugfix for a serious memory leak in mini_fo_follow_link.
628 +2005-09-21 Markus Klotzbuecher <mk@mary>
630 + * new release 0.6.1
632 + * fix of a compiler warning due to changes in 2.6.13
634 +2005-09-21 Klaus Wenninger <klaus.wenninger@siemens.com>
636 + * file.c: readdir: fix for a bug that caused directory entries
637 + to show up twice when using storage filesystems such as
640 +2005-06-30 Eric Lammerts <eric@lammerts.org>
642 + * fix for an oops when overwriting a binary thats beeing
645 +2005-06-09 <mk@mary>
647 + * Renamed overlay to mini_fo-overlay.
649 + * Added mini_fo-merge script to allow merging of storage and base
650 + after making modifications.
652 +2005-05-22 root <mk@mary>
654 + * Added overlay script that allows to easily mount mini_fo ontop
655 + of a given base directory
657 +2005-05-10 <mk@mary>
659 + * inode.c: xattr functions return -EOPNOSUPP instead of
660 + -ENOSUPP, what confuses "ls -l"
662 + * Changed license from LGPL to GPL.
664 +2005-05-08 root <mk@mary>
666 + * Makefile: clean it up and added make install and make
669 +2005-05-06 <mk@mary>
671 + * merged devel branch back to main. [v0-6-0-pre3]
673 + * removed unused files print.c and fist_ioctl. [devel-0-0-18]
675 + * ioctl: removed fist_ioctl stuff, that is not needed for
678 +2005-05-03 <mk@mary>
680 + * file.c: simplified mini_fo_open and mini_fo_setattr using
681 + new state changing functions. [devel-0-0-17]
683 + * inode.c: Fixed getattr state bug (see below) in 2.4 function
684 + mini_fo_inode revalidate.
686 + * inode.c: found an other bug in mini_fo_getattr. States are not
687 + reliable in this function, as a file can be opened, unlinked and
688 + the getattr function called. This results in a deleted dentry
689 + with an inode. Fix is to ignore states and simply use the inode
692 +2005-04-29 <mk@mary>
694 + * file.c: Bugfix and cleanup in fasync and fsync. [devel-0-0-16]
696 + * file.c: do not use mini_fo_lock so the generic version is
699 + * inode.c: getattr, never call getattr on lower files, as this
700 + will cause the inum to change.
702 + * inode.c: rename_reg_file renamed to rename_nondir, as it
703 + doesn't matter as long it't not a dir. Removed all
704 + rename_dev_file etc.
706 + * tagged as devel-0-0-15
708 + * inode.c: added support for chosing support for extended
709 + attrs at compile time by XATTR define in mini_fo.h .
711 + * inode.c: fixed mini_fo_getattr to use mini_fo inode and not
712 + lower again, what avoids inode number changes that confused
713 + rm again. This is the proper solution.
715 +2005-04-24 <mk@mary>
717 + * all files: updated Copyright notive to 2005. [devel-0-0-14]
719 + * inode.c: fixed mini_fo_getattr to not change the inode
720 + number, even if lower files change.
722 + * super.c: fixed a bug that caused deleted base file to show
723 + up suddenly after some time, or after creating a special
724 + file. The problem was that after some time or after special
725 + file creating sync_sb_inodes is called by the vfs, that
726 + called our mini_fo_put_inode. There was (wrongly) called
727 + __meta_put_lists, that nuked the lists, although the inode
728 + was going to continue its life. Moving __meta_put_lists to
729 + mini_fo_clear_inode, where an inode is really destroyed,
730 + solved the problem.
733 +2005-04-23 <mk@mary>
735 + * state.c, aux.c: more cleaning up and
736 + simplifications. [devel-0-0-13]
738 + * inode.c: implemented mini_fo_getattr, that was required for
739 + 2.6 because inode_revalidate has been remove there, and the
740 + old "du" bug returned.
743 +2005-04-20 <mk@mary>
745 + * aux.c: get_neg_sto_dentry(): allow to be called for dentries
746 + in state UNMODIFIED, NON_EXISTANT _and_ DELETED.
748 +2005-04-19 <mk@mary>
750 + * Fixed a bug under 2.6 that caused files deleted via mini_fo
751 + not to be deleted properly and therefore the fs filled up
752 + untill no memory was left. [devel-0-0-12]
754 + * Added basic hard link support. This means that creating
755 + hardlinks will work, but existing ones will be treated as
756 + individual files. [devel-0-0-11]
758 +2005-04-17 <mk@mary>
762 +2005-04-13 root <mk@mary>
764 + * Added file state.c for the state transition
765 + functions. Doesn't work very well yet, though...
767 +2005-04-12 <mk@mary>
769 + * Porting to 2.6 started, which is easier than expected, also
770 + due to Olivier previous work.
772 +2005-04-08 <mk@mary>
774 + * Fixed the bug that caused du to return invalid sizes of
775 + directory trees. The problem was that
776 + mini_fo_inode_revalidate didn't always copy the attributes
777 + from the base inode properly.
779 +2005-04-01 Markus Klotzbuecher <mk@chasey>
781 + * Merged devel branch back to main trunk and updated the
782 + RELEASE notes. This will be 0-6-0-pre1.
784 +2005-03-31 Markus Klotzbuecher <mk@chasey>
786 + * Fixed some bugs in rename_reg_file, that only showed up in
787 + the kernel compile test. Kernel compiles cleanly ontop of
788 + mini_fo, now also make mrproper etc. work. Seems pretty stable.
790 +2005-03-28 Markus Klotzbuecher <mk@chasey>
792 + * Many, many directory renaming bugfixes and a lot of other
793 + cleanup. Dir renaming seems to work relatively stable.
795 +2005-03-22 Markus Klotzbuecher <mk@chasey>
797 + * Finished implementing lightweight directory renaming. Some
798 + basic testing indicates it works fine.
799 + Next is to implement testcases for the testsuite and confirm
800 + everything is really working ok.
802 +2005-03-18 Markus Klotzbuecher <mk@chasey>
804 + * Finished implementing meta.c stuff required for directory
807 +2005-03-17 Markus Klotzbuecher <mk@chasey>
809 + * Fixed all compile warnings + an extremly old bug that
810 + somehow crept in while reworking the wol stuff to the META
811 + system. Turning on -Werror again... :-)
813 + * Fixed some bugs in the new rename_reg_file function.
815 + * Rewrote mini_fo rename and split it into several
816 + subfunctions, that handle the different types
817 + seperately. Rewrote the regular file function aswell, as it
818 + was implemented somewhat inefficient.
820 +2005-03-16 Markus Klotzbuecher <mk@chasey>
822 + * Implemented new META subsystem, removed old WOL stuff in favor
825 + * After some basic testing everything seems ok...
827 +2005-03-11 Markus Klotzbuecher <mk@chasey>
829 + * Renaming a non regular file caused trouble because I always
830 + tried to copy the contents. Now I only do this for regular
831 + files. mini_fo_rename still isn't implemented properly, renaming
832 + of device files, symlinks etc. results in a empty regular file
833 + instead of the proper type.
835 + * Directory renaming suddenly works! What a surprise! I guess
836 + this is because renaming is implemented as making a copy and
837 + removing the original. Still this might not work
840 +2005-03-09 Markus Klotzbuecher <mk@chasey>
842 + * Bugfix, when a mini_fo directory that exists in storage
843 + (state: MODIFIED, CREATED and DEL_REWRITTEN) is deleted, a
844 + possibly existing WOL file contained in it needs to be
847 + * Starting cleanup: defined state names in order to get rid of
850 +2005-03-08 Markus Klotzbuecher <mk@chasey>
852 + * Makefile fix, fist_ioctl was built against wrong sources if ARCH=um
854 + * Fixed a bug in dentry.c, mini_fo_d_hash. In state 4 =
855 + DEL_REWRITTEN the hash was calculated from the base dentry,
856 + which was wrong and and caused assertions in
857 + __mini_fo_hidden_dentry to fail.
859 +2005-02-21 <mk@mary>
861 + * Implemented directory deleting (inode.c)
863 + * main.c: made mini_fo_parse_options a little more robust.
865 +2004-12-22 <mk@mary>
867 + * Makefile cleanup and uml stuff, removed unneccessary files
869 + * Created a new and hopefully more informative README
871 + * CHANGELOG: created a new CHANGELOG and added old entries reversely
874 +2004-10-24 Gleb Natapov <gleb@nbase.co.il>
876 + * Fix: owner and group where not correctly copied from base to
880 +2004-10-05 Gleb Natapov <gleb@nbase.co.il>
882 + * Implementation of fsync, fasync and lock mini_fo functions.
885 +2004-09-29 Bob Lee <bob@pantasys.com>
887 + * Fix of a serious pointer bug
890 +2004-09-28 Gleb Natapov <gleb@nbase.co.il>
892 + * Implementation of mini_fo_mknod and mini_fo_rename, support
895 Index: linux-2.6.23/fs/mini_fo/dentry.c
896 ===================================================================
897 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
898 +++ linux-2.6.23/fs/mini_fo/dentry.c 2007-10-10 13:53:23.000000000 +0800
901 + * Copyright (c) 1997-2003 Erez Zadok
902 + * Copyright (c) 2001-2003 Stony Brook University
904 + * For specific licensing information, see the COPYING file distributed with
905 + * this package, or get one from ftp://ftp.filesystems.org/pub/fist/COPYING.
907 + * This Copyright notice must be kept intact and distributed with all
908 + * fistgen sources INCLUDING sources generated by fistgen.
911 + * Copyright (C) 2004, 2005 Markus Klotzbuecher <mk@creamnet.de>
913 + * This program is free software; you can redistribute it and/or
914 + * modify it under the terms of the GNU General Public License
915 + * as published by the Free Software Foundation; either version
916 + * 2 of the License, or (at your option) any later version.
923 +#ifdef HAVE_CONFIG_H
924 +# include <config.h>
928 +#include "mini_fo.h"
931 + * THIS IS A BOOLEAN FUNCTION: returns 1 if valid, 0 otherwise.
934 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
935 +mini_fo_d_revalidate(dentry_t *dentry, struct nameidata *nd)
937 +mini_fo_d_revalidate(dentry_t *dentry, int flags)
940 + int err1 = 1; /* valid = 1, invalid = 0 */
942 + dentry_t *hidden_dentry;
943 + dentry_t *hidden_sto_dentry;
946 + check_mini_fo_dentry(dentry);
948 + hidden_dentry = dtohd(dentry);
949 + hidden_sto_dentry = dtohd2(dentry);
951 + if(hidden_dentry &&
952 + hidden_dentry->d_op &&
953 + hidden_dentry->d_op->d_revalidate) {
954 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
955 + err1 = hidden_dentry->d_op->d_revalidate(hidden_dentry, nd);
957 + err1 = hidden_dentry->d_op->d_revalidate(hidden_dentry, flags);
960 + if(hidden_sto_dentry &&
961 + hidden_sto_dentry->d_op &&
962 + hidden_sto_dentry->d_op->d_revalidate) {
963 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
964 + err2 = hidden_sto_dentry->d_op->d_revalidate(hidden_sto_dentry,
967 + err2 = hidden_sto_dentry->d_op->d_revalidate(hidden_sto_dentry,
972 + /* mk: if one of the lower level dentries are valid,
973 + * the mini_fo dentry is too.
975 + return (err1 || err2);
980 +mini_fo_d_hash(dentry_t *dentry, qstr_t *name)
983 + dentry_t *hidden_dentry;
984 + dentry_t *hidden_sto_dentry;
986 + /* hidden_dentry = mini_fo_hidden_dentry(dentry);
987 + * hidden_sto_dentry = mini_fo_hidden_sto_dentry(dentry); */
989 + /* state 1, 3, 4, 5: build the hash for the storage dentry */
990 + if((dtopd(dentry)->state == MODIFIED) ||
991 + (dtopd(dentry)->state == CREATED) ||
992 + (dtopd(dentry)->state == DEL_REWRITTEN) ||
993 + (dtopd(dentry)->state == DELETED)) {
994 + hidden_sto_dentry = dtohd2(dentry);
995 + if(hidden_sto_dentry &&
996 + hidden_sto_dentry->d_op &&
997 + hidden_sto_dentry->d_op->d_hash) {
998 + err = hidden_sto_dentry->d_op->d_hash(hidden_sto_dentry, name);
1002 + /* state 2: build the hash for the base dentry */
1003 + if(dtopd(dentry)->state == UNMODIFIED) {
1004 + hidden_dentry = dtohd(dentry);
1005 + if(hidden_dentry &&
1006 + hidden_dentry->d_op &&
1007 + hidden_dentry->d_op->d_hash) {
1008 + err = hidden_dentry->d_op->d_hash(hidden_dentry, name);
1012 + /* state 6: build hash for the dentry that exists */
1013 + if(dtopd(dentry)->state == NON_EXISTANT) {
1014 + hidden_sto_dentry = dtohd2(dentry);
1015 + if(hidden_sto_dentry &&
1016 + hidden_sto_dentry->d_op &&
1017 + hidden_sto_dentry->d_op->d_hash) {
1018 + err = hidden_sto_dentry->d_op->d_hash(hidden_sto_dentry, name);
1021 + hidden_dentry = dtohd(dentry);
1022 + if(hidden_dentry &&
1023 + hidden_dentry->d_op &&
1024 + hidden_dentry->d_op->d_hash) {
1025 + err = hidden_dentry->d_op->d_hash(hidden_dentry, name);
1030 + printk(KERN_CRIT "mini_fo: d_hash: invalid state detected.\n");
1038 +mini_fo_d_compare(dentry_t *dentry, qstr_t *a, qstr_t *b)
1041 + dentry_t *hidden_dentry=NULL;
1043 + /* hidden_dentry = mini_fo_hidden_dentry(dentry); */
1044 + if(dtohd2(dentry))
1045 + hidden_dentry = dtohd2(dentry);
1046 + else if(dtohd(dentry))
1047 + hidden_dentry = dtohd(dentry);
1049 + if (hidden_dentry && hidden_dentry->d_op && hidden_dentry->d_op->d_compare) {
1050 + err = hidden_dentry->d_op->d_compare(hidden_dentry, a, b);
1052 + err = ((a->len != b->len) || memcmp(a->name, b->name, b->len));
1060 +mini_fo_d_delete(dentry_t *dentry)
1062 + dentry_t *hidden_dentry;
1063 + dentry_t *hidden_sto_dentry;
1066 + /* this could be a negative dentry, so check first */
1067 + if (!dtopd(dentry)) {
1068 + printk(KERN_CRIT "mini_fo_d_delete: negative dentry passed.\n");
1071 + hidden_dentry = dtohd(dentry);
1072 + hidden_sto_dentry = dtohd2(dentry);
1074 + if(hidden_dentry) {
1075 + if(hidden_dentry->d_op &&
1076 + hidden_dentry->d_op->d_delete) {
1077 + err = hidden_dentry->d_op->d_delete(hidden_dentry);
1080 + if(hidden_sto_dentry) {
1081 + if(hidden_sto_dentry->d_op &&
1082 + hidden_sto_dentry->d_op->d_delete) {
1083 + err = hidden_sto_dentry->d_op->d_delete(hidden_sto_dentry);
1093 +mini_fo_d_release(dentry_t *dentry)
1095 + dentry_t *hidden_dentry;
1096 + dentry_t *hidden_sto_dentry;
1099 + /* this could be a negative dentry, so check first */
1100 + if (!dtopd(dentry)) {
1101 + printk(KERN_CRIT "mini_fo_d_release: no private data.\n");
1104 + hidden_dentry = dtohd(dentry);
1105 + hidden_sto_dentry = dtohd2(dentry);
1107 + if(hidden_dentry) {
1108 + /* decrement hidden dentry's counter and free its inode */
1109 + dput(hidden_dentry);
1111 + if(hidden_sto_dentry) {
1112 + /* decrement hidden dentry's counter and free its inode */
1113 + dput(hidden_sto_dentry);
1116 + /* free private data (mini_fo_dentry_info) here */
1117 + kfree(dtopd(dentry));
1118 + __dtopd(dentry) = NULL; /* just to be safe */
1125 + * we don't really need mini_fo_d_iput, because dentry_iput will call iput() if
1126 + * mini_fo_d_iput is not defined. We left this implemented for ease of
1127 + * tracing/debugging.
1130 +mini_fo_d_iput(dentry_t *dentry, inode_t *inode)
1136 +struct dentry_operations mini_fo_dops = {
1137 + d_revalidate: mini_fo_d_revalidate,
1138 + d_hash: mini_fo_d_hash,
1139 + d_compare: mini_fo_d_compare,
1140 + d_release: mini_fo_d_release,
1141 + d_delete: mini_fo_d_delete,
1142 + d_iput: mini_fo_d_iput,
1144 Index: linux-2.6.23/fs/mini_fo/file.c
1145 ===================================================================
1146 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
1147 +++ linux-2.6.23/fs/mini_fo/file.c 2007-10-10 13:53:23.000000000 +0800
1150 + * Copyright (c) 1997-2003 Erez Zadok
1151 + * Copyright (c) 2001-2003 Stony Brook University
1153 + * For specific licensing information, see the COPYING file distributed with
1154 + * this package, or get one from ftp://ftp.filesystems.org/pub/fist/COPYING.
1156 + * This Copyright notice must be kept intact and distributed with all
1157 + * fistgen sources INCLUDING sources generated by fistgen.
1160 + * Copyright (C) 2004, 2005 Markus Klotzbuecher <mk@creamnet.de>
1162 + * This program is free software; you can redistribute it and/or
1163 + * modify it under the terms of the GNU General Public License
1164 + * as published by the Free Software Foundation; either version
1165 + * 2 of the License, or (at your option) any later version.
1172 +#ifdef HAVE_CONFIG_H
1173 +# include <config.h>
1177 +#include "mini_fo.h"
1178 +#define ROUND_UP(x) (((x)+sizeof(long)-1) & ~(sizeof(long)-1))
1180 +/*******************
1181 + * File Operations *
1182 + *******************/
1185 +mini_fo_llseek(file_t *file, loff_t offset, int origin)
1188 + file_t *hidden_file = NULL;
1190 + if(S_ISDIR(file->f_dentry->d_inode->i_mode)) {
1191 + /* Check if trying to llseek from a directory */
1195 + if (ftopd(file) != NULL) {
1196 + if(ftohf2(file)) {
1197 + hidden_file = ftohf2(file);
1199 + hidden_file = ftohf(file);
1203 + /* always set hidden position to this one */
1204 + hidden_file->f_pos = file->f_pos;
1206 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
1207 + memcpy(&(hidden_file->f_ra),
1209 + sizeof(struct file_ra_state));
1211 + if (file->f_reada) { /* update readahead information if needed */
1212 + hidden_file->f_reada = file->f_reada;
1213 + hidden_file->f_ramax = file->f_ramax;
1214 + hidden_file->f_raend = file->f_raend;
1215 + hidden_file->f_ralen = file->f_ralen;
1216 + hidden_file->f_rawin = file->f_rawin;
1219 + if (hidden_file->f_op && hidden_file->f_op->llseek)
1220 + err = hidden_file->f_op->llseek(hidden_file, offset, origin);
1222 + err = generic_file_llseek(hidden_file, offset, origin);
1227 + if (err != file->f_pos) {
1228 + file->f_pos = err;
1229 + // ION maybe this?
1230 + // file->f_pos = hidden_file->f_pos;
1231 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
1232 + file->f_reada = 0;
1234 + file->f_version++;
1242 +/* mk: fanout capable */
1244 +mini_fo_read(file_t *file, char *buf, size_t count, loff_t *ppos)
1246 + int err = -EINVAL;
1247 + file_t *hidden_file = NULL;
1248 + loff_t pos = *ppos;
1250 + if(S_ISDIR(file->f_dentry->d_inode->i_mode)) {
1251 + /* Check if trying to read from a directory */
1252 + /* printk(KERN_CRIT "mini_fo_read: ERROR: trying to read data from a directory.\n"); */
1257 + if (ftopd(file) != NULL) {
1258 + if(ftohf2(file)) {
1259 + hidden_file = ftohf2(file);
1261 + hidden_file = ftohf(file);
1265 + if (!hidden_file->f_op || !hidden_file->f_op->read)
1268 + err = hidden_file->f_op->read(hidden_file, buf, count, &pos);
1272 + /* atime should also be updated for reads of size zero or more */
1273 + fist_copy_attr_atime(file->f_dentry->d_inode,
1274 + hidden_file->f_dentry->d_inode);
1277 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
1280 + * because pread() does not have any way to tell us that it is
1281 + * our caller, then we don't know for sure if we have to update
1282 + * the file positions. This hack relies on read() having passed us
1283 + * the "real" pointer of its struct file's f_pos field.
1285 + if (ppos == &file->f_pos)
1286 + hidden_file->f_pos = *ppos = pos;
1287 + if (hidden_file->f_reada) { /* update readahead information if needed */
1288 + file->f_reada = hidden_file->f_reada;
1289 + file->f_ramax = hidden_file->f_ramax;
1290 + file->f_raend = hidden_file->f_raend;
1291 + file->f_ralen = hidden_file->f_ralen;
1292 + file->f_rawin = hidden_file->f_rawin;
1295 + memcpy(&(file->f_ra),&(hidden_file->f_ra),sizeof(struct file_ra_state));
1303 +/* this mini_fo_write() does not modify data pages! */
1305 +mini_fo_write(file_t *file, const char *buf, size_t count, loff_t *ppos)
1307 + int err = -EINVAL;
1308 + file_t *hidden_file = NULL;
1310 + inode_t *hidden_inode;
1311 + loff_t pos = *ppos;
1313 + /* mk: fan out: */
1314 + if (ftopd(file) != NULL) {
1315 + if(ftohf2(file)) {
1316 + hidden_file = ftohf2(file);
1318 + /* This is bad! We have no storage file to write to. This
1319 + * should never happen because if a file is opened for
1320 + * writing, a copy should have been made earlier.
1322 + printk(KERN_CRIT "mini_fo: write : ERROR, no storage file to write.\n");
1328 + inode = file->f_dentry->d_inode;
1329 + hidden_inode = itohi2(inode);
1330 + if(!hidden_inode) {
1331 + printk(KERN_CRIT "mini_fo: write: no sto inode found, not good.\n");
1335 + if (!hidden_file->f_op || !hidden_file->f_op->write)
1338 + /* adjust for append -- seek to the end of the file */
1339 + if (file->f_flags & O_APPEND)
1340 + pos = inode->i_size;
1342 + err = hidden_file->f_op->write(hidden_file, buf, count, &pos);
1345 + * copy ctime and mtime from lower layer attributes
1346 + * atime is unchanged for both layers
1349 + fist_copy_attr_times(inode, hidden_inode);
1352 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
1356 + * because pwrite() does not have any way to tell us that it is
1357 + * our caller, then we don't know for sure if we have to update
1358 + * the file positions. This hack relies on write() having passed us
1359 + * the "real" pointer of its struct file's f_pos field.
1361 + if (ppos == &file->f_pos)
1362 + hidden_file->f_pos = *ppos = pos;
1364 + /* update this inode's size */
1365 + if (pos > inode->i_size)
1366 + inode->i_size = pos;
1372 +/* Global variable to hold a file_t pointer.
1373 + * This serves to allow mini_fo_filldir function to know which file is
1374 + * beeing read, which is required for two reasons:
1376 + * - be able to call wol functions in order to avoid listing deleted
1378 + * - if we're reading a directory which is in state 1, we need to
1379 + * maintain a list (in mini_fo_filldir) of which files allready
1380 + * have been copied to userspace,to detect files existing in base
1381 + * and storage and not list them twice.
1383 +filldir_t mini_fo_filldir_orig;
1384 +file_t *mini_fo_filldir_file;
1386 +/* mainly copied from fs/readdir.c */
1388 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,18)
1389 +mini_fo_filldir(void * __buf, const char * name, int namlen, loff_t offset,
1390 + u64 ino, unsigned int d_type)
1392 +mini_fo_filldir(void * __buf, const char * name, int namlen, loff_t offset,
1393 + ino_t ino, unsigned int d_type)
1396 + struct getdents_callback * buf = (struct getdents_callback *) __buf;
1397 + file_t* file = mini_fo_filldir_file;
1399 + /* In theses states we filter meta files in storage (WOL) */
1400 + if(file && (dtopd(file->f_dentry)->state == MODIFIED ||
1401 + dtopd(file->f_dentry)->state == CREATED ||
1402 + dtopd(file->f_dentry)->state == DEL_REWRITTEN)) {
1404 + int tmp = strlen(META_FILENAME);
1405 + if(tmp == namlen) {
1406 + if(!strncmp(name, META_FILENAME, namlen))
1411 + /* check if we are merging the contents of storage and base */
1412 + if(file && dtopd(file->f_dentry)->state == MODIFIED) {
1413 + /* check if we are still reading storage contents, if
1414 + * yes, we just save the name of the file for duplicate
1415 + * checking later. */
1417 + if(!ftopd(file)->rd.sto_done) {
1418 + /* put file into ndl list */
1419 + if(ndl_add_entry(&ftopd(file)->rd, name, namlen))
1420 + printk(KERN_CRIT "mini_fo_filldir: Error adding to ndl.\n");
1422 + /* check if file has been deleted */
1423 + if(meta_check_d_entry(file->f_dentry, name, namlen))
1426 + /* do duplicate checking */
1427 + if(ndl_check_entry(&ftopd(file)->rd, name, namlen))
1432 + return mini_fo_filldir_orig(buf, name, namlen, offset, ino, d_type);
1437 +mini_fo_readdir(file_t *file, void *dirent, filldir_t filldir)
1439 + int err = 0;/* mk: ??? -ENOTDIR; */
1440 + file_t *hidden_file = NULL;
1441 + file_t *hidden_sto_file = NULL;
1443 + struct getdents_callback *buf;
1446 +#if defined(FIST_FILTER_NAME) || defined(FIST_FILTER_SCA)
1447 + struct mini_fo_getdents_callback buf;
1448 +#endif /* FIST_FILTER_NAME || FIST_FILTER_SCA */
1450 + buf = (struct getdents_callback *) dirent;
1451 + oldcount = buf->count;
1452 + inode = file->f_dentry->d_inode;
1453 + mini_fo_filldir_file = file;
1454 + mini_fo_filldir_orig = filldir;
1456 + ftopd(file)->rd.sto_done = 0;
1458 + if (ftopd(file) != NULL) {
1459 + if(ftohf2(file)) {
1460 + hidden_sto_file = ftohf2(file);
1461 + err = vfs_readdir(hidden_sto_file, mini_fo_filldir, dirent);
1462 + file->f_pos = hidden_sto_file->f_pos;
1464 + fist_copy_attr_atime(inode, hidden_sto_file->f_dentry->d_inode);
1465 + /* not finshed yet, we'll be called again */
1466 + if (buf->count != oldcount)
1470 + ftopd(file)->rd.sto_done = 1;
1473 + hidden_file = ftohf(file);
1474 + err = vfs_readdir(hidden_file, mini_fo_filldir, dirent);
1475 + file->f_pos = hidden_file->f_pos;
1477 + fist_copy_attr_atime(inode, hidden_file->f_dentry->d_inode);
1484 + * we need to check if all the directory data has been copied to userspace,
1485 + * or if we will be called again by userspace to complete the operation.
1487 + if(buf->count == oldcount) {
1488 + ndl_put_list(&ftopd(file)->rd);
1491 + /* unset this, safe */
1492 + mini_fo_filldir_file = NULL;
1497 +STATIC unsigned int
1498 +mini_fo_poll(file_t *file, poll_table *wait)
1500 + unsigned int mask = DEFAULT_POLLMASK;
1501 + file_t *hidden_file = NULL;
1503 + if (ftopd(file) != NULL) {
1504 + if(ftohf2(file)) {
1505 + hidden_file = ftohf2(file);
1507 + hidden_file = ftohf(file);
1511 + if (!hidden_file->f_op || !hidden_file->f_op->poll)
1514 + mask = hidden_file->f_op->poll(hidden_file, wait);
1520 +/* FIST-LITE special version of mmap */
1522 +mini_fo_mmap(file_t *file, vm_area_t *vma)
1525 + file_t *hidden_file = NULL;
1527 + /* fanout capability */
1528 + if (ftopd(file) != NULL) {
1529 + if(ftohf2(file)) {
1530 + hidden_file = ftohf2(file);
1532 + hidden_file = ftohf(file);
1536 + ASSERT(hidden_file != NULL);
1537 + ASSERT(hidden_file->f_op != NULL);
1538 + ASSERT(hidden_file->f_op->mmap != NULL);
1540 + vma->vm_file = hidden_file;
1541 + err = hidden_file->f_op->mmap(hidden_file, vma);
1542 + get_file(hidden_file); /* make sure it doesn't get freed on us */
1543 + fput(file); /* no need to keep extra ref on ours */
1551 +mini_fo_open(inode_t *inode, file_t *file)
1555 + file_t *hidden_file = NULL;
1556 + dentry_t *hidden_dentry = NULL;
1558 + /* fanout stuff */
1559 + file_t *hidden_sto_file = NULL;
1560 + dentry_t *hidden_sto_dentry = NULL;
1563 + kmalloc(sizeof(struct mini_fo_file_info), GFP_KERNEL);
1564 + if (!ftopd(file)) {
1569 + /* init the readdir_helper structure */
1570 + INIT_LIST_HEAD(&ftopd(file)->rd.ndl_list);
1571 + ftopd(file)->rd.ndl_size = 0;
1573 + /* In certain paths this could stay uninitalized and cause trouble */
1574 + ftohf(file) = NULL;
1575 + ftohf2(file) = NULL;
1576 + hidden_flags = file->f_flags;
1578 + /* create storage files? */
1579 + if(dtost(file->f_dentry) == UNMODIFIED) {
1580 + if(!IS_WRITE_FLAG(file->f_flags)) {
1581 + hidden_dentry = dtohd(file->f_dentry);
1582 + dget(hidden_dentry);
1583 + /* dentry_open will decrement mnt refcnt if err.
1584 + * otherwise fput() will do an mntput() for us upon file close. */
1585 + mntget(stopd(inode->i_sb)->hidden_mnt);
1586 + hidden_file = dentry_open(hidden_dentry,
1587 + stopd(inode->i_sb)->hidden_mnt,
1589 + if (IS_ERR(hidden_file)) {
1590 + err = PTR_ERR(hidden_file);
1591 + dput(hidden_dentry);
1594 + ftohf(file) = hidden_file; /* link two files */
1598 + if(S_ISDIR(file->f_dentry->d_inode->i_mode)) {
1599 + err = dir_unmod_to_mod(file->f_dentry);
1601 + err = nondir_unmod_to_mod(file->f_dentry, 1);
1604 + printk("mini_fo_open: ERROR creating storage file.\n");
1609 + hidden_sto_dentry = dtohd2(file->f_dentry);
1610 + dget(hidden_sto_dentry);
1612 + if(dtopd(file->f_dentry)->state == MODIFIED) {
1613 + /* Directorys are special, interpose on both lower level files */
1614 + if(S_ISDIR(itohi(inode)->i_mode)) {
1615 + /* check for invalid file types of lower level files */
1616 + if(!(S_ISDIR(itohi(inode)->i_mode) && S_ISDIR(itohi2(inode)->i_mode))) {
1617 + printk(KERN_CRIT "mini_fo_open: meta data corruption detected.\n");
1618 + dput(hidden_sto_dentry);
1623 + /* lower level directorys are ok, open the base file */
1624 + hidden_dentry = dtohd(file->f_dentry);
1625 + dget(hidden_dentry);
1627 + mntget(stopd(inode->i_sb)->hidden_mnt);
1628 + hidden_file = dentry_open(hidden_dentry,
1629 + stopd(inode->i_sb)->hidden_mnt,
1631 + if (IS_ERR(hidden_file)) {
1632 + err = PTR_ERR(hidden_file);
1633 + dput(hidden_dentry);
1634 + dput(hidden_sto_dentry);
1637 + ftohf(file) = hidden_file; /* link the two files */
1641 + if(!exists_in_storage(file->f_dentry)) {
1642 + printk(KERN_CRIT "mini_fo_open: invalid file state detected.\n");
1644 + dput(hidden_sto_dentry);
1646 + /* If the base file has been opened, we need to close it here */
1648 + if (hidden_file->f_op && hidden_file->f_op->flush)
1649 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,18)
1650 + hidden_file->f_op->flush(hidden_file, NULL);
1652 + hidden_file->f_op->flush(hidden_file);
1654 + dput(hidden_dentry);
1659 + /* ok, now we can safely open the storage file */
1660 + mntget(stopd(inode->i_sb)->hidden_mnt2);
1661 + hidden_sto_file = dentry_open(hidden_sto_dentry,
1662 + stopd(inode->i_sb)->hidden_mnt2,
1665 + /* dentry_open dputs the dentry if it fails */
1666 + if (IS_ERR(hidden_sto_file)) {
1667 + err = PTR_ERR(hidden_sto_file);
1668 + /* close base file if open */
1670 + if (hidden_file->f_op && hidden_file->f_op->flush)
1671 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,18)
1672 + hidden_file->f_op->flush(hidden_file, NULL);
1674 + hidden_file->f_op->flush(hidden_file);
1676 + dput(hidden_dentry);
1680 + ftohf2(file) = hidden_sto_file; /* link storage file */
1683 + if (err < 0 && ftopd(file)) {
1684 + kfree(ftopd(file));
1690 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,18)
1691 +mini_fo_flush(file_t *file, fl_owner_t id)
1693 +mini_fo_flush(file_t *file)
1696 + int err1 = 0; /* assume ok (see open.c:close_fp) */
1698 + file_t *hidden_file = NULL;
1700 + check_mini_fo_file(file);
1702 + /* mk: we don't do any state checking here, as its not worth the time.
1703 + * Just flush the lower level files if they exist.
1705 + if(ftopd(file) != NULL) {
1706 + if(ftohf(file) != NULL) {
1707 + hidden_file = ftohf(file);
1708 + if (hidden_file->f_op && hidden_file->f_op->flush)
1709 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,18)
1710 + err1 = hidden_file->f_op->flush(hidden_file, id);
1712 + err1 = hidden_file->f_op->flush(hidden_file);
1715 + if(ftohf2(file) != NULL) {
1716 + hidden_file = ftohf2(file);
1717 + if (hidden_file->f_op && hidden_file->f_op->flush)
1718 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,18)
1719 + err2 = hidden_file->f_op->flush(hidden_file, id);
1721 + err2 = hidden_file->f_op->flush(hidden_file);
1725 + return (err1 | err2);
1730 +mini_fo_release(inode_t *inode, file_t *file)
1733 + file_t *hidden_file = NULL;
1735 + if (ftopd(file) != NULL) {
1737 + hidden_file = ftohf(file);
1738 + fput(hidden_file);
1740 + if(ftohf2(file)) {
1741 + hidden_file = ftohf2(file);
1742 + fput(hidden_file);
1744 + kfree(ftopd(file));
1750 +mini_fo_fsync(file_t *file, dentry_t *dentry, int datasync)
1754 + file_t *hidden_file = NULL;
1755 + dentry_t *hidden_dentry;
1757 + check_mini_fo_file(file);
1759 + if ((hidden_file = ftohf(file)) != NULL) {
1760 + hidden_dentry = dtohd(dentry);
1761 + if (hidden_file->f_op && hidden_file->f_op->fsync) {
1762 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
1763 + mutex_lock(&hidden_dentry->d_inode->i_mutex);
1765 + down(&hidden_dentry->d_inode->i_sem);
1767 + err1 = hidden_file->f_op->fsync(hidden_file, hidden_dentry, datasync);
1768 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
1769 + mutex_unlock(&hidden_dentry->d_inode->i_mutex);
1771 + up(&hidden_dentry->d_inode->i_sem);
1776 + if ((hidden_file = ftohf2(file)) != NULL) {
1777 + hidden_dentry = dtohd2(dentry);
1778 + if (hidden_file->f_op && hidden_file->f_op->fsync) {
1779 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
1780 + mutex_lock(&hidden_dentry->d_inode->i_mutex);
1782 + down(&hidden_dentry->d_inode->i_sem);
1784 + err2 = hidden_file->f_op->fsync(hidden_file, hidden_dentry, datasync);
1785 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
1786 + mutex_unlock(&hidden_dentry->d_inode->i_mutex);
1788 + up(&hidden_dentry->d_inode->i_sem);
1796 + return (err1 || err2);
1801 +mini_fo_fasync(int fd, file_t *file, int flag)
1806 + file_t *hidden_file = NULL;
1808 + check_mini_fo_file(file);
1810 + if((hidden_file = ftohf(file)) != NULL) {
1811 + err1 = hidden_file->f_op->fasync(fd, hidden_file, flag);
1813 + if((hidden_file = ftohf2(file)) != NULL) {
1814 + err2 = hidden_file->f_op->fasync(fd, hidden_file, flag);
1817 + return (err1 || err2);
1822 +struct file_operations mini_fo_dir_fops =
1824 + read: generic_read_dir,
1825 + write: mini_fo_write,
1826 + readdir: mini_fo_readdir,
1827 + poll: mini_fo_poll,
1828 + /* ioctl: mini_fo_ioctl, */
1829 + mmap: mini_fo_mmap,
1830 + open: mini_fo_open,
1831 + flush: mini_fo_flush,
1832 + release: mini_fo_release,
1833 + fsync: mini_fo_fsync,
1834 + fasync: mini_fo_fasync,
1835 + /* not needed lock: mini_fo_lock, */
1836 + /* not needed: readv */
1837 + /* not needed: writev */
1838 + /* not implemented: sendpage */
1839 + /* not implemented: get_unmapped_area */
1842 +struct file_operations mini_fo_main_fops =
1844 + llseek: mini_fo_llseek,
1845 + read: mini_fo_read,
1846 + write: mini_fo_write,
1847 + readdir: mini_fo_readdir,
1848 + poll: mini_fo_poll,
1849 + /* ioctl: mini_fo_ioctl, */
1850 + mmap: mini_fo_mmap,
1851 + open: mini_fo_open,
1852 + flush: mini_fo_flush,
1853 + release: mini_fo_release,
1854 + fsync: mini_fo_fsync,
1855 + fasync: mini_fo_fasync,
1856 + /* not needed: lock: mini_fo_lock, */
1857 + /* not needed: readv */
1858 + /* not needed: writev */
1859 + /* not implemented: sendpage */
1860 + /* not implemented: get_unmapped_area */
1862 Index: linux-2.6.23/fs/mini_fo/fist.h
1863 ===================================================================
1864 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
1865 +++ linux-2.6.23/fs/mini_fo/fist.h 2007-10-10 13:53:23.000000000 +0800
1868 + * Copyright (c) 1997-2003 Erez Zadok
1869 + * Copyright (c) 2001-2003 Stony Brook University
1871 + * For specific licensing information, see the COPYING file distributed with
1872 + * this package, or get one from ftp://ftp.filesystems.org/pub/fist/COPYING.
1874 + * This Copyright notice must be kept intact and distributed with all
1875 + * fistgen sources INCLUDING sources generated by fistgen.
1878 + * Copyright (C) 2004, 2005 Markus Klotzbuecher <mk@creamnet.de>
1880 + * This program is free software; you can redistribute it and/or
1881 + * modify it under the terms of the GNU General Public License
1882 + * as published by the Free Software Foundation; either version
1883 + * 2 of the License, or (at your option) any later version.
1895 + * KERNEL ONLY CODE:
1898 +#include <linux/version.h>
1899 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,19)
1900 +#include <linux/autoconf.h>
1902 +#include <linux/config.h>
1904 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
1905 +#ifdef CONFIG_MODVERSIONS
1906 +# define MODVERSIONS
1907 +# include <linux/modversions.h>
1908 +#endif /* CONFIG_MODVERSIONS */
1909 +#endif /* KERNEL_VERSION < 2.6.0 */
1910 +#include <linux/sched.h>
1911 +#include <linux/kernel.h>
1912 +#include <linux/mm.h>
1913 +#include <linux/string.h>
1914 +#include <linux/stat.h>
1915 +#include <linux/errno.h>
1916 +#include <linux/wait.h>
1917 +#include <linux/limits.h>
1918 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
1919 +#include <linux/locks.h>
1921 +#include <linux/buffer_head.h>
1922 +#include <linux/pagemap.h>
1923 +#include <linux/namei.h>
1924 +#include <linux/module.h>
1925 +#include <linux/mount.h>
1926 +#include <linux/page-flags.h>
1927 +#include <linux/writeback.h>
1928 +#include <linux/statfs.h>
1930 +#include <linux/smp.h>
1931 +#include <linux/smp_lock.h>
1932 +#include <linux/file.h>
1933 +#include <linux/slab.h>
1934 +#include <linux/vmalloc.h>
1935 +#include <linux/poll.h>
1936 +#include <linux/list.h>
1937 +#include <linux/init.h>
1939 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,20)
1940 +#include <linux/xattr.h>
1943 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
1944 +#include <linux/security.h>
1947 +#include <linux/swap.h>
1949 +#include <asm/system.h>
1950 +/* #include <asm/segment.h> */
1951 +#include <asm/mman.h>
1952 +#include <linux/seq_file.h>
1958 +/* those mapped to ATTR_* were copied from linux/fs.h */
1959 +#define FA_MODE ATTR_MODE
1960 +#define FA_UID ATTR_UID
1961 +#define FA_GID ATTR_GID
1962 +#define FA_SIZE ATTR_SIZE
1963 +#define FA_ATIME ATTR_ATIME
1964 +#define FA_MTIME ATTR_MTIME
1965 +#define FA_CTIME ATTR_CTIME
1966 +#define FA_ATIME_SET ATTR_ATIME_SET
1967 +#define FA_MTIME_SET ATTR_MTIME_SET
1968 +#define FA_FORCE ATTR_FORCE
1969 +#define FA_ATTR_FLAGS ATTR_ATTR_FLAG
1971 +/* must be greater than all other ATTR_* flags! */
1972 +#define FA_NLINK 2048
1973 +#define FA_BLKSIZE 4096
1974 +#define FA_BLOCKS 8192
1975 +#define FA_TIMES (FA_ATIME|FA_MTIME|FA_CTIME)
1978 +/* macros to manage changes between kernels */
1979 +#define INODE_DATA(i) (&(i)->i_data)
1981 +#define MIN(x,y) ((x < y) ? (x) : (y))
1982 +#define MAX(x,y) ((x > y) ? (x) : (y))
1983 +#define MAXPATHLEN PATH_MAX
1985 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,4,5)
1986 +# define lookup_one_len(a,b,c) lookup_one(a,b)
1987 +#endif /* LINUX_VERSION_CODE < KERNEL_VERSION(2,4,5) */
1989 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,4,8)
1990 +# define generic_file_llseek default_llseek
1991 +#endif /* LINUX_VERSION_CODE < KERNEL_VERSION(2,4,8) */
1994 +# define SEEK_SET 0
1995 +#endif /* not SEEK_SET */
1998 +# define SEEK_CUR 1
1999 +#endif /* not SEEK_CUR */
2002 +# define SEEK_END 2
2003 +#endif /* not SEEK_END */
2005 +#ifndef DEFAULT_POLLMASK
2006 +# define DEFAULT_POLLMASK (POLLIN | POLLOUT | POLLRDNORM | POLLWRNORM)
2007 +#endif /* not DEFAULT_POLLMASK */
2009 +/* XXX: fix this so fistgen generates kfree() code directly */
2010 +#define kfree_s(a,b) kfree(a)
2015 +typedef struct dentry dentry_t;
2016 +typedef struct file file_t;
2017 +typedef struct inode inode_t;
2018 +typedef inode_t vnode_t;
2019 +typedef struct page page_t;
2020 +typedef struct qstr qstr_t;
2021 +typedef struct super_block super_block_t;
2022 +typedef super_block_t vfs_t;
2023 +typedef struct vm_area_struct vm_area_t;
2030 +#define FPPF(str,page) printk("PPF %s 0x%x/%d: Lck:%d Err:%d Ref:%d Upd:%d Other::%d:%d:%d:%d:\n", \
2033 + (int) page->index, \
2034 + (PageLocked(page) ? 1 : 0), \
2035 + (PageError(page) ? 1 : 0), \
2036 + (PageReferenced(page) ? 1 : 0), \
2037 + (Page_Uptodate(page) ? 1 : 0), \
2038 + (PageDecrAfter(page) ? 1 : 0), \
2039 + (PageSlab(page) ? 1 : 0), \
2040 + (PageSwapCache(page) ? 1 : 0), \
2041 + (PageReserved(page) ? 1 : 0) \
2043 +#define EZKDBG printk("EZK %s:%d:%s\n",__FILE__,__LINE__,__FUNCTION__)
2045 +# define EZKDBG1 printk("EZK %s:%d\n",__FILE__,__LINE__)
2050 +extern int fist_get_debug_value(void);
2051 +extern int fist_set_debug_value(int val);
2052 +#if 0 /* mini_fo doesn't need these */
2053 +extern void fist_dprint_internal(int level, char *str,...);
2054 +extern void fist_print_dentry(char *str, const dentry_t *dentry);
2055 +extern void fist_print_inode(char *str, const inode_t *inode);
2056 +extern void fist_print_file(char *str, const file_t *file);
2057 +extern void fist_print_buffer_flags(char *str, struct buffer_head *buffer);
2058 +extern void fist_print_page_flags(char *str, page_t *page);
2059 +extern void fist_print_page_bytes(char *str, page_t *page);
2060 +extern void fist_print_pte_flags(char *str, const page_t *page);
2061 +extern void fist_checkinode(inode_t *inode, char *msg);
2062 +extern void fist_print_sb(char *str, const super_block_t *sb);
2064 +/* §$% by mk: special debug functions */
2065 +extern void fist_mk_print_dentry(char *str, const dentry_t *dentry);
2066 +extern void fist_mk_print_inode(char *str, const inode_t *inode);
2068 +extern char *add_indent(void);
2069 +extern char *del_indent(void);
2070 +#endif/* mini_fo doesn't need these */
2074 +#define ASSERT(EX) \
2077 + printk(KERN_CRIT "ASSERTION FAILED: %s at %s:%d (%s)\n", #EX, \
2078 + __FILE__, __LINE__, __FUNCTION__); \
2079 + (*((char *)0))=0; \
2082 +/* same ASSERT, but tell me who was the caller of the function */
2083 +#define ASSERT2(EX) \
2086 + printk(KERN_CRIT "ASSERTION FAILED (caller): %s at %s:%d (%s)\n", #EX, \
2087 + file, line, func); \
2088 + (*((char *)0))=0; \
2092 +#if 0 /* mini_fo doesn't need these */
2093 +#define dprintk(format, args...) printk(KERN_DEBUG format, ##args)
2094 +#define fist_dprint(level, str, args...) fist_dprint_internal(level, KERN_DEBUG str, ## args)
2095 +#define print_entry_location() fist_dprint(4, "%sIN: %s %s:%d\n", add_indent(), __FUNCTION__, __FILE__, __LINE__)
2096 +#define print_exit_location() fist_dprint(4, "%s OUT: %s %s:%d\n", del_indent(), __FUNCTION__, __FILE__, __LINE__)
2097 +#define print_exit_status(status) fist_dprint(4, "%s OUT: %s %s:%d, STATUS: %d\n", del_indent(), __FUNCTION__, __FILE__, __LINE__, status)
2098 +#define print_exit_pointer(status) \
2100 + if (IS_ERR(status)) \
2101 + fist_dprint(4, "%s OUT: %s %s:%d, RESULT: %ld\n", del_indent(), __FUNCTION__, __FILE__, __LINE__, PTR_ERR(status)); \
2103 + fist_dprint(4, "%s OUT: %s %s:%d, RESULT: 0x%x\n", del_indent(), __FUNCTION__, __FILE__, __LINE__, PTR_ERR(status)); \
2105 +#endif/* mini_fo doesn't need these */
2107 +#endif /* __KERNEL__ */
2111 + * DEFINITIONS FOR USER AND KERNEL CODE:
2112 + * (Note: ioctl numbers 1--9 are reserved for fistgen, the rest
2113 + * are auto-generated automatically based on the user's .fist file.)
2115 +# define FIST_IOCTL_GET_DEBUG_VALUE _IOR(0x15, 1, int)
2116 +# define FIST_IOCTL_SET_DEBUG_VALUE _IOW(0x15, 2, int)
2118 +#endif /* not __FIST_H_ */
2119 Index: linux-2.6.23/fs/mini_fo/inode.c
2120 ===================================================================
2121 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
2122 +++ linux-2.6.23/fs/mini_fo/inode.c 2007-10-10 13:53:23.000000000 +0800
2125 + * Copyright (c) 1997-2003 Erez Zadok
2126 + * Copyright (c) 2001-2003 Stony Brook University
2128 + * For specific licensing information, see the COPYING file distributed with
2129 + * this package, or get one from ftp://ftp.filesystems.org/pub/fist/COPYING.
2131 + * This Copyright notice must be kept intact and distributed with all
2132 + * fistgen sources INCLUDING sources generated by fistgen.
2135 + * Copyright (C) 2004, 2005 Markus Klotzbuecher <mk@creamnet.de>
2137 + * This program is free software; you can redistribute it and/or
2138 + * modify it under the terms of the GNU General Public License
2139 + * as published by the Free Software Foundation; either version
2140 + * 2 of the License, or (at your option) any later version.
2147 +#ifdef HAVE_CONFIG_H
2148 +# include <config.h>
2152 +#include "mini_fo.h"
2155 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
2156 +mini_fo_create(inode_t *dir, dentry_t *dentry, int mode, struct nameidata *nd)
2158 +mini_fo_create(inode_t *dir, dentry_t *dentry, int mode)
2163 + check_mini_fo_dentry(dentry);
2165 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
2166 + err = create_sto_reg_file(dentry, mode, nd);
2168 + err = create_sto_reg_file(dentry, mode);
2170 + check_mini_fo_dentry(dentry);
2176 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
2177 +mini_fo_lookup(inode_t *dir, dentry_t *dentry, struct nameidata* nd)
2179 +mini_fo_lookup(inode_t *dir, dentry_t *dentry)
2183 + dentry_t *hidden_dir_dentry;
2184 + dentry_t *hidden_dentry = NULL;
2186 + dentry_t *hidden_sto_dir_dentry;
2187 + dentry_t *hidden_sto_dentry = NULL;
2189 + /* whiteout flag */
2191 + char *bpath = NULL;
2194 + unsigned int namelen;
2196 + /* Don't allow lookups of META-files */
2197 + namelen = strlen(META_FILENAME);
2198 + if(namelen == dentry->d_name.len) {
2199 + if(!strncmp(dentry->d_name.name, META_FILENAME, namelen)) {
2205 + hidden_dir_dentry = dtohd(dentry->d_parent);
2206 + hidden_sto_dir_dentry = dtohd2(dentry->d_parent);
2208 + name = dentry->d_name.name;
2209 + namelen = dentry->d_name.len;
2211 + /* must initialize dentry operations */
2212 + dentry->d_op = &mini_fo_dops;
2214 + /* setup the del_flag */
2215 + del_flag = __meta_check_d_entry(dir, name, namelen);
2216 + bpath = __meta_check_r_entry(dir, name, namelen);
2218 + /* perform the lookups of base and storage files:
2220 + * This caused some serious trouble, as a lookup_one_len passing
2221 + * a negative dentry oopses. Solution is to only do the lookup
2222 + * if the dentry is positive, else we set it to NULL
2223 + * More trouble, who said a *_dir_dentry can't be NULL?
2226 + /* Cross-Interposing (C), yeah! */
2227 + hidden_dentry = bpath_walk(dir->i_sb, bpath);
2228 + if(!hidden_dentry || !hidden_dentry->d_inode) {
2229 + printk(KERN_CRIT "mini_fo_lookup: bpath_walk failed.\n");
2234 + /* this can be set up safely without fear of spaghetti
2235 + * interposing as it is only used for copying times */
2236 + hidden_dir_dentry = hidden_dentry->d_parent;
2239 + else if(hidden_dir_dentry && hidden_dir_dentry->d_inode)
2241 + lookup_one_len(name, hidden_dir_dentry, namelen);
2243 + hidden_dentry = NULL;
2245 + if(hidden_sto_dir_dentry && hidden_sto_dir_dentry->d_inode)
2246 + hidden_sto_dentry =
2247 + lookup_one_len(name, hidden_sto_dir_dentry, namelen);
2249 + hidden_sto_dentry = NULL;
2251 + /* catch error in lookup */
2252 + if (IS_ERR(hidden_dentry) || IS_ERR(hidden_sto_dentry)) {
2253 + /* mk: we need to call dput on the dentry, whose
2254 + * lookup_one_len operation failed, in order to avoid
2255 + * unmount trouble.
2257 + if(IS_ERR(hidden_dentry)) {
2258 + printk(KERN_CRIT "mini_fo_lookup: ERR from base dentry, lookup failed.\n");
2259 + err = PTR_ERR(hidden_dentry);
2261 + dput(hidden_dentry);
2263 + if(IS_ERR(hidden_sto_dentry)) {
2264 + printk(KERN_CRIT "mini_fo_lookup: ERR from storage dentry, lookup failed.\n");
2265 + err = PTR_ERR(hidden_sto_dentry);
2267 + dput(hidden_sto_dentry);
2272 + /* allocate dentry private data */
2273 + __dtopd(dentry) = (struct mini_fo_dentry_info *)
2274 + kmalloc(sizeof(struct mini_fo_dentry_info), GFP_KERNEL);
2276 + if (!dtopd(dentry)) {
2281 + /* check for different states of the mini_fo file to be looked up. */
2283 + /* state 1, file has been modified */
2284 + if(hidden_dentry && hidden_sto_dentry &&
2285 + hidden_dentry->d_inode && hidden_sto_dentry->d_inode && !del_flag) {
2287 + /* update parent directory's atime */
2288 + fist_copy_attr_atime(dir, hidden_sto_dir_dentry->d_inode);
2290 + dtopd(dentry)->state = MODIFIED;
2291 + dtohd(dentry) = hidden_dentry;
2292 + dtohd2(dentry) = hidden_sto_dentry;
2294 + err = mini_fo_tri_interpose(hidden_dentry,
2295 + hidden_sto_dentry,
2296 + dentry, dir->i_sb, 1);
2298 + printk(KERN_CRIT "mini_fo_lookup: error interposing (state1).\n");
2303 + /* state 2, file is unmodified */
2304 + if(hidden_dentry && hidden_dentry->d_inode && !del_flag) {
2306 + fist_copy_attr_atime(dir, hidden_dir_dentry->d_inode);
2308 + dtopd(dentry)->state = UNMODIFIED;
2309 + dtohd(dentry) = hidden_dentry;
2310 + dtohd2(dentry) = hidden_sto_dentry; /* could be negative */
2312 + err = mini_fo_tri_interpose(hidden_dentry,
2313 + hidden_sto_dentry,
2314 + dentry, dir->i_sb, 1);
2316 + printk(KERN_CRIT "mini_fo_lookup: error interposing (state2).\n");
2321 + /* state 3, file has been newly created */
2322 + if(hidden_sto_dentry && hidden_sto_dentry->d_inode && !del_flag) {
2324 + fist_copy_attr_atime(dir, hidden_sto_dir_dentry->d_inode);
2325 + dtopd(dentry)->state = CREATED;
2326 + dtohd(dentry) = hidden_dentry; /* could be negative */
2327 + dtohd2(dentry) = hidden_sto_dentry;
2329 + err = mini_fo_tri_interpose(hidden_dentry,
2330 + hidden_sto_dentry,
2331 + dentry, dir->i_sb, 1);
2333 + printk(KERN_CRIT "mini_fo_lookup: error interposing (state3).\n");
2339 + /* state 4, file has deleted and created again. */
2340 + if(hidden_dentry && hidden_sto_dentry &&
2341 + hidden_dentry->d_inode &&
2342 + hidden_sto_dentry->d_inode && del_flag) {
2344 + fist_copy_attr_atime(dir, hidden_sto_dir_dentry->d_inode);
2345 + dtopd(dentry)->state = DEL_REWRITTEN;
2346 + dtohd(dentry) = NULL;
2347 + dtohd2(dentry) = hidden_sto_dentry;
2349 + err = mini_fo_tri_interpose(NULL,
2350 + hidden_sto_dentry,
2351 + dentry, dir->i_sb, 1);
2353 + printk(KERN_CRIT "mini_fo_lookup: error interposing (state4).\n");
2356 + /* We will never need this dentry again, as the file has been
2357 + * deleted from base */
2358 + dput(hidden_dentry);
2361 + /* state 5, file has been deleted in base */
2362 + if(hidden_dentry && hidden_sto_dentry &&
2363 + hidden_dentry->d_inode &&
2364 + !hidden_sto_dentry->d_inode && del_flag) {
2366 + /* check which parents atime we need for updating */
2367 + if(hidden_sto_dir_dentry->d_inode)
2368 + fist_copy_attr_atime(dir,
2369 + hidden_sto_dir_dentry->d_inode);
2371 + fist_copy_attr_atime(dir,
2372 + hidden_dir_dentry->d_inode);
2374 + dtopd(dentry)->state = DELETED;
2375 + dtohd(dentry) = NULL;
2376 + dtohd2(dentry) = hidden_sto_dentry;
2378 + /* add negative dentry to dcache to speed up lookups */
2379 + d_add(dentry, NULL);
2380 + dput(hidden_dentry);
2383 + /* state 6, file does not exist */
2384 + if(((hidden_dentry && !hidden_dentry->d_inode) ||
2385 + (hidden_sto_dentry && !hidden_sto_dentry->d_inode)) && !del_flag)
2387 + /* check which parents atime we need for updating */
2388 + if(hidden_sto_dir_dentry && hidden_sto_dir_dentry->d_inode)
2389 + fist_copy_attr_atime(dir, hidden_sto_dir_dentry->d_inode);
2391 + fist_copy_attr_atime(dir, hidden_dir_dentry->d_inode);
2393 + dtopd(dentry)->state = NON_EXISTANT;
2394 + dtohd(dentry) = hidden_dentry;
2395 + dtohd2(dentry) = hidden_sto_dentry;
2396 + d_add(dentry, NULL);
2400 + /* if we get to here, were in an invalid state. bad. */
2401 + printk(KERN_CRIT "mini_fo_lookup: ERROR, meta data corruption detected.\n");
2403 + /* end state checking */
2405 + d_drop(dentry); /* so that our bad dentry will get destroyed */
2406 + kfree(dtopd(dentry));
2407 + __dtopd(dentry) = NULL; /* be safe */
2411 + dput(hidden_dentry);
2412 + if(hidden_sto_dentry)
2413 + dput(hidden_sto_dentry); /* drops usage count and marks for release */
2416 + /* initalize wol if file exists and is directory */
2417 + if(dentry->d_inode) {
2418 + if(S_ISDIR(dentry->d_inode->i_mode)) {
2419 + itopd(dentry->d_inode)->deleted_list_size = -1;
2420 + itopd(dentry->d_inode)->renamed_list_size = -1;
2421 + meta_build_lists(dentry);
2424 + return ERR_PTR(err);
2429 +mini_fo_link(dentry_t *old_dentry, inode_t *dir, dentry_t *new_dentry)
2432 + dentry_t *hidden_old_dentry;
2433 + dentry_t *hidden_new_dentry;
2434 + dentry_t *hidden_dir_dentry;
2437 + check_mini_fo_dentry(old_dentry);
2438 + check_mini_fo_dentry(new_dentry);
2439 + check_mini_fo_inode(dir);
2441 + /* no links to directorys and existing targets target allowed */
2442 + if(S_ISDIR(old_dentry->d_inode->i_mode) ||
2443 + is_mini_fo_existant(new_dentry)) {
2448 + /* bring it directly from unmod to del_rew */
2449 + if(dtost(old_dentry) == UNMODIFIED) {
2450 + err = nondir_unmod_to_mod(old_dentry, 1);
2455 + err = meta_add_d_entry(old_dentry->d_parent,
2456 + old_dentry->d_name.name,
2457 + old_dentry->d_name.len);
2462 + dput(dtohd(old_dentry));
2463 + dtohd(old_dentry) = NULL;
2464 + dtost(old_dentry) = DEL_REWRITTEN;
2467 + err = get_neg_sto_dentry(new_dentry);
2473 + hidden_old_dentry = dtohd2(old_dentry);
2474 + hidden_new_dentry = dtohd2(new_dentry);
2476 + dget(hidden_old_dentry);
2477 + dget(hidden_new_dentry);
2479 + /* was: hidden_dir_dentry = lock_parent(hidden_new_dentry); */
2480 + hidden_dir_dentry = dget(hidden_new_dentry->d_parent);
2481 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
2482 + mutex_lock(&hidden_dir_dentry->d_inode->i_mutex);
2484 + down(&hidden_dir_dentry->d_inode->i_sem);
2487 + err = vfs_link(hidden_old_dentry,
2488 + hidden_dir_dentry->d_inode,
2489 + hidden_new_dentry);
2490 + if (err || !hidden_new_dentry->d_inode)
2493 + dtost(new_dentry) = CREATED;
2494 + err = mini_fo_tri_interpose(NULL, hidden_new_dentry, new_dentry, dir->i_sb, 0);
2498 + fist_copy_attr_timesizes(dir, hidden_new_dentry->d_inode);
2499 + /* propagate number of hard-links */
2500 + old_dentry->d_inode->i_nlink = itohi2(old_dentry->d_inode)->i_nlink;
2503 + /* was: unlock_dir(hidden_dir_dentry); */
2504 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
2505 + mutex_unlock(&hidden_dir_dentry->d_inode->i_mutex);
2507 + up(&hidden_dir_dentry->d_inode->i_sem);
2509 + dput(hidden_dir_dentry);
2511 + dput(hidden_new_dentry);
2512 + dput(hidden_old_dentry);
2513 + if (!new_dentry->d_inode)
2514 + d_drop(new_dentry);
2522 +mini_fo_unlink(inode_t *dir, dentry_t *dentry)
2527 + if(dtopd(dentry)->state == MODIFIED) {
2528 + err = nondir_mod_to_del(dentry);
2531 + else if(dtopd(dentry)->state == UNMODIFIED) {
2532 + err = nondir_unmod_to_del(dentry);
2535 + else if(dtopd(dentry)->state == CREATED) {
2536 + err = nondir_creat_to_del(dentry);
2539 + else if(dtopd(dentry)->state == DEL_REWRITTEN) {
2540 + err = nondir_del_rew_to_del(dentry);
2544 + printk(KERN_CRIT "mini_fo_unlink: ERROR, invalid state detected.\n");
2547 + fist_copy_attr_times(dir, itohi2(dentry->d_parent->d_inode));
2550 + /* is this causing my pain? d_delete(dentry); */
2560 +mini_fo_symlink(inode_t *dir, dentry_t *dentry, const char *symname)
2563 + dentry_t *hidden_sto_dentry;
2564 + dentry_t *hidden_sto_dir_dentry;
2565 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
2569 + /* Fail if the symlink file exists */
2570 + if(!(dtost(dentry) == DELETED ||
2571 + dtost(dentry) == NON_EXISTANT)) {
2576 + err = get_neg_sto_dentry(dentry);
2581 + hidden_sto_dentry = dtohd2(dentry);
2583 + dget(hidden_sto_dentry);
2584 + /* was: hidden_sto_dir_dentry = lock_parent(hidden_sto_dentry); */
2585 + hidden_sto_dir_dentry = dget(hidden_sto_dentry->d_parent);
2586 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
2587 + mutex_lock(&hidden_sto_dir_dentry->d_inode->i_mutex);
2589 + down(&hidden_sto_dir_dentry->d_inode->i_sem);
2592 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
2594 + err = vfs_symlink(hidden_sto_dir_dentry->d_inode,
2595 + hidden_sto_dentry, symname, mode);
2597 + err = vfs_symlink(hidden_sto_dir_dentry->d_inode,
2598 + hidden_sto_dentry,
2601 + if (err || !hidden_sto_dentry->d_inode)
2604 + if(dtost(dentry) == DELETED) {
2605 + dtost(dentry) = DEL_REWRITTEN;
2606 + err = mini_fo_tri_interpose(NULL, hidden_sto_dentry, dentry, dir->i_sb, 0);
2609 + } else if(dtost(dentry) == NON_EXISTANT) {
2610 + dtost(dentry) = CREATED;
2611 + err = mini_fo_tri_interpose(dtohd(dentry), hidden_sto_dentry, dentry, dir->i_sb, 0);
2615 + fist_copy_attr_timesizes(dir, hidden_sto_dir_dentry->d_inode);
2618 + /* was: unlock_dir(hidden_sto_dir_dentry); */
2619 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
2620 + mutex_unlock(&hidden_sto_dir_dentry->d_inode->i_mutex);
2622 + up(&hidden_sto_dir_dentry->d_inode->i_sem);
2624 + dput(hidden_sto_dir_dentry);
2626 + dput(hidden_sto_dentry);
2627 + if (!dentry->d_inode)
2634 +mini_fo_mkdir(inode_t *dir, dentry_t *dentry, int mode)
2638 + err = create_sto_dir(dentry, mode);
2640 + check_mini_fo_dentry(dentry);
2647 +mini_fo_rmdir(inode_t *dir, dentry_t *dentry)
2651 + dentry_t *hidden_sto_dentry;
2652 + dentry_t *hidden_sto_dir_dentry;
2653 + dentry_t *meta_dentry;
2654 + inode_t *hidden_sto_dir = NULL;
2656 + check_mini_fo_dentry(dentry);
2657 + check_mini_fo_inode(dir);
2660 + if(dtopd(dentry)->state == MODIFIED) {
2661 + /* XXX: disabled, because it does not bother to check files on
2662 + * the original filesystem - just a hack, but better than simply
2663 + * removing it without testing */
2667 + hidden_sto_dir = itohi2(dir);
2668 + hidden_sto_dentry = dtohd2(dentry);
2670 + /* was:hidden_sto_dir_dentry = lock_parent(hidden_sto_dentry); */
2671 + hidden_sto_dir_dentry = dget(hidden_sto_dentry->d_parent);
2672 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
2673 + mutex_lock(&hidden_sto_dir_dentry->d_inode->i_mutex);
2675 + down(&hidden_sto_dir_dentry->d_inode->i_sem);
2678 + /* Delete an old WOL file contained in the storage dir */
2679 + meta_dentry = lookup_one_len(META_FILENAME,
2680 + hidden_sto_dentry,
2681 + strlen(META_FILENAME));
2682 + if(meta_dentry->d_inode) {
2683 + err = vfs_unlink(hidden_sto_dentry->d_inode, meta_dentry);
2684 + dput(meta_dentry);
2686 + d_delete(meta_dentry);
2689 + err = vfs_rmdir(hidden_sto_dir, hidden_sto_dentry);
2690 + dput(hidden_sto_dentry);
2692 + d_delete(hidden_sto_dentry);
2694 + /* propagate number of hard-links */
2695 + dentry->d_inode->i_nlink = itohi2(dentry->d_inode)->i_nlink;
2697 + dput(dtohd(dentry));
2699 + dtohd(dentry) = NULL;
2700 + dtopd(dentry)->state = DELETED;
2702 + /* carefull with R files */
2703 + if( __meta_is_r_entry(dir,
2704 + dentry->d_name.name,
2705 + dentry->d_name.len) == 1) {
2706 + err = meta_remove_r_entry(dentry->d_parent,
2707 + dentry->d_name.name,
2708 + dentry->d_name.len);
2710 + printk(KERN_CRIT "mini_fo: rmdir: meta_remove_r_entry failed.\n");
2715 + /* ok, add deleted file to META */
2716 + meta_add_d_entry(dentry->d_parent,
2717 + dentry->d_name.name,
2718 + dentry->d_name.len);
2720 + /* was: unlock_dir(hidden_sto_dir_dentry); */
2721 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
2722 + mutex_unlock(&hidden_sto_dir_dentry->d_inode->i_mutex);
2724 + up(&hidden_sto_dir_dentry->d_inode->i_sem);
2726 + dput(hidden_sto_dir_dentry);
2729 + else if(dtopd(dentry)->state == UNMODIFIED) {
2730 + /* XXX: simply adding it to the delete list here is fscking dangerous!
2731 + * as a temporary hack, i will disable rmdir on unmodified directories
2737 + err = get_neg_sto_dentry(dentry);
2743 + /* dput base dentry, this will relase the inode and free the
2744 + * dentry, as we will never need it again. */
2745 + dput(dtohd(dentry));
2746 + dtohd(dentry) = NULL;
2747 + dtopd(dentry)->state = DELETED;
2749 + /* add deleted file to META-file */
2750 + meta_add_d_entry(dentry->d_parent,
2751 + dentry->d_name.name,
2752 + dentry->d_name.len);
2755 + else if(dtopd(dentry)->state == CREATED) {
2756 + hidden_sto_dir = itohi2(dir);
2757 + hidden_sto_dentry = dtohd2(dentry);
2759 + /* was: hidden_sto_dir_dentry = lock_parent(hidden_sto_dentry);*/
2760 + hidden_sto_dir_dentry = dget(hidden_sto_dentry->d_parent);
2762 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
2763 + mutex_lock(&hidden_sto_dir_dentry->d_inode->i_mutex);
2765 + down(&hidden_sto_dir_dentry->d_inode->i_sem);
2768 + /* Delete an old WOL file contained in the storage dir */
2769 + meta_dentry = lookup_one_len(META_FILENAME,
2770 + hidden_sto_dentry,
2771 + strlen(META_FILENAME));
2772 + if(meta_dentry->d_inode) {
2773 + /* is this necessary? dget(meta_dentry); */
2774 + err = vfs_unlink(hidden_sto_dentry->d_inode,
2776 + dput(meta_dentry);
2778 + d_delete(meta_dentry);
2781 + err = vfs_rmdir(hidden_sto_dir, hidden_sto_dentry);
2782 + dput(hidden_sto_dentry);
2784 + d_delete(hidden_sto_dentry);
2786 + /* propagate number of hard-links */
2787 + dentry->d_inode->i_nlink = itohi2(dentry->d_inode)->i_nlink;
2788 + dtopd(dentry)->state = NON_EXISTANT;
2790 + /* was: unlock_dir(hidden_sto_dir_dentry); */
2791 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
2792 + mutex_unlock(&hidden_sto_dir_dentry->d_inode->i_mutex);
2794 + up(&hidden_sto_dir_dentry->d_inode->i_sem);
2796 + dput(hidden_sto_dir_dentry);
2800 + else if(dtopd(dentry)->state == DEL_REWRITTEN) {
2801 + hidden_sto_dir = itohi2(dir);
2802 + hidden_sto_dentry = dtohd2(dentry);
2804 + /* was: hidden_sto_dir_dentry = lock_parent(hidden_sto_dentry);*/
2805 + hidden_sto_dir_dentry = dget(hidden_sto_dentry->d_parent);
2807 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
2808 + mutex_lock(&hidden_sto_dir_dentry->d_inode->i_mutex);
2810 + down(&hidden_sto_dir_dentry->d_inode->i_sem);
2813 + /* Delete an old WOL file contained in the storage dir */
2814 + meta_dentry = lookup_one_len(META_FILENAME,
2815 + hidden_sto_dentry,
2816 + strlen(META_FILENAME));
2817 + if(meta_dentry->d_inode) {
2818 + /* is this necessary? dget(meta_dentry); */
2819 + err = vfs_unlink(hidden_sto_dentry->d_inode,
2821 + dput(meta_dentry);
2823 + d_delete(meta_dentry);
2826 + err = vfs_rmdir(hidden_sto_dir, hidden_sto_dentry);
2827 + dput(hidden_sto_dentry);
2829 + d_delete(hidden_sto_dentry);
2831 + /* propagate number of hard-links */
2832 + dentry->d_inode->i_nlink = itohi2(dentry->d_inode)->i_nlink;
2833 + dtopd(dentry)->state = DELETED;
2834 + /* was: unlock_dir(hidden_sto_dir_dentry); */
2836 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
2837 + mutex_unlock(&hidden_sto_dir_dentry->d_inode->i_mutex);
2839 + up(&hidden_sto_dir_dentry->d_inode->i_sem);
2841 + dput(hidden_sto_dir_dentry);
2845 + printk(KERN_CRIT "mini_fo_rmdir: ERROR, invalid state detected.\n");
2852 + fist_copy_attr_times(dir, itohi2(dentry->d_parent->d_inode));
2860 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
2861 +mini_fo_mknod(inode_t *dir, dentry_t *dentry, int mode, dev_t dev)
2863 +mini_fo_mknod(inode_t *dir, dentry_t *dentry, int mode, int dev)
2868 + check_mini_fo_dentry(dentry);
2870 + err = create_sto_nod(dentry, mode, dev);
2872 + printk(KERN_CRIT "mini_fo_mknod: creating sto nod failed.\n");
2876 + check_mini_fo_dentry(dentry);
2882 +mini_fo_rename(inode_t *old_dir, dentry_t *old_dentry,
2883 + inode_t *new_dir, dentry_t *new_dentry)
2886 + if(S_ISDIR(old_dentry->d_inode->i_mode))
2887 + return rename_directory(old_dir, old_dentry, new_dir, new_dentry);
2888 + return rename_nondir(old_dir, old_dentry, new_dir, new_dentry);
2892 +int rename_directory(inode_t *old_dir, dentry_t *old_dentry,
2893 + inode_t *new_dir, dentry_t *new_dentry)
2895 + int err, bpath_len;
2898 + dentry_t *hidden_old_dentry;
2899 + dentry_t *hidden_new_dentry;
2900 + dentry_t *hidden_old_dir_dentry;
2901 + dentry_t *hidden_new_dir_dentry;
2907 + /* this is a test, chuck out if it works */
2908 + if(!(dtopd(new_dentry)->state == DELETED ||
2909 + dtopd(new_dentry)->state == NON_EXISTANT)) {
2910 + printk(KERN_CRIT "mini_fo: rename_directory: \
2911 + uh, ah, new_dentry not negative.\n");
2915 + /* state = UNMODIFIED */
2916 + if(dtopd(old_dentry)->state == UNMODIFIED) {
2917 + err = dir_unmod_to_mod(old_dentry);
2922 + /* state = MODIFIED */
2923 + if(dtopd(old_dentry)->state == MODIFIED) {
2924 + bpath = meta_check_r_entry(old_dentry->d_parent,
2925 + old_dentry->d_name.name,
2926 + old_dentry->d_name.len);
2928 + err = meta_remove_r_entry(old_dentry->d_parent,
2929 + old_dentry->d_name.name,
2930 + old_dentry->d_name.len);
2932 + printk(KERN_CRIT "mini_fo: rename_directory:\
2933 + meta_remove_r_entry \
2937 + err = meta_add_r_entry(new_dentry->d_parent,
2940 + new_dentry->d_name.name,
2941 + new_dentry->d_name.len);
2944 + else {/* wol it */
2945 + err = meta_add_d_entry(old_dentry->d_parent,
2946 + old_dentry->d_name.name,
2947 + old_dentry->d_name.len);
2950 + /* put it on rename list */
2951 + err = get_mini_fo_bpath(old_dentry,
2956 + err = meta_add_r_entry(new_dentry->d_parent,
2958 + new_dentry->d_name.name,
2959 + new_dentry->d_name.len);
2963 + /* no state change, MODIFIED stays MODIFIED */
2965 + /* state = CREATED */
2966 + if(dtopd(old_dentry)->state == CREATED ||
2967 + dtopd(old_dentry)->state == DEL_REWRITTEN) {
2968 + if(dtohd(old_dentry))
2969 + dput(dtohd(old_dentry));
2971 + if(dtopd(new_dentry)->state == DELETED) {
2972 + dtopd(old_dentry)->state = DEL_REWRITTEN;
2973 + dtohd(old_dentry) = NULL;
2975 + else if(dtopd(new_dentry)->state == NON_EXISTANT) {
2976 + dtopd(old_dentry)->state = CREATED;
2977 + /* steal new dentry's neg. base dentry */
2978 + dtohd(old_dentry) = dtohd(new_dentry);
2979 + dtohd(new_dentry) = NULL;
2982 + if(dtopd(new_dentry)->state == UNMODIFIED ||
2983 + dtopd(new_dentry)->state == NON_EXISTANT) {
2984 + err = get_neg_sto_dentry(new_dentry);
2989 + /* now move sto file */
2990 + hidden_old_dentry = dtohd2(old_dentry);
2991 + hidden_new_dentry = dtohd2(new_dentry);
2993 + dget(hidden_old_dentry);
2994 + dget(hidden_new_dentry);
2996 + hidden_old_dir_dentry = dget(hidden_old_dentry->d_parent);
2997 + hidden_new_dir_dentry = dget(hidden_new_dentry->d_parent);
2998 + double_lock(hidden_old_dir_dentry, hidden_new_dir_dentry);
3000 + err = vfs_rename(hidden_old_dir_dentry->d_inode, hidden_old_dentry,
3001 + hidden_new_dir_dentry->d_inode, hidden_new_dentry);
3005 + fist_copy_attr_all(new_dir, hidden_new_dir_dentry->d_inode);
3006 + if (new_dir != old_dir)
3007 + fist_copy_attr_all(old_dir,
3008 + hidden_old_dir_dentry->d_inode);
3011 + /* double_unlock will dput the new/old parent dentries
3012 + * whose refcnts were incremented via get_parent above. */
3013 + double_unlock(hidden_old_dir_dentry, hidden_new_dir_dentry);
3014 + dput(hidden_new_dentry);
3015 + dput(hidden_old_dentry);
3021 +int rename_nondir(inode_t *old_dir, dentry_t *old_dentry,
3022 + inode_t *new_dir, dentry_t *new_dentry)
3026 + check_mini_fo_dentry(old_dentry);
3027 + check_mini_fo_dentry(new_dentry);
3028 + check_mini_fo_inode(old_dir);
3029 + check_mini_fo_inode(new_dir);
3031 + /* state: UNMODIFIED */
3032 + if(dtost(old_dentry) == UNMODIFIED) {
3033 + err = nondir_unmod_to_mod(old_dentry, 1);
3040 + /* the easy states */
3041 + if(exists_in_storage(old_dentry)) {
3043 + dentry_t *hidden_old_dentry;
3044 + dentry_t *hidden_new_dentry;
3045 + dentry_t *hidden_old_dir_dentry;
3046 + dentry_t *hidden_new_dir_dentry;
3048 + /* if old file is MODIFIED, add it to the deleted_list */
3049 + if(dtopd(old_dentry)->state == MODIFIED) {
3050 + meta_add_d_entry(old_dentry->d_parent,
3051 + old_dentry->d_name.name,
3052 + old_dentry->d_name.len);
3054 + dput(dtohd(old_dentry));
3056 + /* if old file is CREATED, we only release the base dentry */
3057 + if(dtopd(old_dentry)->state == CREATED) {
3058 + if(dtohd(old_dentry))
3059 + dput(dtohd(old_dentry));
3062 + /* now setup the new states (depends on new_dentry state) */
3063 + /* new dentry state = MODIFIED */
3064 + if(dtopd(new_dentry)->state == MODIFIED) {
3065 + meta_add_d_entry(new_dentry->d_parent,
3066 + new_dentry->d_name.name,
3067 + new_dentry->d_name.len);
3069 + /* new dentry will be d_put'ed later by the vfs
3070 + * so don't do it here
3071 + * dput(dtohd(new_dentry));
3073 + dtohd(old_dentry) = NULL;
3074 + dtopd(old_dentry)->state = DEL_REWRITTEN;
3076 + /* new dentry state = UNMODIFIED */
3077 + else if(dtopd(new_dentry)->state == UNMODIFIED) {
3078 + if(get_neg_sto_dentry(new_dentry))
3081 + meta_add_d_entry(new_dentry->d_parent,
3082 + new_dentry->d_name.name,
3083 + new_dentry->d_name.len);
3085 + /* is this right??? */
3086 + /*dput(dtohd(new_dentry));*/
3087 + dtohd(old_dentry) = NULL;
3088 + dtopd(old_dentry)->state = DEL_REWRITTEN;
3090 + /* new dentry state = CREATED */
3091 + else if(dtopd(new_dentry)->state == CREATED) {
3092 + /* we keep the neg. base dentry (if exists) */
3093 + dtohd(old_dentry) = dtohd(new_dentry);
3094 + /* ...and set it to Null, or we'll get
3095 + * dcache.c:345 if it gets dput twice... */
3096 + dtohd(new_dentry) = NULL;
3097 + dtopd(old_dentry)->state = CREATED;
3099 + /* new dentry state = NON_EXISTANT */
3100 + else if(dtopd(new_dentry)->state == NON_EXISTANT) {
3101 + if(get_neg_sto_dentry(new_dentry))
3104 + /* we keep the neg. base dentry (if exists) */
3105 + dtohd(old_dentry) = dtohd(new_dentry);
3106 + /* ...and set it to Null, or we'll get
3107 + * Dr. dcache.c:345 if it gets dput twice... */
3108 + dtohd(new_dentry) = NULL;
3109 + dtopd(old_dentry)->state = CREATED;
3111 + /* new dentry state = DEL_REWRITTEN or DELETED */
3112 + else if(dtopd(new_dentry)->state == DEL_REWRITTEN ||
3113 + dtopd(new_dentry)->state == DELETED) {
3114 + dtohd(old_dentry) = NULL;
3115 + dtopd(old_dentry)->state = DEL_REWRITTEN;
3117 + else { /* not possible, uhh, ahh */
3119 + "mini_fo: rename_reg_file: invalid state detected [1].\n");
3123 + /* now we definitely have a sto file */
3124 + hidden_old_dentry = dtohd2(old_dentry);
3125 + hidden_new_dentry = dtohd2(new_dentry);
3127 + dget(hidden_old_dentry);
3128 + dget(hidden_new_dentry);
3130 + hidden_old_dir_dentry = dget(hidden_old_dentry->d_parent);
3131 + hidden_new_dir_dentry = dget(hidden_new_dentry->d_parent);
3132 + double_lock(hidden_old_dir_dentry, hidden_new_dir_dentry);
3134 + err = vfs_rename(hidden_old_dir_dentry->d_inode,
3135 + hidden_old_dentry,
3136 + hidden_new_dir_dentry->d_inode,
3137 + hidden_new_dentry);
3141 + fist_copy_attr_all(new_dir, hidden_new_dir_dentry->d_inode);
3142 + if (new_dir != old_dir)
3143 + fist_copy_attr_all(old_dir, hidden_old_dir_dentry->d_inode);
3146 + /* double_unlock will dput the new/old parent dentries
3147 + * whose refcnts were incremented via get_parent above.
3149 + double_unlock(hidden_old_dir_dentry, hidden_new_dir_dentry);
3150 + dput(hidden_new_dentry);
3151 + dput(hidden_old_dentry);
3155 + else { /* invalid state */
3156 + printk(KERN_CRIT "mini_fo: rename_reg_file: ERROR: invalid state detected [2].\n");
3163 +mini_fo_readlink(dentry_t *dentry, char *buf, int bufsiz)
3166 + dentry_t *hidden_dentry = NULL;
3168 + if(dtohd2(dentry) && dtohd2(dentry)->d_inode) {
3169 + hidden_dentry = dtohd2(dentry);
3170 + } else if(dtohd(dentry) && dtohd(dentry)->d_inode) {
3171 + hidden_dentry = dtohd(dentry);
3176 + if (!hidden_dentry->d_inode->i_op ||
3177 + !hidden_dentry->d_inode->i_op->readlink) {
3178 + err = -EINVAL; goto out;
3181 + err = hidden_dentry->d_inode->i_op->readlink(hidden_dentry,
3185 + fist_copy_attr_atime(dentry->d_inode, hidden_dentry->d_inode);
3192 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,13)
3193 +static int mini_fo_follow_link(dentry_t *dentry, struct nameidata *nd)
3195 +static void* mini_fo_follow_link(dentry_t *dentry, struct nameidata *nd)
3199 + int len = PAGE_SIZE, err;
3200 + mm_segment_t old_fs;
3202 + /* in 2.6 this is freed by mini_fo_put_link called by __do_follow_link */
3203 + buf = kmalloc(len, GFP_KERNEL);
3209 + /* read the symlink, and then we will follow it */
3210 + old_fs = get_fs();
3211 + set_fs(KERNEL_DS);
3212 + err = dentry->d_inode->i_op->readlink(dentry, buf, len);
3220 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
3221 + nd_set_link(nd, buf);
3224 + err = vfs_follow_link(nd, buf);
3228 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
3232 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,13)
3235 + return ERR_PTR(err);
3240 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
3241 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,13)
3242 +void mini_fo_put_link(struct dentry *dentry, struct nameidata *nd)
3244 +void mini_fo_put_link(struct dentry *dentry, struct nameidata *nd, void *cookie)
3248 + link = nd_get_link(nd);
3254 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
3255 +mini_fo_permission(inode_t *inode, int mask, struct nameidata *nd)
3257 +mini_fo_permission(inode_t *inode, int mask)
3260 + inode_t *hidden_inode;
3264 + if(itohi2(inode)) {
3265 + hidden_inode = itohi2(inode);
3267 + hidden_inode = itohi(inode);
3269 + mode = inode->i_mode;
3271 + /* not really needed, as permission handles everything:
3272 + * err = vfs_permission(inode, mask);
3277 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
3278 + err = permission(hidden_inode, mask, nd);
3280 + err = permission(hidden_inode, mask);
3287 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
3289 +mini_fo_inode_revalidate(dentry_t *dentry)
3292 + dentry_t *hidden_dentry;
3293 + inode_t *hidden_inode;
3295 + ASSERT(dentry->d_inode);
3296 + ASSERT(itopd(dentry->d_inode));
3298 + if(itohi2(dentry->d_inode)) {
3299 + hidden_dentry = dtohd2(dentry);
3300 + hidden_inode = hidden_dentry->d_inode;
3301 + } else if(itohi(dentry->d_inode)) {
3302 + hidden_dentry = dtohd(dentry);
3303 + hidden_inode = hidden_dentry->d_inode;
3305 + printk(KERN_CRIT "mini_fo_inode_revalidate: ERROR, invalid state detected.\n");
3309 + if (hidden_inode && hidden_inode->i_op && hidden_inode->i_op->revalidate){
3310 + err = hidden_inode->i_op->revalidate(hidden_dentry);
3314 + fist_copy_attr_all(dentry->d_inode, hidden_inode);
3321 +mini_fo_setattr(dentry_t *dentry, struct iattr *ia)
3325 + check_mini_fo_dentry(dentry);
3327 + if(!is_mini_fo_existant(dentry)) {
3328 + printk(KERN_CRIT "mini_fo_setattr: ERROR, invalid state detected [1].\n");
3332 + if(dtost(dentry) == UNMODIFIED) {
3333 + if(!IS_COPY_FLAG(ia->ia_valid))
3334 + goto out; /* we ignore these changes to base */
3336 + if(S_ISDIR(dentry->d_inode->i_mode)) {
3337 + err = dir_unmod_to_mod(dentry);
3339 + /* we copy contents if file is not beeing truncated */
3340 + if(S_ISREG(dentry->d_inode->i_mode) &&
3341 + !(ia->ia_size == 0 && (ia->ia_valid & ATTR_SIZE))) {
3342 + err = nondir_unmod_to_mod(dentry, 1);
3344 + err = nondir_unmod_to_mod(dentry, 0);
3348 + printk(KERN_CRIT "mini_fo_setattr: ERROR changing states.\n");
3352 + if(!exists_in_storage(dentry)) {
3353 + printk(KERN_CRIT "mini_fo_setattr: ERROR, invalid state detected [2].\n");
3357 + ASSERT(dentry->d_inode);
3358 + ASSERT(dtohd2(dentry));
3359 + ASSERT(itopd(dentry->d_inode));
3360 + ASSERT(itohi2(dentry->d_inode));
3362 + err = notify_change(dtohd2(dentry), ia);
3363 + fist_copy_attr_all(dentry->d_inode, itohi2(dentry->d_inode));
3368 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
3370 +mini_fo_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
3373 + dentry_t *hidden_dentry;
3375 + ASSERT(dentry->d_inode);
3376 + ASSERT(itopd(dentry->d_inode));
3378 + if(itohi2(dentry->d_inode)) {
3379 + hidden_dentry = dtohd2(dentry);
3380 + } else if(itohi(dentry->d_inode)) {
3381 + hidden_dentry = dtohd(dentry);
3383 + printk(KERN_CRIT "mini_fo_getattr: ERROR, invalid state detected.\n");
3387 + fist_copy_attr_all(dentry->d_inode, hidden_dentry->d_inode);
3389 + ASSERT(hidden_dentry);
3390 + ASSERT(hidden_dentry->d_inode);
3391 + ASSERT(hidden_dentry->d_inode->i_op);
3393 + generic_fillattr(dentry->d_inode, stat);
3394 + if (!stat->blksize) {
3395 + struct super_block *s = hidden_dentry->d_inode->i_sb;
3397 + blocks = (stat->size+s->s_blocksize-1) >> s->s_blocksize_bits;
3398 + stat->blocks = (s->s_blocksize / 512) * blocks;
3399 + stat->blksize = s->s_blocksize;
3406 +#if defined(XATTR) && (LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,20))
3407 +#if 0 /* no xattr_alloc() and xattr_free() */
3408 +/* This is lifted from fs/xattr.c */
3410 +xattr_alloc(size_t size, size_t limit)
3415 + return ERR_PTR(-E2BIG);
3417 + if (!size) /* size request, no buffer is needed */
3419 + else if (size <= PAGE_SIZE)
3420 + ptr = kmalloc((unsigned long) size, GFP_KERNEL);
3422 + ptr = vmalloc((unsigned long) size);
3424 + return ERR_PTR(-ENOMEM);
3429 +xattr_free(void *ptr, size_t size)
3431 + if (!size) /* size request, no buffer was needed */
3433 + else if (size <= PAGE_SIZE)
3438 +#endif /* no xattr_alloc() and xattr_free() */
3440 +/* BKL held by caller.
3441 + * dentry->d_inode->i_sem down
3444 +mini_fo_getxattr(struct dentry *dentry, const char *name, void *value, size_t size) {
3445 + struct dentry *hidden_dentry = NULL;
3446 + int err = -EOPNOTSUPP;
3447 + /* Define these anyway so we don't need as much ifdef'ed code. */
3448 + char *encoded_name = NULL;
3449 + char *encoded_value = NULL;
3451 + check_mini_fo_dentry(dentry);
3453 + if(exists_in_storage(dentry))
3454 + hidden_dentry = dtohd2(dentry);
3456 + hidden_dentry = dtohd(dentry);
3458 + ASSERT(hidden_dentry);
3459 + ASSERT(hidden_dentry->d_inode);
3460 + ASSERT(hidden_dentry->d_inode->i_op);
3462 + if (hidden_dentry->d_inode->i_op->getxattr) {
3463 + encoded_name = (char *)name;
3464 + encoded_value = (char *)value;
3466 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
3467 + mutex_lock(&hidden_dentry->d_inode->i_mutex);
3469 + down(&hidden_dentry->d_inode->i_sem);
3471 + /* lock_kernel() already done by caller. */
3472 + err = hidden_dentry->d_inode->i_op->getxattr(hidden_dentry, encoded_name, encoded_value, size);
3473 + /* unlock_kernel() will be done by caller. */
3474 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
3475 + mutex_lock(&hidden_dentry->d_inode->i_mutex);
3477 + up(&hidden_dentry->d_inode->i_sem);
3483 +/* BKL held by caller.
3484 + * dentry->d_inode->i_sem down
3487 +#if ((LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,21) \
3488 + && LINUX_VERSION_CODE <= KERNEL_VERSION(2,4,23)) \
3489 + || LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0))
3490 +mini_fo_setxattr(struct dentry *dentry, const char *name,
3491 + const void *value, size_t size, int flags)
3493 +mini_fo_setxattr(struct dentry *dentry, const char *name,
3494 + void *value, size_t size, int flags)