1 diff -urN linux.old/fs/Config.in linux.dev/fs/Config.in
2 --- linux.old/fs/Config.in 2006-10-30 03:44:06.000000000 +0100
3 +++ linux.dev/fs/Config.in 2006-10-30 03:42:09.000000000 +0100
5 dep_mbool ' JFS statistics' CONFIG_JFS_STATISTICS $CONFIG_JFS_FS
7 tristate 'Minix fs support' CONFIG_MINIX_FS
8 +tristate 'mini_fo filesystem overlay' CONFIG_MINI_FO
10 tristate 'FreeVxFS file system support (VERITAS VxFS(TM) compatible)' CONFIG_VXFS_FS
11 tristate 'NTFS file system support (read only)' CONFIG_NTFS_FS
12 diff -urN linux.old/fs/Makefile linux.dev/fs/Makefile
13 --- linux.old/fs/Makefile 2006-10-30 03:44:06.000000000 +0100
14 +++ linux.dev/fs/Makefile 2006-10-30 03:42:09.000000000 +0100
16 subdir-$(CONFIG_CODA_FS) += coda
17 subdir-$(CONFIG_INTERMEZZO_FS) += intermezzo
18 subdir-$(CONFIG_MINIX_FS) += minix
19 +subdir-$(CONFIG_MINI_FO) += mini_fo
20 subdir-$(CONFIG_FAT_FS) += fat
21 subdir-$(CONFIG_UMSDOS_FS) += umsdos
22 subdir-$(CONFIG_MSDOS_FS) += msdos
23 diff -urN linux.old/fs/mini_fo/aux.c linux.dev/fs/mini_fo/aux.c
24 --- linux.old/fs/mini_fo/aux.c 1970-01-01 01:00:00.000000000 +0100
25 +++ linux.dev/fs/mini_fo/aux.c 2006-10-30 03:42:09.000000000 +0100
28 + * Copyright (c) 1997-2003 Erez Zadok
29 + * Copyright (c) 2001-2003 Stony Brook University
31 + * For specific licensing information, see the COPYING file distributed with
32 + * this package, or get one from ftp://ftp.filesystems.org/pub/fist/COPYING.
34 + * This Copyright notice must be kept intact and distributed with all
35 + * fistgen sources INCLUDING sources generated by fistgen.
38 + * Copyright (C) 2004, 2005 Markus Klotzbuecher <mk@creamnet.de>
40 + * This program is free software; you can redistribute it and/or
41 + * modify it under the terms of the GNU General Public License
42 + * as published by the Free Software Foundation; either version
43 + * 2 of the License, or (at your option) any later version.
56 +/* check if file exists in storage */
57 +int exists_in_storage(dentry_t *dentry)
59 + check_mini_fo_dentry(dentry);
60 + if(dtost(dentry) == MODIFIED || dtost(dentry) == CREATED || dtost(dentry) == DEL_REWRITTEN)
65 +/* check if dentry is in an existing state */
66 +int is_mini_fo_existant(dentry_t *dentry)
68 + check_mini_fo_dentry(dentry);
70 + if(dtost(dentry) == DELETED || dtost(dentry) == NON_EXISTANT)
77 + * This function will create a negative storage dentry for
78 + * dentry, what is required for many create like options.
79 + * It will create the storage structure if necessary.
81 +int get_neg_sto_dentry(dentry_t *dentry)
85 + const unsigned char *name;
89 + !(dtost(dentry) == UNMODIFIED ||
90 + dtost(dentry) == NON_EXISTANT ||
91 + dtost(dentry) == DELETED)) {
92 + printk(KERN_CRIT "mini_fo: get_neg_sto_dentry: invalid dentry passed.\n");
96 + /* Have we got a neg. dentry already? */
97 + if(dtohd2(dentry)) {
101 + if(dtost(dentry->d_parent) == UNMODIFIED) {
102 + /* build sto struct */
103 + err = build_sto_structure(dentry->d_parent->d_parent, dentry->d_parent);
105 + dtost(dentry->d_parent) != MODIFIED) {
106 + printk(KERN_CRIT "mini_fo: get_neg_sto_dentry: ERROR building sto structure.\n");
112 + len = dentry->d_name.len;
113 + name = dentry->d_name.name;
116 + lookup_one_len(name, dtohd2(dentry->d_parent), len);
122 +int check_mini_fo_dentry(dentry_t *dentry)
124 + ASSERT(dentry != NULL);
125 + ASSERT(dtopd(dentry) != NULL);
126 + ASSERT((dtohd(dentry) != NULL) || (dtohd2(dentry) != NULL));
128 +/* if(dtost(dentry) == MODIFIED) { */
129 +/* ASSERT(dentry->d_inode != NULL); */
130 +/* ASSERT(dtohd(dentry) != NULL); */
131 +/* ASSERT(dtohd(dentry)->d_inode != NULL); */
132 +/* ASSERT(dtohd2(dentry) != NULL); */
133 +/* ASSERT(dtohd2(dentry)->d_inode != NULL); */
135 +/* else if(dtost(dentry) == UNMODIFIED) { */
136 +/* ASSERT(dentry->d_inode != NULL); */
142 +int check_mini_fo_file(file_t *file)
144 + ASSERT(file != NULL);
145 + ASSERT(ftopd(file) != NULL);
146 + ASSERT(file->f_dentry != NULL);
148 + /* violent checking, check depending of state and type
149 + * if(S_ISDIR(file->f_dentry->d_inode->i_mode)) {}
151 + ASSERT((ftohf(file) != NULL) || (ftohf2(file) != NULL));
155 +int check_mini_fo_inode(inode_t *inode)
157 + ASSERT(inode != NULL);
158 + ASSERT(itopd(inode) != NULL);
159 + ASSERT((itohi(inode) != NULL) || (itohi2(inode) != NULL));
164 + * will walk a base path as provided by get_mini_fo_bpath and return
165 + * the (hopefully ;-) ) positive dentry of the renamed base dir.
167 + * This does some work of path_init.
169 +dentry_t *bpath_walk(super_block_t *sb, char *bpath)
172 + struct nameidata nd;
175 + if(!bpath || bpath[0] != '/') {
176 + printk(KERN_CRIT "mini_fo: bpath_walk: Invalid string.\n");
179 + if(!sb || !stopd(sb)) {
180 + printk(KERN_CRIT "mini_fo: bpath_walk: Invalid sb.\n");
184 + /* setup nd as path_init does */
185 + nd.last_type = LAST_ROOT; /* if there are only slashes... */
186 + nd.flags = LOOKUP_FOLLOW;
187 + /* fix this: how do I reach this lock?
188 + * read_lock(¤t->fs->lock); */
189 + nd.mnt = mntget(stopd(sb)->hidden_mnt);
190 + nd.dentry = dget(stopd(sb)->base_dir_dentry);
191 + /* read_unlock(¤t->fs->lock); */
193 + err = path_walk(bpath+1, &nd);
196 + if (err || !nd.dentry || !nd.dentry->d_inode) {
197 + printk(KERN_CRIT "mini_fo: bpath_walk: path_walk failed.\n");
204 +/* returns the full path of the basefile incl. its name */
205 +int get_mini_fo_bpath(dentry_t *dentry, char **bpath, int *bpath_len)
209 + dentry_t *sky_walker;
211 + if(!dentry || !dtohd(dentry)) {
212 + printk(KERN_CRIT "mini_fo: get_mini_fo_bpath: invalid dentry passed.\n");
215 + sky_walker = dtohd(dentry);
218 + len += sky_walker->d_name.len + 1 ; /* 1 for '/' */
219 + sky_walker = sky_walker->d_parent;
220 + } while(sky_walker != stopd(dentry->d_inode->i_sb)->base_dir_dentry);
222 + /* 1 to oil the loop */
223 + *bpath = (char*) kmalloc(len + 1, GFP_KERNEL);
225 + printk(KERN_CRIT "mini_fo: get_mini_fo_bpath: out of mem.\n");
228 + buf_walker = *bpath+len; /* put it on last char */
229 + *buf_walker = '\n';
230 + sky_walker = dtohd(dentry);
233 + buf_walker -= sky_walker->d_name.len;
234 + strncpy(buf_walker,
235 + sky_walker->d_name.name,
236 + sky_walker->d_name.len);
237 + *(--buf_walker) = '/';
238 + sky_walker = sky_walker->d_parent;
239 + } while(sky_walker != stopd(dentry->d_inode->i_sb)->base_dir_dentry);
241 + /* bpath_len doesn't count newline! */
246 +int mini_fo_cp_cont(dentry_t *tgt_dentry, struct vfsmount *tgt_mnt,
247 + dentry_t *src_dentry, struct vfsmount *src_mnt)
250 + mm_segment_t old_fs;
253 + int bytes, len, tmp, err;
256 + if(!(tgt_dentry->d_inode && src_dentry->d_inode)) {
257 + printk(KERN_CRIT "mini_fo_cp_cont: ERROR, neg. dentry passed.\n");
267 + /* open file write only */
268 + tgt_file = dentry_open(tgt_dentry, tgt_mnt, 0x1);
269 + if(!tgt_file || IS_ERR(tgt_file)) {
270 + printk(KERN_CRIT "mini_fo_cp_cont: ERROR opening target file.\n");
271 + err = PTR_ERR(tgt_file);
275 + /* open file read only */
276 + src_file = dentry_open(src_dentry, src_mnt, 0x0);
277 + if(!src_file || IS_ERR(src_file)) {
278 + printk(KERN_CRIT "mini_fo_cp_cont: ERROR opening source file.\n");
279 + err = PTR_ERR(src_file);
281 + /* close target file */
286 + /* check if the filesystem(s) support read respective write */
287 + if(!src_file->f_op->read || !tgt_file->f_op->write) {
288 + printk(KERN_CRIT "mini_fo_cp_cont: ERROR, no fs read or write support.\n");
293 + /* allocate a page for transfering the data */
294 + buf = (void *) __get_free_page(GFP_KERNEL);
296 + printk(KERN_CRIT "mini_fo_cp_cont: ERROR, out of kernel mem.\n");
300 + tgt_file->f_pos = 0;
301 + src_file->f_pos = 0;
306 + /* Doing this I assume that a read operation will return a full
307 + * buffer while there is still data to read, and a less than
308 + * full buffer when all data has been read.
310 + bytes = len = PAGE_SIZE;
311 + while(bytes == len) {
312 + bytes = src_file->f_op->read(src_file, buf, len,
314 + tmp = tgt_file->f_op->write(tgt_file, buf, bytes,
317 + printk(KERN_CRIT "mini_fo_cp_cont: ERROR writing.\n");
318 + goto out_close_unset;
322 + free_page((unsigned long) buf);
329 + free_page((unsigned long) buf);
340 + /* mk: not sure if this need to be done */
349 + * ndl (no-duplicate list) stuff
350 + * This is used in mini_fo_readdir, to save the storage directory contents
351 + * and later when reading base, match them against the list in order
352 + * to avoid duplicates.
355 +/* add a file specified by name and len to the ndl
356 + * Return values: 0 on success, <0 on failure.
358 +int ndl_add_entry(struct readdir_data *rd, const char *name, int len)
360 + struct ndl_entry *tmp_entry;
362 + tmp_entry = (struct ndl_entry *)
363 + kmalloc(sizeof(struct ndl_entry), GFP_KERNEL);
365 + printk(KERN_CRIT "mini_fo: ndl_add_entry: out of mem.\n");
368 + tmp_entry->name = (char*) kmalloc(len, GFP_KERNEL);
369 + if(!tmp_entry->name) {
370 + printk(KERN_CRIT "mini_fo: ndl_add_entry: out of mem.\n");
373 + strncpy(tmp_entry->name, name, len);
374 + tmp_entry->len = len;
376 + list_add(&tmp_entry->list, &rd->ndl_list);
381 +/* delete all list entries and free memory */
382 +void ndl_put_list(struct readdir_data *rd)
384 + struct list_head *tmp;
385 + struct ndl_entry *tmp_entry;
387 + if(rd->ndl_size <= 0)
389 + while(!list_empty(&rd->ndl_list)) {
390 + tmp = rd->ndl_list.next;
392 + tmp_entry = list_entry(tmp, struct ndl_entry, list);
393 + kfree(tmp_entry->name);
399 +/* Check if a file specified by name and len is in the ndl
400 + * Return value: 0 if not in list, 1 if file is found in ndl.
402 +int ndl_check_entry(struct readdir_data *rd, const char *name, int len)
404 + struct list_head *tmp;
405 + struct ndl_entry *tmp_entry;
407 + if(rd->ndl_size <= 0)
410 + list_for_each(tmp, &rd->ndl_list) {
411 + tmp_entry = list_entry(tmp, struct ndl_entry, list);
412 + if(tmp_entry->len != len)
414 + if(!strncmp(tmp_entry->name, name, len))
421 + * Recursive function to create corresponding directorys in the storage fs.
422 + * The function will build the storage directorys up to dentry.
424 +int build_sto_structure(dentry_t *dir, dentry_t *dentry)
427 + dentry_t *hidden_sto_dentry;
428 + dentry_t *hidden_sto_dir_dentry;
430 + if(dentry->d_parent != dir) {
431 + printk(KERN_CRIT "mini_fo: build_sto_structure: invalid parameter or meta data corruption [1].\n");
435 + if(dtost(dir) != MODIFIED) {
436 + err = build_sto_structure(dir->d_parent, dentry->d_parent);
441 + /* ok, coming back again. */
442 + check_mini_fo_dentry(dentry);
443 + hidden_sto_dentry = dtohd2(dentry);
445 + if(!hidden_sto_dentry) {
447 + * This is the case after creating the first
448 + * hidden_sto_dentry.
449 + * After one negative storage_dentry, all pointers to
450 + * hidden_storage dentries are set to NULL. We need to
451 + * create the negative dentry before we create the storage
455 + const unsigned char *name;
456 + len = dtohd(dentry)->d_name.len;
457 + name = dtohd(dentry)->d_name.name;
458 + hidden_sto_dentry = lookup_one_len(name, dtohd2(dir), len);
459 + dtohd2(dentry) = hidden_sto_dentry;
462 + /* was: hidden_sto_dir_dentry = lock_parent(hidden_sto_dentry); */
463 + hidden_sto_dir_dentry = dget(hidden_sto_dentry->d_parent);
464 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
465 + mutex_lock(&hidden_sto_dir_dentry->d_inode->i_mutex);
467 + down(&hidden_sto_dir_dentry->d_inode->i_sem);
470 + if(dtohd2(dir) != hidden_sto_dir_dentry) {
471 + printk(KERN_CRIT "mini_fo: build_sto_structure: invalid parameter or meta data corruption [2].\n");
475 + /* check for errors in lock_parent */
476 + err = PTR_ERR(hidden_sto_dir_dentry);
477 + if(IS_ERR(hidden_sto_dir_dentry)) {
478 + printk(KERN_CRIT "mini_fo: build_sto_structure: lock_parent failed.\n");
482 + err = vfs_mkdir(hidden_sto_dir_dentry->d_inode,
484 + dir->d_inode->i_mode);
487 + printk(KERN_CRIT "mini_fo: build_sto_structure: failed to create storage dir [1].\n");
488 + /* was: unlock_dir(dir); */
489 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
490 + mutex_unlock(&dir->d_inode->i_mutex);
492 + up(&dir->d_inode->i_sem);
498 + /* everything ok! */
499 + if(!dtohd2(dentry)->d_inode) {
500 + printk(KERN_CRIT "mini_fo: build_sto_structure: failed to create storage dir [2].\n");
501 + /* was: unlock_dir(dir); */
502 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
503 + mutex_unlock(&dir->d_inode->i_mutex);
505 + up(&dir->d_inode->i_sem);
511 + /* interpose the new inode and set new state */
512 + itohi2(dentry->d_inode) = igrab(dtohd2(dentry)->d_inode);
513 + dtopd(dentry)->state = MODIFIED;
515 + /* initalize the wol list */
516 + itopd(dentry->d_inode)->deleted_list_size = -1;
517 + itopd(dentry->d_inode)->renamed_list_size = -1;
518 + meta_build_lists(dentry);
520 + fist_copy_attr_all(dentry->d_inode, itohi2(dentry->d_inode));
521 + fist_copy_attr_timesizes(dir->d_inode,
522 + hidden_sto_dir_dentry->d_inode);
523 + dir->d_inode->i_nlink++;
524 + /* was: unlock_dir(hidden_sto_dir_dentry); */
525 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
526 + mutex_unlock(&hidden_sto_dir_dentry->d_inode->i_mutex);
528 + up(&hidden_sto_dir_dentry->d_inode->i_sem);
530 + dput(hidden_sto_dir_dentry);
538 + * Read "len" bytes from "filename" into "buf".
539 + * "buf" is in kernel space.
542 +mini_fo_read_file(const char *filename, void *buf, int len)
545 + mm_segment_t oldfs;
547 + /* Chroot? Maybe NULL isn't right here */
548 + filp = filp_open(filename, O_RDONLY, 0);
549 + if (!filp || IS_ERR(filp)) {
550 + printk("mini_fo_read_file err %d\n", (int) PTR_ERR(filp));
551 + return -1; /* or do something else */
554 + if (!filp->f_op->read)
555 + return -2; /* file(system) doesn't allow reads */
557 + /* now read len bytes from offset 0 */
558 + filp->f_pos = 0; /* start offset */
561 + bytes = filp->f_op->read(filp, buf, len, &filp->f_pos);
564 + /* close the file */
573 + * Write "len" bytes from "buf" to "filename"
574 + * "buf" is in kernel space.
577 +mini_fo_write_file(const char *filename, void *buf, int len)
580 + mm_segment_t oldfs;
582 + /* Chroot? Maybe NULL isn't right here */
583 + filp = filp_open(filename, O_RDWR|O_CREAT, 0640);
584 + if (!filp || IS_ERR(filp)) {
585 + printk("mini_fo_write_file err %d\n", (int) PTR_ERR(filp));
586 + return -1; /* or do something else */
589 + if (!filp->f_op->write)
590 + return -2; /* file(system) doesn't allow writes */
592 + /* now write len bytes from offset 0 */
593 + filp->f_pos = 0; /* start offset */
596 + bytes = filp->f_op->write(filp, buf, len, &filp->f_pos);
599 + /* close the file */
607 diff -urN linux.old/fs/mini_fo/ChangeLog linux.dev/fs/mini_fo/ChangeLog
608 --- linux.old/fs/mini_fo/ChangeLog 1970-01-01 01:00:00.000000000 +0100
609 +++ linux.dev/fs/mini_fo/ChangeLog 2006-10-30 03:42:09.000000000 +0100
611 +2006-01-24 Markus Klotzbuecher <mk@mary.denx.de>
613 + * Add tons of ugly ifdefs to Ed L. Cashin's mutex patch to
614 + retain backwards compatibility.
616 +2006-01-24 Ed L. Cashin <ecashin@coraid.com>
618 + * Support for the new mutex infrastructure
619 + (7892f2f48d165a34b0b8130c8a195dfd807b8cb6)
621 +2005-10-15 Markus Klotzbuecher <mk@localhost.localdomain>
623 + * Bugfix for a serious memory leak in mini_fo_follow_link.
625 +2005-09-21 Markus Klotzbuecher <mk@mary>
627 + * new release 0.6.1
629 + * fix of a compiler warning due to changes in 2.6.13
631 +2005-09-21 Klaus Wenninger <klaus.wenninger@siemens.com>
633 + * file.c: readdir: fix for a bug that caused directory entries
634 + to show up twice when using storage filesystems such as
637 +2005-06-30 Eric Lammerts <eric@lammerts.org>
639 + * fix for an oops when overwriting a binary thats beeing
642 +2005-06-09 <mk@mary>
644 + * Renamed overlay to mini_fo-overlay.
646 + * Added mini_fo-merge script to allow merging of storage and base
647 + after making modifications.
649 +2005-05-22 root <mk@mary>
651 + * Added overlay script that allows to easily mount mini_fo ontop
652 + of a given base directory
654 +2005-05-10 <mk@mary>
656 + * inode.c: xattr functions return -EOPNOSUPP instead of
657 + -ENOSUPP, what confuses "ls -l"
659 + * Changed license from LGPL to GPL.
661 +2005-05-08 root <mk@mary>
663 + * Makefile: clean it up and added make install and make
666 +2005-05-06 <mk@mary>
668 + * merged devel branch back to main. [v0-6-0-pre3]
670 + * removed unused files print.c and fist_ioctl. [devel-0-0-18]
672 + * ioctl: removed fist_ioctl stuff, that is not needed for
675 +2005-05-03 <mk@mary>
677 + * file.c: simplified mini_fo_open and mini_fo_setattr using
678 + new state changing functions. [devel-0-0-17]
680 + * inode.c: Fixed getattr state bug (see below) in 2.4 function
681 + mini_fo_inode revalidate.
683 + * inode.c: found an other bug in mini_fo_getattr. States are not
684 + reliable in this function, as a file can be opened, unlinked and
685 + the getattr function called. This results in a deleted dentry
686 + with an inode. Fix is to ignore states and simply use the inode
689 +2005-04-29 <mk@mary>
691 + * file.c: Bugfix and cleanup in fasync and fsync. [devel-0-0-16]
693 + * file.c: do not use mini_fo_lock so the generic version is
696 + * inode.c: getattr, never call getattr on lower files, as this
697 + will cause the inum to change.
699 + * inode.c: rename_reg_file renamed to rename_nondir, as it
700 + doesn't matter as long it't not a dir. Removed all
701 + rename_dev_file etc.
703 + * tagged as devel-0-0-15
705 + * inode.c: added support for chosing support for extended
706 + attrs at compile time by XATTR define in mini_fo.h .
708 + * inode.c: fixed mini_fo_getattr to use mini_fo inode and not
709 + lower again, what avoids inode number changes that confused
710 + rm again. This is the proper solution.
712 +2005-04-24 <mk@mary>
714 + * all files: updated Copyright notive to 2005. [devel-0-0-14]
716 + * inode.c: fixed mini_fo_getattr to not change the inode
717 + number, even if lower files change.
719 + * super.c: fixed a bug that caused deleted base file to show
720 + up suddenly after some time, or after creating a special
721 + file. The problem was that after some time or after special
722 + file creating sync_sb_inodes is called by the vfs, that
723 + called our mini_fo_put_inode. There was (wrongly) called
724 + __meta_put_lists, that nuked the lists, although the inode
725 + was going to continue its life. Moving __meta_put_lists to
726 + mini_fo_clear_inode, where an inode is really destroyed,
727 + solved the problem.
730 +2005-04-23 <mk@mary>
732 + * state.c, aux.c: more cleaning up and
733 + simplifications. [devel-0-0-13]
735 + * inode.c: implemented mini_fo_getattr, that was required for
736 + 2.6 because inode_revalidate has been remove there, and the
737 + old "du" bug returned.
740 +2005-04-20 <mk@mary>
742 + * aux.c: get_neg_sto_dentry(): allow to be called for dentries
743 + in state UNMODIFIED, NON_EXISTANT _and_ DELETED.
745 +2005-04-19 <mk@mary>
747 + * Fixed a bug under 2.6 that caused files deleted via mini_fo
748 + not to be deleted properly and therefore the fs filled up
749 + untill no memory was left. [devel-0-0-12]
751 + * Added basic hard link support. This means that creating
752 + hardlinks will work, but existing ones will be treated as
753 + individual files. [devel-0-0-11]
755 +2005-04-17 <mk@mary>
759 +2005-04-13 root <mk@mary>
761 + * Added file state.c for the state transition
762 + functions. Doesn't work very well yet, though...
764 +2005-04-12 <mk@mary>
766 + * Porting to 2.6 started, which is easier than expected, also
767 + due to Olivier previous work.
769 +2005-04-08 <mk@mary>
771 + * Fixed the bug that caused du to return invalid sizes of
772 + directory trees. The problem was that
773 + mini_fo_inode_revalidate didn't always copy the attributes
774 + from the base inode properly.
776 +2005-04-01 Markus Klotzbuecher <mk@chasey>
778 + * Merged devel branch back to main trunk and updated the
779 + RELEASE notes. This will be 0-6-0-pre1.
781 +2005-03-31 Markus Klotzbuecher <mk@chasey>
783 + * Fixed some bugs in rename_reg_file, that only showed up in
784 + the kernel compile test. Kernel compiles cleanly ontop of
785 + mini_fo, now also make mrproper etc. work. Seems pretty stable.
787 +2005-03-28 Markus Klotzbuecher <mk@chasey>
789 + * Many, many directory renaming bugfixes and a lot of other
790 + cleanup. Dir renaming seems to work relatively stable.
792 +2005-03-22 Markus Klotzbuecher <mk@chasey>
794 + * Finished implementing lightweight directory renaming. Some
795 + basic testing indicates it works fine.
796 + Next is to implement testcases for the testsuite and confirm
797 + everything is really working ok.
799 +2005-03-18 Markus Klotzbuecher <mk@chasey>
801 + * Finished implementing meta.c stuff required for directory
804 +2005-03-17 Markus Klotzbuecher <mk@chasey>
806 + * Fixed all compile warnings + an extremly old bug that
807 + somehow crept in while reworking the wol stuff to the META
808 + system. Turning on -Werror again... :-)
810 + * Fixed some bugs in the new rename_reg_file function.
812 + * Rewrote mini_fo rename and split it into several
813 + subfunctions, that handle the different types
814 + seperately. Rewrote the regular file function aswell, as it
815 + was implemented somewhat inefficient.
817 +2005-03-16 Markus Klotzbuecher <mk@chasey>
819 + * Implemented new META subsystem, removed old WOL stuff in favor
822 + * After some basic testing everything seems ok...
824 +2005-03-11 Markus Klotzbuecher <mk@chasey>
826 + * Renaming a non regular file caused trouble because I always
827 + tried to copy the contents. Now I only do this for regular
828 + files. mini_fo_rename still isn't implemented properly, renaming
829 + of device files, symlinks etc. results in a empty regular file
830 + instead of the proper type.
832 + * Directory renaming suddenly works! What a surprise! I guess
833 + this is because renaming is implemented as making a copy and
834 + removing the original. Still this might not work
837 +2005-03-09 Markus Klotzbuecher <mk@chasey>
839 + * Bugfix, when a mini_fo directory that exists in storage
840 + (state: MODIFIED, CREATED and DEL_REWRITTEN) is deleted, a
841 + possibly existing WOL file contained in it needs to be
844 + * Starting cleanup: defined state names in order to get rid of
847 +2005-03-08 Markus Klotzbuecher <mk@chasey>
849 + * Makefile fix, fist_ioctl was built against wrong sources if ARCH=um
851 + * Fixed a bug in dentry.c, mini_fo_d_hash. In state 4 =
852 + DEL_REWRITTEN the hash was calculated from the base dentry,
853 + which was wrong and and caused assertions in
854 + __mini_fo_hidden_dentry to fail.
856 +2005-02-21 <mk@mary>
858 + * Implemented directory deleting (inode.c)
860 + * main.c: made mini_fo_parse_options a little more robust.
862 +2004-12-22 <mk@mary>
864 + * Makefile cleanup and uml stuff, removed unneccessary files
866 + * Created a new and hopefully more informative README
868 + * CHANGELOG: created a new CHANGELOG and added old entries reversely
871 +2004-10-24 Gleb Natapov <gleb@nbase.co.il>
873 + * Fix: owner and group where not correctly copied from base to
877 +2004-10-05 Gleb Natapov <gleb@nbase.co.il>
879 + * Implementation of fsync, fasync and lock mini_fo functions.
882 +2004-09-29 Bob Lee <bob@pantasys.com>
884 + * Fix of a serious pointer bug
887 +2004-09-28 Gleb Natapov <gleb@nbase.co.il>
889 + * Implementation of mini_fo_mknod and mini_fo_rename, support
892 diff -urN linux.old/fs/mini_fo/dentry.c linux.dev/fs/mini_fo/dentry.c
893 --- linux.old/fs/mini_fo/dentry.c 1970-01-01 01:00:00.000000000 +0100
894 +++ linux.dev/fs/mini_fo/dentry.c 2006-10-30 03:42:09.000000000 +0100
897 + * Copyright (c) 1997-2003 Erez Zadok
898 + * Copyright (c) 2001-2003 Stony Brook University
900 + * For specific licensing information, see the COPYING file distributed with
901 + * this package, or get one from ftp://ftp.filesystems.org/pub/fist/COPYING.
903 + * This Copyright notice must be kept intact and distributed with all
904 + * fistgen sources INCLUDING sources generated by fistgen.
907 + * Copyright (C) 2004, 2005 Markus Klotzbuecher <mk@creamnet.de>
909 + * This program is free software; you can redistribute it and/or
910 + * modify it under the terms of the GNU General Public License
911 + * as published by the Free Software Foundation; either version
912 + * 2 of the License, or (at your option) any later version.
919 +#ifdef HAVE_CONFIG_H
920 +# include <config.h>
924 +#include "mini_fo.h"
927 + * THIS IS A BOOLEAN FUNCTION: returns 1 if valid, 0 otherwise.
930 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
931 +mini_fo_d_revalidate(dentry_t *dentry, struct nameidata *nd)
933 +mini_fo_d_revalidate(dentry_t *dentry, int flags)
936 + int err1 = 1; /* valid = 1, invalid = 0 */
938 + dentry_t *hidden_dentry;
939 + dentry_t *hidden_sto_dentry;
942 + check_mini_fo_dentry(dentry);
944 + hidden_dentry = dtohd(dentry);
945 + hidden_sto_dentry = dtohd2(dentry);
947 + if(hidden_dentry &&
948 + hidden_dentry->d_op &&
949 + hidden_dentry->d_op->d_revalidate) {
950 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
951 + err1 = hidden_dentry->d_op->d_revalidate(hidden_dentry, nd);
953 + err1 = hidden_dentry->d_op->d_revalidate(hidden_dentry, flags);
956 + if(hidden_sto_dentry &&
957 + hidden_sto_dentry->d_op &&
958 + hidden_sto_dentry->d_op->d_revalidate) {
959 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
960 + err2 = hidden_sto_dentry->d_op->d_revalidate(hidden_sto_dentry,
963 + err2 = hidden_sto_dentry->d_op->d_revalidate(hidden_sto_dentry,
968 + /* mk: if one of the lower level dentries are valid,
969 + * the mini_fo dentry is too.
971 + return (err1 || err2);
976 +mini_fo_d_hash(dentry_t *dentry, qstr_t *name)
979 + dentry_t *hidden_dentry;
980 + dentry_t *hidden_sto_dentry;
982 + /* hidden_dentry = mini_fo_hidden_dentry(dentry);
983 + * hidden_sto_dentry = mini_fo_hidden_sto_dentry(dentry); */
985 + /* state 1, 3, 4, 5: build the hash for the storage dentry */
986 + if((dtopd(dentry)->state == MODIFIED) ||
987 + (dtopd(dentry)->state == CREATED) ||
988 + (dtopd(dentry)->state == DEL_REWRITTEN) ||
989 + (dtopd(dentry)->state == DELETED)) {
990 + hidden_sto_dentry = dtohd2(dentry);
991 + if(hidden_sto_dentry &&
992 + hidden_sto_dentry->d_op &&
993 + hidden_sto_dentry->d_op->d_hash) {
994 + err = hidden_sto_dentry->d_op->d_hash(hidden_sto_dentry, name);
998 + /* state 2: build the hash for the base dentry */
999 + if(dtopd(dentry)->state == UNMODIFIED) {
1000 + hidden_dentry = dtohd(dentry);
1001 + if(hidden_dentry &&
1002 + hidden_dentry->d_op &&
1003 + hidden_dentry->d_op->d_hash) {
1004 + err = hidden_dentry->d_op->d_hash(hidden_dentry, name);
1008 + /* state 6: build hash for the dentry that exists */
1009 + if(dtopd(dentry)->state == NON_EXISTANT) {
1010 + hidden_sto_dentry = dtohd2(dentry);
1011 + if(hidden_sto_dentry &&
1012 + hidden_sto_dentry->d_op &&
1013 + hidden_sto_dentry->d_op->d_hash) {
1014 + err = hidden_sto_dentry->d_op->d_hash(hidden_sto_dentry, name);
1017 + hidden_dentry = dtohd(dentry);
1018 + if(hidden_dentry &&
1019 + hidden_dentry->d_op &&
1020 + hidden_dentry->d_op->d_hash) {
1021 + err = hidden_dentry->d_op->d_hash(hidden_dentry, name);
1026 + printk(KERN_CRIT "mini_fo: d_hash: invalid state detected.\n");
1034 +mini_fo_d_compare(dentry_t *dentry, qstr_t *a, qstr_t *b)
1037 + dentry_t *hidden_dentry=NULL;
1039 + /* hidden_dentry = mini_fo_hidden_dentry(dentry); */
1040 + if(dtohd2(dentry))
1041 + hidden_dentry = dtohd2(dentry);
1042 + else if(dtohd(dentry))
1043 + hidden_dentry = dtohd(dentry);
1045 + if (hidden_dentry && hidden_dentry->d_op && hidden_dentry->d_op->d_compare) {
1046 + err = hidden_dentry->d_op->d_compare(hidden_dentry, a, b);
1048 + err = ((a->len != b->len) || memcmp(a->name, b->name, b->len));
1056 +mini_fo_d_delete(dentry_t *dentry)
1058 + dentry_t *hidden_dentry;
1059 + dentry_t *hidden_sto_dentry;
1062 + /* this could be a negative dentry, so check first */
1063 + if (!dtopd(dentry)) {
1064 + printk(KERN_CRIT "mini_fo_d_delete: negative dentry passed.\n");
1067 + hidden_dentry = dtohd(dentry);
1068 + hidden_sto_dentry = dtohd2(dentry);
1070 + if(hidden_dentry) {
1071 + if(hidden_dentry->d_op &&
1072 + hidden_dentry->d_op->d_delete) {
1073 + err = hidden_dentry->d_op->d_delete(hidden_dentry);
1076 + if(hidden_sto_dentry) {
1077 + if(hidden_sto_dentry->d_op &&
1078 + hidden_sto_dentry->d_op->d_delete) {
1079 + err = hidden_sto_dentry->d_op->d_delete(hidden_sto_dentry);
1089 +mini_fo_d_release(dentry_t *dentry)
1091 + dentry_t *hidden_dentry;
1092 + dentry_t *hidden_sto_dentry;
1095 + /* this could be a negative dentry, so check first */
1096 + if (!dtopd(dentry)) {
1097 + printk(KERN_CRIT "mini_fo_d_release: no private data.\n");
1100 + hidden_dentry = dtohd(dentry);
1101 + hidden_sto_dentry = dtohd2(dentry);
1103 + if(hidden_dentry) {
1104 + /* decrement hidden dentry's counter and free its inode */
1105 + dput(hidden_dentry);
1107 + if(hidden_sto_dentry) {
1108 + /* decrement hidden dentry's counter and free its inode */
1109 + dput(hidden_sto_dentry);
1112 + /* free private data (mini_fo_dentry_info) here */
1113 + kfree(dtopd(dentry));
1114 + __dtopd(dentry) = NULL; /* just to be safe */
1121 + * we don't really need mini_fo_d_iput, because dentry_iput will call iput() if
1122 + * mini_fo_d_iput is not defined. We left this implemented for ease of
1123 + * tracing/debugging.
1126 +mini_fo_d_iput(dentry_t *dentry, inode_t *inode)
1132 +struct dentry_operations mini_fo_dops = {
1133 + d_revalidate: mini_fo_d_revalidate,
1134 + d_hash: mini_fo_d_hash,
1135 + d_compare: mini_fo_d_compare,
1136 + d_release: mini_fo_d_release,
1137 + d_delete: mini_fo_d_delete,
1138 + d_iput: mini_fo_d_iput,
1140 diff -urN linux.old/fs/mini_fo/file.c linux.dev/fs/mini_fo/file.c
1141 --- linux.old/fs/mini_fo/file.c 1970-01-01 01:00:00.000000000 +0100
1142 +++ linux.dev/fs/mini_fo/file.c 2006-10-30 03:42:09.000000000 +0100
1145 + * Copyright (c) 1997-2003 Erez Zadok
1146 + * Copyright (c) 2001-2003 Stony Brook University
1148 + * For specific licensing information, see the COPYING file distributed with
1149 + * this package, or get one from ftp://ftp.filesystems.org/pub/fist/COPYING.
1151 + * This Copyright notice must be kept intact and distributed with all
1152 + * fistgen sources INCLUDING sources generated by fistgen.
1155 + * Copyright (C) 2004, 2005 Markus Klotzbuecher <mk@creamnet.de>
1157 + * This program is free software; you can redistribute it and/or
1158 + * modify it under the terms of the GNU General Public License
1159 + * as published by the Free Software Foundation; either version
1160 + * 2 of the License, or (at your option) any later version.
1167 +#ifdef HAVE_CONFIG_H
1168 +# include <config.h>
1172 +#include "mini_fo.h"
1173 +#define ROUND_UP(x) (((x)+sizeof(long)-1) & ~(sizeof(long)-1))
1175 +/*******************
1176 + * File Operations *
1177 + *******************/
1180 +mini_fo_llseek(file_t *file, loff_t offset, int origin)
1183 + file_t *hidden_file = NULL;
1185 + if(S_ISDIR(file->f_dentry->d_inode->i_mode)) {
1186 + /* Check if trying to llseek from a directory */
1190 + if (ftopd(file) != NULL) {
1191 + if(ftohf2(file)) {
1192 + hidden_file = ftohf2(file);
1194 + hidden_file = ftohf(file);
1198 + /* always set hidden position to this one */
1199 + hidden_file->f_pos = file->f_pos;
1201 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
1202 + memcpy(&(hidden_file->f_ra),
1204 + sizeof(struct file_ra_state));
1206 + if (file->f_reada) { /* update readahead information if needed */
1207 + hidden_file->f_reada = file->f_reada;
1208 + hidden_file->f_ramax = file->f_ramax;
1209 + hidden_file->f_raend = file->f_raend;
1210 + hidden_file->f_ralen = file->f_ralen;
1211 + hidden_file->f_rawin = file->f_rawin;
1214 + if (hidden_file->f_op && hidden_file->f_op->llseek)
1215 + err = hidden_file->f_op->llseek(hidden_file, offset, origin);
1217 + err = generic_file_llseek(hidden_file, offset, origin);
1222 + if (err != file->f_pos) {
1223 + file->f_pos = err;
1224 + // ION maybe this?
1225 + // file->f_pos = hidden_file->f_pos;
1226 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
1227 + file->f_reada = 0;
1229 + file->f_version++;
1237 +/* mk: fanout capable */
1239 +mini_fo_read(file_t *file, char *buf, size_t count, loff_t *ppos)
1241 + int err = -EINVAL;
1242 + file_t *hidden_file = NULL;
1243 + loff_t pos = *ppos;
1245 + if(S_ISDIR(file->f_dentry->d_inode->i_mode)) {
1246 + /* Check if trying to read from a directory */
1247 + /* printk(KERN_CRIT "mini_fo_read: ERROR: trying to read data from a directory.\n"); */
1252 + if (ftopd(file) != NULL) {
1253 + if(ftohf2(file)) {
1254 + hidden_file = ftohf2(file);
1256 + hidden_file = ftohf(file);
1260 + if (!hidden_file->f_op || !hidden_file->f_op->read)
1263 + err = hidden_file->f_op->read(hidden_file, buf, count, &pos);
1267 + /* atime should also be updated for reads of size zero or more */
1268 + fist_copy_attr_atime(file->f_dentry->d_inode,
1269 + hidden_file->f_dentry->d_inode);
1272 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
1275 + * because pread() does not have any way to tell us that it is
1276 + * our caller, then we don't know for sure if we have to update
1277 + * the file positions. This hack relies on read() having passed us
1278 + * the "real" pointer of its struct file's f_pos field.
1280 + if (ppos == &file->f_pos)
1281 + hidden_file->f_pos = *ppos = pos;
1282 + if (hidden_file->f_reada) { /* update readahead information if needed */
1283 + file->f_reada = hidden_file->f_reada;
1284 + file->f_ramax = hidden_file->f_ramax;
1285 + file->f_raend = hidden_file->f_raend;
1286 + file->f_ralen = hidden_file->f_ralen;
1287 + file->f_rawin = hidden_file->f_rawin;
1290 + memcpy(&(file->f_ra),&(hidden_file->f_ra),sizeof(struct file_ra_state));
1298 +/* this mini_fo_write() does not modify data pages! */
1300 +mini_fo_write(file_t *file, const char *buf, size_t count, loff_t *ppos)
1302 + int err = -EINVAL;
1303 + file_t *hidden_file = NULL;
1305 + inode_t *hidden_inode;
1306 + loff_t pos = *ppos;
1308 + /* mk: fan out: */
1309 + if (ftopd(file) != NULL) {
1310 + if(ftohf2(file)) {
1311 + hidden_file = ftohf2(file);
1313 + /* This is bad! We have no storage file to write to. This
1314 + * should never happen because if a file is opened for
1315 + * writing, a copy should have been made earlier.
1317 + printk(KERN_CRIT "mini_fo: write : ERROR, no storage file to write.\n");
1323 + inode = file->f_dentry->d_inode;
1324 + hidden_inode = itohi2(inode);
1325 + if(!hidden_inode) {
1326 + printk(KERN_CRIT "mini_fo: write: no sto inode found, not good.\n");
1330 + if (!hidden_file->f_op || !hidden_file->f_op->write)
1333 + /* adjust for append -- seek to the end of the file */
1334 + if (file->f_flags & O_APPEND)
1335 + pos = inode->i_size;
1337 + err = hidden_file->f_op->write(hidden_file, buf, count, &pos);
1340 + * copy ctime and mtime from lower layer attributes
1341 + * atime is unchanged for both layers
1344 + fist_copy_attr_times(inode, hidden_inode);
1347 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
1351 + * because pwrite() does not have any way to tell us that it is
1352 + * our caller, then we don't know for sure if we have to update
1353 + * the file positions. This hack relies on write() having passed us
1354 + * the "real" pointer of its struct file's f_pos field.
1356 + if (ppos == &file->f_pos)
1357 + hidden_file->f_pos = *ppos = pos;
1359 + /* update this inode's size */
1360 + if (pos > inode->i_size)
1361 + inode->i_size = pos;
1367 +/* Global variable to hold a file_t pointer.
1368 + * This serves to allow mini_fo_filldir function to know which file is
1369 + * beeing read, which is required for two reasons:
1371 + * - be able to call wol functions in order to avoid listing deleted
1373 + * - if we're reading a directory which is in state 1, we need to
1374 + * maintain a list (in mini_fo_filldir) of which files allready
1375 + * have been copied to userspace,to detect files existing in base
1376 + * and storage and not list them twice.
1378 +filldir_t mini_fo_filldir_orig;
1379 +file_t *mini_fo_filldir_file;
1381 +/* mainly copied from fs/readdir.c */
1383 +mini_fo_filldir(void * __buf, const char * name, int namlen, loff_t offset,
1384 + ino_t ino, unsigned int d_type)
1386 + struct linux_dirent *dirent, d;
1387 + struct getdents_callback * buf = (struct getdents_callback *) __buf;
1389 + file_t* file = mini_fo_filldir_file;
1391 + /* In theses states we filter meta files in storage (WOL) */
1392 + if(file && (dtopd(file->f_dentry)->state == MODIFIED ||
1393 + dtopd(file->f_dentry)->state == CREATED ||
1394 + dtopd(file->f_dentry)->state == DEL_REWRITTEN)) {
1396 + int tmp = strlen(META_FILENAME);
1397 + if(tmp == namlen) {
1398 + if(!strncmp(name, META_FILENAME, namlen))
1403 + /* check if we are merging the contents of storage and base */
1404 + if(file && dtopd(file->f_dentry)->state == MODIFIED) {
1405 + /* check if we are still reading storage contents, if
1406 + * yes, we just save the name of the file for duplicate
1407 + * checking later. */
1409 + if(!ftopd(file)->rd.sto_done) {
1410 + /* put file into ndl list */
1411 + if(ndl_add_entry(&ftopd(file)->rd, name, namlen))
1412 + printk(KERN_CRIT "mini_fo_filldir: Error adding to ndl.\n");
1414 + /* check if file has been deleted */
1415 + if(meta_check_d_entry(file->f_dentry, name, namlen))
1418 + /* do duplicate checking */
1419 + if(ndl_check_entry(&ftopd(file)->rd, name, namlen))
1424 + return mini_fo_filldir_orig(buf, name, namlen, offset, ino, d_type);
1429 +mini_fo_readdir(file_t *file, void *dirent, filldir_t filldir)
1431 + int err = 0;/* mk: ??? -ENOTDIR; */
1432 + file_t *hidden_file = NULL;
1433 + file_t *hidden_sto_file = NULL;
1435 + struct getdents_callback *buf;
1438 +#if defined(FIST_FILTER_NAME) || defined(FIST_FILTER_SCA)
1439 + struct mini_fo_getdents_callback buf;
1440 +#endif /* FIST_FILTER_NAME || FIST_FILTER_SCA */
1442 + buf = (struct getdents_callback *) dirent;
1443 + oldcount = buf->count;
1444 + inode = file->f_dentry->d_inode;
1445 + mini_fo_filldir_file = file;
1446 + mini_fo_filldir_orig = filldir;
1448 + ftopd(file)->rd.sto_done = 0;
1450 + if (ftopd(file) != NULL) {
1451 + if(ftohf2(file)) {
1452 + hidden_sto_file = ftohf2(file);
1453 + err = vfs_readdir(hidden_sto_file, mini_fo_filldir, dirent);
1454 + file->f_pos = hidden_sto_file->f_pos;
1456 + fist_copy_attr_atime(inode, hidden_sto_file->f_dentry->d_inode);
1457 + /* not finshed yet, we'll be called again */
1458 + if (buf->count != oldcount)
1462 + ftopd(file)->rd.sto_done = 1;
1465 + hidden_file = ftohf(file);
1466 + err = vfs_readdir(hidden_file, mini_fo_filldir, dirent);
1467 + file->f_pos = hidden_file->f_pos;
1469 + fist_copy_attr_atime(inode, hidden_file->f_dentry->d_inode);
1476 + * we need to check if all the directory data has been copied to userspace,
1477 + * or if we will be called again by userspace to complete the operation.
1479 + if(buf->count == oldcount) {
1480 + ndl_put_list(&ftopd(file)->rd);
1483 + /* unset this, safe */
1484 + mini_fo_filldir_file = NULL;
1489 +STATIC unsigned int
1490 +mini_fo_poll(file_t *file, poll_table *wait)
1492 + unsigned int mask = DEFAULT_POLLMASK;
1493 + file_t *hidden_file = NULL;
1495 + if (ftopd(file) != NULL) {
1496 + if(ftohf2(file)) {
1497 + hidden_file = ftohf2(file);
1499 + hidden_file = ftohf(file);
1503 + if (!hidden_file->f_op || !hidden_file->f_op->poll)
1506 + mask = hidden_file->f_op->poll(hidden_file, wait);
1512 +/* FIST-LITE special version of mmap */
1514 +mini_fo_mmap(file_t *file, vm_area_t *vma)
1517 + file_t *hidden_file = NULL;
1519 + /* fanout capability */
1520 + if (ftopd(file) != NULL) {
1521 + if(ftohf2(file)) {
1522 + hidden_file = ftohf2(file);
1524 + hidden_file = ftohf(file);
1528 + ASSERT(hidden_file != NULL);
1529 + ASSERT(hidden_file->f_op != NULL);
1530 + ASSERT(hidden_file->f_op->mmap != NULL);
1532 + vma->vm_file = hidden_file;
1533 + err = hidden_file->f_op->mmap(hidden_file, vma);
1534 + get_file(hidden_file); /* make sure it doesn't get freed on us */
1535 + fput(file); /* no need to keep extra ref on ours */
1543 +mini_fo_open(inode_t *inode, file_t *file)
1547 + file_t *hidden_file = NULL;
1548 + dentry_t *hidden_dentry = NULL;
1550 + /* fanout stuff */
1551 + file_t *hidden_sto_file = NULL;
1552 + dentry_t *hidden_sto_dentry = NULL;
1555 + kmalloc(sizeof(struct mini_fo_file_info), GFP_KERNEL);
1556 + if (!ftopd(file)) {
1561 + /* init the readdir_helper structure */
1562 + INIT_LIST_HEAD(&ftopd(file)->rd.ndl_list);
1563 + ftopd(file)->rd.ndl_size = 0;
1565 + /* In certain paths this could stay uninitalized and cause trouble */
1566 + ftohf(file) = NULL;
1567 + ftohf2(file) = NULL;
1568 + hidden_flags = file->f_flags;
1570 + /* create storage files? */
1571 + if(dtost(file->f_dentry) == UNMODIFIED) {
1572 + if(!IS_WRITE_FLAG(file->f_flags)) {
1573 + hidden_dentry = dtohd(file->f_dentry);
1574 + dget(hidden_dentry);
1575 + /* dentry_open will decrement mnt refcnt if err.
1576 + * otherwise fput() will do an mntput() for us upon file close. */
1577 + mntget(stopd(inode->i_sb)->hidden_mnt);
1578 + hidden_file = dentry_open(hidden_dentry,
1579 + stopd(inode->i_sb)->hidden_mnt,
1581 + if (IS_ERR(hidden_file)) {
1582 + err = PTR_ERR(hidden_file);
1583 + dput(hidden_dentry);
1586 + ftohf(file) = hidden_file; /* link two files */
1590 + if(S_ISDIR(file->f_dentry->d_inode->i_mode)) {
1591 + err = dir_unmod_to_mod(file->f_dentry);
1593 + err = nondir_unmod_to_mod(file->f_dentry, 1);
1596 + printk("mini_fo_open: ERROR creating storage file.\n");
1601 + hidden_sto_dentry = dtohd2(file->f_dentry);
1602 + dget(hidden_sto_dentry);
1604 + if(dtopd(file->f_dentry)->state == MODIFIED) {
1605 + /* Directorys are special, interpose on both lower level files */
1606 + if(S_ISDIR(itohi(inode)->i_mode)) {
1607 + /* check for invalid file types of lower level files */
1608 + if(!(S_ISDIR(itohi(inode)->i_mode) && S_ISDIR(itohi2(inode)->i_mode))) {
1609 + printk(KERN_CRIT "mini_fo_open: meta data corruption detected.\n");
1610 + dput(hidden_sto_dentry);
1615 + /* lower level directorys are ok, open the base file */
1616 + hidden_dentry = dtohd(file->f_dentry);
1617 + dget(hidden_dentry);
1619 + mntget(stopd(inode->i_sb)->hidden_mnt);
1620 + hidden_file = dentry_open(hidden_dentry,
1621 + stopd(inode->i_sb)->hidden_mnt,
1623 + if (IS_ERR(hidden_file)) {
1624 + err = PTR_ERR(hidden_file);
1625 + dput(hidden_dentry);
1626 + dput(hidden_sto_dentry);
1629 + ftohf(file) = hidden_file; /* link the two files */
1633 + if(!exists_in_storage(file->f_dentry)) {
1634 + printk(KERN_CRIT "mini_fo_open: invalid file state detected.\n");
1636 + dput(hidden_sto_dentry);
1638 + /* If the base file has been opened, we need to close it here */
1640 + if (hidden_file->f_op && hidden_file->f_op->flush)
1641 + hidden_file->f_op->flush(hidden_file);
1642 + dput(hidden_dentry);
1647 + /* ok, now we can safely open the storage file */
1648 + mntget(stopd(inode->i_sb)->hidden_mnt2);
1649 + hidden_sto_file = dentry_open(hidden_sto_dentry,
1650 + stopd(inode->i_sb)->hidden_mnt2,
1653 + /* dentry_open dputs the dentry if it fails */
1654 + if (IS_ERR(hidden_sto_file)) {
1655 + err = PTR_ERR(hidden_sto_file);
1656 + /* close base file if open */
1658 + if (hidden_file->f_op && hidden_file->f_op->flush)
1659 + hidden_file->f_op->flush(hidden_file);
1660 + dput(hidden_dentry);
1664 + ftohf2(file) = hidden_sto_file; /* link storage file */
1667 + if (err < 0 && ftopd(file)) {
1668 + kfree(ftopd(file));
1674 +mini_fo_flush(file_t *file)
1676 + int err1 = 0; /* assume ok (see open.c:close_fp) */
1678 + file_t *hidden_file = NULL;
1680 + check_mini_fo_file(file);
1682 + /* mk: we don't do any state checking here, as its not worth the time.
1683 + * Just flush the lower level files if they exist.
1685 + if(ftopd(file) != NULL) {
1686 + if(ftohf(file) != NULL) {
1687 + hidden_file = ftohf(file);
1688 + if (hidden_file->f_op && hidden_file->f_op->flush)
1689 + err1 = hidden_file->f_op->flush(hidden_file);
1691 + if(ftohf2(file) != NULL) {
1692 + hidden_file = ftohf2(file);
1693 + if (hidden_file->f_op && hidden_file->f_op->flush)
1694 + err2 = hidden_file->f_op->flush(hidden_file);
1697 + return (err1 | err2);
1702 +mini_fo_release(inode_t *inode, file_t *file)
1705 + file_t *hidden_file = NULL;
1707 + if (ftopd(file) != NULL) {
1709 + hidden_file = ftohf(file);
1710 + fput(hidden_file);
1712 + if(ftohf2(file)) {
1713 + hidden_file = ftohf2(file);
1714 + fput(hidden_file);
1716 + kfree(ftopd(file));
1722 +mini_fo_fsync(file_t *file, dentry_t *dentry, int datasync)
1726 + file_t *hidden_file = NULL;
1727 + dentry_t *hidden_dentry;
1729 + check_mini_fo_file(file);
1731 + if ((hidden_file = ftohf(file)) != NULL) {
1732 + hidden_dentry = dtohd(dentry);
1733 + if (hidden_file->f_op && hidden_file->f_op->fsync) {
1734 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
1735 + mutex_lock(&hidden_dentry->d_inode->i_mutex);
1737 + down(&hidden_dentry->d_inode->i_sem);
1739 + err1 = hidden_file->f_op->fsync(hidden_file, hidden_dentry, datasync);
1740 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
1741 + mutex_unlock(&hidden_dentry->d_inode->i_mutex);
1743 + up(&hidden_dentry->d_inode->i_sem);
1748 + if ((hidden_file = ftohf2(file)) != NULL) {
1749 + hidden_dentry = dtohd2(dentry);
1750 + if (hidden_file->f_op && hidden_file->f_op->fsync) {
1751 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
1752 + mutex_lock(&hidden_dentry->d_inode->i_mutex);
1754 + down(&hidden_dentry->d_inode->i_sem);
1756 + err2 = hidden_file->f_op->fsync(hidden_file, hidden_dentry, datasync);
1757 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
1758 + mutex_unlock(&hidden_dentry->d_inode->i_mutex);
1760 + up(&hidden_dentry->d_inode->i_sem);
1768 + return (err1 || err2);
1773 +mini_fo_fasync(int fd, file_t *file, int flag)
1778 + file_t *hidden_file = NULL;
1780 + check_mini_fo_file(file);
1782 + if((hidden_file = ftohf(file)) != NULL) {
1783 + err1 = hidden_file->f_op->fasync(fd, hidden_file, flag);
1785 + if((hidden_file = ftohf2(file)) != NULL) {
1786 + err2 = hidden_file->f_op->fasync(fd, hidden_file, flag);
1789 + return (err1 || err2);
1794 +mini_fo_lock(file_t *file, int cmd, struct file_lock *fl)
1796 + int err = -EINVAL;
1797 + file_t *hidden_file = NULL;
1799 + if(!check_mini_fo_file(file))
1802 + /* which file shall we lock? */
1804 + hidden_file = ftohf2(file);
1806 + hidden_file = ftohf(file);
1808 + if (hidden_file->f_op->lock) {
1809 + fl->fl_file = hidden_file;
1810 + err = hidden_file->f_op->lock(hidden_file, F_GETLK, fl);
1811 + fl->fl_file = file;
1813 + if(posix_test_lock(hidden_file, fl))
1821 +struct file_operations mini_fo_dir_fops =
1823 + read: generic_read_dir,
1824 + write: mini_fo_write,
1825 + readdir: mini_fo_readdir,
1826 + poll: mini_fo_poll,
1827 + /* ioctl: mini_fo_ioctl, */
1828 + mmap: mini_fo_mmap,
1829 + open: mini_fo_open,
1830 + flush: mini_fo_flush,
1831 + release: mini_fo_release,
1832 + fsync: mini_fo_fsync,
1833 + fasync: mini_fo_fasync,
1834 + /* not needed lock: mini_fo_lock, */
1835 + /* not needed: readv */
1836 + /* not needed: writev */
1837 + /* not implemented: sendpage */
1838 + /* not implemented: get_unmapped_area */
1841 +struct file_operations mini_fo_main_fops =
1843 + llseek: mini_fo_llseek,
1844 + read: mini_fo_read,
1845 + write: mini_fo_write,
1846 + readdir: mini_fo_readdir,
1847 + poll: mini_fo_poll,
1848 + /* ioctl: mini_fo_ioctl, */
1849 + mmap: mini_fo_mmap,
1850 + open: mini_fo_open,
1851 + flush: mini_fo_flush,
1852 + release: mini_fo_release,
1853 + fsync: mini_fo_fsync,
1854 + fasync: mini_fo_fasync,
1855 + /* not needed: lock: mini_fo_lock, */
1856 + /* not needed: readv */
1857 + /* not needed: writev */
1858 + /* not implemented: sendpage */
1859 + /* not implemented: get_unmapped_area */
1861 diff -urN linux.old/fs/mini_fo/fist.h linux.dev/fs/mini_fo/fist.h
1862 --- linux.old/fs/mini_fo/fist.h 1970-01-01 01:00:00.000000000 +0100
1863 +++ linux.dev/fs/mini_fo/fist.h 2006-10-30 03:42:09.000000000 +0100
1866 + * Copyright (c) 1997-2003 Erez Zadok
1867 + * Copyright (c) 2001-2003 Stony Brook University
1869 + * For specific licensing information, see the COPYING file distributed with
1870 + * this package, or get one from ftp://ftp.filesystems.org/pub/fist/COPYING.
1872 + * This Copyright notice must be kept intact and distributed with all
1873 + * fistgen sources INCLUDING sources generated by fistgen.
1876 + * Copyright (C) 2004, 2005 Markus Klotzbuecher <mk@creamnet.de>
1878 + * This program is free software; you can redistribute it and/or
1879 + * modify it under the terms of the GNU General Public License
1880 + * as published by the Free Software Foundation; either version
1881 + * 2 of the License, or (at your option) any later version.
1893 + * KERNEL ONLY CODE:
1896 +#include <linux/config.h>
1897 +#include <linux/version.h>
1898 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
1899 +#ifdef CONFIG_MODVERSIONS
1900 +# define MODVERSIONS
1901 +# include <linux/modversions.h>
1902 +#endif /* CONFIG_MODVERSIONS */
1903 +#endif /* KERNEL_VERSION < 2.6.0 */
1904 +#include <linux/sched.h>
1905 +#include <linux/kernel.h>
1906 +#include <linux/mm.h>
1907 +#include <linux/string.h>
1908 +#include <linux/stat.h>
1909 +#include <linux/errno.h>
1910 +#include <linux/wait.h>
1911 +#include <linux/limits.h>
1912 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
1913 +#include <linux/locks.h>
1915 +#include <linux/buffer_head.h>
1916 +#include <linux/pagemap.h>
1917 +#include <linux/namei.h>
1918 +#include <linux/module.h>
1919 +#include <linux/mount.h>
1920 +#include <linux/page-flags.h>
1921 +#include <linux/writeback.h>
1922 +#include <linux/statfs.h>
1924 +#include <linux/smp.h>
1925 +#include <linux/smp_lock.h>
1926 +#include <linux/file.h>
1927 +#include <linux/slab.h>
1928 +#include <linux/vmalloc.h>
1929 +#include <linux/poll.h>
1930 +#include <linux/list.h>
1931 +#include <linux/init.h>
1933 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,20)
1934 +#include <linux/xattr.h>
1937 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
1938 +#include <linux/security.h>
1941 +#include <linux/swap.h>
1943 +#include <asm/system.h>
1944 +#include <asm/segment.h>
1945 +#include <asm/mman.h>
1946 +#include <linux/seq_file.h>
1952 +/* those mapped to ATTR_* were copied from linux/fs.h */
1953 +#define FA_MODE ATTR_MODE
1954 +#define FA_UID ATTR_UID
1955 +#define FA_GID ATTR_GID
1956 +#define FA_SIZE ATTR_SIZE
1957 +#define FA_ATIME ATTR_ATIME
1958 +#define FA_MTIME ATTR_MTIME
1959 +#define FA_CTIME ATTR_CTIME
1960 +#define FA_ATIME_SET ATTR_ATIME_SET
1961 +#define FA_MTIME_SET ATTR_MTIME_SET
1962 +#define FA_FORCE ATTR_FORCE
1963 +#define FA_ATTR_FLAGS ATTR_ATTR_FLAG
1965 +/* must be greater than all other ATTR_* flags! */
1966 +#define FA_NLINK 2048
1967 +#define FA_BLKSIZE 4096
1968 +#define FA_BLOCKS 8192
1969 +#define FA_TIMES (FA_ATIME|FA_MTIME|FA_CTIME)
1972 +/* macros to manage changes between kernels */
1973 +#define INODE_DATA(i) (&(i)->i_data)
1975 +#define MIN(x,y) ((x < y) ? (x) : (y))
1976 +#define MAX(x,y) ((x > y) ? (x) : (y))
1977 +#define MAXPATHLEN PATH_MAX
1979 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,4,5)
1980 +# define lookup_one_len(a,b,c) lookup_one(a,b)
1981 +#endif /* LINUX_VERSION_CODE < KERNEL_VERSION(2,4,5) */
1983 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,4,8)
1984 +# define generic_file_llseek default_llseek
1985 +#endif /* LINUX_VERSION_CODE < KERNEL_VERSION(2,4,8) */
1988 +# define SEEK_SET 0
1989 +#endif /* not SEEK_SET */
1992 +# define SEEK_CUR 1
1993 +#endif /* not SEEK_CUR */
1996 +# define SEEK_END 2
1997 +#endif /* not SEEK_END */
1999 +#ifndef DEFAULT_POLLMASK
2000 +# define DEFAULT_POLLMASK (POLLIN | POLLOUT | POLLRDNORM | POLLWRNORM)
2001 +#endif /* not DEFAULT_POLLMASK */
2003 +/* XXX: fix this so fistgen generates kfree() code directly */
2004 +#define kfree_s(a,b) kfree(a)
2009 +typedef struct dentry dentry_t;
2010 +typedef struct file file_t;
2011 +typedef struct inode inode_t;
2012 +typedef inode_t vnode_t;
2013 +typedef struct page page_t;
2014 +typedef struct qstr qstr_t;
2015 +typedef struct super_block super_block_t;
2016 +typedef super_block_t vfs_t;
2017 +typedef struct vm_area_struct vm_area_t;
2024 +#define FPPF(str,page) printk("PPF %s 0x%x/%d: Lck:%d Err:%d Ref:%d Upd:%d Other::%d:%d:%d:%d:\n", \
2027 + (int) page->index, \
2028 + (PageLocked(page) ? 1 : 0), \
2029 + (PageError(page) ? 1 : 0), \
2030 + (PageReferenced(page) ? 1 : 0), \
2031 + (Page_Uptodate(page) ? 1 : 0), \
2032 + (PageDecrAfter(page) ? 1 : 0), \
2033 + (PageSlab(page) ? 1 : 0), \
2034 + (PageSwapCache(page) ? 1 : 0), \
2035 + (PageReserved(page) ? 1 : 0) \
2037 +#define EZKDBG printk("EZK %s:%d:%s\n",__FILE__,__LINE__,__FUNCTION__)
2039 +# define EZKDBG1 printk("EZK %s:%d\n",__FILE__,__LINE__)
2044 +extern int fist_get_debug_value(void);
2045 +extern int fist_set_debug_value(int val);
2046 +#if 0 /* mini_fo doesn't need these */
2047 +extern void fist_dprint_internal(int level, char *str,...);
2048 +extern void fist_print_dentry(char *str, const dentry_t *dentry);
2049 +extern void fist_print_inode(char *str, const inode_t *inode);
2050 +extern void fist_print_file(char *str, const file_t *file);
2051 +extern void fist_print_buffer_flags(char *str, struct buffer_head *buffer);
2052 +extern void fist_print_page_flags(char *str, page_t *page);
2053 +extern void fist_print_page_bytes(char *str, page_t *page);
2054 +extern void fist_print_pte_flags(char *str, const page_t *page);
2055 +extern void fist_checkinode(inode_t *inode, char *msg);
2056 +extern void fist_print_sb(char *str, const super_block_t *sb);
2058 +/* §$% by mk: special debug functions */
2059 +extern void fist_mk_print_dentry(char *str, const dentry_t *dentry);
2060 +extern void fist_mk_print_inode(char *str, const inode_t *inode);
2062 +extern char *add_indent(void);
2063 +extern char *del_indent(void);
2064 +#endif/* mini_fo doesn't need these */
2068 +#define ASSERT(EX) \
2071 + printk(KERN_CRIT "ASSERTION FAILED: %s at %s:%d (%s)\n", #EX, \
2072 + __FILE__, __LINE__, __FUNCTION__); \
2073 + (*((char *)0))=0; \
2076 +/* same ASSERT, but tell me who was the caller of the function */
2077 +#define ASSERT2(EX) \
2080 + printk(KERN_CRIT "ASSERTION FAILED (caller): %s at %s:%d (%s)\n", #EX, \
2081 + file, line, func); \
2082 + (*((char *)0))=0; \
2086 +#if 0 /* mini_fo doesn't need these */
2087 +#define dprintk(format, args...) printk(KERN_DEBUG format, ##args)
2088 +#define fist_dprint(level, str, args...) fist_dprint_internal(level, KERN_DEBUG str, ## args)
2089 +#define print_entry_location() fist_dprint(4, "%sIN: %s %s:%d\n", add_indent(), __FUNCTION__, __FILE__, __LINE__)
2090 +#define print_exit_location() fist_dprint(4, "%s OUT: %s %s:%d\n", del_indent(), __FUNCTION__, __FILE__, __LINE__)
2091 +#define print_exit_status(status) fist_dprint(4, "%s OUT: %s %s:%d, STATUS: %d\n", del_indent(), __FUNCTION__, __FILE__, __LINE__, status)
2092 +#define print_exit_pointer(status) \
2094 + if (IS_ERR(status)) \
2095 + fist_dprint(4, "%s OUT: %s %s:%d, RESULT: %ld\n", del_indent(), __FUNCTION__, __FILE__, __LINE__, PTR_ERR(status)); \
2097 + fist_dprint(4, "%s OUT: %s %s:%d, RESULT: 0x%x\n", del_indent(), __FUNCTION__, __FILE__, __LINE__, PTR_ERR(status)); \
2099 +#endif/* mini_fo doesn't need these */
2101 +#endif /* __KERNEL__ */
2105 + * DEFINITIONS FOR USER AND KERNEL CODE:
2106 + * (Note: ioctl numbers 1--9 are reserved for fistgen, the rest
2107 + * are auto-generated automatically based on the user's .fist file.)
2109 +# define FIST_IOCTL_GET_DEBUG_VALUE _IOR(0x15, 1, int)
2110 +# define FIST_IOCTL_SET_DEBUG_VALUE _IOW(0x15, 2, int)
2112 +#endif /* not __FIST_H_ */
2113 diff -urN linux.old/fs/mini_fo/inode.c linux.dev/fs/mini_fo/inode.c
2114 --- linux.old/fs/mini_fo/inode.c 1970-01-01 01:00:00.000000000 +0100
2115 +++ linux.dev/fs/mini_fo/inode.c 2006-10-30 03:55:42.000000000 +0100
2118 + * Copyright (c) 1997-2003 Erez Zadok
2119 + * Copyright (c) 2001-2003 Stony Brook University
2121 + * For specific licensing information, see the COPYING file distributed with
2122 + * this package, or get one from ftp://ftp.filesystems.org/pub/fist/COPYING.
2124 + * This Copyright notice must be kept intact and distributed with all
2125 + * fistgen sources INCLUDING sources generated by fistgen.
2128 + * Copyright (C) 2004, 2005 Markus Klotzbuecher <mk@creamnet.de>
2130 + * This program is free software; you can redistribute it and/or
2131 + * modify it under the terms of the GNU General Public License
2132 + * as published by the Free Software Foundation; either version
2133 + * 2 of the License, or (at your option) any later version.
2140 +#ifdef HAVE_CONFIG_H
2141 +# include <config.h>
2145 +#include "mini_fo.h"
2148 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
2149 +mini_fo_create(inode_t *dir, dentry_t *dentry, int mode, struct nameidata *nd)
2151 +mini_fo_create(inode_t *dir, dentry_t *dentry, int mode)
2156 + check_mini_fo_dentry(dentry);
2158 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
2159 + err = create_sto_reg_file(dentry, mode, nd);
2161 + err = create_sto_reg_file(dentry, mode);
2163 + check_mini_fo_dentry(dentry);
2169 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
2170 +mini_fo_lookup(inode_t *dir, dentry_t *dentry, struct nameidata* nd)
2172 +mini_fo_lookup(inode_t *dir, dentry_t *dentry)
2176 + dentry_t *hidden_dir_dentry;
2177 + dentry_t *hidden_dentry = NULL;
2179 + dentry_t *hidden_sto_dir_dentry;
2180 + dentry_t *hidden_sto_dentry = NULL;
2182 + /* whiteout flag */
2184 + char *bpath = NULL;
2187 + unsigned int namelen;
2189 + /* Don't allow lookups of META-files */
2190 + namelen = strlen(META_FILENAME);
2191 + if(namelen == dentry->d_name.len) {
2192 + if(!strncmp(dentry->d_name.name, META_FILENAME, namelen)) {
2198 + hidden_dir_dentry = dtohd(dentry->d_parent);
2199 + hidden_sto_dir_dentry = dtohd2(dentry->d_parent);
2201 + name = dentry->d_name.name;
2202 + namelen = dentry->d_name.len;
2204 + /* must initialize dentry operations */
2205 + dentry->d_op = &mini_fo_dops;
2207 + /* setup the del_flag */
2208 + del_flag = __meta_check_d_entry(dir, name, namelen);
2209 + bpath = __meta_check_r_entry(dir, name, namelen);
2211 + /* perform the lookups of base and storage files:
2213 + * This caused some serious trouble, as a lookup_one_len passing
2214 + * a negative dentry oopses. Solution is to only do the lookup
2215 + * if the dentry is positive, else we set it to NULL
2216 + * More trouble, who said a *_dir_dentry can't be NULL?
2219 + /* Cross-Interposing (C), yeah! */
2220 + hidden_dentry = bpath_walk(dir->i_sb, bpath);
2221 + if(!hidden_dentry || !hidden_dentry->d_inode) {
2222 + printk(KERN_CRIT "mini_fo_lookup: bpath_walk failed.\n");
2227 + /* this can be set up safely without fear of spaghetti
2228 + * interposing as it is only used for copying times */
2229 + hidden_dir_dentry = hidden_dentry->d_parent;
2232 + else if(hidden_dir_dentry && hidden_dir_dentry->d_inode)
2234 + lookup_one_len(name, hidden_dir_dentry, namelen);
2236 + hidden_dentry = NULL;
2238 + if(hidden_sto_dir_dentry && hidden_sto_dir_dentry->d_inode)
2239 + hidden_sto_dentry =
2240 + lookup_one_len(name, hidden_sto_dir_dentry, namelen);
2242 + hidden_sto_dentry = NULL;
2244 + /* catch error in lookup */
2245 + if (IS_ERR(hidden_dentry) || IS_ERR(hidden_sto_dentry)) {
2246 + /* mk: we need to call dput on the dentry, whose
2247 + * lookup_one_len operation failed, in order to avoid
2248 + * unmount trouble.
2250 + if(IS_ERR(hidden_dentry)) {
2251 + printk(KERN_CRIT "mini_fo_lookup: ERR from base dentry, lookup failed.\n");
2252 + err = PTR_ERR(hidden_dentry);
2254 + dput(hidden_dentry);
2256 + if(IS_ERR(hidden_sto_dentry)) {
2257 + printk(KERN_CRIT "mini_fo_lookup: ERR from storage dentry, lookup failed.\n");
2258 + err = PTR_ERR(hidden_sto_dentry);
2260 + dput(hidden_sto_dentry);
2265 + /* allocate dentry private data */
2266 + __dtopd(dentry) = (struct mini_fo_dentry_info *)
2267 + kmalloc(sizeof(struct mini_fo_dentry_info), GFP_KERNEL);
2269 + if (!dtopd(dentry)) {
2274 + /* check for different states of the mini_fo file to be looked up. */
2276 + /* state 1, file has been modified */
2277 + if(hidden_dentry && hidden_sto_dentry &&
2278 + hidden_dentry->d_inode && hidden_sto_dentry->d_inode && !del_flag) {
2280 + /* update parent directory's atime */
2281 + fist_copy_attr_atime(dir, hidden_sto_dir_dentry->d_inode);
2283 + dtopd(dentry)->state = MODIFIED;
2284 + dtohd(dentry) = hidden_dentry;
2285 + dtohd2(dentry) = hidden_sto_dentry;
2287 + err = mini_fo_tri_interpose(hidden_dentry,
2288 + hidden_sto_dentry,
2289 + dentry, dir->i_sb, 1);
2291 + printk(KERN_CRIT "mini_fo_lookup: error interposing (state1).\n");
2296 + /* state 2, file is unmodified */
2297 + if(hidden_dentry && hidden_dentry->d_inode && !del_flag) {
2299 + fist_copy_attr_atime(dir, hidden_dir_dentry->d_inode);
2301 + dtopd(dentry)->state = UNMODIFIED;
2302 + dtohd(dentry) = hidden_dentry;
2303 + dtohd2(dentry) = hidden_sto_dentry; /* could be negative */
2305 + err = mini_fo_tri_interpose(hidden_dentry,
2306 + hidden_sto_dentry,
2307 + dentry, dir->i_sb, 1);
2309 + printk(KERN_CRIT "mini_fo_lookup: error interposing (state2).\n");
2314 + /* state 3, file has been newly created */
2315 + if(hidden_sto_dentry && hidden_sto_dentry->d_inode && !del_flag) {
2317 + fist_copy_attr_atime(dir, hidden_sto_dir_dentry->d_inode);
2318 + dtopd(dentry)->state = CREATED;
2319 + dtohd(dentry) = hidden_dentry; /* could be negative */
2320 + dtohd2(dentry) = hidden_sto_dentry;
2322 + err = mini_fo_tri_interpose(hidden_dentry,
2323 + hidden_sto_dentry,
2324 + dentry, dir->i_sb, 1);
2326 + printk(KERN_CRIT "mini_fo_lookup: error interposing (state3).\n");
2332 + /* state 4, file has deleted and created again. */
2333 + if(hidden_dentry && hidden_sto_dentry &&
2334 + hidden_dentry->d_inode &&
2335 + hidden_sto_dentry->d_inode && del_flag) {
2337 + fist_copy_attr_atime(dir, hidden_sto_dir_dentry->d_inode);
2338 + dtopd(dentry)->state = DEL_REWRITTEN;
2339 + dtohd(dentry) = NULL;
2340 + dtohd2(dentry) = hidden_sto_dentry;
2342 + err = mini_fo_tri_interpose(NULL,
2343 + hidden_sto_dentry,
2344 + dentry, dir->i_sb, 1);
2346 + printk(KERN_CRIT "mini_fo_lookup: error interposing (state4).\n");
2349 + /* We will never need this dentry again, as the file has been
2350 + * deleted from base */
2351 + dput(hidden_dentry);
2354 + /* state 5, file has been deleted in base */
2355 + if(hidden_dentry && hidden_sto_dentry &&
2356 + hidden_dentry->d_inode &&
2357 + !hidden_sto_dentry->d_inode && del_flag) {
2359 + /* check which parents atime we need for updating */
2360 + if(hidden_sto_dir_dentry->d_inode)
2361 + fist_copy_attr_atime(dir,
2362 + hidden_sto_dir_dentry->d_inode);
2364 + fist_copy_attr_atime(dir,
2365 + hidden_dir_dentry->d_inode);
2367 + dtopd(dentry)->state = DELETED;
2368 + dtohd(dentry) = NULL;
2369 + dtohd2(dentry) = hidden_sto_dentry;
2371 + /* add negative dentry to dcache to speed up lookups */
2372 + d_add(dentry, NULL);
2373 + dput(hidden_dentry);
2376 + /* state 6, file does not exist */
2377 + if(((hidden_dentry && !hidden_dentry->d_inode) ||
2378 + (hidden_sto_dentry && !hidden_sto_dentry->d_inode)) && !del_flag)
2380 + /* check which parents atime we need for updating */
2381 + if(hidden_sto_dir_dentry && hidden_sto_dir_dentry->d_inode)
2382 + fist_copy_attr_atime(dir, hidden_sto_dir_dentry->d_inode);
2384 + fist_copy_attr_atime(dir, hidden_dir_dentry->d_inode);
2386 + dtopd(dentry)->state = NON_EXISTANT;
2387 + dtohd(dentry) = hidden_dentry;
2388 + dtohd2(dentry) = hidden_sto_dentry;
2389 + d_add(dentry, NULL);
2393 + /* if we get to here, were in an invalid state. bad. */
2394 + printk(KERN_CRIT "mini_fo_lookup: ERROR, meta data corruption detected.\n");
2396 + /* end state checking */
2398 + d_drop(dentry); /* so that our bad dentry will get destroyed */
2399 + kfree(dtopd(dentry));
2400 + __dtopd(dentry) = NULL; /* be safe */
2404 + dput(hidden_dentry);
2405 + if(hidden_sto_dentry)
2406 + dput(hidden_sto_dentry); /* drops usage count and marks for release */
2409 + /* initalize wol if file exists and is directory */
2410 + if(dentry->d_inode) {
2411 + if(S_ISDIR(dentry->d_inode->i_mode)) {
2412 + itopd(dentry->d_inode)->deleted_list_size = -1;
2413 + itopd(dentry->d_inode)->renamed_list_size = -1;
2414 + meta_build_lists(dentry);
2417 + return ERR_PTR(err);
2422 +mini_fo_link(dentry_t *old_dentry, inode_t *dir, dentry_t *new_dentry)
2425 + dentry_t *hidden_old_dentry;
2426 + dentry_t *hidden_new_dentry;
2427 + dentry_t *hidden_dir_dentry;
2430 + check_mini_fo_dentry(old_dentry);
2431 + check_mini_fo_dentry(new_dentry);
2432 + check_mini_fo_inode(dir);
2434 + /* no links to directorys and existing targets target allowed */
2435 + if(S_ISDIR(old_dentry->d_inode->i_mode) ||
2436 + is_mini_fo_existant(new_dentry)) {
2441 + /* bring it directly from unmod to del_rew */
2442 + if(dtost(old_dentry) == UNMODIFIED) {
2443 + err = nondir_unmod_to_mod(old_dentry, 1);
2448 + err = meta_add_d_entry(old_dentry->d_parent,
2449 + old_dentry->d_name.name,
2450 + old_dentry->d_name.len);
2455 + dput(dtohd(old_dentry));
2456 + dtohd(old_dentry) = NULL;
2457 + dtost(old_dentry) = DEL_REWRITTEN;
2460 + err = get_neg_sto_dentry(new_dentry);
2466 + hidden_old_dentry = dtohd2(old_dentry);
2467 + hidden_new_dentry = dtohd2(new_dentry);
2469 + dget(hidden_old_dentry);
2470 + dget(hidden_new_dentry);
2472 + /* was: hidden_dir_dentry = lock_parent(hidden_new_dentry); */
2473 + hidden_dir_dentry = dget(hidden_new_dentry->d_parent);
2474 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
2475 + mutex_lock(&hidden_dir_dentry->d_inode->i_mutex);
2477 + down(&hidden_dir_dentry->d_inode->i_sem);
2480 + err = vfs_link(hidden_old_dentry,
2481 + hidden_dir_dentry->d_inode,
2482 + hidden_new_dentry);
2483 + if (err || !hidden_new_dentry->d_inode)
2486 + dtost(new_dentry) = CREATED;
2487 + err = mini_fo_tri_interpose(NULL, hidden_new_dentry, new_dentry, dir->i_sb, 0);
2491 + fist_copy_attr_timesizes(dir, hidden_new_dentry->d_inode);
2492 + /* propagate number of hard-links */
2493 + old_dentry->d_inode->i_nlink = itohi2(old_dentry->d_inode)->i_nlink;
2496 + /* was: unlock_dir(hidden_dir_dentry); */
2497 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
2498 + mutex_unlock(&hidden_dir_dentry->d_inode->i_mutex);
2500 + up(&hidden_dir_dentry->d_inode->i_sem);
2502 + dput(hidden_dir_dentry);
2504 + dput(hidden_new_dentry);
2505 + dput(hidden_old_dentry);
2506 + if (!new_dentry->d_inode)
2507 + d_drop(new_dentry);
2515 +mini_fo_unlink(inode_t *dir, dentry_t *dentry)
2520 + if(dtopd(dentry)->state == MODIFIED) {
2521 + err = nondir_mod_to_del(dentry);
2524 + else if(dtopd(dentry)->state == UNMODIFIED) {
2525 + err = nondir_unmod_to_del(dentry);
2528 + else if(dtopd(dentry)->state == CREATED) {
2529 + err = nondir_creat_to_del(dentry);
2532 + else if(dtopd(dentry)->state == DEL_REWRITTEN) {
2533 + err = nondir_del_rew_to_del(dentry);
2537 + printk(KERN_CRIT "mini_fo_unlink: ERROR, invalid state detected.\n");
2540 + fist_copy_attr_times(dir, itohi2(dentry->d_parent->d_inode));
2543 + /* is this causing my pain? d_delete(dentry); */
2553 +mini_fo_symlink(inode_t *dir, dentry_t *dentry, const char *symname)
2556 + dentry_t *hidden_sto_dentry;
2557 + dentry_t *hidden_sto_dir_dentry;
2558 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
2562 + /* Fail if the symlink file exists */
2563 + if(!(dtost(dentry) == DELETED ||
2564 + dtost(dentry) == NON_EXISTANT)) {
2569 + err = get_neg_sto_dentry(dentry);
2574 + hidden_sto_dentry = dtohd2(dentry);
2576 + dget(hidden_sto_dentry);
2577 + /* was: hidden_sto_dir_dentry = lock_parent(hidden_sto_dentry); */
2578 + hidden_sto_dir_dentry = dget(hidden_sto_dentry->d_parent);
2579 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
2580 + mutex_lock(&hidden_sto_dir_dentry->d_inode->i_mutex);
2582 + down(&hidden_sto_dir_dentry->d_inode->i_sem);
2585 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
2587 + err = vfs_symlink(hidden_sto_dir_dentry->d_inode,
2588 + hidden_sto_dentry, symname, mode);
2590 + err = vfs_symlink(hidden_sto_dir_dentry->d_inode,
2591 + hidden_sto_dentry,
2594 + if (err || !hidden_sto_dentry->d_inode)
2597 + if(dtost(dentry) == DELETED) {
2598 + dtost(dentry) = DEL_REWRITTEN;
2599 + err = mini_fo_tri_interpose(NULL, hidden_sto_dentry, dentry, dir->i_sb, 0);
2602 + } else if(dtost(dentry) == NON_EXISTANT) {
2603 + dtost(dentry) = CREATED;
2604 + err = mini_fo_tri_interpose(dtohd(dentry), hidden_sto_dentry, dentry, dir->i_sb, 0);
2608 + fist_copy_attr_timesizes(dir, hidden_sto_dir_dentry->d_inode);
2611 + /* was: unlock_dir(hidden_sto_dir_dentry); */
2612 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
2613 + mutex_unlock(&hidden_sto_dir_dentry->d_inode->i_mutex);
2615 + up(&hidden_sto_dir_dentry->d_inode->i_sem);
2617 + dput(hidden_sto_dir_dentry);
2619 + dput(hidden_sto_dentry);
2620 + if (!dentry->d_inode)
2627 +mini_fo_mkdir(inode_t *dir, dentry_t *dentry, int mode)
2631 + err = create_sto_dir(dentry, mode);
2633 + check_mini_fo_dentry(dentry);
2640 +mini_fo_rmdir(inode_t *dir, dentry_t *dentry)
2644 + dentry_t *hidden_sto_dentry;
2645 + dentry_t *hidden_sto_dir_dentry;
2646 + dentry_t *meta_dentry;
2647 + inode_t *hidden_sto_dir = NULL;
2649 + check_mini_fo_dentry(dentry);
2650 + check_mini_fo_inode(dir);
2653 + if(dtopd(dentry)->state == MODIFIED) {
2654 + /* XXX: disabled, because it does not bother to check files on
2655 + * the original filesystem - just a hack, but better than simply
2656 + * removing it without testing */
2660 + hidden_sto_dir = itohi2(dir);
2661 + hidden_sto_dentry = dtohd2(dentry);
2663 + /* was:hidden_sto_dir_dentry = lock_parent(hidden_sto_dentry); */
2664 + hidden_sto_dir_dentry = dget(hidden_sto_dentry->d_parent);
2665 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
2666 + mutex_lock(&hidden_sto_dir_dentry->d_inode->i_mutex);
2668 + down(&hidden_sto_dir_dentry->d_inode->i_sem);
2671 + /* avoid destroying the hidden inode if the file is in use */
2672 + dget(hidden_sto_dentry);
2674 + /* Delete an old WOL file contained in the storage dir */
2675 + meta_dentry = lookup_one_len(META_FILENAME,
2676 + hidden_sto_dentry,
2677 + strlen(META_FILENAME));
2678 + if(meta_dentry->d_inode) {
2679 + err = vfs_unlink(hidden_sto_dentry->d_inode, meta_dentry);
2680 + dput(meta_dentry);
2682 + d_delete(meta_dentry);
2685 + err = vfs_rmdir(hidden_sto_dir, hidden_sto_dentry);
2686 + dput(hidden_sto_dentry);
2688 + d_delete(hidden_sto_dentry);
2690 + /* propagate number of hard-links */
2691 + dentry->d_inode->i_nlink = itohi2(dentry->d_inode)->i_nlink;
2693 + dput(dtohd(dentry));
2695 + dtohd(dentry) = NULL;
2696 + dtopd(dentry)->state = DELETED;
2698 + /* carefull with R files */
2699 + if( __meta_is_r_entry(dir,
2700 + dentry->d_name.name,
2701 + dentry->d_name.len) == 1) {
2702 + err = meta_remove_r_entry(dentry->d_parent,
2703 + dentry->d_name.name,
2704 + dentry->d_name.len);
2706 + printk(KERN_CRIT "mini_fo: rmdir: meta_remove_r_entry failed.\n");
2711 + /* ok, add deleted file to META */
2712 + meta_add_d_entry(dentry->d_parent,
2713 + dentry->d_name.name,
2714 + dentry->d_name.len);
2716 + /* was: unlock_dir(hidden_sto_dir_dentry); */
2717 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
2718 + mutex_unlock(&hidden_sto_dir_dentry->d_inode->i_mutex);
2720 + up(&hidden_sto_dir_dentry->d_inode->i_sem);
2722 + dput(hidden_sto_dir_dentry);
2725 + else if(dtopd(dentry)->state == UNMODIFIED) {
2726 + /* XXX: simply adding it to the delete list here is fscking dangerous!
2727 + * as a temporary hack, i will disable rmdir on unmodified directories
2733 + err = get_neg_sto_dentry(dentry);
2739 + /* dput base dentry, this will relase the inode and free the
2740 + * dentry, as we will never need it again. */
2741 + dput(dtohd(dentry));
2742 + dtohd(dentry) = NULL;
2743 + dtopd(dentry)->state = DELETED;
2745 + /* add deleted file to META-file */
2746 + meta_add_d_entry(dentry->d_parent,
2747 + dentry->d_name.name,
2748 + dentry->d_name.len);
2751 + else if(dtopd(dentry)->state == CREATED) {
2752 + hidden_sto_dir = itohi2(dir);
2753 + hidden_sto_dentry = dtohd2(dentry);
2755 + /* was: hidden_sto_dir_dentry = lock_parent(hidden_sto_dentry);*/
2756 + hidden_sto_dir_dentry = dget(hidden_sto_dentry->d_parent);
2758 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
2759 + mutex_lock(&hidden_sto_dir_dentry->d_inode->i_mutex);
2761 + down(&hidden_sto_dir_dentry->d_inode->i_sem);
2764 + /* avoid destroying the hidden inode if the file is in use */
2765 + dget(hidden_sto_dentry);
2767 + /* Delete an old WOL file contained in the storage dir */
2768 + meta_dentry = lookup_one_len(META_FILENAME,
2769 + hidden_sto_dentry,
2770 + strlen(META_FILENAME));
2771 + if(meta_dentry->d_inode) {
2772 + /* is this necessary? dget(meta_dentry); */
2773 + err = vfs_unlink(hidden_sto_dentry->d_inode,
2775 + dput(meta_dentry);
2777 + d_delete(meta_dentry);
2780 + err = vfs_rmdir(hidden_sto_dir, hidden_sto_dentry);
2781 + dput(hidden_sto_dentry);
2783 + d_delete(hidden_sto_dentry);
2785 + /* propagate number of hard-links */
2786 + dentry->d_inode->i_nlink = itohi2(dentry->d_inode)->i_nlink;
2787 + dtopd(dentry)->state = NON_EXISTANT;
2789 + /* was: unlock_dir(hidden_sto_dir_dentry); */
2790 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
2791 + mutex_unlock(&hidden_sto_dir_dentry->d_inode->i_mutex);
2793 + up(&hidden_sto_dir_dentry->d_inode->i_sem);
2795 + dput(hidden_sto_dir_dentry);
2799 + else if(dtopd(dentry)->state == DEL_REWRITTEN) {
2800 + hidden_sto_dir = itohi2(dir);
2801 + hidden_sto_dentry = dtohd2(dentry);
2803 + /* was: hidden_sto_dir_dentry = lock_parent(hidden_sto_dentry);*/
2804 + hidden_sto_dir_dentry = dget(hidden_sto_dentry->d_parent);
2806 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
2807 + mutex_lock(&hidden_sto_dir_dentry->d_inode->i_mutex);
2809 + down(&hidden_sto_dir_dentry->d_inode->i_sem);
2812 + /* avoid destroying the hidden inode if the file is in use */
2813 + dget(hidden_sto_dentry);
2815 + /* Delete an old WOL file contained in the storage dir */
2816 + meta_dentry = lookup_one_len(META_FILENAME,
2817 + hidden_sto_dentry,
2818 + strlen(META_FILENAME));
2819 + if(meta_dentry->d_inode) {
2820 + /* is this necessary? dget(meta_dentry); */
2821 + err = vfs_unlink(hidden_sto_dentry->d_inode,
2823 + dput(meta_dentry);
2825 + d_delete(meta_dentry);
2828 + err = vfs_rmdir(hidden_sto_dir, hidden_sto_dentry);
2829 + dput(hidden_sto_dentry);
2831 + d_delete(hidden_sto_dentry);
2833 + /* propagate number of hard-links */
2834 + dentry->d_inode->i_nlink = itohi2(dentry->d_inode)->i_nlink;
2835 + dtopd(dentry)->state = DELETED;
2836 + /* was: unlock_dir(hidden_sto_dir_dentry); */
2838 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
2839 + mutex_unlock(&hidden_sto_dir_dentry->d_inode->i_mutex);
2841 + up(&hidden_sto_dir_dentry->d_inode->i_sem);
2843 + dput(hidden_sto_dir_dentry);
2847 + printk(KERN_CRIT "mini_fo_rmdir: ERROR, invalid state detected.\n");
2854 + fist_copy_attr_times(dir, itohi2(dentry->d_parent->d_inode));
2862 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
2863 +mini_fo_mknod(inode_t *dir, dentry_t *dentry, int mode, dev_t dev)
2865 +mini_fo_mknod(inode_t *dir, dentry_t *dentry, int mode, int dev)
2870 + check_mini_fo_dentry(dentry);
2872 + err = create_sto_nod(dentry, mode, dev);
2874 + printk(KERN_CRIT "mini_fo_mknod: creating sto nod failed.\n");
2878 + check_mini_fo_dentry(dentry);
2884 +mini_fo_rename(inode_t *old_dir, dentry_t *old_dentry,
2885 + inode_t *new_dir, dentry_t *new_dentry)
2888 + if(S_ISDIR(old_dentry->d_inode->i_mode))
2889 + return rename_directory(old_dir, old_dentry, new_dir, new_dentry);
2890 + return rename_nondir(old_dir, old_dentry, new_dir, new_dentry);
2894 +int rename_directory(inode_t *old_dir, dentry_t *old_dentry,
2895 + inode_t *new_dir, dentry_t *new_dentry)
2897 + int err, bpath_len;
2900 + dentry_t *hidden_old_dentry;
2901 + dentry_t *hidden_new_dentry;
2902 + dentry_t *hidden_old_dir_dentry;
2903 + dentry_t *hidden_new_dir_dentry;
2909 + /* this is a test, chuck out if it works */
2910 + if(!(dtopd(new_dentry)->state == DELETED ||
2911 + dtopd(new_dentry)->state == NON_EXISTANT)) {
2912 + printk(KERN_CRIT "mini_fo: rename_directory: \
2913 + uh, ah, new_dentry not negative.\n");
2917 + /* state = UNMODIFIED */
2918 + if(dtopd(old_dentry)->state == UNMODIFIED) {
2919 + err = dir_unmod_to_mod(old_dentry);
2924 + /* state = MODIFIED */
2925 + if(dtopd(old_dentry)->state == MODIFIED) {
2926 + bpath = meta_check_r_entry(old_dentry->d_parent,
2927 + old_dentry->d_name.name,
2928 + old_dentry->d_name.len);
2930 + err = meta_remove_r_entry(old_dentry->d_parent,
2931 + old_dentry->d_name.name,
2932 + old_dentry->d_name.len);
2934 + printk(KERN_CRIT "mini_fo: rename_directory:\
2935 + meta_remove_r_entry \
2939 + err = meta_add_r_entry(new_dentry->d_parent,
2942 + new_dentry->d_name.name,
2943 + new_dentry->d_name.len);
2946 + else {/* wol it */
2947 + err = meta_add_d_entry(old_dentry->d_parent,
2948 + old_dentry->d_name.name,
2949 + old_dentry->d_name.len);
2952 + /* put it on rename list */
2953 + err = get_mini_fo_bpath(old_dentry,
2958 + err = meta_add_r_entry(new_dentry->d_parent,
2960 + new_dentry->d_name.name,
2961 + new_dentry->d_name.len);
2965 + /* no state change, MODIFIED stays MODIFIED */
2967 + /* state = CREATED */
2968 + if(dtopd(old_dentry)->state == CREATED ||
2969 + dtopd(old_dentry)->state == DEL_REWRITTEN) {
2970 + if(dtohd(old_dentry))
2971 + dput(dtohd(old_dentry));
2973 + if(dtopd(new_dentry)->state == DELETED) {
2974 + dtopd(old_dentry)->state = DEL_REWRITTEN;
2975 + dtohd(old_dentry) = NULL;
2977 + else if(dtopd(new_dentry)->state == NON_EXISTANT) {
2978 + dtopd(old_dentry)->state = CREATED;
2979 + /* steal new dentry's neg. base dentry */
2980 + dtohd(old_dentry) = dtohd(new_dentry);
2981 + dtohd(new_dentry) = NULL;
2984 + if(dtopd(new_dentry)->state == UNMODIFIED ||
2985 + dtopd(new_dentry)->state == NON_EXISTANT) {
2986 + err = get_neg_sto_dentry(new_dentry);
2991 + /* now move sto file */
2992 + hidden_old_dentry = dtohd2(old_dentry);
2993 + hidden_new_dentry = dtohd2(new_dentry);
2995 + dget(hidden_old_dentry);
2996 + dget(hidden_new_dentry);
2998 + hidden_old_dir_dentry = dget(hidden_old_dentry->d_parent);
2999 + hidden_new_dir_dentry = dget(hidden_new_dentry->d_parent);
3000 + double_lock(hidden_old_dir_dentry, hidden_new_dir_dentry);
3002 + err = vfs_rename(hidden_old_dir_dentry->d_inode, hidden_old_dentry,
3003 + hidden_new_dir_dentry->d_inode, hidden_new_dentry);
3007 + fist_copy_attr_all(new_dir, hidden_new_dir_dentry->d_inode);
3008 + if (new_dir != old_dir)
3009 + fist_copy_attr_all(old_dir,
3010 + hidden_old_dir_dentry->d_inode);
3013 + /* double_unlock will dput the new/old parent dentries
3014 + * whose refcnts were incremented via get_parent above. */
3015 + double_unlock(hidden_old_dir_dentry, hidden_new_dir_dentry);
3016 + dput(hidden_new_dentry);
3017 + dput(hidden_old_dentry);
3023 +int rename_nondir(inode_t *old_dir, dentry_t *old_dentry,
3024 + inode_t *new_dir, dentry_t *new_dentry)
3028 + check_mini_fo_dentry(old_dentry);
3029 + check_mini_fo_dentry(new_dentry);
3030 + check_mini_fo_inode(old_dir);
3031 + check_mini_fo_inode(new_dir);
3033 + /* state: UNMODIFIED */
3034 + if(dtost(old_dentry) == UNMODIFIED) {
3035 + err = nondir_unmod_to_mod(old_dentry, 1);
3042 + /* the easy states */
3043 + if(exists_in_storage(old_dentry)) {
3045 + dentry_t *hidden_old_dentry;
3046 + dentry_t *hidden_new_dentry;
3047 + dentry_t *hidden_old_dir_dentry;
3048 + dentry_t *hidden_new_dir_dentry;
3050 + /* if old file is MODIFIED, add it to the deleted_list */
3051 + if(dtopd(old_dentry)->state == MODIFIED) {
3052 + meta_add_d_entry(old_dentry->d_parent,
3053 + old_dentry->d_name.name,
3054 + old_dentry->d_name.len);
3056 + dput(dtohd(old_dentry));
3058 + /* if old file is CREATED, we only release the base dentry */
3059 + if(dtopd(old_dentry)->state == CREATED) {
3060 + if(dtohd(old_dentry))
3061 + dput(dtohd(old_dentry));
3064 + /* now setup the new states (depends on new_dentry state) */
3065 + /* new dentry state = MODIFIED */
3066 + if(dtopd(new_dentry)->state == MODIFIED) {
3067 + meta_add_d_entry(new_dentry->d_parent,
3068 + new_dentry->d_name.name,
3069 + new_dentry->d_name.len);
3071 + /* new dentry will be d_put'ed later by the vfs
3072 + * so don't do it here
3073 + * dput(dtohd(new_dentry));
3075 + dtohd(old_dentry) = NULL;
3076 + dtopd(old_dentry)->state = DEL_REWRITTEN;
3078 + /* new dentry state = UNMODIFIED */
3079 + else if(dtopd(new_dentry)->state == UNMODIFIED) {
3080 + if(get_neg_sto_dentry(new_dentry))
3083 + meta_add_d_entry(new_dentry->d_parent,
3084 + new_dentry->d_name.name,
3085 + new_dentry->d_name.len);
3087 + /* is this right??? */
3088 + /*dput(dtohd(new_dentry));*/
3089 + dtohd(old_dentry) = NULL;
3090 + dtopd(old_dentry)->state = DEL_REWRITTEN;
3092 + /* new dentry state = CREATED */
3093 + else if(dtopd(new_dentry)->state == CREATED) {
3094 + /* we keep the neg. base dentry (if exists) */
3095 + dtohd(old_dentry) = dtohd(new_dentry);
3096 + /* ...and set it to Null, or we'll get
3097 + * dcache.c:345 if it gets dput twice... */
3098 + dtohd(new_dentry) = NULL;
3099 + dtopd(old_dentry)->state = CREATED;
3101 + /* new dentry state = NON_EXISTANT */
3102 + else if(dtopd(new_dentry)->state == NON_EXISTANT) {
3103 + if(get_neg_sto_dentry(new_dentry))
3106 + /* we keep the neg. base dentry (if exists) */
3107 + dtohd(old_dentry) = dtohd(new_dentry);
3108 + /* ...and set it to Null, or we'll get
3109 + * Dr. dcache.c:345 if it gets dput twice... */
3110 + dtohd(new_dentry) = NULL;
3111 + dtopd(old_dentry)->state = CREATED;
3113 + /* new dentry state = DEL_REWRITTEN or DELETED */
3114 + else if(dtopd(new_dentry)->state == DEL_REWRITTEN ||
3115 + dtopd(new_dentry)->state == DELETED) {
3116 + dtohd(old_dentry) = NULL;
3117 + dtopd(old_dentry)->state = DEL_REWRITTEN;
3119 + else { /* not possible, uhh, ahh */
3121 + "mini_fo: rename_reg_file: invalid state detected [1].\n");
3125 + /* now we definitely have a sto file */
3126 + hidden_old_dentry = dtohd2(old_dentry);
3127 + hidden_new_dentry = dtohd2(new_dentry);
3129 + dget(hidden_old_dentry);
3130 + dget(hidden_new_dentry);
3132 + hidden_old_dir_dentry = dget(hidden_old_dentry->d_parent);
3133 + hidden_new_dir_dentry = dget(hidden_new_dentry->d_parent);
3134 + double_lock(hidden_old_dir_dentry, hidden_new_dir_dentry);
3136 + err = vfs_rename(hidden_old_dir_dentry->d_inode,
3137 + hidden_old_dentry,
3138 + hidden_new_dir_dentry->d_inode,
3139 + hidden_new_dentry);
3143 + fist_copy_attr_all(new_dir, hidden_new_dir_dentry->d_inode);
3144 + if (new_dir != old_dir)
3145 + fist_copy_attr_all(old_dir, hidden_old_dir_dentry->d_inode);
3148 + /* double_unlock will dput the new/old parent dentries
3149 + * whose refcnts were incremented via get_parent above.
3151 + double_unlock(hidden_old_dir_dentry, hidden_new_dir_dentry);
3152 + dput(hidden_new_dentry);
3153 + dput(hidden_old_dentry);
3157 + else { /* invalid state */
3158 + printk(KERN_CRIT "mini_fo: rename_reg_file: ERROR: invalid state detected [2].\n");
3165 +mini_fo_readlink(dentry_t *dentry, char *buf, int bufsiz)
3168 + dentry_t *hidden_dentry = NULL;
3170 + if(dtohd2(dentry) && dtohd2(dentry)->d_inode) {
3171 + hidden_dentry = dtohd2(dentry);
3172 + } else if(dtohd(dentry) && dtohd(dentry)->d_inode) {
3173 + hidden_dentry = dtohd(dentry);
3178 + if (!hidden_dentry->d_inode->i_op ||
3179 + !hidden_dentry->d_inode->i_op->readlink) {
3180 + err = -EINVAL; goto out;
3183 + err = hidden_dentry->d_inode->i_op->readlink(hidden_dentry,
3187 + fist_copy_attr_atime(dentry->d_inode, hidden_dentry->d_inode);
3194 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,13)
3195 +static int mini_fo_follow_link(dentry_t *dentry, struct nameidata *nd)
3197 +static void* mini_fo_follow_link(dentry_t *dentry, struct nameidata *nd)
3201 + int len = PAGE_SIZE, err;
3202 + mm_segment_t old_fs;
3204 + /* in 2.6 this is freed by mini_fo_put_link called by __do_follow_link */
3205 + buf = kmalloc(len, GFP_KERNEL);
3211 + /* read the symlink, and then we will follow it */
3212 + old_fs = get_fs();
3213 + set_fs(KERNEL_DS);
3214 + err = dentry->d_inode->i_op->readlink(dentry, buf, len);
3222 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
3223 + nd_set_link(nd, buf);
3226 + err = vfs_follow_link(nd, buf);
3230 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
3234 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,13)
3237 + return ERR_PTR(err);
3242 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
3243 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,13)
3244 +void mini_fo_put_link(struct dentry *dentry, struct nameidata *nd)
3246 +void mini_fo_put_link(struct dentry *dentry, struct nameidata *nd, void *cookie)
3250 + link = nd_get_link(nd);
3256 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
3257 +mini_fo_permission(inode_t *inode, int mask, struct nameidata *nd)
3259 +mini_fo_permission(inode_t *inode, int mask)
3262 + inode_t *hidden_inode;
3266 + if(itohi2(inode)) {
3267 + hidden_inode = itohi2(inode);
3269 + hidden_inode = itohi(inode);
3271 + mode = inode->i_mode;
3273 + /* not really needed, as permission handles everything:
3274 + * err = vfs_permission(inode, mask);
3279 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
3280 + err = permission(hidden_inode, mask, nd);
3282 + err = permission(hidden_inode, mask);
3289 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
3291 +mini_fo_inode_revalidate(dentry_t *dentry)
3294 + dentry_t *hidden_dentry;
3295 + inode_t *hidden_inode;
3297 + ASSERT(dentry->d_inode);
3298 + ASSERT(itopd(dentry->d_inode));
3300 + if(itohi2(dentry->d_inode)) {
3301 + hidden_dentry = dtohd2(dentry);
3302 + hidden_inode = hidden_dentry->d_inode;
3303 + } else if(itohi(dentry->d_inode)) {
3304 + hidden_dentry = dtohd(dentry);
3305 + hidden_inode = hidden_dentry->d_inode;
3307 + printk(KERN_CRIT "mini_fo_inode_revalidate: ERROR, invalid state detected.\n");
3311 + if (hidden_inode && hidden_inode->i_op && hidden_inode->i_op->revalidate){
3312 + err = hidden_inode->i_op->revalidate(hidden_dentry);
3316 + fist_copy_attr_all(dentry->d_inode, hidden_inode);
3323 +mini_fo_setattr(dentry_t *dentry, struct iattr *ia)
3327 + check_mini_fo_dentry(dentry);
3329 + if(!is_mini_fo_existant(dentry)) {
3330 + printk(KERN_CRIT "mini_fo_setattr: ERROR, invalid state detected [1].\n");
3334 + if(dtost(dentry) == UNMODIFIED) {
3335 + if(!IS_COPY_FLAG(ia->ia_valid))
3336 + goto out; /* we ignore these changes to base */
3338 + if(S_ISDIR(dentry->d_inode->i_mode)) {
3339 + err = dir_unmod_to_mod(dentry);
3341 + /* we copy contents if file is not beeing truncated */
3342 + if(S_ISREG(dentry->d_inode->i_mode) &&
3343 + !(ia->ia_size == 0 && (ia->ia_valid & ATTR_SIZE))) {
3344 + err = nondir_unmod_to_mod(dentry, 1);
3346 + err = nondir_unmod_to_mod(dentry, 0);
3350 + printk(KERN_CRIT "mini_fo_setattr: ERROR changing states.\n");
3354 + if(!exists_in_storage(dentry)) {
3355 + printk(KERN_CRIT "mini_fo_setattr: ERROR, invalid state detected [2].\n");
3359 + ASSERT(dentry->d_inode);
3360 + ASSERT(dtohd2(dentry));
3361 + ASSERT(itopd(dentry->d_inode));
3362 + ASSERT(itohi2(dentry->d_inode));
3364 + err = notify_change(dtohd2(dentry), ia);
3365 + fist_copy_attr_all(dentry->d_inode, itohi2(dentry->d_inode));
3370 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
3372 +mini_fo_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
3375 + dentry_t *hidden_dentry;
3377 + ASSERT(dentry->d_inode);
3378 + ASSERT(itopd(dentry->d_inode));
3380 + if(itohi2(dentry->d_inode)) {
3381 + hidden_dentry = dtohd2(dentry);
3382 + } else if(itohi(dentry->d_inode)) {
3383 + hidden_dentry = dtohd(dentry);
3385 + printk(KERN_CRIT "mini_fo_getattr: ERROR, invalid state detected.\n");
3389 + fist_copy_attr_all(dentry->d_inode, hidden_dentry->d_inode);
3391 + ASSERT(hidden_dentry);
3392 + ASSERT(hidden_dentry->d_inode);
3393 + ASSERT(hidden_dentry->d_inode->i_op);
3395 + generic_fillattr(dentry->d_inode, stat);
3396 + if (!stat->blksize) {
3397 + struct super_block *s = hidden_dentry->d_inode->i_sb;
3399 + blocks = (stat->size+s->s_blocksize-1) >> s->s_blocksize_bits;
3400 + stat->blocks = (s->s_blocksize / 512) * blocks;
3401 + stat->blksize = s->s_blocksize;
3408 +#if defined(XATTR) && (LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,20))
3409 +#if 0 /* no xattr_alloc() and xattr_free() */
3410 +/* This is lifted from fs/xattr.c */
3412 +xattr_alloc(size_t size, size_t limit)
3417 + return ERR_PTR(-E2BIG);
3419 + if (!size) /* size request, no buffer is needed */
3421 + else if (size <= PAGE_SIZE)
3422 + ptr = kmalloc((unsigned long) size, GFP_KERNEL);
3424 + ptr = vmalloc((unsigned long) size);
3426 + return ERR_PTR(-ENOMEM);
3431 +xattr_free(void *ptr, size_t size)
3433 + if (!size) /* size request, no buffer was needed */
3435 + else if (size <= PAGE_SIZE)
3440 +#endif /* no xattr_alloc() and xattr_free() */
3442 +/* BKL held by caller.
3443 + * dentry->d_inode->i_sem down
3446 +mini_fo_getxattr(struct dentry *dentry, const char *name, void *value, size_t size) {
3447 + struct dentry *hidden_dentry = NULL;
3448 + int err = -EOPNOTSUPP;
3449 + /* Define these anyway so we don't need as much ifdef'ed code. */
3450 + char *encoded_name = NULL;
3451 + char *encoded_value = NULL;
3453 + check_mini_fo_dentry(dentry);
3455 + if(exists_in_storage(dentry))
3456 + hidden_dentry = dtohd2(dentry);
3458 + hidden_dentry = dtohd(dentry);
3460 + ASSERT(hidden_dentry);
3461 + ASSERT(hidden_dentry->d_inode);
3462 + ASSERT(hidden_dentry->d_inode->i_op);
3464 + if (hidden_dentry->d_inode->i_op->getxattr) {
3465 + encoded_name = (char *)name;
3466 + encoded_value = (char *)value;
3468 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
3469 + mutex_lock(&hidden_dentry->d_inode->i_mutex);
3471 + down(&hidden_dentry->d_inode->i_sem);
3473 + /* lock_kernel() already done by caller. */
3474 + err = hidden_dentry->d_inode->i_op->getxattr(hidden_dentry, encoded_name, encoded_value, size);
3475 + /* unlock_kernel() will be done by caller. */
3476 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
3477 + mutex_lock(&hidden_dentry->d_inode->i_mutex);
3479 + up(&hidden_dentry->d_inode->i_sem);
3485 +/* BKL held by caller.
3486 + * dentry->d_inode->i_sem down
3489 +#if ((LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,21) \
3490 + && LINUX_VERSION_CODE <= KERNEL_VERSION(2,4,23)) \
3491 + || LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0))
3492 +mini_fo_setxattr(struct dentry *dentry, const char *name,
3493 + const void *value, size_t size, int flags)
3495 +mini_fo_setxattr(struct dentry *dentry, const char *name,
3496 + void *value, size_t size, int flags)
3500 + struct dentry *hidden_dentry = NULL;
3501 + int err = -EOPNOTSUPP;
3503 + /* Define these anyway, so we don't have as much ifdef'ed code. */
3504 + char *encoded_value = NULL;
3505 + char *encoded_name = NULL;
3507 + check_mini_fo_dentry(dentry);
3509 + if(exists_in_storage(dentry))
3510 + hidden_dentry = dtohd2(dentry);
3512 + hidden_dentry = dtohd(dentry);
3514 + ASSERT(hidden_dentry);
3515 + ASSERT(hidden_dentry->d_inode);
3516 + ASSERT(hidden_dentry->d_inode->i_op);
3518 + if (hidden_dentry->d_inode->i_op->setxattr) {
3519 + encoded_name = (char *)name;
3520 + encoded_value = (char *)value;
3522 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
3523 + mutex_lock(&hidden_dentry->d_inode->i_mutex);
3525 + down(&hidden_dentry->d_inode->i_sem);
3527 + /* lock_kernel() already done by caller. */
3528 + err = hidden_dentry->d_inode->i_op->setxattr(hidden_dentry, encoded_name, encoded_value, size, flags);
3529 + /* unlock_kernel() will be done by caller. */
3530 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
3531 + mutex_unlock(&hidden_dentry->d_inode->i_mutex);
3533 + up(&hidden_dentry->d_inode->i_sem);
3539 +/* BKL held by caller.
3540 + * dentry->d_inode->i_sem down
3543 +mini_fo_removexattr(struct dentry *dentry, const char *name) {
3544 + struct dentry *hidden_dentry = NULL;
3545 + int err = -EOPNOTSUPP;
3546 + char *encoded_name;
3548 + check_mini_fo_dentry(dentry);
3550 + if(exists_in_storage(dentry))
3551 + hidden_dentry = dtohd2(dentry);
3553 + hidden_dentry = dtohd(dentry);
3555 + ASSERT(hidden_dentry);
3556 + ASSERT(hidden_dentry->d_inode);
3557 + ASSERT(hidden_dentry->d_inode->i_op);
3559 + if (hidden_dentry->d_inode->i_op->removexattr) {
3560 + encoded_name = (char *)name;
3562 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
3563 + mutex_lock(&hidden_dentry->d_inode->i_mutex);
3565 + down(&hidden_dentry->d_inode->i_sem);
3567 + /* lock_kernel() already done by caller. */
3568 + err = hidden_dentry->d_inode->i_op->removexattr(hidden_dentry, encoded_name);
3569 + /* unlock_kernel() will be done by caller. */
3570 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
3571 + mutex_unlock(&hidden_dentry->d_inode->i_mutex);
3573 + up(&hidden_dentry->d_inode->i_sem);
3579 +/* BKL held by caller.
3580 + * dentry->d_inode->i_sem down
3583 +mini_fo_listxattr(struct dentry *dentry, char *list, size_t size) {
3584 + struct dentry *hidden_dentry = NULL;
3585 + int err = -EOPNOTSUPP;
3586 + char *encoded_list = NULL;
3588 + check_mini_fo_dentry(dentry);
3590 + if(exists_in_storage(dentry))
3591 + hidden_dentry = dtohd2(dentry);
3593 + hidden_dentry = dtohd(dentry);
3595 + ASSERT(hidden_dentry);
3596 + ASSERT(hidden_dentry->d_inode);
3597 + ASSERT(hidden_dentry->d_inode->i_op);
3599 + if (hidden_dentry->d_inode->i_op->listxattr) {
3600 + encoded_list = list;
3602 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
3603 + mutex_lock(&hidden_dentry->d_inode->i_mutex);
3605 + down(&hidden_dentry->d_inode->i_sem);
3607 + /* lock_kernel() already done by caller. */
3608 + err = hidden_dentry->d_inode->i_op->listxattr(hidden_dentry, encoded_list, size);
3609 + /* unlock_kernel() will be done by caller. */
3610 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
3611 + mutex_unlock(&hidden_dentry->d_inode->i_mutex);
3613 + up(&hidden_dentry->d_inode->i_sem);
3618 +# endif /* defined(XATTR) && (LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,20)) */
3620 +struct inode_operations mini_fo_symlink_iops =
3622 + readlink: mini_fo_readlink,
3623 + follow_link: mini_fo_follow_link,
3624 + /* mk: permission: mini_fo_permission, */
3625 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
3626 + revalidate: mini_fo_inode_revalidate,
3628 + setattr: mini_fo_setattr,
3629 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
3630 + getattr: mini_fo_getattr,
3631 + put_link: mini_fo_put_link,
3634 +#if defined(XATTR) && (LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,20))
3635 + setxattr: mini_fo_setxattr,
3636 + getxattr: mini_fo_getxattr,
3637 + listxattr: mini_fo_listxattr,
3638 + removexattr: mini_fo_removexattr
3639 +# endif /* defined(XATTR) && (LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,20)) */
3642 +struct inode_operations mini_fo_dir_iops =
3644 + create: mini_fo_create,
3645 + lookup: mini_fo_lookup,
3646 + link: mini_fo_link,
3647 + unlink: mini_fo_unlink,
3648 + symlink: mini_fo_symlink,
3649 + mkdir: mini_fo_mkdir,
3650 + rmdir: mini_fo_rmdir,
3651 + mknod: mini_fo_mknod,
3652 + rename: mini_fo_rename,
3653 + /* no readlink/follow_link for non-symlinks */
3654 + // off because we have setattr
3655 + // truncate: mini_fo_truncate,
3656 + /* mk:permission: mini_fo_permission, */
3657 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
3658 + revalidate: mini_fo_inode_revalidate,
3660 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
3661 + getattr: mini_fo_getattr,
3663 + setattr: mini_fo_setattr,
3664 +#if defined(XATTR) && (LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,20))
3665 + setxattr: mini_fo_setxattr,
3666 + getxattr: mini_fo_getxattr,
3667 + listxattr: mini_fo_listxattr,
3668 + removexattr: mini_fo_removexattr
3669 +# endif /* XATTR && LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,20) */
3672 +struct inode_operations mini_fo_main_iops =
3674 + /* permission: mini_fo_permission, */
3675 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
3676 + revalidate: mini_fo_inode_revalidate,
3678 + setattr: mini_fo_setattr,
3680 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
3681 + getattr: mini_fo_getattr,
3683 +#if defined(XATTR) && (LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,20))
3684 + setxattr: mini_fo_setxattr,
3685 + getxattr: mini_fo_getxattr,
3686 + listxattr: mini_fo_listxattr,
3687 + removexattr: mini_fo_removexattr
3688 +# endif /* XATTR && LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,20) */
3690 diff -urN linux.old/fs/mini_fo/main.c linux.dev/fs/mini_fo/main.c
3691 --- linux.old/fs/mini_fo/main.c 1970-01-01 01:00:00.000000000 +0100
3692 +++ linux.dev/fs/mini_fo/main.c 2006-10-30 03:42:09.000000000 +0100
3695 + * Copyright (c) 1997-2003 Erez Zadok
3696 + * Copyright (c) 2001-2003 Stony Brook University
3698 + * For specific licensing information, see the COPYING file distributed with
3699 + * this package, or get one from ftp://ftp.filesystems.org/pub/fist/COPYING.
3701 + * This Copyright notice must be kept intact and distributed with all
3702 + * fistgen sources INCLUDING sources generated by fistgen.
3705 + * Copyright (C) 2004, 2005 Markus Klotzbuecher <mk@creamnet.de>
3707 + * This program is free software; you can redistribute it and/or
3708 + * modify it under the terms of the GNU General Public License
3709 + * as published by the Free Software Foundation; either version
3710 + * 2 of the License, or (at your option) any later version.
3717 +#ifdef HAVE_CONFIG_H
3718 +# include <config.h>
3722 +#include "mini_fo.h"
3723 +#include <linux/module.h>
3725 +/* This definition must only appear after we include <linux/module.h> */
3726 +#ifndef MODULE_LICENSE
3727 +# define MODULE_LICENSE(bison)
3728 +#endif /* not MODULE_LICENSE */
3731 + * This is the mini_fo tri interpose function, which extends the
3732 + * functionality of the regular interpose by interposing a higher
3733 + * level inode on top of two lower level ones: the base filesystem
3734 + * inode and the storage filesystem inode.
3736 + * sb we pass is mini_fo's super_block
3739 +mini_fo_tri_interpose(dentry_t *hidden_dentry,
3740 + dentry_t *hidden_sto_dentry,
3741 + dentry_t *dentry, super_block_t *sb, int flag)
3743 + inode_t *hidden_inode = NULL;
3744 + inode_t *hidden_sto_inode = NULL; /* store corresponding storage inode */
3748 + /* Pointer to hidden_sto_inode if exists, else to hidden_inode.
3749 + * This is used to copy the attributes of the correct inode. */
3750 + inode_t *master_inode;
3753 + hidden_inode = hidden_dentry->d_inode;
3754 + if(hidden_sto_dentry)
3755 + hidden_sto_inode = hidden_sto_dentry->d_inode;
3757 + ASSERT(dentry->d_inode == NULL);
3759 + /* mk: One of the inodes associated with the dentrys is likely to
3760 + * be NULL, so carefull:
3762 + ASSERT((hidden_inode != NULL) || (hidden_sto_inode != NULL));
3764 + if(hidden_sto_inode)
3765 + master_inode = hidden_sto_inode;
3767 + master_inode = hidden_inode;
3770 + * We allocate our new inode below, by calling iget.
3771 + * iget will call our read_inode which will initialize some
3772 + * of the new inode's fields
3776 + * original: inode = iget(sb, hidden_inode->i_ino);
3778 + inode = iget(sb, iunique(sb, 25));
3780 + err = -EACCES; /* should be impossible??? */
3785 + * interpose the inode if not already interposed
3786 + * this is possible if the inode is being reused
3787 + * XXX: what happens if we get_empty_inode() but there's another already?
3788 + * for now, ASSERT() that this can't happen; fix later.
3790 + if (itohi(inode) != NULL) {
3791 + printk(KERN_CRIT "mini_fo_tri_interpose: itohi(inode) != NULL.\n");
3793 + if (itohi2(inode) != NULL) {
3794 + printk(KERN_CRIT "mini_fo_tri_interpose: itohi2(inode) != NULL.\n");
3797 + /* mk: Carefull, igrab can't handle NULL inodes (ok, why should it?), so
3798 + * we need to check here:
3801 + itohi(inode) = igrab(hidden_inode);
3803 + itohi(inode) = NULL;
3805 + if(hidden_sto_inode)
3806 + itohi2(inode) = igrab(hidden_sto_inode);
3808 + itohi2(inode) = NULL;
3811 + /* Use different set of inode ops for symlinks & directories*/
3812 + if (S_ISLNK(master_inode->i_mode))
3813 + inode->i_op = &mini_fo_symlink_iops;
3814 + else if (S_ISDIR(master_inode->i_mode))
3815 + inode->i_op = &mini_fo_dir_iops;
3817 + /* Use different set of file ops for directories */
3818 + if (S_ISDIR(master_inode->i_mode))
3819 + inode->i_fop = &mini_fo_dir_fops;
3821 + /* properly initialize special inodes */
3822 + if (S_ISBLK(master_inode->i_mode) || S_ISCHR(master_inode->i_mode) ||
3823 + S_ISFIFO(master_inode->i_mode) || S_ISSOCK(master_inode->i_mode)) {
3824 + init_special_inode(inode, master_inode->i_mode, master_inode->i_rdev);
3827 + /* Fix our inode's address operations to that of the lower inode */
3828 + if (inode->i_mapping->a_ops != master_inode->i_mapping->a_ops) {
3829 + inode->i_mapping->a_ops = master_inode->i_mapping->a_ops;
3832 + /* only (our) lookup wants to do a d_add */
3834 + d_add(dentry, inode);
3836 + d_instantiate(dentry, inode);
3838 + ASSERT(dtopd(dentry) != NULL);
3840 + /* all well, copy inode attributes */
3841 + fist_copy_attr_all(inode, master_inode);
3847 +/* parse mount options "base=" and "sto=" */
3849 +mini_fo_parse_options(super_block_t *sb, char *options)
3851 + dentry_t *hidden_root = ERR_PTR(-EINVAL);
3852 + dentry_t *hidden_root2 = ERR_PTR(-EINVAL);
3853 + struct nameidata nd, nd2;
3854 + char *name, *tmp, *end;
3857 + /* We don't want to go off the end of our arguments later on. */
3858 + for (end = options; *end; end++);
3860 + while (options < end) {
3862 + while (*tmp && *tmp != ',')
3865 + if (!strncmp("base=", options, 5)) {
3866 + name = options + 5;
3867 + printk(KERN_INFO "mini_fo: using base directory: %s\n", name);
3869 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
3870 + if (path_init(name, LOOKUP_FOLLOW, &nd))
3871 + err = path_walk(name, &nd);
3873 + err = path_lookup(name, LOOKUP_FOLLOW, &nd);
3876 + printk(KERN_CRIT "mini_fo: error accessing hidden directory '%s'\n", name);
3877 + hidden_root = ERR_PTR(err);
3880 + hidden_root = nd.dentry;
3881 + stopd(sb)->base_dir_dentry = nd.dentry;
3882 + stopd(sb)->hidden_mnt = nd.mnt;
3884 + } else if(!strncmp("sto=", options, 4)) {
3885 + /* parse the storage dir */
3886 + name = options + 4;
3887 + printk(KERN_INFO "mini_fo: using storage directory: %s\n", name);
3888 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
3889 + if(path_init(name, LOOKUP_FOLLOW, &nd2))
3890 + err = path_walk(name, &nd2);
3892 + err = path_lookup(name, LOOKUP_FOLLOW, &nd2);
3895 + printk(KERN_CRIT "mini_fo: error accessing hidden storage directory '%s'\n", name);
3897 + hidden_root2 = ERR_PTR(err);
3900 + hidden_root2 = nd2.dentry;
3901 + stopd(sb)->storage_dir_dentry = nd2.dentry;
3902 + stopd(sb)->hidden_mnt2 = nd2.mnt;
3903 + stohs2(sb) = hidden_root2->d_sb;
3905 + /* validate storage dir, this is done in
3906 + * mini_fo_read_super for the base directory.
3908 + if (IS_ERR(hidden_root2)) {
3909 + printk(KERN_WARNING "mini_fo_parse_options: storage dentry lookup failed (err = %ld)\n", PTR_ERR(hidden_root2));
3912 + if (!hidden_root2->d_inode) {
3913 + printk(KERN_WARNING "mini_fo_parse_options: no storage dir to interpose on.\n");
3916 + stohs2(sb) = hidden_root2->d_sb;
3918 + printk(KERN_WARNING "mini_fo: unrecognized option '%s'\n", options);
3919 + hidden_root = ERR_PTR(-EINVAL);
3922 + options = tmp + 1;
3926 + if(IS_ERR(hidden_root2))
3927 + return hidden_root2;
3928 + return hidden_root;
3932 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
3937 +mini_fo_read_super(super_block_t *sb, void *raw_data, int silent)
3939 + dentry_t *hidden_root;
3943 + printk(KERN_WARNING "mini_fo_read_super: missing argument\n");
3948 + * Allocate superblock private data
3950 + __stopd(sb) = kmalloc(sizeof(struct mini_fo_sb_info), GFP_KERNEL);
3952 + printk(KERN_WARNING "%s: out of memory\n", __FUNCTION__);
3958 + hidden_root = mini_fo_parse_options(sb, raw_data);
3959 + if (IS_ERR(hidden_root)) {
3960 + printk(KERN_WARNING "mini_fo_read_super: lookup_dentry failed (err = %ld)\n", PTR_ERR(hidden_root));
3961 + err = PTR_ERR(hidden_root);
3964 + if (!hidden_root->d_inode) {
3965 + printk(KERN_WARNING "mini_fo_read_super: no directory to interpose on\n");
3968 + stohs(sb) = hidden_root->d_sb;
3971 + * Linux 2.4.2-ac3 and beyond has code in
3972 + * mm/filemap.c:generic_file_write() that requires sb->s_maxbytes
3973 + * to be populated. If not set, all write()s under that sb will
3976 + * Linux 2.4.4+ automatically sets s_maxbytes to MAX_NON_LFS;
3977 + * the filesystem should override it only if it supports LFS.
3979 + /* non-SCA code is good to go with LFS */
3980 + sb->s_maxbytes = hidden_root->d_sb->s_maxbytes;
3982 + sb->s_op = &mini_fo_sops;
3984 + * we can't use d_alloc_root if we want to use
3985 + * our own interpose function unchanged,
3986 + * so we simply replicate *most* of the code in d_alloc_root here
3988 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
3989 + sb->s_root = d_alloc(NULL, &(const struct qstr) { "/", 1, 0 });
3991 + sb->s_root = d_alloc(NULL, &(const struct qstr){hash: 0, name: "/", len : 1});
3993 + if (IS_ERR(sb->s_root)) {
3994 + printk(KERN_WARNING "mini_fo_read_super: d_alloc failed\n");
3999 + sb->s_root->d_op = &mini_fo_dops;
4000 + sb->s_root->d_sb = sb;
4001 + sb->s_root->d_parent = sb->s_root;
4003 + /* link the upper and lower dentries */
4004 + __dtopd(sb->s_root) = (struct mini_fo_dentry_info *)
4005 + kmalloc(sizeof(struct mini_fo_dentry_info), GFP_KERNEL);
4006 + if (!dtopd(sb->s_root)) {
4010 + dtopd(sb->s_root)->state = MODIFIED;
4011 + dtohd(sb->s_root) = hidden_root;
4013 + /* fanout relevant, interpose on storage root dentry too */
4014 + dtohd2(sb->s_root) = stopd(sb)->storage_dir_dentry;
4016 + /* ...and call tri-interpose to interpose root dir inodes
4017 + * if (mini_fo_interpose(hidden_root, sb->s_root, sb, 0))
4019 + if(mini_fo_tri_interpose(hidden_root, dtohd2(sb->s_root), sb->s_root, sb, 0))
4022 + /* initalize the wol list */
4023 + itopd(sb->s_root->d_inode)->deleted_list_size = -1;
4024 + itopd(sb->s_root->d_inode)->renamed_list_size = -1;
4025 + meta_build_lists(sb->s_root);
4032 + dput(hidden_root);
4033 + dput(dtohd2(sb->s_root)); /* release the hidden_sto_dentry too */
4036 + __stopd(sb) = NULL;
4039 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
4043 + return ERR_PTR(err);
4050 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
4051 +static struct super_block *mini_fo_get_sb(struct file_system_type *fs_type,
4052 + int flags, const char *dev_name,
4055 + return get_sb_nodev(fs_type, flags, raw_data, mini_fo_read_super);
4058 +void mini_fo_kill_block_super(struct super_block *sb)
4060 + generic_shutdown_super(sb);
4062 + * XXX: BUG: Halcrow: Things get unstable sometime after this point:
4063 + * lib/rwsem-spinlock.c:127: spin_is_locked on uninitialized
4064 + * fs/fs-writeback.c:402: spin_lock(fs/super.c:a0381828) already
4065 + * locked by fs/fs-writeback.c/402
4067 + * Apparently, someone's not releasing a lock on sb_lock...
4071 +static struct file_system_type mini_fo_fs_type = {
4072 + .owner = THIS_MODULE,
4073 + .name = "mini_fo",
4074 + .get_sb = mini_fo_get_sb,
4075 + .kill_sb = mini_fo_kill_block_super,
4081 +static DECLARE_FSTYPE(mini_fo_fs_type, "mini_fo", mini_fo_read_super, 0);
4084 +static int __init init_mini_fo_fs(void)
4086 + printk("Registering mini_fo version $Id$\n");
4087 + return register_filesystem(&mini_fo_fs_type);
4089 +static void __exit exit_mini_fo_fs(void)
4091 + printk("Unregistering mini_fo version $Id$\n");
4092 + unregister_filesystem(&mini_fo_fs_type);
4095 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
4099 +MODULE_AUTHOR("Erez Zadok <ezk@cs.sunysb.edu>");
4100 +MODULE_DESCRIPTION("FiST-generated mini_fo filesystem");
4101 +MODULE_LICENSE("GPL");
4103 +/* MODULE_PARM(fist_debug_var, "i"); */
4104 +/* MODULE_PARM_DESC(fist_debug_var, "Debug level"); */
4106 +module_init(init_mini_fo_fs)
4107 +module_exit(exit_mini_fo_fs)
4108 diff -urN linux.old/fs/mini_fo/Makefile linux.dev/fs/mini_fo/Makefile
4109 --- linux.old/fs/mini_fo/Makefile 1970-01-01 01:00:00.000000000 +0100
4110 +++ linux.dev/fs/mini_fo/Makefile 2006-10-30 03:42:09.000000000 +0100
4113 +# Makefile for mini_fo 2.4 and 2.6 Linux kernels
4115 +# Copyright (C) 2004, 2005 Markus Klotzbuecher <mk@creamnet.de>
4117 +# This program is free software; you can redistribute it and/or
4118 +# modify it under the terms of the GNU General Public License
4119 +# as published by the Free Software Foundation; either version
4120 +# 2 of the License, or (at your option) any later version.
4123 +obj-$(CONFIG_MINI_FO) := mini_fo.o
4124 +mini_fo-objs := meta.o dentry.o file.o inode.o main.o super.o state.o aux.o
4126 +O_TARGET := $(obj-$(CONFIG_MINI_FO))
4127 +obj-y := $(mini_fo-objs)
4129 +-include $(TOPDIR)/Rules.make
4132 +${mini_fo-objs}: mini_fo.h fist.h
4134 diff -urN linux.old/fs/mini_fo/meta.c linux.dev/fs/mini_fo/meta.c
4135 --- linux.old/fs/mini_fo/meta.c 1970-01-01 01:00:00.000000000 +0100
4136 +++ linux.dev/fs/mini_fo/meta.c 2006-10-30 03:42:09.000000000 +0100
4139 + * Copyright (C) 2004, 2005 Markus Klotzbuecher <mk@creamnet.de>
4141 + * This program is free software; you can redistribute it and/or
4142 + * modify it under the terms of the GNU General Public License
4143 + * as published by the Free Software Foundation; either version
4144 + * 2 of the License, or (at your option) any later version.
4147 +#ifdef HAVE_CONFIG_H
4148 +# include <config.h>
4149 +#endif /* HAVE_CONFIG_H */
4151 +#include "mini_fo.h"
4153 +int meta_build_lists(dentry_t *dentry)
4155 + struct mini_fo_inode_info *inode_info;
4157 + dentry_t *meta_dentry = 0;
4158 + file_t *meta_file = 0;
4159 + mm_segment_t old_fs;
4163 + struct vfsmount *meta_mnt;
4166 + inode_info = itopd(dentry->d_inode);
4167 + if(!(inode_info->deleted_list_size == -1 &&
4168 + inode_info->renamed_list_size == -1)) {
4169 + printk(KERN_CRIT "mini_fo: meta_build_lists: \
4170 + Error, list(s) not virgin.\n");
4174 + /* init our meta lists */
4175 + INIT_LIST_HEAD(&inode_info->deleted_list);
4176 + inode_info->deleted_list_size = 0;
4178 + INIT_LIST_HEAD(&inode_info->renamed_list);
4179 + inode_info->renamed_list_size = 0;
4181 + /* might there be a META-file? */
4182 + if(dtohd2(dentry) && dtohd2(dentry)->d_inode) {
4183 + meta_dentry = lookup_one_len(META_FILENAME,
4185 + strlen(META_FILENAME));
4186 + if(!meta_dentry->d_inode) {
4187 + dput(meta_dentry);
4190 + /* $%& err, is this correct? */
4191 + meta_mnt = stopd(dentry->d_inode->i_sb)->hidden_mnt2;
4195 + /* open META-file for reading */
4196 + meta_file = dentry_open(meta_dentry, meta_mnt, 0x0);
4197 + if(!meta_file || IS_ERR(meta_file)) {
4198 + printk(KERN_CRIT "mini_fo: meta_build_lists: \
4199 + ERROR opening META file.\n");
4203 + /* check if fs supports reading */
4204 + if(!meta_file->f_op->read) {
4205 + printk(KERN_CRIT "mini_fo: meta_build_lists: \
4206 + ERROR, fs does not support reading.\n");
4207 + goto out_err_close;
4210 + /* allocate a page for transfering the data */
4211 + buf = (void *) __get_free_page(GFP_KERNEL);
4213 + printk(KERN_CRIT "mini_fo: meta_build_lists: \
4214 + ERROR, out of mem.\n");
4215 + goto out_err_close;
4217 + meta_file->f_pos = 0;
4218 + old_fs = get_fs();
4219 + set_fs(KERNEL_DS);
4222 + bytes = meta_file->f_op->read(meta_file, buf, PAGE_SIZE, &meta_file->f_pos);
4223 + if(bytes == PAGE_SIZE) {
4224 + /* trim a cut off filename and adjust f_pos to get it next time */
4225 + for(c = (char*) buf+PAGE_SIZE;
4227 + c--, bytes--, meta_file->f_pos--);
4229 + entry = (char *) buf;
4230 + while(entry < (char *) buf+bytes) {
4234 + int old_len, new_len;
4236 + /* len without '\n'*/
4237 + len = (int) (strchr(entry, '\n') - entry);
4240 + /* format: "D filename" */
4241 + meta_list_add_d_entry(dentry,
4246 + /* format: "R path/xy/dir newDir" */
4247 + old_path = entry+2;
4248 + dir_name = strchr(old_path, ' ') + 1;
4249 + old_len = dir_name - old_path - 1;
4250 + new_len = ((int) entry) + len - ((int ) dir_name);
4251 + meta_list_add_r_entry(dentry,
4258 + /* unknown entry type detected */
4264 + } while(meta_file->f_pos < meta_dentry->d_inode->i_size);
4266 + free_page((unsigned long) buf);
4276 + dput(meta_dentry);
4279 + return 1; /* check this!!! inode_info->wol_size; */
4282 +/* cleanups up all lists and free's the mem by dentry */
4283 +int meta_put_lists(dentry_t *dentry)
4285 + if(!dentry || !dentry->d_inode) {
4286 + printk("mini_fo: meta_put_lists: invalid dentry passed.\n");
4289 + return __meta_put_lists(dentry->d_inode);
4292 +/* cleanups up all lists and free's the mem by inode */
4293 +int __meta_put_lists(inode_t *inode)
4296 + if(!inode || !itopd(inode)) {
4297 + printk("mini_fo: __meta_put_lists: invalid inode passed.\n");
4300 + err = __meta_put_d_list(inode);
4301 + err |= __meta_put_r_list(inode);
4305 +int meta_sync_lists(dentry_t *dentry)
4308 + if(!dentry || !dentry->d_inode) {
4309 + printk("mini_fo: meta_sync_lists: \
4310 + invalid dentry passed.\n");
4313 + err = meta_sync_d_list(dentry, 0);
4314 + err |= meta_sync_r_list(dentry, 1);
4319 +/* remove all D entries from the renamed list and free the mem */
4320 +int __meta_put_d_list(inode_t *inode)
4322 + struct list_head *tmp;
4323 + struct deleted_entry *del_entry;
4324 + struct mini_fo_inode_info *inode_info;
4326 + if(!inode || !itopd(inode)) {
4327 + printk(KERN_CRIT "mini_fo: __meta_put_d_list: \
4328 + invalid inode passed.\n");
4331 + inode_info = itopd(inode);
4333 + /* nuke the DELETED-list */
4334 + if(inode_info->deleted_list_size <= 0)
4337 + while(!list_empty(&inode_info->deleted_list)) {
4338 + tmp = inode_info->deleted_list.next;
4340 + del_entry = list_entry(tmp, struct deleted_entry, list);
4341 + kfree(del_entry->name);
4344 + inode_info->deleted_list_size = 0;
4349 +/* remove all R entries from the renamed list and free the mem */
4350 +int __meta_put_r_list(inode_t *inode)
4352 + struct list_head *tmp;
4353 + struct renamed_entry *ren_entry;
4354 + struct mini_fo_inode_info *inode_info;
4356 + if(!inode || !itopd(inode)) {
4357 + printk(KERN_CRIT "mini_fo: meta_put_r_list: invalid inode.\n");
4360 + inode_info = itopd(inode);
4362 + /* nuke the RENAMED-list */
4363 + if(inode_info->renamed_list_size <= 0)
4366 + while(!list_empty(&inode_info->renamed_list)) {
4367 + tmp = inode_info->renamed_list.next;
4369 + ren_entry = list_entry(tmp, struct renamed_entry, list);
4370 + kfree(ren_entry->new_name);
4371 + kfree(ren_entry->old_name);
4374 + inode_info->renamed_list_size = 0;
4379 +int meta_add_d_entry(dentry_t *dentry, const char *name, int len)
4382 + err = meta_list_add_d_entry(dentry, name, len);
4383 + err |= meta_write_d_entry(dentry,name,len);
4387 +/* add a D entry to the deleted list */
4388 +int meta_list_add_d_entry(dentry_t *dentry, const char *name, int len)
4390 + struct deleted_entry *del_entry;
4391 + struct mini_fo_inode_info *inode_info;
4393 + if(!dentry || !dentry->d_inode) {
4394 + printk(KERN_CRIT "mini_fo: meta_list_add_d_entry: \
4395 + invalid dentry passed.\n");
4398 + inode_info = itopd(dentry->d_inode);
4400 + if(inode_info->deleted_list_size < 0)
4403 + del_entry = (struct deleted_entry *)
4404 + kmalloc(sizeof(struct deleted_entry), GFP_KERNEL);
4405 + del_entry->name = (char*) kmalloc(len, GFP_KERNEL);
4406 + if(!del_entry || !del_entry->name) {
4407 + printk(KERN_CRIT "mini_fo: meta_list_add_d_entry: \
4409 + kfree(del_entry->name);
4414 + strncpy(del_entry->name, name, len);
4415 + del_entry->len = len;
4417 + list_add(&del_entry->list, &inode_info->deleted_list);
4418 + inode_info->deleted_list_size++;
4422 +int meta_add_r_entry(dentry_t *dentry,
4423 + const char *old_name, int old_len,
4424 + const char *new_name, int new_len)
4427 + err = meta_list_add_r_entry(dentry,
4428 + old_name, old_len,
4429 + new_name, new_len);
4430 + err |= meta_write_r_entry(dentry,
4431 + old_name, old_len,
4432 + new_name, new_len);
4436 +/* add a R entry to the renamed list */
4437 +int meta_list_add_r_entry(dentry_t *dentry,
4438 + const char *old_name, int old_len,
4439 + const char *new_name, int new_len)
4441 + struct renamed_entry *ren_entry;
4442 + struct mini_fo_inode_info *inode_info;
4444 + if(!dentry || !dentry->d_inode) {
4445 + printk(KERN_CRIT "mini_fo: meta_list_add_r_entry: \
4446 + invalid dentry passed.\n");
4449 + inode_info = itopd(dentry->d_inode);
4451 + if(inode_info->renamed_list_size < 0)
4454 + ren_entry = (struct renamed_entry *)
4455 + kmalloc(sizeof(struct renamed_entry), GFP_KERNEL);
4456 + ren_entry->old_name = (char*) kmalloc(old_len, GFP_KERNEL);
4457 + ren_entry->new_name = (char*) kmalloc(new_len, GFP_KERNEL);
4459 + if(!ren_entry || !ren_entry->old_name || !ren_entry->new_name) {
4460 + printk(KERN_CRIT "mini_fo: meta_list_add_r_entry: \
4462 + kfree(ren_entry->new_name);
4463 + kfree(ren_entry->old_name);
4468 + strncpy(ren_entry->old_name, old_name, old_len);
4469 + ren_entry->old_len = old_len;
4470 + strncpy(ren_entry->new_name, new_name, new_len);
4471 + ren_entry->new_len = new_len;
4473 + list_add(&ren_entry->list, &inode_info->renamed_list);
4474 + inode_info->renamed_list_size++;
4479 +int meta_remove_r_entry(dentry_t *dentry, const char *name, int len)
4482 + if(!dentry || !dentry->d_inode) {
4484 + "mini_fo: meta_remove_r_entry: \
4485 + invalid dentry passed.\n");
4489 + err = meta_list_remove_r_entry(dentry, name, len);
4490 + err |= meta_sync_lists(dentry);
4494 +int meta_list_remove_r_entry(dentry_t *dentry, const char *name, int len)
4496 + if(!dentry || !dentry->d_inode) {
4498 + "mini_fo: meta_list_remove_r_entry: \
4499 + invalid dentry passed.\n");
4502 + return __meta_list_remove_r_entry(dentry->d_inode, name, len);
4505 +int __meta_list_remove_r_entry(inode_t *inode, const char *name, int len)
4507 + struct list_head *tmp;
4508 + struct renamed_entry *ren_entry;
4509 + struct mini_fo_inode_info *inode_info;
4511 + if(!inode || !itopd(inode))
4513 + "mini_fo: __meta_list_remove_r_entry: \
4514 + invalid inode passed.\n");
4515 + inode_info = itopd(inode);
4517 + if(inode_info->renamed_list_size < 0)
4519 + if(inode_info->renamed_list_size == 0)
4522 + list_for_each(tmp, &inode_info->renamed_list) {
4523 + ren_entry = list_entry(tmp, struct renamed_entry, list);
4524 + if(ren_entry->new_len != len)
4527 + if(!strncmp(ren_entry->new_name, name, len)) {
4529 + kfree(ren_entry->new_name);
4530 + kfree(ren_entry->old_name);
4532 + inode_info->renamed_list_size--;
4540 +/* append a single D entry to the meta file */
4541 +int meta_write_d_entry(dentry_t *dentry, const char *name, int len)
4543 + dentry_t *meta_dentry = 0;
4544 + file_t *meta_file = 0;
4545 + mm_segment_t old_fs;
4548 + struct vfsmount *meta_mnt = 0;
4553 + if(itopd(dentry->d_inode)->deleted_list_size < 0) {
4558 + if(dtopd(dentry)->state == UNMODIFIED) {
4559 + err = build_sto_structure(dentry->d_parent, dentry);
4561 + printk(KERN_CRIT "mini_fo: meta_write_d_entry: \
4562 + build_sto_structure failed.\n");
4566 + meta_dentry = lookup_one_len(META_FILENAME,
4567 + dtohd2(dentry), strlen (META_FILENAME));
4569 + /* We need to create a META-file */
4570 + if(!meta_dentry->d_inode) {
4571 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
4572 + vfs_create(dtohd2(dentry)->d_inode,
4574 + S_IRUSR | S_IWUSR,
4577 + vfs_create(dtohd2(dentry)->d_inode,
4579 + S_IRUSR | S_IWUSR);
4582 + /* open META-file for writing */
4583 + meta_file = dentry_open(meta_dentry, meta_mnt, 0x1);
4584 + if(!meta_file || IS_ERR(meta_file)) {
4585 + printk(KERN_CRIT "mini_fo: meta_write_d_entry: \
4586 + ERROR opening meta file.\n");
4587 + mntput(meta_mnt); /* $%& is this necessary? */
4588 + dput(meta_dentry);
4593 + /* check if fs supports writing */
4594 + if(!meta_file->f_op->write) {
4595 + printk(KERN_CRIT "mini_fo: meta_write_d_entry: \
4596 + ERROR, fs does not support writing.\n");
4597 + goto out_err_close;
4600 + meta_file->f_pos = meta_dentry->d_inode->i_size; /* append */
4601 + old_fs = get_fs();
4602 + set_fs(KERNEL_DS);
4604 + /* size: len for name, 1 for \n and 2 for "D " */
4605 + buf = (char *) kmalloc(len+3, GFP_KERNEL);
4607 + printk(KERN_CRIT "mini_fo: meta_write_d_entry: \
4614 + strncpy(buf+2, name, len);
4615 + buf[len+2] = '\n';
4616 + bytes = meta_file->f_op->write(meta_file, buf, len+3,
4617 + &meta_file->f_pos);
4618 + if(bytes != len+3) {
4619 + printk(KERN_CRIT "mini_fo: meta_write_d_entry: \
4620 + ERROR writing.\n");
4632 +/* append a single R entry to the meta file */
4633 +int meta_write_r_entry(dentry_t *dentry,
4634 + const char *old_name, int old_len,
4635 + const char *new_name, int new_len)
4637 + dentry_t *meta_dentry = 0;
4638 + file_t *meta_file = 0;
4639 + mm_segment_t old_fs;
4641 + int bytes, err, buf_len;
4642 + struct vfsmount *meta_mnt = 0;
4648 + if(itopd(dentry->d_inode)->renamed_list_size < 0) {
4653 + /* build the storage structure? */
4654 + if(dtopd(dentry)->state == UNMODIFIED) {
4655 + err = build_sto_structure(dentry->d_parent, dentry);
4657 + printk(KERN_CRIT "mini_fo: meta_write_r_entry: \
4658 + build_sto_structure failed.\n");
4662 + meta_dentry = lookup_one_len(META_FILENAME,
4664 + strlen (META_FILENAME));
4665 + if(!meta_dentry->d_inode) {
4666 + /* We need to create a META-file */
4667 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
4668 + vfs_create(dtohd2(dentry)->d_inode,
4669 + meta_dentry, S_IRUSR | S_IWUSR, NULL);
4671 + vfs_create(dtohd2(dentry)->d_inode,
4672 + meta_dentry, S_IRUSR | S_IWUSR);
4675 + /* open META-file for writing */
4676 + meta_file = dentry_open(meta_dentry, meta_mnt, 0x1);
4677 + if(!meta_file || IS_ERR(meta_file)) {
4678 + printk(KERN_CRIT "mini_fo: meta_write_r_entry: \
4679 + ERROR opening meta file.\n");
4681 + dput(meta_dentry);
4686 + /* check if fs supports writing */
4687 + if(!meta_file->f_op->write) {
4688 + printk(KERN_CRIT "mini_fo: meta_write_r_entry: \
4689 + ERROR, fs does not support writing.\n");
4690 + goto out_err_close;
4693 + meta_file->f_pos = meta_dentry->d_inode->i_size; /* append */
4694 + old_fs = get_fs();
4695 + set_fs(KERNEL_DS);
4697 + /* size: 2 for "R ", old_len+new_len for names, 1 blank+1 \n */
4698 + buf_len = old_len + new_len + 4;
4699 + buf = (char *) kmalloc(buf_len, GFP_KERNEL);
4701 + printk(KERN_CRIT "mini_fo: meta_write_r_entry: out of mem.\n");
4707 + strncpy(buf + 2, old_name, old_len);
4708 + buf[old_len + 2] = ' ';
4709 + strncpy(buf + old_len + 3, new_name, new_len);
4710 + buf[buf_len -1] = '\n';
4711 + bytes = meta_file->f_op->write(meta_file, buf, buf_len, &meta_file->f_pos);
4712 + if(bytes != buf_len) {
4713 + printk(KERN_CRIT "mini_fo: meta_write_r_entry: ERROR writing.\n");
4726 +/* sync D list to disk, append data if app_flag is 1 */
4727 +/* check the meta_mnt, which seems not to be used (properly) */
4729 +int meta_sync_d_list(dentry_t *dentry, int app_flag)
4731 + dentry_t *meta_dentry;
4732 + file_t *meta_file;
4733 + mm_segment_t old_fs;
4736 + struct vfsmount *meta_mnt;
4739 + struct list_head *tmp;
4740 + struct deleted_entry *del_entry;
4741 + struct mini_fo_inode_info *inode_info;
4747 + if(!dentry || !dentry->d_inode) {
4748 + printk(KERN_CRIT "mini_fo: meta_sync_d_list: \
4749 + invalid inode passed.\n");
4753 + inode_info = itopd(dentry->d_inode);
4755 + if(inode_info->deleted_list_size < 0) {
4760 + /* ok, there is something to sync */
4762 + /* build the storage structure? */
4763 + if(!dtohd2(dentry) && !itohi2(dentry->d_inode)) {
4764 + err = build_sto_structure(dentry->d_parent, dentry);
4766 + printk(KERN_CRIT "mini_fo: meta_sync_d_list: \
4767 + build_sto_structure failed.\n");
4771 + meta_dentry = lookup_one_len(META_FILENAME,
4773 + strlen(META_FILENAME));
4774 + if(!meta_dentry->d_inode) {
4775 + /* We need to create a META-file */
4776 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
4777 + vfs_create(dtohd2(dentry)->d_inode,
4778 + meta_dentry, S_IRUSR | S_IWUSR, NULL);
4780 + vfs_create(dtohd2(dentry)->d_inode,
4781 + meta_dentry, S_IRUSR | S_IWUSR);
4785 + /* need we truncate the meta file? */
4787 + struct iattr newattrs;
4788 + newattrs.ia_size = 0;
4789 + newattrs.ia_valid = ATTR_SIZE | ATTR_CTIME;
4791 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
4792 + mutex_lock(&meta_dentry->d_inode->i_mutex);
4794 + down(&meta_dentry->d_inode->i_sem);
4796 + err = notify_change(meta_dentry, &newattrs);
4798 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
4799 + mutex_unlock(&meta_dentry->d_inode->i_mutex);
4801 + up(&meta_dentry->d_inode->i_sem);
4804 + if(err || meta_dentry->d_inode->i_size != 0) {
4805 + printk(KERN_CRIT "mini_fo: meta_sync_d_list: \
4806 + ERROR truncating meta file.\n");
4807 + goto out_err_close;
4811 + /* open META-file for writing */
4812 + meta_file = dentry_open(meta_dentry, meta_mnt, 0x1);
4813 + if(!meta_file || IS_ERR(meta_file)) {
4814 + printk(KERN_CRIT "mini_fo: meta_sync_d_list: \
4815 + ERROR opening meta file.\n");
4816 + /* we don't mntget so we dont't mntput (for now)
4817 + * mntput(meta_mnt);
4819 + dput(meta_dentry);
4824 + /* check if fs supports writing */
4825 + if(!meta_file->f_op->write) {
4826 + printk(KERN_CRIT "mini_fo: meta_sync_d_list: \
4827 + ERROR, fs does not support writing.\n");
4828 + goto out_err_close;
4831 + meta_file->f_pos = meta_dentry->d_inode->i_size; /* append */
4832 + old_fs = get_fs();
4833 + set_fs(KERNEL_DS);
4835 + /* here we go... */
4836 + list_for_each(tmp, &inode_info->deleted_list) {
4837 + del_entry = list_entry(tmp, struct deleted_entry, list);
4839 + /* size: len for name, 1 for \n and 2 for "D " */
4840 + buf = (char *) kmalloc(del_entry->len+3, GFP_KERNEL);
4842 + printk(KERN_CRIT "mini_fo: meta_sync_d_list: \
4849 + strncpy(buf+2, del_entry->name, del_entry->len);
4850 + buf[del_entry->len+2] = '\n';
4851 + bytes = meta_file->f_op->write(meta_file, buf,
4853 + &meta_file->f_pos);
4854 + if(bytes != del_entry->len+3) {
4855 + printk(KERN_CRIT "mini_fo: meta_sync_d_list: \
4856 + ERROR writing.\n");
4870 +int meta_sync_r_list(dentry_t *dentry, int app_flag)
4872 + dentry_t *meta_dentry;
4873 + file_t *meta_file;
4874 + mm_segment_t old_fs;
4876 + int bytes, err, buf_len;
4877 + struct vfsmount *meta_mnt;
4880 + struct list_head *tmp;
4881 + struct renamed_entry *ren_entry;
4882 + struct mini_fo_inode_info *inode_info;
4888 + if(!dentry || !dentry->d_inode) {
4889 + printk(KERN_CRIT "mini_fo: meta_sync_r_list: \
4890 + invalid dentry passed.\n");
4894 + inode_info = itopd(dentry->d_inode);
4896 + if(inode_info->deleted_list_size < 0) {
4901 + /* ok, there is something to sync */
4903 + /* build the storage structure? */
4904 + if(!dtohd2(dentry) && !itohi2(dentry->d_inode)) {
4905 + err = build_sto_structure(dentry->d_parent, dentry);
4907 + printk(KERN_CRIT "mini_fo: meta_sync_r_list: \
4908 + build_sto_structure failed.\n");
4912 + meta_dentry = lookup_one_len(META_FILENAME,
4914 + strlen(META_FILENAME));
4915 + if(!meta_dentry->d_inode) {
4916 + /* We need to create a META-file */
4917 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
4918 + vfs_create(dtohd2(dentry)->d_inode,
4919 + meta_dentry, S_IRUSR | S_IWUSR, NULL);
4921 + vfs_create(dtohd2(dentry)->d_inode,
4922 + meta_dentry, S_IRUSR | S_IWUSR);
4926 + /* need we truncate the meta file? */
4928 + struct iattr newattrs;
4929 + newattrs.ia_size = 0;
4930 + newattrs.ia_valid = ATTR_SIZE | ATTR_CTIME;
4932 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
4933 + mutex_lock(&meta_dentry->d_inode->i_mutex);
4935 + down(&meta_dentry->d_inode->i_sem);
4937 + err = notify_change(meta_dentry, &newattrs);
4939 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
4940 + mutex_unlock(&meta_dentry->d_inode->i_mutex);
4942 + up(&meta_dentry->d_inode->i_sem);
4944 + if(err || meta_dentry->d_inode->i_size != 0) {
4945 + printk(KERN_CRIT "mini_fo: meta_sync_r_list: \
4946 + ERROR truncating meta file.\n");
4947 + goto out_err_close;
4951 + /* open META-file for writing */
4952 + meta_file = dentry_open(meta_dentry, meta_mnt, 0x1);
4953 + if(!meta_file || IS_ERR(meta_file)) {
4954 + printk(KERN_CRIT "mini_fo: meta_sync_r_list: \
4955 + ERROR opening meta file.\n");
4956 + /* we don't mntget so we dont't mntput (for now)
4957 + * mntput(meta_mnt);
4959 + dput(meta_dentry);
4964 + /* check if fs supports writing */
4965 + if(!meta_file->f_op->write) {
4966 + printk(KERN_CRIT "mini_fo: meta_sync_r_list: \
4967 + ERROR, fs does not support writing.\n");
4968 + goto out_err_close;
4971 + meta_file->f_pos = meta_dentry->d_inode->i_size; /* append */
4972 + old_fs = get_fs();
4973 + set_fs(KERNEL_DS);
4975 + /* here we go... */
4976 + list_for_each(tmp, &inode_info->renamed_list) {
4977 + ren_entry = list_entry(tmp, struct renamed_entry, list);
4979 + * 2 for "R ", old_len+new_len for names, 1 blank+1 \n */
4980 + buf_len = ren_entry->old_len + ren_entry->new_len + 4;
4981 + buf = (char *) kmalloc(buf_len, GFP_KERNEL);
4983 + printk(KERN_CRIT "mini_fo: meta_sync_r_list: \
4989 + strncpy(buf + 2, ren_entry->old_name, ren_entry->old_len);
4990 + buf[ren_entry->old_len + 2] = ' ';
4991 + strncpy(buf + ren_entry->old_len + 3,
4992 + ren_entry->new_name, ren_entry->new_len);
4993 + buf[buf_len - 1] = '\n';
4994 + bytes = meta_file->f_op->write(meta_file, buf,
4995 + buf_len, &meta_file->f_pos);
4996 + if(bytes != buf_len) {
4997 + printk(KERN_CRIT "mini_fo: meta_sync_r_list: \
4998 + ERROR writing.\n");
5011 +int meta_check_d_entry(dentry_t *dentry, const char *name, int len)
5013 + if(!dentry || !dentry->d_inode)
5014 + printk(KERN_CRIT "mini_fo: meta_check_d_dentry: \
5015 + invalid dentry passed.\n");
5016 + return __meta_check_d_entry(dentry->d_inode, name, len);
5019 +int __meta_check_d_entry(inode_t *inode, const char *name, int len)
5021 + struct list_head *tmp;
5022 + struct deleted_entry *del_entry;
5023 + struct mini_fo_inode_info *inode_info;
5025 + if(!inode || !itopd(inode))
5026 + printk(KERN_CRIT "mini_fo: __meta_check_d_dentry: \
5027 + invalid inode passed.\n");
5029 + inode_info = itopd(inode);
5031 + if(inode_info->deleted_list_size <= 0)
5034 + list_for_each(tmp, &inode_info->deleted_list) {
5035 + del_entry = list_entry(tmp, struct deleted_entry, list);
5036 + if(del_entry->len != len)
5039 + if(!strncmp(del_entry->name, name, len))
5046 + * check if file has been renamed and return path to orig. base dir.
5047 + * Implements no error return values so far, what of course sucks.
5048 + * String is null terminated.'
5050 +char* meta_check_r_entry(dentry_t *dentry, const char *name, int len)
5052 + if(!dentry || !dentry->d_inode) {
5053 + printk(KERN_CRIT "mini_fo: meta_check_r_dentry: \
5054 + invalid dentry passed.\n");
5057 + return __meta_check_r_entry(dentry->d_inode, name, len);
5060 +char* __meta_check_r_entry(inode_t *inode, const char *name, int len)
5062 + struct list_head *tmp;
5063 + struct renamed_entry *ren_entry;
5064 + struct mini_fo_inode_info *inode_info;
5067 + if(!inode || !itopd(inode)) {
5068 + printk(KERN_CRIT "mini_fo: meta_check_r_dentry: \
5069 + invalid inode passed.\n");
5072 + inode_info = itopd(inode);
5074 + if(inode_info->renamed_list_size <= 0)
5077 + list_for_each(tmp, &inode_info->renamed_list) {
5078 + ren_entry = list_entry(tmp, struct renamed_entry, list);
5079 + if(ren_entry->new_len != len)
5082 + if(!strncmp(ren_entry->new_name, name, len)) {
5083 + old_path = (char *)
5084 + kmalloc(ren_entry->old_len+1, GFP_KERNEL);
5086 + ren_entry->old_name,
5087 + ren_entry->old_len);
5088 + old_path[ren_entry->old_len]='\0';
5096 + * This version only checks if entry exists and return:
5101 +int meta_is_r_entry(dentry_t *dentry, const char *name, int len)
5103 + if(!dentry || !dentry->d_inode) {
5104 + printk(KERN_CRIT "mini_fo: meta_check_r_dentry [2]: \
5105 + invalid dentry passed.\n");
5108 + return __meta_is_r_entry(dentry->d_inode, name, len);
5111 +int __meta_is_r_entry(inode_t *inode, const char *name, int len)
5113 + struct list_head *tmp;
5114 + struct renamed_entry *ren_entry;
5115 + struct mini_fo_inode_info *inode_info;
5117 + if(!inode || !itopd(inode)) {
5118 + printk(KERN_CRIT "mini_fo: meta_check_r_dentry [2]: \
5119 + invalid inode passed.\n");
5122 + inode_info = itopd(inode);
5124 + if(inode_info->renamed_list_size <= 0)
5127 + list_for_each(tmp, &inode_info->renamed_list) {
5128 + ren_entry = list_entry(tmp, struct renamed_entry, list);
5129 + if(ren_entry->new_len != len)
5132 + if(!strncmp(ren_entry->new_name, name, len))
5138 diff -urN linux.old/fs/mini_fo/mini_fo.h linux.dev/fs/mini_fo/mini_fo.h
5139 --- linux.old/fs/mini_fo/mini_fo.h 1970-01-01 01:00:00.000000000 +0100
5140 +++ linux.dev/fs/mini_fo/mini_fo.h 2006-10-30 03:42:09.000000000 +0100
5143 + * Copyright (c) 1997-2003 Erez Zadok
5144 + * Copyright (c) 2001-2003 Stony Brook University
5146 + * For specific licensing information, see the COPYING file distributed with
5147 + * this package, or get one from ftp://ftp.filesystems.org/pub/fist/COPYING.
5149 + * This Copyright notice must be kept intact and distributed with all
5150 + * fistgen sources INCLUDING sources generated by fistgen.
5153 + * Copyright (C) 2004, 2005 Markus Klotzbuecher <mk@creamnet.de>
5155 + * This program is free software; you can redistribute it and/or
5156 + * modify it under the terms of the GNU General Public License
5157 + * as published by the Free Software Foundation; either version
5158 + * 2 of the License, or (at your option) any later version.
5165 +#ifndef __MINI_FO_H_
5166 +#define __MINI_FO_H_
5171 +#define META_FILENAME "META_dAfFgHE39ktF3HD2sr"
5176 +/* File attributes that when changed, result in a file beeing copied to storage */
5177 +#define COPY_FLAGS ATTR_MODE | ATTR_UID | ATTR_GID | ATTR_SIZE
5180 + * mini_fo filestates
5183 +#define UNMODIFIED 2
5185 +#define DEL_REWRITTEN 4
5187 +#define NON_EXISTANT 6
5189 +/* fist file systems superblock magic */
5190 +# define MINI_FO_SUPER_MAGIC 0xf15f
5196 +/* mini_fo inode data in memory */
5197 +struct mini_fo_inode_info {
5198 + inode_t *wii_inode;
5199 + inode_t *wii_inode2; /* pointer to storage inode */
5201 + /* META-data lists */
5202 + /* deleted list, ex wol */
5203 + struct list_head deleted_list;
5204 + int deleted_list_size;
5206 + /* renamed list */
5207 + struct list_head renamed_list;
5208 + int renamed_list_size;
5210 + /* add other lists here ... */
5213 +/* mini_fo dentry data in memory */
5214 +struct mini_fo_dentry_info {
5215 + dentry_t *wdi_dentry;
5216 + dentry_t *wdi_dentry2; /* pointer to storage dentry */
5217 + unsigned int state; /* state of the mini_fo dentry */
5221 +/* mini_fo super-block data in memory */
5222 +struct mini_fo_sb_info {
5223 + super_block_t *wsi_sb, *wsi_sb2; /* mk: might point to the same sb */
5224 + struct vfsmount *hidden_mnt, *hidden_mnt2;
5225 + dentry_t *base_dir_dentry;
5226 + dentry_t *storage_dir_dentry;
5230 +/* readdir_data, readdir helper struct */
5231 +struct readdir_data {
5232 + struct list_head ndl_list; /* linked list head ptr */
5233 + int ndl_size; /* list size */
5234 + int sto_done; /* flag to show that the storage dir entries have
5235 + * all been read an now follow base entries */
5238 +/* file private data. */
5239 +struct mini_fo_file_info {
5240 + struct file *wfi_file;
5241 + struct file *wfi_file2; /* pointer to storage file */
5242 + struct readdir_data rd;
5245 +/* struct ndl_entry */
5247 + struct list_head list;
5252 +/********************************
5253 + * META-data structures
5254 + ********************************/
5256 +/* deleted entry */
5257 +struct deleted_entry {
5258 + struct list_head list;
5263 +/* renamed entry */
5264 +struct renamed_entry {
5265 + struct list_head list;
5266 + char *old_name; /* old directory with full path */
5267 + int old_len; /* length of above string */
5268 + char *new_name; /* new directory name */
5269 + int new_len; /* length of above string */
5272 +/* attr_change entry */
5273 +struct attr_change_entry {
5274 + struct list_head list;
5280 +struct link_entry {
5281 + struct list_head list;
5286 + int weird_name_len;
5290 +/* Some other stuff required for mini_fo_filldir64, copied from
5294 +#define ROUND_UP64(x) (((x)+sizeof(u64)-1) & ~(sizeof(u64)-1))
5295 +#define NAME_OFFSET(de) ((int) ((de)->d_name - (char *) (de)))
5298 +struct linux_dirent64 {
5301 + unsigned short d_reclen;
5302 + unsigned char d_type;
5307 +struct getdents_callback64 {
5308 + struct linux_dirent64 * current_dir;
5309 + struct linux_dirent64 * previous;
5314 +struct linux_dirent {
5315 + unsigned long d_ino;
5316 + unsigned long d_off;
5317 + unsigned short d_reclen;
5321 +struct getdents_callback {
5322 + struct linux_dirent * current_dir;
5323 + struct linux_dirent * previous;
5333 +/* file TO private_data */
5334 +# define ftopd(file) ((struct mini_fo_file_info *)((file)->private_data))
5335 +# define __ftopd(file) ((file)->private_data)
5336 +/* file TO hidden_file */
5337 +# define ftohf(file) ((ftopd(file))->wfi_file)
5338 +# define ftohf2(file) ((ftopd(file))->wfi_file2)
5340 +/* inode TO private_data */
5341 +# define itopd(ino) ((struct mini_fo_inode_info *)(ino)->u.generic_ip)
5342 +# define __itopd(ino) ((ino)->u.generic_ip)
5343 +/* inode TO hidden_inode */
5344 +# define itohi(ino) (itopd(ino)->wii_inode)
5345 +# define itohi2(ino) (itopd(ino)->wii_inode2)
5347 +/* superblock TO private_data */
5348 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
5349 +# define stopd(super) ((struct mini_fo_sb_info *)(super)->s_fs_info)
5350 +# define __stopd(super) ((super)->s_fs_info)
5352 +# define stopd(super) ((struct mini_fo_sb_info *)(super)->u.generic_sbp)
5353 +# define __stopd(super) ((super)->u.generic_sbp)
5356 +/* unused? # define vfs2priv stopd */
5357 +/* superblock TO hidden_superblock */
5359 +# define stohs(super) (stopd(super)->wsi_sb)
5360 +# define stohs2(super) (stopd(super)->wsi_sb2)
5362 +/* dentry TO private_data */
5363 +# define dtopd(dentry) ((struct mini_fo_dentry_info *)(dentry)->d_fsdata)
5364 +# define __dtopd(dentry) ((dentry)->d_fsdata)
5365 +/* dentry TO hidden_dentry */
5366 +# define dtohd(dent) (dtopd(dent)->wdi_dentry)
5367 +# define dtohd2(dent) (dtopd(dent)->wdi_dentry2)
5369 +/* dentry to state */
5370 +# define dtost(dent) (dtopd(dent)->state)
5371 +# define sbt(sb) ((sb)->s_type->name)
5373 +#define IS_WRITE_FLAG(flag) (flag & (O_RDWR | O_WRONLY | O_APPEND))
5374 +#define IS_COPY_FLAG(flag) (flag & (COPY_FLAGS))
5376 +/* macros to simplify non-SCA code */
5377 +# define MALLOC_PAGE_POINTERS(hidden_pages, num_hidden_pages)
5378 +# define MALLOC_PAGEDATA_POINTERS(hidden_pages_data, num_hidden_pages)
5379 +# define FREE_PAGE_POINTERS(hidden_pages, num)
5380 +# define FREE_PAGEDATA_POINTERS(hidden_pages_data, num)
5381 +# define FOR_EACH_PAGE
5382 +# define CURRENT_HIDDEN_PAGE hidden_page
5383 +# define CURRENT_HIDDEN_PAGEDATA hidden_page_data
5384 +# define CURRENT_HIDDEN_PAGEINDEX page->index
5389 +extern struct file_operations mini_fo_main_fops;
5390 +extern struct file_operations mini_fo_dir_fops;
5391 +extern struct inode_operations mini_fo_main_iops;
5392 +extern struct inode_operations mini_fo_dir_iops;
5393 +extern struct inode_operations mini_fo_symlink_iops;
5394 +extern struct super_operations mini_fo_sops;
5395 +extern struct dentry_operations mini_fo_dops;
5396 +extern struct vm_operations_struct mini_fo_shared_vmops;
5397 +extern struct vm_operations_struct mini_fo_private_vmops;
5398 +extern struct address_space_operations mini_fo_aops;
5400 +#if 0 /* unused by mini_fo */
5401 +extern int mini_fo_interpose(dentry_t *hidden_dentry, dentry_t *this_dentry, super_block_t *sb, int flag);
5402 +#if defined(FIST_FILTER_DATA) || defined(FIST_FILTER_SCA)
5403 +extern page_t *mini_fo_get1page(file_t *file, int index);
5404 +extern int mini_fo_fill_zeros(file_t *file, page_t *page, unsigned from);
5405 +# endif /* FIST_FILTER_DATA || FIST_FILTER_SCA */
5408 +# define mini_fo_hidden_dentry(d) __mini_fo_hidden_dentry(__FILE__,__FUNCTION__,__LINE__,(d))
5409 +# define mini_fo_hidden_sto_dentry(d) __mini_fo_hidden_sto_dentry(__FILE__,__FUNCTION__,__LINE__,(d))
5411 +extern dentry_t *__mini_fo_hidden_dentry(char *file, char *func, int line, dentry_t *this_dentry);
5412 +extern dentry_t *__mini_fo_hidden_sto_dentry(char *file, char *func, int line, dentry_t *this_dentry);
5414 +extern int mini_fo_read_file(const char *filename, void *buf, int len);
5415 +extern int mini_fo_write_file(const char *filename, void *buf, int len);
5416 +extern dentry_t *fist_lookup(dentry_t *dir, const char *name, vnode_t **out, uid_t uid, gid_t gid);
5417 +#endif /* unused by mini_fo */
5419 +/* state transition functions */
5420 +extern int nondir_unmod_to_mod(dentry_t *dentry, int cp_flag);
5421 +extern int nondir_del_rew_to_del(dentry_t *dentry);
5422 +extern int nondir_creat_to_del(dentry_t *dentry);
5423 +extern int nondir_mod_to_del(dentry_t *dentry);
5424 +extern int nondir_unmod_to_del(dentry_t *dentry);
5426 +extern int dir_unmod_to_mod(dentry_t *dentry);
5428 +/* rename specials */
5429 +extern int rename_directory(inode_t *old_dir, dentry_t *old_dentry, inode_t *new_dir, dentry_t *new_dentry);
5430 +extern int rename_nondir(inode_t *old_dir, dentry_t *old_dentry, inode_t *new_dir, dentry_t *new_dentry);
5433 +extern int mini_fo_tri_interpose(dentry_t *hidden_dentry,
5434 + dentry_t *hidden_sto_dentry,
5436 + super_block_t *sb, int flag);
5438 +extern int mini_fo_cp_cont(dentry_t *tgt_dentry, struct vfsmount *tgt_mnt,
5439 + dentry_t *src_dentry, struct vfsmount *src_mnt);
5441 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
5442 +extern int mini_fo_create(inode_t *dir, dentry_t *dentry, int mode, struct nameidata *nd);
5444 +extern int create_sto_nod(dentry_t *dentry, int mode, dev_t dev);
5445 +extern int create_sto_reg_file(dentry_t *dentry, int mode, struct nameidata *nd);
5447 +extern int mini_fo_create(inode_t *dir, dentry_t *dentry, int mode);
5449 +extern int create_sto_nod(dentry_t *dentry, int mode, int dev);
5450 +extern int create_sto_reg_file(dentry_t *dentry, int mode);
5453 +extern int create_sto_dir(dentry_t *dentry, int mode);
5455 +extern int exists_in_storage(dentry_t *dentry);
5456 +extern int is_mini_fo_existant(dentry_t *dentry);
5457 +extern int get_neg_sto_dentry(dentry_t *dentry);
5458 +extern int build_sto_structure(dentry_t *dir, dentry_t *dentry);
5459 +extern int get_mini_fo_bpath(dentry_t *dentry, char **bpath, int *bpath_len);
5460 +extern dentry_t *bpath_walk(super_block_t *sb, char *bpath);
5461 +extern int bpath_put(dentry_t *dentry);
5463 +/* check_mini_fo types functions */
5464 +extern int check_mini_fo_dentry(dentry_t *dentry);
5465 +extern int check_mini_fo_file(file_t *file);
5466 +extern int check_mini_fo_inode(inode_t *inode);
5468 +/* General meta functions, can be called from outside of meta.c */
5469 +extern int meta_build_lists(dentry_t *dentry);
5470 +extern int meta_put_lists(dentry_t *dentry);
5471 +extern int __meta_put_lists(inode_t *inode);
5473 +extern int meta_add_d_entry(dentry_t *dentry, const char *name, int len);
5474 +extern int meta_add_r_entry(dentry_t *dentry,
5475 + const char *old_name, int old_len,
5476 + const char *new_name, int new_len);
5478 +extern int meta_remove_r_entry(dentry_t *dentry, const char *name, int len);
5480 +extern int meta_check_d_entry(dentry_t *dentry, const char *name, int len);
5481 +extern int __meta_check_d_entry(inode_t *inode, const char *name, int len);
5483 +extern char* meta_check_r_entry(dentry_t *dentry, const char *name, int len);
5484 +extern char* __meta_check_r_entry(inode_t *inode, const char *name, int len);
5485 +extern int meta_is_r_entry(dentry_t *dentry, const char *name, int len);
5486 +extern int __meta_is_r_entry(inode_t *inode, const char *name, int len);
5488 +/* Specific meta functions, should be called only inside meta.c */
5489 +extern int __meta_put_d_list(inode_t *inode);
5490 +extern int __meta_put_r_list(inode_t *inode);
5492 +extern int meta_list_add_d_entry(dentry_t *dentry,
5493 + const char *name, int len);
5494 +extern int meta_list_add_r_entry(dentry_t *dentry,
5495 + const char *old_name, int old_len,
5496 + const char *new_name, int new_len);
5498 +extern int meta_list_remove_r_entry(dentry_t *dentry,
5499 + const char *name, int len);
5501 +extern int __meta_list_remove_r_entry(inode_t *inode,
5502 + const char *name, int len);
5504 +extern int meta_write_d_entry(dentry_t *dentry, const char *name, int len);
5505 +extern int meta_write_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_sync_lists(dentry_t *dentry);
5510 +extern int meta_sync_d_list(dentry_t *dentry, int app_flag);
5511 +extern int meta_sync_r_list(dentry_t *dentry, int app_flag);
5514 +extern int ndl_add_entry(struct readdir_data *rd, const char *name, int len);
5515 +extern void ndl_put_list(struct readdir_data *rd);
5516 +extern int ndl_check_entry(struct readdir_data *rd,
5517 + const char *name, int len);
5520 +# define copy_inode_size(dst, src) \
5521 + dst->i_size = src->i_size; \
5522 + dst->i_blocks = src->i_blocks;
5525 +fist_copy_attr_atime(inode_t *dest, const inode_t *src)
5527 + ASSERT(dest != NULL);
5528 + ASSERT(src != NULL);
5529 + dest->i_atime = src->i_atime;
5532 +fist_copy_attr_times(inode_t *dest, const inode_t *src)
5534 + ASSERT(dest != NULL);
5535 + ASSERT(src != NULL);
5536 + dest->i_atime = src->i_atime;
5537 + dest->i_mtime = src->i_mtime;
5538 + dest->i_ctime = src->i_ctime;
5541 +fist_copy_attr_timesizes(inode_t *dest, const inode_t *src)
5543 + ASSERT(dest != NULL);
5544 + ASSERT(src != NULL);
5545 + dest->i_atime = src->i_atime;
5546 + dest->i_mtime = src->i_mtime;
5547 + dest->i_ctime = src->i_ctime;
5548 + copy_inode_size(dest, src);
5551 +fist_copy_attr_all(inode_t *dest, const inode_t *src)
5553 + ASSERT(dest != NULL);
5554 + ASSERT(src != NULL);
5555 + dest->i_mode = src->i_mode;
5556 + dest->i_nlink = src->i_nlink;
5557 + dest->i_uid = src->i_uid;
5558 + dest->i_gid = src->i_gid;
5559 + dest->i_rdev = src->i_rdev;
5560 + dest->i_atime = src->i_atime;
5561 + dest->i_mtime = src->i_mtime;
5562 + dest->i_ctime = src->i_ctime;
5563 + dest->i_blksize = src->i_blksize;
5564 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,12)
5565 + dest->i_blkbits = src->i_blkbits;
5566 +# endif /* linux 2.4.12 and newer */
5567 + copy_inode_size(dest, src);
5568 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
5569 + dest->i_attr_flags = src->i_attr_flags;
5571 + dest->i_flags = src->i_flags;
5575 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
5576 +/* copied from linux/fs.h */
5577 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
5578 +static inline void double_lock(struct dentry *d1, struct dentry *d2)
5580 + struct mutex *m1 = &d1->d_inode->i_mutex;
5581 + struct mutex *m2 = &d2->d_inode->i_mutex;
5583 + if ((unsigned long) m1 < (unsigned long) m2) {
5584 + struct mutex *tmp = m2;
5585 + m2 = m1; m1 = tmp;
5592 +static inline void double_unlock(struct dentry *d1, struct dentry *d2)
5594 + struct mutex *m1 = &d1->d_inode->i_mutex;
5595 + struct mutex *m2 = &d2->d_inode->i_mutex;
5604 +static inline void double_down(struct semaphore *s1, struct semaphore *s2)
5607 + if ((unsigned long) s1 < (unsigned long) s2) {
5608 + struct semaphore *tmp = s2;
5609 + s2 = s1; s1 = tmp;
5616 +static inline void double_up(struct semaphore *s1, struct semaphore *s2)
5623 +static inline void double_lock(struct dentry *d1, struct dentry *d2)
5625 + double_down(&d1->d_inode->i_sem, &d2->d_inode->i_sem);
5628 +static inline void double_unlock(struct dentry *d1, struct dentry *d2)
5630 + double_up(&d1->d_inode->i_sem,&d2->d_inode->i_sem);
5634 +#endif /* if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16) */
5635 +#endif /* if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0) */
5636 +#endif /* __KERNEL__ */
5639 + * Definitions for user and kernel code
5644 +#endif /* not __MINI_FO_H_ */
5645 diff -urN linux.old/fs/mini_fo/mini_fo-merge linux.dev/fs/mini_fo/mini_fo-merge
5646 --- linux.old/fs/mini_fo/mini_fo-merge 1970-01-01 01:00:00.000000000 +0100
5647 +++ linux.dev/fs/mini_fo/mini_fo-merge 2006-10-30 03:42:09.000000000 +0100
5651 +# Copyright (C) 2005 Markus Klotzbuecher <mk@creamnet.de>
5652 +# This program is free software; you can redistribute it and/or
5653 +# modify it under the terms of the GNU General Public License
5654 +# as published by the Free Software Foundation; either version
5655 +# 2 of the License, or (at your option) any later version.
5664 +META_NAME="META_dAfFgHE39ktF3HD2sr"
5665 +SKIP_DEL_LIST="skip-delete-list.mini_fo-merge"
5670 + if [ x$DRYRUN == "xset" ]; then
5671 + echo " would run: $COMMAND"
5672 + elif ! [ x$DRYRUN == "xset" ]; then
5673 + if [ x$VERBOSE == "xset" ]; then
5674 + echo " running: $COMMAND"
5684 +USAGE: $0 -b <base dir> -s <storage dir>
5687 +This script merges the contents of a mini_fo storage file system back
5688 +to the base file system.
5690 +!!! Warning: This will modify the base filesystem and can destroy data
5695 + the directory of the base file system.
5698 + the directory of the storage file system.
5700 + -d dry run, will not change anything and print the commands that
5701 + would be executed.
5703 + -t tmp dir for storing temporary file. default: $TMP
5705 + -v show what operations are performed.
5707 + -h displays this message.
5713 +while getopts hdvt:b:s: OPTS
5718 + v) VERBOSE="set";;
5719 + b) BASE="$OPTARG";;
5720 + s) STO="$OPTARG";;
5721 + t) TMP="$OPTARG";;
5727 +if [ "x$HELP" == "xset" ]; then
5732 +if ! [ -d "$BASE" ] || ! [ -d "$STO" ]; then
5733 + echo -e "$0:\n Error, -s and/or -b argument missing. type $0 -h for help."
5738 +pushd $STO; STO=`pwd`; popd
5739 +pushd $BASE; BASE=`pwd`; popd
5744 +###############################################################################
5748 +# storage dir: $STO
5749 +# meta filename: $META_NAME
5751 +# verbose: $VERBOSE
5753 +###############################################################################
5757 +rm $TMP/$SKIP_DEL_LIST
5759 +# first process all renamed dirs
5760 +echo "Merging renamed directories..."
5761 +pushd $STO &> /dev/null
5762 +find . -name $META_NAME -type f -print0 | xargs -0 -e grep -e '^R ' | tr -s ':R' ' ' | while read ENTRY; do
5763 + echo "entry: $ENTRY"
5764 + META_FILE=`echo $ENTRY | cut -d ' ' -f 1`
5765 + OLD_B_DIR=`echo $ENTRY | cut -d ' ' -f 2 | sed -e 's/\///'`
5766 + NEW_NAME=`echo $ENTRY | cut -d ' ' -f 3`
5767 + NEW_B_DIR=`echo $META_FILE | sed -e "s/$META_NAME/$NEW_NAME/" | sed -e 's/^\.\///'`
5768 + echo "META_FILE: $META_FILE"
5769 + echo "OLD_B_DIR: $OLD_B_DIR"
5770 + echo "NEW_NAME: $NEW_NAME"
5771 + echo "NEW_B_DIR: $NEW_B_DIR"
5773 + pushd $BASE &> /dev/null
5774 + # remove an existing dir in storage
5775 + COMMAND="rm -rf $NEW_B_DIR"; exec_command
5776 + COMMAND="cp -R $OLD_B_DIR $NEW_B_DIR"; exec_command
5780 + # remember this dir to exclude it from deleting later
5781 + echo $NEW_B_DIR >> $TMP/$SKIP_DEL_LIST
5784 +# delete all whiteouted files from base
5785 +echo -e "\nDeleting whiteout'ed files from base file system..."
5786 +find . -name $META_NAME -type f -print0 | xargs -0 -e grep -e '^D ' | sed -e 's/:D//' | while read ENTRY; do
5787 + META_FILE=`echo $ENTRY | cut -d ' ' -f 1`
5788 + DEL_NAME=`echo $ENTRY | cut -d ' ' -f 2`
5789 + DEL_FILE=`echo $META_FILE | sed -e "s/$META_NAME/$DEL_NAME/" | sed -e 's/^\.\///'`
5790 + grep -x $DEL_FILE $TMP/$SKIP_DEL_LIST &> /dev/null
5791 + if [ $? -ne 0 ]; then
5792 + pushd $BASE &> /dev/null
5793 + COMMAND="rm -rf $DEL_FILE"; exec_command
5796 + echo " excluding: $DEL_FILE as in skip-del-list."
5800 +# create all dirs and update permissions
5801 +echo -e "\nSetting up directory structures in base file system..."
5802 +find . -type d | sed -e 's/^\.\///' | while read DIR; do
5803 + PERMS=`stat -c %a $DIR`
5804 + DIR_UID=`stat -c %u $DIR`
5805 + DIR_GID=`stat -c %g $DIR`
5806 + pushd $BASE &> /dev/null
5807 + if ! [ -d $DIR ]; then
5808 + COMMAND="mkdir -p $DIR"; exec_command
5810 + COMMAND="chmod $PERMS $DIR"; exec_command
5811 + COMMAND="chown $DIR_UID:$DIR_GID $DIR"; exec_command
5815 +# merge all non-directory files
5816 +echo -e "\nMerging all non-directory files...."
5817 +for i in b c p f l s; do
5818 + find . -type $i | sed -e 's/^\.\///' | grep -v "$META_NAME" | while read FILE; do
5819 + pushd $BASE #&> /dev/null
5820 + COMMAND="cp -df $STO/$FILE $BASE/$FILE"; exec_command
5826 +#rm $TMP/$SKIP_DEL_LIST
5829 diff -urN linux.old/fs/mini_fo/mini_fo-overlay linux.dev/fs/mini_fo/mini_fo-overlay
5830 --- linux.old/fs/mini_fo/mini_fo-overlay 1970-01-01 01:00:00.000000000 +0100
5831 +++ linux.dev/fs/mini_fo/mini_fo-overlay 2006-10-30 03:42:09.000000000 +0100
5835 +# Copyright (C) 2005 Markus Klotzbuecher <mk@creamnet.de>
5836 +# This program is free software; you can redistribute it and/or
5837 +# modify it under the terms of the GNU General Public License
5838 +# as published by the Free Software Foundation; either version
5839 +# 2 of the License, or (at your option) any later version.
5854 +Usage: $0 [-s suffix] [-d sto_dir_dir] [-m mount point] base_dir
5857 +This script overlays the given base directory using the mini_fo file
5858 +system. If only the base directory base_dir is given, $0
5859 +will use a storage directory called "sto-<base_dir_name>" in $STO_DIR,
5860 +and mount point "mini_fo-<base_dir_dir>" in $MNT_DIR.
5864 + add given suffix to storage directory and the mount
5865 + point. This is usefull for overlaying one base directory
5866 + several times and avoiding conflicts with storage directory
5867 + names and mount points.
5870 + change the directory in which the storage directory will be
5871 + created (default is currently "$STO_DIR".
5874 + use an alternative directory to create the mini_fo
5875 + mountpoint (default is currently "$MNT_DIR".
5877 + -h displays this message.
5883 +while getopts hm:s:d: OPTS
5886 + s) SUFF="$OPTARG";;
5887 + d) STO_DIR="$OPTARG";;
5888 + m) MNT_DIR="$OPTARG";;
5894 +shift $(($OPTIND - 1))
5898 +if [ "x$HELP" == "xset" ]; then
5904 +if [ "x$SUFF" != "x" ]; then
5908 +# kill trailing slashes
5909 +MNT_DIR=${MNT_DIR%/}
5910 +STO_DIR=${STO_DIR%/}
5914 +if ! [ -d "$BASE" ]; then
5915 + echo "invalid base dir $BASE, run $0 -h for help."
5920 +if ! [ -d "$MNT_DIR" ]; then
5921 + echo "invalid mount dir $MNT_DIR, run $0 -h for help."
5925 +if ! [ -d "$STO_DIR" ]; then
5926 + echo "invalid sto_dir_dir $STO_DIR, run $0 -h for help."
5930 +MNTP="$MNT_DIR/mini_fo-`basename $BASE`$SUFF"
5931 +STO="$STO_DIR/sto-`basename $BASE`$SUFF"
5933 +# create the mount point if it doesn't exist
5935 +if [ $? -ne 0 ]; then
5936 + echo "Error, failed to create mount point $MNTP"
5940 +if [ $? -ne 0 ]; then
5941 + echo "Error, failed to create storage dir $STO"
5944 +# check if fs is already mounted
5945 +mount | grep mini_fo | grep $MNTP &> /dev/null
5946 +if [ $? -eq 0 ]; then
5947 + echo "Error, existing mini_fo mount at $MNTP."
5951 +mount | grep mini_fo | grep $STO &> /dev/null
5952 +if [ $? -eq 0 ]; then
5953 + echo "Error, $STO seems to be used already."
5958 +mount -t mini_fo -o base=$BASE,sto=$STO $BASE $MNTP
5960 +if [ $? -ne 0 ]; then
5961 + echo "Error, mounting failed, maybe no permisson to mount?"
5963 diff -urN linux.old/fs/mini_fo/mmap.c linux.dev/fs/mini_fo/mmap.c
5964 --- linux.old/fs/mini_fo/mmap.c 1970-01-01 01:00:00.000000000 +0100
5965 +++ linux.dev/fs/mini_fo/mmap.c 2006-10-30 03:42:09.000000000 +0100
5968 + * Copyright (c) 1997-2003 Erez Zadok
5969 + * Copyright (c) 2001-2003 Stony Brook University
5971 + * For specific licensing information, see the COPYING file distributed with
5972 + * this package, or get one from ftp://ftp.filesystems.org/pub/fist/COPYING.
5974 + * This Copyright notice must be kept intact and distributed with all
5975 + * fistgen sources INCLUDING sources generated by fistgen.
5978 + * Copyright (C) 2004, 2005 Markus Klotzbuecher <mk@creamnet.de>
5980 + * This program is free software; you can redistribute it and/or
5981 + * modify it under the terms of the GNU General Public License
5982 + * as published by the Free Software Foundation; either version
5983 + * 2 of the License, or (at your option) any later version.
5990 +#ifdef HAVE_CONFIG_H
5991 +# include <config.h>
5992 +#endif /* HAVE_CONFIG_H */
5995 +#include "mini_fo.h"
5998 +#ifdef FIST_COUNT_WRITES
5999 +/* for counting writes in the middle vs. regular writes */
6000 +unsigned long count_writes = 0, count_writes_middle = 0;
6001 +#endif /* FIST_COUNT_WRITES */
6003 +/* forward declaration of commit write and prepare write */
6004 +STATIC int mini_fo_commit_write(file_t *file, page_t *page, unsigned from, unsigned to);
6005 +STATIC int mini_fo_prepare_write(file_t *file, page_t *page, unsigned from, unsigned to);
6009 + * Function for handling creation of holes when lseek-ing past the
6010 + * end of the file and then writing some data.
6013 +mini_fo_fill_zeros(file_t* file, page_t *page, unsigned from)
6016 + dentry_t *dentry = file->f_dentry;
6017 + inode_t *inode = dentry->d_inode;
6021 + print_entry_location();
6023 + for (index = inode->i_size >> PAGE_CACHE_SHIFT; index < page->index; index++) {
6024 + tmp_page = mini_fo_get1page(file, index);
6025 + if (IS_ERR(tmp_page)) {
6026 + err = PTR_ERR(tmp_page);
6031 + * zero out rest of the contents of the page between the appropriate
6034 + memset((char*)page_address(tmp_page) + (inode->i_size & ~PAGE_CACHE_MASK), 0, PAGE_CACHE_SIZE - (inode->i_size & ~PAGE_CACHE_MASK));
6036 + if (! (err = mini_fo_prepare_write(file, tmp_page, 0, PAGE_CACHE_SIZE)))
6037 + err = mini_fo_commit_write(file, tmp_page, 0, PAGE_CACHE_SIZE);
6039 + page_cache_release(tmp_page);
6042 + if (current->need_resched)
6046 + /* zero out appropriate parts of last page */
6049 + * if the encoding type is block, then adjust the 'from' (where the
6050 + * zeroing will start) offset appropriately
6052 + from = from & (~(FIST_ENCODING_BLOCKSIZE - 1));
6054 + if ((from - (inode->i_size & ~PAGE_CACHE_MASK)) > 0) {
6056 + memset((char*)page_address(page) + (inode->i_size & ~PAGE_CACHE_MASK), 0, from - (inode->i_size & ~PAGE_CACHE_MASK));
6057 + if (! (err = mini_fo_prepare_write(file, page, 0, PAGE_CACHE_SIZE)))
6058 + err = mini_fo_commit_write(file, page, 0, PAGE_CACHE_SIZE);
6062 + if (current->need_resched)
6067 + print_exit_status(err);
6074 +mini_fo_writepage(page_t *page)
6078 + inode_t *hidden_inode;
6079 + page_t *hidden_page;
6080 + char *kaddr, *hidden_kaddr;
6082 + print_entry_location();
6084 + inode = page->mapping->host;
6085 + hidden_inode = itohi(inode);
6088 + * writepage is called when shared mmap'ed files need to write
6089 + * their pages, while prepare/commit_write are called from the
6090 + * non-paged write() interface. (However, in 2.3 the two interfaces
6091 + * share the same cache, while in 2.2 they didn't.)
6093 + * So we pretty much have to duplicate much of what commit_write does.
6096 + /* find lower page (returns a locked page) */
6097 + hidden_page = grab_cache_page(hidden_inode->i_mapping, page->index);
6101 + /* get page address, and encode it */
6102 + kaddr = (char *) kmap(page);
6103 + hidden_kaddr = (char*) kmap(hidden_page);
6104 + mini_fo_encode_block(kaddr, hidden_kaddr, PAGE_CACHE_SIZE, inode, inode->i_sb, page->index);
6105 + /* if encode_block could fail, then return error */
6107 + kunmap(hidden_page);
6109 + /* call lower writepage (expects locked page) */
6110 + err = hidden_inode->i_mapping->a_ops->writepage(hidden_page);
6113 + * update mtime and ctime of lower level file system
6114 + * mini_fo' mtime and ctime are updated by generic_file_write
6116 + hidden_inode->i_mtime = hidden_inode->i_ctime = CURRENT_TIME;
6118 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,4,1)
6119 + UnlockPage(hidden_page); /* b/c grab_cache_page locked it */
6120 +# endif /* kernel older than 2.4.1 */
6121 + page_cache_release(hidden_page); /* b/c grab_cache_page increased refcnt */
6124 + ClearPageUptodate(page);
6126 + SetPageUptodate(page);
6128 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,1)
6130 +# endif /* kernel 2.4.1 and newer */
6131 + print_exit_status(err);
6137 + * get one page from cache or lower f/s, return error otherwise.
6138 + * returns unlocked, up-to-date page (if ok), with increased refcnt.
6141 +mini_fo_get1page(file_t *file, int index)
6146 + struct address_space *mapping;
6149 + print_entry_location();
6151 + dentry = file->f_dentry; /* CPW: Moved below print_entry_location */
6152 + inode = dentry->d_inode;
6153 + mapping = inode->i_mapping;
6155 + fist_dprint(8, "%s: read page index %d pid %d\n", __FUNCTION__, index, current->pid);
6157 + printk("%s BUG: index=%d\n", __FUNCTION__, index);
6158 + page = ERR_PTR(-EIO);
6161 + page = read_cache_page(mapping,
6163 + (filler_t *) mapping->a_ops->readpage,
6167 + wait_on_page(page);
6168 + if (!Page_Uptodate(page)) {
6170 + err = mapping->a_ops->readpage(file, page);
6172 + page = ERR_PTR(err);
6175 + wait_on_page(page);
6176 + if (!Page_Uptodate(page)) {
6177 + page = ERR_PTR(-EIO);
6183 + print_exit_pointer(page);
6189 + * get one page from cache or lower f/s, return error otherwise.
6190 + * similar to get1page, but doesn't guarantee that it will return
6191 + * an unlocked page.
6194 +mini_fo_get1page_cached(file_t *file, int index)
6199 + struct address_space *mapping;
6202 + print_entry_location();
6204 + dentry = file->f_dentry; /* CPW: Moved below print_entry_location */
6205 + inode = dentry->d_inode;
6206 + mapping = inode->i_mapping;
6208 + fist_dprint(8, "%s: read page index %d pid %d\n", __FUNCTION__, index, current->pid);
6210 + printk("%s BUG: index=%d\n", __FUNCTION__, index);
6211 + page = ERR_PTR(-EIO);
6214 + page = read_cache_page(mapping,
6216 + (filler_t *) mapping->a_ops->readpage,
6222 + print_exit_pointer(page);
6228 + * readpage is called from generic_page_read and the fault handler.
6229 + * If your file system uses generic_page_read for the read op, it
6230 + * must implement readpage.
6232 + * Readpage expects a locked page, and must unlock it.
6235 +mini_fo_do_readpage(file_t *file, page_t *page)
6239 + file_t *hidden_file = NULL;
6240 + dentry_t *hidden_dentry;
6242 + inode_t *hidden_inode;
6244 + page_t *hidden_page;
6245 + char *hidden_page_data;
6248 + print_entry_location();
6250 + dentry = file->f_dentry; /* CPW: Moved below print_entry_location */
6251 + if (ftopd(file) != NULL)
6252 + hidden_file = ftohf(file);
6253 + hidden_dentry = dtohd(dentry);
6254 + inode = dentry->d_inode;
6255 + hidden_inode = itohi(inode);
6257 + fist_dprint(7, "%s: requesting page %d from file %s\n", __FUNCTION__, page->index, dentry->d_name.name);
6259 + MALLOC_PAGE_POINTERS(hidden_pages, num_hidden_pages);
6260 + MALLOC_PAGEDATA_POINTERS(hidden_pages_data, num_hidden_pages);
6262 + CURRENT_HIDDEN_PAGE = NULL;
6264 + /* find lower page (returns a locked page) */
6266 + fist_dprint(8, "%s: Current page index = %d\n", __FUNCTION__, CURRENT_HIDDEN_PAGEINDEX);
6267 + CURRENT_HIDDEN_PAGE = read_cache_page(hidden_inode->i_mapping,
6268 + CURRENT_HIDDEN_PAGEINDEX,
6269 + (filler_t *) hidden_inode->i_mapping->a_ops->readpage,
6270 + (void *) hidden_file);
6271 + if (IS_ERR(CURRENT_HIDDEN_PAGE)) {
6272 + err = PTR_ERR(CURRENT_HIDDEN_PAGE);
6273 + CURRENT_HIDDEN_PAGE = NULL;
6279 + * wait for the page data to show up
6280 + * (signaled by readpage as unlocking the page)
6283 + wait_on_page(CURRENT_HIDDEN_PAGE);
6284 + if (!Page_Uptodate(CURRENT_HIDDEN_PAGE)) {
6286 + * call readpage() again if we returned from wait_on_page with a
6287 + * page that's not up-to-date; that can happen when a partial
6288 + * page has a few buffers which are ok, but not the whole
6291 + lock_page(CURRENT_HIDDEN_PAGE);
6292 + err = hidden_inode->i_mapping->a_ops->readpage(hidden_file,
6293 + CURRENT_HIDDEN_PAGE);
6295 + CURRENT_HIDDEN_PAGE = NULL;
6298 + wait_on_page(CURRENT_HIDDEN_PAGE);
6299 + if (!Page_Uptodate(CURRENT_HIDDEN_PAGE)) {
6306 + /* map pages, get their addresses */
6307 + page_data = (char *) kmap(page);
6309 + CURRENT_HIDDEN_PAGEDATA = (char *) kmap(CURRENT_HIDDEN_PAGE);
6311 + /* if decode_block could fail, then return error */
6313 + real_size = hidden_inode->i_size - (page->index << PAGE_CACHE_SHIFT);
6314 + if (real_size <= 0)
6315 + memset(page_data, 0, PAGE_CACHE_SIZE);
6316 + else if (real_size < PAGE_CACHE_SIZE) {
6317 + mini_fo_decode_block(hidden_page_data, page_data, real_size, inode, inode->i_sb, page->index);
6318 + memset(page_data + real_size, 0, PAGE_CACHE_SIZE - real_size);
6320 + mini_fo_decode_block(hidden_page_data, page_data, PAGE_CACHE_SIZE, inode, inode->i_sb, page->index);
6323 + kunmap(CURRENT_HIDDEN_PAGE);
6328 + if (CURRENT_HIDDEN_PAGE)
6329 + page_cache_release(CURRENT_HIDDEN_PAGE); /* undo read_cache_page */
6331 + FREE_PAGE_POINTERS(hidden_pages, num_hidden_pages);
6332 + FREE_PAGEDATA_POINTERS(hidden_pages_data, num_hidden_pages);
6336 + SetPageUptodate(page);
6338 + ClearPageUptodate(page);
6340 + print_exit_status(err);
6346 +mini_fo_readpage(file_t *file, page_t *page)
6349 + print_entry_location();
6351 + err = mini_fo_do_readpage(file, page);
6354 + * we have to unlock our page, b/c we _might_ have gotten a locked page.
6355 + * but we no longer have to wakeup on our page here, b/c UnlockPage does
6360 + print_exit_status(err);
6366 +mini_fo_prepare_write(file_t *file, page_t *page, unsigned from, unsigned to)
6370 + print_entry_location();
6373 + * we call kmap(page) only here, and do the kunmap
6374 + * and the actual downcalls, including unlockpage and uncache
6375 + * in commit_write.
6379 + /* fast path for whole page writes */
6380 + if (from == 0 && to == PAGE_CACHE_SIZE)
6382 + /* read the page to "revalidate" our data */
6383 + /* call the helper function which doesn't unlock the page */
6384 + if (!Page_Uptodate(page))
6385 + err = mini_fo_do_readpage(file, page);
6388 + print_exit_status(err);
6395 +mini_fo_commit_write(file_t *file, page_t *page, unsigned from, unsigned to)
6397 + int err = -ENOMEM;
6399 + inode_t *hidden_inode;
6400 + page_t *hidden_page;
6401 + file_t *hidden_file = NULL;
6403 + unsigned bytes = to - from;
6404 + unsigned hidden_from, hidden_to, hidden_bytes;
6406 + print_entry_location();
6408 + inode = page->mapping->host; /* CPW: Moved below print_entry_location */
6409 + hidden_inode = itohi(inode);
6411 + ASSERT(file != NULL);
6413 + * here we have a kmapped page, with data from the user copied
6414 + * into it. we need to encode_block it, and then call the lower
6415 + * commit_write. We also need to simulate same behavior of
6416 + * generic_file_write, and call prepare_write on the lower f/s first.
6418 +#ifdef FIST_COUNT_WRITES
6420 +# endif /* FIST_COUNT_WRITES */
6422 + /* this is append and/or extend -- we can't have holes so fill them in */
6423 + if (page->index > (hidden_inode->i_size >> PAGE_CACHE_SHIFT)) {
6426 + for (index = hidden_inode->i_size >> PAGE_CACHE_SHIFT; index < page->index; index++) {
6427 + tmp_page = mini_fo_get1page(file, index);
6428 + if (IS_ERR(tmp_page)) {
6429 + err = PTR_ERR(tmp_page);
6432 + /* zero out the contents of the page at the appropriate offsets */
6433 + memset((char*)page_address(tmp_page) + (inode->i_size & ~PAGE_CACHE_MASK), 0, PAGE_CACHE_SIZE - (inode->i_size & ~PAGE_CACHE_MASK));
6434 + if (!(err = mini_fo_prepare_write(file, tmp_page, 0, PAGE_CACHE_SIZE)))
6435 + err = mini_fo_commit_write(file, tmp_page, 0, PAGE_CACHE_SIZE);
6436 + page_cache_release(tmp_page);
6439 + if (current->need_resched)
6444 + if (ftopd(file) != NULL)
6445 + hidden_file = ftohf(file);
6447 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
6448 + mutex_lock(&hidden_inode->i_mutex);
6450 + down(&hidden_inode->i_sem);
6452 + /* find lower page (returns a locked page) */
6453 + hidden_page = grab_cache_page(hidden_inode->i_mapping, page->index);
6457 +#if FIST_ENCODING_BLOCKSIZE > 1
6458 +# error encoding_blocksize greater than 1 is not yet supported
6459 +# endif /* FIST_ENCODING_BLOCKSIZE > 1 */
6461 + hidden_from = from & (~(FIST_ENCODING_BLOCKSIZE - 1));
6462 + hidden_to = ((to + FIST_ENCODING_BLOCKSIZE - 1) & (~(FIST_ENCODING_BLOCKSIZE - 1)));
6463 + if ((page->index << PAGE_CACHE_SHIFT) + to > hidden_inode->i_size) {
6466 + * if this call to commit_write had introduced holes and the code
6467 + * for handling holes was invoked, then the beginning of this page
6468 + * must be zeroed out
6469 + * zero out bytes from 'size_of_file%pagesize' to 'from'.
6471 + if ((hidden_from - (inode->i_size & ~PAGE_CACHE_MASK)) > 0)
6472 + memset((char*)page_address(page) + (inode->i_size & ~PAGE_CACHE_MASK), 0, hidden_from - (inode->i_size & ~PAGE_CACHE_MASK));
6475 + hidden_bytes = hidden_to - hidden_from;
6477 + /* call lower prepare_write */
6479 + if (hidden_inode->i_mapping &&
6480 + hidden_inode->i_mapping->a_ops &&
6481 + hidden_inode->i_mapping->a_ops->prepare_write)
6482 + err = hidden_inode->i_mapping->a_ops->prepare_write(hidden_file,
6487 + /* don't leave locked pages behind, esp. on an ENOSPC */
6490 + fist_dprint(8, "%s: encoding %d bytes\n", __FUNCTION__, hidden_bytes);
6491 + 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);
6492 + /* if encode_block could fail, then goto unlock and return error */
6494 + /* call lower commit_write */
6495 + err = hidden_inode->i_mapping->a_ops->commit_write(hidden_file,
6503 + err = bytes; /* convert error to no. of bytes */
6505 + inode->i_blocks = hidden_inode->i_blocks;
6506 + /* we may have to update i_size */
6507 + pos = (page->index << PAGE_CACHE_SHIFT) + to;
6508 + if (pos > inode->i_size)
6509 + inode->i_size = pos;
6512 + * update mtime and ctime of lower level file system
6513 + * mini_fo' mtime and ctime are updated by generic_file_write
6515 + hidden_inode->i_mtime = hidden_inode->i_ctime = CURRENT_TIME;
6517 + mark_inode_dirty_sync(inode);
6520 + UnlockPage(hidden_page);
6521 + page_cache_release(hidden_page);
6522 + kunmap(page); /* kmap was done in prepare_write */
6524 + /* we must set our page as up-to-date */
6526 + ClearPageUptodate(page);
6528 + SetPageUptodate(page);
6530 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
6531 + mutex_unlock(&hidden_inode->i_mutex);
6533 + up(&hidden_inode->i_sem);
6535 + print_exit_status(err);
6536 + return err; /* assume all is ok */
6541 +mini_fo_bmap(struct address_space *mapping, long block)
6545 + inode_t *hidden_inode;
6547 + print_entry_location();
6549 + inode = (inode_t *) mapping->host;
6550 + hidden_inode = itohi(inode);
6552 + if (hidden_inode->i_mapping->a_ops->bmap)
6553 + err = hidden_inode->i_mapping->a_ops->bmap(hidden_inode->i_mapping, block);
6554 + print_exit_location();
6560 + * This function is copied verbatim from mm/filemap.c.
6561 + * XXX: It should be simply moved to some header file instead -- bug Al about it!
6563 +static inline int sync_page(struct page *page)
6565 + struct address_space *mapping = page->mapping;
6567 + if (mapping && mapping->a_ops && mapping->a_ops->sync_page)
6568 + return mapping->a_ops->sync_page(page);
6574 + * XXX: we may not need this function if not FIST_FILTER_DATA.
6575 + * FIXME: for FIST_FILTER_SCA, get all lower pages and sync them each.
6578 +mini_fo_sync_page(page_t *page)
6582 + inode_t *hidden_inode;
6583 + page_t *hidden_page;
6585 + print_entry_location();
6587 + inode = page->mapping->host; /* CPW: Moved below print_entry_location */
6588 + hidden_inode = itohi(inode);
6590 + /* find lower page (returns a locked page) */
6591 + hidden_page = grab_cache_page(hidden_inode->i_mapping, page->index);
6595 + err = sync_page(hidden_page);
6597 + UnlockPage(hidden_page); /* b/c grab_cache_page locked it */
6598 + page_cache_release(hidden_page); /* b/c grab_cache_page increased refcnt */
6601 + print_exit_status(err);
6604 diff -urN linux.old/fs/mini_fo/README linux.dev/fs/mini_fo/README
6605 --- linux.old/fs/mini_fo/README 1970-01-01 01:00:00.000000000 +0100
6606 +++ linux.dev/fs/mini_fo/README 2006-10-30 03:42:09.000000000 +0100
6608 +README for the mini_fo overlay file system
6609 +=========================================
6615 +mini_fo is a virtual kernel file system that can make read-only
6616 +file systems writable. This is done by redirecting modifying operations
6617 +to a writeable location called "storage directory", and leaving the
6618 +original data in the "base directory" untouched. When reading, the
6619 +file system merges the modifed and original data so that only the
6620 +newest versions will appear. This occurs transparently to the user,
6621 +who can access the data like on any other read-write file system.
6623 +Base and storage directories may be located on the same or on
6624 +different partitions and may be of different file system types. While
6625 +the storage directory obviously needs to be writable, the base may or
6626 +may not be writable, what doesn't matter as it will no be modified
6633 +The primary purpose of the mini_fo file system is to allow easy
6634 +software updates to embedded systems, that often store their root
6635 +file system in a read-only flash file system, but there are many
6636 +more as for example sandboxing, or for allowing live-cds to
6637 +permanently store information.
6642 +This should be simple. Adjust the Makefile to point to the correct
6643 +kernel headers you want to build the module for. Then:
6647 +should build "mini_fo.o" for a 2.4 kernel or "mini_fo.ko" for a 2.6
6650 +If you are building the module for you current kernel, you can install
6651 +the module (as root):
6660 +USING THE FILE SYSTEM
6661 +--------------------
6663 +the general mount syntax is:
6665 + mount -t mini_fo -o base=<base directory>,sto=<storage directory>\
6666 + <base directory> <mount point>
6670 +You have mounted a cdrom to /mnt/cdrom and want to modifiy some files
6673 +load the module (as root)
6675 + # insmod mini_fo.o for a 2.4 kernel or
6677 + # insmod mini_fo.ko for a 2.6 kernel
6680 +create a storage dir in tmp and a mountpoint for mini_fo:
6683 + # mkdir /mnt/mini_fo
6685 +and mount the mini_fo file system:
6687 + # mount -t mini_fo -o base=/mnt/cdrom,sto=/tmp/sto /mnt/cdrom /mnt/mini_fo
6690 +Now the data stored on the cd can be accessed via the mini_fo
6691 +mountpoint just like any read-write file system, files can be modified
6692 +and deleted, new ones can be created and so on. When done unmount the
6695 + # unmount /mnt/mini_fo
6697 +Note that if the file system is mounted again using the same storage
6698 +file system, of course it will appear in the modified state again. If
6699 +you remount it using an new empty storage directory, it will be
6700 +unmodified. Therefore by executing:
6705 +you can nuke all the changes you made to the original file system. But
6706 + remember NEVER do this while the mini_fo file system is mounted!
6709 +Alternatively you can use the mini_fo-overlay bash script, that
6710 +simplifies managing mini_fo mounts. See TOOLS Section.
6716 +mini_fo-merge (experimental):
6718 +This is a bash script that will merge changes contained in the storage
6719 +directory back to the base directory. This allows mini_fo to function
6720 +as a cache file system by overlaying a slow (network, ...) file system
6721 +and using a fast (ramdisk, ...) as storage. When done, changes can be
6722 +merged back to the (slow) base with mini_fo-merge. See "mini_fo-merge
6725 +It can be usefull for merging changes back after a successfull test
6726 +(patches, software updates...)
6731 +This bash script simplifies managing one or more mini_fo mounts. For
6732 +overlaying a directory called "basedir1", you can just call:
6734 + # mini_fo-overlay basedir1
6736 +This will mount mini_fo with "basedir1" as base, "/tmp/sto-basedir1/"
6737 +as storage to "/mnt/mini_fo-basedir1/". It has more options though,
6738 +type "mini_fo-overlay -h" for details.
6741 +DOCUMENTATION, REPORTING BUGS, GETTING HELP
6742 +-------------------------------------------
6744 +Please visit the mini_fo project page at:
6746 +http://www.denx.de/twiki/bin/view/Know/MiniFOHome
6752 +Never modify the base or the storage directorys while the mini_fo
6753 +file system is mounted, or you might crash you system. Simply accessing
6754 +and reading should not cause any trouble.
6756 +Exporting a mini_fo mount point via NFS has not been tested, and may
6759 +Check the RELEASE_NOTES for details on bugs and features.
6763 +Copyright (C) 2004, 2005 Markus Klotzbuecher <mk@creamnet.de>
6765 +This program is free software; you can redistribute it and/or
6766 +modify it under the terms of the GNU General Public License
6767 +as published by the Free Software Foundation; either version
6768 +2 of the License, or (at your option) any later version.
6771 diff -urN linux.old/fs/mini_fo/RELEASE_NOTES linux.dev/fs/mini_fo/RELEASE_NOTES
6772 --- linux.old/fs/mini_fo/RELEASE_NOTES 1970-01-01 01:00:00.000000000 +0100
6773 +++ linux.dev/fs/mini_fo/RELEASE_NOTES 2006-10-30 03:42:09.000000000 +0100
6775 +Release: mini_fo-0.6.1 (v0-6-1)
6783 +- bugfixes (see ChangeLog)
6785 +- two helper scripts "mini_fo_merge" and "mini_fo_overlay" (see
6786 + README for details).
6790 +- Support for 2.4 and 2.6 (see Makefile)
6792 +- Partial hard link support (creating works as expected, but already
6793 + existing links in the base file system will be treated as if they
6794 + were individual files).
6796 +- Various bugfixes and cleanups.
6801 +- This is mini_fo-0-6-0-pre1! This release is a complete rewrite of
6802 + many vital mini_fo parts such as the old whiteout list code which
6803 + has been replaced by the new META subsystem.
6805 +- Light weight directory renaming implemented. This means if a
6806 + directory is renamed via the mini_fo filesystem this will no longer
6807 + result in a complete copy in storage, instead only one empty
6808 + directory will be created. All base filed contained in the original
6809 + directory stay there until modified.
6811 +- Special files (creating, renaming, deleting etc.) now working.
6813 +- Many bugfixes and cleanup, mini_fo is now a lot more stable.
6818 +- Final release of the 0-5-* versions. Next will be a complete rewrite
6819 + of many features. This release contains several bugfixes related to
6820 + directory renaming.
6825 +- Lots of cleanup and several bugfixes related to directory deleting
6827 +- Directory renaming suddenly works, what is most likely due to the
6828 + fact tha that "mv" is smart: if the classic rename doesn't work it
6829 + will assume that source and target file are on different fs and will
6830 + copy the directory and try to remove the source directory. Until
6831 + directory removing wasn't implemented, it would fail to do this and
6833 + So, directory renaming works for now, but it doesn't yet do what you
6834 + would expect from a overlay fs, so use with care.
6839 +- implemented directory deleting
6840 +- made parsing of mount options more stable
6841 +- New format of mount options! (See README)
6842 +- I can't reproduce the unknown panic with 2.4.25 anymore, so I'll
6843 + happily assume it never existed!
6846 +Implemented features:
6847 +---------------------
6849 +- creating hard links (see BUGS on already existing hard links)
6850 +- lightweight directory renaming
6851 +- renaming device files, pipes, sockets, etc.
6852 +- creating, renaming, deleting of special files
6853 +- deleting directorys
6854 +- general directory reading (simple "ls" )
6855 +- creating files in existing directorys
6856 +- creating directorys
6858 +- reading and writing files (involves opening)
6859 +- appending to files (creates copy in storage)
6861 +- llseek works too, what allows editors to work
6862 +- persistency (a deleted file stay deleted over remounts)
6863 +- use of symbolic links
6864 +- creating of device files
6867 +Not (yet) implemented features:
6868 +-------------------------------
6870 +- full hard link support.
6877 +Hard links in the base file system will be treated as individual
6878 +files, not as links to one inode.
6880 +The main problem with hard links isn't allowing to create them, but
6881 +their pure existence. If you modify a base hard link, the changes made
6882 +will only show up on this link, the other link will remain in the
6883 +original state. I hope to fix this someday. Please note that this does
6884 +not effect the special hard links '.' and '..', that are handled
6885 +seperately by the lower fs.
6886 diff -urN linux.old/fs/mini_fo/state.c linux.dev/fs/mini_fo/state.c
6887 --- linux.old/fs/mini_fo/state.c 1970-01-01 01:00:00.000000000 +0100
6888 +++ linux.dev/fs/mini_fo/state.c 2006-10-30 03:42:09.000000000 +0100
6891 + * Copyright (C) 2005 Markus Klotzbuecher <mk@creamnet.de>
6893 + * This program is free software; you can redistribute it and/or
6894 + * modify it under the terms of the GNU General Public License
6895 + * as published by the Free Software Foundation; either version
6896 + * 2 of the License, or (at your option) any later version.
6899 +#ifdef HAVE_CONFIG_H
6900 +# include <config.h>
6901 +#endif /* HAVE_CONFIG_H */
6904 +#include "mini_fo.h"
6907 +/* create the storage file, setup new states */
6908 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
6909 +int create_sto_reg_file(dentry_t *dentry, int mode, struct nameidata *nd)
6911 +int create_sto_reg_file(dentry_t *dentry, int mode)
6916 + dentry_t *hidden_sto_dentry;
6917 + dentry_t *hidden_sto_dir_dentry;
6919 + if(exists_in_storage(dentry)) {
6920 + printk(KERN_CRIT "mini_fo: create_sto_file: wrong type or state.\n");
6924 + err = get_neg_sto_dentry(dentry);
6927 + printk(KERN_CRIT "mini_fo: create_sto_file: ERROR getting neg. sto dentry.\n");
6931 + dir = dentry->d_parent->d_inode;
6932 + hidden_sto_dentry = dtohd2(dentry);
6935 + hidden_sto_dir_dentry = dget(hidden_sto_dentry->d_parent);
6937 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
6938 + mutex_lock(&hidden_sto_dir_dentry->d_inode->i_mutex);
6940 + down(&hidden_sto_dir_dentry->d_inode->i_sem);
6943 + err = PTR_ERR(hidden_sto_dir_dentry);
6944 + if (IS_ERR(hidden_sto_dir_dentry))
6947 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
6948 + err = vfs_create(hidden_sto_dir_dentry->d_inode,
6949 + hidden_sto_dentry,
6952 + err = vfs_create(hidden_sto_dir_dentry->d_inode,
6953 + hidden_sto_dentry,
6957 + printk(KERN_CRIT "mini_fo: create_sto_file: ERROR creating sto file.\n");
6961 + if(!dtohd2(dentry)->d_inode) {
6962 + printk(KERN_CRIT "mini_fo: create_sto_file: ERROR creating sto file [2].\n");
6967 + /* interpose the new inode */
6968 + if(dtost(dentry) == DELETED) {
6969 + dtost(dentry) = DEL_REWRITTEN;
6970 + err = mini_fo_tri_interpose(NULL, hidden_sto_dentry, dentry, dir->i_sb, 0);
6974 + else if(dtost(dentry) == NON_EXISTANT) {
6975 + dtost(dentry) = CREATED;
6976 + err = mini_fo_tri_interpose(dtohd(dentry), hidden_sto_dentry, dentry, dir->i_sb, 0);
6980 + else if(dtost(dentry) == UNMODIFIED) {
6981 + dtost(dentry) = MODIFIED;
6982 + /* interpose on new inode */
6983 + if(itohi2(dentry->d_inode) != NULL) {
6984 + printk(KERN_CRIT "mini_fo: create_sto_file: invalid inode detected.\n");
6988 + itohi2(dentry->d_inode) = igrab(dtohd2(dentry)->d_inode);
6990 + fist_copy_attr_timesizes(dentry->d_parent->d_inode,
6991 + hidden_sto_dir_dentry->d_inode);
6994 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
6995 + mutex_unlock(&hidden_sto_dir_dentry->d_inode->i_mutex);
6997 + up(&hidden_sto_dir_dentry->d_inode->i_sem);
6999 + dput(hidden_sto_dir_dentry);
7004 +/* create the sto dir, setup states */
7005 +int create_sto_dir(dentry_t *dentry, int mode)
7009 + dentry_t *hidden_sto_dentry;
7010 + dentry_t *hidden_sto_dir_dentry;
7012 + /* had to take the "!S_ISDIR(mode))" check out, because it failed */
7013 + if(exists_in_storage(dentry)) {
7014 + printk(KERN_CRIT "mini_fo: create_sto_dir: wrong type or state.\\
7020 + err = get_neg_sto_dentry(dentry);
7026 + dir = dentry->d_parent->d_inode;
7027 + hidden_sto_dentry = dtohd2(dentry);
7029 + /* was: hidden_sto_dir_dentry = lock_parent(hidden_sto_dentry); */
7030 + hidden_sto_dir_dentry = dget(hidden_sto_dentry->d_parent);
7032 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
7033 + mutex_lock(&hidden_sto_dir_dentry->d_inode->i_mutex);
7035 + down(&hidden_sto_dir_dentry->d_inode->i_sem);
7038 + err = PTR_ERR(hidden_sto_dir_dentry);
7039 + if (IS_ERR(hidden_sto_dir_dentry))
7042 + err = vfs_mkdir(hidden_sto_dir_dentry->d_inode,
7043 + hidden_sto_dentry,
7046 + printk(KERN_CRIT "mini_fo: create_sto_dir: ERROR creating sto dir.\n");
7050 + if(!dtohd2(dentry)->d_inode) {
7051 + printk(KERN_CRIT "mini_fo: create_sto_dir: ERROR creating sto dir [2].\n");
7056 + /* interpose the new inode */
7057 + if(dtost(dentry) == DELETED) {
7058 + dtost(dentry) = DEL_REWRITTEN;
7059 + err = mini_fo_tri_interpose(NULL, hidden_sto_dentry, dentry, dir->i_sb, 0);
7063 + else if(dtopd(dentry)->state == NON_EXISTANT) {
7064 + dtopd(dentry)->state = CREATED;
7065 + err = mini_fo_tri_interpose(dtohd(dentry), hidden_sto_dentry, dentry, dir->i_sb, 0);
7069 + else if(dtopd(dentry)->state == UNMODIFIED) {
7070 + dtopd(dentry)->state = MODIFIED;
7071 + /* interpose on new inode */
7072 + if(itohi2(dentry->d_inode) != NULL) {
7073 + printk(KERN_CRIT "mini_fo: create_sto_dir: ERROR, invalid inode detected.\n");
7077 + itohi2(dentry->d_inode) = igrab(dtohd2(dentry)->d_inode);
7080 + fist_copy_attr_timesizes(dir, hidden_sto_dir_dentry->d_inode);
7082 + /* initalize the wol list */
7083 + itopd(dentry->d_inode)->deleted_list_size = -1;
7084 + itopd(dentry->d_inode)->renamed_list_size = -1;
7085 + meta_build_lists(dentry);
7089 + /* was: unlock_dir(hidden_sto_dir_dentry); */
7090 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
7091 + mutex_unlock(&hidden_sto_dir_dentry->d_inode->i_mutex);
7093 + up(&hidden_sto_dir_dentry->d_inode->i_sem);
7095 + dput(hidden_sto_dir_dentry);
7100 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
7101 +int create_sto_nod(dentry_t *dentry, int mode, dev_t dev)
7103 +int create_sto_nod(dentry_t *dentry, int mode, int dev)
7108 + dentry_t *hidden_sto_dentry;
7109 + dentry_t *hidden_sto_dir_dentry;
7111 + if(exists_in_storage(dentry)) {
7115 + err = get_neg_sto_dentry(dentry);
7118 + printk(KERN_CRIT "mini_fo: create_sto_nod: ERROR getting neg. sto dentry.\n");
7122 + dir = dentry->d_parent->d_inode;
7123 + hidden_sto_dentry = dtohd2(dentry);
7126 + hidden_sto_dir_dentry = dget(hidden_sto_dentry->d_parent);
7128 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
7129 + mutex_lock(&hidden_sto_dir_dentry->d_inode->i_mutex);
7131 + down(&hidden_sto_dir_dentry->d_inode->i_sem);
7134 + err = PTR_ERR(hidden_sto_dir_dentry);
7135 + if (IS_ERR(hidden_sto_dir_dentry))
7138 + err = vfs_mknod(hidden_sto_dir_dentry->d_inode, hidden_sto_dentry, mode, dev);
7142 + if(!dtohd2(dentry)->d_inode) {
7143 + printk(KERN_CRIT "mini_fo: create_sto_nod: creating storage inode failed [1].\n");
7144 + err = -EINVAL; /* return something indicating failure */
7148 + /* interpose the new inode */
7149 + if(dtost(dentry) == DELETED) {
7150 + dtost(dentry) = DEL_REWRITTEN;
7151 + err = mini_fo_tri_interpose(NULL, hidden_sto_dentry, dentry, dir->i_sb, 0);
7155 + else if(dtost(dentry) == NON_EXISTANT) {
7156 + dtost(dentry) = CREATED;
7157 + err = mini_fo_tri_interpose(dtohd(dentry), hidden_sto_dentry, dentry, dir->i_sb, 0);
7161 + else if(dtost(dentry) == UNMODIFIED) {
7162 + dtost(dentry) = MODIFIED;
7163 + /* interpose on new inode */
7164 + if(itohi2(dentry->d_inode) != NULL) {
7165 + printk(KERN_CRIT "mini_fo: create_sto_nod: error, invalid inode detected.\n");
7169 + itohi2(dentry->d_inode) = igrab(dtohd2(dentry)->d_inode);
7172 + fist_copy_attr_timesizes(dir, hidden_sto_dir_dentry->d_inode);
7175 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
7176 + mutex_unlock(&hidden_sto_dir_dentry->d_inode->i_mutex);
7178 + up(&hidden_sto_dir_dentry->d_inode->i_sem);
7180 + dput(hidden_sto_dir_dentry);
7186 +/* unimplemented (and possibly not usefull):
7188 + nondir-del_to_del_rew
7189 + nondir-non_exist_to_creat
7194 + dir-del_rew_to_del
7195 + dir-del_to_del_rew
7196 + dir-non_exist_to_creat
7200 +/* bring a file of any type from state UNMODIFIED to MODIFIED */
7201 +int nondir_unmod_to_mod(dentry_t *dentry, int cp_flag)
7204 + struct vfsmount *tgt_mnt;
7205 + struct vfsmount *src_mnt;
7206 + dentry_t *tgt_dentry;
7207 + dentry_t *src_dentry;
7208 + dentry_t *hidden_sto_dentry;
7209 + dentry_t *hidden_sto_dir_dentry;
7211 + check_mini_fo_dentry(dentry);
7213 + if((dtost(dentry) != UNMODIFIED) ||
7214 + S_ISDIR(dentry->d_inode->i_mode)) {
7215 + printk(KERN_CRIT "mini_fo: nondir_unmod_to_mod: \
7216 + wrong type or state.\n");
7220 + err = get_neg_sto_dentry(dentry);
7223 + printk(KERN_CRIT "mini_fo: nondir_unmod_to_mod: \
7224 + ERROR getting neg. sto dentry.\n");
7228 + /* create sto file */
7229 + hidden_sto_dentry = dtohd2(dentry);
7232 + hidden_sto_dir_dentry = dget(hidden_sto_dentry->d_parent);
7234 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
7235 + mutex_lock(&hidden_sto_dir_dentry->d_inode->i_mutex);
7237 + down(&hidden_sto_dir_dentry->d_inode->i_sem);
7240 + err = PTR_ERR(hidden_sto_dir_dentry);
7241 + if (IS_ERR(hidden_sto_dir_dentry))
7244 + /* handle different types of nondirs */
7245 + if(S_ISCHR(dentry->d_inode->i_mode) ||
7246 + S_ISBLK(dentry->d_inode->i_mode)) {
7247 + err = vfs_mknod(hidden_sto_dir_dentry->d_inode,
7248 + hidden_sto_dentry,
7249 + dtohd(dentry)->d_inode->i_mode,
7250 + dtohd(dentry)->d_inode->i_rdev);
7253 + else if(S_ISREG(dentry->d_inode->i_mode)) {
7255 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
7256 + err = vfs_create(hidden_sto_dir_dentry->d_inode,
7257 + hidden_sto_dentry,
7258 + dtohd(dentry)->d_inode->i_mode, NULL);
7260 + err = vfs_create(hidden_sto_dir_dentry->d_inode,
7261 + hidden_sto_dentry,
7262 + dtohd(dentry)->d_inode->i_mode);
7266 + printk(KERN_CRIT "mini_fo: nondir_unmod_to_mod: \
7267 + ERROR creating sto file.\n");
7271 + /* interpose on new inode */
7272 + if(itohi2(dentry->d_inode) != NULL) {
7273 + printk(KERN_CRIT "mini_fo: nondir_unmod_to_mod: \
7274 + ERROR, invalid inode detected.\n");
7279 + itohi2(dentry->d_inode) = igrab(dtohd2(dentry)->d_inode);
7281 + fist_copy_attr_timesizes(dentry->d_parent->d_inode,
7282 + hidden_sto_dir_dentry->d_inode);
7283 + dtost(dentry) = MODIFIED;
7285 + /* copy contents if regular file and cp_flag = 1 */
7286 + if((cp_flag == 1) && S_ISREG(dentry->d_inode->i_mode)) {
7288 + /* unlock first */
7289 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
7290 + mutex_unlock(&hidden_sto_dir_dentry->d_inode->i_mutex);
7292 + up(&hidden_sto_dir_dentry->d_inode->i_sem);
7295 + dput(hidden_sto_dir_dentry);
7297 + tgt_dentry = dtohd2(dentry);
7298 + tgt_mnt = stopd(dentry->d_inode->i_sb)->hidden_mnt2;
7299 + src_dentry = dtohd(dentry);
7300 + src_mnt = stopd(dentry->d_inode->i_sb)->hidden_mnt;
7302 + err = mini_fo_cp_cont(tgt_dentry, tgt_mnt,
7303 + src_dentry, src_mnt);
7305 + printk(KERN_CRIT "mini_fo: nondir_unmod_to_mod: \
7306 + ERROR copying contents.\n");
7312 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
7313 + mutex_unlock(&hidden_sto_dir_dentry->d_inode->i_mutex);
7315 + up(&hidden_sto_dir_dentry->d_inode->i_sem);
7317 + dput(hidden_sto_dir_dentry);
7322 +/* this function is currently identical to nondir_creat_to_del */
7323 +int nondir_del_rew_to_del(dentry_t *dentry)
7325 + return nondir_creat_to_del(dentry);
7328 +int nondir_creat_to_del(dentry_t *dentry)
7332 + inode_t *hidden_sto_dir_inode;
7333 + dentry_t *hidden_sto_dir_dentry;
7334 + dentry_t *hidden_sto_dentry;
7336 + check_mini_fo_dentry(dentry);
7338 + /* for now this function serves for both state DEL_REWRITTEN and
7340 + if(!(dtost(dentry) == CREATED || (dtost(dentry) == DEL_REWRITTEN)) ||
7341 + S_ISDIR(dentry->d_inode->i_mode)) {
7342 + printk(KERN_CRIT "mini_fo: nondir_mod_to_del/del_rew_to_del: \
7343 + wrong type or state.\n");
7348 + hidden_sto_dir_inode = itohi2(dentry->d_parent->d_inode);
7349 + hidden_sto_dentry = dtohd2(dentry);
7351 + /* was: hidden_sto_dir_dentry = lock_parent(hidden_sto_dentry);*/
7352 + hidden_sto_dir_dentry = dget(hidden_sto_dentry->d_parent);
7354 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
7355 + mutex_lock(&hidden_sto_dir_dentry->d_inode->i_mutex);
7357 + down(&hidden_sto_dir_dentry->d_inode->i_sem);
7360 + /* avoid destroying the hidden inode if the file is in use */
7361 + dget(hidden_sto_dentry);
7362 + err = vfs_unlink(hidden_sto_dir_inode, hidden_sto_dentry);
7363 + dput(hidden_sto_dentry);
7365 + d_delete(hidden_sto_dentry);
7367 + /* propagate number of hard-links */
7368 + dentry->d_inode->i_nlink = itohi2(dentry->d_inode)->i_nlink;
7370 + dtost(dentry) = NON_EXISTANT;
7372 + /* was: unlock_dir(hidden_sto_dir_dentry); */
7373 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
7374 + mutex_unlock(&hidden_sto_dir_dentry->d_inode->i_mutex);
7376 + up(&hidden_sto_dir_dentry->d_inode->i_sem);
7378 + dput(hidden_sto_dir_dentry);
7384 +int nondir_mod_to_del(dentry_t *dentry)
7387 + dentry_t *hidden_sto_dentry;
7388 + inode_t *hidden_sto_dir_inode;
7389 + dentry_t *hidden_sto_dir_dentry;
7391 + check_mini_fo_dentry(dentry);
7393 + if(dtost(dentry) != MODIFIED ||
7394 + S_ISDIR(dentry->d_inode->i_mode)) {
7395 + printk(KERN_CRIT "mini_fo: nondir_mod_to_del: \
7396 + wrong type or state.\n");
7401 + hidden_sto_dir_inode = itohi2(dentry->d_parent->d_inode);
7402 + hidden_sto_dentry = dtohd2(dentry);
7404 + /* was hidden_sto_dir_dentry = lock_parent(hidden_sto_dentry); */
7405 + hidden_sto_dir_dentry = dget(hidden_sto_dentry->d_parent);
7407 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
7408 + mutex_lock(&hidden_sto_dir_dentry->d_inode->i_mutex);
7410 + down(&hidden_sto_dir_dentry->d_inode->i_sem);
7413 + /* avoid destroying the hidden inode if the file is in use */
7414 + dget(hidden_sto_dentry);
7415 + err = vfs_unlink(hidden_sto_dir_inode, hidden_sto_dentry);
7416 + dput(hidden_sto_dentry);
7418 + d_delete(hidden_sto_dentry);
7420 + /* propagate number of hard-links */
7421 + dentry->d_inode->i_nlink = itohi2(dentry->d_inode)->i_nlink;
7423 + /* dput base dentry, this will relase the inode and free the
7424 + * dentry, as we will never need it again. */
7425 + dput(dtohd(dentry));
7426 + dtohd(dentry) = NULL;
7427 + dtost(dentry) = DELETED;
7429 + /* add deleted file to META-file */
7430 + meta_add_d_entry(dentry->d_parent,
7431 + dentry->d_name.name,
7432 + dentry->d_name.len);
7434 + /* was: unlock_dir(hidden_sto_dir_dentry); */
7435 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
7436 + mutex_unlock(&hidden_sto_dir_dentry->d_inode->i_mutex);
7438 + up(&hidden_sto_dir_dentry->d_inode->i_sem);
7440 + dput(hidden_sto_dir_dentry);
7446 +int nondir_unmod_to_del(dentry_t *dentry)
7450 + check_mini_fo_dentry(dentry);
7452 + if(dtost(dentry) != UNMODIFIED ||
7453 + S_ISDIR(dentry->d_inode->i_mode)) {
7454 + printk(KERN_CRIT "mini_fo: nondir_unmod_to_del: \
7455 + wrong type or state.\n");
7460 + /* next we have to get a negative dentry for the storage file */
7461 + err = get_neg_sto_dentry(dentry);
7466 + /* add deleted file to META lists */
7467 + err = meta_add_d_entry(dentry->d_parent,
7468 + dentry->d_name.name,
7469 + dentry->d_name.len);
7474 + /* dput base dentry, this will relase the inode and free the
7475 + * dentry, as we will never need it again. */
7476 + dput(dtohd(dentry));
7477 + dtohd(dentry) = NULL;
7478 + dtost(dentry) = DELETED;
7484 +/* bring a dir from state UNMODIFIED to MODIFIED */
7485 +int dir_unmod_to_mod(dentry_t *dentry)
7489 + check_mini_fo_dentry(dentry);
7491 + if(dtost(dentry) != UNMODIFIED ||
7492 + !S_ISDIR(dentry->d_inode->i_mode)) {
7493 + printk(KERN_CRIT "mini_fo: dir_unmod_to_mod: \
7494 + wrong type or state.\n");
7499 + /* this creates our dir incl. sto. structure */
7500 + err = build_sto_structure(dentry->d_parent, dentry);
7502 + printk(KERN_CRIT "mini_fo: dir_unmod_to_mod: \
7503 + build_sto_structure failed.\n");
7510 diff -urN linux.old/fs/mini_fo/super.c linux.dev/fs/mini_fo/super.c
7511 --- linux.old/fs/mini_fo/super.c 1970-01-01 01:00:00.000000000 +0100
7512 +++ linux.dev/fs/mini_fo/super.c 2006-10-30 03:42:09.000000000 +0100
7515 + * Copyright (c) 1997-2003 Erez Zadok
7516 + * Copyright (c) 2001-2003 Stony Brook University
7518 + * For specific licensing information, see the COPYING file distributed with
7519 + * this package, or get one from ftp://ftp.filesystems.org/pub/fist/COPYING.
7521 + * This Copyright notice must be kept intact and distributed with all
7522 + * fistgen sources INCLUDING sources generated by fistgen.
7525 + * Copyright (C) 2004, 2005 Markus Klotzbuecher <mk@creamnet.de>
7527 + * This program is free software; you can redistribute it and/or
7528 + * modify it under the terms of the GNU General Public License
7529 + * as published by the Free Software Foundation; either version
7530 + * 2 of the License, or (at your option) any later version.
7537 +#ifdef HAVE_CONFIG_H
7538 +# include <config.h>
7542 +#include "mini_fo.h"
7546 +mini_fo_read_inode(inode_t *inode)
7548 + static struct address_space_operations mini_fo_empty_aops;
7550 + __itopd(inode) = kmalloc(sizeof(struct mini_fo_inode_info), GFP_KERNEL);
7551 + if (!itopd(inode)) {
7552 + printk("<0>%s:%s:%d: No kernel memory!\n", __FILE__, __FUNCTION__, __LINE__);
7555 + itohi(inode) = NULL;
7556 + itohi2(inode) = NULL;
7558 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
7559 + inode->i_version++;
7561 + inode->i_version = ++event; /* increment inode version */
7563 + inode->i_op = &mini_fo_main_iops;
7564 + inode->i_fop = &mini_fo_main_fops;
7567 + * XXX: To export a file system via NFS, it has to have the
7568 + * FS_REQUIRES_DEV flag, so turn it on. But should we inherit it from
7569 + * the lower file system, or can we allow our file system to be exported
7570 + * even if the lower one cannot be natively exported.
7572 + inode->i_sb->s_type->fs_flags |= FS_REQUIRES_DEV;
7574 + * OK, the above was a hack, which is now turned off because it may
7575 + * cause a panic/oops on some systems. The correct way to export a
7576 + * "nodev" filesystem is via using nfs-utils > 1.0 and the "fsid=" export
7577 + * parameter, which requires 2.4.20 or later.
7580 + /* I don't think ->a_ops is ever allowed to be NULL */
7581 + inode->i_mapping->a_ops = &mini_fo_empty_aops;
7585 +#if defined(FIST_DEBUG) || defined(FIST_FILTER_SCA)
7587 + * No need to call write_inode() on the lower inode, as it
7588 + * will have been marked 'dirty' anyway. But we might need
7589 + * to write some of our own stuff to disk.
7592 +mini_fo_write_inode(inode_t *inode, int sync)
7594 + print_entry_location();
7595 + print_exit_location();
7597 +#endif /* defined(FIST_DEBUG) || defined(FIST_FILTER_SCA) */
7601 +mini_fo_put_inode(inode_t *inode)
7604 + * This is really funky stuff:
7605 + * Basically, if i_count == 1, iput will then decrement it and this inode will be destroyed.
7606 + * It is currently holding a reference to the hidden inode.
7607 + * Therefore, it needs to release that reference by calling iput on the hidden inode.
7608 + * iput() _will_ do it for us (by calling our clear_inode), but _only_ if i_nlink == 0.
7609 + * The problem is, NFS keeps i_nlink == 1 for silly_rename'd files.
7610 + * So we must for our i_nlink to 0 here to trick iput() into calling our clear_inode.
7612 + if (atomic_read(&inode->i_count) == 1)
7613 + inode->i_nlink = 0;
7617 +#if defined(FIST_DEBUG) || defined(FIST_FILTER_SCA)
7619 + * we now define delete_inode, because there are two VFS paths that may
7620 + * destroy an inode: one of them calls clear inode before doing everything
7621 + * else that's needed, and the other is fine. This way we truncate the inode
7622 + * size (and its pages) and then clear our own inode, which will do an iput
7623 + * on our and the lower inode.
7626 +mini_fo_delete_inode(inode_t *inode)
7628 + print_entry_location();
7630 + fist_checkinode(inode, "mini_fo_delete_inode IN");
7631 + inode->i_size = 0; /* every f/s seems to do that */
7632 + clear_inode(inode);
7634 + print_exit_location();
7636 +#endif /* defined(FIST_DEBUG) || defined(FIST_FILTER_SCA) */
7639 +/* final actions when unmounting a file system */
7641 +mini_fo_put_super(super_block_t *sb)
7644 + mntput(stopd(sb)->hidden_mnt);
7645 + mntput(stopd(sb)->hidden_mnt2);
7647 + /* mk: no! dput(stopd(sb)->base_dir_dentry);
7648 + dput(stopd(sb)->storage_dir_dentry); */
7651 + __stopd(sb) = NULL;
7658 + * This is called in do_umount before put_super.
7659 + * The superblock lock is not held yet.
7660 + * We probably do not need to define this or call write_super
7661 + * on the hidden_sb, because sync_supers() will get to hidden_sb
7662 + * sooner or later. But it is also called from file_fsync()...
7665 +mini_fo_write_super(super_block_t *sb)
7669 +#endif /* NOT_NEEDED */
7673 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
7674 +mini_fo_statfs(super_block_t *sb, struct kstatfs *buf)
7676 +mini_fo_statfs(super_block_t *sb, struct statfs *buf)
7680 + super_block_t *hidden_sb;
7682 + hidden_sb = stohs(sb);
7683 + err = vfs_statfs(hidden_sb, buf);
7690 + * XXX: not implemented. This is not allowed yet.
7691 + * Should we call this on the hidden_sb? Probably not.
7694 +mini_fo_remount_fs(super_block_t *sb, int *flags, char *data)
7696 + //printk(KERN_CRIT "mini_fo_remount_fs: WARNING, this function is umimplemented.\n");
7702 + * Called by iput() when the inode reference count reached zero
7703 + * and the inode is not hashed anywhere. Used to clear anything
7704 + * that needs to be, before the inode is completely destroyed and put
7705 + * on the inode free list.
7708 +mini_fo_clear_inode(inode_t *inode)
7711 + * Decrement a reference to a hidden_inode, which was incremented
7712 + * by our read_inode when it was created initially.
7715 + /* release the wol_list */
7716 + if(S_ISDIR(inode->i_mode)) {
7717 + __meta_put_lists(inode);
7720 + /* mk: fan out fun */
7722 + iput(itohi(inode));
7724 + iput(itohi2(inode));
7726 + // XXX: why this assertion fails?
7727 + // because it doesn't like us
7728 + // ASSERT((inode->i_state & I_DIRTY) == 0);
7729 + kfree(itopd(inode));
7730 + __itopd(inode) = NULL;
7735 + * Called in do_umount() if the MNT_FORCE flag was used and this
7736 + * function is defined. See comment in linux/fs/super.c:do_umount().
7737 + * Used only in nfs, to kill any pending RPC tasks, so that subsequent
7738 + * code can actually succeed and won't leave tasks that need handling.
7740 + * PS. I wonder if this is somehow useful to undo damage that was
7741 + * left in the kernel after a user level file server (such as amd)
7745 +mini_fo_umount_begin(super_block_t *sb)
7747 + super_block_t *hidden_sb;
7749 + hidden_sb = stohs(sb);
7751 + if (hidden_sb->s_op->umount_begin)
7752 + hidden_sb->s_op->umount_begin(hidden_sb);
7757 +struct super_operations mini_fo_sops =
7759 + read_inode: mini_fo_read_inode,
7760 +#if defined(FIST_DEBUG) || defined(FIST_FILTER_SCA)
7761 + write_inode: mini_fo_write_inode,
7762 +#endif /* defined(FIST_DEBUG) || defined(FIST_FILTER_SCA) */
7763 + put_inode: mini_fo_put_inode,
7764 +#if defined(FIST_DEBUG) || defined(FIST_FILTER_SCA)
7765 + delete_inode: mini_fo_delete_inode,
7766 +#endif /* defined(FIST_DEBUG) || defined(FIST_FILTER_SCA) */
7767 + put_super: mini_fo_put_super,
7768 + statfs: mini_fo_statfs,
7769 + remount_fs: mini_fo_remount_fs,
7770 + clear_inode: mini_fo_clear_inode,
7771 + umount_begin: mini_fo_umount_begin,