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