1 diff -urN linux.old/fs/Config.in linux.dev/fs/Config.in
2 --- linux.old/fs/Config.in 2006-10-28 22:29:42.000000000 +0200
3 +++ linux.dev/fs/Config.in 2006-10-29 01:45:26.000000000 +0200
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-28 22:29:42.000000000 +0200
14 +++ linux.dev/fs/Makefile 2006-10-29 01:45:50.000000000 +0200
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-29 04:32:06.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-29 01:18:22.000000000 +0200
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-29 04:32:06.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-29 04:32:06.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 2005-10-15 12:49:43.000000000 +0200
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-29 04:32:06.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 + hidden_sto_dir = itohi2(dir);
2655 + hidden_sto_dentry = dtohd2(dentry);
2657 + /* was:hidden_sto_dir_dentry = lock_parent(hidden_sto_dentry); */
2658 + hidden_sto_dir_dentry = dget(hidden_sto_dentry->d_parent);
2659 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
2660 + mutex_lock(&hidden_sto_dir_dentry->d_inode->i_mutex);
2662 + down(&hidden_sto_dir_dentry->d_inode->i_sem);
2665 + /* avoid destroying the hidden inode if the file is in use */
2666 + dget(hidden_sto_dentry);
2668 + /* Delete an old WOL file contained in the storage dir */
2669 + meta_dentry = lookup_one_len(META_FILENAME,
2670 + hidden_sto_dentry,
2671 + strlen(META_FILENAME));
2672 + if(meta_dentry->d_inode) {
2673 + err = vfs_unlink(hidden_sto_dentry->d_inode, meta_dentry);
2674 + dput(meta_dentry);
2676 + d_delete(meta_dentry);
2679 + err = vfs_rmdir(hidden_sto_dir, hidden_sto_dentry);
2680 + dput(hidden_sto_dentry);
2682 + d_delete(hidden_sto_dentry);
2684 + /* propagate number of hard-links */
2685 + dentry->d_inode->i_nlink = itohi2(dentry->d_inode)->i_nlink;
2687 + dput(dtohd(dentry));
2689 + dtohd(dentry) = NULL;
2690 + dtopd(dentry)->state = DELETED;
2692 + /* carefull with R files */
2693 + if( __meta_is_r_entry(dir,
2694 + dentry->d_name.name,
2695 + dentry->d_name.len) == 1) {
2696 + err = meta_remove_r_entry(dentry->d_parent,
2697 + dentry->d_name.name,
2698 + dentry->d_name.len);
2700 + printk(KERN_CRIT "mini_fo: rmdir: meta_remove_r_entry failed.\n");
2705 + /* XXX: disabled, because it does not bother to check files on
2706 + * the original filesystem - just a hack, but better than simply
2707 + * removing it without testing */
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) {
2727 + err = get_neg_sto_dentry(dentry);
2733 + /* XXX: simply adding it to the delete list here is fscking dangerous!
2734 + * as a temporary hack, i will disable rmdir on unmodified directories
2740 + /* dput base dentry, this will relase the inode and free the
2741 + * dentry, as we will never need it again. */
2742 + dput(dtohd(dentry));
2743 + dtohd(dentry) = NULL;
2744 + dtopd(dentry)->state = DELETED;
2746 + /* add deleted file to META-file */
2747 + meta_add_d_entry(dentry->d_parent,
2748 + dentry->d_name.name,
2749 + dentry->d_name.len);
2752 + else if(dtopd(dentry)->state == CREATED) {
2753 + hidden_sto_dir = itohi2(dir);
2754 + hidden_sto_dentry = dtohd2(dentry);
2756 + /* was: hidden_sto_dir_dentry = lock_parent(hidden_sto_dentry);*/
2757 + hidden_sto_dir_dentry = dget(hidden_sto_dentry->d_parent);
2759 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
2760 + mutex_lock(&hidden_sto_dir_dentry->d_inode->i_mutex);
2762 + down(&hidden_sto_dir_dentry->d_inode->i_sem);
2765 + /* avoid destroying the hidden inode if the file is in use */
2766 + dget(hidden_sto_dentry);
2768 + /* Delete an old WOL file contained in the storage dir */
2769 + meta_dentry = lookup_one_len(META_FILENAME,
2770 + hidden_sto_dentry,
2771 + strlen(META_FILENAME));
2772 + if(meta_dentry->d_inode) {
2773 + /* is this necessary? dget(meta_dentry); */
2774 + err = vfs_unlink(hidden_sto_dentry->d_inode,
2776 + dput(meta_dentry);
2778 + d_delete(meta_dentry);
2781 + err = vfs_rmdir(hidden_sto_dir, hidden_sto_dentry);
2782 + dput(hidden_sto_dentry);
2784 + d_delete(hidden_sto_dentry);
2786 + /* propagate number of hard-links */
2787 + dentry->d_inode->i_nlink = itohi2(dentry->d_inode)->i_nlink;
2788 + dtopd(dentry)->state = NON_EXISTANT;
2790 + /* was: unlock_dir(hidden_sto_dir_dentry); */
2791 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
2792 + mutex_unlock(&hidden_sto_dir_dentry->d_inode->i_mutex);
2794 + up(&hidden_sto_dir_dentry->d_inode->i_sem);
2796 + dput(hidden_sto_dir_dentry);
2800 + else if(dtopd(dentry)->state == DEL_REWRITTEN) {
2801 + hidden_sto_dir = itohi2(dir);
2802 + hidden_sto_dentry = dtohd2(dentry);
2804 + /* was: hidden_sto_dir_dentry = lock_parent(hidden_sto_dentry);*/
2805 + hidden_sto_dir_dentry = dget(hidden_sto_dentry->d_parent);
2807 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
2808 + mutex_lock(&hidden_sto_dir_dentry->d_inode->i_mutex);
2810 + down(&hidden_sto_dir_dentry->d_inode->i_sem);
2813 + /* avoid destroying the hidden inode if the file is in use */
2814 + dget(hidden_sto_dentry);
2816 + /* Delete an old WOL file contained in the storage dir */
2817 + meta_dentry = lookup_one_len(META_FILENAME,
2818 + hidden_sto_dentry,
2819 + strlen(META_FILENAME));
2820 + if(meta_dentry->d_inode) {
2821 + /* is this necessary? dget(meta_dentry); */
2822 + err = vfs_unlink(hidden_sto_dentry->d_inode,
2824 + dput(meta_dentry);
2826 + d_delete(meta_dentry);
2829 + err = vfs_rmdir(hidden_sto_dir, hidden_sto_dentry);
2830 + dput(hidden_sto_dentry);
2832 + d_delete(hidden_sto_dentry);
2834 + /* propagate number of hard-links */
2835 + dentry->d_inode->i_nlink = itohi2(dentry->d_inode)->i_nlink;
2836 + dtopd(dentry)->state = DELETED;
2837 + /* was: unlock_dir(hidden_sto_dir_dentry); */
2839 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
2840 + mutex_unlock(&hidden_sto_dir_dentry->d_inode->i_mutex);
2842 + up(&hidden_sto_dir_dentry->d_inode->i_sem);
2844 + dput(hidden_sto_dir_dentry);
2848 + printk(KERN_CRIT "mini_fo_rmdir: ERROR, invalid state detected.\n");
2855 + fist_copy_attr_times(dir, itohi2(dentry->d_parent->d_inode));
2863 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
2864 +mini_fo_mknod(inode_t *dir, dentry_t *dentry, int mode, dev_t dev)
2866 +mini_fo_mknod(inode_t *dir, dentry_t *dentry, int mode, int dev)
2871 + check_mini_fo_dentry(dentry);
2873 + err = create_sto_nod(dentry, mode, dev);
2875 + printk(KERN_CRIT "mini_fo_mknod: creating sto nod failed.\n");
2879 + check_mini_fo_dentry(dentry);
2885 +mini_fo_rename(inode_t *old_dir, dentry_t *old_dentry,
2886 + inode_t *new_dir, dentry_t *new_dentry)
2889 + if(S_ISDIR(old_dentry->d_inode->i_mode))
2890 + return rename_directory(old_dir, old_dentry, new_dir, new_dentry);
2891 + return rename_nondir(old_dir, old_dentry, new_dir, new_dentry);
2895 +int rename_directory(inode_t *old_dir, dentry_t *old_dentry,
2896 + inode_t *new_dir, dentry_t *new_dentry)
2898 + int err, bpath_len;
2901 + dentry_t *hidden_old_dentry;
2902 + dentry_t *hidden_new_dentry;
2903 + dentry_t *hidden_old_dir_dentry;
2904 + dentry_t *hidden_new_dir_dentry;
2910 + /* this is a test, chuck out if it works */
2911 + if(!(dtopd(new_dentry)->state == DELETED ||
2912 + dtopd(new_dentry)->state == NON_EXISTANT)) {
2913 + printk(KERN_CRIT "mini_fo: rename_directory: \
2914 + uh, ah, new_dentry not negative.\n");
2918 + /* state = UNMODIFIED */
2919 + if(dtopd(old_dentry)->state == UNMODIFIED) {
2920 + err = dir_unmod_to_mod(old_dentry);
2925 + /* state = MODIFIED */
2926 + if(dtopd(old_dentry)->state == MODIFIED) {
2927 + bpath = meta_check_r_entry(old_dentry->d_parent,
2928 + old_dentry->d_name.name,
2929 + old_dentry->d_name.len);
2931 + err = meta_remove_r_entry(old_dentry->d_parent,
2932 + old_dentry->d_name.name,
2933 + old_dentry->d_name.len);
2935 + printk(KERN_CRIT "mini_fo: rename_directory:\
2936 + meta_remove_r_entry \
2940 + err = meta_add_r_entry(new_dentry->d_parent,
2943 + new_dentry->d_name.name,
2944 + new_dentry->d_name.len);
2947 + else {/* wol it */
2948 + err = meta_add_d_entry(old_dentry->d_parent,
2949 + old_dentry->d_name.name,
2950 + old_dentry->d_name.len);
2953 + /* put it on rename list */
2954 + err = get_mini_fo_bpath(old_dentry,
2959 + err = meta_add_r_entry(new_dentry->d_parent,
2961 + new_dentry->d_name.name,
2962 + new_dentry->d_name.len);
2966 + /* no state change, MODIFIED stays MODIFIED */
2968 + /* state = CREATED */
2969 + if(dtopd(old_dentry)->state == CREATED ||
2970 + dtopd(old_dentry)->state == DEL_REWRITTEN) {
2971 + if(dtohd(old_dentry))
2972 + dput(dtohd(old_dentry));
2974 + if(dtopd(new_dentry)->state == DELETED) {
2975 + dtopd(old_dentry)->state = DEL_REWRITTEN;
2976 + dtohd(old_dentry) = NULL;
2978 + else if(dtopd(new_dentry)->state == NON_EXISTANT) {
2979 + dtopd(old_dentry)->state = CREATED;
2980 + /* steal new dentry's neg. base dentry */
2981 + dtohd(old_dentry) = dtohd(new_dentry);
2982 + dtohd(new_dentry) = NULL;
2985 + if(dtopd(new_dentry)->state == UNMODIFIED ||
2986 + dtopd(new_dentry)->state == NON_EXISTANT) {
2987 + err = get_neg_sto_dentry(new_dentry);
2992 + /* now move sto file */
2993 + hidden_old_dentry = dtohd2(old_dentry);
2994 + hidden_new_dentry = dtohd2(new_dentry);
2996 + dget(hidden_old_dentry);
2997 + dget(hidden_new_dentry);
2999 + hidden_old_dir_dentry = dget(hidden_old_dentry->d_parent);
3000 + hidden_new_dir_dentry = dget(hidden_new_dentry->d_parent);
3001 + double_lock(hidden_old_dir_dentry, hidden_new_dir_dentry);
3003 + err = vfs_rename(hidden_old_dir_dentry->d_inode, hidden_old_dentry,
3004 + hidden_new_dir_dentry->d_inode, hidden_new_dentry);
3008 + fist_copy_attr_all(new_dir, hidden_new_dir_dentry->d_inode);
3009 + if (new_dir != old_dir)
3010 + fist_copy_attr_all(old_dir,
3011 + hidden_old_dir_dentry->d_inode);
3014 + /* double_unlock will dput the new/old parent dentries
3015 + * whose refcnts were incremented via get_parent above. */
3016 + double_unlock(hidden_old_dir_dentry, hidden_new_dir_dentry);
3017 + dput(hidden_new_dentry);
3018 + dput(hidden_old_dentry);
3024 +int rename_nondir(inode_t *old_dir, dentry_t *old_dentry,
3025 + inode_t *new_dir, dentry_t *new_dentry)
3029 + check_mini_fo_dentry(old_dentry);
3030 + check_mini_fo_dentry(new_dentry);
3031 + check_mini_fo_inode(old_dir);
3032 + check_mini_fo_inode(new_dir);
3034 + /* state: UNMODIFIED */
3035 + if(dtost(old_dentry) == UNMODIFIED) {
3036 + err = nondir_unmod_to_mod(old_dentry, 1);
3043 + /* the easy states */
3044 + if(exists_in_storage(old_dentry)) {
3046 + dentry_t *hidden_old_dentry;
3047 + dentry_t *hidden_new_dentry;
3048 + dentry_t *hidden_old_dir_dentry;
3049 + dentry_t *hidden_new_dir_dentry;
3051 + /* if old file is MODIFIED, add it to the deleted_list */
3052 + if(dtopd(old_dentry)->state == MODIFIED) {
3053 + meta_add_d_entry(old_dentry->d_parent,
3054 + old_dentry->d_name.name,
3055 + old_dentry->d_name.len);
3057 + dput(dtohd(old_dentry));
3059 + /* if old file is CREATED, we only release the base dentry */
3060 + if(dtopd(old_dentry)->state == CREATED) {
3061 + if(dtohd(old_dentry))
3062 + dput(dtohd(old_dentry));
3065 + /* now setup the new states (depends on new_dentry state) */
3066 + /* new dentry state = MODIFIED */
3067 + if(dtopd(new_dentry)->state == MODIFIED) {
3068 + meta_add_d_entry(new_dentry->d_parent,
3069 + new_dentry->d_name.name,
3070 + new_dentry->d_name.len);
3072 + /* new dentry will be d_put'ed later by the vfs
3073 + * so don't do it here
3074 + * dput(dtohd(new_dentry));
3076 + dtohd(old_dentry) = NULL;
3077 + dtopd(old_dentry)->state = DEL_REWRITTEN;
3079 + /* new dentry state = UNMODIFIED */
3080 + else if(dtopd(new_dentry)->state == UNMODIFIED) {
3081 + if(get_neg_sto_dentry(new_dentry))
3084 + meta_add_d_entry(new_dentry->d_parent,
3085 + new_dentry->d_name.name,
3086 + new_dentry->d_name.len);
3088 + /* is this right??? */
3089 + /*dput(dtohd(new_dentry));*/
3090 + dtohd(old_dentry) = NULL;
3091 + dtopd(old_dentry)->state = DEL_REWRITTEN;
3093 + /* new dentry state = CREATED */
3094 + else if(dtopd(new_dentry)->state == CREATED) {
3095 + /* we keep the neg. base dentry (if exists) */
3096 + dtohd(old_dentry) = dtohd(new_dentry);
3097 + /* ...and set it to Null, or we'll get
3098 + * dcache.c:345 if it gets dput twice... */
3099 + dtohd(new_dentry) = NULL;
3100 + dtopd(old_dentry)->state = CREATED;
3102 + /* new dentry state = NON_EXISTANT */
3103 + else if(dtopd(new_dentry)->state == NON_EXISTANT) {
3104 + if(get_neg_sto_dentry(new_dentry))
3107 + /* we keep the neg. base dentry (if exists) */
3108 + dtohd(old_dentry) = dtohd(new_dentry);
3109 + /* ...and set it to Null, or we'll get
3110 + * Dr. dcache.c:345 if it gets dput twice... */
3111 + dtohd(new_dentry) = NULL;
3112 + dtopd(old_dentry)->state = CREATED;
3114 + /* new dentry state = DEL_REWRITTEN or DELETED */
3115 + else if(dtopd(new_dentry)->state == DEL_REWRITTEN ||
3116 + dtopd(new_dentry)->state == DELETED) {
3117 + dtohd(old_dentry) = NULL;
3118 + dtopd(old_dentry)->state = DEL_REWRITTEN;
3120 + else { /* not possible, uhh, ahh */
3122 + "mini_fo: rename_reg_file: invalid state detected [1].\n");
3126 + /* now we definitely have a sto file */
3127 + hidden_old_dentry = dtohd2(old_dentry);
3128 + hidden_new_dentry = dtohd2(new_dentry);
3130 + dget(hidden_old_dentry);
3131 + dget(hidden_new_dentry);
3133 + hidden_old_dir_dentry = dget(hidden_old_dentry->d_parent);
3134 + hidden_new_dir_dentry = dget(hidden_new_dentry->d_parent);
3135 + double_lock(hidden_old_dir_dentry, hidden_new_dir_dentry);
3137 + err = vfs_rename(hidden_old_dir_dentry->d_inode,
3138 + hidden_old_dentry,
3139 + hidden_new_dir_dentry->d_inode,
3140 + hidden_new_dentry);
3144 + fist_copy_attr_all(new_dir, hidden_new_dir_dentry->d_inode);
3145 + if (new_dir != old_dir)
3146 + fist_copy_attr_all(old_dir, hidden_old_dir_dentry->d_inode);
3149 + /* double_unlock will dput the new/old parent dentries
3150 + * whose refcnts were incremented via get_parent above.
3152 + double_unlock(hidden_old_dir_dentry, hidden_new_dir_dentry);
3153 + dput(hidden_new_dentry);
3154 + dput(hidden_old_dentry);
3158 + else { /* invalid state */
3159 + printk(KERN_CRIT "mini_fo: rename_reg_file: ERROR: invalid state detected [2].\n");
3166 +mini_fo_readlink(dentry_t *dentry, char *buf, int bufsiz)
3169 + dentry_t *hidden_dentry = NULL;
3171 + if(dtohd2(dentry) && dtohd2(dentry)->d_inode) {
3172 + hidden_dentry = dtohd2(dentry);
3173 + } else if(dtohd(dentry) && dtohd(dentry)->d_inode) {
3174 + hidden_dentry = dtohd(dentry);
3179 + if (!hidden_dentry->d_inode->i_op ||
3180 + !hidden_dentry->d_inode->i_op->readlink) {
3181 + err = -EINVAL; goto out;
3184 + err = hidden_dentry->d_inode->i_op->readlink(hidden_dentry,
3188 + fist_copy_attr_atime(dentry->d_inode, hidden_dentry->d_inode);
3195 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,13)
3196 +static int mini_fo_follow_link(dentry_t *dentry, struct nameidata *nd)
3198 +static void* mini_fo_follow_link(dentry_t *dentry, struct nameidata *nd)
3202 + int len = PAGE_SIZE, err;
3203 + mm_segment_t old_fs;
3205 + /* in 2.6 this is freed by mini_fo_put_link called by __do_follow_link */
3206 + buf = kmalloc(len, GFP_KERNEL);
3212 + /* read the symlink, and then we will follow it */
3213 + old_fs = get_fs();
3214 + set_fs(KERNEL_DS);
3215 + err = dentry->d_inode->i_op->readlink(dentry, buf, len);
3223 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
3224 + nd_set_link(nd, buf);
3227 + err = vfs_follow_link(nd, buf);
3231 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
3235 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,13)
3238 + return ERR_PTR(err);
3243 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
3244 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,13)
3245 +void mini_fo_put_link(struct dentry *dentry, struct nameidata *nd)
3247 +void mini_fo_put_link(struct dentry *dentry, struct nameidata *nd, void *cookie)
3251 + link = nd_get_link(nd);
3257 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
3258 +mini_fo_permission(inode_t *inode, int mask, struct nameidata *nd)
3260 +mini_fo_permission(inode_t *inode, int mask)
3263 + inode_t *hidden_inode;
3267 + if(itohi2(inode)) {
3268 + hidden_inode = itohi2(inode);
3270 + hidden_inode = itohi(inode);
3272 + mode = inode->i_mode;
3274 + /* not really needed, as permission handles everything:
3275 + * err = vfs_permission(inode, mask);
3280 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
3281 + err = permission(hidden_inode, mask, nd);
3283 + err = permission(hidden_inode, mask);
3290 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
3292 +mini_fo_inode_revalidate(dentry_t *dentry)
3295 + dentry_t *hidden_dentry;
3296 + inode_t *hidden_inode;
3298 + ASSERT(dentry->d_inode);
3299 + ASSERT(itopd(dentry->d_inode));
3301 + if(itohi2(dentry->d_inode)) {
3302 + hidden_dentry = dtohd2(dentry);
3303 + hidden_inode = hidden_dentry->d_inode;
3304 + } else if(itohi(dentry->d_inode)) {
3305 + hidden_dentry = dtohd(dentry);
3306 + hidden_inode = hidden_dentry->d_inode;
3308 + printk(KERN_CRIT "mini_fo_inode_revalidate: ERROR, invalid state detected.\n");
3312 + if (hidden_inode && hidden_inode->i_op && hidden_inode->i_op->revalidate){
3313 + err = hidden_inode->i_op->revalidate(hidden_dentry);
3317 + fist_copy_attr_all(dentry->d_inode, hidden_inode);
3324 +mini_fo_setattr(dentry_t *dentry, struct iattr *ia)
3328 + check_mini_fo_dentry(dentry);
3330 + if(!is_mini_fo_existant(dentry)) {
3331 + printk(KERN_CRIT "mini_fo_setattr: ERROR, invalid state detected [1].\n");
3335 + if(dtost(dentry) == UNMODIFIED) {
3336 + if(!IS_COPY_FLAG(ia->ia_valid))
3337 + goto out; /* we ignore these changes to base */
3339 + if(S_ISDIR(dentry->d_inode->i_mode)) {
3340 + err = dir_unmod_to_mod(dentry);
3342 + /* we copy contents if file is not beeing truncated */
3343 + if(S_ISREG(dentry->d_inode->i_mode) &&
3344 + !(ia->ia_size == 0 && (ia->ia_valid & ATTR_SIZE))) {
3345 + err = nondir_unmod_to_mod(dentry, 1);
3347 + err = nondir_unmod_to_mod(dentry, 0);
3351 + printk(KERN_CRIT "mini_fo_setattr: ERROR changing states.\n");
3355 + if(!exists_in_storage(dentry)) {
3356 + printk(KERN_CRIT "mini_fo_setattr: ERROR, invalid state detected [2].\n");
3360 + ASSERT(dentry->d_inode);
3361 + ASSERT(dtohd2(dentry));
3362 + ASSERT(itopd(dentry->d_inode));
3363 + ASSERT(itohi2(dentry->d_inode));
3365 + err = notify_change(dtohd2(dentry), ia);
3366 + fist_copy_attr_all(dentry->d_inode, itohi2(dentry->d_inode));
3371 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
3373 +mini_fo_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
3376 + dentry_t *hidden_dentry;
3378 + ASSERT(dentry->d_inode);
3379 + ASSERT(itopd(dentry->d_inode));
3381 + if(itohi2(dentry->d_inode)) {
3382 + hidden_dentry = dtohd2(dentry);
3383 + } else if(itohi(dentry->d_inode)) {
3384 + hidden_dentry = dtohd(dentry);
3386 + printk(KERN_CRIT "mini_fo_getattr: ERROR, invalid state detected.\n");
3390 + fist_copy_attr_all(dentry->d_inode, hidden_dentry->d_inode);
3392 + ASSERT(hidden_dentry);
3393 + ASSERT(hidden_dentry->d_inode);
3394 + ASSERT(hidden_dentry->d_inode->i_op);
3396 + generic_fillattr(dentry->d_inode, stat);
3397 + if (!stat->blksize) {
3398 + struct super_block *s = hidden_dentry->d_inode->i_sb;
3400 + blocks = (stat->size+s->s_blocksize-1) >> s->s_blocksize_bits;
3401 + stat->blocks = (s->s_blocksize / 512) * blocks;
3402 + stat->blksize = s->s_blocksize;
3409 +#if defined(XATTR) && (LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,20))
3410 +#if 0 /* no xattr_alloc() and xattr_free() */
3411 +/* This is lifted from fs/xattr.c */
3413 +xattr_alloc(size_t size, size_t limit)
3418 + return ERR_PTR(-E2BIG);
3420 + if (!size) /* size request, no buffer is needed */
3422 + else if (size <= PAGE_SIZE)
3423 + ptr = kmalloc((unsigned long) size, GFP_KERNEL);
3425 + ptr = vmalloc((unsigned long) size);
3427 + return ERR_PTR(-ENOMEM);
3432 +xattr_free(void *ptr, size_t size)
3434 + if (!size) /* size request, no buffer was needed */
3436 + else if (size <= PAGE_SIZE)
3441 +#endif /* no xattr_alloc() and xattr_free() */
3443 +/* BKL held by caller.
3444 + * dentry->d_inode->i_sem down
3447 +mini_fo_getxattr(struct dentry *dentry, const char *name, void *value, size_t size) {
3448 + struct dentry *hidden_dentry = NULL;
3449 + int err = -EOPNOTSUPP;
3450 + /* Define these anyway so we don't need as much ifdef'ed code. */
3451 + char *encoded_name = NULL;
3452 + char *encoded_value = NULL;
3454 + check_mini_fo_dentry(dentry);
3456 + if(exists_in_storage(dentry))
3457 + hidden_dentry = dtohd2(dentry);
3459 + hidden_dentry = dtohd(dentry);
3461 + ASSERT(hidden_dentry);
3462 + ASSERT(hidden_dentry->d_inode);
3463 + ASSERT(hidden_dentry->d_inode->i_op);
3465 + if (hidden_dentry->d_inode->i_op->getxattr) {
3466 + encoded_name = (char *)name;
3467 + encoded_value = (char *)value;
3469 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
3470 + mutex_lock(&hidden_dentry->d_inode->i_mutex);
3472 + down(&hidden_dentry->d_inode->i_sem);
3474 + /* lock_kernel() already done by caller. */
3475 + err = hidden_dentry->d_inode->i_op->getxattr(hidden_dentry, encoded_name, encoded_value, size);
3476 + /* unlock_kernel() will be done by caller. */
3477 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
3478 + mutex_lock(&hidden_dentry->d_inode->i_mutex);
3480 + up(&hidden_dentry->d_inode->i_sem);
3486 +/* BKL held by caller.
3487 + * dentry->d_inode->i_sem down
3490 +#if ((LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,21) \
3491 + && LINUX_VERSION_CODE <= KERNEL_VERSION(2,4,23)) \
3492 + || LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0))
3493 +mini_fo_setxattr(struct dentry *dentry, const char *name,
3494 + const void *value, size_t size, int flags)
3496 +mini_fo_setxattr(struct dentry *dentry, const char *name,
3497 + void *value, size_t size, int flags)
3501 + struct dentry *hidden_dentry = NULL;
3502 + int err = -EOPNOTSUPP;
3504 + /* Define these anyway, so we don't have as much ifdef'ed code. */
3505 + char *encoded_value = NULL;
3506 + char *encoded_name = NULL;
3508 + check_mini_fo_dentry(dentry);
3510 + if(exists_in_storage(dentry))
3511 + hidden_dentry = dtohd2(dentry);
3513 + hidden_dentry = dtohd(dentry);
3515 + ASSERT(hidden_dentry);
3516 + ASSERT(hidden_dentry->d_inode);
3517 + ASSERT(hidden_dentry->d_inode->i_op);
3519 + if (hidden_dentry->d_inode->i_op->setxattr) {
3520 + encoded_name = (char *)name;
3521 + encoded_value = (char *)value;
3523 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
3524 + mutex_lock(&hidden_dentry->d_inode->i_mutex);
3526 + down(&hidden_dentry->d_inode->i_sem);
3528 + /* lock_kernel() already done by caller. */
3529 + err = hidden_dentry->d_inode->i_op->setxattr(hidden_dentry, encoded_name, encoded_value, size, flags);
3530 + /* unlock_kernel() will be done by caller. */
3531 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
3532 + mutex_unlock(&hidden_dentry->d_inode->i_mutex);
3534 + up(&hidden_dentry->d_inode->i_sem);
3540 +/* BKL held by caller.
3541 + * dentry->d_inode->i_sem down
3544 +mini_fo_removexattr(struct dentry *dentry, const char *name) {
3545 + struct dentry *hidden_dentry = NULL;
3546 + int err = -EOPNOTSUPP;
3547 + char *encoded_name;
3549 + check_mini_fo_dentry(dentry);
3551 + if(exists_in_storage(dentry))
3552 + hidden_dentry = dtohd2(dentry);
3554 + hidden_dentry = dtohd(dentry);
3556 + ASSERT(hidden_dentry);
3557 + ASSERT(hidden_dentry->d_inode);
3558 + ASSERT(hidden_dentry->d_inode->i_op);
3560 + if (hidden_dentry->d_inode->i_op->removexattr) {
3561 + encoded_name = (char *)name;
3563 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
3564 + mutex_lock(&hidden_dentry->d_inode->i_mutex);
3566 + down(&hidden_dentry->d_inode->i_sem);
3568 + /* lock_kernel() already done by caller. */
3569 + err = hidden_dentry->d_inode->i_op->removexattr(hidden_dentry, encoded_name);
3570 + /* unlock_kernel() will be done by caller. */
3571 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
3572 + mutex_unlock(&hidden_dentry->d_inode->i_mutex);
3574 + up(&hidden_dentry->d_inode->i_sem);
3580 +/* BKL held by caller.
3581 + * dentry->d_inode->i_sem down
3584 +mini_fo_listxattr(struct dentry *dentry, char *list, size_t size) {
3585 + struct dentry *hidden_dentry = NULL;
3586 + int err = -EOPNOTSUPP;
3587 + char *encoded_list = NULL;
3589 + check_mini_fo_dentry(dentry);
3591 + if(exists_in_storage(dentry))
3592 + hidden_dentry = dtohd2(dentry);
3594 + hidden_dentry = dtohd(dentry);
3596 + ASSERT(hidden_dentry);
3597 + ASSERT(hidden_dentry->d_inode);
3598 + ASSERT(hidden_dentry->d_inode->i_op);
3600 + if (hidden_dentry->d_inode->i_op->listxattr) {
3601 + encoded_list = list;
3603 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
3604 + mutex_lock(&hidden_dentry->d_inode->i_mutex);
3606 + down(&hidden_dentry->d_inode->i_sem);
3608 + /* lock_kernel() already done by caller. */
3609 + err = hidden_dentry->d_inode->i_op->listxattr(hidden_dentry, encoded_list, size);
3610 + /* unlock_kernel() will be done by caller. */
3611 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
3612 + mutex_unlock(&hidden_dentry->d_inode->i_mutex);
3614 + up(&hidden_dentry->d_inode->i_sem);
3619 +# endif /* defined(XATTR) && (LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,20)) */
3621 +struct inode_operations mini_fo_symlink_iops =
3623 + readlink: mini_fo_readlink,
3624 + follow_link: mini_fo_follow_link,
3625 + /* mk: permission: mini_fo_permission, */
3626 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
3627 + revalidate: mini_fo_inode_revalidate,
3629 + setattr: mini_fo_setattr,
3630 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
3631 + getattr: mini_fo_getattr,
3632 + put_link: mini_fo_put_link,
3635 +#if defined(XATTR) && (LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,20))
3636 + setxattr: mini_fo_setxattr,
3637 + getxattr: mini_fo_getxattr,
3638 + listxattr: mini_fo_listxattr,
3639 + removexattr: mini_fo_removexattr
3640 +# endif /* defined(XATTR) && (LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,20)) */
3643 +struct inode_operations mini_fo_dir_iops =
3645 + create: mini_fo_create,
3646 + lookup: mini_fo_lookup,
3647 + link: mini_fo_link,
3648 + unlink: mini_fo_unlink,
3649 + symlink: mini_fo_symlink,
3650 + mkdir: mini_fo_mkdir,
3651 + rmdir: mini_fo_rmdir,
3652 + mknod: mini_fo_mknod,
3653 + rename: mini_fo_rename,
3654 + /* no readlink/follow_link for non-symlinks */
3655 + // off because we have setattr
3656 + // truncate: mini_fo_truncate,
3657 + /* mk:permission: mini_fo_permission, */
3658 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
3659 + revalidate: mini_fo_inode_revalidate,
3661 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
3662 + getattr: mini_fo_getattr,
3664 + setattr: mini_fo_setattr,
3665 +#if defined(XATTR) && (LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,20))
3666 + setxattr: mini_fo_setxattr,
3667 + getxattr: mini_fo_getxattr,
3668 + listxattr: mini_fo_listxattr,
3669 + removexattr: mini_fo_removexattr
3670 +# endif /* XATTR && LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,20) */
3673 +struct inode_operations mini_fo_main_iops =
3675 + /* permission: mini_fo_permission, */
3676 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
3677 + revalidate: mini_fo_inode_revalidate,
3679 + setattr: mini_fo_setattr,
3681 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
3682 + getattr: mini_fo_getattr,
3684 +#if defined(XATTR) && (LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,20))
3685 + setxattr: mini_fo_setxattr,
3686 + getxattr: mini_fo_getxattr,
3687 + listxattr: mini_fo_listxattr,
3688 + removexattr: mini_fo_removexattr
3689 +# endif /* XATTR && LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,20) */
3691 diff -urN linux.old/fs/mini_fo/main.c linux.dev/fs/mini_fo/main.c
3692 --- linux.old/fs/mini_fo/main.c 1970-01-01 01:00:00.000000000 +0100
3693 +++ linux.dev/fs/mini_fo/main.c 2006-10-29 04:32:06.000000000 +0100
3696 + * Copyright (c) 1997-2003 Erez Zadok
3697 + * Copyright (c) 2001-2003 Stony Brook University
3699 + * For specific licensing information, see the COPYING file distributed with
3700 + * this package, or get one from ftp://ftp.filesystems.org/pub/fist/COPYING.
3702 + * This Copyright notice must be kept intact and distributed with all
3703 + * fistgen sources INCLUDING sources generated by fistgen.
3706 + * Copyright (C) 2004, 2005 Markus Klotzbuecher <mk@creamnet.de>
3708 + * This program is free software; you can redistribute it and/or
3709 + * modify it under the terms of the GNU General Public License
3710 + * as published by the Free Software Foundation; either version
3711 + * 2 of the License, or (at your option) any later version.
3718 +#ifdef HAVE_CONFIG_H
3719 +# include <config.h>
3723 +#include "mini_fo.h"
3724 +#include <linux/module.h>
3726 +/* This definition must only appear after we include <linux/module.h> */
3727 +#ifndef MODULE_LICENSE
3728 +# define MODULE_LICENSE(bison)
3729 +#endif /* not MODULE_LICENSE */
3732 + * This is the mini_fo tri interpose function, which extends the
3733 + * functionality of the regular interpose by interposing a higher
3734 + * level inode on top of two lower level ones: the base filesystem
3735 + * inode and the storage filesystem inode.
3737 + * sb we pass is mini_fo's super_block
3740 +mini_fo_tri_interpose(dentry_t *hidden_dentry,
3741 + dentry_t *hidden_sto_dentry,
3742 + dentry_t *dentry, super_block_t *sb, int flag)
3744 + inode_t *hidden_inode = NULL;
3745 + inode_t *hidden_sto_inode = NULL; /* store corresponding storage inode */
3749 + /* Pointer to hidden_sto_inode if exists, else to hidden_inode.
3750 + * This is used to copy the attributes of the correct inode. */
3751 + inode_t *master_inode;
3754 + hidden_inode = hidden_dentry->d_inode;
3755 + if(hidden_sto_dentry)
3756 + hidden_sto_inode = hidden_sto_dentry->d_inode;
3758 + ASSERT(dentry->d_inode == NULL);
3760 + /* mk: One of the inodes associated with the dentrys is likely to
3761 + * be NULL, so carefull:
3763 + ASSERT((hidden_inode != NULL) || (hidden_sto_inode != NULL));
3765 + if(hidden_sto_inode)
3766 + master_inode = hidden_sto_inode;
3768 + master_inode = hidden_inode;
3771 + * We allocate our new inode below, by calling iget.
3772 + * iget will call our read_inode which will initialize some
3773 + * of the new inode's fields
3777 + * original: inode = iget(sb, hidden_inode->i_ino);
3779 + inode = iget(sb, iunique(sb, 25));
3781 + err = -EACCES; /* should be impossible??? */
3786 + * interpose the inode if not already interposed
3787 + * this is possible if the inode is being reused
3788 + * XXX: what happens if we get_empty_inode() but there's another already?
3789 + * for now, ASSERT() that this can't happen; fix later.
3791 + if (itohi(inode) != NULL) {
3792 + printk(KERN_CRIT "mini_fo_tri_interpose: itohi(inode) != NULL.\n");
3794 + if (itohi2(inode) != NULL) {
3795 + printk(KERN_CRIT "mini_fo_tri_interpose: itohi2(inode) != NULL.\n");
3798 + /* mk: Carefull, igrab can't handle NULL inodes (ok, why should it?), so
3799 + * we need to check here:
3802 + itohi(inode) = igrab(hidden_inode);
3804 + itohi(inode) = NULL;
3806 + if(hidden_sto_inode)
3807 + itohi2(inode) = igrab(hidden_sto_inode);
3809 + itohi2(inode) = NULL;
3812 + /* Use different set of inode ops for symlinks & directories*/
3813 + if (S_ISLNK(master_inode->i_mode))
3814 + inode->i_op = &mini_fo_symlink_iops;
3815 + else if (S_ISDIR(master_inode->i_mode))
3816 + inode->i_op = &mini_fo_dir_iops;
3818 + /* Use different set of file ops for directories */
3819 + if (S_ISDIR(master_inode->i_mode))
3820 + inode->i_fop = &mini_fo_dir_fops;
3822 + /* properly initialize special inodes */
3823 + if (S_ISBLK(master_inode->i_mode) || S_ISCHR(master_inode->i_mode) ||
3824 + S_ISFIFO(master_inode->i_mode) || S_ISSOCK(master_inode->i_mode)) {
3825 + init_special_inode(inode, master_inode->i_mode, master_inode->i_rdev);
3828 + /* Fix our inode's address operations to that of the lower inode */
3829 + if (inode->i_mapping->a_ops != master_inode->i_mapping->a_ops) {
3830 + inode->i_mapping->a_ops = master_inode->i_mapping->a_ops;
3833 + /* only (our) lookup wants to do a d_add */
3835 + d_add(dentry, inode);
3837 + d_instantiate(dentry, inode);
3839 + ASSERT(dtopd(dentry) != NULL);
3841 + /* all well, copy inode attributes */
3842 + fist_copy_attr_all(inode, master_inode);
3848 +/* parse mount options "base=" and "sto=" */
3850 +mini_fo_parse_options(super_block_t *sb, char *options)
3852 + dentry_t *hidden_root = ERR_PTR(-EINVAL);
3853 + dentry_t *hidden_root2 = ERR_PTR(-EINVAL);
3854 + struct nameidata nd, nd2;
3855 + char *name, *tmp, *end;
3858 + /* We don't want to go off the end of our arguments later on. */
3859 + for (end = options; *end; end++);
3861 + while (options < end) {
3863 + while (*tmp && *tmp != ',')
3866 + if (!strncmp("base=", options, 5)) {
3867 + name = options + 5;
3868 + printk(KERN_INFO "mini_fo: using base directory: %s\n", name);
3870 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
3871 + if (path_init(name, LOOKUP_FOLLOW, &nd))
3872 + err = path_walk(name, &nd);
3874 + err = path_lookup(name, LOOKUP_FOLLOW, &nd);
3877 + printk(KERN_CRIT "mini_fo: error accessing hidden directory '%s'\n", name);
3878 + hidden_root = ERR_PTR(err);
3881 + hidden_root = nd.dentry;
3882 + stopd(sb)->base_dir_dentry = nd.dentry;
3883 + stopd(sb)->hidden_mnt = nd.mnt;
3885 + } else if(!strncmp("sto=", options, 4)) {
3886 + /* parse the storage dir */
3887 + name = options + 4;
3888 + printk(KERN_INFO "mini_fo: using storage directory: %s\n", name);
3889 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
3890 + if(path_init(name, LOOKUP_FOLLOW, &nd2))
3891 + err = path_walk(name, &nd2);
3893 + err = path_lookup(name, LOOKUP_FOLLOW, &nd2);
3896 + printk(KERN_CRIT "mini_fo: error accessing hidden storage directory '%s'\n", name);
3898 + hidden_root2 = ERR_PTR(err);
3901 + hidden_root2 = nd2.dentry;
3902 + stopd(sb)->storage_dir_dentry = nd2.dentry;
3903 + stopd(sb)->hidden_mnt2 = nd2.mnt;
3904 + stohs2(sb) = hidden_root2->d_sb;
3906 + /* validate storage dir, this is done in
3907 + * mini_fo_read_super for the base directory.
3909 + if (IS_ERR(hidden_root2)) {
3910 + printk(KERN_WARNING "mini_fo_parse_options: storage dentry lookup failed (err = %ld)\n", PTR_ERR(hidden_root2));
3913 + if (!hidden_root2->d_inode) {
3914 + printk(KERN_WARNING "mini_fo_parse_options: no storage dir to interpose on.\n");
3917 + stohs2(sb) = hidden_root2->d_sb;
3919 + printk(KERN_WARNING "mini_fo: unrecognized option '%s'\n", options);
3920 + hidden_root = ERR_PTR(-EINVAL);
3923 + options = tmp + 1;
3927 + if(IS_ERR(hidden_root2))
3928 + return hidden_root2;
3929 + return hidden_root;
3933 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
3938 +mini_fo_read_super(super_block_t *sb, void *raw_data, int silent)
3940 + dentry_t *hidden_root;
3944 + printk(KERN_WARNING "mini_fo_read_super: missing argument\n");
3949 + * Allocate superblock private data
3951 + __stopd(sb) = kmalloc(sizeof(struct mini_fo_sb_info), GFP_KERNEL);
3953 + printk(KERN_WARNING "%s: out of memory\n", __FUNCTION__);
3959 + hidden_root = mini_fo_parse_options(sb, raw_data);
3960 + if (IS_ERR(hidden_root)) {
3961 + printk(KERN_WARNING "mini_fo_read_super: lookup_dentry failed (err = %ld)\n", PTR_ERR(hidden_root));
3962 + err = PTR_ERR(hidden_root);
3965 + if (!hidden_root->d_inode) {
3966 + printk(KERN_WARNING "mini_fo_read_super: no directory to interpose on\n");
3969 + stohs(sb) = hidden_root->d_sb;
3972 + * Linux 2.4.2-ac3 and beyond has code in
3973 + * mm/filemap.c:generic_file_write() that requires sb->s_maxbytes
3974 + * to be populated. If not set, all write()s under that sb will
3977 + * Linux 2.4.4+ automatically sets s_maxbytes to MAX_NON_LFS;
3978 + * the filesystem should override it only if it supports LFS.
3980 + /* non-SCA code is good to go with LFS */
3981 + sb->s_maxbytes = hidden_root->d_sb->s_maxbytes;
3983 + sb->s_op = &mini_fo_sops;
3985 + * we can't use d_alloc_root if we want to use
3986 + * our own interpose function unchanged,
3987 + * so we simply replicate *most* of the code in d_alloc_root here
3989 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
3990 + sb->s_root = d_alloc(NULL, &(const struct qstr) { "/", 1, 0 });
3992 + sb->s_root = d_alloc(NULL, &(const struct qstr){hash: 0, name: "/", len : 1});
3994 + if (IS_ERR(sb->s_root)) {
3995 + printk(KERN_WARNING "mini_fo_read_super: d_alloc failed\n");
4000 + sb->s_root->d_op = &mini_fo_dops;
4001 + sb->s_root->d_sb = sb;
4002 + sb->s_root->d_parent = sb->s_root;
4004 + /* link the upper and lower dentries */
4005 + __dtopd(sb->s_root) = (struct mini_fo_dentry_info *)
4006 + kmalloc(sizeof(struct mini_fo_dentry_info), GFP_KERNEL);
4007 + if (!dtopd(sb->s_root)) {
4011 + dtopd(sb->s_root)->state = MODIFIED;
4012 + dtohd(sb->s_root) = hidden_root;
4014 + /* fanout relevant, interpose on storage root dentry too */
4015 + dtohd2(sb->s_root) = stopd(sb)->storage_dir_dentry;
4017 + /* ...and call tri-interpose to interpose root dir inodes
4018 + * if (mini_fo_interpose(hidden_root, sb->s_root, sb, 0))
4020 + if(mini_fo_tri_interpose(hidden_root, dtohd2(sb->s_root), sb->s_root, sb, 0))
4023 + /* initalize the wol list */
4024 + itopd(sb->s_root->d_inode)->deleted_list_size = -1;
4025 + itopd(sb->s_root->d_inode)->renamed_list_size = -1;
4026 + meta_build_lists(sb->s_root);
4033 + dput(hidden_root);
4034 + dput(dtohd2(sb->s_root)); /* release the hidden_sto_dentry too */
4037 + __stopd(sb) = NULL;
4040 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
4044 + return ERR_PTR(err);
4051 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
4052 +static struct super_block *mini_fo_get_sb(struct file_system_type *fs_type,
4053 + int flags, const char *dev_name,
4056 + return get_sb_nodev(fs_type, flags, raw_data, mini_fo_read_super);
4059 +void mini_fo_kill_block_super(struct super_block *sb)
4061 + generic_shutdown_super(sb);
4063 + * XXX: BUG: Halcrow: Things get unstable sometime after this point:
4064 + * lib/rwsem-spinlock.c:127: spin_is_locked on uninitialized
4065 + * fs/fs-writeback.c:402: spin_lock(fs/super.c:a0381828) already
4066 + * locked by fs/fs-writeback.c/402
4068 + * Apparently, someone's not releasing a lock on sb_lock...
4072 +static struct file_system_type mini_fo_fs_type = {
4073 + .owner = THIS_MODULE,
4074 + .name = "mini_fo",
4075 + .get_sb = mini_fo_get_sb,
4076 + .kill_sb = mini_fo_kill_block_super,
4082 +static DECLARE_FSTYPE(mini_fo_fs_type, "mini_fo", mini_fo_read_super, 0);
4085 +static int __init init_mini_fo_fs(void)
4087 + printk("Registering mini_fo version $Id$\n");
4088 + return register_filesystem(&mini_fo_fs_type);
4090 +static void __exit exit_mini_fo_fs(void)
4092 + printk("Unregistering mini_fo version $Id$\n");
4093 + unregister_filesystem(&mini_fo_fs_type);
4096 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
4100 +MODULE_AUTHOR("Erez Zadok <ezk@cs.sunysb.edu>");
4101 +MODULE_DESCRIPTION("FiST-generated mini_fo filesystem");
4102 +MODULE_LICENSE("GPL");
4104 +/* MODULE_PARM(fist_debug_var, "i"); */
4105 +/* MODULE_PARM_DESC(fist_debug_var, "Debug level"); */
4107 +module_init(init_mini_fo_fs)
4108 +module_exit(exit_mini_fo_fs)
4109 diff -urN linux.old/fs/mini_fo/Makefile linux.dev/fs/mini_fo/Makefile
4110 --- linux.old/fs/mini_fo/Makefile 1970-01-01 01:00:00.000000000 +0100
4111 +++ linux.dev/fs/mini_fo/Makefile 2006-10-29 03:08:04.000000000 +0100
4114 +# Makefile for mini_fo 2.4 and 2.6 Linux kernels
4116 +# Copyright (C) 2004, 2005 Markus Klotzbuecher <mk@creamnet.de>
4118 +# This program is free software; you can redistribute it and/or
4119 +# modify it under the terms of the GNU General Public License
4120 +# as published by the Free Software Foundation; either version
4121 +# 2 of the License, or (at your option) any later version.
4124 +obj-$(CONFIG_MINI_FO) := mini_fo.o
4125 +mini_fo-objs := meta.o dentry.o file.o inode.o main.o super.o state.o aux.o
4127 +O_TARGET := $(obj-$(CONFIG_MINI_FO))
4128 +obj-y := $(mini_fo-objs)
4130 +-include $(TOPDIR)/Rules.make
4133 +${mini_fo-objs}: mini_fo.h fist.h
4135 diff -urN linux.old/fs/mini_fo/meta.c linux.dev/fs/mini_fo/meta.c
4136 --- linux.old/fs/mini_fo/meta.c 1970-01-01 01:00:00.000000000 +0100
4137 +++ linux.dev/fs/mini_fo/meta.c 2006-10-29 04:32:06.000000000 +0100
4140 + * Copyright (C) 2004, 2005 Markus Klotzbuecher <mk@creamnet.de>
4142 + * This program is free software; you can redistribute it and/or
4143 + * modify it under the terms of the GNU General Public License
4144 + * as published by the Free Software Foundation; either version
4145 + * 2 of the License, or (at your option) any later version.
4148 +#ifdef HAVE_CONFIG_H
4149 +# include <config.h>
4150 +#endif /* HAVE_CONFIG_H */
4152 +#include "mini_fo.h"
4154 +int meta_build_lists(dentry_t *dentry)
4156 + struct mini_fo_inode_info *inode_info;
4158 + dentry_t *meta_dentry = 0;
4159 + file_t *meta_file = 0;
4160 + mm_segment_t old_fs;
4164 + struct vfsmount *meta_mnt;
4167 + inode_info = itopd(dentry->d_inode);
4168 + if(!(inode_info->deleted_list_size == -1 &&
4169 + inode_info->renamed_list_size == -1)) {
4170 + printk(KERN_CRIT "mini_fo: meta_build_lists: \
4171 + Error, list(s) not virgin.\n");
4175 + /* init our meta lists */
4176 + INIT_LIST_HEAD(&inode_info->deleted_list);
4177 + inode_info->deleted_list_size = 0;
4179 + INIT_LIST_HEAD(&inode_info->renamed_list);
4180 + inode_info->renamed_list_size = 0;
4182 + /* might there be a META-file? */
4183 + if(dtohd2(dentry) && dtohd2(dentry)->d_inode) {
4184 + meta_dentry = lookup_one_len(META_FILENAME,
4186 + strlen(META_FILENAME));
4187 + if(!meta_dentry->d_inode) {
4188 + dput(meta_dentry);
4191 + /* $%& err, is this correct? */
4192 + meta_mnt = stopd(dentry->d_inode->i_sb)->hidden_mnt2;
4196 + /* open META-file for reading */
4197 + meta_file = dentry_open(meta_dentry, meta_mnt, 0x0);
4198 + if(!meta_file || IS_ERR(meta_file)) {
4199 + printk(KERN_CRIT "mini_fo: meta_build_lists: \
4200 + ERROR opening META file.\n");
4204 + /* check if fs supports reading */
4205 + if(!meta_file->f_op->read) {
4206 + printk(KERN_CRIT "mini_fo: meta_build_lists: \
4207 + ERROR, fs does not support reading.\n");
4208 + goto out_err_close;
4211 + /* allocate a page for transfering the data */
4212 + buf = (void *) __get_free_page(GFP_KERNEL);
4214 + printk(KERN_CRIT "mini_fo: meta_build_lists: \
4215 + ERROR, out of mem.\n");
4216 + goto out_err_close;
4218 + meta_file->f_pos = 0;
4219 + old_fs = get_fs();
4220 + set_fs(KERNEL_DS);
4223 + bytes = meta_file->f_op->read(meta_file, buf, PAGE_SIZE, &meta_file->f_pos);
4224 + if(bytes == PAGE_SIZE) {
4225 + /* trim a cut off filename and adjust f_pos to get it next time */
4226 + for(c = (char*) buf+PAGE_SIZE;
4228 + c--, bytes--, meta_file->f_pos--);
4230 + entry = (char *) buf;
4231 + while(entry < (char *) buf+bytes) {
4235 + int old_len, new_len;
4237 + /* len without '\n'*/
4238 + len = (int) (strchr(entry, '\n') - entry);
4241 + /* format: "D filename" */
4242 + meta_list_add_d_entry(dentry,
4247 + /* format: "R path/xy/dir newDir" */
4248 + old_path = entry+2;
4249 + dir_name = strchr(old_path, ' ') + 1;
4250 + old_len = dir_name - old_path - 1;
4251 + new_len = ((int) entry) + len - ((int ) dir_name);
4252 + meta_list_add_r_entry(dentry,
4259 + /* unknown entry type detected */
4265 + } while(meta_file->f_pos < meta_dentry->d_inode->i_size);
4267 + free_page((unsigned long) buf);
4277 + dput(meta_dentry);
4280 + return 1; /* check this!!! inode_info->wol_size; */
4283 +/* cleanups up all lists and free's the mem by dentry */
4284 +int meta_put_lists(dentry_t *dentry)
4286 + if(!dentry || !dentry->d_inode) {
4287 + printk("mini_fo: meta_put_lists: invalid dentry passed.\n");
4290 + return __meta_put_lists(dentry->d_inode);
4293 +/* cleanups up all lists and free's the mem by inode */
4294 +int __meta_put_lists(inode_t *inode)
4297 + if(!inode || !itopd(inode)) {
4298 + printk("mini_fo: __meta_put_lists: invalid inode passed.\n");
4301 + err = __meta_put_d_list(inode);
4302 + err |= __meta_put_r_list(inode);
4306 +int meta_sync_lists(dentry_t *dentry)
4309 + if(!dentry || !dentry->d_inode) {
4310 + printk("mini_fo: meta_sync_lists: \
4311 + invalid dentry passed.\n");
4314 + err = meta_sync_d_list(dentry, 0);
4315 + err |= meta_sync_r_list(dentry, 1);
4320 +/* remove all D entries from the renamed list and free the mem */
4321 +int __meta_put_d_list(inode_t *inode)
4323 + struct list_head *tmp;
4324 + struct deleted_entry *del_entry;
4325 + struct mini_fo_inode_info *inode_info;
4327 + if(!inode || !itopd(inode)) {
4328 + printk(KERN_CRIT "mini_fo: __meta_put_d_list: \
4329 + invalid inode passed.\n");
4332 + inode_info = itopd(inode);
4334 + /* nuke the DELETED-list */
4335 + if(inode_info->deleted_list_size <= 0)
4338 + while(!list_empty(&inode_info->deleted_list)) {
4339 + tmp = inode_info->deleted_list.next;
4341 + del_entry = list_entry(tmp, struct deleted_entry, list);
4342 + kfree(del_entry->name);
4345 + inode_info->deleted_list_size = 0;
4350 +/* remove all R entries from the renamed list and free the mem */
4351 +int __meta_put_r_list(inode_t *inode)
4353 + struct list_head *tmp;
4354 + struct renamed_entry *ren_entry;
4355 + struct mini_fo_inode_info *inode_info;
4357 + if(!inode || !itopd(inode)) {
4358 + printk(KERN_CRIT "mini_fo: meta_put_r_list: invalid inode.\n");
4361 + inode_info = itopd(inode);
4363 + /* nuke the RENAMED-list */
4364 + if(inode_info->renamed_list_size <= 0)
4367 + while(!list_empty(&inode_info->renamed_list)) {
4368 + tmp = inode_info->renamed_list.next;
4370 + ren_entry = list_entry(tmp, struct renamed_entry, list);
4371 + kfree(ren_entry->new_name);
4372 + kfree(ren_entry->old_name);
4375 + inode_info->renamed_list_size = 0;
4380 +int meta_add_d_entry(dentry_t *dentry, const char *name, int len)
4383 + err = meta_list_add_d_entry(dentry, name, len);
4384 + err |= meta_write_d_entry(dentry,name,len);
4388 +/* add a D entry to the deleted list */
4389 +int meta_list_add_d_entry(dentry_t *dentry, const char *name, int len)
4391 + struct deleted_entry *del_entry;
4392 + struct mini_fo_inode_info *inode_info;
4394 + if(!dentry || !dentry->d_inode) {
4395 + printk(KERN_CRIT "mini_fo: meta_list_add_d_entry: \
4396 + invalid dentry passed.\n");
4399 + inode_info = itopd(dentry->d_inode);
4401 + if(inode_info->deleted_list_size < 0)
4404 + del_entry = (struct deleted_entry *)
4405 + kmalloc(sizeof(struct deleted_entry), GFP_KERNEL);
4406 + del_entry->name = (char*) kmalloc(len, GFP_KERNEL);
4407 + if(!del_entry || !del_entry->name) {
4408 + printk(KERN_CRIT "mini_fo: meta_list_add_d_entry: \
4410 + kfree(del_entry->name);
4415 + strncpy(del_entry->name, name, len);
4416 + del_entry->len = len;
4418 + list_add(&del_entry->list, &inode_info->deleted_list);
4419 + inode_info->deleted_list_size++;
4423 +int meta_add_r_entry(dentry_t *dentry,
4424 + const char *old_name, int old_len,
4425 + const char *new_name, int new_len)
4428 + err = meta_list_add_r_entry(dentry,
4429 + old_name, old_len,
4430 + new_name, new_len);
4431 + err |= meta_write_r_entry(dentry,
4432 + old_name, old_len,
4433 + new_name, new_len);
4437 +/* add a R entry to the renamed list */
4438 +int meta_list_add_r_entry(dentry_t *dentry,
4439 + const char *old_name, int old_len,
4440 + const char *new_name, int new_len)
4442 + struct renamed_entry *ren_entry;
4443 + struct mini_fo_inode_info *inode_info;
4445 + if(!dentry || !dentry->d_inode) {
4446 + printk(KERN_CRIT "mini_fo: meta_list_add_r_entry: \
4447 + invalid dentry passed.\n");
4450 + inode_info = itopd(dentry->d_inode);
4452 + if(inode_info->renamed_list_size < 0)
4455 + ren_entry = (struct renamed_entry *)
4456 + kmalloc(sizeof(struct renamed_entry), GFP_KERNEL);
4457 + ren_entry->old_name = (char*) kmalloc(old_len, GFP_KERNEL);
4458 + ren_entry->new_name = (char*) kmalloc(new_len, GFP_KERNEL);
4460 + if(!ren_entry || !ren_entry->old_name || !ren_entry->new_name) {
4461 + printk(KERN_CRIT "mini_fo: meta_list_add_r_entry: \
4463 + kfree(ren_entry->new_name);
4464 + kfree(ren_entry->old_name);
4469 + strncpy(ren_entry->old_name, old_name, old_len);
4470 + ren_entry->old_len = old_len;
4471 + strncpy(ren_entry->new_name, new_name, new_len);
4472 + ren_entry->new_len = new_len;
4474 + list_add(&ren_entry->list, &inode_info->renamed_list);
4475 + inode_info->renamed_list_size++;
4480 +int meta_remove_r_entry(dentry_t *dentry, const char *name, int len)
4483 + if(!dentry || !dentry->d_inode) {
4485 + "mini_fo: meta_remove_r_entry: \
4486 + invalid dentry passed.\n");
4490 + err = meta_list_remove_r_entry(dentry, name, len);
4491 + err |= meta_sync_lists(dentry);
4495 +int meta_list_remove_r_entry(dentry_t *dentry, const char *name, int len)
4497 + if(!dentry || !dentry->d_inode) {
4499 + "mini_fo: meta_list_remove_r_entry: \
4500 + invalid dentry passed.\n");
4503 + return __meta_list_remove_r_entry(dentry->d_inode, name, len);
4506 +int __meta_list_remove_r_entry(inode_t *inode, const char *name, int len)
4508 + struct list_head *tmp;
4509 + struct renamed_entry *ren_entry;
4510 + struct mini_fo_inode_info *inode_info;
4512 + if(!inode || !itopd(inode))
4514 + "mini_fo: __meta_list_remove_r_entry: \
4515 + invalid inode passed.\n");
4516 + inode_info = itopd(inode);
4518 + if(inode_info->renamed_list_size < 0)
4520 + if(inode_info->renamed_list_size == 0)
4523 + list_for_each(tmp, &inode_info->renamed_list) {
4524 + ren_entry = list_entry(tmp, struct renamed_entry, list);
4525 + if(ren_entry->new_len != len)
4528 + if(!strncmp(ren_entry->new_name, name, len)) {
4530 + kfree(ren_entry->new_name);
4531 + kfree(ren_entry->old_name);
4533 + inode_info->renamed_list_size--;
4541 +/* append a single D entry to the meta file */
4542 +int meta_write_d_entry(dentry_t *dentry, const char *name, int len)
4544 + dentry_t *meta_dentry = 0;
4545 + file_t *meta_file = 0;
4546 + mm_segment_t old_fs;
4549 + struct vfsmount *meta_mnt = 0;
4554 + if(itopd(dentry->d_inode)->deleted_list_size < 0) {
4559 + if(dtopd(dentry)->state == UNMODIFIED) {
4560 + err = build_sto_structure(dentry->d_parent, dentry);
4562 + printk(KERN_CRIT "mini_fo: meta_write_d_entry: \
4563 + build_sto_structure failed.\n");
4567 + meta_dentry = lookup_one_len(META_FILENAME,
4568 + dtohd2(dentry), strlen (META_FILENAME));
4570 + /* We need to create a META-file */
4571 + if(!meta_dentry->d_inode) {
4572 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
4573 + vfs_create(dtohd2(dentry)->d_inode,
4575 + S_IRUSR | S_IWUSR,
4578 + vfs_create(dtohd2(dentry)->d_inode,
4580 + S_IRUSR | S_IWUSR);
4583 + /* open META-file for writing */
4584 + meta_file = dentry_open(meta_dentry, meta_mnt, 0x1);
4585 + if(!meta_file || IS_ERR(meta_file)) {
4586 + printk(KERN_CRIT "mini_fo: meta_write_d_entry: \
4587 + ERROR opening meta file.\n");
4588 + mntput(meta_mnt); /* $%& is this necessary? */
4589 + dput(meta_dentry);
4594 + /* check if fs supports writing */
4595 + if(!meta_file->f_op->write) {
4596 + printk(KERN_CRIT "mini_fo: meta_write_d_entry: \
4597 + ERROR, fs does not support writing.\n");
4598 + goto out_err_close;
4601 + meta_file->f_pos = meta_dentry->d_inode->i_size; /* append */
4602 + old_fs = get_fs();
4603 + set_fs(KERNEL_DS);
4605 + /* size: len for name, 1 for \n and 2 for "D " */
4606 + buf = (char *) kmalloc(len+3, GFP_KERNEL);
4608 + printk(KERN_CRIT "mini_fo: meta_write_d_entry: \
4615 + strncpy(buf+2, name, len);
4616 + buf[len+2] = '\n';
4617 + bytes = meta_file->f_op->write(meta_file, buf, len+3,
4618 + &meta_file->f_pos);
4619 + if(bytes != len+3) {
4620 + printk(KERN_CRIT "mini_fo: meta_write_d_entry: \
4621 + ERROR writing.\n");
4633 +/* append a single R entry to the meta file */
4634 +int meta_write_r_entry(dentry_t *dentry,
4635 + const char *old_name, int old_len,
4636 + const char *new_name, int new_len)
4638 + dentry_t *meta_dentry = 0;
4639 + file_t *meta_file = 0;
4640 + mm_segment_t old_fs;
4642 + int bytes, err, buf_len;
4643 + struct vfsmount *meta_mnt = 0;
4649 + if(itopd(dentry->d_inode)->renamed_list_size < 0) {
4654 + /* build the storage structure? */
4655 + if(dtopd(dentry)->state == UNMODIFIED) {
4656 + err = build_sto_structure(dentry->d_parent, dentry);
4658 + printk(KERN_CRIT "mini_fo: meta_write_r_entry: \
4659 + build_sto_structure failed.\n");
4663 + meta_dentry = lookup_one_len(META_FILENAME,
4665 + strlen (META_FILENAME));
4666 + if(!meta_dentry->d_inode) {
4667 + /* We need to create a META-file */
4668 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
4669 + vfs_create(dtohd2(dentry)->d_inode,
4670 + meta_dentry, S_IRUSR | S_IWUSR, NULL);
4672 + vfs_create(dtohd2(dentry)->d_inode,
4673 + meta_dentry, S_IRUSR | S_IWUSR);
4676 + /* open META-file for writing */
4677 + meta_file = dentry_open(meta_dentry, meta_mnt, 0x1);
4678 + if(!meta_file || IS_ERR(meta_file)) {
4679 + printk(KERN_CRIT "mini_fo: meta_write_r_entry: \
4680 + ERROR opening meta file.\n");
4682 + dput(meta_dentry);
4687 + /* check if fs supports writing */
4688 + if(!meta_file->f_op->write) {
4689 + printk(KERN_CRIT "mini_fo: meta_write_r_entry: \
4690 + ERROR, fs does not support writing.\n");
4691 + goto out_err_close;
4694 + meta_file->f_pos = meta_dentry->d_inode->i_size; /* append */
4695 + old_fs = get_fs();
4696 + set_fs(KERNEL_DS);
4698 + /* size: 2 for "R ", old_len+new_len for names, 1 blank+1 \n */
4699 + buf_len = old_len + new_len + 4;
4700 + buf = (char *) kmalloc(buf_len, GFP_KERNEL);
4702 + printk(KERN_CRIT "mini_fo: meta_write_r_entry: out of mem.\n");
4708 + strncpy(buf + 2, old_name, old_len);
4709 + buf[old_len + 2] = ' ';
4710 + strncpy(buf + old_len + 3, new_name, new_len);
4711 + buf[buf_len -1] = '\n';
4712 + bytes = meta_file->f_op->write(meta_file, buf, buf_len, &meta_file->f_pos);
4713 + if(bytes != buf_len) {
4714 + printk(KERN_CRIT "mini_fo: meta_write_r_entry: ERROR writing.\n");
4727 +/* sync D list to disk, append data if app_flag is 1 */
4728 +/* check the meta_mnt, which seems not to be used (properly) */
4730 +int meta_sync_d_list(dentry_t *dentry, int app_flag)
4732 + dentry_t *meta_dentry;
4733 + file_t *meta_file;
4734 + mm_segment_t old_fs;
4737 + struct vfsmount *meta_mnt;
4740 + struct list_head *tmp;
4741 + struct deleted_entry *del_entry;
4742 + struct mini_fo_inode_info *inode_info;
4748 + if(!dentry || !dentry->d_inode) {
4749 + printk(KERN_CRIT "mini_fo: meta_sync_d_list: \
4750 + invalid inode passed.\n");
4754 + inode_info = itopd(dentry->d_inode);
4756 + if(inode_info->deleted_list_size < 0) {
4761 + /* ok, there is something to sync */
4763 + /* build the storage structure? */
4764 + if(!dtohd2(dentry) && !itohi2(dentry->d_inode)) {
4765 + err = build_sto_structure(dentry->d_parent, dentry);
4767 + printk(KERN_CRIT "mini_fo: meta_sync_d_list: \
4768 + build_sto_structure failed.\n");
4772 + meta_dentry = lookup_one_len(META_FILENAME,
4774 + strlen(META_FILENAME));
4775 + if(!meta_dentry->d_inode) {
4776 + /* We need to create a META-file */
4777 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
4778 + vfs_create(dtohd2(dentry)->d_inode,
4779 + meta_dentry, S_IRUSR | S_IWUSR, NULL);
4781 + vfs_create(dtohd2(dentry)->d_inode,
4782 + meta_dentry, S_IRUSR | S_IWUSR);
4786 + /* need we truncate the meta file? */
4788 + struct iattr newattrs;
4789 + newattrs.ia_size = 0;
4790 + newattrs.ia_valid = ATTR_SIZE | ATTR_CTIME;
4792 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
4793 + mutex_lock(&meta_dentry->d_inode->i_mutex);
4795 + down(&meta_dentry->d_inode->i_sem);
4797 + err = notify_change(meta_dentry, &newattrs);
4799 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
4800 + mutex_unlock(&meta_dentry->d_inode->i_mutex);
4802 + up(&meta_dentry->d_inode->i_sem);
4805 + if(err || meta_dentry->d_inode->i_size != 0) {
4806 + printk(KERN_CRIT "mini_fo: meta_sync_d_list: \
4807 + ERROR truncating meta file.\n");
4808 + goto out_err_close;
4812 + /* open META-file for writing */
4813 + meta_file = dentry_open(meta_dentry, meta_mnt, 0x1);
4814 + if(!meta_file || IS_ERR(meta_file)) {
4815 + printk(KERN_CRIT "mini_fo: meta_sync_d_list: \
4816 + ERROR opening meta file.\n");
4817 + /* we don't mntget so we dont't mntput (for now)
4818 + * mntput(meta_mnt);
4820 + dput(meta_dentry);
4825 + /* check if fs supports writing */
4826 + if(!meta_file->f_op->write) {
4827 + printk(KERN_CRIT "mini_fo: meta_sync_d_list: \
4828 + ERROR, fs does not support writing.\n");
4829 + goto out_err_close;
4832 + meta_file->f_pos = meta_dentry->d_inode->i_size; /* append */
4833 + old_fs = get_fs();
4834 + set_fs(KERNEL_DS);
4836 + /* here we go... */
4837 + list_for_each(tmp, &inode_info->deleted_list) {
4838 + del_entry = list_entry(tmp, struct deleted_entry, list);
4840 + /* size: len for name, 1 for \n and 2 for "D " */
4841 + buf = (char *) kmalloc(del_entry->len+3, GFP_KERNEL);
4843 + printk(KERN_CRIT "mini_fo: meta_sync_d_list: \
4850 + strncpy(buf+2, del_entry->name, del_entry->len);
4851 + buf[del_entry->len+2] = '\n';
4852 + bytes = meta_file->f_op->write(meta_file, buf,
4854 + &meta_file->f_pos);
4855 + if(bytes != del_entry->len+3) {
4856 + printk(KERN_CRIT "mini_fo: meta_sync_d_list: \
4857 + ERROR writing.\n");
4871 +int meta_sync_r_list(dentry_t *dentry, int app_flag)
4873 + dentry_t *meta_dentry;
4874 + file_t *meta_file;
4875 + mm_segment_t old_fs;
4877 + int bytes, err, buf_len;
4878 + struct vfsmount *meta_mnt;
4881 + struct list_head *tmp;
4882 + struct renamed_entry *ren_entry;
4883 + struct mini_fo_inode_info *inode_info;
4889 + if(!dentry || !dentry->d_inode) {
4890 + printk(KERN_CRIT "mini_fo: meta_sync_r_list: \
4891 + invalid dentry passed.\n");
4895 + inode_info = itopd(dentry->d_inode);
4897 + if(inode_info->deleted_list_size < 0) {
4902 + /* ok, there is something to sync */
4904 + /* build the storage structure? */
4905 + if(!dtohd2(dentry) && !itohi2(dentry->d_inode)) {
4906 + err = build_sto_structure(dentry->d_parent, dentry);
4908 + printk(KERN_CRIT "mini_fo: meta_sync_r_list: \
4909 + build_sto_structure failed.\n");
4913 + meta_dentry = lookup_one_len(META_FILENAME,
4915 + strlen(META_FILENAME));
4916 + if(!meta_dentry->d_inode) {
4917 + /* We need to create a META-file */
4918 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
4919 + vfs_create(dtohd2(dentry)->d_inode,
4920 + meta_dentry, S_IRUSR | S_IWUSR, NULL);
4922 + vfs_create(dtohd2(dentry)->d_inode,
4923 + meta_dentry, S_IRUSR | S_IWUSR);
4927 + /* need we truncate the meta file? */
4929 + struct iattr newattrs;
4930 + newattrs.ia_size = 0;
4931 + newattrs.ia_valid = ATTR_SIZE | ATTR_CTIME;
4933 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
4934 + mutex_lock(&meta_dentry->d_inode->i_mutex);
4936 + down(&meta_dentry->d_inode->i_sem);
4938 + err = notify_change(meta_dentry, &newattrs);
4940 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
4941 + mutex_unlock(&meta_dentry->d_inode->i_mutex);
4943 + up(&meta_dentry->d_inode->i_sem);
4945 + if(err || meta_dentry->d_inode->i_size != 0) {
4946 + printk(KERN_CRIT "mini_fo: meta_sync_r_list: \
4947 + ERROR truncating meta file.\n");
4948 + goto out_err_close;
4952 + /* open META-file for writing */
4953 + meta_file = dentry_open(meta_dentry, meta_mnt, 0x1);
4954 + if(!meta_file || IS_ERR(meta_file)) {
4955 + printk(KERN_CRIT "mini_fo: meta_sync_r_list: \
4956 + ERROR opening meta file.\n");
4957 + /* we don't mntget so we dont't mntput (for now)
4958 + * mntput(meta_mnt);
4960 + dput(meta_dentry);
4965 + /* check if fs supports writing */
4966 + if(!meta_file->f_op->write) {
4967 + printk(KERN_CRIT "mini_fo: meta_sync_r_list: \
4968 + ERROR, fs does not support writing.\n");
4969 + goto out_err_close;
4972 + meta_file->f_pos = meta_dentry->d_inode->i_size; /* append */
4973 + old_fs = get_fs();
4974 + set_fs(KERNEL_DS);
4976 + /* here we go... */
4977 + list_for_each(tmp, &inode_info->renamed_list) {
4978 + ren_entry = list_entry(tmp, struct renamed_entry, list);
4980 + * 2 for "R ", old_len+new_len for names, 1 blank+1 \n */
4981 + buf_len = ren_entry->old_len + ren_entry->new_len + 4;
4982 + buf = (char *) kmalloc(buf_len, GFP_KERNEL);
4984 + printk(KERN_CRIT "mini_fo: meta_sync_r_list: \
4990 + strncpy(buf + 2, ren_entry->old_name, ren_entry->old_len);
4991 + buf[ren_entry->old_len + 2] = ' ';
4992 + strncpy(buf + ren_entry->old_len + 3,
4993 + ren_entry->new_name, ren_entry->new_len);
4994 + buf[buf_len - 1] = '\n';
4995 + bytes = meta_file->f_op->write(meta_file, buf,
4996 + buf_len, &meta_file->f_pos);
4997 + if(bytes != buf_len) {
4998 + printk(KERN_CRIT "mini_fo: meta_sync_r_list: \
4999 + ERROR writing.\n");
5012 +int meta_check_d_entry(dentry_t *dentry, const char *name, int len)
5014 + if(!dentry || !dentry->d_inode)
5015 + printk(KERN_CRIT "mini_fo: meta_check_d_dentry: \
5016 + invalid dentry passed.\n");
5017 + return __meta_check_d_entry(dentry->d_inode, name, len);
5020 +int __meta_check_d_entry(inode_t *inode, const char *name, int len)
5022 + struct list_head *tmp;
5023 + struct deleted_entry *del_entry;
5024 + struct mini_fo_inode_info *inode_info;
5026 + if(!inode || !itopd(inode))
5027 + printk(KERN_CRIT "mini_fo: __meta_check_d_dentry: \
5028 + invalid inode passed.\n");
5030 + inode_info = itopd(inode);
5032 + if(inode_info->deleted_list_size <= 0)
5035 + list_for_each(tmp, &inode_info->deleted_list) {
5036 + del_entry = list_entry(tmp, struct deleted_entry, list);
5037 + if(del_entry->len != len)
5040 + if(!strncmp(del_entry->name, name, len))
5047 + * check if file has been renamed and return path to orig. base dir.
5048 + * Implements no error return values so far, what of course sucks.
5049 + * String is null terminated.'
5051 +char* meta_check_r_entry(dentry_t *dentry, const char *name, int len)
5053 + if(!dentry || !dentry->d_inode) {
5054 + printk(KERN_CRIT "mini_fo: meta_check_r_dentry: \
5055 + invalid dentry passed.\n");
5058 + return __meta_check_r_entry(dentry->d_inode, name, len);
5061 +char* __meta_check_r_entry(inode_t *inode, const char *name, int len)
5063 + struct list_head *tmp;
5064 + struct renamed_entry *ren_entry;
5065 + struct mini_fo_inode_info *inode_info;
5068 + if(!inode || !itopd(inode)) {
5069 + printk(KERN_CRIT "mini_fo: meta_check_r_dentry: \
5070 + invalid inode passed.\n");
5073 + inode_info = itopd(inode);
5075 + if(inode_info->renamed_list_size <= 0)
5078 + list_for_each(tmp, &inode_info->renamed_list) {
5079 + ren_entry = list_entry(tmp, struct renamed_entry, list);
5080 + if(ren_entry->new_len != len)
5083 + if(!strncmp(ren_entry->new_name, name, len)) {
5084 + old_path = (char *)
5085 + kmalloc(ren_entry->old_len+1, GFP_KERNEL);
5087 + ren_entry->old_name,
5088 + ren_entry->old_len);
5089 + old_path[ren_entry->old_len]='\0';
5097 + * This version only checks if entry exists and return:
5102 +int meta_is_r_entry(dentry_t *dentry, const char *name, int len)
5104 + if(!dentry || !dentry->d_inode) {
5105 + printk(KERN_CRIT "mini_fo: meta_check_r_dentry [2]: \
5106 + invalid dentry passed.\n");
5109 + return __meta_is_r_entry(dentry->d_inode, name, len);
5112 +int __meta_is_r_entry(inode_t *inode, const char *name, int len)
5114 + struct list_head *tmp;
5115 + struct renamed_entry *ren_entry;
5116 + struct mini_fo_inode_info *inode_info;
5118 + if(!inode || !itopd(inode)) {
5119 + printk(KERN_CRIT "mini_fo: meta_check_r_dentry [2]: \
5120 + invalid inode passed.\n");
5123 + inode_info = itopd(inode);
5125 + if(inode_info->renamed_list_size <= 0)
5128 + list_for_each(tmp, &inode_info->renamed_list) {
5129 + ren_entry = list_entry(tmp, struct renamed_entry, list);
5130 + if(ren_entry->new_len != len)
5133 + if(!strncmp(ren_entry->new_name, name, len))
5139 diff -urN linux.old/fs/mini_fo/mini_fo.h linux.dev/fs/mini_fo/mini_fo.h
5140 --- linux.old/fs/mini_fo/mini_fo.h 1970-01-01 01:00:00.000000000 +0100
5141 +++ linux.dev/fs/mini_fo/mini_fo.h 2006-10-29 01:18:22.000000000 +0200
5144 + * Copyright (c) 1997-2003 Erez Zadok
5145 + * Copyright (c) 2001-2003 Stony Brook University
5147 + * For specific licensing information, see the COPYING file distributed with
5148 + * this package, or get one from ftp://ftp.filesystems.org/pub/fist/COPYING.
5150 + * This Copyright notice must be kept intact and distributed with all
5151 + * fistgen sources INCLUDING sources generated by fistgen.
5154 + * Copyright (C) 2004, 2005 Markus Klotzbuecher <mk@creamnet.de>
5156 + * This program is free software; you can redistribute it and/or
5157 + * modify it under the terms of the GNU General Public License
5158 + * as published by the Free Software Foundation; either version
5159 + * 2 of the License, or (at your option) any later version.
5166 +#ifndef __MINI_FO_H_
5167 +#define __MINI_FO_H_
5172 +#define META_FILENAME "META_dAfFgHE39ktF3HD2sr"
5177 +/* File attributes that when changed, result in a file beeing copied to storage */
5178 +#define COPY_FLAGS ATTR_MODE | ATTR_UID | ATTR_GID | ATTR_SIZE
5181 + * mini_fo filestates
5184 +#define UNMODIFIED 2
5186 +#define DEL_REWRITTEN 4
5188 +#define NON_EXISTANT 6
5190 +/* fist file systems superblock magic */
5191 +# define MINI_FO_SUPER_MAGIC 0xf15f
5197 +/* mini_fo inode data in memory */
5198 +struct mini_fo_inode_info {
5199 + inode_t *wii_inode;
5200 + inode_t *wii_inode2; /* pointer to storage inode */
5202 + /* META-data lists */
5203 + /* deleted list, ex wol */
5204 + struct list_head deleted_list;
5205 + int deleted_list_size;
5207 + /* renamed list */
5208 + struct list_head renamed_list;
5209 + int renamed_list_size;
5211 + /* add other lists here ... */
5214 +/* mini_fo dentry data in memory */
5215 +struct mini_fo_dentry_info {
5216 + dentry_t *wdi_dentry;
5217 + dentry_t *wdi_dentry2; /* pointer to storage dentry */
5218 + unsigned int state; /* state of the mini_fo dentry */
5222 +/* mini_fo super-block data in memory */
5223 +struct mini_fo_sb_info {
5224 + super_block_t *wsi_sb, *wsi_sb2; /* mk: might point to the same sb */
5225 + struct vfsmount *hidden_mnt, *hidden_mnt2;
5226 + dentry_t *base_dir_dentry;
5227 + dentry_t *storage_dir_dentry;
5231 +/* readdir_data, readdir helper struct */
5232 +struct readdir_data {
5233 + struct list_head ndl_list; /* linked list head ptr */
5234 + int ndl_size; /* list size */
5235 + int sto_done; /* flag to show that the storage dir entries have
5236 + * all been read an now follow base entries */
5239 +/* file private data. */
5240 +struct mini_fo_file_info {
5241 + struct file *wfi_file;
5242 + struct file *wfi_file2; /* pointer to storage file */
5243 + struct readdir_data rd;
5246 +/* struct ndl_entry */
5248 + struct list_head list;
5253 +/********************************
5254 + * META-data structures
5255 + ********************************/
5257 +/* deleted entry */
5258 +struct deleted_entry {
5259 + struct list_head list;
5264 +/* renamed entry */
5265 +struct renamed_entry {
5266 + struct list_head list;
5267 + char *old_name; /* old directory with full path */
5268 + int old_len; /* length of above string */
5269 + char *new_name; /* new directory name */
5270 + int new_len; /* length of above string */
5273 +/* attr_change entry */
5274 +struct attr_change_entry {
5275 + struct list_head list;
5281 +struct link_entry {
5282 + struct list_head list;
5287 + int weird_name_len;
5291 +/* Some other stuff required for mini_fo_filldir64, copied from
5295 +#define ROUND_UP64(x) (((x)+sizeof(u64)-1) & ~(sizeof(u64)-1))
5296 +#define NAME_OFFSET(de) ((int) ((de)->d_name - (char *) (de)))
5299 +struct linux_dirent64 {
5302 + unsigned short d_reclen;
5303 + unsigned char d_type;
5308 +struct getdents_callback64 {
5309 + struct linux_dirent64 * current_dir;
5310 + struct linux_dirent64 * previous;
5315 +struct linux_dirent {
5316 + unsigned long d_ino;
5317 + unsigned long d_off;
5318 + unsigned short d_reclen;
5322 +struct getdents_callback {
5323 + struct linux_dirent * current_dir;
5324 + struct linux_dirent * previous;
5334 +/* file TO private_data */
5335 +# define ftopd(file) ((struct mini_fo_file_info *)((file)->private_data))
5336 +# define __ftopd(file) ((file)->private_data)
5337 +/* file TO hidden_file */
5338 +# define ftohf(file) ((ftopd(file))->wfi_file)
5339 +# define ftohf2(file) ((ftopd(file))->wfi_file2)
5341 +/* inode TO private_data */
5342 +# define itopd(ino) ((struct mini_fo_inode_info *)(ino)->u.generic_ip)
5343 +# define __itopd(ino) ((ino)->u.generic_ip)
5344 +/* inode TO hidden_inode */
5345 +# define itohi(ino) (itopd(ino)->wii_inode)
5346 +# define itohi2(ino) (itopd(ino)->wii_inode2)
5348 +/* superblock TO private_data */
5349 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
5350 +# define stopd(super) ((struct mini_fo_sb_info *)(super)->s_fs_info)
5351 +# define __stopd(super) ((super)->s_fs_info)
5353 +# define stopd(super) ((struct mini_fo_sb_info *)(super)->u.generic_sbp)
5354 +# define __stopd(super) ((super)->u.generic_sbp)
5357 +/* unused? # define vfs2priv stopd */
5358 +/* superblock TO hidden_superblock */
5360 +# define stohs(super) (stopd(super)->wsi_sb)
5361 +# define stohs2(super) (stopd(super)->wsi_sb2)
5363 +/* dentry TO private_data */
5364 +# define dtopd(dentry) ((struct mini_fo_dentry_info *)(dentry)->d_fsdata)
5365 +# define __dtopd(dentry) ((dentry)->d_fsdata)
5366 +/* dentry TO hidden_dentry */
5367 +# define dtohd(dent) (dtopd(dent)->wdi_dentry)
5368 +# define dtohd2(dent) (dtopd(dent)->wdi_dentry2)
5370 +/* dentry to state */
5371 +# define dtost(dent) (dtopd(dent)->state)
5372 +# define sbt(sb) ((sb)->s_type->name)
5374 +#define IS_WRITE_FLAG(flag) (flag & (O_RDWR | O_WRONLY | O_APPEND))
5375 +#define IS_COPY_FLAG(flag) (flag & (COPY_FLAGS))
5377 +/* macros to simplify non-SCA code */
5378 +# define MALLOC_PAGE_POINTERS(hidden_pages, num_hidden_pages)
5379 +# define MALLOC_PAGEDATA_POINTERS(hidden_pages_data, num_hidden_pages)
5380 +# define FREE_PAGE_POINTERS(hidden_pages, num)
5381 +# define FREE_PAGEDATA_POINTERS(hidden_pages_data, num)
5382 +# define FOR_EACH_PAGE
5383 +# define CURRENT_HIDDEN_PAGE hidden_page
5384 +# define CURRENT_HIDDEN_PAGEDATA hidden_page_data
5385 +# define CURRENT_HIDDEN_PAGEINDEX page->index
5390 +extern struct file_operations mini_fo_main_fops;
5391 +extern struct file_operations mini_fo_dir_fops;
5392 +extern struct inode_operations mini_fo_main_iops;
5393 +extern struct inode_operations mini_fo_dir_iops;
5394 +extern struct inode_operations mini_fo_symlink_iops;
5395 +extern struct super_operations mini_fo_sops;
5396 +extern struct dentry_operations mini_fo_dops;
5397 +extern struct vm_operations_struct mini_fo_shared_vmops;
5398 +extern struct vm_operations_struct mini_fo_private_vmops;
5399 +extern struct address_space_operations mini_fo_aops;
5401 +#if 0 /* unused by mini_fo */
5402 +extern int mini_fo_interpose(dentry_t *hidden_dentry, dentry_t *this_dentry, super_block_t *sb, int flag);
5403 +#if defined(FIST_FILTER_DATA) || defined(FIST_FILTER_SCA)
5404 +extern page_t *mini_fo_get1page(file_t *file, int index);
5405 +extern int mini_fo_fill_zeros(file_t *file, page_t *page, unsigned from);
5406 +# endif /* FIST_FILTER_DATA || FIST_FILTER_SCA */
5409 +# define mini_fo_hidden_dentry(d) __mini_fo_hidden_dentry(__FILE__,__FUNCTION__,__LINE__,(d))
5410 +# define mini_fo_hidden_sto_dentry(d) __mini_fo_hidden_sto_dentry(__FILE__,__FUNCTION__,__LINE__,(d))
5412 +extern dentry_t *__mini_fo_hidden_dentry(char *file, char *func, int line, dentry_t *this_dentry);
5413 +extern dentry_t *__mini_fo_hidden_sto_dentry(char *file, char *func, int line, dentry_t *this_dentry);
5415 +extern int mini_fo_read_file(const char *filename, void *buf, int len);
5416 +extern int mini_fo_write_file(const char *filename, void *buf, int len);
5417 +extern dentry_t *fist_lookup(dentry_t *dir, const char *name, vnode_t **out, uid_t uid, gid_t gid);
5418 +#endif /* unused by mini_fo */
5420 +/* state transition functions */
5421 +extern int nondir_unmod_to_mod(dentry_t *dentry, int cp_flag);
5422 +extern int nondir_del_rew_to_del(dentry_t *dentry);
5423 +extern int nondir_creat_to_del(dentry_t *dentry);
5424 +extern int nondir_mod_to_del(dentry_t *dentry);
5425 +extern int nondir_unmod_to_del(dentry_t *dentry);
5427 +extern int dir_unmod_to_mod(dentry_t *dentry);
5429 +/* rename specials */
5430 +extern int rename_directory(inode_t *old_dir, dentry_t *old_dentry, inode_t *new_dir, dentry_t *new_dentry);
5431 +extern int rename_nondir(inode_t *old_dir, dentry_t *old_dentry, inode_t *new_dir, dentry_t *new_dentry);
5434 +extern int mini_fo_tri_interpose(dentry_t *hidden_dentry,
5435 + dentry_t *hidden_sto_dentry,
5437 + super_block_t *sb, int flag);
5439 +extern int mini_fo_cp_cont(dentry_t *tgt_dentry, struct vfsmount *tgt_mnt,
5440 + dentry_t *src_dentry, struct vfsmount *src_mnt);
5442 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
5443 +extern int mini_fo_create(inode_t *dir, dentry_t *dentry, int mode, struct nameidata *nd);
5445 +extern int create_sto_nod(dentry_t *dentry, int mode, dev_t dev);
5446 +extern int create_sto_reg_file(dentry_t *dentry, int mode, struct nameidata *nd);
5448 +extern int mini_fo_create(inode_t *dir, dentry_t *dentry, int mode);
5450 +extern int create_sto_nod(dentry_t *dentry, int mode, int dev);
5451 +extern int create_sto_reg_file(dentry_t *dentry, int mode);
5454 +extern int create_sto_dir(dentry_t *dentry, int mode);
5456 +extern int exists_in_storage(dentry_t *dentry);
5457 +extern int is_mini_fo_existant(dentry_t *dentry);
5458 +extern int get_neg_sto_dentry(dentry_t *dentry);
5459 +extern int build_sto_structure(dentry_t *dir, dentry_t *dentry);
5460 +extern int get_mini_fo_bpath(dentry_t *dentry, char **bpath, int *bpath_len);
5461 +extern dentry_t *bpath_walk(super_block_t *sb, char *bpath);
5462 +extern int bpath_put(dentry_t *dentry);
5464 +/* check_mini_fo types functions */
5465 +extern int check_mini_fo_dentry(dentry_t *dentry);
5466 +extern int check_mini_fo_file(file_t *file);
5467 +extern int check_mini_fo_inode(inode_t *inode);
5469 +/* General meta functions, can be called from outside of meta.c */
5470 +extern int meta_build_lists(dentry_t *dentry);
5471 +extern int meta_put_lists(dentry_t *dentry);
5472 +extern int __meta_put_lists(inode_t *inode);
5474 +extern int meta_add_d_entry(dentry_t *dentry, const char *name, int len);
5475 +extern int meta_add_r_entry(dentry_t *dentry,
5476 + const char *old_name, int old_len,
5477 + const char *new_name, int new_len);
5479 +extern int meta_remove_r_entry(dentry_t *dentry, const char *name, int len);
5481 +extern int meta_check_d_entry(dentry_t *dentry, const char *name, int len);
5482 +extern int __meta_check_d_entry(inode_t *inode, const char *name, int len);
5484 +extern char* meta_check_r_entry(dentry_t *dentry, const char *name, int len);
5485 +extern char* __meta_check_r_entry(inode_t *inode, const char *name, int len);
5486 +extern int meta_is_r_entry(dentry_t *dentry, const char *name, int len);
5487 +extern int __meta_is_r_entry(inode_t *inode, const char *name, int len);
5489 +/* Specific meta functions, should be called only inside meta.c */
5490 +extern int __meta_put_d_list(inode_t *inode);
5491 +extern int __meta_put_r_list(inode_t *inode);
5493 +extern int meta_list_add_d_entry(dentry_t *dentry,
5494 + const char *name, int len);
5495 +extern int meta_list_add_r_entry(dentry_t *dentry,
5496 + const char *old_name, int old_len,
5497 + const char *new_name, int new_len);
5499 +extern int meta_list_remove_r_entry(dentry_t *dentry,
5500 + const char *name, int len);
5502 +extern int __meta_list_remove_r_entry(inode_t *inode,
5503 + const char *name, int len);
5505 +extern int meta_write_d_entry(dentry_t *dentry, const char *name, int len);
5506 +extern int meta_write_r_entry(dentry_t *dentry,
5507 + const char *old_name, int old_len,
5508 + const char *new_name, int new_len);
5510 +extern int meta_sync_lists(dentry_t *dentry);
5511 +extern int meta_sync_d_list(dentry_t *dentry, int app_flag);
5512 +extern int meta_sync_r_list(dentry_t *dentry, int app_flag);
5515 +extern int ndl_add_entry(struct readdir_data *rd, const char *name, int len);
5516 +extern void ndl_put_list(struct readdir_data *rd);
5517 +extern int ndl_check_entry(struct readdir_data *rd,
5518 + const char *name, int len);
5521 +# define copy_inode_size(dst, src) \
5522 + dst->i_size = src->i_size; \
5523 + dst->i_blocks = src->i_blocks;
5526 +fist_copy_attr_atime(inode_t *dest, const inode_t *src)
5528 + ASSERT(dest != NULL);
5529 + ASSERT(src != NULL);
5530 + dest->i_atime = src->i_atime;
5533 +fist_copy_attr_times(inode_t *dest, const inode_t *src)
5535 + ASSERT(dest != NULL);
5536 + ASSERT(src != NULL);
5537 + dest->i_atime = src->i_atime;
5538 + dest->i_mtime = src->i_mtime;
5539 + dest->i_ctime = src->i_ctime;
5542 +fist_copy_attr_timesizes(inode_t *dest, const inode_t *src)
5544 + ASSERT(dest != NULL);
5545 + ASSERT(src != NULL);
5546 + dest->i_atime = src->i_atime;
5547 + dest->i_mtime = src->i_mtime;
5548 + dest->i_ctime = src->i_ctime;
5549 + copy_inode_size(dest, src);
5552 +fist_copy_attr_all(inode_t *dest, const inode_t *src)
5554 + ASSERT(dest != NULL);
5555 + ASSERT(src != NULL);
5556 + dest->i_mode = src->i_mode;
5557 + dest->i_nlink = src->i_nlink;
5558 + dest->i_uid = src->i_uid;
5559 + dest->i_gid = src->i_gid;
5560 + dest->i_rdev = src->i_rdev;
5561 + dest->i_atime = src->i_atime;
5562 + dest->i_mtime = src->i_mtime;
5563 + dest->i_ctime = src->i_ctime;
5564 + dest->i_blksize = src->i_blksize;
5565 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,12)
5566 + dest->i_blkbits = src->i_blkbits;
5567 +# endif /* linux 2.4.12 and newer */
5568 + copy_inode_size(dest, src);
5569 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
5570 + dest->i_attr_flags = src->i_attr_flags;
5572 + dest->i_flags = src->i_flags;
5576 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
5577 +/* copied from linux/fs.h */
5578 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
5579 +static inline void double_lock(struct dentry *d1, struct dentry *d2)
5581 + struct mutex *m1 = &d1->d_inode->i_mutex;
5582 + struct mutex *m2 = &d2->d_inode->i_mutex;
5584 + if ((unsigned long) m1 < (unsigned long) m2) {
5585 + struct mutex *tmp = m2;
5586 + m2 = m1; m1 = tmp;
5593 +static inline void double_unlock(struct dentry *d1, struct dentry *d2)
5595 + struct mutex *m1 = &d1->d_inode->i_mutex;
5596 + struct mutex *m2 = &d2->d_inode->i_mutex;
5605 +static inline void double_down(struct semaphore *s1, struct semaphore *s2)
5608 + if ((unsigned long) s1 < (unsigned long) s2) {
5609 + struct semaphore *tmp = s2;
5610 + s2 = s1; s1 = tmp;
5617 +static inline void double_up(struct semaphore *s1, struct semaphore *s2)
5624 +static inline void double_lock(struct dentry *d1, struct dentry *d2)
5626 + double_down(&d1->d_inode->i_sem, &d2->d_inode->i_sem);
5629 +static inline void double_unlock(struct dentry *d1, struct dentry *d2)
5631 + double_up(&d1->d_inode->i_sem,&d2->d_inode->i_sem);
5635 +#endif /* if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16) */
5636 +#endif /* if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0) */
5637 +#endif /* __KERNEL__ */
5640 + * Definitions for user and kernel code
5645 +#endif /* not __MINI_FO_H_ */
5646 diff -urN linux.old/fs/mini_fo/mini_fo-merge linux.dev/fs/mini_fo/mini_fo-merge
5647 --- linux.old/fs/mini_fo/mini_fo-merge 1970-01-01 01:00:00.000000000 +0100
5648 +++ linux.dev/fs/mini_fo/mini_fo-merge 2005-10-15 12:49:43.000000000 +0200
5652 +# Copyright (C) 2005 Markus Klotzbuecher <mk@creamnet.de>
5653 +# This program is free software; you can redistribute it and/or
5654 +# modify it under the terms of the GNU General Public License
5655 +# as published by the Free Software Foundation; either version
5656 +# 2 of the License, or (at your option) any later version.
5665 +META_NAME="META_dAfFgHE39ktF3HD2sr"
5666 +SKIP_DEL_LIST="skip-delete-list.mini_fo-merge"
5671 + if [ x$DRYRUN == "xset" ]; then
5672 + echo " would run: $COMMAND"
5673 + elif ! [ x$DRYRUN == "xset" ]; then
5674 + if [ x$VERBOSE == "xset" ]; then
5675 + echo " running: $COMMAND"
5685 +USAGE: $0 -b <base dir> -s <storage dir>
5688 +This script merges the contents of a mini_fo storage file system back
5689 +to the base file system.
5691 +!!! Warning: This will modify the base filesystem and can destroy data
5696 + the directory of the base file system.
5699 + the directory of the storage file system.
5701 + -d dry run, will not change anything and print the commands that
5702 + would be executed.
5704 + -t tmp dir for storing temporary file. default: $TMP
5706 + -v show what operations are performed.
5708 + -h displays this message.
5714 +while getopts hdvt:b:s: OPTS
5719 + v) VERBOSE="set";;
5720 + b) BASE="$OPTARG";;
5721 + s) STO="$OPTARG";;
5722 + t) TMP="$OPTARG";;
5728 +if [ "x$HELP" == "xset" ]; then
5733 +if ! [ -d "$BASE" ] || ! [ -d "$STO" ]; then
5734 + echo -e "$0:\n Error, -s and/or -b argument missing. type $0 -h for help."
5739 +pushd $STO; STO=`pwd`; popd
5740 +pushd $BASE; BASE=`pwd`; popd
5745 +###############################################################################
5749 +# storage dir: $STO
5750 +# meta filename: $META_NAME
5752 +# verbose: $VERBOSE
5754 +###############################################################################
5758 +rm $TMP/$SKIP_DEL_LIST
5760 +# first process all renamed dirs
5761 +echo "Merging renamed directories..."
5762 +pushd $STO &> /dev/null
5763 +find . -name $META_NAME -type f -print0 | xargs -0 -e grep -e '^R ' | tr -s ':R' ' ' | while read ENTRY; do
5764 + echo "entry: $ENTRY"
5765 + META_FILE=`echo $ENTRY | cut -d ' ' -f 1`
5766 + OLD_B_DIR=`echo $ENTRY | cut -d ' ' -f 2 | sed -e 's/\///'`
5767 + NEW_NAME=`echo $ENTRY | cut -d ' ' -f 3`
5768 + NEW_B_DIR=`echo $META_FILE | sed -e "s/$META_NAME/$NEW_NAME/" | sed -e 's/^\.\///'`
5769 + echo "META_FILE: $META_FILE"
5770 + echo "OLD_B_DIR: $OLD_B_DIR"
5771 + echo "NEW_NAME: $NEW_NAME"
5772 + echo "NEW_B_DIR: $NEW_B_DIR"
5774 + pushd $BASE &> /dev/null
5775 + # remove an existing dir in storage
5776 + COMMAND="rm -rf $NEW_B_DIR"; exec_command
5777 + COMMAND="cp -R $OLD_B_DIR $NEW_B_DIR"; exec_command
5781 + # remember this dir to exclude it from deleting later
5782 + echo $NEW_B_DIR >> $TMP/$SKIP_DEL_LIST
5785 +# delete all whiteouted files from base
5786 +echo -e "\nDeleting whiteout'ed files from base file system..."
5787 +find . -name $META_NAME -type f -print0 | xargs -0 -e grep -e '^D ' | sed -e 's/:D//' | while read ENTRY; do
5788 + META_FILE=`echo $ENTRY | cut -d ' ' -f 1`
5789 + DEL_NAME=`echo $ENTRY | cut -d ' ' -f 2`
5790 + DEL_FILE=`echo $META_FILE | sed -e "s/$META_NAME/$DEL_NAME/" | sed -e 's/^\.\///'`
5791 + grep -x $DEL_FILE $TMP/$SKIP_DEL_LIST &> /dev/null
5792 + if [ $? -ne 0 ]; then
5793 + pushd $BASE &> /dev/null
5794 + COMMAND="rm -rf $DEL_FILE"; exec_command
5797 + echo " excluding: $DEL_FILE as in skip-del-list."
5801 +# create all dirs and update permissions
5802 +echo -e "\nSetting up directory structures in base file system..."
5803 +find . -type d | sed -e 's/^\.\///' | while read DIR; do
5804 + PERMS=`stat -c %a $DIR`
5805 + DIR_UID=`stat -c %u $DIR`
5806 + DIR_GID=`stat -c %g $DIR`
5807 + pushd $BASE &> /dev/null
5808 + if ! [ -d $DIR ]; then
5809 + COMMAND="mkdir -p $DIR"; exec_command
5811 + COMMAND="chmod $PERMS $DIR"; exec_command
5812 + COMMAND="chown $DIR_UID:$DIR_GID $DIR"; exec_command
5816 +# merge all non-directory files
5817 +echo -e "\nMerging all non-directory files...."
5818 +for i in b c p f l s; do
5819 + find . -type $i | sed -e 's/^\.\///' | grep -v "$META_NAME" | while read FILE; do
5820 + pushd $BASE #&> /dev/null
5821 + COMMAND="cp -df $STO/$FILE $BASE/$FILE"; exec_command
5827 +#rm $TMP/$SKIP_DEL_LIST
5830 diff -urN linux.old/fs/mini_fo/mini_fo-overlay linux.dev/fs/mini_fo/mini_fo-overlay
5831 --- linux.old/fs/mini_fo/mini_fo-overlay 1970-01-01 01:00:00.000000000 +0100
5832 +++ linux.dev/fs/mini_fo/mini_fo-overlay 2005-10-15 12:49:43.000000000 +0200
5836 +# Copyright (C) 2005 Markus Klotzbuecher <mk@creamnet.de>
5837 +# This program is free software; you can redistribute it and/or
5838 +# modify it under the terms of the GNU General Public License
5839 +# as published by the Free Software Foundation; either version
5840 +# 2 of the License, or (at your option) any later version.
5855 +Usage: $0 [-s suffix] [-d sto_dir_dir] [-m mount point] base_dir
5858 +This script overlays the given base directory using the mini_fo file
5859 +system. If only the base directory base_dir is given, $0
5860 +will use a storage directory called "sto-<base_dir_name>" in $STO_DIR,
5861 +and mount point "mini_fo-<base_dir_dir>" in $MNT_DIR.
5865 + add given suffix to storage directory and the mount
5866 + point. This is usefull for overlaying one base directory
5867 + several times and avoiding conflicts with storage directory
5868 + names and mount points.
5871 + change the directory in which the storage directory will be
5872 + created (default is currently "$STO_DIR".
5875 + use an alternative directory to create the mini_fo
5876 + mountpoint (default is currently "$MNT_DIR".
5878 + -h displays this message.
5884 +while getopts hm:s:d: OPTS
5887 + s) SUFF="$OPTARG";;
5888 + d) STO_DIR="$OPTARG";;
5889 + m) MNT_DIR="$OPTARG";;
5895 +shift $(($OPTIND - 1))
5899 +if [ "x$HELP" == "xset" ]; then
5905 +if [ "x$SUFF" != "x" ]; then
5909 +# kill trailing slashes
5910 +MNT_DIR=${MNT_DIR%/}
5911 +STO_DIR=${STO_DIR%/}
5915 +if ! [ -d "$BASE" ]; then
5916 + echo "invalid base dir $BASE, run $0 -h for help."
5921 +if ! [ -d "$MNT_DIR" ]; then
5922 + echo "invalid mount dir $MNT_DIR, run $0 -h for help."
5926 +if ! [ -d "$STO_DIR" ]; then
5927 + echo "invalid sto_dir_dir $STO_DIR, run $0 -h for help."
5931 +MNTP="$MNT_DIR/mini_fo-`basename $BASE`$SUFF"
5932 +STO="$STO_DIR/sto-`basename $BASE`$SUFF"
5934 +# create the mount point if it doesn't exist
5936 +if [ $? -ne 0 ]; then
5937 + echo "Error, failed to create mount point $MNTP"
5941 +if [ $? -ne 0 ]; then
5942 + echo "Error, failed to create storage dir $STO"
5945 +# check if fs is already mounted
5946 +mount | grep mini_fo | grep $MNTP &> /dev/null
5947 +if [ $? -eq 0 ]; then
5948 + echo "Error, existing mini_fo mount at $MNTP."
5952 +mount | grep mini_fo | grep $STO &> /dev/null
5953 +if [ $? -eq 0 ]; then
5954 + echo "Error, $STO seems to be used already."
5959 +mount -t mini_fo -o base=$BASE,sto=$STO $BASE $MNTP
5961 +if [ $? -ne 0 ]; then
5962 + echo "Error, mounting failed, maybe no permisson to mount?"
5964 diff -urN linux.old/fs/mini_fo/mmap.c linux.dev/fs/mini_fo/mmap.c
5965 --- linux.old/fs/mini_fo/mmap.c 1970-01-01 01:00:00.000000000 +0100
5966 +++ linux.dev/fs/mini_fo/mmap.c 2006-10-29 04:32:06.000000000 +0100
5969 + * Copyright (c) 1997-2003 Erez Zadok
5970 + * Copyright (c) 2001-2003 Stony Brook University
5972 + * For specific licensing information, see the COPYING file distributed with
5973 + * this package, or get one from ftp://ftp.filesystems.org/pub/fist/COPYING.
5975 + * This Copyright notice must be kept intact and distributed with all
5976 + * fistgen sources INCLUDING sources generated by fistgen.
5979 + * Copyright (C) 2004, 2005 Markus Klotzbuecher <mk@creamnet.de>
5981 + * This program is free software; you can redistribute it and/or
5982 + * modify it under the terms of the GNU General Public License
5983 + * as published by the Free Software Foundation; either version
5984 + * 2 of the License, or (at your option) any later version.
5991 +#ifdef HAVE_CONFIG_H
5992 +# include <config.h>
5993 +#endif /* HAVE_CONFIG_H */
5996 +#include "mini_fo.h"
5999 +#ifdef FIST_COUNT_WRITES
6000 +/* for counting writes in the middle vs. regular writes */
6001 +unsigned long count_writes = 0, count_writes_middle = 0;
6002 +#endif /* FIST_COUNT_WRITES */
6004 +/* forward declaration of commit write and prepare write */
6005 +STATIC int mini_fo_commit_write(file_t *file, page_t *page, unsigned from, unsigned to);
6006 +STATIC int mini_fo_prepare_write(file_t *file, page_t *page, unsigned from, unsigned to);
6010 + * Function for handling creation of holes when lseek-ing past the
6011 + * end of the file and then writing some data.
6014 +mini_fo_fill_zeros(file_t* file, page_t *page, unsigned from)
6017 + dentry_t *dentry = file->f_dentry;
6018 + inode_t *inode = dentry->d_inode;
6022 + print_entry_location();
6024 + for (index = inode->i_size >> PAGE_CACHE_SHIFT; index < page->index; index++) {
6025 + tmp_page = mini_fo_get1page(file, index);
6026 + if (IS_ERR(tmp_page)) {
6027 + err = PTR_ERR(tmp_page);
6032 + * zero out rest of the contents of the page between the appropriate
6035 + memset((char*)page_address(tmp_page) + (inode->i_size & ~PAGE_CACHE_MASK), 0, PAGE_CACHE_SIZE - (inode->i_size & ~PAGE_CACHE_MASK));
6037 + if (! (err = mini_fo_prepare_write(file, tmp_page, 0, PAGE_CACHE_SIZE)))
6038 + err = mini_fo_commit_write(file, tmp_page, 0, PAGE_CACHE_SIZE);
6040 + page_cache_release(tmp_page);
6043 + if (current->need_resched)
6047 + /* zero out appropriate parts of last page */
6050 + * if the encoding type is block, then adjust the 'from' (where the
6051 + * zeroing will start) offset appropriately
6053 + from = from & (~(FIST_ENCODING_BLOCKSIZE - 1));
6055 + if ((from - (inode->i_size & ~PAGE_CACHE_MASK)) > 0) {
6057 + memset((char*)page_address(page) + (inode->i_size & ~PAGE_CACHE_MASK), 0, from - (inode->i_size & ~PAGE_CACHE_MASK));
6058 + if (! (err = mini_fo_prepare_write(file, page, 0, PAGE_CACHE_SIZE)))
6059 + err = mini_fo_commit_write(file, page, 0, PAGE_CACHE_SIZE);
6063 + if (current->need_resched)
6068 + print_exit_status(err);
6075 +mini_fo_writepage(page_t *page)
6079 + inode_t *hidden_inode;
6080 + page_t *hidden_page;
6081 + char *kaddr, *hidden_kaddr;
6083 + print_entry_location();
6085 + inode = page->mapping->host;
6086 + hidden_inode = itohi(inode);
6089 + * writepage is called when shared mmap'ed files need to write
6090 + * their pages, while prepare/commit_write are called from the
6091 + * non-paged write() interface. (However, in 2.3 the two interfaces
6092 + * share the same cache, while in 2.2 they didn't.)
6094 + * So we pretty much have to duplicate much of what commit_write does.
6097 + /* find lower page (returns a locked page) */
6098 + hidden_page = grab_cache_page(hidden_inode->i_mapping, page->index);
6102 + /* get page address, and encode it */
6103 + kaddr = (char *) kmap(page);
6104 + hidden_kaddr = (char*) kmap(hidden_page);
6105 + mini_fo_encode_block(kaddr, hidden_kaddr, PAGE_CACHE_SIZE, inode, inode->i_sb, page->index);
6106 + /* if encode_block could fail, then return error */
6108 + kunmap(hidden_page);
6110 + /* call lower writepage (expects locked page) */
6111 + err = hidden_inode->i_mapping->a_ops->writepage(hidden_page);
6114 + * update mtime and ctime of lower level file system
6115 + * mini_fo' mtime and ctime are updated by generic_file_write
6117 + hidden_inode->i_mtime = hidden_inode->i_ctime = CURRENT_TIME;
6119 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,4,1)
6120 + UnlockPage(hidden_page); /* b/c grab_cache_page locked it */
6121 +# endif /* kernel older than 2.4.1 */
6122 + page_cache_release(hidden_page); /* b/c grab_cache_page increased refcnt */
6125 + ClearPageUptodate(page);
6127 + SetPageUptodate(page);
6129 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,1)
6131 +# endif /* kernel 2.4.1 and newer */
6132 + print_exit_status(err);
6138 + * get one page from cache or lower f/s, return error otherwise.
6139 + * returns unlocked, up-to-date page (if ok), with increased refcnt.
6142 +mini_fo_get1page(file_t *file, int index)
6147 + struct address_space *mapping;
6150 + print_entry_location();
6152 + dentry = file->f_dentry; /* CPW: Moved below print_entry_location */
6153 + inode = dentry->d_inode;
6154 + mapping = inode->i_mapping;
6156 + fist_dprint(8, "%s: read page index %d pid %d\n", __FUNCTION__, index, current->pid);
6158 + printk("%s BUG: index=%d\n", __FUNCTION__, index);
6159 + page = ERR_PTR(-EIO);
6162 + page = read_cache_page(mapping,
6164 + (filler_t *) mapping->a_ops->readpage,
6168 + wait_on_page(page);
6169 + if (!Page_Uptodate(page)) {
6171 + err = mapping->a_ops->readpage(file, page);
6173 + page = ERR_PTR(err);
6176 + wait_on_page(page);
6177 + if (!Page_Uptodate(page)) {
6178 + page = ERR_PTR(-EIO);
6184 + print_exit_pointer(page);
6190 + * get one page from cache or lower f/s, return error otherwise.
6191 + * similar to get1page, but doesn't guarantee that it will return
6192 + * an unlocked page.
6195 +mini_fo_get1page_cached(file_t *file, int index)
6200 + struct address_space *mapping;
6203 + print_entry_location();
6205 + dentry = file->f_dentry; /* CPW: Moved below print_entry_location */
6206 + inode = dentry->d_inode;
6207 + mapping = inode->i_mapping;
6209 + fist_dprint(8, "%s: read page index %d pid %d\n", __FUNCTION__, index, current->pid);
6211 + printk("%s BUG: index=%d\n", __FUNCTION__, index);
6212 + page = ERR_PTR(-EIO);
6215 + page = read_cache_page(mapping,
6217 + (filler_t *) mapping->a_ops->readpage,
6223 + print_exit_pointer(page);
6229 + * readpage is called from generic_page_read and the fault handler.
6230 + * If your file system uses generic_page_read for the read op, it
6231 + * must implement readpage.
6233 + * Readpage expects a locked page, and must unlock it.
6236 +mini_fo_do_readpage(file_t *file, page_t *page)
6240 + file_t *hidden_file = NULL;
6241 + dentry_t *hidden_dentry;
6243 + inode_t *hidden_inode;
6245 + page_t *hidden_page;
6246 + char *hidden_page_data;
6249 + print_entry_location();
6251 + dentry = file->f_dentry; /* CPW: Moved below print_entry_location */
6252 + if (ftopd(file) != NULL)
6253 + hidden_file = ftohf(file);
6254 + hidden_dentry = dtohd(dentry);
6255 + inode = dentry->d_inode;
6256 + hidden_inode = itohi(inode);
6258 + fist_dprint(7, "%s: requesting page %d from file %s\n", __FUNCTION__, page->index, dentry->d_name.name);
6260 + MALLOC_PAGE_POINTERS(hidden_pages, num_hidden_pages);
6261 + MALLOC_PAGEDATA_POINTERS(hidden_pages_data, num_hidden_pages);
6263 + CURRENT_HIDDEN_PAGE = NULL;
6265 + /* find lower page (returns a locked page) */
6267 + fist_dprint(8, "%s: Current page index = %d\n", __FUNCTION__, CURRENT_HIDDEN_PAGEINDEX);
6268 + CURRENT_HIDDEN_PAGE = read_cache_page(hidden_inode->i_mapping,
6269 + CURRENT_HIDDEN_PAGEINDEX,
6270 + (filler_t *) hidden_inode->i_mapping->a_ops->readpage,
6271 + (void *) hidden_file);
6272 + if (IS_ERR(CURRENT_HIDDEN_PAGE)) {
6273 + err = PTR_ERR(CURRENT_HIDDEN_PAGE);
6274 + CURRENT_HIDDEN_PAGE = NULL;
6280 + * wait for the page data to show up
6281 + * (signaled by readpage as unlocking the page)
6284 + wait_on_page(CURRENT_HIDDEN_PAGE);
6285 + if (!Page_Uptodate(CURRENT_HIDDEN_PAGE)) {
6287 + * call readpage() again if we returned from wait_on_page with a
6288 + * page that's not up-to-date; that can happen when a partial
6289 + * page has a few buffers which are ok, but not the whole
6292 + lock_page(CURRENT_HIDDEN_PAGE);
6293 + err = hidden_inode->i_mapping->a_ops->readpage(hidden_file,
6294 + CURRENT_HIDDEN_PAGE);
6296 + CURRENT_HIDDEN_PAGE = NULL;
6299 + wait_on_page(CURRENT_HIDDEN_PAGE);
6300 + if (!Page_Uptodate(CURRENT_HIDDEN_PAGE)) {
6307 + /* map pages, get their addresses */
6308 + page_data = (char *) kmap(page);
6310 + CURRENT_HIDDEN_PAGEDATA = (char *) kmap(CURRENT_HIDDEN_PAGE);
6312 + /* if decode_block could fail, then return error */
6314 + real_size = hidden_inode->i_size - (page->index << PAGE_CACHE_SHIFT);
6315 + if (real_size <= 0)
6316 + memset(page_data, 0, PAGE_CACHE_SIZE);
6317 + else if (real_size < PAGE_CACHE_SIZE) {
6318 + mini_fo_decode_block(hidden_page_data, page_data, real_size, inode, inode->i_sb, page->index);
6319 + memset(page_data + real_size, 0, PAGE_CACHE_SIZE - real_size);
6321 + mini_fo_decode_block(hidden_page_data, page_data, PAGE_CACHE_SIZE, inode, inode->i_sb, page->index);
6324 + kunmap(CURRENT_HIDDEN_PAGE);
6329 + if (CURRENT_HIDDEN_PAGE)
6330 + page_cache_release(CURRENT_HIDDEN_PAGE); /* undo read_cache_page */
6332 + FREE_PAGE_POINTERS(hidden_pages, num_hidden_pages);
6333 + FREE_PAGEDATA_POINTERS(hidden_pages_data, num_hidden_pages);
6337 + SetPageUptodate(page);
6339 + ClearPageUptodate(page);
6341 + print_exit_status(err);
6347 +mini_fo_readpage(file_t *file, page_t *page)
6350 + print_entry_location();
6352 + err = mini_fo_do_readpage(file, page);
6355 + * we have to unlock our page, b/c we _might_ have gotten a locked page.
6356 + * but we no longer have to wakeup on our page here, b/c UnlockPage does
6361 + print_exit_status(err);
6367 +mini_fo_prepare_write(file_t *file, page_t *page, unsigned from, unsigned to)
6371 + print_entry_location();
6374 + * we call kmap(page) only here, and do the kunmap
6375 + * and the actual downcalls, including unlockpage and uncache
6376 + * in commit_write.
6380 + /* fast path for whole page writes */
6381 + if (from == 0 && to == PAGE_CACHE_SIZE)
6383 + /* read the page to "revalidate" our data */
6384 + /* call the helper function which doesn't unlock the page */
6385 + if (!Page_Uptodate(page))
6386 + err = mini_fo_do_readpage(file, page);
6389 + print_exit_status(err);
6396 +mini_fo_commit_write(file_t *file, page_t *page, unsigned from, unsigned to)
6398 + int err = -ENOMEM;
6400 + inode_t *hidden_inode;
6401 + page_t *hidden_page;
6402 + file_t *hidden_file = NULL;
6404 + unsigned bytes = to - from;
6405 + unsigned hidden_from, hidden_to, hidden_bytes;
6407 + print_entry_location();
6409 + inode = page->mapping->host; /* CPW: Moved below print_entry_location */
6410 + hidden_inode = itohi(inode);
6412 + ASSERT(file != NULL);
6414 + * here we have a kmapped page, with data from the user copied
6415 + * into it. we need to encode_block it, and then call the lower
6416 + * commit_write. We also need to simulate same behavior of
6417 + * generic_file_write, and call prepare_write on the lower f/s first.
6419 +#ifdef FIST_COUNT_WRITES
6421 +# endif /* FIST_COUNT_WRITES */
6423 + /* this is append and/or extend -- we can't have holes so fill them in */
6424 + if (page->index > (hidden_inode->i_size >> PAGE_CACHE_SHIFT)) {
6427 + for (index = hidden_inode->i_size >> PAGE_CACHE_SHIFT; index < page->index; index++) {
6428 + tmp_page = mini_fo_get1page(file, index);
6429 + if (IS_ERR(tmp_page)) {
6430 + err = PTR_ERR(tmp_page);
6433 + /* zero out the contents of the page at the appropriate offsets */
6434 + memset((char*)page_address(tmp_page) + (inode->i_size & ~PAGE_CACHE_MASK), 0, PAGE_CACHE_SIZE - (inode->i_size & ~PAGE_CACHE_MASK));
6435 + if (!(err = mini_fo_prepare_write(file, tmp_page, 0, PAGE_CACHE_SIZE)))
6436 + err = mini_fo_commit_write(file, tmp_page, 0, PAGE_CACHE_SIZE);
6437 + page_cache_release(tmp_page);
6440 + if (current->need_resched)
6445 + if (ftopd(file) != NULL)
6446 + hidden_file = ftohf(file);
6448 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
6449 + mutex_lock(&hidden_inode->i_mutex);
6451 + down(&hidden_inode->i_sem);
6453 + /* find lower page (returns a locked page) */
6454 + hidden_page = grab_cache_page(hidden_inode->i_mapping, page->index);
6458 +#if FIST_ENCODING_BLOCKSIZE > 1
6459 +# error encoding_blocksize greater than 1 is not yet supported
6460 +# endif /* FIST_ENCODING_BLOCKSIZE > 1 */
6462 + hidden_from = from & (~(FIST_ENCODING_BLOCKSIZE - 1));
6463 + hidden_to = ((to + FIST_ENCODING_BLOCKSIZE - 1) & (~(FIST_ENCODING_BLOCKSIZE - 1)));
6464 + if ((page->index << PAGE_CACHE_SHIFT) + to > hidden_inode->i_size) {
6467 + * if this call to commit_write had introduced holes and the code
6468 + * for handling holes was invoked, then the beginning of this page
6469 + * must be zeroed out
6470 + * zero out bytes from 'size_of_file%pagesize' to 'from'.
6472 + if ((hidden_from - (inode->i_size & ~PAGE_CACHE_MASK)) > 0)
6473 + memset((char*)page_address(page) + (inode->i_size & ~PAGE_CACHE_MASK), 0, hidden_from - (inode->i_size & ~PAGE_CACHE_MASK));
6476 + hidden_bytes = hidden_to - hidden_from;
6478 + /* call lower prepare_write */
6480 + if (hidden_inode->i_mapping &&
6481 + hidden_inode->i_mapping->a_ops &&
6482 + hidden_inode->i_mapping->a_ops->prepare_write)
6483 + err = hidden_inode->i_mapping->a_ops->prepare_write(hidden_file,
6488 + /* don't leave locked pages behind, esp. on an ENOSPC */
6491 + fist_dprint(8, "%s: encoding %d bytes\n", __FUNCTION__, hidden_bytes);
6492 + 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);
6493 + /* if encode_block could fail, then goto unlock and return error */
6495 + /* call lower commit_write */
6496 + err = hidden_inode->i_mapping->a_ops->commit_write(hidden_file,
6504 + err = bytes; /* convert error to no. of bytes */
6506 + inode->i_blocks = hidden_inode->i_blocks;
6507 + /* we may have to update i_size */
6508 + pos = (page->index << PAGE_CACHE_SHIFT) + to;
6509 + if (pos > inode->i_size)
6510 + inode->i_size = pos;
6513 + * update mtime and ctime of lower level file system
6514 + * mini_fo' mtime and ctime are updated by generic_file_write
6516 + hidden_inode->i_mtime = hidden_inode->i_ctime = CURRENT_TIME;
6518 + mark_inode_dirty_sync(inode);
6521 + UnlockPage(hidden_page);
6522 + page_cache_release(hidden_page);
6523 + kunmap(page); /* kmap was done in prepare_write */
6525 + /* we must set our page as up-to-date */
6527 + ClearPageUptodate(page);
6529 + SetPageUptodate(page);
6531 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
6532 + mutex_unlock(&hidden_inode->i_mutex);
6534 + up(&hidden_inode->i_sem);
6536 + print_exit_status(err);
6537 + return err; /* assume all is ok */
6542 +mini_fo_bmap(struct address_space *mapping, long block)
6546 + inode_t *hidden_inode;
6548 + print_entry_location();
6550 + inode = (inode_t *) mapping->host;
6551 + hidden_inode = itohi(inode);
6553 + if (hidden_inode->i_mapping->a_ops->bmap)
6554 + err = hidden_inode->i_mapping->a_ops->bmap(hidden_inode->i_mapping, block);
6555 + print_exit_location();
6561 + * This function is copied verbatim from mm/filemap.c.
6562 + * XXX: It should be simply moved to some header file instead -- bug Al about it!
6564 +static inline int sync_page(struct page *page)
6566 + struct address_space *mapping = page->mapping;
6568 + if (mapping && mapping->a_ops && mapping->a_ops->sync_page)
6569 + return mapping->a_ops->sync_page(page);
6575 + * XXX: we may not need this function if not FIST_FILTER_DATA.
6576 + * FIXME: for FIST_FILTER_SCA, get all lower pages and sync them each.
6579 +mini_fo_sync_page(page_t *page)
6583 + inode_t *hidden_inode;
6584 + page_t *hidden_page;
6586 + print_entry_location();
6588 + inode = page->mapping->host; /* CPW: Moved below print_entry_location */
6589 + hidden_inode = itohi(inode);
6591 + /* find lower page (returns a locked page) */
6592 + hidden_page = grab_cache_page(hidden_inode->i_mapping, page->index);
6596 + err = sync_page(hidden_page);
6598 + UnlockPage(hidden_page); /* b/c grab_cache_page locked it */
6599 + page_cache_release(hidden_page); /* b/c grab_cache_page increased refcnt */
6602 + print_exit_status(err);
6605 diff -urN linux.old/fs/mini_fo/README linux.dev/fs/mini_fo/README
6606 --- linux.old/fs/mini_fo/README 1970-01-01 01:00:00.000000000 +0100
6607 +++ linux.dev/fs/mini_fo/README 2005-10-15 12:49:43.000000000 +0200
6609 +README for the mini_fo overlay file system
6610 +=========================================
6616 +mini_fo is a virtual kernel file system that can make read-only
6617 +file systems writable. This is done by redirecting modifying operations
6618 +to a writeable location called "storage directory", and leaving the
6619 +original data in the "base directory" untouched. When reading, the
6620 +file system merges the modifed and original data so that only the
6621 +newest versions will appear. This occurs transparently to the user,
6622 +who can access the data like on any other read-write file system.
6624 +Base and storage directories may be located on the same or on
6625 +different partitions and may be of different file system types. While
6626 +the storage directory obviously needs to be writable, the base may or
6627 +may not be writable, what doesn't matter as it will no be modified
6634 +The primary purpose of the mini_fo file system is to allow easy
6635 +software updates to embedded systems, that often store their root
6636 +file system in a read-only flash file system, but there are many
6637 +more as for example sandboxing, or for allowing live-cds to
6638 +permanently store information.
6643 +This should be simple. Adjust the Makefile to point to the correct
6644 +kernel headers you want to build the module for. Then:
6648 +should build "mini_fo.o" for a 2.4 kernel or "mini_fo.ko" for a 2.6
6651 +If you are building the module for you current kernel, you can install
6652 +the module (as root):
6661 +USING THE FILE SYSTEM
6662 +--------------------
6664 +the general mount syntax is:
6666 + mount -t mini_fo -o base=<base directory>,sto=<storage directory>\
6667 + <base directory> <mount point>
6671 +You have mounted a cdrom to /mnt/cdrom and want to modifiy some files
6674 +load the module (as root)
6676 + # insmod mini_fo.o for a 2.4 kernel or
6678 + # insmod mini_fo.ko for a 2.6 kernel
6681 +create a storage dir in tmp and a mountpoint for mini_fo:
6684 + # mkdir /mnt/mini_fo
6686 +and mount the mini_fo file system:
6688 + # mount -t mini_fo -o base=/mnt/cdrom,sto=/tmp/sto /mnt/cdrom /mnt/mini_fo
6691 +Now the data stored on the cd can be accessed via the mini_fo
6692 +mountpoint just like any read-write file system, files can be modified
6693 +and deleted, new ones can be created and so on. When done unmount the
6696 + # unmount /mnt/mini_fo
6698 +Note that if the file system is mounted again using the same storage
6699 +file system, of course it will appear in the modified state again. If
6700 +you remount it using an new empty storage directory, it will be
6701 +unmodified. Therefore by executing:
6706 +you can nuke all the changes you made to the original file system. But
6707 + remember NEVER do this while the mini_fo file system is mounted!
6710 +Alternatively you can use the mini_fo-overlay bash script, that
6711 +simplifies managing mini_fo mounts. See TOOLS Section.
6717 +mini_fo-merge (experimental):
6719 +This is a bash script that will merge changes contained in the storage
6720 +directory back to the base directory. This allows mini_fo to function
6721 +as a cache file system by overlaying a slow (network, ...) file system
6722 +and using a fast (ramdisk, ...) as storage. When done, changes can be
6723 +merged back to the (slow) base with mini_fo-merge. See "mini_fo-merge
6726 +It can be usefull for merging changes back after a successfull test
6727 +(patches, software updates...)
6732 +This bash script simplifies managing one or more mini_fo mounts. For
6733 +overlaying a directory called "basedir1", you can just call:
6735 + # mini_fo-overlay basedir1
6737 +This will mount mini_fo with "basedir1" as base, "/tmp/sto-basedir1/"
6738 +as storage to "/mnt/mini_fo-basedir1/". It has more options though,
6739 +type "mini_fo-overlay -h" for details.
6742 +DOCUMENTATION, REPORTING BUGS, GETTING HELP
6743 +-------------------------------------------
6745 +Please visit the mini_fo project page at:
6747 +http://www.denx.de/twiki/bin/view/Know/MiniFOHome
6753 +Never modify the base or the storage directorys while the mini_fo
6754 +file system is mounted, or you might crash you system. Simply accessing
6755 +and reading should not cause any trouble.
6757 +Exporting a mini_fo mount point via NFS has not been tested, and may
6760 +Check the RELEASE_NOTES for details on bugs and features.
6764 +Copyright (C) 2004, 2005 Markus Klotzbuecher <mk@creamnet.de>
6766 +This program is free software; you can redistribute it and/or
6767 +modify it under the terms of the GNU General Public License
6768 +as published by the Free Software Foundation; either version
6769 +2 of the License, or (at your option) any later version.
6772 diff -urN linux.old/fs/mini_fo/RELEASE_NOTES linux.dev/fs/mini_fo/RELEASE_NOTES
6773 --- linux.old/fs/mini_fo/RELEASE_NOTES 1970-01-01 01:00:00.000000000 +0100
6774 +++ linux.dev/fs/mini_fo/RELEASE_NOTES 2005-10-15 12:49:43.000000000 +0200
6776 +Release: mini_fo-0.6.1 (v0-6-1)
6784 +- bugfixes (see ChangeLog)
6786 +- two helper scripts "mini_fo_merge" and "mini_fo_overlay" (see
6787 + README for details).
6791 +- Support for 2.4 and 2.6 (see Makefile)
6793 +- Partial hard link support (creating works as expected, but already
6794 + existing links in the base file system will be treated as if they
6795 + were individual files).
6797 +- Various bugfixes and cleanups.
6802 +- This is mini_fo-0-6-0-pre1! This release is a complete rewrite of
6803 + many vital mini_fo parts such as the old whiteout list code which
6804 + has been replaced by the new META subsystem.
6806 +- Light weight directory renaming implemented. This means if a
6807 + directory is renamed via the mini_fo filesystem this will no longer
6808 + result in a complete copy in storage, instead only one empty
6809 + directory will be created. All base filed contained in the original
6810 + directory stay there until modified.
6812 +- Special files (creating, renaming, deleting etc.) now working.
6814 +- Many bugfixes and cleanup, mini_fo is now a lot more stable.
6819 +- Final release of the 0-5-* versions. Next will be a complete rewrite
6820 + of many features. This release contains several bugfixes related to
6821 + directory renaming.
6826 +- Lots of cleanup and several bugfixes related to directory deleting
6828 +- Directory renaming suddenly works, what is most likely due to the
6829 + fact tha that "mv" is smart: if the classic rename doesn't work it
6830 + will assume that source and target file are on different fs and will
6831 + copy the directory and try to remove the source directory. Until
6832 + directory removing wasn't implemented, it would fail to do this and
6834 + So, directory renaming works for now, but it doesn't yet do what you
6835 + would expect from a overlay fs, so use with care.
6840 +- implemented directory deleting
6841 +- made parsing of mount options more stable
6842 +- New format of mount options! (See README)
6843 +- I can't reproduce the unknown panic with 2.4.25 anymore, so I'll
6844 + happily assume it never existed!
6847 +Implemented features:
6848 +---------------------
6850 +- creating hard links (see BUGS on already existing hard links)
6851 +- lightweight directory renaming
6852 +- renaming device files, pipes, sockets, etc.
6853 +- creating, renaming, deleting of special files
6854 +- deleting directorys
6855 +- general directory reading (simple "ls" )
6856 +- creating files in existing directorys
6857 +- creating directorys
6859 +- reading and writing files (involves opening)
6860 +- appending to files (creates copy in storage)
6862 +- llseek works too, what allows editors to work
6863 +- persistency (a deleted file stay deleted over remounts)
6864 +- use of symbolic links
6865 +- creating of device files
6868 +Not (yet) implemented features:
6869 +-------------------------------
6871 +- full hard link support.
6878 +Hard links in the base file system will be treated as individual
6879 +files, not as links to one inode.
6881 +The main problem with hard links isn't allowing to create them, but
6882 +their pure existence. If you modify a base hard link, the changes made
6883 +will only show up on this link, the other link will remain in the
6884 +original state. I hope to fix this someday. Please note that this does
6885 +not effect the special hard links '.' and '..', that are handled
6886 +seperately by the lower fs.
6887 diff -urN linux.old/fs/mini_fo/state.c linux.dev/fs/mini_fo/state.c
6888 --- linux.old/fs/mini_fo/state.c 1970-01-01 01:00:00.000000000 +0100
6889 +++ linux.dev/fs/mini_fo/state.c 2006-10-29 04:32:06.000000000 +0100
6892 + * Copyright (C) 2005 Markus Klotzbuecher <mk@creamnet.de>
6894 + * This program is free software; you can redistribute it and/or
6895 + * modify it under the terms of the GNU General Public License
6896 + * as published by the Free Software Foundation; either version
6897 + * 2 of the License, or (at your option) any later version.
6900 +#ifdef HAVE_CONFIG_H
6901 +# include <config.h>
6902 +#endif /* HAVE_CONFIG_H */
6905 +#include "mini_fo.h"
6908 +/* create the storage file, setup new states */
6909 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
6910 +int create_sto_reg_file(dentry_t *dentry, int mode, struct nameidata *nd)
6912 +int create_sto_reg_file(dentry_t *dentry, int mode)
6917 + dentry_t *hidden_sto_dentry;
6918 + dentry_t *hidden_sto_dir_dentry;
6920 + if(exists_in_storage(dentry)) {
6921 + printk(KERN_CRIT "mini_fo: create_sto_file: wrong type or state.\n");
6925 + err = get_neg_sto_dentry(dentry);
6928 + printk(KERN_CRIT "mini_fo: create_sto_file: ERROR getting neg. sto dentry.\n");
6932 + dir = dentry->d_parent->d_inode;
6933 + hidden_sto_dentry = dtohd2(dentry);
6936 + hidden_sto_dir_dentry = dget(hidden_sto_dentry->d_parent);
6938 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
6939 + mutex_lock(&hidden_sto_dir_dentry->d_inode->i_mutex);
6941 + down(&hidden_sto_dir_dentry->d_inode->i_sem);
6944 + err = PTR_ERR(hidden_sto_dir_dentry);
6945 + if (IS_ERR(hidden_sto_dir_dentry))
6948 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
6949 + err = vfs_create(hidden_sto_dir_dentry->d_inode,
6950 + hidden_sto_dentry,
6953 + err = vfs_create(hidden_sto_dir_dentry->d_inode,
6954 + hidden_sto_dentry,
6958 + printk(KERN_CRIT "mini_fo: create_sto_file: ERROR creating sto file.\n");
6962 + if(!dtohd2(dentry)->d_inode) {
6963 + printk(KERN_CRIT "mini_fo: create_sto_file: ERROR creating sto file [2].\n");
6968 + /* interpose the new inode */
6969 + if(dtost(dentry) == DELETED) {
6970 + dtost(dentry) = DEL_REWRITTEN;
6971 + err = mini_fo_tri_interpose(NULL, hidden_sto_dentry, dentry, dir->i_sb, 0);
6975 + else if(dtost(dentry) == NON_EXISTANT) {
6976 + dtost(dentry) = CREATED;
6977 + err = mini_fo_tri_interpose(dtohd(dentry), hidden_sto_dentry, dentry, dir->i_sb, 0);
6981 + else if(dtost(dentry) == UNMODIFIED) {
6982 + dtost(dentry) = MODIFIED;
6983 + /* interpose on new inode */
6984 + if(itohi2(dentry->d_inode) != NULL) {
6985 + printk(KERN_CRIT "mini_fo: create_sto_file: invalid inode detected.\n");
6989 + itohi2(dentry->d_inode) = igrab(dtohd2(dentry)->d_inode);
6991 + fist_copy_attr_timesizes(dentry->d_parent->d_inode,
6992 + hidden_sto_dir_dentry->d_inode);
6995 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
6996 + mutex_unlock(&hidden_sto_dir_dentry->d_inode->i_mutex);
6998 + up(&hidden_sto_dir_dentry->d_inode->i_sem);
7000 + dput(hidden_sto_dir_dentry);
7005 +/* create the sto dir, setup states */
7006 +int create_sto_dir(dentry_t *dentry, int mode)
7010 + dentry_t *hidden_sto_dentry;
7011 + dentry_t *hidden_sto_dir_dentry;
7013 + /* had to take the "!S_ISDIR(mode))" check out, because it failed */
7014 + if(exists_in_storage(dentry)) {
7015 + printk(KERN_CRIT "mini_fo: create_sto_dir: wrong type or state.\\
7021 + err = get_neg_sto_dentry(dentry);
7027 + dir = dentry->d_parent->d_inode;
7028 + hidden_sto_dentry = dtohd2(dentry);
7030 + /* was: hidden_sto_dir_dentry = lock_parent(hidden_sto_dentry); */
7031 + hidden_sto_dir_dentry = dget(hidden_sto_dentry->d_parent);
7033 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
7034 + mutex_lock(&hidden_sto_dir_dentry->d_inode->i_mutex);
7036 + down(&hidden_sto_dir_dentry->d_inode->i_sem);
7039 + err = PTR_ERR(hidden_sto_dir_dentry);
7040 + if (IS_ERR(hidden_sto_dir_dentry))
7043 + err = vfs_mkdir(hidden_sto_dir_dentry->d_inode,
7044 + hidden_sto_dentry,
7047 + printk(KERN_CRIT "mini_fo: create_sto_dir: ERROR creating sto dir.\n");
7051 + if(!dtohd2(dentry)->d_inode) {
7052 + printk(KERN_CRIT "mini_fo: create_sto_dir: ERROR creating sto dir [2].\n");
7057 + /* interpose the new inode */
7058 + if(dtost(dentry) == DELETED) {
7059 + dtost(dentry) = DEL_REWRITTEN;
7060 + err = mini_fo_tri_interpose(NULL, hidden_sto_dentry, dentry, dir->i_sb, 0);
7064 + else if(dtopd(dentry)->state == NON_EXISTANT) {
7065 + dtopd(dentry)->state = CREATED;
7066 + err = mini_fo_tri_interpose(dtohd(dentry), hidden_sto_dentry, dentry, dir->i_sb, 0);
7070 + else if(dtopd(dentry)->state == UNMODIFIED) {
7071 + dtopd(dentry)->state = MODIFIED;
7072 + /* interpose on new inode */
7073 + if(itohi2(dentry->d_inode) != NULL) {
7074 + printk(KERN_CRIT "mini_fo: create_sto_dir: ERROR, invalid inode detected.\n");
7078 + itohi2(dentry->d_inode) = igrab(dtohd2(dentry)->d_inode);
7081 + fist_copy_attr_timesizes(dir, hidden_sto_dir_dentry->d_inode);
7083 + /* initalize the wol list */
7084 + itopd(dentry->d_inode)->deleted_list_size = -1;
7085 + itopd(dentry->d_inode)->renamed_list_size = -1;
7086 + meta_build_lists(dentry);
7090 + /* was: unlock_dir(hidden_sto_dir_dentry); */
7091 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
7092 + mutex_unlock(&hidden_sto_dir_dentry->d_inode->i_mutex);
7094 + up(&hidden_sto_dir_dentry->d_inode->i_sem);
7096 + dput(hidden_sto_dir_dentry);
7101 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
7102 +int create_sto_nod(dentry_t *dentry, int mode, dev_t dev)
7104 +int create_sto_nod(dentry_t *dentry, int mode, int dev)
7109 + dentry_t *hidden_sto_dentry;
7110 + dentry_t *hidden_sto_dir_dentry;
7112 + if(exists_in_storage(dentry)) {
7116 + err = get_neg_sto_dentry(dentry);
7119 + printk(KERN_CRIT "mini_fo: create_sto_nod: ERROR getting neg. sto dentry.\n");
7123 + dir = dentry->d_parent->d_inode;
7124 + hidden_sto_dentry = dtohd2(dentry);
7127 + hidden_sto_dir_dentry = dget(hidden_sto_dentry->d_parent);
7129 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
7130 + mutex_lock(&hidden_sto_dir_dentry->d_inode->i_mutex);
7132 + down(&hidden_sto_dir_dentry->d_inode->i_sem);
7135 + err = PTR_ERR(hidden_sto_dir_dentry);
7136 + if (IS_ERR(hidden_sto_dir_dentry))
7139 + err = vfs_mknod(hidden_sto_dir_dentry->d_inode, hidden_sto_dentry, mode, dev);
7143 + if(!dtohd2(dentry)->d_inode) {
7144 + printk(KERN_CRIT "mini_fo: create_sto_nod: creating storage inode failed [1].\n");
7145 + err = -EINVAL; /* return something indicating failure */
7149 + /* interpose the new inode */
7150 + if(dtost(dentry) == DELETED) {
7151 + dtost(dentry) = DEL_REWRITTEN;
7152 + err = mini_fo_tri_interpose(NULL, hidden_sto_dentry, dentry, dir->i_sb, 0);
7156 + else if(dtost(dentry) == NON_EXISTANT) {
7157 + dtost(dentry) = CREATED;
7158 + err = mini_fo_tri_interpose(dtohd(dentry), hidden_sto_dentry, dentry, dir->i_sb, 0);
7162 + else if(dtost(dentry) == UNMODIFIED) {
7163 + dtost(dentry) = MODIFIED;
7164 + /* interpose on new inode */
7165 + if(itohi2(dentry->d_inode) != NULL) {
7166 + printk(KERN_CRIT "mini_fo: create_sto_nod: error, invalid inode detected.\n");
7170 + itohi2(dentry->d_inode) = igrab(dtohd2(dentry)->d_inode);
7173 + fist_copy_attr_timesizes(dir, hidden_sto_dir_dentry->d_inode);
7176 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
7177 + mutex_unlock(&hidden_sto_dir_dentry->d_inode->i_mutex);
7179 + up(&hidden_sto_dir_dentry->d_inode->i_sem);
7181 + dput(hidden_sto_dir_dentry);
7187 +/* unimplemented (and possibly not usefull):
7189 + nondir-del_to_del_rew
7190 + nondir-non_exist_to_creat
7195 + dir-del_rew_to_del
7196 + dir-del_to_del_rew
7197 + dir-non_exist_to_creat
7201 +/* bring a file of any type from state UNMODIFIED to MODIFIED */
7202 +int nondir_unmod_to_mod(dentry_t *dentry, int cp_flag)
7205 + struct vfsmount *tgt_mnt;
7206 + struct vfsmount *src_mnt;
7207 + dentry_t *tgt_dentry;
7208 + dentry_t *src_dentry;
7209 + dentry_t *hidden_sto_dentry;
7210 + dentry_t *hidden_sto_dir_dentry;
7212 + check_mini_fo_dentry(dentry);
7214 + if((dtost(dentry) != UNMODIFIED) ||
7215 + S_ISDIR(dentry->d_inode->i_mode)) {
7216 + printk(KERN_CRIT "mini_fo: nondir_unmod_to_mod: \
7217 + wrong type or state.\n");
7221 + err = get_neg_sto_dentry(dentry);
7224 + printk(KERN_CRIT "mini_fo: nondir_unmod_to_mod: \
7225 + ERROR getting neg. sto dentry.\n");
7229 + /* create sto file */
7230 + hidden_sto_dentry = dtohd2(dentry);
7233 + hidden_sto_dir_dentry = dget(hidden_sto_dentry->d_parent);
7235 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
7236 + mutex_lock(&hidden_sto_dir_dentry->d_inode->i_mutex);
7238 + down(&hidden_sto_dir_dentry->d_inode->i_sem);
7241 + err = PTR_ERR(hidden_sto_dir_dentry);
7242 + if (IS_ERR(hidden_sto_dir_dentry))
7245 + /* handle different types of nondirs */
7246 + if(S_ISCHR(dentry->d_inode->i_mode) ||
7247 + S_ISBLK(dentry->d_inode->i_mode)) {
7248 + err = vfs_mknod(hidden_sto_dir_dentry->d_inode,
7249 + hidden_sto_dentry,
7250 + dtohd(dentry)->d_inode->i_mode,
7251 + dtohd(dentry)->d_inode->i_rdev);
7254 + else if(S_ISREG(dentry->d_inode->i_mode)) {
7256 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
7257 + err = vfs_create(hidden_sto_dir_dentry->d_inode,
7258 + hidden_sto_dentry,
7259 + dtohd(dentry)->d_inode->i_mode, NULL);
7261 + err = vfs_create(hidden_sto_dir_dentry->d_inode,
7262 + hidden_sto_dentry,
7263 + dtohd(dentry)->d_inode->i_mode);
7267 + printk(KERN_CRIT "mini_fo: nondir_unmod_to_mod: \
7268 + ERROR creating sto file.\n");
7272 + /* interpose on new inode */
7273 + if(itohi2(dentry->d_inode) != NULL) {
7274 + printk(KERN_CRIT "mini_fo: nondir_unmod_to_mod: \
7275 + ERROR, invalid inode detected.\n");
7280 + itohi2(dentry->d_inode) = igrab(dtohd2(dentry)->d_inode);
7282 + fist_copy_attr_timesizes(dentry->d_parent->d_inode,
7283 + hidden_sto_dir_dentry->d_inode);
7284 + dtost(dentry) = MODIFIED;
7286 + /* copy contents if regular file and cp_flag = 1 */
7287 + if((cp_flag == 1) && S_ISREG(dentry->d_inode->i_mode)) {
7289 + /* unlock first */
7290 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
7291 + mutex_unlock(&hidden_sto_dir_dentry->d_inode->i_mutex);
7293 + up(&hidden_sto_dir_dentry->d_inode->i_sem);
7296 + dput(hidden_sto_dir_dentry);
7298 + tgt_dentry = dtohd2(dentry);
7299 + tgt_mnt = stopd(dentry->d_inode->i_sb)->hidden_mnt2;
7300 + src_dentry = dtohd(dentry);
7301 + src_mnt = stopd(dentry->d_inode->i_sb)->hidden_mnt;
7303 + err = mini_fo_cp_cont(tgt_dentry, tgt_mnt,
7304 + src_dentry, src_mnt);
7306 + printk(KERN_CRIT "mini_fo: nondir_unmod_to_mod: \
7307 + ERROR copying contents.\n");
7313 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
7314 + mutex_unlock(&hidden_sto_dir_dentry->d_inode->i_mutex);
7316 + up(&hidden_sto_dir_dentry->d_inode->i_sem);
7318 + dput(hidden_sto_dir_dentry);
7323 +/* this function is currently identical to nondir_creat_to_del */
7324 +int nondir_del_rew_to_del(dentry_t *dentry)
7326 + return nondir_creat_to_del(dentry);
7329 +int nondir_creat_to_del(dentry_t *dentry)
7333 + inode_t *hidden_sto_dir_inode;
7334 + dentry_t *hidden_sto_dir_dentry;
7335 + dentry_t *hidden_sto_dentry;
7337 + check_mini_fo_dentry(dentry);
7339 + /* for now this function serves for both state DEL_REWRITTEN and
7341 + if(!(dtost(dentry) == CREATED || (dtost(dentry) == DEL_REWRITTEN)) ||
7342 + S_ISDIR(dentry->d_inode->i_mode)) {
7343 + printk(KERN_CRIT "mini_fo: nondir_mod_to_del/del_rew_to_del: \
7344 + wrong type or state.\n");
7349 + hidden_sto_dir_inode = itohi2(dentry->d_parent->d_inode);
7350 + hidden_sto_dentry = dtohd2(dentry);
7352 + /* was: hidden_sto_dir_dentry = lock_parent(hidden_sto_dentry);*/
7353 + hidden_sto_dir_dentry = dget(hidden_sto_dentry->d_parent);
7355 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
7356 + mutex_lock(&hidden_sto_dir_dentry->d_inode->i_mutex);
7358 + down(&hidden_sto_dir_dentry->d_inode->i_sem);
7361 + /* avoid destroying the hidden inode if the file is in use */
7362 + dget(hidden_sto_dentry);
7363 + err = vfs_unlink(hidden_sto_dir_inode, hidden_sto_dentry);
7364 + dput(hidden_sto_dentry);
7366 + d_delete(hidden_sto_dentry);
7368 + /* propagate number of hard-links */
7369 + dentry->d_inode->i_nlink = itohi2(dentry->d_inode)->i_nlink;
7371 + dtost(dentry) = NON_EXISTANT;
7373 + /* was: unlock_dir(hidden_sto_dir_dentry); */
7374 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
7375 + mutex_unlock(&hidden_sto_dir_dentry->d_inode->i_mutex);
7377 + up(&hidden_sto_dir_dentry->d_inode->i_sem);
7379 + dput(hidden_sto_dir_dentry);
7385 +int nondir_mod_to_del(dentry_t *dentry)
7388 + dentry_t *hidden_sto_dentry;
7389 + inode_t *hidden_sto_dir_inode;
7390 + dentry_t *hidden_sto_dir_dentry;
7392 + check_mini_fo_dentry(dentry);
7394 + if(dtost(dentry) != MODIFIED ||
7395 + S_ISDIR(dentry->d_inode->i_mode)) {
7396 + printk(KERN_CRIT "mini_fo: nondir_mod_to_del: \
7397 + wrong type or state.\n");
7402 + hidden_sto_dir_inode = itohi2(dentry->d_parent->d_inode);
7403 + hidden_sto_dentry = dtohd2(dentry);
7405 + /* was hidden_sto_dir_dentry = lock_parent(hidden_sto_dentry); */
7406 + hidden_sto_dir_dentry = dget(hidden_sto_dentry->d_parent);
7408 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
7409 + mutex_lock(&hidden_sto_dir_dentry->d_inode->i_mutex);
7411 + down(&hidden_sto_dir_dentry->d_inode->i_sem);
7414 + /* avoid destroying the hidden inode if the file is in use */
7415 + dget(hidden_sto_dentry);
7416 + err = vfs_unlink(hidden_sto_dir_inode, hidden_sto_dentry);
7417 + dput(hidden_sto_dentry);
7419 + d_delete(hidden_sto_dentry);
7421 + /* propagate number of hard-links */
7422 + dentry->d_inode->i_nlink = itohi2(dentry->d_inode)->i_nlink;
7424 + /* dput base dentry, this will relase the inode and free the
7425 + * dentry, as we will never need it again. */
7426 + dput(dtohd(dentry));
7427 + dtohd(dentry) = NULL;
7428 + dtost(dentry) = DELETED;
7430 + /* add deleted file to META-file */
7431 + meta_add_d_entry(dentry->d_parent,
7432 + dentry->d_name.name,
7433 + dentry->d_name.len);
7435 + /* was: unlock_dir(hidden_sto_dir_dentry); */
7436 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
7437 + mutex_unlock(&hidden_sto_dir_dentry->d_inode->i_mutex);
7439 + up(&hidden_sto_dir_dentry->d_inode->i_sem);
7441 + dput(hidden_sto_dir_dentry);
7447 +int nondir_unmod_to_del(dentry_t *dentry)
7451 + check_mini_fo_dentry(dentry);
7453 + if(dtost(dentry) != UNMODIFIED ||
7454 + S_ISDIR(dentry->d_inode->i_mode)) {
7455 + printk(KERN_CRIT "mini_fo: nondir_unmod_to_del: \
7456 + wrong type or state.\n");
7461 + /* next we have to get a negative dentry for the storage file */
7462 + err = get_neg_sto_dentry(dentry);
7467 + /* add deleted file to META lists */
7468 + err = meta_add_d_entry(dentry->d_parent,
7469 + dentry->d_name.name,
7470 + dentry->d_name.len);
7475 + /* dput base dentry, this will relase the inode and free the
7476 + * dentry, as we will never need it again. */
7477 + dput(dtohd(dentry));
7478 + dtohd(dentry) = NULL;
7479 + dtost(dentry) = DELETED;
7485 +/* bring a dir from state UNMODIFIED to MODIFIED */
7486 +int dir_unmod_to_mod(dentry_t *dentry)
7490 + check_mini_fo_dentry(dentry);
7492 + if(dtost(dentry) != UNMODIFIED ||
7493 + !S_ISDIR(dentry->d_inode->i_mode)) {
7494 + printk(KERN_CRIT "mini_fo: dir_unmod_to_mod: \
7495 + wrong type or state.\n");
7500 + /* this creates our dir incl. sto. structure */
7501 + err = build_sto_structure(dentry->d_parent, dentry);
7503 + printk(KERN_CRIT "mini_fo: dir_unmod_to_mod: \
7504 + build_sto_structure failed.\n");
7511 diff -urN linux.old/fs/mini_fo/super.c linux.dev/fs/mini_fo/super.c
7512 --- linux.old/fs/mini_fo/super.c 1970-01-01 01:00:00.000000000 +0100
7513 +++ linux.dev/fs/mini_fo/super.c 2006-10-29 04:32:06.000000000 +0100
7516 + * Copyright (c) 1997-2003 Erez Zadok
7517 + * Copyright (c) 2001-2003 Stony Brook University
7519 + * For specific licensing information, see the COPYING file distributed with
7520 + * this package, or get one from ftp://ftp.filesystems.org/pub/fist/COPYING.
7522 + * This Copyright notice must be kept intact and distributed with all
7523 + * fistgen sources INCLUDING sources generated by fistgen.
7526 + * Copyright (C) 2004, 2005 Markus Klotzbuecher <mk@creamnet.de>
7528 + * This program is free software; you can redistribute it and/or
7529 + * modify it under the terms of the GNU General Public License
7530 + * as published by the Free Software Foundation; either version
7531 + * 2 of the License, or (at your option) any later version.
7538 +#ifdef HAVE_CONFIG_H
7539 +# include <config.h>
7543 +#include "mini_fo.h"
7547 +mini_fo_read_inode(inode_t *inode)
7549 + static struct address_space_operations mini_fo_empty_aops;
7551 + __itopd(inode) = kmalloc(sizeof(struct mini_fo_inode_info), GFP_KERNEL);
7552 + if (!itopd(inode)) {
7553 + printk("<0>%s:%s:%d: No kernel memory!\n", __FILE__, __FUNCTION__, __LINE__);
7556 + itohi(inode) = NULL;
7557 + itohi2(inode) = NULL;
7559 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
7560 + inode->i_version++;
7562 + inode->i_version = ++event; /* increment inode version */
7564 + inode->i_op = &mini_fo_main_iops;
7565 + inode->i_fop = &mini_fo_main_fops;
7568 + * XXX: To export a file system via NFS, it has to have the
7569 + * FS_REQUIRES_DEV flag, so turn it on. But should we inherit it from
7570 + * the lower file system, or can we allow our file system to be exported
7571 + * even if the lower one cannot be natively exported.
7573 + inode->i_sb->s_type->fs_flags |= FS_REQUIRES_DEV;
7575 + * OK, the above was a hack, which is now turned off because it may
7576 + * cause a panic/oops on some systems. The correct way to export a
7577 + * "nodev" filesystem is via using nfs-utils > 1.0 and the "fsid=" export
7578 + * parameter, which requires 2.4.20 or later.
7581 + /* I don't think ->a_ops is ever allowed to be NULL */
7582 + inode->i_mapping->a_ops = &mini_fo_empty_aops;
7586 +#if defined(FIST_DEBUG) || defined(FIST_FILTER_SCA)
7588 + * No need to call write_inode() on the lower inode, as it
7589 + * will have been marked 'dirty' anyway. But we might need
7590 + * to write some of our own stuff to disk.
7593 +mini_fo_write_inode(inode_t *inode, int sync)
7595 + print_entry_location();
7596 + print_exit_location();
7598 +#endif /* defined(FIST_DEBUG) || defined(FIST_FILTER_SCA) */
7602 +mini_fo_put_inode(inode_t *inode)
7605 + * This is really funky stuff:
7606 + * Basically, if i_count == 1, iput will then decrement it and this inode will be destroyed.
7607 + * It is currently holding a reference to the hidden inode.
7608 + * Therefore, it needs to release that reference by calling iput on the hidden inode.
7609 + * iput() _will_ do it for us (by calling our clear_inode), but _only_ if i_nlink == 0.
7610 + * The problem is, NFS keeps i_nlink == 1 for silly_rename'd files.
7611 + * So we must for our i_nlink to 0 here to trick iput() into calling our clear_inode.
7613 + if (atomic_read(&inode->i_count) == 1)
7614 + inode->i_nlink = 0;
7618 +#if defined(FIST_DEBUG) || defined(FIST_FILTER_SCA)
7620 + * we now define delete_inode, because there are two VFS paths that may
7621 + * destroy an inode: one of them calls clear inode before doing everything
7622 + * else that's needed, and the other is fine. This way we truncate the inode
7623 + * size (and its pages) and then clear our own inode, which will do an iput
7624 + * on our and the lower inode.
7627 +mini_fo_delete_inode(inode_t *inode)
7629 + print_entry_location();
7631 + fist_checkinode(inode, "mini_fo_delete_inode IN");
7632 + inode->i_size = 0; /* every f/s seems to do that */
7633 + clear_inode(inode);
7635 + print_exit_location();
7637 +#endif /* defined(FIST_DEBUG) || defined(FIST_FILTER_SCA) */
7640 +/* final actions when unmounting a file system */
7642 +mini_fo_put_super(super_block_t *sb)
7645 + mntput(stopd(sb)->hidden_mnt);
7646 + mntput(stopd(sb)->hidden_mnt2);
7648 + /* mk: no! dput(stopd(sb)->base_dir_dentry);
7649 + dput(stopd(sb)->storage_dir_dentry); */
7652 + __stopd(sb) = NULL;
7659 + * This is called in do_umount before put_super.
7660 + * The superblock lock is not held yet.
7661 + * We probably do not need to define this or call write_super
7662 + * on the hidden_sb, because sync_supers() will get to hidden_sb
7663 + * sooner or later. But it is also called from file_fsync()...
7666 +mini_fo_write_super(super_block_t *sb)
7670 +#endif /* NOT_NEEDED */
7674 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
7675 +mini_fo_statfs(super_block_t *sb, struct kstatfs *buf)
7677 +mini_fo_statfs(super_block_t *sb, struct statfs *buf)
7681 + super_block_t *hidden_sb;
7683 + hidden_sb = stohs(sb);
7684 + err = vfs_statfs(hidden_sb, buf);
7691 + * XXX: not implemented. This is not allowed yet.
7692 + * Should we call this on the hidden_sb? Probably not.
7695 +mini_fo_remount_fs(super_block_t *sb, int *flags, char *data)
7697 + printk(KERN_CRIT "mini_fo_remount_fs: WARNING, this function is umimplemented.\n");
7703 + * Called by iput() when the inode reference count reached zero
7704 + * and the inode is not hashed anywhere. Used to clear anything
7705 + * that needs to be, before the inode is completely destroyed and put
7706 + * on the inode free list.
7709 +mini_fo_clear_inode(inode_t *inode)
7712 + * Decrement a reference to a hidden_inode, which was incremented
7713 + * by our read_inode when it was created initially.
7716 + /* release the wol_list */
7717 + if(S_ISDIR(inode->i_mode)) {
7718 + __meta_put_lists(inode);
7721 + /* mk: fan out fun */
7723 + iput(itohi(inode));
7725 + iput(itohi2(inode));
7727 + // XXX: why this assertion fails?
7728 + // because it doesn't like us
7729 + // ASSERT((inode->i_state & I_DIRTY) == 0);
7730 + kfree(itopd(inode));
7731 + __itopd(inode) = NULL;
7736 + * Called in do_umount() if the MNT_FORCE flag was used and this
7737 + * function is defined. See comment in linux/fs/super.c:do_umount().
7738 + * Used only in nfs, to kill any pending RPC tasks, so that subsequent
7739 + * code can actually succeed and won't leave tasks that need handling.
7741 + * PS. I wonder if this is somehow useful to undo damage that was
7742 + * left in the kernel after a user level file server (such as amd)
7746 +mini_fo_umount_begin(super_block_t *sb)
7748 + super_block_t *hidden_sb;
7750 + hidden_sb = stohs(sb);
7752 + if (hidden_sb->s_op->umount_begin)
7753 + hidden_sb->s_op->umount_begin(hidden_sb);
7758 +struct super_operations mini_fo_sops =
7760 + read_inode: mini_fo_read_inode,
7761 +#if defined(FIST_DEBUG) || defined(FIST_FILTER_SCA)
7762 + write_inode: mini_fo_write_inode,
7763 +#endif /* defined(FIST_DEBUG) || defined(FIST_FILTER_SCA) */
7764 + put_inode: mini_fo_put_inode,
7765 +#if defined(FIST_DEBUG) || defined(FIST_FILTER_SCA)
7766 + delete_inode: mini_fo_delete_inode,
7767 +#endif /* defined(FIST_DEBUG) || defined(FIST_FILTER_SCA) */
7768 + put_super: mini_fo_put_super,
7769 + statfs: mini_fo_statfs,
7770 + remount_fs: mini_fo_remount_fs,
7771 + clear_inode: mini_fo_clear_inode,
7772 + umount_begin: mini_fo_umount_begin,