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