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