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