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