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