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