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