mini_fo fixes
[oweals/openwrt.git] / target / linux / generic-2.6 / patches / 209-mini_fo.patch
1 diff -urN linux.old/fs/Kconfig linux.dev/fs/Kconfig
2 --- linux.old/fs/Kconfig        2006-11-17 03:10:00.000000000 +0100
3 +++ linux.dev/fs/Kconfig        2006-11-17 03:12:36.000000000 +0100
4 @@ -356,6 +356,9 @@
5                   - POSIX ACLs
6                   - readpages / writepages (not user visible)
7  
8 +config MINI_FO
9 +       tristate "Mini fanout overlay filesystem"
10 +
11  config MINIX_FS
12         tristate "Minix fs support"
13         help
14 diff -urN linux.old/fs/Makefile linux.dev/fs/Makefile
15 --- linux.old/fs/Makefile       2006-11-17 03:10:00.000000000 +0100
16 +++ linux.dev/fs/Makefile       2006-11-17 03:13:05.000000000 +0100
17 @@ -60,6 +60,7 @@
18  obj-$(CONFIG_RAMFS)            += ramfs/
19  obj-$(CONFIG_HUGETLBFS)                += hugetlbfs/
20  obj-$(CONFIG_CODA_FS)          += coda/
21 +obj-$(CONFIG_MINI_FO)          += mini_fo/
22  obj-$(CONFIG_MINIX_FS)         += minix/
23  obj-$(CONFIG_FAT_FS)           += fat/
24  obj-$(CONFIG_MSDOS_FS)         += msdos/
25 diff -urN linux.old/fs/mini_fo/aux.c linux.dev/fs/mini_fo/aux.c
26 --- linux.old/fs/mini_fo/aux.c  1970-01-01 01:00:00.000000000 +0100
27 +++ linux.dev/fs/mini_fo/aux.c  2006-11-17 03:11:48.000000000 +0100
28 @@ -0,0 +1,580 @@
29 +/*
30 + * Copyright (c) 1997-2003 Erez Zadok
31 + * Copyright (c) 2001-2003 Stony Brook University
32 + *
33 + * For specific licensing information, see the COPYING file distributed with
34 + * this package, or get one from ftp://ftp.filesystems.org/pub/fist/COPYING.
35 + *
36 + * This Copyright notice must be kept intact and distributed with all
37 + * fistgen sources INCLUDING sources generated by fistgen.
38 + */
39 +/*
40 + * Copyright (C) 2004, 2005 Markus Klotzbuecher <mk@creamnet.de>
41 + *
42 + * This program is free software; you can redistribute it and/or
43 + * modify it under the terms of the GNU General Public License
44 + * as published by the Free Software Foundation; either version
45 + * 2 of the License, or (at your option) any later version.
46 + */
47 +/*
48 + *  $Id$
49 + */
50 +
51 +#ifdef HAVE_CONFIG_H
52 +# include <config.h>
53 +#endif
54 +
55 +#include "fist.h"
56 +#include "mini_fo.h"
57 +
58 +/* check if file exists in storage  */
59 +int exists_in_storage(dentry_t *dentry)
60 +{
61 +       check_mini_fo_dentry(dentry);
62 +       if(dtost(dentry) == MODIFIED || dtost(dentry) == CREATED || dtost(dentry) == DEL_REWRITTEN)
63 +               return 1;
64 +       return 0;       
65 +}
66 +
67 +/* check if dentry is in an existing state */
68 +int is_mini_fo_existant(dentry_t *dentry) 
69 +{
70 +       check_mini_fo_dentry(dentry);
71 +
72 +       if(dtost(dentry) == DELETED || dtost(dentry) == NON_EXISTANT)
73 +               return 0;
74 +       else
75 +               return 1;
76 +}
77 +
78 +/* 
79 + * This function will create a negative storage dentry for 
80 + * dentry, what is required for many create like options.
81 + * It will create the storage structure if necessary.
82 + */
83 +int get_neg_sto_dentry(dentry_t *dentry) 
84 +{
85 +       int err = 0;
86 +       unsigned int len;
87 +       const unsigned char *name;
88 +
89 +       if(!dentry ||
90 +          !dtopd(dentry) ||
91 +          !(dtost(dentry) == UNMODIFIED ||
92 +            dtost(dentry) == NON_EXISTANT ||
93 +            dtost(dentry) == DELETED)) {
94 +               printk(KERN_CRIT "mini_fo: get_neg_sto_dentry: invalid dentry passed.\n");
95 +               err = -1;
96 +               goto out;
97 +       }
98 +       /* Have we got a neg. dentry already? */
99 +       if(dtohd2(dentry)) {
100 +               err = 0;
101 +               goto out;
102 +       }
103 +       if(dtost(dentry->d_parent) == UNMODIFIED) {
104 +               /* build sto struct */
105 +               err = build_sto_structure(dentry->d_parent->d_parent, dentry->d_parent);
106 +               if(err || 
107 +                  dtost(dentry->d_parent) != MODIFIED) {
108 +                       printk(KERN_CRIT "mini_fo: get_neg_sto_dentry: ERROR building sto structure.\n");
109 +                       err = -1;
110 +                       goto out;
111 +               }               
112 +       }
113 +
114 +       len = dentry->d_name.len;
115 +       name = dentry->d_name.name;
116 +        
117 +       dtohd2(dentry) = 
118 +               lookup_one_len(name, dtohd2(dentry->d_parent), len);
119 +
120 + out:
121 +       return err;
122 +}
123 +
124 +int check_mini_fo_dentry(dentry_t *dentry)
125 +{
126 +       ASSERT(dentry != NULL);
127 +       ASSERT(dtopd(dentry) != NULL);
128 +       ASSERT((dtohd(dentry) != NULL) || (dtohd2(dentry) != NULL));
129 +              
130 +/*     if(dtost(dentry) == MODIFIED) { */
131 +/*             ASSERT(dentry->d_inode != NULL); */
132 +/*             ASSERT(dtohd(dentry) != NULL); */
133 +/*             ASSERT(dtohd(dentry)->d_inode != NULL); */
134 +/*             ASSERT(dtohd2(dentry) != NULL); */
135 +/*             ASSERT(dtohd2(dentry)->d_inode != NULL); */
136 +/*     } */
137 +/*     else if(dtost(dentry) == UNMODIFIED) { */
138 +/*             ASSERT(dentry->d_inode != NULL); */
139 +/*             ASSERT( */
140 +/*     } */
141 +       return 0;              
142 +}
143 +
144 +int check_mini_fo_file(file_t *file)
145 +{
146 +       ASSERT(file != NULL);
147 +       ASSERT(ftopd(file) != NULL);
148 +       ASSERT(file->f_dentry != NULL);
149 +       
150 +       /* violent checking, check depending of state and type 
151 +        *      if(S_ISDIR(file->f_dentry->d_inode->i_mode)) {}
152 +        */
153 +       ASSERT((ftohf(file) != NULL) || (ftohf2(file) != NULL));
154 +       return 0;
155 +}
156 +
157 +int check_mini_fo_inode(inode_t *inode)
158 +{
159 +       ASSERT(inode != NULL);
160 +       ASSERT(itopd(inode) != NULL);
161 +       ASSERT((itohi(inode) != NULL) || (itohi2(inode) != NULL));
162 +       return 0;
163 +}
164 +
165 +/* 
166 + * will walk a base path as provided by get_mini_fo_bpath and return
167 + * the (hopefully ;-) ) positive dentry of the renamed base dir.
168 + *
169 + * This does some work of path_init.
170 + */
171 +dentry_t *bpath_walk(super_block_t *sb, char *bpath) 
172 +{
173 +       int err;
174 +       struct nameidata nd;
175 +
176 +       /* be paranoid */
177 +       if(!bpath || bpath[0] != '/') {
178 +               printk(KERN_CRIT "mini_fo: bpath_walk: Invalid string.\n");
179 +               return NULL;
180 +       }
181 +       if(!sb || !stopd(sb)) {
182 +               printk(KERN_CRIT "mini_fo: bpath_walk: Invalid sb.\n");
183 +               return NULL;
184 +       }
185 +       
186 +       /* setup nd as path_init does */
187 +       nd.last_type = LAST_ROOT; /* if there are only slashes... */
188 +       nd.flags = LOOKUP_FOLLOW;
189 +       /* fix this: how do I reach this lock? 
190 +        * read_lock(&current->fs->lock); */
191 +       nd.mnt = mntget(stopd(sb)->hidden_mnt);
192 +       nd.dentry = dget(stopd(sb)->base_dir_dentry);
193 +       /* read_unlock(&current->fs->lock); */
194 +       
195 +       err = path_walk(bpath+1, &nd);
196 +
197 +       /* validate */
198 +       if (err || !nd.dentry || !nd.dentry->d_inode) {
199 +               printk(KERN_CRIT "mini_fo: bpath_walk: path_walk failed.\n");
200 +               return NULL;
201 +       }
202 +       return nd.dentry;
203 +}
204 +
205 +
206 +/* returns the full path of the basefile incl. its name */
207 +int get_mini_fo_bpath(dentry_t *dentry, char **bpath, int *bpath_len)
208 +{
209 +       char *buf_walker;
210 +       int len = 0;
211 +       dentry_t *sky_walker;
212 +       
213 +       if(!dentry || !dtohd(dentry)) {
214 +               printk(KERN_CRIT "mini_fo: get_mini_fo_bpath: invalid dentry passed.\n");
215 +               return -1;
216 +       }
217 +       sky_walker = dtohd(dentry);
218 +
219 +       do {
220 +               len += sky_walker->d_name.len + 1 ; /* 1 for '/' */
221 +               sky_walker = sky_walker->d_parent;
222 +       } while(sky_walker != stopd(dentry->d_inode->i_sb)->base_dir_dentry);
223 +
224 +       /* 1 to oil the loop */
225 +       *bpath = (char*)  kmalloc(len + 1, GFP_KERNEL);
226 +       if(!*bpath) {
227 +               printk(KERN_CRIT "mini_fo: get_mini_fo_bpath: out of mem.\n");
228 +               return -1;
229 +       }
230 +       buf_walker = *bpath+len; /* put it on last char */
231 +       *buf_walker = '\n';
232 +       sky_walker = dtohd(dentry);
233 +       
234 +       do {
235 +               buf_walker -= sky_walker->d_name.len;
236 +               strncpy(buf_walker, 
237 +                       sky_walker->d_name.name, 
238 +                       sky_walker->d_name.len);
239 +               *(--buf_walker) = '/';
240 +               sky_walker = sky_walker->d_parent;
241 +       } while(sky_walker != stopd(dentry->d_inode->i_sb)->base_dir_dentry);
242 +
243 +       /* bpath_len doesn't count newline! */
244 +       *bpath_len = len;
245 +       return 0;
246 +}
247 +
248 +int mini_fo_cp_cont(dentry_t *tgt_dentry, struct vfsmount *tgt_mnt,
249 +                   dentry_t *src_dentry, struct vfsmount *src_mnt)
250 +{
251 +       void *buf;
252 +       mm_segment_t old_fs;
253 +       file_t *tgt_file;
254 +       file_t *src_file;
255 +       int bytes, len, tmp, err;
256 +       err = 0;
257 +
258 +       if(!(tgt_dentry->d_inode && src_dentry->d_inode)) {
259 +               printk(KERN_CRIT "mini_fo_cp_cont: ERROR, neg. dentry passed.\n");
260 +               err = -EINVAL;
261 +               goto out;
262 +       }
263 +
264 +       dget(tgt_dentry);
265 +       dget(src_dentry);
266 +       mntget(tgt_mnt);
267 +       mntget(src_mnt);
268 +
269 +       /* open file write only */
270 +       tgt_file = dentry_open(tgt_dentry, tgt_mnt, 0x1);
271 +       if(!tgt_file || IS_ERR(tgt_file)) {
272 +               printk(KERN_CRIT "mini_fo_cp_cont: ERROR opening target file.\n");
273 +               err = PTR_ERR(tgt_file);
274 +               goto out_err;
275 +       }
276 +
277 +       /* open file read only */
278 +       src_file = dentry_open(src_dentry, src_mnt, 0x0);
279 +       if(!src_file || IS_ERR(src_file)) {
280 +               printk(KERN_CRIT "mini_fo_cp_cont: ERROR opening source file.\n");
281 +               err = PTR_ERR(src_file);
282 +
283 +               /* close target file */
284 +               fput(tgt_file);
285 +               goto out_err;
286 +       }
287 +
288 +       /* check if the filesystem(s) support read respective write */
289 +       if(!src_file->f_op->read || !tgt_file->f_op->write) {
290 +               printk(KERN_CRIT "mini_fo_cp_cont: ERROR, no fs read or write support.\n");
291 +               err = -EPERM;
292 +               goto out_close;
293 +       }
294 +
295 +       /* allocate a page for transfering the data */
296 +       buf = (void *) __get_free_page(GFP_KERNEL);
297 +       if(!buf) {
298 +               printk(KERN_CRIT "mini_fo_cp_cont: ERROR, out of kernel mem.\n");
299 +               goto out_err;
300 +       }
301 +
302 +       tgt_file->f_pos = 0;
303 +       src_file->f_pos = 0;
304 +
305 +       old_fs = get_fs();
306 +       set_fs(KERNEL_DS);
307 +
308 +       /* Doing this I assume that a read operation will return a full
309 +        * buffer while there is still data to read, and a less than
310 +        * full buffer when all data has been read.
311 +        */
312 +       bytes = len = PAGE_SIZE;
313 +       while(bytes == len) {
314 +               bytes = src_file->f_op->read(src_file, buf, len, 
315 +                                            &src_file->f_pos);
316 +               tmp = tgt_file->f_op->write(tgt_file, buf, bytes, 
317 +                                           &tgt_file->f_pos);
318 +               if(tmp != bytes) {
319 +                       printk(KERN_CRIT "mini_fo_cp_cont: ERROR writing.\n");
320 +                       goto out_close_unset;
321 +               }
322 +       }
323 +
324 +       free_page((unsigned long) buf);
325 +       set_fs(old_fs);
326 +       fput(tgt_file);
327 +       fput(src_file);
328 +       goto out;
329 +
330 + out_close_unset:
331 +       free_page((unsigned long) buf);
332 +       set_fs(old_fs);
333 +
334 + out_close:
335 +       fput(tgt_file);
336 +       fput(src_file);
337 +
338 + out_err:
339 +       dput(tgt_dentry);
340 +       dput(src_dentry);
341 +
342 +       /* mk: not sure if this need to be done */
343 +       mntput(tgt_mnt);
344 +       mntput(src_mnt);
345 +
346 + out:
347 +       return err;
348 +}
349 +
350 +/* mk:
351 + * ndl (no-duplicate list) stuff
352 + * This is used in mini_fo_readdir, to save the storage directory contents
353 + * and later when reading base, match them against the list in order
354 + * to avoid duplicates.
355 + */
356 +
357 +/* add a file specified by name and len to the ndl
358 + * Return values: 0 on success, <0 on failure.
359 + */
360 +int ndl_add_entry(struct readdir_data *rd, const char *name, int len)
361 +{
362 +       struct ndl_entry *tmp_entry;
363 +
364 +       tmp_entry = (struct ndl_entry *) 
365 +               kmalloc(sizeof(struct ndl_entry), GFP_KERNEL);
366 +       if(!tmp_entry) {
367 +                printk(KERN_CRIT "mini_fo: ndl_add_entry: out of mem.\n");
368 +                return -ENOMEM;
369 +        }
370 +        tmp_entry->name = (char*) kmalloc(len, GFP_KERNEL);
371 +        if(!tmp_entry->name) {
372 +                printk(KERN_CRIT "mini_fo: ndl_add_entry: out of mem.\n");
373 +                return -ENOMEM;
374 +        }
375 +       strncpy(tmp_entry->name, name, len);
376 +        tmp_entry->len = len;
377 +
378 +        list_add(&tmp_entry->list, &rd->ndl_list);
379 +        rd->ndl_size++;
380 +        return 0;
381 +}
382 +
383 +/* delete all list entries and free memory */
384 +void ndl_put_list(struct readdir_data *rd)
385 +{
386 +       struct list_head *tmp;
387 +       struct ndl_entry *tmp_entry;
388 +
389 +       if(rd->ndl_size <= 0)
390 +               return;
391 +       while(!list_empty(&rd->ndl_list)) {
392 +               tmp = rd->ndl_list.next;
393 +                list_del(tmp);
394 +                tmp_entry = list_entry(tmp, struct ndl_entry, list);
395 +               kfree(tmp_entry->name);
396 +                kfree(tmp_entry);
397 +        }
398 +       rd->ndl_size = 0;
399 +}
400 +
401 +/* Check if a file specified by name and len is in the ndl
402 + * Return value: 0 if not in list, 1 if file is found in ndl.
403 + */
404 +int ndl_check_entry(struct readdir_data *rd, const char *name, int len)
405 +{
406 +       struct list_head *tmp;
407 +       struct ndl_entry *tmp_entry;
408 +
409 +       if(rd->ndl_size <= 0)
410 +               return 0;
411 +
412 +       list_for_each(tmp, &rd->ndl_list) {
413 +                tmp_entry = list_entry(tmp, struct ndl_entry, list);
414 +                if(tmp_entry->len != len)
415 +                        continue;
416 +                if(!strncmp(tmp_entry->name, name, len))
417 +                        return 1;
418 +        }
419 +        return 0;
420 +}
421 +
422 +/* mk:
423 + * Recursive function to create corresponding directorys in the storage fs.
424 + * The function will build the storage directorys up to dentry.
425 + */
426 +int build_sto_structure(dentry_t *dir, dentry_t *dentry)
427 +{
428 +       int err;
429 +       dentry_t *hidden_sto_dentry;
430 +       dentry_t *hidden_sto_dir_dentry;
431 +
432 +       if(dentry->d_parent != dir) {
433 +               printk(KERN_CRIT "mini_fo: build_sto_structure: invalid parameter or meta data corruption [1].\n");
434 +               return 1;
435 +       }
436 +
437 +               if(dtost(dir) != MODIFIED) {
438 +               err = build_sto_structure(dir->d_parent, dentry->d_parent);
439 +               if(err)
440 +                       return err;
441 +       }
442 +
443 +       /* ok, coming back again. */
444 +       check_mini_fo_dentry(dentry);
445 +       hidden_sto_dentry = dtohd2(dentry);
446 +
447 +       if(!hidden_sto_dentry) {
448 +               /*
449 +                * This is the case after creating the first 
450 +                * hidden_sto_dentry.
451 +                * After one negative storage_dentry, all pointers to 
452 +                * hidden_storage dentries are set to NULL. We need to
453 +                * create the negative dentry before we create the storage
454 +                * file.
455 +                */
456 +               unsigned int len;
457 +               const unsigned char *name;
458 +               len = dtohd(dentry)->d_name.len;
459 +               name = dtohd(dentry)->d_name.name;
460 +               hidden_sto_dentry = lookup_one_len(name, dtohd2(dir), len);
461 +               dtohd2(dentry) = hidden_sto_dentry;
462 +       }
463 +
464 +       /* was: hidden_sto_dir_dentry = lock_parent(hidden_sto_dentry); */
465 +       hidden_sto_dir_dentry = dget(hidden_sto_dentry->d_parent);
466 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
467 +       mutex_lock(&hidden_sto_dir_dentry->d_inode->i_mutex);
468 +#else
469 +       down(&hidden_sto_dir_dentry->d_inode->i_sem);
470 +#endif
471 +       /* lets be safe */
472 +       if(dtohd2(dir) != hidden_sto_dir_dentry) {
473 +               printk(KERN_CRIT "mini_fo: build_sto_structure: invalid parameter or meta data corruption [2].\n");
474 +               return 1;
475 +       }
476 +
477 +       /* check for errors in lock_parent */
478 +       err = PTR_ERR(hidden_sto_dir_dentry);
479 +       if(IS_ERR(hidden_sto_dir_dentry)) {
480 +               printk(KERN_CRIT "mini_fo: build_sto_structure: lock_parent failed.\n");
481 +               return err;
482 +       }
483 +
484 +       err = vfs_mkdir(hidden_sto_dir_dentry->d_inode,
485 +                       hidden_sto_dentry,
486 +                       dir->d_inode->i_mode);
487 +
488 +       if(err) {
489 +               printk(KERN_CRIT "mini_fo: build_sto_structure: failed to create storage dir [1].\n");
490 +               /* was: unlock_dir(dir); */
491 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
492 +               mutex_unlock(&dir->d_inode->i_mutex);
493 +#else
494 +               up(&dir->d_inode->i_sem);
495 +#endif
496 +               dput(dir);
497 +               return err;
498 +       }
499 +       
500 +       /* everything ok! */
501 +       if(!dtohd2(dentry)->d_inode) {
502 +               printk(KERN_CRIT "mini_fo: build_sto_structure: failed to create storage dir [2].\n");
503 +               /* was: unlock_dir(dir); */
504 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
505 +               mutex_unlock(&dir->d_inode->i_mutex);
506 +#else
507 +               up(&dir->d_inode->i_sem);
508 +#endif
509 +               dput(dir);
510 +               return 1;
511 +       }
512 +
513 +       /* interpose the new inode and set new state */
514 +       itohi2(dentry->d_inode) = igrab(dtohd2(dentry)->d_inode);
515 +       dtopd(dentry)->state = MODIFIED;
516 +
517 +       /* initalize the wol list */
518 +       itopd(dentry->d_inode)->deleted_list_size = -1;
519 +       itopd(dentry->d_inode)->renamed_list_size = -1;
520 +       meta_build_lists(dentry);
521 +       
522 +       fist_copy_attr_all(dentry->d_inode, itohi2(dentry->d_inode));
523 +       fist_copy_attr_timesizes(dir->d_inode, 
524 +                                hidden_sto_dir_dentry->d_inode);
525 +       dir->d_inode->i_nlink++;
526 +       /* was: unlock_dir(hidden_sto_dir_dentry); */
527 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
528 +       mutex_unlock(&hidden_sto_dir_dentry->d_inode->i_mutex);
529 +#else
530 +       up(&hidden_sto_dir_dentry->d_inode->i_sem);
531 +#endif
532 +       dput(hidden_sto_dir_dentry);
533 +       return 0;
534 +}
535 +
536 +
537 +#if 0 /* unused */
538 +
539 +/*
540 + * Read "len" bytes from "filename" into "buf".
541 + * "buf" is in kernel space.
542 + */
543 +int
544 +mini_fo_read_file(const char *filename, void *buf, int len)
545 +{
546 +    file_t *filp;
547 +    mm_segment_t oldfs;
548 +    int bytes;
549 +    /* Chroot? Maybe NULL isn't right here */
550 +    filp = filp_open(filename, O_RDONLY, 0);
551 +    if (!filp || IS_ERR(filp)) {
552 +       printk("mini_fo_read_file err %d\n", (int) PTR_ERR(filp));
553 +       return -1;  /* or do something else */
554 +    }
555 +
556 +    if (!filp->f_op->read)
557 +       return -2;  /* file(system) doesn't allow reads */
558 +
559 +    /* now read len bytes from offset 0 */
560 +    filp->f_pos = 0;           /* start offset */
561 +    oldfs = get_fs();
562 +    set_fs(KERNEL_DS);
563 +    bytes = filp->f_op->read(filp, buf, len, &filp->f_pos);
564 +    set_fs(oldfs);
565 +
566 +    /* close the file */
567 +    fput(filp);
568 +
569 +    return bytes;
570 +}
571 +
572 +
573 +
574 +/*
575 + * Write "len" bytes from "buf" to "filename"
576 + * "buf" is in kernel space.
577 + */
578 +int
579 +mini_fo_write_file(const char *filename, void *buf, int len)
580 +{
581 +    file_t *filp;
582 +    mm_segment_t oldfs;
583 +    int bytes;
584 +                               /* Chroot? Maybe NULL isn't right here */
585 +    filp = filp_open(filename, O_RDWR|O_CREAT, 0640);
586 +    if (!filp || IS_ERR(filp)) {
587 +       printk("mini_fo_write_file err %d\n", (int) PTR_ERR(filp));
588 +       return -1;  /* or do something else */
589 +    }
590 +
591 +    if (!filp->f_op->write)
592 +       return -2;  /* file(system) doesn't allow writes */
593 +
594 +    /* now write len bytes from offset 0 */
595 +    filp->f_pos = 0;           /* start offset */
596 +    oldfs = get_fs();
597 +    set_fs(KERNEL_DS);
598 +    bytes = filp->f_op->write(filp, buf, len, &filp->f_pos);
599 +    set_fs(oldfs);
600 +
601 +    /* close the file */
602 +    fput(filp);
603 +
604 +    return bytes;
605 +}
606 +
607 +#endif /* unused */
608 +
609 diff -urN linux.old/fs/mini_fo/ChangeLog linux.dev/fs/mini_fo/ChangeLog
610 --- linux.old/fs/mini_fo/ChangeLog      1970-01-01 01:00:00.000000000 +0100
611 +++ linux.dev/fs/mini_fo/ChangeLog      2006-11-17 03:11:48.000000000 +0100
612 @@ -0,0 +1,281 @@
613 +2006-01-24  Markus Klotzbuecher  <mk@mary.denx.de>
614 +
615 +       * Add tons of ugly ifdefs to Ed L. Cashin's mutex patch to
616 +          retain backwards compatibility.
617 +       
618 +2006-01-24  Ed L. Cashin <ecashin@coraid.com>
619 +
620 +       * Support for the new mutex infrastructure
621 +       (7892f2f48d165a34b0b8130c8a195dfd807b8cb6)
622 +
623 +2005-10-15  Markus Klotzbuecher  <mk@localhost.localdomain>
624 +
625 +       * Bugfix for a serious memory leak in mini_fo_follow_link.
626 +
627 +2005-09-21  Markus Klotzbuecher  <mk@mary>
628 +
629 +       * new release 0.6.1
630 +
631 +       * fix of a compiler warning due to changes in 2.6.13
632 +
633 +2005-09-21  Klaus Wenninger  <klaus.wenninger@siemens.com>
634 +
635 +       * file.c: readdir: fix for a bug that caused directory entries
636 +          to show up twice when using storage filesystems such as
637 +          minixfs or pramfs.
638 +
639 +2005-06-30  Eric Lammerts <eric@lammerts.org>
640 +
641 +       * fix for an oops when overwriting a binary thats beeing
642 +          executed.
643 +
644 +2005-06-09    <mk@mary>
645 +
646 +       * Renamed overlay to mini_fo-overlay.
647 +
648 +       * Added mini_fo-merge script to allow merging of storage and base
649 +       after making modifications.
650 +
651 +2005-05-22  root  <mk@mary>
652 +
653 +       * Added overlay script that allows to easily mount mini_fo ontop
654 +       of a given base directory
655 +
656 +2005-05-10    <mk@mary>
657 +
658 +       * inode.c: xattr functions return -EOPNOSUPP instead of
659 +          -ENOSUPP, what confuses "ls -l"
660 +
661 +       * Changed license from LGPL to GPL.
662 +
663 +2005-05-08  root  <mk@mary>
664 +
665 +       * Makefile: clean it up and added make install and make
666 +          uninstall.
667 +       
668 +2005-05-06    <mk@mary>
669 +
670 +       * merged devel branch back to main. [v0-6-0-pre3]
671 +
672 +       * removed unused files print.c and fist_ioctl. [devel-0-0-18]
673 +
674 +       * ioctl: removed fist_ioctl stuff, that is not needed for
675 +          now.
676 +
677 +2005-05-03    <mk@mary>
678 +
679 +       * file.c: simplified mini_fo_open and mini_fo_setattr using
680 +          new state changing functions. [devel-0-0-17]
681 +
682 +       * inode.c: Fixed getattr state bug (see below) in 2.4 function
683 +          mini_fo_inode revalidate.
684 +
685 +       * inode.c: found an other bug in mini_fo_getattr. States are not
686 +         reliable in this function, as a file can be opened, unlinked and
687 +         the getattr function called. This results in a deleted dentry
688 +         with an inode. Fix is to ignore states and simply use the inode
689 +         available.
690 +
691 +2005-04-29    <mk@mary>
692 +
693 +       * file.c: Bugfix and cleanup in fasync and fsync. [devel-0-0-16]
694 +
695 +       * file.c: do not use mini_fo_lock so the generic version is
696 +          used (I guess).
697 +
698 +       * inode.c: getattr, never call getattr on lower files, as this
699 +          will cause the inum to change.
700 +
701 +       * inode.c: rename_reg_file renamed to rename_nondir, as it
702 +          doesn't matter as long it't not a dir. Removed all
703 +          rename_dev_file etc.           
704 +
705 +       * tagged as devel-0-0-15
706 +
707 +       * inode.c: added support for chosing support for extended
708 +          attrs at compile time by XATTR define in mini_fo.h .
709 +
710 +       * inode.c: fixed mini_fo_getattr to use mini_fo inode and not
711 +          lower again, what avoids inode number changes that confused
712 +          rm again. This is the proper solution.
713 +
714 +2005-04-24    <mk@mary>
715 +
716 +       * all files: updated Copyright notive to 2005. [devel-0-0-14]
717 +
718 +       * inode.c: fixed mini_fo_getattr to not change the inode
719 +          number, even if lower files change.
720 +
721 +       * super.c: fixed a bug that caused deleted base file to show
722 +          up suddenly after some time, or after creating a special
723 +          file. The problem was that after some time or after special
724 +          file creating sync_sb_inodes is called by the vfs, that
725 +          called our mini_fo_put_inode. There was (wrongly) called
726 +          __meta_put_lists, that nuked the lists, although the inode
727 +          was going to continue its life. Moving __meta_put_lists to
728 +          mini_fo_clear_inode, where an inode is really destroyed,
729 +          solved the problem.
730 +
731 +
732 +2005-04-23    <mk@mary>
733 +
734 +       * state.c, aux.c: more cleaning up and
735 +          simplifications. [devel-0-0-13] 
736 +
737 +       * inode.c: implemented mini_fo_getattr, that was required for
738 +          2.6 because inode_revalidate has been remove there, and the
739 +         old "du" bug returned.
740 +
741 +
742 +2005-04-20    <mk@mary>
743 +
744 +       * aux.c: get_neg_sto_dentry(): allow to be called for dentries
745 +          in state UNMODIFIED, NON_EXISTANT _and_ DELETED.
746 +
747 +2005-04-19    <mk@mary>
748 +
749 +       * Fixed a bug under 2.6 that caused files deleted via mini_fo
750 +          not to be deleted properly and therefore the fs filled up
751 +          untill no memory was left. [devel-0-0-12]
752 +
753 +       * Added basic hard link support. This means that creating
754 +          hardlinks will work, but existing ones will be treated as
755 +          individual files. [devel-0-0-11]
756 +
757 +2005-04-17    <mk@mary>
758 +
759 +       * Bugfixes
760 +
761 +2005-04-13  root  <mk@mary>
762 +
763 +       * Added file state.c for the state transition
764 +          functions. Doesn't work very well yet, though...
765 +
766 +2005-04-12    <mk@mary>
767 +
768 +       * Porting to 2.6 started, which is easier than expected, also
769 +          due to Olivier previous work.
770 +
771 +2005-04-08    <mk@mary>
772 +
773 +       * Fixed the bug that caused du to return invalid sizes of
774 +          directory trees. The problem was that
775 +          mini_fo_inode_revalidate didn't always copy the attributes
776 +          from the base inode properly.
777 +
778 +2005-04-01  Markus Klotzbuecher  <mk@chasey>
779 +
780 +       * Merged devel branch back to main trunk and updated the
781 +          RELEASE notes. This will be 0-6-0-pre1.
782 +
783 +2005-03-31  Markus Klotzbuecher  <mk@chasey>
784 +
785 +       * Fixed some bugs in rename_reg_file, that only showed up in
786 +          the kernel compile test. Kernel compiles cleanly ontop of
787 +          mini_fo, now also make mrproper etc. work. Seems pretty stable.
788 +
789 +2005-03-28  Markus Klotzbuecher  <mk@chasey>
790 +
791 +       * Many, many directory renaming bugfixes and a lot of other
792 +          cleanup. Dir renaming seems to work relatively stable.
793 +
794 +2005-03-22  Markus Klotzbuecher  <mk@chasey>
795 +
796 +       * Finished implementing lightweight directory renaming. Some
797 +          basic testing indicates it works fine.
798 +         Next is to implement testcases for the testsuite and confirm
799 +          everything is really working ok.
800 +
801 +2005-03-18  Markus Klotzbuecher  <mk@chasey>
802 +
803 +       * Finished implementing meta.c stuff required for directory
804 +          renaming.
805 +
806 +2005-03-17  Markus Klotzbuecher  <mk@chasey>
807 +
808 +       * Fixed all compile warnings + an extremly old bug that
809 +          somehow crept in while reworking the wol stuff to the META
810 +          system. Turning on -Werror again... :-)
811 +
812 +       * Fixed some bugs in the new rename_reg_file function.
813 +
814 +       * Rewrote mini_fo rename and split it into several
815 +          subfunctions, that handle the different types
816 +          seperately. Rewrote the regular file function aswell, as it
817 +          was implemented somewhat inefficient. 
818 +
819 +2005-03-16  Markus Klotzbuecher  <mk@chasey>
820 +
821 +       * Implemented new META subsystem, removed old WOL stuff in favor 
822 +         if it.
823 +
824 +       * After some basic testing everything seems ok...
825 +
826 +2005-03-11  Markus Klotzbuecher  <mk@chasey>
827 +
828 +       * Renaming a non regular file caused trouble because I always
829 +         tried to copy the contents. Now I only do this for regular
830 +         files. mini_fo_rename still isn't implemented properly, renaming
831 +         of device files, symlinks etc. results in a empty regular file
832 +         instead of the proper type.
833 +       
834 +       * Directory renaming suddenly works! What a surprise! I guess
835 +          this is because renaming is implemented as making a copy and
836 +          removing the original. Still this might not work
837 +          everywhere...
838 +
839 +2005-03-09  Markus Klotzbuecher  <mk@chasey>
840 +
841 +       * Bugfix, when a mini_fo directory that exists in storage
842 +         (state: MODIFIED, CREATED and DEL_REWRITTEN) is deleted, a
843 +         possibly existing WOL file contained in it needs to be
844 +         deleted too.
845 +
846 +       * Starting cleanup: defined state names in order to get rid of
847 +          the state numbers.
848 +
849 +2005-03-08  Markus Klotzbuecher  <mk@chasey>
850 +       
851 +       * Makefile fix, fist_ioctl was built against wrong sources if ARCH=um
852 +
853 +       * Fixed a bug in dentry.c, mini_fo_d_hash. In state 4 =
854 +          DEL_REWRITTEN the hash was calculated from the base dentry,
855 +          which was wrong and and caused assertions in
856 +          __mini_fo_hidden_dentry to fail.
857 +
858 +2005-02-21    <mk@mary>
859 +
860 +       * Implemented directory deleting (inode.c)
861 +
862 +       * main.c: made mini_fo_parse_options a little more robust.
863 +
864 +2004-12-22    <mk@mary>
865 +
866 +       * Makefile cleanup and uml stuff, removed unneccessary files
867 +
868 +       * Created a new and hopefully more informative README
869 +
870 +       * CHANGELOG: created a new CHANGELOG and added old entries reversely
871 +
872 +
873 +2004-10-24 Gleb Natapov <gleb@nbase.co.il>
874 +
875 +       * Fix: owner and group where not correctly copied from base to
876 +          storage. 
877 +
878 +
879 +2004-10-05 Gleb Natapov <gleb@nbase.co.il>
880 +
881 +       * Implementation of fsync, fasync and lock mini_fo functions.
882 +       
883 +
884 +2004-09-29 Bob Lee <bob@pantasys.com>
885 +
886 +       * Fix of a serious pointer bug
887 +       
888 +
889 +2004-09-28 Gleb Natapov <gleb@nbase.co.il>
890 +
891 +       * Implementation of mini_fo_mknod and mini_fo_rename, support
892 +          for device files.
893 +       
894 diff -urN linux.old/fs/mini_fo/dentry.c linux.dev/fs/mini_fo/dentry.c
895 --- linux.old/fs/mini_fo/dentry.c       1970-01-01 01:00:00.000000000 +0100
896 +++ linux.dev/fs/mini_fo/dentry.c       2006-11-17 03:11:48.000000000 +0100
897 @@ -0,0 +1,244 @@
898 +/*
899 + * Copyright (c) 1997-2003 Erez Zadok
900 + * Copyright (c) 2001-2003 Stony Brook University
901 + *
902 + * For specific licensing information, see the COPYING file distributed with
903 + * this package, or get one from ftp://ftp.filesystems.org/pub/fist/COPYING.
904 + *
905 + * This Copyright notice must be kept intact and distributed with all
906 + * fistgen sources INCLUDING sources generated by fistgen.
907 + */
908 +/*
909 + * Copyright (C) 2004, 2005 Markus Klotzbuecher <mk@creamnet.de>
910 + *
911 + * This program is free software; you can redistribute it and/or
912 + * modify it under the terms of the GNU General Public License
913 + * as published by the Free Software Foundation; either version
914 + * 2 of the License, or (at your option) any later version.
915 + */
916 +
917 +/*
918 + *  $Id$
919 + */
920 +
921 +#ifdef HAVE_CONFIG_H
922 +# include <config.h>
923 +#endif
924 +
925 +#include "fist.h"
926 +#include "mini_fo.h"
927 +
928 +/*
929 + * THIS IS A BOOLEAN FUNCTION: returns 1 if valid, 0 otherwise.
930 + */
931 +STATIC int
932 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
933 +mini_fo_d_revalidate(dentry_t *dentry, struct nameidata *nd)
934 +#else
935 +mini_fo_d_revalidate(dentry_t *dentry, int flags)
936 +#endif
937 +{
938 +       int err1 = 1; /* valid = 1, invalid = 0 */
939 +       int err2 = 1;
940 +       dentry_t *hidden_dentry;
941 +       dentry_t *hidden_sto_dentry;
942 +
943 +
944 +       check_mini_fo_dentry(dentry);
945 +
946 +       hidden_dentry  = dtohd(dentry);
947 +       hidden_sto_dentry = dtohd2(dentry);
948 +
949 +       if(hidden_dentry &&
950 +          hidden_dentry->d_op &&
951 +          hidden_dentry->d_op->d_revalidate) {
952 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
953 +               err1 = hidden_dentry->d_op->d_revalidate(hidden_dentry, nd);
954 +#else
955 +               err1 = hidden_dentry->d_op->d_revalidate(hidden_dentry, flags);
956 +#endif
957 +       }
958 +       if(hidden_sto_dentry &&
959 +          hidden_sto_dentry->d_op &&
960 +          hidden_sto_dentry->d_op->d_revalidate) {
961 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
962 +               err2 = hidden_sto_dentry->d_op->d_revalidate(hidden_sto_dentry, 
963 +                                                            nd);
964 +#else
965 +               err2 = hidden_sto_dentry->d_op->d_revalidate(hidden_sto_dentry, 
966 +                                                            flags);
967 +#endif
968 +       }
969 +
970 +       /* mk: if one of the lower level dentries are valid,
971 +        * the mini_fo dentry is too.
972 +        */
973 +       return (err1 || err2);
974 +}
975 +
976 +
977 +STATIC int
978 +mini_fo_d_hash(dentry_t *dentry, qstr_t *name)
979 +{
980 +       int err = 0;
981 +       dentry_t *hidden_dentry;
982 +       dentry_t *hidden_sto_dentry;
983 +
984 +       /* hidden_dentry = mini_fo_hidden_dentry(dentry);
985 +        * hidden_sto_dentry = mini_fo_hidden_sto_dentry(dentry); */
986 +
987 +       /* state 1, 3, 4, 5: build the hash for the storage dentry */
988 +       if((dtopd(dentry)->state == MODIFIED) ||
989 +          (dtopd(dentry)->state == CREATED) ||
990 +          (dtopd(dentry)->state == DEL_REWRITTEN) ||
991 +          (dtopd(dentry)->state == DELETED)) {
992 +               hidden_sto_dentry = dtohd2(dentry);
993 +               if(hidden_sto_dentry &&
994 +                  hidden_sto_dentry->d_op &&
995 +                  hidden_sto_dentry->d_op->d_hash) {
996 +                       err = hidden_sto_dentry->d_op->d_hash(hidden_sto_dentry, name);
997 +               }
998 +               goto out;
999 +       }
1000 +       /* state 2: build the hash for the base dentry */
1001 +       if(dtopd(dentry)->state == UNMODIFIED) {
1002 +               hidden_dentry = dtohd(dentry);
1003 +               if(hidden_dentry &&
1004 +                  hidden_dentry->d_op &&
1005 +                  hidden_dentry->d_op->d_hash) {
1006 +                       err = hidden_dentry->d_op->d_hash(hidden_dentry, name);
1007 +               }
1008 +               goto out;
1009 +       }
1010 +       /* state 6: build hash for the dentry that exists */
1011 +       if(dtopd(dentry)->state == NON_EXISTANT) {
1012 +               hidden_sto_dentry = dtohd2(dentry);
1013 +               if(hidden_sto_dentry &&
1014 +                  hidden_sto_dentry->d_op &&
1015 +                  hidden_sto_dentry->d_op->d_hash) {
1016 +                       err = hidden_sto_dentry->d_op->d_hash(hidden_sto_dentry, name);
1017 +                       goto out;
1018 +               }
1019 +               hidden_dentry = dtohd(dentry);
1020 +               if(hidden_dentry &&
1021 +                  hidden_dentry->d_op &&
1022 +                  hidden_dentry->d_op->d_hash) {
1023 +                       err = hidden_dentry->d_op->d_hash(hidden_dentry, name);
1024 +                       goto out;
1025 +               }
1026 +       }
1027 +
1028 +       printk(KERN_CRIT "mini_fo: d_hash: invalid state detected.\n");
1029 +
1030 + out:
1031 +       return err;
1032 +}
1033 +
1034 +
1035 +STATIC int
1036 +mini_fo_d_compare(dentry_t *dentry, qstr_t *a, qstr_t *b)
1037 +{
1038 +       int err;
1039 +       dentry_t *hidden_dentry=NULL;
1040 +
1041 +       /* hidden_dentry = mini_fo_hidden_dentry(dentry); */
1042 +       if(dtohd2(dentry))
1043 +               hidden_dentry = dtohd2(dentry);
1044 +       else if(dtohd(dentry))
1045 +               hidden_dentry = dtohd(dentry);
1046 +
1047 +       if (hidden_dentry && hidden_dentry->d_op && hidden_dentry->d_op->d_compare) {
1048 +               err = hidden_dentry->d_op->d_compare(hidden_dentry, a, b);
1049 +       } else {
1050 +               err = ((a->len != b->len) || memcmp(a->name, b->name, b->len));
1051 +       }
1052 +
1053 +       return err;
1054 +}
1055 +
1056 +
1057 +int
1058 +mini_fo_d_delete(dentry_t *dentry)
1059 +{
1060 +       dentry_t *hidden_dentry;
1061 +       dentry_t *hidden_sto_dentry;
1062 +       int err = 0;
1063 +
1064 +       /* this could be a negative dentry, so check first */
1065 +       if (!dtopd(dentry)) {
1066 +               printk(KERN_CRIT "mini_fo_d_delete: negative dentry passed.\n");
1067 +               goto out;
1068 +       }
1069 +       hidden_dentry = dtohd(dentry);
1070 +       hidden_sto_dentry = dtohd2(dentry);
1071 +
1072 +       if(hidden_dentry) {
1073 +               if(hidden_dentry->d_op &&
1074 +                  hidden_dentry->d_op->d_delete) {
1075 +                       err = hidden_dentry->d_op->d_delete(hidden_dentry);
1076 +               }
1077 +       }
1078 +       if(hidden_sto_dentry) {
1079 +               if(hidden_sto_dentry->d_op &&
1080 +                  hidden_sto_dentry->d_op->d_delete) {
1081 +                       err = hidden_sto_dentry->d_op->d_delete(hidden_sto_dentry);
1082 +               }
1083 +       }
1084 +
1085 + out:
1086 +       return err;
1087 +}
1088 +
1089 +
1090 +void
1091 +mini_fo_d_release(dentry_t *dentry)
1092 +{
1093 +       dentry_t *hidden_dentry;
1094 +       dentry_t *hidden_sto_dentry;
1095 +
1096 +
1097 +       /* this could be a negative dentry, so check first */
1098 +       if (!dtopd(dentry)) {
1099 +               printk(KERN_CRIT "mini_fo_d_release: no private data.\n");
1100 +               goto out;
1101 +       }
1102 +       hidden_dentry = dtohd(dentry);
1103 +       hidden_sto_dentry = dtohd2(dentry);
1104 +
1105 +       if(hidden_dentry) {
1106 +               /* decrement hidden dentry's counter and free its inode */
1107 +               dput(hidden_dentry);
1108 +       }
1109 +       if(hidden_sto_dentry) {
1110 +                /* decrement hidden dentry's counter and free its inode */
1111 +               dput(hidden_sto_dentry);
1112 +       }
1113 +
1114 +       /* free private data (mini_fo_dentry_info) here */
1115 +       kfree(dtopd(dentry));
1116 +       __dtopd(dentry) = NULL; /* just to be safe */
1117 + out:
1118 +       return;
1119 +}
1120 +
1121 +
1122 +/*
1123 + * we don't really need mini_fo_d_iput, because dentry_iput will call iput() if
1124 + * mini_fo_d_iput is not defined. We left this implemented for ease of
1125 + * tracing/debugging.
1126 + */
1127 +void
1128 +mini_fo_d_iput(dentry_t *dentry, inode_t *inode)
1129 +{
1130 +       iput(inode);
1131 +}
1132 +
1133 +
1134 +struct dentry_operations mini_fo_dops = {
1135 +       d_revalidate:   mini_fo_d_revalidate,
1136 +       d_hash:         mini_fo_d_hash,
1137 +       d_compare:              mini_fo_d_compare,
1138 +       d_release:              mini_fo_d_release,
1139 +       d_delete:               mini_fo_d_delete,
1140 +       d_iput:         mini_fo_d_iput,
1141 +};
1142 diff -urN linux.old/fs/mini_fo/file.c linux.dev/fs/mini_fo/file.c
1143 --- linux.old/fs/mini_fo/file.c 1970-01-01 01:00:00.000000000 +0100
1144 +++ linux.dev/fs/mini_fo/file.c 2006-11-17 03:11:48.000000000 +0100
1145 @@ -0,0 +1,690 @@
1146 +/*
1147 + * Copyright (c) 1997-2003 Erez Zadok
1148 + * Copyright (c) 2001-2003 Stony Brook University
1149 + *
1150 + * For specific licensing information, see the COPYING file distributed with
1151 + * this package, or get one from ftp://ftp.filesystems.org/pub/fist/COPYING.
1152 + *
1153 + * This Copyright notice must be kept intact and distributed with all
1154 + * fistgen sources INCLUDING sources generated by fistgen.
1155 + */
1156 +/*
1157 + * Copyright (C) 2004, 2005 Markus Klotzbuecher <mk@creamnet.de>
1158 + *
1159 + * This program is free software; you can redistribute it and/or
1160 + * modify it under the terms of the GNU General Public License
1161 + * as published by the Free Software Foundation; either version
1162 + * 2 of the License, or (at your option) any later version.
1163 + */
1164 +
1165 +/*
1166 + *  $Id$
1167 + */
1168 +
1169 +#ifdef HAVE_CONFIG_H
1170 +# include <config.h>
1171 +#endif
1172 +
1173 +#include "fist.h"
1174 +#include "mini_fo.h"
1175 +#define ROUND_UP(x) (((x)+sizeof(long)-1) & ~(sizeof(long)-1))
1176 +
1177 +/*******************
1178 + * File Operations *
1179 + *******************/
1180 +
1181 +STATIC loff_t
1182 +mini_fo_llseek(file_t *file, loff_t offset, int origin)
1183 +{
1184 +       loff_t err;
1185 +       file_t *hidden_file = NULL;
1186 +
1187 +       if(S_ISDIR(file->f_dentry->d_inode->i_mode)) {
1188 +               /* Check if trying to llseek from a directory */
1189 +               err = -EISDIR;
1190 +               goto out;
1191 +       }
1192 +       if (ftopd(file) != NULL) {
1193 +               if(ftohf2(file)) {
1194 +                       hidden_file = ftohf2(file);
1195 +               } else {
1196 +                       hidden_file = ftohf(file);
1197 +               }
1198 +       }
1199 +
1200 +       /* always set hidden position to this one */
1201 +       hidden_file->f_pos = file->f_pos;
1202 +
1203 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
1204 +       memcpy(&(hidden_file->f_ra), 
1205 +              &(file->f_ra), 
1206 +              sizeof(struct file_ra_state));
1207 +#else
1208 +       if (file->f_reada) { /* update readahead information if needed */
1209 +               hidden_file->f_reada = file->f_reada;
1210 +               hidden_file->f_ramax = file->f_ramax;
1211 +               hidden_file->f_raend = file->f_raend;
1212 +               hidden_file->f_ralen = file->f_ralen;
1213 +               hidden_file->f_rawin = file->f_rawin;
1214 +       }
1215 +#endif
1216 +       if (hidden_file->f_op && hidden_file->f_op->llseek)
1217 +               err = hidden_file->f_op->llseek(hidden_file, offset, origin);
1218 +       else
1219 +               err = generic_file_llseek(hidden_file, offset, origin);
1220 +
1221 +       if (err < 0)
1222 +               goto out;
1223 +
1224 +       if (err != file->f_pos) {
1225 +               file->f_pos = err;
1226 +               // ION maybe this?
1227 +               //      file->f_pos = hidden_file->f_pos;
1228 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
1229 +               file->f_reada = 0;
1230 +#endif
1231 +               file->f_version++;
1232 +       }
1233 +
1234 + out:
1235 +       return err;
1236 +}
1237 +
1238 +
1239 +/* mk: fanout capable */
1240 +STATIC ssize_t
1241 +mini_fo_read(file_t *file, char *buf, size_t count, loff_t *ppos)
1242 +{
1243 +       int err = -EINVAL;
1244 +       file_t *hidden_file = NULL;
1245 +       loff_t pos = *ppos;
1246 +
1247 +       if(S_ISDIR(file->f_dentry->d_inode->i_mode)) {
1248 +               /* Check if trying to read from a directory */
1249 +               /* printk(KERN_CRIT "mini_fo_read: ERROR: trying to read data from a directory.\n"); */
1250 +               err = -EISDIR;
1251 +               goto out;
1252 +       }
1253 +
1254 +       if (ftopd(file) != NULL) {
1255 +               if(ftohf2(file)) {
1256 +                       hidden_file = ftohf2(file);
1257 +               } else {
1258 +                       hidden_file = ftohf(file);
1259 +               }
1260 +       }
1261 +
1262 +       if (!hidden_file->f_op || !hidden_file->f_op->read)
1263 +               goto out;
1264 +
1265 +       err = hidden_file->f_op->read(hidden_file, buf, count, &pos);
1266 +       *ppos = pos;
1267 +
1268 +       if (err >= 0) {
1269 +               /* atime should also be updated for reads of size zero or more */
1270 +               fist_copy_attr_atime(file->f_dentry->d_inode,
1271 +                                    hidden_file->f_dentry->d_inode);
1272 +       }
1273 +
1274 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
1275 +       /*
1276 +        * MAJOR HACK
1277 +        * because pread() does not have any way to tell us that it is
1278 +        * our caller, then we don't know for sure if we have to update
1279 +        * the file positions.  This hack relies on read() having passed us
1280 +        * the "real" pointer of its struct file's f_pos field.
1281 +        */
1282 +       if (ppos == &file->f_pos)
1283 +               hidden_file->f_pos = *ppos = pos;
1284 +       if (hidden_file->f_reada) { /* update readahead information if needed */
1285 +               file->f_reada = hidden_file->f_reada;
1286 +               file->f_ramax = hidden_file->f_ramax;
1287 +               file->f_raend = hidden_file->f_raend;
1288 +               file->f_ralen = hidden_file->f_ralen;
1289 +               file->f_rawin = hidden_file->f_rawin;
1290 +       }
1291 +#else
1292 +       memcpy(&(file->f_ra),&(hidden_file->f_ra),sizeof(struct file_ra_state));
1293 +#endif
1294 +
1295 + out:
1296 +       return err;
1297 +}
1298 +
1299 +
1300 +/* this mini_fo_write() does not modify data pages! */
1301 +STATIC ssize_t
1302 +mini_fo_write(file_t *file, const char *buf, size_t count, loff_t *ppos)
1303 +{
1304 +       int err = -EINVAL;
1305 +       file_t *hidden_file = NULL;
1306 +       inode_t *inode;
1307 +       inode_t *hidden_inode;
1308 +       loff_t pos = *ppos;
1309 +
1310 +       /* mk: fan out: */
1311 +       if (ftopd(file) != NULL) {
1312 +               if(ftohf2(file)) {
1313 +                       hidden_file = ftohf2(file);
1314 +               } else {
1315 +                       /* This is bad! We have no storage file to write to. This
1316 +                        * should never happen because if a file is opened for
1317 +                        * writing, a copy should have been made earlier.
1318 +                        */
1319 +                       printk(KERN_CRIT "mini_fo: write : ERROR, no storage file to write.\n");
1320 +                       err = -EINVAL;
1321 +                       goto out;
1322 +               }
1323 +       }
1324 +
1325 +       inode = file->f_dentry->d_inode;
1326 +       hidden_inode = itohi2(inode);
1327 +       if(!hidden_inode) {
1328 +               printk(KERN_CRIT "mini_fo: write: no sto inode found, not good.\n");
1329 +               goto out;
1330 +       }
1331 +
1332 +       if (!hidden_file->f_op || !hidden_file->f_op->write)
1333 +               goto out;
1334 +
1335 +       /* adjust for append -- seek to the end of the file */
1336 +       if (file->f_flags & O_APPEND)
1337 +               pos = inode->i_size;
1338 +
1339 +       err = hidden_file->f_op->write(hidden_file, buf, count, &pos);
1340 +
1341 +       /*
1342 +        * copy ctime and mtime from lower layer attributes
1343 +        * atime is unchanged for both layers
1344 +        */
1345 +       if (err >= 0)
1346 +               fist_copy_attr_times(inode, hidden_inode);
1347 +       
1348 +       *ppos = pos;
1349 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
1350 +       /*
1351 +        * XXX: MAJOR HACK
1352 +        *
1353 +        * because pwrite() does not have any way to tell us that it is
1354 +        * our caller, then we don't know for sure if we have to update
1355 +        * the file positions.  This hack relies on write() having passed us
1356 +        * the "real" pointer of its struct file's f_pos field.
1357 +        */
1358 +       if (ppos == &file->f_pos)
1359 +               hidden_file->f_pos = *ppos = pos;
1360 +#endif
1361 +       /* update this inode's size */
1362 +       if (pos > inode->i_size)
1363 +               inode->i_size = pos;
1364 +
1365 + out:
1366 +       return err;
1367 +}
1368 +
1369 +/* Global variable to hold a file_t pointer.
1370 + * This serves to allow mini_fo_filldir function to know which file is
1371 + * beeing read, which is required for two reasons:
1372 + *
1373 + *   - be able to call wol functions in order to avoid listing deleted
1374 + *     base files.
1375 + *   - if we're reading a directory which is in state 1, we need to
1376 + *     maintain a list (in mini_fo_filldir) of which files allready 
1377 + *     have been copied to userspace,to detect files existing in base
1378 + *     and storage and not list them twice.
1379 + */
1380 +filldir_t mini_fo_filldir_orig;
1381 +file_t *mini_fo_filldir_file;
1382 +
1383 +/* mainly copied from fs/readdir.c */
1384 +STATIC int
1385 +mini_fo_filldir(void * __buf, const char * name, int namlen, loff_t offset,
1386 +                 ino_t ino, unsigned int d_type)
1387 +{
1388 +       struct linux_dirent *dirent, d;
1389 +       struct getdents_callback * buf = (struct getdents_callback *) __buf;
1390 +       int reclen;
1391 +       file_t* file = mini_fo_filldir_file;
1392 +
1393 +       /* In theses states we filter meta files in storage (WOL) */
1394 +       if(file && (dtopd(file->f_dentry)->state == MODIFIED ||
1395 +                   dtopd(file->f_dentry)->state == CREATED ||
1396 +                   dtopd(file->f_dentry)->state == DEL_REWRITTEN)) {
1397 +
1398 +               int tmp = strlen(META_FILENAME);
1399 +               if(tmp  == namlen) {
1400 +                       if(!strncmp(name, META_FILENAME, namlen))
1401 +                               return 0;
1402 +               }
1403 +       }
1404 +
1405 +       /* check if we are merging the contents of storage and base */
1406 +       if(file && dtopd(file->f_dentry)->state == MODIFIED) {
1407 +               /* check if we are still reading storage contents, if
1408 +                * yes, we just save the name of the file for duplicate
1409 +                * checking later. */
1410 +
1411 +               if(!ftopd(file)->rd.sto_done) {
1412 +                       /* put file into ndl list */
1413 +                       if(ndl_add_entry(&ftopd(file)->rd, name, namlen))
1414 +                               printk(KERN_CRIT "mini_fo_filldir: Error adding to ndl.\n");
1415 +               } else {
1416 +                       /* check if file has been deleted */
1417 +                       if(meta_check_d_entry(file->f_dentry, name, namlen))
1418 +                               return 0;
1419 +                       
1420 +                       /* do duplicate checking */
1421 +                       if(ndl_check_entry(&ftopd(file)->rd, name, namlen))
1422 +                               return 0;
1423 +               }
1424 +       }
1425 +
1426 +       return mini_fo_filldir_orig(buf, name, namlen, offset, ino, d_type);
1427 +}
1428 +
1429 +
1430 +STATIC int
1431 +mini_fo_readdir(file_t *file, void *dirent, filldir_t filldir)
1432 +{
1433 +       int err = 0;/* mk: ??? -ENOTDIR; */
1434 +       file_t *hidden_file = NULL;
1435 +       file_t *hidden_sto_file = NULL;
1436 +       inode_t *inode;
1437 +       struct getdents_callback *buf;
1438 +       int oldcount;
1439 +
1440 +#if defined(FIST_FILTER_NAME) || defined(FIST_FILTER_SCA)
1441 +       struct mini_fo_getdents_callback buf;
1442 +#endif /* FIST_FILTER_NAME || FIST_FILTER_SCA */
1443 +
1444 +       buf = (struct getdents_callback *) dirent;
1445 +       oldcount = buf->count;
1446 +       inode = file->f_dentry->d_inode;
1447 +       mini_fo_filldir_file = file;
1448 +       mini_fo_filldir_orig = filldir;
1449 +
1450 +       ftopd(file)->rd.sto_done = 0;
1451 +       do {
1452 +               if (ftopd(file) != NULL) {
1453 +                       if(ftohf2(file)) { 
1454 +                               hidden_sto_file = ftohf2(file);
1455 +                               err = vfs_readdir(hidden_sto_file, mini_fo_filldir, dirent);
1456 +                               file->f_pos = hidden_sto_file->f_pos;
1457 +                               if (err > 0)
1458 +                                       fist_copy_attr_atime(inode, hidden_sto_file->f_dentry->d_inode);
1459 +                               /* not finshed yet, we'll be called again */
1460 +                               if (buf->count != oldcount)
1461 +                                       break;
1462 +                       }
1463 +
1464 +                       ftopd(file)->rd.sto_done = 1;
1465 +
1466 +                       if(ftohf(file)) { 
1467 +                               hidden_file = ftohf(file);
1468 +                               err = vfs_readdir(hidden_file, mini_fo_filldir, dirent);
1469 +                               file->f_pos = hidden_file->f_pos;
1470 +                               if (err > 0)
1471 +                                       fist_copy_attr_atime(inode, hidden_file->f_dentry->d_inode);
1472 +                       }
1473 +
1474 +               }
1475 +       } while (0);
1476 +
1477 +       /* mk:
1478 +        * we need to check if all the directory data has been copied to userspace,
1479 +        * or if we will be called again by userspace to complete the operation.
1480 +        */
1481 +       if(buf->count == oldcount) {
1482 +               ndl_put_list(&ftopd(file)->rd);
1483 +       }
1484 +
1485 +       /* unset this, safe */
1486 +       mini_fo_filldir_file = NULL;
1487 +       return err;
1488 +}
1489 +
1490 +
1491 +STATIC unsigned int
1492 +mini_fo_poll(file_t *file, poll_table *wait)
1493 +{
1494 +       unsigned int mask = DEFAULT_POLLMASK;
1495 +       file_t *hidden_file = NULL;
1496 +
1497 +       if (ftopd(file) != NULL) {
1498 +               if(ftohf2(file)) {
1499 +                       hidden_file = ftohf2(file);
1500 +               } else {
1501 +                       hidden_file = ftohf(file);
1502 +               }
1503 +       }
1504 +
1505 +       if (!hidden_file->f_op || !hidden_file->f_op->poll)
1506 +               goto out;
1507 +
1508 +       mask = hidden_file->f_op->poll(hidden_file, wait);
1509 +
1510 + out:
1511 +       return mask;
1512 +}
1513 +
1514 +/* FIST-LITE special version of mmap */
1515 +STATIC int
1516 +mini_fo_mmap(file_t *file, vm_area_t *vma)
1517 +{
1518 +       int err = 0;
1519 +       file_t *hidden_file = NULL;
1520 +
1521 +       /* fanout capability */
1522 +       if (ftopd(file) != NULL) {
1523 +               if(ftohf2(file)) {
1524 +                       hidden_file = ftohf2(file);
1525 +               } else {
1526 +                       hidden_file = ftohf(file);
1527 +               }
1528 +       }
1529 +
1530 +       ASSERT(hidden_file != NULL);
1531 +       ASSERT(hidden_file->f_op != NULL);
1532 +       ASSERT(hidden_file->f_op->mmap != NULL);
1533 +
1534 +       vma->vm_file = hidden_file;
1535 +       err = hidden_file->f_op->mmap(hidden_file, vma);
1536 +       get_file(hidden_file); /* make sure it doesn't get freed on us */
1537 +       fput(file);            /* no need to keep extra ref on ours */
1538 +
1539 +       return err;
1540 +}
1541 +
1542 +
1543 +
1544 +STATIC int
1545 +mini_fo_open(inode_t *inode, file_t *file)
1546 +{
1547 +       int err = 0;
1548 +       int hidden_flags; 
1549 +       file_t *hidden_file = NULL;
1550 +       dentry_t *hidden_dentry = NULL;
1551 +
1552 +       /* fanout stuff */
1553 +       file_t *hidden_sto_file = NULL;
1554 +       dentry_t *hidden_sto_dentry = NULL;
1555 +
1556 +       __ftopd(file) = 
1557 +               kmalloc(sizeof(struct mini_fo_file_info), GFP_KERNEL);
1558 +       if (!ftopd(file)) {
1559 +               err = -ENOMEM;
1560 +               goto out;
1561 +       }
1562 +
1563 +       /* init the readdir_helper structure */
1564 +       INIT_LIST_HEAD(&ftopd(file)->rd.ndl_list);
1565 +       ftopd(file)->rd.ndl_size = 0;
1566 +
1567 +       /* In certain paths this could stay uninitalized and cause trouble */
1568 +       ftohf(file) = NULL;
1569 +       ftohf2(file) = NULL;
1570 +       hidden_flags = file->f_flags;
1571 +
1572 +       /* create storage files? */
1573 +       if(dtost(file->f_dentry) == UNMODIFIED) {
1574 +               if(!IS_WRITE_FLAG(file->f_flags)) {
1575 +                       hidden_dentry = dtohd(file->f_dentry);
1576 +                       dget(hidden_dentry);
1577 +                       /* dentry_open will decrement mnt refcnt if err.
1578 +                        * otherwise fput() will do an mntput() for us upon file close. */
1579 +                       mntget(stopd(inode->i_sb)->hidden_mnt);
1580 +                       hidden_file = dentry_open(hidden_dentry,
1581 +                                                 stopd(inode->i_sb)->hidden_mnt,
1582 +                                                 hidden_flags);
1583 +                       if (IS_ERR(hidden_file)) {
1584 +                               err = PTR_ERR(hidden_file);
1585 +                               dput(hidden_dentry);
1586 +                               goto out;
1587 +                       }
1588 +                       ftohf(file) = hidden_file;      /* link two files */
1589 +                       goto out;
1590 +               }
1591 +               else {
1592 +                       if(S_ISDIR(file->f_dentry->d_inode->i_mode)) {
1593 +                               err = dir_unmod_to_mod(file->f_dentry);
1594 +                       } else
1595 +                               err = nondir_unmod_to_mod(file->f_dentry, 1);
1596 +
1597 +                       if (err) {
1598 +                               printk("mini_fo_open: ERROR creating storage file.\n");
1599 +                               goto out;
1600 +                       }
1601 +               }
1602 +       }
1603 +       hidden_sto_dentry = dtohd2(file->f_dentry);
1604 +       dget(hidden_sto_dentry);
1605 +
1606 +       if(dtopd(file->f_dentry)->state == MODIFIED) {
1607 +               /* Directorys are special, interpose on both lower level files */
1608 +               if(S_ISDIR(itohi(inode)->i_mode)) {
1609 +                       /* check for invalid file types of lower level files */
1610 +                       if(!(S_ISDIR(itohi(inode)->i_mode) && S_ISDIR(itohi2(inode)->i_mode))) {
1611 +                               printk(KERN_CRIT "mini_fo_open: meta data corruption detected.\n");
1612 +                               dput(hidden_sto_dentry);
1613 +                               err = -EINVAL;
1614 +                               goto out;
1615 +                       }
1616 +
1617 +                       /* lower level directorys are ok, open the base file */
1618 +                       hidden_dentry = dtohd(file->f_dentry);
1619 +                       dget(hidden_dentry);
1620 +
1621 +                       mntget(stopd(inode->i_sb)->hidden_mnt);
1622 +                       hidden_file = dentry_open(hidden_dentry,
1623 +                                                 stopd(inode->i_sb)->hidden_mnt,
1624 +                                                 hidden_flags);
1625 +                       if (IS_ERR(hidden_file)) {
1626 +                               err = PTR_ERR(hidden_file);
1627 +                               dput(hidden_dentry);
1628 +                               dput(hidden_sto_dentry);
1629 +                               goto out;
1630 +                       }
1631 +                       ftohf(file) = hidden_file; /* link the two files */
1632 +               }
1633 +       }
1634 +
1635 +       if(!exists_in_storage(file->f_dentry)) {
1636 +               printk(KERN_CRIT "mini_fo_open: invalid file state detected.\n");
1637 +               err = -EINVAL;
1638 +               dput(hidden_sto_dentry);
1639 +
1640 +               /* If the base file has been opened, we need to close it here */
1641 +               if(ftohf(file)) {
1642 +                       if (hidden_file->f_op && hidden_file->f_op->flush)
1643 +                               hidden_file->f_op->flush(hidden_file);
1644 +                       dput(hidden_dentry);
1645 +               }
1646 +               goto out;
1647 +       }
1648 +
1649 +       /* ok, now we can safely open the storage file */
1650 +       mntget(stopd(inode->i_sb)->hidden_mnt2);
1651 +       hidden_sto_file = dentry_open(hidden_sto_dentry,
1652 +                                     stopd(inode->i_sb)->hidden_mnt2,
1653 +                                     hidden_flags);
1654 +
1655 +       /* dentry_open dputs the dentry if it fails */
1656 +       if (IS_ERR(hidden_sto_file)) {
1657 +               err = PTR_ERR(hidden_sto_file);
1658 +               /* close base file if open */
1659 +               if(ftohf(file)) {
1660 +                       if (hidden_file->f_op && hidden_file->f_op->flush)
1661 +                               hidden_file->f_op->flush(hidden_file);
1662 +                       dput(hidden_dentry);
1663 +               }
1664 +               goto out;
1665 +       }
1666 +       ftohf2(file) = hidden_sto_file; /* link storage file */
1667 +       
1668 + out:
1669 +       if (err < 0 && ftopd(file)) {
1670 +               kfree(ftopd(file));
1671 +       }
1672 +       return err;
1673 +}
1674 +
1675 +STATIC int
1676 +mini_fo_flush(file_t *file)
1677 +{
1678 +       int err1 = 0;           /* assume ok (see open.c:close_fp) */
1679 +       int err2 = 0;
1680 +       file_t *hidden_file = NULL;
1681 +       
1682 +       check_mini_fo_file(file);
1683 +
1684 +       /* mk: we don't do any state checking here, as its not worth the time.
1685 +        * Just flush the lower level files if they exist.
1686 +        */
1687 +       if(ftopd(file) != NULL) {
1688 +               if(ftohf(file) != NULL) {
1689 +                       hidden_file = ftohf(file);
1690 +                       if (hidden_file->f_op && hidden_file->f_op->flush)
1691 +                               err1 = hidden_file->f_op->flush(hidden_file);
1692 +               }
1693 +               if(ftohf2(file) != NULL) {
1694 +                       hidden_file = ftohf2(file);
1695 +                       if (hidden_file->f_op && hidden_file->f_op->flush)
1696 +                               err2 = hidden_file->f_op->flush(hidden_file);
1697 +               }
1698 +       }
1699 +       return (err1 | err2);
1700 +}
1701 +
1702 +
1703 +STATIC int
1704 +mini_fo_release(inode_t *inode, file_t *file)
1705 +{
1706 +       int err = 0;
1707 +       file_t *hidden_file = NULL;
1708 +
1709 +       if (ftopd(file) != NULL) {
1710 +               if(ftohf(file)) {
1711 +                       hidden_file = ftohf(file);
1712 +                       fput(hidden_file);
1713 +               }
1714 +               if(ftohf2(file)) {
1715 +                       hidden_file = ftohf2(file);
1716 +                       fput(hidden_file);
1717 +               }
1718 +               kfree(ftopd(file));
1719 +       }
1720 +       return err;
1721 +}
1722 +
1723 +STATIC int
1724 +mini_fo_fsync(file_t *file, dentry_t *dentry, int datasync)
1725 +{
1726 +       int err1 = 0;
1727 +       int err2 = 0;
1728 +       file_t *hidden_file = NULL;
1729 +       dentry_t *hidden_dentry;
1730 +
1731 +       check_mini_fo_file(file);
1732 +
1733 +       if ((hidden_file = ftohf(file)) != NULL) {
1734 +               hidden_dentry = dtohd(dentry);
1735 +               if (hidden_file->f_op && hidden_file->f_op->fsync) {
1736 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
1737 +                       mutex_lock(&hidden_dentry->d_inode->i_mutex);
1738 +#else
1739 +                       down(&hidden_dentry->d_inode->i_sem);
1740 +#endif
1741 +                       err1 = hidden_file->f_op->fsync(hidden_file, hidden_dentry, datasync);
1742 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
1743 +                       mutex_unlock(&hidden_dentry->d_inode->i_mutex);
1744 +#else
1745 +                       up(&hidden_dentry->d_inode->i_sem);
1746 +#endif
1747 +               }
1748 +       }
1749 +
1750 +       if ((hidden_file = ftohf2(file)) != NULL) {
1751 +               hidden_dentry = dtohd2(dentry);
1752 +               if (hidden_file->f_op && hidden_file->f_op->fsync) {
1753 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
1754 +                       mutex_lock(&hidden_dentry->d_inode->i_mutex);
1755 +#else
1756 +                       down(&hidden_dentry->d_inode->i_sem);
1757 +#endif
1758 +                       err2 = hidden_file->f_op->fsync(hidden_file, hidden_dentry, datasync);
1759 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
1760 +                       mutex_unlock(&hidden_dentry->d_inode->i_mutex);
1761 +#else
1762 +                       up(&hidden_dentry->d_inode->i_sem);
1763 +#endif
1764 +               }
1765 +       }
1766 +       else
1767 +               goto err;
1768 +
1769 +err:
1770 +       return (err1 || err2);
1771 +}
1772 +
1773 +
1774 +STATIC int
1775 +mini_fo_fasync(int fd, file_t *file, int flag)
1776 +{
1777 +       int err1 = 0;
1778 +       int err2 = 0;
1779 +
1780 +       file_t *hidden_file = NULL;
1781 +
1782 +       check_mini_fo_file(file);
1783 +
1784 +       if((hidden_file = ftohf(file)) != NULL) {
1785 +               err1 = hidden_file->f_op->fasync(fd, hidden_file, flag);
1786 +       }
1787 +       if((hidden_file = ftohf2(file)) != NULL) {
1788 +               err2 = hidden_file->f_op->fasync(fd, hidden_file, flag);
1789 +       }
1790 +       
1791 +       return (err1 || err2);
1792 +}
1793 +
1794 +
1795 +
1796 +struct file_operations mini_fo_dir_fops =
1797 +       {
1798 +               read:   generic_read_dir,
1799 +               write:  mini_fo_write,
1800 +               readdir: mini_fo_readdir,
1801 +               poll:   mini_fo_poll,
1802 +               /* ioctl:       mini_fo_ioctl, */
1803 +               mmap:   mini_fo_mmap,
1804 +               open:   mini_fo_open,
1805 +               flush:  mini_fo_flush,
1806 +               release: mini_fo_release,
1807 +               fsync:  mini_fo_fsync,
1808 +               fasync: mini_fo_fasync,
1809 +               /* not needed lock:     mini_fo_lock, */
1810 +               /* not needed: readv */
1811 +               /* not needed: writev */
1812 +               /* not implemented: sendpage */
1813 +               /* not implemented: get_unmapped_area */
1814 +       };
1815 +
1816 +struct file_operations mini_fo_main_fops =
1817 +       {
1818 +               llseek: mini_fo_llseek,
1819 +               read:   mini_fo_read,
1820 +               write:  mini_fo_write,
1821 +               readdir: mini_fo_readdir,
1822 +               poll:   mini_fo_poll,
1823 +               /* ioctl:       mini_fo_ioctl, */
1824 +               mmap:   mini_fo_mmap,
1825 +               open:   mini_fo_open,
1826 +               flush:  mini_fo_flush,
1827 +               release: mini_fo_release,
1828 +               fsync:  mini_fo_fsync,
1829 +               fasync: mini_fo_fasync,
1830 +               /* not needed: lock:    mini_fo_lock, */
1831 +               /* not needed: readv */
1832 +               /* not needed: writev */
1833 +               /* not implemented: sendpage */
1834 +               /* not implemented: get_unmapped_area */
1835 +       };
1836 diff -urN linux.old/fs/mini_fo/fist.h linux.dev/fs/mini_fo/fist.h
1837 --- linux.old/fs/mini_fo/fist.h 1970-01-01 01:00:00.000000000 +0100
1838 +++ linux.dev/fs/mini_fo/fist.h 2006-11-17 03:11:48.000000000 +0100
1839 @@ -0,0 +1,248 @@
1840 +/*
1841 + * Copyright (c) 1997-2003 Erez Zadok
1842 + * Copyright (c) 2001-2003 Stony Brook University
1843 + *
1844 + * For specific licensing information, see the COPYING file distributed with
1845 + * this package, or get one from ftp://ftp.filesystems.org/pub/fist/COPYING.
1846 + *
1847 + * This Copyright notice must be kept intact and distributed with all
1848 + * fistgen sources INCLUDING sources generated by fistgen.
1849 + */
1850 +/*
1851 + * Copyright (C) 2004, 2005 Markus Klotzbuecher <mk@creamnet.de>
1852 + *
1853 + * This program is free software; you can redistribute it and/or
1854 + * modify it under the terms of the GNU General Public License
1855 + * as published by the Free Software Foundation; either version
1856 + * 2 of the License, or (at your option) any later version.
1857 + */
1858 +
1859 +
1860 +/*
1861 + *  $Id$
1862 + */
1863 +
1864 +#ifndef __FIST_H_
1865 +#define __FIST_H_
1866 +
1867 +/*
1868 + * KERNEL ONLY CODE:
1869 + */
1870 +#ifdef __KERNEL__
1871 +#include <linux/config.h>
1872 +#include <linux/version.h>
1873 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
1874 +#ifdef CONFIG_MODVERSIONS
1875 +# define MODVERSIONS
1876 +# include <linux/modversions.h>
1877 +#endif /* CONFIG_MODVERSIONS */
1878 +#endif /* KERNEL_VERSION < 2.6.0 */
1879 +#include <linux/sched.h>
1880 +#include <linux/kernel.h>
1881 +#include <linux/mm.h>
1882 +#include <linux/string.h>
1883 +#include <linux/stat.h>
1884 +#include <linux/errno.h>
1885 +#include <linux/wait.h>
1886 +#include <linux/limits.h>
1887 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
1888 +#include <linux/locks.h>
1889 +#else
1890 +#include <linux/buffer_head.h>
1891 +#include <linux/pagemap.h>
1892 +#include <linux/namei.h>
1893 +#include <linux/module.h>
1894 +#include <linux/mount.h>
1895 +#include <linux/page-flags.h>
1896 +#include <linux/writeback.h>
1897 +#include <linux/statfs.h>
1898 +#endif
1899 +#include <linux/smp.h>
1900 +#include <linux/smp_lock.h>
1901 +#include <linux/file.h>
1902 +#include <linux/slab.h>
1903 +#include <linux/vmalloc.h>
1904 +#include <linux/poll.h>
1905 +#include <linux/list.h>
1906 +#include <linux/init.h>
1907 +
1908 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,20)
1909 +#include <linux/xattr.h>
1910 +#endif
1911 +
1912 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
1913 +#include <linux/security.h>
1914 +#endif
1915 +
1916 +#include <linux/swap.h>
1917 +
1918 +#include <asm/system.h>
1919 +#include <asm/segment.h>
1920 +#include <asm/mman.h>
1921 +#include <linux/seq_file.h>
1922 +
1923 +/*
1924 + * MACROS:
1925 + */
1926 +
1927 +/* those mapped to ATTR_* were copied from linux/fs.h */
1928 +#define FA_MODE                ATTR_MODE
1929 +#define FA_UID         ATTR_UID
1930 +#define FA_GID         ATTR_GID
1931 +#define FA_SIZE                ATTR_SIZE
1932 +#define FA_ATIME       ATTR_ATIME
1933 +#define FA_MTIME       ATTR_MTIME
1934 +#define FA_CTIME       ATTR_CTIME
1935 +#define FA_ATIME_SET   ATTR_ATIME_SET
1936 +#define FA_MTIME_SET   ATTR_MTIME_SET
1937 +#define FA_FORCE       ATTR_FORCE
1938 +#define FA_ATTR_FLAGS  ATTR_ATTR_FLAG
1939 +
1940 +/* must be greater than all other ATTR_* flags! */
1941 +#define FA_NLINK       2048
1942 +#define FA_BLKSIZE     4096
1943 +#define FA_BLOCKS      8192
1944 +#define FA_TIMES       (FA_ATIME|FA_MTIME|FA_CTIME)
1945 +#define FA_ALL         0
1946 +
1947 +/* macros to manage changes between kernels */
1948 +#define INODE_DATA(i)  (&(i)->i_data)
1949 +
1950 +#define MIN(x,y) ((x < y) ? (x) : (y))
1951 +#define MAX(x,y) ((x > y) ? (x) : (y))
1952 +#define MAXPATHLEN PATH_MAX
1953 +
1954 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,4,5)
1955 +# define lookup_one_len(a,b,c) lookup_one(a,b)
1956 +#endif /* LINUX_VERSION_CODE < KERNEL_VERSION(2,4,5) */
1957 +
1958 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,4,8)
1959 +# define generic_file_llseek default_llseek
1960 +#endif /* LINUX_VERSION_CODE < KERNEL_VERSION(2,4,8) */
1961 +
1962 +#ifndef SEEK_SET
1963 +# define SEEK_SET 0
1964 +#endif /* not SEEK_SET */
1965 +
1966 +#ifndef SEEK_CUR
1967 +# define SEEK_CUR 1
1968 +#endif /* not SEEK_CUR */
1969 +
1970 +#ifndef SEEK_END
1971 +# define SEEK_END 2
1972 +#endif /* not SEEK_END */
1973 +
1974 +#ifndef DEFAULT_POLLMASK
1975 +# define DEFAULT_POLLMASK (POLLIN | POLLOUT | POLLRDNORM | POLLWRNORM)
1976 +#endif /* not DEFAULT_POLLMASK */
1977 +
1978 +/* XXX: fix this so fistgen generates kfree() code directly */
1979 +#define kfree_s(a,b) kfree(a)
1980 +
1981 +/*
1982 + * TYPEDEFS:
1983 + */
1984 +typedef struct dentry dentry_t;
1985 +typedef struct file file_t;
1986 +typedef struct inode inode_t;
1987 +typedef inode_t vnode_t;
1988 +typedef struct page page_t;
1989 +typedef struct qstr qstr_t;
1990 +typedef struct super_block super_block_t;
1991 +typedef super_block_t vfs_t;
1992 +typedef struct vm_area_struct vm_area_t;
1993 +
1994 +
1995 +/*
1996 + * EXTERNALS:
1997 + */
1998 +
1999 +#define FPPF(str,page) printk("PPF %s 0x%x/%d: Lck:%d Err:%d Ref:%d Upd:%d Other::%d:%d:%d:%d:\n", \
2000 +               str, \
2001 +               (int) page, \
2002 +               (int) page->index, \
2003 +               (PageLocked(page) ? 1 : 0), \
2004 +               (PageError(page) ? 1 : 0), \
2005 +               (PageReferenced(page) ? 1 : 0), \
2006 +               (Page_Uptodate(page) ? 1 : 0), \
2007 +               (PageDecrAfter(page) ? 1 : 0), \
2008 +               (PageSlab(page) ? 1 : 0), \
2009 +               (PageSwapCache(page) ? 1 : 0), \
2010 +               (PageReserved(page) ? 1 : 0) \
2011 +               )
2012 +#define EZKDBG printk("EZK %s:%d:%s\n",__FILE__,__LINE__,__FUNCTION__)
2013 +#if 0
2014 +# define EZKDBG1 printk("EZK %s:%d\n",__FILE__,__LINE__)
2015 +#else
2016 +# define EZKDBG1
2017 +#endif
2018 +
2019 +extern int fist_get_debug_value(void);
2020 +extern int fist_set_debug_value(int val);
2021 +#if 0 /* mini_fo doesn't need these */
2022 +extern void fist_dprint_internal(int level, char *str,...);
2023 +extern void fist_print_dentry(char *str, const dentry_t *dentry);
2024 +extern void fist_print_inode(char *str, const inode_t *inode);
2025 +extern void fist_print_file(char *str, const file_t *file);
2026 +extern void fist_print_buffer_flags(char *str, struct buffer_head *buffer);
2027 +extern void fist_print_page_flags(char *str, page_t *page);
2028 +extern void fist_print_page_bytes(char *str, page_t *page);
2029 +extern void fist_print_pte_flags(char *str, const page_t *page);
2030 +extern void fist_checkinode(inode_t *inode, char *msg);
2031 +extern void fist_print_sb(char *str, const super_block_t *sb);
2032 +
2033 +/* Â§$% by mk: special debug functions */
2034 +extern void fist_mk_print_dentry(char *str, const dentry_t *dentry);
2035 +extern void fist_mk_print_inode(char *str, const inode_t *inode);
2036 +
2037 +extern char *add_indent(void);
2038 +extern char *del_indent(void);
2039 +#endif/* mini_fo doesn't need these */
2040 +
2041 +
2042 +#define STATIC
2043 +#define ASSERT(EX)     \
2044 +do {   \
2045 +    if (!(EX)) {       \
2046 +       printk(KERN_CRIT "ASSERTION FAILED: %s at %s:%d (%s)\n", #EX,   \
2047 +              __FILE__, __LINE__, __FUNCTION__);       \
2048 +       (*((char *)0))=0;       \
2049 +    }  \
2050 +} while (0)
2051 +/* same ASSERT, but tell me who was the caller of the function */
2052 +#define ASSERT2(EX)    \
2053 +do {   \
2054 +    if (!(EX)) {       \
2055 +       printk(KERN_CRIT "ASSERTION FAILED (caller): %s at %s:%d (%s)\n", #EX,  \
2056 +              file, line, func);       \
2057 +       (*((char *)0))=0;       \
2058 +    }  \
2059 +} while (0)
2060 +
2061 +#if 0 /* mini_fo doesn't need these */
2062 +#define dprintk(format, args...) printk(KERN_DEBUG format, ##args)
2063 +#define fist_dprint(level, str, args...) fist_dprint_internal(level, KERN_DEBUG str, ## args)
2064 +#define print_entry_location() fist_dprint(4, "%sIN:  %s %s:%d\n", add_indent(), __FUNCTION__, __FILE__, __LINE__)
2065 +#define print_exit_location() fist_dprint(4, "%s OUT: %s %s:%d\n", del_indent(), __FUNCTION__, __FILE__, __LINE__)
2066 +#define print_exit_status(status) fist_dprint(4, "%s OUT: %s %s:%d, STATUS: %d\n", del_indent(), __FUNCTION__, __FILE__, __LINE__, status)
2067 +#define print_exit_pointer(status) \
2068 +do { \
2069 +  if (IS_ERR(status)) \
2070 +    fist_dprint(4, "%s OUT: %s %s:%d, RESULT: %ld\n", del_indent(), __FUNCTION__, __FILE__, __LINE__, PTR_ERR(status)); \
2071 +  else \
2072 +    fist_dprint(4, "%s OUT: %s %s:%d, RESULT: 0x%x\n", del_indent(), __FUNCTION__, __FILE__, __LINE__, PTR_ERR(status)); \
2073 +} while (0)
2074 +#endif/* mini_fo doesn't need these */
2075 +
2076 +#endif /* __KERNEL__ */
2077 +
2078 +
2079 +/*
2080 + * DEFINITIONS FOR USER AND KERNEL CODE:
2081 + * (Note: ioctl numbers 1--9 are reserved for fistgen, the rest
2082 + *  are auto-generated automatically based on the user's .fist file.)
2083 + */
2084 +# define FIST_IOCTL_GET_DEBUG_VALUE    _IOR(0x15, 1, int)
2085 +# define FIST_IOCTL_SET_DEBUG_VALUE    _IOW(0x15, 2, int)
2086 +
2087 +#endif /* not __FIST_H_ */
2088 diff -urN linux.old/fs/mini_fo/inode.c linux.dev/fs/mini_fo/inode.c
2089 --- linux.old/fs/mini_fo/inode.c        1970-01-01 01:00:00.000000000 +0100
2090 +++ linux.dev/fs/mini_fo/inode.c        2006-11-17 03:11:48.000000000 +0100
2091 @@ -0,0 +1,1573 @@
2092 +/*
2093 + * Copyright (c) 1997-2003 Erez Zadok
2094 + * Copyright (c) 2001-2003 Stony Brook University
2095 + *
2096 + * For specific licensing information, see the COPYING file distributed with
2097 + * this package, or get one from ftp://ftp.filesystems.org/pub/fist/COPYING.
2098 + *
2099 + * This Copyright notice must be kept intact and distributed with all
2100 + * fistgen sources INCLUDING sources generated by fistgen.
2101 + */
2102 +/*
2103 + * Copyright (C) 2004, 2005 Markus Klotzbuecher <mk@creamnet.de>
2104 + *
2105 + * This program is free software; you can redistribute it and/or
2106 + * modify it under the terms of the GNU General Public License
2107 + * as published by the Free Software Foundation; either version
2108 + * 2 of the License, or (at your option) any later version.
2109 + */
2110 +
2111 +/*
2112 + *  $Id$
2113 + */
2114 +
2115 +#ifdef HAVE_CONFIG_H
2116 +# include <config.h>
2117 +#endif 
2118 +
2119 +#include "fist.h"
2120 +#include "mini_fo.h"
2121 +
2122 +STATIC int
2123 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
2124 +mini_fo_create(inode_t *dir, dentry_t *dentry, int mode, struct nameidata *nd)
2125 +#else
2126 +mini_fo_create(inode_t *dir, dentry_t *dentry, int mode)
2127 +#endif
2128 +{
2129 +       int err = 0;
2130 +
2131 +       check_mini_fo_dentry(dentry);
2132 +
2133 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
2134 +       err = create_sto_reg_file(dentry, mode, nd);
2135 +#else
2136 +       err = create_sto_reg_file(dentry, mode);
2137 +#endif
2138 +       check_mini_fo_dentry(dentry);
2139 +       return err;
2140 +}
2141 +
2142 +
2143 +STATIC dentry_t *
2144 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
2145 +mini_fo_lookup(inode_t *dir, dentry_t *dentry, struct nameidata* nd)
2146 +#else
2147 +mini_fo_lookup(inode_t *dir, dentry_t *dentry)
2148 +#endif
2149 +{
2150 +       int err = 0;
2151 +       dentry_t *hidden_dir_dentry;
2152 +       dentry_t *hidden_dentry = NULL;
2153 +
2154 +       dentry_t *hidden_sto_dir_dentry;
2155 +       dentry_t *hidden_sto_dentry = NULL;
2156 +
2157 +       /* whiteout flag */
2158 +       int del_flag = 0; 
2159 +       char *bpath = NULL;
2160 +
2161 +       const char *name;
2162 +       unsigned int namelen;
2163 +
2164 +       /* Don't allow lookups of META-files */
2165 +       namelen = strlen(META_FILENAME);
2166 +       if(namelen == dentry->d_name.len) {
2167 +               if(!strncmp(dentry->d_name.name, META_FILENAME, namelen)) {
2168 +                       err = -ENOENT;
2169 +                       goto out;
2170 +               }
2171 +       }
2172 +
2173 +       hidden_dir_dentry = dtohd(dentry->d_parent);
2174 +       hidden_sto_dir_dentry = dtohd2(dentry->d_parent);
2175 +
2176 +       name = dentry->d_name.name;
2177 +       namelen = dentry->d_name.len;
2178 +
2179 +       /* must initialize dentry operations */
2180 +       dentry->d_op = &mini_fo_dops;
2181 +
2182 +       /* setup the del_flag */
2183 +       del_flag = __meta_check_d_entry(dir, name, namelen);
2184 +       bpath = __meta_check_r_entry(dir, name, namelen);
2185 +
2186 +       /* perform the lookups of base and storage files:
2187 +        *
2188 +        * This caused some serious trouble, as a lookup_one_len passing
2189 +        * a negative dentry oopses. Solution is to only do the lookup
2190 +        * if the dentry is positive, else we set it to NULL
2191 +        * More trouble, who said a *_dir_dentry can't be NULL?
2192 +        */
2193 +       if(bpath) {
2194 +               /* Cross-Interposing (C), yeah! */
2195 +               hidden_dentry = bpath_walk(dir->i_sb, bpath);
2196 +               if(!hidden_dentry || !hidden_dentry->d_inode) {
2197 +                       printk(KERN_CRIT "mini_fo_lookup: bpath_walk failed.\n");
2198 +                       err= -EINVAL;
2199 +                       goto out;
2200 +               }
2201 +               
2202 +               /* this can be set up safely without fear of spaghetti
2203 +                * interposing as it is only used for copying times */
2204 +               hidden_dir_dentry = hidden_dentry->d_parent;
2205 +               kfree(bpath);
2206 +       }
2207 +       else if(hidden_dir_dentry && hidden_dir_dentry->d_inode)
2208 +               hidden_dentry = 
2209 +                       lookup_one_len(name, hidden_dir_dentry, namelen);
2210 +       else
2211 +               hidden_dentry = NULL;
2212 +
2213 +       if(hidden_sto_dir_dentry && hidden_sto_dir_dentry->d_inode)
2214 +               hidden_sto_dentry = 
2215 +                       lookup_one_len(name, hidden_sto_dir_dentry, namelen);
2216 +       else
2217 +               hidden_sto_dentry =  NULL;
2218 +
2219 +       /* catch error in lookup */
2220 +       if (IS_ERR(hidden_dentry) || IS_ERR(hidden_sto_dentry)) {
2221 +               /* mk: we need to call dput on the dentry, whose 
2222 +                * lookup_one_len operation failed, in order to avoid
2223 +                * unmount trouble.
2224 +                */
2225 +               if(IS_ERR(hidden_dentry)) {
2226 +                       printk(KERN_CRIT "mini_fo_lookup: ERR from base dentry, lookup failed.\n");
2227 +                       err = PTR_ERR(hidden_dentry);
2228 +               } else {
2229 +                       dput(hidden_dentry);
2230 +               }
2231 +               if(IS_ERR(hidden_sto_dentry)) {
2232 +                       printk(KERN_CRIT "mini_fo_lookup: ERR from storage dentry, lookup failed.\n");
2233 +                       err = PTR_ERR(hidden_sto_dentry);
2234 +               } else {
2235 +                       dput(hidden_sto_dentry);
2236 +               }
2237 +               goto out;
2238 +       }
2239 +
2240 +       /* allocate dentry private data */
2241 +       __dtopd(dentry) = (struct mini_fo_dentry_info *)
2242 +               kmalloc(sizeof(struct mini_fo_dentry_info), GFP_KERNEL);
2243 +       
2244 +       if (!dtopd(dentry)) {
2245 +               err = -ENOMEM;
2246 +               goto out_dput;
2247 +       }
2248 +
2249 +       /* check for different states of the mini_fo file to be looked up. */
2250 +       
2251 +       /* state 1, file has been modified */
2252 +       if(hidden_dentry && hidden_sto_dentry &&
2253 +          hidden_dentry->d_inode && hidden_sto_dentry->d_inode && !del_flag) {
2254 +
2255 +               /* update parent directory's atime */
2256 +               fist_copy_attr_atime(dir, hidden_sto_dir_dentry->d_inode);
2257 +
2258 +               dtopd(dentry)->state = MODIFIED;
2259 +               dtohd(dentry) = hidden_dentry;
2260 +               dtohd2(dentry) = hidden_sto_dentry;
2261 +
2262 +               err = mini_fo_tri_interpose(hidden_dentry,
2263 +                                           hidden_sto_dentry,
2264 +                                           dentry, dir->i_sb, 1);
2265 +               if (err) {
2266 +                       printk(KERN_CRIT "mini_fo_lookup: error interposing (state1).\n");
2267 +                       goto out_free;
2268 +               }
2269 +               goto out;
2270 +       }
2271 +       /* state 2, file is unmodified */
2272 +       if(hidden_dentry && hidden_dentry->d_inode && !del_flag) {
2273 +
2274 +               fist_copy_attr_atime(dir, hidden_dir_dentry->d_inode);
2275 +
2276 +               dtopd(dentry)->state = UNMODIFIED;
2277 +               dtohd(dentry) = hidden_dentry;
2278 +               dtohd2(dentry) = hidden_sto_dentry; /* could be negative */
2279 +
2280 +               err = mini_fo_tri_interpose(hidden_dentry,
2281 +                                           hidden_sto_dentry,
2282 +                                           dentry, dir->i_sb, 1);
2283 +               if (err) {
2284 +                       printk(KERN_CRIT "mini_fo_lookup: error interposing (state2).\n");
2285 +                       goto out_free;
2286 +               }
2287 +               goto out;
2288 +       }
2289 +       /* state 3, file has been newly created */
2290 +       if(hidden_sto_dentry && hidden_sto_dentry->d_inode && !del_flag) {
2291 +
2292 +               fist_copy_attr_atime(dir, hidden_sto_dir_dentry->d_inode);
2293 +               dtopd(dentry)->state = CREATED;
2294 +               dtohd(dentry) = hidden_dentry; /* could be negative */
2295 +               dtohd2(dentry) = hidden_sto_dentry;
2296 +
2297 +               err = mini_fo_tri_interpose(hidden_dentry,
2298 +                                           hidden_sto_dentry,
2299 +                                           dentry, dir->i_sb, 1);
2300 +               if (err) {
2301 +                       printk(KERN_CRIT "mini_fo_lookup: error interposing (state3).\n");
2302 +                       goto out_free;
2303 +               }
2304 +               goto out;
2305 +       }
2306 +
2307 +       /* state 4, file has deleted and created again. */
2308 +       if(hidden_dentry && hidden_sto_dentry &&
2309 +          hidden_dentry->d_inode && 
2310 +          hidden_sto_dentry->d_inode && del_flag) {
2311 +
2312 +               fist_copy_attr_atime(dir, hidden_sto_dir_dentry->d_inode);
2313 +               dtopd(dentry)->state = DEL_REWRITTEN;
2314 +               dtohd(dentry) = NULL;
2315 +               dtohd2(dentry) = hidden_sto_dentry;
2316 +
2317 +               err = mini_fo_tri_interpose(NULL,
2318 +                                           hidden_sto_dentry,
2319 +                                           dentry, dir->i_sb, 1);
2320 +               if (err) {
2321 +                       printk(KERN_CRIT "mini_fo_lookup: error interposing (state4).\n");
2322 +                       goto out_free;
2323 +               }
2324 +               /* We will never need this dentry again, as the file has been
2325 +                * deleted from base */
2326 +               dput(hidden_dentry);
2327 +               goto out;
2328 +       }
2329 +       /* state 5, file has been deleted in base */
2330 +       if(hidden_dentry && hidden_sto_dentry &&
2331 +          hidden_dentry->d_inode && 
2332 +          !hidden_sto_dentry->d_inode && del_flag) {
2333 +
2334 +               /* check which parents atime we need for updating */
2335 +               if(hidden_sto_dir_dentry->d_inode)
2336 +                       fist_copy_attr_atime(dir, 
2337 +                                            hidden_sto_dir_dentry->d_inode);
2338 +               else
2339 +                       fist_copy_attr_atime(dir, 
2340 +                                            hidden_dir_dentry->d_inode);
2341 +
2342 +               dtopd(dentry)->state = DELETED;
2343 +               dtohd(dentry) = NULL;
2344 +               dtohd2(dentry) = hidden_sto_dentry;
2345 +
2346 +               /* add negative dentry to dcache to speed up lookups */
2347 +               d_add(dentry, NULL);
2348 +               dput(hidden_dentry);
2349 +               goto out;
2350 +       }
2351 +       /* state 6, file does not exist */
2352 +       if(((hidden_dentry && !hidden_dentry->d_inode) ||
2353 +           (hidden_sto_dentry && !hidden_sto_dentry->d_inode)) && !del_flag)
2354 +               {
2355 +                       /* check which parents atime we need for updating */
2356 +                       if(hidden_sto_dir_dentry && hidden_sto_dir_dentry->d_inode)
2357 +                               fist_copy_attr_atime(dir, hidden_sto_dir_dentry->d_inode);
2358 +                       else
2359 +                               fist_copy_attr_atime(dir, hidden_dir_dentry->d_inode);
2360 +
2361 +                       dtopd(dentry)->state = NON_EXISTANT;
2362 +                       dtohd(dentry) = hidden_dentry;
2363 +                       dtohd2(dentry) = hidden_sto_dentry;
2364 +                       d_add(dentry, NULL);
2365 +                       goto out;
2366 +               }
2367 +
2368 +       /* if we get to here, were in an invalid state. bad. */
2369 +       printk(KERN_CRIT "mini_fo_lookup: ERROR, meta data corruption detected.\n");
2370 +
2371 +       /* end state checking */
2372 + out_free:
2373 +       d_drop(dentry);         /* so that our bad dentry will get destroyed */
2374 +       kfree(dtopd(dentry));
2375 +       __dtopd(dentry) = NULL; /* be safe */
2376 +
2377 + out_dput:
2378 +       if(hidden_dentry)
2379 +               dput(hidden_dentry);
2380 +       if(hidden_sto_dentry)
2381 +               dput(hidden_sto_dentry); /* drops usage count and marks for release */
2382 +
2383 + out:
2384 +       /* initalize wol if file exists and is directory */
2385 +       if(dentry->d_inode) {
2386 +               if(S_ISDIR(dentry->d_inode->i_mode)) {
2387 +                       itopd(dentry->d_inode)->deleted_list_size = -1;
2388 +                       itopd(dentry->d_inode)->renamed_list_size = -1;
2389 +                       meta_build_lists(dentry);
2390 +               }
2391 +       }
2392 +       return ERR_PTR(err);
2393 +}
2394 +
2395 +
2396 +STATIC int
2397 +mini_fo_link(dentry_t *old_dentry, inode_t *dir, dentry_t *new_dentry)
2398 +{
2399 +       int err;
2400 +       dentry_t *hidden_old_dentry;
2401 +       dentry_t *hidden_new_dentry;
2402 +       dentry_t *hidden_dir_dentry;
2403 +
2404 +
2405 +       check_mini_fo_dentry(old_dentry);
2406 +       check_mini_fo_dentry(new_dentry);
2407 +       check_mini_fo_inode(dir);
2408 +
2409 +       /* no links to directorys and existing targets target allowed */
2410 +       if(S_ISDIR(old_dentry->d_inode->i_mode) ||
2411 +          is_mini_fo_existant(new_dentry)) {
2412 +               err = -EPERM;
2413 +               goto out;
2414 +       }
2415 +
2416 +       /* bring it directly from unmod to del_rew */
2417 +       if(dtost(old_dentry) == UNMODIFIED) {
2418 +               err = nondir_unmod_to_mod(old_dentry, 1);
2419 +               if(err) {
2420 +                       err = -EINVAL;
2421 +                       goto out;
2422 +               }
2423 +               err = meta_add_d_entry(old_dentry->d_parent,
2424 +                                      old_dentry->d_name.name,
2425 +                                      old_dentry->d_name.len);
2426 +               if(err) {
2427 +                       err = -EINVAL;
2428 +                       goto out;
2429 +               }
2430 +               dput(dtohd(old_dentry));
2431 +               dtohd(old_dentry) = NULL;
2432 +               dtost(old_dentry) = DEL_REWRITTEN;
2433 +       }
2434 +       
2435 +       err = get_neg_sto_dentry(new_dentry);
2436 +       if(err) {
2437 +               err = -EINVAL;
2438 +               goto out;
2439 +       }
2440 +
2441 +       hidden_old_dentry = dtohd2(old_dentry);
2442 +       hidden_new_dentry = dtohd2(new_dentry);
2443 +
2444 +       dget(hidden_old_dentry);
2445 +       dget(hidden_new_dentry);
2446 +
2447 +       /* was: hidden_dir_dentry = lock_parent(hidden_new_dentry); */
2448 +       hidden_dir_dentry = dget(hidden_new_dentry->d_parent);
2449 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
2450 +       mutex_lock(&hidden_dir_dentry->d_inode->i_mutex);
2451 +#else
2452 +       down(&hidden_dir_dentry->d_inode->i_sem);
2453 +#endif
2454 +
2455 +       err = vfs_link(hidden_old_dentry,
2456 +                      hidden_dir_dentry->d_inode,
2457 +                      hidden_new_dentry);
2458 +       if (err || !hidden_new_dentry->d_inode)
2459 +               goto out_lock;
2460 +
2461 +       dtost(new_dentry) = CREATED;
2462 +       err = mini_fo_tri_interpose(NULL, hidden_new_dentry, new_dentry, dir->i_sb, 0);
2463 +       if (err)
2464 +               goto out_lock;
2465 +
2466 +       fist_copy_attr_timesizes(dir, hidden_new_dentry->d_inode);
2467 +       /* propagate number of hard-links */
2468 +       old_dentry->d_inode->i_nlink = itohi2(old_dentry->d_inode)->i_nlink;
2469 +
2470 + out_lock:
2471 +       /* was: unlock_dir(hidden_dir_dentry); */
2472 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
2473 +       mutex_unlock(&hidden_dir_dentry->d_inode->i_mutex);
2474 +#else
2475 +       up(&hidden_dir_dentry->d_inode->i_sem);
2476 +#endif
2477 +       dput(hidden_dir_dentry);
2478 +
2479 +       dput(hidden_new_dentry);
2480 +       dput(hidden_old_dentry);
2481 +       if (!new_dentry->d_inode)
2482 +               d_drop(new_dentry);
2483 +
2484 + out:
2485 +       return err;
2486 +}
2487 +
2488 +
2489 +STATIC int
2490 +mini_fo_unlink(inode_t *dir, dentry_t *dentry)
2491 +{
2492 +       int err = 0;
2493 +
2494 +       dget(dentry);
2495 +       if(dtopd(dentry)->state == MODIFIED) {
2496 +               err = nondir_mod_to_del(dentry);
2497 +               goto out;
2498 +       }
2499 +       else if(dtopd(dentry)->state == UNMODIFIED) {
2500 +               err = nondir_unmod_to_del(dentry);
2501 +               goto out;
2502 +       }
2503 +       else if(dtopd(dentry)->state == CREATED) {
2504 +               err = nondir_creat_to_del(dentry);
2505 +               goto out;
2506 +       }
2507 +       else if(dtopd(dentry)->state == DEL_REWRITTEN) {
2508 +               err = nondir_del_rew_to_del(dentry);
2509 +               goto out;
2510 +       }
2511 +
2512 +       printk(KERN_CRIT "mini_fo_unlink: ERROR, invalid state detected.\n");
2513 +
2514 + out:
2515 +       fist_copy_attr_times(dir, itohi2(dentry->d_parent->d_inode));
2516 +
2517 +       if(!err) {
2518 +               /* is this causing my pain? d_delete(dentry); */
2519 +               d_drop(dentry);
2520 +       }
2521 +
2522 +       dput(dentry);
2523 +       return err;
2524 +}
2525 +
2526 +
2527 +STATIC int
2528 +mini_fo_symlink(inode_t *dir, dentry_t *dentry, const char *symname)
2529 +{
2530 +       int err=0;
2531 +       dentry_t *hidden_sto_dentry;
2532 +       dentry_t *hidden_sto_dir_dentry;
2533 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
2534 +        umode_t mode;
2535 +#endif
2536 +
2537 +       /* Fail if the symlink file exists */
2538 +       if(!(dtost(dentry) == DELETED || 
2539 +            dtost(dentry) == NON_EXISTANT)) {
2540 +               err = -EEXIST;
2541 +               goto out;
2542 +       }
2543 +
2544 +       err = get_neg_sto_dentry(dentry);
2545 +       if(err) {
2546 +               err = -EINVAL;
2547 +               goto out;
2548 +       }
2549 +       hidden_sto_dentry = dtohd2(dentry);
2550 +
2551 +       dget(hidden_sto_dentry);
2552 +       /* was: hidden_sto_dir_dentry = lock_parent(hidden_sto_dentry); */
2553 +       hidden_sto_dir_dentry = dget(hidden_sto_dentry->d_parent);
2554 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
2555 +       mutex_lock(&hidden_sto_dir_dentry->d_inode->i_mutex);
2556 +#else
2557 +       down(&hidden_sto_dir_dentry->d_inode->i_sem);
2558 +#endif
2559 +
2560 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
2561 +       mode = S_IALLUGO;
2562 +       err = vfs_symlink(hidden_sto_dir_dentry->d_inode,
2563 +                         hidden_sto_dentry, symname, mode);
2564 +#else
2565 +       err = vfs_symlink(hidden_sto_dir_dentry->d_inode,
2566 +                         hidden_sto_dentry,
2567 +                         symname);
2568 +#endif
2569 +       if (err || !hidden_sto_dentry->d_inode)
2570 +                goto out_lock;
2571 +
2572 +        if(dtost(dentry) == DELETED) {
2573 +                dtost(dentry) = DEL_REWRITTEN;
2574 +                err = mini_fo_tri_interpose(NULL, hidden_sto_dentry, dentry, dir->i_sb, 0);
2575 +                if(err)
2576 +                        goto out_lock;
2577 +        } else if(dtost(dentry) == NON_EXISTANT) {
2578 +                dtost(dentry) = CREATED;
2579 +                err = mini_fo_tri_interpose(dtohd(dentry), hidden_sto_dentry, dentry, dir->i_sb, 0);
2580 +                if(err)
2581 +                        goto out_lock;
2582 +        }
2583 +       fist_copy_attr_timesizes(dir, hidden_sto_dir_dentry->d_inode);
2584 +       
2585 + out_lock:
2586 +        /* was: unlock_dir(hidden_sto_dir_dentry); */
2587 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
2588 +       mutex_unlock(&hidden_sto_dir_dentry->d_inode->i_mutex);
2589 +#else
2590 +       up(&hidden_sto_dir_dentry->d_inode->i_sem);
2591 +#endif
2592 +       dput(hidden_sto_dir_dentry);
2593 +
2594 +        dput(hidden_sto_dentry);
2595 +        if (!dentry->d_inode)
2596 +                d_drop(dentry);
2597 + out:
2598 +        return err;
2599 +}
2600 +
2601 +STATIC int
2602 +mini_fo_mkdir(inode_t *dir, dentry_t *dentry, int mode)
2603 +{
2604 +       int err;
2605 +
2606 +       err = create_sto_dir(dentry, mode);
2607 +
2608 +       check_mini_fo_dentry(dentry);
2609 +
2610 +       return err;
2611 +}
2612 +
2613 +
2614 +STATIC int
2615 +mini_fo_rmdir(inode_t *dir, dentry_t *dentry)
2616 +{
2617 +       int err = 0;
2618 +       
2619 +       dentry_t *hidden_sto_dentry;
2620 +       dentry_t *hidden_sto_dir_dentry;
2621 +       dentry_t *meta_dentry;
2622 +       inode_t *hidden_sto_dir = NULL;
2623 +
2624 +       check_mini_fo_dentry(dentry);
2625 +       check_mini_fo_inode(dir);
2626 +
2627 +       dget(dentry);
2628 +       if(dtopd(dentry)->state == MODIFIED) {
2629 +               /* XXX: disabled, because it does not bother to check files on
2630 +                * the original filesystem - just a hack, but better than simply
2631 +                * removing it without testing */
2632 +               err = -EINVAL;
2633 +               goto out;
2634 +
2635 +               hidden_sto_dir = itohi2(dir);
2636 +               hidden_sto_dentry = dtohd2(dentry);
2637 +
2638 +               /* was:hidden_sto_dir_dentry = lock_parent(hidden_sto_dentry); */
2639 +               hidden_sto_dir_dentry = dget(hidden_sto_dentry->d_parent);
2640 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
2641 +               mutex_lock(&hidden_sto_dir_dentry->d_inode->i_mutex);
2642 +#else
2643 +               down(&hidden_sto_dir_dentry->d_inode->i_sem);
2644 +#endif
2645 +
2646 +               /* avoid destroying the hidden inode if the file is in use */
2647 +               dget(hidden_sto_dentry);
2648 +
2649 +               /* Delete an old WOL file contained in the storage dir */
2650 +               meta_dentry = lookup_one_len(META_FILENAME, 
2651 +                                            hidden_sto_dentry, 
2652 +                                            strlen(META_FILENAME));
2653 +               if(meta_dentry->d_inode) {
2654 +                       err = vfs_unlink(hidden_sto_dentry->d_inode, meta_dentry);
2655 +                       dput(meta_dentry);
2656 +                       if(!err)
2657 +                               d_delete(meta_dentry);
2658 +               }
2659 +
2660 +               err = vfs_rmdir(hidden_sto_dir, hidden_sto_dentry);
2661 +               dput(hidden_sto_dentry);
2662 +               if(!err)
2663 +                       d_delete(hidden_sto_dentry);
2664 +
2665 +               /* propagate number of hard-links */
2666 +               dentry->d_inode->i_nlink = itohi2(dentry->d_inode)->i_nlink;
2667 +
2668 +               dput(dtohd(dentry));
2669 +               
2670 +               dtohd(dentry) = NULL;
2671 +               dtopd(dentry)->state = DELETED;
2672 +
2673 +               /* carefull with R files */
2674 +               if( __meta_is_r_entry(dir, 
2675 +                                     dentry->d_name.name, 
2676 +                                     dentry->d_name.len) == 1) {
2677 +                       err = meta_remove_r_entry(dentry->d_parent, 
2678 +                                                 dentry->d_name.name,
2679 +                                                 dentry->d_name.len);
2680 +                       if(err) {
2681 +                               printk(KERN_CRIT "mini_fo: rmdir: meta_remove_r_entry failed.\n");
2682 +                               goto out;
2683 +                       }
2684 +               }
2685 +               else {
2686 +                       /* ok, add deleted file to META */              
2687 +                       meta_add_d_entry(dentry->d_parent, 
2688 +                                        dentry->d_name.name, 
2689 +                                        dentry->d_name.len);
2690 +               }
2691 +               /* was: unlock_dir(hidden_sto_dir_dentry); */
2692 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
2693 +               mutex_unlock(&hidden_sto_dir_dentry->d_inode->i_mutex);
2694 +#else
2695 +               up(&hidden_sto_dir_dentry->d_inode->i_sem);
2696 +#endif
2697 +               dput(hidden_sto_dir_dentry);
2698 +               goto out;
2699 +       }
2700 +       else if(dtopd(dentry)->state == UNMODIFIED) {
2701 +               /* XXX: simply adding it to the delete list here is fscking dangerous!
2702 +                * as a temporary hack, i will disable rmdir on unmodified directories 
2703 +                * for now.
2704 +                */
2705 +               err = -EINVAL;
2706 +               goto out;
2707 +
2708 +               err = get_neg_sto_dentry(dentry);
2709 +               if(err) {
2710 +                       err = -EINVAL;
2711 +                       goto out;
2712 +               }
2713 +               
2714 +               /* dput base dentry, this will relase the inode and free the
2715 +                * dentry, as we will never need it again. */
2716 +               dput(dtohd(dentry));
2717 +               dtohd(dentry) = NULL;
2718 +               dtopd(dentry)->state = DELETED;
2719 +
2720 +               /* add deleted file to META-file */
2721 +               meta_add_d_entry(dentry->d_parent, 
2722 +                                dentry->d_name.name, 
2723 +                                dentry->d_name.len);
2724 +               goto out;
2725 +       }
2726 +       else if(dtopd(dentry)->state == CREATED) {
2727 +               hidden_sto_dir = itohi2(dir);
2728 +               hidden_sto_dentry = dtohd2(dentry);
2729 +
2730 +               /* was: hidden_sto_dir_dentry = lock_parent(hidden_sto_dentry);*/
2731 +               hidden_sto_dir_dentry = dget(hidden_sto_dentry->d_parent);
2732 +
2733 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
2734 +               mutex_lock(&hidden_sto_dir_dentry->d_inode->i_mutex);
2735 +#else
2736 +               down(&hidden_sto_dir_dentry->d_inode->i_sem);
2737 +#endif
2738 +
2739 +               /* avoid destroying the hidden inode if the file is in use */
2740 +               dget(hidden_sto_dentry);
2741 +
2742 +               /* Delete an old WOL file contained in the storage dir */
2743 +               meta_dentry = lookup_one_len(META_FILENAME, 
2744 +                                            hidden_sto_dentry, 
2745 +                                            strlen(META_FILENAME));
2746 +               if(meta_dentry->d_inode) {
2747 +                       /* is this necessary? dget(meta_dentry); */
2748 +                       err = vfs_unlink(hidden_sto_dentry->d_inode, 
2749 +                                        meta_dentry);
2750 +                       dput(meta_dentry);
2751 +                       if(!err)
2752 +                               d_delete(meta_dentry);
2753 +               }
2754 +
2755 +               err = vfs_rmdir(hidden_sto_dir, hidden_sto_dentry);
2756 +               dput(hidden_sto_dentry);
2757 +               if(!err)
2758 +                       d_delete(hidden_sto_dentry);
2759 +
2760 +               /* propagate number of hard-links */
2761 +               dentry->d_inode->i_nlink = itohi2(dentry->d_inode)->i_nlink;
2762 +               dtopd(dentry)->state = NON_EXISTANT;
2763 +
2764 +               /* was: unlock_dir(hidden_sto_dir_dentry); */
2765 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
2766 +               mutex_unlock(&hidden_sto_dir_dentry->d_inode->i_mutex);
2767 +#else
2768 +               up(&hidden_sto_dir_dentry->d_inode->i_sem);
2769 +#endif
2770 +               dput(hidden_sto_dir_dentry);
2771 +
2772 +               goto out;
2773 +       }
2774 +       else if(dtopd(dentry)->state == DEL_REWRITTEN) {
2775 +               hidden_sto_dir = itohi2(dir);
2776 +               hidden_sto_dentry = dtohd2(dentry);
2777 +
2778 +               /* was: hidden_sto_dir_dentry = lock_parent(hidden_sto_dentry);*/
2779 +               hidden_sto_dir_dentry = dget(hidden_sto_dentry->d_parent);
2780 +
2781 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
2782 +               mutex_lock(&hidden_sto_dir_dentry->d_inode->i_mutex);
2783 +#else
2784 +               down(&hidden_sto_dir_dentry->d_inode->i_sem);
2785 +#endif
2786 +
2787 +               /* avoid destroying the hidden inode if the file is in use */
2788 +               dget(hidden_sto_dentry);
2789 +
2790 +               /* Delete an old WOL file contained in the storage dir */
2791 +               meta_dentry = lookup_one_len(META_FILENAME, 
2792 +                                            hidden_sto_dentry, 
2793 +                                            strlen(META_FILENAME));
2794 +               if(meta_dentry->d_inode) {
2795 +                       /* is this necessary? dget(meta_dentry); */
2796 +                       err = vfs_unlink(hidden_sto_dentry->d_inode,
2797 +                                        meta_dentry);
2798 +                       dput(meta_dentry);
2799 +                       if(!err)
2800 +                               d_delete(meta_dentry);
2801 +               }
2802 +
2803 +               err = vfs_rmdir(hidden_sto_dir, hidden_sto_dentry);
2804 +               dput(hidden_sto_dentry);
2805 +               if(!err)
2806 +                       d_delete(hidden_sto_dentry);
2807 +
2808 +               /* propagate number of hard-links */
2809 +               dentry->d_inode->i_nlink = itohi2(dentry->d_inode)->i_nlink;
2810 +               dtopd(dentry)->state = DELETED;
2811 +               /* was: unlock_dir(hidden_sto_dir_dentry); */
2812 +
2813 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
2814 +               mutex_unlock(&hidden_sto_dir_dentry->d_inode->i_mutex);
2815 +#else
2816 +               up(&hidden_sto_dir_dentry->d_inode->i_sem);
2817 +#endif
2818 +               dput(hidden_sto_dir_dentry);
2819 +               goto out;
2820 +       }
2821 +
2822 +       printk(KERN_CRIT "mini_fo_rmdir: ERROR, invalid state detected.\n");
2823 +
2824 + out:
2825 +       if(!err) {
2826 +               d_drop(dentry);
2827 +       }
2828 +               
2829 +       fist_copy_attr_times(dir, itohi2(dentry->d_parent->d_inode));
2830 +       dput(dentry);
2831 +
2832 +       return err;
2833 +}
2834 +
2835 +
2836 +STATIC int
2837 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
2838 +mini_fo_mknod(inode_t *dir, dentry_t *dentry, int mode, dev_t dev)
2839 +#else
2840 +mini_fo_mknod(inode_t *dir, dentry_t *dentry, int mode, int dev)
2841 +#endif
2842 +{
2843 +       int err = 0;
2844 +
2845 +       check_mini_fo_dentry(dentry);
2846 +
2847 +       err = create_sto_nod(dentry, mode, dev);
2848 +       if(err) {
2849 +               printk(KERN_CRIT "mini_fo_mknod: creating sto nod failed.\n");
2850 +               err = -EINVAL;
2851 +       }
2852 +       
2853 +       check_mini_fo_dentry(dentry);
2854 +       return err;
2855 +}
2856 +
2857 +
2858 +STATIC int
2859 +mini_fo_rename(inode_t *old_dir, dentry_t *old_dentry,
2860 +              inode_t *new_dir, dentry_t *new_dentry)
2861 +{
2862 +       /* dispatch */
2863 +       if(S_ISDIR(old_dentry->d_inode->i_mode))
2864 +               return rename_directory(old_dir, old_dentry, new_dir, new_dentry);
2865 +       return rename_nondir(old_dir, old_dentry, new_dir, new_dentry);
2866 +       
2867 +}
2868 +
2869 +int rename_directory(inode_t *old_dir, dentry_t *old_dentry,
2870 +                    inode_t *new_dir, dentry_t *new_dentry)
2871 +{
2872 +       int err, bpath_len;
2873 +       char *bpath;
2874 +
2875 +       dentry_t *hidden_old_dentry;
2876 +       dentry_t *hidden_new_dentry;
2877 +       dentry_t *hidden_old_dir_dentry;
2878 +       dentry_t *hidden_new_dir_dentry;
2879 +
2880 +       err = 0;
2881 +       bpath = NULL;
2882 +       bpath_len = 0;
2883 +
2884 +       /* this is a test, chuck out if it works */
2885 +       if(!(dtopd(new_dentry)->state == DELETED ||
2886 +            dtopd(new_dentry)->state == NON_EXISTANT)) {
2887 +               printk(KERN_CRIT "mini_fo: rename_directory: \
2888 +                                  uh, ah, new_dentry not negative.\n");
2889 +               /* return -1; */
2890 +       }
2891 +       
2892 +       /* state = UNMODIFIED */
2893 +       if(dtopd(old_dentry)->state == UNMODIFIED) {
2894 +               err = dir_unmod_to_mod(old_dentry);
2895 +               if (err) 
2896 +                       goto out;
2897 +       }
2898 +
2899 +       /* state = MODIFIED */
2900 +       if(dtopd(old_dentry)->state == MODIFIED) {
2901 +               bpath = meta_check_r_entry(old_dentry->d_parent, 
2902 +                                          old_dentry->d_name.name,
2903 +                                          old_dentry->d_name.len);
2904 +               if(bpath) {
2905 +                       err = meta_remove_r_entry(old_dentry->d_parent,
2906 +                                                 old_dentry->d_name.name,
2907 +                                                 old_dentry->d_name.len);
2908 +                       if(err) {
2909 +                               printk(KERN_CRIT "mini_fo: rename_directory:\
2910 +                                                   meta_remove_r_entry \
2911 +                                                  failed.\n");
2912 +                               goto out;
2913 +                       }
2914 +                       err = meta_add_r_entry(new_dentry->d_parent,
2915 +                                              bpath,
2916 +                                              strlen(bpath),
2917 +                                              new_dentry->d_name.name,
2918 +                                              new_dentry->d_name.len);
2919 +                       kfree(bpath);
2920 +               }
2921 +               else {/* wol it */
2922 +                       err = meta_add_d_entry(old_dentry->d_parent, 
2923 +                                              old_dentry->d_name.name,
2924 +                                              old_dentry->d_name.len);
2925 +                       if (err) 
2926 +                               goto out;
2927 +                       /* put it on rename list */
2928 +                       err = get_mini_fo_bpath(old_dentry,
2929 +                                               &bpath, 
2930 +                                               &bpath_len);
2931 +                       if (err) 
2932 +                               goto out;
2933 +                       err = meta_add_r_entry(new_dentry->d_parent,
2934 +                                              bpath, bpath_len,
2935 +                                              new_dentry->d_name.name,
2936 +                                              new_dentry->d_name.len);
2937 +                       if (err) 
2938 +                               goto out;
2939 +               }
2940 +               /* no state change, MODIFIED stays MODIFIED */
2941 +       }
2942 +       /* state = CREATED */
2943 +       if(dtopd(old_dentry)->state == CREATED ||
2944 +          dtopd(old_dentry)->state == DEL_REWRITTEN) {
2945 +               if(dtohd(old_dentry))
2946 +                       dput(dtohd(old_dentry));
2947 +               
2948 +               if(dtopd(new_dentry)->state == DELETED) {
2949 +                       dtopd(old_dentry)->state = DEL_REWRITTEN;
2950 +                       dtohd(old_dentry) = NULL;
2951 +               } 
2952 +               else if(dtopd(new_dentry)->state == NON_EXISTANT) {
2953 +                       dtopd(old_dentry)->state = CREATED;
2954 +                       /* steal new dentry's neg. base dentry */
2955 +                       dtohd(old_dentry) = dtohd(new_dentry);
2956 +                       dtohd(new_dentry) = NULL;
2957 +               }
2958 +       }               
2959 +       if(dtopd(new_dentry)->state == UNMODIFIED ||
2960 +          dtopd(new_dentry)->state == NON_EXISTANT) {
2961 +               err = get_neg_sto_dentry(new_dentry);
2962 +               if(err)
2963 +                       goto out;
2964 +       }
2965 +                       
2966 +       /* now move sto file */
2967 +       hidden_old_dentry = dtohd2(old_dentry);
2968 +       hidden_new_dentry = dtohd2(new_dentry);
2969 +       
2970 +       dget(hidden_old_dentry);
2971 +       dget(hidden_new_dentry);
2972 +       
2973 +       hidden_old_dir_dentry = dget(hidden_old_dentry->d_parent);
2974 +       hidden_new_dir_dentry = dget(hidden_new_dentry->d_parent);
2975 +       double_lock(hidden_old_dir_dentry, hidden_new_dir_dentry);
2976 +       
2977 +       err = vfs_rename(hidden_old_dir_dentry->d_inode, hidden_old_dentry,
2978 +                        hidden_new_dir_dentry->d_inode, hidden_new_dentry);
2979 +       if(err)
2980 +               goto out_lock;
2981 +       
2982 +       fist_copy_attr_all(new_dir, hidden_new_dir_dentry->d_inode);
2983 +       if (new_dir != old_dir)
2984 +               fist_copy_attr_all(old_dir, 
2985 +                                  hidden_old_dir_dentry->d_inode);
2986 +       
2987 + out_lock:
2988 +       /* double_unlock will dput the new/old parent dentries
2989 +        * whose refcnts were incremented via get_parent above. */
2990 +       double_unlock(hidden_old_dir_dentry, hidden_new_dir_dentry);
2991 +       dput(hidden_new_dentry);
2992 +       dput(hidden_old_dentry);
2993 +       
2994 + out:
2995 +       return err;
2996 +}
2997 +
2998 +int rename_nondir(inode_t *old_dir, dentry_t *old_dentry,
2999 +                 inode_t *new_dir, dentry_t *new_dentry)
3000 +{
3001 +       int err=0;
3002 +
3003 +       check_mini_fo_dentry(old_dentry);
3004 +       check_mini_fo_dentry(new_dentry);
3005 +       check_mini_fo_inode(old_dir);
3006 +       check_mini_fo_inode(new_dir);
3007 +
3008 +       /* state: UNMODIFIED */
3009 +       if(dtost(old_dentry) == UNMODIFIED) {
3010 +               err = nondir_unmod_to_mod(old_dentry, 1);
3011 +               if(err) {
3012 +                       err = -EINVAL;
3013 +                       goto out;
3014 +               }
3015 +       }
3016 +
3017 +       /* the easy states */
3018 +       if(exists_in_storage(old_dentry)) {
3019 +               
3020 +               dentry_t *hidden_old_dentry;
3021 +               dentry_t *hidden_new_dentry;
3022 +               dentry_t *hidden_old_dir_dentry;
3023 +               dentry_t *hidden_new_dir_dentry;
3024 +
3025 +               /* if old file is MODIFIED, add it to the deleted_list */
3026 +               if(dtopd(old_dentry)->state == MODIFIED) {
3027 +                       meta_add_d_entry(old_dentry->d_parent,
3028 +                                        old_dentry->d_name.name,
3029 +                                        old_dentry->d_name.len);
3030 +
3031 +                       dput(dtohd(old_dentry));
3032 +               }
3033 +               /* if old file is CREATED, we only release the base dentry */
3034 +               if(dtopd(old_dentry)->state == CREATED) {
3035 +                       if(dtohd(old_dentry))
3036 +                               dput(dtohd(old_dentry));
3037 +               }
3038 +
3039 +               /* now setup the new states (depends on new_dentry state) */
3040 +               /* new dentry state =  MODIFIED */
3041 +               if(dtopd(new_dentry)->state == MODIFIED) {
3042 +                       meta_add_d_entry(new_dentry->d_parent,
3043 +                                        new_dentry->d_name.name,
3044 +                                        new_dentry->d_name.len);
3045 +
3046 +                       /* new dentry will be d_put'ed later by the vfs
3047 +                        * so don't do it here
3048 +                        * dput(dtohd(new_dentry));
3049 +                        */
3050 +                       dtohd(old_dentry) = NULL;
3051 +                       dtopd(old_dentry)->state = DEL_REWRITTEN;
3052 +               }
3053 +               /* new dentry state =  UNMODIFIED */
3054 +               else if(dtopd(new_dentry)->state == UNMODIFIED) {
3055 +                       if(get_neg_sto_dentry(new_dentry))
3056 +                               return -EINVAL;
3057 +
3058 +                       meta_add_d_entry(new_dentry->d_parent,
3059 +                                        new_dentry->d_name.name,
3060 +                                        new_dentry->d_name.len);
3061 +
3062 +                       /* is this right??? */
3063 +                       /*dput(dtohd(new_dentry));*/
3064 +                       dtohd(old_dentry) = NULL;
3065 +                       dtopd(old_dentry)->state = DEL_REWRITTEN;
3066 +               }
3067 +               /* new dentry state =  CREATED */
3068 +               else if(dtopd(new_dentry)->state == CREATED) {
3069 +                       /* we keep the neg. base dentry (if exists) */
3070 +                       dtohd(old_dentry) = dtohd(new_dentry);
3071 +                       /* ...and set it to Null, or we'll get
3072 +                        * dcache.c:345 if it gets dput twice... */
3073 +                       dtohd(new_dentry) = NULL;
3074 +                       dtopd(old_dentry)->state = CREATED;
3075 +               }
3076 +               /* new dentry state =  NON_EXISTANT */
3077 +               else if(dtopd(new_dentry)->state == NON_EXISTANT) {
3078 +                       if(get_neg_sto_dentry(new_dentry))
3079 +                               return -EINVAL;
3080 +
3081 +                       /* we keep the neg. base dentry (if exists) */
3082 +                       dtohd(old_dentry) = dtohd(new_dentry);
3083 +                       /* ...and set it to Null, or we'll get 
3084 +                        * Dr. dcache.c:345 if it gets dput twice... */
3085 +                       dtohd(new_dentry) = NULL;
3086 +                       dtopd(old_dentry)->state = CREATED;
3087 +               }
3088 +               /* new dentry state =  DEL_REWRITTEN or DELETED */
3089 +               else if(dtopd(new_dentry)->state == DEL_REWRITTEN ||
3090 +                       dtopd(new_dentry)->state == DELETED) {
3091 +                       dtohd(old_dentry) = NULL;
3092 +                       dtopd(old_dentry)->state = DEL_REWRITTEN;
3093 +               }
3094 +               else { /* not possible, uhh, ahh */
3095 +                       printk(KERN_CRIT 
3096 +                              "mini_fo: rename_reg_file: invalid state detected [1].\n");
3097 +                       return -1;
3098 +               }
3099 +               
3100 +               /* now we definitely have a sto file */
3101 +               hidden_old_dentry = dtohd2(old_dentry);
3102 +               hidden_new_dentry = dtohd2(new_dentry);
3103 +
3104 +               dget(hidden_old_dentry);
3105 +               dget(hidden_new_dentry);
3106 +               
3107 +               hidden_old_dir_dentry = dget(hidden_old_dentry->d_parent);
3108 +               hidden_new_dir_dentry = dget(hidden_new_dentry->d_parent);
3109 +               double_lock(hidden_old_dir_dentry, hidden_new_dir_dentry);
3110 +
3111 +               err = vfs_rename(hidden_old_dir_dentry->d_inode, 
3112 +                                hidden_old_dentry,
3113 +                                hidden_new_dir_dentry->d_inode, 
3114 +                                hidden_new_dentry);
3115 +               if(err) 
3116 +                       goto out_lock;
3117 +
3118 +               fist_copy_attr_all(new_dir, hidden_new_dir_dentry->d_inode);
3119 +               if (new_dir != old_dir)
3120 +                       fist_copy_attr_all(old_dir, hidden_old_dir_dentry->d_inode);
3121 +               
3122 +       out_lock:
3123 +               /* double_unlock will dput the new/old parent dentries 
3124 +                * whose refcnts were incremented via get_parent above.
3125 +                */
3126 +               double_unlock(hidden_old_dir_dentry, hidden_new_dir_dentry);
3127 +               dput(hidden_new_dentry);
3128 +               dput(hidden_old_dentry);
3129 +       out:            
3130 +               return err;
3131 +       }
3132 +       else { /* invalid state */
3133 +               printk(KERN_CRIT "mini_fo: rename_reg_file: ERROR: invalid state detected [2].\n");
3134 +               return -1;
3135 +       }
3136 +}
3137 +
3138 +
3139 +STATIC int
3140 +mini_fo_readlink(dentry_t *dentry, char *buf, int bufsiz)
3141 +{
3142 +       int err=0;
3143 +       dentry_t *hidden_dentry = NULL;
3144 +
3145 +       if(dtohd2(dentry) && dtohd2(dentry)->d_inode) {
3146 +               hidden_dentry = dtohd2(dentry);
3147 +       } else if(dtohd(dentry) && dtohd(dentry)->d_inode) {
3148 +               hidden_dentry = dtohd(dentry);
3149 +       } else {
3150 +               goto out;
3151 +       }
3152 +
3153 +       if (!hidden_dentry->d_inode->i_op ||
3154 +           !hidden_dentry->d_inode->i_op->readlink) {
3155 +               err = -EINVAL;          goto out;
3156 +       }
3157 +
3158 +       err = hidden_dentry->d_inode->i_op->readlink(hidden_dentry,
3159 +                                                    buf,
3160 +                                                    bufsiz);
3161 +       if (err > 0)
3162 +               fist_copy_attr_atime(dentry->d_inode, hidden_dentry->d_inode);
3163 +
3164 + out:
3165 +       return err;
3166 +}
3167 +
3168 +
3169 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,13)
3170 +static int mini_fo_follow_link(dentry_t *dentry, struct nameidata *nd)
3171 +#else
3172 +static void* mini_fo_follow_link(dentry_t *dentry, struct nameidata *nd)
3173 +#endif
3174 +{
3175 +       char *buf;
3176 +       int len = PAGE_SIZE, err;
3177 +       mm_segment_t old_fs;
3178 +
3179 +       /* in 2.6 this is freed by mini_fo_put_link called by __do_follow_link */
3180 +       buf = kmalloc(len, GFP_KERNEL);
3181 +       if (!buf) {
3182 +               err = -ENOMEM;
3183 +               goto out;
3184 +       }
3185 +
3186 +       /* read the symlink, and then we will follow it */
3187 +       old_fs = get_fs();
3188 +       set_fs(KERNEL_DS);
3189 +       err = dentry->d_inode->i_op->readlink(dentry, buf, len);
3190 +       set_fs(old_fs);
3191 +       if (err < 0) {
3192 +               kfree(buf);
3193 +               buf = NULL;
3194 +               goto out;
3195 +       }
3196 +       buf[err] = 0;
3197 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
3198 +        nd_set_link(nd, buf);
3199 +        err = 0;
3200 +#else
3201 +       err = vfs_follow_link(nd, buf);
3202 +#endif
3203 +
3204 + out:
3205 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
3206 +       kfree(buf);
3207 +#endif
3208 +
3209 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,13)
3210 +        return err;
3211 +#else
3212 +        return ERR_PTR(err);
3213 +#endif
3214 +}
3215 +
3216 +STATIC
3217 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
3218 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,13)
3219 +void mini_fo_put_link(struct dentry *dentry, struct nameidata *nd)
3220 +#else
3221 +void mini_fo_put_link(struct dentry *dentry, struct nameidata *nd, void *cookie)
3222 +#endif
3223 +{
3224 +        char *link;
3225 +        link = nd_get_link(nd);
3226 +        kfree(link);
3227 +}
3228 +#endif
3229 +
3230 +STATIC int
3231 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
3232 +mini_fo_permission(inode_t *inode, int mask, struct nameidata *nd)
3233 +#else
3234 +mini_fo_permission(inode_t *inode, int mask)
3235 +#endif
3236 +{
3237 +       inode_t *hidden_inode;
3238 +       int mode;
3239 +       int err;
3240 +
3241 +       if(itohi2(inode)) {
3242 +               hidden_inode = itohi2(inode);
3243 +       } else {
3244 +               hidden_inode = itohi(inode);
3245 +       }
3246 +       mode = inode->i_mode;
3247 +
3248 +       /* not really needed, as permission handles everything:
3249 +        *      err = vfs_permission(inode, mask);
3250 +        *      if (err)
3251 +        *              goto out;
3252 +        */
3253 +       
3254 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
3255 +       err = permission(hidden_inode, mask, nd);
3256 +#else
3257 +       err = permission(hidden_inode, mask);
3258 +#endif
3259 +       
3260 +       /*  out: */
3261 +       return err;
3262 +}
3263 +
3264 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
3265 +STATIC int
3266 +mini_fo_inode_revalidate(dentry_t *dentry)
3267 +{
3268 +       int err = 0;
3269 +       dentry_t *hidden_dentry;
3270 +       inode_t *hidden_inode;
3271 +
3272 +       ASSERT(dentry->d_inode);
3273 +       ASSERT(itopd(dentry->d_inode));
3274 +
3275 +       if(itohi2(dentry->d_inode)) {
3276 +                hidden_dentry = dtohd2(dentry);
3277 +               hidden_inode = hidden_dentry->d_inode;
3278 +       } else if(itohi(dentry->d_inode)) {
3279 +                hidden_dentry = dtohd(dentry);
3280 +               hidden_inode = hidden_dentry->d_inode;
3281 +       } else {
3282 +                printk(KERN_CRIT "mini_fo_inode_revalidate: ERROR, invalid state detected.\n");
3283 +                err = -ENOENT;
3284 +                goto out;
3285 +        }
3286 +       if (hidden_inode && hidden_inode->i_op && hidden_inode->i_op->revalidate){
3287 +               err = hidden_inode->i_op->revalidate(hidden_dentry);
3288 +               if (err)
3289 +                       goto out;
3290 +       }
3291 +       fist_copy_attr_all(dentry->d_inode, hidden_inode);
3292 + out:
3293 +       return err;
3294 +}
3295 +#endif
3296 +
3297 +STATIC int
3298 +mini_fo_setattr(dentry_t *dentry, struct iattr *ia)
3299 +{
3300 +       int err = 0;
3301 +
3302 +       check_mini_fo_dentry(dentry);
3303 +       
3304 +       if(!is_mini_fo_existant(dentry)) {
3305 +               printk(KERN_CRIT "mini_fo_setattr: ERROR, invalid state detected [1].\n");
3306 +               goto out;
3307 +       }
3308 +
3309 +       if(dtost(dentry) == UNMODIFIED) {
3310 +               if(!IS_COPY_FLAG(ia->ia_valid))
3311 +                       goto out; /* we ignore these changes to base */
3312 +
3313 +               if(S_ISDIR(dentry->d_inode->i_mode)) {
3314 +                       err = dir_unmod_to_mod(dentry);
3315 +               } else {
3316 +                       /* we copy contents if file is not beeing truncated */
3317 +                       if(S_ISREG(dentry->d_inode->i_mode) && 
3318 +                          !(ia->ia_size == 0 && (ia->ia_valid & ATTR_SIZE))) {
3319 +                               err = nondir_unmod_to_mod(dentry, 1);
3320 +                       } else
3321 +                               err = nondir_unmod_to_mod(dentry, 0);
3322 +               }
3323 +               if(err) {
3324 +                       err = -EINVAL;
3325 +                       printk(KERN_CRIT "mini_fo_setattr: ERROR changing states.\n");
3326 +                       goto out;
3327 +               }
3328 +       }
3329 +       if(!exists_in_storage(dentry)) {
3330 +               printk(KERN_CRIT "mini_fo_setattr: ERROR, invalid state detected [2].\n");
3331 +               err = -EINVAL;
3332 +               goto out;
3333 +       }
3334 +       ASSERT(dentry->d_inode);
3335 +       ASSERT(dtohd2(dentry));
3336 +       ASSERT(itopd(dentry->d_inode));
3337 +       ASSERT(itohi2(dentry->d_inode));
3338 +       
3339 +       err = notify_change(dtohd2(dentry), ia);
3340 +       fist_copy_attr_all(dentry->d_inode, itohi2(dentry->d_inode));
3341 + out:
3342 +       return err;
3343 +}
3344 +
3345 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
3346 +STATIC int
3347 +mini_fo_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
3348 +{
3349 +       int err = 0;
3350 +        dentry_t *hidden_dentry;
3351 +
3352 +       ASSERT(dentry->d_inode);
3353 +       ASSERT(itopd(dentry->d_inode));
3354 +
3355 +       if(itohi2(dentry->d_inode)) {
3356 +                hidden_dentry = dtohd2(dentry);
3357 +       } else if(itohi(dentry->d_inode)) {
3358 +                hidden_dentry = dtohd(dentry);
3359 +       } else {
3360 +                printk(KERN_CRIT "mini_fo_getattr: ERROR, invalid state detected.\n");
3361 +                err = -ENOENT;
3362 +                goto out;
3363 +        }
3364 +       fist_copy_attr_all(dentry->d_inode, hidden_dentry->d_inode);
3365 +
3366 +       ASSERT(hidden_dentry);
3367 +       ASSERT(hidden_dentry->d_inode);
3368 +       ASSERT(hidden_dentry->d_inode->i_op);
3369 +
3370 +       generic_fillattr(dentry->d_inode, stat);
3371 +       if (!stat->blksize) {
3372 +               struct super_block *s = hidden_dentry->d_inode->i_sb;
3373 +               unsigned blocks;
3374 +               blocks = (stat->size+s->s_blocksize-1) >> s->s_blocksize_bits;
3375 +               stat->blocks = (s->s_blocksize / 512) * blocks;
3376 +               stat->blksize = s->s_blocksize;
3377 +       }
3378 + out:
3379 +        return err;
3380 +}
3381 +#endif
3382 +
3383 +#if defined(XATTR) && (LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,20))
3384 +#if 0 /* no xattr_alloc() and xattr_free() */
3385 +/* This is lifted from fs/xattr.c */
3386 +static void *
3387 +xattr_alloc(size_t size, size_t limit)
3388 +{
3389 +       void *ptr;
3390 +
3391 +       if (size > limit)
3392 +               return ERR_PTR(-E2BIG);
3393 +
3394 +       if (!size)      /* size request, no buffer is needed */
3395 +               return NULL;
3396 +       else if (size <= PAGE_SIZE)
3397 +               ptr = kmalloc((unsigned long) size, GFP_KERNEL);
3398 +       else
3399 +               ptr = vmalloc((unsigned long) size);
3400 +       if (!ptr)
3401 +               return ERR_PTR(-ENOMEM);
3402 +       return ptr;
3403 +}
3404 +
3405 +static void
3406 +xattr_free(void *ptr, size_t size)
3407 +{
3408 +       if (!size)      /* size request, no buffer was needed */
3409 +               return;
3410 +       else if (size <= PAGE_SIZE)
3411 +               kfree(ptr);
3412 +       else
3413 +               vfree(ptr);
3414 +}
3415 +#endif /* no xattr_alloc() and xattr_free() */
3416 +
3417 +/* BKL held by caller.
3418 + * dentry->d_inode->i_sem down
3419 + */
3420 +STATIC int
3421 +mini_fo_getxattr(struct dentry *dentry, const char *name, void *value, size_t size) {
3422 +       struct dentry *hidden_dentry = NULL;
3423 +       int err = -EOPNOTSUPP;
3424 +       /* Define these anyway so we don't need as much ifdef'ed code. */
3425 +       char *encoded_name = NULL;
3426 +       char *encoded_value = NULL;
3427 +
3428 +       check_mini_fo_dentry(dentry);
3429 +
3430 +       if(exists_in_storage(dentry))
3431 +               hidden_dentry = dtohd2(dentry);
3432 +       else
3433 +               hidden_dentry = dtohd(dentry);
3434 +          
3435 +       ASSERT(hidden_dentry);
3436 +       ASSERT(hidden_dentry->d_inode);
3437 +       ASSERT(hidden_dentry->d_inode->i_op);
3438 +
3439 +       if (hidden_dentry->d_inode->i_op->getxattr) {
3440 +               encoded_name = (char *)name;
3441 +               encoded_value = (char *)value;
3442 +
3443 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
3444 +               mutex_lock(&hidden_dentry->d_inode->i_mutex);
3445 +#else
3446 +               down(&hidden_dentry->d_inode->i_sem);
3447 +#endif
3448 +               /* lock_kernel() already done by caller. */
3449 +               err = hidden_dentry->d_inode->i_op->getxattr(hidden_dentry, encoded_name, encoded_value, size);
3450 +               /* unlock_kernel() will be done by caller. */
3451 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
3452 +               mutex_lock(&hidden_dentry->d_inode->i_mutex);
3453 +#else
3454 +               up(&hidden_dentry->d_inode->i_sem);
3455 +#endif
3456 +       }
3457 +       return err;
3458 +}
3459 +
3460 +/* BKL held by caller.
3461 + * dentry->d_inode->i_sem down
3462 + */
3463 +STATIC int
3464 +#if ((LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,21) \
3465 +     && LINUX_VERSION_CODE <= KERNEL_VERSION(2,4,23)) \
3466 +     || LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0))
3467 +mini_fo_setxattr(struct dentry *dentry, const char *name, 
3468 +                const void *value, size_t size, int flags)
3469 +#else
3470 +mini_fo_setxattr(struct dentry *dentry, const char *name, 
3471 +                void *value, size_t size, int flags)
3472 +#endif
3473 +
3474 +{
3475 +       struct dentry *hidden_dentry = NULL;
3476 +       int err = -EOPNOTSUPP;
3477 +
3478 +       /* Define these anyway, so we don't have as much ifdef'ed code. */
3479 +       char *encoded_value = NULL;
3480 +       char *encoded_name = NULL;
3481 +
3482 +       check_mini_fo_dentry(dentry);
3483 +
3484 +       if(exists_in_storage(dentry))
3485 +               hidden_dentry = dtohd2(dentry);
3486 +       else
3487 +               hidden_dentry = dtohd(dentry);
3488 +       
3489 +       ASSERT(hidden_dentry);
3490 +       ASSERT(hidden_dentry->d_inode);
3491 +       ASSERT(hidden_dentry->d_inode->i_op);
3492 +
3493 +       if (hidden_dentry->d_inode->i_op->setxattr) {
3494 +               encoded_name = (char *)name;
3495 +               encoded_value = (char *)value;
3496 +
3497 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
3498 +               mutex_lock(&hidden_dentry->d_inode->i_mutex);
3499 +#else
3500 +               down(&hidden_dentry->d_inode->i_sem);
3501 +#endif
3502 +               /* lock_kernel() already done by caller. */
3503 +               err = hidden_dentry->d_inode->i_op->setxattr(hidden_dentry, encoded_name, encoded_value, size, flags);
3504 +               /* unlock_kernel() will be done by caller. */
3505 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
3506 +               mutex_unlock(&hidden_dentry->d_inode->i_mutex);
3507 +#else
3508 +               up(&hidden_dentry->d_inode->i_sem);
3509 +#endif
3510 +       }
3511 +       return err;
3512 +}
3513 +
3514 +/* BKL held by caller.
3515 + * dentry->d_inode->i_sem down
3516 + */
3517 +STATIC int
3518 +mini_fo_removexattr(struct dentry *dentry, const char *name) {
3519 +       struct dentry *hidden_dentry = NULL;
3520 +       int err = -EOPNOTSUPP;
3521 +       char *encoded_name;
3522 +
3523 +       check_mini_fo_dentry(dentry);
3524 +
3525 +       if(exists_in_storage(dentry))
3526 +               hidden_dentry = dtohd2(dentry);
3527 +       else
3528 +               hidden_dentry = dtohd(dentry);
3529 +       
3530 +       ASSERT(hidden_dentry);
3531 +       ASSERT(hidden_dentry->d_inode);
3532 +       ASSERT(hidden_dentry->d_inode->i_op);
3533 +
3534 +       if (hidden_dentry->d_inode->i_op->removexattr) {
3535 +               encoded_name = (char *)name;
3536 +
3537 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
3538 +               mutex_lock(&hidden_dentry->d_inode->i_mutex);
3539 +#else
3540 +               down(&hidden_dentry->d_inode->i_sem);
3541 +#endif
3542 +               /* lock_kernel() already done by caller. */
3543 +               err = hidden_dentry->d_inode->i_op->removexattr(hidden_dentry, encoded_name);
3544 +               /* unlock_kernel() will be done by caller. */
3545 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
3546 +               mutex_unlock(&hidden_dentry->d_inode->i_mutex);
3547 +#else
3548 +               up(&hidden_dentry->d_inode->i_sem);
3549 +#endif
3550 +       }
3551 +       return err;
3552 +}
3553 +
3554 +/* BKL held by caller.
3555 + * dentry->d_inode->i_sem down
3556 + */
3557 +STATIC int
3558 +mini_fo_listxattr(struct dentry *dentry, char *list, size_t size) {
3559 +       struct dentry *hidden_dentry = NULL;
3560 +       int err = -EOPNOTSUPP;
3561 +       char *encoded_list = NULL;
3562 +
3563 +       check_mini_fo_dentry(dentry);
3564 +
3565 +       if(exists_in_storage(dentry))
3566 +               hidden_dentry = dtohd2(dentry);
3567 +       else
3568 +               hidden_dentry = dtohd(dentry);
3569 +
3570 +       ASSERT(hidden_dentry);
3571 +       ASSERT(hidden_dentry->d_inode);
3572 +       ASSERT(hidden_dentry->d_inode->i_op);
3573 +
3574 +       if (hidden_dentry->d_inode->i_op->listxattr) {
3575 +               encoded_list = list;
3576 +
3577 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
3578 +               mutex_lock(&hidden_dentry->d_inode->i_mutex);
3579 +#else
3580 +               down(&hidden_dentry->d_inode->i_sem);
3581 +#endif
3582 +               /* lock_kernel() already done by caller. */
3583 +               err = hidden_dentry->d_inode->i_op->listxattr(hidden_dentry, encoded_list, size);
3584 +               /* unlock_kernel() will be done by caller. */
3585 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
3586 +               mutex_unlock(&hidden_dentry->d_inode->i_mutex);
3587 +#else
3588 +               up(&hidden_dentry->d_inode->i_sem);
3589 +#endif
3590 +       }
3591 +       return err;
3592 +}
3593 +# endif /* defined(XATTR) && (LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,20)) */
3594 +
3595 +struct inode_operations mini_fo_symlink_iops =
3596 +       {
3597 +               readlink:       mini_fo_readlink,
3598 +               follow_link: mini_fo_follow_link,
3599 +               /* mk: permission:      mini_fo_permission, */
3600 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
3601 +               revalidate:     mini_fo_inode_revalidate,
3602 +#endif
3603 +               setattr:        mini_fo_setattr,
3604 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
3605 +               getattr:        mini_fo_getattr,
3606 +               put_link:       mini_fo_put_link,
3607 +#endif
3608 +
3609 +#if defined(XATTR) && (LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,20))
3610 +               setxattr:       mini_fo_setxattr,
3611 +               getxattr:       mini_fo_getxattr,
3612 +               listxattr:      mini_fo_listxattr,
3613 +               removexattr: mini_fo_removexattr
3614 +# endif /* defined(XATTR) && (LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,20)) */
3615 +       };
3616 +
3617 +struct inode_operations mini_fo_dir_iops =
3618 +       {
3619 +               create: mini_fo_create,
3620 +               lookup: mini_fo_lookup,
3621 +               link:   mini_fo_link,
3622 +               unlink: mini_fo_unlink,
3623 +               symlink:        mini_fo_symlink,
3624 +               mkdir:  mini_fo_mkdir,
3625 +               rmdir:  mini_fo_rmdir,
3626 +               mknod:  mini_fo_mknod,
3627 +               rename: mini_fo_rename,
3628 +               /* no readlink/follow_link for non-symlinks */
3629 +               // off because we have setattr
3630 +               //    truncate: mini_fo_truncate,
3631 +               /* mk:permission:       mini_fo_permission, */
3632 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
3633 +               revalidate:     mini_fo_inode_revalidate,
3634 +#endif
3635 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
3636 +               getattr:        mini_fo_getattr,
3637 +#endif
3638 +               setattr:        mini_fo_setattr,
3639 +#if defined(XATTR) && (LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,20))
3640 +               setxattr:       mini_fo_setxattr,
3641 +               getxattr:       mini_fo_getxattr,
3642 +               listxattr:      mini_fo_listxattr,
3643 +               removexattr: mini_fo_removexattr
3644 +# endif /* XATTR && LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,20) */
3645 +       };
3646 +
3647 +struct inode_operations mini_fo_main_iops =
3648 +       {
3649 +               /* permission:  mini_fo_permission, */
3650 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
3651 +               revalidate:     mini_fo_inode_revalidate,
3652 +#endif
3653 +               setattr:        mini_fo_setattr,
3654 +
3655 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
3656 +               getattr:        mini_fo_getattr,
3657 +#endif
3658 +#if defined(XATTR) && (LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,20))
3659 +               setxattr:       mini_fo_setxattr,
3660 +               getxattr:       mini_fo_getxattr,
3661 +               listxattr:      mini_fo_listxattr,
3662 +               removexattr:    mini_fo_removexattr
3663 +# endif /* XATTR && LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,20) */
3664 +       };
3665 diff -urN linux.old/fs/mini_fo/main.c linux.dev/fs/mini_fo/main.c
3666 --- linux.old/fs/mini_fo/main.c 1970-01-01 01:00:00.000000000 +0100
3667 +++ linux.dev/fs/mini_fo/main.c 2006-11-17 03:11:48.000000000 +0100
3668 @@ -0,0 +1,414 @@
3669 +/*
3670 + * Copyright (c) 1997-2003 Erez Zadok
3671 + * Copyright (c) 2001-2003 Stony Brook University
3672 + *
3673 + * For specific licensing information, see the COPYING file distributed with
3674 + * this package, or get one from ftp://ftp.filesystems.org/pub/fist/COPYING.
3675 + *
3676 + * This Copyright notice must be kept intact and distributed with all
3677 + * fistgen sources INCLUDING sources generated by fistgen.
3678 + */
3679 +/*
3680 + * Copyright (C) 2004, 2005 Markus Klotzbuecher <mk@creamnet.de>
3681 + *
3682 + * This program is free software; you can redistribute it and/or
3683 + * modify it under the terms of the GNU General Public License
3684 + * as published by the Free Software Foundation; either version
3685 + * 2 of the License, or (at your option) any later version.
3686 + */
3687 +
3688 +/*
3689 + *  $Id$
3690 + */
3691 +
3692 +#ifdef HAVE_CONFIG_H
3693 +# include <config.h>
3694 +#endif
3695 +
3696 +#include "fist.h"
3697 +#include "mini_fo.h"
3698 +#include <linux/module.h>
3699 +
3700 +/* This definition must only appear after we include <linux/module.h> */
3701 +#ifndef MODULE_LICENSE
3702 +# define MODULE_LICENSE(bison)
3703 +#endif /* not MODULE_LICENSE */
3704 +
3705 +/*
3706 + * This is the mini_fo tri interpose function, which extends the
3707 + * functionality of the regular interpose by interposing a higher
3708 + * level inode on top of two lower level ones: the base filesystem
3709 + * inode and the storage filesystem inode.
3710 + *
3711 + *  sb we pass is mini_fo's super_block
3712 + */
3713 +int
3714 +mini_fo_tri_interpose(dentry_t *hidden_dentry,
3715 +                     dentry_t *hidden_sto_dentry,
3716 +                     dentry_t *dentry, super_block_t *sb, int flag)
3717 +{
3718 +       inode_t *hidden_inode = NULL;
3719 +       inode_t *hidden_sto_inode = NULL; /* store corresponding storage inode */
3720 +       int err = 0;
3721 +       inode_t *inode;
3722 +
3723 +       /* Pointer to hidden_sto_inode if exists, else to hidden_inode.
3724 +        * This is used to copy the attributes of the correct inode. */
3725 +       inode_t *master_inode;
3726 +
3727 +       if(hidden_dentry)
3728 +               hidden_inode = hidden_dentry->d_inode;
3729 +       if(hidden_sto_dentry)
3730 +               hidden_sto_inode = hidden_sto_dentry->d_inode;
3731 +
3732 +       ASSERT(dentry->d_inode == NULL);
3733 +
3734 +       /* mk: One of the inodes associated with the dentrys is likely to
3735 +        * be NULL, so carefull:
3736 +        */
3737 +       ASSERT((hidden_inode != NULL) || (hidden_sto_inode != NULL));
3738 +
3739 +       if(hidden_sto_inode)
3740 +               master_inode = hidden_sto_inode;
3741 +       else
3742 +               master_inode = hidden_inode;
3743 +
3744 +       /*
3745 +        * We allocate our new inode below, by calling iget.
3746 +        * iget will call our read_inode which will initialize some
3747 +        * of the new inode's fields
3748 +        */
3749 +
3750 +       /*
3751 +        * original: inode = iget(sb, hidden_inode->i_ino);
3752 +        */
3753 +       inode = iget(sb, iunique(sb, 25));
3754 +       if (!inode) {
3755 +               err = -EACCES;          /* should be impossible??? */
3756 +               goto out;
3757 +       }
3758 +
3759 +       /*
3760 +        * interpose the inode if not already interposed
3761 +        *   this is possible if the inode is being reused
3762 +        * XXX: what happens if we get_empty_inode() but there's another already?
3763 +        * for now, ASSERT() that this can't happen; fix later.
3764 +        */
3765 +       if (itohi(inode) != NULL) {
3766 +               printk(KERN_CRIT "mini_fo_tri_interpose: itohi(inode) != NULL.\n");
3767 +       }
3768 +       if (itohi2(inode) != NULL) {
3769 +               printk(KERN_CRIT "mini_fo_tri_interpose: itohi2(inode) != NULL.\n");
3770 +       }
3771 +
3772 +       /* mk: Carefull, igrab can't handle NULL inodes (ok, why should it?), so
3773 +        * we need to check here:
3774 +        */
3775 +       if(hidden_inode)
3776 +               itohi(inode) = igrab(hidden_inode);
3777 +       else
3778 +               itohi(inode) = NULL;
3779 +
3780 +       if(hidden_sto_inode)
3781 +               itohi2(inode) = igrab(hidden_sto_inode);
3782 +       else
3783 +               itohi2(inode) = NULL;
3784 +
3785 +
3786 +       /* Use different set of inode ops for symlinks & directories*/
3787 +       if (S_ISLNK(master_inode->i_mode))
3788 +               inode->i_op = &mini_fo_symlink_iops;
3789 +       else if (S_ISDIR(master_inode->i_mode))
3790 +               inode->i_op = &mini_fo_dir_iops;
3791 +
3792 +       /* Use different set of file ops for directories */
3793 +       if (S_ISDIR(master_inode->i_mode))
3794 +               inode->i_fop = &mini_fo_dir_fops;
3795 +
3796 +       /* properly initialize special inodes */
3797 +       if (S_ISBLK(master_inode->i_mode) || S_ISCHR(master_inode->i_mode) ||
3798 +           S_ISFIFO(master_inode->i_mode) || S_ISSOCK(master_inode->i_mode)) {
3799 +               init_special_inode(inode, master_inode->i_mode, master_inode->i_rdev);
3800 +       }
3801 +
3802 +       /* Fix our inode's address operations to that of the lower inode */
3803 +       if (inode->i_mapping->a_ops != master_inode->i_mapping->a_ops) {
3804 +               inode->i_mapping->a_ops = master_inode->i_mapping->a_ops;
3805 +       }
3806 +
3807 +       /* only (our) lookup wants to do a d_add */
3808 +       if (flag)
3809 +               d_add(dentry, inode);
3810 +       else
3811 +               d_instantiate(dentry, inode);
3812 +
3813 +       ASSERT(dtopd(dentry) != NULL);
3814 +
3815 +       /* all well, copy inode attributes */
3816 +       fist_copy_attr_all(inode, master_inode);
3817 +
3818 + out:
3819 +       return err;
3820 +}
3821 +
3822 +/* parse mount options "base=" and "sto=" */
3823 +dentry_t *
3824 +mini_fo_parse_options(super_block_t *sb, char *options)
3825 +{
3826 +       dentry_t *hidden_root = ERR_PTR(-EINVAL);
3827 +       dentry_t *hidden_root2 = ERR_PTR(-EINVAL);
3828 +       struct nameidata nd, nd2; 
3829 +       char *name, *tmp, *end;
3830 +       int err = 0;
3831 +
3832 +       /* We don't want to go off the end of our arguments later on. */
3833 +       for (end = options; *end; end++);
3834 +
3835 +       while (options < end) {
3836 +               tmp = options;
3837 +               while (*tmp && *tmp != ',')
3838 +                       tmp++;
3839 +               *tmp = '\0';
3840 +               if (!strncmp("base=", options, 5)) {
3841 +                       name = options + 5;
3842 +                       printk(KERN_INFO "mini_fo: using base directory: %s\n", name);
3843 +
3844 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
3845 +                       if (path_init(name, LOOKUP_FOLLOW, &nd))
3846 +                               err = path_walk(name, &nd);
3847 +#else
3848 +                       err = path_lookup(name, LOOKUP_FOLLOW, &nd);
3849 +#endif
3850 +                       if (err) {
3851 +                               printk(KERN_CRIT "mini_fo: error accessing hidden directory '%s'\n", name);
3852 +                               hidden_root = ERR_PTR(err);
3853 +                               goto out;
3854 +                       }
3855 +                       hidden_root = nd.dentry;
3856 +                       stopd(sb)->base_dir_dentry = nd.dentry;
3857 +                       stopd(sb)->hidden_mnt = nd.mnt;
3858 +
3859 +               } else if(!strncmp("sto=", options, 4)) {
3860 +                       /* parse the storage dir */
3861 +                       name = options + 4;
3862 +                       printk(KERN_INFO "mini_fo: using storage directory: %s\n", name);
3863 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
3864 +                       if(path_init(name, LOOKUP_FOLLOW, &nd2))
3865 +                               err = path_walk(name, &nd2);
3866 +#else
3867 +                        err = path_lookup(name, LOOKUP_FOLLOW, &nd2);
3868 +#endif
3869 +                       if(err) {
3870 +                               printk(KERN_CRIT "mini_fo: error accessing hidden storage directory '%s'\n", name);
3871 +
3872 +                               hidden_root2 = ERR_PTR(err);
3873 +                               goto out;
3874 +                       }
3875 +                       hidden_root2 = nd2.dentry;
3876 +                       stopd(sb)->storage_dir_dentry = nd2.dentry;
3877 +                       stopd(sb)->hidden_mnt2 = nd2.mnt;
3878 +                       stohs2(sb) = hidden_root2->d_sb;
3879 +
3880 +                       /* validate storage dir, this is done in 
3881 +                        * mini_fo_read_super for the base directory.
3882 +                        */
3883 +                       if (IS_ERR(hidden_root2)) {
3884 +                               printk(KERN_WARNING "mini_fo_parse_options: storage dentry lookup failed (err = %ld)\n", PTR_ERR(hidden_root2));
3885 +                               goto out;
3886 +                       }
3887 +                       if (!hidden_root2->d_inode) {
3888 +                               printk(KERN_WARNING "mini_fo_parse_options: no storage dir to interpose on.\n");
3889 +                               goto out;
3890 +                       }
3891 +                       stohs2(sb) = hidden_root2->d_sb;
3892 +               } else {
3893 +                       printk(KERN_WARNING "mini_fo: unrecognized option '%s'\n", options);
3894 +                       hidden_root = ERR_PTR(-EINVAL);
3895 +                       goto out;
3896 +               }
3897 +               options = tmp + 1;
3898 +       }
3899 +
3900 + out:
3901 +       if(IS_ERR(hidden_root2))
3902 +               return hidden_root2;
3903 +       return hidden_root;
3904 +}
3905 +
3906 +
3907 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
3908 +static int
3909 +#else
3910 +super_block_t *
3911 +#endif
3912 +mini_fo_read_super(super_block_t *sb, void *raw_data, int silent)
3913 +{
3914 +       dentry_t *hidden_root;
3915 +       int err = 0;
3916 +
3917 +       if (!raw_data) {
3918 +               printk(KERN_WARNING "mini_fo_read_super: missing argument\n");
3919 +               err = -EINVAL;
3920 +               goto out;
3921 +       }
3922 +       /*
3923 +        * Allocate superblock private data
3924 +        */
3925 +       __stopd(sb) = kmalloc(sizeof(struct mini_fo_sb_info), GFP_KERNEL);
3926 +       if (!stopd(sb)) {
3927 +               printk(KERN_WARNING "%s: out of memory\n", __FUNCTION__);
3928 +               err = -ENOMEM;
3929 +               goto out;
3930 +       }
3931 +       stohs(sb) = NULL;
3932 +
3933 +       hidden_root = mini_fo_parse_options(sb, raw_data);
3934 +       if (IS_ERR(hidden_root)) {
3935 +               printk(KERN_WARNING "mini_fo_read_super: lookup_dentry failed (err = %ld)\n", PTR_ERR(hidden_root));
3936 +               err = PTR_ERR(hidden_root);
3937 +               goto out_free;
3938 +       }
3939 +       if (!hidden_root->d_inode) {
3940 +               printk(KERN_WARNING "mini_fo_read_super: no directory to interpose on\n");
3941 +               goto out_free;
3942 +       }
3943 +       stohs(sb) = hidden_root->d_sb;
3944 +
3945 +       /*
3946 +        * Linux 2.4.2-ac3 and beyond has code in
3947 +        * mm/filemap.c:generic_file_write() that requires sb->s_maxbytes
3948 +        * to be populated.  If not set, all write()s under that sb will
3949 +        * return 0.
3950 +        *
3951 +        * Linux 2.4.4+ automatically sets s_maxbytes to MAX_NON_LFS;
3952 +        * the filesystem should override it only if it supports LFS.
3953 +        */
3954 +       /* non-SCA code is good to go with LFS */
3955 +       sb->s_maxbytes = hidden_root->d_sb->s_maxbytes;
3956 +
3957 +       sb->s_op = &mini_fo_sops;
3958 +       /*
3959 +        * we can't use d_alloc_root if we want to use
3960 +        * our own interpose function unchanged,
3961 +        * so we simply replicate *most* of the code in d_alloc_root here
3962 +        */
3963 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
3964 +       sb->s_root = d_alloc(NULL, &(const struct qstr) { "/", 1, 0 });
3965 +#else
3966 +       sb->s_root = d_alloc(NULL, &(const struct qstr){hash: 0, name: "/", len : 1});
3967 +#endif
3968 +       if (IS_ERR(sb->s_root)) {
3969 +               printk(KERN_WARNING "mini_fo_read_super: d_alloc failed\n");
3970 +               err = -ENOMEM;
3971 +               goto out_dput;
3972 +       }
3973 +
3974 +       sb->s_root->d_op = &mini_fo_dops;
3975 +       sb->s_root->d_sb = sb;
3976 +       sb->s_root->d_parent = sb->s_root;
3977 +
3978 +       /* link the upper and lower dentries */
3979 +       __dtopd(sb->s_root) = (struct mini_fo_dentry_info *) 
3980 +               kmalloc(sizeof(struct mini_fo_dentry_info), GFP_KERNEL);
3981 +       if (!dtopd(sb->s_root)) {
3982 +               err = -ENOMEM;
3983 +               goto out_dput2;
3984 +       }
3985 +       dtopd(sb->s_root)->state = MODIFIED;
3986 +       dtohd(sb->s_root) = hidden_root;
3987 +
3988 +       /* fanout relevant, interpose on storage root dentry too */
3989 +       dtohd2(sb->s_root) = stopd(sb)->storage_dir_dentry;
3990 +
3991 +       /* ...and call tri-interpose to interpose root dir inodes
3992 +        * if (mini_fo_interpose(hidden_root, sb->s_root, sb, 0))
3993 +        */
3994 +       if(mini_fo_tri_interpose(hidden_root, dtohd2(sb->s_root), sb->s_root, sb, 0))
3995 +               goto out_dput2;
3996 +
3997 +       /* initalize the wol list */
3998 +       itopd(sb->s_root->d_inode)->deleted_list_size = -1;
3999 +       itopd(sb->s_root->d_inode)->renamed_list_size = -1;
4000 +       meta_build_lists(sb->s_root);
4001 +
4002 +       goto out;
4003 +
4004 + out_dput2:
4005 +       dput(sb->s_root);
4006 + out_dput:
4007 +       dput(hidden_root);
4008 +       dput(dtohd2(sb->s_root)); /* release the hidden_sto_dentry too */
4009 + out_free:
4010 +       kfree(stopd(sb));
4011 +       __stopd(sb) = NULL;
4012 + out:
4013 +
4014 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
4015 +        return err;
4016 +#else
4017 +        if (err) {
4018 +               return ERR_PTR(err);
4019 +        } else {
4020 +               return sb;
4021 +        }
4022 +#endif
4023 +}
4024 +
4025 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
4026 +static struct super_block *mini_fo_get_sb(struct file_system_type *fs_type,
4027 +                                         int flags, const char *dev_name,
4028 +                                         void *raw_data) 
4029 +{
4030 +       return get_sb_nodev(fs_type, flags, raw_data, mini_fo_read_super);
4031 +}
4032 +
4033 +void mini_fo_kill_block_super(struct super_block *sb)
4034 +{
4035 +       generic_shutdown_super(sb);
4036 +       /*
4037 +        *      XXX: BUG: Halcrow: Things get unstable sometime after this point:
4038 +        *      lib/rwsem-spinlock.c:127: spin_is_locked on uninitialized
4039 +        *      fs/fs-writeback.c:402: spin_lock(fs/super.c:a0381828) already
4040 +        *      locked by fs/fs-writeback.c/402
4041 +        *
4042 +        *      Apparently, someone's not releasing a lock on sb_lock...
4043 +        */
4044 +}
4045 +
4046 +static struct file_system_type mini_fo_fs_type = {
4047 +       .owner          = THIS_MODULE,
4048 +       .name           = "mini_fo",
4049 +       .get_sb         = mini_fo_get_sb,
4050 +       .kill_sb        = mini_fo_kill_block_super,
4051 +       .fs_flags       = 0,
4052 +};
4053 +
4054 +
4055 +#else
4056 +static DECLARE_FSTYPE(mini_fo_fs_type, "mini_fo", mini_fo_read_super, 0);
4057 +#endif
4058 +
4059 +static int __init init_mini_fo_fs(void)
4060 +{
4061 +       printk("Registering mini_fo version $Id$\n");
4062 +       return register_filesystem(&mini_fo_fs_type);
4063 +}
4064 +static void __exit exit_mini_fo_fs(void)
4065 +{
4066 +       printk("Unregistering mini_fo version $Id$\n");
4067 +       unregister_filesystem(&mini_fo_fs_type);
4068 +}
4069 +
4070 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
4071 +EXPORT_NO_SYMBOLS;
4072 +#endif
4073 +
4074 +MODULE_AUTHOR("Erez Zadok <ezk@cs.sunysb.edu>");
4075 +MODULE_DESCRIPTION("FiST-generated mini_fo filesystem");
4076 +MODULE_LICENSE("GPL");
4077 +
4078 +/* MODULE_PARM(fist_debug_var, "i"); */
4079 +/* MODULE_PARM_DESC(fist_debug_var, "Debug level"); */
4080 +
4081 +module_init(init_mini_fo_fs)
4082 +module_exit(exit_mini_fo_fs)
4083 diff -urN linux.old/fs/mini_fo/Makefile linux.dev/fs/mini_fo/Makefile
4084 --- linux.old/fs/mini_fo/Makefile       1970-01-01 01:00:00.000000000 +0100
4085 +++ linux.dev/fs/mini_fo/Makefile       2006-11-17 03:11:48.000000000 +0100
4086 @@ -0,0 +1,17 @@
4087 +#
4088 +# Makefile for mini_fo 2.4 and 2.6 Linux kernels
4089 +#
4090 +# Copyright (C) 2004, 2005 Markus Klotzbuecher <mk@creamnet.de>
4091 +#
4092 +# This program is free software; you can redistribute it and/or
4093 +# modify it under the terms of the GNU General Public License
4094 +# as published by the Free Software Foundation; either version
4095 +# 2 of the License, or (at your option) any later version.
4096 +#
4097 +
4098 +obj-$(CONFIG_MINI_FO) := mini_fo.o
4099 +mini_fo-objs   := meta.o dentry.o file.o inode.o main.o super.o state.o aux.o
4100 +
4101 +# dependencies
4102 +${mini_fo-objs}: mini_fo.h fist.h
4103 +
4104 diff -urN linux.old/fs/mini_fo/meta.c linux.dev/fs/mini_fo/meta.c
4105 --- linux.old/fs/mini_fo/meta.c 1970-01-01 01:00:00.000000000 +0100
4106 +++ linux.dev/fs/mini_fo/meta.c 2006-11-17 03:11:48.000000000 +0100
4107 @@ -0,0 +1,1000 @@
4108 +/*
4109 + * Copyright (C) 2004, 2005 Markus Klotzbuecher <mk@creamnet.de>
4110 + *
4111 + * This program is free software; you can redistribute it and/or
4112 + * modify it under the terms of the GNU General Public License
4113 + * as published by the Free Software Foundation; either version
4114 + * 2 of the License, or (at your option) any later version.
4115 + */
4116 +
4117 +#ifdef HAVE_CONFIG_H
4118 +# include <config.h>
4119 +#endif /* HAVE_CONFIG_H */
4120 +#include "fist.h"
4121 +#include "mini_fo.h"
4122 +
4123 +int meta_build_lists(dentry_t *dentry) 
4124 +{
4125 +       struct mini_fo_inode_info *inode_info;
4126 +
4127 +       dentry_t *meta_dentry = 0;
4128 +       file_t *meta_file = 0;
4129 +       mm_segment_t old_fs;
4130 +       void *buf;
4131 +
4132 +       int bytes, len;
4133 +       struct vfsmount *meta_mnt;
4134 +       char *entry;
4135 +
4136 +       inode_info = itopd(dentry->d_inode);
4137 +       if(!(inode_info->deleted_list_size == -1 &&
4138 +            inode_info->renamed_list_size == -1)) {
4139 +               printk(KERN_CRIT "mini_fo: meta_build_lists: \
4140 +                                  Error, list(s) not virgin.\n");
4141 +               return -1;
4142 +       }
4143 +
4144 +       /* init our meta lists */
4145 +       INIT_LIST_HEAD(&inode_info->deleted_list);
4146 +       inode_info->deleted_list_size = 0;
4147 +
4148 +       INIT_LIST_HEAD(&inode_info->renamed_list);
4149 +       inode_info->renamed_list_size = 0;
4150 +
4151 +       /* might there be a META-file? */
4152 +       if(dtohd2(dentry) && dtohd2(dentry)->d_inode) {
4153 +               meta_dentry = lookup_one_len(META_FILENAME,
4154 +                                            dtohd2(dentry), 
4155 +                                            strlen(META_FILENAME));
4156 +               if(!meta_dentry->d_inode) {
4157 +                       dput(meta_dentry);
4158 +                       goto out_ok;
4159 +               }
4160 +               /* $%& err, is this correct? */
4161 +               meta_mnt = stopd(dentry->d_inode->i_sb)->hidden_mnt2;
4162 +               mntget(meta_mnt);
4163 +               
4164 +
4165 +               /* open META-file for reading */
4166 +               meta_file = dentry_open(meta_dentry, meta_mnt, 0x0);
4167 +               if(!meta_file || IS_ERR(meta_file)) {
4168 +                       printk(KERN_CRIT "mini_fo: meta_build_lists: \
4169 +                                          ERROR opening META file.\n");
4170 +                       goto out_err;
4171 +               }
4172 +
4173 +               /* check if fs supports reading */
4174 +               if(!meta_file->f_op->read) {
4175 +                       printk(KERN_CRIT "mini_fo: meta_build_lists: \
4176 +                                          ERROR, fs does not support reading.\n");
4177 +                       goto out_err_close;
4178 +               }
4179 +
4180 +               /* allocate a page for transfering the data */
4181 +               buf = (void *) __get_free_page(GFP_KERNEL);
4182 +               if(!buf) {
4183 +                       printk(KERN_CRIT "mini_fo: meta_build_lists: \
4184 +                                          ERROR, out of mem.\n");
4185 +                       goto out_err_close;
4186 +               }
4187 +               meta_file->f_pos = 0;
4188 +               old_fs = get_fs();
4189 +               set_fs(KERNEL_DS);
4190 +               do {
4191 +                       char *c;
4192 +                       bytes = meta_file->f_op->read(meta_file, buf, PAGE_SIZE, &meta_file->f_pos);
4193 +                       if(bytes == PAGE_SIZE) {
4194 +                               /* trim a cut off filename and adjust f_pos to get it next time */
4195 +                               for(c = (char*) buf+PAGE_SIZE;
4196 +                                   *c != '\n';
4197 +                                   c--, bytes--, meta_file->f_pos--);
4198 +                       }
4199 +                       entry = (char *) buf;
4200 +                       while(entry < (char *) buf+bytes) {
4201 +
4202 +                               char *old_path;
4203 +                               char *dir_name;
4204 +                               int old_len, new_len;
4205 +
4206 +                               /* len without '\n'*/
4207 +                               len = (int) (strchr(entry, '\n') - entry);
4208 +                               switch (*entry) {
4209 +                               case 'D':
4210 +                                       /* format: "D filename" */
4211 +                                       meta_list_add_d_entry(dentry, 
4212 +                                                             entry+2, 
4213 +                                                             len-2);
4214 +                                       break;
4215 +                               case 'R':
4216 +                                       /* format: "R path/xy/dir newDir" */
4217 +                                       old_path = entry+2;
4218 +                                       dir_name = strchr(old_path, ' ') + 1;
4219 +                                       old_len =  dir_name - old_path - 1;
4220 +                                       new_len = ((int) entry) + len - ((int ) dir_name);
4221 +                                       meta_list_add_r_entry(dentry, 
4222 +                                                             old_path, 
4223 +                                                             old_len,
4224 +                                                             dir_name, 
4225 +                                                             new_len);
4226 +                                       break;
4227 +                               default:
4228 +                                       /* unknown entry type detected */
4229 +                                       break;
4230 +                               }
4231 +                               entry += len+1;
4232 +                       }
4233 +
4234 +               } while(meta_file->f_pos < meta_dentry->d_inode->i_size);
4235 +
4236 +               free_page((unsigned long) buf);
4237 +               set_fs(old_fs);
4238 +               fput(meta_file);
4239 +       }
4240 +       goto out_ok;
4241 +
4242 + out_err_close:
4243 +       fput(meta_file);
4244 + out_err:
4245 +       mntput(meta_mnt);
4246 +       dput(meta_dentry);
4247 +       return -1;
4248 + out_ok:
4249 +       return 1; /* check this!!! inode_info->wol_size; */ 
4250 +}
4251 +
4252 +/* cleanups up all lists and free's the mem by dentry */
4253 +int meta_put_lists(dentry_t *dentry) 
4254 +{
4255 +       if(!dentry || !dentry->d_inode) {
4256 +               printk("mini_fo: meta_put_lists: invalid dentry passed.\n");
4257 +               return -1;
4258 +       }
4259 +       return __meta_put_lists(dentry->d_inode);
4260 +}
4261 +
4262 +/* cleanups up all lists and free's the mem by inode */
4263 +int __meta_put_lists(inode_t *inode) 
4264 +{
4265 +       int err = 0;
4266 +       if(!inode || !itopd(inode)) {
4267 +               printk("mini_fo: __meta_put_lists: invalid inode passed.\n");
4268 +               return -1;
4269 +       }
4270 +       err = __meta_put_d_list(inode);
4271 +       err |= __meta_put_r_list(inode);
4272 +       return err;
4273 +}
4274 +
4275 +int meta_sync_lists(dentry_t *dentry)
4276 +{
4277 +       int err = 0;
4278 +       if(!dentry || !dentry->d_inode) {
4279 +               printk("mini_fo: meta_sync_lists: \
4280 +                        invalid dentry passed.\n");
4281 +               return -1;
4282 +       }
4283 +       err = meta_sync_d_list(dentry, 0);
4284 +       err |= meta_sync_r_list(dentry, 1);
4285 +       return err;
4286 +}
4287 +
4288 +
4289 +/* remove all D entries from the renamed list and free the mem */
4290 +int __meta_put_d_list(inode_t *inode) 
4291 +{
4292 +       struct list_head *tmp;
4293 +        struct deleted_entry *del_entry;
4294 +        struct mini_fo_inode_info *inode_info;
4295 +       
4296 +       if(!inode || !itopd(inode)) {
4297 +               printk(KERN_CRIT "mini_fo: __meta_put_d_list: \
4298 +                                  invalid inode passed.\n");
4299 +               return -1;
4300 +       }
4301 +       inode_info = itopd(inode);
4302 +       
4303 +        /* nuke the DELETED-list */
4304 +        if(inode_info->deleted_list_size <= 0)
4305 +               return 0;
4306 +
4307 +       while(!list_empty(&inode_info->deleted_list)) {
4308 +               tmp = inode_info->deleted_list.next;
4309 +               list_del(tmp);
4310 +               del_entry = list_entry(tmp, struct deleted_entry, list);
4311 +               kfree(del_entry->name);
4312 +               kfree(del_entry);
4313 +       }
4314 +       inode_info->deleted_list_size = 0;
4315 +       
4316 +       return 0;
4317 +}
4318 +
4319 +/* remove all R entries from the renamed list and free the mem */
4320 +int __meta_put_r_list(inode_t *inode) 
4321 +{
4322 +       struct list_head *tmp;
4323 +       struct renamed_entry *ren_entry;
4324 +        struct mini_fo_inode_info *inode_info;
4325 +       
4326 +       if(!inode || !itopd(inode)) {
4327 +               printk(KERN_CRIT "mini_fo: meta_put_r_list: invalid inode.\n");
4328 +               return -1;
4329 +       }
4330 +       inode_info = itopd(inode);
4331 +       
4332 +        /* nuke the RENAMED-list */
4333 +        if(inode_info->renamed_list_size <= 0) 
4334 +               return 0;
4335 +
4336 +       while(!list_empty(&inode_info->renamed_list)) {
4337 +               tmp = inode_info->renamed_list.next;
4338 +               list_del(tmp);
4339 +               ren_entry = list_entry(tmp, struct renamed_entry, list);
4340 +               kfree(ren_entry->new_name);
4341 +               kfree(ren_entry->old_name);
4342 +               kfree(ren_entry);
4343 +       }
4344 +       inode_info->renamed_list_size = 0;
4345 +       
4346 +       return 0;
4347 +}
4348 +
4349 +int meta_add_d_entry(dentry_t *dentry, const char *name, int len)
4350 +{
4351 +       int err = 0;
4352 +       err = meta_list_add_d_entry(dentry, name, len);
4353 +       err |= meta_write_d_entry(dentry,name,len);
4354 +       return err;     
4355 +}
4356 +
4357 +/* add a D entry to the deleted list */
4358 +int meta_list_add_d_entry(dentry_t *dentry, const char *name, int len) 
4359 +{
4360 +        struct deleted_entry *del_entry;
4361 +        struct mini_fo_inode_info *inode_info;
4362 +
4363 +       if(!dentry || !dentry->d_inode) {
4364 +               printk(KERN_CRIT "mini_fo: meta_list_add_d_entry: \
4365 +                                  invalid dentry passed.\n");
4366 +               return -1;
4367 +       }
4368 +       inode_info = itopd(dentry->d_inode);
4369 +
4370 +        if(inode_info->deleted_list_size < 0)
4371 +                return -1;
4372 +
4373 +        del_entry = (struct deleted_entry *) 
4374 +               kmalloc(sizeof(struct deleted_entry), GFP_KERNEL);
4375 +        del_entry->name = (char*) kmalloc(len, GFP_KERNEL);
4376 +        if(!del_entry || !del_entry->name) {
4377 +                printk(KERN_CRIT "mini_fo: meta_list_add_d_entry: \
4378 +                                  out of mem.\n");
4379 +               kfree(del_entry->name);
4380 +               kfree(del_entry);
4381 +                return -ENOMEM;
4382 +        }
4383 +
4384 +        strncpy(del_entry->name, name, len);
4385 +        del_entry->len = len;
4386 +
4387 +        list_add(&del_entry->list, &inode_info->deleted_list);
4388 +        inode_info->deleted_list_size++;
4389 +        return 0;
4390 +}
4391 +
4392 +int meta_add_r_entry(dentry_t *dentry, 
4393 +                         const char *old_name, int old_len, 
4394 +                         const char *new_name, int new_len)
4395 +{
4396 +       int err = 0;
4397 +       err = meta_list_add_r_entry(dentry, 
4398 +                                   old_name, old_len,
4399 +                                   new_name, new_len);
4400 +       err |= meta_write_r_entry(dentry,
4401 +                                 old_name, old_len,
4402 +                                 new_name, new_len);
4403 +       return err;
4404 +}
4405 +
4406 +/* add a R entry to the renamed list */
4407 +int meta_list_add_r_entry(dentry_t *dentry, 
4408 +                         const char *old_name, int old_len, 
4409 +                         const char *new_name, int new_len)
4410 +{
4411 +        struct renamed_entry *ren_entry;
4412 +        struct mini_fo_inode_info *inode_info;
4413 +
4414 +       if(!dentry || !dentry->d_inode) {
4415 +               printk(KERN_CRIT "mini_fo: meta_list_add_r_entry: \
4416 +                                  invalid dentry passed.\n");
4417 +               return -1;
4418 +       }
4419 +       inode_info = itopd(dentry->d_inode);
4420 +
4421 +        if(inode_info->renamed_list_size < 0)
4422 +                return -1;
4423 +
4424 +        ren_entry = (struct renamed_entry *) 
4425 +               kmalloc(sizeof(struct renamed_entry), GFP_KERNEL);
4426 +        ren_entry->old_name = (char*) kmalloc(old_len, GFP_KERNEL);
4427 +        ren_entry->new_name = (char*) kmalloc(new_len, GFP_KERNEL);
4428 +
4429 +        if(!ren_entry || !ren_entry->old_name || !ren_entry->new_name) {
4430 +                printk(KERN_CRIT "mini_fo: meta_list_add_r_entry: \
4431 +                                  out of mem.\n");
4432 +               kfree(ren_entry->new_name);
4433 +               kfree(ren_entry->old_name);
4434 +               kfree(ren_entry);
4435 +                return -ENOMEM;
4436 +        }
4437 +
4438 +        strncpy(ren_entry->old_name, old_name, old_len);
4439 +        ren_entry->old_len = old_len;
4440 +        strncpy(ren_entry->new_name, new_name, new_len);
4441 +        ren_entry->new_len = new_len;
4442 +
4443 +        list_add(&ren_entry->list, &inode_info->renamed_list);
4444 +        inode_info->renamed_list_size++;
4445 +        return 0;
4446 +}
4447 +
4448 +
4449 +int meta_remove_r_entry(dentry_t *dentry, const char *name, int len)
4450 +{
4451 +       int err = 0;
4452 +       if(!dentry || !dentry->d_inode) {
4453 +               printk(KERN_CRIT 
4454 +                      "mini_fo: meta_remove_r_entry: \
4455 +                        invalid dentry passed.\n");
4456 +               return -1;
4457 +       }
4458 +
4459 +       err = meta_list_remove_r_entry(dentry, name, len);
4460 +       err |= meta_sync_lists(dentry);
4461 +       return err;
4462 +}
4463 +
4464 +int meta_list_remove_r_entry(dentry_t *dentry, const char *name, int len)
4465 +{
4466 +       if(!dentry || !dentry->d_inode) {
4467 +               printk(KERN_CRIT 
4468 +                      "mini_fo: meta_list_remove_r_entry: \
4469 +                        invalid dentry passed.\n");
4470 +               return -1;
4471 +       }
4472 +       return __meta_list_remove_r_entry(dentry->d_inode, name, len);
4473 +}
4474 +
4475 +int __meta_list_remove_r_entry(inode_t *inode, const char *name, int len)
4476 +{
4477 +       struct list_head *tmp;
4478 +        struct renamed_entry *ren_entry;
4479 +        struct mini_fo_inode_info *inode_info;
4480 +
4481 +       if(!inode || !itopd(inode))
4482 +               printk(KERN_CRIT 
4483 +                      "mini_fo: __meta_list_remove_r_entry: \
4484 +                        invalid inode passed.\n");
4485 +       inode_info = itopd(inode);
4486 +
4487 +        if(inode_info->renamed_list_size < 0)
4488 +                return -1;
4489 +        if(inode_info->renamed_list_size == 0)
4490 +                return 1;
4491 +       
4492 +       list_for_each(tmp, &inode_info->renamed_list) {
4493 +               ren_entry = list_entry(tmp, struct renamed_entry, list);
4494 +               if(ren_entry->new_len != len)
4495 +                       continue;
4496 +               
4497 +               if(!strncmp(ren_entry->new_name, name, len)) {
4498 +                       list_del(tmp);
4499 +                       kfree(ren_entry->new_name);
4500 +                       kfree(ren_entry->old_name);
4501 +                       kfree(ren_entry);
4502 +                       inode_info->renamed_list_size--;
4503 +                       return 0;
4504 +               }
4505 +       }
4506 +       return 1;
4507 +}
4508 +
4509 +
4510 +/* append a single D entry to the meta file */
4511 +int meta_write_d_entry(dentry_t *dentry, const char *name, int len) 
4512 +{
4513 +       dentry_t *meta_dentry = 0;
4514 +        file_t *meta_file = 0;
4515 +        mm_segment_t old_fs;
4516 +
4517 +        int bytes, err;
4518 +        struct vfsmount *meta_mnt = 0;
4519 +        char *buf;
4520 +
4521 +       err = 0;
4522 +
4523 +       if(itopd(dentry->d_inode)->deleted_list_size < 0) {
4524 +               err = -1;
4525 +               goto out;
4526 +       }
4527 +
4528 +       if(dtopd(dentry)->state == UNMODIFIED) {
4529 +                err = build_sto_structure(dentry->d_parent, dentry);
4530 +                if(err) {
4531 +                        printk(KERN_CRIT "mini_fo: meta_write_d_entry: \
4532 +                                          build_sto_structure failed.\n");
4533 +                       goto out;
4534 +                }
4535 +        }
4536 +       meta_dentry = lookup_one_len(META_FILENAME, 
4537 +                                    dtohd2(dentry), strlen (META_FILENAME));
4538 +
4539 +       /* We need to create a META-file */
4540 +        if(!meta_dentry->d_inode) {
4541 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
4542 +               vfs_create(dtohd2(dentry)->d_inode,
4543 +                          meta_dentry, 
4544 +                          S_IRUSR | S_IWUSR,
4545 +                          NULL);
4546 +#else
4547 +                vfs_create(dtohd2(dentry)->d_inode,
4548 +                          meta_dentry, 
4549 +                          S_IRUSR | S_IWUSR);
4550 +#endif
4551 +       }
4552 +        /* open META-file for writing */
4553 +        meta_file = dentry_open(meta_dentry, meta_mnt, 0x1);
4554 +        if(!meta_file || IS_ERR(meta_file)) {
4555 +                printk(KERN_CRIT "mini_fo: meta_write_d_entry: \
4556 +                                  ERROR opening meta file.\n");
4557 +                mntput(meta_mnt); /* $%& is this necessary? */
4558 +                dput(meta_dentry);
4559 +               err = -1;
4560 +                goto out;
4561 +        }
4562 +
4563 +        /* check if fs supports writing */
4564 +        if(!meta_file->f_op->write) {
4565 +                printk(KERN_CRIT "mini_fo: meta_write_d_entry: \
4566 +                                  ERROR, fs does not support writing.\n");
4567 +                goto out_err_close;
4568 +        }
4569 +
4570 +       meta_file->f_pos = meta_dentry->d_inode->i_size; /* append */
4571 +        old_fs = get_fs();
4572 +        set_fs(KERNEL_DS);
4573 +
4574 +       /* size: len for name, 1 for \n and 2 for "D " */
4575 +       buf = (char *) kmalloc(len+3, GFP_KERNEL);
4576 +       if (!buf) {
4577 +               printk(KERN_CRIT "mini_fo: meta_write_d_entry: \
4578 +                                  out of mem.\n");
4579 +               return -ENOMEM;
4580 +       }
4581 +                     
4582 +       buf[0] = 'D';
4583 +       buf[1] = ' ';
4584 +       strncpy(buf+2, name, len);
4585 +       buf[len+2] = '\n';
4586 +       bytes = meta_file->f_op->write(meta_file, buf, len+3, 
4587 +                                      &meta_file->f_pos);
4588 +       if(bytes != len+3) {
4589 +               printk(KERN_CRIT "mini_fo: meta_write_d_entry: \
4590 +                                  ERROR writing.\n");
4591 +               err = -1;
4592 +       }
4593 +       kfree(buf);
4594 +       set_fs(old_fs);
4595 +
4596 + out_err_close:
4597 +       fput(meta_file);
4598 + out:
4599 +       return err;
4600 +}
4601 +
4602 +/* append a single R entry to the meta file */
4603 +int meta_write_r_entry(dentry_t *dentry, 
4604 +                      const char *old_name, int old_len, 
4605 +                      const char *new_name, int new_len) 
4606 +{
4607 +       dentry_t *meta_dentry = 0;
4608 +        file_t *meta_file = 0;
4609 +        mm_segment_t old_fs;
4610 +
4611 +        int bytes, err, buf_len;
4612 +       struct vfsmount *meta_mnt = 0;
4613 +        char *buf;
4614 +
4615 +
4616 +       err = 0;
4617 +
4618 +       if(itopd(dentry->d_inode)->renamed_list_size < 0) {
4619 +               err = -1;
4620 +               goto out;
4621 +       }
4622 +
4623 +       /* build the storage structure? */
4624 +       if(dtopd(dentry)->state == UNMODIFIED) {
4625 +                err = build_sto_structure(dentry->d_parent, dentry);
4626 +                if(err) {
4627 +                        printk(KERN_CRIT "mini_fo: meta_write_r_entry: \
4628 +                                          build_sto_structure failed.\n");
4629 +                       goto out;
4630 +                }
4631 +        }
4632 +       meta_dentry = lookup_one_len(META_FILENAME, 
4633 +                                    dtohd2(dentry), 
4634 +                                    strlen (META_FILENAME));
4635 +        if(!meta_dentry->d_inode) {
4636 +                /* We need to create a META-file */
4637 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
4638 +                vfs_create(dtohd2(dentry)->d_inode, 
4639 +                          meta_dentry, S_IRUSR | S_IWUSR, NULL);
4640 +#else
4641 +                vfs_create(dtohd2(dentry)->d_inode, 
4642 +                          meta_dentry, S_IRUSR | S_IWUSR);
4643 +#endif
4644 +       }
4645 +        /* open META-file for writing */
4646 +        meta_file = dentry_open(meta_dentry, meta_mnt, 0x1);
4647 +        if(!meta_file || IS_ERR(meta_file)) {
4648 +                printk(KERN_CRIT "mini_fo: meta_write_r_entry: \
4649 +                                  ERROR opening meta file.\n");
4650 +                mntput(meta_mnt);
4651 +                dput(meta_dentry);
4652 +               err = -1;
4653 +                goto out;
4654 +        }
4655 +
4656 +        /* check if fs supports writing */
4657 +        if(!meta_file->f_op->write) {
4658 +                printk(KERN_CRIT "mini_fo: meta_write_r_entry: \
4659 +                                  ERROR, fs does not support writing.\n");
4660 +                goto out_err_close;
4661 +        }
4662 +
4663 +       meta_file->f_pos = meta_dentry->d_inode->i_size; /* append */
4664 +        old_fs = get_fs();
4665 +        set_fs(KERNEL_DS);
4666 +
4667 +       /* size: 2 for "R ", old_len+new_len for names, 1 blank+1 \n */
4668 +       buf_len = old_len + new_len + 4;
4669 +       buf = (char *) kmalloc(buf_len, GFP_KERNEL);
4670 +       if (!buf) {
4671 +               printk(KERN_CRIT "mini_fo: meta_write_r_entry: out of mem.\n");
4672 +               return -ENOMEM;
4673 +       }
4674 +                     
4675 +       buf[0] = 'R';
4676 +       buf[1] = ' ';
4677 +       strncpy(buf + 2, old_name, old_len);
4678 +       buf[old_len + 2] = ' ';
4679 +       strncpy(buf + old_len + 3, new_name, new_len);
4680 +       buf[buf_len -1] = '\n';
4681 +       bytes = meta_file->f_op->write(meta_file, buf, buf_len, &meta_file->f_pos);
4682 +       if(bytes != buf_len) {
4683 +               printk(KERN_CRIT "mini_fo: meta_write_r_entry: ERROR writing.\n");
4684 +               err = -1;
4685 +       }
4686 +       
4687 +       kfree(buf);
4688 +       set_fs(old_fs);
4689 +
4690 + out_err_close:
4691 +       fput(meta_file);
4692 + out:
4693 +       return err;
4694 +}
4695 +
4696 +/* sync D list to disk, append data if app_flag is 1 */
4697 +/* check the meta_mnt, which seems not to be used (properly)  */
4698 +
4699 +int meta_sync_d_list(dentry_t *dentry, int app_flag)
4700 +{
4701 +       dentry_t *meta_dentry;
4702 +        file_t *meta_file;
4703 +        mm_segment_t old_fs;
4704 +       
4705 +        int bytes, err;
4706 +        struct vfsmount *meta_mnt;
4707 +        char *buf;
4708 +
4709 +       struct list_head *tmp;
4710 +        struct deleted_entry *del_entry;
4711 +        struct mini_fo_inode_info *inode_info;
4712 +
4713 +       err = 0;
4714 +       meta_file=0;
4715 +       meta_mnt=0;
4716 +       
4717 +       if(!dentry || !dentry->d_inode) {
4718 +               printk(KERN_CRIT "mini_fo: meta_sync_d_list: \
4719 +                                  invalid inode passed.\n");
4720 +               err = -1;
4721 +               goto out;
4722 +       }
4723 +       inode_info = itopd(dentry->d_inode);
4724 +       
4725 +        if(inode_info->deleted_list_size < 0) {
4726 +               err = -1;
4727 +               goto out;
4728 +       }
4729 +       
4730 +       /* ok, there is something to sync */
4731 +
4732 +       /* build the storage structure? */
4733 +        if(!dtohd2(dentry) && !itohi2(dentry->d_inode)) {
4734 +                err = build_sto_structure(dentry->d_parent, dentry);
4735 +                if(err) {
4736 +                        printk(KERN_CRIT "mini_fo: meta_sync_d_list: \
4737 +                                          build_sto_structure failed.\n");
4738 +                       goto out;
4739 +                }
4740 +        }
4741 +       meta_dentry = lookup_one_len(META_FILENAME, 
4742 +                                    dtohd2(dentry), 
4743 +                                    strlen(META_FILENAME));
4744 +        if(!meta_dentry->d_inode) {
4745 +                /* We need to create a META-file */
4746 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
4747 +                vfs_create(dtohd2(dentry)->d_inode, 
4748 +                          meta_dentry, S_IRUSR | S_IWUSR, NULL);
4749 +#else
4750 +                vfs_create(dtohd2(dentry)->d_inode, 
4751 +                          meta_dentry, S_IRUSR | S_IWUSR);
4752 +#endif
4753 +               app_flag = 0;
4754 +       }
4755 +       /* need we truncate the meta file? */
4756 +       if(!app_flag) {
4757 +               struct iattr newattrs;
4758 +                newattrs.ia_size = 0;
4759 +                newattrs.ia_valid = ATTR_SIZE | ATTR_CTIME;
4760 +
4761 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
4762 +               mutex_lock(&meta_dentry->d_inode->i_mutex);
4763 +#else
4764 +                down(&meta_dentry->d_inode->i_sem);
4765 +#endif
4766 +                err = notify_change(meta_dentry, &newattrs);
4767 +
4768 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
4769 +               mutex_unlock(&meta_dentry->d_inode->i_mutex);
4770 +#else
4771 +                up(&meta_dentry->d_inode->i_sem);
4772 +#endif
4773 +
4774 +                if(err || meta_dentry->d_inode->i_size != 0) {
4775 +                        printk(KERN_CRIT "mini_fo: meta_sync_d_list: \
4776 +                                          ERROR truncating meta file.\n");
4777 +                        goto out_err_close;
4778 +               }
4779 +       }
4780 +
4781 +        /* open META-file for writing */
4782 +        meta_file = dentry_open(meta_dentry, meta_mnt, 0x1);
4783 +        if(!meta_file || IS_ERR(meta_file)) {
4784 +                printk(KERN_CRIT "mini_fo: meta_sync_d_list: \
4785 +                                  ERROR opening meta file.\n");
4786 +               /* we don't mntget so we dont't mntput (for now)
4787 +                * mntput(meta_mnt); 
4788 +                */
4789 +               dput(meta_dentry);
4790 +               err = -1;
4791 +                goto out;
4792 +        }
4793 +
4794 +        /* check if fs supports writing */
4795 +        if(!meta_file->f_op->write) {
4796 +                printk(KERN_CRIT "mini_fo: meta_sync_d_list: \
4797 +                                  ERROR, fs does not support writing.\n");
4798 +                goto out_err_close;
4799 +        }
4800 +       
4801 +       meta_file->f_pos = meta_dentry->d_inode->i_size; /* append */
4802 +        old_fs = get_fs();
4803 +        set_fs(KERNEL_DS);
4804 +
4805 +       /* here we go... */
4806 +        list_for_each(tmp, &inode_info->deleted_list) {
4807 +               del_entry = list_entry(tmp, struct deleted_entry, list);
4808 +               
4809 +               /* size: len for name, 1 for \n and 2 for "D " */
4810 +               buf = (char *) kmalloc(del_entry->len+3, GFP_KERNEL);
4811 +               if (!buf) {
4812 +                       printk(KERN_CRIT "mini_fo: meta_sync_d_list: \
4813 +                                          out of mem.\n");
4814 +                       return -ENOMEM;
4815 +               }
4816 +                     
4817 +               buf[0] = 'D';
4818 +               buf[1] = ' ';
4819 +               strncpy(buf+2, del_entry->name, del_entry->len);
4820 +               buf[del_entry->len+2] = '\n';
4821 +               bytes = meta_file->f_op->write(meta_file, buf, 
4822 +                                              del_entry->len+3, 
4823 +                                              &meta_file->f_pos);
4824 +               if(bytes != del_entry->len+3) {
4825 +                       printk(KERN_CRIT "mini_fo: meta_sync_d_list: \
4826 +                                          ERROR writing.\n");
4827 +                       err |= -1;
4828 +               }
4829 +               kfree(buf);
4830 +       }
4831 +       set_fs(old_fs);
4832 +       
4833 + out_err_close:
4834 +       fput(meta_file);
4835 + out:
4836 +       return err;
4837 +
4838 +}
4839 +
4840 +int meta_sync_r_list(dentry_t *dentry, int app_flag)
4841 +{
4842 +       dentry_t *meta_dentry;
4843 +        file_t *meta_file;
4844 +        mm_segment_t old_fs;
4845 +       
4846 +        int bytes, err, buf_len;
4847 +        struct vfsmount *meta_mnt;
4848 +        char *buf;
4849 +       
4850 +       struct list_head *tmp;
4851 +        struct renamed_entry *ren_entry;
4852 +        struct mini_fo_inode_info *inode_info;
4853 +       
4854 +       err = 0;
4855 +       meta_file=0;
4856 +       meta_mnt=0;
4857 +       
4858 +       if(!dentry || !dentry->d_inode) {
4859 +               printk(KERN_CRIT "mini_fo: meta_sync_r_list: \
4860 +                                  invalid dentry passed.\n");
4861 +               err = -1;
4862 +               goto out;
4863 +       }
4864 +       inode_info = itopd(dentry->d_inode);
4865 +       
4866 +        if(inode_info->deleted_list_size < 0) {
4867 +               err = -1;
4868 +               goto out;
4869 +       }
4870 +       
4871 +       /* ok, there is something to sync */
4872 +
4873 +       /* build the storage structure? */
4874 +        if(!dtohd2(dentry) && !itohi2(dentry->d_inode)) {
4875 +                err = build_sto_structure(dentry->d_parent, dentry);
4876 +                if(err) {
4877 +                        printk(KERN_CRIT "mini_fo: meta_sync_r_list: \
4878 +                                          build_sto_structure failed.\n");
4879 +                       goto out;
4880 +                }
4881 +        }
4882 +       meta_dentry = lookup_one_len(META_FILENAME, 
4883 +                                    dtohd2(dentry), 
4884 +                                    strlen(META_FILENAME));
4885 +        if(!meta_dentry->d_inode) {
4886 +                /* We need to create a META-file */
4887 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
4888 +                vfs_create(dtohd2(dentry)->d_inode, 
4889 +                          meta_dentry, S_IRUSR | S_IWUSR, NULL);
4890 +#else
4891 +                vfs_create(dtohd2(dentry)->d_inode, 
4892 +                          meta_dentry, S_IRUSR | S_IWUSR);
4893 +#endif
4894 +               app_flag = 0;
4895 +       }
4896 +       /* need we truncate the meta file? */
4897 +       if(!app_flag) {
4898 +               struct iattr newattrs;
4899 +                newattrs.ia_size = 0;
4900 +                newattrs.ia_valid = ATTR_SIZE | ATTR_CTIME;
4901 +
4902 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
4903 +               mutex_lock(&meta_dentry->d_inode->i_mutex);
4904 +#else
4905 +                down(&meta_dentry->d_inode->i_sem);
4906 +#endif
4907 +                err = notify_change(meta_dentry, &newattrs);
4908 +
4909 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
4910 +               mutex_unlock(&meta_dentry->d_inode->i_mutex);
4911 +#else
4912 +                up(&meta_dentry->d_inode->i_sem);
4913 +#endif
4914 +                if(err || meta_dentry->d_inode->i_size != 0) {
4915 +                        printk(KERN_CRIT "mini_fo: meta_sync_r_list: \
4916 +                                          ERROR truncating meta file.\n");
4917 +                        goto out_err_close;
4918 +               }
4919 +       }
4920 +
4921 +        /* open META-file for writing */
4922 +        meta_file = dentry_open(meta_dentry, meta_mnt, 0x1);
4923 +        if(!meta_file || IS_ERR(meta_file)) {
4924 +                printk(KERN_CRIT "mini_fo: meta_sync_r_list: \
4925 +                                  ERROR opening meta file.\n");
4926 +               /* we don't mntget so we dont't mntput (for now)
4927 +                * mntput(meta_mnt); 
4928 +                */
4929 +               dput(meta_dentry);
4930 +               err = -1;
4931 +                goto out;
4932 +        }
4933 +
4934 +        /* check if fs supports writing */
4935 +        if(!meta_file->f_op->write) {
4936 +                printk(KERN_CRIT "mini_fo: meta_sync_r_list: \
4937 +                                  ERROR, fs does not support writing.\n");
4938 +                goto out_err_close;
4939 +        }
4940 +       
4941 +       meta_file->f_pos = meta_dentry->d_inode->i_size; /* append */
4942 +        old_fs = get_fs();
4943 +        set_fs(KERNEL_DS);
4944 +
4945 +       /* here we go... */
4946 +        list_for_each(tmp, &inode_info->renamed_list) {
4947 +               ren_entry = list_entry(tmp, struct renamed_entry, list);
4948 +               /* size: 
4949 +                * 2 for "R ", old_len+new_len for names, 1 blank+1 \n */
4950 +               buf_len = ren_entry->old_len + ren_entry->new_len + 4;
4951 +               buf = (char *) kmalloc(buf_len, GFP_KERNEL);
4952 +               if (!buf) {
4953 +                       printk(KERN_CRIT "mini_fo: meta_sync_r_list: \
4954 +                                          out of mem.\n");
4955 +                       return -ENOMEM;
4956 +               }
4957 +               buf[0] = 'R';
4958 +               buf[1] = ' ';
4959 +               strncpy(buf + 2, ren_entry->old_name, ren_entry->old_len);
4960 +               buf[ren_entry->old_len + 2] = ' ';
4961 +               strncpy(buf + ren_entry->old_len + 3, 
4962 +                       ren_entry->new_name, ren_entry->new_len);
4963 +               buf[buf_len - 1] = '\n';
4964 +               bytes = meta_file->f_op->write(meta_file, buf, 
4965 +                                              buf_len, &meta_file->f_pos);
4966 +               if(bytes != buf_len) {
4967 +                       printk(KERN_CRIT "mini_fo: meta_sync_r_list: \
4968 +                                          ERROR writing.\n");
4969 +                       err |= -1;
4970 +               }               
4971 +               kfree(buf);
4972 +       }
4973 +       set_fs(old_fs);
4974 +       
4975 + out_err_close:
4976 +       fput(meta_file);
4977 + out:
4978 +       return err;
4979 +}
4980 +
4981 +int meta_check_d_entry(dentry_t *dentry, const char *name, int len) 
4982 +{
4983 +       if(!dentry || !dentry->d_inode)
4984 +               printk(KERN_CRIT "mini_fo: meta_check_d_dentry: \
4985 +                                  invalid dentry passed.\n");
4986 +       return __meta_check_d_entry(dentry->d_inode, name, len);        
4987 +}
4988 +
4989 +int __meta_check_d_entry(inode_t *inode, const char *name, int len) 
4990 +{
4991 +       struct list_head *tmp;
4992 +        struct deleted_entry *del_entry;
4993 +        struct mini_fo_inode_info *inode_info;
4994 +
4995 +       if(!inode || !itopd(inode))
4996 +               printk(KERN_CRIT "mini_fo: __meta_check_d_dentry: \
4997 +                                  invalid inode passed.\n");
4998 +
4999 +        inode_info = itopd(inode);
5000 +       
5001 +        if(inode_info->deleted_list_size <= 0)
5002 +                return 0;
5003 +
5004 +        list_for_each(tmp, &inode_info->deleted_list) {
5005 +               del_entry = list_entry(tmp, struct deleted_entry, list);
5006 +               if(del_entry->len != len)
5007 +                       continue;
5008 +               
5009 +               if(!strncmp(del_entry->name, name, len))
5010 +                       return 1;
5011 +       }
5012 +       return 0;
5013 +}
5014 +
5015 +/* 
5016 + * check if file has been renamed and return path to orig. base dir.
5017 + * Implements no error return values so far, what of course sucks.
5018 + * String is null terminated.'
5019 + */
5020 +char* meta_check_r_entry(dentry_t *dentry, const char *name, int len) 
5021 +{
5022 +       if(!dentry || !dentry->d_inode) {
5023 +               printk(KERN_CRIT "mini_fo: meta_check_r_dentry: \
5024 +                                  invalid dentry passed.\n");
5025 +               return NULL;
5026 +       }
5027 +       return __meta_check_r_entry(dentry->d_inode, name, len);        
5028 +}
5029 +
5030 +char* __meta_check_r_entry(inode_t *inode, const char *name, int len)
5031 +{
5032 +       struct list_head *tmp;
5033 +        struct renamed_entry *ren_entry;
5034 +        struct mini_fo_inode_info *inode_info;
5035 +       char *old_path;
5036 +       
5037 +       if(!inode || !itopd(inode)) {
5038 +               printk(KERN_CRIT "mini_fo: meta_check_r_dentry: \
5039 +                                  invalid inode passed.\n");
5040 +               return NULL;
5041 +       }
5042 +       inode_info = itopd(inode);
5043 +       
5044 +        if(inode_info->renamed_list_size <= 0)
5045 +                return NULL;
5046 +       
5047 +        list_for_each(tmp, &inode_info->renamed_list) {
5048 +               ren_entry = list_entry(tmp, struct renamed_entry, list);
5049 +               if(ren_entry->new_len != len)
5050 +                       continue;
5051 +               
5052 +               if(!strncmp(ren_entry->new_name, name, len)) {
5053 +                       old_path = (char *) 
5054 +                               kmalloc(ren_entry->old_len+1, GFP_KERNEL);
5055 +                       strncpy(old_path, 
5056 +                               ren_entry->old_name, 
5057 +                               ren_entry->old_len);
5058 +                       old_path[ren_entry->old_len]='\0';
5059 +                       return old_path;
5060 +               }
5061 +       }
5062 +       return NULL;
5063 +}
5064 +
5065 +/*
5066 + * This version only checks if entry exists and return:
5067 + *     1 if exists,
5068 + *     0 if not,
5069 + *    -1 if error.
5070 + */
5071 +int meta_is_r_entry(dentry_t *dentry, const char *name, int len) 
5072 +{
5073 +       if(!dentry || !dentry->d_inode) {
5074 +               printk(KERN_CRIT "mini_fo: meta_check_r_dentry [2]: \
5075 +                                  invalid dentry passed.\n");
5076 +               return -1;
5077 +       }
5078 +       return __meta_is_r_entry(dentry->d_inode, name, len);   
5079 +}
5080 +
5081 +int __meta_is_r_entry(inode_t *inode, const char *name, int len)
5082 +{
5083 +       struct list_head *tmp;
5084 +        struct renamed_entry *ren_entry;
5085 +        struct mini_fo_inode_info *inode_info;
5086 +       
5087 +       if(!inode || !itopd(inode)) {
5088 +               printk(KERN_CRIT "mini_fo: meta_check_r_dentry [2]: \
5089 +                                  invalid inode passed.\n");
5090 +               return -1;
5091 +       }
5092 +       inode_info = itopd(inode);
5093 +       
5094 +        if(inode_info->renamed_list_size <= 0)
5095 +                return -1;
5096 +       
5097 +        list_for_each(tmp, &inode_info->renamed_list) {
5098 +               ren_entry = list_entry(tmp, struct renamed_entry, list);
5099 +               if(ren_entry->new_len != len)
5100 +                       continue;
5101 +               
5102 +               if(!strncmp(ren_entry->new_name, name, len)) 
5103 +                       return 1;
5104 +       }
5105 +       return 0;
5106 +}
5107 +
5108 diff -urN linux.old/fs/mini_fo/mini_fo.h linux.dev/fs/mini_fo/mini_fo.h
5109 --- linux.old/fs/mini_fo/mini_fo.h      1970-01-01 01:00:00.000000000 +0100
5110 +++ linux.dev/fs/mini_fo/mini_fo.h      2006-11-17 03:11:48.000000000 +0100
5111 @@ -0,0 +1,503 @@
5112 +/*
5113 + * Copyright (c) 1997-2003 Erez Zadok
5114 + * Copyright (c) 2001-2003 Stony Brook University
5115 + *
5116 + * For specific licensing information, see the COPYING file distributed with
5117 + * this package, or get one from ftp://ftp.filesystems.org/pub/fist/COPYING.
5118 + *
5119 + * This Copyright notice must be kept intact and distributed with all
5120 + * fistgen sources INCLUDING sources generated by fistgen.
5121 + */
5122 +/*
5123 + * Copyright (C) 2004, 2005 Markus Klotzbuecher <mk@creamnet.de>
5124 + *
5125 + * This program is free software; you can redistribute it and/or
5126 + * modify it under the terms of the GNU General Public License
5127 + * as published by the Free Software Foundation; either version
5128 + * 2 of the License, or (at your option) any later version.
5129 + */
5130 +
5131 +/*
5132 + *  $Id$
5133 + */
5134 +
5135 +#ifndef __MINI_FO_H_
5136 +#define __MINI_FO_H_
5137 +
5138 +#ifdef __KERNEL__
5139 +
5140 +/* META stuff */
5141 +#define META_FILENAME "META_dAfFgHE39ktF3HD2sr"
5142 +
5143 +/* use xattrs? */
5144 +#define XATTR
5145 +
5146 +/* File attributes that when changed, result in a file beeing copied to storage */
5147 +#define COPY_FLAGS ATTR_MODE | ATTR_UID | ATTR_GID | ATTR_SIZE
5148 +
5149 +/*
5150 + * mini_fo filestates
5151 + */
5152 +#define MODIFIED       1
5153 +#define UNMODIFIED     2
5154 +#define CREATED        3
5155 +#define DEL_REWRITTEN  4
5156 +#define DELETED        5
5157 +#define NON_EXISTANT   6
5158 +
5159 +/* fist file systems superblock magic */
5160 +# define MINI_FO_SUPER_MAGIC 0xf15f
5161 +
5162 +/*
5163 + * STRUCTURES:
5164 + */
5165 +
5166 +/* mini_fo inode data in memory */
5167 +struct mini_fo_inode_info {
5168 +       inode_t *wii_inode;
5169 +       inode_t *wii_inode2; /* pointer to storage inode */
5170 +
5171 +       /* META-data lists */
5172 +       /* deleted list, ex wol */
5173 +       struct list_head deleted_list;
5174 +       int deleted_list_size;
5175 +
5176 +       /* renamed list */
5177 +       struct list_head renamed_list;
5178 +       int renamed_list_size;
5179 +
5180 +       /* add other lists here ... */
5181 +};
5182 +
5183 +/* mini_fo dentry data in memory */
5184 +struct mini_fo_dentry_info {
5185 +       dentry_t *wdi_dentry;
5186 +       dentry_t *wdi_dentry2; /* pointer to  storage dentry */
5187 +       unsigned int state;  /* state of the mini_fo dentry */
5188 +};
5189 +
5190 +
5191 +/* mini_fo super-block data in memory */
5192 +struct mini_fo_sb_info {
5193 +       super_block_t *wsi_sb, *wsi_sb2; /* mk: might point to the same sb */
5194 +       struct vfsmount *hidden_mnt, *hidden_mnt2;
5195 +       dentry_t *base_dir_dentry;
5196 +       dentry_t *storage_dir_dentry;
5197 +       ;
5198 +};
5199 +
5200 +/* readdir_data, readdir helper struct */
5201 +struct readdir_data {
5202 +       struct list_head ndl_list; /* linked list head ptr */
5203 +       int ndl_size; /* list size */
5204 +       int sto_done; /* flag to show that the storage dir entries have
5205 +                      * all been read an now follow base entries */
5206 +};
5207 +
5208 +/* file private data. */
5209 +struct mini_fo_file_info {
5210 +       struct file *wfi_file;
5211 +       struct file *wfi_file2; /* pointer to storage file */
5212 +       struct readdir_data rd;
5213 +};
5214 +
5215 +/* struct ndl_entry */
5216 +struct ndl_entry {
5217 +       struct list_head list;
5218 +       char *name;
5219 +       int len;
5220 +};
5221 +
5222 +/********************************
5223 + *  META-data structures
5224 + ********************************/
5225 +
5226 +/* deleted entry */
5227 +struct deleted_entry {
5228 +       struct list_head list;
5229 +       char *name;
5230 +       int len;
5231 +};
5232 +
5233 +/* renamed entry */
5234 +struct renamed_entry {
5235 +       struct list_head list;
5236 +       char *old_name;     /* old directory with full path */
5237 +       int old_len;        /* length of above string */
5238 +       char *new_name;     /* new directory name */
5239 +       int new_len;        /* length of above string */
5240 +};
5241 +
5242 +/* attr_change entry */
5243 +struct attr_change_entry {
5244 +       struct list_head list;
5245 +       char *name;
5246 +       int len;
5247 +};
5248 +
5249 +/* link entry */
5250 +struct link_entry {
5251 +       struct list_head list;
5252 +       int links_moved;
5253 +       int inum_base;
5254 +       int inum_sto;
5255 +       char *weird_name;
5256 +       int weird_name_len;
5257 +};
5258 +
5259 +
5260 +/* Some other stuff required for mini_fo_filldir64, copied from
5261 + * fs/readdir.c
5262 + */
5263 +
5264 +#define ROUND_UP64(x) (((x)+sizeof(u64)-1) & ~(sizeof(u64)-1))
5265 +#define NAME_OFFSET(de) ((int) ((de)->d_name - (char *) (de)))
5266 +
5267 +
5268 +struct linux_dirent64 {
5269 +        u64             d_ino;
5270 +        s64             d_off;
5271 +        unsigned short  d_reclen;
5272 +        unsigned char   d_type;
5273 +        char            d_name[0];
5274 +};
5275 +
5276 +
5277 +struct getdents_callback64 {
5278 +        struct linux_dirent64 * current_dir;
5279 +        struct linux_dirent64 * previous;
5280 +        int count;
5281 +        int error;
5282 +};
5283 +
5284 +struct linux_dirent {
5285 +       unsigned long   d_ino;
5286 +       unsigned long   d_off;
5287 +       unsigned short  d_reclen;
5288 +       char            d_name[1];
5289 +};
5290 +
5291 +struct getdents_callback {
5292 +       struct linux_dirent * current_dir;
5293 +       struct linux_dirent * previous;
5294 +       int count;
5295 +       int error;
5296 +};
5297 +
5298 +
5299 +/*
5300 + * MACROS:
5301 + */
5302 +
5303 +/* file TO private_data */
5304 +# define ftopd(file) ((struct mini_fo_file_info *)((file)->private_data))
5305 +# define __ftopd(file) ((file)->private_data)
5306 +/* file TO hidden_file */
5307 +# define ftohf(file) ((ftopd(file))->wfi_file)
5308 +# define ftohf2(file) ((ftopd(file))->wfi_file2) 
5309 +
5310 +/* inode TO private_data */
5311 +# define itopd(ino) ((struct mini_fo_inode_info *)(ino)->u.generic_ip)
5312 +# define __itopd(ino) ((ino)->u.generic_ip)
5313 +/* inode TO hidden_inode */
5314 +# define itohi(ino) (itopd(ino)->wii_inode)
5315 +# define itohi2(ino) (itopd(ino)->wii_inode2)
5316 +
5317 +/* superblock TO private_data */
5318 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
5319 +# define stopd(super) ((struct mini_fo_sb_info *)(super)->s_fs_info)
5320 +# define __stopd(super) ((super)->s_fs_info)
5321 +#else
5322 +# define stopd(super) ((struct mini_fo_sb_info *)(super)->u.generic_sbp)
5323 +# define __stopd(super) ((super)->u.generic_sbp)
5324 +#endif
5325 +
5326 +/* unused? # define vfs2priv stopd */
5327 +/* superblock TO hidden_superblock */
5328 +
5329 +# define stohs(super) (stopd(super)->wsi_sb)
5330 +# define stohs2(super) (stopd(super)->wsi_sb2)
5331 +
5332 +/* dentry TO private_data */
5333 +# define dtopd(dentry) ((struct mini_fo_dentry_info *)(dentry)->d_fsdata)
5334 +# define __dtopd(dentry) ((dentry)->d_fsdata)
5335 +/* dentry TO hidden_dentry */
5336 +# define dtohd(dent) (dtopd(dent)->wdi_dentry)
5337 +# define dtohd2(dent) (dtopd(dent)->wdi_dentry2)
5338 +
5339 +/* dentry to state */
5340 +# define dtost(dent) (dtopd(dent)->state)
5341 +# define sbt(sb) ((sb)->s_type->name)
5342 +
5343 +#define IS_WRITE_FLAG(flag) (flag & (O_RDWR | O_WRONLY | O_APPEND))
5344 +#define IS_COPY_FLAG(flag) (flag & (COPY_FLAGS))
5345 +
5346 +/* macros to simplify non-SCA code */
5347 +#  define MALLOC_PAGE_POINTERS(hidden_pages, num_hidden_pages)
5348 +#  define MALLOC_PAGEDATA_POINTERS(hidden_pages_data, num_hidden_pages)
5349 +#  define FREE_PAGE_POINTERS(hidden_pages, num)
5350 +#  define FREE_PAGEDATA_POINTERS(hidden_pages_data, num)
5351 +#  define FOR_EACH_PAGE
5352 +#  define CURRENT_HIDDEN_PAGE hidden_page
5353 +#  define CURRENT_HIDDEN_PAGEDATA hidden_page_data
5354 +#  define CURRENT_HIDDEN_PAGEINDEX page->index
5355 +
5356 +/*
5357 + * EXTERNALS:
5358 + */
5359 +extern struct file_operations mini_fo_main_fops;
5360 +extern struct file_operations mini_fo_dir_fops;
5361 +extern struct inode_operations mini_fo_main_iops;
5362 +extern struct inode_operations mini_fo_dir_iops;
5363 +extern struct inode_operations mini_fo_symlink_iops;
5364 +extern struct super_operations mini_fo_sops;
5365 +extern struct dentry_operations mini_fo_dops;
5366 +extern struct vm_operations_struct mini_fo_shared_vmops;
5367 +extern struct vm_operations_struct mini_fo_private_vmops;
5368 +extern struct address_space_operations mini_fo_aops;
5369 +
5370 +#if 0 /* unused by mini_fo */
5371 +extern int mini_fo_interpose(dentry_t *hidden_dentry, dentry_t *this_dentry, super_block_t *sb, int flag);
5372 +#if defined(FIST_FILTER_DATA) || defined(FIST_FILTER_SCA)
5373 +extern page_t *mini_fo_get1page(file_t *file, int index);
5374 +extern int mini_fo_fill_zeros(file_t *file, page_t *page, unsigned from);
5375 +# endif /* FIST_FILTER_DATA || FIST_FILTER_SCA */
5376 +
5377 +
5378 +#  define mini_fo_hidden_dentry(d) __mini_fo_hidden_dentry(__FILE__,__FUNCTION__,__LINE__,(d))
5379 +#  define mini_fo_hidden_sto_dentry(d) __mini_fo_hidden_sto_dentry(__FILE__,__FUNCTION__,__LINE__,(d))
5380 +
5381 +extern dentry_t *__mini_fo_hidden_dentry(char *file, char *func, int line, dentry_t *this_dentry);
5382 +extern dentry_t *__mini_fo_hidden_sto_dentry(char *file, char *func, int line, dentry_t *this_dentry);
5383 +
5384 +extern int mini_fo_read_file(const char *filename, void *buf, int len);
5385 +extern int mini_fo_write_file(const char *filename, void *buf, int len);
5386 +extern dentry_t *fist_lookup(dentry_t *dir, const char *name, vnode_t **out, uid_t uid, gid_t gid);
5387 +#endif /* unused by mini_fo */
5388 +
5389 +/* state transition functions */
5390 +extern int nondir_unmod_to_mod(dentry_t *dentry, int cp_flag);
5391 +extern int nondir_del_rew_to_del(dentry_t *dentry);
5392 +extern int nondir_creat_to_del(dentry_t *dentry);
5393 +extern int nondir_mod_to_del(dentry_t *dentry);
5394 +extern int nondir_unmod_to_del(dentry_t *dentry);
5395 +
5396 +extern int dir_unmod_to_mod(dentry_t *dentry);
5397 +
5398 +/* rename specials */
5399 +extern int rename_directory(inode_t *old_dir, dentry_t *old_dentry, inode_t *new_dir, dentry_t *new_dentry);
5400 +extern int rename_nondir(inode_t *old_dir, dentry_t *old_dentry, inode_t *new_dir, dentry_t *new_dentry);
5401 +
5402 +/* misc stuff */
5403 +extern int mini_fo_tri_interpose(dentry_t *hidden_dentry,
5404 +                                dentry_t *hidden_sto_dentry,
5405 +                                dentry_t *dentry, 
5406 +                                super_block_t *sb, int flag);
5407 +
5408 +extern int mini_fo_cp_cont(dentry_t *tgt_dentry, struct vfsmount *tgt_mnt,
5409 +                          dentry_t *src_dentry, struct vfsmount *src_mnt);
5410 +
5411 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
5412 +extern int mini_fo_create(inode_t *dir, dentry_t *dentry, int mode, struct nameidata *nd);
5413 +
5414 +extern int create_sto_nod(dentry_t *dentry, int mode, dev_t dev);
5415 +extern int create_sto_reg_file(dentry_t *dentry, int mode, struct nameidata *nd);
5416 +#else
5417 +extern int mini_fo_create(inode_t *dir, dentry_t *dentry, int mode);
5418 +
5419 +extern int create_sto_nod(dentry_t *dentry, int mode, int dev);
5420 +extern int create_sto_reg_file(dentry_t *dentry, int mode);
5421 +#endif
5422 +
5423 +extern int create_sto_dir(dentry_t *dentry, int mode);
5424 +
5425 +extern int exists_in_storage(dentry_t *dentry);
5426 +extern int is_mini_fo_existant(dentry_t *dentry);
5427 +extern int get_neg_sto_dentry(dentry_t *dentry);
5428 +extern int build_sto_structure(dentry_t *dir, dentry_t *dentry);
5429 +extern int get_mini_fo_bpath(dentry_t *dentry, char **bpath, int *bpath_len);
5430 +extern dentry_t *bpath_walk(super_block_t *sb, char *bpath);
5431 +extern int bpath_put(dentry_t *dentry);
5432 +
5433 +/* check_mini_fo types functions */
5434 +extern int check_mini_fo_dentry(dentry_t *dentry);
5435 +extern int check_mini_fo_file(file_t *file);
5436 +extern int check_mini_fo_inode(inode_t *inode);
5437 +
5438 +/* General meta functions, can be called from outside of meta.c */
5439 +extern int meta_build_lists(dentry_t *dentry);
5440 +extern int meta_put_lists(dentry_t *dentry);
5441 +extern int __meta_put_lists(inode_t *inode);
5442 +
5443 +extern int meta_add_d_entry(dentry_t *dentry, const char *name, int len);
5444 +extern int meta_add_r_entry(dentry_t *dentry, 
5445 +                           const char *old_name, int old_len, 
5446 +                           const char *new_name, int new_len);
5447 +
5448 +extern int meta_remove_r_entry(dentry_t *dentry, const char *name, int len);
5449 +
5450 +extern int meta_check_d_entry(dentry_t *dentry, const char *name, int len);
5451 +extern int __meta_check_d_entry(inode_t *inode, const char *name, int len);
5452 +
5453 +extern char* meta_check_r_entry(dentry_t *dentry, const char *name, int len);
5454 +extern char* __meta_check_r_entry(inode_t *inode, const char *name, int len);
5455 +extern int meta_is_r_entry(dentry_t *dentry, const char *name, int len);
5456 +extern int __meta_is_r_entry(inode_t *inode, const char *name, int len);
5457 +
5458 +/* Specific meta functions, should be called only inside meta.c */
5459 +extern int __meta_put_d_list(inode_t *inode);
5460 +extern int __meta_put_r_list(inode_t *inode);
5461 +
5462 +extern int meta_list_add_d_entry(dentry_t *dentry, 
5463 +                                const char *name, int len);
5464 +extern int meta_list_add_r_entry(dentry_t *dentry, 
5465 +                                const char *old_name, int old_len, 
5466 +                                const char *new_name, int new_len);
5467 +
5468 +extern int meta_list_remove_r_entry(dentry_t *dentry, 
5469 +                                   const char *name, int len);
5470 +
5471 +extern int __meta_list_remove_r_entry(inode_t *inode, 
5472 +                                     const char *name, int len);
5473 +
5474 +extern int meta_write_d_entry(dentry_t *dentry, const char *name, int len);
5475 +extern int meta_write_r_entry(dentry_t *dentry, 
5476 +                             const char *old_name, int old_len, 
5477 +                             const char *new_name, int new_len);
5478 +
5479 +extern int meta_sync_lists(dentry_t *dentry);
5480 +extern int meta_sync_d_list(dentry_t *dentry, int app_flag);
5481 +extern int meta_sync_r_list(dentry_t *dentry, int app_flag);
5482 +
5483 +/* ndl stuff */
5484 +extern int ndl_add_entry(struct readdir_data *rd, const char *name, int len);
5485 +extern void ndl_put_list(struct readdir_data *rd);
5486 +extern int ndl_check_entry(struct readdir_data *rd, 
5487 +                          const char *name, int len);
5488 +
5489 +
5490 +# define copy_inode_size(dst, src) \
5491 +    dst->i_size = src->i_size; \
5492 +    dst->i_blocks = src->i_blocks;
5493 +
5494 +static inline void
5495 +fist_copy_attr_atime(inode_t *dest, const inode_t *src)
5496 +{
5497 +       ASSERT(dest != NULL);
5498 +       ASSERT(src != NULL);
5499 +       dest->i_atime = src->i_atime;
5500 +}
5501 +static inline void
5502 +fist_copy_attr_times(inode_t *dest, const inode_t *src)
5503 +{
5504 +       ASSERT(dest != NULL);
5505 +       ASSERT(src != NULL);
5506 +       dest->i_atime = src->i_atime;
5507 +       dest->i_mtime = src->i_mtime;
5508 +       dest->i_ctime = src->i_ctime;
5509 +}
5510 +static inline void
5511 +fist_copy_attr_timesizes(inode_t *dest, const inode_t *src)
5512 +{
5513 +       ASSERT(dest != NULL);
5514 +       ASSERT(src != NULL);
5515 +       dest->i_atime = src->i_atime;
5516 +       dest->i_mtime = src->i_mtime;
5517 +       dest->i_ctime = src->i_ctime;
5518 +       copy_inode_size(dest, src);
5519 +}
5520 +static inline void
5521 +fist_copy_attr_all(inode_t *dest, const inode_t *src)
5522 +{
5523 +       ASSERT(dest != NULL);
5524 +       ASSERT(src != NULL);
5525 +       dest->i_mode = src->i_mode;
5526 +       dest->i_nlink = src->i_nlink;
5527 +       dest->i_uid = src->i_uid;
5528 +       dest->i_gid = src->i_gid;
5529 +       dest->i_rdev = src->i_rdev;
5530 +       dest->i_atime = src->i_atime;
5531 +       dest->i_mtime = src->i_mtime;
5532 +       dest->i_ctime = src->i_ctime;
5533 +       dest->i_blksize = src->i_blksize;
5534 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,12)
5535 +       dest->i_blkbits = src->i_blkbits;
5536 +# endif /* linux 2.4.12 and newer */
5537 +       copy_inode_size(dest, src);
5538 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
5539 +       dest->i_attr_flags = src->i_attr_flags;
5540 +#else
5541 +       dest->i_flags = src->i_flags;
5542 +#endif
5543 +}
5544 +
5545 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
5546 +/* copied from linux/fs.h */
5547 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
5548 +static inline void double_lock(struct dentry *d1, struct dentry *d2)
5549 +{
5550 +       struct mutex *m1 = &d1->d_inode->i_mutex;
5551 +       struct mutex *m2 = &d2->d_inode->i_mutex;
5552 +       if (m1 != m2) {
5553 +               if ((unsigned long) m1 < (unsigned long) m2) {
5554 +                       struct mutex *tmp = m2;
5555 +                       m2 = m1; m1 = tmp;
5556 +               }
5557 +               mutex_lock(m1);
5558 +       }
5559 +       mutex_lock(m2);
5560 +}
5561 +
5562 +static inline void double_unlock(struct dentry *d1, struct dentry *d2)
5563 +{
5564 +       struct mutex *m1 = &d1->d_inode->i_mutex;
5565 +       struct mutex *m2 = &d2->d_inode->i_mutex;
5566 +       mutex_unlock(m1);
5567 +       if (m1 != m2)
5568 +               mutex_unlock(m2);
5569 +       dput(d1);
5570 +       dput(d2);
5571 +}
5572 +
5573 +#else
5574 +static inline void double_down(struct semaphore *s1, struct semaphore *s2)
5575 +{
5576 +        if (s1 != s2) {
5577 +                if ((unsigned long) s1 < (unsigned long) s2) {
5578 +                        struct semaphore *tmp = s2;
5579 +                        s2 = s1; s1 = tmp;
5580 +                }
5581 +                down(s1);
5582 +        }
5583 +        down(s2);
5584 +}
5585 +
5586 +static inline void double_up(struct semaphore *s1, struct semaphore *s2)
5587 +{
5588 +        up(s1);
5589 +        if (s1 != s2)
5590 +                up(s2);
5591 +}
5592 +
5593 +static inline void double_lock(struct dentry *d1, struct dentry *d2)
5594 +{
5595 +        double_down(&d1->d_inode->i_sem, &d2->d_inode->i_sem);
5596 +}
5597 +
5598 +static inline void double_unlock(struct dentry *d1, struct dentry *d2)
5599 +{
5600 +        double_up(&d1->d_inode->i_sem,&d2->d_inode->i_sem);
5601 +        dput(d1);
5602 +        dput(d2);
5603 +}
5604 +#endif   /* if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16) */
5605 +#endif  /* if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0) */
5606 +#endif /* __KERNEL__ */
5607 +
5608 +/*
5609 + * Definitions for user and kernel code
5610 + */
5611 +
5612 +/* ioctls */
5613 +
5614 +#endif /* not __MINI_FO_H_ */
5615 diff -urN linux.old/fs/mini_fo/mini_fo-merge linux.dev/fs/mini_fo/mini_fo-merge
5616 --- linux.old/fs/mini_fo/mini_fo-merge  1970-01-01 01:00:00.000000000 +0100
5617 +++ linux.dev/fs/mini_fo/mini_fo-merge  2006-11-17 03:11:48.000000000 +0100
5618 @@ -0,0 +1,180 @@
5619 +#!/bin/bash
5620 +#
5621 +# Copyright (C) 2005 Markus Klotzbuecher <mk@creamnet.de>
5622 +# This program is free software; you can redistribute it and/or
5623 +# modify it under the terms of the GNU General Public License
5624 +# as published by the Free Software Foundation; either version
5625 +# 2 of the License, or (at your option) any later version.
5626 +#
5627 +
5628 +BASE=
5629 +STO=
5630 +HELP=
5631 +DRYRUN=
5632 +VERBOSE=
5633 +TMP="/tmp/"
5634 +META_NAME="META_dAfFgHE39ktF3HD2sr"
5635 +SKIP_DEL_LIST="skip-delete-list.mini_fo-merge"
5636 +
5637 +COMMAND=
5638 +exec_command()
5639 +{
5640 +    if [ x$DRYRUN == "xset" ]; then
5641 +       echo "  would run: $COMMAND"
5642 +    elif ! [ x$DRYRUN == "xset" ]; then
5643 +       if [ x$VERBOSE == "xset" ]; then
5644 +           echo "  running: $COMMAND"
5645 +       fi
5646 +       eval $COMMAND
5647 +    fi
5648 +}
5649 +
5650 +usage()
5651 +{
5652 +cat <<EOF
5653 +
5654 +USAGE: $0 -b <base dir> -s <storage dir>
5655 +Version 0.1
5656 +
5657 +This script merges the contents of a mini_fo storage file system back
5658 +to the base file system.
5659 +
5660 +!!! Warning: This will modify the base filesystem and can destroy data
5661 +             if used wrongly.
5662 +
5663 +Options:
5664 +     -b <base dir>
5665 +          the directory of the base file system.
5666 +
5667 +     -s <storage dir>
5668 +          the directory of the storage file system.
5669 +
5670 +     -d   dry run, will not change anything and print the commands that
5671 +          would be executed.
5672 +
5673 +     -t   tmp dir for storing temporary file. default: $TMP
5674 +
5675 +     -v   show what operations are performed.
5676 +
5677 +     -h   displays this message.
5678 +
5679 +EOF
5680 +}
5681 +
5682 +# parse parameters
5683 +while getopts hdvt:b:s: OPTS
5684 +  do
5685 +  case $OPTS in
5686 +      h)  HELP="set";;
5687 +      d)  DRYRUN="set";;
5688 +      v)  VERBOSE="set";;
5689 +      b)  BASE="$OPTARG";;
5690 +      s)  STO="$OPTARG";;
5691 +      t)  TMP="$OPTARG";;
5692 +      ?)  usage
5693 +         exit 1;;
5694 +  esac
5695 +done
5696 +
5697 +if [ "x$HELP" == "xset" ]; then
5698 +    usage
5699 +    exit -1
5700 +fi
5701 +
5702 +if ! [ -d "$BASE" ] || ! [ -d "$STO" ]; then
5703 +    echo -e "$0:\n Error, -s and/or -b argument missing. type $0 -h for help."
5704 +    exit -1;
5705 +fi
5706 +
5707 +# get full paths
5708 +pushd $STO; STO=`pwd`; popd
5709 +pushd $BASE; BASE=`pwd`; popd
5710 +TMP=${TMP%/}
5711 +
5712 +
5713 +cat<<EOF
5714 +###############################################################################
5715 +# mini_fo-merge
5716 +#
5717 +# base dir:       $BASE
5718 +# storage dir:    $STO
5719 +# meta filename:  $META_NAME
5720 +# dry run:        $DRYRUN
5721 +# verbose:        $VERBOSE     
5722 +# tmp files:      $TMP
5723 +###############################################################################
5724 +
5725 +EOF
5726 +
5727 +rm $TMP/$SKIP_DEL_LIST
5728 +
5729 +# first process all renamed dirs
5730 +echo "Merging renamed directories..."
5731 +pushd $STO &> /dev/null
5732 +find . -name $META_NAME -type f -print0  | xargs -0 -e grep  -e '^R ' | tr -s ':R' ' ' | while read ENTRY; do 
5733 +    echo "entry: $ENTRY"
5734 +    META_FILE=`echo $ENTRY | cut -d ' ' -f 1`
5735 +    OLD_B_DIR=`echo $ENTRY | cut -d ' ' -f 2 | sed -e 's/\///'`
5736 +    NEW_NAME=`echo $ENTRY | cut -d ' ' -f 3`
5737 +    NEW_B_DIR=`echo $META_FILE | sed -e "s/$META_NAME/$NEW_NAME/" | sed -e 's/^\.\///'`
5738 +    echo "META_FILE: $META_FILE"
5739 +    echo "OLD_B_DIR: $OLD_B_DIR"
5740 +    echo "NEW_NAME: $NEW_NAME"
5741 +    echo  "NEW_B_DIR: $NEW_B_DIR"
5742 +
5743 +    pushd $BASE &> /dev/null
5744 +    # remove an existing dir in storage
5745 +    COMMAND="rm -rf $NEW_B_DIR"; exec_command
5746 +    COMMAND="cp -R $OLD_B_DIR $NEW_B_DIR"; exec_command
5747 +    echo ""
5748 +    popd &> /dev/null
5749 +
5750 +    # remember this dir to exclude it from deleting later
5751 +    echo $NEW_B_DIR >> $TMP/$SKIP_DEL_LIST
5752 +done
5753 +
5754 +# delete all whiteouted files from base
5755 +echo -e "\nDeleting whiteout'ed files from base file system..."
5756 +find . -name $META_NAME -type f -print0  | xargs -0 -e grep  -e '^D ' | sed -e 's/:D//' | while read ENTRY; do 
5757 +    META_FILE=`echo $ENTRY | cut -d ' ' -f 1`
5758 +    DEL_NAME=`echo $ENTRY | cut -d ' ' -f 2`
5759 +    DEL_FILE=`echo $META_FILE | sed -e "s/$META_NAME/$DEL_NAME/" | sed -e 's/^\.\///'`
5760 +    grep -x $DEL_FILE $TMP/$SKIP_DEL_LIST &> /dev/null
5761 +    if [ $? -ne 0 ]; then
5762 +       pushd $BASE &> /dev/null
5763 +       COMMAND="rm -rf $DEL_FILE"; exec_command
5764 +       popd &> /dev/null
5765 +    else
5766 +       echo "  excluding: $DEL_FILE as in skip-del-list."
5767 +    fi
5768 +done
5769 +
5770 +# create all dirs and update permissions
5771 +echo -e "\nSetting up directory structures in base file system..."
5772 +find . -type d | sed -e 's/^\.\///' | while read DIR; do
5773 +    PERMS=`stat -c %a $DIR`
5774 +    DIR_UID=`stat -c %u $DIR`
5775 +    DIR_GID=`stat -c %g $DIR`
5776 +    pushd $BASE &> /dev/null
5777 +    if ! [ -d $DIR ]; then
5778 +       COMMAND="mkdir -p $DIR"; exec_command
5779 +    fi
5780 +    COMMAND="chmod $PERMS $DIR"; exec_command
5781 +    COMMAND="chown $DIR_UID:$DIR_GID $DIR"; exec_command
5782 +    popd &> /dev/null
5783 +done
5784 +
5785 +# merge all non-directory files
5786 +echo -e "\nMerging all non-directory files...."
5787 +for i in b c p f l s; do
5788 +    find . -type $i | sed -e 's/^\.\///' | grep -v "$META_NAME" | while read FILE; do
5789 +       pushd $BASE #&> /dev/null
5790 +       COMMAND="cp -df $STO/$FILE $BASE/$FILE"; exec_command
5791 +       popd &> /dev/null
5792 +    done   
5793 +done
5794 +popd &> /dev/null
5795 +
5796 +#rm $TMP/$SKIP_DEL_LIST 
5797 +
5798 +echo "Done!"
5799 diff -urN linux.old/fs/mini_fo/mini_fo-overlay linux.dev/fs/mini_fo/mini_fo-overlay
5800 --- linux.old/fs/mini_fo/mini_fo-overlay        1970-01-01 01:00:00.000000000 +0100
5801 +++ linux.dev/fs/mini_fo/mini_fo-overlay        2006-11-17 03:11:48.000000000 +0100
5802 @@ -0,0 +1,130 @@
5803 +#!/bin/bash
5804 +#
5805 +# Copyright (C) 2005 Markus Klotzbuecher <mk@creamnet.de>
5806 +# This program is free software; you can redistribute it and/or
5807 +# modify it under the terms of the GNU General Public License
5808 +# as published by the Free Software Foundation; either version
5809 +# 2 of the License, or (at your option) any later version.
5810 +#
5811 +
5812 +HELP=
5813 +SUFF=
5814 +MNTP=
5815 +MNT_DIR="/mnt"
5816 +STO=
5817 +STO_DIR="/tmp"
5818 +BASE=
5819 +
5820 +usage() 
5821 +{
5822 +cat <<EOF
5823 +
5824 +Usage: $0 [-s suffix] [-d sto_dir_dir] [-m mount point] base_dir
5825 +Version 0.1
5826 +
5827 +This script overlays the given base directory using the mini_fo file
5828 +system. If only the base directory base_dir is given, $0 
5829 +will use a storage directory called "sto-<base_dir_name>" in $STO_DIR,
5830 +and mount point "mini_fo-<base_dir_dir>" in $MNT_DIR.
5831 +
5832 +Options:
5833 +     -s <suffix>
5834 +          add given suffix to storage directory and the mount
5835 +          point. This is usefull for overlaying one base directory
5836 +          several times and avoiding conflicts with storage directory
5837 +          names and mount points.
5838 +
5839 +     -d <sto_dir_dir>
5840 +          change the directory in which the storage directory will be
5841 +          created (default is currently "$STO_DIR".
5842 +
5843 +     -m <mount point>
5844 +          use an alternative directory to create the mini_fo
5845 +          mountpoint (default is currently "$MNT_DIR".
5846 +
5847 +     -h   displays this message.
5848 +
5849 +EOF
5850 +exit 1;
5851 +}
5852 +
5853 +while getopts hm:s:d: OPTS
5854 +  do
5855 +  case $OPTS in
5856 +      s)  SUFF="$OPTARG";;
5857 +      d)  STO_DIR="$OPTARG";;
5858 +      m)  MNT_DIR="$OPTARG";;
5859 +      h)  HELP="set";;
5860 +      ?)  usage
5861 +         exit 1;;
5862 +  esac
5863 +done
5864 +shift $(($OPTIND - 1))
5865 +
5866 +BASE="$1"
5867 +
5868 +if [ "x$HELP" == "xset" ]; then
5869 +    usage
5870 +    exit -1
5871 +fi
5872 +
5873 +# fix suffix 
5874 +if [ "x$SUFF" != "x" ]; then
5875 +    SUFF="-$SUFF"
5876 +fi
5877 +
5878 +# kill trailing slashes
5879 +MNT_DIR=${MNT_DIR%/}
5880 +STO_DIR=${STO_DIR%/}
5881 +BASE=${BASE%/}
5882 +
5883 +
5884 +if ! [ -d "$BASE" ]; then
5885 +    echo "invalid base dir $BASE, run $0 -h for help."
5886 +    exit -1
5887 +fi
5888 +
5889 +# check opts
5890 +if ! [ -d "$MNT_DIR" ]; then
5891 +    echo "invalid mount dir $MNT_DIR, run $0 -h for help."
5892 +    exit -1
5893 +fi
5894 +
5895 +if ! [ -d "$STO_DIR" ]; then
5896 +    echo "invalid sto_dir_dir $STO_DIR, run $0 -h for help."
5897 +    exit -1
5898 +fi
5899 +
5900 +MNTP="$MNT_DIR/mini_fo-`basename $BASE`$SUFF"
5901 +STO="$STO_DIR/sto-`basename $BASE`$SUFF"
5902 +
5903 +# create the mount point if it doesn't exist
5904 +mkdir -p $MNTP
5905 +if [ $? -ne 0 ]; then
5906 +    echo "Error, failed to create mount point $MNTP"
5907 +fi
5908 +
5909 +mkdir -p $STO
5910 +if [ $? -ne 0 ]; then
5911 +    echo "Error, failed to create storage dir $STO"
5912 +fi
5913 +
5914 +# check if fs is already mounted
5915 +mount | grep mini_fo | grep $MNTP &> /dev/null
5916 +if [ $? -eq 0 ]; then
5917 +    echo "Error, existing mini_fo mount at $MNTP."
5918 +    exit -1
5919 +fi
5920 +
5921 +mount | grep mini_fo | grep $STO &> /dev/null
5922 +if [ $? -eq 0 ]; then
5923 +    echo "Error, $STO seems to be used already."
5924 +    exit -1
5925 +fi
5926 +
5927 +# mount 
5928 +mount -t mini_fo -o base=$BASE,sto=$STO $BASE $MNTP
5929 +
5930 +if [ $? -ne 0 ]; then
5931 +    echo "Error, mounting failed, maybe no permisson to mount?"
5932 +fi
5933 diff -urN linux.old/fs/mini_fo/mmap.c linux.dev/fs/mini_fo/mmap.c
5934 --- linux.old/fs/mini_fo/mmap.c 1970-01-01 01:00:00.000000000 +0100
5935 +++ linux.dev/fs/mini_fo/mmap.c 2006-11-17 03:11:48.000000000 +0100
5936 @@ -0,0 +1,637 @@
5937 +/*
5938 + * Copyright (c) 1997-2003 Erez Zadok
5939 + * Copyright (c) 2001-2003 Stony Brook University
5940 + *
5941 + * For specific licensing information, see the COPYING file distributed with
5942 + * this package, or get one from ftp://ftp.filesystems.org/pub/fist/COPYING.
5943 + *
5944 + * This Copyright notice must be kept intact and distributed with all
5945 + * fistgen sources INCLUDING sources generated by fistgen.
5946 + */
5947 +/*
5948 + * Copyright (C) 2004, 2005 Markus Klotzbuecher <mk@creamnet.de>
5949 + *
5950 + * This program is free software; you can redistribute it and/or
5951 + * modify it under the terms of the GNU General Public License
5952 + * as published by the Free Software Foundation; either version
5953 + * 2 of the License, or (at your option) any later version.
5954 + */
5955 +
5956 +/*
5957 + *  $Id$
5958 + */
5959 +
5960 +#ifdef HAVE_CONFIG_H
5961 +# include <config.h>
5962 +#endif /* HAVE_CONFIG_H */
5963 +
5964 +#include "fist.h"
5965 +#include "mini_fo.h"
5966 +
5967 +
5968 +#ifdef FIST_COUNT_WRITES
5969 +/* for counting writes in the middle vs. regular writes */
5970 +unsigned long count_writes = 0, count_writes_middle = 0;
5971 +#endif /* FIST_COUNT_WRITES */
5972 +
5973 +/* forward declaration of commit write and prepare write */
5974 +STATIC int mini_fo_commit_write(file_t *file, page_t *page, unsigned from, unsigned to);
5975 +STATIC int mini_fo_prepare_write(file_t *file, page_t *page, unsigned from, unsigned to);
5976 +
5977 +
5978 +/*
5979 + * Function for handling creation of holes when lseek-ing past the
5980 + * end of the file and then writing some data.
5981 + */
5982 +int
5983 +mini_fo_fill_zeros(file_t* file, page_t *page, unsigned from)
5984 +{
5985 +       int err = 0;
5986 +       dentry_t *dentry = file->f_dentry;
5987 +       inode_t *inode = dentry->d_inode;
5988 +       page_t *tmp_page;
5989 +       int index;
5990 +
5991 +       print_entry_location();
5992 +
5993 +       for (index = inode->i_size >> PAGE_CACHE_SHIFT; index < page->index; index++) {
5994 +               tmp_page = mini_fo_get1page(file, index);
5995 +               if (IS_ERR(tmp_page)) {
5996 +                       err = PTR_ERR(tmp_page);
5997 +                       goto out;
5998 +               }
5999 +
6000 +               /*
6001 +                * zero out rest of the contents of the page between the appropriate
6002 +                * offsets.
6003 +                */
6004 +               memset((char*)page_address(tmp_page) + (inode->i_size & ~PAGE_CACHE_MASK), 0, PAGE_CACHE_SIZE - (inode->i_size & ~PAGE_CACHE_MASK));
6005 +
6006 +               if (! (err = mini_fo_prepare_write(file, tmp_page, 0, PAGE_CACHE_SIZE)))
6007 +                       err = mini_fo_commit_write(file, tmp_page, 0, PAGE_CACHE_SIZE);
6008 +
6009 +               page_cache_release(tmp_page);
6010 +               if (err < 0)
6011 +                       goto out;
6012 +               if (current->need_resched)
6013 +                       schedule();
6014 +       }
6015 +
6016 +       /* zero out appropriate parts of last page */
6017 +
6018 +       /*
6019 +        * if the encoding type is block, then adjust the 'from' (where the
6020 +        * zeroing will start) offset appropriately
6021 +        */
6022 +       from = from & (~(FIST_ENCODING_BLOCKSIZE - 1));
6023 +
6024 +       if ((from - (inode->i_size & ~PAGE_CACHE_MASK)) > 0) {
6025 +
6026 +               memset((char*)page_address(page) + (inode->i_size & ~PAGE_CACHE_MASK), 0, from - (inode->i_size & ~PAGE_CACHE_MASK));
6027 +               if (! (err = mini_fo_prepare_write(file, page, 0, PAGE_CACHE_SIZE)))
6028 +                       err = mini_fo_commit_write(file, page, 0, PAGE_CACHE_SIZE);
6029 +
6030 +               if (err < 0)
6031 +                       goto out;
6032 +               if (current->need_resched)
6033 +                       schedule();
6034 +       }
6035 +
6036 + out:
6037 +       print_exit_status(err);
6038 +       return err;
6039 +}
6040 +
6041 +
6042 +
6043 +STATIC int
6044 +mini_fo_writepage(page_t *page)
6045 +{
6046 +       int err = -EIO;
6047 +       inode_t *inode;
6048 +       inode_t *hidden_inode;
6049 +       page_t *hidden_page;
6050 +       char *kaddr, *hidden_kaddr;
6051 +
6052 +       print_entry_location();
6053 +
6054 +       inode = page->mapping->host;
6055 +       hidden_inode = itohi(inode);
6056 +
6057 +       /*
6058 +        * writepage is called when shared mmap'ed files need to write
6059 +        * their pages, while prepare/commit_write are called from the
6060 +        * non-paged write() interface.  (However, in 2.3 the two interfaces
6061 +        * share the same cache, while in 2.2 they didn't.)
6062 +        *
6063 +        * So we pretty much have to duplicate much of what commit_write does.
6064 +        */
6065 +
6066 +       /* find lower page (returns a locked page) */
6067 +       hidden_page = grab_cache_page(hidden_inode->i_mapping, page->index);
6068 +       if (!hidden_page)
6069 +               goto out;
6070 +
6071 +       /* get page address, and encode it */
6072 +       kaddr = (char *) kmap(page);
6073 +       hidden_kaddr = (char*) kmap(hidden_page);
6074 +       mini_fo_encode_block(kaddr, hidden_kaddr, PAGE_CACHE_SIZE, inode, inode->i_sb, page->index);
6075 +       /* if encode_block could fail, then return error */
6076 +       kunmap(page);
6077 +       kunmap(hidden_page);
6078 +
6079 +       /* call lower writepage (expects locked page) */
6080 +       err = hidden_inode->i_mapping->a_ops->writepage(hidden_page);
6081 +
6082 +       /*
6083 +        * update mtime and ctime of lower level file system
6084 +        * mini_fo' mtime and ctime are updated by generic_file_write
6085 +        */
6086 +       hidden_inode->i_mtime = hidden_inode->i_ctime = CURRENT_TIME;
6087 +
6088 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,4,1)
6089 +       UnlockPage(hidden_page);        /* b/c grab_cache_page locked it */
6090 +# endif /* kernel older than 2.4.1 */
6091 +       page_cache_release(hidden_page); /* b/c grab_cache_page increased refcnt */
6092 +
6093 +       if (err)
6094 +               ClearPageUptodate(page);
6095 +       else
6096 +               SetPageUptodate(page);
6097 + out:
6098 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,1)
6099 +       UnlockPage(page);
6100 +# endif /* kernel 2.4.1 and newer */
6101 +       print_exit_status(err);
6102 +       return err;
6103 +}
6104 +
6105 +
6106 +/*
6107 + * get one page from cache or lower f/s, return error otherwise.
6108 + * returns unlocked, up-to-date page (if ok), with increased refcnt.
6109 + */
6110 +page_t *
6111 +mini_fo_get1page(file_t *file, int index)
6112 +{
6113 +       page_t *page;
6114 +       dentry_t *dentry;
6115 +       inode_t *inode;
6116 +       struct address_space *mapping;
6117 +       int err;
6118 +
6119 +       print_entry_location();
6120 +
6121 +       dentry = file->f_dentry; /* CPW: Moved below print_entry_location */
6122 +       inode = dentry->d_inode;
6123 +       mapping = inode->i_mapping;
6124 +
6125 +       fist_dprint(8, "%s: read page index %d pid %d\n", __FUNCTION__, index, current->pid);
6126 +       if (index < 0) {
6127 +               printk("%s BUG: index=%d\n", __FUNCTION__, index);
6128 +               page = ERR_PTR(-EIO);
6129 +               goto out;
6130 +       }
6131 +       page = read_cache_page(mapping,
6132 +                              index,
6133 +                              (filler_t *) mapping->a_ops->readpage,
6134 +                              (void *) file);
6135 +       if (IS_ERR(page))
6136 +               goto out;
6137 +       wait_on_page(page);
6138 +       if (!Page_Uptodate(page)) {
6139 +               lock_page(page);
6140 +               err = mapping->a_ops->readpage(file, page);
6141 +               if (err) {
6142 +                       page = ERR_PTR(err);
6143 +                       goto out;
6144 +               }
6145 +               wait_on_page(page);
6146 +               if (!Page_Uptodate(page)) {
6147 +                       page = ERR_PTR(-EIO);
6148 +                       goto out;
6149 +               }
6150 +       }
6151 +
6152 + out:
6153 +       print_exit_pointer(page);
6154 +       return page;
6155 +}
6156 +
6157 +
6158 +/*
6159 + * get one page from cache or lower f/s, return error otherwise.
6160 + * similar to get1page, but doesn't guarantee that it will return
6161 + * an unlocked page.
6162 + */
6163 +page_t *
6164 +mini_fo_get1page_cached(file_t *file, int index)
6165 +{
6166 +       page_t *page;
6167 +       dentry_t *dentry;
6168 +       inode_t *inode;
6169 +       struct address_space *mapping;
6170 +       int err;
6171 +
6172 +       print_entry_location();
6173 +
6174 +       dentry = file->f_dentry; /* CPW: Moved below print_entry_location */
6175 +       inode = dentry->d_inode;
6176 +       mapping = inode->i_mapping;
6177 +
6178 +       fist_dprint(8, "%s: read page index %d pid %d\n", __FUNCTION__, index, current->pid);
6179 +       if (index < 0) {
6180 +               printk("%s BUG: index=%d\n", __FUNCTION__, index);
6181 +               page = ERR_PTR(-EIO);
6182 +               goto out;
6183 +       }
6184 +       page = read_cache_page(mapping,
6185 +                              index,
6186 +                              (filler_t *) mapping->a_ops->readpage,
6187 +                              (void *) file);
6188 +       if (IS_ERR(page))
6189 +               goto out;
6190 +
6191 + out:
6192 +       print_exit_pointer(page);
6193 +       return page;
6194 +}
6195 +
6196 +
6197 +/*
6198 + * readpage is called from generic_page_read and the fault handler.
6199 + * If your file system uses generic_page_read for the read op, it
6200 + * must implement readpage.
6201 + *
6202 + * Readpage expects a locked page, and must unlock it.
6203 + */
6204 +STATIC int
6205 +mini_fo_do_readpage(file_t *file, page_t *page)
6206 +{
6207 +       int err = -EIO;
6208 +       dentry_t *dentry;
6209 +       file_t *hidden_file = NULL;
6210 +       dentry_t *hidden_dentry;
6211 +       inode_t *inode;
6212 +       inode_t *hidden_inode;
6213 +       char *page_data;
6214 +       page_t *hidden_page;
6215 +       char *hidden_page_data;
6216 +       int real_size;
6217 +
6218 +       print_entry_location();
6219 +
6220 +       dentry = file->f_dentry; /* CPW: Moved below print_entry_location */
6221 +       if (ftopd(file) != NULL)
6222 +               hidden_file = ftohf(file);
6223 +       hidden_dentry = dtohd(dentry);
6224 +       inode = dentry->d_inode;
6225 +       hidden_inode = itohi(inode);
6226 +
6227 +       fist_dprint(7, "%s: requesting page %d from file %s\n", __FUNCTION__, page->index, dentry->d_name.name);
6228 +
6229 +       MALLOC_PAGE_POINTERS(hidden_pages, num_hidden_pages);
6230 +       MALLOC_PAGEDATA_POINTERS(hidden_pages_data, num_hidden_pages);
6231 +       FOR_EACH_PAGE
6232 +               CURRENT_HIDDEN_PAGE = NULL;
6233 +
6234 +       /* find lower page (returns a locked page) */
6235 +       FOR_EACH_PAGE {
6236 +               fist_dprint(8, "%s: Current page index = %d\n", __FUNCTION__, CURRENT_HIDDEN_PAGEINDEX);
6237 +               CURRENT_HIDDEN_PAGE = read_cache_page(hidden_inode->i_mapping,
6238 +                                                     CURRENT_HIDDEN_PAGEINDEX,
6239 +                                                     (filler_t *) hidden_inode->i_mapping->a_ops->readpage,
6240 +                                                     (void *) hidden_file);
6241 +               if (IS_ERR(CURRENT_HIDDEN_PAGE)) {
6242 +                       err = PTR_ERR(CURRENT_HIDDEN_PAGE);
6243 +                       CURRENT_HIDDEN_PAGE = NULL;
6244 +                       goto out_release;
6245 +               }
6246 +       }
6247 +
6248 +       /*
6249 +        * wait for the page data to show up
6250 +        * (signaled by readpage as unlocking the page)
6251 +        */
6252 +       FOR_EACH_PAGE {
6253 +               wait_on_page(CURRENT_HIDDEN_PAGE);
6254 +               if (!Page_Uptodate(CURRENT_HIDDEN_PAGE)) {
6255 +                       /*
6256 +                        * call readpage() again if we returned from wait_on_page with a
6257 +                        * page that's not up-to-date; that can happen when a partial
6258 +                        * page has a few buffers which are ok, but not the whole
6259 +                        * page.
6260 +                        */
6261 +                       lock_page(CURRENT_HIDDEN_PAGE);
6262 +                       err = hidden_inode->i_mapping->a_ops->readpage(hidden_file,
6263 +                                                                      CURRENT_HIDDEN_PAGE);
6264 +                       if (err) {
6265 +                               CURRENT_HIDDEN_PAGE = NULL;
6266 +                               goto out_release;
6267 +                       }
6268 +                       wait_on_page(CURRENT_HIDDEN_PAGE);
6269 +                       if (!Page_Uptodate(CURRENT_HIDDEN_PAGE)) {
6270 +                               err = -EIO;
6271 +                               goto out_release;
6272 +                       }
6273 +               }
6274 +       }
6275 +
6276 +       /* map pages, get their addresses */
6277 +       page_data = (char *) kmap(page);
6278 +       FOR_EACH_PAGE
6279 +               CURRENT_HIDDEN_PAGEDATA = (char *) kmap(CURRENT_HIDDEN_PAGE);
6280 +
6281 +       /* if decode_block could fail, then return error */
6282 +       err = 0;
6283 +       real_size = hidden_inode->i_size - (page->index << PAGE_CACHE_SHIFT);
6284 +       if (real_size <= 0)
6285 +               memset(page_data, 0, PAGE_CACHE_SIZE);
6286 +       else if (real_size < PAGE_CACHE_SIZE) {
6287 +               mini_fo_decode_block(hidden_page_data, page_data, real_size, inode, inode->i_sb, page->index);
6288 +               memset(page_data + real_size, 0, PAGE_CACHE_SIZE - real_size);
6289 +       } else
6290 +               mini_fo_decode_block(hidden_page_data, page_data, PAGE_CACHE_SIZE, inode, inode->i_sb, page->index);
6291 +
6292 +       FOR_EACH_PAGE
6293 +               kunmap(CURRENT_HIDDEN_PAGE);
6294 +       kunmap(page);
6295 +
6296 + out_release:
6297 +       FOR_EACH_PAGE
6298 +               if (CURRENT_HIDDEN_PAGE)
6299 +                       page_cache_release(CURRENT_HIDDEN_PAGE); /* undo read_cache_page */
6300 +
6301 +       FREE_PAGE_POINTERS(hidden_pages, num_hidden_pages);
6302 +       FREE_PAGEDATA_POINTERS(hidden_pages_data, num_hidden_pages);
6303 +
6304 + out:
6305 +       if (err == 0)
6306 +               SetPageUptodate(page);
6307 +       else
6308 +               ClearPageUptodate(page);
6309 +
6310 +       print_exit_status(err);
6311 +       return err;
6312 +}
6313 +
6314 +
6315 +STATIC int
6316 +mini_fo_readpage(file_t *file, page_t *page)
6317 +{
6318 +       int err;
6319 +       print_entry_location();
6320 +
6321 +       err = mini_fo_do_readpage(file, page);
6322 +
6323 +       /*
6324 +        * we have to unlock our page, b/c we _might_ have gotten a locked page.
6325 +        * but we no longer have to wakeup on our page here, b/c UnlockPage does
6326 +        * it
6327 +        */
6328 +       UnlockPage(page);
6329 +
6330 +       print_exit_status(err);
6331 +       return err;
6332 +}
6333 +
6334 +
6335 +STATIC int
6336 +mini_fo_prepare_write(file_t *file, page_t *page, unsigned from, unsigned to)
6337 +{
6338 +       int err = 0;
6339 +
6340 +       print_entry_location();
6341 +
6342 +       /*
6343 +        * we call kmap(page) only here, and do the kunmap
6344 +        * and the actual downcalls, including unlockpage and uncache
6345 +        * in commit_write.
6346 +        */
6347 +       kmap(page);
6348 +
6349 +       /* fast path for whole page writes */
6350 +       if (from == 0 && to == PAGE_CACHE_SIZE)
6351 +               goto out;
6352 +       /* read the page to "revalidate" our data */
6353 +       /* call the helper function which doesn't unlock the page */
6354 +       if (!Page_Uptodate(page))
6355 +               err = mini_fo_do_readpage(file, page);
6356 +
6357 + out:
6358 +       print_exit_status(err);
6359 +       return err;
6360 +}
6361 +
6362 +
6363 +
6364 +STATIC int
6365 +mini_fo_commit_write(file_t *file, page_t *page, unsigned from, unsigned to)
6366 +{
6367 +       int err = -ENOMEM;
6368 +       inode_t *inode;
6369 +       inode_t *hidden_inode;
6370 +       page_t *hidden_page;
6371 +       file_t *hidden_file = NULL;
6372 +       loff_t pos;
6373 +       unsigned bytes = to - from;
6374 +       unsigned hidden_from, hidden_to, hidden_bytes;
6375 +
6376 +       print_entry_location();
6377 +
6378 +       inode = page->mapping->host; /* CPW: Moved below print_entry_location */
6379 +       hidden_inode = itohi(inode);
6380 +
6381 +       ASSERT(file != NULL);
6382 +       /*
6383 +        * here we have a kmapped page, with data from the user copied
6384 +        * into it.  we need to encode_block it, and then call the lower
6385 +        * commit_write.  We also need to simulate same behavior of
6386 +        * generic_file_write, and call prepare_write on the lower f/s first.
6387 +        */
6388 +#ifdef FIST_COUNT_WRITES
6389 +       count_writes++;
6390 +# endif /* FIST_COUNT_WRITES */
6391 +
6392 +       /* this is append and/or extend -- we can't have holes so fill them in */
6393 +       if (page->index > (hidden_inode->i_size >> PAGE_CACHE_SHIFT)) {
6394 +               page_t *tmp_page;
6395 +               int index;
6396 +               for (index = hidden_inode->i_size >> PAGE_CACHE_SHIFT; index < page->index; index++) {
6397 +                       tmp_page = mini_fo_get1page(file, index);
6398 +                       if (IS_ERR(tmp_page)) {
6399 +                               err = PTR_ERR(tmp_page);
6400 +                               goto out;
6401 +                       }
6402 +                       /* zero out the contents of the page at the appropriate offsets */
6403 +                       memset((char*)page_address(tmp_page) + (inode->i_size & ~PAGE_CACHE_MASK), 0, PAGE_CACHE_SIZE - (inode->i_size & ~PAGE_CACHE_MASK));
6404 +                       if (!(err = mini_fo_prepare_write(file, tmp_page, 0, PAGE_CACHE_SIZE)))
6405 +                               err = mini_fo_commit_write(file, tmp_page, 0, PAGE_CACHE_SIZE);
6406 +                       page_cache_release(tmp_page);
6407 +                       if (err < 0)
6408 +                               goto out;
6409 +                       if (current->need_resched)
6410 +                               schedule();
6411 +               }
6412 +       }
6413 +
6414 +       if (ftopd(file) != NULL)
6415 +               hidden_file = ftohf(file);
6416 +
6417 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
6418 +       mutex_lock(&hidden_inode->i_mutex);
6419 +#else
6420 +       down(&hidden_inode->i_sem);
6421 +#endif
6422 +       /* find lower page (returns a locked page) */
6423 +       hidden_page = grab_cache_page(hidden_inode->i_mapping, page->index);
6424 +       if (!hidden_page)
6425 +               goto out;
6426 +
6427 +#if FIST_ENCODING_BLOCKSIZE > 1
6428 +#  error encoding_blocksize greater than 1 is not yet supported
6429 +# endif /* FIST_ENCODING_BLOCKSIZE > 1 */
6430 +
6431 +       hidden_from = from & (~(FIST_ENCODING_BLOCKSIZE - 1));
6432 +       hidden_to = ((to + FIST_ENCODING_BLOCKSIZE - 1) & (~(FIST_ENCODING_BLOCKSIZE - 1)));
6433 +       if ((page->index << PAGE_CACHE_SHIFT) + to > hidden_inode->i_size) {
6434 +
6435 +               /*
6436 +                * if this call to commit_write had introduced holes and the code
6437 +                * for handling holes was invoked, then the beginning of this page
6438 +                * must be zeroed out
6439 +                * zero out bytes from 'size_of_file%pagesize' to 'from'.
6440 +                */
6441 +               if ((hidden_from - (inode->i_size & ~PAGE_CACHE_MASK)) > 0)
6442 +                       memset((char*)page_address(page) + (inode->i_size & ~PAGE_CACHE_MASK), 0, hidden_from - (inode->i_size & ~PAGE_CACHE_MASK));
6443 +
6444 +       }
6445 +       hidden_bytes = hidden_to - hidden_from;
6446 +
6447 +       /* call lower prepare_write */
6448 +       err = -EINVAL;
6449 +       if (hidden_inode->i_mapping &&
6450 +           hidden_inode->i_mapping->a_ops &&
6451 +           hidden_inode->i_mapping->a_ops->prepare_write)
6452 +               err = hidden_inode->i_mapping->a_ops->prepare_write(hidden_file,
6453 +                                                                   hidden_page,
6454 +                                                                   hidden_from,
6455 +                                                                   hidden_to);
6456 +       if (err)
6457 +               /* don't leave locked pages behind, esp. on an ENOSPC */
6458 +               goto out_unlock;
6459 +
6460 +       fist_dprint(8, "%s: encoding %d bytes\n", __FUNCTION__, hidden_bytes);
6461 +       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);
6462 +       /* if encode_block could fail, then goto unlock and return error */
6463 +
6464 +       /* call lower commit_write */
6465 +       err = hidden_inode->i_mapping->a_ops->commit_write(hidden_file,
6466 +                                                          hidden_page,
6467 +                                                          hidden_from,
6468 +                                                          hidden_to);
6469 +
6470 +       if (err < 0)
6471 +               goto out_unlock;
6472 +
6473 +       err = bytes;    /* convert error to no. of bytes */
6474 +
6475 +       inode->i_blocks = hidden_inode->i_blocks;
6476 +       /* we may have to update i_size */
6477 +       pos = (page->index << PAGE_CACHE_SHIFT) + to;
6478 +       if (pos > inode->i_size)
6479 +               inode->i_size = pos;
6480 +
6481 +       /*
6482 +        * update mtime and ctime of lower level file system
6483 +        * mini_fo' mtime and ctime are updated by generic_file_write
6484 +        */
6485 +       hidden_inode->i_mtime = hidden_inode->i_ctime = CURRENT_TIME;
6486 +
6487 +       mark_inode_dirty_sync(inode);
6488 +
6489 + out_unlock:
6490 +       UnlockPage(hidden_page);
6491 +       page_cache_release(hidden_page);
6492 +       kunmap(page);           /* kmap was done in prepare_write */
6493 + out:
6494 +       /* we must set our page as up-to-date */
6495 +       if (err < 0)
6496 +               ClearPageUptodate(page);
6497 +       else
6498 +               SetPageUptodate(page);
6499 +
6500 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
6501 +       mutex_unlock(&hidden_inode->i_mutex);
6502 +#else
6503 +       up(&hidden_inode->i_sem);
6504 +#endif
6505 +       print_exit_status(err);
6506 +       return err;                     /* assume all is ok */
6507 +}
6508 +
6509 +
6510 +STATIC int
6511 +mini_fo_bmap(struct address_space *mapping, long block)
6512 +{
6513 +       int err = 0;
6514 +       inode_t *inode;
6515 +       inode_t *hidden_inode;
6516 +
6517 +       print_entry_location();
6518 +
6519 +       inode = (inode_t *) mapping->host;
6520 +       hidden_inode = itohi(inode);
6521 +
6522 +       if (hidden_inode->i_mapping->a_ops->bmap)
6523 +               err = hidden_inode->i_mapping->a_ops->bmap(hidden_inode->i_mapping, block);
6524 +       print_exit_location();
6525 +       return err;
6526 +}
6527 +
6528 +
6529 +/*
6530 + * This function is copied verbatim from mm/filemap.c.
6531 + * XXX: It should be simply moved to some header file instead -- bug Al about it!
6532 + */
6533 +static inline int sync_page(struct page *page)
6534 +{
6535 +       struct address_space *mapping = page->mapping;
6536 +
6537 +       if (mapping && mapping->a_ops && mapping->a_ops->sync_page)
6538 +               return mapping->a_ops->sync_page(page);
6539 +       return 0;
6540 +}
6541 +
6542 +
6543 +/*
6544 + * XXX: we may not need this function if not FIST_FILTER_DATA.
6545 + * FIXME: for FIST_FILTER_SCA, get all lower pages and sync them each.
6546 + */
6547 +STATIC int
6548 +mini_fo_sync_page(page_t *page)
6549 +{
6550 +       int err = 0;
6551 +       inode_t *inode;
6552 +       inode_t *hidden_inode;
6553 +       page_t *hidden_page;
6554 +
6555 +       print_entry_location();
6556 +
6557 +       inode = page->mapping->host; /* CPW: Moved below print_entry_location */
6558 +       hidden_inode = itohi(inode);
6559 +
6560 +       /* find lower page (returns a locked page) */
6561 +       hidden_page = grab_cache_page(hidden_inode->i_mapping, page->index);
6562 +       if (!hidden_page)
6563 +               goto out;
6564 +
6565 +       err = sync_page(hidden_page);
6566 +
6567 +       UnlockPage(hidden_page);        /* b/c grab_cache_page locked it */
6568 +       page_cache_release(hidden_page); /* b/c grab_cache_page increased refcnt */
6569 +
6570 + out:
6571 +       print_exit_status(err);
6572 +       return err;
6573 +}
6574 diff -urN linux.old/fs/mini_fo/README linux.dev/fs/mini_fo/README
6575 --- linux.old/fs/mini_fo/README 1970-01-01 01:00:00.000000000 +0100
6576 +++ linux.dev/fs/mini_fo/README 2006-11-17 03:11:48.000000000 +0100
6577 @@ -0,0 +1,163 @@
6578 +README for the mini_fo overlay file system
6579 +=========================================
6580 +
6581 +
6582 +WHAT IS MINI_FO?
6583 +----------------
6584 +
6585 +mini_fo is a virtual kernel file system that can make read-only
6586 +file systems writable. This is done by redirecting modifying operations
6587 +to a writeable location called "storage directory", and leaving the
6588 +original data in the "base directory" untouched. When reading, the
6589 +file system merges the modifed and original data so that only the
6590 +newest versions will appear. This occurs transparently to the user,
6591 +who can access the data like on any other read-write file system.
6592 +
6593 +Base and storage directories may be located on the same or on
6594 +different partitions and may be of different file system types. While
6595 +the storage directory obviously needs to be writable, the base may or
6596 +may not be writable, what doesn't matter as it will no be modified
6597 +anyway.
6598 +
6599 +
6600 +WHAT IS GOOD FOR?
6601 +-----------------
6602 +
6603 +The primary purpose of the mini_fo file system is to allow easy
6604 +software updates to embedded systems, that often store their root
6605 +file system in a read-only flash file system, but there are many
6606 +more as for example sandboxing, or for allowing live-cds to
6607 +permanently store information.
6608 +
6609 +
6610 +BUILDING
6611 +--------
6612 +This should be simple. Adjust the Makefile to point to the correct
6613 +kernel headers you want to build the module for. Then:
6614 +
6615 +    # make
6616 +
6617 +should build "mini_fo.o" for a 2.4 kernel or "mini_fo.ko" for a 2.6
6618 +kernel.
6619 +
6620 +If you are building the module for you current kernel, you can install
6621 +the module (as root):
6622 +
6623 +    # make install
6624 +
6625 +or uninstall with
6626 +
6627 +    # make uninstall
6628 +
6629 +
6630 +USING THE FILE SYSTEM
6631 +--------------------
6632 +
6633 +the general mount syntax is:
6634 +
6635 +   mount -t mini_fo -o base=<base directory>,sto=<storage directory>\
6636 +                            <base directory> <mount point>
6637 +
6638 +Example:
6639 +
6640 +You have mounted a cdrom to /mnt/cdrom and want to modifiy some files
6641 +on it:
6642 +
6643 +load the module (as root)
6644 +    
6645 +    # insmod mini_fo.o for a 2.4 kernel or
6646
6647 +    # insmod mini_fo.ko for a 2.6 kernel
6648 +
6649 +
6650 +create a storage dir in tmp and a mountpoint for mini_fo:
6651 +
6652 +    # mkdir /tmp/sto
6653 +    # mkdir /mnt/mini_fo
6654 +
6655 +and mount the mini_fo file system:
6656 +
6657 +    # mount -t mini_fo -o base=/mnt/cdrom,sto=/tmp/sto /mnt/cdrom /mnt/mini_fo
6658 +
6659 +
6660 +Now the data stored on the cd can be accessed via the mini_fo
6661 +mountpoint just like any read-write file system, files can be modified
6662 +and deleted, new ones can be created and so on. When done unmount the
6663 +file system:
6664 +
6665 +    # unmount /mnt/mini_fo
6666 +
6667 +Note that if the file system is mounted again using the same storage
6668 +file system, of course it will appear in the modified state again. If
6669 +you remount it using an new empty storage directory, it will be
6670 +unmodified. Therefore by executing:
6671 +
6672 +    # cd /tmp/sto
6673 +    # rm -rf *
6674 +
6675 +you can nuke all the changes you made to the original file system. But
6676 + remember NEVER do this while the mini_fo file system is mounted!
6677 +
6678 +
6679 +Alternatively you can use the mini_fo-overlay bash script, that
6680 +simplifies managing mini_fo mounts. See TOOLS Section.
6681 +
6682 +
6683 +TOOLS
6684 +-----
6685 +
6686 +mini_fo-merge (experimental):
6687 +
6688 +This is a bash script that will merge changes contained in the storage
6689 +directory back to the base directory. This allows mini_fo to function
6690 +as a cache file system by overlaying a slow (network, ...) file system
6691 +and using a fast (ramdisk, ...) as storage. When done, changes can be
6692 +merged back to the (slow) base with mini_fo-merge. See "mini_fo-merge
6693 +-h" for details.
6694 +
6695 +It can be usefull for merging changes back after a successfull test
6696 +(patches, software updates...)
6697 +
6698 +
6699 +mini_fo-overlay:
6700 +
6701 +This bash script simplifies managing one or more mini_fo mounts. For
6702 +overlaying a directory called "basedir1", you can just call:
6703 +
6704 +    # mini_fo-overlay basedir1
6705 +
6706 +This will mount mini_fo with "basedir1" as base, "/tmp/sto-basedir1/"
6707 +as storage to "/mnt/mini_fo-basedir1/". It has more options though,
6708 +type "mini_fo-overlay -h" for details.
6709 +
6710 +
6711 +DOCUMENTATION, REPORTING BUGS, GETTING HELP
6712 +-------------------------------------------
6713 +
6714 +Please visit the mini_fo project page at:
6715 +
6716 +http://www.denx.de/twiki/bin/view/Know/MiniFOHome
6717 +
6718 +
6719 +WARNINGS
6720 +--------
6721 +
6722 +Never modify the base or the storage directorys while the mini_fo
6723 +file system is mounted, or you might crash you system. Simply accessing
6724 +and reading should not cause any trouble.
6725 +
6726 +Exporting a mini_fo mount point via NFS has not been tested, and may
6727 +or may not work.
6728 +
6729 +Check the RELEASE_NOTES for details on bugs and features.
6730 +
6731 +
6732 +
6733 +Copyright (C) 2004, 2005 Markus Klotzbuecher <mk@creamnet.de>
6734 +
6735 +This program is free software; you can redistribute it and/or
6736 +modify it under the terms of the GNU General Public License
6737 +as published by the Free Software Foundation; either version
6738 +2 of the License, or (at your option) any later version.
6739 +
6740 +
6741 diff -urN linux.old/fs/mini_fo/RELEASE_NOTES linux.dev/fs/mini_fo/RELEASE_NOTES
6742 --- linux.old/fs/mini_fo/RELEASE_NOTES  1970-01-01 01:00:00.000000000 +0100
6743 +++ linux.dev/fs/mini_fo/RELEASE_NOTES  2006-11-17 03:11:48.000000000 +0100
6744 @@ -0,0 +1,111 @@
6745 +Release:       mini_fo-0.6.1 (v0-6-1)
6746 +Date:          21.09.2005
6747 +
6748 +
6749 +Changes:
6750 +--------
6751 +v0-6-1:
6752 +
6753 +- bugfixes (see ChangeLog)
6754 +
6755 +- two helper scripts "mini_fo_merge" and "mini_fo_overlay" (see
6756 +  README for details).
6757 +
6758 +v0-6-0:
6759 +
6760 +- Support for 2.4 and 2.6 (see Makefile)
6761 +
6762 +- Partial hard link support (creating works as expected, but already
6763 +  existing links in the base file system will be treated as if they
6764 +  were individual files).
6765 +
6766 +- Various bugfixes and cleanups.
6767 +
6768 +
6769 +v0-6-0-pre1:
6770 +
6771 +- This is mini_fo-0-6-0-pre1! This release is a complete rewrite of
6772 +  many vital mini_fo parts such as the old whiteout list code which
6773 +  has been replaced by the new META subsystem.
6774 +
6775 +- Light weight directory renaming implemented. This means if a
6776 +  directory is renamed via the mini_fo filesystem this will no longer
6777 +  result in a complete copy in storage, instead only one empty
6778 +  directory will be created. All base filed contained in the original
6779 +  directory stay there until modified.
6780 +
6781 +- Special files (creating, renaming, deleting etc.) now working.
6782 +
6783 +- Many bugfixes and cleanup, mini_fo is now a lot more stable.
6784 +
6785 +
6786 +v0-5-10:
6787 +
6788 +- Final release of the 0-5-* versions. Next will be a complete rewrite
6789 +  of many features. This release contains several bugfixes related to
6790 +  directory renaming.
6791 +
6792 +
6793 +v0-5-10-pre6:
6794 +
6795 +- Lots of cleanup and several bugfixes related to directory deleting
6796 +
6797 +- Directory renaming suddenly works, what is most likely due to the
6798 +  fact tha that "mv" is smart: if the classic rename doesn't work it
6799 +  will assume that source and target file are on different fs and will
6800 +  copy the directory and try to remove the source directory. Until
6801 +  directory removing wasn't implemented, it would fail to do this and
6802 +  rollback.
6803 +  So, directory renaming works for now, but it doesn't yet do what you
6804 +  would expect from a overlay fs, so use with care.
6805 +
6806 +
6807 +v0-5-10-pre5:
6808 +
6809 +- implemented directory deleting 
6810 +- made parsing of mount options more stable
6811 +- New format of mount options! (See README)
6812 +- I can't reproduce the unknown panic with 2.4.25 anymore, so I'll
6813 +  happily assume it never existed!
6814 +
6815 +
6816 +Implemented features:
6817 +---------------------
6818 +
6819 +- creating hard links (see BUGS on already existing hard links)        
6820 +- lightweight directory renaming
6821 +- renaming device files, pipes, sockets, etc.  
6822 +- creating, renaming, deleting of special files 
6823 +- deleting directorys
6824 +- general directory reading (simple "ls" )
6825 +- creating files in existing directorys
6826 +- creating directorys
6827 +- renaming files.
6828 +- reading and writing files (involves opening)
6829 +- appending to files (creates copy in storage)
6830 +- deleting files
6831 +- llseek works too, what allows editors to work
6832 +- persistency (a deleted file stay deleted over remounts)
6833 +- use of symbolic links
6834 +- creating of device files
6835 +
6836 +
6837 +Not (yet) implemented features:
6838 +-------------------------------
6839 +
6840 +- full hard link support.
6841 +
6842 +
6843 +
6844 +BUGS:
6845 +-----
6846 +
6847 +Hard links in the base file system will be treated as individual
6848 +files, not as links to one inode.
6849 +
6850 +The main problem with hard links isn't allowing to create them, but
6851 +their pure existence. If you modify a base hard link, the changes made
6852 +will only show up on this link, the other link will remain in the
6853 +original state. I hope to fix this someday. Please note that this does
6854 +not effect the special hard links '.' and '..', that are handled
6855 +seperately by the lower fs.
6856 diff -urN linux.old/fs/mini_fo/state.c linux.dev/fs/mini_fo/state.c
6857 --- linux.old/fs/mini_fo/state.c        1970-01-01 01:00:00.000000000 +0100
6858 +++ linux.dev/fs/mini_fo/state.c        2006-11-17 03:11:48.000000000 +0100
6859 @@ -0,0 +1,620 @@
6860 +/*
6861 + * Copyright (C) 2005 Markus Klotzbuecher <mk@creamnet.de>
6862 + *
6863 + * This program is free software; you can redistribute it and/or
6864 + * modify it under the terms of the GNU General Public License
6865 + * as published by the Free Software Foundation; either version
6866 + * 2 of the License, or (at your option) any later version.
6867 + */
6868 +
6869 +#ifdef HAVE_CONFIG_H
6870 +# include <config.h>
6871 +#endif /* HAVE_CONFIG_H */
6872 +
6873 +#include "fist.h"
6874 +#include "mini_fo.h"
6875 +
6876 +
6877 +/* create the storage file, setup new states */
6878 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
6879 +int create_sto_reg_file(dentry_t *dentry, int mode, struct nameidata *nd)
6880 +#else
6881 +int create_sto_reg_file(dentry_t *dentry, int mode)
6882 +#endif
6883 +{
6884 +       int err = 0;
6885 +       inode_t *dir;
6886 +       dentry_t *hidden_sto_dentry;
6887 +       dentry_t *hidden_sto_dir_dentry;
6888 +
6889 +       if(exists_in_storage(dentry)) {
6890 +               printk(KERN_CRIT "mini_fo: create_sto_file: wrong type or state.\n");
6891 +               err = -EINVAL;
6892 +               goto out;
6893 +       }
6894 +       err = get_neg_sto_dentry(dentry);
6895 +
6896 +       if (err) {
6897 +               printk(KERN_CRIT "mini_fo: create_sto_file: ERROR getting neg. sto dentry.\n");
6898 +               goto out;
6899 +       }
6900 +       
6901 +       dir = dentry->d_parent->d_inode;
6902 +       hidden_sto_dentry = dtohd2(dentry);
6903 +
6904 +       /* lock parent */
6905 +       hidden_sto_dir_dentry = dget(hidden_sto_dentry->d_parent);
6906 +
6907 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
6908 +       mutex_lock(&hidden_sto_dir_dentry->d_inode->i_mutex);
6909 +#else
6910 +        down(&hidden_sto_dir_dentry->d_inode->i_sem);
6911 +#endif
6912 +
6913 +       err = PTR_ERR(hidden_sto_dir_dentry);
6914 +        if (IS_ERR(hidden_sto_dir_dentry))
6915 +                goto out;
6916 +
6917 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
6918 +       err = vfs_create(hidden_sto_dir_dentry->d_inode,
6919 +                        hidden_sto_dentry,
6920 +                        mode, nd);
6921 +#else
6922 +       err = vfs_create(hidden_sto_dir_dentry->d_inode,
6923 +                        hidden_sto_dentry,
6924 +                        mode);
6925 +#endif
6926 +        if(err) {
6927 +               printk(KERN_CRIT "mini_fo: create_sto_file: ERROR creating sto file.\n");
6928 +                goto out_lock;
6929 +       }
6930 +
6931 +       if(!dtohd2(dentry)->d_inode) {
6932 +               printk(KERN_CRIT "mini_fo: create_sto_file: ERROR creating sto file [2].\n");
6933 +                err = -EINVAL;
6934 +                goto out_lock;
6935 +        }
6936 +
6937 +        /* interpose the new inode */
6938 +        if(dtost(dentry) == DELETED) {
6939 +                dtost(dentry) = DEL_REWRITTEN;
6940 +                err = mini_fo_tri_interpose(NULL, hidden_sto_dentry, dentry, dir->i_sb, 0);
6941 +                if(err)
6942 +                        goto out_lock;
6943 +        }
6944 +        else if(dtost(dentry) == NON_EXISTANT) {
6945 +                dtost(dentry) = CREATED;
6946 +                err = mini_fo_tri_interpose(dtohd(dentry), hidden_sto_dentry, dentry, dir->i_sb, 0);
6947 +                if(err)
6948 +                        goto out_lock;
6949 +        }
6950 +        else if(dtost(dentry) == UNMODIFIED) {
6951 +                dtost(dentry) = MODIFIED;
6952 +                /* interpose on new inode */
6953 +                if(itohi2(dentry->d_inode) != NULL) {
6954 +                        printk(KERN_CRIT "mini_fo: create_sto_file: invalid inode detected.\n");
6955 +                        err = -EINVAL;
6956 +                        goto out_lock;
6957 +                }
6958 +                itohi2(dentry->d_inode) = igrab(dtohd2(dentry)->d_inode);
6959 +       }
6960 +       fist_copy_attr_timesizes(dentry->d_parent->d_inode, 
6961 +                                hidden_sto_dir_dentry->d_inode);
6962 +
6963 + out_lock:
6964 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
6965 +       mutex_unlock(&hidden_sto_dir_dentry->d_inode->i_mutex);
6966 +#else
6967 +       up(&hidden_sto_dir_dentry->d_inode->i_sem);
6968 +#endif
6969 +        dput(hidden_sto_dir_dentry);
6970 + out:
6971 +       return err;
6972 +}
6973 +
6974 +/* create the sto dir, setup states */
6975 +int create_sto_dir(dentry_t *dentry, int mode)
6976 +{
6977 +       int err = 0;
6978 +       inode_t *dir;
6979 +       dentry_t *hidden_sto_dentry;
6980 +        dentry_t *hidden_sto_dir_dentry;
6981 +
6982 +       /* had to take the "!S_ISDIR(mode))" check out, because it failed */
6983 +       if(exists_in_storage(dentry)) {
6984 +                printk(KERN_CRIT "mini_fo: create_sto_dir: wrong type or state.\\
6985 +n");
6986 +                err = -EINVAL;
6987 +                goto out;
6988 +        }
6989 +       
6990 +       err = get_neg_sto_dentry(dentry);
6991 +       if(err) {
6992 +               err = -EINVAL;
6993 +               goto out;
6994 +       }
6995 +
6996 +       dir = dentry->d_parent->d_inode;
6997 +       hidden_sto_dentry = dtohd2(dentry);
6998 +
6999 +       /* was: hidden_sto_dir_dentry = lock_parent(hidden_sto_dentry); */
7000 +       hidden_sto_dir_dentry = dget(hidden_sto_dentry->d_parent);
7001 +
7002 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
7003 +       mutex_lock(&hidden_sto_dir_dentry->d_inode->i_mutex);
7004 +#else
7005 +       down(&hidden_sto_dir_dentry->d_inode->i_sem);
7006 +#endif
7007 +
7008 +       err = PTR_ERR(hidden_sto_dir_dentry);
7009 +       if (IS_ERR(hidden_sto_dir_dentry))
7010 +               goto out;
7011 +       
7012 +       err = vfs_mkdir(hidden_sto_dir_dentry->d_inode,
7013 +                       hidden_sto_dentry,
7014 +                       mode);
7015 +       if(err) {
7016 +               printk(KERN_CRIT "mini_fo: create_sto_dir: ERROR creating sto dir.\n");
7017 +               goto out_lock;
7018 +       }
7019 +
7020 +       if(!dtohd2(dentry)->d_inode) {
7021 +               printk(KERN_CRIT "mini_fo: create_sto_dir: ERROR creating sto dir [2].\n");
7022 +               err = -EINVAL;
7023 +               goto out_lock;
7024 +       }
7025 +
7026 +       /* interpose the new inode */
7027 +       if(dtost(dentry) == DELETED) {
7028 +               dtost(dentry) = DEL_REWRITTEN;
7029 +               err = mini_fo_tri_interpose(NULL, hidden_sto_dentry, dentry, dir->i_sb, 0);
7030 +               if(err)
7031 +                       goto out_lock;
7032 +       }
7033 +       else if(dtopd(dentry)->state == NON_EXISTANT) {
7034 +               dtopd(dentry)->state = CREATED;
7035 +               err = mini_fo_tri_interpose(dtohd(dentry), hidden_sto_dentry, dentry, dir->i_sb, 0);
7036 +               if(err)
7037 +                       goto out_lock;
7038 +       }
7039 +       else if(dtopd(dentry)->state == UNMODIFIED) {
7040 +               dtopd(dentry)->state = MODIFIED;
7041 +               /* interpose on new inode */
7042 +               if(itohi2(dentry->d_inode) != NULL) {
7043 +                       printk(KERN_CRIT "mini_fo:  create_sto_dir: ERROR, invalid inode detected.\n");
7044 +                       err = -EINVAL;
7045 +                       goto out_lock;
7046 +               }
7047 +               itohi2(dentry->d_inode) = igrab(dtohd2(dentry)->d_inode);
7048 +       }
7049 +
7050 +       fist_copy_attr_timesizes(dir, hidden_sto_dir_dentry->d_inode);
7051 +
7052 +       /* initalize the wol list */
7053 +       itopd(dentry->d_inode)->deleted_list_size = -1;
7054 +       itopd(dentry->d_inode)->renamed_list_size = -1;
7055 +       meta_build_lists(dentry);
7056 +
7057 +
7058 + out_lock:
7059 +       /* was: unlock_dir(hidden_sto_dir_dentry); */
7060 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
7061 +       mutex_unlock(&hidden_sto_dir_dentry->d_inode->i_mutex);
7062 +#else
7063 +       up(&hidden_sto_dir_dentry->d_inode->i_sem);
7064 +#endif
7065 +       dput(hidden_sto_dir_dentry);
7066 + out:
7067 +       return err;
7068 +}
7069 +
7070 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
7071 +int create_sto_nod(dentry_t *dentry, int mode, dev_t dev) 
7072 +#else
7073 +int create_sto_nod(dentry_t *dentry, int mode, int dev) 
7074 +#endif
7075 +{
7076 +       int err = 0;
7077 +       inode_t *dir;
7078 +       dentry_t *hidden_sto_dentry;
7079 +       dentry_t *hidden_sto_dir_dentry;
7080 +
7081 +       if(exists_in_storage(dentry)) {
7082 +               err = -EEXIST;
7083 +               goto out;
7084 +       }
7085 +       err = get_neg_sto_dentry(dentry);
7086 +
7087 +       if (err) {
7088 +                printk(KERN_CRIT "mini_fo: create_sto_nod: ERROR getting neg. sto dentry.\n");
7089 +                goto out;
7090 +        }      
7091 +
7092 +       dir = dentry->d_parent->d_inode;
7093 +       hidden_sto_dentry = dtohd2(dentry);
7094 +       
7095 +       /* lock parent */
7096 +       hidden_sto_dir_dentry = dget(hidden_sto_dentry->d_parent);
7097 +
7098 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
7099 +       mutex_lock(&hidden_sto_dir_dentry->d_inode->i_mutex);
7100 +#else
7101 +       down(&hidden_sto_dir_dentry->d_inode->i_sem);
7102 +#endif
7103 +       
7104 +       err = PTR_ERR(hidden_sto_dir_dentry);
7105 +       if (IS_ERR(hidden_sto_dir_dentry))
7106 +               goto out;
7107 +
7108 +       err = vfs_mknod(hidden_sto_dir_dentry->d_inode, hidden_sto_dentry, mode, dev);
7109 +       if(err)
7110 +               goto out_lock;
7111 +
7112 +       if(!dtohd2(dentry)->d_inode) {
7113 +               printk(KERN_CRIT "mini_fo: create_sto_nod: creating storage inode failed [1].\n");
7114 +               err = -EINVAL; /* return something indicating failure */
7115 +               goto out_lock;
7116 +       }
7117 +
7118 +       /* interpose the new inode */
7119 +       if(dtost(dentry) == DELETED) {
7120 +               dtost(dentry) = DEL_REWRITTEN;
7121 +               err = mini_fo_tri_interpose(NULL, hidden_sto_dentry, dentry, dir->i_sb, 0);
7122 +               if(err)
7123 +                       goto out_lock;
7124 +       }
7125 +       else if(dtost(dentry) == NON_EXISTANT) {
7126 +               dtost(dentry) = CREATED;
7127 +               err = mini_fo_tri_interpose(dtohd(dentry), hidden_sto_dentry, dentry, dir->i_sb, 0);
7128 +               if(err)
7129 +                       goto out_lock;
7130 +       }
7131 +       else if(dtost(dentry) == UNMODIFIED) {
7132 +               dtost(dentry) = MODIFIED;
7133 +               /* interpose on new inode */
7134 +               if(itohi2(dentry->d_inode) != NULL) {
7135 +                       printk(KERN_CRIT "mini_fo: create_sto_nod: error, invalid inode detected.\n");
7136 +                       err = -EINVAL;
7137 +                       goto out_lock;
7138 +               }
7139 +               itohi2(dentry->d_inode) = igrab(dtohd2(dentry)->d_inode);
7140 +       }
7141 +
7142 +       fist_copy_attr_timesizes(dir, hidden_sto_dir_dentry->d_inode);
7143 +
7144 + out_lock:
7145 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
7146 +       mutex_unlock(&hidden_sto_dir_dentry->d_inode->i_mutex);
7147 +#else
7148 +       up(&hidden_sto_dir_dentry->d_inode->i_sem);
7149 +#endif
7150 +       dput(hidden_sto_dir_dentry);
7151 + out:
7152 +       return err;
7153 +}
7154 +
7155 +
7156 +/* unimplemented (and possibly not usefull): 
7157 +
7158 +   nondir-del_to_del_rew
7159 +   nondir-non_exist_to_creat
7160 +
7161 +   dir-unmod_to_del
7162 +   dir-mod_to_del
7163 +   dir-creat_to_del
7164 +   dir-del_rew_to_del
7165 +   dir-del_to_del_rew
7166 +   dir-non_exist_to_creat
7167 +*/
7168 +
7169 +
7170 +/* bring a file of any type from state UNMODIFIED to MODIFIED */
7171 +int nondir_unmod_to_mod(dentry_t *dentry, int cp_flag) 
7172 +{
7173 +       int err = 0;
7174 +       struct vfsmount *tgt_mnt;
7175 +       struct vfsmount *src_mnt;
7176 +       dentry_t *tgt_dentry;
7177 +       dentry_t *src_dentry;
7178 +       dentry_t *hidden_sto_dentry;
7179 +       dentry_t *hidden_sto_dir_dentry;
7180 +
7181 +       check_mini_fo_dentry(dentry);
7182 +
7183 +       if((dtost(dentry) != UNMODIFIED) ||
7184 +          S_ISDIR(dentry->d_inode->i_mode)) {
7185 +               printk(KERN_CRIT "mini_fo: nondir_unmod_to_mod: \
7186 +                                  wrong type or state.\n");
7187 +               err = -1;
7188 +               goto out;
7189 +       }
7190 +       err = get_neg_sto_dentry(dentry);
7191 +
7192 +       if (err) {
7193 +               printk(KERN_CRIT "mini_fo: nondir_unmod_to_mod: \
7194 +                                  ERROR getting neg. sto dentry.\n");
7195 +               goto out;
7196 +       }
7197 +       
7198 +       /* create sto file */
7199 +       hidden_sto_dentry = dtohd2(dentry);
7200 +
7201 +       /* lock parent */
7202 +       hidden_sto_dir_dentry = dget(hidden_sto_dentry->d_parent);
7203 +
7204 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
7205 +       mutex_lock(&hidden_sto_dir_dentry->d_inode->i_mutex);
7206 +#else
7207 +        down(&hidden_sto_dir_dentry->d_inode->i_sem);
7208 +#endif
7209 +
7210 +       err = PTR_ERR(hidden_sto_dir_dentry);
7211 +        if (IS_ERR(hidden_sto_dir_dentry))
7212 +                goto out;
7213 +
7214 +       /* handle different types of nondirs */
7215 +       if(S_ISCHR(dentry->d_inode->i_mode) ||
7216 +          S_ISBLK(dentry->d_inode->i_mode)) {
7217 +               err = vfs_mknod(hidden_sto_dir_dentry->d_inode,
7218 +                               hidden_sto_dentry,
7219 +                               dtohd(dentry)->d_inode->i_mode,
7220 +                               dtohd(dentry)->d_inode->i_rdev);
7221 +       }
7222 +       
7223 +       else if(S_ISREG(dentry->d_inode->i_mode)) {
7224 +
7225 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
7226 +               err = vfs_create(hidden_sto_dir_dentry->d_inode,
7227 +                                hidden_sto_dentry,
7228 +                                dtohd(dentry)->d_inode->i_mode, NULL);
7229 +#else
7230 +               err = vfs_create(hidden_sto_dir_dentry->d_inode,
7231 +                                hidden_sto_dentry,
7232 +                                dtohd(dentry)->d_inode->i_mode);
7233 +#endif
7234 +       }
7235 +        if(err) {
7236 +               printk(KERN_CRIT "mini_fo: nondir_unmod_to_mod: \
7237 +                                  ERROR creating sto file.\n");
7238 +                goto out_lock;
7239 +       }
7240 +
7241 +       /* interpose on new inode */
7242 +       if(itohi2(dentry->d_inode) != NULL) {
7243 +               printk(KERN_CRIT "mini_fo: nondir_unmod_to_mod: \
7244 +                                  ERROR, invalid inode detected.\n");
7245 +               err = -EINVAL;
7246 +               goto out_lock;
7247 +       }
7248 +
7249 +       itohi2(dentry->d_inode) = igrab(dtohd2(dentry)->d_inode);
7250 +        
7251 +        fist_copy_attr_timesizes(dentry->d_parent->d_inode, 
7252 +                                hidden_sto_dir_dentry->d_inode);
7253 +       dtost(dentry) = MODIFIED;
7254 +
7255 +       /* copy contents if regular file and cp_flag = 1 */
7256 +       if((cp_flag == 1) && S_ISREG(dentry->d_inode->i_mode)) {
7257 +
7258 +               /* unlock first */
7259 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
7260 +               mutex_unlock(&hidden_sto_dir_dentry->d_inode->i_mutex);
7261 +#else
7262 +               up(&hidden_sto_dir_dentry->d_inode->i_sem);
7263 +#endif
7264 +
7265 +               dput(hidden_sto_dir_dentry);
7266 +
7267 +               tgt_dentry = dtohd2(dentry);
7268 +               tgt_mnt = stopd(dentry->d_inode->i_sb)->hidden_mnt2;
7269 +               src_dentry = dtohd(dentry);
7270 +               src_mnt = stopd(dentry->d_inode->i_sb)->hidden_mnt;
7271 +               
7272 +               err = mini_fo_cp_cont(tgt_dentry, tgt_mnt, 
7273 +                                     src_dentry, src_mnt);
7274 +               if(err) {
7275 +                       printk(KERN_CRIT "mini_fo: nondir_unmod_to_mod: \
7276 +                                          ERROR copying contents.\n");
7277 +               }
7278 +               goto out;       
7279 +       }
7280 +
7281 + out_lock:
7282 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
7283 +       mutex_unlock(&hidden_sto_dir_dentry->d_inode->i_mutex);
7284 +#else
7285 +       up(&hidden_sto_dir_dentry->d_inode->i_sem);
7286 +#endif
7287 +        dput(hidden_sto_dir_dentry);
7288 + out:
7289 +       return err;
7290 +}
7291 +
7292 +/* this function is currently identical to nondir_creat_to_del */
7293 +int nondir_del_rew_to_del(dentry_t *dentry)
7294 +{
7295 +       return nondir_creat_to_del(dentry);
7296 +}
7297 +
7298 +int nondir_creat_to_del(dentry_t *dentry) 
7299 +{
7300 +       int err = 0;
7301 +
7302 +       inode_t *hidden_sto_dir_inode;
7303 +       dentry_t *hidden_sto_dir_dentry;
7304 +       dentry_t *hidden_sto_dentry;
7305 +       
7306 +       check_mini_fo_dentry(dentry);
7307 +
7308 +       /* for now this function serves for both state DEL_REWRITTEN and 
7309 +        * CREATED */
7310 +       if(!(dtost(dentry) == CREATED || (dtost(dentry) == DEL_REWRITTEN)) ||
7311 +          S_ISDIR(dentry->d_inode->i_mode)) {
7312 +               printk(KERN_CRIT "mini_fo: nondir_mod_to_del/del_rew_to_del: \
7313 +                                  wrong type or state.\n");
7314 +               err = -1;
7315 +               goto out;
7316 +       }
7317 +       
7318 +       hidden_sto_dir_inode = itohi2(dentry->d_parent->d_inode);
7319 +       hidden_sto_dentry = dtohd2(dentry);
7320 +       
7321 +       /* was: hidden_sto_dir_dentry = lock_parent(hidden_sto_dentry);*/
7322 +       hidden_sto_dir_dentry = dget(hidden_sto_dentry->d_parent);
7323 +
7324 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
7325 +       mutex_lock(&hidden_sto_dir_dentry->d_inode->i_mutex);
7326 +#else
7327 +       down(&hidden_sto_dir_dentry->d_inode->i_sem);
7328 +#endif
7329 +       
7330 +       /* avoid destroying the hidden inode if the file is in use */
7331 +       dget(hidden_sto_dentry);
7332 +       err = vfs_unlink(hidden_sto_dir_inode, hidden_sto_dentry);
7333 +       dput(hidden_sto_dentry);
7334 +       if(!err)
7335 +               d_delete(hidden_sto_dentry);
7336 +       
7337 +       /* propagate number of hard-links */
7338 +       dentry->d_inode->i_nlink = itohi2(dentry->d_inode)->i_nlink;
7339 +       
7340 +       dtost(dentry) = NON_EXISTANT;
7341 +       
7342 +       /* was: unlock_dir(hidden_sto_dir_dentry); */
7343 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
7344 +       mutex_unlock(&hidden_sto_dir_dentry->d_inode->i_mutex);
7345 +#else
7346 +       up(&hidden_sto_dir_dentry->d_inode->i_sem);
7347 +#endif
7348 +       dput(hidden_sto_dir_dentry);
7349 +       
7350 + out:
7351 +       return err;
7352 +}
7353 +
7354 +int nondir_mod_to_del(dentry_t *dentry)
7355 +{
7356 +       int err;
7357 +       dentry_t *hidden_sto_dentry;
7358 +       inode_t *hidden_sto_dir_inode;
7359 +       dentry_t *hidden_sto_dir_dentry;
7360 +       
7361 +       check_mini_fo_dentry(dentry);
7362 +
7363 +       if(dtost(dentry) != MODIFIED ||
7364 +          S_ISDIR(dentry->d_inode->i_mode)) {
7365 +               printk(KERN_CRIT "mini_fo: nondir_mod_to_del: \
7366 +                                  wrong type or state.\n");
7367 +               err = -1;
7368 +               goto out;
7369 +       }
7370 +
7371 +       hidden_sto_dir_inode = itohi2(dentry->d_parent->d_inode);
7372 +       hidden_sto_dentry = dtohd2(dentry);
7373 +       
7374 +       /* was hidden_sto_dir_dentry = lock_parent(hidden_sto_dentry); */
7375 +       hidden_sto_dir_dentry = dget(hidden_sto_dentry->d_parent);
7376 +
7377 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
7378 +       mutex_lock(&hidden_sto_dir_dentry->d_inode->i_mutex);
7379 +#else
7380 +       down(&hidden_sto_dir_dentry->d_inode->i_sem);
7381 +#endif
7382 +       
7383 +       /* avoid destroying the hidden inode if the file is in use */
7384 +       dget(hidden_sto_dentry);
7385 +       err = vfs_unlink(hidden_sto_dir_inode, hidden_sto_dentry);
7386 +       dput(hidden_sto_dentry);
7387 +       if(!err)
7388 +               d_delete(hidden_sto_dentry);
7389 +       
7390 +       /* propagate number of hard-links */
7391 +       dentry->d_inode->i_nlink = itohi2(dentry->d_inode)->i_nlink;
7392 +       
7393 +       /* dput base dentry, this will relase the inode and free the
7394 +        * dentry, as we will never need it again. */
7395 +       dput(dtohd(dentry));
7396 +       dtohd(dentry) = NULL;
7397 +       dtost(dentry) = DELETED;
7398 +
7399 +       /* add deleted file to META-file */
7400 +       meta_add_d_entry(dentry->d_parent, 
7401 +                        dentry->d_name.name, 
7402 +                        dentry->d_name.len);
7403 +       
7404 +       /* was: unlock_dir(hidden_sto_dir_dentry); */
7405 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
7406 +       mutex_unlock(&hidden_sto_dir_dentry->d_inode->i_mutex);
7407 +#else
7408 +       up(&hidden_sto_dir_dentry->d_inode->i_sem);
7409 +#endif
7410 +       dput(hidden_sto_dir_dentry);
7411 +
7412 + out:
7413 +       return err;
7414 +}
7415 +
7416 +int nondir_unmod_to_del(dentry_t *dentry)
7417 +{
7418 +       int err = 0;
7419 +
7420 +       check_mini_fo_dentry(dentry);
7421 +
7422 +       if(dtost(dentry) != UNMODIFIED ||
7423 +          S_ISDIR(dentry->d_inode->i_mode)) {
7424 +               printk(KERN_CRIT "mini_fo: nondir_unmod_to_del: \
7425 +                                  wrong type or state.\n");
7426 +               err = -1;
7427 +               goto out;
7428 +       }
7429 +       
7430 +        /* next we have to get a negative dentry for the storage file */
7431 +       err = get_neg_sto_dentry(dentry);
7432 +
7433 +       if(err)
7434 +               goto out;               
7435 +
7436 +       /* add deleted file to META lists */
7437 +       err = meta_add_d_entry(dentry->d_parent, 
7438 +                              dentry->d_name.name, 
7439 +                              dentry->d_name.len);
7440 +
7441 +       if(err)
7442 +               goto out;
7443 +       
7444 +       /* dput base dentry, this will relase the inode and free the
7445 +        * dentry, as we will never need it again. */
7446 +       dput(dtohd(dentry));
7447 +       dtohd(dentry) = NULL;
7448 +       dtost(dentry) = DELETED;
7449 +       
7450 + out:
7451 +       return err;
7452 +}
7453 +
7454 +/* bring a dir from state UNMODIFIED to MODIFIED */
7455 +int dir_unmod_to_mod(dentry_t *dentry) 
7456 +{
7457 +       int err;
7458 +
7459 +       check_mini_fo_dentry(dentry);
7460 +
7461 +       if(dtost(dentry) != UNMODIFIED ||
7462 +          !S_ISDIR(dentry->d_inode->i_mode)) {
7463 +               printk(KERN_CRIT "mini_fo: dir_unmod_to_mod: \
7464 +                                  wrong type or state.\n");
7465 +               err = -1;
7466 +               goto out;
7467 +       }
7468 +
7469 +       /* this creates our dir incl. sto. structure */
7470 +       err = build_sto_structure(dentry->d_parent, dentry);
7471 +       if(err) {
7472 +               printk(KERN_CRIT "mini_fo: dir_unmod_to_mod: \
7473 +                                  build_sto_structure failed.\n");
7474 +               goto out;
7475 +       }
7476 + out:
7477 +       return err;
7478 +}
7479 +
7480 diff -urN linux.old/fs/mini_fo/super.c linux.dev/fs/mini_fo/super.c
7481 --- linux.old/fs/mini_fo/super.c        1970-01-01 01:00:00.000000000 +0100
7482 +++ linux.dev/fs/mini_fo/super.c        2006-11-17 03:11:48.000000000 +0100
7483 @@ -0,0 +1,259 @@
7484 +/*
7485 + * Copyright (c) 1997-2003 Erez Zadok
7486 + * Copyright (c) 2001-2003 Stony Brook University
7487 + *
7488 + * For specific licensing information, see the COPYING file distributed with
7489 + * this package, or get one from ftp://ftp.filesystems.org/pub/fist/COPYING.
7490 + *
7491 + * This Copyright notice must be kept intact and distributed with all
7492 + * fistgen sources INCLUDING sources generated by fistgen.
7493 + */
7494 +/*
7495 + * Copyright (C) 2004, 2005 Markus Klotzbuecher <mk@creamnet.de>
7496 + *
7497 + * This program is free software; you can redistribute it and/or
7498 + * modify it under the terms of the GNU General Public License
7499 + * as published by the Free Software Foundation; either version
7500 + * 2 of the License, or (at your option) any later version.
7501 + */
7502 +
7503 +/*
7504 + *  $Id$
7505 + */
7506 +
7507 +#ifdef HAVE_CONFIG_H
7508 +# include <config.h>
7509 +#endif 
7510 +
7511 +#include "fist.h"
7512 +#include "mini_fo.h"
7513 +
7514 +
7515 +STATIC void
7516 +mini_fo_read_inode(inode_t *inode)
7517 +{
7518 +       static struct address_space_operations mini_fo_empty_aops;
7519 +
7520 +       __itopd(inode) = kmalloc(sizeof(struct mini_fo_inode_info), GFP_KERNEL);
7521 +       if (!itopd(inode)) {
7522 +               printk("<0>%s:%s:%d: No kernel memory!\n", __FILE__, __FUNCTION__, __LINE__);
7523 +               ASSERT(NULL);
7524 +       }
7525 +       itohi(inode) = NULL;
7526 +       itohi2(inode) = NULL;
7527 +
7528 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
7529 +       inode->i_version++;
7530 +#else
7531 +       inode->i_version = ++event;     /* increment inode version */
7532 +#endif
7533 +       inode->i_op = &mini_fo_main_iops;
7534 +       inode->i_fop = &mini_fo_main_fops;
7535 +#if 0
7536 +       /*
7537 +        * XXX: To export a file system via NFS, it has to have the
7538 +        * FS_REQUIRES_DEV flag, so turn it on.  But should we inherit it from
7539 +        * the lower file system, or can we allow our file system to be exported
7540 +        * even if the lower one cannot be natively exported.
7541 +        */
7542 +       inode->i_sb->s_type->fs_flags |= FS_REQUIRES_DEV;
7543 +       /*
7544 +        * OK, the above was a hack, which is now turned off because it may
7545 +        * cause a panic/oops on some systems.  The correct way to export a
7546 +        * "nodev" filesystem is via using nfs-utils > 1.0 and the "fsid=" export
7547 +        * parameter, which requires 2.4.20 or later.
7548 +        */
7549 +#endif
7550 +       /* I don't think ->a_ops is ever allowed to be NULL */
7551 +       inode->i_mapping->a_ops = &mini_fo_empty_aops;
7552 +}
7553 +
7554 +
7555 +#if defined(FIST_DEBUG) || defined(FIST_FILTER_SCA)
7556 +/*
7557 + * No need to call write_inode() on the lower inode, as it
7558 + * will have been marked 'dirty' anyway. But we might need
7559 + * to write some of our own stuff to disk.
7560 + */
7561 +STATIC void
7562 +mini_fo_write_inode(inode_t *inode, int sync)
7563 +{
7564 +       print_entry_location();
7565 +       print_exit_location();
7566 +}
7567 +#endif /* defined(FIST_DEBUG) || defined(FIST_FILTER_SCA) */
7568 +
7569 +
7570 +STATIC void
7571 +mini_fo_put_inode(inode_t *inode)
7572 +{
7573 +       /*
7574 +        * This is really funky stuff:
7575 +        * Basically, if i_count == 1, iput will then decrement it and this inode will be destroyed.
7576 +        * It is currently holding a reference to the hidden inode.
7577 +        * Therefore, it needs to release that reference by calling iput on the hidden inode.
7578 +        * iput() _will_ do it for us (by calling our clear_inode), but _only_ if i_nlink == 0.
7579 +        * The problem is, NFS keeps i_nlink == 1 for silly_rename'd files.
7580 +        * So we must for our i_nlink to 0 here to trick iput() into calling our clear_inode.
7581 +        */
7582 +       if (atomic_read(&inode->i_count) == 1)
7583 +               inode->i_nlink = 0;
7584 +}
7585 +
7586 +
7587 +#if defined(FIST_DEBUG) || defined(FIST_FILTER_SCA)
7588 +/*
7589 + * we now define delete_inode, because there are two VFS paths that may
7590 + * destroy an inode: one of them calls clear inode before doing everything
7591 + * else that's needed, and the other is fine.  This way we truncate the inode
7592 + * size (and its pages) and then clear our own inode, which will do an iput
7593 + * on our and the lower inode.
7594 + */
7595 +STATIC void
7596 +mini_fo_delete_inode(inode_t *inode)
7597 +{
7598 +       print_entry_location();
7599 +
7600 +       fist_checkinode(inode, "mini_fo_delete_inode IN");
7601 +       inode->i_size = 0;              /* every f/s seems to do that */
7602 +       clear_inode(inode);
7603 +
7604 +       print_exit_location();
7605 +}
7606 +#endif /* defined(FIST_DEBUG) || defined(FIST_FILTER_SCA) */
7607 +
7608 +
7609 +/* final actions when unmounting a file system */
7610 +STATIC void
7611 +mini_fo_put_super(super_block_t *sb)
7612 +{
7613 +       if (stopd(sb)) {
7614 +               mntput(stopd(sb)->hidden_mnt);
7615 +               mntput(stopd(sb)->hidden_mnt2);
7616 +
7617 +               /* mk: no! dput(stopd(sb)->base_dir_dentry); 
7618 +                  dput(stopd(sb)->storage_dir_dentry); */
7619 +
7620 +               kfree(stopd(sb));
7621 +               __stopd(sb) = NULL;
7622 +       }
7623 +}
7624 +
7625 +
7626 +#ifdef NOT_NEEDED
7627 +/*
7628 + * This is called in do_umount before put_super.
7629 + * The superblock lock is not held yet.
7630 + * We probably do not need to define this or call write_super
7631 + * on the hidden_sb, because sync_supers() will get to hidden_sb
7632 + * sooner or later.  But it is also called from file_fsync()...
7633 + */
7634 +STATIC void
7635 +mini_fo_write_super(super_block_t *sb)
7636 +{
7637 +       return;
7638 +}
7639 +#endif /* NOT_NEEDED */
7640 +
7641 +
7642 +STATIC int
7643 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
7644 +mini_fo_statfs(super_block_t *sb, struct kstatfs *buf)
7645 +#else
7646 +mini_fo_statfs(super_block_t *sb, struct statfs *buf)
7647 +#endif
7648 +{
7649 +       int err = 0;
7650 +       super_block_t *hidden_sb;
7651 +
7652 +       hidden_sb = stohs(sb);
7653 +       err = vfs_statfs(hidden_sb, buf);
7654 +
7655 +       return err;
7656 +}
7657 +
7658 +
7659 +/*
7660 + * XXX: not implemented.  This is not allowed yet.
7661 + * Should we call this on the hidden_sb?  Probably not.
7662 + */
7663 +STATIC int
7664 +mini_fo_remount_fs(super_block_t *sb, int *flags, char *data)
7665 +{
7666 +       //printk(KERN_CRIT "mini_fo_remount_fs: WARNING, this function is umimplemented.\n");
7667 +       return -ENOSYS;
7668 +}
7669 +
7670 +
7671 +/*
7672 + * Called by iput() when the inode reference count reached zero
7673 + * and the inode is not hashed anywhere.  Used to clear anything
7674 + * that needs to be, before the inode is completely destroyed and put
7675 + * on the inode free list.
7676 + */
7677 +STATIC void
7678 +mini_fo_clear_inode(inode_t *inode)
7679 +{
7680 +       /*
7681 +        * Decrement a reference to a hidden_inode, which was incremented
7682 +        * by our read_inode when it was created initially.
7683 +        */
7684 +
7685 +       /* release the wol_list */
7686 +       if(S_ISDIR(inode->i_mode)) {
7687 +               __meta_put_lists(inode);
7688 +       }
7689 +
7690 +       /* mk: fan out fun */
7691 +       if(itohi(inode))
7692 +               iput(itohi(inode));
7693 +       if(itohi2(inode))
7694 +               iput(itohi2(inode));
7695 +
7696 +       // XXX: why this assertion fails?
7697 +       // because it doesn't like us
7698 +       // ASSERT((inode->i_state & I_DIRTY) == 0);
7699 +       kfree(itopd(inode));
7700 +       __itopd(inode) = NULL;
7701 +}
7702 +
7703 +
7704 +/*
7705 + * Called in do_umount() if the MNT_FORCE flag was used and this
7706 + * function is defined.  See comment in linux/fs/super.c:do_umount().
7707 + * Used only in nfs, to kill any pending RPC tasks, so that subsequent
7708 + * code can actually succeed and won't leave tasks that need handling.
7709 + *
7710 + * PS. I wonder if this is somehow useful to undo damage that was
7711 + * left in the kernel after a user level file server (such as amd)
7712 + * dies.
7713 + */
7714 +STATIC void
7715 +mini_fo_umount_begin(super_block_t *sb)
7716 +{
7717 +       super_block_t *hidden_sb;
7718 +
7719 +       hidden_sb = stohs(sb);
7720 +
7721 +       if (hidden_sb->s_op->umount_begin)
7722 +               hidden_sb->s_op->umount_begin(hidden_sb);
7723 +
7724 +}
7725 +
7726 +
7727 +struct super_operations mini_fo_sops =
7728 +{
7729 +       read_inode:             mini_fo_read_inode,
7730 +#if defined(FIST_DEBUG) || defined(FIST_FILTER_SCA)
7731 +       write_inode:    mini_fo_write_inode,
7732 +#endif /* defined(FIST_DEBUG) || defined(FIST_FILTER_SCA) */
7733 +       put_inode:              mini_fo_put_inode,
7734 +#if defined(FIST_DEBUG) || defined(FIST_FILTER_SCA)
7735 +       delete_inode:   mini_fo_delete_inode,
7736 +#endif /* defined(FIST_DEBUG) || defined(FIST_FILTER_SCA) */
7737 +       put_super:              mini_fo_put_super,
7738 +       statfs:         mini_fo_statfs,
7739 +       remount_fs:             mini_fo_remount_fs,
7740 +       clear_inode:    mini_fo_clear_inode,
7741 +       umount_begin:   mini_fo_umount_begin,
7742 +};