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