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