ps3: Update kernel to linux-2.6.30
[openwrt.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(hidden_dentry->d_inode->i_op);
3502 +
3503 + if (hidden_dentry->d_inode->i_op->setxattr) {
3504 + encoded_name = (char *)name;
3505 + encoded_value = (char *)value;
3506 +
3507 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
3508 + mutex_lock(&hidden_dentry->d_inode->i_mutex);
3509 +#else
3510 + down(&hidden_dentry->d_inode->i_sem);
3511 +#endif
3512 + /* lock_kernel() already done by caller. */
3513 + err = hidden_dentry->d_inode->i_op->setxattr(hidden_dentry, encoded_name, encoded_value, size, flags);
3514 + /* unlock_kernel() will be done by caller. */
3515 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
3516 + mutex_unlock(&hidden_dentry->d_inode->i_mutex);
3517 +#else
3518 + up(&hidden_dentry->d_inode->i_sem);
3519 +#endif
3520 + }
3521 + return err;
3522 +}
3523 +
3524 +/* BKL held by caller.
3525 + * dentry->d_inode->i_sem down
3526 + */
3527 +STATIC int
3528 +mini_fo_removexattr(struct dentry *dentry, const char *name) {
3529 + struct dentry *hidden_dentry = NULL;
3530 + int err = -EOPNOTSUPP;
3531 + char *encoded_name;
3532 +
3533 + check_mini_fo_dentry(dentry);
3534 +
3535 + if(exists_in_storage(dentry))
3536 + hidden_dentry = dtohd2(dentry);
3537 + else
3538 + hidden_dentry = dtohd(dentry);
3539 +
3540 + ASSERT(hidden_dentry);
3541 + ASSERT(hidden_dentry->d_inode);
3542 + ASSERT(hidden_dentry->d_inode->i_op);
3543 +
3544 + if (hidden_dentry->d_inode->i_op->removexattr) {
3545 + encoded_name = (char *)name;
3546 +
3547 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
3548 + mutex_lock(&hidden_dentry->d_inode->i_mutex);
3549 +#else
3550 + down(&hidden_dentry->d_inode->i_sem);
3551 +#endif
3552 + /* lock_kernel() already done by caller. */
3553 + err = hidden_dentry->d_inode->i_op->removexattr(hidden_dentry, encoded_name);
3554 + /* unlock_kernel() will be done by caller. */
3555 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
3556 + mutex_unlock(&hidden_dentry->d_inode->i_mutex);
3557 +#else
3558 + up(&hidden_dentry->d_inode->i_sem);
3559 +#endif
3560 + }
3561 + return err;
3562 +}
3563 +
3564 +/* BKL held by caller.
3565 + * dentry->d_inode->i_sem down
3566 + */
3567 +STATIC int
3568 +mini_fo_listxattr(struct dentry *dentry, char *list, size_t size) {
3569 + struct dentry *hidden_dentry = NULL;
3570 + int err = -EOPNOTSUPP;
3571 + char *encoded_list = NULL;
3572 +
3573 + check_mini_fo_dentry(dentry);
3574 +
3575 + if(exists_in_storage(dentry))
3576 + hidden_dentry = dtohd2(dentry);
3577 + else
3578 + hidden_dentry = dtohd(dentry);
3579 +
3580 + ASSERT(hidden_dentry);
3581 + ASSERT(hidden_dentry->d_inode);
3582 + ASSERT(hidden_dentry->d_inode->i_op);
3583 +
3584 + if (hidden_dentry->d_inode->i_op->listxattr) {
3585 + encoded_list = list;
3586 +
3587 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
3588 + mutex_lock(&hidden_dentry->d_inode->i_mutex);
3589 +#else
3590 + down(&hidden_dentry->d_inode->i_sem);
3591 +#endif
3592 + /* lock_kernel() already done by caller. */
3593 + err = hidden_dentry->d_inode->i_op->listxattr(hidden_dentry, encoded_list, size);
3594 + /* unlock_kernel() will be done by caller. */
3595 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
3596 + mutex_unlock(&hidden_dentry->d_inode->i_mutex);
3597 +#else
3598 + up(&hidden_dentry->d_inode->i_sem);
3599 +#endif
3600 + }
3601 + return err;
3602 +}
3603 +# endif /* defined(XATTR) && (LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,20)) */
3604 +
3605 +struct inode_operations mini_fo_symlink_iops =
3606 + {
3607 + readlink: mini_fo_readlink,
3608 + follow_link: mini_fo_follow_link,
3609 + /* mk: permission: mini_fo_permission, */
3610 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
3611 + revalidate: mini_fo_inode_revalidate,
3612 +#endif
3613 + setattr: mini_fo_setattr,
3614 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
3615 + getattr: mini_fo_getattr,
3616 + put_link: mini_fo_put_link,
3617 +#endif
3618 +
3619 +#if defined(XATTR) && (LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,20))
3620 + setxattr: mini_fo_setxattr,
3621 + getxattr: mini_fo_getxattr,
3622 + listxattr: mini_fo_listxattr,
3623 + removexattr: mini_fo_removexattr
3624 +# endif /* defined(XATTR) && (LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,20)) */
3625 + };
3626 +
3627 +struct inode_operations mini_fo_dir_iops =
3628 + {
3629 + create: mini_fo_create,
3630 + lookup: mini_fo_lookup,
3631 + link: mini_fo_link,
3632 + unlink: mini_fo_unlink,
3633 + symlink: mini_fo_symlink,
3634 + mkdir: mini_fo_mkdir,
3635 + rmdir: mini_fo_rmdir,
3636 + mknod: mini_fo_mknod,
3637 + rename: mini_fo_rename,
3638 + /* no readlink/follow_link for non-symlinks */
3639 + // off because we have setattr
3640 + // truncate: mini_fo_truncate,
3641 + /* mk:permission: mini_fo_permission, */
3642 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
3643 + revalidate: mini_fo_inode_revalidate,
3644 +#endif
3645 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
3646 + getattr: mini_fo_getattr,
3647 +#endif
3648 + setattr: mini_fo_setattr,
3649 +#if defined(XATTR) && (LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,20))
3650 + setxattr: mini_fo_setxattr,
3651 + getxattr: mini_fo_getxattr,
3652 + listxattr: mini_fo_listxattr,
3653 + removexattr: mini_fo_removexattr
3654 +# endif /* XATTR && LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,20) */
3655 + };
3656 +
3657 +struct inode_operations mini_fo_main_iops =
3658 + {
3659 + /* permission: mini_fo_permission, */
3660 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
3661 + revalidate: mini_fo_inode_revalidate,
3662 +#endif
3663 + setattr: mini_fo_setattr,
3664 +
3665 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
3666 + getattr: mini_fo_getattr,
3667 +#endif
3668 +#if defined(XATTR) && (LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,20))
3669 + setxattr: mini_fo_setxattr,
3670 + getxattr: mini_fo_getxattr,
3671 + listxattr: mini_fo_listxattr,
3672 + removexattr: mini_fo_removexattr
3673 +# endif /* XATTR && LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,20) */
3674 + };
3675 --- /dev/null
3676 +++ b/fs/mini_fo/main.c
3677 @@ -0,0 +1,423 @@
3678 +/*
3679 + * Copyright (c) 1997-2003 Erez Zadok
3680 + * Copyright (c) 2001-2003 Stony Brook University
3681 + *
3682 + * For specific licensing information, see the COPYING file distributed with
3683 + * this package, or get one from ftp://ftp.filesystems.org/pub/fist/COPYING.
3684 + *
3685 + * This Copyright notice must be kept intact and distributed with all
3686 + * fistgen sources INCLUDING sources generated by fistgen.
3687 + */
3688 +/*
3689 + * Copyright (C) 2004, 2005 Markus Klotzbuecher <mk@creamnet.de>
3690 + *
3691 + * This program is free software; you can redistribute it and/or
3692 + * modify it under the terms of the GNU General Public License
3693 + * as published by the Free Software Foundation; either version
3694 + * 2 of the License, or (at your option) any later version.
3695 + */
3696 +
3697 +/*
3698 + * $Id$
3699 + */
3700 +
3701 +#ifdef HAVE_CONFIG_H
3702 +# include <config.h>
3703 +#endif
3704 +
3705 +#include "fist.h"
3706 +#include "mini_fo.h"
3707 +#include <linux/module.h>
3708 +
3709 +/* This definition must only appear after we include <linux/module.h> */
3710 +#ifndef MODULE_LICENSE
3711 +# define MODULE_LICENSE(bison)
3712 +#endif /* not MODULE_LICENSE */
3713 +
3714 +/*
3715 + * This is the mini_fo tri interpose function, which extends the
3716 + * functionality of the regular interpose by interposing a higher
3717 + * level inode on top of two lower level ones: the base filesystem
3718 + * inode and the storage filesystem inode.
3719 + *
3720 + * sb we pass is mini_fo's super_block
3721 + */
3722 +int
3723 +mini_fo_tri_interpose(dentry_t *hidden_dentry,
3724 + dentry_t *hidden_sto_dentry,
3725 + dentry_t *dentry, super_block_t *sb, int flag)
3726 +{
3727 + inode_t *hidden_inode = NULL;
3728 + inode_t *hidden_sto_inode = NULL; /* store corresponding storage inode */
3729 + int err = 0;
3730 + inode_t *inode;
3731 +
3732 + /* Pointer to hidden_sto_inode if exists, else to hidden_inode.
3733 + * This is used to copy the attributes of the correct inode. */
3734 + inode_t *master_inode;
3735 +
3736 + if(hidden_dentry)
3737 + hidden_inode = hidden_dentry->d_inode;
3738 + if(hidden_sto_dentry)
3739 + hidden_sto_inode = hidden_sto_dentry->d_inode;
3740 +
3741 + ASSERT(dentry->d_inode == NULL);
3742 +
3743 + /* mk: One of the inodes associated with the dentrys is likely to
3744 + * be NULL, so carefull:
3745 + */
3746 + ASSERT((hidden_inode != NULL) || (hidden_sto_inode != NULL));
3747 +
3748 + if(hidden_sto_inode)
3749 + master_inode = hidden_sto_inode;
3750 + else
3751 + master_inode = hidden_inode;
3752 +
3753 + /*
3754 + * We allocate our new inode below, by calling iget.
3755 + * iget will call our read_inode which will initialize some
3756 + * of the new inode's fields
3757 + */
3758 +
3759 + /*
3760 + * original: inode = iget(sb, hidden_inode->i_ino);
3761 + */
3762 + inode = iget(sb, iunique(sb, 25));
3763 + if (!inode) {
3764 + err = -EACCES; /* should be impossible??? */
3765 + goto out;
3766 + }
3767 +
3768 + /*
3769 + * interpose the inode if not already interposed
3770 + * this is possible if the inode is being reused
3771 + * XXX: what happens if we get_empty_inode() but there's another already?
3772 + * for now, ASSERT() that this can't happen; fix later.
3773 + */
3774 + if (itohi(inode) != NULL) {
3775 + printk(KERN_CRIT "mini_fo_tri_interpose: itohi(inode) != NULL.\n");
3776 + }
3777 + if (itohi2(inode) != NULL) {
3778 + printk(KERN_CRIT "mini_fo_tri_interpose: itohi2(inode) != NULL.\n");
3779 + }
3780 +
3781 + /* mk: Carefull, igrab can't handle NULL inodes (ok, why should it?), so
3782 + * we need to check here:
3783 + */
3784 + if(hidden_inode)
3785 + itohi(inode) = igrab(hidden_inode);
3786 + else
3787 + itohi(inode) = NULL;
3788 +
3789 + if(hidden_sto_inode)
3790 + itohi2(inode) = igrab(hidden_sto_inode);
3791 + else
3792 + itohi2(inode) = NULL;
3793 +
3794 +
3795 + /* Use different set of inode ops for symlinks & directories*/
3796 + if (S_ISLNK(master_inode->i_mode))
3797 + inode->i_op = &mini_fo_symlink_iops;
3798 + else if (S_ISDIR(master_inode->i_mode))
3799 + inode->i_op = &mini_fo_dir_iops;
3800 +
3801 + /* Use different set of file ops for directories */
3802 + if (S_ISDIR(master_inode->i_mode))
3803 + inode->i_fop = &mini_fo_dir_fops;
3804 +
3805 + /* properly initialize special inodes */
3806 + if (S_ISBLK(master_inode->i_mode) || S_ISCHR(master_inode->i_mode) ||
3807 + S_ISFIFO(master_inode->i_mode) || S_ISSOCK(master_inode->i_mode)) {
3808 + init_special_inode(inode, master_inode->i_mode, master_inode->i_rdev);
3809 + }
3810 +
3811 + /* Fix our inode's address operations to that of the lower inode */
3812 + if (inode->i_mapping->a_ops != master_inode->i_mapping->a_ops) {
3813 + inode->i_mapping->a_ops = master_inode->i_mapping->a_ops;
3814 + }
3815 +
3816 + /* only (our) lookup wants to do a d_add */
3817 + if (flag)
3818 + d_add(dentry, inode);
3819 + else
3820 + d_instantiate(dentry, inode);
3821 +
3822 + ASSERT(dtopd(dentry) != NULL);
3823 +
3824 + /* all well, copy inode attributes */
3825 + fist_copy_attr_all(inode, master_inode);
3826 +
3827 + out:
3828 + return err;
3829 +}
3830 +
3831 +/* parse mount options "base=" and "sto=" */
3832 +dentry_t *
3833 +mini_fo_parse_options(super_block_t *sb, char *options)
3834 +{
3835 + dentry_t *hidden_root = ERR_PTR(-EINVAL);
3836 + dentry_t *hidden_root2 = ERR_PTR(-EINVAL);
3837 + struct nameidata nd, nd2;
3838 + char *name, *tmp, *end;
3839 + int err = 0;
3840 +
3841 + /* We don't want to go off the end of our arguments later on. */
3842 + for (end = options; *end; end++);
3843 +
3844 + while (options < end) {
3845 + tmp = options;
3846 + while (*tmp && *tmp != ',')
3847 + tmp++;
3848 + *tmp = '\0';
3849 + if (!strncmp("base=", options, 5)) {
3850 + name = options + 5;
3851 + printk(KERN_INFO "mini_fo: using base directory: %s\n", name);
3852 +
3853 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
3854 + if (path_init(name, LOOKUP_FOLLOW, &nd))
3855 + err = path_walk(name, &nd);
3856 +#else
3857 + err = path_lookup(name, LOOKUP_FOLLOW, &nd);
3858 +#endif
3859 + if (err) {
3860 + printk(KERN_CRIT "mini_fo: error accessing hidden directory '%s'\n", name);
3861 + hidden_root = ERR_PTR(err);
3862 + goto out;
3863 + }
3864 + hidden_root = nd.dentry;
3865 + stopd(sb)->base_dir_dentry = nd.dentry;
3866 + stopd(sb)->hidden_mnt = nd.mnt;
3867 +
3868 + } else if(!strncmp("sto=", options, 4)) {
3869 + /* parse the storage dir */
3870 + name = options + 4;
3871 + printk(KERN_INFO "mini_fo: using storage directory: %s\n", name);
3872 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
3873 + if(path_init(name, LOOKUP_FOLLOW, &nd2))
3874 + err = path_walk(name, &nd2);
3875 +#else
3876 + err = path_lookup(name, LOOKUP_FOLLOW, &nd2);
3877 +#endif
3878 + if(err) {
3879 + printk(KERN_CRIT "mini_fo: error accessing hidden storage directory '%s'\n", name);
3880 +
3881 + hidden_root2 = ERR_PTR(err);
3882 + goto out;
3883 + }
3884 + hidden_root2 = nd2.dentry;
3885 + stopd(sb)->storage_dir_dentry = nd2.dentry;
3886 + stopd(sb)->hidden_mnt2 = nd2.mnt;
3887 + stohs2(sb) = hidden_root2->d_sb;
3888 +
3889 + /* validate storage dir, this is done in
3890 + * mini_fo_read_super for the base directory.
3891 + */
3892 + if (IS_ERR(hidden_root2)) {
3893 + printk(KERN_WARNING "mini_fo_parse_options: storage dentry lookup failed (err = %ld)\n", PTR_ERR(hidden_root2));
3894 + goto out;
3895 + }
3896 + if (!hidden_root2->d_inode) {
3897 + printk(KERN_WARNING "mini_fo_parse_options: no storage dir to interpose on.\n");
3898 + goto out;
3899 + }
3900 + stohs2(sb) = hidden_root2->d_sb;
3901 + } else {
3902 + printk(KERN_WARNING "mini_fo: unrecognized option '%s'\n", options);
3903 + hidden_root = ERR_PTR(-EINVAL);
3904 + goto out;
3905 + }
3906 + options = tmp + 1;
3907 + }
3908 +
3909 + out:
3910 + if(IS_ERR(hidden_root2))
3911 + return hidden_root2;
3912 + return hidden_root;
3913 +}
3914 +
3915 +
3916 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
3917 +static int
3918 +#else
3919 +super_block_t *
3920 +#endif
3921 +mini_fo_read_super(super_block_t *sb, void *raw_data, int silent)
3922 +{
3923 + dentry_t *hidden_root;
3924 + int err = 0;
3925 +
3926 + if (!raw_data) {
3927 + printk(KERN_WARNING "mini_fo_read_super: missing argument\n");
3928 + err = -EINVAL;
3929 + goto out;
3930 + }
3931 + /*
3932 + * Allocate superblock private data
3933 + */
3934 + __stopd(sb) = kmalloc(sizeof(struct mini_fo_sb_info), GFP_KERNEL);
3935 + if (!stopd(sb)) {
3936 + printk(KERN_WARNING "%s: out of memory\n", __FUNCTION__);
3937 + err = -ENOMEM;
3938 + goto out;
3939 + }
3940 + stohs(sb) = NULL;
3941 +
3942 + hidden_root = mini_fo_parse_options(sb, raw_data);
3943 + if (IS_ERR(hidden_root)) {
3944 + printk(KERN_WARNING "mini_fo_read_super: lookup_dentry failed (err = %ld)\n", PTR_ERR(hidden_root));
3945 + err = PTR_ERR(hidden_root);
3946 + goto out_free;
3947 + }
3948 + if (!hidden_root->d_inode) {
3949 + printk(KERN_WARNING "mini_fo_read_super: no directory to interpose on\n");
3950 + goto out_free;
3951 + }
3952 + stohs(sb) = hidden_root->d_sb;
3953 +
3954 + /*
3955 + * Linux 2.4.2-ac3 and beyond has code in
3956 + * mm/filemap.c:generic_file_write() that requires sb->s_maxbytes
3957 + * to be populated. If not set, all write()s under that sb will
3958 + * return 0.
3959 + *
3960 + * Linux 2.4.4+ automatically sets s_maxbytes to MAX_NON_LFS;
3961 + * the filesystem should override it only if it supports LFS.
3962 + */
3963 + /* non-SCA code is good to go with LFS */
3964 + sb->s_maxbytes = hidden_root->d_sb->s_maxbytes;
3965 +
3966 + sb->s_op = &mini_fo_sops;
3967 + /*
3968 + * we can't use d_alloc_root if we want to use
3969 + * our own interpose function unchanged,
3970 + * so we simply replicate *most* of the code in d_alloc_root here
3971 + */
3972 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
3973 + sb->s_root = d_alloc(NULL, &(const struct qstr) { "/", 1, 0 });
3974 +#else
3975 + sb->s_root = d_alloc(NULL, &(const struct qstr){hash: 0, name: "/", len : 1});
3976 +#endif
3977 + if (IS_ERR(sb->s_root)) {
3978 + printk(KERN_WARNING "mini_fo_read_super: d_alloc failed\n");
3979 + err = -ENOMEM;
3980 + goto out_dput;
3981 + }
3982 +
3983 + sb->s_root->d_op = &mini_fo_dops;
3984 + sb->s_root->d_sb = sb;
3985 + sb->s_root->d_parent = sb->s_root;
3986 +
3987 + /* link the upper and lower dentries */
3988 + __dtopd(sb->s_root) = (struct mini_fo_dentry_info *)
3989 + kmalloc(sizeof(struct mini_fo_dentry_info), GFP_KERNEL);
3990 + if (!dtopd(sb->s_root)) {
3991 + err = -ENOMEM;
3992 + goto out_dput2;
3993 + }
3994 + dtopd(sb->s_root)->state = MODIFIED;
3995 + dtohd(sb->s_root) = hidden_root;
3996 +
3997 + /* fanout relevant, interpose on storage root dentry too */
3998 + dtohd2(sb->s_root) = stopd(sb)->storage_dir_dentry;
3999 +
4000 + /* ...and call tri-interpose to interpose root dir inodes
4001 + * if (mini_fo_interpose(hidden_root, sb->s_root, sb, 0))
4002 + */
4003 + if(mini_fo_tri_interpose(hidden_root, dtohd2(sb->s_root), sb->s_root, sb, 0))
4004 + goto out_dput2;
4005 +
4006 + /* initalize the wol list */
4007 + itopd(sb->s_root->d_inode)->deleted_list_size = -1;
4008 + itopd(sb->s_root->d_inode)->renamed_list_size = -1;
4009 + meta_build_lists(sb->s_root);
4010 +
4011 + goto out;
4012 +
4013 + out_dput2:
4014 + dput(sb->s_root);
4015 + out_dput:
4016 + dput(hidden_root);
4017 + dput(dtohd2(sb->s_root)); /* release the hidden_sto_dentry too */
4018 + out_free:
4019 + kfree(stopd(sb));
4020 + __stopd(sb) = NULL;
4021 + out:
4022 +
4023 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
4024 + return err;
4025 +#else
4026 + if (err) {
4027 + return ERR_PTR(err);
4028 + } else {
4029 + return sb;
4030 + }
4031 +#endif
4032 +}
4033 +
4034 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
4035 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,18)
4036 +static int mini_fo_get_sb(struct file_system_type *fs_type,
4037 + int flags, const char *dev_name,
4038 + void *raw_data, struct vfsmount *mnt)
4039 +{
4040 + return get_sb_nodev(fs_type, flags, raw_data, mini_fo_read_super, mnt);
4041 +}
4042 +#else
4043 +static struct super_block *mini_fo_get_sb(struct file_system_type *fs_type,
4044 + int flags, const char *dev_name,
4045 + void *raw_data)
4046 +{
4047 + return get_sb_nodev(fs_type, flags, raw_data, mini_fo_read_super);
4048 +}
4049 +#endif
4050 +
4051 +void mini_fo_kill_block_super(struct super_block *sb)
4052 +{
4053 + generic_shutdown_super(sb);
4054 + /*
4055 + * XXX: BUG: Halcrow: Things get unstable sometime after this point:
4056 + * lib/rwsem-spinlock.c:127: spin_is_locked on uninitialized
4057 + * fs/fs-writeback.c:402: spin_lock(fs/super.c:a0381828) already
4058 + * locked by fs/fs-writeback.c/402
4059 + *
4060 + * Apparently, someone's not releasing a lock on sb_lock...
4061 + */
4062 +}
4063 +
4064 +static struct file_system_type mini_fo_fs_type = {
4065 + .owner = THIS_MODULE,
4066 + .name = "mini_fo",
4067 + .get_sb = mini_fo_get_sb,
4068 + .kill_sb = mini_fo_kill_block_super,
4069 + .fs_flags = 0,
4070 +};
4071 +
4072 +
4073 +#else
4074 +static DECLARE_FSTYPE(mini_fo_fs_type, "mini_fo", mini_fo_read_super, 0);
4075 +#endif
4076 +
4077 +static int __init init_mini_fo_fs(void)
4078 +{
4079 + printk("Registering mini_fo version $Id$\n");
4080 + return register_filesystem(&mini_fo_fs_type);
4081 +}
4082 +static void __exit exit_mini_fo_fs(void)
4083 +{
4084 + printk("Unregistering mini_fo version $Id$\n");
4085 + unregister_filesystem(&mini_fo_fs_type);
4086 +}
4087 +
4088 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
4089 +EXPORT_NO_SYMBOLS;
4090 +#endif
4091 +
4092 +MODULE_AUTHOR("Erez Zadok <ezk@cs.sunysb.edu>");
4093 +MODULE_DESCRIPTION("FiST-generated mini_fo filesystem");
4094 +MODULE_LICENSE("GPL");
4095 +
4096 +/* MODULE_PARM(fist_debug_var, "i"); */
4097 +/* MODULE_PARM_DESC(fist_debug_var, "Debug level"); */
4098 +
4099 +module_init(init_mini_fo_fs)
4100 +module_exit(exit_mini_fo_fs)
4101 --- /dev/null
4102 +++ b/fs/mini_fo/Makefile
4103 @@ -0,0 +1,17 @@
4104 +#
4105 +# Makefile for mini_fo 2.4 and 2.6 Linux kernels
4106 +#
4107 +# Copyright (C) 2004, 2005 Markus Klotzbuecher <mk@creamnet.de>
4108 +#
4109 +# This program is free software; you can redistribute it and/or
4110 +# modify it under the terms of the GNU General Public License
4111 +# as published by the Free Software Foundation; either version
4112 +# 2 of the License, or (at your option) any later version.
4113 +#
4114 +
4115 +obj-$(CONFIG_MINI_FO) := mini_fo.o
4116 +mini_fo-objs := meta.o dentry.o file.o inode.o main.o super.o state.o aux.o
4117 +
4118 +# dependencies
4119 +${mini_fo-objs}: mini_fo.h fist.h
4120 +
4121 --- /dev/null
4122 +++ b/fs/mini_fo/meta.c
4123 @@ -0,0 +1,1000 @@
4124 +/*
4125 + * Copyright (C) 2004, 2005 Markus Klotzbuecher <mk@creamnet.de>
4126 + *
4127 + * This program is free software; you can redistribute it and/or
4128 + * modify it under the terms of the GNU General Public License
4129 + * as published by the Free Software Foundation; either version
4130 + * 2 of the License, or (at your option) any later version.
4131 + */
4132 +
4133 +#ifdef HAVE_CONFIG_H
4134 +# include <config.h>
4135 +#endif /* HAVE_CONFIG_H */
4136 +#include "fist.h"
4137 +#include "mini_fo.h"
4138 +
4139 +int meta_build_lists(dentry_t *dentry)
4140 +{
4141 + struct mini_fo_inode_info *inode_info;
4142 +
4143 + dentry_t *meta_dentry = 0;
4144 + file_t *meta_file = 0;
4145 + mm_segment_t old_fs;
4146 + void *buf;
4147 +
4148 + int bytes, len;
4149 + struct vfsmount *meta_mnt;
4150 + char *entry;
4151 +
4152 + inode_info = itopd(dentry->d_inode);
4153 + if(!(inode_info->deleted_list_size == -1 &&
4154 + inode_info->renamed_list_size == -1)) {
4155 + printk(KERN_CRIT "mini_fo: meta_build_lists: \
4156 + Error, list(s) not virgin.\n");
4157 + return -1;
4158 + }
4159 +
4160 + /* init our meta lists */
4161 + INIT_LIST_HEAD(&inode_info->deleted_list);
4162 + inode_info->deleted_list_size = 0;
4163 +
4164 + INIT_LIST_HEAD(&inode_info->renamed_list);
4165 + inode_info->renamed_list_size = 0;
4166 +
4167 + /* might there be a META-file? */
4168 + if(dtohd2(dentry) && dtohd2(dentry)->d_inode) {
4169 + meta_dentry = lookup_one_len(META_FILENAME,
4170 + dtohd2(dentry),
4171 + strlen(META_FILENAME));
4172 + if(!meta_dentry->d_inode) {
4173 + dput(meta_dentry);
4174 + goto out_ok;
4175 + }
4176 + /* $%& err, is this correct? */
4177 + meta_mnt = stopd(dentry->d_inode->i_sb)->hidden_mnt2;
4178 + mntget(meta_mnt);
4179 +
4180 +
4181 + /* open META-file for reading */
4182 + meta_file = dentry_open(meta_dentry, meta_mnt, 0x0);
4183 + if(!meta_file || IS_ERR(meta_file)) {
4184 + printk(KERN_CRIT "mini_fo: meta_build_lists: \
4185 + ERROR opening META file.\n");
4186 + goto out_err;
4187 + }
4188 +
4189 + /* check if fs supports reading */
4190 + if(!meta_file->f_op->read) {
4191 + printk(KERN_CRIT "mini_fo: meta_build_lists: \
4192 + ERROR, fs does not support reading.\n");
4193 + goto out_err_close;
4194 + }
4195 +
4196 + /* allocate a page for transfering the data */
4197 + buf = (void *) __get_free_page(GFP_KERNEL);
4198 + if(!buf) {
4199 + printk(KERN_CRIT "mini_fo: meta_build_lists: \
4200 + ERROR, out of mem.\n");
4201 + goto out_err_close;
4202 + }
4203 + meta_file->f_pos = 0;
4204 + old_fs = get_fs();
4205 + set_fs(KERNEL_DS);
4206 + do {
4207 + char *c;
4208 + bytes = meta_file->f_op->read(meta_file, buf, PAGE_SIZE, &meta_file->f_pos);
4209 + if(bytes == PAGE_SIZE) {
4210 + /* trim a cut off filename and adjust f_pos to get it next time */
4211 + for(c = (char*) buf+PAGE_SIZE;
4212 + *c != '\n';
4213 + c--, bytes--, meta_file->f_pos--);
4214 + }
4215 + entry = (char *) buf;
4216 + while(entry < (char *) buf+bytes) {
4217 +
4218 + char *old_path;
4219 + char *dir_name;
4220 + int old_len, new_len;
4221 +
4222 + /* len without '\n'*/
4223 + len = (int) (strchr(entry, '\n') - entry);
4224 + switch (*entry) {
4225 + case 'D':
4226 + /* format: "D filename" */
4227 + meta_list_add_d_entry(dentry,
4228 + entry+2,
4229 + len-2);
4230 + break;
4231 + case 'R':
4232 + /* format: "R path/xy/dir newDir" */
4233 + old_path = entry+2;
4234 + dir_name = strchr(old_path, ' ') + 1;
4235 + old_len = dir_name - old_path - 1;
4236 + new_len = ((int) entry) + len - ((int ) dir_name);
4237 + meta_list_add_r_entry(dentry,
4238 + old_path,
4239 + old_len,
4240 + dir_name,
4241 + new_len);
4242 + break;
4243 + default:
4244 + /* unknown entry type detected */
4245 + break;
4246 + }
4247 + entry += len+1;
4248 + }
4249 +
4250 + } while(meta_file->f_pos < meta_dentry->d_inode->i_size);
4251 +
4252 + free_page((unsigned long) buf);
4253 + set_fs(old_fs);
4254 + fput(meta_file);
4255 + }
4256 + goto out_ok;
4257 +
4258 + out_err_close:
4259 + fput(meta_file);
4260 + out_err:
4261 + mntput(meta_mnt);
4262 + dput(meta_dentry);
4263 + return -1;
4264 + out_ok:
4265 + return 1; /* check this!!! inode_info->wol_size; */
4266 +}
4267 +
4268 +/* cleanups up all lists and free's the mem by dentry */
4269 +int meta_put_lists(dentry_t *dentry)
4270 +{
4271 + if(!dentry || !dentry->d_inode) {
4272 + printk("mini_fo: meta_put_lists: invalid dentry passed.\n");
4273 + return -1;
4274 + }
4275 + return __meta_put_lists(dentry->d_inode);
4276 +}
4277 +
4278 +/* cleanups up all lists and free's the mem by inode */
4279 +int __meta_put_lists(inode_t *inode)
4280 +{
4281 + int err = 0;
4282 + if(!inode || !itopd(inode)) {
4283 + printk("mini_fo: __meta_put_lists: invalid inode passed.\n");
4284 + return -1;
4285 + }
4286 + err = __meta_put_d_list(inode);
4287 + err |= __meta_put_r_list(inode);
4288 + return err;
4289 +}
4290 +
4291 +int meta_sync_lists(dentry_t *dentry)
4292 +{
4293 + int err = 0;
4294 + if(!dentry || !dentry->d_inode) {
4295 + printk("mini_fo: meta_sync_lists: \
4296 + invalid dentry passed.\n");
4297 + return -1;
4298 + }
4299 + err = meta_sync_d_list(dentry, 0);
4300 + err |= meta_sync_r_list(dentry, 1);
4301 + return err;
4302 +}
4303 +
4304 +
4305 +/* remove all D entries from the renamed list and free the mem */
4306 +int __meta_put_d_list(inode_t *inode)
4307 +{
4308 + struct list_head *tmp;
4309 + struct deleted_entry *del_entry;
4310 + struct mini_fo_inode_info *inode_info;
4311 +
4312 + if(!inode || !itopd(inode)) {
4313 + printk(KERN_CRIT "mini_fo: __meta_put_d_list: \
4314 + invalid inode passed.\n");
4315 + return -1;
4316 + }
4317 + inode_info = itopd(inode);
4318 +
4319 + /* nuke the DELETED-list */
4320 + if(inode_info->deleted_list_size <= 0)
4321 + return 0;
4322 +
4323 + while(!list_empty(&inode_info->deleted_list)) {
4324 + tmp = inode_info->deleted_list.next;
4325 + list_del(tmp);
4326 + del_entry = list_entry(tmp, struct deleted_entry, list);
4327 + kfree(del_entry->name);
4328 + kfree(del_entry);
4329 + }
4330 + inode_info->deleted_list_size = 0;
4331 +
4332 + return 0;
4333 +}
4334 +
4335 +/* remove all R entries from the renamed list and free the mem */
4336 +int __meta_put_r_list(inode_t *inode)
4337 +{
4338 + struct list_head *tmp;
4339 + struct renamed_entry *ren_entry;
4340 + struct mini_fo_inode_info *inode_info;
4341 +
4342 + if(!inode || !itopd(inode)) {
4343 + printk(KERN_CRIT "mini_fo: meta_put_r_list: invalid inode.\n");
4344 + return -1;
4345 + }
4346 + inode_info = itopd(inode);
4347 +
4348 + /* nuke the RENAMED-list */
4349 + if(inode_info->renamed_list_size <= 0)
4350 + return 0;
4351 +
4352 + while(!list_empty(&inode_info->renamed_list)) {
4353 + tmp = inode_info->renamed_list.next;
4354 + list_del(tmp);
4355 + ren_entry = list_entry(tmp, struct renamed_entry, list);
4356 + kfree(ren_entry->new_name);
4357 + kfree(ren_entry->old_name);
4358 + kfree(ren_entry);
4359 + }
4360 + inode_info->renamed_list_size = 0;
4361 +
4362 + return 0;
4363 +}
4364 +
4365 +int meta_add_d_entry(dentry_t *dentry, const char *name, int len)
4366 +{
4367 + int err = 0;
4368 + err = meta_list_add_d_entry(dentry, name, len);
4369 + err |= meta_write_d_entry(dentry,name,len);
4370 + return err;
4371 +}
4372 +
4373 +/* add a D entry to the deleted list */
4374 +int meta_list_add_d_entry(dentry_t *dentry, const char *name, int len)
4375 +{
4376 + struct deleted_entry *del_entry;
4377 + struct mini_fo_inode_info *inode_info;
4378 +
4379 + if(!dentry || !dentry->d_inode) {
4380 + printk(KERN_CRIT "mini_fo: meta_list_add_d_entry: \
4381 + invalid dentry passed.\n");
4382 + return -1;
4383 + }
4384 + inode_info = itopd(dentry->d_inode);
4385 +
4386 + if(inode_info->deleted_list_size < 0)
4387 + return -1;
4388 +
4389 + del_entry = (struct deleted_entry *)
4390 + kmalloc(sizeof(struct deleted_entry), GFP_KERNEL);
4391 + del_entry->name = (char*) kmalloc(len, GFP_KERNEL);
4392 + if(!del_entry || !del_entry->name) {
4393 + printk(KERN_CRIT "mini_fo: meta_list_add_d_entry: \
4394 + out of mem.\n");
4395 + kfree(del_entry->name);
4396 + kfree(del_entry);
4397 + return -ENOMEM;
4398 + }
4399 +
4400 + strncpy(del_entry->name, name, len);
4401 + del_entry->len = len;
4402 +
4403 + list_add(&del_entry->list, &inode_info->deleted_list);
4404 + inode_info->deleted_list_size++;
4405 + return 0;
4406 +}
4407 +
4408 +int meta_add_r_entry(dentry_t *dentry,
4409 + const char *old_name, int old_len,
4410 + const char *new_name, int new_len)
4411 +{
4412 + int err = 0;
4413 + err = meta_list_add_r_entry(dentry,
4414 + old_name, old_len,
4415 + new_name, new_len);
4416 + err |= meta_write_r_entry(dentry,
4417 + old_name, old_len,
4418 + new_name, new_len);
4419 + return err;
4420 +}
4421 +
4422 +/* add a R entry to the renamed list */
4423 +int meta_list_add_r_entry(dentry_t *dentry,
4424 + const char *old_name, int old_len,
4425 + const char *new_name, int new_len)
4426 +{
4427 + struct renamed_entry *ren_entry;
4428 + struct mini_fo_inode_info *inode_info;
4429 +
4430 + if(!dentry || !dentry->d_inode) {
4431 + printk(KERN_CRIT "mini_fo: meta_list_add_r_entry: \
4432 + invalid dentry passed.\n");
4433 + return -1;
4434 + }
4435 + inode_info = itopd(dentry->d_inode);
4436 +
4437 + if(inode_info->renamed_list_size < 0)
4438 + return -1;
4439 +
4440 + ren_entry = (struct renamed_entry *)
4441 + kmalloc(sizeof(struct renamed_entry), GFP_KERNEL);
4442 + ren_entry->old_name = (char*) kmalloc(old_len, GFP_KERNEL);
4443 + ren_entry->new_name = (char*) kmalloc(new_len, GFP_KERNEL);
4444 +
4445 + if(!ren_entry || !ren_entry->old_name || !ren_entry->new_name) {
4446 + printk(KERN_CRIT "mini_fo: meta_list_add_r_entry: \
4447 + out of mem.\n");
4448 + kfree(ren_entry->new_name);
4449 + kfree(ren_entry->old_name);
4450 + kfree(ren_entry);
4451 + return -ENOMEM;
4452 + }
4453 +
4454 + strncpy(ren_entry->old_name, old_name, old_len);
4455 + ren_entry->old_len = old_len;
4456 + strncpy(ren_entry->new_name, new_name, new_len);
4457 + ren_entry->new_len = new_len;
4458 +
4459 + list_add(&ren_entry->list, &inode_info->renamed_list);
4460 + inode_info->renamed_list_size++;
4461 + return 0;
4462 +}
4463 +
4464 +
4465 +int meta_remove_r_entry(dentry_t *dentry, const char *name, int len)
4466 +{
4467 + int err = 0;
4468 + if(!dentry || !dentry->d_inode) {
4469 + printk(KERN_CRIT
4470 + "mini_fo: meta_remove_r_entry: \
4471 + invalid dentry passed.\n");
4472 + return -1;
4473 + }
4474 +
4475 + err = meta_list_remove_r_entry(dentry, name, len);
4476 + err |= meta_sync_lists(dentry);
4477 + return err;
4478 +}
4479 +
4480 +int meta_list_remove_r_entry(dentry_t *dentry, const char *name, int len)
4481 +{
4482 + if(!dentry || !dentry->d_inode) {
4483 + printk(KERN_CRIT
4484 + "mini_fo: meta_list_remove_r_entry: \
4485 + invalid dentry passed.\n");
4486 + return -1;
4487 + }
4488 + return __meta_list_remove_r_entry(dentry->d_inode, name, len);
4489 +}
4490 +
4491 +int __meta_list_remove_r_entry(inode_t *inode, const char *name, int len)
4492 +{
4493 + struct list_head *tmp;
4494 + struct renamed_entry *ren_entry;
4495 + struct mini_fo_inode_info *inode_info;
4496 +
4497 + if(!inode || !itopd(inode))
4498 + printk(KERN_CRIT
4499 + "mini_fo: __meta_list_remove_r_entry: \
4500 + invalid inode passed.\n");
4501 + inode_info = itopd(inode);
4502 +
4503 + if(inode_info->renamed_list_size < 0)
4504 + return -1;
4505 + if(inode_info->renamed_list_size == 0)
4506 + return 1;
4507 +
4508 + list_for_each(tmp, &inode_info->renamed_list) {
4509 + ren_entry = list_entry(tmp, struct renamed_entry, list);
4510 + if(ren_entry->new_len != len)
4511 + continue;
4512 +
4513 + if(!strncmp(ren_entry->new_name, name, len)) {
4514 + list_del(tmp);
4515 + kfree(ren_entry->new_name);
4516 + kfree(ren_entry->old_name);
4517 + kfree(ren_entry);
4518 + inode_info->renamed_list_size--;
4519 + return 0;
4520 + }
4521 + }
4522 + return 1;
4523 +}
4524 +
4525 +
4526 +/* append a single D entry to the meta file */
4527 +int meta_write_d_entry(dentry_t *dentry, const char *name, int len)
4528 +{
4529 + dentry_t *meta_dentry = 0;
4530 + file_t *meta_file = 0;
4531 + mm_segment_t old_fs;
4532 +
4533 + int bytes, err;
4534 + struct vfsmount *meta_mnt = 0;
4535 + char *buf;
4536 +
4537 + err = 0;
4538 +
4539 + if(itopd(dentry->d_inode)->deleted_list_size < 0) {
4540 + err = -1;
4541 + goto out;
4542 + }
4543 +
4544 + if(dtopd(dentry)->state == UNMODIFIED) {
4545 + err = build_sto_structure(dentry->d_parent, dentry);
4546 + if(err) {
4547 + printk(KERN_CRIT "mini_fo: meta_write_d_entry: \
4548 + build_sto_structure failed.\n");
4549 + goto out;
4550 + }
4551 + }
4552 + meta_dentry = lookup_one_len(META_FILENAME,
4553 + dtohd2(dentry), strlen (META_FILENAME));
4554 +
4555 + /* We need to create a META-file */
4556 + if(!meta_dentry->d_inode) {
4557 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
4558 + vfs_create(dtohd2(dentry)->d_inode,
4559 + meta_dentry,
4560 + S_IRUSR | S_IWUSR,
4561 + NULL);
4562 +#else
4563 + vfs_create(dtohd2(dentry)->d_inode,
4564 + meta_dentry,
4565 + S_IRUSR | S_IWUSR);
4566 +#endif
4567 + }
4568 + /* open META-file for writing */
4569 + meta_file = dentry_open(meta_dentry, meta_mnt, 0x1);
4570 + if(!meta_file || IS_ERR(meta_file)) {
4571 + printk(KERN_CRIT "mini_fo: meta_write_d_entry: \
4572 + ERROR opening meta file.\n");
4573 + mntput(meta_mnt); /* $%& is this necessary? */
4574 + dput(meta_dentry);
4575 + err = -1;
4576 + goto out;
4577 + }
4578 +
4579 + /* check if fs supports writing */
4580 + if(!meta_file->f_op->write) {
4581 + printk(KERN_CRIT "mini_fo: meta_write_d_entry: \
4582 + ERROR, fs does not support writing.\n");
4583 + goto out_err_close;
4584 + }
4585 +
4586 + meta_file->f_pos = meta_dentry->d_inode->i_size; /* append */
4587 + old_fs = get_fs();
4588 + set_fs(KERNEL_DS);
4589 +
4590 + /* size: len for name, 1 for \n and 2 for "D " */
4591 + buf = (char *) kmalloc(len+3, GFP_KERNEL);
4592 + if (!buf) {
4593 + printk(KERN_CRIT "mini_fo: meta_write_d_entry: \
4594 + out of mem.\n");
4595 + return -ENOMEM;
4596 + }
4597 +
4598 + buf[0] = 'D';
4599 + buf[1] = ' ';
4600 + strncpy(buf+2, name, len);
4601 + buf[len+2] = '\n';
4602 + bytes = meta_file->f_op->write(meta_file, buf, len+3,
4603 + &meta_file->f_pos);
4604 + if(bytes != len+3) {
4605 + printk(KERN_CRIT "mini_fo: meta_write_d_entry: \
4606 + ERROR writing.\n");
4607 + err = -1;
4608 + }
4609 + kfree(buf);
4610 + set_fs(old_fs);
4611 +
4612 + out_err_close:
4613 + fput(meta_file);
4614 + out:
4615 + return err;
4616 +}
4617 +
4618 +/* append a single R entry to the meta file */
4619 +int meta_write_r_entry(dentry_t *dentry,
4620 + const char *old_name, int old_len,
4621 + const char *new_name, int new_len)
4622 +{
4623 + dentry_t *meta_dentry = 0;
4624 + file_t *meta_file = 0;
4625 + mm_segment_t old_fs;
4626 +
4627 + int bytes, err, buf_len;
4628 + struct vfsmount *meta_mnt = 0;
4629 + char *buf;
4630 +
4631 +
4632 + err = 0;
4633 +
4634 + if(itopd(dentry->d_inode)->renamed_list_size < 0) {
4635 + err = -1;
4636 + goto out;
4637 + }
4638 +
4639 + /* build the storage structure? */
4640 + if(dtopd(dentry)->state == UNMODIFIED) {
4641 + err = build_sto_structure(dentry->d_parent, dentry);
4642 + if(err) {
4643 + printk(KERN_CRIT "mini_fo: meta_write_r_entry: \
4644 + build_sto_structure failed.\n");
4645 + goto out;
4646 + }
4647 + }
4648 + meta_dentry = lookup_one_len(META_FILENAME,
4649 + dtohd2(dentry),
4650 + strlen (META_FILENAME));
4651 + if(!meta_dentry->d_inode) {
4652 + /* We need to create a META-file */
4653 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
4654 + vfs_create(dtohd2(dentry)->d_inode,
4655 + meta_dentry, S_IRUSR | S_IWUSR, NULL);
4656 +#else
4657 + vfs_create(dtohd2(dentry)->d_inode,
4658 + meta_dentry, S_IRUSR | S_IWUSR);
4659 +#endif
4660 + }
4661 + /* open META-file for writing */
4662 + meta_file = dentry_open(meta_dentry, meta_mnt, 0x1);
4663 + if(!meta_file || IS_ERR(meta_file)) {
4664 + printk(KERN_CRIT "mini_fo: meta_write_r_entry: \
4665 + ERROR opening meta file.\n");
4666 + mntput(meta_mnt);
4667 + dput(meta_dentry);
4668 + err = -1;
4669 + goto out;
4670 + }
4671 +
4672 + /* check if fs supports writing */
4673 + if(!meta_file->f_op->write) {
4674 + printk(KERN_CRIT "mini_fo: meta_write_r_entry: \
4675 + ERROR, fs does not support writing.\n");
4676 + goto out_err_close;
4677 + }
4678 +
4679 + meta_file->f_pos = meta_dentry->d_inode->i_size; /* append */
4680 + old_fs = get_fs();
4681 + set_fs(KERNEL_DS);
4682 +
4683 + /* size: 2 for "R ", old_len+new_len for names, 1 blank+1 \n */
4684 + buf_len = old_len + new_len + 4;
4685 + buf = (char *) kmalloc(buf_len, GFP_KERNEL);
4686 + if (!buf) {
4687 + printk(KERN_CRIT "mini_fo: meta_write_r_entry: out of mem.\n");
4688 + return -ENOMEM;
4689 + }
4690 +
4691 + buf[0] = 'R';
4692 + buf[1] = ' ';
4693 + strncpy(buf + 2, old_name, old_len);
4694 + buf[old_len + 2] = ' ';
4695 + strncpy(buf + old_len + 3, new_name, new_len);
4696 + buf[buf_len -1] = '\n';
4697 + bytes = meta_file->f_op->write(meta_file, buf, buf_len, &meta_file->f_pos);
4698 + if(bytes != buf_len) {
4699 + printk(KERN_CRIT "mini_fo: meta_write_r_entry: ERROR writing.\n");
4700 + err = -1;
4701 + }
4702 +
4703 + kfree(buf);
4704 + set_fs(old_fs);
4705 +
4706 + out_err_close:
4707 + fput(meta_file);
4708 + out:
4709 + return err;
4710 +}
4711 +
4712 +/* sync D list to disk, append data if app_flag is 1 */
4713 +/* check the meta_mnt, which seems not to be used (properly) */
4714 +
4715 +int meta_sync_d_list(dentry_t *dentry, int app_flag)
4716 +{
4717 + dentry_t *meta_dentry;
4718 + file_t *meta_file;
4719 + mm_segment_t old_fs;
4720 +
4721 + int bytes, err;
4722 + struct vfsmount *meta_mnt;
4723 + char *buf;
4724 +
4725 + struct list_head *tmp;
4726 + struct deleted_entry *del_entry;
4727 + struct mini_fo_inode_info *inode_info;
4728 +
4729 + err = 0;
4730 + meta_file=0;
4731 + meta_mnt=0;
4732 +
4733 + if(!dentry || !dentry->d_inode) {
4734 + printk(KERN_CRIT "mini_fo: meta_sync_d_list: \
4735 + invalid inode passed.\n");
4736 + err = -1;
4737 + goto out;
4738 + }
4739 + inode_info = itopd(dentry->d_inode);
4740 +
4741 + if(inode_info->deleted_list_size < 0) {
4742 + err = -1;
4743 + goto out;
4744 + }
4745 +
4746 + /* ok, there is something to sync */
4747 +
4748 + /* build the storage structure? */
4749 + if(!dtohd2(dentry) && !itohi2(dentry->d_inode)) {
4750 + err = build_sto_structure(dentry->d_parent, dentry);
4751 + if(err) {
4752 + printk(KERN_CRIT "mini_fo: meta_sync_d_list: \
4753 + build_sto_structure failed.\n");
4754 + goto out;
4755 + }
4756 + }
4757 + meta_dentry = lookup_one_len(META_FILENAME,
4758 + dtohd2(dentry),
4759 + strlen(META_FILENAME));
4760 + if(!meta_dentry->d_inode) {
4761 + /* We need to create a META-file */
4762 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
4763 + vfs_create(dtohd2(dentry)->d_inode,
4764 + meta_dentry, S_IRUSR | S_IWUSR, NULL);
4765 +#else
4766 + vfs_create(dtohd2(dentry)->d_inode,
4767 + meta_dentry, S_IRUSR | S_IWUSR);
4768 +#endif
4769 + app_flag = 0;
4770 + }
4771 + /* need we truncate the meta file? */
4772 + if(!app_flag) {
4773 + struct iattr newattrs;
4774 + newattrs.ia_size = 0;
4775 + newattrs.ia_valid = ATTR_SIZE | ATTR_CTIME;
4776 +
4777 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
4778 + mutex_lock(&meta_dentry->d_inode->i_mutex);
4779 +#else
4780 + down(&meta_dentry->d_inode->i_sem);
4781 +#endif
4782 + err = notify_change(meta_dentry, &newattrs);
4783 +
4784 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
4785 + mutex_unlock(&meta_dentry->d_inode->i_mutex);
4786 +#else
4787 + up(&meta_dentry->d_inode->i_sem);
4788 +#endif
4789 +
4790 + if(err || meta_dentry->d_inode->i_size != 0) {
4791 + printk(KERN_CRIT "mini_fo: meta_sync_d_list: \
4792 + ERROR truncating meta file.\n");
4793 + goto out_err_close;
4794 + }
4795 + }
4796 +
4797 + /* open META-file for writing */
4798 + meta_file = dentry_open(meta_dentry, meta_mnt, 0x1);
4799 + if(!meta_file || IS_ERR(meta_file)) {
4800 + printk(KERN_CRIT "mini_fo: meta_sync_d_list: \
4801 + ERROR opening meta file.\n");
4802 + /* we don't mntget so we dont't mntput (for now)
4803 + * mntput(meta_mnt);
4804 + */
4805 + dput(meta_dentry);
4806 + err = -1;
4807 + goto out;
4808 + }
4809 +
4810 + /* check if fs supports writing */
4811 + if(!meta_file->f_op->write) {
4812 + printk(KERN_CRIT "mini_fo: meta_sync_d_list: \
4813 + ERROR, fs does not support writing.\n");
4814 + goto out_err_close;
4815 + }
4816 +
4817 + meta_file->f_pos = meta_dentry->d_inode->i_size; /* append */
4818 + old_fs = get_fs();
4819 + set_fs(KERNEL_DS);
4820 +
4821 + /* here we go... */
4822 + list_for_each(tmp, &inode_info->deleted_list) {
4823 + del_entry = list_entry(tmp, struct deleted_entry, list);
4824 +
4825 + /* size: len for name, 1 for \n and 2 for "D " */
4826 + buf = (char *) kmalloc(del_entry->len+3, GFP_KERNEL);
4827 + if (!buf) {
4828 + printk(KERN_CRIT "mini_fo: meta_sync_d_list: \
4829 + out of mem.\n");
4830 + return -ENOMEM;
4831 + }
4832 +
4833 + buf[0] = 'D';
4834 + buf[1] = ' ';
4835 + strncpy(buf+2, del_entry->name, del_entry->len);
4836 + buf[del_entry->len+2] = '\n';
4837 + bytes = meta_file->f_op->write(meta_file, buf,
4838 + del_entry->len+3,
4839 + &meta_file->f_pos);
4840 + if(bytes != del_entry->len+3) {
4841 + printk(KERN_CRIT "mini_fo: meta_sync_d_list: \
4842 + ERROR writing.\n");
4843 + err |= -1;
4844 + }
4845 + kfree(buf);
4846 + }
4847 + set_fs(old_fs);
4848 +
4849 + out_err_close:
4850 + fput(meta_file);
4851 + out:
4852 + return err;
4853 +
4854 +}
4855 +
4856 +int meta_sync_r_list(dentry_t *dentry, int app_flag)
4857 +{
4858 + dentry_t *meta_dentry;
4859 + file_t *meta_file;
4860 + mm_segment_t old_fs;
4861 +
4862 + int bytes, err, buf_len;
4863 + struct vfsmount *meta_mnt;
4864 + char *buf;
4865 +
4866 + struct list_head *tmp;
4867 + struct renamed_entry *ren_entry;
4868 + struct mini_fo_inode_info *inode_info;
4869 +
4870 + err = 0;
4871 + meta_file=0;
4872 + meta_mnt=0;
4873 +
4874 + if(!dentry || !dentry->d_inode) {
4875 + printk(KERN_CRIT "mini_fo: meta_sync_r_list: \
4876 + invalid dentry passed.\n");
4877 + err = -1;
4878 + goto out;
4879 + }
4880 + inode_info = itopd(dentry->d_inode);
4881 +
4882 + if(inode_info->deleted_list_size < 0) {
4883 + err = -1;
4884 + goto out;
4885 + }
4886 +
4887 + /* ok, there is something to sync */
4888 +
4889 + /* build the storage structure? */
4890 + if(!dtohd2(dentry) && !itohi2(dentry->d_inode)) {
4891 + err = build_sto_structure(dentry->d_parent, dentry);
4892 + if(err) {
4893 + printk(KERN_CRIT "mini_fo: meta_sync_r_list: \
4894 + build_sto_structure failed.\n");
4895 + goto out;
4896 + }
4897 + }
4898 + meta_dentry = lookup_one_len(META_FILENAME,
4899 + dtohd2(dentry),
4900 + strlen(META_FILENAME));
4901 + if(!meta_dentry->d_inode) {
4902 + /* We need to create a META-file */
4903 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
4904 + vfs_create(dtohd2(dentry)->d_inode,
4905 + meta_dentry, S_IRUSR | S_IWUSR, NULL);
4906 +#else
4907 + vfs_create(dtohd2(dentry)->d_inode,
4908 + meta_dentry, S_IRUSR | S_IWUSR);
4909 +#endif
4910 + app_flag = 0;
4911 + }
4912 + /* need we truncate the meta file? */
4913 + if(!app_flag) {
4914 + struct iattr newattrs;
4915 + newattrs.ia_size = 0;
4916 + newattrs.ia_valid = ATTR_SIZE | ATTR_CTIME;
4917 +
4918 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
4919 + mutex_lock(&meta_dentry->d_inode->i_mutex);
4920 +#else
4921 + down(&meta_dentry->d_inode->i_sem);
4922 +#endif
4923 + err = notify_change(meta_dentry, &newattrs);
4924 +
4925 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
4926 + mutex_unlock(&meta_dentry->d_inode->i_mutex);
4927 +#else
4928 + up(&meta_dentry->d_inode->i_sem);
4929 +#endif
4930 + if(err || meta_dentry->d_inode->i_size != 0) {
4931 + printk(KERN_CRIT "mini_fo: meta_sync_r_list: \
4932 + ERROR truncating meta file.\n");
4933 + goto out_err_close;
4934 + }
4935 + }
4936 +
4937 + /* open META-file for writing */
4938 + meta_file = dentry_open(meta_dentry, meta_mnt, 0x1);
4939 + if(!meta_file || IS_ERR(meta_file)) {
4940 + printk(KERN_CRIT "mini_fo: meta_sync_r_list: \
4941 + ERROR opening meta file.\n");
4942 + /* we don't mntget so we dont't mntput (for now)
4943 + * mntput(meta_mnt);
4944 + */
4945 + dput(meta_dentry);
4946 + err = -1;
4947 + goto out;
4948 + }
4949 +
4950 + /* check if fs supports writing */
4951 + if(!meta_file->f_op->write) {
4952 + printk(KERN_CRIT "mini_fo: meta_sync_r_list: \
4953 + ERROR, fs does not support writing.\n");
4954 + goto out_err_close;
4955 + }
4956 +
4957 + meta_file->f_pos = meta_dentry->d_inode->i_size; /* append */
4958 + old_fs = get_fs();
4959 + set_fs(KERNEL_DS);
4960 +
4961 + /* here we go... */
4962 + list_for_each(tmp, &inode_info->renamed_list) {
4963 + ren_entry = list_entry(tmp, struct renamed_entry, list);
4964 + /* size:
4965 + * 2 for "R ", old_len+new_len for names, 1 blank+1 \n */
4966 + buf_len = ren_entry->old_len + ren_entry->new_len + 4;
4967 + buf = (char *) kmalloc(buf_len, GFP_KERNEL);
4968 + if (!buf) {
4969 + printk(KERN_CRIT "mini_fo: meta_sync_r_list: \
4970 + out of mem.\n");
4971 + return -ENOMEM;
4972 + }
4973 + buf[0] = 'R';
4974 + buf[1] = ' ';
4975 + strncpy(buf + 2, ren_entry->old_name, ren_entry->old_len);
4976 + buf[ren_entry->old_len + 2] = ' ';
4977 + strncpy(buf + ren_entry->old_len + 3,
4978 + ren_entry->new_name, ren_entry->new_len);
4979 + buf[buf_len - 1] = '\n';
4980 + bytes = meta_file->f_op->write(meta_file, buf,
4981 + buf_len, &meta_file->f_pos);
4982 + if(bytes != buf_len) {
4983 + printk(KERN_CRIT "mini_fo: meta_sync_r_list: \
4984 + ERROR writing.\n");
4985 + err |= -1;
4986 + }
4987 + kfree(buf);
4988 + }
4989 + set_fs(old_fs);
4990 +
4991 + out_err_close:
4992 + fput(meta_file);
4993 + out:
4994 + return err;
4995 +}
4996 +
4997 +int meta_check_d_entry(dentry_t *dentry, const char *name, int len)
4998 +{
4999 + if(!dentry || !dentry->d_inode)
5000 + printk(KERN_CRIT "mini_fo: meta_check_d_dentry: \
5001 + invalid dentry passed.\n");
5002 + return __meta_check_d_entry(dentry->d_inode, name, len);
5003 +}
5004 +
5005 +int __meta_check_d_entry(inode_t *inode, const char *name, int len)
5006 +{
5007 + struct list_head *tmp;
5008 + struct deleted_entry *del_entry;
5009 + struct mini_fo_inode_info *inode_info;
5010 +
5011 + if(!inode || !itopd(inode))
5012 + printk(KERN_CRIT "mini_fo: __meta_check_d_dentry: \
5013 + invalid inode passed.\n");
5014 +
5015 + inode_info = itopd(inode);
5016 +
5017 + if(inode_info->deleted_list_size <= 0)
5018 + return 0;
5019 +
5020 + list_for_each(tmp, &inode_info->deleted_list) {
5021 + del_entry = list_entry(tmp, struct deleted_entry, list);
5022 + if(del_entry->len != len)
5023 + continue;
5024 +
5025 + if(!strncmp(del_entry->name, name, len))
5026 + return 1;
5027 + }
5028 + return 0;
5029 +}
5030 +
5031 +/*
5032 + * check if file has been renamed and return path to orig. base dir.
5033 + * Implements no error return values so far, what of course sucks.
5034 + * String is null terminated.'
5035 + */
5036 +char* meta_check_r_entry(dentry_t *dentry, const char *name, int len)
5037 +{
5038 + if(!dentry || !dentry->d_inode) {
5039 + printk(KERN_CRIT "mini_fo: meta_check_r_dentry: \
5040 + invalid dentry passed.\n");
5041 + return NULL;
5042 + }
5043 + return __meta_check_r_entry(dentry->d_inode, name, len);
5044 +}
5045 +
5046 +char* __meta_check_r_entry(inode_t *inode, const char *name, int len)
5047 +{
5048 + struct list_head *tmp;
5049 + struct renamed_entry *ren_entry;
5050 + struct mini_fo_inode_info *inode_info;
5051 + char *old_path;
5052 +
5053 + if(!inode || !itopd(inode)) {
5054 + printk(KERN_CRIT "mini_fo: meta_check_r_dentry: \
5055 + invalid inode passed.\n");
5056 + return NULL;
5057 + }
5058 + inode_info = itopd(inode);
5059 +
5060 + if(inode_info->renamed_list_size <= 0)
5061 + return NULL;
5062 +
5063 + list_for_each(tmp, &inode_info->renamed_list) {
5064 + ren_entry = list_entry(tmp, struct renamed_entry, list);
5065 + if(ren_entry->new_len != len)
5066 + continue;
5067 +
5068 + if(!strncmp(ren_entry->new_name, name, len)) {
5069 + old_path = (char *)
5070 + kmalloc(ren_entry->old_len+1, GFP_KERNEL);
5071 + strncpy(old_path,
5072 + ren_entry->old_name,
5073 + ren_entry->old_len);
5074 + old_path[ren_entry->old_len]='\0';
5075 + return old_path;
5076 + }
5077 + }
5078 + return NULL;
5079 +}
5080 +
5081 +/*
5082 + * This version only checks if entry exists and return:
5083 + * 1 if exists,
5084 + * 0 if not,
5085 + * -1 if error.
5086 + */
5087 +int meta_is_r_entry(dentry_t *dentry, const char *name, int len)
5088 +{
5089 + if(!dentry || !dentry->d_inode) {
5090 + printk(KERN_CRIT "mini_fo: meta_check_r_dentry [2]: \
5091 + invalid dentry passed.\n");
5092 + return -1;
5093 + }
5094 + return __meta_is_r_entry(dentry->d_inode, name, len);
5095 +}
5096 +
5097 +int __meta_is_r_entry(inode_t *inode, const char *name, int len)
5098 +{
5099 + struct list_head *tmp;
5100 + struct renamed_entry *ren_entry;
5101 + struct mini_fo_inode_info *inode_info;
5102 +
5103 + if(!inode || !itopd(inode)) {
5104 + printk(KERN_CRIT "mini_fo: meta_check_r_dentry [2]: \
5105 + invalid inode passed.\n");
5106 + return -1;
5107 + }
5108 + inode_info = itopd(inode);
5109 +
5110 + if(inode_info->renamed_list_size <= 0)
5111 + return -1;
5112 +
5113 + list_for_each(tmp, &inode_info->renamed_list) {
5114 + ren_entry = list_entry(tmp, struct renamed_entry, list);
5115 + if(ren_entry->new_len != len)
5116 + continue;
5117 +
5118 + if(!strncmp(ren_entry->new_name, name, len))
5119 + return 1;
5120 + }
5121 + return 0;
5122 +}
5123 +
5124 --- /dev/null
5125 +++ b/fs/mini_fo/mini_fo.h
5126 @@ -0,0 +1,510 @@
5127 +/*
5128 + * Copyright (c) 1997-2003 Erez Zadok
5129 + * Copyright (c) 2001-2003 Stony Brook University
5130 + *
5131 + * For specific licensing information, see the COPYING file distributed with
5132 + * this package, or get one from ftp://ftp.filesystems.org/pub/fist/COPYING.
5133 + *
5134 + * This Copyright notice must be kept intact and distributed with all
5135 + * fistgen sources INCLUDING sources generated by fistgen.
5136 + */
5137 +/*
5138 + * Copyright (C) 2004, 2005 Markus Klotzbuecher <mk@creamnet.de>
5139 + *
5140 + * This program is free software; you can redistribute it and/or
5141 + * modify it under the terms of the GNU General Public License
5142 + * as published by the Free Software Foundation; either version
5143 + * 2 of the License, or (at your option) any later version.
5144 + */
5145 +
5146 +/*
5147 + * $Id$
5148 + */
5149 +
5150 +#ifndef __MINI_FO_H_
5151 +#define __MINI_FO_H_
5152 +
5153 +#ifdef __KERNEL__
5154 +
5155 +/* META stuff */
5156 +#define META_FILENAME "META_dAfFgHE39ktF3HD2sr"
5157 +
5158 +/* use xattrs? */
5159 +#define XATTR
5160 +
5161 +/* File attributes that when changed, result in a file beeing copied to storage */
5162 +#define COPY_FLAGS ATTR_MODE | ATTR_UID | ATTR_GID | ATTR_SIZE
5163 +
5164 +/*
5165 + * mini_fo filestates
5166 + */
5167 +#define MODIFIED 1
5168 +#define UNMODIFIED 2
5169 +#define CREATED 3
5170 +#define DEL_REWRITTEN 4
5171 +#define DELETED 5
5172 +#define NON_EXISTANT 6
5173 +
5174 +/* fist file systems superblock magic */
5175 +# define MINI_FO_SUPER_MAGIC 0xf15f
5176 +
5177 +/*
5178 + * STRUCTURES:
5179 + */
5180 +
5181 +/* mini_fo inode data in memory */
5182 +struct mini_fo_inode_info {
5183 + inode_t *wii_inode;
5184 + inode_t *wii_inode2; /* pointer to storage inode */
5185 +
5186 + /* META-data lists */
5187 + /* deleted list, ex wol */
5188 + struct list_head deleted_list;
5189 + int deleted_list_size;
5190 +
5191 + /* renamed list */
5192 + struct list_head renamed_list;
5193 + int renamed_list_size;
5194 +
5195 + /* add other lists here ... */
5196 +};
5197 +
5198 +/* mini_fo dentry data in memory */
5199 +struct mini_fo_dentry_info {
5200 + dentry_t *wdi_dentry;
5201 + dentry_t *wdi_dentry2; /* pointer to storage dentry */
5202 + unsigned int state; /* state of the mini_fo dentry */
5203 +};
5204 +
5205 +
5206 +/* mini_fo super-block data in memory */
5207 +struct mini_fo_sb_info {
5208 + super_block_t *wsi_sb, *wsi_sb2; /* mk: might point to the same sb */
5209 + struct vfsmount *hidden_mnt, *hidden_mnt2;
5210 + dentry_t *base_dir_dentry;
5211 + dentry_t *storage_dir_dentry;
5212 + ;
5213 +};
5214 +
5215 +/* readdir_data, readdir helper struct */
5216 +struct readdir_data {
5217 + struct list_head ndl_list; /* linked list head ptr */
5218 + int ndl_size; /* list size */
5219 + int sto_done; /* flag to show that the storage dir entries have
5220 + * all been read an now follow base entries */
5221 +};
5222 +
5223 +/* file private data. */
5224 +struct mini_fo_file_info {
5225 + struct file *wfi_file;
5226 + struct file *wfi_file2; /* pointer to storage file */
5227 + struct readdir_data rd;
5228 +};
5229 +
5230 +/* struct ndl_entry */
5231 +struct ndl_entry {
5232 + struct list_head list;
5233 + char *name;
5234 + int len;
5235 +};
5236 +
5237 +/********************************
5238 + * META-data structures
5239 + ********************************/
5240 +
5241 +/* deleted entry */
5242 +struct deleted_entry {
5243 + struct list_head list;
5244 + char *name;
5245 + int len;
5246 +};
5247 +
5248 +/* renamed entry */
5249 +struct renamed_entry {
5250 + struct list_head list;
5251 + char *old_name; /* old directory with full path */
5252 + int old_len; /* length of above string */
5253 + char *new_name; /* new directory name */
5254 + int new_len; /* length of above string */
5255 +};
5256 +
5257 +/* attr_change entry */
5258 +struct attr_change_entry {
5259 + struct list_head list;
5260 + char *name;
5261 + int len;
5262 +};
5263 +
5264 +/* link entry */
5265 +struct link_entry {
5266 + struct list_head list;
5267 + int links_moved;
5268 + int inum_base;
5269 + int inum_sto;
5270 + char *weird_name;
5271 + int weird_name_len;
5272 +};
5273 +
5274 +
5275 +/* Some other stuff required for mini_fo_filldir64, copied from
5276 + * fs/readdir.c
5277 + */
5278 +
5279 +#define ROUND_UP64(x) (((x)+sizeof(u64)-1) & ~(sizeof(u64)-1))
5280 +#define NAME_OFFSET(de) ((int) ((de)->d_name - (char *) (de)))
5281 +
5282 +
5283 +struct linux_dirent64 {
5284 + u64 d_ino;
5285 + s64 d_off;
5286 + unsigned short d_reclen;
5287 + unsigned char d_type;
5288 + char d_name[0];
5289 +};
5290 +
5291 +
5292 +struct getdents_callback64 {
5293 + struct linux_dirent64 * current_dir;
5294 + struct linux_dirent64 * previous;
5295 + int count;
5296 + int error;
5297 +};
5298 +
5299 +struct linux_dirent {
5300 + unsigned long d_ino;
5301 + unsigned long d_off;
5302 + unsigned short d_reclen;
5303 + char d_name[1];
5304 +};
5305 +
5306 +struct getdents_callback {
5307 + struct linux_dirent * current_dir;
5308 + struct linux_dirent * previous;
5309 + int count;
5310 + int error;
5311 +};
5312 +
5313 +
5314 +/*
5315 + * MACROS:
5316 + */
5317 +
5318 +/* file TO private_data */
5319 +# define ftopd(file) ((struct mini_fo_file_info *)((file)->private_data))
5320 +# define __ftopd(file) ((file)->private_data)
5321 +/* file TO hidden_file */
5322 +# define ftohf(file) ((ftopd(file))->wfi_file)
5323 +# define ftohf2(file) ((ftopd(file))->wfi_file2)
5324 +
5325 +/* inode TO private_data */
5326 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,18)
5327 +# define itopd(ino) ((struct mini_fo_inode_info *)(ino)->i_private)
5328 +# define __itopd(ino) ((ino)->i_private)
5329 +#else
5330 +# define itopd(ino) ((struct mini_fo_inode_info *)(ino)->u.generic_ip)
5331 +# define __itopd(ino) ((ino)->u.generic_ip)
5332 +#endif
5333 +/* inode TO hidden_inode */
5334 +# define itohi(ino) (itopd(ino)->wii_inode)
5335 +# define itohi2(ino) (itopd(ino)->wii_inode2)
5336 +
5337 +/* superblock TO private_data */
5338 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
5339 +# define stopd(super) ((struct mini_fo_sb_info *)(super)->s_fs_info)
5340 +# define __stopd(super) ((super)->s_fs_info)
5341 +#else
5342 +# define stopd(super) ((struct mini_fo_sb_info *)(super)->u.generic_sbp)
5343 +# define __stopd(super) ((super)->u.generic_sbp)
5344 +#endif
5345 +
5346 +/* unused? # define vfs2priv stopd */
5347 +/* superblock TO hidden_superblock */
5348 +
5349 +# define stohs(super) (stopd(super)->wsi_sb)
5350 +# define stohs2(super) (stopd(super)->wsi_sb2)
5351 +
5352 +/* dentry TO private_data */
5353 +# define dtopd(dentry) ((struct mini_fo_dentry_info *)(dentry)->d_fsdata)
5354 +# define __dtopd(dentry) ((dentry)->d_fsdata)
5355 +/* dentry TO hidden_dentry */
5356 +# define dtohd(dent) (dtopd(dent)->wdi_dentry)
5357 +# define dtohd2(dent) (dtopd(dent)->wdi_dentry2)
5358 +
5359 +/* dentry to state */
5360 +# define dtost(dent) (dtopd(dent)->state)
5361 +# define sbt(sb) ((sb)->s_type->name)
5362 +
5363 +#define IS_WRITE_FLAG(flag) (flag & (O_RDWR | O_WRONLY | O_APPEND))
5364 +#define IS_COPY_FLAG(flag) (flag & (COPY_FLAGS))
5365 +
5366 +/* macros to simplify non-SCA code */
5367 +# define MALLOC_PAGE_POINTERS(hidden_pages, num_hidden_pages)
5368 +# define MALLOC_PAGEDATA_POINTERS(hidden_pages_data, num_hidden_pages)
5369 +# define FREE_PAGE_POINTERS(hidden_pages, num)
5370 +# define FREE_PAGEDATA_POINTERS(hidden_pages_data, num)
5371 +# define FOR_EACH_PAGE
5372 +# define CURRENT_HIDDEN_PAGE hidden_page
5373 +# define CURRENT_HIDDEN_PAGEDATA hidden_page_data
5374 +# define CURRENT_HIDDEN_PAGEINDEX page->index
5375 +
5376 +/*
5377 + * EXTERNALS:
5378 + */
5379 +extern struct file_operations mini_fo_main_fops;
5380 +extern struct file_operations mini_fo_dir_fops;
5381 +extern struct inode_operations mini_fo_main_iops;
5382 +extern struct inode_operations mini_fo_dir_iops;
5383 +extern struct inode_operations mini_fo_symlink_iops;
5384 +extern struct super_operations mini_fo_sops;
5385 +extern struct dentry_operations mini_fo_dops;
5386 +extern struct vm_operations_struct mini_fo_shared_vmops;
5387 +extern struct vm_operations_struct mini_fo_private_vmops;
5388 +extern struct address_space_operations mini_fo_aops;
5389 +
5390 +#if 0 /* unused by mini_fo */
5391 +extern int mini_fo_interpose(dentry_t *hidden_dentry, dentry_t *this_dentry, super_block_t *sb, int flag);
5392 +#if defined(FIST_FILTER_DATA) || defined(FIST_FILTER_SCA)
5393 +extern page_t *mini_fo_get1page(file_t *file, int index);
5394 +extern int mini_fo_fill_zeros(file_t *file, page_t *page, unsigned from);
5395 +# endif /* FIST_FILTER_DATA || FIST_FILTER_SCA */
5396 +
5397 +
5398 +# define mini_fo_hidden_dentry(d) __mini_fo_hidden_dentry(__FILE__,__FUNCTION__,__LINE__,(d))
5399 +# define mini_fo_hidden_sto_dentry(d) __mini_fo_hidden_sto_dentry(__FILE__,__FUNCTION__,__LINE__,(d))
5400 +
5401 +extern dentry_t *__mini_fo_hidden_dentry(char *file, char *func, int line, dentry_t *this_dentry);
5402 +extern dentry_t *__mini_fo_hidden_sto_dentry(char *file, char *func, int line, dentry_t *this_dentry);
5403 +
5404 +extern int mini_fo_read_file(const char *filename, void *buf, int len);
5405 +extern int mini_fo_write_file(const char *filename, void *buf, int len);
5406 +extern dentry_t *fist_lookup(dentry_t *dir, const char *name, vnode_t **out, uid_t uid, gid_t gid);
5407 +#endif /* unused by mini_fo */
5408 +
5409 +/* state transition functions */
5410 +extern int nondir_unmod_to_mod(dentry_t *dentry, int cp_flag);
5411 +extern int nondir_del_rew_to_del(dentry_t *dentry);
5412 +extern int nondir_creat_to_del(dentry_t *dentry);
5413 +extern int nondir_mod_to_del(dentry_t *dentry);
5414 +extern int nondir_unmod_to_del(dentry_t *dentry);
5415 +
5416 +extern int dir_unmod_to_mod(dentry_t *dentry);
5417 +
5418 +/* rename specials */
5419 +extern int rename_directory(inode_t *old_dir, dentry_t *old_dentry, inode_t *new_dir, dentry_t *new_dentry);
5420 +extern int rename_nondir(inode_t *old_dir, dentry_t *old_dentry, inode_t *new_dir, dentry_t *new_dentry);
5421 +
5422 +/* misc stuff */
5423 +extern int mini_fo_tri_interpose(dentry_t *hidden_dentry,
5424 + dentry_t *hidden_sto_dentry,
5425 + dentry_t *dentry,
5426 + super_block_t *sb, int flag);
5427 +
5428 +extern int mini_fo_cp_cont(dentry_t *tgt_dentry, struct vfsmount *tgt_mnt,
5429 + dentry_t *src_dentry, struct vfsmount *src_mnt);
5430 +
5431 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
5432 +extern int mini_fo_create(inode_t *dir, dentry_t *dentry, int mode, struct nameidata *nd);
5433 +
5434 +extern int create_sto_nod(dentry_t *dentry, int mode, dev_t dev);
5435 +extern int create_sto_reg_file(dentry_t *dentry, int mode, struct nameidata *nd);
5436 +#else
5437 +extern int mini_fo_create(inode_t *dir, dentry_t *dentry, int mode);
5438 +
5439 +extern int create_sto_nod(dentry_t *dentry, int mode, int dev);
5440 +extern int create_sto_reg_file(dentry_t *dentry, int mode);
5441 +#endif
5442 +
5443 +extern int create_sto_dir(dentry_t *dentry, int mode);
5444 +
5445 +extern int exists_in_storage(dentry_t *dentry);
5446 +extern int is_mini_fo_existant(dentry_t *dentry);
5447 +extern int get_neg_sto_dentry(dentry_t *dentry);
5448 +extern int build_sto_structure(dentry_t *dir, dentry_t *dentry);
5449 +extern int get_mini_fo_bpath(dentry_t *dentry, char **bpath, int *bpath_len);
5450 +extern dentry_t *bpath_walk(super_block_t *sb, char *bpath);
5451 +extern int bpath_put(dentry_t *dentry);
5452 +
5453 +/* check_mini_fo types functions */
5454 +extern int check_mini_fo_dentry(dentry_t *dentry);
5455 +extern int check_mini_fo_file(file_t *file);
5456 +extern int check_mini_fo_inode(inode_t *inode);
5457 +
5458 +/* General meta functions, can be called from outside of meta.c */
5459 +extern int meta_build_lists(dentry_t *dentry);
5460 +extern int meta_put_lists(dentry_t *dentry);
5461 +extern int __meta_put_lists(inode_t *inode);
5462 +
5463 +extern int meta_add_d_entry(dentry_t *dentry, const char *name, int len);
5464 +extern int meta_add_r_entry(dentry_t *dentry,
5465 + const char *old_name, int old_len,
5466 + const char *new_name, int new_len);
5467 +
5468 +extern int meta_remove_r_entry(dentry_t *dentry, const char *name, int len);
5469 +
5470 +extern int meta_check_d_entry(dentry_t *dentry, const char *name, int len);
5471 +extern int __meta_check_d_entry(inode_t *inode, const char *name, int len);
5472 +
5473 +extern char* meta_check_r_entry(dentry_t *dentry, const char *name, int len);
5474 +extern char* __meta_check_r_entry(inode_t *inode, const char *name, int len);
5475 +extern int meta_is_r_entry(dentry_t *dentry, const char *name, int len);
5476 +extern int __meta_is_r_entry(inode_t *inode, const char *name, int len);
5477 +
5478 +/* Specific meta functions, should be called only inside meta.c */
5479 +extern int __meta_put_d_list(inode_t *inode);
5480 +extern int __meta_put_r_list(inode_t *inode);
5481 +
5482 +extern int meta_list_add_d_entry(dentry_t *dentry,
5483 + const char *name, int len);
5484 +extern int meta_list_add_r_entry(dentry_t *dentry,
5485 + const char *old_name, int old_len,
5486 + const char *new_name, int new_len);
5487 +
5488 +extern int meta_list_remove_r_entry(dentry_t *dentry,
5489 + const char *name, int len);
5490 +
5491 +extern int __meta_list_remove_r_entry(inode_t *inode,
5492 + const char *name, int len);
5493 +
5494 +extern int meta_write_d_entry(dentry_t *dentry, const char *name, int len);
5495 +extern int meta_write_r_entry(dentry_t *dentry,
5496 + const char *old_name, int old_len,
5497 + const char *new_name, int new_len);
5498 +
5499 +extern int meta_sync_lists(dentry_t *dentry);
5500 +extern int meta_sync_d_list(dentry_t *dentry, int app_flag);
5501 +extern int meta_sync_r_list(dentry_t *dentry, int app_flag);
5502 +
5503 +/* ndl stuff */
5504 +extern int ndl_add_entry(struct readdir_data *rd, const char *name, int len);
5505 +extern void ndl_put_list(struct readdir_data *rd);
5506 +extern int ndl_check_entry(struct readdir_data *rd,
5507 + const char *name, int len);
5508 +
5509 +
5510 +# define copy_inode_size(dst, src) \
5511 + dst->i_size = src->i_size; \
5512 + dst->i_blocks = src->i_blocks;
5513 +
5514 +static inline void
5515 +fist_copy_attr_atime(inode_t *dest, const inode_t *src)
5516 +{
5517 + ASSERT(dest != NULL);
5518 + ASSERT(src != NULL);
5519 + dest->i_atime = src->i_atime;
5520 +}
5521 +static inline void
5522 +fist_copy_attr_times(inode_t *dest, const inode_t *src)
5523 +{
5524 + ASSERT(dest != NULL);
5525 + ASSERT(src != NULL);
5526 + dest->i_atime = src->i_atime;
5527 + dest->i_mtime = src->i_mtime;
5528 + dest->i_ctime = src->i_ctime;
5529 +}
5530 +static inline void
5531 +fist_copy_attr_timesizes(inode_t *dest, const inode_t *src)
5532 +{
5533 + ASSERT(dest != NULL);
5534 + ASSERT(src != NULL);
5535 + dest->i_atime = src->i_atime;
5536 + dest->i_mtime = src->i_mtime;
5537 + dest->i_ctime = src->i_ctime;
5538 + copy_inode_size(dest, src);
5539 +}
5540 +static inline void
5541 +fist_copy_attr_all(inode_t *dest, const inode_t *src)
5542 +{
5543 + ASSERT(dest != NULL);
5544 + ASSERT(src != NULL);
5545 + dest->i_mode = src->i_mode;
5546 + dest->i_nlink = src->i_nlink;
5547 + dest->i_uid = src->i_uid;
5548 + dest->i_gid = src->i_gid;
5549 + dest->i_rdev = src->i_rdev;
5550 + dest->i_atime = src->i_atime;
5551 + dest->i_mtime = src->i_mtime;
5552 + dest->i_ctime = src->i_ctime;
5553 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,19)
5554 + dest->i_blksize = src->i_blksize;
5555 +#endif
5556 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,12)
5557 + dest->i_blkbits = src->i_blkbits;
5558 +# endif /* linux 2.4.12 and newer */
5559 + copy_inode_size(dest, src);
5560 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
5561 + dest->i_attr_flags = src->i_attr_flags;
5562 +#else
5563 + dest->i_flags = src->i_flags;
5564 +#endif
5565 +}
5566 +
5567 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
5568 +/* copied from linux/fs.h */
5569 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
5570 +static inline void double_lock(struct dentry *d1, struct dentry *d2)
5571 +{
5572 + struct mutex *m1 = &d1->d_inode->i_mutex;
5573 + struct mutex *m2 = &d2->d_inode->i_mutex;
5574 + if (m1 != m2) {
5575 + if ((unsigned long) m1 < (unsigned long) m2) {
5576 + struct mutex *tmp = m2;
5577 + m2 = m1; m1 = tmp;
5578 + }
5579 + mutex_lock(m1);
5580 + }
5581 + mutex_lock(m2);
5582 +}
5583 +
5584 +static inline void double_unlock(struct dentry *d1, struct dentry *d2)
5585 +{
5586 + struct mutex *m1 = &d1->d_inode->i_mutex;
5587 + struct mutex *m2 = &d2->d_inode->i_mutex;
5588 + mutex_unlock(m1);
5589 + if (m1 != m2)
5590 + mutex_unlock(m2);
5591 + dput(d1);
5592 + dput(d2);
5593 +}
5594 +
5595 +#else
5596 +static inline void double_down(struct semaphore *s1, struct semaphore *s2)
5597 +{
5598 + if (s1 != s2) {
5599 + if ((unsigned long) s1 < (unsigned long) s2) {
5600 + struct semaphore *tmp = s2;
5601 + s2 = s1; s1 = tmp;
5602 + }
5603 + down(s1);
5604 + }
5605 + down(s2);
5606 +}
5607 +
5608 +static inline void double_up(struct semaphore *s1, struct semaphore *s2)
5609 +{
5610 + up(s1);
5611 + if (s1 != s2)
5612 + up(s2);
5613 +}
5614 +
5615 +static inline void double_lock(struct dentry *d1, struct dentry *d2)
5616 +{
5617 + double_down(&d1->d_inode->i_sem, &d2->d_inode->i_sem);
5618 +}
5619 +
5620 +static inline void double_unlock(struct dentry *d1, struct dentry *d2)
5621 +{
5622 + double_up(&d1->d_inode->i_sem,&d2->d_inode->i_sem);
5623 + dput(d1);
5624 + dput(d2);
5625 +}
5626 +#endif /* if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16) */
5627 +#endif /* if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0) */
5628 +#endif /* __KERNEL__ */
5629 +
5630 +/*
5631 + * Definitions for user and kernel code
5632 + */
5633 +
5634 +/* ioctls */
5635 +
5636 +#endif /* not __MINI_FO_H_ */
5637 --- /dev/null
5638 +++ b/fs/mini_fo/mini_fo-merge
5639 @@ -0,0 +1,180 @@
5640 +#!/bin/bash
5641 +#
5642 +# Copyright (C) 2005 Markus Klotzbuecher <mk@creamnet.de>
5643 +# This program is free software; you can redistribute it and/or
5644 +# modify it under the terms of the GNU General Public License
5645 +# as published by the Free Software Foundation; either version
5646 +# 2 of the License, or (at your option) any later version.
5647 +#
5648 +
5649 +BASE=
5650 +STO=
5651 +HELP=
5652 +DRYRUN=
5653 +VERBOSE=
5654 +TMP="/tmp/"
5655 +META_NAME="META_dAfFgHE39ktF3HD2sr"
5656 +SKIP_DEL_LIST="skip-delete-list.mini_fo-merge"
5657 +
5658 +COMMAND=
5659 +exec_command()
5660 +{
5661 + if [ x$DRYRUN == "xset" ]; then
5662 + echo " would run: $COMMAND"
5663 + elif ! [ x$DRYRUN == "xset" ]; then
5664 + if [ x$VERBOSE == "xset" ]; then
5665 + echo " running: $COMMAND"
5666 + fi
5667 + eval $COMMAND
5668 + fi
5669 +}
5670 +
5671 +usage()
5672 +{
5673 +cat <<EOF
5674 +
5675 +USAGE: $0 -b <base dir> -s <storage dir>
5676 +Version 0.1
5677 +
5678 +This script merges the contents of a mini_fo storage file system back
5679 +to the base file system.
5680 +
5681 +!!! Warning: This will modify the base filesystem and can destroy data
5682 + if used wrongly.
5683 +
5684 +Options:
5685 + -b <base dir>
5686 + the directory of the base file system.
5687 +
5688 + -s <storage dir>
5689 + the directory of the storage file system.
5690 +
5691 + -d dry run, will not change anything and print the commands that
5692 + would be executed.
5693 +
5694 + -t tmp dir for storing temporary file. default: $TMP
5695 +
5696 + -v show what operations are performed.
5697 +
5698 + -h displays this message.
5699 +
5700 +EOF
5701 +}
5702 +
5703 +# parse parameters
5704 +while getopts hdvt:b:s: OPTS
5705 + do
5706 + case $OPTS in
5707 + h) HELP="set";;
5708 + d) DRYRUN="set";;
5709 + v) VERBOSE="set";;
5710 + b) BASE="$OPTARG";;
5711 + s) STO="$OPTARG";;
5712 + t) TMP="$OPTARG";;
5713 + ?) usage
5714 + exit 1;;
5715 + esac
5716 +done
5717 +
5718 +if [ "x$HELP" == "xset" ]; then
5719 + usage
5720 + exit -1
5721 +fi
5722 +
5723 +if ! [ -d "$BASE" ] || ! [ -d "$STO" ]; then
5724 + echo -e "$0:\n Error, -s and/or -b argument missing. type $0 -h for help."
5725 + exit -1;
5726 +fi
5727 +
5728 +# get full paths
5729 +pushd $STO; STO=`pwd`; popd
5730 +pushd $BASE; BASE=`pwd`; popd
5731 +TMP=${TMP%/}
5732 +
5733 +
5734 +cat<<EOF
5735 +###############################################################################
5736 +# mini_fo-merge
5737 +#
5738 +# base dir: $BASE
5739 +# storage dir: $STO
5740 +# meta filename: $META_NAME
5741 +# dry run: $DRYRUN
5742 +# verbose: $VERBOSE
5743 +# tmp files: $TMP
5744 +###############################################################################
5745 +
5746 +EOF
5747 +
5748 +rm $TMP/$SKIP_DEL_LIST
5749 +
5750 +# first process all renamed dirs
5751 +echo "Merging renamed directories..."
5752 +pushd $STO &> /dev/null
5753 +find . -name $META_NAME -type f -print0 | xargs -0 -e grep -e '^R ' | tr -s ':R' ' ' | while read ENTRY; do
5754 + echo "entry: $ENTRY"
5755 + META_FILE=`echo $ENTRY | cut -d ' ' -f 1`
5756 + OLD_B_DIR=`echo $ENTRY | cut -d ' ' -f 2 | sed -e 's/\///'`
5757 + NEW_NAME=`echo $ENTRY | cut -d ' ' -f 3`
5758 + NEW_B_DIR=`echo $META_FILE | sed -e "s/$META_NAME/$NEW_NAME/" | sed -e 's/^\.\///'`
5759 + echo "META_FILE: $META_FILE"
5760 + echo "OLD_B_DIR: $OLD_B_DIR"
5761 + echo "NEW_NAME: $NEW_NAME"
5762 + echo "NEW_B_DIR: $NEW_B_DIR"
5763 +
5764 + pushd $BASE &> /dev/null
5765 + # remove an existing dir in storage
5766 + COMMAND="rm -rf $NEW_B_DIR"; exec_command
5767 + COMMAND="cp -R $OLD_B_DIR $NEW_B_DIR"; exec_command
5768 + echo ""
5769 + popd &> /dev/null
5770 +
5771 + # remember this dir to exclude it from deleting later
5772 + echo $NEW_B_DIR >> $TMP/$SKIP_DEL_LIST
5773 +done
5774 +
5775 +# delete all whiteouted files from base
5776 +echo -e "\nDeleting whiteout'ed files from base file system..."
5777 +find . -name $META_NAME -type f -print0 | xargs -0 -e grep -e '^D ' | sed -e 's/:D//' | while read ENTRY; do
5778 + META_FILE=`echo $ENTRY | cut -d ' ' -f 1`
5779 + DEL_NAME=`echo $ENTRY | cut -d ' ' -f 2`
5780 + DEL_FILE=`echo $META_FILE | sed -e "s/$META_NAME/$DEL_NAME/" | sed -e 's/^\.\///'`
5781 + grep -x $DEL_FILE $TMP/$SKIP_DEL_LIST &> /dev/null
5782 + if [ $? -ne 0 ]; then
5783 + pushd $BASE &> /dev/null
5784 + COMMAND="rm -rf $DEL_FILE"; exec_command
5785 + popd &> /dev/null
5786 + else
5787 + echo " excluding: $DEL_FILE as in skip-del-list."
5788 + fi
5789 +done
5790 +
5791 +# create all dirs and update permissions
5792 +echo -e "\nSetting up directory structures in base file system..."
5793 +find . -type d | sed -e 's/^\.\///' | while read DIR; do
5794 + PERMS=`stat -c %a $DIR`
5795 + DIR_UID=`stat -c %u $DIR`
5796 + DIR_GID=`stat -c %g $DIR`
5797 + pushd $BASE &> /dev/null
5798 + if ! [ -d $DIR ]; then
5799 + COMMAND="mkdir -p $DIR"; exec_command
5800 + fi
5801 + COMMAND="chmod $PERMS $DIR"; exec_command
5802 + COMMAND="chown $DIR_UID:$DIR_GID $DIR"; exec_command
5803 + popd &> /dev/null
5804 +done
5805 +
5806 +# merge all non-directory files
5807 +echo -e "\nMerging all non-directory files...."
5808 +for i in b c p f l s; do
5809 + find . -type $i | sed -e 's/^\.\///' | grep -v "$META_NAME" | while read FILE; do
5810 + pushd $BASE #&> /dev/null
5811 + COMMAND="cp -df $STO/$FILE $BASE/$FILE"; exec_command
5812 + popd &> /dev/null
5813 + done
5814 +done
5815 +popd &> /dev/null
5816 +
5817 +#rm $TMP/$SKIP_DEL_LIST
5818 +
5819 +echo "Done!"
5820 --- /dev/null
5821 +++ b/fs/mini_fo/mini_fo-overlay
5822 @@ -0,0 +1,130 @@
5823 +#!/bin/bash
5824 +#
5825 +# Copyright (C) 2005 Markus Klotzbuecher <mk@creamnet.de>
5826 +# This program is free software; you can redistribute it and/or
5827 +# modify it under the terms of the GNU General Public License
5828 +# as published by the Free Software Foundation; either version
5829 +# 2 of the License, or (at your option) any later version.
5830 +#
5831 +
5832 +HELP=
5833 +SUFF=
5834 +MNTP=
5835 +MNT_DIR="/mnt"
5836 +STO=
5837 +STO_DIR="/tmp"
5838 +BASE=
5839 +
5840 +usage()
5841 +{
5842 +cat <<EOF
5843 +
5844 +Usage: $0 [-s suffix] [-d sto_dir_dir] [-m mount point] base_dir
5845 +Version 0.1
5846 +
5847 +This script overlays the given base directory using the mini_fo file
5848 +system. If only the base directory base_dir is given, $0
5849 +will use a storage directory called "sto-<base_dir_name>" in $STO_DIR,
5850 +and mount point "mini_fo-<base_dir_dir>" in $MNT_DIR.
5851 +
5852 +Options:
5853 + -s <suffix>
5854 + add given suffix to storage directory and the mount
5855 + point. This is usefull for overlaying one base directory
5856 + several times and avoiding conflicts with storage directory
5857 + names and mount points.
5858 +
5859 + -d <sto_dir_dir>
5860 + change the directory in which the storage directory will be
5861 + created (default is currently "$STO_DIR".
5862 +
5863 + -m <mount point>
5864 + use an alternative directory to create the mini_fo
5865 + mountpoint (default is currently "$MNT_DIR".
5866 +
5867 + -h displays this message.
5868 +
5869 +EOF
5870 +exit 1;
5871 +}
5872 +
5873 +while getopts hm:s:d: OPTS
5874 + do
5875 + case $OPTS in
5876 + s) SUFF="$OPTARG";;
5877 + d) STO_DIR="$OPTARG";;
5878 + m) MNT_DIR="$OPTARG";;
5879 + h) HELP="set";;
5880 + ?) usage
5881 + exit 1;;
5882 + esac
5883 +done
5884 +shift $(($OPTIND - 1))
5885 +
5886 +BASE="$1"
5887 +
5888 +if [ "x$HELP" == "xset" ]; then
5889 + usage
5890 + exit -1
5891 +fi
5892 +
5893 +# fix suffix
5894 +if [ "x$SUFF" != "x" ]; then
5895 + SUFF="-$SUFF"
5896 +fi
5897 +
5898 +# kill trailing slashes
5899 +MNT_DIR=${MNT_DIR%/}
5900 +STO_DIR=${STO_DIR%/}
5901 +BASE=${BASE%/}
5902 +
5903 +
5904 +if ! [ -d "$BASE" ]; then
5905 + echo "invalid base dir $BASE, run $0 -h for help."
5906 + exit -1
5907 +fi
5908 +
5909 +# check opts
5910 +if ! [ -d "$MNT_DIR" ]; then
5911 + echo "invalid mount dir $MNT_DIR, run $0 -h for help."
5912 + exit -1
5913 +fi
5914 +
5915 +if ! [ -d "$STO_DIR" ]; then
5916 + echo "invalid sto_dir_dir $STO_DIR, run $0 -h for help."
5917 + exit -1
5918 +fi
5919 +
5920 +MNTP="$MNT_DIR/mini_fo-`basename $BASE`$SUFF"
5921 +STO="$STO_DIR/sto-`basename $BASE`$SUFF"
5922 +
5923 +# create the mount point if it doesn't exist
5924 +mkdir -p $MNTP
5925 +if [ $? -ne 0 ]; then
5926 + echo "Error, failed to create mount point $MNTP"
5927 +fi
5928 +
5929 +mkdir -p $STO
5930 +if [ $? -ne 0 ]; then
5931 + echo "Error, failed to create storage dir $STO"
5932 +fi
5933 +
5934 +# check if fs is already mounted
5935 +mount | grep mini_fo | grep $MNTP &> /dev/null
5936 +if [ $? -eq 0 ]; then
5937 + echo "Error, existing mini_fo mount at $MNTP."
5938 + exit -1
5939 +fi
5940 +
5941 +mount | grep mini_fo | grep $STO &> /dev/null
5942 +if [ $? -eq 0 ]; then
5943 + echo "Error, $STO seems to be used already."
5944 + exit -1
5945 +fi
5946 +
5947 +# mount
5948 +mount -t mini_fo -o base=$BASE,sto=$STO $BASE $MNTP
5949 +
5950 +if [ $? -ne 0 ]; then
5951 + echo "Error, mounting failed, maybe no permisson to mount?"
5952 +fi
5953 --- /dev/null
5954 +++ b/fs/mini_fo/mmap.c
5955 @@ -0,0 +1,637 @@
5956 +/*
5957 + * Copyright (c) 1997-2003 Erez Zadok
5958 + * Copyright (c) 2001-2003 Stony Brook University
5959 + *
5960 + * For specific licensing information, see the COPYING file distributed with
5961 + * this package, or get one from ftp://ftp.filesystems.org/pub/fist/COPYING.
5962 + *
5963 + * This Copyright notice must be kept intact and distributed with all
5964 + * fistgen sources INCLUDING sources generated by fistgen.
5965 + */
5966 +/*
5967 + * Copyright (C) 2004, 2005 Markus Klotzbuecher <mk@creamnet.de>
5968 + *
5969 + * This program is free software; you can redistribute it and/or
5970 + * modify it under the terms of the GNU General Public License
5971 + * as published by the Free Software Foundation; either version
5972 + * 2 of the License, or (at your option) any later version.
5973 + */
5974 +
5975 +/*
5976 + * $Id$
5977 + */
5978 +
5979 +#ifdef HAVE_CONFIG_H
5980 +# include <config.h>
5981 +#endif /* HAVE_CONFIG_H */
5982 +
5983 +#include "fist.h"
5984 +#include "mini_fo.h"
5985 +
5986 +
5987 +#ifdef FIST_COUNT_WRITES
5988 +/* for counting writes in the middle vs. regular writes */
5989 +unsigned long count_writes = 0, count_writes_middle = 0;
5990 +#endif /* FIST_COUNT_WRITES */
5991 +
5992 +/* forward declaration of commit write and prepare write */
5993 +STATIC int mini_fo_commit_write(file_t *file, page_t *page, unsigned from, unsigned to);
5994 +STATIC int mini_fo_prepare_write(file_t *file, page_t *page, unsigned from, unsigned to);
5995 +
5996 +
5997 +/*
5998 + * Function for handling creation of holes when lseek-ing past the
5999 + * end of the file and then writing some data.
6000 + */
6001 +int
6002 +mini_fo_fill_zeros(file_t* file, page_t *page, unsigned from)
6003 +{
6004 + int err = 0;
6005 + dentry_t *dentry = file->f_dentry;
6006 + inode_t *inode = dentry->d_inode;
6007 + page_t *tmp_page;
6008 + int index;
6009 +
6010 + print_entry_location();
6011 +
6012 + for (index = inode->i_size >> PAGE_CACHE_SHIFT; index < page->index; index++) {
6013 + tmp_page = mini_fo_get1page(file, index);
6014 + if (IS_ERR(tmp_page)) {
6015 + err = PTR_ERR(tmp_page);
6016 + goto out;
6017 + }
6018 +
6019 + /*
6020 + * zero out rest of the contents of the page between the appropriate
6021 + * offsets.
6022 + */
6023 + memset((char*)page_address(tmp_page) + (inode->i_size & ~PAGE_CACHE_MASK), 0, PAGE_CACHE_SIZE - (inode->i_size & ~PAGE_CACHE_MASK));
6024 +
6025 + if (! (err = mini_fo_prepare_write(file, tmp_page, 0, PAGE_CACHE_SIZE)))
6026 + err = mini_fo_commit_write(file, tmp_page, 0, PAGE_CACHE_SIZE);
6027 +
6028 + page_cache_release(tmp_page);
6029 + if (err < 0)
6030 + goto out;
6031 + if (current->need_resched)
6032 + schedule();
6033 + }
6034 +
6035 + /* zero out appropriate parts of last page */
6036 +
6037 + /*
6038 + * if the encoding type is block, then adjust the 'from' (where the
6039 + * zeroing will start) offset appropriately
6040 + */
6041 + from = from & (~(FIST_ENCODING_BLOCKSIZE - 1));
6042 +
6043 + if ((from - (inode->i_size & ~PAGE_CACHE_MASK)) > 0) {
6044 +
6045 + memset((char*)page_address(page) + (inode->i_size & ~PAGE_CACHE_MASK), 0, from - (inode->i_size & ~PAGE_CACHE_MASK));
6046 + if (! (err = mini_fo_prepare_write(file, page, 0, PAGE_CACHE_SIZE)))
6047 + err = mini_fo_commit_write(file, page, 0, PAGE_CACHE_SIZE);
6048 +
6049 + if (err < 0)
6050 + goto out;
6051 + if (current->need_resched)
6052 + schedule();
6053 + }
6054 +
6055 + out:
6056 + print_exit_status(err);
6057 + return err;
6058 +}
6059 +
6060 +
6061 +
6062 +STATIC int
6063 +mini_fo_writepage(page_t *page)
6064 +{
6065 + int err = -EIO;
6066 + inode_t *inode;
6067 + inode_t *hidden_inode;
6068 + page_t *hidden_page;
6069 + char *kaddr, *hidden_kaddr;
6070 +
6071 + print_entry_location();
6072 +
6073 + inode = page->mapping->host;
6074 + hidden_inode = itohi(inode);
6075 +
6076 + /*
6077 + * writepage is called when shared mmap'ed files need to write
6078 + * their pages, while prepare/commit_write are called from the
6079 + * non-paged write() interface. (However, in 2.3 the two interfaces
6080 + * share the same cache, while in 2.2 they didn't.)
6081 + *
6082 + * So we pretty much have to duplicate much of what commit_write does.
6083 + */
6084 +
6085 + /* find lower page (returns a locked page) */
6086 + hidden_page = grab_cache_page(hidden_inode->i_mapping, page->index);
6087 + if (!hidden_page)
6088 + goto out;
6089 +
6090 + /* get page address, and encode it */
6091 + kaddr = (char *) kmap(page);
6092 + hidden_kaddr = (char*) kmap(hidden_page);
6093 + mini_fo_encode_block(kaddr, hidden_kaddr, PAGE_CACHE_SIZE, inode, inode->i_sb, page->index);
6094 + /* if encode_block could fail, then return error */
6095 + kunmap(page);
6096 + kunmap(hidden_page);
6097 +
6098 + /* call lower writepage (expects locked page) */
6099 + err = hidden_inode->i_mapping->a_ops->writepage(hidden_page);
6100 +
6101 + /*
6102 + * update mtime and ctime of lower level file system
6103 + * mini_fo' mtime and ctime are updated by generic_file_write
6104 + */
6105 + hidden_inode->i_mtime = hidden_inode->i_ctime = CURRENT_TIME;
6106 +
6107 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,4,1)
6108 + UnlockPage(hidden_page); /* b/c grab_cache_page locked it */
6109 +# endif /* kernel older than 2.4.1 */
6110 + page_cache_release(hidden_page); /* b/c grab_cache_page increased refcnt */
6111 +
6112 + if (err)
6113 + ClearPageUptodate(page);
6114 + else
6115 + SetPageUptodate(page);
6116 + out:
6117 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,1)
6118 + UnlockPage(page);
6119 +# endif /* kernel 2.4.1 and newer */
6120 + print_exit_status(err);
6121 + return err;
6122 +}
6123 +
6124 +
6125 +/*
6126 + * get one page from cache or lower f/s, return error otherwise.
6127 + * returns unlocked, up-to-date page (if ok), with increased refcnt.
6128 + */
6129 +page_t *
6130 +mini_fo_get1page(file_t *file, int index)
6131 +{
6132 + page_t *page;
6133 + dentry_t *dentry;
6134 + inode_t *inode;
6135 + struct address_space *mapping;
6136 + int err;
6137 +
6138 + print_entry_location();
6139 +
6140 + dentry = file->f_dentry; /* CPW: Moved below print_entry_location */
6141 + inode = dentry->d_inode;
6142 + mapping = inode->i_mapping;
6143 +
6144 + fist_dprint(8, "%s: read page index %d pid %d\n", __FUNCTION__, index, current->pid);
6145 + if (index < 0) {
6146 + printk("%s BUG: index=%d\n", __FUNCTION__, index);
6147 + page = ERR_PTR(-EIO);
6148 + goto out;
6149 + }
6150 + page = read_cache_page(mapping,
6151 + index,
6152 + (filler_t *) mapping->a_ops->readpage,
6153 + (void *) file);
6154 + if (IS_ERR(page))
6155 + goto out;
6156 + wait_on_page(page);
6157 + if (!Page_Uptodate(page)) {
6158 + lock_page(page);
6159 + err = mapping->a_ops->readpage(file, page);
6160 + if (err) {
6161 + page = ERR_PTR(err);
6162 + goto out;
6163 + }
6164 + wait_on_page(page);
6165 + if (!Page_Uptodate(page)) {
6166 + page = ERR_PTR(-EIO);
6167 + goto out;
6168 + }
6169 + }
6170 +
6171 + out:
6172 + print_exit_pointer(page);
6173 + return page;
6174 +}
6175 +
6176 +
6177 +/*
6178 + * get one page from cache or lower f/s, return error otherwise.
6179 + * similar to get1page, but doesn't guarantee that it will return
6180 + * an unlocked page.
6181 + */
6182 +page_t *
6183 +mini_fo_get1page_cached(file_t *file, int index)
6184 +{
6185 + page_t *page;
6186 + dentry_t *dentry;
6187 + inode_t *inode;
6188 + struct address_space *mapping;
6189 + int err;
6190 +
6191 + print_entry_location();
6192 +
6193 + dentry = file->f_dentry; /* CPW: Moved below print_entry_location */
6194 + inode = dentry->d_inode;
6195 + mapping = inode->i_mapping;
6196 +
6197 + fist_dprint(8, "%s: read page index %d pid %d\n", __FUNCTION__, index, current->pid);
6198 + if (index < 0) {
6199 + printk("%s BUG: index=%d\n", __FUNCTION__, index);
6200 + page = ERR_PTR(-EIO);
6201 + goto out;
6202 + }
6203 + page = read_cache_page(mapping,
6204 + index,
6205 + (filler_t *) mapping->a_ops->readpage,
6206 + (void *) file);
6207 + if (IS_ERR(page))
6208 + goto out;
6209 +
6210 + out:
6211 + print_exit_pointer(page);
6212 + return page;
6213 +}
6214 +
6215 +
6216 +/*
6217 + * readpage is called from generic_page_read and the fault handler.
6218 + * If your file system uses generic_page_read for the read op, it
6219 + * must implement readpage.
6220 + *
6221 + * Readpage expects a locked page, and must unlock it.
6222 + */
6223 +STATIC int
6224 +mini_fo_do_readpage(file_t *file, page_t *page)
6225 +{
6226 + int err = -EIO;
6227 + dentry_t *dentry;
6228 + file_t *hidden_file = NULL;
6229 + dentry_t *hidden_dentry;
6230 + inode_t *inode;
6231 + inode_t *hidden_inode;
6232 + char *page_data;
6233 + page_t *hidden_page;
6234 + char *hidden_page_data;
6235 + int real_size;
6236 +
6237 + print_entry_location();
6238 +
6239 + dentry = file->f_dentry; /* CPW: Moved below print_entry_location */
6240 + if (ftopd(file) != NULL)
6241 + hidden_file = ftohf(file);
6242 + hidden_dentry = dtohd(dentry);
6243 + inode = dentry->d_inode;
6244 + hidden_inode = itohi(inode);
6245 +
6246 + fist_dprint(7, "%s: requesting page %d from file %s\n", __FUNCTION__, page->index, dentry->d_name.name);
6247 +
6248 + MALLOC_PAGE_POINTERS(hidden_pages, num_hidden_pages);
6249 + MALLOC_PAGEDATA_POINTERS(hidden_pages_data, num_hidden_pages);
6250 + FOR_EACH_PAGE
6251 + CURRENT_HIDDEN_PAGE = NULL;
6252 +
6253 + /* find lower page (returns a locked page) */
6254 + FOR_EACH_PAGE {
6255 + fist_dprint(8, "%s: Current page index = %d\n", __FUNCTION__, CURRENT_HIDDEN_PAGEINDEX);
6256 + CURRENT_HIDDEN_PAGE = read_cache_page(hidden_inode->i_mapping,
6257 + CURRENT_HIDDEN_PAGEINDEX,
6258 + (filler_t *) hidden_inode->i_mapping->a_ops->readpage,
6259 + (void *) hidden_file);
6260 + if (IS_ERR(CURRENT_HIDDEN_PAGE)) {
6261 + err = PTR_ERR(CURRENT_HIDDEN_PAGE);
6262 + CURRENT_HIDDEN_PAGE = NULL;
6263 + goto out_release;
6264 + }
6265 + }
6266 +
6267 + /*
6268 + * wait for the page data to show up
6269 + * (signaled by readpage as unlocking the page)
6270 + */
6271 + FOR_EACH_PAGE {
6272 + wait_on_page(CURRENT_HIDDEN_PAGE);
6273 + if (!Page_Uptodate(CURRENT_HIDDEN_PAGE)) {
6274 + /*
6275 + * call readpage() again if we returned from wait_on_page with a
6276 + * page that's not up-to-date; that can happen when a partial
6277 + * page has a few buffers which are ok, but not the whole
6278 + * page.
6279 + */
6280 + lock_page(CURRENT_HIDDEN_PAGE);
6281 + err = hidden_inode->i_mapping->a_ops->readpage(hidden_file,
6282 + CURRENT_HIDDEN_PAGE);
6283 + if (err) {
6284 + CURRENT_HIDDEN_PAGE = NULL;
6285 + goto out_release;
6286 + }
6287 + wait_on_page(CURRENT_HIDDEN_PAGE);
6288 + if (!Page_Uptodate(CURRENT_HIDDEN_PAGE)) {
6289 + err = -EIO;
6290 + goto out_release;
6291 + }
6292 + }
6293 + }
6294 +
6295 + /* map pages, get their addresses */
6296 + page_data = (char *) kmap(page);
6297 + FOR_EACH_PAGE
6298 + CURRENT_HIDDEN_PAGEDATA = (char *) kmap(CURRENT_HIDDEN_PAGE);
6299 +
6300 + /* if decode_block could fail, then return error */
6301 + err = 0;
6302 + real_size = hidden_inode->i_size - (page->index << PAGE_CACHE_SHIFT);
6303 + if (real_size <= 0)
6304 + memset(page_data, 0, PAGE_CACHE_SIZE);
6305 + else if (real_size < PAGE_CACHE_SIZE) {
6306 + mini_fo_decode_block(hidden_page_data, page_data, real_size, inode, inode->i_sb, page->index);
6307 + memset(page_data + real_size, 0, PAGE_CACHE_SIZE - real_size);
6308 + } else
6309 + mini_fo_decode_block(hidden_page_data, page_data, PAGE_CACHE_SIZE, inode, inode->i_sb, page->index);
6310 +
6311 + FOR_EACH_PAGE
6312 + kunmap(CURRENT_HIDDEN_PAGE);
6313 + kunmap(page);
6314 +
6315 + out_release:
6316 + FOR_EACH_PAGE
6317 + if (CURRENT_HIDDEN_PAGE)
6318 + page_cache_release(CURRENT_HIDDEN_PAGE); /* undo read_cache_page */
6319 +
6320 + FREE_PAGE_POINTERS(hidden_pages, num_hidden_pages);
6321 + FREE_PAGEDATA_POINTERS(hidden_pages_data, num_hidden_pages);
6322 +
6323 + out:
6324 + if (err == 0)
6325 + SetPageUptodate(page);
6326 + else
6327 + ClearPageUptodate(page);
6328 +
6329 + print_exit_status(err);
6330 + return err;
6331 +}
6332 +
6333 +
6334 +STATIC int
6335 +mini_fo_readpage(file_t *file, page_t *page)
6336 +{
6337 + int err;
6338 + print_entry_location();
6339 +
6340 + err = mini_fo_do_readpage(file, page);
6341 +
6342 + /*
6343 + * we have to unlock our page, b/c we _might_ have gotten a locked page.
6344 + * but we no longer have to wakeup on our page here, b/c UnlockPage does
6345 + * it
6346 + */
6347 + UnlockPage(page);
6348 +
6349 + print_exit_status(err);
6350 + return err;
6351 +}
6352 +
6353 +
6354 +STATIC int
6355 +mini_fo_prepare_write(file_t *file, page_t *page, unsigned from, unsigned to)
6356 +{
6357 + int err = 0;
6358 +
6359 + print_entry_location();
6360 +
6361 + /*
6362 + * we call kmap(page) only here, and do the kunmap
6363 + * and the actual downcalls, including unlockpage and uncache
6364 + * in commit_write.
6365 + */
6366 + kmap(page);
6367 +
6368 + /* fast path for whole page writes */
6369 + if (from == 0 && to == PAGE_CACHE_SIZE)
6370 + goto out;
6371 + /* read the page to "revalidate" our data */
6372 + /* call the helper function which doesn't unlock the page */
6373 + if (!Page_Uptodate(page))
6374 + err = mini_fo_do_readpage(file, page);
6375 +
6376 + out:
6377 + print_exit_status(err);
6378 + return err;
6379 +}
6380 +
6381 +
6382 +
6383 +STATIC int
6384 +mini_fo_commit_write(file_t *file, page_t *page, unsigned from, unsigned to)
6385 +{
6386 + int err = -ENOMEM;
6387 + inode_t *inode;
6388 + inode_t *hidden_inode;
6389 + page_t *hidden_page;
6390 + file_t *hidden_file = NULL;
6391 + loff_t pos;
6392 + unsigned bytes = to - from;
6393 + unsigned hidden_from, hidden_to, hidden_bytes;
6394 +
6395 + print_entry_location();
6396 +
6397 + inode = page->mapping->host; /* CPW: Moved below print_entry_location */
6398 + hidden_inode = itohi(inode);
6399 +
6400 + ASSERT(file != NULL);
6401 + /*
6402 + * here we have a kmapped page, with data from the user copied
6403 + * into it. we need to encode_block it, and then call the lower
6404 + * commit_write. We also need to simulate same behavior of
6405 + * generic_file_write, and call prepare_write on the lower f/s first.
6406 + */
6407 +#ifdef FIST_COUNT_WRITES
6408 + count_writes++;
6409 +# endif /* FIST_COUNT_WRITES */
6410 +
6411 + /* this is append and/or extend -- we can't have holes so fill them in */
6412 + if (page->index > (hidden_inode->i_size >> PAGE_CACHE_SHIFT)) {
6413 + page_t *tmp_page;
6414 + int index;
6415 + for (index = hidden_inode->i_size >> PAGE_CACHE_SHIFT; index < page->index; index++) {
6416 + tmp_page = mini_fo_get1page(file, index);
6417 + if (IS_ERR(tmp_page)) {
6418 + err = PTR_ERR(tmp_page);
6419 + goto out;
6420 + }
6421 + /* zero out the contents of the page at the appropriate offsets */
6422 + memset((char*)page_address(tmp_page) + (inode->i_size & ~PAGE_CACHE_MASK), 0, PAGE_CACHE_SIZE - (inode->i_size & ~PAGE_CACHE_MASK));
6423 + if (!(err = mini_fo_prepare_write(file, tmp_page, 0, PAGE_CACHE_SIZE)))
6424 + err = mini_fo_commit_write(file, tmp_page, 0, PAGE_CACHE_SIZE);
6425 + page_cache_release(tmp_page);
6426 + if (err < 0)
6427 + goto out;
6428 + if (current->need_resched)
6429 + schedule();
6430 + }
6431 + }
6432 +
6433 + if (ftopd(file) != NULL)
6434 + hidden_file = ftohf(file);
6435 +
6436 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
6437 + mutex_lock(&hidden_inode->i_mutex);
6438 +#else
6439 + down(&hidden_inode->i_sem);
6440 +#endif
6441 + /* find lower page (returns a locked page) */
6442 + hidden_page = grab_cache_page(hidden_inode->i_mapping, page->index);
6443 + if (!hidden_page)
6444 + goto out;
6445 +
6446 +#if FIST_ENCODING_BLOCKSIZE > 1
6447 +# error encoding_blocksize greater than 1 is not yet supported
6448 +# endif /* FIST_ENCODING_BLOCKSIZE > 1 */
6449 +
6450 + hidden_from = from & (~(FIST_ENCODING_BLOCKSIZE - 1));
6451 + hidden_to = ((to + FIST_ENCODING_BLOCKSIZE - 1) & (~(FIST_ENCODING_BLOCKSIZE - 1)));
6452 + if ((page->index << PAGE_CACHE_SHIFT) + to > hidden_inode->i_size) {
6453 +
6454 + /*
6455 + * if this call to commit_write had introduced holes and the code
6456 + * for handling holes was invoked, then the beginning of this page
6457 + * must be zeroed out
6458 + * zero out bytes from 'size_of_file%pagesize' to 'from'.
6459 + */
6460 + if ((hidden_from - (inode->i_size & ~PAGE_CACHE_MASK)) > 0)
6461 + memset((char*)page_address(page) + (inode->i_size & ~PAGE_CACHE_MASK), 0, hidden_from - (inode->i_size & ~PAGE_CACHE_MASK));
6462 +
6463 + }
6464 + hidden_bytes = hidden_to - hidden_from;
6465 +
6466 + /* call lower prepare_write */
6467 + err = -EINVAL;
6468 + if (hidden_inode->i_mapping &&
6469 + hidden_inode->i_mapping->a_ops &&
6470 + hidden_inode->i_mapping->a_ops->prepare_write)
6471 + err = hidden_inode->i_mapping->a_ops->prepare_write(hidden_file,
6472 + hidden_page,
6473 + hidden_from,
6474 + hidden_to);
6475 + if (err)
6476 + /* don't leave locked pages behind, esp. on an ENOSPC */
6477 + goto out_unlock;
6478 +
6479 + fist_dprint(8, "%s: encoding %d bytes\n", __FUNCTION__, hidden_bytes);
6480 + mini_fo_encode_block((char *) page_address(page) + hidden_from, (char*) page_address(hidden_page) + hidden_from, hidden_bytes, inode, inode->i_sb, page->index);
6481 + /* if encode_block could fail, then goto unlock and return error */
6482 +
6483 + /* call lower commit_write */
6484 + err = hidden_inode->i_mapping->a_ops->commit_write(hidden_file,
6485 + hidden_page,
6486 + hidden_from,
6487 + hidden_to);
6488 +
6489 + if (err < 0)
6490 + goto out_unlock;
6491 +
6492 + err = bytes; /* convert error to no. of bytes */
6493 +
6494 + inode->i_blocks = hidden_inode->i_blocks;
6495 + /* we may have to update i_size */
6496 + pos = (page->index << PAGE_CACHE_SHIFT) + to;
6497 + if (pos > inode->i_size)
6498 + inode->i_size = pos;
6499 +
6500 + /*
6501 + * update mtime and ctime of lower level file system
6502 + * mini_fo' mtime and ctime are updated by generic_file_write
6503 + */
6504 + hidden_inode->i_mtime = hidden_inode->i_ctime = CURRENT_TIME;
6505 +
6506 + mark_inode_dirty_sync(inode);
6507 +
6508 + out_unlock:
6509 + UnlockPage(hidden_page);
6510 + page_cache_release(hidden_page);
6511 + kunmap(page); /* kmap was done in prepare_write */
6512 + out:
6513 + /* we must set our page as up-to-date */
6514 + if (err < 0)
6515 + ClearPageUptodate(page);
6516 + else
6517 + SetPageUptodate(page);
6518 +
6519 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
6520 + mutex_unlock(&hidden_inode->i_mutex);
6521 +#else
6522 + up(&hidden_inode->i_sem);
6523 +#endif
6524 + print_exit_status(err);
6525 + return err; /* assume all is ok */
6526 +}
6527 +
6528 +
6529 +STATIC int
6530 +mini_fo_bmap(struct address_space *mapping, long block)
6531 +{
6532 + int err = 0;
6533 + inode_t *inode;
6534 + inode_t *hidden_inode;
6535 +
6536 + print_entry_location();
6537 +
6538 + inode = (inode_t *) mapping->host;
6539 + hidden_inode = itohi(inode);
6540 +
6541 + if (hidden_inode->i_mapping->a_ops->bmap)
6542 + err = hidden_inode->i_mapping->a_ops->bmap(hidden_inode->i_mapping, block);
6543 + print_exit_location();
6544 + return err;
6545 +}
6546 +
6547 +
6548 +/*
6549 + * This function is copied verbatim from mm/filemap.c.
6550 + * XXX: It should be simply moved to some header file instead -- bug Al about it!
6551 + */
6552 +static inline int sync_page(struct page *page)
6553 +{
6554 + struct address_space *mapping = page->mapping;
6555 +
6556 + if (mapping && mapping->a_ops && mapping->a_ops->sync_page)
6557 + return mapping->a_ops->sync_page(page);
6558 + return 0;
6559 +}
6560 +
6561 +
6562 +/*
6563 + * XXX: we may not need this function if not FIST_FILTER_DATA.
6564 + * FIXME: for FIST_FILTER_SCA, get all lower pages and sync them each.
6565 + */
6566 +STATIC int
6567 +mini_fo_sync_page(page_t *page)
6568 +{
6569 + int err = 0;
6570 + inode_t *inode;
6571 + inode_t *hidden_inode;
6572 + page_t *hidden_page;
6573 +
6574 + print_entry_location();
6575 +
6576 + inode = page->mapping->host; /* CPW: Moved below print_entry_location */
6577 + hidden_inode = itohi(inode);
6578 +
6579 + /* find lower page (returns a locked page) */
6580 + hidden_page = grab_cache_page(hidden_inode->i_mapping, page->index);
6581 + if (!hidden_page)
6582 + goto out;
6583 +
6584 + err = sync_page(hidden_page);
6585 +
6586 + UnlockPage(hidden_page); /* b/c grab_cache_page locked it */
6587 + page_cache_release(hidden_page); /* b/c grab_cache_page increased refcnt */
6588 +
6589 + out:
6590 + print_exit_status(err);
6591 + return err;
6592 +}
6593 --- /dev/null
6594 +++ b/fs/mini_fo/README
6595 @@ -0,0 +1,163 @@
6596 +README for the mini_fo overlay file system
6597 +=========================================
6598 +
6599 +
6600 +WHAT IS MINI_FO?
6601 +----------------
6602 +
6603 +mini_fo is a virtual kernel file system that can make read-only
6604 +file systems writable. This is done by redirecting modifying operations
6605 +to a writeable location called "storage directory", and leaving the
6606 +original data in the "base directory" untouched. When reading, the
6607 +file system merges the modifed and original data so that only the
6608 +newest versions will appear. This occurs transparently to the user,
6609 +who can access the data like on any other read-write file system.
6610 +
6611 +Base and storage directories may be located on the same or on
6612 +different partitions and may be of different file system types. While
6613 +the storage directory obviously needs to be writable, the base may or
6614 +may not be writable, what doesn't matter as it will no be modified
6615 +anyway.
6616 +
6617 +
6618 +WHAT IS GOOD FOR?
6619 +-----------------
6620 +
6621 +The primary purpose of the mini_fo file system is to allow easy
6622 +software updates to embedded systems, that often store their root
6623 +file system in a read-only flash file system, but there are many
6624 +more as for example sandboxing, or for allowing live-cds to
6625 +permanently store information.
6626 +
6627 +
6628 +BUILDING
6629 +--------
6630 +This should be simple. Adjust the Makefile to point to the correct
6631 +kernel headers you want to build the module for. Then:
6632 +
6633 + # make
6634 +
6635 +should build "mini_fo.o" for a 2.4 kernel or "mini_fo.ko" for a 2.6
6636 +kernel.
6637 +
6638 +If you are building the module for you current kernel, you can install
6639 +the module (as root):
6640 +
6641 + # make install
6642 +
6643 +or uninstall with
6644 +
6645 + # make uninstall
6646 +
6647 +
6648 +USING THE FILE SYSTEM
6649 +--------------------
6650 +
6651 +the general mount syntax is:
6652 +
6653 + mount -t mini_fo -o base=<base directory>,sto=<storage directory>\
6654 + <base directory> <mount point>
6655 +
6656 +Example:
6657 +
6658 +You have mounted a cdrom to /mnt/cdrom and want to modifiy some files
6659 +on it:
6660 +
6661 +load the module (as root)
6662 +
6663 + # insmod mini_fo.o for a 2.4 kernel or
6664 +
6665 + # insmod mini_fo.ko for a 2.6 kernel
6666 +
6667 +
6668 +create a storage dir in tmp and a mountpoint for mini_fo:
6669 +
6670 + # mkdir /tmp/sto
6671 + # mkdir /mnt/mini_fo
6672 +
6673 +and mount the mini_fo file system:
6674 +
6675 + # mount -t mini_fo -o base=/mnt/cdrom,sto=/tmp/sto /mnt/cdrom /mnt/mini_fo
6676 +
6677 +
6678 +Now the data stored on the cd can be accessed via the mini_fo
6679 +mountpoint just like any read-write file system, files can be modified
6680 +and deleted, new ones can be created and so on. When done unmount the
6681 +file system:
6682 +
6683 + # unmount /mnt/mini_fo
6684 +
6685 +Note that if the file system is mounted again using the same storage
6686 +file system, of course it will appear in the modified state again. If
6687 +you remount it using an new empty storage directory, it will be
6688 +unmodified. Therefore by executing:
6689 +
6690 + # cd /tmp/sto
6691 + # rm -rf *
6692 +
6693 +you can nuke all the changes you made to the original file system. But
6694 + remember NEVER do this while the mini_fo file system is mounted!
6695 +
6696 +
6697 +Alternatively you can use the mini_fo-overlay bash script, that
6698 +simplifies managing mini_fo mounts. See TOOLS Section.
6699 +
6700 +
6701 +TOOLS
6702 +-----
6703 +
6704 +mini_fo-merge (experimental):
6705 +
6706 +This is a bash script that will merge changes contained in the storage
6707 +directory back to the base directory. This allows mini_fo to function
6708 +as a cache file system by overlaying a slow (network, ...) file system
6709 +and using a fast (ramdisk, ...) as storage. When done, changes can be
6710 +merged back to the (slow) base with mini_fo-merge. See "mini_fo-merge
6711 +-h" for details.
6712 +
6713 +It can be usefull for merging changes back after a successfull test
6714 +(patches, software updates...)
6715 +
6716 +
6717 +mini_fo-overlay:
6718 +
6719 +This bash script simplifies managing one or more mini_fo mounts. For
6720 +overlaying a directory called "basedir1", you can just call:
6721 +
6722 + # mini_fo-overlay basedir1
6723 +
6724 +This will mount mini_fo with "basedir1" as base, "/tmp/sto-basedir1/"
6725 +as storage to "/mnt/mini_fo-basedir1/". It has more options though,
6726 +type "mini_fo-overlay -h" for details.
6727 +
6728 +
6729 +DOCUMENTATION, REPORTING BUGS, GETTING HELP
6730 +-------------------------------------------
6731 +
6732 +Please visit the mini_fo project page at:
6733 +
6734 +http://www.denx.de/twiki/bin/view/Know/MiniFOHome
6735 +
6736 +
6737 +WARNINGS
6738 +--------
6739 +
6740 +Never modify the base or the storage directorys while the mini_fo
6741 +file system is mounted, or you might crash you system. Simply accessing
6742 +and reading should not cause any trouble.
6743 +
6744 +Exporting a mini_fo mount point via NFS has not been tested, and may
6745 +or may not work.
6746 +
6747 +Check the RELEASE_NOTES for details on bugs and features.
6748 +
6749 +
6750 +
6751 +Copyright (C) 2004, 2005 Markus Klotzbuecher <mk@creamnet.de>
6752 +
6753 +This program is free software; you can redistribute it and/or
6754 +modify it under the terms of the GNU General Public License
6755 +as published by the Free Software Foundation; either version
6756 +2 of the License, or (at your option) any later version.
6757 +
6758 +
6759 --- /dev/null
6760 +++ b/fs/mini_fo/RELEASE_NOTES
6761 @@ -0,0 +1,111 @@
6762 +Release: mini_fo-0.6.1 (v0-6-1)
6763 +Date: 21.09.2005
6764 +
6765 +
6766 +Changes:
6767 +--------
6768 +v0-6-1:
6769 +
6770 +- bugfixes (see ChangeLog)
6771 +
6772 +- two helper scripts "mini_fo_merge" and "mini_fo_overlay" (see
6773 + README for details).
6774 +
6775 +v0-6-0:
6776 +
6777 +- Support for 2.4 and 2.6 (see Makefile)
6778 +
6779 +- Partial hard link support (creating works as expected, but already
6780 + existing links in the base file system will be treated as if they
6781 + were individual files).
6782 +
6783 +- Various bugfixes and cleanups.
6784 +
6785 +
6786 +v0-6-0-pre1:
6787 +
6788 +- This is mini_fo-0-6-0-pre1! This release is a complete rewrite of
6789 + many vital mini_fo parts such as the old whiteout list code which
6790 + has been replaced by the new META subsystem.
6791 +
6792 +- Light weight directory renaming implemented. This means if a
6793 + directory is renamed via the mini_fo filesystem this will no longer
6794 + result in a complete copy in storage, instead only one empty
6795 + directory will be created. All base filed contained in the original
6796 + directory stay there until modified.
6797 +
6798 +- Special files (creating, renaming, deleting etc.) now working.
6799 +
6800 +- Many bugfixes and cleanup, mini_fo is now a lot more stable.
6801 +
6802 +
6803 +v0-5-10:
6804 +
6805 +- Final release of the 0-5-* versions. Next will be a complete rewrite
6806 + of many features. This release contains several bugfixes related to
6807 + directory renaming.
6808 +
6809 +
6810 +v0-5-10-pre6:
6811 +
6812 +- Lots of cleanup and several bugfixes related to directory deleting
6813 +
6814 +- Directory renaming suddenly works, what is most likely due to the
6815 + fact tha that "mv" is smart: if the classic rename doesn't work it
6816 + will assume that source and target file are on different fs and will
6817 + copy the directory and try to remove the source directory. Until
6818 + directory removing wasn't implemented, it would fail to do this and
6819 + rollback.
6820 + So, directory renaming works for now, but it doesn't yet do what you
6821 + would expect from a overlay fs, so use with care.
6822 +
6823 +
6824 +v0-5-10-pre5:
6825 +
6826 +- implemented directory deleting
6827 +- made parsing of mount options more stable
6828 +- New format of mount options! (See README)
6829 +- I can't reproduce the unknown panic with 2.4.25 anymore, so I'll
6830 + happily assume it never existed!
6831 +
6832 +
6833 +Implemented features:
6834 +---------------------
6835 +
6836 +- creating hard links (see BUGS on already existing hard links)
6837 +- lightweight directory renaming
6838 +- renaming device files, pipes, sockets, etc.
6839 +- creating, renaming, deleting of special files
6840 +- deleting directorys
6841 +- general directory reading (simple "ls" )
6842 +- creating files in existing directorys
6843 +- creating directorys
6844 +- renaming files.
6845 +- reading and writing files (involves opening)
6846 +- appending to files (creates copy in storage)
6847 +- deleting files
6848 +- llseek works too, what allows editors to work
6849 +- persistency (a deleted file stay deleted over remounts)
6850 +- use of symbolic links
6851 +- creating of device files
6852 +
6853 +
6854 +Not (yet) implemented features:
6855 +-------------------------------
6856 +
6857 +- full hard link support.
6858 +
6859 +
6860 +
6861 +BUGS:
6862 +-----
6863 +
6864 +Hard links in the base file system will be treated as individual
6865 +files, not as links to one inode.
6866 +
6867 +The main problem with hard links isn't allowing to create them, but
6868 +their pure existence. If you modify a base hard link, the changes made
6869 +will only show up on this link, the other link will remain in the
6870 +original state. I hope to fix this someday. Please note that this does
6871 +not effect the special hard links '.' and '..', that are handled
6872 +seperately by the lower fs.
6873 --- /dev/null
6874 +++ b/fs/mini_fo/state.c
6875 @@ -0,0 +1,620 @@
6876 +/*
6877 + * Copyright (C) 2005 Markus Klotzbuecher <mk@creamnet.de>
6878 + *
6879 + * This program is free software; you can redistribute it and/or
6880 + * modify it under the terms of the GNU General Public License
6881 + * as published by the Free Software Foundation; either version
6882 + * 2 of the License, or (at your option) any later version.
6883 + */
6884 +
6885 +#ifdef HAVE_CONFIG_H
6886 +# include <config.h>
6887 +#endif /* HAVE_CONFIG_H */
6888 +
6889 +#include "fist.h"
6890 +#include "mini_fo.h"
6891 +
6892 +
6893 +/* create the storage file, setup new states */
6894 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
6895 +int create_sto_reg_file(dentry_t *dentry, int mode, struct nameidata *nd)
6896 +#else
6897 +int create_sto_reg_file(dentry_t *dentry, int mode)
6898 +#endif
6899 +{
6900 + int err = 0;
6901 + inode_t *dir;
6902 + dentry_t *hidden_sto_dentry;
6903 + dentry_t *hidden_sto_dir_dentry;
6904 +
6905 + if(exists_in_storage(dentry)) {
6906 + printk(KERN_CRIT "mini_fo: create_sto_file: wrong type or state.\n");
6907 + err = -EINVAL;
6908 + goto out;
6909 + }
6910 + err = get_neg_sto_dentry(dentry);
6911 +
6912 + if (err) {
6913 + printk(KERN_CRIT "mini_fo: create_sto_file: ERROR getting neg. sto dentry.\n");
6914 + goto out;
6915 + }
6916 +
6917 + dir = dentry->d_parent->d_inode;
6918 + hidden_sto_dentry = dtohd2(dentry);
6919 +
6920 + /* lock parent */
6921 + hidden_sto_dir_dentry = dget(hidden_sto_dentry->d_parent);
6922 +
6923 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
6924 + mutex_lock(&hidden_sto_dir_dentry->d_inode->i_mutex);
6925 +#else
6926 + down(&hidden_sto_dir_dentry->d_inode->i_sem);
6927 +#endif
6928 +
6929 + err = PTR_ERR(hidden_sto_dir_dentry);
6930 + if (IS_ERR(hidden_sto_dir_dentry))
6931 + goto out;
6932 +
6933 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
6934 + err = vfs_create(hidden_sto_dir_dentry->d_inode,
6935 + hidden_sto_dentry,
6936 + mode, nd);
6937 +#else
6938 + err = vfs_create(hidden_sto_dir_dentry->d_inode,
6939 + hidden_sto_dentry,
6940 + mode);
6941 +#endif
6942 + if(err) {
6943 + printk(KERN_CRIT "mini_fo: create_sto_file: ERROR creating sto file.\n");
6944 + goto out_lock;
6945 + }
6946 +
6947 + if(!dtohd2(dentry)->d_inode) {
6948 + printk(KERN_CRIT "mini_fo: create_sto_file: ERROR creating sto file [2].\n");
6949 + err = -EINVAL;
6950 + goto out_lock;
6951 + }
6952 +
6953 + /* interpose the new inode */
6954 + if(dtost(dentry) == DELETED) {
6955 + dtost(dentry) = DEL_REWRITTEN;
6956 + err = mini_fo_tri_interpose(NULL, hidden_sto_dentry, dentry, dir->i_sb, 0);
6957 + if(err)
6958 + goto out_lock;
6959 + }
6960 + else if(dtost(dentry) == NON_EXISTANT) {
6961 + dtost(dentry) = CREATED;
6962 + err = mini_fo_tri_interpose(dtohd(dentry), hidden_sto_dentry, dentry, dir->i_sb, 0);
6963 + if(err)
6964 + goto out_lock;
6965 + }
6966 + else if(dtost(dentry) == UNMODIFIED) {
6967 + dtost(dentry) = MODIFIED;
6968 + /* interpose on new inode */
6969 + if(itohi2(dentry->d_inode) != NULL) {
6970 + printk(KERN_CRIT "mini_fo: create_sto_file: invalid inode detected.\n");
6971 + err = -EINVAL;
6972 + goto out_lock;
6973 + }
6974 + itohi2(dentry->d_inode) = igrab(dtohd2(dentry)->d_inode);
6975 + }
6976 + fist_copy_attr_timesizes(dentry->d_parent->d_inode,
6977 + hidden_sto_dir_dentry->d_inode);
6978 +
6979 + out_lock:
6980 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
6981 + mutex_unlock(&hidden_sto_dir_dentry->d_inode->i_mutex);
6982 +#else
6983 + up(&hidden_sto_dir_dentry->d_inode->i_sem);
6984 +#endif
6985 + dput(hidden_sto_dir_dentry);
6986 + out:
6987 + return err;
6988 +}
6989 +
6990 +/* create the sto dir, setup states */
6991 +int create_sto_dir(dentry_t *dentry, int mode)
6992 +{
6993 + int err = 0;
6994 + inode_t *dir;
6995 + dentry_t *hidden_sto_dentry;
6996 + dentry_t *hidden_sto_dir_dentry;
6997 +
6998 + /* had to take the "!S_ISDIR(mode))" check out, because it failed */
6999 + if(exists_in_storage(dentry)) {
7000 + printk(KERN_CRIT "mini_fo: create_sto_dir: wrong type or state.\\
7001 +n");
7002 + err = -EINVAL;
7003 + goto out;
7004 + }
7005 +
7006 + err = get_neg_sto_dentry(dentry);
7007 + if(err) {
7008 + err = -EINVAL;
7009 + goto out;
7010 + }
7011 +
7012 + dir = dentry->d_parent->d_inode;
7013 + hidden_sto_dentry = dtohd2(dentry);
7014 +
7015 + /* was: hidden_sto_dir_dentry = lock_parent(hidden_sto_dentry); */
7016 + hidden_sto_dir_dentry = dget(hidden_sto_dentry->d_parent);
7017 +
7018 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
7019 + mutex_lock(&hidden_sto_dir_dentry->d_inode->i_mutex);
7020 +#else
7021 + down(&hidden_sto_dir_dentry->d_inode->i_sem);
7022 +#endif
7023 +
7024 + err = PTR_ERR(hidden_sto_dir_dentry);
7025 + if (IS_ERR(hidden_sto_dir_dentry))
7026 + goto out;
7027 +
7028 + err = vfs_mkdir(hidden_sto_dir_dentry->d_inode,
7029 + hidden_sto_dentry,
7030 + mode);
7031 + if(err) {
7032 + printk(KERN_CRIT "mini_fo: create_sto_dir: ERROR creating sto dir.\n");
7033 + goto out_lock;
7034 + }
7035 +
7036 + if(!dtohd2(dentry)->d_inode) {
7037 + printk(KERN_CRIT "mini_fo: create_sto_dir: ERROR creating sto dir [2].\n");
7038 + err = -EINVAL;
7039 + goto out_lock;
7040 + }
7041 +
7042 + /* interpose the new inode */
7043 + if(dtost(dentry) == DELETED) {
7044 + dtost(dentry) = DEL_REWRITTEN;
7045 + err = mini_fo_tri_interpose(NULL, hidden_sto_dentry, dentry, dir->i_sb, 0);
7046 + if(err)
7047 + goto out_lock;
7048 + }
7049 + else if(dtopd(dentry)->state == NON_EXISTANT) {
7050 + dtopd(dentry)->state = CREATED;
7051 + err = mini_fo_tri_interpose(dtohd(dentry), hidden_sto_dentry, dentry, dir->i_sb, 0);
7052 + if(err)
7053 + goto out_lock;
7054 + }
7055 + else if(dtopd(dentry)->state == UNMODIFIED) {
7056 + dtopd(dentry)->state = MODIFIED;
7057 + /* interpose on new inode */
7058 + if(itohi2(dentry->d_inode) != NULL) {
7059 + printk(KERN_CRIT "mini_fo: create_sto_dir: ERROR, invalid inode detected.\n");
7060 + err = -EINVAL;
7061 + goto out_lock;
7062 + }
7063 + itohi2(dentry->d_inode) = igrab(dtohd2(dentry)->d_inode);
7064 + }
7065 +
7066 + fist_copy_attr_timesizes(dir, hidden_sto_dir_dentry->d_inode);
7067 +
7068 + /* initalize the wol list */
7069 + itopd(dentry->d_inode)->deleted_list_size = -1;
7070 + itopd(dentry->d_inode)->renamed_list_size = -1;
7071 + meta_build_lists(dentry);
7072 +
7073 +
7074 + out_lock:
7075 + /* was: unlock_dir(hidden_sto_dir_dentry); */
7076 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
7077 + mutex_unlock(&hidden_sto_dir_dentry->d_inode->i_mutex);
7078 +#else
7079 + up(&hidden_sto_dir_dentry->d_inode->i_sem);
7080 +#endif
7081 + dput(hidden_sto_dir_dentry);
7082 + out:
7083 + return err;
7084 +}
7085 +
7086 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
7087 +int create_sto_nod(dentry_t *dentry, int mode, dev_t dev)
7088 +#else
7089 +int create_sto_nod(dentry_t *dentry, int mode, int dev)
7090 +#endif
7091 +{
7092 + int err = 0;
7093 + inode_t *dir;
7094 + dentry_t *hidden_sto_dentry;
7095 + dentry_t *hidden_sto_dir_dentry;
7096 +
7097 + if(exists_in_storage(dentry)) {
7098 + err = -EEXIST;
7099 + goto out;
7100 + }
7101 + err = get_neg_sto_dentry(dentry);
7102 +
7103 + if (err) {
7104 + printk(KERN_CRIT "mini_fo: create_sto_nod: ERROR getting neg. sto dentry.\n");
7105 + goto out;
7106 + }
7107 +
7108 + dir = dentry->d_parent->d_inode;
7109 + hidden_sto_dentry = dtohd2(dentry);
7110 +
7111 + /* lock parent */
7112 + hidden_sto_dir_dentry = dget(hidden_sto_dentry->d_parent);
7113 +
7114 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
7115 + mutex_lock(&hidden_sto_dir_dentry->d_inode->i_mutex);
7116 +#else
7117 + down(&hidden_sto_dir_dentry->d_inode->i_sem);
7118 +#endif
7119 +
7120 + err = PTR_ERR(hidden_sto_dir_dentry);
7121 + if (IS_ERR(hidden_sto_dir_dentry))
7122 + goto out;
7123 +
7124 + err = vfs_mknod(hidden_sto_dir_dentry->d_inode, hidden_sto_dentry, mode, dev);
7125 + if(err)
7126 + goto out_lock;
7127 +
7128 + if(!dtohd2(dentry)->d_inode) {
7129 + printk(KERN_CRIT "mini_fo: create_sto_nod: creating storage inode failed [1].\n");
7130 + err = -EINVAL; /* return something indicating failure */
7131 + goto out_lock;
7132 + }
7133 +
7134 + /* interpose the new inode */
7135 + if(dtost(dentry) == DELETED) {
7136 + dtost(dentry) = DEL_REWRITTEN;
7137 + err = mini_fo_tri_interpose(NULL, hidden_sto_dentry, dentry, dir->i_sb, 0);
7138 + if(err)
7139 + goto out_lock;
7140 + }
7141 + else if(dtost(dentry) == NON_EXISTANT) {
7142 + dtost(dentry) = CREATED;
7143 + err = mini_fo_tri_interpose(dtohd(dentry), hidden_sto_dentry, dentry, dir->i_sb, 0);
7144 + if(err)
7145 + goto out_lock;
7146 + }
7147 + else if(dtost(dentry) == UNMODIFIED) {
7148 + dtost(dentry) = MODIFIED;
7149 + /* interpose on new inode */
7150 + if(itohi2(dentry->d_inode) != NULL) {
7151 + printk(KERN_CRIT "mini_fo: create_sto_nod: error, invalid inode detected.\n");
7152 + err = -EINVAL;
7153 + goto out_lock;
7154 + }
7155 + itohi2(dentry->d_inode) = igrab(dtohd2(dentry)->d_inode);
7156 + }
7157 +
7158 + fist_copy_attr_timesizes(dir, hidden_sto_dir_dentry->d_inode);
7159 +
7160 + out_lock:
7161 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
7162 + mutex_unlock(&hidden_sto_dir_dentry->d_inode->i_mutex);
7163 +#else
7164 + up(&hidden_sto_dir_dentry->d_inode->i_sem);
7165 +#endif
7166 + dput(hidden_sto_dir_dentry);
7167 + out:
7168 + return err;
7169 +}
7170 +
7171 +
7172 +/* unimplemented (and possibly not usefull):
7173 +
7174 + nondir-del_to_del_rew
7175 + nondir-non_exist_to_creat
7176 +
7177 + dir-unmod_to_del
7178 + dir-mod_to_del
7179 + dir-creat_to_del
7180 + dir-del_rew_to_del
7181 + dir-del_to_del_rew
7182 + dir-non_exist_to_creat
7183 +*/
7184 +
7185 +
7186 +/* bring a file of any type from state UNMODIFIED to MODIFIED */
7187 +int nondir_unmod_to_mod(dentry_t *dentry, int cp_flag)
7188 +{
7189 + int err = 0;
7190 + struct vfsmount *tgt_mnt;
7191 + struct vfsmount *src_mnt;
7192 + dentry_t *tgt_dentry;
7193 + dentry_t *src_dentry;
7194 + dentry_t *hidden_sto_dentry;
7195 + dentry_t *hidden_sto_dir_dentry;
7196 +
7197 + check_mini_fo_dentry(dentry);
7198 +
7199 + if((dtost(dentry) != UNMODIFIED) ||
7200 + S_ISDIR(dentry->d_inode->i_mode)) {
7201 + printk(KERN_CRIT "mini_fo: nondir_unmod_to_mod: \
7202 + wrong type or state.\n");
7203 + err = -1;
7204 + goto out;
7205 + }
7206 + err = get_neg_sto_dentry(dentry);
7207 +
7208 + if (err) {
7209 + printk(KERN_CRIT "mini_fo: nondir_unmod_to_mod: \
7210 + ERROR getting neg. sto dentry.\n");
7211 + goto out;
7212 + }
7213 +
7214 + /* create sto file */
7215 + hidden_sto_dentry = dtohd2(dentry);
7216 +
7217 + /* lock parent */
7218 + hidden_sto_dir_dentry = dget(hidden_sto_dentry->d_parent);
7219 +
7220 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
7221 + mutex_lock(&hidden_sto_dir_dentry->d_inode->i_mutex);
7222 +#else
7223 + down(&hidden_sto_dir_dentry->d_inode->i_sem);
7224 +#endif
7225 +
7226 + err = PTR_ERR(hidden_sto_dir_dentry);
7227 + if (IS_ERR(hidden_sto_dir_dentry))
7228 + goto out;
7229 +
7230 + /* handle different types of nondirs */
7231 + if(S_ISCHR(dentry->d_inode->i_mode) ||
7232 + S_ISBLK(dentry->d_inode->i_mode)) {
7233 + err = vfs_mknod(hidden_sto_dir_dentry->d_inode,
7234 + hidden_sto_dentry,
7235 + dtohd(dentry)->d_inode->i_mode,
7236 + dtohd(dentry)->d_inode->i_rdev);
7237 + }
7238 +
7239 + else if(S_ISREG(dentry->d_inode->i_mode)) {
7240 +
7241 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
7242 + err = vfs_create(hidden_sto_dir_dentry->d_inode,
7243 + hidden_sto_dentry,
7244 + dtohd(dentry)->d_inode->i_mode, NULL);
7245 +#else
7246 + err = vfs_create(hidden_sto_dir_dentry->d_inode,
7247 + hidden_sto_dentry,
7248 + dtohd(dentry)->d_inode->i_mode);
7249 +#endif
7250 + }
7251 + if(err) {
7252 + printk(KERN_CRIT "mini_fo: nondir_unmod_to_mod: \
7253 + ERROR creating sto file.\n");
7254 + goto out_lock;
7255 + }
7256 +
7257 + /* interpose on new inode */
7258 + if(itohi2(dentry->d_inode) != NULL) {
7259 + printk(KERN_CRIT "mini_fo: nondir_unmod_to_mod: \
7260 + ERROR, invalid inode detected.\n");
7261 + err = -EINVAL;
7262 + goto out_lock;
7263 + }
7264 +
7265 + itohi2(dentry->d_inode) = igrab(dtohd2(dentry)->d_inode);
7266 +
7267 + fist_copy_attr_timesizes(dentry->d_parent->d_inode,
7268 + hidden_sto_dir_dentry->d_inode);
7269 + dtost(dentry) = MODIFIED;
7270 +
7271 + /* copy contents if regular file and cp_flag = 1 */
7272 + if((cp_flag == 1) && S_ISREG(dentry->d_inode->i_mode)) {
7273 +
7274 + /* unlock first */
7275 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
7276 + mutex_unlock(&hidden_sto_dir_dentry->d_inode->i_mutex);
7277 +#else
7278 + up(&hidden_sto_dir_dentry->d_inode->i_sem);
7279 +#endif
7280 +
7281 + dput(hidden_sto_dir_dentry);
7282 +
7283 + tgt_dentry = dtohd2(dentry);
7284 + tgt_mnt = stopd(dentry->d_inode->i_sb)->hidden_mnt2;
7285 + src_dentry = dtohd(dentry);
7286 + src_mnt = stopd(dentry->d_inode->i_sb)->hidden_mnt;
7287 +
7288 + err = mini_fo_cp_cont(tgt_dentry, tgt_mnt,
7289 + src_dentry, src_mnt);
7290 + if(err) {
7291 + printk(KERN_CRIT "mini_fo: nondir_unmod_to_mod: \
7292 + ERROR copying contents.\n");
7293 + }
7294 + goto out;
7295 + }
7296 +
7297 + out_lock:
7298 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
7299 + mutex_unlock(&hidden_sto_dir_dentry->d_inode->i_mutex);
7300 +#else
7301 + up(&hidden_sto_dir_dentry->d_inode->i_sem);
7302 +#endif
7303 + dput(hidden_sto_dir_dentry);
7304 + out:
7305 + return err;
7306 +}
7307 +
7308 +/* this function is currently identical to nondir_creat_to_del */
7309 +int nondir_del_rew_to_del(dentry_t *dentry)
7310 +{
7311 + return nondir_creat_to_del(dentry);
7312 +}
7313 +
7314 +int nondir_creat_to_del(dentry_t *dentry)
7315 +{
7316 + int err = 0;
7317 +
7318 + inode_t *hidden_sto_dir_inode;
7319 + dentry_t *hidden_sto_dir_dentry;
7320 + dentry_t *hidden_sto_dentry;
7321 +
7322 + check_mini_fo_dentry(dentry);
7323 +
7324 + /* for now this function serves for both state DEL_REWRITTEN and
7325 + * CREATED */
7326 + if(!(dtost(dentry) == CREATED || (dtost(dentry) == DEL_REWRITTEN)) ||
7327 + S_ISDIR(dentry->d_inode->i_mode)) {
7328 + printk(KERN_CRIT "mini_fo: nondir_mod_to_del/del_rew_to_del: \
7329 + wrong type or state.\n");
7330 + err = -1;
7331 + goto out;
7332 + }
7333 +
7334 + hidden_sto_dir_inode = itohi2(dentry->d_parent->d_inode);
7335 + hidden_sto_dentry = dtohd2(dentry);
7336 +
7337 + /* was: hidden_sto_dir_dentry = lock_parent(hidden_sto_dentry);*/
7338 + hidden_sto_dir_dentry = dget(hidden_sto_dentry->d_parent);
7339 +
7340 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
7341 + mutex_lock(&hidden_sto_dir_dentry->d_inode->i_mutex);
7342 +#else
7343 + down(&hidden_sto_dir_dentry->d_inode->i_sem);
7344 +#endif
7345 +
7346 + /* avoid destroying the hidden inode if the file is in use */
7347 + dget(hidden_sto_dentry);
7348 + err = vfs_unlink(hidden_sto_dir_inode, hidden_sto_dentry);
7349 + dput(hidden_sto_dentry);
7350 + if(!err)
7351 + d_delete(hidden_sto_dentry);
7352 +
7353 + /* propagate number of hard-links */
7354 + dentry->d_inode->i_nlink = itohi2(dentry->d_inode)->i_nlink;
7355 +
7356 + dtost(dentry) = NON_EXISTANT;
7357 +
7358 + /* was: unlock_dir(hidden_sto_dir_dentry); */
7359 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
7360 + mutex_unlock(&hidden_sto_dir_dentry->d_inode->i_mutex);
7361 +#else
7362 + up(&hidden_sto_dir_dentry->d_inode->i_sem);
7363 +#endif
7364 + dput(hidden_sto_dir_dentry);
7365 +
7366 + out:
7367 + return err;
7368 +}
7369 +
7370 +int nondir_mod_to_del(dentry_t *dentry)
7371 +{
7372 + int err;
7373 + dentry_t *hidden_sto_dentry;
7374 + inode_t *hidden_sto_dir_inode;
7375 + dentry_t *hidden_sto_dir_dentry;
7376 +
7377 + check_mini_fo_dentry(dentry);
7378 +
7379 + if(dtost(dentry) != MODIFIED ||
7380 + S_ISDIR(dentry->d_inode->i_mode)) {
7381 + printk(KERN_CRIT "mini_fo: nondir_mod_to_del: \
7382 + wrong type or state.\n");
7383 + err = -1;
7384 + goto out;
7385 + }
7386 +
7387 + hidden_sto_dir_inode = itohi2(dentry->d_parent->d_inode);
7388 + hidden_sto_dentry = dtohd2(dentry);
7389 +
7390 + /* was hidden_sto_dir_dentry = lock_parent(hidden_sto_dentry); */
7391 + hidden_sto_dir_dentry = dget(hidden_sto_dentry->d_parent);
7392 +
7393 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
7394 + mutex_lock(&hidden_sto_dir_dentry->d_inode->i_mutex);
7395 +#else
7396 + down(&hidden_sto_dir_dentry->d_inode->i_sem);
7397 +#endif
7398 +
7399 + /* avoid destroying the hidden inode if the file is in use */
7400 + dget(hidden_sto_dentry);
7401 + err = vfs_unlink(hidden_sto_dir_inode, hidden_sto_dentry);
7402 + dput(hidden_sto_dentry);
7403 + if(!err)
7404 + d_delete(hidden_sto_dentry);
7405 +
7406 + /* propagate number of hard-links */
7407 + dentry->d_inode->i_nlink = itohi2(dentry->d_inode)->i_nlink;
7408 +
7409 + /* dput base dentry, this will relase the inode and free the
7410 + * dentry, as we will never need it again. */
7411 + dput(dtohd(dentry));
7412 + dtohd(dentry) = NULL;
7413 + dtost(dentry) = DELETED;
7414 +
7415 + /* add deleted file to META-file */
7416 + meta_add_d_entry(dentry->d_parent,
7417 + dentry->d_name.name,
7418 + dentry->d_name.len);
7419 +
7420 + /* was: unlock_dir(hidden_sto_dir_dentry); */
7421 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
7422 + mutex_unlock(&hidden_sto_dir_dentry->d_inode->i_mutex);
7423 +#else
7424 + up(&hidden_sto_dir_dentry->d_inode->i_sem);
7425 +#endif
7426 + dput(hidden_sto_dir_dentry);
7427 +
7428 + out:
7429 + return err;
7430 +}
7431 +
7432 +int nondir_unmod_to_del(dentry_t *dentry)
7433 +{
7434 + int err = 0;
7435 +
7436 + check_mini_fo_dentry(dentry);
7437 +
7438 + if(dtost(dentry) != UNMODIFIED ||
7439 + S_ISDIR(dentry->d_inode->i_mode)) {
7440 + printk(KERN_CRIT "mini_fo: nondir_unmod_to_del: \
7441 + wrong type or state.\n");
7442 + err = -1;
7443 + goto out;
7444 + }
7445 +
7446 + /* next we have to get a negative dentry for the storage file */
7447 + err = get_neg_sto_dentry(dentry);
7448 +
7449 + if(err)
7450 + goto out;
7451 +
7452 + /* add deleted file to META lists */
7453 + err = meta_add_d_entry(dentry->d_parent,
7454 + dentry->d_name.name,
7455 + dentry->d_name.len);
7456 +
7457 + if(err)
7458 + goto out;
7459 +
7460 + /* dput base dentry, this will relase the inode and free the
7461 + * dentry, as we will never need it again. */
7462 + dput(dtohd(dentry));
7463 + dtohd(dentry) = NULL;
7464 + dtost(dentry) = DELETED;
7465 +
7466 + out:
7467 + return err;
7468 +}
7469 +
7470 +/* bring a dir from state UNMODIFIED to MODIFIED */
7471 +int dir_unmod_to_mod(dentry_t *dentry)
7472 +{
7473 + int err;
7474 +
7475 + check_mini_fo_dentry(dentry);
7476 +
7477 + if(dtost(dentry) != UNMODIFIED ||
7478 + !S_ISDIR(dentry->d_inode->i_mode)) {
7479 + printk(KERN_CRIT "mini_fo: dir_unmod_to_mod: \
7480 + wrong type or state.\n");
7481 + err = -1;
7482 + goto out;
7483 + }
7484 +
7485 + /* this creates our dir incl. sto. structure */
7486 + err = build_sto_structure(dentry->d_parent, dentry);
7487 + if(err) {
7488 + printk(KERN_CRIT "mini_fo: dir_unmod_to_mod: \
7489 + build_sto_structure failed.\n");
7490 + goto out;
7491 + }
7492 + out:
7493 + return err;
7494 +}
7495 +
7496 --- /dev/null
7497 +++ b/fs/mini_fo/super.c
7498 @@ -0,0 +1,281 @@
7499 +/*
7500 + * Copyright (c) 1997-2003 Erez Zadok
7501 + * Copyright (c) 2001-2003 Stony Brook University
7502 + *
7503 + * For specific licensing information, see the COPYING file distributed with
7504 + * this package, or get one from ftp://ftp.filesystems.org/pub/fist/COPYING.
7505 + *
7506 + * This Copyright notice must be kept intact and distributed with all
7507 + * fistgen sources INCLUDING sources generated by fistgen.
7508 + */
7509 +/*
7510 + * Copyright (C) 2004, 2005 Markus Klotzbuecher <mk@creamnet.de>
7511 + *
7512 + * This program is free software; you can redistribute it and/or
7513 + * modify it under the terms of the GNU General Public License
7514 + * as published by the Free Software Foundation; either version
7515 + * 2 of the License, or (at your option) any later version.
7516 + */
7517 +
7518 +/*
7519 + * $Id$
7520 + */
7521 +
7522 +#ifdef HAVE_CONFIG_H
7523 +# include <config.h>
7524 +#endif
7525 +
7526 +#include "fist.h"
7527 +#include "mini_fo.h"
7528 +
7529 +
7530 +STATIC void
7531 +mini_fo_read_inode(inode_t *inode)
7532 +{
7533 + static struct address_space_operations mini_fo_empty_aops;
7534 +
7535 + __itopd(inode) = kmalloc(sizeof(struct mini_fo_inode_info), GFP_KERNEL);
7536 + if (!itopd(inode)) {
7537 + printk("<0>%s:%s:%d: No kernel memory!\n", __FILE__, __FUNCTION__, __LINE__);
7538 + ASSERT(NULL);
7539 + }
7540 + itohi(inode) = NULL;
7541 + itohi2(inode) = NULL;
7542 +
7543 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
7544 + inode->i_version++;
7545 +#else
7546 + inode->i_version = ++event; /* increment inode version */
7547 +#endif
7548 + inode->i_op = &mini_fo_main_iops;
7549 + inode->i_fop = &mini_fo_main_fops;
7550 +#if 0
7551 + /*
7552 + * XXX: To export a file system via NFS, it has to have the
7553 + * FS_REQUIRES_DEV flag, so turn it on. But should we inherit it from
7554 + * the lower file system, or can we allow our file system to be exported
7555 + * even if the lower one cannot be natively exported.
7556 + */
7557 + inode->i_sb->s_type->fs_flags |= FS_REQUIRES_DEV;
7558 + /*
7559 + * OK, the above was a hack, which is now turned off because it may
7560 + * cause a panic/oops on some systems. The correct way to export a
7561 + * "nodev" filesystem is via using nfs-utils > 1.0 and the "fsid=" export
7562 + * parameter, which requires 2.4.20 or later.
7563 + */
7564 +#endif
7565 + /* I don't think ->a_ops is ever allowed to be NULL */
7566 + inode->i_mapping->a_ops = &mini_fo_empty_aops;
7567 +}
7568 +
7569 +
7570 +#if defined(FIST_DEBUG) || defined(FIST_FILTER_SCA)
7571 +/*
7572 + * No need to call write_inode() on the lower inode, as it
7573 + * will have been marked 'dirty' anyway. But we might need
7574 + * to write some of our own stuff to disk.
7575 + */
7576 +STATIC void
7577 +mini_fo_write_inode(inode_t *inode, int sync)
7578 +{
7579 + print_entry_location();
7580 + print_exit_location();
7581 +}
7582 +#endif /* defined(FIST_DEBUG) || defined(FIST_FILTER_SCA) */
7583 +
7584 +
7585 +STATIC void
7586 +mini_fo_put_inode(inode_t *inode)
7587 +{
7588 + /*
7589 + * This is really funky stuff:
7590 + * Basically, if i_count == 1, iput will then decrement it and this inode will be destroyed.
7591 + * It is currently holding a reference to the hidden inode.
7592 + * Therefore, it needs to release that reference by calling iput on the hidden inode.
7593 + * iput() _will_ do it for us (by calling our clear_inode), but _only_ if i_nlink == 0.
7594 + * The problem is, NFS keeps i_nlink == 1 for silly_rename'd files.
7595 + * So we must for our i_nlink to 0 here to trick iput() into calling our clear_inode.
7596 + */
7597 + if (atomic_read(&inode->i_count) == 1)
7598 + inode->i_nlink = 0;
7599 +}
7600 +
7601 +
7602 +#if defined(FIST_DEBUG) || defined(FIST_FILTER_SCA)
7603 +/*
7604 + * we now define delete_inode, because there are two VFS paths that may
7605 + * destroy an inode: one of them calls clear inode before doing everything
7606 + * else that's needed, and the other is fine. This way we truncate the inode
7607 + * size (and its pages) and then clear our own inode, which will do an iput
7608 + * on our and the lower inode.
7609 + */
7610 +STATIC void
7611 +mini_fo_delete_inode(inode_t *inode)
7612 +{
7613 + print_entry_location();
7614 +
7615 + fist_checkinode(inode, "mini_fo_delete_inode IN");
7616 + inode->i_size = 0; /* every f/s seems to do that */
7617 + clear_inode(inode);
7618 +
7619 + print_exit_location();
7620 +}
7621 +#endif /* defined(FIST_DEBUG) || defined(FIST_FILTER_SCA) */
7622 +
7623 +
7624 +/* final actions when unmounting a file system */
7625 +STATIC void
7626 +mini_fo_put_super(super_block_t *sb)
7627 +{
7628 + if (stopd(sb)) {
7629 + mntput(stopd(sb)->hidden_mnt);
7630 + mntput(stopd(sb)->hidden_mnt2);
7631 +
7632 + /* mk: no! dput(stopd(sb)->base_dir_dentry);
7633 + dput(stopd(sb)->storage_dir_dentry); */
7634 +
7635 + kfree(stopd(sb));
7636 + __stopd(sb) = NULL;
7637 + }
7638 +}
7639 +
7640 +
7641 +#ifdef NOT_NEEDED
7642 +/*
7643 + * This is called in do_umount before put_super.
7644 + * The superblock lock is not held yet.
7645 + * We probably do not need to define this or call write_super
7646 + * on the hidden_sb, because sync_supers() will get to hidden_sb
7647 + * sooner or later. But it is also called from file_fsync()...
7648 + */
7649 +STATIC void
7650 +mini_fo_write_super(super_block_t *sb)
7651 +{
7652 + return;
7653 +}
7654 +#endif /* NOT_NEEDED */
7655 +
7656 +
7657 +STATIC int
7658 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,18)
7659 +mini_fo_statfs(struct dentry *d, struct kstatfs *buf)
7660 +#elif LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
7661 +mini_fo_statfs(super_block_t *sb, struct kstatfs *buf)
7662 +#else
7663 +mini_fo_statfs(super_block_t *sb, struct statfs *buf)
7664 +#endif
7665 +{
7666 + int err = 0;
7667 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,18)
7668 + struct dentry *hidden_d;
7669 +
7670 + hidden_d = dtohd(d);
7671 + err = vfs_statfs(hidden_d, buf);
7672 +#else
7673 + super_block_t *hidden_sb;
7674 +
7675 + hidden_sb = stohs(sb);
7676 + err = vfs_statfs(hidden_sb, buf);
7677 +#endif
7678 +
7679 + return err;
7680 +}
7681 +
7682 +
7683 +/*
7684 + * XXX: not implemented. This is not allowed yet.
7685 + * Should we call this on the hidden_sb? Probably not.
7686 + */
7687 +STATIC int
7688 +mini_fo_remount_fs(super_block_t *sb, int *flags, char *data)
7689 +{
7690 + //printk(KERN_CRIT "mini_fo_remount_fs: WARNING, this function is umimplemented.\n");
7691 + return -ENOSYS;
7692 +}
7693 +
7694 +
7695 +/*
7696 + * Called by iput() when the inode reference count reached zero
7697 + * and the inode is not hashed anywhere. Used to clear anything
7698 + * that needs to be, before the inode is completely destroyed and put
7699 + * on the inode free list.
7700 + */
7701 +STATIC void
7702 +mini_fo_clear_inode(inode_t *inode)
7703 +{
7704 + /*
7705 + * Decrement a reference to a hidden_inode, which was incremented
7706 + * by our read_inode when it was created initially.
7707 + */
7708 +
7709 + /* release the wol_list */
7710 + if(S_ISDIR(inode->i_mode)) {
7711 + __meta_put_lists(inode);
7712 + }
7713 +
7714 + /* mk: fan out fun */
7715 + if(itohi(inode))
7716 + iput(itohi(inode));
7717 + if(itohi2(inode))
7718 + iput(itohi2(inode));
7719 +
7720 + // XXX: why this assertion fails?
7721 + // because it doesn't like us
7722 + // ASSERT((inode->i_state & I_DIRTY) == 0);
7723 + kfree(itopd(inode));
7724 + __itopd(inode) = NULL;
7725 +}
7726 +
7727 +
7728 +/*
7729 + * Called in do_umount() if the MNT_FORCE flag was used and this
7730 + * function is defined. See comment in linux/fs/super.c:do_umount().
7731 + * Used only in nfs, to kill any pending RPC tasks, so that subsequent
7732 + * code can actually succeed and won't leave tasks that need handling.
7733 + *
7734 + * PS. I wonder if this is somehow useful to undo damage that was
7735 + * left in the kernel after a user level file server (such as amd)
7736 + * dies.
7737 + */
7738 +STATIC void
7739 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,18)
7740 +mini_fo_umount_begin(struct vfsmount *mnt, int flags)
7741 +{
7742 + struct vfsmount *hidden_mnt;
7743 +
7744 + hidden_mnt = stopd(mnt->mnt_sb)->hidden_mnt;
7745 +
7746 + if (hidden_mnt->mnt_sb->s_op->umount_begin)
7747 + hidden_mnt->mnt_sb->s_op->umount_begin(hidden_mnt, flags);
7748 +
7749 +}
7750 +#else
7751 +mini_fo_umount_begin(super_block_t *sb)
7752 +{
7753 + super_block_t *hidden_sb;
7754 +
7755 + hidden_sb = stohs(sb);
7756 +
7757 + if (hidden_sb->s_op->umount_begin)
7758 + hidden_sb->s_op->umount_begin(hidden_sb);
7759 +
7760 +}
7761 +#endif
7762 +
7763 +
7764 +struct super_operations mini_fo_sops =
7765 +{
7766 + read_inode: mini_fo_read_inode,
7767 +#if defined(FIST_DEBUG) || defined(FIST_FILTER_SCA)
7768 + write_inode: mini_fo_write_inode,
7769 +#endif /* defined(FIST_DEBUG) || defined(FIST_FILTER_SCA) */
7770 + put_inode: mini_fo_put_inode,
7771 +#if defined(FIST_DEBUG) || defined(FIST_FILTER_SCA)
7772 + delete_inode: mini_fo_delete_inode,
7773 +#endif /* defined(FIST_DEBUG) || defined(FIST_FILTER_SCA) */
7774 + put_super: mini_fo_put_super,
7775 + statfs: mini_fo_statfs,
7776 + remount_fs: mini_fo_remount_fs,
7777 + clear_inode: mini_fo_clear_inode,
7778 + umount_begin: mini_fo_umount_begin,
7779 +};
This page took 0.361214 seconds and 5 git commands to generate.