update iptables to 1.4.0 (2.6 kernels only), refresh kernel patches
[openwrt/svn-archive/archive.git] / target / linux / generic-2.6 / patches-2.6.23 / 209-mini_fo.patch
1 Index: linux-2.6.23/fs/Kconfig
2 ===================================================================
3 --- linux-2.6.23.orig/fs/Kconfig 2007-10-10 13:52:14.000000000 +0800
4 +++ linux-2.6.23/fs/Kconfig 2007-10-10 13:53:23.000000000 +0800
5 @@ -458,6 +458,9 @@
6 This option will enlarge your kernel, but it allows debugging of
7 ocfs2 filesystem issues.
8
9 +config MINI_FO
10 + tristate "Mini fanout overlay filesystem"
11 +
12 config MINIX_FS
13 tristate "Minix fs support"
14 help
15 Index: linux-2.6.23/fs/Makefile
16 ===================================================================
17 --- linux-2.6.23.orig/fs/Makefile 2007-10-10 13:52:14.000000000 +0800
18 +++ linux-2.6.23/fs/Makefile 2007-10-10 13:53:23.000000000 +0800
19 @@ -76,6 +76,7 @@
20 obj-$(CONFIG_RAMFS) += ramfs/
21 obj-$(CONFIG_HUGETLBFS) += hugetlbfs/
22 obj-$(CONFIG_CODA_FS) += coda/
23 +obj-$(CONFIG_MINI_FO) += mini_fo/
24 obj-$(CONFIG_MINIX_FS) += minix/
25 obj-$(CONFIG_FAT_FS) += fat/
26 obj-$(CONFIG_MSDOS_FS) += msdos/
27 Index: linux-2.6.23/fs/mini_fo/aux.c
28 ===================================================================
29 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
30 +++ linux-2.6.23/fs/mini_fo/aux.c 2007-10-10 13:53:23.000000000 +0800
31 @@ -0,0 +1,577 @@
32 +/*
33 + * Copyright (c) 1997-2003 Erez Zadok
34 + * Copyright (c) 2001-2003 Stony Brook University
35 + *
36 + * For specific licensing information, see the COPYING file distributed with
37 + * this package, or get one from ftp://ftp.filesystems.org/pub/fist/COPYING.
38 + *
39 + * This Copyright notice must be kept intact and distributed with all
40 + * fistgen sources INCLUDING sources generated by fistgen.
41 + */
42 +/*
43 + * Copyright (C) 2004, 2005 Markus Klotzbuecher <mk@creamnet.de>
44 + *
45 + * This program is free software; you can redistribute it and/or
46 + * modify it under the terms of the GNU General Public License
47 + * as published by the Free Software Foundation; either version
48 + * 2 of the License, or (at your option) any later version.
49 + */
50 +/*
51 + * $Id$
52 + */
53 +
54 +#ifdef HAVE_CONFIG_H
55 +# include <config.h>
56 +#endif
57 +
58 +#include "fist.h"
59 +#include "mini_fo.h"
60 +
61 +/* check if file exists in storage */
62 +int exists_in_storage(dentry_t *dentry)
63 +{
64 + check_mini_fo_dentry(dentry);
65 + if(dtost(dentry) == MODIFIED || dtost(dentry) == CREATED || dtost(dentry) == DEL_REWRITTEN)
66 + return 1;
67 + return 0;
68 +}
69 +
70 +/* check if dentry is in an existing state */
71 +int is_mini_fo_existant(dentry_t *dentry)
72 +{
73 + check_mini_fo_dentry(dentry);
74 +
75 + if(dtost(dentry) == DELETED || dtost(dentry) == NON_EXISTANT)
76 + return 0;
77 + else
78 + return 1;
79 +}
80 +
81 +/*
82 + * This function will create a negative storage dentry for
83 + * dentry, what is required for many create like options.
84 + * It will create the storage structure if necessary.
85 + */
86 +int get_neg_sto_dentry(dentry_t *dentry)
87 +{
88 + int err = 0;
89 + unsigned int len;
90 + const unsigned char *name;
91 +
92 + if(!dentry ||
93 + !dtopd(dentry) ||
94 + !(dtost(dentry) == UNMODIFIED ||
95 + dtost(dentry) == NON_EXISTANT ||
96 + dtost(dentry) == DELETED)) {
97 + printk(KERN_CRIT "mini_fo: get_neg_sto_dentry: invalid dentry passed.\n");
98 + err = -1;
99 + goto out;
100 + }
101 + /* Have we got a neg. dentry already? */
102 + if(dtohd2(dentry)) {
103 + err = 0;
104 + goto out;
105 + }
106 + if(dtost(dentry->d_parent) == UNMODIFIED) {
107 + /* build sto struct */
108 + err = build_sto_structure(dentry->d_parent->d_parent, dentry->d_parent);
109 + if(err ||
110 + dtost(dentry->d_parent) != MODIFIED) {
111 + printk(KERN_CRIT "mini_fo: get_neg_sto_dentry: ERROR building sto structure.\n");
112 + err = -1;
113 + goto out;
114 + }
115 + }
116 +
117 + len = dentry->d_name.len;
118 + name = dentry->d_name.name;
119 +
120 + dtohd2(dentry) =
121 + lookup_one_len(name, dtohd2(dentry->d_parent), len);
122 +
123 + out:
124 + return err;
125 +}
126 +
127 +int check_mini_fo_dentry(dentry_t *dentry)
128 +{
129 + ASSERT(dentry != NULL);
130 + ASSERT(dtopd(dentry) != NULL);
131 + ASSERT((dtohd(dentry) != NULL) || (dtohd2(dentry) != NULL));
132 +
133 +/* if(dtost(dentry) == MODIFIED) { */
134 +/* ASSERT(dentry->d_inode != NULL); */
135 +/* ASSERT(dtohd(dentry) != NULL); */
136 +/* ASSERT(dtohd(dentry)->d_inode != NULL); */
137 +/* ASSERT(dtohd2(dentry) != NULL); */
138 +/* ASSERT(dtohd2(dentry)->d_inode != NULL); */
139 +/* } */
140 +/* else if(dtost(dentry) == UNMODIFIED) { */
141 +/* ASSERT(dentry->d_inode != NULL); */
142 +/* ASSERT( */
143 +/* } */
144 + return 0;
145 +}
146 +
147 +int check_mini_fo_file(file_t *file)
148 +{
149 + ASSERT(file != NULL);
150 + ASSERT(ftopd(file) != NULL);
151 + ASSERT(file->f_dentry != NULL);
152 +
153 + /* violent checking, check depending of state and type
154 + * if(S_ISDIR(file->f_dentry->d_inode->i_mode)) {}
155 + */
156 + ASSERT((ftohf(file) != NULL) || (ftohf2(file) != NULL));
157 + return 0;
158 +}
159 +
160 +int check_mini_fo_inode(inode_t *inode)
161 +{
162 + ASSERT(inode != NULL);
163 + ASSERT(itopd(inode) != NULL);
164 + ASSERT((itohi(inode) != NULL) || (itohi2(inode) != NULL));
165 + return 0;
166 +}
167 +
168 +/*
169 + * will walk a base path as provided by get_mini_fo_bpath and return
170 + * the (hopefully ;-) ) positive dentry of the renamed base dir.
171 + *
172 + * This does some work of path_init.
173 + */
174 +dentry_t *bpath_walk(super_block_t *sb, char *bpath)
175 +{
176 + int err;
177 + struct vfsmount *mnt;
178 + struct nameidata nd;
179 +
180 + /* be paranoid */
181 + if(!bpath || bpath[0] != '/') {
182 + printk(KERN_CRIT "mini_fo: bpath_walk: Invalid string.\n");
183 + return NULL;
184 + }
185 + if(!sb || !stopd(sb)) {
186 + printk(KERN_CRIT "mini_fo: bpath_walk: Invalid sb.\n");
187 + return NULL;
188 + }
189 +
190 + /* fix this: how do I reach this lock?
191 + * read_lock(&current->fs->lock); */
192 + mnt = mntget(stopd(sb)->hidden_mnt);
193 + /* read_unlock(&current->fs->lock); */
194 +
195 + err = vfs_path_lookup(mnt->mnt_root, mnt, bpath+1, 0, &nd);
196 +
197 + /* validate */
198 + if (err || !nd.dentry || !nd.dentry->d_inode) {
199 + printk(KERN_CRIT "mini_fo: bpath_walk: path_walk failed.\n");
200 + return NULL;
201 + }
202 + return nd.dentry;
203 +}
204 +
205 +
206 +/* returns the full path of the basefile incl. its name */
207 +int get_mini_fo_bpath(dentry_t *dentry, char **bpath, int *bpath_len)
208 +{
209 + char *buf_walker;
210 + int len = 0;
211 + dentry_t *sky_walker;
212 +
213 + if(!dentry || !dtohd(dentry)) {
214 + printk(KERN_CRIT "mini_fo: get_mini_fo_bpath: invalid dentry passed.\n");
215 + return -1;
216 + }
217 + sky_walker = dtohd(dentry);
218 +
219 + do {
220 + len += sky_walker->d_name.len + 1 ; /* 1 for '/' */
221 + sky_walker = sky_walker->d_parent;
222 + } while(sky_walker != stopd(dentry->d_inode->i_sb)->base_dir_dentry);
223 +
224 + /* 1 to oil the loop */
225 + *bpath = (char*) kmalloc(len + 1, GFP_KERNEL);
226 + if(!*bpath) {
227 + printk(KERN_CRIT "mini_fo: get_mini_fo_bpath: out of mem.\n");
228 + return -1;
229 + }
230 + buf_walker = *bpath+len; /* put it on last char */
231 + *buf_walker = '\n';
232 + sky_walker = dtohd(dentry);
233 +
234 + do {
235 + buf_walker -= sky_walker->d_name.len;
236 + strncpy(buf_walker,
237 + sky_walker->d_name.name,
238 + sky_walker->d_name.len);
239 + *(--buf_walker) = '/';
240 + sky_walker = sky_walker->d_parent;
241 + } while(sky_walker != stopd(dentry->d_inode->i_sb)->base_dir_dentry);
242 +
243 + /* bpath_len doesn't count newline! */
244 + *bpath_len = len;
245 + return 0;
246 +}
247 +
248 +int mini_fo_cp_cont(dentry_t *tgt_dentry, struct vfsmount *tgt_mnt,
249 + dentry_t *src_dentry, struct vfsmount *src_mnt)
250 +{
251 + void *buf;
252 + mm_segment_t old_fs;
253 + file_t *tgt_file;
254 + file_t *src_file;
255 + int bytes, len, tmp, err;
256 + err = 0;
257 +
258 + if(!(tgt_dentry->d_inode && src_dentry->d_inode)) {
259 + printk(KERN_CRIT "mini_fo_cp_cont: ERROR, neg. dentry passed.\n");
260 + err = -EINVAL;
261 + goto out;
262 + }
263 +
264 + dget(tgt_dentry);
265 + dget(src_dentry);
266 + mntget(tgt_mnt);
267 + mntget(src_mnt);
268 +
269 + /* open file write only */
270 + tgt_file = dentry_open(tgt_dentry, tgt_mnt, 0x1);
271 + if(!tgt_file || IS_ERR(tgt_file)) {
272 + printk(KERN_CRIT "mini_fo_cp_cont: ERROR opening target file.\n");
273 + err = PTR_ERR(tgt_file);
274 + goto out_err;
275 + }
276 +
277 + /* open file read only */
278 + src_file = dentry_open(src_dentry, src_mnt, 0x0);
279 + if(!src_file || IS_ERR(src_file)) {
280 + printk(KERN_CRIT "mini_fo_cp_cont: ERROR opening source file.\n");
281 + err = PTR_ERR(src_file);
282 +
283 + /* close target file */
284 + fput(tgt_file);
285 + goto out_err;
286 + }
287 +
288 + /* check if the filesystem(s) support read respective write */
289 + if(!src_file->f_op->read || !tgt_file->f_op->write) {
290 + printk(KERN_CRIT "mini_fo_cp_cont: ERROR, no fs read or write support.\n");
291 + err = -EPERM;
292 + goto out_close;
293 + }
294 +
295 + /* allocate a page for transfering the data */
296 + buf = (void *) __get_free_page(GFP_KERNEL);
297 + if(!buf) {
298 + printk(KERN_CRIT "mini_fo_cp_cont: ERROR, out of kernel mem.\n");
299 + goto out_err;
300 + }
301 +
302 + tgt_file->f_pos = 0;
303 + src_file->f_pos = 0;
304 +
305 + old_fs = get_fs();
306 + set_fs(KERNEL_DS);
307 +
308 + /* Doing this I assume that a read operation will return a full
309 + * buffer while there is still data to read, and a less than
310 + * full buffer when all data has been read.
311 + */
312 + bytes = len = PAGE_SIZE;
313 + while(bytes == len) {
314 + bytes = src_file->f_op->read(src_file, buf, len,
315 + &src_file->f_pos);
316 + tmp = tgt_file->f_op->write(tgt_file, buf, bytes,
317 + &tgt_file->f_pos);
318 + if(tmp != bytes) {
319 + printk(KERN_CRIT "mini_fo_cp_cont: ERROR writing.\n");
320 + goto out_close_unset;
321 + }
322 + }
323 +
324 + free_page((unsigned long) buf);
325 + set_fs(old_fs);
326 + fput(tgt_file);
327 + fput(src_file);
328 + goto out;
329 +
330 + out_close_unset:
331 + free_page((unsigned long) buf);
332 + set_fs(old_fs);
333 +
334 + out_close:
335 + fput(tgt_file);
336 + fput(src_file);
337 +
338 + out_err:
339 + dput(tgt_dentry);
340 + dput(src_dentry);
341 +
342 + /* mk: not sure if this need to be done */
343 + mntput(tgt_mnt);
344 + mntput(src_mnt);
345 +
346 + out:
347 + return err;
348 +}
349 +
350 +/* mk:
351 + * ndl (no-duplicate list) stuff
352 + * This is used in mini_fo_readdir, to save the storage directory contents
353 + * and later when reading base, match them against the list in order
354 + * to avoid duplicates.
355 + */
356 +
357 +/* add a file specified by name and len to the ndl
358 + * Return values: 0 on success, <0 on failure.
359 + */
360 +int ndl_add_entry(struct readdir_data *rd, const char *name, int len)
361 +{
362 + struct ndl_entry *tmp_entry;
363 +
364 + tmp_entry = (struct ndl_entry *)
365 + kmalloc(sizeof(struct ndl_entry), GFP_KERNEL);
366 + if(!tmp_entry) {
367 + printk(KERN_CRIT "mini_fo: ndl_add_entry: out of mem.\n");
368 + return -ENOMEM;
369 + }
370 + tmp_entry->name = (char*) kmalloc(len, GFP_KERNEL);
371 + if(!tmp_entry->name) {
372 + printk(KERN_CRIT "mini_fo: ndl_add_entry: out of mem.\n");
373 + return -ENOMEM;
374 + }
375 + strncpy(tmp_entry->name, name, len);
376 + tmp_entry->len = len;
377 +
378 + list_add(&tmp_entry->list, &rd->ndl_list);
379 + rd->ndl_size++;
380 + return 0;
381 +}
382 +
383 +/* delete all list entries and free memory */
384 +void ndl_put_list(struct readdir_data *rd)
385 +{
386 + struct list_head *tmp;
387 + struct ndl_entry *tmp_entry;
388 +
389 + if(rd->ndl_size <= 0)
390 + return;
391 + while(!list_empty(&rd->ndl_list)) {
392 + tmp = rd->ndl_list.next;
393 + list_del(tmp);
394 + tmp_entry = list_entry(tmp, struct ndl_entry, list);
395 + kfree(tmp_entry->name);
396 + kfree(tmp_entry);
397 + }
398 + rd->ndl_size = 0;
399 +}
400 +
401 +/* Check if a file specified by name and len is in the ndl
402 + * Return value: 0 if not in list, 1 if file is found in ndl.
403 + */
404 +int ndl_check_entry(struct readdir_data *rd, const char *name, int len)
405 +{
406 + struct list_head *tmp;
407 + struct ndl_entry *tmp_entry;
408 +
409 + if(rd->ndl_size <= 0)
410 + return 0;
411 +
412 + list_for_each(tmp, &rd->ndl_list) {
413 + tmp_entry = list_entry(tmp, struct ndl_entry, list);
414 + if(tmp_entry->len != len)
415 + continue;
416 + if(!strncmp(tmp_entry->name, name, len))
417 + return 1;
418 + }
419 + return 0;
420 +}
421 +
422 +/* mk:
423 + * Recursive function to create corresponding directorys in the storage fs.
424 + * The function will build the storage directorys up to dentry.
425 + */
426 +int build_sto_structure(dentry_t *dir, dentry_t *dentry)
427 +{
428 + int err;
429 + dentry_t *hidden_sto_dentry;
430 + dentry_t *hidden_sto_dir_dentry;
431 +
432 + if(dentry->d_parent != dir) {
433 + printk(KERN_CRIT "mini_fo: build_sto_structure: invalid parameter or meta data corruption [1].\n");
434 + return 1;
435 + }
436 +
437 + if(dtost(dir) != MODIFIED) {
438 + err = build_sto_structure(dir->d_parent, dentry->d_parent);
439 + if(err)
440 + return err;
441 + }
442 +
443 + /* ok, coming back again. */
444 + check_mini_fo_dentry(dentry);
445 + hidden_sto_dentry = dtohd2(dentry);
446 +
447 + if(!hidden_sto_dentry) {
448 + /*
449 + * This is the case after creating the first
450 + * hidden_sto_dentry.
451 + * After one negative storage_dentry, all pointers to
452 + * hidden_storage dentries are set to NULL. We need to
453 + * create the negative dentry before we create the storage
454 + * file.
455 + */
456 + unsigned int len;
457 + const unsigned char *name;
458 + len = dtohd(dentry)->d_name.len;
459 + name = dtohd(dentry)->d_name.name;
460 + hidden_sto_dentry = lookup_one_len(name, dtohd2(dir), len);
461 + dtohd2(dentry) = hidden_sto_dentry;
462 + }
463 +
464 + /* was: hidden_sto_dir_dentry = lock_parent(hidden_sto_dentry); */
465 + hidden_sto_dir_dentry = dget(hidden_sto_dentry->d_parent);
466 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
467 + mutex_lock(&hidden_sto_dir_dentry->d_inode->i_mutex);
468 +#else
469 + down(&hidden_sto_dir_dentry->d_inode->i_sem);
470 +#endif
471 + /* lets be safe */
472 + if(dtohd2(dir) != hidden_sto_dir_dentry) {
473 + printk(KERN_CRIT "mini_fo: build_sto_structure: invalid parameter or meta data corruption [2].\n");
474 + return 1;
475 + }
476 +
477 + /* check for errors in lock_parent */
478 + err = PTR_ERR(hidden_sto_dir_dentry);
479 + if(IS_ERR(hidden_sto_dir_dentry)) {
480 + printk(KERN_CRIT "mini_fo: build_sto_structure: lock_parent failed.\n");
481 + return err;
482 + }
483 +
484 + err = vfs_mkdir(hidden_sto_dir_dentry->d_inode,
485 + hidden_sto_dentry,
486 + dir->d_inode->i_mode);
487 +
488 + if(err) {
489 + printk(KERN_CRIT "mini_fo: build_sto_structure: failed to create storage dir [1].\n");
490 + /* was: unlock_dir(dir); */
491 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
492 + mutex_unlock(&dir->d_inode->i_mutex);
493 +#else
494 + up(&dir->d_inode->i_sem);
495 +#endif
496 + dput(dir);
497 + return err;
498 + }
499 +
500 + /* everything ok! */
501 + if(!dtohd2(dentry)->d_inode) {
502 + printk(KERN_CRIT "mini_fo: build_sto_structure: failed to create storage dir [2].\n");
503 + /* was: unlock_dir(dir); */
504 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
505 + mutex_unlock(&dir->d_inode->i_mutex);
506 +#else
507 + up(&dir->d_inode->i_sem);
508 +#endif
509 + dput(dir);
510 + return 1;
511 + }
512 +
513 + /* interpose the new inode and set new state */
514 + itohi2(dentry->d_inode) = igrab(dtohd2(dentry)->d_inode);
515 + dtopd(dentry)->state = MODIFIED;
516 +
517 + /* initalize the wol list */
518 + itopd(dentry->d_inode)->deleted_list_size = -1;
519 + itopd(dentry->d_inode)->renamed_list_size = -1;
520 + meta_build_lists(dentry);
521 +
522 + fist_copy_attr_all(dentry->d_inode, itohi2(dentry->d_inode));
523 + fist_copy_attr_timesizes(dir->d_inode,
524 + hidden_sto_dir_dentry->d_inode);
525 + dir->d_inode->i_nlink++;
526 + /* was: unlock_dir(hidden_sto_dir_dentry); */
527 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
528 + mutex_unlock(&hidden_sto_dir_dentry->d_inode->i_mutex);
529 +#else
530 + up(&hidden_sto_dir_dentry->d_inode->i_sem);
531 +#endif
532 + dput(hidden_sto_dir_dentry);
533 + return 0;
534 +}
535 +
536 +
537 +#if 0 /* unused */
538 +
539 +/*
540 + * Read "len" bytes from "filename" into "buf".
541 + * "buf" is in kernel space.
542 + */
543 +int
544 +mini_fo_read_file(const char *filename, void *buf, int len)
545 +{
546 + file_t *filp;
547 + mm_segment_t oldfs;
548 + int bytes;
549 + /* Chroot? Maybe NULL isn't right here */
550 + filp = filp_open(filename, O_RDONLY, 0);
551 + if (!filp || IS_ERR(filp)) {
552 + printk("mini_fo_read_file err %d\n", (int) PTR_ERR(filp));
553 + return -1; /* or do something else */
554 + }
555 +
556 + if (!filp->f_op->read)
557 + return -2; /* file(system) doesn't allow reads */
558 +
559 + /* now read len bytes from offset 0 */
560 + filp->f_pos = 0; /* start offset */
561 + oldfs = get_fs();
562 + set_fs(KERNEL_DS);
563 + bytes = filp->f_op->read(filp, buf, len, &filp->f_pos);
564 + set_fs(oldfs);
565 +
566 + /* close the file */
567 + fput(filp);
568 +
569 + return bytes;
570 +}
571 +
572 +
573 +
574 +/*
575 + * Write "len" bytes from "buf" to "filename"
576 + * "buf" is in kernel space.
577 + */
578 +int
579 +mini_fo_write_file(const char *filename, void *buf, int len)
580 +{
581 + file_t *filp;
582 + mm_segment_t oldfs;
583 + int bytes;
584 + /* Chroot? Maybe NULL isn't right here */
585 + filp = filp_open(filename, O_RDWR|O_CREAT, 0640);
586 + if (!filp || IS_ERR(filp)) {
587 + printk("mini_fo_write_file err %d\n", (int) PTR_ERR(filp));
588 + return -1; /* or do something else */
589 + }
590 +
591 + if (!filp->f_op->write)
592 + return -2; /* file(system) doesn't allow writes */
593 +
594 + /* now write len bytes from offset 0 */
595 + filp->f_pos = 0; /* start offset */
596 + oldfs = get_fs();
597 + set_fs(KERNEL_DS);
598 + bytes = filp->f_op->write(filp, buf, len, &filp->f_pos);
599 + set_fs(oldfs);
600 +
601 + /* close the file */
602 + fput(filp);
603 +
604 + return bytes;
605 +}
606 +
607 +#endif /* unused */
608 +
609 Index: linux-2.6.23/fs/mini_fo/ChangeLog
610 ===================================================================
611 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
612 +++ linux-2.6.23/fs/mini_fo/ChangeLog 2007-10-10 13:53:23.000000000 +0800
613 @@ -0,0 +1,281 @@
614 +2006-01-24 Markus Klotzbuecher <mk@mary.denx.de>
615 +
616 + * Add tons of ugly ifdefs to Ed L. Cashin's mutex patch to
617 + retain backwards compatibility.
618 +
619 +2006-01-24 Ed L. Cashin <ecashin@coraid.com>
620 +
621 + * Support for the new mutex infrastructure
622 + (7892f2f48d165a34b0b8130c8a195dfd807b8cb6)
623 +
624 +2005-10-15 Markus Klotzbuecher <mk@localhost.localdomain>
625 +
626 + * Bugfix for a serious memory leak in mini_fo_follow_link.
627 +
628 +2005-09-21 Markus Klotzbuecher <mk@mary>
629 +
630 + * new release 0.6.1
631 +
632 + * fix of a compiler warning due to changes in 2.6.13
633 +
634 +2005-09-21 Klaus Wenninger <klaus.wenninger@siemens.com>
635 +
636 + * file.c: readdir: fix for a bug that caused directory entries
637 + to show up twice when using storage filesystems such as
638 + minixfs or pramfs.
639 +
640 +2005-06-30 Eric Lammerts <eric@lammerts.org>
641 +
642 + * fix for an oops when overwriting a binary thats beeing
643 + executed.
644 +
645 +2005-06-09 <mk@mary>
646 +
647 + * Renamed overlay to mini_fo-overlay.
648 +
649 + * Added mini_fo-merge script to allow merging of storage and base
650 + after making modifications.
651 +
652 +2005-05-22 root <mk@mary>
653 +
654 + * Added overlay script that allows to easily mount mini_fo ontop
655 + of a given base directory
656 +
657 +2005-05-10 <mk@mary>
658 +
659 + * inode.c: xattr functions return -EOPNOSUPP instead of
660 + -ENOSUPP, what confuses "ls -l"
661 +
662 + * Changed license from LGPL to GPL.
663 +
664 +2005-05-08 root <mk@mary>
665 +
666 + * Makefile: clean it up and added make install and make
667 + uninstall.
668 +
669 +2005-05-06 <mk@mary>
670 +
671 + * merged devel branch back to main. [v0-6-0-pre3]
672 +
673 + * removed unused files print.c and fist_ioctl. [devel-0-0-18]
674 +
675 + * ioctl: removed fist_ioctl stuff, that is not needed for
676 + now.
677 +
678 +2005-05-03 <mk@mary>
679 +
680 + * file.c: simplified mini_fo_open and mini_fo_setattr using
681 + new state changing functions. [devel-0-0-17]
682 +
683 + * inode.c: Fixed getattr state bug (see below) in 2.4 function
684 + mini_fo_inode revalidate.
685 +
686 + * inode.c: found an other bug in mini_fo_getattr. States are not
687 + reliable in this function, as a file can be opened, unlinked and
688 + the getattr function called. This results in a deleted dentry
689 + with an inode. Fix is to ignore states and simply use the inode
690 + available.
691 +
692 +2005-04-29 <mk@mary>
693 +
694 + * file.c: Bugfix and cleanup in fasync and fsync. [devel-0-0-16]
695 +
696 + * file.c: do not use mini_fo_lock so the generic version is
697 + used (I guess).
698 +
699 + * inode.c: getattr, never call getattr on lower files, as this
700 + will cause the inum to change.
701 +
702 + * inode.c: rename_reg_file renamed to rename_nondir, as it
703 + doesn't matter as long it't not a dir. Removed all
704 + rename_dev_file etc.
705 +
706 + * tagged as devel-0-0-15
707 +
708 + * inode.c: added support for chosing support for extended
709 + attrs at compile time by XATTR define in mini_fo.h .
710 +
711 + * inode.c: fixed mini_fo_getattr to use mini_fo inode and not
712 + lower again, what avoids inode number changes that confused
713 + rm again. This is the proper solution.
714 +
715 +2005-04-24 <mk@mary>
716 +
717 + * all files: updated Copyright notive to 2005. [devel-0-0-14]
718 +
719 + * inode.c: fixed mini_fo_getattr to not change the inode
720 + number, even if lower files change.
721 +
722 + * super.c: fixed a bug that caused deleted base file to show
723 + up suddenly after some time, or after creating a special
724 + file. The problem was that after some time or after special
725 + file creating sync_sb_inodes is called by the vfs, that
726 + called our mini_fo_put_inode. There was (wrongly) called
727 + __meta_put_lists, that nuked the lists, although the inode
728 + was going to continue its life. Moving __meta_put_lists to
729 + mini_fo_clear_inode, where an inode is really destroyed,
730 + solved the problem.
731 +
732 +
733 +2005-04-23 <mk@mary>
734 +
735 + * state.c, aux.c: more cleaning up and
736 + simplifications. [devel-0-0-13]
737 +
738 + * inode.c: implemented mini_fo_getattr, that was required for
739 + 2.6 because inode_revalidate has been remove there, and the
740 + old "du" bug returned.
741 +
742 +
743 +2005-04-20 <mk@mary>
744 +
745 + * aux.c: get_neg_sto_dentry(): allow to be called for dentries
746 + in state UNMODIFIED, NON_EXISTANT _and_ DELETED.
747 +
748 +2005-04-19 <mk@mary>
749 +
750 + * Fixed a bug under 2.6 that caused files deleted via mini_fo
751 + not to be deleted properly and therefore the fs filled up
752 + untill no memory was left. [devel-0-0-12]
753 +
754 + * Added basic hard link support. This means that creating
755 + hardlinks will work, but existing ones will be treated as
756 + individual files. [devel-0-0-11]
757 +
758 +2005-04-17 <mk@mary>
759 +
760 + * Bugfixes
761 +
762 +2005-04-13 root <mk@mary>
763 +
764 + * Added file state.c for the state transition
765 + functions. Doesn't work very well yet, though...
766 +
767 +2005-04-12 <mk@mary>
768 +
769 + * Porting to 2.6 started, which is easier than expected, also
770 + due to Olivier previous work.
771 +
772 +2005-04-08 <mk@mary>
773 +
774 + * Fixed the bug that caused du to return invalid sizes of
775 + directory trees. The problem was that
776 + mini_fo_inode_revalidate didn't always copy the attributes
777 + from the base inode properly.
778 +
779 +2005-04-01 Markus Klotzbuecher <mk@chasey>
780 +
781 + * Merged devel branch back to main trunk and updated the
782 + RELEASE notes. This will be 0-6-0-pre1.
783 +
784 +2005-03-31 Markus Klotzbuecher <mk@chasey>
785 +
786 + * Fixed some bugs in rename_reg_file, that only showed up in
787 + the kernel compile test. Kernel compiles cleanly ontop of
788 + mini_fo, now also make mrproper etc. work. Seems pretty stable.
789 +
790 +2005-03-28 Markus Klotzbuecher <mk@chasey>
791 +
792 + * Many, many directory renaming bugfixes and a lot of other
793 + cleanup. Dir renaming seems to work relatively stable.
794 +
795 +2005-03-22 Markus Klotzbuecher <mk@chasey>
796 +
797 + * Finished implementing lightweight directory renaming. Some
798 + basic testing indicates it works fine.
799 + Next is to implement testcases for the testsuite and confirm
800 + everything is really working ok.
801 +
802 +2005-03-18 Markus Klotzbuecher <mk@chasey>
803 +
804 + * Finished implementing meta.c stuff required for directory
805 + renaming.
806 +
807 +2005-03-17 Markus Klotzbuecher <mk@chasey>
808 +
809 + * Fixed all compile warnings + an extremly old bug that
810 + somehow crept in while reworking the wol stuff to the META
811 + system. Turning on -Werror again... :-)
812 +
813 + * Fixed some bugs in the new rename_reg_file function.
814 +
815 + * Rewrote mini_fo rename and split it into several
816 + subfunctions, that handle the different types
817 + seperately. Rewrote the regular file function aswell, as it
818 + was implemented somewhat inefficient.
819 +
820 +2005-03-16 Markus Klotzbuecher <mk@chasey>
821 +
822 + * Implemented new META subsystem, removed old WOL stuff in favor
823 + if it.
824 +
825 + * After some basic testing everything seems ok...
826 +
827 +2005-03-11 Markus Klotzbuecher <mk@chasey>
828 +
829 + * Renaming a non regular file caused trouble because I always
830 + tried to copy the contents. Now I only do this for regular
831 + files. mini_fo_rename still isn't implemented properly, renaming
832 + of device files, symlinks etc. results in a empty regular file
833 + instead of the proper type.
834 +
835 + * Directory renaming suddenly works! What a surprise! I guess
836 + this is because renaming is implemented as making a copy and
837 + removing the original. Still this might not work
838 + everywhere...
839 +
840 +2005-03-09 Markus Klotzbuecher <mk@chasey>
841 +
842 + * Bugfix, when a mini_fo directory that exists in storage
843 + (state: MODIFIED, CREATED and DEL_REWRITTEN) is deleted, a
844 + possibly existing WOL file contained in it needs to be
845 + deleted too.
846 +
847 + * Starting cleanup: defined state names in order to get rid of
848 + the state numbers.
849 +
850 +2005-03-08 Markus Klotzbuecher <mk@chasey>
851 +
852 + * Makefile fix, fist_ioctl was built against wrong sources if ARCH=um
853 +
854 + * Fixed a bug in dentry.c, mini_fo_d_hash. In state 4 =
855 + DEL_REWRITTEN the hash was calculated from the base dentry,
856 + which was wrong and and caused assertions in
857 + __mini_fo_hidden_dentry to fail.
858 +
859 +2005-02-21 <mk@mary>
860 +
861 + * Implemented directory deleting (inode.c)
862 +
863 + * main.c: made mini_fo_parse_options a little more robust.
864 +
865 +2004-12-22 <mk@mary>
866 +
867 + * Makefile cleanup and uml stuff, removed unneccessary files
868 +
869 + * Created a new and hopefully more informative README
870 +
871 + * CHANGELOG: created a new CHANGELOG and added old entries reversely
872 +
873 +
874 +2004-10-24 Gleb Natapov <gleb@nbase.co.il>
875 +
876 + * Fix: owner and group where not correctly copied from base to
877 + storage.
878 +
879 +
880 +2004-10-05 Gleb Natapov <gleb@nbase.co.il>
881 +
882 + * Implementation of fsync, fasync and lock mini_fo functions.
883 +
884 +
885 +2004-09-29 Bob Lee <bob@pantasys.com>
886 +
887 + * Fix of a serious pointer bug
888 +
889 +
890 +2004-09-28 Gleb Natapov <gleb@nbase.co.il>
891 +
892 + * Implementation of mini_fo_mknod and mini_fo_rename, support
893 + for device files.
894 +
895 Index: linux-2.6.23/fs/mini_fo/dentry.c
896 ===================================================================
897 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
898 +++ linux-2.6.23/fs/mini_fo/dentry.c 2007-10-10 13:53:23.000000000 +0800
899 @@ -0,0 +1,244 @@
900 +/*
901 + * Copyright (c) 1997-2003 Erez Zadok
902 + * Copyright (c) 2001-2003 Stony Brook University
903 + *
904 + * For specific licensing information, see the COPYING file distributed with
905 + * this package, or get one from ftp://ftp.filesystems.org/pub/fist/COPYING.
906 + *
907 + * This Copyright notice must be kept intact and distributed with all
908 + * fistgen sources INCLUDING sources generated by fistgen.
909 + */
910 +/*
911 + * Copyright (C) 2004, 2005 Markus Klotzbuecher <mk@creamnet.de>
912 + *
913 + * This program is free software; you can redistribute it and/or
914 + * modify it under the terms of the GNU General Public License
915 + * as published by the Free Software Foundation; either version
916 + * 2 of the License, or (at your option) any later version.
917 + */
918 +
919 +/*
920 + * $Id$
921 + */
922 +
923 +#ifdef HAVE_CONFIG_H
924 +# include <config.h>
925 +#endif
926 +
927 +#include "fist.h"
928 +#include "mini_fo.h"
929 +
930 +/*
931 + * THIS IS A BOOLEAN FUNCTION: returns 1 if valid, 0 otherwise.
932 + */
933 +STATIC int
934 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
935 +mini_fo_d_revalidate(dentry_t *dentry, struct nameidata *nd)
936 +#else
937 +mini_fo_d_revalidate(dentry_t *dentry, int flags)
938 +#endif
939 +{
940 + int err1 = 1; /* valid = 1, invalid = 0 */
941 + int err2 = 1;
942 + dentry_t *hidden_dentry;
943 + dentry_t *hidden_sto_dentry;
944 +
945 +
946 + check_mini_fo_dentry(dentry);
947 +
948 + hidden_dentry = dtohd(dentry);
949 + hidden_sto_dentry = dtohd2(dentry);
950 +
951 + if(hidden_dentry &&
952 + hidden_dentry->d_op &&
953 + hidden_dentry->d_op->d_revalidate) {
954 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
955 + err1 = hidden_dentry->d_op->d_revalidate(hidden_dentry, nd);
956 +#else
957 + err1 = hidden_dentry->d_op->d_revalidate(hidden_dentry, flags);
958 +#endif
959 + }
960 + if(hidden_sto_dentry &&
961 + hidden_sto_dentry->d_op &&
962 + hidden_sto_dentry->d_op->d_revalidate) {
963 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
964 + err2 = hidden_sto_dentry->d_op->d_revalidate(hidden_sto_dentry,
965 + nd);
966 +#else
967 + err2 = hidden_sto_dentry->d_op->d_revalidate(hidden_sto_dentry,
968 + flags);
969 +#endif
970 + }
971 +
972 + /* mk: if one of the lower level dentries are valid,
973 + * the mini_fo dentry is too.
974 + */
975 + return (err1 || err2);
976 +}
977 +
978 +
979 +STATIC int
980 +mini_fo_d_hash(dentry_t *dentry, qstr_t *name)
981 +{
982 + int err = 0;
983 + dentry_t *hidden_dentry;
984 + dentry_t *hidden_sto_dentry;
985 +
986 + /* hidden_dentry = mini_fo_hidden_dentry(dentry);
987 + * hidden_sto_dentry = mini_fo_hidden_sto_dentry(dentry); */
988 +
989 + /* state 1, 3, 4, 5: build the hash for the storage dentry */
990 + if((dtopd(dentry)->state == MODIFIED) ||
991 + (dtopd(dentry)->state == CREATED) ||
992 + (dtopd(dentry)->state == DEL_REWRITTEN) ||
993 + (dtopd(dentry)->state == DELETED)) {
994 + hidden_sto_dentry = dtohd2(dentry);
995 + if(hidden_sto_dentry &&
996 + hidden_sto_dentry->d_op &&
997 + hidden_sto_dentry->d_op->d_hash) {
998 + err = hidden_sto_dentry->d_op->d_hash(hidden_sto_dentry, name);
999 + }
1000 + goto out;
1001 + }
1002 + /* state 2: build the hash for the base dentry */
1003 + if(dtopd(dentry)->state == UNMODIFIED) {
1004 + hidden_dentry = dtohd(dentry);
1005 + if(hidden_dentry &&
1006 + hidden_dentry->d_op &&
1007 + hidden_dentry->d_op->d_hash) {
1008 + err = hidden_dentry->d_op->d_hash(hidden_dentry, name);
1009 + }
1010 + goto out;
1011 + }
1012 + /* state 6: build hash for the dentry that exists */
1013 + if(dtopd(dentry)->state == NON_EXISTANT) {
1014 + hidden_sto_dentry = dtohd2(dentry);
1015 + if(hidden_sto_dentry &&
1016 + hidden_sto_dentry->d_op &&
1017 + hidden_sto_dentry->d_op->d_hash) {
1018 + err = hidden_sto_dentry->d_op->d_hash(hidden_sto_dentry, name);
1019 + goto out;
1020 + }
1021 + hidden_dentry = dtohd(dentry);
1022 + if(hidden_dentry &&
1023 + hidden_dentry->d_op &&
1024 + hidden_dentry->d_op->d_hash) {
1025 + err = hidden_dentry->d_op->d_hash(hidden_dentry, name);
1026 + goto out;
1027 + }
1028 + }
1029 +
1030 + printk(KERN_CRIT "mini_fo: d_hash: invalid state detected.\n");
1031 +
1032 + out:
1033 + return err;
1034 +}
1035 +
1036 +
1037 +STATIC int
1038 +mini_fo_d_compare(dentry_t *dentry, qstr_t *a, qstr_t *b)
1039 +{
1040 + int err;
1041 + dentry_t *hidden_dentry=NULL;
1042 +
1043 + /* hidden_dentry = mini_fo_hidden_dentry(dentry); */
1044 + if(dtohd2(dentry))
1045 + hidden_dentry = dtohd2(dentry);
1046 + else if(dtohd(dentry))
1047 + hidden_dentry = dtohd(dentry);
1048 +
1049 + if (hidden_dentry && hidden_dentry->d_op && hidden_dentry->d_op->d_compare) {
1050 + err = hidden_dentry->d_op->d_compare(hidden_dentry, a, b);
1051 + } else {
1052 + err = ((a->len != b->len) || memcmp(a->name, b->name, b->len));
1053 + }
1054 +
1055 + return err;
1056 +}
1057 +
1058 +
1059 +int
1060 +mini_fo_d_delete(dentry_t *dentry)
1061 +{
1062 + dentry_t *hidden_dentry;
1063 + dentry_t *hidden_sto_dentry;
1064 + int err = 0;
1065 +
1066 + /* this could be a negative dentry, so check first */
1067 + if (!dtopd(dentry)) {
1068 + printk(KERN_CRIT "mini_fo_d_delete: negative dentry passed.\n");
1069 + goto out;
1070 + }
1071 + hidden_dentry = dtohd(dentry);
1072 + hidden_sto_dentry = dtohd2(dentry);
1073 +
1074 + if(hidden_dentry) {
1075 + if(hidden_dentry->d_op &&
1076 + hidden_dentry->d_op->d_delete) {
1077 + err = hidden_dentry->d_op->d_delete(hidden_dentry);
1078 + }
1079 + }
1080 + if(hidden_sto_dentry) {
1081 + if(hidden_sto_dentry->d_op &&
1082 + hidden_sto_dentry->d_op->d_delete) {
1083 + err = hidden_sto_dentry->d_op->d_delete(hidden_sto_dentry);
1084 + }
1085 + }
1086 +
1087 + out:
1088 + return err;
1089 +}
1090 +
1091 +
1092 +void
1093 +mini_fo_d_release(dentry_t *dentry)
1094 +{
1095 + dentry_t *hidden_dentry;
1096 + dentry_t *hidden_sto_dentry;
1097 +
1098 +
1099 + /* this could be a negative dentry, so check first */
1100 + if (!dtopd(dentry)) {
1101 + printk(KERN_CRIT "mini_fo_d_release: no private data.\n");
1102 + goto out;
1103 + }
1104 + hidden_dentry = dtohd(dentry);
1105 + hidden_sto_dentry = dtohd2(dentry);
1106 +
1107 + if(hidden_dentry) {
1108 + /* decrement hidden dentry's counter and free its inode */
1109 + dput(hidden_dentry);
1110 + }
1111 + if(hidden_sto_dentry) {
1112 + /* decrement hidden dentry's counter and free its inode */
1113 + dput(hidden_sto_dentry);
1114 + }
1115 +
1116 + /* free private data (mini_fo_dentry_info) here */
1117 + kfree(dtopd(dentry));
1118 + __dtopd(dentry) = NULL; /* just to be safe */
1119 + out:
1120 + return;
1121 +}
1122 +
1123 +
1124 +/*
1125 + * we don't really need mini_fo_d_iput, because dentry_iput will call iput() if
1126 + * mini_fo_d_iput is not defined. We left this implemented for ease of
1127 + * tracing/debugging.
1128 + */
1129 +void
1130 +mini_fo_d_iput(dentry_t *dentry, inode_t *inode)
1131 +{
1132 + iput(inode);
1133 +}
1134 +
1135 +
1136 +struct dentry_operations mini_fo_dops = {
1137 + d_revalidate: mini_fo_d_revalidate,
1138 + d_hash: mini_fo_d_hash,
1139 + d_compare: mini_fo_d_compare,
1140 + d_release: mini_fo_d_release,
1141 + d_delete: mini_fo_d_delete,
1142 + d_iput: mini_fo_d_iput,
1143 +};
1144 Index: linux-2.6.23/fs/mini_fo/file.c
1145 ===================================================================
1146 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
1147 +++ linux-2.6.23/fs/mini_fo/file.c 2007-10-10 13:53:23.000000000 +0800
1148 @@ -0,0 +1,713 @@
1149 +/*
1150 + * Copyright (c) 1997-2003 Erez Zadok
1151 + * Copyright (c) 2001-2003 Stony Brook University
1152 + *
1153 + * For specific licensing information, see the COPYING file distributed with
1154 + * this package, or get one from ftp://ftp.filesystems.org/pub/fist/COPYING.
1155 + *
1156 + * This Copyright notice must be kept intact and distributed with all
1157 + * fistgen sources INCLUDING sources generated by fistgen.
1158 + */
1159 +/*
1160 + * Copyright (C) 2004, 2005 Markus Klotzbuecher <mk@creamnet.de>
1161 + *
1162 + * This program is free software; you can redistribute it and/or
1163 + * modify it under the terms of the GNU General Public License
1164 + * as published by the Free Software Foundation; either version
1165 + * 2 of the License, or (at your option) any later version.
1166 + */
1167 +
1168 +/*
1169 + * $Id$
1170 + */
1171 +
1172 +#ifdef HAVE_CONFIG_H
1173 +# include <config.h>
1174 +#endif
1175 +
1176 +#include "fist.h"
1177 +#include "mini_fo.h"
1178 +#define ROUND_UP(x) (((x)+sizeof(long)-1) & ~(sizeof(long)-1))
1179 +
1180 +/*******************
1181 + * File Operations *
1182 + *******************/
1183 +
1184 +STATIC loff_t
1185 +mini_fo_llseek(file_t *file, loff_t offset, int origin)
1186 +{
1187 + loff_t err;
1188 + file_t *hidden_file = NULL;
1189 +
1190 + if(S_ISDIR(file->f_dentry->d_inode->i_mode)) {
1191 + /* Check if trying to llseek from a directory */
1192 + err = -EISDIR;
1193 + goto out;
1194 + }
1195 + if (ftopd(file) != NULL) {
1196 + if(ftohf2(file)) {
1197 + hidden_file = ftohf2(file);
1198 + } else {
1199 + hidden_file = ftohf(file);
1200 + }
1201 + }
1202 +
1203 + /* always set hidden position to this one */
1204 + hidden_file->f_pos = file->f_pos;
1205 +
1206 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
1207 + memcpy(&(hidden_file->f_ra),
1208 + &(file->f_ra),
1209 + sizeof(struct file_ra_state));
1210 +#else
1211 + if (file->f_reada) { /* update readahead information if needed */
1212 + hidden_file->f_reada = file->f_reada;
1213 + hidden_file->f_ramax = file->f_ramax;
1214 + hidden_file->f_raend = file->f_raend;
1215 + hidden_file->f_ralen = file->f_ralen;
1216 + hidden_file->f_rawin = file->f_rawin;
1217 + }
1218 +#endif
1219 + if (hidden_file->f_op && hidden_file->f_op->llseek)
1220 + err = hidden_file->f_op->llseek(hidden_file, offset, origin);
1221 + else
1222 + err = generic_file_llseek(hidden_file, offset, origin);
1223 +
1224 + if (err < 0)
1225 + goto out;
1226 +
1227 + if (err != file->f_pos) {
1228 + file->f_pos = err;
1229 + // ION maybe this?
1230 + // file->f_pos = hidden_file->f_pos;
1231 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
1232 + file->f_reada = 0;
1233 +#endif
1234 + file->f_version++;
1235 + }
1236 +
1237 + out:
1238 + return err;
1239 +}
1240 +
1241 +
1242 +/* mk: fanout capable */
1243 +STATIC ssize_t
1244 +mini_fo_read(file_t *file, char *buf, size_t count, loff_t *ppos)
1245 +{
1246 + int err = -EINVAL;
1247 + file_t *hidden_file = NULL;
1248 + loff_t pos = *ppos;
1249 +
1250 + if(S_ISDIR(file->f_dentry->d_inode->i_mode)) {
1251 + /* Check if trying to read from a directory */
1252 + /* printk(KERN_CRIT "mini_fo_read: ERROR: trying to read data from a directory.\n"); */
1253 + err = -EISDIR;
1254 + goto out;
1255 + }
1256 +
1257 + if (ftopd(file) != NULL) {
1258 + if(ftohf2(file)) {
1259 + hidden_file = ftohf2(file);
1260 + } else {
1261 + hidden_file = ftohf(file);
1262 + }
1263 + }
1264 +
1265 + if (!hidden_file->f_op || !hidden_file->f_op->read)
1266 + goto out;
1267 +
1268 + err = hidden_file->f_op->read(hidden_file, buf, count, &pos);
1269 + *ppos = pos;
1270 +
1271 + if (err >= 0) {
1272 + /* atime should also be updated for reads of size zero or more */
1273 + fist_copy_attr_atime(file->f_dentry->d_inode,
1274 + hidden_file->f_dentry->d_inode);
1275 + }
1276 +
1277 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
1278 + /*
1279 + * MAJOR HACK
1280 + * because pread() does not have any way to tell us that it is
1281 + * our caller, then we don't know for sure if we have to update
1282 + * the file positions. This hack relies on read() having passed us
1283 + * the "real" pointer of its struct file's f_pos field.
1284 + */
1285 + if (ppos == &file->f_pos)
1286 + hidden_file->f_pos = *ppos = pos;
1287 + if (hidden_file->f_reada) { /* update readahead information if needed */
1288 + file->f_reada = hidden_file->f_reada;
1289 + file->f_ramax = hidden_file->f_ramax;
1290 + file->f_raend = hidden_file->f_raend;
1291 + file->f_ralen = hidden_file->f_ralen;
1292 + file->f_rawin = hidden_file->f_rawin;
1293 + }
1294 +#else
1295 + memcpy(&(file->f_ra),&(hidden_file->f_ra),sizeof(struct file_ra_state));
1296 +#endif
1297 +
1298 + out:
1299 + return err;
1300 +}
1301 +
1302 +
1303 +/* this mini_fo_write() does not modify data pages! */
1304 +STATIC ssize_t
1305 +mini_fo_write(file_t *file, const char *buf, size_t count, loff_t *ppos)
1306 +{
1307 + int err = -EINVAL;
1308 + file_t *hidden_file = NULL;
1309 + inode_t *inode;
1310 + inode_t *hidden_inode;
1311 + loff_t pos = *ppos;
1312 +
1313 + /* mk: fan out: */
1314 + if (ftopd(file) != NULL) {
1315 + if(ftohf2(file)) {
1316 + hidden_file = ftohf2(file);
1317 + } else {
1318 + /* This is bad! We have no storage file to write to. This
1319 + * should never happen because if a file is opened for
1320 + * writing, a copy should have been made earlier.
1321 + */
1322 + printk(KERN_CRIT "mini_fo: write : ERROR, no storage file to write.\n");
1323 + err = -EINVAL;
1324 + goto out;
1325 + }
1326 + }
1327 +
1328 + inode = file->f_dentry->d_inode;
1329 + hidden_inode = itohi2(inode);
1330 + if(!hidden_inode) {
1331 + printk(KERN_CRIT "mini_fo: write: no sto inode found, not good.\n");
1332 + goto out;
1333 + }
1334 +
1335 + if (!hidden_file->f_op || !hidden_file->f_op->write)
1336 + goto out;
1337 +
1338 + /* adjust for append -- seek to the end of the file */
1339 + if (file->f_flags & O_APPEND)
1340 + pos = inode->i_size;
1341 +
1342 + err = hidden_file->f_op->write(hidden_file, buf, count, &pos);
1343 +
1344 + /*
1345 + * copy ctime and mtime from lower layer attributes
1346 + * atime is unchanged for both layers
1347 + */
1348 + if (err >= 0)
1349 + fist_copy_attr_times(inode, hidden_inode);
1350 +
1351 + *ppos = pos;
1352 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
1353 + /*
1354 + * XXX: MAJOR HACK
1355 + *
1356 + * because pwrite() does not have any way to tell us that it is
1357 + * our caller, then we don't know for sure if we have to update
1358 + * the file positions. This hack relies on write() having passed us
1359 + * the "real" pointer of its struct file's f_pos field.
1360 + */
1361 + if (ppos == &file->f_pos)
1362 + hidden_file->f_pos = *ppos = pos;
1363 +#endif
1364 + /* update this inode's size */
1365 + if (pos > inode->i_size)
1366 + inode->i_size = pos;
1367 +
1368 + out:
1369 + return err;
1370 +}
1371 +
1372 +/* Global variable to hold a file_t pointer.
1373 + * This serves to allow mini_fo_filldir function to know which file is
1374 + * beeing read, which is required for two reasons:
1375 + *
1376 + * - be able to call wol functions in order to avoid listing deleted
1377 + * base files.
1378 + * - if we're reading a directory which is in state 1, we need to
1379 + * maintain a list (in mini_fo_filldir) of which files allready
1380 + * have been copied to userspace,to detect files existing in base
1381 + * and storage and not list them twice.
1382 + */
1383 +filldir_t mini_fo_filldir_orig;
1384 +file_t *mini_fo_filldir_file;
1385 +
1386 +/* mainly copied from fs/readdir.c */
1387 +STATIC int
1388 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,18)
1389 +mini_fo_filldir(void * __buf, const char * name, int namlen, loff_t offset,
1390 + u64 ino, unsigned int d_type)
1391 +#else
1392 +mini_fo_filldir(void * __buf, const char * name, int namlen, loff_t offset,
1393 + ino_t ino, unsigned int d_type)
1394 +#endif
1395 +{
1396 + struct getdents_callback * buf = (struct getdents_callback *) __buf;
1397 + file_t* file = mini_fo_filldir_file;
1398 +
1399 + /* In theses states we filter meta files in storage (WOL) */
1400 + if(file && (dtopd(file->f_dentry)->state == MODIFIED ||
1401 + dtopd(file->f_dentry)->state == CREATED ||
1402 + dtopd(file->f_dentry)->state == DEL_REWRITTEN)) {
1403 +
1404 + int tmp = strlen(META_FILENAME);
1405 + if(tmp == namlen) {
1406 + if(!strncmp(name, META_FILENAME, namlen))
1407 + return 0;
1408 + }
1409 + }
1410 +
1411 + /* check if we are merging the contents of storage and base */
1412 + if(file && dtopd(file->f_dentry)->state == MODIFIED) {
1413 + /* check if we are still reading storage contents, if
1414 + * yes, we just save the name of the file for duplicate
1415 + * checking later. */
1416 +
1417 + if(!ftopd(file)->rd.sto_done) {
1418 + /* put file into ndl list */
1419 + if(ndl_add_entry(&ftopd(file)->rd, name, namlen))
1420 + printk(KERN_CRIT "mini_fo_filldir: Error adding to ndl.\n");
1421 + } else {
1422 + /* check if file has been deleted */
1423 + if(meta_check_d_entry(file->f_dentry, name, namlen))
1424 + return 0;
1425 +
1426 + /* do duplicate checking */
1427 + if(ndl_check_entry(&ftopd(file)->rd, name, namlen))
1428 + return 0;
1429 + }
1430 + }
1431 +
1432 + return mini_fo_filldir_orig(buf, name, namlen, offset, ino, d_type);
1433 +}
1434 +
1435 +
1436 +STATIC int
1437 +mini_fo_readdir(file_t *file, void *dirent, filldir_t filldir)
1438 +{
1439 + int err = 0;/* mk: ??? -ENOTDIR; */
1440 + file_t *hidden_file = NULL;
1441 + file_t *hidden_sto_file = NULL;
1442 + inode_t *inode;
1443 + struct getdents_callback *buf;
1444 + int oldcount;
1445 +
1446 +#if defined(FIST_FILTER_NAME) || defined(FIST_FILTER_SCA)
1447 + struct mini_fo_getdents_callback buf;
1448 +#endif /* FIST_FILTER_NAME || FIST_FILTER_SCA */
1449 +
1450 + buf = (struct getdents_callback *) dirent;
1451 + oldcount = buf->count;
1452 + inode = file->f_dentry->d_inode;
1453 + mini_fo_filldir_file = file;
1454 + mini_fo_filldir_orig = filldir;
1455 +
1456 + ftopd(file)->rd.sto_done = 0;
1457 + do {
1458 + if (ftopd(file) != NULL) {
1459 + if(ftohf2(file)) {
1460 + hidden_sto_file = ftohf2(file);
1461 + err = vfs_readdir(hidden_sto_file, mini_fo_filldir, dirent);
1462 + file->f_pos = hidden_sto_file->f_pos;
1463 + if (err > 0)
1464 + fist_copy_attr_atime(inode, hidden_sto_file->f_dentry->d_inode);
1465 + /* not finshed yet, we'll be called again */
1466 + if (buf->count != oldcount)
1467 + break;
1468 + }
1469 +
1470 + ftopd(file)->rd.sto_done = 1;
1471 +
1472 + if(ftohf(file)) {
1473 + hidden_file = ftohf(file);
1474 + err = vfs_readdir(hidden_file, mini_fo_filldir, dirent);
1475 + file->f_pos = hidden_file->f_pos;
1476 + if (err > 0)
1477 + fist_copy_attr_atime(inode, hidden_file->f_dentry->d_inode);
1478 + }
1479 +
1480 + }
1481 + } while (0);
1482 +
1483 + /* mk:
1484 + * we need to check if all the directory data has been copied to userspace,
1485 + * or if we will be called again by userspace to complete the operation.
1486 + */
1487 + if(buf->count == oldcount) {
1488 + ndl_put_list(&ftopd(file)->rd);
1489 + }
1490 +
1491 + /* unset this, safe */
1492 + mini_fo_filldir_file = NULL;
1493 + return err;
1494 +}
1495 +
1496 +
1497 +STATIC unsigned int
1498 +mini_fo_poll(file_t *file, poll_table *wait)
1499 +{
1500 + unsigned int mask = DEFAULT_POLLMASK;
1501 + file_t *hidden_file = NULL;
1502 +
1503 + if (ftopd(file) != NULL) {
1504 + if(ftohf2(file)) {
1505 + hidden_file = ftohf2(file);
1506 + } else {
1507 + hidden_file = ftohf(file);
1508 + }
1509 + }
1510 +
1511 + if (!hidden_file->f_op || !hidden_file->f_op->poll)
1512 + goto out;
1513 +
1514 + mask = hidden_file->f_op->poll(hidden_file, wait);
1515 +
1516 + out:
1517 + return mask;
1518 +}
1519 +
1520 +/* FIST-LITE special version of mmap */
1521 +STATIC int
1522 +mini_fo_mmap(file_t *file, vm_area_t *vma)
1523 +{
1524 + int err = 0;
1525 + file_t *hidden_file = NULL;
1526 +
1527 + /* fanout capability */
1528 + if (ftopd(file) != NULL) {
1529 + if(ftohf2(file)) {
1530 + hidden_file = ftohf2(file);
1531 + } else {
1532 + hidden_file = ftohf(file);
1533 + }
1534 + }
1535 +
1536 + ASSERT(hidden_file != NULL);
1537 + ASSERT(hidden_file->f_op != NULL);
1538 + ASSERT(hidden_file->f_op->mmap != NULL);
1539 +
1540 + vma->vm_file = hidden_file;
1541 + err = hidden_file->f_op->mmap(hidden_file, vma);
1542 + get_file(hidden_file); /* make sure it doesn't get freed on us */
1543 + fput(file); /* no need to keep extra ref on ours */
1544 +
1545 + return err;
1546 +}
1547 +
1548 +
1549 +
1550 +STATIC int
1551 +mini_fo_open(inode_t *inode, file_t *file)
1552 +{
1553 + int err = 0;
1554 + int hidden_flags;
1555 + file_t *hidden_file = NULL;
1556 + dentry_t *hidden_dentry = NULL;
1557 +
1558 + /* fanout stuff */
1559 + file_t *hidden_sto_file = NULL;
1560 + dentry_t *hidden_sto_dentry = NULL;
1561 +
1562 + __ftopd(file) =
1563 + kmalloc(sizeof(struct mini_fo_file_info), GFP_KERNEL);
1564 + if (!ftopd(file)) {
1565 + err = -ENOMEM;
1566 + goto out;
1567 + }
1568 +
1569 + /* init the readdir_helper structure */
1570 + INIT_LIST_HEAD(&ftopd(file)->rd.ndl_list);
1571 + ftopd(file)->rd.ndl_size = 0;
1572 +
1573 + /* In certain paths this could stay uninitalized and cause trouble */
1574 + ftohf(file) = NULL;
1575 + ftohf2(file) = NULL;
1576 + hidden_flags = file->f_flags;
1577 +
1578 + /* create storage files? */
1579 + if(dtost(file->f_dentry) == UNMODIFIED) {
1580 + if(!IS_WRITE_FLAG(file->f_flags)) {
1581 + hidden_dentry = dtohd(file->f_dentry);
1582 + dget(hidden_dentry);
1583 + /* dentry_open will decrement mnt refcnt if err.
1584 + * otherwise fput() will do an mntput() for us upon file close. */
1585 + mntget(stopd(inode->i_sb)->hidden_mnt);
1586 + hidden_file = dentry_open(hidden_dentry,
1587 + stopd(inode->i_sb)->hidden_mnt,
1588 + hidden_flags);
1589 + if (IS_ERR(hidden_file)) {
1590 + err = PTR_ERR(hidden_file);
1591 + dput(hidden_dentry);
1592 + goto out;
1593 + }
1594 + ftohf(file) = hidden_file; /* link two files */
1595 + goto out;
1596 + }
1597 + else {
1598 + if(S_ISDIR(file->f_dentry->d_inode->i_mode)) {
1599 + err = dir_unmod_to_mod(file->f_dentry);
1600 + } else
1601 + err = nondir_unmod_to_mod(file->f_dentry, 1);
1602 +
1603 + if (err) {
1604 + printk("mini_fo_open: ERROR creating storage file.\n");
1605 + goto out;
1606 + }
1607 + }
1608 + }
1609 + hidden_sto_dentry = dtohd2(file->f_dentry);
1610 + dget(hidden_sto_dentry);
1611 +
1612 + if(dtopd(file->f_dentry)->state == MODIFIED) {
1613 + /* Directorys are special, interpose on both lower level files */
1614 + if(S_ISDIR(itohi(inode)->i_mode)) {
1615 + /* check for invalid file types of lower level files */
1616 + if(!(S_ISDIR(itohi(inode)->i_mode) && S_ISDIR(itohi2(inode)->i_mode))) {
1617 + printk(KERN_CRIT "mini_fo_open: meta data corruption detected.\n");
1618 + dput(hidden_sto_dentry);
1619 + err = -EINVAL;
1620 + goto out;
1621 + }
1622 +
1623 + /* lower level directorys are ok, open the base file */
1624 + hidden_dentry = dtohd(file->f_dentry);
1625 + dget(hidden_dentry);
1626 +
1627 + mntget(stopd(inode->i_sb)->hidden_mnt);
1628 + hidden_file = dentry_open(hidden_dentry,
1629 + stopd(inode->i_sb)->hidden_mnt,
1630 + hidden_flags);
1631 + if (IS_ERR(hidden_file)) {
1632 + err = PTR_ERR(hidden_file);
1633 + dput(hidden_dentry);
1634 + dput(hidden_sto_dentry);
1635 + goto out;
1636 + }
1637 + ftohf(file) = hidden_file; /* link the two files */
1638 + }
1639 + }
1640 +
1641 + if(!exists_in_storage(file->f_dentry)) {
1642 + printk(KERN_CRIT "mini_fo_open: invalid file state detected.\n");
1643 + err = -EINVAL;
1644 + dput(hidden_sto_dentry);
1645 +
1646 + /* If the base file has been opened, we need to close it here */
1647 + if(ftohf(file)) {
1648 + if (hidden_file->f_op && hidden_file->f_op->flush)
1649 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,18)
1650 + hidden_file->f_op->flush(hidden_file, NULL);
1651 +#else
1652 + hidden_file->f_op->flush(hidden_file);
1653 +#endif
1654 + dput(hidden_dentry);
1655 + }
1656 + goto out;
1657 + }
1658 +
1659 + /* ok, now we can safely open the storage file */
1660 + mntget(stopd(inode->i_sb)->hidden_mnt2);
1661 + hidden_sto_file = dentry_open(hidden_sto_dentry,
1662 + stopd(inode->i_sb)->hidden_mnt2,
1663 + hidden_flags);
1664 +
1665 + /* dentry_open dputs the dentry if it fails */
1666 + if (IS_ERR(hidden_sto_file)) {
1667 + err = PTR_ERR(hidden_sto_file);
1668 + /* close base file if open */
1669 + if(ftohf(file)) {
1670 + if (hidden_file->f_op && hidden_file->f_op->flush)
1671 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,18)
1672 + hidden_file->f_op->flush(hidden_file, NULL);
1673 +#else
1674 + hidden_file->f_op->flush(hidden_file);
1675 +#endif
1676 + dput(hidden_dentry);
1677 + }
1678 + goto out;
1679 + }
1680 + ftohf2(file) = hidden_sto_file; /* link storage file */
1681 +
1682 + out:
1683 + if (err < 0 && ftopd(file)) {
1684 + kfree(ftopd(file));
1685 + }
1686 + return err;
1687 +}
1688 +
1689 +STATIC int
1690 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,18)
1691 +mini_fo_flush(file_t *file, fl_owner_t id)
1692 +#else
1693 +mini_fo_flush(file_t *file)
1694 +#endif
1695 +{
1696 + int err1 = 0; /* assume ok (see open.c:close_fp) */
1697 + int err2 = 0;
1698 + file_t *hidden_file = NULL;
1699 +
1700 + check_mini_fo_file(file);
1701 +
1702 + /* mk: we don't do any state checking here, as its not worth the time.
1703 + * Just flush the lower level files if they exist.
1704 + */
1705 + if(ftopd(file) != NULL) {
1706 + if(ftohf(file) != NULL) {
1707 + hidden_file = ftohf(file);
1708 + if (hidden_file->f_op && hidden_file->f_op->flush)
1709 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,18)
1710 + err1 = hidden_file->f_op->flush(hidden_file, id);
1711 +#else
1712 + err1 = hidden_file->f_op->flush(hidden_file);
1713 +#endif
1714 + }
1715 + if(ftohf2(file) != NULL) {
1716 + hidden_file = ftohf2(file);
1717 + if (hidden_file->f_op && hidden_file->f_op->flush)
1718 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,18)
1719 + err2 = hidden_file->f_op->flush(hidden_file, id);
1720 +#else
1721 + err2 = hidden_file->f_op->flush(hidden_file);
1722 +#endif
1723 + }
1724 + }
1725 + return (err1 | err2);
1726 +}
1727 +
1728 +
1729 +STATIC int
1730 +mini_fo_release(inode_t *inode, file_t *file)
1731 +{
1732 + int err = 0;
1733 + file_t *hidden_file = NULL;
1734 +
1735 + if (ftopd(file) != NULL) {
1736 + if(ftohf(file)) {
1737 + hidden_file = ftohf(file);
1738 + fput(hidden_file);
1739 + }
1740 + if(ftohf2(file)) {
1741 + hidden_file = ftohf2(file);
1742 + fput(hidden_file);
1743 + }
1744 + kfree(ftopd(file));
1745 + }
1746 + return err;
1747 +}
1748 +
1749 +STATIC int
1750 +mini_fo_fsync(file_t *file, dentry_t *dentry, int datasync)
1751 +{
1752 + int err1 = 0;
1753 + int err2 = 0;
1754 + file_t *hidden_file = NULL;
1755 + dentry_t *hidden_dentry;
1756 +
1757 + check_mini_fo_file(file);
1758 +
1759 + if ((hidden_file = ftohf(file)) != NULL) {
1760 + hidden_dentry = dtohd(dentry);
1761 + if (hidden_file->f_op && hidden_file->f_op->fsync) {
1762 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
1763 + mutex_lock(&hidden_dentry->d_inode->i_mutex);
1764 +#else
1765 + down(&hidden_dentry->d_inode->i_sem);
1766 +#endif
1767 + err1 = hidden_file->f_op->fsync(hidden_file, hidden_dentry, datasync);
1768 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
1769 + mutex_unlock(&hidden_dentry->d_inode->i_mutex);
1770 +#else
1771 + up(&hidden_dentry->d_inode->i_sem);
1772 +#endif
1773 + }
1774 + }
1775 +
1776 + if ((hidden_file = ftohf2(file)) != NULL) {
1777 + hidden_dentry = dtohd2(dentry);
1778 + if (hidden_file->f_op && hidden_file->f_op->fsync) {
1779 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
1780 + mutex_lock(&hidden_dentry->d_inode->i_mutex);
1781 +#else
1782 + down(&hidden_dentry->d_inode->i_sem);
1783 +#endif
1784 + err2 = hidden_file->f_op->fsync(hidden_file, hidden_dentry, datasync);
1785 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
1786 + mutex_unlock(&hidden_dentry->d_inode->i_mutex);
1787 +#else
1788 + up(&hidden_dentry->d_inode->i_sem);
1789 +#endif
1790 + }
1791 + }
1792 + else
1793 + goto err;
1794 +
1795 +err:
1796 + return (err1 || err2);
1797 +}
1798 +
1799 +
1800 +STATIC int
1801 +mini_fo_fasync(int fd, file_t *file, int flag)
1802 +{
1803 + int err1 = 0;
1804 + int err2 = 0;
1805 +
1806 + file_t *hidden_file = NULL;
1807 +
1808 + check_mini_fo_file(file);
1809 +
1810 + if((hidden_file = ftohf(file)) != NULL) {
1811 + err1 = hidden_file->f_op->fasync(fd, hidden_file, flag);
1812 + }
1813 + if((hidden_file = ftohf2(file)) != NULL) {
1814 + err2 = hidden_file->f_op->fasync(fd, hidden_file, flag);
1815 + }
1816 +
1817 + return (err1 || err2);
1818 +}
1819 +
1820 +
1821 +
1822 +struct file_operations mini_fo_dir_fops =
1823 + {
1824 + read: generic_read_dir,
1825 + write: mini_fo_write,
1826 + readdir: mini_fo_readdir,
1827 + poll: mini_fo_poll,
1828 + /* ioctl: mini_fo_ioctl, */
1829 + mmap: mini_fo_mmap,
1830 + open: mini_fo_open,
1831 + flush: mini_fo_flush,
1832 + release: mini_fo_release,
1833 + fsync: mini_fo_fsync,
1834 + fasync: mini_fo_fasync,
1835 + /* not needed lock: mini_fo_lock, */
1836 + /* not needed: readv */
1837 + /* not needed: writev */
1838 + /* not implemented: sendpage */
1839 + /* not implemented: get_unmapped_area */
1840 + };
1841 +
1842 +struct file_operations mini_fo_main_fops =
1843 + {
1844 + llseek: mini_fo_llseek,
1845 + read: mini_fo_read,
1846 + write: mini_fo_write,
1847 + readdir: mini_fo_readdir,
1848 + poll: mini_fo_poll,
1849 + /* ioctl: mini_fo_ioctl, */
1850 + mmap: mini_fo_mmap,
1851 + open: mini_fo_open,
1852 + flush: mini_fo_flush,
1853 + release: mini_fo_release,
1854 + fsync: mini_fo_fsync,
1855 + fasync: mini_fo_fasync,
1856 + /* not needed: lock: mini_fo_lock, */
1857 + /* not needed: readv */
1858 + /* not needed: writev */
1859 + /* not implemented: sendpage */
1860 + /* not implemented: get_unmapped_area */
1861 + };
1862 Index: linux-2.6.23/fs/mini_fo/fist.h
1863 ===================================================================
1864 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
1865 +++ linux-2.6.23/fs/mini_fo/fist.h 2007-10-10 13:53:23.000000000 +0800
1866 @@ -0,0 +1,252 @@
1867 +/*
1868 + * Copyright (c) 1997-2003 Erez Zadok
1869 + * Copyright (c) 2001-2003 Stony Brook University
1870 + *
1871 + * For specific licensing information, see the COPYING file distributed with
1872 + * this package, or get one from ftp://ftp.filesystems.org/pub/fist/COPYING.
1873 + *
1874 + * This Copyright notice must be kept intact and distributed with all
1875 + * fistgen sources INCLUDING sources generated by fistgen.
1876 + */
1877 +/*
1878 + * Copyright (C) 2004, 2005 Markus Klotzbuecher <mk@creamnet.de>
1879 + *
1880 + * This program is free software; you can redistribute it and/or
1881 + * modify it under the terms of the GNU General Public License
1882 + * as published by the Free Software Foundation; either version
1883 + * 2 of the License, or (at your option) any later version.
1884 + */
1885 +
1886 +
1887 +/*
1888 + * $Id$
1889 + */
1890 +
1891 +#ifndef __FIST_H_
1892 +#define __FIST_H_
1893 +
1894 +/*
1895 + * KERNEL ONLY CODE:
1896 + */
1897 +#ifdef __KERNEL__
1898 +#include <linux/version.h>
1899 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,19)
1900 +#include <linux/autoconf.h>
1901 +#else
1902 +#include <linux/config.h>
1903 +#endif
1904 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
1905 +#ifdef CONFIG_MODVERSIONS
1906 +# define MODVERSIONS
1907 +# include <linux/modversions.h>
1908 +#endif /* CONFIG_MODVERSIONS */
1909 +#endif /* KERNEL_VERSION < 2.6.0 */
1910 +#include <linux/sched.h>
1911 +#include <linux/kernel.h>
1912 +#include <linux/mm.h>
1913 +#include <linux/string.h>
1914 +#include <linux/stat.h>
1915 +#include <linux/errno.h>
1916 +#include <linux/wait.h>
1917 +#include <linux/limits.h>
1918 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
1919 +#include <linux/locks.h>
1920 +#else
1921 +#include <linux/buffer_head.h>
1922 +#include <linux/pagemap.h>
1923 +#include <linux/namei.h>
1924 +#include <linux/module.h>
1925 +#include <linux/mount.h>
1926 +#include <linux/page-flags.h>
1927 +#include <linux/writeback.h>
1928 +#include <linux/statfs.h>
1929 +#endif
1930 +#include <linux/smp.h>
1931 +#include <linux/smp_lock.h>
1932 +#include <linux/file.h>
1933 +#include <linux/slab.h>
1934 +#include <linux/vmalloc.h>
1935 +#include <linux/poll.h>
1936 +#include <linux/list.h>
1937 +#include <linux/init.h>
1938 +
1939 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,20)
1940 +#include <linux/xattr.h>
1941 +#endif
1942 +
1943 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
1944 +#include <linux/security.h>
1945 +#endif
1946 +
1947 +#include <linux/swap.h>
1948 +
1949 +#include <asm/system.h>
1950 +/* #include <asm/segment.h> */
1951 +#include <asm/mman.h>
1952 +#include <linux/seq_file.h>
1953 +
1954 +/*
1955 + * MACROS:
1956 + */
1957 +
1958 +/* those mapped to ATTR_* were copied from linux/fs.h */
1959 +#define FA_MODE ATTR_MODE
1960 +#define FA_UID ATTR_UID
1961 +#define FA_GID ATTR_GID
1962 +#define FA_SIZE ATTR_SIZE
1963 +#define FA_ATIME ATTR_ATIME
1964 +#define FA_MTIME ATTR_MTIME
1965 +#define FA_CTIME ATTR_CTIME
1966 +#define FA_ATIME_SET ATTR_ATIME_SET
1967 +#define FA_MTIME_SET ATTR_MTIME_SET
1968 +#define FA_FORCE ATTR_FORCE
1969 +#define FA_ATTR_FLAGS ATTR_ATTR_FLAG
1970 +
1971 +/* must be greater than all other ATTR_* flags! */
1972 +#define FA_NLINK 2048
1973 +#define FA_BLKSIZE 4096
1974 +#define FA_BLOCKS 8192
1975 +#define FA_TIMES (FA_ATIME|FA_MTIME|FA_CTIME)
1976 +#define FA_ALL 0
1977 +
1978 +/* macros to manage changes between kernels */
1979 +#define INODE_DATA(i) (&(i)->i_data)
1980 +
1981 +#define MIN(x,y) ((x < y) ? (x) : (y))
1982 +#define MAX(x,y) ((x > y) ? (x) : (y))
1983 +#define MAXPATHLEN PATH_MAX
1984 +
1985 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,4,5)
1986 +# define lookup_one_len(a,b,c) lookup_one(a,b)
1987 +#endif /* LINUX_VERSION_CODE < KERNEL_VERSION(2,4,5) */
1988 +
1989 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,4,8)
1990 +# define generic_file_llseek default_llseek
1991 +#endif /* LINUX_VERSION_CODE < KERNEL_VERSION(2,4,8) */
1992 +
1993 +#ifndef SEEK_SET
1994 +# define SEEK_SET 0
1995 +#endif /* not SEEK_SET */
1996 +
1997 +#ifndef SEEK_CUR
1998 +# define SEEK_CUR 1
1999 +#endif /* not SEEK_CUR */
2000 +
2001 +#ifndef SEEK_END
2002 +# define SEEK_END 2
2003 +#endif /* not SEEK_END */
2004 +
2005 +#ifndef DEFAULT_POLLMASK
2006 +# define DEFAULT_POLLMASK (POLLIN | POLLOUT | POLLRDNORM | POLLWRNORM)
2007 +#endif /* not DEFAULT_POLLMASK */
2008 +
2009 +/* XXX: fix this so fistgen generates kfree() code directly */
2010 +#define kfree_s(a,b) kfree(a)
2011 +
2012 +/*
2013 + * TYPEDEFS:
2014 + */
2015 +typedef struct dentry dentry_t;
2016 +typedef struct file file_t;
2017 +typedef struct inode inode_t;
2018 +typedef inode_t vnode_t;
2019 +typedef struct page page_t;
2020 +typedef struct qstr qstr_t;
2021 +typedef struct super_block super_block_t;
2022 +typedef super_block_t vfs_t;
2023 +typedef struct vm_area_struct vm_area_t;
2024 +
2025 +
2026 +/*
2027 + * EXTERNALS:
2028 + */
2029 +
2030 +#define FPPF(str,page) printk("PPF %s 0x%x/%d: Lck:%d Err:%d Ref:%d Upd:%d Other::%d:%d:%d:%d:\n", \
2031 + str, \
2032 + (int) page, \
2033 + (int) page->index, \
2034 + (PageLocked(page) ? 1 : 0), \
2035 + (PageError(page) ? 1 : 0), \
2036 + (PageReferenced(page) ? 1 : 0), \
2037 + (Page_Uptodate(page) ? 1 : 0), \
2038 + (PageDecrAfter(page) ? 1 : 0), \
2039 + (PageSlab(page) ? 1 : 0), \
2040 + (PageSwapCache(page) ? 1 : 0), \
2041 + (PageReserved(page) ? 1 : 0) \
2042 + )
2043 +#define EZKDBG printk("EZK %s:%d:%s\n",__FILE__,__LINE__,__FUNCTION__)
2044 +#if 0
2045 +# define EZKDBG1 printk("EZK %s:%d\n",__FILE__,__LINE__)
2046 +#else
2047 +# define EZKDBG1
2048 +#endif
2049 +
2050 +extern int fist_get_debug_value(void);
2051 +extern int fist_set_debug_value(int val);
2052 +#if 0 /* mini_fo doesn't need these */
2053 +extern void fist_dprint_internal(int level, char *str,...);
2054 +extern void fist_print_dentry(char *str, const dentry_t *dentry);
2055 +extern void fist_print_inode(char *str, const inode_t *inode);
2056 +extern void fist_print_file(char *str, const file_t *file);
2057 +extern void fist_print_buffer_flags(char *str, struct buffer_head *buffer);
2058 +extern void fist_print_page_flags(char *str, page_t *page);
2059 +extern void fist_print_page_bytes(char *str, page_t *page);
2060 +extern void fist_print_pte_flags(char *str, const page_t *page);
2061 +extern void fist_checkinode(inode_t *inode, char *msg);
2062 +extern void fist_print_sb(char *str, const super_block_t *sb);
2063 +
2064 +/* ยง$% by mk: special debug functions */
2065 +extern void fist_mk_print_dentry(char *str, const dentry_t *dentry);
2066 +extern void fist_mk_print_inode(char *str, const inode_t *inode);
2067 +
2068 +extern char *add_indent(void);
2069 +extern char *del_indent(void);
2070 +#endif/* mini_fo doesn't need these */
2071 +
2072 +
2073 +#define STATIC
2074 +#define ASSERT(EX) \
2075 +do { \
2076 + if (!(EX)) { \
2077 + printk(KERN_CRIT "ASSERTION FAILED: %s at %s:%d (%s)\n", #EX, \
2078 + __FILE__, __LINE__, __FUNCTION__); \
2079 + (*((char *)0))=0; \
2080 + } \
2081 +} while (0)
2082 +/* same ASSERT, but tell me who was the caller of the function */
2083 +#define ASSERT2(EX) \
2084 +do { \
2085 + if (!(EX)) { \
2086 + printk(KERN_CRIT "ASSERTION FAILED (caller): %s at %s:%d (%s)\n", #EX, \
2087 + file, line, func); \
2088 + (*((char *)0))=0; \
2089 + } \
2090 +} while (0)
2091 +
2092 +#if 0 /* mini_fo doesn't need these */
2093 +#define dprintk(format, args...) printk(KERN_DEBUG format, ##args)
2094 +#define fist_dprint(level, str, args...) fist_dprint_internal(level, KERN_DEBUG str, ## args)
2095 +#define print_entry_location() fist_dprint(4, "%sIN: %s %s:%d\n", add_indent(), __FUNCTION__, __FILE__, __LINE__)
2096 +#define print_exit_location() fist_dprint(4, "%s OUT: %s %s:%d\n", del_indent(), __FUNCTION__, __FILE__, __LINE__)
2097 +#define print_exit_status(status) fist_dprint(4, "%s OUT: %s %s:%d, STATUS: %d\n", del_indent(), __FUNCTION__, __FILE__, __LINE__, status)
2098 +#define print_exit_pointer(status) \
2099 +do { \
2100 + if (IS_ERR(status)) \
2101 + fist_dprint(4, "%s OUT: %s %s:%d, RESULT: %ld\n", del_indent(), __FUNCTION__, __FILE__, __LINE__, PTR_ERR(status)); \
2102 + else \
2103 + fist_dprint(4, "%s OUT: %s %s:%d, RESULT: 0x%x\n", del_indent(), __FUNCTION__, __FILE__, __LINE__, PTR_ERR(status)); \
2104 +} while (0)
2105 +#endif/* mini_fo doesn't need these */
2106 +
2107 +#endif /* __KERNEL__ */
2108 +
2109 +
2110 +/*
2111 + * DEFINITIONS FOR USER AND KERNEL CODE:
2112 + * (Note: ioctl numbers 1--9 are reserved for fistgen, the rest
2113 + * are auto-generated automatically based on the user's .fist file.)
2114 + */
2115 +# define FIST_IOCTL_GET_DEBUG_VALUE _IOR(0x15, 1, int)
2116 +# define FIST_IOCTL_SET_DEBUG_VALUE _IOW(0x15, 2, int)
2117 +
2118 +#endif /* not __FIST_H_ */
2119 Index: linux-2.6.23/fs/mini_fo/inode.c
2120 ===================================================================
2121 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
2122 +++ linux-2.6.23/fs/mini_fo/inode.c 2007-10-10 13:53:23.000000000 +0800
2123 @@ -0,0 +1,1564 @@
2124 +/*
2125 + * Copyright (c) 1997-2003 Erez Zadok
2126 + * Copyright (c) 2001-2003 Stony Brook University
2127 + *
2128 + * For specific licensing information, see the COPYING file distributed with
2129 + * this package, or get one from ftp://ftp.filesystems.org/pub/fist/COPYING.
2130 + *
2131 + * This Copyright notice must be kept intact and distributed with all
2132 + * fistgen sources INCLUDING sources generated by fistgen.
2133 + */
2134 +/*
2135 + * Copyright (C) 2004, 2005 Markus Klotzbuecher <mk@creamnet.de>
2136 + *
2137 + * This program is free software; you can redistribute it and/or
2138 + * modify it under the terms of the GNU General Public License
2139 + * as published by the Free Software Foundation; either version
2140 + * 2 of the License, or (at your option) any later version.
2141 + */
2142 +
2143 +/*
2144 + * $Id$
2145 + */
2146 +
2147 +#ifdef HAVE_CONFIG_H
2148 +# include <config.h>
2149 +#endif
2150 +
2151 +#include "fist.h"
2152 +#include "mini_fo.h"
2153 +
2154 +STATIC int
2155 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
2156 +mini_fo_create(inode_t *dir, dentry_t *dentry, int mode, struct nameidata *nd)
2157 +#else
2158 +mini_fo_create(inode_t *dir, dentry_t *dentry, int mode)
2159 +#endif
2160 +{
2161 + int err = 0;
2162 +
2163 + check_mini_fo_dentry(dentry);
2164 +
2165 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
2166 + err = create_sto_reg_file(dentry, mode, nd);
2167 +#else
2168 + err = create_sto_reg_file(dentry, mode);
2169 +#endif
2170 + check_mini_fo_dentry(dentry);
2171 + return err;
2172 +}
2173 +
2174 +
2175 +STATIC dentry_t *
2176 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
2177 +mini_fo_lookup(inode_t *dir, dentry_t *dentry, struct nameidata* nd)
2178 +#else
2179 +mini_fo_lookup(inode_t *dir, dentry_t *dentry)
2180 +#endif
2181 +{
2182 + int err = 0;
2183 + dentry_t *hidden_dir_dentry;
2184 + dentry_t *hidden_dentry = NULL;
2185 +
2186 + dentry_t *hidden_sto_dir_dentry;
2187 + dentry_t *hidden_sto_dentry = NULL;
2188 +
2189 + /* whiteout flag */
2190 + int del_flag = 0;
2191 + char *bpath = NULL;
2192 +
2193 + const char *name;
2194 + unsigned int namelen;
2195 +
2196 + /* Don't allow lookups of META-files */
2197 + namelen = strlen(META_FILENAME);
2198 + if(namelen == dentry->d_name.len) {
2199 + if(!strncmp(dentry->d_name.name, META_FILENAME, namelen)) {
2200 + err = -ENOENT;
2201 + goto out;
2202 + }
2203 + }
2204 +
2205 + hidden_dir_dentry = dtohd(dentry->d_parent);
2206 + hidden_sto_dir_dentry = dtohd2(dentry->d_parent);
2207 +
2208 + name = dentry->d_name.name;
2209 + namelen = dentry->d_name.len;
2210 +
2211 + /* must initialize dentry operations */
2212 + dentry->d_op = &mini_fo_dops;
2213 +
2214 + /* setup the del_flag */
2215 + del_flag = __meta_check_d_entry(dir, name, namelen);
2216 + bpath = __meta_check_r_entry(dir, name, namelen);
2217 +
2218 + /* perform the lookups of base and storage files:
2219 + *
2220 + * This caused some serious trouble, as a lookup_one_len passing
2221 + * a negative dentry oopses. Solution is to only do the lookup
2222 + * if the dentry is positive, else we set it to NULL
2223 + * More trouble, who said a *_dir_dentry can't be NULL?
2224 + */
2225 + if(bpath) {
2226 + /* Cross-Interposing (C), yeah! */
2227 + hidden_dentry = bpath_walk(dir->i_sb, bpath);
2228 + if(!hidden_dentry || !hidden_dentry->d_inode) {
2229 + printk(KERN_CRIT "mini_fo_lookup: bpath_walk failed.\n");
2230 + err= -EINVAL;
2231 + goto out;
2232 + }
2233 +
2234 + /* this can be set up safely without fear of spaghetti
2235 + * interposing as it is only used for copying times */
2236 + hidden_dir_dentry = hidden_dentry->d_parent;
2237 + kfree(bpath);
2238 + }
2239 + else if(hidden_dir_dentry && hidden_dir_dentry->d_inode)
2240 + hidden_dentry =
2241 + lookup_one_len(name, hidden_dir_dentry, namelen);
2242 + else
2243 + hidden_dentry = NULL;
2244 +
2245 + if(hidden_sto_dir_dentry && hidden_sto_dir_dentry->d_inode)
2246 + hidden_sto_dentry =
2247 + lookup_one_len(name, hidden_sto_dir_dentry, namelen);
2248 + else
2249 + hidden_sto_dentry = NULL;
2250 +
2251 + /* catch error in lookup */
2252 + if (IS_ERR(hidden_dentry) || IS_ERR(hidden_sto_dentry)) {
2253 + /* mk: we need to call dput on the dentry, whose
2254 + * lookup_one_len operation failed, in order to avoid
2255 + * unmount trouble.
2256 + */
2257 + if(IS_ERR(hidden_dentry)) {
2258 + printk(KERN_CRIT "mini_fo_lookup: ERR from base dentry, lookup failed.\n");
2259 + err = PTR_ERR(hidden_dentry);
2260 + } else {
2261 + dput(hidden_dentry);
2262 + }
2263 + if(IS_ERR(hidden_sto_dentry)) {
2264 + printk(KERN_CRIT "mini_fo_lookup: ERR from storage dentry, lookup failed.\n");
2265 + err = PTR_ERR(hidden_sto_dentry);
2266 + } else {
2267 + dput(hidden_sto_dentry);
2268 + }
2269 + goto out;
2270 + }
2271 +
2272 + /* allocate dentry private data */
2273 + __dtopd(dentry) = (struct mini_fo_dentry_info *)
2274 + kmalloc(sizeof(struct mini_fo_dentry_info), GFP_KERNEL);
2275 +
2276 + if (!dtopd(dentry)) {
2277 + err = -ENOMEM;
2278 + goto out_dput;
2279 + }
2280 +
2281 + /* check for different states of the mini_fo file to be looked up. */
2282 +
2283 + /* state 1, file has been modified */
2284 + if(hidden_dentry && hidden_sto_dentry &&
2285 + hidden_dentry->d_inode && hidden_sto_dentry->d_inode && !del_flag) {
2286 +
2287 + /* update parent directory's atime */
2288 + fist_copy_attr_atime(dir, hidden_sto_dir_dentry->d_inode);
2289 +
2290 + dtopd(dentry)->state = MODIFIED;
2291 + dtohd(dentry) = hidden_dentry;
2292 + dtohd2(dentry) = hidden_sto_dentry;
2293 +
2294 + err = mini_fo_tri_interpose(hidden_dentry,
2295 + hidden_sto_dentry,
2296 + dentry, dir->i_sb, 1);
2297 + if (err) {
2298 + printk(KERN_CRIT "mini_fo_lookup: error interposing (state1).\n");
2299 + goto out_free;
2300 + }
2301 + goto out;
2302 + }
2303 + /* state 2, file is unmodified */
2304 + if(hidden_dentry && hidden_dentry->d_inode && !del_flag) {
2305 +
2306 + fist_copy_attr_atime(dir, hidden_dir_dentry->d_inode);
2307 +
2308 + dtopd(dentry)->state = UNMODIFIED;
2309 + dtohd(dentry) = hidden_dentry;
2310 + dtohd2(dentry) = hidden_sto_dentry; /* could be negative */
2311 +
2312 + err = mini_fo_tri_interpose(hidden_dentry,
2313 + hidden_sto_dentry,
2314 + dentry, dir->i_sb, 1);
2315 + if (err) {
2316 + printk(KERN_CRIT "mini_fo_lookup: error interposing (state2).\n");
2317 + goto out_free;
2318 + }
2319 + goto out;
2320 + }
2321 + /* state 3, file has been newly created */
2322 + if(hidden_sto_dentry && hidden_sto_dentry->d_inode && !del_flag) {
2323 +
2324 + fist_copy_attr_atime(dir, hidden_sto_dir_dentry->d_inode);
2325 + dtopd(dentry)->state = CREATED;
2326 + dtohd(dentry) = hidden_dentry; /* could be negative */
2327 + dtohd2(dentry) = hidden_sto_dentry;
2328 +
2329 + err = mini_fo_tri_interpose(hidden_dentry,
2330 + hidden_sto_dentry,
2331 + dentry, dir->i_sb, 1);
2332 + if (err) {
2333 + printk(KERN_CRIT "mini_fo_lookup: error interposing (state3).\n");
2334 + goto out_free;
2335 + }
2336 + goto out;
2337 + }
2338 +
2339 + /* state 4, file has deleted and created again. */
2340 + if(hidden_dentry && hidden_sto_dentry &&
2341 + hidden_dentry->d_inode &&
2342 + hidden_sto_dentry->d_inode && del_flag) {
2343 +
2344 + fist_copy_attr_atime(dir, hidden_sto_dir_dentry->d_inode);
2345 + dtopd(dentry)->state = DEL_REWRITTEN;
2346 + dtohd(dentry) = NULL;
2347 + dtohd2(dentry) = hidden_sto_dentry;
2348 +
2349 + err = mini_fo_tri_interpose(NULL,
2350 + hidden_sto_dentry,
2351 + dentry, dir->i_sb, 1);
2352 + if (err) {
2353 + printk(KERN_CRIT "mini_fo_lookup: error interposing (state4).\n");
2354 + goto out_free;
2355 + }
2356 + /* We will never need this dentry again, as the file has been
2357 + * deleted from base */
2358 + dput(hidden_dentry);
2359 + goto out;
2360 + }
2361 + /* state 5, file has been deleted in base */
2362 + if(hidden_dentry && hidden_sto_dentry &&
2363 + hidden_dentry->d_inode &&
2364 + !hidden_sto_dentry->d_inode && del_flag) {
2365 +
2366 + /* check which parents atime we need for updating */
2367 + if(hidden_sto_dir_dentry->d_inode)
2368 + fist_copy_attr_atime(dir,
2369 + hidden_sto_dir_dentry->d_inode);
2370 + else
2371 + fist_copy_attr_atime(dir,
2372 + hidden_dir_dentry->d_inode);
2373 +
2374 + dtopd(dentry)->state = DELETED;
2375 + dtohd(dentry) = NULL;
2376 + dtohd2(dentry) = hidden_sto_dentry;
2377 +
2378 + /* add negative dentry to dcache to speed up lookups */
2379 + d_add(dentry, NULL);
2380 + dput(hidden_dentry);
2381 + goto out;
2382 + }
2383 + /* state 6, file does not exist */
2384 + if(((hidden_dentry && !hidden_dentry->d_inode) ||
2385 + (hidden_sto_dentry && !hidden_sto_dentry->d_inode)) && !del_flag)
2386 + {
2387 + /* check which parents atime we need for updating */
2388 + if(hidden_sto_dir_dentry && hidden_sto_dir_dentry->d_inode)
2389 + fist_copy_attr_atime(dir, hidden_sto_dir_dentry->d_inode);
2390 + else
2391 + fist_copy_attr_atime(dir, hidden_dir_dentry->d_inode);
2392 +
2393 + dtopd(dentry)->state = NON_EXISTANT;
2394 + dtohd(dentry) = hidden_dentry;
2395 + dtohd2(dentry) = hidden_sto_dentry;
2396 + d_add(dentry, NULL);
2397 + goto out;
2398 + }
2399 +
2400 + /* if we get to here, were in an invalid state. bad. */
2401 + printk(KERN_CRIT "mini_fo_lookup: ERROR, meta data corruption detected.\n");
2402 +
2403 + /* end state checking */
2404 + out_free:
2405 + d_drop(dentry); /* so that our bad dentry will get destroyed */
2406 + kfree(dtopd(dentry));
2407 + __dtopd(dentry) = NULL; /* be safe */
2408 +
2409 + out_dput:
2410 + if(hidden_dentry)
2411 + dput(hidden_dentry);
2412 + if(hidden_sto_dentry)
2413 + dput(hidden_sto_dentry); /* drops usage count and marks for release */
2414 +
2415 + out:
2416 + /* initalize wol if file exists and is directory */
2417 + if(dentry->d_inode) {
2418 + if(S_ISDIR(dentry->d_inode->i_mode)) {
2419 + itopd(dentry->d_inode)->deleted_list_size = -1;
2420 + itopd(dentry->d_inode)->renamed_list_size = -1;
2421 + meta_build_lists(dentry);
2422 + }
2423 + }
2424 + return ERR_PTR(err);
2425 +}
2426 +
2427 +
2428 +STATIC int
2429 +mini_fo_link(dentry_t *old_dentry, inode_t *dir, dentry_t *new_dentry)
2430 +{
2431 + int err;
2432 + dentry_t *hidden_old_dentry;
2433 + dentry_t *hidden_new_dentry;
2434 + dentry_t *hidden_dir_dentry;
2435 +
2436 +
2437 + check_mini_fo_dentry(old_dentry);
2438 + check_mini_fo_dentry(new_dentry);
2439 + check_mini_fo_inode(dir);
2440 +
2441 + /* no links to directorys and existing targets target allowed */
2442 + if(S_ISDIR(old_dentry->d_inode->i_mode) ||
2443 + is_mini_fo_existant(new_dentry)) {
2444 + err = -EPERM;
2445 + goto out;
2446 + }
2447 +
2448 + /* bring it directly from unmod to del_rew */
2449 + if(dtost(old_dentry) == UNMODIFIED) {
2450 + err = nondir_unmod_to_mod(old_dentry, 1);
2451 + if(err) {
2452 + err = -EINVAL;
2453 + goto out;
2454 + }
2455 + err = meta_add_d_entry(old_dentry->d_parent,
2456 + old_dentry->d_name.name,
2457 + old_dentry->d_name.len);
2458 + if(err) {
2459 + err = -EINVAL;
2460 + goto out;
2461 + }
2462 + dput(dtohd(old_dentry));
2463 + dtohd(old_dentry) = NULL;
2464 + dtost(old_dentry) = DEL_REWRITTEN;
2465 + }
2466 +
2467 + err = get_neg_sto_dentry(new_dentry);
2468 + if(err) {
2469 + err = -EINVAL;
2470 + goto out;
2471 + }
2472 +
2473 + hidden_old_dentry = dtohd2(old_dentry);
2474 + hidden_new_dentry = dtohd2(new_dentry);
2475 +
2476 + dget(hidden_old_dentry);
2477 + dget(hidden_new_dentry);
2478 +
2479 + /* was: hidden_dir_dentry = lock_parent(hidden_new_dentry); */
2480 + hidden_dir_dentry = dget(hidden_new_dentry->d_parent);
2481 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
2482 + mutex_lock(&hidden_dir_dentry->d_inode->i_mutex);
2483 +#else
2484 + down(&hidden_dir_dentry->d_inode->i_sem);
2485 +#endif
2486 +
2487 + err = vfs_link(hidden_old_dentry,
2488 + hidden_dir_dentry->d_inode,
2489 + hidden_new_dentry);
2490 + if (err || !hidden_new_dentry->d_inode)
2491 + goto out_lock;
2492 +
2493 + dtost(new_dentry) = CREATED;
2494 + err = mini_fo_tri_interpose(NULL, hidden_new_dentry, new_dentry, dir->i_sb, 0);
2495 + if (err)
2496 + goto out_lock;
2497 +
2498 + fist_copy_attr_timesizes(dir, hidden_new_dentry->d_inode);
2499 + /* propagate number of hard-links */
2500 + old_dentry->d_inode->i_nlink = itohi2(old_dentry->d_inode)->i_nlink;
2501 +
2502 + out_lock:
2503 + /* was: unlock_dir(hidden_dir_dentry); */
2504 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
2505 + mutex_unlock(&hidden_dir_dentry->d_inode->i_mutex);
2506 +#else
2507 + up(&hidden_dir_dentry->d_inode->i_sem);
2508 +#endif
2509 + dput(hidden_dir_dentry);
2510 +
2511 + dput(hidden_new_dentry);
2512 + dput(hidden_old_dentry);
2513 + if (!new_dentry->d_inode)
2514 + d_drop(new_dentry);
2515 +
2516 + out:
2517 + return err;
2518 +}
2519 +
2520 +
2521 +STATIC int
2522 +mini_fo_unlink(inode_t *dir, dentry_t *dentry)
2523 +{
2524 + int err = 0;
2525 +
2526 + dget(dentry);
2527 + if(dtopd(dentry)->state == MODIFIED) {
2528 + err = nondir_mod_to_del(dentry);
2529 + goto out;
2530 + }
2531 + else if(dtopd(dentry)->state == UNMODIFIED) {
2532 + err = nondir_unmod_to_del(dentry);
2533 + goto out;
2534 + }
2535 + else if(dtopd(dentry)->state == CREATED) {
2536 + err = nondir_creat_to_del(dentry);
2537 + goto out;
2538 + }
2539 + else if(dtopd(dentry)->state == DEL_REWRITTEN) {
2540 + err = nondir_del_rew_to_del(dentry);
2541 + goto out;
2542 + }
2543 +
2544 + printk(KERN_CRIT "mini_fo_unlink: ERROR, invalid state detected.\n");
2545 +
2546 + out:
2547 + fist_copy_attr_times(dir, itohi2(dentry->d_parent->d_inode));
2548 +
2549 + if(!err) {
2550 + /* is this causing my pain? d_delete(dentry); */
2551 + d_drop(dentry);
2552 + }
2553 +
2554 + dput(dentry);
2555 + return err;
2556 +}
2557 +
2558 +
2559 +STATIC int
2560 +mini_fo_symlink(inode_t *dir, dentry_t *dentry, const char *symname)
2561 +{
2562 + int err=0;
2563 + dentry_t *hidden_sto_dentry;
2564 + dentry_t *hidden_sto_dir_dentry;
2565 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
2566 + umode_t mode;
2567 +#endif
2568 +
2569 + /* Fail if the symlink file exists */
2570 + if(!(dtost(dentry) == DELETED ||
2571 + dtost(dentry) == NON_EXISTANT)) {
2572 + err = -EEXIST;
2573 + goto out;
2574 + }
2575 +
2576 + err = get_neg_sto_dentry(dentry);
2577 + if(err) {
2578 + err = -EINVAL;
2579 + goto out;
2580 + }
2581 + hidden_sto_dentry = dtohd2(dentry);
2582 +
2583 + dget(hidden_sto_dentry);
2584 + /* was: hidden_sto_dir_dentry = lock_parent(hidden_sto_dentry); */
2585 + hidden_sto_dir_dentry = dget(hidden_sto_dentry->d_parent);
2586 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
2587 + mutex_lock(&hidden_sto_dir_dentry->d_inode->i_mutex);
2588 +#else
2589 + down(&hidden_sto_dir_dentry->d_inode->i_sem);
2590 +#endif
2591 +
2592 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
2593 + mode = S_IALLUGO;
2594 + err = vfs_symlink(hidden_sto_dir_dentry->d_inode,
2595 + hidden_sto_dentry, symname, mode);
2596 +#else
2597 + err = vfs_symlink(hidden_sto_dir_dentry->d_inode,
2598 + hidden_sto_dentry,
2599 + symname);
2600 +#endif
2601 + if (err || !hidden_sto_dentry->d_inode)
2602 + goto out_lock;
2603 +
2604 + if(dtost(dentry) == DELETED) {
2605 + dtost(dentry) = DEL_REWRITTEN;
2606 + err = mini_fo_tri_interpose(NULL, hidden_sto_dentry, dentry, dir->i_sb, 0);
2607 + if(err)
2608 + goto out_lock;
2609 + } else if(dtost(dentry) == NON_EXISTANT) {
2610 + dtost(dentry) = CREATED;
2611 + err = mini_fo_tri_interpose(dtohd(dentry), hidden_sto_dentry, dentry, dir->i_sb, 0);
2612 + if(err)
2613 + goto out_lock;
2614 + }
2615 + fist_copy_attr_timesizes(dir, hidden_sto_dir_dentry->d_inode);
2616 +
2617 + out_lock:
2618 + /* was: unlock_dir(hidden_sto_dir_dentry); */
2619 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
2620 + mutex_unlock(&hidden_sto_dir_dentry->d_inode->i_mutex);
2621 +#else
2622 + up(&hidden_sto_dir_dentry->d_inode->i_sem);
2623 +#endif
2624 + dput(hidden_sto_dir_dentry);
2625 +
2626 + dput(hidden_sto_dentry);
2627 + if (!dentry->d_inode)
2628 + d_drop(dentry);
2629 + out:
2630 + return err;
2631 +}
2632 +
2633 +STATIC int
2634 +mini_fo_mkdir(inode_t *dir, dentry_t *dentry, int mode)
2635 +{
2636 + int err;
2637 +
2638 + err = create_sto_dir(dentry, mode);
2639 +
2640 + check_mini_fo_dentry(dentry);
2641 +
2642 + return err;
2643 +}
2644 +
2645 +
2646 +STATIC int
2647 +mini_fo_rmdir(inode_t *dir, dentry_t *dentry)
2648 +{
2649 + int err = 0;
2650 +
2651 + dentry_t *hidden_sto_dentry;
2652 + dentry_t *hidden_sto_dir_dentry;
2653 + dentry_t *meta_dentry;
2654 + inode_t *hidden_sto_dir = NULL;
2655 +
2656 + check_mini_fo_dentry(dentry);
2657 + check_mini_fo_inode(dir);
2658 +
2659 + dget(dentry);
2660 + if(dtopd(dentry)->state == MODIFIED) {
2661 + /* XXX: disabled, because it does not bother to check files on
2662 + * the original filesystem - just a hack, but better than simply
2663 + * removing it without testing */
2664 + err = -EINVAL;
2665 + goto out;
2666 +
2667 + hidden_sto_dir = itohi2(dir);
2668 + hidden_sto_dentry = dtohd2(dentry);
2669 +
2670 + /* was:hidden_sto_dir_dentry = lock_parent(hidden_sto_dentry); */
2671 + hidden_sto_dir_dentry = dget(hidden_sto_dentry->d_parent);
2672 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
2673 + mutex_lock(&hidden_sto_dir_dentry->d_inode->i_mutex);
2674 +#else
2675 + down(&hidden_sto_dir_dentry->d_inode->i_sem);
2676 +#endif
2677 +
2678 + /* Delete an old WOL file contained in the storage dir */
2679 + meta_dentry = lookup_one_len(META_FILENAME,
2680 + hidden_sto_dentry,
2681 + strlen(META_FILENAME));
2682 + if(meta_dentry->d_inode) {
2683 + err = vfs_unlink(hidden_sto_dentry->d_inode, meta_dentry);
2684 + dput(meta_dentry);
2685 + if(!err)
2686 + d_delete(meta_dentry);
2687 + }
2688 +
2689 + err = vfs_rmdir(hidden_sto_dir, hidden_sto_dentry);
2690 + dput(hidden_sto_dentry);
2691 + if(!err)
2692 + d_delete(hidden_sto_dentry);
2693 +
2694 + /* propagate number of hard-links */
2695 + dentry->d_inode->i_nlink = itohi2(dentry->d_inode)->i_nlink;
2696 +
2697 + dput(dtohd(dentry));
2698 +
2699 + dtohd(dentry) = NULL;
2700 + dtopd(dentry)->state = DELETED;
2701 +
2702 + /* carefull with R files */
2703 + if( __meta_is_r_entry(dir,
2704 + dentry->d_name.name,
2705 + dentry->d_name.len) == 1) {
2706 + err = meta_remove_r_entry(dentry->d_parent,
2707 + dentry->d_name.name,
2708 + dentry->d_name.len);
2709 + if(err) {
2710 + printk(KERN_CRIT "mini_fo: rmdir: meta_remove_r_entry failed.\n");
2711 + goto out;
2712 + }
2713 + }
2714 + else {
2715 + /* ok, add deleted file to META */
2716 + meta_add_d_entry(dentry->d_parent,
2717 + dentry->d_name.name,
2718 + dentry->d_name.len);
2719 + }
2720 + /* was: unlock_dir(hidden_sto_dir_dentry); */
2721 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
2722 + mutex_unlock(&hidden_sto_dir_dentry->d_inode->i_mutex);
2723 +#else
2724 + up(&hidden_sto_dir_dentry->d_inode->i_sem);
2725 +#endif
2726 + dput(hidden_sto_dir_dentry);
2727 + goto out;
2728 + }
2729 + else if(dtopd(dentry)->state == UNMODIFIED) {
2730 + /* XXX: simply adding it to the delete list here is fscking dangerous!
2731 + * as a temporary hack, i will disable rmdir on unmodified directories
2732 + * for now.
2733 + */
2734 + err = -EINVAL;
2735 + goto out;
2736 +
2737 + err = get_neg_sto_dentry(dentry);
2738 + if(err) {
2739 + err = -EINVAL;
2740 + goto out;
2741 + }
2742 +
2743 + /* dput base dentry, this will relase the inode and free the
2744 + * dentry, as we will never need it again. */
2745 + dput(dtohd(dentry));
2746 + dtohd(dentry) = NULL;
2747 + dtopd(dentry)->state = DELETED;
2748 +
2749 + /* add deleted file to META-file */
2750 + meta_add_d_entry(dentry->d_parent,
2751 + dentry->d_name.name,
2752 + dentry->d_name.len);
2753 + goto out;
2754 + }
2755 + else if(dtopd(dentry)->state == CREATED) {
2756 + hidden_sto_dir = itohi2(dir);
2757 + hidden_sto_dentry = dtohd2(dentry);
2758 +
2759 + /* was: hidden_sto_dir_dentry = lock_parent(hidden_sto_dentry);*/
2760 + hidden_sto_dir_dentry = dget(hidden_sto_dentry->d_parent);
2761 +
2762 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
2763 + mutex_lock(&hidden_sto_dir_dentry->d_inode->i_mutex);
2764 +#else
2765 + down(&hidden_sto_dir_dentry->d_inode->i_sem);
2766 +#endif
2767 +
2768 + /* Delete an old WOL file contained in the storage dir */
2769 + meta_dentry = lookup_one_len(META_FILENAME,
2770 + hidden_sto_dentry,
2771 + strlen(META_FILENAME));
2772 + if(meta_dentry->d_inode) {
2773 + /* is this necessary? dget(meta_dentry); */
2774 + err = vfs_unlink(hidden_sto_dentry->d_inode,
2775 + meta_dentry);
2776 + dput(meta_dentry);
2777 + if(!err)
2778 + d_delete(meta_dentry);
2779 + }
2780 +
2781 + err = vfs_rmdir(hidden_sto_dir, hidden_sto_dentry);
2782 + dput(hidden_sto_dentry);
2783 + if(!err)
2784 + d_delete(hidden_sto_dentry);
2785 +
2786 + /* propagate number of hard-links */
2787 + dentry->d_inode->i_nlink = itohi2(dentry->d_inode)->i_nlink;
2788 + dtopd(dentry)->state = NON_EXISTANT;
2789 +
2790 + /* was: unlock_dir(hidden_sto_dir_dentry); */
2791 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
2792 + mutex_unlock(&hidden_sto_dir_dentry->d_inode->i_mutex);
2793 +#else
2794 + up(&hidden_sto_dir_dentry->d_inode->i_sem);
2795 +#endif
2796 + dput(hidden_sto_dir_dentry);
2797 +
2798 + goto out;
2799 + }
2800 + else if(dtopd(dentry)->state == DEL_REWRITTEN) {
2801 + hidden_sto_dir = itohi2(dir);
2802 + hidden_sto_dentry = dtohd2(dentry);
2803 +
2804 + /* was: hidden_sto_dir_dentry = lock_parent(hidden_sto_dentry);*/
2805 + hidden_sto_dir_dentry = dget(hidden_sto_dentry->d_parent);
2806 +
2807 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
2808 + mutex_lock(&hidden_sto_dir_dentry->d_inode->i_mutex);
2809 +#else
2810 + down(&hidden_sto_dir_dentry->d_inode->i_sem);
2811 +#endif
2812 +
2813 + /* Delete an old WOL file contained in the storage dir */
2814 + meta_dentry = lookup_one_len(META_FILENAME,
2815 + hidden_sto_dentry,
2816 + strlen(META_FILENAME));
2817 + if(meta_dentry->d_inode) {
2818 + /* is this necessary? dget(meta_dentry); */
2819 + err = vfs_unlink(hidden_sto_dentry->d_inode,
2820 + meta_dentry);
2821 + dput(meta_dentry);
2822 + if(!err)
2823 + d_delete(meta_dentry);
2824 + }
2825 +
2826 + err = vfs_rmdir(hidden_sto_dir, hidden_sto_dentry);
2827 + dput(hidden_sto_dentry);
2828 + if(!err)
2829 + d_delete(hidden_sto_dentry);
2830 +
2831 + /* propagate number of hard-links */
2832 + dentry->d_inode->i_nlink = itohi2(dentry->d_inode)->i_nlink;
2833 + dtopd(dentry)->state = DELETED;
2834 + /* was: unlock_dir(hidden_sto_dir_dentry); */
2835 +
2836 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
2837 + mutex_unlock(&hidden_sto_dir_dentry->d_inode->i_mutex);
2838 +#else
2839 + up(&hidden_sto_dir_dentry->d_inode->i_sem);
2840 +#endif
2841 + dput(hidden_sto_dir_dentry);
2842 + goto out;
2843 + }
2844 +
2845 + printk(KERN_CRIT "mini_fo_rmdir: ERROR, invalid state detected.\n");
2846 +
2847 + out:
2848 + if(!err) {
2849 + d_drop(dentry);
2850 + }
2851 +
2852 + fist_copy_attr_times(dir, itohi2(dentry->d_parent->d_inode));
2853 + dput(dentry);
2854 +
2855 + return err;
2856 +}
2857 +
2858 +
2859 +STATIC int
2860 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
2861 +mini_fo_mknod(inode_t *dir, dentry_t *dentry, int mode, dev_t dev)
2862 +#else
2863 +mini_fo_mknod(inode_t *dir, dentry_t *dentry, int mode, int dev)
2864 +#endif
2865 +{
2866 + int err = 0;
2867 +
2868 + check_mini_fo_dentry(dentry);
2869 +
2870 + err = create_sto_nod(dentry, mode, dev);
2871 + if(err) {
2872 + printk(KERN_CRIT "mini_fo_mknod: creating sto nod failed.\n");
2873 + err = -EINVAL;
2874 + }
2875 +
2876 + check_mini_fo_dentry(dentry);
2877 + return err;
2878 +}
2879 +
2880 +
2881 +STATIC int
2882 +mini_fo_rename(inode_t *old_dir, dentry_t *old_dentry,
2883 + inode_t *new_dir, dentry_t *new_dentry)
2884 +{
2885 + /* dispatch */
2886 + if(S_ISDIR(old_dentry->d_inode->i_mode))
2887 + return rename_directory(old_dir, old_dentry, new_dir, new_dentry);
2888 + return rename_nondir(old_dir, old_dentry, new_dir, new_dentry);
2889 +
2890 +}
2891 +
2892 +int rename_directory(inode_t *old_dir, dentry_t *old_dentry,
2893 + inode_t *new_dir, dentry_t *new_dentry)
2894 +{
2895 + int err, bpath_len;
2896 + char *bpath;
2897 +
2898 + dentry_t *hidden_old_dentry;
2899 + dentry_t *hidden_new_dentry;
2900 + dentry_t *hidden_old_dir_dentry;
2901 + dentry_t *hidden_new_dir_dentry;
2902 +
2903 + err = 0;
2904 + bpath = NULL;
2905 + bpath_len = 0;
2906 +
2907 + /* this is a test, chuck out if it works */
2908 + if(!(dtopd(new_dentry)->state == DELETED ||
2909 + dtopd(new_dentry)->state == NON_EXISTANT)) {
2910 + printk(KERN_CRIT "mini_fo: rename_directory: \
2911 + uh, ah, new_dentry not negative.\n");
2912 + /* return -1; */
2913 + }
2914 +
2915 + /* state = UNMODIFIED */
2916 + if(dtopd(old_dentry)->state == UNMODIFIED) {
2917 + err = dir_unmod_to_mod(old_dentry);
2918 + if (err)
2919 + goto out;
2920 + }
2921 +
2922 + /* state = MODIFIED */
2923 + if(dtopd(old_dentry)->state == MODIFIED) {
2924 + bpath = meta_check_r_entry(old_dentry->d_parent,
2925 + old_dentry->d_name.name,
2926 + old_dentry->d_name.len);
2927 + if(bpath) {
2928 + err = meta_remove_r_entry(old_dentry->d_parent,
2929 + old_dentry->d_name.name,
2930 + old_dentry->d_name.len);
2931 + if(err) {
2932 + printk(KERN_CRIT "mini_fo: rename_directory:\
2933 + meta_remove_r_entry \
2934 + failed.\n");
2935 + goto out;
2936 + }
2937 + err = meta_add_r_entry(new_dentry->d_parent,
2938 + bpath,
2939 + strlen(bpath),
2940 + new_dentry->d_name.name,
2941 + new_dentry->d_name.len);
2942 + kfree(bpath);
2943 + }
2944 + else {/* wol it */
2945 + err = meta_add_d_entry(old_dentry->d_parent,
2946 + old_dentry->d_name.name,
2947 + old_dentry->d_name.len);
2948 + if (err)
2949 + goto out;
2950 + /* put it on rename list */
2951 + err = get_mini_fo_bpath(old_dentry,
2952 + &bpath,
2953 + &bpath_len);
2954 + if (err)
2955 + goto out;
2956 + err = meta_add_r_entry(new_dentry->d_parent,
2957 + bpath, bpath_len,
2958 + new_dentry->d_name.name,
2959 + new_dentry->d_name.len);
2960 + if (err)
2961 + goto out;
2962 + }
2963 + /* no state change, MODIFIED stays MODIFIED */
2964 + }
2965 + /* state = CREATED */
2966 + if(dtopd(old_dentry)->state == CREATED ||
2967 + dtopd(old_dentry)->state == DEL_REWRITTEN) {
2968 + if(dtohd(old_dentry))
2969 + dput(dtohd(old_dentry));
2970 +
2971 + if(dtopd(new_dentry)->state == DELETED) {
2972 + dtopd(old_dentry)->state = DEL_REWRITTEN;
2973 + dtohd(old_dentry) = NULL;
2974 + }
2975 + else if(dtopd(new_dentry)->state == NON_EXISTANT) {
2976 + dtopd(old_dentry)->state = CREATED;
2977 + /* steal new dentry's neg. base dentry */
2978 + dtohd(old_dentry) = dtohd(new_dentry);
2979 + dtohd(new_dentry) = NULL;
2980 + }
2981 + }
2982 + if(dtopd(new_dentry)->state == UNMODIFIED ||
2983 + dtopd(new_dentry)->state == NON_EXISTANT) {
2984 + err = get_neg_sto_dentry(new_dentry);
2985 + if(err)
2986 + goto out;
2987 + }
2988 +
2989 + /* now move sto file */
2990 + hidden_old_dentry = dtohd2(old_dentry);
2991 + hidden_new_dentry = dtohd2(new_dentry);
2992 +
2993 + dget(hidden_old_dentry);
2994 + dget(hidden_new_dentry);
2995 +
2996 + hidden_old_dir_dentry = dget(hidden_old_dentry->d_parent);
2997 + hidden_new_dir_dentry = dget(hidden_new_dentry->d_parent);
2998 + double_lock(hidden_old_dir_dentry, hidden_new_dir_dentry);
2999 +
3000 + err = vfs_rename(hidden_old_dir_dentry->d_inode, hidden_old_dentry,
3001 + hidden_new_dir_dentry->d_inode, hidden_new_dentry);
3002 + if(err)
3003 + goto out_lock;
3004 +
3005 + fist_copy_attr_all(new_dir, hidden_new_dir_dentry->d_inode);
3006 + if (new_dir != old_dir)
3007 + fist_copy_attr_all(old_dir,
3008 + hidden_old_dir_dentry->d_inode);
3009 +
3010 + out_lock:
3011 + /* double_unlock will dput the new/old parent dentries
3012 + * whose refcnts were incremented via get_parent above. */
3013 + double_unlock(hidden_old_dir_dentry, hidden_new_dir_dentry);
3014 + dput(hidden_new_dentry);
3015 + dput(hidden_old_dentry);
3016 +
3017 + out:
3018 + return err;
3019 +}
3020 +
3021 +int rename_nondir(inode_t *old_dir, dentry_t *old_dentry,
3022 + inode_t *new_dir, dentry_t *new_dentry)
3023 +{
3024 + int err=0;
3025 +
3026 + check_mini_fo_dentry(old_dentry);
3027 + check_mini_fo_dentry(new_dentry);
3028 + check_mini_fo_inode(old_dir);
3029 + check_mini_fo_inode(new_dir);
3030 +
3031 + /* state: UNMODIFIED */
3032 + if(dtost(old_dentry) == UNMODIFIED) {
3033 + err = nondir_unmod_to_mod(old_dentry, 1);
3034 + if(err) {
3035 + err = -EINVAL;
3036 + goto out;
3037 + }
3038 + }
3039 +
3040 + /* the easy states */
3041 + if(exists_in_storage(old_dentry)) {
3042 +
3043 + dentry_t *hidden_old_dentry;
3044 + dentry_t *hidden_new_dentry;
3045 + dentry_t *hidden_old_dir_dentry;
3046 + dentry_t *hidden_new_dir_dentry;
3047 +
3048 + /* if old file is MODIFIED, add it to the deleted_list */
3049 + if(dtopd(old_dentry)->state == MODIFIED) {
3050 + meta_add_d_entry(old_dentry->d_parent,
3051 + old_dentry->d_name.name,
3052 + old_dentry->d_name.len);
3053 +
3054 + dput(dtohd(old_dentry));
3055 + }
3056 + /* if old file is CREATED, we only release the base dentry */
3057 + if(dtopd(old_dentry)->state == CREATED) {
3058 + if(dtohd(old_dentry))
3059 + dput(dtohd(old_dentry));
3060 + }
3061 +
3062 + /* now setup the new states (depends on new_dentry state) */
3063 + /* new dentry state = MODIFIED */
3064 + if(dtopd(new_dentry)->state == MODIFIED) {
3065 + meta_add_d_entry(new_dentry->d_parent,
3066 + new_dentry->d_name.name,
3067 + new_dentry->d_name.len);
3068 +
3069 + /* new dentry will be d_put'ed later by the vfs
3070 + * so don't do it here
3071 + * dput(dtohd(new_dentry));
3072 + */
3073 + dtohd(old_dentry) = NULL;
3074 + dtopd(old_dentry)->state = DEL_REWRITTEN;
3075 + }
3076 + /* new dentry state = UNMODIFIED */
3077 + else if(dtopd(new_dentry)->state == UNMODIFIED) {
3078 + if(get_neg_sto_dentry(new_dentry))
3079 + return -EINVAL;
3080 +
3081 + meta_add_d_entry(new_dentry->d_parent,
3082 + new_dentry->d_name.name,
3083 + new_dentry->d_name.len);
3084 +
3085 + /* is this right??? */
3086 + /*dput(dtohd(new_dentry));*/
3087 + dtohd(old_dentry) = NULL;
3088 + dtopd(old_dentry)->state = DEL_REWRITTEN;
3089 + }
3090 + /* new dentry state = CREATED */
3091 + else if(dtopd(new_dentry)->state == CREATED) {
3092 + /* we keep the neg. base dentry (if exists) */
3093 + dtohd(old_dentry) = dtohd(new_dentry);
3094 + /* ...and set it to Null, or we'll get
3095 + * dcache.c:345 if it gets dput twice... */
3096 + dtohd(new_dentry) = NULL;
3097 + dtopd(old_dentry)->state = CREATED;
3098 + }
3099 + /* new dentry state = NON_EXISTANT */
3100 + else if(dtopd(new_dentry)->state == NON_EXISTANT) {
3101 + if(get_neg_sto_dentry(new_dentry))
3102 + return -EINVAL;
3103 +
3104 + /* we keep the neg. base dentry (if exists) */
3105 + dtohd(old_dentry) = dtohd(new_dentry);
3106 + /* ...and set it to Null, or we'll get
3107 + * Dr. dcache.c:345 if it gets dput twice... */
3108 + dtohd(new_dentry) = NULL;
3109 + dtopd(old_dentry)->state = CREATED;
3110 + }
3111 + /* new dentry state = DEL_REWRITTEN or DELETED */
3112 + else if(dtopd(new_dentry)->state == DEL_REWRITTEN ||
3113 + dtopd(new_dentry)->state == DELETED) {
3114 + dtohd(old_dentry) = NULL;
3115 + dtopd(old_dentry)->state = DEL_REWRITTEN;
3116 + }
3117 + else { /* not possible, uhh, ahh */
3118 + printk(KERN_CRIT
3119 + "mini_fo: rename_reg_file: invalid state detected [1].\n");
3120 + return -1;
3121 + }
3122 +
3123 + /* now we definitely have a sto file */
3124 + hidden_old_dentry = dtohd2(old_dentry);
3125 + hidden_new_dentry = dtohd2(new_dentry);
3126 +
3127 + dget(hidden_old_dentry);
3128 + dget(hidden_new_dentry);
3129 +
3130 + hidden_old_dir_dentry = dget(hidden_old_dentry->d_parent);
3131 + hidden_new_dir_dentry = dget(hidden_new_dentry->d_parent);
3132 + double_lock(hidden_old_dir_dentry, hidden_new_dir_dentry);
3133 +
3134 + err = vfs_rename(hidden_old_dir_dentry->d_inode,
3135 + hidden_old_dentry,
3136 + hidden_new_dir_dentry->d_inode,
3137 + hidden_new_dentry);
3138 + if(err)
3139 + goto out_lock;
3140 +
3141 + fist_copy_attr_all(new_dir, hidden_new_dir_dentry->d_inode);
3142 + if (new_dir != old_dir)
3143 + fist_copy_attr_all(old_dir, hidden_old_dir_dentry->d_inode);
3144 +
3145 + out_lock:
3146 + /* double_unlock will dput the new/old parent dentries
3147 + * whose refcnts were incremented via get_parent above.
3148 + */
3149 + double_unlock(hidden_old_dir_dentry, hidden_new_dir_dentry);
3150 + dput(hidden_new_dentry);
3151 + dput(hidden_old_dentry);
3152 + out:
3153 + return err;
3154 + }
3155 + else { /* invalid state */
3156 + printk(KERN_CRIT "mini_fo: rename_reg_file: ERROR: invalid state detected [2].\n");
3157 + return -1;
3158 + }
3159 +}
3160 +
3161 +
3162 +STATIC int
3163 +mini_fo_readlink(dentry_t *dentry, char *buf, int bufsiz)
3164 +{
3165 + int err=0;
3166 + dentry_t *hidden_dentry = NULL;
3167 +
3168 + if(dtohd2(dentry) && dtohd2(dentry)->d_inode) {
3169 + hidden_dentry = dtohd2(dentry);
3170 + } else if(dtohd(dentry) && dtohd(dentry)->d_inode) {
3171 + hidden_dentry = dtohd(dentry);
3172 + } else {
3173 + goto out;
3174 + }
3175 +
3176 + if (!hidden_dentry->d_inode->i_op ||
3177 + !hidden_dentry->d_inode->i_op->readlink) {
3178 + err = -EINVAL; goto out;
3179 + }
3180 +
3181 + err = hidden_dentry->d_inode->i_op->readlink(hidden_dentry,
3182 + buf,
3183 + bufsiz);
3184 + if (err > 0)
3185 + fist_copy_attr_atime(dentry->d_inode, hidden_dentry->d_inode);
3186 +
3187 + out:
3188 + return err;
3189 +}
3190 +
3191 +
3192 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,13)
3193 +static int mini_fo_follow_link(dentry_t *dentry, struct nameidata *nd)
3194 +#else
3195 +static void* mini_fo_follow_link(dentry_t *dentry, struct nameidata *nd)
3196 +#endif
3197 +{
3198 + char *buf;
3199 + int len = PAGE_SIZE, err;
3200 + mm_segment_t old_fs;
3201 +
3202 + /* in 2.6 this is freed by mini_fo_put_link called by __do_follow_link */
3203 + buf = kmalloc(len, GFP_KERNEL);
3204 + if (!buf) {
3205 + err = -ENOMEM;
3206 + goto out;
3207 + }
3208 +
3209 + /* read the symlink, and then we will follow it */
3210 + old_fs = get_fs();
3211 + set_fs(KERNEL_DS);
3212 + err = dentry->d_inode->i_op->readlink(dentry, buf, len);
3213 + set_fs(old_fs);
3214 + if (err < 0) {
3215 + kfree(buf);
3216 + buf = NULL;
3217 + goto out;
3218 + }
3219 + buf[err] = 0;
3220 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
3221 + nd_set_link(nd, buf);
3222 + err = 0;
3223 +#else
3224 + err = vfs_follow_link(nd, buf);
3225 +#endif
3226 +
3227 + out:
3228 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
3229 + kfree(buf);
3230 +#endif
3231 +
3232 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,13)
3233 + return err;
3234 +#else
3235 + return ERR_PTR(err);
3236 +#endif
3237 +}
3238 +
3239 +STATIC
3240 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
3241 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,13)
3242 +void mini_fo_put_link(struct dentry *dentry, struct nameidata *nd)
3243 +#else
3244 +void mini_fo_put_link(struct dentry *dentry, struct nameidata *nd, void *cookie)
3245 +#endif
3246 +{
3247 + char *link;
3248 + link = nd_get_link(nd);
3249 + kfree(link);
3250 +}
3251 +#endif
3252 +
3253 +STATIC int
3254 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
3255 +mini_fo_permission(inode_t *inode, int mask, struct nameidata *nd)
3256 +#else
3257 +mini_fo_permission(inode_t *inode, int mask)
3258 +#endif
3259 +{
3260 + inode_t *hidden_inode;
3261 + int mode;
3262 + int err;
3263 +
3264 + if(itohi2(inode)) {
3265 + hidden_inode = itohi2(inode);
3266 + } else {
3267 + hidden_inode = itohi(inode);
3268 + }
3269 + mode = inode->i_mode;
3270 +
3271 + /* not really needed, as permission handles everything:
3272 + * err = vfs_permission(inode, mask);
3273 + * if (err)
3274 + * goto out;
3275 + */
3276 +
3277 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
3278 + err = permission(hidden_inode, mask, nd);
3279 +#else
3280 + err = permission(hidden_inode, mask);
3281 +#endif
3282 +
3283 + /* out: */
3284 + return err;
3285 +}
3286 +
3287 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
3288 +STATIC int
3289 +mini_fo_inode_revalidate(dentry_t *dentry)
3290 +{
3291 + int err = 0;
3292 + dentry_t *hidden_dentry;
3293 + inode_t *hidden_inode;
3294 +
3295 + ASSERT(dentry->d_inode);
3296 + ASSERT(itopd(dentry->d_inode));
3297 +
3298 + if(itohi2(dentry->d_inode)) {
3299 + hidden_dentry = dtohd2(dentry);
3300 + hidden_inode = hidden_dentry->d_inode;
3301 + } else if(itohi(dentry->d_inode)) {
3302 + hidden_dentry = dtohd(dentry);
3303 + hidden_inode = hidden_dentry->d_inode;
3304 + } else {
3305 + printk(KERN_CRIT "mini_fo_inode_revalidate: ERROR, invalid state detected.\n");
3306 + err = -ENOENT;
3307 + goto out;
3308 + }
3309 + if (hidden_inode && hidden_inode->i_op && hidden_inode->i_op->revalidate){
3310 + err = hidden_inode->i_op->revalidate(hidden_dentry);
3311 + if (err)
3312 + goto out;
3313 + }
3314 + fist_copy_attr_all(dentry->d_inode, hidden_inode);
3315 + out:
3316 + return err;
3317 +}
3318 +#endif
3319 +
3320 +STATIC int
3321 +mini_fo_setattr(dentry_t *dentry, struct iattr *ia)
3322 +{
3323 + int err = 0;
3324 +
3325 + check_mini_fo_dentry(dentry);
3326 +
3327 + if(!is_mini_fo_existant(dentry)) {
3328 + printk(KERN_CRIT "mini_fo_setattr: ERROR, invalid state detected [1].\n");
3329 + goto out;
3330 + }
3331 +
3332 + if(dtost(dentry) == UNMODIFIED) {
3333 + if(!IS_COPY_FLAG(ia->ia_valid))
3334 + goto out; /* we ignore these changes to base */
3335 +
3336 + if(S_ISDIR(dentry->d_inode->i_mode)) {
3337 + err = dir_unmod_to_mod(dentry);
3338 + } else {
3339 + /* we copy contents if file is not beeing truncated */
3340 + if(S_ISREG(dentry->d_inode->i_mode) &&
3341 + !(ia->ia_size == 0 && (ia->ia_valid & ATTR_SIZE))) {
3342 + err = nondir_unmod_to_mod(dentry, 1);
3343 + } else
3344 + err = nondir_unmod_to_mod(dentry, 0);
3345 + }
3346 + if(err) {
3347 + err = -EINVAL;
3348 + printk(KERN_CRIT "mini_fo_setattr: ERROR changing states.\n");
3349 + goto out;
3350 + }
3351 + }
3352 + if(!exists_in_storage(dentry)) {
3353 + printk(KERN_CRIT "mini_fo_setattr: ERROR, invalid state detected [2].\n");
3354 + err = -EINVAL;
3355 + goto out;
3356 + }
3357 + ASSERT(dentry->d_inode);
3358 + ASSERT(dtohd2(dentry));
3359 + ASSERT(itopd(dentry->d_inode));
3360 + ASSERT(itohi2(dentry->d_inode));
3361 +
3362 + err = notify_change(dtohd2(dentry), ia);
3363 + fist_copy_attr_all(dentry->d_inode, itohi2(dentry->d_inode));
3364 + out:
3365 + return err;
3366 +}
3367 +
3368 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
3369 +STATIC int
3370 +mini_fo_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
3371 +{
3372 + int err = 0;
3373 + dentry_t *hidden_dentry;
3374 +
3375 + ASSERT(dentry->d_inode);
3376 + ASSERT(itopd(dentry->d_inode));
3377 +
3378 + if(itohi2(dentry->d_inode)) {
3379 + hidden_dentry = dtohd2(dentry);
3380 + } else if(itohi(dentry->d_inode)) {
3381 + hidden_dentry = dtohd(dentry);
3382 + } else {
3383 + printk(KERN_CRIT "mini_fo_getattr: ERROR, invalid state detected.\n");
3384 + err = -ENOENT;
3385 + goto out;
3386 + }
3387 + fist_copy_attr_all(dentry->d_inode, hidden_dentry->d_inode);
3388 +
3389 + ASSERT(hidden_dentry);
3390 + ASSERT(hidden_dentry->d_inode);
3391 + ASSERT(hidden_dentry->d_inode->i_op);
3392 +
3393 + generic_fillattr(dentry->d_inode, stat);
3394 + if (!stat->blksize) {
3395 + struct super_block *s = hidden_dentry->d_inode->i_sb;
3396 + unsigned blocks;
3397 + blocks = (stat->size+s->s_blocksize-1) >> s->s_blocksize_bits;
3398 + stat->blocks = (s->s_blocksize / 512) * blocks;
3399 + stat->blksize = s->s_blocksize;
3400 + }
3401 + out:
3402 + return err;
3403 +}
3404 +#endif
3405 +
3406 +#if defined(XATTR) && (LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,20))
3407 +#if 0 /* no xattr_alloc() and xattr_free() */
3408 +/* This is lifted from fs/xattr.c */
3409 +static void *
3410 +xattr_alloc(size_t size, size_t limit)
3411 +{
3412 + void *ptr;
3413 +
3414 + if (size > limit)
3415 + return ERR_PTR(-E2BIG);
3416 +
3417 + if (!size) /* size request, no buffer is needed */
3418 + return NULL;
3419 + else if (size <= PAGE_SIZE)
3420 + ptr = kmalloc((unsigned long) size, GFP_KERNEL);
3421 + else
3422 + ptr = vmalloc((unsigned long) size);
3423 + if (!ptr)
3424 + return ERR_PTR(-ENOMEM);
3425 + return ptr;
3426 +}
3427 +
3428 +static void
3429 +xattr_free(void *ptr, size_t size)
3430 +{
3431 + if (!size) /* size request, no buffer was needed */
3432 + return;
3433 + else if (size <= PAGE_SIZE)
3434 + kfree(ptr);
3435 + else
3436 + vfree(ptr);
3437 +}
3438 +#endif /* no xattr_alloc() and xattr_free() */
3439 +
3440 +/* BKL held by caller.
3441 + * dentry->d_inode->i_sem down
3442 + */
3443 +STATIC int
3444 +mini_fo_getxattr(struct dentry *dentry, const char *name, void *value, size_t size) {
3445 + struct dentry *hidden_dentry = NULL;
3446 + int err = -EOPNOTSUPP;
3447 + /* Define these anyway so we don't need as much ifdef'ed code. */
3448 + char *encoded_name = NULL;
3449 + char *encoded_value = NULL;
3450 +
3451 + check_mini_fo_dentry(dentry);
3452 +
3453 + if(exists_in_storage(dentry))
3454 + hidden_dentry = dtohd2(dentry);
3455 + else
3456 + hidden_dentry = dtohd(dentry);
3457 +
3458 + ASSERT(hidden_dentry);
3459 + ASSERT(hidden_dentry->d_inode);
3460 + ASSERT(hidden_dentry->d_inode->i_op);
3461 +
3462 + if (hidden_dentry->d_inode->i_op->getxattr) {
3463 + encoded_name = (char *)name;
3464 + encoded_value = (char *)value;
3465 +
3466 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
3467 + mutex_lock(&hidden_dentry->d_inode->i_mutex);
3468 +#else
3469 + down(&hidden_dentry->d_inode->i_sem);
3470 +#endif
3471 + /* lock_kernel() already done by caller. */
3472 + err = hidden_dentry->d_inode->i_op->getxattr(hidden_dentry, encoded_name, encoded_value, size);
3473 + /* unlock_kernel() will be done by caller. */
3474 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
3475 + mutex_lock(&hidden_dentry->d_inode->i_mutex);
3476 +#else
3477 + up(&hidden_dentry->d_inode->i_sem);
3478 +#endif
3479 + }
3480 + return err;
3481 +}
3482 +
3483 +/* BKL held by caller.
3484 + * dentry->d_inode->i_sem down
3485 + */
3486 +STATIC int
3487 +#if ((LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,21) \
3488 + && LINUX_VERSION_CODE <= KERNEL_VERSION(2,4,23)) \
3489 + || LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0))
3490 +mini_fo_setxattr(struct dentry *dentry, const char *name,
3491 + const void *value, size_t size, int flags)
3492 +#else
3493 +mini_fo_setxattr(struct dentry *dentry, const char *name,
3494 + void *value, size_t size, int flags)
3495 +#endif
3496 +
3497 +{