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