]> git.ipfire.org Git - people/pmueller/ipfire-2.x.git/blobdiff - src/patches/reiser4-for-2.6.22-2.patch
Kernel 2.6.22.1 - leider ohne OpenSwan.
[people/pmueller/ipfire-2.x.git] / src / patches / reiser4-for-2.6.22-2.patch
similarity index 87%
rename from src/patches/reiser4-for-2.6.16-5.patch
rename to src/patches/reiser4-for-2.6.22-2.patch
index 0a62c8631c9182b7ca2035bf12ea9131025855a9..8f79f8d2bdc8d68f3a78602f3860ed0693e6b9bc 100644 (file)
@@ -1,16 +1,37 @@
-Index: linux-2.6.16/Documentation/Changes
-===================================================================
---- linux-2.6.16.orig/Documentation/Changes
-+++ linux-2.6.16/Documentation/Changes
-@@ -54,6 +54,7 @@ o  module-init-tools      0.9.10        
+The same as reiser4-for-2.6.22.patch plus a fix for file conversion
+related bug wich caused metadata corruption when REISER4_DEBUG is on.
+
+diff -urN linux-2.6.22.orig/arch/i386/lib/usercopy.c linux-2.6.22/arch/i386/lib/usercopy.c
+--- linux-2.6.22.orig/arch/i386/lib/usercopy.c 2007-07-21 00:32:46.973831675 +0400
++++ linux-2.6.22/arch/i386/lib/usercopy.c      2007-07-29 00:25:34.800676805 +0400
+@@ -817,6 +817,7 @@
+ #endif
+       return n;
+ }
++EXPORT_SYMBOL(__copy_from_user_ll_nocache);
+ unsigned long __copy_from_user_ll_nocache_nozero(void *to, const void __user *from,
+                                       unsigned long n)
+@@ -831,6 +832,7 @@
+ #endif
+       return n;
+ }
++EXPORT_SYMBOL(__copy_from_user_ll_nocache_nozero);
+ /**
+  * copy_to_user: - Copy a block of data into user space.
+diff -urN linux-2.6.22.orig/Documentation/Changes linux-2.6.22/Documentation/Changes
+--- linux-2.6.22.orig/Documentation/Changes    2007-07-21 00:31:57.012856483 +0400
++++ linux-2.6.22/Documentation/Changes 2007-07-29 00:25:34.800676805 +0400
+@@ -36,6 +36,7 @@
  o  e2fsprogs              1.29                    # tune2fs
  o  jfsutils               1.1.3                   # fsck.jfs -V
  o  reiserfsprogs          3.6.3                   # reiserfsck -V 2>&1|grep reiserfsprogs
 +o  reiser4progs           1.0.0                   # fsck.reiser4 -V
  o  xfsprogs               2.6.0                   # xfs_db -V
- o  pcmciautils            004
- o  pcmcia-cs              3.1.21                  # cardmgr -V
-@@ -163,6 +164,13 @@ The reiserfsprogs package should be used
+ o  pcmciautils            004                     # pccardctl -V
+ o  quota-tools            3.09                    # quota -V
+@@ -144,6 +145,13 @@
  versions of mkreiserfs, resize_reiserfs, debugreiserfs and
  reiserfsck. These utils work on both i386 and alpha platforms.
  
@@ -24,7 +45,7 @@ Index: linux-2.6.16/Documentation/Changes
  Xfsprogs
  --------
  
-@@ -344,6 +352,10 @@ Reiserfsprogs
+@@ -322,6 +330,10 @@
  -------------
  o  <http://www.namesys.com/pub/reiserfsprogs/reiserfsprogs-3.6.3.tar.gz>
  
@@ -35,10 +56,9 @@ Index: linux-2.6.16/Documentation/Changes
  Xfsprogs
  --------
  o  <ftp://oss.sgi.com/projects/xfs/download/>
-Index: linux-2.6.16/Documentation/filesystems/reiser4.txt
-===================================================================
---- /dev/null
-+++ linux-2.6.16/Documentation/filesystems/reiser4.txt
+diff -urN linux-2.6.22.orig/Documentation/filesystems/reiser4.txt linux-2.6.22/Documentation/filesystems/reiser4.txt
+--- linux-2.6.22.orig/Documentation/filesystems/reiser4.txt    1970-01-01 03:00:00.000000000 +0300
++++ linux-2.6.22/Documentation/filesystems/reiser4.txt 2007-07-29 00:25:34.800676805 +0400
 @@ -0,0 +1,75 @@
 +Reiser4 filesystem
 +==================
@@ -115,36 +135,10 @@ Index: linux-2.6.16/Documentation/filesystems/reiser4.txt
 +dont_load_bitmap
 +      Don't load all bitmap blocks at mount time, it is useful for
 +      machines with tiny RAM and large disks.
-Index: linux-2.6.16/fs/Kconfig
-===================================================================
---- linux-2.6.16.orig/fs/Kconfig
-+++ linux-2.6.16/fs/Kconfig
-@@ -177,6 +177,8 @@ config FS_MBCACHE
-       default y if EXT2_FS=y || EXT3_FS=y
-       default m if EXT2_FS=m || EXT3_FS=m
-+source "fs/reiser4/Kconfig"
-+
- config REISERFS_FS
-       tristate "Reiserfs support"
-       help
-Index: linux-2.6.16/fs/Makefile
-===================================================================
---- linux-2.6.16.orig/fs/Makefile
-+++ linux-2.6.16/fs/Makefile
-@@ -51,6 +51,7 @@ obj-$(CONFIG_PROFILING)              += dcookies.o
-  
- # Do not add any filesystems before this line
- obj-$(CONFIG_REISERFS_FS)     += reiserfs/
-+obj-$(CONFIG_REISER4_FS)      += reiser4/
- obj-$(CONFIG_EXT3_FS)         += ext3/ # Before ext2 so root fs can be ext3
- obj-$(CONFIG_JBD)             += jbd/
- obj-$(CONFIG_EXT2_FS)         += ext2/
-Index: linux-2.6.16/fs/fs-writeback.c
-===================================================================
---- linux-2.6.16.orig/fs/fs-writeback.c
-+++ linux-2.6.16/fs/fs-writeback.c
-@@ -286,8 +286,6 @@ __writeback_single_inode(struct inode *i
+diff -urN linux-2.6.22.orig/fs/fs-writeback.c linux-2.6.22/fs/fs-writeback.c
+--- linux-2.6.22.orig/fs/fs-writeback.c        2007-07-21 00:32:04.502801671 +0400
++++ linux-2.6.22/fs/fs-writeback.c     2007-07-29 00:25:34.808678876 +0400
+@@ -296,8 +296,6 @@
   * WB_SYNC_HOLD is a hack for sys_sync(): reattach the inode to sb->s_dirty so
   * that it can be located for waiting on in __writeback_single_inode().
   *
@@ -153,7 +147,7 @@ Index: linux-2.6.16/fs/fs-writeback.c
   * If `bdi' is non-zero then we're being asked to writeback a specific queue.
   * This function assumes that the blockdev superblock's inodes are backed by
   * a variety of queues, so all inodes are searched.  For other superblocks,
-@@ -303,11 +301,13 @@ __writeback_single_inode(struct inode *i
+@@ -313,11 +311,13 @@
   * on the writer throttling path, and we get decent balancing between many
   * throttled threads: we don't want them all piling up on __wait_on_inode.
   */
@@ -169,7 +163,7 @@ Index: linux-2.6.16/fs/fs-writeback.c
        if (!wbc->for_kupdate || list_empty(&sb->s_io))
                list_splice_init(&sb->s_dirty, &sb->s_io);
  
-@@ -387,8 +387,19 @@ sync_sb_inodes(struct super_block *sb, s
+@@ -397,8 +397,19 @@
                if (wbc->nr_to_write <= 0)
                        break;
        }
@@ -189,7 +183,7 @@ Index: linux-2.6.16/fs/fs-writeback.c
  
  /*
   * Start writeback of dirty pagecache data against all unlocked inodes.
-@@ -429,11 +440,8 @@ restart:
+@@ -439,11 +450,8 @@
                         * be unmounted by the time it is released.
                         */
                        if (down_read_trylock(&sb->s_umount)) {
@@ -202,7 +196,7 @@ Index: linux-2.6.16/fs/fs-writeback.c
                                up_read(&sb->s_umount);
                        }
                        spin_lock(&sb_lock);
-@@ -469,9 +477,7 @@ void sync_inodes_sb(struct super_block *
+@@ -481,9 +489,7 @@
                        (inodes_stat.nr_inodes - inodes_stat.nr_unused) +
                        nr_dirty + nr_unstable;
        wbc.nr_to_write += wbc.nr_to_write / 2;         /* Bit more for luck */
@@ -212,282 +206,33 @@ Index: linux-2.6.16/fs/fs-writeback.c
  }
  
  /*
-Index: linux-2.6.16/fs/reiser4/Kconfig
-===================================================================
---- /dev/null
-+++ linux-2.6.16/fs/reiser4/Kconfig
-@@ -0,0 +1,31 @@
-+config REISER4_FS
-+      tristate "Reiser4 (EXPERIMENTAL)"
-+      depends on EXPERIMENTAL
-+      select ZLIB_INFLATE
-+      select ZLIB_DEFLATE
-+      help
-+        Reiser4 is a filesystem that performs all filesystem operations
-+        as atomic transactions, which means that it either performs a
-+        write, or it does not, and in the event of a crash it does not
-+        partially perform it or corrupt it.
-+
-+        It stores files in dancing trees, which are like balanced trees but
-+        faster.  It packs small files together so that they share blocks
-+        without wasting space.  This means you can use it to store really
-+        small files.  It also means that it saves you disk space.  It avoids
-+        hassling you with anachronisms like having a maximum number of
-+        inodes, and wasting space if you use less than that number.
-+
-+        Reiser4 is a distinct filesystem type from reiserfs (V3).
-+        It's therefore not possible to use reiserfs file systems
-+        with reiser4.
-+
-+        To learn more about reiser4, go to http://www.namesys.com
-+
-+config REISER4_DEBUG
-+      bool "Enable reiser4 debug mode"
-+      depends on REISER4_FS
-+      help
-+        Don't use this unless you are debugging reiser4.
-+
-+        If unsure, say N.
-Index: linux-2.6.16/fs/reiser4/Makefile
-===================================================================
---- /dev/null
-+++ linux-2.6.16/fs/reiser4/Makefile
-@@ -0,0 +1,100 @@
-+#
-+# reiser4/Makefile
-+#
-+
-+obj-$(CONFIG_REISER4_FS) += reiser4.o
-+
-+reiser4-y := \
-+                 debug.o \
-+                 jnode.o \
-+                 znode.o \
-+                 key.o \
-+                 pool.o \
-+                 tree_mod.o \
-+                 estimate.o \
-+                 carry.o \
-+                 carry_ops.o \
-+                 lock.o \
-+                 tree.o \
-+                 context.o \
-+                 tap.o \
-+                 coord.o \
-+                 block_alloc.o \
-+                 txnmgr.o \
-+                 kassign.o \
-+                 flush.o \
-+                 wander.o \
-+                 eottl.o \
-+                 search.o \
-+                 page_cache.o \
-+                 seal.o \
-+                 dscale.o \
-+                 flush_queue.o \
-+                 ktxnmgrd.o \
-+                 blocknrset.o \
-+                 super.o \
-+                 super_ops.o \
-+                 fsdata.o \
-+                 export_ops.o \
-+                 oid.o \
-+                 tree_walk.o \
-+                 inode.o \
-+                 vfs_ops.o \
-+                 as_ops.o \
-+                 entd.o\
-+                 readahead.o \
-+                 status_flags.o \
-+                 init_super.o \
-+                 safe_link.o \
-+           \
-+                 plugin/plugin.o \
-+                 plugin/plugin_set.o \
-+                 plugin/node/node.o \
-+                 plugin/object.o \
-+                 plugin/cluster.o \
-+                 plugin/inode_ops.o \
-+                 plugin/inode_ops_rename.o \
-+                 plugin/file_ops.o \
-+                 plugin/file_ops_readdir.o \
-+                 plugin/file_plugin_common.o \
-+                 plugin/file/file.o \
-+                 plugin/file/tail_conversion.o \
-+                 plugin/file/symlink.o \
-+                 plugin/file/cryptcompress.o \
-+                 plugin/dir_plugin_common.o \
-+                 plugin/dir/hashed_dir.o \
-+                 plugin/dir/seekable_dir.o \
-+                 plugin/node/node40.o \
-+           \
-+                 plugin/crypto/cipher.o \
-+                 plugin/crypto/digest.o \
-+           \
-+                 plugin/compress/minilzo.o \
-+                 plugin/compress/compress.o \
-+                 plugin/compress/compress_mode.o \
-+           \
-+                 plugin/item/static_stat.o \
-+                 plugin/item/sde.o \
-+                 plugin/item/cde.o \
-+                 plugin/item/blackbox.o \
-+                 plugin/item/internal.o \
-+                 plugin/item/tail.o \
-+                 plugin/item/ctail.o \
-+                 plugin/item/extent.o \
-+                 plugin/item/extent_item_ops.o \
-+                 plugin/item/extent_file_ops.o \
-+                 plugin/item/extent_flush_ops.o \
-+           \
-+                 plugin/hash.o \
-+                 plugin/fibration.o \
-+                 plugin/tail_policy.o \
-+                 plugin/item/item.o \
-+           \
-+                 plugin/security/perm.o \
-+                 plugin/space/bitmap.o \
-+           \
-+                 plugin/disk_format/disk_format40.o \
-+                 plugin/disk_format/disk_format.o \
-+         \
-+                 plugin/regular.o
-+
-Index: linux-2.6.16/fs/reiser4/README
-===================================================================
---- /dev/null
-+++ linux-2.6.16/fs/reiser4/README
-@@ -0,0 +1,125 @@
-+[LICENSING]
-+
-+Reiser4 is hereby licensed under the GNU General
-+Public License version 2.
-+
-+Source code files that contain the phrase "licensing governed by
-+reiser4/README" are "governed files" throughout this file.  Governed
-+files are licensed under the GPL.  The portions of them owned by Hans
-+Reiser, or authorized to be licensed by him, have been in the past,
-+and likely will be in the future, licensed to other parties under
-+other licenses.  If you add your code to governed files, and don't
-+want it to be owned by Hans Reiser, put your copyright label on that
-+code so the poor blight and his customers can keep things straight.
-+All portions of governed files not labeled otherwise are owned by Hans
-+Reiser, and by adding your code to it, widely distributing it to
-+others or sending us a patch, and leaving the sentence in stating that
-+licensing is governed by the statement in this file, you accept this.
-+It will be a kindness if you identify whether Hans Reiser is allowed
-+to license code labeled as owned by you on your behalf other than
-+under the GPL, because he wants to know if it is okay to do so and put
-+a check in the mail to you (for non-trivial improvements) when he
-+makes his next sale.  He makes no guarantees as to the amount if any,
-+though he feels motivated to motivate contributors, and you can surely
-+discuss this with him before or after contributing.  You have the
-+right to decline to allow him to license your code contribution other
-+than under the GPL.
-+
-+Further licensing options are available for commercial and/or other
-+interests directly from Hans Reiser: reiser@namesys.com.  If you interpret
-+the GPL as not allowing those additional licensing options, you read
-+it wrongly, and Richard Stallman agrees with me, when carefully read
-+you can see that those restrictions on additional terms do not apply
-+to the owner of the copyright, and my interpretation of this shall
-+govern for this license.
-+
-+[END LICENSING]
-+
-+Reiser4 is a file system based on dancing tree algorithms, and is
-+described at http://www.namesys.com
-+
-+mkfs.reiser4 and other utilities are on our webpage or wherever your
-+Linux provider put them.  You really want to be running the latest
-+version off the website if you use fsck.
-+
-+Yes, if you update your reiser4 kernel module you do have to
-+recompile your kernel, most of the time.  The errors you get will be
-+quite cryptic if your forget to do so.
-+
-+Hideous Commercial Pitch: Spread your development costs across other OS
-+vendors.  Select from the best in the world, not the best in your
-+building, by buying from third party OS component suppliers.  Leverage
-+the software component development power of the internet.  Be the most
-+aggressive in taking advantage of the commercial possibilities of
-+decentralized internet development, and add value through your branded
-+integration that you sell as an operating system.  Let your competitors
-+be the ones to compete against the entire internet by themselves.  Be
-+hip, get with the new economic trend, before your competitors do.  Send
-+email to reiser@namesys.com
-+
-+Hans Reiser was the primary architect of Reiser4, but a whole team
-+chipped their ideas in.  He invested everything he had into Namesys
-+for 5.5 dark years of no money before Reiser3 finally started to work well
-+enough to bring in money.  He owns the copyright.
-+
-+DARPA was the primary sponsor of Reiser4.  DARPA does not endorse
-+Reiser4, it merely sponsors it.  DARPA is, in solely Hans's personal
-+opinion, unique in its willingness to invest into things more
-+theoretical than the VC community can readily understand, and more
-+longterm than allows them to be sure that they will be the ones to
-+extract the economic benefits from.  DARPA also integrated us into a
-+security community that transformed our security worldview.
-+
-+Vladimir Saveliev is our lead programmer, with us from the beginning,
-+and he worked long hours writing the cleanest code.  This is why he is
-+now the lead programmer after years of commitment to our work.  He
-+always made the effort to be the best he could be, and to make his
-+code the best that it could be.  What resulted was quite remarkable. I
-+don't think that money can ever motivate someone to work the way he
-+did, he is one of the most selfless men I know.
-+
-+Alexander Lyamin was our sysadmin, and helped to educate us in
-+security issues.  Moscow State University and IMT were very generous
-+in the internet access they provided us, and in lots of other little
-+ways that a generous institution can be.
-+
-+Alexander Zarochentcev (sometimes known as zam, or sasha), wrote the
-+locking code, the block allocator, and finished the flushing code.
-+His code is always crystal clean and well structured.
-+
-+Nikita Danilov wrote the core of the balancing code, the core of the
-+plugins code, and the directory code.  He worked a steady pace of long
-+hours that produced a whole lot of well abstracted code.  He is our
-+senior computer scientist.
-+
-+Vladimir Demidov wrote the parser.  Writing an in kernel parser is
-+something very few persons have the skills for, and it is thanks to
-+him that we can say that the parser is really not so big compared to
-+various bits of our other code, and making a parser work in the kernel
-+was not so complicated as everyone would imagine mainly because it was
-+him doing it...
-+
-+Joshua McDonald wrote the transaction manager, and the flush code.
-+The flush code unexpectedly turned out be extremely hairy for reasons
-+you can read about on our web page, and he did a great job on an
-+extremely difficult task.
-+
-+Nina Reiser handled our accounting, government relations, and much
-+more.
-+
-+Ramon Reiser developed our website.
-+
-+Beverly Palmer drew our graphics.
-+
-+Vitaly Fertman developed librepair, userspace plugins repair code, fsck
-+and worked with Umka on developing libreiser4 and userspace plugins.
-+
-+Yury Umanets (aka Umka) developed libreiser4, userspace plugins and
-+userspace tools (reiser4progs).
-+
-+Oleg Drokin (aka Green) is the release manager who fixes everything.
-+It is so nice to have someone like that on the team.  He (plus Chris
-+and Jeff) make it possible for the entire rest of the Namesys team to
-+focus on Reiser4, and he fixed a whole lot of Reiser4 bugs also.  It
-+is just amazing to watch his talent for spotting bugs in action.
+diff -urN linux-2.6.22.orig/fs/Kconfig linux-2.6.22/fs/Kconfig
+--- linux-2.6.22.orig/fs/Kconfig       2007-07-21 00:32:57.540575927 +0400
++++ linux-2.6.22/fs/Kconfig    2007-07-29 00:25:34.812679911 +0400
+@@ -272,6 +272,8 @@
+       default y if EXT2_FS=y || EXT3_FS=y || EXT4DEV_FS=y
+       default m if EXT2_FS=m || EXT3_FS=m || EXT4DEV_FS=m
++source "fs/reiser4/Kconfig"
 +
-Index: linux-2.6.16/fs/reiser4/as_ops.c
-===================================================================
---- /dev/null
-+++ linux-2.6.16/fs/reiser4/as_ops.c
-@@ -0,0 +1,392 @@
+ config REISERFS_FS
+       tristate "Reiserfs support"
+       help
+diff -urN linux-2.6.22.orig/fs/Makefile linux-2.6.22/fs/Makefile
+--- linux-2.6.22.orig/fs/Makefile      2007-07-21 00:32:57.544576967 +0400
++++ linux-2.6.22/fs/Makefile   2007-07-29 00:25:34.812679911 +0400
+@@ -66,6 +66,7 @@
+  
+ # Do not add any filesystems before this line
+ obj-$(CONFIG_REISERFS_FS)     += reiserfs/
++obj-$(CONFIG_REISER4_FS)      += reiser4/
+ obj-$(CONFIG_EXT3_FS)         += ext3/ # Before ext2 so root fs can be ext3
+ obj-$(CONFIG_EXT4DEV_FS)      += ext4/ # Before ext2 so root fs can be ext4dev
+ obj-$(CONFIG_JBD)             += jbd/
+diff -urN linux-2.6.22.orig/fs/reiser4/as_ops.c linux-2.6.22/fs/reiser4/as_ops.c
+--- linux-2.6.22.orig/fs/reiser4/as_ops.c      1970-01-01 03:00:00.000000000 +0300
++++ linux-2.6.22/fs/reiser4/as_ops.c   2007-07-29 00:25:34.816680947 +0400
+@@ -0,0 +1,337 @@
 +/* Copyright 2003 by Hans Reiser, licensing governed by reiser4/README */
 +
 +/* Interface to VFS. Reiser4 address_space_operations are defined here. */
@@ -541,7 +286,7 @@ Index: linux-2.6.16/fs/reiser4/as_ops.c
 + * @page: page to be dirtied
 + *
 + * Operation of struct address_space_operations. This implementation is used by
-+ * unix and crc file plugins.
++ * unix and cryptcompress file plugins.
 + *
 + * This is called when reiser4 page gets dirtied outside of reiser4, for
 + * example, when dirty bit is moved from pte to physical page.
@@ -556,11 +301,11 @@ Index: linux-2.6.16/fs/reiser4/as_ops.c
 +      /* this page can be unformatted only */
 +      assert("vs-1734", (page->mapping &&
 +                         page->mapping->host &&
-+                         get_super_fake(page->mapping->host->i_sb) !=
++                         reiser4_get_super_fake(page->mapping->host->i_sb) !=
 +                         page->mapping->host
-+                         && get_cc_fake(page->mapping->host->i_sb) !=
++                         && reiser4_get_cc_fake(page->mapping->host->i_sb) !=
 +                         page->mapping->host
-+                         && get_bitmap_fake(page->mapping->host->i_sb) !=
++                         && reiser4_get_bitmap_fake(page->mapping->host->i_sb) !=
 +                         page->mapping->host));
 +
 +      if (!TestSetPageDirty(page)) {
@@ -573,7 +318,8 @@ Index: linux-2.6.16/fs/reiser4/as_ops.c
 +                      if (page->mapping) {
 +                              assert("vs-1652", page->mapping == mapping);
 +                              if (mapping_cap_account_dirty(mapping))
-+                                      inc_page_state(nr_dirty);
++                                      inc_zone_page_state(page,
++                                                      NR_FILE_DIRTY);
 +                              radix_tree_tag_set(&mapping->page_tree,
 +                                                 page->index,
 +                                                 PAGECACHE_TAG_REISER4_MOVED);
@@ -585,64 +331,6 @@ Index: linux-2.6.16/fs/reiser4/as_ops.c
 +      return 0;
 +}
 +
-+static int filler(void *vp, struct page *page)
-+{
-+      return page->mapping->a_ops->readpage(vp, page);
-+}
-+
-+/**
-+ * reiser4_readpages - submit read for a set of pages
-+ * @file: file to read
-+ * @mapping: address space
-+ * @pages: list of pages to submit read for
-+ * @nr_pages: number of pages no the list
-+ *
-+ * Operation of struct address_space_operations. This implementation is used by
-+ * unix and crc file plugins.
-+ *
-+ * Calls read_cache_pages or readpages hook if it is set.
-+ */
-+int
-+reiser4_readpages(struct file *file, struct address_space *mapping,
-+                struct list_head *pages, unsigned nr_pages)
-+{
-+      reiser4_context *ctx;
-+      reiser4_file_fsdata *fsdata;
-+
-+      ctx = init_context(mapping->host->i_sb);
-+      if (IS_ERR(ctx))
-+              return PTR_ERR(ctx);
-+
-+      fsdata = reiser4_get_file_fsdata(file);
-+      if (IS_ERR(fsdata)) {
-+              reiser4_exit_context(ctx);
-+              return PTR_ERR(fsdata);
-+      }
-+
-+      if (fsdata->ra2.readpages)
-+              fsdata->ra2.readpages(mapping, pages, fsdata->ra2.data);
-+      else {
-+              /*
-+               * filler (reiser4 readpage method) may involve tree search
-+               * which is not allowed when lock stack is not clean. If lock
-+               * stack is not clean - do nothing.
-+               */
-+              if (lock_stack_isclean(get_current_lock_stack()))
-+                      read_cache_pages(mapping, pages, filler, file);
-+              else {
-+                      while (!list_empty(pages)) {
-+                              struct page *victim;
-+
-+                              victim = list_entry(pages->prev, struct page, lru);
-+                              list_del(&victim->lru);
-+                              page_cache_release(victim);
-+                      }
-+              }
-+      }
-+      reiser4_exit_context(ctx);
-+      return 0;
-+}
-+
 +/* ->invalidatepage method for reiser4 */
 +
 +/*
@@ -659,7 +347,7 @@ Index: linux-2.6.16/fs/reiser4/as_ops.c
 + * @offset: starting offset for partial invalidation
 + *
 + */
-+int reiser4_invalidatepage(struct page *page, unsigned long offset)
++void reiser4_invalidatepage(struct page *page, unsigned long offset)
 +{
 +      int ret = 0;
 +      reiser4_context *ctx;
@@ -680,9 +368,9 @@ Index: linux-2.6.16/fs/reiser4/as_ops.c
 +       *
 +       * After many troubles with vmtruncate() based truncate (including
 +       * races with flush, tail conversion, etc.) it was re-written in the
-+       * top-to-bottom style: items are killed in cut_tree_object() and
-+       * pages belonging to extent are invalidated in kill_hook_extent(). So
-+       * probably now additional call to capture is not needed here.
++       * top-to-bottom style: items are killed in reiser4_cut_tree_object()
++       * and pages belonging to extent are invalidated in kill_hook_extent().
++       * So probably now additional call to capture is not needed here.
 +       */
 +
 +      assert("nikita-3137", PageLocked(page));
@@ -696,22 +384,23 @@ Index: linux-2.6.16/fs/reiser4/as_ops.c
 +       * during mount) it is simpler to let ->invalidatepage to be called on
 +       * them. Check for this, and do nothing.
 +       */
-+      if (get_super_fake(inode->i_sb) == inode)
-+              return 0;
-+      if (get_cc_fake(inode->i_sb) == inode)
-+              return 0;
-+      if (get_bitmap_fake(inode->i_sb) == inode)
-+              return 0;
++      if (reiser4_get_super_fake(inode->i_sb) == inode)
++              return;
++      if (reiser4_get_cc_fake(inode->i_sb) == inode)
++              return;
++      if (reiser4_get_bitmap_fake(inode->i_sb) == inode)
++              return;
 +      assert("vs-1426", PagePrivate(page));
 +      assert("vs-1427",
 +             page->mapping == jnode_get_mapping(jnode_by_page(page)));
 +      assert("", jprivate(page) != NULL);
 +      assert("", ergo(inode_file_plugin(inode) !=
-+                      file_plugin_by_id(CRC_FILE_PLUGIN_ID), offset == 0));
++                      file_plugin_by_id(CRYPTCOMPRESS_FILE_PLUGIN_ID),
++                      offset == 0));
 +
-+      ctx = init_context(inode->i_sb);
++      ctx = reiser4_init_context(inode->i_sb);
 +      if (IS_ERR(ctx))
-+              return PTR_ERR(ctx);
++              return;
 +
 +      node = jprivate(page);
 +      spin_lock_jnode(node);
@@ -721,11 +410,11 @@ Index: linux-2.6.16/fs/reiser4/as_ops.c
 +              jref(node);
 +              JF_SET(node, JNODE_HEARD_BANSHEE);
 +              page_clear_jnode(page, node);
-+              uncapture_jnode(node);
++              reiser4_uncapture_jnode(node);
 +              unhash_unformatted_jnode(node);
 +              jput(node);
 +              reiser4_exit_context(ctx);
-+              return 0;
++              return;
 +      }
 +      spin_unlock_jnode(node);
 +
@@ -740,7 +429,7 @@ Index: linux-2.6.16/fs/reiser4/as_ops.c
 +              JF_SET(node, JNODE_HEARD_BANSHEE);
 +              /* page cannot be detached from jnode concurrently, because it
 +               * is locked */
-+              uncapture_page(page);
++              reiser4_uncapture_page(page);
 +
 +              /* this detaches page from jnode, so that jdelete will not try
 +               * to lock page which is already locked */
@@ -753,7 +442,6 @@ Index: linux-2.6.16/fs/reiser4/as_ops.c
 +      }
 +
 +      reiser4_exit_context(ctx);
-+      return 0;
 +}
 +
 +/* help function called from reiser4_releasepage(). It returns true if jnode
@@ -778,7 +466,7 @@ Index: linux-2.6.16/fs/reiser4/as_ops.c
 +       * clean, not it atom yet, and still having fake block number. For
 +       * example, node just created in jinit_new().
 +       */
-+      if (blocknr_is_fake(jnode_get_block(node)))
++      if (reiser4_blocknr_is_fake(jnode_get_block(node)))
 +              return 0;
 +
 +      /*
@@ -826,7 +514,7 @@ Index: linux-2.6.16/fs/reiser4/as_ops.c
 +      assert("nikita-2257", PagePrivate(page));
 +      assert("nikita-2259", PageLocked(page));
 +      assert("nikita-2892", !PageWriteback(page));
-+      assert("nikita-3019", schedulable());
++      assert("nikita-3019", reiser4_schedulable());
 +
 +      /* NOTE-NIKITA: this can be called in the context of reiser4 call. It
 +         is not clear what to do in this case. A lot of deadlocks seems be
@@ -840,6 +528,8 @@ Index: linux-2.6.16/fs/reiser4/as_ops.c
 +      if (PageDirty(page))
 +              return 0;
 +
++      /* extra page reference is used by reiser4 to protect
++       * jnode<->page link from this ->releasepage(). */
 +      if (page_count(page) > 3)
 +              return 0;
 +
@@ -866,7 +556,7 @@ Index: linux-2.6.16/fs/reiser4/as_ops.c
 +      } else {
 +              spin_unlock(&(node->load));
 +              spin_unlock_jnode(node);
-+              assert("nikita-3020", schedulable());
++              assert("nikita-3020", reiser4_schedulable());
 +              return 0;
 +      }
 +}
@@ -880,11 +570,10 @@ Index: linux-2.6.16/fs/reiser4/as_ops.c
 +   fill-column: 120
 +   End:
 +*/
-Index: linux-2.6.16/fs/reiser4/block_alloc.c
-===================================================================
---- /dev/null
-+++ linux-2.6.16/fs/reiser4/block_alloc.c
-@@ -0,0 +1,1139 @@
+diff -urN linux-2.6.22.orig/fs/reiser4/block_alloc.c linux-2.6.22/fs/reiser4/block_alloc.c
+--- linux-2.6.22.orig/fs/reiser4/block_alloc.c 1970-01-01 03:00:00.000000000 +0300
++++ linux-2.6.22/fs/reiser4/block_alloc.c      2007-07-29 00:25:34.816680947 +0400
+@@ -0,0 +1,1137 @@
 +/* Copyright 2001, 2002, 2003 by Hans Reiser, licensing governed by reiser4/README */
 +
 +#include "debug.h"
@@ -1006,20 +695,20 @@ Index: linux-2.6.16/fs/reiser4/block_alloc.c
 +   impossible to overload this counter during one transaction life. */
 +
 +/* Initialize a blocknr hint. */
-+void blocknr_hint_init(reiser4_blocknr_hint * hint)
++void reiser4_blocknr_hint_init(reiser4_blocknr_hint * hint)
 +{
 +      memset(hint, 0, sizeof(reiser4_blocknr_hint));
 +}
 +
 +/* Release any resources of a blocknr hint. */
-+void blocknr_hint_done(reiser4_blocknr_hint * hint UNUSED_ARG)
++void reiser4_blocknr_hint_done(reiser4_blocknr_hint * hint UNUSED_ARG)
 +{
 +      /* No resources should be freed in current blocknr_hint implementation. */
 +}
 +
 +/* see above for explanation of fake block number.  */
 +/* Audited by: green(2002.06.11) */
-+int blocknr_is_fake(const reiser4_block_nr * da)
++int reiser4_blocknr_is_fake(const reiser4_block_nr * da)
 +{
 +      /* The reason for not simply returning result of '&' operation is that
 +         while return value is (possibly 32bit) int,  the reiser4_block_nr is
@@ -1105,13 +794,13 @@ Index: linux-2.6.16/fs/reiser4/block_alloc.c
 +/* super block has 6 counters: free, used, grabbed, fake allocated
 +   (formatted and unformatted) and flush reserved. Their sum must be
 +   number of blocks on a device. This function checks this */
-+int check_block_counters(const struct super_block *super)
++int reiser4_check_block_counters(const struct super_block *super)
 +{
 +      __u64 sum;
 +
 +      sum = reiser4_grabbed_blocks(super) + reiser4_free_blocks(super) +
 +          reiser4_data_blocks(super) + reiser4_fake_allocated(super) +
-+          reiser4_fake_allocated_unformatted(super) + flush_reserved(super) +
++          reiser4_fake_allocated_unformatted(super) + reiser4_flush_reserved(super) +
 +          reiser4_clustered_blocks(super);
 +      if (reiser4_block_count(super) != sum) {
 +              printk("super block counters: "
@@ -1124,7 +813,7 @@ Index: linux-2.6.16/fs/reiser4/block_alloc.c
 +                     (unsigned long long)reiser4_fake_allocated(super),
 +                     (unsigned long long)
 +                     reiser4_fake_allocated_unformatted(super),
-+                     (unsigned long long)flush_reserved(super),
++                     (unsigned long long)reiser4_flush_reserved(super),
 +                     (unsigned long long)reiser4_clustered_blocks(super),
 +                     (unsigned long long)sum,
 +                     (unsigned long long)reiser4_block_count(super));
@@ -1182,7 +871,7 @@ Index: linux-2.6.16/fs/reiser4/block_alloc.c
 +              ctx->grabbed_initially = count;
 +#endif
 +
-+      assert("nikita-2986", check_block_counters(ctx->super));
++      assert("nikita-2986", reiser4_check_block_counters(ctx->super));
 +
 +      /* disable grab space in current context */
 +      ctx->grab_enabled = 0;
@@ -1232,7 +921,7 @@ Index: linux-2.6.16/fs/reiser4/block_alloc.c
 + * Solution is to reserve 5% of disk space for truncates and
 + * unlinks. Specifically, normal space grabbing requests don't grab space from
 + * reserved area. Only requests with BA_RESERVED bit in flags are allowed to
-+ * drain it. Per super block delete_sema semaphore is used to allow only one
++ * drain it. Per super block delete mutex is used to allow only one
 + * thread at a time to grab from reserved area.
 + *
 + * Grabbing from reserved area should always be performed with BA_CAN_COMMIT
@@ -1247,9 +936,9 @@ Index: linux-2.6.16/fs/reiser4/block_alloc.c
 +
 +      assert("nikita-3175", flags & BA_CAN_COMMIT);
 +
-+      /* Check the delete semaphore already taken by us, we assume that
++      /* Check the delete mutex already taken by us, we assume that
 +       * reading of machine word is atomic. */
-+      if (sbinfo->delete_sema_owner == current) {
++      if (sbinfo->delete_mutex_owner == current) {
 +              if (reiser4_grab_space
 +                  (count, (flags | BA_RESERVED) & ~BA_CAN_COMMIT)) {
 +                      warning("zam-1003",
@@ -1262,9 +951,9 @@ Index: linux-2.6.16/fs/reiser4/block_alloc.c
 +      }
 +
 +      if (reiser4_grab_space(count, flags)) {
-+              down(&sbinfo->delete_sema);
-+              assert("nikita-2929", sbinfo->delete_sema_owner == NULL);
-+              sbinfo->delete_sema_owner = current;
++              mutex_lock(&sbinfo->delete_mutex);
++              assert("nikita-2929", sbinfo->delete_mutex_owner == NULL);
++              sbinfo->delete_mutex_owner = current;
 +
 +              if (reiser4_grab_space(count, flags | BA_RESERVED)) {
 +                      warning("zam-833",
@@ -1282,9 +971,9 @@ Index: linux-2.6.16/fs/reiser4/block_alloc.c
 +      reiser4_super_info_data *info;
 +
 +      info = get_super_private(super);
-+      if (info->delete_sema_owner == current) {
-+              info->delete_sema_owner = NULL;
-+              up(&info->delete_sema);
++      if (info->delete_mutex_owner == current) {
++              info->delete_mutex_owner = NULL;
++              mutex_unlock(&info->delete_mutex);
 +      }
 +}
 +
@@ -1313,7 +1002,7 @@ Index: linux-2.6.16/fs/reiser4/block_alloc.c
 +      sbinfo = grabbed2fake_allocated_head(1);
 +      sbinfo->blocks_fake_allocated++;
 +
-+      assert("vs-922", check_block_counters(reiser4_get_current_sb()));
++      assert("vs-922", reiser4_check_block_counters(reiser4_get_current_sb()));
 +
 +      spin_unlock_reiser4_super(sbinfo);
 +}
@@ -1330,7 +1019,7 @@ Index: linux-2.6.16/fs/reiser4/block_alloc.c
 +      sbinfo = grabbed2fake_allocated_head(count);
 +      sbinfo->blocks_fake_allocated_unformatted += count;
 +
-+      assert("vs-9221", check_block_counters(reiser4_get_current_sb()));
++      assert("vs-9221", reiser4_check_block_counters(reiser4_get_current_sb()));
 +
 +      spin_unlock_reiser4_super(sbinfo);
 +}
@@ -1349,7 +1038,7 @@ Index: linux-2.6.16/fs/reiser4/block_alloc.c
 +      sub_from_sb_grabbed(sbinfo, count);
 +      sbinfo->blocks_clustered += count;
 +
-+      assert("edward-504", check_block_counters(ctx->super));
++      assert("edward-504", reiser4_check_block_counters(ctx->super));
 +
 +      spin_unlock_reiser4_super(sbinfo);
 +}
@@ -1367,7 +1056,7 @@ Index: linux-2.6.16/fs/reiser4/block_alloc.c
 +      sub_from_cluster_reserved(sbinfo, count);
 +      sbinfo->blocks_grabbed += count;
 +
-+      assert("edward-505", check_block_counters(ctx->super));
++      assert("edward-505", reiser4_check_block_counters(ctx->super));
 +
 +      spin_unlock_reiser4_super(sbinfo);
 +      add_to_ctx_grabbed(ctx, count);
@@ -1378,18 +1067,11 @@ Index: linux-2.6.16/fs/reiser4/block_alloc.c
 +      reiser4_context *ctx;
 +      reiser4_super_info_data *sbinfo;
 +
-+      assert("edward-503", get_current_context()->grabbed_blocks == 0);
-+
 +      ctx = get_current_context();
 +      sbinfo = get_super_private(ctx->super);
-+      spin_lock_reiser4_super(sbinfo);
-+
-+      sub_from_cluster_reserved(sbinfo, count);
-+      sbinfo->blocks_free += count;
 +
-+      assert("edward-502", check_block_counters(ctx->super));
-+
-+      spin_unlock_reiser4_super(sbinfo);
++      cluster_reserved2grabbed(count);
++      grabbed2free(ctx, sbinfo, count);
 +}
 +
 +static DEFINE_SPINLOCK(fake_lock);
@@ -1441,8 +1123,8 @@ Index: linux-2.6.16/fs/reiser4/block_alloc.c
 +
 +/* adjust sb block counters, if real (on-disk) block allocation immediately
 +   follows grabbing of free disk space. */
-+void grabbed2used(reiser4_context *ctx, reiser4_super_info_data *sbinfo,
-+                __u64 count)
++static void grabbed2used(reiser4_context *ctx, reiser4_super_info_data *sbinfo,
++                       __u64 count)
 +{
 +      sub_from_ctx_grabbed(ctx, count);
 +
@@ -1451,26 +1133,27 @@ Index: linux-2.6.16/fs/reiser4/block_alloc.c
 +      sub_from_sb_grabbed(sbinfo, count);
 +      sbinfo->blocks_used += count;
 +
-+      assert("nikita-2679", check_block_counters(ctx->super));
++      assert("nikita-2679", reiser4_check_block_counters(ctx->super));
 +
 +      spin_unlock_reiser4_super(sbinfo);
 +}
 +
 +/* adjust sb block counters when @count unallocated blocks get mapped to disk */
-+void fake_allocated2used(reiser4_super_info_data *sbinfo, __u64 count,
-+                       reiser4_ba_flags_t flags)
++static void fake_allocated2used(reiser4_super_info_data *sbinfo, __u64 count,
++                              reiser4_ba_flags_t flags)
 +{
 +      spin_lock_reiser4_super(sbinfo);
 +
 +      sub_from_sb_fake_allocated(sbinfo, count, flags);
 +      sbinfo->blocks_used += count;
 +
-+      assert("nikita-2680", check_block_counters(reiser4_get_current_sb()));
++      assert("nikita-2680",
++             reiser4_check_block_counters(reiser4_get_current_sb()));
 +
 +      spin_unlock_reiser4_super(sbinfo);
 +}
 +
-+void flush_reserved2used(txn_atom * atom, __u64 count)
++static void flush_reserved2used(txn_atom * atom, __u64 count)
 +{
 +      reiser4_super_info_data *sbinfo;
 +
@@ -1485,7 +1168,8 @@ Index: linux-2.6.16/fs/reiser4/block_alloc.c
 +      sub_from_sb_flush_reserved(sbinfo, count);
 +      sbinfo->blocks_used += count;
 +
-+      assert("zam-789", check_block_counters(reiser4_get_current_sb()));
++      assert("zam-789",
++             reiser4_check_block_counters(reiser4_get_current_sb()));
 +
 +      spin_unlock_reiser4_super(sbinfo);
 +}
@@ -1497,7 +1181,7 @@ Index: linux-2.6.16/fs/reiser4/block_alloc.c
 +{
 +      reiser4_super_info_data *sbinfo = get_super_private(s);
 +
-+      assert("nikita-3342", !blocknr_is_fake(block));
++      assert("nikita-3342", !reiser4_blocknr_is_fake(block));
 +
 +      spin_lock_reiser4_super(sbinfo);
 +      if (*block < sbinfo->block_count) {
@@ -1569,8 +1253,8 @@ Index: linux-2.6.16/fs/reiser4/block_alloc.c
 +      }
 +
 +      ret =
-+          sa_alloc_blocks(get_space_allocator(ctx->super), hint, (int)needed,
-+                          blk, len);
++          sa_alloc_blocks(reiser4_get_space_allocator(ctx->super),
++                          hint, (int)needed, blk, len);
 +
 +      if (!ret) {
 +              assert("zam-680", *blk < reiser4_block_count(ctx->super));
@@ -1630,7 +1314,8 @@ Index: linux-2.6.16/fs/reiser4/block_alloc.c
 +
 +      sub_from_sb_used(sbinfo, count);
 +
-+      assert("nikita-2681", check_block_counters(reiser4_get_current_sb()));
++      assert("nikita-2681",
++             reiser4_check_block_counters(reiser4_get_current_sb()));
 +
 +      spin_unlock_reiser4_super(sbinfo);
 +}
@@ -1650,7 +1335,8 @@ Index: linux-2.6.16/fs/reiser4/block_alloc.c
 +      /*add_to_sb_flush_reserved(sbinfo, count); */
 +      sub_from_sb_used(sbinfo, count);
 +
-+      assert("nikita-2681", check_block_counters(reiser4_get_current_sb()));
++      assert("nikita-2681",
++             reiser4_check_block_counters(reiser4_get_current_sb()));
 +
 +      spin_unlock_reiser4_super(sbinfo);
 +}
@@ -1664,12 +1350,12 @@ Index: linux-2.6.16/fs/reiser4/block_alloc.c
 +
 +      spin_lock_reiser4_super(sbinfo);
 +
-+      assert("nikita-2682", check_block_counters(ctx->super));
++      assert("nikita-2682", reiser4_check_block_counters(ctx->super));
 +
 +      sbinfo->blocks_grabbed += count;
 +      sub_from_sb_fake_allocated(sbinfo, count, flags & BA_FORMATTED);
 +
-+      assert("nikita-2683", check_block_counters(ctx->super));
++      assert("nikita-2683", reiser4_check_block_counters(ctx->super));
 +
 +      spin_unlock_reiser4_super(sbinfo);
 +}
@@ -1717,7 +1403,7 @@ Index: linux-2.6.16/fs/reiser4/block_alloc.c
 +
 +      sub_from_sb_grabbed(sbinfo, count);
 +      sbinfo->blocks_free += count;
-+      assert("nikita-2684", check_block_counters(ctx->super));
++      assert("nikita-2684", reiser4_check_block_counters(ctx->super));
 +
 +      spin_unlock_reiser4_super(sbinfo);
 +}
@@ -1741,7 +1427,7 @@ Index: linux-2.6.16/fs/reiser4/block_alloc.c
 +      sbinfo->blocks_flush_reserved += count;
 +      sub_from_sb_grabbed(sbinfo, count);
 +
-+      assert("vpf-292", check_block_counters(ctx->super));
++      assert("vpf-292", reiser4_check_block_counters(ctx->super));
 +
 +      spin_unlock_reiser4_super(sbinfo);
 +}
@@ -1775,7 +1461,7 @@ Index: linux-2.6.16/fs/reiser4/block_alloc.c
 +      sbinfo->blocks_grabbed += count;
 +      sub_from_sb_flush_reserved(sbinfo, count);
 +
-+      assert("vpf-292", check_block_counters(ctx->super));
++      assert("vpf-292", reiser4_check_block_counters(ctx->super));
 +
 +      spin_unlock_reiser4_super(sbinfo);
 +}
@@ -1807,7 +1493,7 @@ Index: linux-2.6.16/fs/reiser4/block_alloc.c
 +      sbinfo->blocks_grabbed += count;
 +      sub_from_sb_used(sbinfo, count);
 +
-+      assert("nikita-2685", check_block_counters(ctx->super));
++      assert("nikita-2685", reiser4_check_block_counters(ctx->super));
 +
 +      spin_unlock_reiser4_super(sbinfo);
 +}
@@ -1820,7 +1506,8 @@ Index: linux-2.6.16/fs/reiser4/block_alloc.c
 +      sbinfo->blocks_free += count;
 +      sub_from_sb_used(sbinfo, count);
 +
-+      assert("nikita-2685", check_block_counters(reiser4_get_current_sb()));
++      assert("nikita-2685",
++             reiser4_check_block_counters(reiser4_get_current_sb()));
 +
 +      spin_unlock_reiser4_super(sbinfo);
 +}
@@ -1873,7 +1560,7 @@ Index: linux-2.6.16/fs/reiser4/block_alloc.c
 +      if (REISER4_DEBUG) {
 +              assert("zam-431", *len != 0);
 +              assert("zam-432", *start != 0);
-+              assert("zam-558", !blocknr_is_fake(start));
++              assert("zam-558", !reiser4_blocknr_is_fake(start));
 +
 +              spin_lock_reiser4_super(sbinfo);
 +              assert("zam-562", *start < sbinfo->block_count);
@@ -1906,8 +1593,8 @@ Index: linux-2.6.16/fs/reiser4/block_alloc.c
 +
 +      } else {
 +              assert("zam-425", get_current_super_private() != NULL);
-+              sa_dealloc_blocks(get_space_allocator(ctx->super), *start,
-+                                *len);
++              sa_dealloc_blocks(reiser4_get_space_allocator(ctx->super),
++                                *start, *len);
 +
 +              if (flags & BA_PERMANENT) {
 +                      /* These blocks were counted as allocated, we have to revert it
@@ -1950,7 +1637,7 @@ Index: linux-2.6.16/fs/reiser4/block_alloc.c
 +}
 +
 +/* wrappers for block allocator plugin methods */
-+int pre_commit_hook(void)
++int reiser4_pre_commit_hook(void)
 +{
 +      assert("zam-502", get_current_super_private() != NULL);
 +      sa_pre_commit_hook();
@@ -1991,7 +1678,7 @@ Index: linux-2.6.16/fs/reiser4/block_alloc.c
 +      return 0;
 +}
 +
-+void post_commit_hook(void)
++void reiser4_post_commit_hook(void)
 +{
 +      txn_atom *atom;
 +
@@ -2007,7 +1694,7 @@ Index: linux-2.6.16/fs/reiser4/block_alloc.c
 +      sa_post_commit_hook();
 +}
 +
-+void post_write_back_hook(void)
++void reiser4_post_write_back_hook(void)
 +{
 +      assert("zam-504", get_current_super_private() != NULL);
 +
@@ -2024,10 +1711,9 @@ Index: linux-2.6.16/fs/reiser4/block_alloc.c
 +   scroll-step: 1
 +   End:
 +*/
-Index: linux-2.6.16/fs/reiser4/block_alloc.h
-===================================================================
---- /dev/null
-+++ linux-2.6.16/fs/reiser4/block_alloc.h
+diff -urN linux-2.6.22.orig/fs/reiser4/block_alloc.h linux-2.6.22/fs/reiser4/block_alloc.h
+--- linux-2.6.22.orig/fs/reiser4/block_alloc.h 1970-01-01 03:00:00.000000000 +0300
++++ linux-2.6.22/fs/reiser4/block_alloc.h      2007-07-29 00:25:34.820681982 +0400
 @@ -0,0 +1,175 @@
 +/* Copyright 2002, 2003 by Hans Reiser, licensing governed by reiser4/README */
 +
@@ -2113,8 +1799,8 @@ Index: linux-2.6.16/fs/reiser4/block_alloc.h
 +
 +typedef enum reiser4_ba_flags reiser4_ba_flags_t;
 +
-+extern void blocknr_hint_init(reiser4_blocknr_hint * hint);
-+extern void blocknr_hint_done(reiser4_blocknr_hint * hint);
++extern void reiser4_blocknr_hint_init(reiser4_blocknr_hint * hint);
++extern void reiser4_blocknr_hint_done(reiser4_blocknr_hint * hint);
 +extern void update_blocknr_hint_default(const struct super_block *,
 +                                      const reiser4_block_nr *);
 +extern void get_blocknr_hint_default(reiser4_block_nr *);
@@ -2171,13 +1857,13 @@ Index: linux-2.6.16/fs/reiser4/block_alloc.h
 +
 +extern void flush_reserved2grabbed(txn_atom * atom, __u64 count);
 +
-+extern int blocknr_is_fake(const reiser4_block_nr * da);
++extern int reiser4_blocknr_is_fake(const reiser4_block_nr * da);
 +
 +extern void grabbed2cluster_reserved(int count);
 +extern void cluster_reserved2grabbed(int count);
 +extern void cluster_reserved2free(int count);
 +
-+extern int check_block_counters(const struct super_block *);
++extern int reiser4_check_block_counters(const struct super_block *);
 +
 +#if REISER4_DEBUG
 +
@@ -2189,9 +1875,9 @@ Index: linux-2.6.16/fs/reiser4/block_alloc.h
 +
 +#endif
 +
-+extern int pre_commit_hook(void);
-+extern void post_commit_hook(void);
-+extern void post_write_back_hook(void);
++extern int reiser4_pre_commit_hook(void);
++extern void reiser4_post_commit_hook(void);
++extern void reiser4_post_write_back_hook(void);
 +
 +#endif                                /* __FS_REISER4_BLOCK_ALLOC_H__ */
 +
@@ -2204,10 +1890,9 @@ Index: linux-2.6.16/fs/reiser4/block_alloc.h
 +   fill-column: 120
 +   End:
 +*/
-Index: linux-2.6.16/fs/reiser4/blocknrset.c
-===================================================================
---- /dev/null
-+++ linux-2.6.16/fs/reiser4/blocknrset.c
+diff -urN linux-2.6.22.orig/fs/reiser4/blocknrset.c linux-2.6.22/fs/reiser4/blocknrset.c
+--- linux-2.6.22.orig/fs/reiser4/blocknrset.c  1970-01-01 03:00:00.000000000 +0300
++++ linux-2.6.22/fs/reiser4/blocknrset.c       2007-07-29 00:25:34.820681982 +0400
 @@ -0,0 +1,368 @@
 +/* Copyright 2001, 2002, 2003 by Hans Reiser, licensing governed by reiser4/README */
 +
@@ -2239,7 +1924,8 @@ Index: linux-2.6.16/fs/reiser4/blocknrset.c
 + * extent; atom's wandered map is also stored as a blocknr set, blocknr pairs
 + * there represent a (real block) -> (wandered block) mapping. */
 +
-+typedef struct blocknr_pair blocknr_pair;
++/* Protection: blocknr sets belong to reiser4 atom, and
++ * their modifications are performed with the atom lock held */
 +
 +/* The total size of a blocknr_set_entry. */
 +#define BLOCKNR_SET_ENTRY_SIZE 128
@@ -2292,7 +1978,7 @@ Index: linux-2.6.16/fs/reiser4/blocknrset.c
 +      blocknr_set_entry *e;
 +
 +      if ((e = (blocknr_set_entry *) kmalloc(sizeof(blocknr_set_entry),
-+                                             get_gfp_mask())) == NULL)
++                                         reiser4_ctx_gfp_mask_get())) == NULL)
 +              return NULL;
 +
 +      bse_init(e);
@@ -2319,12 +2005,14 @@ Index: linux-2.6.16/fs/reiser4/blocknrset.c
 +
 +/* Get a pair of block numbers */
 +/* Audited by: green(2002.06.11) */
-+static inline blocknr_pair *bse_get_pair(blocknr_set_entry * bse, unsigned pno)
++static inline struct blocknr_pair *bse_get_pair(blocknr_set_entry * bse,
++                                              unsigned pno)
 +{
 +      assert("green-1", BLOCKNR_SET_ENTRIES_NUMBER >= 2 * (pno + 1));
 +
-+      return (blocknr_pair *) (bse->entries + BLOCKNR_SET_ENTRIES_NUMBER -
-+                               2 * (pno + 1));
++      return (struct blocknr_pair *) (bse->entries +
++                                      BLOCKNR_SET_ENTRIES_NUMBER -
++                                      2 * (pno + 1));
 +}
 +
 +/* Add a pair of block numbers to a blocknr_set_entry */
@@ -2333,7 +2021,7 @@ Index: linux-2.6.16/fs/reiser4/blocknrset.c
 +bse_put_pair(blocknr_set_entry * bse, const reiser4_block_nr * a,
 +           const reiser4_block_nr * b)
 +{
-+      blocknr_pair *pair;
++      struct blocknr_pair *pair;
 +
 +      assert("jmacd-5100", bse_avail(bse) >= 2 && a != NULL && b != NULL);
 +
@@ -2354,7 +2042,7 @@ Index: linux-2.6.16/fs/reiser4/blocknrset.c
 +   returned with the atom unlocked for the operation to be tried again.  If
 +   the operation succeeds, 0 is returned.  If new_bsep is non-NULL and not
 +   used during the call, it will be freed automatically. */
-+static int blocknr_set_add(txn_atom *atom, blocknr_set *bset,
++static int blocknr_set_add(txn_atom *atom, struct list_head *bset,
 +                         blocknr_set_entry **new_bsep, const reiser4_block_nr *a,
 +                         const reiser4_block_nr *b)
 +{
@@ -2364,8 +2052,8 @@ Index: linux-2.6.16/fs/reiser4/blocknrset.c
 +      assert("jmacd-5101", a != NULL);
 +
 +      entries_needed = (b == NULL) ? 1 : 2;
-+      if (list_empty(&bset->entries) ||
-+          bse_avail(list_entry(bset->entries.next, blocknr_set_entry, link)) < entries_needed) {
++      if (list_empty(bset) ||
++          bse_avail(list_entry(bset->next, blocknr_set_entry, link)) < entries_needed) {
 +              /* See if a bse was previously allocated. */
 +              if (*new_bsep == NULL) {
 +                      spin_unlock_atom(atom);
@@ -2375,13 +2063,13 @@ Index: linux-2.6.16/fs/reiser4/blocknrset.c
 +              }
 +
 +              /* Put it on the head of the list. */
-+              list_add(&((*new_bsep)->link), &bset->entries);
++              list_add(&((*new_bsep)->link), bset);
 +
 +              *new_bsep = NULL;
 +      }
 +
 +      /* Add the single or pair. */
-+      bse = list_entry(bset->entries.next, blocknr_set_entry, link);
++      bse = list_entry(bset->next, blocknr_set_entry, link);
 +      if (b == NULL) {
 +              bse_put_single(bse, a);
 +      } else {
@@ -2405,7 +2093,7 @@ Index: linux-2.6.16/fs/reiser4/blocknrset.c
 +   properly freed. */
 +int
 +blocknr_set_add_extent(txn_atom * atom,
-+                     blocknr_set * bset,
++                     struct list_head * bset,
 +                     blocknr_set_entry ** new_bsep,
 +                     const reiser4_block_nr * start,
 +                     const reiser4_block_nr * len)
@@ -2423,7 +2111,7 @@ Index: linux-2.6.16/fs/reiser4/blocknrset.c
 +   properly freed. */
 +int
 +blocknr_set_add_pair(txn_atom * atom,
-+                   blocknr_set * bset,
++                   struct list_head * bset,
 +                   blocknr_set_entry ** new_bsep, const reiser4_block_nr * a,
 +                   const reiser4_block_nr * b)
 +{
@@ -2432,18 +2120,18 @@ Index: linux-2.6.16/fs/reiser4/blocknrset.c
 +}
 +
 +/* Initialize a blocknr_set. */
-+void blocknr_set_init(blocknr_set *bset)
++void blocknr_set_init(struct list_head *bset)
 +{
-+      INIT_LIST_HEAD(&bset->entries);
++      INIT_LIST_HEAD(bset);
 +}
 +
 +/* Release the entries of a blocknr_set. */
-+void blocknr_set_destroy(blocknr_set *bset)
++void blocknr_set_destroy(struct list_head *bset)
 +{
 +      blocknr_set_entry *bse;
 +
-+      while (!list_empty_careful(&bset->entries)) {
-+              bse = list_entry(bset->entries.next, blocknr_set_entry, link);
++      while (!list_empty(bset)) {
++              bse = list_entry(bset->next, blocknr_set_entry, link);
 +              list_del_init(&bse->link);
 +              bse_free(bse);
 +      }
@@ -2459,25 +2147,23 @@ Index: linux-2.6.16/fs/reiser4/blocknrset.c
 +   actual processing of this set. Testing this kind of stuff right here is
 +   also complicated by the fact that these sets are not sorted and going
 +   through whole set on each element addition is going to be CPU-heavy task */
-+void blocknr_set_merge(blocknr_set * from, blocknr_set * into)
++void blocknr_set_merge(struct list_head * from, struct list_head * into)
 +{
 +      blocknr_set_entry *bse_into = NULL;
 +
 +      /* If @from is empty, no work to perform. */
-+      if (list_empty_careful(&from->entries)) {
++      if (list_empty(from))
 +              return;
-+      }
-+
 +      /* If @into is not empty, try merging partial-entries. */
-+      if (!list_empty_careful(&into->entries)) {
++      if (!list_empty(into)) {
 +
 +              /* Neither set is empty, pop the front to members and try to combine them. */
 +              blocknr_set_entry *bse_from;
 +              unsigned into_avail;
 +
-+              bse_into = list_entry(into->entries.next, blocknr_set_entry, link);
++              bse_into = list_entry(into->next, blocknr_set_entry, link);
 +              list_del_init(&bse_into->link);
-+              bse_from = list_entry(from->entries.next, blocknr_set_entry, link);
++              bse_from = list_entry(from->next, blocknr_set_entry, link);
 +              list_del_init(&bse_from->link);
 +
 +              /* Combine singles. */
@@ -2492,8 +2178,8 @@ Index: linux-2.6.16/fs/reiser4/blocknrset.c
 +              /* Combine pairs. */
 +              for (; into_avail > 1 && bse_from->nr_pairs != 0;
 +                   into_avail -= 2) {
-+                      blocknr_pair *pair =
-+                          bse_get_pair(bse_from, --bse_from->nr_pairs);
++                      struct blocknr_pair *pair =
++                              bse_get_pair(bse_from, --bse_from->nr_pairs);
 +                      bse_put_pair(bse_into, &pair->a, &pair->b);
 +              }
 +
@@ -2505,22 +2191,21 @@ Index: linux-2.6.16/fs/reiser4/blocknrset.c
 +                         it could have one slot avail and bse_from has one
 +                         pair left).  Push it back onto the list.  bse_from
 +                         becomes bse_into, which will be the new partial. */
-+                      list_add(&bse_into->link, &into->entries);
++                      list_add(&bse_into->link, into);
 +                      bse_into = bse_from;
 +              }
 +      }
 +
 +      /* Splice lists together. */
-+      list_splice_init(&from->entries, into->entries.prev);
++      list_splice_init(from, into->prev);
 +
 +      /* Add the partial entry back to the head of the list. */
-+      if (bse_into != NULL) {
-+              list_add(&bse_into->link, &into->entries);
-+      }
++      if (bse_into != NULL)
++              list_add(&bse_into->link, into);
 +}
 +
 +/* Iterate over all blocknr set elements. */
-+int blocknr_set_iterator(txn_atom *atom, blocknr_set *bset,
++int blocknr_set_iterator(txn_atom *atom, struct list_head *bset,
 +                       blocknr_set_actor_f actor, void *data, int delete)
 +{
 +
@@ -2531,8 +2216,8 @@ Index: linux-2.6.16/fs/reiser4/blocknrset.c
 +      assert("zam-431", bset != 0);
 +      assert("zam-432", actor != NULL);
 +
-+      entry = list_entry(bset->entries.next, blocknr_set_entry, link);
-+      while (&bset->entries != &entry->link) {
++      entry = list_entry(bset->next, blocknr_set_entry, link);
++      while (bset != &entry->link) {
 +              blocknr_set_entry *tmp = list_entry(entry->link.next, blocknr_set_entry, link);
 +              unsigned int i;
 +              int ret;
@@ -2577,11 +2262,10 @@ Index: linux-2.6.16/fs/reiser4/blocknrset.c
 + * scroll-step: 1
 + * End:
 + */
-Index: linux-2.6.16/fs/reiser4/carry.c
-===================================================================
---- /dev/null
-+++ linux-2.6.16/fs/reiser4/carry.c
-@@ -0,0 +1,1381 @@
+diff -urN linux-2.6.22.orig/fs/reiser4/carry.c linux-2.6.22/fs/reiser4/carry.c
+--- linux-2.6.22.orig/fs/reiser4/carry.c       1970-01-01 03:00:00.000000000 +0300
++++ linux-2.6.22/fs/reiser4/carry.c    2007-07-29 00:25:34.820681982 +0400
+@@ -0,0 +1,1391 @@
 +/* Copyright 2001, 2002, 2003 by Hans Reiser, licensing governed by reiser4/README */
 +/* Functions to "carry" tree modification(s) upward. */
 +/* Tree is modified one level at a time. As we modify a level we accumulate a
@@ -2645,7 +2329,7 @@ Index: linux-2.6.16/fs/reiser4/carry.c
 +       //   COP_UPDATE    --- update delimiting key in least
 +       //                     common ancestor of two
 +
-+       op = post_carry( &lowest_level, operation, node, 0 );
++       op = reiser4_post_carry( &lowest_level, operation, node, 0 );
 +       if( IS_ERR( op ) || ( op == NULL ) ) {
 +           handle error
 +       } else {
@@ -2664,7 +2348,7 @@ Index: linux-2.6.16/fs/reiser4/carry.c
 +
 +       ....
 +
-+       // note, that last argument to post_carry() is non-null
++       // note, that last argument to reiser4_post_carry() is non-null
 +       // here, because @op is to be applied to the parent of @node, rather
 +       // than to the @node itself as in the previous case.
 +
@@ -2701,8 +2385,8 @@ Index: linux-2.6.16/fs/reiser4/carry.c
 +    2. whole balancing logic is implemented here, in particular, insertion
 +    logic is coded in make_space().
 +
-+    3. special cases like insertion (add_tree_root()) or deletion
-+    (kill_tree_root()) of tree root and morphing of paste into insert
++    3. special cases like insertion (reiser4_add_tree_root()) or deletion
++    (reiser4_kill_tree_root()) of tree root and morphing of paste into insert
 +    (insert_paste()) have to be handled.
 +
 +    4. there is non-trivial interdependency between allocation of new nodes
@@ -2752,7 +2436,6 @@ Index: linux-2.6.16/fs/reiser4/carry.c
 +static void fatal_carry_error(carry_level * doing, int ecode);
 +static int add_new_root(carry_level * level, carry_node * node, znode * fake);
 +
-+
 +static void print_level(const char *prefix, carry_level * level);
 +
 +#if REISER4_DEBUG
@@ -2774,9 +2457,11 @@ Index: linux-2.6.16/fs/reiser4/carry.c
 +   For usage, see comment at the top of fs/reiser4/carry.c
 +
 +*/
-+int carry(carry_level * doing /* set of carry operations to be performed */ ,
-+        carry_level * done    /* set of nodes, already performed at the
-+                               * previous level. NULL in most cases */ )
++int reiser4_carry(carry_level * doing /* set of carry operations to be
++                                     * performed */ ,
++                carry_level * done  /* set of nodes, already performed
++                                     *  at the previous level.
++                                     * NULL in most cases */)
 +{
 +      int result = 0;
 +      /* queue of new requests */
@@ -2850,7 +2535,7 @@ Index: linux-2.6.16/fs/reiser4/carry.c
 +              init_carry_level(todo, doing->pool);
 +
 +              /* give other threads chance to run */
-+              preempt_point();
++              reiser4_preempt_point();
 +      }
 +      done_carry_level(done);
 +
@@ -2941,7 +2626,7 @@ Index: linux-2.6.16/fs/reiser4/carry.c
 +              for_all_nodes(doing, scan, tmp_scan) {
 +                      znode *node;
 +
-+                      node = carry_real(scan);
++                      node = reiser4_carry_real(scan);
 +                      assert("nikita-2547", node != NULL);
 +                      if (node_is_empty(node)) {
 +                              result =
@@ -2969,14 +2654,14 @@ Index: linux-2.6.16/fs/reiser4/carry.c
 +   caller to guarantee proper ordering of node queue.
 +
 +*/
-+carry_op *post_carry(carry_level * level      /* queue where new operation is to
-+                                               * be posted at */ ,
-+                   carry_opcode op /* opcode of operation */ ,
-+                   znode * node       /* node on which this operation
-+                                       * will operate */ ,
-+                   int apply_to_parent_p      /* whether operation will operate
-+                                               * directly on @node or on it
-+                                               * parent. */ )
++carry_op * reiser4_post_carry(carry_level * level /* queue where new operation
++                                                 * is to be posted at */ ,
++                            carry_opcode op /* opcode of operation */ ,
++                            znode * node      /* node on which this operation
++                                               * will operate */ ,
++                            int apply_to_parent_p /* whether operation will
++                                                   * operate directly on @node
++                                                   * or on it parent. */)
 +{
 +      carry_op *result;
 +      carry_node *child;
@@ -2987,7 +2672,7 @@ Index: linux-2.6.16/fs/reiser4/carry.c
 +      result = add_op(level, POOLO_LAST, NULL);
 +      if (IS_ERR(result))
 +              return result;
-+      child = add_carry(level, POOLO_LAST, NULL);
++      child = reiser4_add_carry(level, POOLO_LAST, NULL);
 +      if (IS_ERR(child)) {
 +              reiser4_pool_free(&level->pool->op_pool, &result->header);
 +              return (carry_op *) child;
@@ -3022,7 +2707,7 @@ Index: linux-2.6.16/fs/reiser4/carry.c
 +      carry_pool *pool;
 +
 +      assert("", size >= sizeof(carry_pool) + 3 * sizeof(carry_level));
-+      pool = kmalloc(size, get_gfp_mask());
++      pool = kmalloc(size, reiser4_ctx_gfp_mask_get());
 +      if (pool == NULL)
 +              return ERR_PTR(RETERR(-ENOMEM));
 +
@@ -3050,15 +2735,17 @@ Index: linux-2.6.16/fs/reiser4/carry.c
 +   automatically. To control ordering use @order and @reference parameters.
 +
 +*/
-+carry_node *add_carry_skip(carry_level * level        /* &carry_level to add node
-+                                               * to */ ,
-+                         pool_ordering order  /* where to insert: at the
-+                                               * beginning of @level,
-+                                               * before @reference, after
-+                                               * @reference, at the end
-+                                               * of @level */ ,
-+                         carry_node * reference       /* reference node for
-+                                                       * insertion */ )
++carry_node *reiser4_add_carry_skip(carry_level * level        /* &carry_level to add
++                                                       * node to */ ,
++                                 pool_ordering order  /* where to insert:
++                                                       * at the beginning of
++                                                       * @level,
++                                                       * before @reference,
++                                                       * after @reference,
++                                                       * at the end of @level
++                                                       */ ,
++                                 carry_node * reference/* reference node for
++                                                        * insertion */)
 +{
 +      ON_DEBUG(carry_node * orig_ref = reference);
 +
@@ -3081,11 +2768,12 @@ Index: linux-2.6.16/fs/reiser4/carry.c
 +      }
 +      assert("nikita-2209",
 +             ergo(orig_ref != NULL,
-+                  carry_real(reference) == carry_real(orig_ref)));
-+      return add_carry(level, order, reference);
++                  reiser4_carry_real(reference) ==
++                  reiser4_carry_real(orig_ref)));
++      return reiser4_add_carry(level, order, reference);
 +}
 +
-+carry_node *add_carry(carry_level * level     /* &carry_level to add node
++carry_node *reiser4_add_carry(carry_level * level     /* &carry_level to add node
 +                                               * to */ ,
 +                    pool_ordering order       /* where to insert: at the
 +                                               * beginning of @level, before
@@ -3097,8 +2785,9 @@ Index: linux-2.6.16/fs/reiser4/carry.c
 +      carry_node *result;
 +
 +      result =
-+          (carry_node *) add_obj(&level->pool->node_pool, &level->nodes,
-+                                 order, &reference->header);
++          (carry_node *) reiser4_add_obj(&level->pool->node_pool,
++                                         &level->nodes,
++                                         order, &reference->header);
 +      if (!IS_ERR(result) && (result != NULL))
 +              ++level->nodes_num;
 +      return result;
@@ -3121,8 +2810,8 @@ Index: linux-2.6.16/fs/reiser4/carry.c
 +      carry_op *result;
 +
 +      result =
-+          (carry_op *) add_obj(&level->pool->op_pool, &level->ops, order,
-+                               &reference->header);
++          (carry_op *) reiser4_add_obj(&level->pool->op_pool, &level->ops,
++                                       order, &reference->header);
 +      if (!IS_ERR(result) && (result != NULL))
 +              ++level->ops_num;
 +      return result;
@@ -3147,16 +2836,16 @@ Index: linux-2.6.16/fs/reiser4/carry.c
 +      assert("nikita-1614", node != NULL);
 +      assert("nikita-1615", kin != NULL);
 +      assert("nikita-1616", LOCK_CNT_GTZ(rw_locked_tree));
-+      assert("nikita-1619", ergo(carry_real(node) != NULL,
-+                                 ZF_ISSET(carry_real(node), JNODE_ORPHAN)));
-+
++      assert("nikita-1619", ergo(reiser4_carry_real(node) != NULL,
++                                 ZF_ISSET(reiser4_carry_real(node),
++                                          JNODE_ORPHAN)));
 +      for (scan = node;;
 +           scan = list_entry(scan->header.level_linkage.prev, carry_node,
 +                             header.level_linkage)) {
 +              assert("nikita-1617", &kin->nodes != &scan->header.level_linkage);
 +              if ((scan->node != node->node) &&
 +                  !ZF_ISSET(scan->node, JNODE_ORPHAN)) {
-+                      assert("nikita-1618", carry_real(scan) != NULL);
++                      assert("nikita-1618", reiser4_carry_real(scan) != NULL);
 +                      break;
 +              }
 +      }
@@ -3190,13 +2879,13 @@ Index: linux-2.6.16/fs/reiser4/carry.c
 +      assert("nikita-2203", node != NULL);
 +
 +      for_all_nodes(level, scan, tmp_scan) {
-+              if (carry_real(scan) == node)
++              if (reiser4_carry_real(scan) == node)
 +                      return scan;
 +      }
 +      return NULL;
 +}
 +
-+znode *carry_real(const carry_node * node)
++znode *reiser4_carry_real(const carry_node * node)
 +{
 +      assert("nikita-3061", node != NULL);
 +
@@ -3235,12 +2924,12 @@ Index: linux-2.6.16/fs/reiser4/carry.c
 +      reference = insert_carry_node(doing, todo, node);
 +      assert("nikita-2997", reference != NULL);
 +
-+      return add_carry(todo, POOLO_BEFORE, reference);
++      return reiser4_add_carry(todo, POOLO_BEFORE, reference);
 +}
 +
-+/* like post_carry(), but designed to be called from node plugin methods.
-+   This function is different from post_carry() in that it finds proper place
-+   to insert node in the queue. */
++/* like reiser4_post_carry(), but designed to be called from node plugin methods.
++   This function is different from reiser4_post_carry() in that it finds proper
++   place to insert node in the queue. */
 +carry_op *node_post_carry(carry_plugin_info * info    /* carry parameters
 +                                                       * passed down to node
 +                                                       * plugin */ ,
@@ -3258,7 +2947,8 @@ Index: linux-2.6.16/fs/reiser4/carry.c
 +      assert("nikita-2208", info->todo != NULL);
 +
 +      if (info->doing == NULL)
-+              return post_carry(info->todo, op, node, apply_to_parent_p);
++              return reiser4_post_carry(info->todo, op, node,
++                                        apply_to_parent_p);
 +
 +      result = add_op(info->todo, POOLO_LAST, NULL);
 +      if (IS_ERR(result))
@@ -3376,8 +3066,8 @@ Index: linux-2.6.16/fs/reiser4/carry.c
 +              spot = NULL;
 +              /* update delimiting keys */
 +              for_all_nodes(level, node, tmp_node) {
-+                      if (carry_real(node) != spot) {
-+                              spot = carry_real(node);
++                      if (reiser4_carry_real(node) != spot) {
++                              spot = reiser4_carry_real(node);
 +                              sync_dkeys(spot);
 +                      }
 +              }
@@ -3390,9 +3080,10 @@ Index: linux-2.6.16/fs/reiser4/carry.c
 +      for_all_nodes_back(level, node, tmp_node) {
 +              /* all allocated nodes should be already linked to their
 +                 parents at this moment. */
-+              assert("nikita-1631", ergo(!failure, !ZF_ISSET(carry_real(node),
-+                                                             JNODE_ORPHAN)));
-+              ON_DEBUG(check_dkeys(carry_real(node)));
++              assert("nikita-1631",
++                     ergo(!failure, !ZF_ISSET(reiser4_carry_real(node),
++                                              JNODE_ORPHAN)));
++              ON_DEBUG(check_dkeys(reiser4_carry_real(node)));
 +              unlock_carry_node(level, node, failure);
 +      }
 +      level->new_root = NULL;
@@ -3433,7 +3124,7 @@ Index: linux-2.6.16/fs/reiser4/carry.c
 +int lock_carry_node_tail(carry_node * node /* node to complete locking of */ )
 +{
 +      assert("nikita-1052", node != NULL);
-+      assert("nikita-1187", carry_real(node) != NULL);
++      assert("nikita-1187", reiser4_carry_real(node) != NULL);
 +      assert("nikita-1188", !node->unlock);
 +
 +      node->unlock = 1;
@@ -3445,7 +3136,7 @@ Index: linux-2.6.16/fs/reiser4/carry.c
 +
 +         Corresponding zrelse() is in unlock_carry_node()
 +       */
-+      return zload(carry_real(node));
++      return zload(reiser4_carry_real(node));
 +}
 +
 +/* lock carry node
@@ -3581,7 +3272,7 @@ Index: linux-2.6.16/fs/reiser4/carry.c
 +
 +      assert("nikita-884", node != NULL);
 +
-+      real_node = carry_real(node);
++      real_node = reiser4_carry_real(node);
 +      /* pair to zload() in lock_carry_node_tail() */
 +      zrelse(real_node);
 +      if (node->unlock && (real_node != NULL)) {
@@ -3664,7 +3355,7 @@ Index: linux-2.6.16/fs/reiser4/carry.c
 +
 +   This function itself only manages changes in carry structures and delegates
 +   all hard work (allocation of znode for new root, changes of parent and
-+   sibling pointers to the add_tree_root().
++   sibling pointers to the reiser4_add_tree_root().
 +
 +   Locking: old tree root is locked by carry at this point. Fake znode is also
 +   locked.
@@ -3690,7 +3381,7 @@ Index: linux-2.6.16/fs/reiser4/carry.c
 +         tree root right now.
 +       */
 +      if (level->new_root == NULL)
-+              level->new_root = add_tree_root(node->node, fake);
++              level->new_root = reiser4_add_tree_root(node->node, fake);
 +      if (!IS_ERR(level->new_root)) {
 +              assert("nikita-1210", znode_is_root(level->new_root));
 +              node->deallocate = 1;
@@ -3712,7 +3403,7 @@ Index: linux-2.6.16/fs/reiser4/carry.c
 +   Allocate new znode, add it into carry queue and post into @todo queue
 +   request to add pointer to new node into its parent.
 +
-+   This is carry related routing that calls new_node() to allocate new
++   This is carry related routing that calls reiser4_new_node() to allocate new
 +   node.
 +*/
 +carry_node *add_new_znode(znode * brother     /* existing left neighbor of new
@@ -3745,14 +3436,15 @@ Index: linux-2.6.16/fs/reiser4/carry.c
 +
 +       */
 +
-+      fresh = add_carry_skip(doing, ref ? POOLO_AFTER : POOLO_LAST, ref);
++      fresh = reiser4_add_carry_skip(doing,
++                                     ref ? POOLO_AFTER : POOLO_LAST, ref);
 +      if (IS_ERR(fresh))
 +              return fresh;
 +
 +      fresh->deallocate = 1;
 +      fresh->free = 1;
 +
-+      new_znode = new_node(brother, znode_get_level(brother));
++      new_znode = reiser4_new_node(brother, znode_get_level(brother));
 +      if (IS_ERR(new_znode))
 +              /* @fresh will be deallocated automatically by error
 +                 handling code in the caller. */
@@ -3764,14 +3456,15 @@ Index: linux-2.6.16/fs/reiser4/carry.c
 +      ZF_SET(new_znode, JNODE_ORPHAN);
 +      fresh->node = new_znode;
 +
-+      while (ZF_ISSET(carry_real(ref), JNODE_ORPHAN)) {
++      while (ZF_ISSET(reiser4_carry_real(ref), JNODE_ORPHAN)) {
 +              ref = carry_node_prev(ref);
 +              assert("nikita-1606", !carry_node_end(doing, ref));
 +      }
 +
 +      info.todo = todo;
 +      info.doing = doing;
-+      add_pointer = node_post_carry(&info, COP_INSERT, carry_real(ref), 1);
++      add_pointer = node_post_carry(&info, COP_INSERT,
++                                    reiser4_carry_real(ref), 1);
 +      if (IS_ERR(add_pointer)) {
 +              /* no need to deallocate @new_znode here: it will be
 +                 deallocated during carry error handling. */
@@ -3822,8 +3515,8 @@ Index: linux-2.6.16/fs/reiser4/carry.c
 +                              right = node->node;
 +                              left = carry_node_prev(node)->node;
 +                      } else {
-+                              right = carry_real(node);
-+                              left = carry_real(carry_node_prev(node));
++                              right = reiser4_carry_real(node);
++                              left = reiser4_carry_real(carry_node_prev(node));
 +                      }
 +                      if (right == NULL || left == NULL)
 +                              continue;
@@ -3903,7 +3596,8 @@ Index: linux-2.6.16/fs/reiser4/carry.c
 +      case COP_PASTE:
 +              print_coord("\tcoord",
 +                          op->u.insert.d ? op->u.insert.d->coord : NULL, 0);
-+              print_key("\tkey", op->u.insert.d ? op->u.insert.d->key : NULL);
++              reiser4_print_key("\tkey",
++                                op->u.insert.d ? op->u.insert.d->key : NULL);
 +              print_carry("\tchild", op->u.insert.child);
 +              break;
 +      case COP_DELETE:
@@ -3963,10 +3657,9 @@ Index: linux-2.6.16/fs/reiser4/carry.c
 +   scroll-step: 1
 +   End:
 +*/
-Index: linux-2.6.16/fs/reiser4/carry.h
-===================================================================
---- /dev/null
-+++ linux-2.6.16/fs/reiser4/carry.h
+diff -urN linux-2.6.22.orig/fs/reiser4/carry.h linux-2.6.22/fs/reiser4/carry.h
+--- linux-2.6.22.orig/fs/reiser4/carry.h       1970-01-01 03:00:00.000000000 +0300
++++ linux-2.6.22/fs/reiser4/carry.h    2007-07-29 00:25:34.824683017 +0400
 @@ -0,0 +1,442 @@
 +/* Copyright 2001, 2002, 2003 by Hans Reiser, licensing governed by reiser4/README */
 +
@@ -3997,7 +3690,7 @@ Index: linux-2.6.16/fs/reiser4/carry.h
 +*/
 +typedef struct carry_node {
 +      /* pool linkage */
-+      reiser4_pool_header header;
++      struct reiser4_pool_header header;
 +
 +      /* base node from which real_node is calculated. See
 +         fs/reiser4/carry.c:lock_carry_node(). */
@@ -4183,7 +3876,7 @@ Index: linux-2.6.16/fs/reiser4/carry.h
 +*/
 +typedef struct carry_op {
 +      /* pool linkage */
-+      reiser4_pool_header header;
++      struct reiser4_pool_header header;
 +      carry_opcode op;
 +      /* node on which operation is to be performed:
 +
@@ -4257,9 +3950,9 @@ Index: linux-2.6.16/fs/reiser4/carry.h
 +/* &carry_op_pool - preallocated pool of carry operations, and nodes */
 +typedef struct carry_pool {
 +      carry_op op[CARRIES_POOL_SIZE];
-+      reiser4_pool op_pool;
++      struct reiser4_pool op_pool;
 +      carry_node node[NODES_LOCKED_POOL_SIZE];
-+      reiser4_pool node_pool;
++      struct reiser4_pool node_pool;
 +} carry_pool;
 +
 +/* &carry_tree_level - carry process on given level
@@ -4282,8 +3975,8 @@ Index: linux-2.6.16/fs/reiser4/carry.h
 +      int nodes_num;
 +      /* new root created on this level, if any */
 +      znode *new_root;
-+      /* This is set by caller (insert_by_key(), resize_item(), etc.) when
-+         they want ->tracked to automagically wander to the node where
++      /* This is set by caller (insert_by_key(), rreiser4_esize_item(), etc.)
++         when they want ->tracked to automagically wander to the node where
 +         insertion point moved after insert or paste.
 +       */
 +      carry_track_type track_type;
@@ -4299,12 +3992,12 @@ Index: linux-2.6.16/fs/reiser4/carry.h
 +      carry_level *todo;
 +};
 +
-+int carry(carry_level * doing, carry_level * done);
++int reiser4_carry(carry_level * doing, carry_level * done);
 +
-+carry_node *add_carry(carry_level * level, pool_ordering order,
-+                    carry_node * reference);
-+carry_node *add_carry_skip(carry_level * level, pool_ordering order,
-+                         carry_node * reference);
++carry_node *reiser4_add_carry(carry_level * level, pool_ordering order,
++                            carry_node * reference);
++carry_node *reiser4_add_carry_skip(carry_level * level, pool_ordering order,
++                                 carry_node * reference);
 +
 +extern carry_node *insert_carry_node(carry_level * doing,
 +                                   carry_level * todo, const znode * node);
@@ -4314,8 +4007,8 @@ Index: linux-2.6.16/fs/reiser4/carry.h
 +
 +extern void init_carry_level(carry_level * level, carry_pool * pool);
 +
-+extern carry_op *post_carry(carry_level * level, carry_opcode op, znode * node,
-+                          int apply_to_parent);
++extern carry_op *reiser4_post_carry(carry_level * level, carry_opcode op,
++                                  znode * node, int apply_to_parent);
 +extern carry_op *node_post_carry(carry_plugin_info * info, carry_opcode op,
 +                               znode * node, int apply_to_parent_p);
 +
@@ -4324,7 +4017,7 @@ Index: linux-2.6.16/fs/reiser4/carry.h
 +
 +carry_node *find_carry_node(carry_level * level, const znode * node);
 +
-+extern znode *carry_real(const carry_node * node);
++extern znode *reiser4_carry_real(const carry_node * node);
 +
 +/* helper macros to iterate over carry queues */
 +
@@ -4410,11 +4103,10 @@ Index: linux-2.6.16/fs/reiser4/carry.h
 +   scroll-step: 1
 +   End:
 +*/
-Index: linux-2.6.16/fs/reiser4/carry_ops.c
-===================================================================
---- /dev/null
-+++ linux-2.6.16/fs/reiser4/carry_ops.c
-@@ -0,0 +1,2103 @@
+diff -urN linux-2.6.22.orig/fs/reiser4/carry_ops.c linux-2.6.22/fs/reiser4/carry_ops.c
+--- linux-2.6.22.orig/fs/reiser4/carry_ops.c   1970-01-01 03:00:00.000000000 +0300
++++ linux-2.6.22/fs/reiser4/carry_ops.c        2007-07-29 00:25:34.828684053 +0400
+@@ -0,0 +1,2131 @@
 +/* Copyright 2001, 2002, 2003 by Hans Reiser, licensing governed by reiser4/README */
 +
 +/* implementation of carry operations */
@@ -4468,10 +4160,11 @@ Index: linux-2.6.16/fs/reiser4/carry_ops.c
 +      tree = current_tree;
 +      read_lock_tree(tree);
 +      /* first, check whether left neighbor is already in a @doing queue */
-+      if (carry_real(node)->left != NULL) {
++      if (reiser4_carry_real(node)->left != NULL) {
 +              /* NOTE: there is locking subtlety here. Look into
 +               * find_right_neighbor() for more info */
-+              if (find_carry_node(doing, carry_real(node)->left) != NULL) {
++              if (find_carry_node(doing,
++                                  reiser4_carry_real(node)->left) != NULL) {
 +                      read_unlock_tree(tree);
 +                      left = node;
 +                      do {
@@ -4479,13 +4172,14 @@ Index: linux-2.6.16/fs/reiser4/carry_ops.c
 +                                                carry_node, header.level_linkage);
 +                              assert("nikita-3408", !carry_node_end(doing,
 +                                                                    left));
-+                      } while (carry_real(left) == carry_real(node));
++                      } while (reiser4_carry_real(left) ==
++                               reiser4_carry_real(node));
 +                      return left;
 +              }
 +      }
 +      read_unlock_tree(tree);
 +
-+      left = add_carry_skip(doing, POOLO_BEFORE, node);
++      left = reiser4_add_carry_skip(doing, POOLO_BEFORE, node);
 +      if (IS_ERR(left))
 +              return left;
 +
@@ -4497,7 +4191,8 @@ Index: linux-2.6.16/fs/reiser4/carry_ops.c
 +              flags |= GN_NO_ALLOC;
 +
 +      /* then, feeling lucky, peek left neighbor in the cache. */
-+      result = reiser4_get_left_neighbor(&left->lock_handle, carry_real(node),
++      result = reiser4_get_left_neighbor(&left->lock_handle,
++                                         reiser4_carry_real(node),
 +                                         ZNODE_WRITE_LOCK, flags);
 +      if (result == 0) {
 +              /* ok, node found and locked. */
@@ -4550,7 +4245,7 @@ Index: linux-2.6.16/fs/reiser4/carry_ops.c
 +      tree = current_tree;
 +      read_lock_tree(tree);
 +      /* first, check whether right neighbor is already in a @doing queue */
-+      if (carry_real(node)->right != NULL) {
++      if (reiser4_carry_real(node)->right != NULL) {
 +              /*
 +               * Tree lock is taken here anyway, because, even if _outcome_
 +               * of (find_carry_node() != NULL) doesn't depends on
@@ -4571,7 +4266,8 @@ Index: linux-2.6.16/fs/reiser4/carry_ops.c
 +               * couldn't change, because node cannot be inserted between
 +               * locked neighbors.
 +               */
-+              if (find_carry_node(doing, carry_real(node)->right) != NULL) {
++              if (find_carry_node(doing,
++                                  reiser4_carry_real(node)->right) != NULL) {
 +                      read_unlock_tree(tree);
 +                      /*
 +                       * What we are doing here (this is also applicable to
@@ -4607,7 +4303,8 @@ Index: linux-2.6.16/fs/reiser4/carry_ops.c
 +                                                 carry_node, header.level_linkage);
 +                              assert("nikita-3408", !carry_node_end(doing,
 +                                                                    right));
-+                      } while (carry_real(right) == carry_real(node));
++                      } while (reiser4_carry_real(right) ==
++                               reiser4_carry_real(node));
 +                      return right;
 +              }
 +      }
@@ -4619,11 +4316,12 @@ Index: linux-2.6.16/fs/reiser4/carry_ops.c
 +
 +      /* then, try to lock right neighbor */
 +      init_lh(&lh);
-+      result = reiser4_get_right_neighbor(&lh, carry_real(node),
++      result = reiser4_get_right_neighbor(&lh,
++                                          reiser4_carry_real(node),
 +                                          ZNODE_WRITE_LOCK, flags);
 +      if (result == 0) {
 +              /* ok, node found and locked. */
-+              right = add_carry_skip(doing, POOLO_AFTER, node);
++              right = reiser4_add_carry_skip(doing, POOLO_AFTER, node);
 +              if (!IS_ERR(right)) {
 +                      right->node = lh.node;
 +                      move_lh(&right->lock_handle, &lh);
@@ -4718,11 +4416,11 @@ Index: linux-2.6.16/fs/reiser4/carry_ops.c
 +      assert("nikita-941", op != NULL);
 +      assert("nikita-942", op->op == COP_INSERT);
 +
-+      node = carry_real(op->node);
++      node = reiser4_carry_real(op->node);
 +      assert("nikita-943", node != NULL);
 +      assert("nikita-944", node_plugin_by_node(node) != NULL);
 +
-+      child = carry_real(op->u.insert.child);
++      child = reiser4_carry_real(op->u.insert.child);
 +      result =
 +          find_new_child_ptr(node, child, op->u.insert.brother,
 +                             op->u.insert.d->coord);
@@ -4765,12 +4463,13 @@ Index: linux-2.6.16/fs/reiser4/carry_ops.c
 +      insertion_node = op->u.insert.d->coord->node;
 +      /* if insertion point was actually moved into new node,
 +         update carry node pointer in operation. */
-+      if (insertion_node != carry_real(op->node)) {
++      if (insertion_node != reiser4_carry_real(op->node)) {
 +              op->node = target;
-+              assert("nikita-2540", carry_real(target) == insertion_node);
++              assert("nikita-2540",
++                     reiser4_carry_real(target) == insertion_node);
 +      }
 +      assert("nikita-2541",
-+             carry_real(op->node) == op->u.insert.d->coord->node);
++             reiser4_carry_real(op->node) == op->u.insert.d->coord->node);
 +      return insertion_node;
 +}
 +
@@ -4833,7 +4532,7 @@ Index: linux-2.6.16/fs/reiser4/carry_ops.c
 +             op->op == COP_INSERT ||
 +             op->op == COP_PASTE || op->op == COP_EXTENT);
 +      assert("nikita-1607",
-+             carry_real(op->node) == op->u.insert.d->coord->node);
++             reiser4_carry_real(op->node) == op->u.insert.d->coord->node);
 +
 +      flags = op->u.insert.flags;
 +
@@ -4886,7 +4585,8 @@ Index: linux-2.6.16/fs/reiser4/carry_ops.c
 +                      /* shift everything possible on the left of and
 +                         including insertion coord into the left neighbor */
 +                      result = carry_shift_data(LEFT_SIDE, coord,
-+                                                carry_real(left), doing, todo,
++                                                reiser4_carry_real(left),
++                                                doing, todo,
 +                                                flags & COPI_GO_LEFT);
 +
 +                      /* reget node from coord: shift_left() might move
@@ -4918,7 +4618,7 @@ Index: linux-2.6.16/fs/reiser4/carry_ops.c
 +                         excluding insertion coord into the right neighbor
 +                       */
 +                      result = carry_shift_data(RIGHT_SIDE, coord,
-+                                                carry_real(right),
++                                                reiser4_carry_real(right),
 +                                                doing, todo,
 +                                                flags & COPI_GO_RIGHT);
 +                      /* reget node from coord: shift_right() might move
@@ -4963,7 +4663,7 @@ Index: linux-2.6.16/fs/reiser4/carry_ops.c
 +
 +              /* Try to shift into new node. */
 +              result = lock_carry_node(doing, fresh);
-+              zput(carry_real(fresh));
++              zput(reiser4_carry_real(fresh));
 +              if (result != 0) {
 +                      warning("nikita-947",
 +                              "Cannot lock new node: %i", result);
@@ -4986,7 +4686,26 @@ Index: linux-2.6.16/fs/reiser4/carry_ops.c
 +                  (blk_alloc > 0) ||
 +                  coord_is_after_rightmost(op->u.insert.d->coord);
 +
-+              result = carry_shift_data(RIGHT_SIDE, coord, carry_real(fresh),
++              if (gointo &&
++                  op->op == COP_PASTE &&
++                  coord_is_existing_item(op->u.insert.d->coord) &&
++                  is_solid_item((item_plugin_by_coord(op->u.insert.d->coord)))) {
++                      /* paste into solid (atomic) item, which can contain
++                         only one unit, so we need to shift it right, where
++                         insertion point supposed to be */
++
++                      assert("edward-1444", op->u.insert.d->data->iplug ==
++                             item_plugin_by_id(STATIC_STAT_DATA_ID));
++                      assert("edward-1445",
++                             op->u.insert.d->data->length >
++                             node_plugin_by_node(coord->node)->free_space
++                             (coord->node));
++
++                      op->u.insert.d->coord->between = BEFORE_UNIT;
++              }
++
++              result = carry_shift_data(RIGHT_SIDE, coord,
++                                        reiser4_carry_real(fresh),
 +                                        doing, todo, gointo);
 +              /* if insertion point was actually moved into new node,
 +                 update carry node pointer in operation. */
@@ -5018,7 +4737,7 @@ Index: linux-2.6.16/fs/reiser4/carry_ops.c
 +              result = -E_NODE_FULL;
 +      }
 +      assert("nikita-1622", ergo(result == 0,
-+                                 carry_real(op->node) == coord->node));
++                                reiser4_carry_real(op->node) == coord->node));
 +      assert("nikita-2616", coord == op->u.insert.d->coord);
 +      if (result == 0)
 +              result = make_space_tail(op, doing, orig_node);
@@ -5105,7 +4824,7 @@ Index: linux-2.6.16/fs/reiser4/carry_ops.c
 +              /* NOTE-NIKITA Lookup bias is fixed to FIND_EXACT. Complain
 +                 if you need something else. */
 +              op->u.insert.d->coord = coord;
-+              node = carry_real(op->node);
++              node = reiser4_carry_real(op->node);
 +              intra_node = node_plugin_by_node(node)->lookup
 +                  (node, op->u.insert.d->key, FIND_EXACT,
 +                   op->u.insert.d->coord);
@@ -5125,9 +4844,9 @@ Index: linux-2.6.16/fs/reiser4/carry_ops.c
 +              op->u.insert.d = cdata;
 +              op->u.insert.d->coord = coord;
 +              op->u.insert.d->data = data;
-+              op->u.insert.d->coord->node = carry_real(op->node);
++              op->u.insert.d->coord->node = reiser4_carry_real(op->node);
 +              result = find_new_child_coord(op);
-+              child = carry_real(op->u.insert.child);
++              child = reiser4_carry_real(op->u.insert.child);
 +              if (result != NS_NOT_FOUND) {
 +                      warning("nikita-993",
 +                              "Cannot find a place for child pointer: %i",
@@ -5158,7 +4877,8 @@ Index: linux-2.6.16/fs/reiser4/carry_ops.c
 +                 moved into another node. Handle this by creating new carry
 +                 node for insertion point if necessary.
 +               */
-+              if (carry_real(op->node) != op->u.insert.d->coord->node) {
++              if (reiser4_carry_real(op->node) !=
++                  op->u.insert.d->coord->node) {
 +                      pool_ordering direction;
 +                      znode *z1;
 +                      znode *z2;
@@ -5170,7 +4890,7 @@ Index: linux-2.6.16/fs/reiser4/carry_ops.c
 +                       * moved. Do this by comparing delimiting keys.
 +                       */
 +                      z1 = op->u.insert.d->coord->node;
-+                      z2 = carry_real(op->node);
++                      z2 = reiser4_carry_real(op->node);
 +                      if (keyle(leftmost_key_in_node(z1, &k1),
 +                                leftmost_key_in_node(z2, &k2)))
 +                              /* insertion point moved to the left */
@@ -5179,7 +4899,8 @@ Index: linux-2.6.16/fs/reiser4/carry_ops.c
 +                              /* insertion point moved to the right */
 +                              direction = POOLO_AFTER;
 +
-+                      op->node = add_carry_skip(doing, direction, op->node);
++                      op->node = reiser4_add_carry_skip(doing,
++                                                        direction, op->node);
 +                      if (IS_ERR(op->node))
 +                              return PTR_ERR(op->node);
 +                      op->node->node = op->u.insert.d->coord->node;
@@ -5201,7 +4922,7 @@ Index: linux-2.6.16/fs/reiser4/carry_ops.c
 +              op->u.insert.d->data->arg = op->u.insert.brother;
 +      } else {
 +              assert("vs-243", op->u.insert.d->coord != NULL);
-+              op->u.insert.d->coord->node = carry_real(op->node);
++              op->u.insert.d->coord->node = reiser4_carry_real(op->node);
 +      }
 +
 +      /* find free space. */
@@ -5359,9 +5080,10 @@ Index: linux-2.6.16/fs/reiser4/carry_ops.c
 +      orig = flow_insert_point(op)->node;
 +      /* try to shift content of node @orig from its head upto insert point
 +         including insertion point into the left neighbor */
-+      carry_shift_data(LEFT_SIDE, flow_insert_point(op), carry_real(left), doing, todo, 1     /* including insert
-+                                                                                               * point */ );
-+      if (carry_real(left) != flow_insert_point(op)->node) {
++      carry_shift_data(LEFT_SIDE, flow_insert_point(op),
++                       reiser4_carry_real(left), doing, todo,
++                       1 /* including insert point */);
++      if (reiser4_carry_real(left) != flow_insert_point(op)->node) {
 +              /* insertion point did not move */
 +              return 1;
 +      }
@@ -5400,10 +5122,9 @@ Index: linux-2.6.16/fs/reiser4/carry_ops.c
 +      if (right) {
 +              /* shift everything possible on the right of but excluding
 +                 insertion coord into the right neighbor */
-+              carry_shift_data(RIGHT_SIDE, flow_insert_point(op), carry_real(right), doing, todo, 0   /* not
-+                                                                                                       * including
-+                                                                                                       * insert
-+                                                                                                       * point */ );
++              carry_shift_data(RIGHT_SIDE, flow_insert_point(op),
++                               reiser4_carry_real(right), doing, todo,
++                               0 /* not including insert point */);
 +      } else {
 +              /* right neighbor either does not exist or is unformatted
 +                 node */
@@ -5440,17 +5161,15 @@ Index: linux-2.6.16/fs/reiser4/carry_ops.c
 +              return PTR_ERR(new);
 +      }
 +      result = lock_carry_node(doing, new);
-+      zput(carry_real(new));
++      zput(reiser4_carry_real(new));
 +      if (unlikely(result)) {
 +              return result;
 +      }
 +      op->u.insert_flow.new_nodes++;
 +      if (!coord_is_after_rightmost(flow_insert_point(op))) {
-+              carry_shift_data(RIGHT_SIDE, flow_insert_point(op), carry_real(new), doing, todo, 0     /* not
-+                                                                                                       * including
-+                                                                                                       * insert
-+                                                                                                       * point */ );
-+
++              carry_shift_data(RIGHT_SIDE, flow_insert_point(op),
++                               reiser4_carry_real(new), doing, todo,
++                               0 /* not including insert point */);
 +              assert("vs-901",
 +                     coord_is_after_rightmost(flow_insert_point(op)));
 +
@@ -5466,7 +5185,7 @@ Index: linux-2.6.16/fs/reiser4/carry_ops.c
 +                      return PTR_ERR(new);
 +              }
 +              result = lock_carry_node(doing, new);
-+              zput(carry_real(new));
++              zput(reiser4_carry_real(new));
 +              if (unlikely(result)) {
 +                      return result;
 +              }
@@ -5474,7 +5193,8 @@ Index: linux-2.6.16/fs/reiser4/carry_ops.c
 +      }
 +
 +      /* move insertion point to new node */
-+      coord_init_before_first_item(flow_insert_point(op), carry_real(new));
++      coord_init_before_first_item(flow_insert_point(op),
++                                   reiser4_carry_real(new));
 +      op->node = new;
 +      return 0;
 +}
@@ -5643,9 +5363,9 @@ Index: linux-2.6.16/fs/reiser4/carry_ops.c
 +      coord_init_zero(&coord);
 +      coord_init_zero(&coord2);
 +
-+      parent = carry_real(op->node);
++      parent = reiser4_carry_real(op->node);
 +      child = op->u.delete.child ?
-+          carry_real(op->u.delete.child) : op->node->node;
++              reiser4_carry_real(op->u.delete.child) : op->node->node;
 +      tree = znode_get_tree(child);
 +      read_lock_tree(tree);
 +
@@ -5675,8 +5395,8 @@ Index: linux-2.6.16/fs/reiser4/carry_ops.c
 +          node_num_items(parent) == 1) {
 +              /* Delimiting key manipulations. */
 +              write_lock_dk(tree);
-+              znode_set_ld_key(child, znode_set_ld_key(parent, min_key()));
-+              znode_set_rd_key(child, znode_set_rd_key(parent, max_key()));
++              znode_set_ld_key(child, znode_set_ld_key(parent, reiser4_min_key()));
++              znode_set_rd_key(child, znode_set_rd_key(parent, reiser4_max_key()));
 +              ZF_SET(child, JNODE_DKSET);
 +              write_unlock_dk(tree);
 +
@@ -5725,7 +5445,7 @@ Index: linux-2.6.16/fs/reiser4/carry_ops.c
 +          /* don't kill roots at and lower than twig level */
 +          znode_get_level(parent) > REISER4_MIN_TREE_HEIGHT &&
 +          node_num_items(parent) == 1) {
-+              result = kill_tree_root(coord.node);
++              result = reiser4_kill_tree_root(coord.node);
 +      }
 +
 +      return result < 0 ? : 0;
@@ -5751,7 +5471,7 @@ Index: linux-2.6.16/fs/reiser4/carry_ops.c
 +      info.doing = doing;
 +      info.todo = todo;
 +
-+      nplug = node_plugin_by_node(carry_real(op->node));
++      nplug = node_plugin_by_node(reiser4_carry_real(op->node));
 +      if (op->u.cut_or_kill.is_cut)
 +              result = nplug->cut(op->u.cut_or_kill.u.cut, &info);
 +      else
@@ -6177,7 +5897,7 @@ Index: linux-2.6.16/fs/reiser4/carry_ops.c
 +      if (lchild != NULL) {
 +              assert("nikita-1001", lchild->parent);
 +              assert("nikita-1003", !lchild->left);
-+              left = carry_real(lchild);
++              left = reiser4_carry_real(lchild);
 +      } else
 +              left = NULL;
 +
@@ -6317,7 +6037,7 @@ Index: linux-2.6.16/fs/reiser4/carry_ops.c
 +              if (carry_node_end(level, neighbor))
 +                      /* list head is reached */
 +                      return NULL;
-+              if (carry_real(neighbor) != carry_real(node))
++              if (reiser4_carry_real(neighbor) != reiser4_carry_real(node))
 +                      return neighbor;
 +      }
 +}
@@ -6518,10 +6238,9 @@ Index: linux-2.6.16/fs/reiser4/carry_ops.c
 +   scroll-step: 1
 +   End:
 +*/
-Index: linux-2.6.16/fs/reiser4/carry_ops.h
-===================================================================
---- /dev/null
-+++ linux-2.6.16/fs/reiser4/carry_ops.h
+diff -urN linux-2.6.22.orig/fs/reiser4/carry_ops.h linux-2.6.22/fs/reiser4/carry_ops.h
+--- linux-2.6.22.orig/fs/reiser4/carry_ops.h   1970-01-01 03:00:00.000000000 +0300
++++ linux-2.6.22/fs/reiser4/carry_ops.h        2007-07-29 00:25:34.828684053 +0400
 @@ -0,0 +1,42 @@
 +/* Copyright 2001, 2002, 2003 by Hans Reiser, licensing governed by reiser4/README */
 +
@@ -6565,11 +6284,10 @@ Index: linux-2.6.16/fs/reiser4/carry_ops.h
 +   scroll-step: 1
 +   End:
 +*/
-Index: linux-2.6.16/fs/reiser4/context.c
-===================================================================
---- /dev/null
-+++ linux-2.6.16/fs/reiser4/context.c
-@@ -0,0 +1,278 @@
+diff -urN linux-2.6.22.orig/fs/reiser4/context.c linux-2.6.22/fs/reiser4/context.c
+--- linux-2.6.22.orig/fs/reiser4/context.c     1970-01-01 03:00:00.000000000 +0300
++++ linux-2.6.22/fs/reiser4/context.c  2007-07-29 00:25:34.832685088 +0400
+@@ -0,0 +1,288 @@
 +/* Copyright 2002, 2003 by Hans Reiser, licensing governed by reiser4/README */
 +
 +/* Manipulation of reiser4_context */
@@ -6591,8 +6309,9 @@ Index: linux-2.6.16/fs/reiser4/context.c
 + *
 + * In such situations "child" context acts like dummy: all activity is
 + * actually performed in the top level context, and get_current_context()
-+ * always returns top level context. Of course, init_context()/done_context()
-+ * have to be properly nested any way.
++ * always returns top level context.
++ * Of course, reiser4_init_context()/reiser4_done_context() have to be properly
++ * nested any way.
 + *
 + * Note that there is an important difference between reiser4 uses
 + * ->fs_context and the way other file systems use it. Other file systems
@@ -6612,8 +6331,8 @@ Index: linux-2.6.16/fs/reiser4/context.c
 +#include <linux/writeback.h>  /* balance_dirty_pages() */
 +#include <linux/hardirq.h>
 +
-+
-+static void _init_context(reiser4_context * context, struct super_block *super)
++static void _reiser4_init_context(reiser4_context * context,
++                                struct super_block *super)
 +{
 +      memset(context, 0, sizeof(*context));
 +
@@ -6626,7 +6345,7 @@ Index: linux-2.6.16/fs/reiser4/context.c
 +
 +      init_lock_stack(&context->stack);
 +
-+      txn_begin(context);
++      reiser4_txn_begin(context);
 +
 +      /* initialize head of tap list */
 +      INIT_LIST_HEAD(&context->taps);
@@ -6641,8 +6360,7 @@ Index: linux-2.6.16/fs/reiser4/context.c
 +   This function should be called at the beginning of reiser4 part of
 +   syscall.
 +*/
-+reiser4_context *init_context(struct super_block *super       /* super block we are going to
-+                                                       * work with */ )
++reiser4_context * reiser4_init_context(struct super_block * super)
 +{
 +      reiser4_context *context;
 +
@@ -6661,7 +6379,7 @@ Index: linux-2.6.16/fs/reiser4/context.c
 +      if (context == NULL)
 +              return ERR_PTR(RETERR(-ENOMEM));
 +
-+      _init_context(context, super);
++      _reiser4_init_context(context, super);
 +      return context;
 +}
 +
@@ -6674,7 +6392,7 @@ Index: linux-2.6.16/fs/reiser4/context.c
 +      assert("nikita-3358", super->s_op == NULL || is_reiser4_super(super));
 +      assert("vs-12", !is_in_reiser4_context());
 +
-+      _init_context(context, super);
++      _reiser4_init_context(context, super);
 +      context->on_stack = 1;
 +      return;
 +}
@@ -6737,7 +6455,7 @@ Index: linux-2.6.16/fs/reiser4/context.c
 +   thread released all locks and closed transcrash etc.
 +
 +*/
-+static void done_context(reiser4_context * context /* context being released */ )
++static void reiser4_done_context(reiser4_context * context /* context being released */ )
 +{
 +      assert("nikita-860", context != NULL);
 +      assert("nikita-859", context->magic == context_magic);
@@ -6749,10 +6467,10 @@ Index: linux-2.6.16/fs/reiser4/context.c
 +      if (context->nr_children == 0) {
 +              assert("jmacd-673", context->trans == NULL);
 +              assert("jmacd-1002", lock_stack_isclean(&context->stack));
-+              assert("nikita-1936", no_counters_are_held());
-+              assert("nikita-2626", list_empty_careful(taps_list()));
++              assert("nikita-1936", reiser4_no_counters_are_held());
++              assert("nikita-2626", list_empty_careful(reiser4_taps_list()));
 +              assert("zam-1004", ergo(get_super_private(context->super),
-+                                      get_super_private(context->super)->delete_sema_owner !=
++                                      get_super_private(context->super)->delete_mutex_owner !=
 +                                      current));
 +
 +              /* release all grabbed but as yet unused blocks */
@@ -6794,11 +6512,11 @@ Index: linux-2.6.16/fs/reiser4/context.c
 + */
 +void reiser4_exit_context(reiser4_context * context)
 +{
-+      assert("nikita-3021", schedulable());
++      assert("nikita-3021", reiser4_schedulable());
 +
 +      if (context->nr_children == 0) {
 +              if (!context->nobalance) {
-+                      txn_restart(context);
++                      reiser4_txn_restart(context);
 +                      balance_dirty_pages_at(context);
 +              }
 +
@@ -6820,12 +6538,12 @@ Index: linux-2.6.16/fs/reiser4/context.c
 +                              spin_unlock_atom(atom);
 +                      }
 +              }
-+              txn_end(context);
++              reiser4_txn_end(context);
 +      }
-+      done_context(context);
++      reiser4_done_context(context);
 +}
 +
-+void set_gfp_mask(void)
++void reiser4_ctx_gfp_mask_set(void)
 +{
 +      reiser4_context *ctx;
 +
@@ -6838,6 +6556,16 @@ Index: linux-2.6.16/fs/reiser4/context.c
 +              ctx->gfp_mask = GFP_NOFS;
 +}
 +
++void reiser4_ctx_gfp_mask_force (gfp_t mask)
++{
++      reiser4_context *ctx;
++      ctx = get_current_context();
++
++      assert("edward-1454", ctx != NULL);
++
++      ctx->gfp_mask = mask;
++}
++
 +/*
 + * Local variables:
 + * c-indentation-style: "K&R"
@@ -6848,10 +6576,9 @@ Index: linux-2.6.16/fs/reiser4/context.c
 + * scroll-step: 1
 + * End:
 + */
-Index: linux-2.6.16/fs/reiser4/context.h
-===================================================================
---- /dev/null
-+++ linux-2.6.16/fs/reiser4/context.h
+diff -urN linux-2.6.22.orig/fs/reiser4/context.h linux-2.6.22/fs/reiser4/context.h
+--- linux-2.6.22.orig/fs/reiser4/context.h     1970-01-01 03:00:00.000000000 +0300
++++ linux-2.6.22/fs/reiser4/context.h  2007-07-29 00:25:34.832685088 +0400
 @@ -0,0 +1,228 @@
 +/* Copyright 2001, 2002, 2003, 2004 by Hans Reiser, licensing governed by
 + * reiser4/README */
@@ -6872,7 +6599,6 @@ Index: linux-2.6.16/fs/reiser4/context.h
 +#include <linux/spinlock.h>
 +#include <linux/sched.h>      /* for struct task_struct */
 +
-+
 +/* reiser4 per-thread context */
 +struct reiser4_context {
 +      /* magic constant. For identification of reiser4 contexts. */
@@ -6915,7 +6641,7 @@ Index: linux-2.6.16/fs/reiser4/context.h
 +       * ->i_mutex */
 +      unsigned int nobalance:1;
 +
-+      /* this bit is used on done_context to decide whether context is
++      /* this bit is used on reiser4_done_context to decide whether context is
 +         kmalloc-ed and has to be kfree-ed */
 +      unsigned int on_stack:1;
 +
@@ -6932,7 +6658,7 @@ Index: linux-2.6.16/fs/reiser4/context.h
 +#if REISER4_DEBUG
 +      /* debugging information about reiser4 locks held by the current
 +       * thread */
-+      lock_counters_info locks;
++      reiser4_lock_cnt_info locks;
 +      struct task_struct *task;       /* so we can easily find owner of the stack */
 +
 +      /*
@@ -6962,7 +6688,7 @@ Index: linux-2.6.16/fs/reiser4/context.h
 +#define current_blocksize reiser4_get_current_sb()->s_blocksize
 +#define current_blocksize_bits reiser4_get_current_sb()->s_blocksize_bits
 +
-+extern reiser4_context *init_context(struct super_block *);
++extern reiser4_context *reiser4_init_context(struct super_block *);
 +extern void init_stack_context(reiser4_context *, struct super_block *);
 +extern void reiser4_exit_context(reiser4_context *);
 +
@@ -7001,7 +6727,7 @@ Index: linux-2.6.16/fs/reiser4/context.h
 +      return get_context(current);
 +}
 +
-+static inline gfp_t get_gfp_mask(void)
++static inline gfp_t reiser4_ctx_gfp_mask_get(void)
 +{
 +      reiser4_context *ctx;
 +
@@ -7009,7 +6735,8 @@ Index: linux-2.6.16/fs/reiser4/context.h
 +      return (ctx == NULL) ? GFP_KERNEL : ctx->gfp_mask;
 +}
 +
-+void set_gfp_mask(void);
++void reiser4_ctx_gfp_mask_set(void);
++void reiser4_ctx_gfp_mask_force (gfp_t mask);
 +
 +/*
 + * true if current thread is in the write-out mode. Thread enters write-out
@@ -7081,11 +6808,10 @@ Index: linux-2.6.16/fs/reiser4/context.h
 +   scroll-step: 1
 +   End:
 +*/
-Index: linux-2.6.16/fs/reiser4/coord.c
-===================================================================
---- /dev/null
-+++ linux-2.6.16/fs/reiser4/coord.c
-@@ -0,0 +1,937 @@
+diff -urN linux-2.6.22.orig/fs/reiser4/coord.c linux-2.6.22/fs/reiser4/coord.c
+--- linux-2.6.22.orig/fs/reiser4/coord.c       1970-01-01 03:00:00.000000000 +0300
++++ linux-2.6.22/fs/reiser4/coord.c    2007-07-29 00:25:34.832685088 +0400
+@@ -0,0 +1,935 @@
 +/* Copyright 2001, 2002, 2003 by Hans Reiser, licensing governed by reiser4/README */
 +
 +#include "forward.h"
@@ -7656,11 +7382,6 @@ Index: linux-2.6.16/fs/reiser4/coord.c
 +}
 +
 +#if REISER4_DEBUG
-+#define DEBUG_COORD_FIELDS (sizeof(c1->plug_v) + sizeof(c1->body_v))
-+#else
-+#define DEBUG_COORD_FIELDS (0)
-+#endif
-+
 +int coords_equal(const coord_t * c1, const coord_t * c2)
 +{
 +      assert("nikita-2840", c1 != NULL);
@@ -7671,6 +7392,7 @@ Index: linux-2.6.16/fs/reiser4/coord.c
 +          c1->item_pos == c2->item_pos &&
 +          c1->unit_pos == c2->unit_pos && c1->between == c2->between;
 +}
++#endif  /*  REISER4_DEBUG  */
 +
 +/* If coord_is_after_rightmost return NCOORD_ON_THE_RIGHT, if coord_is_after_leftmost
 +   return NCOORD_ON_THE_LEFT, otherwise return NCOORD_INSIDE. */
@@ -7771,6 +7493,7 @@ Index: linux-2.6.16/fs/reiser4/coord.c
 +      return 0;
 +}
 +
++#if REISER4_DEBUG
 +/* Returns true if the coordinates are positioned at adjacent units, regardless of
 +   before-after or item boundaries. */
 +int coord_are_neighbors(coord_t * c1, coord_t * c2)
@@ -7809,6 +7532,7 @@ Index: linux-2.6.16/fs/reiser4/coord.c
 +              return 0;
 +      }
 +}
++#endif  /*  REISER4_DEBUG  */
 +
 +/* Assuming two coordinates are positioned in the same node, return COORD_CMP_ON_RIGHT,
 +   COORD_CMP_ON_LEFT, or COORD_CMP_SAME depending on c1's position relative to c2.  */
@@ -8023,10 +7747,9 @@ Index: linux-2.6.16/fs/reiser4/coord.c
 +   scroll-step: 1
 +   End:
 +*/
-Index: linux-2.6.16/fs/reiser4/coord.h
-===================================================================
---- /dev/null
-+++ linux-2.6.16/fs/reiser4/coord.h
+diff -urN linux-2.6.22.orig/fs/reiser4/coord.h linux-2.6.22/fs/reiser4/coord.h
+--- linux-2.6.22.orig/fs/reiser4/coord.h       1970-01-01 03:00:00.000000000 +0300
++++ linux-2.6.22/fs/reiser4/coord.h    2007-07-29 00:25:34.832685088 +0400
 @@ -0,0 +1,389 @@
 +/* Copyright 2001, 2002, 2003 by Hans Reiser, licensing governed by reiser4/README */
 +
@@ -8417,11 +8140,10 @@ Index: linux-2.6.16/fs/reiser4/coord.h
 +   scroll-step: 1
 +   End:
 +*/
-Index: linux-2.6.16/fs/reiser4/debug.c
-===================================================================
---- /dev/null
-+++ linux-2.6.16/fs/reiser4/debug.c
-@@ -0,0 +1,300 @@
+diff -urN linux-2.6.22.orig/fs/reiser4/debug.c linux-2.6.22/fs/reiser4/debug.c
+--- linux-2.6.22.orig/fs/reiser4/debug.c       1970-01-01 03:00:00.000000000 +0300
++++ linux-2.6.22/fs/reiser4/debug.c    2007-07-29 00:25:34.836686123 +0400
+@@ -0,0 +1,308 @@
 +/* Copyright 2001, 2002, 2003 by Hans Reiser, licensing governed by
 + * reiser4/README */
 +
@@ -8433,15 +8155,17 @@ Index: linux-2.6.16/fs/reiser4/debug.c
 + *
 + *     panicking: reiser4_do_panic(), reiser4_print_prefix().
 + *
-+ *     locking: schedulable(), lock_counters(), print_lock_counters(),
-+ *     no_counters_are_held(), commit_check_locks()
++ *     locking:
++ *     reiser4_schedulable(), reiser4_lock_counters(), print_lock_counters(),
++ *     reiser4_no_counters_are_held(), reiser4_commit_check_locks()
 + *
-+ *     error code monitoring (see comment before RETERR macro): return_err(),
-+ *     report_err().
++ *     error code monitoring (see comment before RETERR macro):
++ *     reiser4_return_err(), reiser4_report_err().
 + *
 + *     stack back-tracing: fill_backtrace()
 + *
-+ *     miscellaneous: preempt_point(), call_on_each_assert(), debugtrap().
++ *     miscellaneous: reiser4_preempt_point(), call_on_each_assert(),
++ *     reiser4_debugtrap().
 + *
 + */
 +
@@ -8462,11 +8186,13 @@ Index: linux-2.6.16/fs/reiser4/debug.c
 +#include <linux/sysctl.h>
 +#include <linux/hardirq.h>
 +
++#if 0
 +#if REISER4_DEBUG
-+static void report_err(void);
++static void reiser4_report_err(void);
 +#else
-+#define report_err() noop
++#define reiser4_report_err() noop
 +#endif
++#endif  /*  0  */
 +
 +/*
 + * global buffer where message given to reiser4_panic is formatted.
@@ -8517,6 +8243,7 @@ Index: linux-2.6.16/fs/reiser4/debug.c
 +      panic("%s", panic_buf);
 +}
 +
++#if 0
 +void
 +reiser4_print_prefix(const char *level, int reperr, const char *mid,
 +                   const char *function, const char *file, int lineno)
@@ -8534,14 +8261,15 @@ Index: linux-2.6.16/fs/reiser4/debug.c
 +      printk("%sreiser4[%.16s(%i)]: %s (%s:%i)[%s]:\n",
 +             level, comm, pid, function, file, lineno, mid);
 +      if (reperr)
-+              report_err();
++              reiser4_report_err();
 +}
++#endif  /*  0  */
 +
 +/* Preemption point: this should be called periodically during long running
 +   operations (carry, allocate, and squeeze are best examples) */
-+int preempt_point(void)
++int reiser4_preempt_point(void)
 +{
-+      assert("nikita-3008", schedulable());
++      assert("nikita-3008", reiser4_schedulable());
 +      cond_resched();
 +      return signal_pending(current);
 +}
@@ -8552,7 +8280,7 @@ Index: linux-2.6.16/fs/reiser4/debug.c
 +   constraints and various assertions.
 +
 +*/
-+lock_counters_info *lock_counters(void)
++reiser4_lock_cnt_info *reiser4_lock_counters(void)
 +{
 +      reiser4_context *ctx = get_current_context();
 +      assert("jmacd-1123", ctx != NULL);
@@ -8563,7 +8291,7 @@ Index: linux-2.6.16/fs/reiser4/debug.c
 + * print human readable information about locks held by the reiser4 context.
 + */
 +static void print_lock_counters(const char *prefix,
-+                              const lock_counters_info * info)
++                              const reiser4_lock_cnt_info * info)
 +{
 +      printk("%s: jnode: %i, tree: %i (r:%i,w:%i), dk: %i (r:%i,w:%i)\n"
 +             "jload: %i, "
@@ -8597,11 +8325,11 @@ Index: linux-2.6.16/fs/reiser4/debug.c
 +}
 +
 +/* check that no spinlocks are held */
-+int schedulable(void)
++int reiser4_schedulable(void)
 +{
 +      if (get_current_context_check() != NULL) {
 +              if (!LOCK_CNT_NIL(spin_locked)) {
-+                      print_lock_counters("in atomic", lock_counters());
++                      print_lock_counters("in atomic", reiser4_lock_counters());
 +                      return 0;
 +              }
 +      }
@@ -8611,11 +8339,11 @@ Index: linux-2.6.16/fs/reiser4/debug.c
 +/*
 + * return true, iff no locks are held.
 + */
-+int no_counters_are_held(void)
++int reiser4_no_counters_are_held(void)
 +{
-+      lock_counters_info *counters;
++      reiser4_lock_cnt_info *counters;
 +
-+      counters = lock_counters();
++      counters = reiser4_lock_counters();
 +      return
 +          (counters->spin_locked_zlock == 0) &&
 +          (counters->spin_locked_jnode == 0) &&
@@ -8640,9 +8368,9 @@ Index: linux-2.6.16/fs/reiser4/debug.c
 + * return true, iff transaction commit can be done under locks held by the
 + * current thread.
 + */
-+int commit_check_locks(void)
++int reiser4_commit_check_locks(void)
 +{
-+      lock_counters_info *counters;
++      reiser4_lock_cnt_info *counters;
 +      int inode_sem_r;
 +      int inode_sem_w;
 +      int result;
@@ -8652,12 +8380,12 @@ Index: linux-2.6.16/fs/reiser4/debug.c
 +       * held during commit.
 +       */
 +
-+      counters = lock_counters();
++      counters = reiser4_lock_counters();
 +      inode_sem_r = counters->inode_sem_r;
 +      inode_sem_w = counters->inode_sem_w;
 +
 +      counters->inode_sem_r = counters->inode_sem_w = 0;
-+      result = no_counters_are_held();
++      result = reiser4_no_counters_are_held();
 +      counters->inode_sem_r = inode_sem_r;
 +      counters->inode_sem_w = inode_sem_w;
 +      return result;
@@ -8667,7 +8395,7 @@ Index: linux-2.6.16/fs/reiser4/debug.c
 + * fill "error site" in the current reiser4 context. See comment before RETERR
 + * macro for more details.
 + */
-+void return_err(int code, const char *file, int line)
++void reiser4_return_err(int code, const char *file, int line)
 +{
 +      if (code < 0 && is_in_reiser4_context()) {
 +              reiser4_context *ctx = get_current_context();
@@ -8680,10 +8408,11 @@ Index: linux-2.6.16/fs/reiser4/debug.c
 +      }
 +}
 +
++#if 0
 +/*
-+ * report error information recorder by return_err().
++ * report error information recorder by reiser4_return_err().
 + */
-+static void report_err(void)
++static void reiser4_report_err(void)
 +{
 +      reiser4_context *ctx = get_current_context_check();
 +
@@ -8694,6 +8423,7 @@ Index: linux-2.6.16/fs/reiser4/debug.c
 +              }
 +      }
 +}
++#endif  /*  0  */
 +
 +#endif                                /* REISER4_DEBUG */
 +
@@ -8703,7 +8433,7 @@ Index: linux-2.6.16/fs/reiser4/debug.c
 + * this functions just drops into kernel debugger. It is a convenient place to
 + * put breakpoint in.
 + */
-+void debugtrap(void)
++void reiser4_debugtrap(void)
 +{
 +      /* do nothing. Put break point here. */
 +#if defined(CONFIG_KGDB) && !defined(CONFIG_REISER4_FS_MODULE)
@@ -8722,10 +8452,9 @@ Index: linux-2.6.16/fs/reiser4/debug.c
 +   fill-column: 120
 +   End:
 +*/
-Index: linux-2.6.16/fs/reiser4/debug.h
-===================================================================
---- /dev/null
-+++ linux-2.6.16/fs/reiser4/debug.h
+diff -urN linux-2.6.22.orig/fs/reiser4/debug.h linux-2.6.22/fs/reiser4/debug.h
+--- linux-2.6.22.orig/fs/reiser4/debug.h       1970-01-01 03:00:00.000000000 +0300
++++ linux-2.6.22/fs/reiser4/debug.h    2007-07-29 00:25:34.836686123 +0400
 @@ -0,0 +1,350 @@
 +/* Copyright 2001, 2002, 2003 by Hans Reiser, licensing governed by reiser4/README */
 +
@@ -8799,7 +8528,7 @@ Index: linux-2.6.16/fs/reiser4/debug.h
 +
 +#define ON_DEBUG( exp ) exp
 +
-+extern int schedulable(void);
++extern int reiser4_schedulable(void);
 +extern void call_on_each_assert(void);
 +
 +#else
@@ -8809,7 +8538,7 @@ Index: linux-2.6.16/fs/reiser4/debug.h
 +#define assert( label, cond ) noop
 +#define check_me( label, expr )       ( ( void ) ( expr ) )
 +#define ON_DEBUG( exp )
-+#define schedulable() might_sleep()
++#define reiser4_schedulable() might_sleep()
 +
 +/* REISER4_DEBUG */
 +#endif
@@ -8817,7 +8546,7 @@ Index: linux-2.6.16/fs/reiser4/debug.h
 +#if REISER4_DEBUG
 +/* per-thread information about lock acquired by this thread. Used by lock
 + * ordering checking in spin_macros.h */
-+typedef struct lock_counters_info {
++typedef struct reiser4_lock_cnt_info {
 +      int rw_locked_tree;
 +      int read_locked_tree;
 +      int write_locked_tree;
@@ -8850,33 +8579,38 @@ Index: linux-2.6.16/fs/reiser4/debug.h
 +      int d_refs;
 +      int x_refs;
 +      int t_refs;
-+} lock_counters_info;
++} reiser4_lock_cnt_info;
 +
-+extern lock_counters_info *lock_counters(void);
++extern struct reiser4_lock_cnt_info *reiser4_lock_counters(void);
 +#define IN_CONTEXT(a, b) (is_in_reiser4_context() ? (a) : (b))
 +
 +/* increment lock-counter @counter, if present */
-+#define LOCK_CNT_INC(counter) IN_CONTEXT(++(lock_counters()->counter), 0)
++#define LOCK_CNT_INC(counter)                                 \
++      IN_CONTEXT(++(reiser4_lock_counters()->counter), 0)
 +
 +/* decrement lock-counter @counter, if present */
-+#define LOCK_CNT_DEC(counter) IN_CONTEXT(--(lock_counters()->counter), 0)
++#define LOCK_CNT_DEC(counter)                                 \
++      IN_CONTEXT(--(reiser4_lock_counters()->counter), 0)
 +
 +/* check that lock-counter is zero. This is for use in assertions */
-+#define LOCK_CNT_NIL(counter) IN_CONTEXT(lock_counters()->counter == 0, 1)
++#define LOCK_CNT_NIL(counter)                                 \
++      IN_CONTEXT(reiser4_lock_counters()->counter == 0, 1)
 +
 +/* check that lock-counter is greater than zero. This is for use in
 + * assertions */
-+#define LOCK_CNT_GTZ(counter) IN_CONTEXT(lock_counters()->counter > 0, 1)
-+#define LOCK_CNT_LT(counter,n) IN_CONTEXT(lock_counters()->counter < n, 1)
++#define LOCK_CNT_GTZ(counter)                                 \
++      IN_CONTEXT(reiser4_lock_counters()->counter > 0, 1)
++#define LOCK_CNT_LT(counter,n)                                        \
++      IN_CONTEXT(reiser4_lock_counters()->counter < n, 1)
 +
 +#else                         /* REISER4_DEBUG */
 +
 +/* no-op versions on the above */
 +
-+typedef struct lock_counters_info {
-+} lock_counters_info;
++typedef struct reiser4_lock_cnt_info {
++} reiser4_lock_cnt_info;
 +
-+#define lock_counters() ((lock_counters_info *)NULL)
++#define reiser4_lock_counters() ((reiser4_lock_cnt_info *)NULL)
 +#define LOCK_CNT_INC(counter) noop
 +#define LOCK_CNT_DEC(counter) noop
 +#define LOCK_CNT_NIL(counter) (1)
@@ -8947,20 +8681,15 @@ Index: linux-2.6.16/fs/reiser4/debug.h
 +extern void reiser4_do_panic(const char *format, ...)
 +    __attribute__ ((noreturn, format(printf, 1, 2)));
 +
-+extern void reiser4_print_prefix(const char *level, int reperr, const char *mid,
-+                               const char *function,
-+                               const char *file, int lineno);
-+
-+extern int preempt_point(void);
++extern int reiser4_preempt_point(void);
 +extern void reiser4_print_stats(void);
 +
-+
 +#if REISER4_DEBUG
-+extern int no_counters_are_held(void);
-+extern int commit_check_locks(void);
++extern int reiser4_no_counters_are_held(void);
++extern int reiser4_commit_check_locks(void);
 +#else
-+#define no_counters_are_held() (1)
-+#define commit_check_locks() (1)
++#define reiser4_no_counters_are_held() (1)
++#define reiser4_commit_check_locks() (1)
 +#endif
 +
 +/* true if @i is power-of-two. Useful for rate-limited warnings, etc. */
@@ -8976,16 +8705,16 @@ Index: linux-2.6.16/fs/reiser4/debug.h
 +
 +#if KERNEL_DEBUGGER
 +
-+extern void debugtrap(void);
++extern void reiser4_debugtrap(void);
 +
 +/*
 + * Check condition @cond and drop into kernel debugger (kgdb) if it's true. If
 + * kgdb is not compiled in, do nothing.
 + */
-+#define DEBUGON(cond)                         \
-+({                                            \
-+      if (unlikely(cond))                     \
-+              debugtrap();                    \
++#define DEBUGON(cond)                                 \
++({                                                    \
++      if (unlikely(cond))                             \
++              reiser4_debugtrap();                    \
 +})
 +#else
 +#define DEBUGON(cond) noop
@@ -9014,9 +8743,9 @@ Index: linux-2.6.16/fs/reiser4/debug.h
 + *
 + * RETERR() macro fills a backtrace in reiser4_context. This back-trace is
 + * printed in error and warning messages. Moreover, it's possible to put a
-+ * conditional breakpoint in return_err (low-level function called by RETERR()
-+ * to do the actual work) to break into debugger immediately when particular
-+ * error happens.
++ * conditional breakpoint in reiser4_return_err (low-level function called
++ * by RETERR() to do the actual work) to break into debugger immediately
++ * when particular error happens.
 + *
 + */
 +
@@ -9031,18 +8760,18 @@ Index: linux-2.6.16/fs/reiser4/debug.h
 +      int line;               /* source file line, filled by __LINE__ */
 +} err_site;
 +
-+extern void return_err(int code, const char *file, int line);
++extern void reiser4_return_err(int code, const char *file, int line);
 +
 +/*
 + * fill &get_current_context()->err_site with error information.
 + */
-+#define RETERR(code)                          \
-+({                                            \
-+      typeof(code) __code;                    \
-+                                              \
-+      __code = (code);                        \
-+      return_err(__code, __FILE__, __LINE__); \
-+      __code;                                 \
++#define RETERR(code)                                  \
++({                                                    \
++      typeof(code) __code;                            \
++                                                      \
++      __code = (code);                                \
++      reiser4_return_err(__code, __FILE__, __LINE__); \
++      __code;                                         \
 +})
 +
 +#else
@@ -9077,11 +8806,10 @@ Index: linux-2.6.16/fs/reiser4/debug.h
 +   fill-column: 120
 +   End:
 +*/
-Index: linux-2.6.16/fs/reiser4/dformat.h
-===================================================================
---- /dev/null
-+++ linux-2.6.16/fs/reiser4/dformat.h
-@@ -0,0 +1,71 @@
+diff -urN linux-2.6.22.orig/fs/reiser4/dformat.h linux-2.6.22/fs/reiser4/dformat.h
+--- linux-2.6.22.orig/fs/reiser4/dformat.h     1970-01-01 03:00:00.000000000 +0300
++++ linux-2.6.22/fs/reiser4/dformat.h  2007-07-29 00:25:34.836686123 +0400
+@@ -0,0 +1,70 @@
 +/* Copyright 2001, 2002, 2003 by Hans Reiser, licensing governed by reiser4/README */
 +
 +/* Formats of on-disk data and conversion functions. */
@@ -9101,7 +8829,6 @@ Index: linux-2.6.16/fs/reiser4/dformat.h
 +#include <asm/unaligned.h>
 +#include <linux/types.h>
 +
-+
 +typedef __u8 d8;
 +typedef __le16 d16;
 +typedef __le32 d32;
@@ -9153,10 +8880,9 @@ Index: linux-2.6.16/fs/reiser4/dformat.h
 + * fill-column: 79
 + * End:
 + */
-Index: linux-2.6.16/fs/reiser4/dscale.c
-===================================================================
---- /dev/null
-+++ linux-2.6.16/fs/reiser4/dscale.c
+diff -urN linux-2.6.22.orig/fs/reiser4/dscale.c linux-2.6.22/fs/reiser4/dscale.c
+--- linux-2.6.22.orig/fs/reiser4/dscale.c      1970-01-01 03:00:00.000000000 +0300
++++ linux-2.6.22/fs/reiser4/dscale.c   2007-07-29 00:25:34.836686123 +0400
 @@ -0,0 +1,174 @@
 +/* Copyright 2001, 2002, 2003 by Hans Reiser, licensing governed by
 + * reiser4/README */
@@ -9332,10 +9058,9 @@ Index: linux-2.6.16/fs/reiser4/dscale.c
 +   scroll-step: 1
 +   End:
 +*/
-Index: linux-2.6.16/fs/reiser4/dscale.h
-===================================================================
---- /dev/null
-+++ linux-2.6.16/fs/reiser4/dscale.h
+diff -urN linux-2.6.22.orig/fs/reiser4/dscale.h linux-2.6.22/fs/reiser4/dscale.h
+--- linux-2.6.22.orig/fs/reiser4/dscale.h      1970-01-01 03:00:00.000000000 +0300
++++ linux-2.6.22/fs/reiser4/dscale.h   2007-07-29 00:25:34.836686123 +0400
 @@ -0,0 +1,27 @@
 +/* Copyright 2001, 2002, 2003 by Hans Reiser, licensing governed by
 + * reiser4/README */
@@ -9364,11 +9089,10 @@ Index: linux-2.6.16/fs/reiser4/dscale.h
 +   fill-column: 120
 +   End:
 +*/
-Index: linux-2.6.16/fs/reiser4/entd.c
-===================================================================
---- /dev/null
-+++ linux-2.6.16/fs/reiser4/entd.c
-@@ -0,0 +1,356 @@
+diff -urN linux-2.6.22.orig/fs/reiser4/entd.c linux-2.6.22/fs/reiser4/entd.c
+--- linux-2.6.22.orig/fs/reiser4/entd.c        1970-01-01 03:00:00.000000000 +0300
++++ linux-2.6.22/fs/reiser4/entd.c     2007-07-29 00:25:34.840687159 +0400
+@@ -0,0 +1,335 @@
 +/* Copyright 2003, 2004 by Hans Reiser, licensing governed by
 + * reiser4/README */
 +
@@ -9393,8 +9117,7 @@ Index: linux-2.6.16/fs/reiser4/entd.c
 +#include <linux/backing-dev.h>        /* bdi_write_congested */
 +#include <linux/wait.h>
 +#include <linux/kthread.h>
-+
-+#define LLONG_MAX      ((long long)(~0ULL>>1))
++#include <linux/freezer.h>
 +
 +#define DEF_PRIORITY 12
 +#define MAX_ENTD_ITERS 10
@@ -9410,13 +9133,13 @@ Index: linux-2.6.16/fs/reiser4/entd.c
 +               "ent:%s%s", super->s_id, (state))
 +
 +/**
-+ * init_entd - initialize entd context and start kernel daemon
++ * reiser4_init_entd - initialize entd context and start kernel daemon
 + * @super: super block to start ent thread for
 + *
 + * Creates entd contexts, starts kernel thread and waits until it
 + * initializes.
 + */
-+int init_entd(struct super_block *super)
++int reiser4_init_entd(struct super_block *super)
 +{
 +      entd_context *ctx;
 +
@@ -9440,9 +9163,10 @@ Index: linux-2.6.16/fs/reiser4/entd.c
 +      return 0;
 +}
 +
-+static void __put_wbq(entd_context *ent, struct wbq *rq)
++static void put_wbq(struct wbq *rq)
 +{
-+      up(&rq->sem);
++      iput(rq->mapping->host);
++      complete(&rq->completion);
 +}
 +
 +/* ent should be locked */
@@ -9450,7 +9174,7 @@ Index: linux-2.6.16/fs/reiser4/entd.c
 +{
 +      struct wbq *wbq;
 +
-+      if (list_empty_careful(&ent->todo_list))
++      if (list_empty(&ent->todo_list))
 +              return NULL;
 +
 +      ent->nr_todo_reqs --;
@@ -9459,16 +9183,6 @@ Index: linux-2.6.16/fs/reiser4/entd.c
 +      return wbq;
 +}
 +
-+static void wakeup_all_wbq(entd_context * ent)
-+{
-+      struct wbq *rq;
-+
-+      spin_lock(&ent->guard);
-+      while ((rq = __get_wbq(ent)) != NULL)
-+              __put_wbq(ent, rq);
-+      spin_unlock(&ent->guard);
-+}
-+
 +/* ent thread function */
 +static int entd(void *arg)
 +{
@@ -9490,9 +9204,9 @@ Index: linux-2.6.16/fs/reiser4/entd.c
 +
 +              spin_lock(&ent->guard);
 +              while (ent->nr_todo_reqs != 0) {
-+                      struct wbq *rq, *next;
++                      struct wbq *rq;
 +
-+                      assert("", list_empty_careful(&ent->done_list));
++                      assert("", list_empty(&ent->done_list));
 +
 +                      /* take request from the queue head */
 +                      rq = __get_wbq(ent);
@@ -9503,21 +9217,19 @@ Index: linux-2.6.16/fs/reiser4/entd.c
 +                      entd_set_comm("!");
 +                      entd_flush(super, rq);
 +
-+                      iput(rq->mapping->host);
-+                      up(&(rq->sem));
++                      put_wbq(rq);
 +
 +                      /*
 +                       * wakeup all requestors and iput their inodes
 +                       */
 +                      spin_lock(&ent->guard);
-+                      list_for_each_entry_safe(rq, next, &ent->done_list, link) {
-+                              list_del_init(&(rq->link));
++                      while (!list_empty(&ent->done_list)) {
++                              rq = list_entry(ent->done_list.next, struct wbq, link);
++                              list_del_init(&rq->link);
 +                              ent->nr_done_reqs --;
 +                              spin_unlock(&ent->guard);
-+
 +                              assert("", rq->written == 1);
-+                              iput(rq->mapping->host);
-+                              up(&(rq->sem));
++                              put_wbq(rq);
 +                              spin_lock(&ent->guard);
 +                      }
 +              }
@@ -9541,21 +9253,18 @@ Index: linux-2.6.16/fs/reiser4/entd.c
 +                      finish_wait(&ent->wait, &__wait);
 +              }
 +      }
-+      spin_lock(&ent->guard);
 +      BUG_ON(ent->nr_todo_reqs != 0);
-+      spin_unlock(&ent->guard);
-+      wakeup_all_wbq(ent);
 +      return 0;
 +}
 +
 +/**
-+ * done_entd - stop entd kernel thread
++ * reiser4_done_entd - stop entd kernel thread
 + * @super: super block to stop ent thread for
 + *
 + * It is called on umount. Sends stop signal to entd and wait until it handles
 + * it.
 + */
-+void done_entd(struct super_block *super)
++void reiser4_done_entd(struct super_block *super)
 +{
 +      entd_context *ent;
 +
@@ -9568,7 +9277,7 @@ Index: linux-2.6.16/fs/reiser4/entd.c
 +
 +/* called at the beginning of jnode_flush to register flusher thread with ent
 + * daemon */
-+void enter_flush(struct super_block *super)
++void reiser4_enter_flush(struct super_block *super)
 +{
 +      entd_context *ent;
 +
@@ -9586,7 +9295,7 @@ Index: linux-2.6.16/fs/reiser4/entd.c
 +}
 +
 +/* called at the end of jnode_flush */
-+void leave_flush(struct super_block *super)
++void reiser4_leave_flush(struct super_block *super)
 +{
 +      entd_context *ent;
 +      int wake_up_ent;
@@ -9618,18 +9327,19 @@ Index: linux-2.6.16/fs/reiser4/entd.c
 +      ctx.entd = 1;
 +      ctx.gfp_mask = GFP_NOFS;
 +
-+      rq->wbc->start = rq->page->index << PAGE_CACHE_SHIFT;
-+      rq->wbc->end = (rq->page->index + ENTD_CAPTURE_APAGE_BURST) << PAGE_CACHE_SHIFT;
++      rq->wbc->range_start = page_offset(rq->page);
++      rq->wbc->range_end = rq->wbc->range_start +
++              (ENTD_CAPTURE_APAGE_BURST << PAGE_CACHE_SHIFT);
 +      tmp = rq->wbc->nr_to_write;
 +      rq->mapping->a_ops->writepages(rq->mapping, rq->wbc);
 +
 +      if (rq->wbc->nr_to_write > 0) {
-+              rq->wbc->start = 0;
-+              rq->wbc->end = LLONG_MAX;
++              rq->wbc->range_start = 0;
++              rq->wbc->range_end = LLONG_MAX;
 +              generic_sync_sb_inodes(super, rq->wbc);
 +      }
 +      rq->wbc->nr_to_write = ENTD_CAPTURE_APAGE_BURST;
-+      writeout(super, rq->wbc);
++      reiser4_writeout(super, rq->wbc);
 +
 +      context_set_commit_async(&ctx);
 +      reiser4_exit_context(&ctx);
@@ -9662,7 +9372,7 @@ Index: linux-2.6.16/fs/reiser4/entd.c
 +       * page. Re-dirty page before unlocking so that if ent thread fails to
 +       * write it - it will remain dirty
 +       */
-+      set_page_dirty_internal(page);
++      reiser4_set_page_dirty_internal(page);
 +
 +      /*
 +       * pin inode in memory, unlock page, entd_flush will iput. We can not
@@ -9682,7 +9392,7 @@ Index: linux-2.6.16/fs/reiser4/entd.c
 +      rq.mapping = inode->i_mapping;
 +      rq.node = NULL;
 +      rq.written = 0;
-+      sema_init(&rq.sem, 0);
++      init_completion(&rq.completion);
 +
 +      /* add request to entd's list of writepage requests */
 +      spin_lock(&ent->guard);
@@ -9694,14 +9404,7 @@ Index: linux-2.6.16/fs/reiser4/entd.c
 +      spin_unlock(&ent->guard);
 +
 +      /* wait until entd finishes */
-+      down(&rq.sem);
-+
-+      /*
-+       * spin until entd thread which did up(&rq.sem) does not need rq
-+       * anymore
-+       */
-+      spin_lock(&ent->guard);
-+      spin_unlock(&ent->guard);
++      wait_for_completion(&rq.completion);
 +
 +      if (rq.written)
 +              /* Eventually ENTD has written the page to disk. */
@@ -9725,10 +9428,9 @@ Index: linux-2.6.16/fs/reiser4/entd.c
 + * fill-column: 79
 + * End:
 + */
-Index: linux-2.6.16/fs/reiser4/entd.h
-===================================================================
---- /dev/null
-+++ linux-2.6.16/fs/reiser4/entd.h
+diff -urN linux-2.6.22.orig/fs/reiser4/entd.h linux-2.6.22/fs/reiser4/entd.h
+--- linux-2.6.22.orig/fs/reiser4/entd.h        1970-01-01 03:00:00.000000000 +0300
++++ linux-2.6.22/fs/reiser4/entd.h     2007-07-29 00:25:34.840687159 +0400
 @@ -0,0 +1,90 @@
 +/* Copyright 2003 by Hans Reiser, licensing governed by reiser4/README */
 +
@@ -9754,7 +9456,7 @@ Index: linux-2.6.16/fs/reiser4/entd.h
 +      struct writeback_control *wbc;
 +      struct page *page;
 +      struct address_space *mapping;
-+      struct semaphore sem;
++      struct completion completion;
 +      jnode *node; /* set if ent thread captured requested page */
 +      int written; /* set if ent thread wrote requested page */
 +};
@@ -9797,11 +9499,11 @@ Index: linux-2.6.16/fs/reiser4/entd.h
 +#endif
 +} entd_context;
 +
-+extern int  init_entd(struct super_block *);
-+extern void done_entd(struct super_block *);
++extern int  reiser4_init_entd(struct super_block *);
++extern void reiser4_done_entd(struct super_block *);
 +
-+extern void enter_flush(struct super_block *);
-+extern void leave_flush(struct super_block *);
++extern void reiser4_enter_flush(struct super_block *);
++extern void reiser4_leave_flush(struct super_block *);
 +
 +extern int write_page_by_ent(struct page *, struct writeback_control *);
 +extern int wbq_available(void);
@@ -9820,11 +9522,10 @@ Index: linux-2.6.16/fs/reiser4/entd.h
 +   fill-column: 120
 +   End:
 +*/
-Index: linux-2.6.16/fs/reiser4/eottl.c
-===================================================================
---- /dev/null
-+++ linux-2.6.16/fs/reiser4/eottl.c
-@@ -0,0 +1,510 @@
+diff -urN linux-2.6.22.orig/fs/reiser4/eottl.c linux-2.6.22/fs/reiser4/eottl.c
+--- linux-2.6.22.orig/fs/reiser4/eottl.c       1970-01-01 03:00:00.000000000 +0300
++++ linux-2.6.22/fs/reiser4/eottl.c    2007-07-29 00:25:34.840687159 +0400
+@@ -0,0 +1,509 @@
 +/* Copyright 2001, 2002, 2003 by Hans Reiser, licensing governed by reiser4/README */
 +
 +#include "forward.h"
@@ -10094,7 +9795,7 @@ Index: linux-2.6.16/fs/reiser4/eottl.c
 +
 +      assert("vs-49827", znode_contains_key_lock(insert_coord->node, key));
 +      tree = znode_get_tree(insert_coord->node);
-+      node = new_node(insert_coord->node, LEAF_LEVEL);
++      node = reiser4_new_node(insert_coord->node, LEAF_LEVEL);
 +      if (IS_ERR(node))
 +              return PTR_ERR(node);
 +
@@ -10122,7 +9823,7 @@ Index: linux-2.6.16/fs/reiser4/eottl.c
 +      item = (reiser4_item_data *) (todo + 3);
 +      cdata = (carry_insert_data *) (item + 1);
 +
-+      op = post_carry(todo, COP_INSERT, insert_coord->node, 0);
++      op = reiser4_post_carry(todo, COP_INSERT, insert_coord->node, 0);
 +      if (!IS_ERR(op)) {
 +              cdata->coord = insert_coord;
 +              cdata->key = key;
@@ -10136,7 +9837,7 @@ Index: linux-2.6.16/fs/reiser4/eottl.c
 +              todo->track_type = CARRY_TRACK_CHANGE;
 +              todo->tracked = lh;
 +
-+              result = carry(todo, NULL);
++              result = reiser4_carry(todo, NULL);
 +              if (result == 0) {
 +                      /*
 +                       * pin node in memory. This is necessary for
@@ -10175,8 +9876,7 @@ Index: linux-2.6.16/fs/reiser4/eottl.c
 +                                      write_unlock_tree(tree);
 +                                      result =
 +                                          connect_znode(insert_coord, node);
-+                                      if (result == 0)
-+                                              ON_DEBUG(check_dkeys(node));
++                                      ON_DEBUG(if (result == 0) check_dkeys(node););
 +
 +                                      done_lh(lh);
 +                                      move_lh(lh, &local_lh);
@@ -10335,11 +10035,10 @@ Index: linux-2.6.16/fs/reiser4/eottl.c
 + * scroll-step: 1
 + * End:
 + */
-Index: linux-2.6.16/fs/reiser4/estimate.c
-===================================================================
---- /dev/null
-+++ linux-2.6.16/fs/reiser4/estimate.c
-@@ -0,0 +1,111 @@
+diff -urN linux-2.6.22.orig/fs/reiser4/estimate.c linux-2.6.22/fs/reiser4/estimate.c
+--- linux-2.6.22.orig/fs/reiser4/estimate.c    1970-01-01 03:00:00.000000000 +0300
++++ linux-2.6.22/fs/reiser4/estimate.c 2007-07-29 00:25:34.840687159 +0400
+@@ -0,0 +1,120 @@
 +/* Copyright 2001, 2002, 2003 by Hans Reiser, licensing governed by reiser4/README */
 +
 +#include "debug.h"
@@ -10435,10 +10134,19 @@ Index: linux-2.6.16/fs/reiser4/estimate.c
 +      return estimate_cluster(inode, 0); /* 44, for 64K-cluster */
 +}
 +
-+/* how many nodes occupied by a disk cluster might get dirty */
++/* How many nodes occupied by a disk cluster might get dirty.
++   Note that this estimation is not precise (i.e. disk cluster
++   can occupy more nodes).
++   Q: Why we don't use precise estimation?
++   A: 1.Because precise estimation is fairly bad: 65536 nodes
++        for 64K logical cluster, it means 256M of dead space on
++      a partition
++      2.It is a very rare case when disk cluster occupies more
++        nodes then this estimation returns.
++*/
 +reiser4_block_nr estimate_dirty_cluster(struct inode * inode)
 +{
-+      return 2 + cluster_nrpages(inode);
++      return cluster_nrpages(inode) + 4;
 +}
 +
 +/* Make Linus happy.
@@ -10451,18 +10159,16 @@ Index: linux-2.6.16/fs/reiser4/estimate.c
 +   scroll-step: 1
 +   End:
 +*/
-Index: linux-2.6.16/fs/reiser4/export_ops.c
-===================================================================
---- /dev/null
-+++ linux-2.6.16/fs/reiser4/export_ops.c
-@@ -0,0 +1,296 @@
+diff -urN linux-2.6.22.orig/fs/reiser4/export_ops.c linux-2.6.22/fs/reiser4/export_ops.c
+--- linux-2.6.22.orig/fs/reiser4/export_ops.c  1970-01-01 03:00:00.000000000 +0300
++++ linux-2.6.22/fs/reiser4/export_ops.c       2007-07-29 00:25:34.840687159 +0400
+@@ -0,0 +1,295 @@
 +/* Copyright 2005 by Hans Reiser, licensing governed by
 + * reiser4/README */
 +
 +#include "inode.h"
 +#include "plugin/plugin.h"
 +
-+
 +/*
 + * Supported file-handle types
 + */
@@ -10497,7 +10203,7 @@ Index: linux-2.6.16/fs/reiser4/export_ops.c
 +
 +      /* identifier of object plugin is stored in the first two bytes,
 +       * followed by... */
-+      fplug = file_plugin_by_disk_id(get_tree(s), (d16 *) addr);
++      fplug = file_plugin_by_disk_id(reiser4_get_tree(s), (d16 *) addr);
 +      if (fplug != NULL) {
 +              addr += sizeof(d16);
 +              obj->plugin = fplug;
@@ -10532,7 +10238,7 @@ Index: linux-2.6.16/fs/reiser4/export_ops.c
 +      char *addr;
 +      int with_parent;
 +
-+      ctx = init_context(super);
++      ctx = reiser4_init_context(super);
 +      if (IS_ERR(ctx))
 +              return (struct dentry *)ctx;
 +
@@ -10663,7 +10369,7 @@ Index: linux-2.6.16/fs/reiser4/export_ops.c
 +              need += delta;
 +      }
 +
-+      ctx = init_context(dentry->d_inode->i_sb);
++      ctx = reiser4_init_context(dentry->d_inode->i_sb);
 +      if (IS_ERR(ctx))
 +              return PTR_ERR(ctx);
 +
@@ -10752,11 +10458,10 @@ Index: linux-2.6.16/fs/reiser4/export_ops.c
 + * fill-column: 79
 + * End:
 + */
-Index: linux-2.6.16/fs/reiser4/flush.c
-===================================================================
---- /dev/null
-+++ linux-2.6.16/fs/reiser4/flush.c
-@@ -0,0 +1,3626 @@
+diff -urN linux-2.6.22.orig/fs/reiser4/flush.c linux-2.6.22/fs/reiser4/flush.c
+--- linux-2.6.22.orig/fs/reiser4/flush.c       1970-01-01 03:00:00.000000000 +0300
++++ linux-2.6.22/fs/reiser4/flush.c    2007-07-29 00:25:34.000000000 +0400
+@@ -0,0 +1,3625 @@
 +/* Copyright 2001, 2002, 2003 by Hans Reiser, licensing governed by reiser4/README */
 +
 +/* The design document for this file is at http://www.namesys.com/v4/v4.html. */
@@ -11174,7 +10879,7 @@ Index: linux-2.6.16/fs/reiser4/flush.c
 +                                 load_count * parent_zh,
 +                                 znode_lock_mode mode, int try);
 +static int neighbor_in_slum(znode * node, lock_handle * right_lock, sideof side,
-+                          znode_lock_mode mode, int check_dirty);
++                          znode_lock_mode mode, int check_dirty, int expected);
 +static int znode_same_parents(znode * a, znode * b);
 +
 +static int znode_check_flushprepped(znode * node)
@@ -11211,7 +10916,7 @@ Index: linux-2.6.16/fs/reiser4/flush.c
 +      struct backing_dev_info *bdi;
 +
 +      sb = reiser4_get_current_sb();
-+      bdi = get_super_fake(sb)->i_mapping->backing_dev_info;
++      bdi = reiser4_get_super_fake(sb)->i_mapping->backing_dev_info;
 +      return bdi_write_congested(bdi);
 +}
 +
@@ -11229,7 +10934,7 @@ Index: linux-2.6.16/fs/reiser4/flush.c
 +      if (check_write_congestion())
 +              return 0;
 +
-+      ret = write_fq(pos->fq, pos->nr_written,
++      ret = reiser4_write_fq(pos->fq, pos->nr_written,
 +                     WRITEOUT_SINGLE_STREAM | WRITEOUT_FOR_PAGE_RECLAIM);
 +      return ret;
 +}
@@ -11267,7 +10972,7 @@ Index: linux-2.6.16/fs/reiser4/flush.c
 +      assert("zam-1020", node_is_empty(node));
 +      assert("zam-1023", znode_is_wlocked(node));
 +
-+      return delete_node(node, &smallest_removed, NULL, 1);
++      return reiser4_delete_node(node, &smallest_removed, NULL, 1);
 +}
 +
 +/* Prepare flush position for alloc_pos_and_ancestors() and squalloc() */
@@ -11418,15 +11123,15 @@ Index: linux-2.6.16/fs/reiser4/flush.c
 +      jnode *leftmost_in_slum = NULL;
 +
 +      assert("jmacd-76619", lock_stack_isclean(get_current_lock_stack()));
-+      assert("nikita-3022", schedulable());
++      assert("nikita-3022", reiser4_schedulable());
 +
-+      /* lock ordering: delete_sema and flush_sema are unordered */
 +      assert("nikita-3185",
-+             get_current_super_private()->delete_sema_owner != current);
++             get_current_super_private()->delete_mutex_owner != current);
 +
 +      /* allocate right_scan, left_scan and flush_pos */
 +      right_scan =
-+          kmalloc(2 * sizeof(*right_scan) + sizeof(*flush_pos), get_gfp_mask());
++          kmalloc(2 * sizeof(*right_scan) + sizeof(*flush_pos),
++                  reiser4_ctx_gfp_mask_get());
 +      if (right_scan == NULL)
 +              return RETERR(-ENOMEM);
 +      left_scan = right_scan + 1;
@@ -11434,16 +11139,13 @@ Index: linux-2.6.16/fs/reiser4/flush.c
 +
 +      sb = reiser4_get_current_sb();
 +      sbinfo = get_super_private(sb);
-+      if (!reiser4_is_set(sb, REISER4_MTFLUSH)) {
-+              down(&sbinfo->flush_sema);
-+      }
 +
 +      /* Flush-concurrency debug code */
 +#if REISER4_DEBUG
 +      atomic_inc(&flush_cnt);
 +#endif
 +
-+      enter_flush(sb);
++      reiser4_enter_flush(sb);
 +
 +      /* Initialize a flush position. */
 +      pos_init(flush_pos);
@@ -11634,10 +11336,7 @@ Index: linux-2.6.16/fs/reiser4/flush.c
 +
 +      ON_DEBUG(atomic_dec(&flush_cnt));
 +
-+      leave_flush(sb);
-+
-+      if (!reiser4_is_set(sb, REISER4_MTFLUSH))
-+              up(&sbinfo->flush_sema);
++      reiser4_leave_flush(sb);
 +
 +      return ret;
 +}
@@ -11730,7 +11429,6 @@ Index: linux-2.6.16/fs/reiser4/flush.c
 +      return node;
 +}
 +
-+
 +/* Flush some nodes of current atom, usually slum, return -E_REPEAT if there are more nodes
 + * to flush, return 0 if atom's dirty lists empty and keep current atom locked, return
 + * other errors as they are. */
@@ -11750,7 +11448,7 @@ Index: linux-2.6.16/fs/reiser4/flush.c
 +
 +      nr_to_write = LONG_MAX;
 +      while (1) {
-+              ret = fq_by_atom(*atom, &fq);
++              ret = reiser4_fq_by_atom(*atom, &fq);
 +              if (ret != -E_REPEAT)
 +                      break;
 +              *atom = get_current_atom_locked();
@@ -11763,10 +11461,10 @@ Index: linux-2.6.16/fs/reiser4/flush.c
 +      /* parallel flushers limit */
 +      if (sinfo->tmgr.atom_max_flushers != 0) {
 +              while ((*atom)->nr_flushers >= sinfo->tmgr.atom_max_flushers) {
-+                      /* An atom_send_event() call is inside fq_put_nolock() which is
-+                         called when flush is finished and nr_flushers is
-+                         decremented. */
-+                      atom_wait_event(*atom);
++                      /* An reiser4_atom_send_event() call is inside
++                         reiser4_fq_put_nolock() which is called when flush is
++                         finished and nr_flushers is decremented. */
++                      reiser4_atom_wait_event(*atom);
 +                      *atom = get_current_atom_locked();
 +              }
 +      }
@@ -11782,8 +11480,8 @@ Index: linux-2.6.16/fs/reiser4/flush.c
 +      if (node == NULL) {
 +              if (nr_queued == 0) {
 +                      (*atom)->nr_flushers--;
-+                      fq_put_nolock(fq);
-+                      atom_send_event(*atom);
++                      reiser4_fq_put_nolock(fq);
++                      reiser4_atom_send_event(*atom);
 +                      /* current atom remains locked */
 +                      writeout_mode_disable();
 +                      return 0;
@@ -11800,13 +11498,13 @@ Index: linux-2.6.16/fs/reiser4/flush.c
 +      }
 +
 +      ret =
-+          write_fq(fq, nr_submitted,
++          reiser4_write_fq(fq, nr_submitted,
 +                   WRITEOUT_SINGLE_STREAM | WRITEOUT_FOR_PAGE_RECLAIM);
 +
 +      *atom = get_current_atom_locked();
 +      (*atom)->nr_flushers--;
-+      fq_put_nolock(fq);
-+      atom_send_event(*atom);
++      reiser4_fq_put_nolock(fq);
++      reiser4_atom_send_event(*atom);
 +      spin_unlock_atom(*atom);
 +
 +      writeout_mode_disable();
@@ -11832,8 +11530,8 @@ Index: linux-2.6.16/fs/reiser4/flush.c
 +      reiser4_block_nr dist;
 +
 +      assert("jmacd-7710", *pblk != 0 && *nblk != 0);
-+      assert("jmacd-7711", !blocknr_is_fake(pblk));
-+      assert("jmacd-7712", !blocknr_is_fake(nblk));
++      assert("jmacd-7711", !reiser4_blocknr_is_fake(pblk));
++      assert("jmacd-7712", !reiser4_blocknr_is_fake(nblk));
 +
 +      /* Distance is the absolute value. */
 +      dist = (*pblk > *nblk) ? (*pblk - *nblk) : (*nblk - *pblk);
@@ -11895,7 +11593,7 @@ Index: linux-2.6.16/fs/reiser4/flush.c
 +
 +      nblk = *jnode_get_block(node);
 +
-+      if (blocknr_is_fake(&nblk))
++      if (reiser4_blocknr_is_fake(&nblk))
 +              /* child is unallocated, mark parent dirty */
 +              return 1;
 +
@@ -12244,13 +11942,13 @@ Index: linux-2.6.16/fs/reiser4/flush.c
 +              ON_DEBUG(vp = shift_check_prepare(left, coord.node));
 +
 +              /* stop_key is used to find what was copied and what to cut */
-+              stop_key = *min_key();
++              stop_key = *reiser4_min_key();
 +              ret = squalloc_extent(left, &coord, pos, &stop_key);
 +              if (ret != SQUEEZE_CONTINUE) {
 +                      ON_DEBUG(kfree(vp));
 +                      break;
 +              }
-+              assert("vs-1465", !keyeq(&stop_key, min_key()));
++              assert("vs-1465", !keyeq(&stop_key, reiser4_min_key()));
 +
 +              /* Helper function to do the cutting. */
 +              set_key_offset(&stop_key, get_key_offset(&stop_key) - 1);
@@ -12654,14 +12352,17 @@ Index: linux-2.6.16/fs/reiser4/flush.c
 +      }
 +
 +      while (1) {
-+              ret =
-+                  neighbor_in_slum(pos->lock.node, &right_lock, RIGHT_SIDE,
-+                                   ZNODE_WRITE_LOCK,
-+                                   !should_convert_next_node(pos,
-+                                                             right_lock.
-+                                                             node));
-+              if (ret)
++              int expected;
++              expected = should_convert_next_node(pos);
++              ret = neighbor_in_slum(pos->lock.node, &right_lock, RIGHT_SIDE,
++                                     ZNODE_WRITE_LOCK, !expected, expected);
++              if (ret) {
++                      if (expected)
++                              warning("edward-1495",
++                              "Expected neighbor not found (ret = %d). Fsck?",
++                                      ret);
 +                      break;
++              }
 +
 +              /* we don't prep(allocate) nodes for flushing twice.  This can be suboptimal, or it
 +               * can be optimal.  For now we choose to live with the risk that it will
@@ -12669,8 +12370,7 @@ Index: linux-2.6.16/fs/reiser4/flush.c
 +               * smarter. */
 +              if (znode_check_flushprepped(right_lock.node)
 +                  && !znode_convertible(right_lock.node)) {
-+                      assert("edward-1005",
-+                             !should_convert_next_node(pos, right_lock.node));
++                      assert("edward-1005", !should_convert_next_node(pos));
 +                      pos_stop(pos);
 +                      break;
 +              }
@@ -12678,7 +12378,6 @@ Index: linux-2.6.16/fs/reiser4/flush.c
 +              ret = incr_load_count_znode(&right_load, right_lock.node);
 +              if (ret)
 +                      break;
-+
 +              if (should_convert_node(pos, right_lock.node)) {
 +                      ret = convert_node(pos, right_lock.node);
 +                      if (ret)
@@ -12699,7 +12398,7 @@ Index: linux-2.6.16/fs/reiser4/flush.c
 +                      break;
 +
 +              if (znode_check_flushprepped(right_lock.node)) {
-+                      if (should_convert_next_node(pos, right_lock.node)) {
++                      if (should_convert_next_node(pos)) {
 +                              /* in spite of flushprepped status of the node,
 +                                 its right slum neighbor should be converted */
 +                              assert("edward-953", convert_data(pos));
@@ -12735,7 +12434,6 @@ Index: linux-2.6.16/fs/reiser4/flush.c
 +              ret = lock_parent_and_allocate_znode(right_lock.node, pos);
 +              if (ret)
 +                      break;
-+
 +              if (should_terminate_squalloc(pos)) {
 +                      set_item_convert_count(pos, 0);
 +                      break;
@@ -12748,9 +12446,7 @@ Index: linux-2.6.16/fs/reiser4/flush.c
 +              if (ret)
 +                      break;
 +      }
-+
-+      assert("edward-1006", !convert_data(pos) || !item_convert_data(pos));
-+
++      check_convert_info(pos);
 +      done_load_count(&right_load);
 +      done_lh(&right_lock);
 +
@@ -12846,7 +12542,7 @@ Index: linux-2.6.16/fs/reiser4/flush.c
 +
 +      while (pos_valid(pos) && coord_is_existing_unit(&pos->coord)
 +             && item_is_extent(&pos->coord)) {
-+              ret = alloc_extent(pos);
++              ret = reiser4_alloc_extent(pos);
 +              if (ret) {
 +                      break;
 +              }
@@ -13234,7 +12930,7 @@ Index: linux-2.6.16/fs/reiser4/flush.c
 +              grabbed = get_current_context()->grabbed_blocks;
 +              ret = reiser4_grab_space_force(tree->height, BA_RESERVED);
 +              assert("nikita-3003", ret == 0);        /* reserved space is exhausted. Ask Hans. */
-+              ret = carry(todo, NULL /* previous level */ );
++              ret = reiser4_carry(todo, NULL /* previous level */ );
 +              grabbed2free_mark(grabbed);
 +      } else {
 +              /* Shifting impossible, we return appropriate result code */
@@ -13345,7 +13041,7 @@ Index: linux-2.6.16/fs/reiser4/flush.c
 +              ret = reiser4_grab_space_force(tree->height, BA_RESERVED);
 +              assert("nikita-3003", ret == 0);        /* reserved space is exhausted. Ask Hans. */
 +
-+              ret = carry(todo, NULL /* previous level */ );
++              ret = reiser4_carry(todo, NULL /* previous level */ );
 +              grabbed2free_mark(grabbed);
 +      }
 +
@@ -13400,8 +13096,8 @@ Index: linux-2.6.16/fs/reiser4/flush.c
 +              reiser4_block_nr dist;
 +              reiser4_block_nr nblk = *znode_get_block(node);
 +
-+              assert("jmacd-6172", !blocknr_is_fake(&nblk));
-+              assert("jmacd-6173", !blocknr_is_fake(&pos->preceder.blk));
++              assert("jmacd-6172", !reiser4_blocknr_is_fake(&nblk));
++              assert("jmacd-6173", !reiser4_blocknr_is_fake(&pos->preceder.blk));
 +              assert("jmacd-6174", pos->preceder.blk != 0);
 +
 +              if (pos->preceder.blk == nblk - 1) {
@@ -13454,7 +13150,7 @@ Index: linux-2.6.16/fs/reiser4/flush.c
 +      check_preceder(pos->preceder.blk);
 +      pos->alloc_cnt += 1;
 +
-+      assert("jmacd-4277", !blocknr_is_fake(&pos->preceder.blk));
++      assert("jmacd-4277", !reiser4_blocknr_is_fake(&pos->preceder.blk));
 +
 +      return 0;
 +}
@@ -13499,7 +13195,7 @@ Index: linux-2.6.16/fs/reiser4/flush.c
 +              return ret;
 +
 +      if (ZF_ISSET(node, JNODE_CREATED)) {
-+              assert("zam-816", blocknr_is_fake(znode_get_block(node)));
++              assert("zam-816", reiser4_blocknr_is_fake(znode_get_block(node)));
 +              pos->preceder.block_stage = BLOCK_UNALLOCATED;
 +      } else {
 +              pos->preceder.block_stage = BLOCK_GRABBED;
@@ -13743,24 +13439,26 @@ Index: linux-2.6.16/fs/reiser4/flush.c
 +                          lock_handle * lock, /* lock on starting point */
 +                          sideof side,        /* left or right direction we seek the next node in */
 +                          znode_lock_mode mode,       /* kind of lock we want */
-+                          int check_dirty)
-+{                             /* true if the neighbor should be dirty */
++                          int check_dirty, /* true if the neighbor should be dirty */
++                          int use_upper_levels /* get neighbor by going though
++                                                  upper levels */)
++{
 +      int ret;
++      int flags;
 +
 +      assert("jmacd-6334", znode_is_connected(node));
 +
-+      ret =
-+          reiser4_get_neighbor(lock, node, mode,
-+                               GN_SAME_ATOM | (side ==
-+                                               LEFT_SIDE ? GN_GO_LEFT : 0));
++      flags =  GN_SAME_ATOM | (side == LEFT_SIDE ? GN_GO_LEFT : 0);
++      if (use_upper_levels)
++              flags |= GN_CAN_USE_UPPER_LEVELS;
 +
++      ret = reiser4_get_neighbor(lock, node, mode, flags);
 +      if (ret) {
 +              /* May return -ENOENT or -E_NO_NEIGHBOR. */
 +              /* FIXME(C): check EINVAL, E_DEADLOCK */
 +              if (ret == -ENOENT) {
 +                      ret = RETERR(-E_NO_NEIGHBOR);
 +              }
-+
 +              return ret;
 +      }
 +      if (!check_dirty)
@@ -13817,7 +13515,7 @@ Index: linux-2.6.16/fs/reiser4/flush.c
 +}
 +
 +/* Returns true if flush scanning is finished. */
-+int scan_finished(flush_scan * scan)
++int reiser4_scan_finished(flush_scan * scan)
 +{
 +      return scan->stop || (scan->direction == RIGHT_SIDE &&
 +                            scan->count >= scan->max_count);
@@ -13825,7 +13523,7 @@ Index: linux-2.6.16/fs/reiser4/flush.c
 +
 +/* Return true if the scan should continue to the @tonode.  True if the node meets the
 +   same_slum_check condition.  If not, deref the "left" node and stop the scan. */
-+int scan_goto(flush_scan * scan, jnode * tonode)
++int reiser4_scan_goto(flush_scan * scan, jnode * tonode)
 +{
 +      int go = same_slum_check(scan->node, tonode, 1, 0);
 +
@@ -13853,7 +13551,7 @@ Index: linux-2.6.16/fs/reiser4/flush.c
 +      scan->node = node;
 +      scan->count += add_count;
 +
-+      /* This next stmt is somewhat inefficient.  The scan_extent_coord code could
++      /* This next stmt is somewhat inefficient.  The reiser4_scan_extent() code could
 +         delay this update step until it finishes and update the parent_coord only once.
 +         It did that before, but there was a bug and this was the easiest way to make it
 +         correct. */
@@ -13867,7 +13565,7 @@ Index: linux-2.6.16/fs/reiser4/flush.c
 +}
 +
 +/* Return true if scanning in the leftward direction. */
-+int scanning_left(flush_scan * scan)
++int reiser4_scanning_left(flush_scan * scan)
 +{
 +      return scan->direction == LEFT_SIDE;
 +}
@@ -13980,7 +13678,7 @@ Index: linux-2.6.16/fs/reiser4/flush.c
 +      }
 +      /* This loop expects to start at a formatted position and performs chaining of
 +         formatted regions */
-+      while (!scan_finished(scan)) {
++      while (!reiser4_scan_finished(scan)) {
 +
 +              ret = scan_formatted(scan);
 +              if (ret != 0) {
@@ -14017,7 +13715,7 @@ Index: linux-2.6.16/fs/reiser4/flush.c
 +               * there is already lock held by this thread,
 +               * jnode_lock_parent_coord() should use try-lock.
 +               */
-+              try = scanning_left(scan)
++              try = reiser4_scanning_left(scan)
 +                  && !lock_stack_isclean(get_current_lock_stack());
 +              /* Need the node locked to get the parent lock, We have to
 +                 take write lock since there is at least one call path
@@ -14025,7 +13723,8 @@ Index: linux-2.6.16/fs/reiser4/flush.c
 +              ret =
 +                  longterm_lock_znode(&lock, JZNODE(scan->node),
 +                                      ZNODE_WRITE_LOCK,
-+                                      scanning_left(scan) ? ZNODE_LOCK_LOPRI :
++                                      reiser4_scanning_left(scan) ?
++                                      ZNODE_LOCK_LOPRI :
 +                                      ZNODE_LOCK_HIPRI);
 +              if (ret != 0)
 +                      /* EINVAL or E_DEADLOCK here mean... try again!  At this point we've
@@ -14087,7 +13786,7 @@ Index: linux-2.6.16/fs/reiser4/flush.c
 +      int ret;
 +      znode *neighbor = NULL;
 +
-+      assert("jmacd-1401", !scan_finished(scan));
++      assert("jmacd-1401", !reiser4_scan_finished(scan));
 +
 +      do {
 +              znode *node = JZNODE(scan->node);
@@ -14105,7 +13804,8 @@ Index: linux-2.6.16/fs/reiser4/flush.c
 +                 left sibling while the tree lock is released, but the flush-scan count
 +                 does not need to be precise.  Thus, we release the tree lock as soon as
 +                 we get the neighboring node. */
-+              neighbor = scanning_left(scan) ? node->left : node->right;
++              neighbor =
++                      reiser4_scanning_left(scan) ? node->left : node->right;
 +              if (neighbor != NULL) {
 +                      zref(neighbor);
 +              }
@@ -14120,7 +13820,7 @@ Index: linux-2.6.16/fs/reiser4/flush.c
 +
 +              /* Check the condition for going left, break if it is not met.  This also
 +                 releases (jputs) the neighbor if false. */
-+              if (!scan_goto(scan, ZJNODE(neighbor))) {
++              if (!reiser4_scan_goto(scan, ZJNODE(neighbor))) {
 +                      break;
 +              }
 +
@@ -14130,13 +13830,13 @@ Index: linux-2.6.16/fs/reiser4/flush.c
 +                      return ret;
 +              }
 +
-+      } while (!scan_finished(scan));
++      } while (!reiser4_scan_finished(scan));
 +
 +      /* If neighbor is NULL then we reached the end of a formatted region, or else the
 +         sibling is out of memory, now check for an extent to the left (as long as
 +         LEAF_LEVEL). */
 +      if (neighbor != NULL || jnode_get_level(scan->node) != LEAF_LEVEL
-+          || scan_finished(scan)) {
++          || reiser4_scan_finished(scan)) {
 +              scan->stop = 1;
 +              return 0;
 +      }
@@ -14171,7 +13871,7 @@ Index: linux-2.6.16/fs/reiser4/flush.c
 +      /* set initial item id */
 +      iplug = item_plugin_by_coord(&scan->parent_coord);
 +
-+      for (; !scan_finished(scan); scan_this_coord = 1) {
++      for (; !reiser4_scan_finished(scan); scan_this_coord = 1) {
 +              if (scan_this_coord) {
 +                      /* Here we expect that unit is scannable. it would not be so due
 +                       * to race with extent->tail conversion.  */
@@ -14186,7 +13886,7 @@ Index: linux-2.6.16/fs/reiser4/flush.c
 +                      if (ret != 0)
 +                              goto exit;
 +
-+                      if (scan_finished(scan)) {
++                      if (reiser4_scan_finished(scan)) {
 +                              checkchild(scan);
 +                              break;
 +                      }
@@ -14222,10 +13922,13 @@ Index: linux-2.6.16/fs/reiser4/flush.c
 +              if (coord_is_after_sideof_unit(&next_coord, scan->direction)) {
 +                      /* We take the write lock because we may start flushing from this
 +                       * coordinate. */
-+                      ret =
-+                          neighbor_in_slum(next_coord.node, &next_lock,
-+                                           scan->direction, ZNODE_WRITE_LOCK,
-+                                           1 /* check dirty */ );
++                      ret = neighbor_in_slum(next_coord.node,
++                                             &next_lock,
++                                             scan->direction,
++                                             ZNODE_WRITE_LOCK,
++                                             1 /* check dirty */,
++                                             0 /* don't go though upper
++                                                  levels */);
 +                      if (ret == -E_NO_NEIGHBOR) {
 +                              scan->stop = 1;
 +                              ret = 0;
@@ -14267,7 +13970,7 @@ Index: linux-2.6.16/fs/reiser4/flush.c
 +                     || jnode_is_znode(child));
 +
 +              /* See if it is dirty, part of the same atom. */
-+              if (!scan_goto(scan, child)) {
++              if (!reiser4_scan_goto(scan, child)) {
 +                      checkchild(scan);
 +                      break;
 +              }
@@ -14290,7 +13993,8 @@ Index: linux-2.6.16/fs/reiser4/flush.c
 +              }
 +      }
 +
-+      assert("jmacd-6233", scan_finished(scan) || jnode_is_znode(scan->node));
++      assert("jmacd-6233",
++             reiser4_scan_finished(scan) || jnode_is_znode(scan->node));
 +      exit:
 +      checkchild(scan);
 +      race:                   /* skip the above check  */
@@ -14316,7 +14020,7 @@ Index: linux-2.6.16/fs/reiser4/flush.c
 +      init_lh(&pos->lock);
 +      init_load_count(&pos->load);
 +
-+      blocknr_hint_init(&pos->preceder);
++      reiser4_blocknr_hint_init(&pos->preceder);
 +}
 +
 +/* The flush loop inside squalloc periodically checks pos_valid to
@@ -14340,7 +14044,7 @@ Index: linux-2.6.16/fs/reiser4/flush.c
 +static void pos_done(flush_pos_t * pos)
 +{
 +      pos_stop(pos);
-+      blocknr_hint_done(&pos->preceder);
++      reiser4_blocknr_hint_done(&pos->preceder);
 +      if (convert_data(pos))
 +              free_convert_data(pos);
 +}
@@ -14363,12 +14067,12 @@ Index: linux-2.6.16/fs/reiser4/flush.c
 +}
 +
 +/* Return the flush_position's block allocator hint. */
-+reiser4_blocknr_hint *pos_hint(flush_pos_t * pos)
++reiser4_blocknr_hint *reiser4_pos_hint(flush_pos_t * pos)
 +{
 +      return &pos->preceder;
 +}
 +
-+flush_queue_t *pos_fq(flush_pos_t * pos)
++flush_queue_t * reiser4_pos_fq(flush_pos_t * pos)
 +{
 +      return pos->fq;
 +}
@@ -14383,11 +14087,10 @@ Index: linux-2.6.16/fs/reiser4/flush.c
 +   LocalWords:  preceder
 +   End:
 +*/
-Index: linux-2.6.16/fs/reiser4/flush.h
-===================================================================
---- /dev/null
-+++ linux-2.6.16/fs/reiser4/flush.h
-@@ -0,0 +1,274 @@
+diff -urN linux-2.6.22.orig/fs/reiser4/flush.h linux-2.6.22/fs/reiser4/flush.h
+--- linux-2.6.22.orig/fs/reiser4/flush.h       1970-01-01 03:00:00.000000000 +0300
++++ linux-2.6.22/fs/reiser4/flush.h    2007-07-29 00:25:34.864693371 +0400
+@@ -0,0 +1,295 @@
 +/* Copyright 2002, 2003 by Hans Reiser, licensing governed by reiser4/README */
 +
 +/* DECLARATIONS: */
@@ -14446,19 +14149,19 @@ Index: linux-2.6.16/fs/reiser4/flush.h
 +      reiser4_block_nr preceder_blk;
 +};
 +
-+typedef struct convert_item_info {
++struct convert_item_info {
 +      dc_item_stat d_cur;     /* disk cluster state of the current item */
 +      dc_item_stat d_next;    /* disk cluster state of the next slum item */
 +      struct inode *inode;
 +      flow_t flow;
-+} convert_item_info_t;
++};
 +
-+typedef struct convert_info {
++struct convert_info {
 +      int count;              /* for squalloc terminating */
-+      reiser4_cluster_t clust;        /* transform cluster */
 +      item_plugin *iplug;     /* current item plugin */
-+      convert_item_info_t *itm;       /* current item info */
-+} convert_info_t;
++      struct convert_item_info *itm;  /* current item info */
++      struct cluster_handle clust;    /* transform cluster */
++};
 +
 +typedef enum flush_position_state {
 +      POS_INVALID,            /* Invalid or stopped pos, do not continue slum
@@ -14498,7 +14201,7 @@ Index: linux-2.6.16/fs/reiser4/flush.h
 +
 +      znode *prev_twig;       /* previous parent pointer value, used to catch
 +                               * processing of new twig node */
-+      convert_info_t *sq;     /* convert info */
++      struct convert_info *sq;        /* convert info */
 +
 +      unsigned long pos_in_unit;      /* for extents only. Position
 +                                         within an extent unit of first
@@ -14523,26 +14226,27 @@ Index: linux-2.6.16/fs/reiser4/flush.h
 +      return pos->sq->iplug;
 +}
 +
-+static inline convert_info_t *convert_data(flush_pos_t * pos)
++static inline struct convert_info *convert_data(flush_pos_t * pos)
 +{
 +      return pos->sq;
 +}
 +
-+static inline convert_item_info_t *item_convert_data(flush_pos_t * pos)
++static inline struct convert_item_info *item_convert_data(flush_pos_t * pos)
 +{
 +      assert("edward-955", convert_data(pos));
 +      return pos->sq->itm;
 +}
 +
-+static inline tfm_cluster_t *tfm_cluster_sq(flush_pos_t * pos)
++static inline struct tfm_cluster * tfm_cluster_sq(flush_pos_t * pos)
 +{
 +      return &pos->sq->clust.tc;
 +}
 +
-+static inline tfm_stream_t *tfm_stream_sq(flush_pos_t * pos, tfm_stream_id id)
++static inline struct tfm_stream * tfm_stream_sq(flush_pos_t * pos,
++                                              tfm_stream_id id)
 +{
 +      assert("edward-854", pos->sq != NULL);
-+      return tfm_stream(tfm_cluster_sq(pos), id);
++      return get_tfm_stream(tfm_cluster_sq(pos), id);
 +}
 +
 +static inline int chaining_data_present(flush_pos_t * pos)
@@ -14608,7 +14312,7 @@ Index: linux-2.6.16/fs/reiser4/flush.h
 +}
 +
 +/* true if there is attached convert item info */
-+static inline int should_convert_next_node(flush_pos_t * pos, znode * node)
++static inline int should_convert_next_node(flush_pos_t * pos)
 +{
 +      return convert_data(pos) && item_convert_data(pos);
 +}
@@ -14622,23 +14326,43 @@ Index: linux-2.6.16/fs/reiser4/flush.h
 +          item_convert_count(pos) >= SQUALLOC_THRESHOLD;
 +}
 +
++#if 1
++#define check_convert_info(pos)                                               \
++do {                                                                  \
++      if (unlikely(should_convert_next_node(pos))){                   \
++              warning("edward-1006", "unprocessed chained data");     \
++              printk("d_cur = %d, d_next = %d, flow.len = %llu\n",    \
++                     item_convert_data(pos)->d_cur,                   \
++                     item_convert_data(pos)->d_next,                  \
++                     item_convert_data(pos)->flow.length);            \
++              printk("inode %llu, size = %llu, cluster %lu\n",        \
++                     (unsigned long long)get_inode_oid                \
++                     (item_convert_data(pos)->inode),                 \
++                     i_size_read(item_convert_data(pos)->inode),      \
++                     convert_data(pos)->clust.index);                 \
++      }                                                               \
++} while (0)
++#else
++#define check_convert_info(pos)
++#endif /* REISER4_DEBUG */
++
 +void free_convert_data(flush_pos_t * pos);
 +/* used in extent.c */
 +int scan_set_current(flush_scan * scan, jnode * node, unsigned add_size,
 +                   const coord_t * parent);
-+int scan_finished(flush_scan * scan);
-+int scanning_left(flush_scan * scan);
-+int scan_goto(flush_scan * scan, jnode * tonode);
++int reiser4_scan_finished(flush_scan * scan);
++int reiser4_scanning_left(flush_scan * scan);
++int reiser4_scan_goto(flush_scan * scan, jnode * tonode);
 +txn_atom *atom_locked_by_fq(flush_queue_t * fq);
-+int alloc_extent(flush_pos_t *flush_pos);
++int reiser4_alloc_extent(flush_pos_t *flush_pos);
 +squeeze_result squalloc_extent(znode *left, const coord_t *, flush_pos_t *,
 +                             reiser4_key *stop_key);
-+extern int init_fqs(void);
-+extern void done_fqs(void);
++extern int reiser4_init_fqs(void);
++extern void reiser4_done_fqs(void);
 +
 +#if REISER4_DEBUG
 +
-+extern void check_fq(const txn_atom *atom);
++extern void reiser4_check_fq(const txn_atom *atom);
 +extern atomic_t flush_cnt;
 +
 +#define check_preceder(blk) \
@@ -14662,11 +14386,10 @@ Index: linux-2.6.16/fs/reiser4/flush.h
 +   LocalWords:  preceder
 +   End:
 +*/
-Index: linux-2.6.16/fs/reiser4/flush_queue.c
-===================================================================
---- /dev/null
-+++ linux-2.6.16/fs/reiser4/flush_queue.c
-@@ -0,0 +1,681 @@
+diff -urN linux-2.6.22.orig/fs/reiser4/flush_queue.c linux-2.6.22/fs/reiser4/flush_queue.c
+--- linux-2.6.22.orig/fs/reiser4/flush_queue.c 1970-01-01 03:00:00.000000000 +0300
++++ linux-2.6.22/fs/reiser4/flush_queue.c      2007-07-29 00:25:34.864693371 +0400
+@@ -0,0 +1,680 @@
 +/* Copyright 2001, 2002, 2003 by Hans Reiser, licensing governed by reiser4/README */
 +
 +#include "debug.h"
@@ -14771,21 +14494,20 @@ Index: linux-2.6.16/fs/reiser4/flush_queue.c
 +
 +      INIT_LIST_HEAD(ATOM_FQ_LIST(fq));
 +
-+      sema_init(&fq->io_sem, 0);
++      init_waitqueue_head(&fq->wait);
 +      spin_lock_init(&fq->guard);
 +}
 +
 +/* slab for flush queues */
-+static kmem_cache_t *fq_slab;
-+
++static struct kmem_cache *fq_slab;
 +
 +/**
-+ * init_fqs - create flush queue cache
++ * reiser4_init_fqs - create flush queue cache
 + *
 + * Initializes slab cache of flush queues. It is part of reiser4 module
 + * initialization.
 + */
-+int init_fqs(void)
++int reiser4_init_fqs(void)
 +{
 +      fq_slab = kmem_cache_create("fq",
 +                                  sizeof(flush_queue_t),
@@ -14796,11 +14518,11 @@ Index: linux-2.6.16/fs/reiser4/flush_queue.c
 +}
 +
 +/**
-+ * done_fqs - delete flush queue cache
++ * reiser4_done_fqs - delete flush queue cache
 + *
 + * This is called on reiser4 module unloading or system shutdown.
 + */
-+void done_fqs(void)
++void reiser4_done_fqs(void)
 +{
 +      destroy_reiser4_cache(&fq_slab);
 +}
@@ -14860,7 +14582,7 @@ Index: linux-2.6.16/fs/reiser4/flush_queue.c
 +}
 +
 +/* */
-+void mark_jnode_queued(flush_queue_t * fq, jnode * node)
++static void mark_jnode_queued(flush_queue_t * fq, jnode * node)
 +{
 +      JF_SET(node, JNODE_FLUSH_QUEUED);
 +      count_enqueued_node(fq);
@@ -14902,15 +14624,15 @@ Index: linux-2.6.16/fs/reiser4/flush_queue.c
 +
 +              spin_unlock_atom(fq->atom);
 +
-+              assert("nikita-3013", schedulable());
++              assert("nikita-3013", reiser4_schedulable());
 +
 +              super = reiser4_get_current_sb();
 +
 +              /* FIXME: this is instead of blk_run_queues() */
-+              blk_run_address_space(get_super_fake(super)->i_mapping);
++              blk_run_address_space(reiser4_get_super_fake(super)->i_mapping);
 +
 +              if (!(super->s_flags & MS_RDONLY))
-+                      down(&fq->io_sem);
++                      wait_event(fq->wait, atomic_read(&fq->nr_submitted) == 0);
 +
 +              /* Ask the caller to re-acquire the locks and call this
 +                 function again. Note: this technique is commonly used in
@@ -14939,7 +14661,7 @@ Index: linux-2.6.16/fs/reiser4/flush_queue.c
 +      detach_fq(fq);
 +      done_fq(fq);
 +
-+      atom_send_event(atom);
++      reiser4_atom_send_event(atom);
 +
 +      return 0;
 +}
@@ -14968,7 +14690,7 @@ Index: linux-2.6.16/fs/reiser4/flush_queue.c
 +                              reiser4_handle_error();
 +
 +                      if (ret) {
-+                              fq_put(fq);
++                              reiser4_fq_put(fq);
 +                              return ret;
 +                      }
 +
@@ -14995,7 +14717,7 @@ Index: linux-2.6.16/fs/reiser4/flush_queue.c
 +                      ret = finish_all_fq(atom, &nr_io_errors);
 +                      if (ret != -EBUSY)
 +                              break;
-+                      atom_wait_event(atom);
++                      reiser4_atom_wait_event(atom);
 +              }
 +      } while (ret == -E_REPEAT);
 +
@@ -15030,7 +14752,7 @@ Index: linux-2.6.16/fs/reiser4/flush_queue.c
 +}
 +
 +/* support for atom fusion operation */
-+void fuse_fq(txn_atom *to, txn_atom *from)
++void reiser4_fuse_fq(txn_atom *to, txn_atom *from)
 +{
 +      flush_queue_t *fq;
 +
@@ -15111,9 +14833,9 @@ Index: linux-2.6.16/fs/reiser4/flush_queue.c
 +              atomic_add(nr_errors, &fq->nr_errors);
 +
 +              /* If all write requests registered in this "fq" are done we up
-+               * the semaphore. */
++               * the waiter. */
 +              if (atomic_sub_and_test(bio->bi_vcnt, &fq->nr_submitted))
-+                      up(&fq->io_sem);
++                      wake_up(&fq->wait);
 +      }
 +
 +      bio_put(bio);
@@ -15167,7 +14889,7 @@ Index: linux-2.6.16/fs/reiser4/flush_queue.c
 +      }
 +
 +      if (--atom->nr_running_queues == 0)
-+              atom_send_event(atom);
++              reiser4_atom_send_event(atom);
 +
 +      spin_unlock_atom(atom);
 +}
@@ -15177,7 +14899,7 @@ Index: linux-2.6.16/fs/reiser4/flush_queue.c
 +   @fq: flush queue object which contains jnodes we can (and will) write.
 +   @return: number of submitted blocks (>=0) if success, otherwise -- an error
 +            code (<0). */
-+int write_fq(flush_queue_t * fq, long *nr_submitted, int flags)
++int reiser4_write_fq(flush_queue_t * fq, long *nr_submitted, int flags)
 +{
 +      int ret;
 +      txn_atom *atom;
@@ -15189,7 +14911,7 @@ Index: linux-2.6.16/fs/reiser4/flush_queue.c
 +              if (atom->nr_running_queues == 0
 +                  || !(flags & WRITEOUT_SINGLE_STREAM))
 +                      break;
-+              atom_wait_event(atom);
++              reiser4_atom_wait_event(atom);
 +      }
 +
 +      atom->nr_running_queues++;
@@ -15257,13 +14979,13 @@ Index: linux-2.6.16/fs/reiser4/flush_queue.c
 +      return RETERR(-E_REPEAT);
 +}
 +
-+int fq_by_atom(txn_atom * atom, flush_queue_t ** new_fq)
++int reiser4_fq_by_atom(txn_atom * atom, flush_queue_t ** new_fq)
 +{
-+      return fq_by_atom_gfp(atom, new_fq, get_gfp_mask());
++      return fq_by_atom_gfp(atom, new_fq, reiser4_ctx_gfp_mask_get());
 +}
 +
-+/* A wrapper around fq_by_atom for getting a flush queue object for current
-+ * atom, if success fq->atom remains locked. */
++/* A wrapper around reiser4_fq_by_atom for getting a flush queue
++   object for current atom, if success fq->atom remains locked. */
 +flush_queue_t *get_fq_for_current_atom(void)
 +{
 +      flush_queue_t *fq = NULL;
@@ -15272,7 +14994,7 @@ Index: linux-2.6.16/fs/reiser4/flush_queue.c
 +
 +      do {
 +              atom = get_current_atom_locked();
-+              ret = fq_by_atom(atom, &fq);
++              ret = reiser4_fq_by_atom(atom, &fq);
 +      } while (ret == -E_REPEAT);
 +
 +      if (ret)
@@ -15281,7 +15003,7 @@ Index: linux-2.6.16/fs/reiser4/flush_queue.c
 +}
 +
 +/* Releasing flush queue object after exclusive use */
-+void fq_put_nolock(flush_queue_t *fq)
++void reiser4_fq_put_nolock(flush_queue_t *fq)
 +{
 +      assert("zam-747", fq->atom != NULL);
 +      assert("zam-902", list_empty_careful(ATOM_FQ_LIST(fq)));
@@ -15290,7 +15012,7 @@ Index: linux-2.6.16/fs/reiser4/flush_queue.c
 +      ON_DEBUG(fq->owner = NULL);
 +}
 +
-+void fq_put(flush_queue_t * fq)
++void reiser4_fq_put(flush_queue_t * fq)
 +{
 +      txn_atom *atom;
 +
@@ -15299,8 +15021,8 @@ Index: linux-2.6.16/fs/reiser4/flush_queue.c
 +
 +      assert("zam-746", atom != NULL);
 +
-+      fq_put_nolock(fq);
-+      atom_send_event(atom);
++      reiser4_fq_put_nolock(fq);
++      reiser4_atom_send_event(atom);
 +
 +      spin_unlock(&(fq->guard));
 +      spin_unlock_atom(atom);
@@ -15316,7 +15038,7 @@ Index: linux-2.6.16/fs/reiser4/flush_queue.c
 +
 +#if REISER4_DEBUG
 +
-+void check_fq(const txn_atom *atom)
++void reiser4_check_fq(const txn_atom *atom)
 +{
 +      /* check number of nodes on all atom's flush queues */
 +      flush_queue_t *fq;
@@ -15348,11 +15070,10 @@ Index: linux-2.6.16/fs/reiser4/flush_queue.c
 + * scroll-step: 1
 + * End:
 + */
-Index: linux-2.6.16/fs/reiser4/forward.h
-===================================================================
---- /dev/null
-+++ linux-2.6.16/fs/reiser4/forward.h
-@@ -0,0 +1,258 @@
+diff -urN linux-2.6.22.orig/fs/reiser4/forward.h linux-2.6.22/fs/reiser4/forward.h
+--- linux-2.6.22.orig/fs/reiser4/forward.h     1970-01-01 03:00:00.000000000 +0300
++++ linux-2.6.22/fs/reiser4/forward.h  2007-07-29 00:25:34.864693371 +0400
+@@ -0,0 +1,252 @@
 +/* Copyright 2001, 2002, 2003 by Hans Reiser, licensing governed by reiser4/README */
 +
 +/* Forward declarations. Thank you Kernighan. */
@@ -15370,11 +15091,10 @@ Index: linux-2.6.16/fs/reiser4/forward.h
 +typedef struct flow flow_t;
 +typedef struct coord coord_t;
 +typedef struct tree_access_pointer tap_t;
-+typedef struct item_coord item_coord;
-+typedef struct shift_params shift_params;
 +typedef struct reiser4_object_create_data reiser4_object_create_data;
 +typedef union reiser4_plugin reiser4_plugin;
 +typedef __u16 reiser4_plugin_id;
++typedef __u64 reiser4_plugin_groups;
 +typedef struct item_plugin item_plugin;
 +typedef struct jnode_plugin jnode_plugin;
 +typedef struct reiser4_item_data reiser4_item_data;
@@ -15392,7 +15112,6 @@ Index: linux-2.6.16/fs/reiser4/forward.h
 +typedef struct reiser4_dir_entry_desc reiser4_dir_entry_desc;
 +typedef struct reiser4_context reiser4_context;
 +typedef struct carry_level carry_level;
-+typedef struct blocknr_set blocknr_set;
 +typedef struct blocknr_set_entry blocknr_set_entry;
 +/* super_block->s_fs_info points to this */
 +typedef struct reiser4_super_info_data reiser4_super_info_data;
@@ -15414,8 +15133,6 @@ Index: linux-2.6.16/fs/reiser4/forward.h
 +
 +typedef struct ktxnmgrd_context ktxnmgrd_context;
 +
-+typedef struct reiser4_xattr_plugin reiser4_xattr_plugin;
-+
 +struct inode;
 +struct page;
 +struct file;
@@ -15597,8 +15314,6 @@ Index: linux-2.6.16/fs/reiser4/forward.h
 +      OVRWR_LIST
 +} atom_list;
 +
-+
-+
 +/* __REISER4_FORWARD_H__ */
 +#endif
 +
@@ -15611,11 +15326,10 @@ Index: linux-2.6.16/fs/reiser4/forward.h
 +   fill-column: 120
 +   End:
 +*/
-Index: linux-2.6.16/fs/reiser4/fsdata.c
-===================================================================
---- /dev/null
-+++ linux-2.6.16/fs/reiser4/fsdata.c
-@@ -0,0 +1,803 @@
+diff -urN linux-2.6.22.orig/fs/reiser4/fsdata.c linux-2.6.22/fs/reiser4/fsdata.c
+--- linux-2.6.22.orig/fs/reiser4/fsdata.c      1970-01-01 03:00:00.000000000 +0300
++++ linux-2.6.22/fs/reiser4/fsdata.c   2007-07-29 00:25:34.868694406 +0400
+@@ -0,0 +1,808 @@
 +/* Copyright 2001, 2002, 2003, 2004, 2005 by Hans Reiser, licensing governed by
 + * reiser4/README */
 +
@@ -15624,7 +15338,7 @@ Index: linux-2.6.16/fs/reiser4/fsdata.c
 +
 +
 +/* cache or dir_cursors */
-+static kmem_cache_t *d_cursor_cache;
++static struct kmem_cache *d_cursor_cache;
 +static struct shrinker *d_cursor_shrinker;
 +
 +/* list of unused cursors */
@@ -15672,12 +15386,12 @@ Index: linux-2.6.16/fs/reiser4/fsdata.c
 +}
 +
 +/**
-+ * init_d_cursor - create d_cursor cache
++ * reiser4_init_d_cursor - create d_cursor cache
 + *
 + * Initializes slab cache of d_cursors. It is part of reiser4 module
 + * initialization.
 + */
-+int init_d_cursor(void)
++int reiser4_init_d_cursor(void)
 +{
 +      d_cursor_cache = kmem_cache_create("d_cursor", sizeof(dir_cursor), 0,
 +                                         SLAB_HWCACHE_ALIGN, NULL, NULL);
@@ -15702,11 +15416,11 @@ Index: linux-2.6.16/fs/reiser4/fsdata.c
 +}
 +
 +/**
-+ * done_d_cursor - delete d_cursor cache and d_cursor shrinker
++ * reiser4_done_d_cursor - delete d_cursor cache and d_cursor shrinker
 + *
 + * This is called on reiser4 module unloading or system shutdown.
 + */
-+void done_d_cursor(void)
++void reiser4_done_d_cursor(void)
 +{
 +      BUG_ON(d_cursor_shrinker == NULL);
 +      remove_shrinker(d_cursor_shrinker);
@@ -15718,13 +15432,14 @@ Index: linux-2.6.16/fs/reiser4/fsdata.c
 +#define D_CURSOR_TABLE_SIZE (256)
 +
 +static inline unsigned long
-+d_cursor_hash(d_cursor_hash_table *table, const d_cursor_key *key)
++d_cursor_hash(d_cursor_hash_table *table, const struct d_cursor_key *key)
 +{
 +      assert("nikita-3555", IS_POW(D_CURSOR_TABLE_SIZE));
 +      return (key->oid + key->cid) & (D_CURSOR_TABLE_SIZE - 1);
 +}
 +
-+static inline int d_cursor_eq(const d_cursor_key *k1, const d_cursor_key *k2)
++static inline int d_cursor_eq(const struct d_cursor_key *k1,
++                            const struct d_cursor_key *k2)
 +{
 +      return k1->cid == k2->cid && k1->oid == k2->oid;
 +}
@@ -15733,40 +15448,41 @@ Index: linux-2.6.16/fs/reiser4/fsdata.c
 + * define functions to manipulate reiser4 super block's hash table of
 + * dir_cursors
 + */
-+#define KMALLOC(size) kmalloc((size), get_gfp_mask())
++#define KMALLOC(size) kmalloc((size), reiser4_ctx_gfp_mask_get())
 +#define KFREE(ptr, size) kfree(ptr)
 +TYPE_SAFE_HASH_DEFINE(d_cursor,
 +                    dir_cursor,
-+                    d_cursor_key, key, hash, d_cursor_hash, d_cursor_eq);
++                    struct d_cursor_key,
++                    key, hash, d_cursor_hash, d_cursor_eq);
 +#undef KFREE
 +#undef KMALLOC
 +
 +/**
-+ * init_super_d_info - initialize per-super-block d_cursor resources
++ * reiser4_init_super_d_info - initialize per-super-block d_cursor resources
 + * @super: super block to initialize
 + *
 + * Initializes per-super-block d_cursor's hash table and radix tree. It is part
 + * of mount.
 + */
-+int init_super_d_info(struct super_block *super)
++int reiser4_init_super_d_info(struct super_block *super)
 +{
-+      d_cursor_info *p;
++      struct d_cursor_info *p;
 +
 +      p = &get_super_private(super)->d_info;
 +
-+      INIT_RADIX_TREE(&p->tree, get_gfp_mask());
++      INIT_RADIX_TREE(&p->tree, reiser4_ctx_gfp_mask_get());
 +      return d_cursor_hash_init(&p->table, D_CURSOR_TABLE_SIZE);
 +}
 +
 +/**
-+ * done_super_d_info - release per-super-block d_cursor resources
++ * reiser4_done_super_d_info - release per-super-block d_cursor resources
 + * @super: super block being umounted
 + *
 + * It is called on umount. Kills all directory cursors attached to suoer block.
 + */
-+void done_super_d_info(struct super_block *super)
++void reiser4_done_super_d_info(struct super_block *super)
 +{
-+      d_cursor_info *d_info;
++      struct d_cursor_info *d_info;
 +      dir_cursor *cursor, *next;
 +
 +      d_info = &get_super_private(super)->d_info;
@@ -15851,7 +15567,7 @@ Index: linux-2.6.16/fs/reiser4/fsdata.c
 +/*
 + * return d_cursor data for the file system @inode is in.
 + */
-+static inline d_cursor_info *d_info(struct inode *inode)
++static inline struct d_cursor_info *d_info(struct inode *inode)
 +{
 +      return &get_super_private(inode->i_sb)->d_info;
 +}
@@ -15859,7 +15575,8 @@ Index: linux-2.6.16/fs/reiser4/fsdata.c
 +/*
 + * lookup d_cursor in the per-super-block radix tree.
 + */
-+static inline dir_cursor *lookup(d_cursor_info * info, unsigned long index)
++static inline dir_cursor *lookup(struct d_cursor_info * info,
++                               unsigned long index)
 +{
 +      return (dir_cursor *) radix_tree_lookup(&info->tree, index);
 +}
@@ -15943,9 +15660,9 @@ Index: linux-2.6.16/fs/reiser4/fsdata.c
 +       * cursor. */
 +      fsdata = create_fsdata(NULL);
 +      if (fsdata != NULL) {
-+              result = radix_tree_preload(get_gfp_mask());
++              result = radix_tree_preload(reiser4_ctx_gfp_mask_get());
 +              if (result == 0) {
-+                      d_cursor_info *info;
++                      struct d_cursor_info *info;
 +                      oid_t oid;
 +
 +                      info = d_info(inode);
@@ -15999,7 +15716,7 @@ Index: linux-2.6.16/fs/reiser4/fsdata.c
 +      dir_cursor *start;
 +      struct list_head *head;
 +      reiser4_context *ctx;
-+      d_cursor_info *info;
++      struct d_cursor_info *info;
 +
 +      /* this can be called by
 +       *
@@ -16007,7 +15724,7 @@ Index: linux-2.6.16/fs/reiser4/fsdata.c
 +       *
 +       * without reiser4_context
 +       */
-+      ctx = init_context(inode->i_sb);
++      ctx = reiser4_init_context(inode->i_sb);
 +      if (IS_ERR(ctx)) {
 +              warning("vs-23", "failed to init context");
 +              return;
@@ -16066,38 +15783,38 @@ Index: linux-2.6.16/fs/reiser4/fsdata.c
 +}
 +
 +/**
-+ * dispose_cursors - removes cursors from inode's list
++ * reiser4_dispose_cursors - removes cursors from inode's list
 + * @inode: inode to dispose cursors of
 + *
 + * For each of cursors corresponding to @inode - removes reiser4_file_fsdata
 + * attached to cursor from inode's readdir list. This is called when inode is
 + * removed from the memory by memory pressure.
 + */
-+void dispose_cursors(struct inode *inode)
++void reiser4_dispose_cursors(struct inode *inode)
 +{
 +      process_cursors(inode, CURSOR_DISPOSE);
 +}
 +
 +/**
-+ * load_cursors - attach cursors to inode
++ * reiser4_load_cursors - attach cursors to inode
 + * @inode: inode to load cursors to
 + *
 + * For each of cursors corresponding to @inode - attaches reiser4_file_fsdata
 + * attached to cursor to inode's readdir list. This is done when inode is
 + * loaded into memory.
 + */
-+void load_cursors(struct inode *inode)
++void reiser4_load_cursors(struct inode *inode)
 +{
 +      process_cursors(inode, CURSOR_LOAD);
 +}
 +
 +/**
-+ * kill_cursors - kill all inode cursors
++ * reiser4_kill_cursors - kill all inode cursors
 + * @inode: inode to kill cursors of
 + *
 + * Frees all cursors for this inode. This is called when inode is destroyed.
 + */
-+void kill_cursors(struct inode *inode)
++void reiser4_kill_cursors(struct inode *inode)
 +{
 +      process_cursors(inode, CURSOR_KILL);
 +}
@@ -16116,14 +15833,14 @@ Index: linux-2.6.16/fs/reiser4/fsdata.c
 +}
 +
 +/**
-+ * get_dir_fpos -
++ * reiser4_get_dir_fpos -
 + * @dir:
 + *
 + * Calculates ->fpos from user-supplied cookie. Normally it is dir->f_pos, but
 + * in the case of stateless directory operation (readdir-over-nfs), client id
 + * was encoded in the high bits of cookie and should me masked off.
 + */
-+loff_t get_dir_fpos(struct file *dir)
++loff_t reiser4_get_dir_fpos(struct file *dir)
 +{
 +      if (file_is_stateless(dir))
 +              return dir->f_pos & CID_MASK;
@@ -16132,13 +15849,13 @@ Index: linux-2.6.16/fs/reiser4/fsdata.c
 +}
 +
 +/**
-+ * try_to_attach_fsdata - ???
++ * reiser4_attach_fsdata - try to attach fsdata
 + * @file:
 + * @inode:
 + *
 + * Finds or creates cursor for readdir-over-nfs.
 + */
-+int try_to_attach_fsdata(struct file *file, struct inode *inode)
++int reiser4_attach_fsdata(struct file *file, struct inode *inode)
 +{
 +      loff_t pos;
 +      int result;
@@ -16157,14 +15874,15 @@ Index: linux-2.6.16/fs/reiser4/fsdata.c
 +               * first call to readdir (or rewind to the beginning of
 +               * directory)
 +               */
-+              cursor = kmem_cache_alloc(d_cursor_cache, get_gfp_mask());
++              cursor = kmem_cache_alloc(d_cursor_cache,
++                                        reiser4_ctx_gfp_mask_get());
 +              if (cursor != NULL)
 +                      result = insert_cursor(cursor, file, inode);
 +              else
 +                      result = RETERR(-ENOMEM);
 +      } else {
 +              /* try to find existing cursor */
-+              d_cursor_key key;
++              struct d_cursor_key key;
 +
 +              key.cid = pos >> CID_SHIFT;
 +              key.oid = get_inode_oid(inode);
@@ -16193,12 +15911,12 @@ Index: linux-2.6.16/fs/reiser4/fsdata.c
 +}
 +
 +/**
-+ * detach_fsdata - ???
++ * reiser4_detach_fsdata - ???
 + * @file:
 + *
 + * detach fsdata, if necessary
 + */
-+void detach_fsdata(struct file *file)
++void reiser4_detach_fsdata(struct file *file)
 +{
 +      struct inode *inode;
 +
@@ -16212,33 +15930,33 @@ Index: linux-2.6.16/fs/reiser4/fsdata.c
 +}
 +
 +/* slab for reiser4_dentry_fsdata */
-+static kmem_cache_t *dentry_fsdata_cache;
++static struct kmem_cache *dentry_fsdata_cache;
 +
 +/**
-+ * init_dentry_fsdata - create cache of dentry_fsdata
++ * reiser4_init_dentry_fsdata - create cache of dentry_fsdata
 + *
 + * Initializes slab cache of structures attached to denty->d_fsdata. It is
 + * part of reiser4 module initialization.
 + */
-+int init_dentry_fsdata(void)
++int reiser4_init_dentry_fsdata(void)
 +{
 +      dentry_fsdata_cache = kmem_cache_create("dentry_fsdata",
-+                                              sizeof(reiser4_dentry_fsdata),
-+                                              0,
-+                                              SLAB_HWCACHE_ALIGN |
-+                                              SLAB_RECLAIM_ACCOUNT, NULL,
-+                                              NULL);
++                                         sizeof(struct reiser4_dentry_fsdata),
++                                         0,
++                                         SLAB_HWCACHE_ALIGN |
++                                         SLAB_RECLAIM_ACCOUNT, NULL,
++                                         NULL);
 +      if (dentry_fsdata_cache == NULL)
 +              return RETERR(-ENOMEM);
 +      return 0;
 +}
 +
 +/**
-+ * done_dentry_fsdata - delete cache of dentry_fsdata
++ * reiser4_done_dentry_fsdata - delete cache of dentry_fsdata
 + *
 + * This is called on reiser4 module unloading or system shutdown.
 + */
-+void done_dentry_fsdata(void)
++void reiser4_done_dentry_fsdata(void)
 +{
 +      destroy_reiser4_cache(&dentry_fsdata_cache);
 +}
@@ -16250,16 +15968,17 @@ Index: linux-2.6.16/fs/reiser4/fsdata.c
 + * Allocates if necessary and returns per-dentry data that we attach to each
 + * dentry.
 + */
-+reiser4_dentry_fsdata *reiser4_get_dentry_fsdata(struct dentry *dentry)
++struct reiser4_dentry_fsdata *reiser4_get_dentry_fsdata(struct dentry *dentry)
 +{
 +      assert("nikita-1365", dentry != NULL);
 +
 +      if (dentry->d_fsdata == NULL) {
 +              dentry->d_fsdata = kmem_cache_alloc(dentry_fsdata_cache,
-+                                                  get_gfp_mask());
++                                                  reiser4_ctx_gfp_mask_get());
 +              if (dentry->d_fsdata == NULL)
 +                      return ERR_PTR(RETERR(-ENOMEM));
-+              memset(dentry->d_fsdata, 0, sizeof(reiser4_dentry_fsdata));
++              memset(dentry->d_fsdata, 0,
++                     sizeof(struct reiser4_dentry_fsdata));
 +      }
 +      return dentry->d_fsdata;
 +}
@@ -16278,17 +15997,16 @@ Index: linux-2.6.16/fs/reiser4/fsdata.c
 +      }
 +}
 +
-+
 +/* slab for reiser4_file_fsdata */
-+static kmem_cache_t *file_fsdata_cache;
++static struct kmem_cache *file_fsdata_cache;
 +
 +/**
-+ * init_file_fsdata - create cache of reiser4_file_fsdata
++ * reiser4_init_file_fsdata - create cache of reiser4_file_fsdata
 + *
 + * Initializes slab cache of structures attached to file->private_data. It is
 + * part of reiser4 module initialization.
 + */
-+int init_file_fsdata(void)
++int reiser4_init_file_fsdata(void)
 +{
 +      file_fsdata_cache = kmem_cache_create("file_fsdata",
 +                                            sizeof(reiser4_file_fsdata),
@@ -16301,11 +16019,11 @@ Index: linux-2.6.16/fs/reiser4/fsdata.c
 +}
 +
 +/**
-+ * done_file_fsdata - delete cache of reiser4_file_fsdata
++ * reiser4_done_file_fsdata - delete cache of reiser4_file_fsdata
 + *
 + * This is called on reiser4 module unloading or system shutdown.
 + */
-+void done_file_fsdata(void)
++void reiser4_done_file_fsdata(void)
 +{
 +      destroy_reiser4_cache(&file_fsdata_cache);
 +}
@@ -16320,7 +16038,8 @@ Index: linux-2.6.16/fs/reiser4/fsdata.c
 +{
 +      reiser4_file_fsdata *fsdata;
 +
-+      fsdata = kmem_cache_alloc(file_fsdata_cache, get_gfp_mask());
++      fsdata = kmem_cache_alloc(file_fsdata_cache,
++                                reiser4_ctx_gfp_mask_get());
 +      if (fsdata != NULL) {
 +              memset(fsdata, 0, sizeof *fsdata);
 +              fsdata->ra1.max_window_size = VM_MAX_READAHEAD * 1024;
@@ -16419,11 +16138,10 @@ Index: linux-2.6.16/fs/reiser4/fsdata.c
 + * fill-column: 79
 + * End:
 + */
-Index: linux-2.6.16/fs/reiser4/fsdata.h
-===================================================================
---- /dev/null
-+++ linux-2.6.16/fs/reiser4/fsdata.h
-@@ -0,0 +1,218 @@
+diff -urN linux-2.6.22.orig/fs/reiser4/fsdata.h linux-2.6.22/fs/reiser4/fsdata.h
+--- linux-2.6.22.orig/fs/reiser4/fsdata.h      1970-01-01 03:00:00.000000000 +0300
++++ linux-2.6.22/fs/reiser4/fsdata.h   2007-07-29 00:25:34.868694406 +0400
+@@ -0,0 +1,205 @@
 +/* Copyright 2001, 2002, 2003 by Hans Reiser, licensing governed by
 + * reiser4/README */
 +
@@ -16455,31 +16173,31 @@ Index: linux-2.6.16/fs/reiser4/fsdata.h
 + */
 +
 +/* logical position within directory */
-+typedef struct {
++struct dir_pos {
 +      /* key of directory entry (actually, part of a key sufficient to
 +         identify directory entry)  */
 +      de_id dir_entry_key;
 +      /* ordinal number of directory entry among all entries with the same
 +         key. (Starting from 0.) */
 +      unsigned pos;
-+} dir_pos;
++};
 +
-+typedef struct {
++struct readdir_pos {
 +      /* f_pos corresponding to this readdir position */
 +      __u64 fpos;
 +      /* logical position within directory */
-+      dir_pos position;
++      struct dir_pos position;
 +      /* logical number of directory entry within
 +         directory  */
 +      __u64 entry_no;
-+} readdir_pos;
++};
 +
 +/*
 + * this is used to speed up lookups for directory entry: on initial call to
 + * ->lookup() seal and coord of directory entry (if found, that is) are stored
 + * in struct dentry and reused later to avoid tree traversals.
 + */
-+typedef struct de_location {
++struct de_location {
 +      /* seal covering directory entry */
 +      seal_t entry_seal;
 +      /* coord of directory entry */
@@ -16487,7 +16205,7 @@ Index: linux-2.6.16/fs/reiser4/fsdata.h
 +      /* ordinal number of directory entry among all entries with the same
 +         key. (Starting from 0.) */
 +      int pos;
-+} de_location;
++};
 +
 +/**
 + * reiser4_dentry_fsdata - reiser4-specific data attached to dentries
@@ -16497,23 +16215,22 @@ Index: linux-2.6.16/fs/reiser4/fsdata.h
 + * Currently it only contains cached location (hint) of directory entry, but
 + * it is expected that other information will be accumulated here.
 + */
-+typedef struct reiser4_dentry_fsdata {
++struct reiser4_dentry_fsdata {
 +      /*
 +       * here will go fields filled by ->lookup() to speedup next
 +       * create/unlink, like blocknr of znode with stat-data, or key of
 +       * stat-data.
 +       */
-+      de_location dec;
++      struct de_location dec;
 +      int stateless;          /* created through reiser4_decode_fh, needs special
 +                               * treatment in readdir. */
-+} reiser4_dentry_fsdata;
++};
 +
-+extern int init_dentry_fsdata(void);
-+extern void done_dentry_fsdata(void);
-+extern reiser4_dentry_fsdata *reiser4_get_dentry_fsdata(struct dentry *);
++extern int reiser4_init_dentry_fsdata(void);
++extern void reiser4_done_dentry_fsdata(void);
++extern struct reiser4_dentry_fsdata *reiser4_get_dentry_fsdata(struct dentry *);
 +extern void reiser4_free_dentry_fsdata(struct dentry *dentry);
 +
-+
 +/**
 + * reiser4_file_fsdata - reiser4-specific data attached to file->private_data
 + *
@@ -16536,7 +16253,7 @@ Index: linux-2.6.16/fs/reiser4/fsdata.h
 +               * position in directory. It is updated each time directory is
 +               * modified
 +               */
-+              readdir_pos readdir;
++              struct readdir_pos readdir;
 +              /* head of this list is reiser4_inode->lists.readdir_list */
 +              struct list_head linkage;
 +      } dir;
@@ -16544,34 +16261,24 @@ Index: linux-2.6.16/fs/reiser4/fsdata.h
 +      struct {
 +              hint_t hint;
 +      } reg;
-+      /* */
-+      struct {
-+              /* this is called by reiser4_readpages if set */
-+              void (*readpages) (struct address_space *,
-+                                 struct list_head * pages, void *data);
-+              /* reiser4_readpaextended coord. It is set by read_extent before
-+                 calling page_cache_readahead */
-+              void *data;
-+      } ra2;
 +      struct reiser4_file_ra_state ra1;
 +
 +} reiser4_file_fsdata;
 +
-+extern int init_file_fsdata(void);
-+extern void done_file_fsdata(void);
++extern int reiser4_init_file_fsdata(void);
++extern void reiser4_done_file_fsdata(void);
 +extern reiser4_file_fsdata *reiser4_get_file_fsdata(struct file *);
 +extern void reiser4_free_file_fsdata(struct file *);
 +
-+
 +/*
 + * d_cursor is reiser4_file_fsdata not attached to struct file. d_cursors are
 + * used to address problem reiser4 has with readdir accesses via NFS. See
 + * plugin/file_ops_readdir.c for more details.
 + */
-+typedef struct {
++struct d_cursor_key{
 +      __u16 cid;
 +      __u64 oid;
-+} d_cursor_key;
++};
 +
 +/*
 + * define structures d_cursor_hash_table d_cursor_hash_link which are used to
@@ -16580,8 +16287,6 @@ Index: linux-2.6.16/fs/reiser4/fsdata.h
 +typedef struct dir_cursor dir_cursor;
 +TYPE_SAFE_HASH_DECLARE(d_cursor, dir_cursor);
 +
-+typedef struct d_cursor_info d_cursor_info;
-+
 +struct dir_cursor {
 +      int ref;
 +      reiser4_file_fsdata *fsdata;
@@ -16594,29 +16299,29 @@ Index: linux-2.6.16/fs/reiser4/fsdata.h
 +       * cursors if there are more than one cursor of the same objectid
 +       */
 +      struct list_head list;
-+      d_cursor_key key;
-+      d_cursor_info *info;
++      struct d_cursor_key key;
++      struct d_cursor_info *info;
 +      /* list of unused cursors */
 +      struct list_head alist;
 +};
 +
-+extern int init_d_cursor(void);
-+extern void done_d_cursor(void);
-+
-+extern int init_super_d_info(struct super_block *);
-+extern void done_super_d_info(struct super_block *);
++extern int reiser4_init_d_cursor(void);
++extern void reiser4_done_d_cursor(void);
 +
-+extern loff_t get_dir_fpos(struct file *);
-+extern int try_to_attach_fsdata(struct file *, struct inode *);
-+extern void detach_fsdata(struct file *);
++extern int reiser4_init_super_d_info(struct super_block *);
++extern void reiser4_done_super_d_info(struct super_block *);
 +
++extern loff_t reiser4_get_dir_fpos(struct file *);
++extern int reiser4_attach_fsdata(struct file *, struct inode *);
++extern void reiser4_detach_fsdata(struct file *);
 +
 +/* these are needed for "stateless" readdir. See plugin/file_ops_readdir.c for
 +   more details */
-+void dispose_cursors(struct inode *inode);
-+void load_cursors(struct inode *inode);
-+void kill_cursors(struct inode *inode);
-+void adjust_dir_file(struct inode *dir, const struct dentry *de, int offset, int adj);
++void reiser4_dispose_cursors(struct inode *inode);
++void reiser4_load_cursors(struct inode *inode);
++void reiser4_kill_cursors(struct inode *inode);
++void reiser4_adjust_dir_file(struct inode *dir, const struct dentry *de,
++                           int offset, int adj);
 +
 +/*
 + * this structure is embedded to reise4_super_info_data. It maintains d_cursors
@@ -16642,11 +16347,10 @@ Index: linux-2.6.16/fs/reiser4/fsdata.h
 + * fill-column: 120
 + * End:
 + */
-Index: linux-2.6.16/fs/reiser4/init_super.c
-===================================================================
---- /dev/null
-+++ linux-2.6.16/fs/reiser4/init_super.c
-@@ -0,0 +1,739 @@
+diff -urN linux-2.6.22.orig/fs/reiser4/init_super.c linux-2.6.22/fs/reiser4/init_super.c
+--- linux-2.6.22.orig/fs/reiser4/init_super.c  1970-01-01 03:00:00.000000000 +0300
++++ linux-2.6.22/fs/reiser4/init_super.c       2007-07-29 00:25:34.868694406 +0400
+@@ -0,0 +1,752 @@
 +/* Copyright by Hans Reiser, 2003 */
 +
 +#include "super.h"
@@ -16655,7 +16359,6 @@ Index: linux-2.6.16/fs/reiser4/init_super.c
 +
 +#include <linux/swap.h>
 +
-+
 +/**
 + * init_fs_info - allocate reiser4 specific super block
 + * @super: super block of filesystem
@@ -16663,11 +16366,12 @@ Index: linux-2.6.16/fs/reiser4/init_super.c
 + * Allocates and initialize reiser4_super_info_data, attaches it to
 + * super->s_fs_info, initializes structures maintaining d_cursor-s.
 + */
-+int init_fs_info(struct super_block *super)
++int reiser4_init_fs_info(struct super_block *super)
 +{
 +      reiser4_super_info_data *sbinfo;
 +
-+      sbinfo = kmalloc(sizeof(reiser4_super_info_data), get_gfp_mask());
++      sbinfo = kmalloc(sizeof(reiser4_super_info_data),
++                       reiser4_ctx_gfp_mask_get());
 +      if (!sbinfo)
 +              return RETERR(-ENOMEM);
 +
@@ -16678,34 +16382,33 @@ Index: linux-2.6.16/fs/reiser4/init_super.c
 +      ON_DEBUG(INIT_LIST_HEAD(&sbinfo->all_jnodes));
 +      ON_DEBUG(spin_lock_init(&sbinfo->all_guard));
 +
-+      sema_init(&sbinfo->delete_sema, 1);
-+      sema_init(&sbinfo->flush_sema, 1);
++      mutex_init(&sbinfo->delete_mutex);
 +      spin_lock_init(&(sbinfo->guard));
 +
 +      /*  initialize per-super-block d_cursor resources */
-+      init_super_d_info(super);
++      reiser4_init_super_d_info(super);
 +
 +      return 0;
 +}
 +
 +/**
-+ * done_fs_info - free reiser4 specific super block
++ * reiser4_done_fs_info - free reiser4 specific super block
 + * @super: super block of filesystem
 + *
 + * Performs some sanity checks, releases structures maintaining d_cursor-s,
 + * frees reiser4_super_info_data.
 + */
-+void done_fs_info(struct super_block *super)
++void reiser4_done_fs_info(struct super_block *super)
 +{
 +      assert("zam-990", super->s_fs_info != NULL);
 +
 +      /* release per-super-block d_cursor resources */
-+      done_super_d_info(super);
++      reiser4_done_super_d_info(super);
 +
 +      /* make sure that there are not jnodes already */
 +      assert("", list_empty(&get_super_private(super)->all_jnodes));
 +      assert("", get_current_context()->trans->atom == NULL);
-+      check_block_counters(super);
++      reiser4_check_block_counters(super);
 +      kfree(super->s_fs_info);
 +      super->s_fs_info = NULL;
 +}
@@ -16735,13 +16438,15 @@ Index: linux-2.6.16/fs/reiser4/init_super.c
 +      OPT_ONEOF,
 +} opt_type_t;
 +
-+typedef struct opt_bitmask_bit {
++#if 0
++struct opt_bitmask_bit {
 +      const char *bit_name;
 +      int bit_nr;
-+} opt_bitmask_bit;
++};
++#endif
 +
 +/* description of option parseable by parse_option() */
-+typedef struct opt_desc {
++struct opt_desc {
 +      /* option name.
 +
 +         parsed portion of string has a form "name=value".
@@ -16774,10 +16479,10 @@ Index: linux-2.6.16/fs/reiser4/init_super.c
 +              struct {
 +                      void *addr;
 +                      int nr_bits;
-+                      opt_bitmask_bit *bits;
++                      //struct opt_bitmask_bit *bits;
 +              } bitmask;
 +      } u;
-+} opt_desc_t;
++};
 +
 +/**
 + * parse_option - parse one option
@@ -16791,7 +16496,7 @@ Index: linux-2.6.16/fs/reiser4/init_super.c
 + * +-- opt_string
 + * Figures out option type and handles option correspondingly.
 + */
-+static int parse_option(char *opt_string, opt_desc_t *opt)
++static int parse_option(char *opt_string, struct opt_desc *opt)
 +{
 +      char *val_start;
 +      int result;
@@ -16876,7 +16581,7 @@ Index: linux-2.6.16/fs/reiser4/init_super.c
 + *
 + * Parses comma separated list of reiser4 mount options.
 + */
-+static int parse_options(char *opt_string, opt_desc_t *opts, int nr_opts)
++static int parse_options(char *opt_string, struct opt_desc *opts, int nr_opts)
 +{
 +      int result;
 +
@@ -16942,17 +16647,17 @@ Index: linux-2.6.16/fs/reiser4/init_super.c
 +#define MAX_NR_OPTIONS (30)
 +
 +/**
-+ * init_super_data - initialize reiser4 private super block
++ * reiser4_init_super_data - initialize reiser4 private super block
 + * @super: super block to initialize
 + * @opt_string: list of reiser4 mount options
 + *
 + * Sets various reiser4 parameters to default values. Parses mount options and
 + * overwrites default settings.
 + */
-+int init_super_data(struct super_block *super, char *opt_string)
++int reiser4_init_super_data(struct super_block *super, char *opt_string)
 +{
 +      int result;
-+      opt_desc_t *opts, *p;
++      struct opt_desc *opts, *p;
 +      reiser4_super_info_data *sbinfo = get_super_private(super);
 +
 +      /* initialize super, export, dentry operations */
@@ -16993,7 +16698,8 @@ Index: linux-2.6.16/fs/reiser4/init_super.c
 +      sbinfo->ra_params.flags = 0;
 +
 +      /* allocate memory for structure describing reiser4 mount options */
-+      opts = kmalloc(sizeof(opt_desc_t) * MAX_NR_OPTIONS, get_gfp_mask());
++      opts = kmalloc(sizeof(struct opt_desc) * MAX_NR_OPTIONS,
++                     reiser4_ctx_gfp_mask_get());
 +      if (opts == NULL)
 +              return RETERR(-ENOMEM);
 +
@@ -17010,9 +16716,9 @@ Index: linux-2.6.16/fs/reiser4/init_super.c
 +
 +#define PUSH_OPT(...)                         \
 +do {                                          \
-+       opt_desc_t o = __VA_ARGS__;            \
-+       OPT_ARRAY_CHECK;                       \
-+       *p ++ = o;                             \
++      struct opt_desc o = __VA_ARGS__;        \
++      OPT_ARRAY_CHECK;                        \
++      *p ++ = o;                              \
 +} while (0)
 +
 +#define PUSH_SB_FIELD_OPT(field, format) PUSH_OPT(SB_FIELD_OPT(field, format))
@@ -17088,8 +16794,6 @@ Index: linux-2.6.16/fs/reiser4/init_super.c
 +      PUSH_BIT_OPT("bsdgroups", REISER4_BSD_GID);
 +      /* turn on 32 bit times */
 +      PUSH_BIT_OPT("32bittimes", REISER4_32_BIT_TIMES);
-+      /* turn off concurrent flushing */
-+      PUSH_BIT_OPT("mtflush", REISER4_MTFLUSH);
 +      /*
 +       * Don't load all bitmap blocks at mount time, it is useful for
 +       * machines with tiny RAM and large disks.
@@ -17160,21 +16864,18 @@ Index: linux-2.6.16/fs/reiser4/init_super.c
 +              warning("nikita-2497", "optimal_io_size is too small");
 +              return RETERR(-EINVAL);
 +      }
-+
-+      /* disable single-threaded flush as it leads to deadlock */
-+      sbinfo->fs_flags |= (1 << REISER4_MTFLUSH);
 +      return result;
 +}
 +
 +/**
-+ * init_read_super - read reiser4 master super block
++ * reiser4_init_read_super - read reiser4 master super block
 + * @super: super block to fill
 + * @silent: if 0 - print warnings
 + *
 + * Reads reiser4 master super block either from predefined location or from
 + * location specified by altsuper mount option, initializes disk format plugin.
 + */
-+int init_read_super(struct super_block *super, int silent)
++int reiser4_init_read_super(struct super_block *super, int silent)
 +{
 +      struct buffer_head *super_bh;
 +      struct reiser4_master_sb *master_sb;
@@ -17303,33 +17004,33 @@ Index: linux-2.6.16/fs/reiser4/init_super.c
 +      },
 +      [PSET_COMPRESSION_MODE] = {
 +              .type = REISER4_COMPRESSION_MODE_PLUGIN_TYPE,
-+              .id = COL_16_COMPRESSION_MODE_ID
++              .id = CONVX_COMPRESSION_MODE_ID
 +      },
 +      [PSET_CLUSTER] = {
 +              .type = REISER4_CLUSTER_PLUGIN_TYPE,
 +              .id = CLUSTER_64K_ID
 +      },
-+      [PSET_REGULAR_ENTRY] = {
-+              .type = REISER4_REGULAR_PLUGIN_TYPE,
-+              .id = UF_REGULAR_ID
++      [PSET_CREATE] = {
++              .type = REISER4_FILE_PLUGIN_TYPE,
++              .id = UNIX_FILE_PLUGIN_ID
 +      }
 +};
 +
 +/* access to default plugin table */
-+static reiser4_plugin *get_default_plugin(pset_member memb)
++reiser4_plugin *get_default_plugin(pset_member memb)
 +{
 +      return plugin_by_id(default_plugins[memb].type,
 +                          default_plugins[memb].id);
 +}
 +
 +/**
-+ * init_root_inode - obtain inode of root directory
++ * reiser4_init_root_inode - obtain inode of root directory
 + * @super: super block of filesystem
 + *
 + * Obtains inode of root directory (reading it from disk), initializes plugin
 + * set it was not initialized.
 + */
-+int init_root_inode(struct super_block *super)
++int reiser4_init_root_inode(struct super_block *super)
 +{
 +      reiser4_super_info_data *sbinfo = get_super_private(super);
 +      struct inode *inode;
@@ -17349,30 +17050,46 @@ Index: linux-2.6.16/fs/reiser4/init_super.c
 +
 +      if (!is_inode_loaded(inode)) {
 +              pset_member memb;
++              plugin_set *pset;
 +
++              pset = reiser4_inode_data(inode)->pset;
 +              for (memb = 0; memb < PSET_LAST; ++memb) {
-+                      reiser4_plugin *plug;
 +
-+                      plug = get_default_plugin(memb);
-+                      result = grab_plugin_from(inode, memb, plug);
++                      if (aset_get(pset, memb) != NULL)
++                              continue;
++
++                      result = grab_plugin_pset(inode, NULL, memb);
 +                      if (result != 0)
 +                              break;
++
++                      reiser4_inode_clr_flag(inode, REISER4_SDLEN_KNOWN);
 +              }
 +
 +              if (result == 0) {
 +                      if (REISER4_DEBUG) {
-+                              plugin_set *pset;
-+
-+                              pset = reiser4_inode_data(inode)->pset;
 +                              for (memb = 0; memb < PSET_LAST; ++memb)
 +                                      assert("nikita-3500",
-+                                             pset_get(pset, memb) != NULL);
++                                             aset_get(pset, memb) != NULL);
 +                      }
 +              } else
 +                      warning("nikita-3448", "Cannot set plugins of root: %i",
 +                              result);
 +              reiser4_iget_complete(inode);
++
++              /* As the default pset kept in the root dir may has been changed
++                 (length is unknown), call update_sd. */
++              if (!reiser4_inode_get_flag(inode, REISER4_SDLEN_KNOWN)) {
++                      result = reiser4_grab_space(
++                              inode_file_plugin(inode)->estimate.update(inode),
++                              BA_CAN_COMMIT);
++
++                      if (result == 0)
++                              result = reiser4_update_sd(inode);
++
++                      all_grabbed2free();
++              }
 +      }
++
 +      super->s_maxbytes = MAX_LFS_FILESIZE;
 +      return result;
 +}
@@ -17386,11 +17103,10 @@ Index: linux-2.6.16/fs/reiser4/init_super.c
 + * fill-column: 79
 + * End:
 + */
-Index: linux-2.6.16/fs/reiser4/inode.c
-===================================================================
---- /dev/null
-+++ linux-2.6.16/fs/reiser4/inode.c
-@@ -0,0 +1,727 @@
+diff -urN linux-2.6.22.orig/fs/reiser4/inode.c linux-2.6.22/fs/reiser4/inode.c
+--- linux-2.6.22.orig/fs/reiser4/inode.c       1970-01-01 03:00:00.000000000 +0300
++++ linux-2.6.22/fs/reiser4/inode.c    2007-07-29 00:25:34.872695441 +0400
+@@ -0,0 +1,709 @@
 +/* Copyright 2001, 2002, 2003 by Hans Reiser, licensing governed by reiser4/README */
 +
 +/* Inode specific operations. */
@@ -17416,11 +17132,11 @@ Index: linux-2.6.16/fs/reiser4/inode.c
 +
 +/* return reiser4 internal tree which inode belongs to */
 +/* Audited by: green(2002.06.17) */
-+reiser4_tree *tree_by_inode(const struct inode *inode /* inode queried */ )
++reiser4_tree *reiser4_tree_by_inode(const struct inode *inode /* inode queried */ )
 +{
 +      assert("nikita-256", inode != NULL);
 +      assert("nikita-257", inode->i_sb != NULL);
-+      return get_tree(inode->i_sb);
++      return reiser4_get_tree(inode->i_sb);
 +}
 +
 +/* return reiser4-specific inode flags */
@@ -17431,21 +17147,22 @@ Index: linux-2.6.16/fs/reiser4/inode.c
 +}
 +
 +/* set reiser4-specific flag @f in @inode */
-+void inode_set_flag(struct inode *inode, reiser4_file_plugin_flags f)
++void reiser4_inode_set_flag(struct inode *inode, reiser4_file_plugin_flags f)
 +{
 +      assert("nikita-2248", inode != NULL);
 +      set_bit((int)f, inode_flags(inode));
 +}
 +
 +/* clear reiser4-specific flag @f in @inode */
-+void inode_clr_flag(struct inode *inode, reiser4_file_plugin_flags f)
++void reiser4_inode_clr_flag(struct inode *inode, reiser4_file_plugin_flags f)
 +{
 +      assert("nikita-2250", inode != NULL);
 +      clear_bit((int)f, inode_flags(inode));
 +}
 +
 +/* true if reiser4-specific flag @f is set in @inode */
-+int inode_get_flag(const struct inode *inode, reiser4_file_plugin_flags f)
++int reiser4_inode_get_flag(const struct inode *inode,
++                         reiser4_file_plugin_flags f)
 +{
 +      assert("nikita-2251", inode != NULL);
 +      return test_bit((int)f, inode_flags(inode));
@@ -17571,7 +17288,7 @@ Index: linux-2.6.16/fs/reiser4/inode.c
 +      case S_IFREG:
 +              assert("vs-46", fplug != NULL);
 +              assert("vs-43", (fplug->h.id == UNIX_FILE_PLUGIN_ID ||
-+                               fplug->h.id == CRC_FILE_PLUGIN_ID));
++                               fplug->h.id == CRYPTCOMPRESS_FILE_PLUGIN_ID));
 +              inode->i_op = &file_plugins[fplug->h.id].inode_ops;
 +              inode->i_fop = &file_plugins[fplug->h.id].file_ops;
 +              inode->i_mapping->a_ops = &file_plugins[fplug->h.id].as_ops;
@@ -17586,8 +17303,8 @@ Index: linux-2.6.16/fs/reiser4/inode.c
 +      return 0;
 +}
 +
-+/* initialize inode from disk data. Called with inode locked.
-+    Return inode locked. */
++/* Initialize inode from disk data. Called with inode locked.
++   Return inode locked. */
 +static int init_inode(struct inode *inode /* inode to intialise */ ,
 +                    coord_t * coord /* coord of stat data */ )
 +{
@@ -17617,29 +17334,12 @@ Index: linux-2.6.16/fs/reiser4/inode.c
 +      state = reiser4_inode_data(inode);
 +      /* call stat-data plugin method to load sd content into inode */
 +      result = iplug->s.sd.init_inode(inode, body, length);
-+      plugin_set_sd(&state->pset, iplug);
++      set_plugin(&state->pset, PSET_SD, item_plugin_to_plugin(iplug));
 +      if (result == 0) {
 +              result = setup_inode_ops(inode, NULL);
-+              if (result == 0 &&
-+                  inode->i_sb->s_root && inode->i_sb->s_root->d_inode) {
-+                      struct inode *root;
-+                      pset_member ind;
-+
-+                      /* take missing plugins from file-system defaults */
-+                      root = inode->i_sb->s_root->d_inode;
-+                      /* file and directory plugins are already initialized. */
-+                      for (ind = PSET_DIR + 1; ind < PSET_LAST; ++ind) {
-+                              result = grab_plugin(inode, root, ind);
-+                              if (result != 0)
-+                                      break;
-+                      }
-+                      if (result != 0) {
-+                              warning("nikita-3447",
-+                                      "Cannot set up plugins for %lli",
-+                                      (unsigned long long)
-+                                      get_inode_oid(inode));
-+                      }
-+              }
++              if (result == 0 && inode->i_sb->s_root &&
++                  inode->i_sb->s_root->d_inode)
++                      result = finish_pset(inode);
 +      }
 +      zrelse(coord->node);
 +      return result;
@@ -17676,7 +17376,7 @@ Index: linux-2.6.16/fs/reiser4/inode.c
 +              if (result == 0) {
 +                      /* initialize stat-data seal */
 +                      spin_lock_inode(inode);
-+                      seal_init(&info->sd_seal, &coord, key);
++                      reiser4_seal_init(&info->sd_seal, &coord, key);
 +                      info->sd_coord = coord;
 +                      spin_unlock_inode(inode);
 +
@@ -17688,7 +17388,7 @@ Index: linux-2.6.16/fs/reiser4/inode.c
 +                                                                        0);
 +                      /* load detached directory cursors for stateless
 +                       * directory readers (NFS). */
-+                      load_cursors(inode);
++                      reiser4_load_cursors(inode);
 +
 +                      /* Check the opened inode for consistency. */
 +                      result =
@@ -17762,35 +17462,29 @@ Index: linux-2.6.16/fs/reiser4/inode.c
 +/* hook for kmem_cache_create */
 +void loading_init_once(reiser4_inode * info)
 +{
-+      sema_init(&info->loading, 1);
++      mutex_init(&info->loading);
 +}
 +
 +/* for reiser4_alloc_inode */
 +void loading_alloc(reiser4_inode * info)
 +{
-+#if REISER4_DEBUG
-+      assert("vs-1717", down_trylock(&info->loading) == 0);
-+      up(&info->loading);
-+#endif
++      assert("vs-1717", !mutex_is_locked(&info->loading));
 +}
 +
 +/* for reiser4_destroy */
 +void loading_destroy(reiser4_inode * info)
 +{
-+#if REISER4_DEBUG
-+      assert("vs-1717", down_trylock(&info->loading) == 0);
-+      up(&info->loading);
-+#endif
++      assert("vs-1717a", !mutex_is_locked(&info->loading));
 +}
 +
-+static void loading_down(reiser4_inode * info)
++static void loading_begin(reiser4_inode * info)
 +{
-+      down(&info->loading);
++      mutex_lock(&info->loading);
 +}
 +
-+static void loading_up(reiser4_inode * info)
++static void loading_end(reiser4_inode * info)
 +{
-+      up(&info->loading);
++      mutex_unlock(&info->loading);
 +}
 +
 +/**
@@ -17800,7 +17494,7 @@ Index: linux-2.6.16/fs/reiser4/inode.c
 + * @silent:
 + *
 + * This is our helper function a la iget(). This is be called by
-+ * reiser4_lookup() and reiser4_read_super(). Return inode locked or error
++ * lookup_common() and reiser4_read_super(). Return inode locked or error
 + * encountered.
 + */
 +struct inode *reiser4_iget(struct super_block *super, const reiser4_key *key,
@@ -17825,7 +17519,7 @@ Index: linux-2.6.16/fs/reiser4/inode.c
 +              return ERR_PTR(RETERR(-ENOMEM));
 +      if (is_bad_inode(inode)) {
 +              warning("nikita-304", "Bad inode found");
-+              print_key("key", key);
++              reiser4_print_key("key", key);
 +              iput(inode);
 +              return ERR_PTR(RETERR(-EIO));
 +      }
@@ -17839,7 +17533,7 @@ Index: linux-2.6.16/fs/reiser4/inode.c
 +         is the reiser4 repacker, see repacker-related functions in
 +         plugin/item/extent.c */
 +      if (!is_inode_loaded(inode)) {
-+              loading_down(info);
++              loading_begin(info);
 +              if (!is_inode_loaded(inode)) {
 +                      /* locking: iget5_locked returns locked inode */
 +                      assert("nikita-1941", !is_inode_loaded(inode));
@@ -17851,7 +17545,7 @@ Index: linux-2.6.16/fs/reiser4/inode.c
 +                         read_inode() to read stat data from the disk */
 +                      result = read_inode(inode, key, silent);
 +              } else
-+                      loading_up(info);
++                      loading_end(info);
 +      }
 +
 +      if (inode->i_state & I_NEW)
@@ -17859,7 +17553,7 @@ Index: linux-2.6.16/fs/reiser4/inode.c
 +
 +      if (is_bad_inode(inode)) {
 +              assert("vs-1717", result != 0);
-+              loading_up(info);
++              loading_end(info);
 +              iput(inode);
 +              inode = ERR_PTR(result);
 +      } else if (REISER4_DEBUG) {
@@ -17869,8 +17563,8 @@ Index: linux-2.6.16/fs/reiser4/inode.c
 +              build_sd_key(inode, &found_key);
 +              if (!keyeq(&found_key, key)) {
 +                      warning("nikita-305", "Wrong key in sd");
-+                      print_key("sought for", key);
-+                      print_key("found", &found_key);
++                      reiser4_print_key("sought for", key);
++                      reiser4_print_key("found", &found_key);
 +              }
 +              if (inode->i_nlink == 0) {
 +                      warning("nikita-3559", "Unlinked inode found: %llu\n",
@@ -17887,8 +17581,8 @@ Index: linux-2.6.16/fs/reiser4/inode.c
 +      assert("zam-988", is_reiser4_inode(inode));
 +
 +      if (!is_inode_loaded(inode)) {
-+              inode_set_flag(inode, REISER4_LOADED);
-+              loading_up(reiser4_inode_data(inode));
++              reiser4_inode_set_flag(inode, REISER4_LOADED);
++              loading_end(reiser4_inode_data(inode));
 +      }
 +}
 +
@@ -17897,7 +17591,7 @@ Index: linux-2.6.16/fs/reiser4/inode.c
 +      assert("nikita-1934", inode != NULL);
 +
 +      /* clear LOADED bit */
-+      inode_clr_flag(inode, REISER4_LOADED);
++      reiser4_inode_clr_flag(inode, REISER4_LOADED);
 +      make_bad_inode(inode);
 +      return;
 +}
@@ -17914,14 +17608,6 @@ Index: linux-2.6.16/fs/reiser4/inode.c
 +      return reiser4_inode_data(inode)->pset->dir;
 +}
 +
-+#if 0
-+perm_plugin *inode_perm_plugin(const struct inode * inode)
-+{
-+      assert("nikita-1999", inode != NULL);
-+      return reiser4_inode_data(inode)->pset->perm;
-+}
-+#endif  /*  0  */
-+
 +formatting_plugin *inode_formatting_plugin(const struct inode * inode)
 +{
 +      assert("nikita-2000", inode != NULL);
@@ -17965,10 +17651,10 @@ Index: linux-2.6.16/fs/reiser4/inode.c
 +      return reiser4_inode_data(inode)->pset->cluster;
 +}
 +
-+regular_plugin *inode_regular_plugin(const struct inode * inode)
++file_plugin *inode_create_plugin(const struct inode * inode)
 +{
 +      assert("edward-1329", inode != NULL);
-+      return reiser4_inode_data(inode)->pset->regular_entry;
++      return reiser4_inode_data(inode)->pset->create;
 +}
 +
 +digest_plugin *inode_digest_plugin(const struct inode * inode)
@@ -17989,6 +17675,12 @@ Index: linux-2.6.16/fs/reiser4/inode.c
 +      return reiser4_inode_data(inode)->pset->dir_item;
 +}
 +
++file_plugin *child_create_plugin(const struct inode * inode)
++{
++      assert("edward-1329", inode != NULL);
++      return reiser4_inode_data(inode)->hset->create;
++}
++
 +void inode_set_extension(struct inode *inode, sd_ext_bits ext)
 +{
 +      reiser4_inode *state;
@@ -18001,23 +17693,29 @@ Index: linux-2.6.16/fs/reiser4/inode.c
 +      state->extmask |= 1 << ext;
 +      /* force re-calculation of stat-data length on next call to
 +         update_sd(). */
-+      inode_clr_flag(inode, REISER4_SDLEN_KNOWN);
++      reiser4_inode_clr_flag(inode, REISER4_SDLEN_KNOWN);
 +}
 +
-+void
-+inode_set_plugin(struct inode *inode, reiser4_plugin * plug, pset_member memb)
++void inode_clr_extension(struct inode *inode, sd_ext_bits ext)
 +{
-+      assert("nikita-2718", inode != NULL);
-+      assert("nikita-2719", plug != NULL);
++      reiser4_inode *state;
++
++      assert("vpf-1926", inode != NULL);
++      assert("vpf-1927", ext < LAST_SD_EXTENSION);
++      assert("vpf-1928", spin_inode_is_locked(inode));
 +
-+      reiser4_inode_data(inode)->plugin_mask |= (1 << memb);
++      state = reiser4_inode_data(inode);
++      state->extmask &= ~(1 << ext);
++      /* force re-calculation of stat-data length on next call to
++         update_sd(). */
++      reiser4_inode_clr_flag(inode, REISER4_SDLEN_KNOWN);
 +}
 +
 +void inode_check_scale_nolock(struct inode *inode, __u64 old, __u64 new)
 +{
 +      assert("edward-1287", inode != NULL);
 +      if (!dscale_fit(old, new))
-+              inode_clr_flag(inode, REISER4_SDLEN_KNOWN);
++              reiser4_inode_clr_flag(inode, REISER4_SDLEN_KNOWN);
 +      return;
 +}
 +
@@ -18070,7 +17768,7 @@ Index: linux-2.6.16/fs/reiser4/inode.c
 +      blk = reiser4_inode_data(inode)->vroot;
 +      spin_unlock_inode(inode);
 +      if (!disk_addr_eq(&UBER_TREE_ADDR, &blk))
-+              result = zlook(tree_by_inode(inode), &blk);
++              result = zlook(reiser4_tree_by_inode(inode), &blk);
 +      else
 +              result = NULL;
 +      return result;
@@ -18085,7 +17783,7 @@ Index: linux-2.6.16/fs/reiser4/inode.c
 +
 +#if REISER4_DEBUG
 +
-+void inode_invariant(const struct inode *inode)
++void reiser4_inode_invariant(const struct inode *inode)
 +{
 +      assert("nikita-3077", spin_inode_is_locked(inode));
 +}
@@ -18118,11 +17816,10 @@ Index: linux-2.6.16/fs/reiser4/inode.c
 +   fill-column: 120
 +   End:
 +*/
-Index: linux-2.6.16/fs/reiser4/inode.h
-===================================================================
---- /dev/null
-+++ linux-2.6.16/fs/reiser4/inode.h
-@@ -0,0 +1,430 @@
+diff -urN linux-2.6.22.orig/fs/reiser4/inode.h linux-2.6.22/fs/reiser4/inode.h
+--- linux-2.6.22.orig/fs/reiser4/inode.h       1970-01-01 03:00:00.000000000 +0300
++++ linux-2.6.22/fs/reiser4/inode.h    2007-07-29 00:25:34.872695441 +0400
+@@ -0,0 +1,449 @@
 +/* Copyright 2001, 2002, 2003 by Hans Reiser, licensing governed by reiser4/README */
 +
 +/* Inode functions. */
@@ -18166,7 +17863,7 @@ Index: linux-2.6.16/fs/reiser4/inode.h
 +      REISER4_IMMUTABLE = 2,
 +      /* inode was read from storage */
 +      REISER4_LOADED = 3,
-+      /* this bit is set for symlinks. inode->u.generic_ip points to target
++      /* this bit is set for symlinks. inode->i_private points to target
 +         name of symlink. */
 +      REISER4_GENERIC_PTR_USED = 4,
 +      /* set if size of stat-data item for this inode is known. If this is
@@ -18182,9 +17879,10 @@ Index: linux-2.6.16/fs/reiser4/inode.h
 +       * kill-hook of tail items. It is never cleared once set. This bit is
 +       * modified and inspected under i_mutex. */
 +      REISER4_HAS_MMAP = 8,
-+
 +      REISER4_PART_MIXED = 9,
-+      REISER4_PART_IN_CONV = 10 
++      REISER4_PART_IN_CONV = 10,
++      /* This flag indicates that file plugin conversion is in progress */
++      REISER4_FILE_CONV_IN_PROGRESS = 11
 +} reiser4_file_plugin_flags;
 +
 +/* state associated with each inode.
@@ -18224,9 +17922,11 @@ Index: linux-2.6.16/fs/reiser4/inode.h
 +struct reiser4_inode {
 +      /* spin lock protecting fields of this structure. */
 +      spinlock_t guard;
-+      /* object plugins */
++      /* main plugin set that control the file
++         (see comments in plugin/plugin_set.c) */
 +      plugin_set *pset;
-+      /* plugins set for inheritance */
++      /* plugin set for inheritance
++         (see comments in plugin/plugin_set.c) */
 +      plugin_set *hset;
 +      /* high 32 bits of object id */
 +      oid_hi_t oid_hi;
@@ -18243,6 +17943,8 @@ Index: linux-2.6.16/fs/reiser4/inode.h
 +      __u64 extmask;
 +      /* bitmask of non-default plugins for this inode */
 +      __u16 plugin_mask;
++      /* bitmask of set heir plugins for this inode. */
++      __u16 heir_mask;
 +      union {
 +              struct list_head readdir_list;
 +              struct list_head not_used;
@@ -18251,11 +17953,16 @@ Index: linux-2.6.16/fs/reiser4/inode.h
 +      unsigned long flags;
 +      union {
 +              /* fields specific to unix_file plugin */
-+              unix_file_info_t unix_file_info;
-+              /* fields specific to cryptcompress plugin */
-+              cryptcompress_info_t cryptcompress_info;
++              struct unix_file_info unix_file_info;
++              /* fields specific to cryptcompress file plugin */
++              struct cryptcompress_info cryptcompress_info;
 +      } file_plugin_data;
 +
++      /* this semaphore is to serialize readers and writers of @pset->file
++       * when file plugin conversion is enabled
++       */
++      struct rw_semaphore conv_sem;
++
 +      /* tree of jnodes. Phantom jnodes (ones not attched to any atom) are
 +         tagged in that tree by EFLUSH_TAG_ANONYMOUS */
 +      struct radix_tree_root jnodes_tree;
@@ -18267,33 +17974,33 @@ Index: linux-2.6.16/fs/reiser4/inode.h
 +      /* block number of virtual root for this object. See comment above
 +       * fs/reiser4/search.c:handle_vroot() */
 +      reiser4_block_nr vroot;
-+      struct semaphore loading;
++      struct mutex loading;
 +};
 +
 +void loading_init_once(reiser4_inode *);
 +void loading_alloc(reiser4_inode *);
 +void loading_destroy(reiser4_inode *);
 +
-+typedef struct reiser4_inode_object {
++struct reiser4_inode_object {
 +      /* private part */
 +      reiser4_inode p;
 +      /* generic fields not specific to reiser4, but used by VFS */
 +      struct inode vfs_inode;
-+} reiser4_inode_object;
++};
 +
 +/* return pointer to the reiser4 specific portion of @inode */
 +static inline reiser4_inode *reiser4_inode_data(const struct inode *inode
 +                                              /* inode queried */ )
 +{
 +      assert("nikita-254", inode != NULL);
-+      return &container_of(inode, reiser4_inode_object, vfs_inode)->p;
++      return &container_of(inode, struct reiser4_inode_object, vfs_inode)->p;
 +}
 +
 +static inline struct inode *inode_by_reiser4_inode(const reiser4_inode *
 +                                                 r4_inode /* inode queried */
 +                                                 )
 +{
-+      return &container_of(r4_inode, reiser4_inode_object, p)->vfs_inode;
++      return &container_of(r4_inode, struct reiser4_inode_object, p)->vfs_inode;
 +}
 +
 +/*
@@ -18366,24 +18073,23 @@ Index: linux-2.6.16/fs/reiser4/inode.h
 +#endif
 +
 +/* return inode in which @uf_info is embedded */
-+static inline struct inode *unix_file_info_to_inode(const unix_file_info_t *
-+                                                  uf_info)
++static inline struct inode *
++unix_file_info_to_inode(const struct unix_file_info * uf_info)
 +{
-+      return &container_of(uf_info, reiser4_inode_object,
++      return &container_of(uf_info, struct reiser4_inode_object,
 +                           p.file_plugin_data.unix_file_info)->vfs_inode;
 +}
 +
-+
 +extern ino_t oid_to_ino(oid_t oid) __attribute__ ((const));
 +extern ino_t oid_to_uino(oid_t oid) __attribute__ ((const));
 +
-+extern reiser4_tree *tree_by_inode(const struct inode *inode);
++extern reiser4_tree *reiser4_tree_by_inode(const struct inode *inode);
 +
 +#if REISER4_DEBUG
-+extern void inode_invariant(const struct inode *inode);
++extern void reiser4_inode_invariant(const struct inode *inode);
 +extern int inode_has_no_jnodes(reiser4_inode *);
 +#else
-+#define inode_invariant(inode) noop
++#define reiser4_inode_invariant(inode) noop
 +#endif
 +
 +static inline int spin_inode_is_locked(const struct inode *inode)
@@ -18411,7 +18117,7 @@ Index: linux-2.6.16/fs/reiser4/inode.h
 +      LOCK_CNT_INC(spin_locked_inode);
 +      LOCK_CNT_INC(spin_locked);
 +
-+      inode_invariant(inode);
++      reiser4_inode_invariant(inode);
 +}
 +
 +/**
@@ -18427,7 +18133,7 @@ Index: linux-2.6.16/fs/reiser4/inode.h
 +      assert("nikita-1375", LOCK_CNT_GTZ(spin_locked_inode));
 +      assert("nikita-1376", LOCK_CNT_GTZ(spin_locked));
 +
-+      inode_invariant(inode);
++      reiser4_inode_invariant(inode);
 +
 +      LOCK_CNT_DEC(spin_locked_inode);
 +      LOCK_CNT_DEC(spin_locked);
@@ -18435,7 +18141,6 @@ Index: linux-2.6.16/fs/reiser4/inode.h
 +      spin_unlock(&reiser4_inode_data(inode)->guard);
 +}
 +
-+
 +extern znode *inode_get_vroot(struct inode *inode);
 +extern void inode_set_vroot(struct inode *inode, znode * vroot);
 +
@@ -18447,17 +18152,17 @@ Index: linux-2.6.16/fs/reiser4/inode.h
 +extern struct inode *reiser4_iget(struct super_block *super,
 +                                const reiser4_key * key, int silent);
 +extern void reiser4_iget_complete(struct inode *inode);
-+extern void inode_set_flag(struct inode *inode, reiser4_file_plugin_flags f);
-+extern void inode_clr_flag(struct inode *inode, reiser4_file_plugin_flags f);
-+extern int inode_get_flag(const struct inode *inode,
-+                        reiser4_file_plugin_flags f);
++extern void reiser4_inode_set_flag(struct inode *inode, reiser4_file_plugin_flags f);
++extern void reiser4_inode_clr_flag(struct inode *inode, reiser4_file_plugin_flags f);
++extern int reiser4_inode_get_flag(const struct inode *inode,
++                                reiser4_file_plugin_flags f);
 +
 +/*  has inode been initialized? */
 +static inline int
 +is_inode_loaded(const struct inode *inode /* inode queried */ )
 +{
 +      assert("nikita-1120", inode != NULL);
-+      return inode_get_flag(inode, REISER4_LOADED);
++      return reiser4_inode_get_flag(inode, REISER4_LOADED);
 +}
 +
 +extern file_plugin *inode_file_plugin(const struct inode *inode);
@@ -18471,18 +18176,29 @@ Index: linux-2.6.16/fs/reiser4/inode.h
 +extern compression_mode_plugin *inode_compression_mode_plugin(const struct inode
 +                                                            *inode);
 +extern cluster_plugin *inode_cluster_plugin(const struct inode *inode);
-+extern regular_plugin *inode_regular_plugin(const struct inode *inode);
++extern file_plugin *inode_create_plugin(const struct inode *inode);
 +extern item_plugin *inode_sd_plugin(const struct inode *inode);
 +extern item_plugin *inode_dir_item_plugin(const struct inode *inode);
++extern file_plugin *child_create_plugin(const struct inode *inode);
 +
-+extern void inode_set_plugin(struct inode *inode,
-+                           reiser4_plugin * plug, pset_member memb);
 +extern void reiser4_make_bad_inode(struct inode *inode);
 +
 +extern void inode_set_extension(struct inode *inode, sd_ext_bits ext);
++extern void inode_clr_extension(struct inode *inode, sd_ext_bits ext);
 +extern void inode_check_scale(struct inode *inode, __u64 old, __u64 new);
 +extern void inode_check_scale_nolock(struct inode * inode, __u64 old, __u64 new);
 +
++#define INODE_SET_SIZE(i, value)                      \
++({                                                    \
++      struct inode *__i;                              \
++      typeof(value) __v;                              \
++                                                      \
++      __i = (i);                                      \
++      __v = (value);                                  \
++      inode_check_scale(__i, __i->i_size, __v);       \
++      i_size_write(__i, __v);                         \
++})
++
 +/*
 + * update field @field in inode @i to contain value @value.
 + */
@@ -18515,7 +18231,7 @@ Index: linux-2.6.16/fs/reiser4/inode.h
 +      -- __i->field;                                          \
 +})
 +
-+/* See comment before readdir_common() for description. */
++/* See comment before reiser4_readdir_common() for description. */
 +static inline struct list_head *get_readdir_list(const struct inode *inode)
 +{
 +      return &reiser4_inode_data(inode)->lists.readdir_list;
@@ -18553,10 +18269,9 @@ Index: linux-2.6.16/fs/reiser4/inode.h
 +   fill-column: 120
 +   End:
 +*/
-Index: linux-2.6.16/fs/reiser4/ioctl.h
-===================================================================
---- /dev/null
-+++ linux-2.6.16/fs/reiser4/ioctl.h
+diff -urN linux-2.6.22.orig/fs/reiser4/ioctl.h linux-2.6.22/fs/reiser4/ioctl.h
+--- linux-2.6.22.orig/fs/reiser4/ioctl.h       1970-01-01 03:00:00.000000000 +0300
++++ linux-2.6.22/fs/reiser4/ioctl.h    2007-07-29 00:25:34.872695441 +0400
 @@ -0,0 +1,41 @@
 +/* Copyright 2001, 2002, 2003 by Hans Reiser, licensing governed by
 + * reiser4/README */
@@ -18599,11 +18314,10 @@ Index: linux-2.6.16/fs/reiser4/ioctl.h
 +   scroll-step: 1
 +   End:
 +*/
-Index: linux-2.6.16/fs/reiser4/jnode.c
-===================================================================
---- /dev/null
-+++ linux-2.6.16/fs/reiser4/jnode.c
-@@ -0,0 +1,1921 @@
+diff -urN linux-2.6.22.orig/fs/reiser4/jnode.c linux-2.6.22/fs/reiser4/jnode.c
+--- linux-2.6.22.orig/fs/reiser4/jnode.c       1970-01-01 03:00:00.000000000 +0300
++++ linux-2.6.22/fs/reiser4/jnode.c    2007-07-29 00:25:34.876696477 +0400
+@@ -0,0 +1,1924 @@
 +/* Copyright 2001, 2002, 2003, 2004 by Hans Reiser, licensing governed by
 + * reiser4/README */
 +/* Jnode manipulation functions. */
@@ -18725,12 +18439,11 @@ Index: linux-2.6.16/fs/reiser4/jnode.c
 +#include <linux/types.h>
 +#include <linux/slab.h>
 +#include <linux/pagemap.h>
-+#include <linux/vmalloc.h>    /* for vmalloc(), vfree() */
 +#include <linux/swap.h>
 +#include <linux/fs.h>         /* for struct address_space  */
 +#include <linux/writeback.h>  /* for inode_lock */
 +
-+static kmem_cache_t *_jnode_slab = NULL;
++static struct kmem_cache *_jnode_slab = NULL;
 +
 +static void jnode_set_type(jnode * node, jnode_type type);
 +static int jdelete(jnode * node);
@@ -18749,7 +18462,8 @@ Index: linux-2.6.16/fs/reiser4/jnode.c
 +/* hash table support */
 +
 +/* compare two jnode keys for equality. Used by hash-table macros */
-+static inline int jnode_key_eq(const jnode_key_t * k1, const jnode_key_t * k2)
++static inline int jnode_key_eq(const struct jnode_key * k1,
++                             const struct jnode_key * k2)
 +{
 +      assert("nikita-2350", k1 != NULL);
 +      assert("nikita-2351", k2 != NULL);
@@ -18758,8 +18472,8 @@ Index: linux-2.6.16/fs/reiser4/jnode.c
 +}
 +
 +/* Hash jnode by its key (inode plus offset). Used by hash-table macros */
-+static inline __u32
-+jnode_key_hashfn(j_hash_table * table, const jnode_key_t * key)
++static inline __u32 jnode_key_hashfn(j_hash_table * table,
++                                   const struct jnode_key * key)
 +{
 +      assert("nikita-2352", key != NULL);
 +      assert("nikita-3346", IS_POW(table->_buckets));
@@ -18769,10 +18483,10 @@ Index: linux-2.6.16/fs/reiser4/jnode.c
 +}
 +
 +/* The hash table definition */
-+#define KMALLOC(size) vmalloc(size)
++#define KMALLOC(size) reiser4_vmalloc(size)
 +#define KFREE(ptr, size) vfree(ptr)
-+TYPE_SAFE_HASH_DEFINE(j, jnode, jnode_key_t, key.j, link.j, jnode_key_hashfn,
-+                    jnode_key_eq);
++TYPE_SAFE_HASH_DEFINE(j, jnode, struct jnode_key, key.j, link.j,
++                    jnode_key_hashfn, jnode_key_eq);
 +#undef KFREE
 +#undef KMALLOC
 +
@@ -18897,7 +18611,7 @@ Index: linux-2.6.16/fs/reiser4/jnode.c
 +/* exported functions to allocate/free jnode objects outside this file */
 +jnode *jalloc(void)
 +{
-+      jnode *jal = kmem_cache_alloc(_jnode_slab, get_gfp_mask());
++      jnode *jal = kmem_cache_alloc(_jnode_slab, reiser4_ctx_gfp_mask_get());
 +      return jal;
 +}
 +
@@ -18977,7 +18691,7 @@ Index: linux-2.6.16/fs/reiser4/jnode.c
 +/* look for jnode with given mapping and offset within hash table */
 +jnode *jlookup(reiser4_tree * tree, oid_t objectid, unsigned long index)
 +{
-+      jnode_key_t jkey;
++      struct jnode_key jkey;
 +      jnode *node;
 +
 +      assert("nikita-2353", tree != NULL);
@@ -19016,7 +18730,7 @@ Index: linux-2.6.16/fs/reiser4/jnode.c
 +      jnode *node;
 +
 +      assert("vs-1694", mapping->host != NULL);
-+      tree = tree_by_inode(mapping->host);
++      tree = reiser4_tree_by_inode(mapping->host);
 +
 +      read_lock_tree(tree);
 +      node = jfind_nolock(mapping, index);
@@ -19128,7 +18842,7 @@ Index: linux-2.6.16/fs/reiser4/jnode.c
 +
 +/* remove jnode from hash table and from inode's tree of jnodes. This is used in
 +   reiser4_invalidatepage and in kill_hook_extent -> truncate_inode_jnodes ->
-+   uncapture_jnode */
++   reiser4_uncapture_jnode */
 +void unhash_unformatted_jnode(jnode * node)
 +{
 +      assert("vs-1445", jnode_is_unformatted(node));
@@ -19143,8 +18857,9 @@ Index: linux-2.6.16/fs/reiser4/jnode.c
 + * allocate new jnode, insert it, and also insert into radix tree for the
 + * given inode/mapping.
 + */
-+jnode *find_get_jnode(reiser4_tree * tree, struct address_space *mapping,
-+                    oid_t oid, unsigned long index)
++static jnode *find_get_jnode(reiser4_tree * tree,
++                           struct address_space *mapping,
++                           oid_t oid, unsigned long index)
 +{
 +      jnode *result;
 +      jnode *shadow;
@@ -19155,7 +18870,7 @@ Index: linux-2.6.16/fs/reiser4/jnode.c
 +      if (unlikely(result == NULL))
 +              return ERR_PTR(RETERR(-ENOMEM));
 +
-+      preload = radix_tree_preload(get_gfp_mask());
++      preload = radix_tree_preload(reiser4_ctx_gfp_mask_get());
 +      if (preload != 0)
 +              return ERR_PTR(preload);
 +
@@ -19208,7 +18923,7 @@ Index: linux-2.6.16/fs/reiser4/jnode.c
 +      if (likely(result != NULL))
 +              return jref(result);
 +
-+      tree = tree_by_page(pg);
++      tree = reiser4_tree_by_page(pg);
 +
 +      /* check hash-table first */
 +      result = jfind(pg->mapping, pg->index);
@@ -19220,6 +18935,8 @@ Index: linux-2.6.16/fs/reiser4/jnode.c
 +              return result;
 +      }
 +
++      /* since page is locked, jnode should be allocated with GFP_NOFS flag */
++      reiser4_ctx_gfp_mask_force(GFP_NOFS);
 +      result = find_get_jnode(tree, pg->mapping, oid, pg->index);
 +      if (unlikely(IS_ERR(result)))
 +              return result;
@@ -19240,7 +18957,7 @@ Index: linux-2.6.16/fs/reiser4/jnode.c
 +      assert("umka-176", pg != NULL);
 +      assert("nikita-2394", PageLocked(pg));
 +
-+      result = do_jget(tree_by_page(pg), pg);
++      result = do_jget(reiser4_tree_by_page(pg), pg);
 +
 +      if (REISER4_DEBUG && !IS_ERR(result)) {
 +              assert("nikita-3210", result == jprivate(pg));
@@ -19302,6 +19019,7 @@ Index: linux-2.6.16/fs/reiser4/jnode.c
 +      page_cache_release(page);
 +}
 +
++#if 0
 +/* it is only used in one place to handle error */
 +void
 +page_detach_jnode(struct page *page, struct address_space *mapping,
@@ -19321,6 +19039,7 @@ Index: linux-2.6.16/fs/reiser4/jnode.c
 +      }
 +      unlock_page(page);
 +}
++#endif  /*  0  */
 +
 +/* return @node page locked.
 +
@@ -19392,7 +19111,7 @@ Index: linux-2.6.16/fs/reiser4/jnode.c
 +
 +/* Lock a page attached to jnode, create and attach page to jnode if it had no
 + * one. */
-+struct page *jnode_get_page_locked(jnode * node, gfp_t gfp_flags)
++static struct page *jnode_get_page_locked(jnode * node, gfp_t gfp_flags)
 +{
 +      struct page *page;
 +
@@ -19435,7 +19154,7 @@ Index: linux-2.6.16/fs/reiser4/jnode.c
 +              unlock_page(page);
 +              return 0;
 +      }
-+      return page_io(page, node, READ, get_gfp_mask());
++      return reiser4_page_io(page, node, READ, reiser4_ctx_gfp_mask_get());
 +}
 +
 +#if REISER4_DEBUG
@@ -19478,7 +19197,7 @@ Index: linux-2.6.16/fs/reiser4/jnode.c
 +      int result = 0;
 +      int parsed;
 +
-+      assert("nikita-3010", schedulable());
++      assert("nikita-3010", reiser4_schedulable());
 +
 +      prefetchw(&node->pg);
 +
@@ -19552,7 +19271,7 @@ Index: linux-2.6.16/fs/reiser4/jnode.c
 +{
 +      struct page *page;
 +
-+      page = jnode_get_page_locked(node, get_gfp_mask());
++      page = jnode_get_page_locked(node, reiser4_ctx_gfp_mask_get());
 +      if (IS_ERR(page))
 +              return PTR_ERR(page);
 +
@@ -19668,8 +19387,6 @@ Index: linux-2.6.16/fs/reiser4/jnode.c
 +              rcu_read_unlock();
 +              return;
 +      }
-+      assert("edward-1432", node->page_count == 0);
-+
 +      r_i_p = !JF_TEST_AND_SET(node, JNODE_RIP);
 +      /*
 +       * if r_i_p is true, we were first to set JNODE_RIP on this node. In
@@ -19789,7 +19506,7 @@ Index: linux-2.6.16/fs/reiser4/jnode.c
 +static struct address_space *mapping_znode(const jnode * node)
 +{
 +      /* all znodes belong to fake inode */
-+      return get_super_fake(jnode_get_tree(node)->super)->i_mapping;
++      return reiser4_get_super_fake(jnode_get_tree(node)->super)->i_mapping;
 +}
 +
 +/* ->index() method for znodes */
@@ -19945,7 +19662,7 @@ Index: linux-2.6.16/fs/reiser4/jnode.c
 +      znode *clone;
 +
 +      assert("vs-1430", jnode_is_znode(node));
-+      clone = zalloc(get_gfp_mask());
++      clone = zalloc(reiser4_ctx_gfp_mask_get());
 +      if (clone == NULL)
 +              return ERR_PTR(RETERR(-ENOMEM));
 +      zinit(clone, NULL, current_tree);
@@ -20255,7 +19972,7 @@ Index: linux-2.6.16/fs/reiser4/jnode.c
 +              jnode_free(node, jtype);
 +              /* @node is no longer valid pointer */
 +              if (page != NULL)
-+                      drop_page(page);
++                      reiser4_drop_page(page);
 +      } else {
 +              /* busy check failed: reference was acquired by concurrent
 +               * thread. */
@@ -20311,7 +20028,7 @@ Index: linux-2.6.16/fs/reiser4/jnode.c
 +              write_unlock_tree(tree);
 +              jnode_free(node, jtype);
 +              if (page != NULL) {
-+                      drop_page(page);
++                      reiser4_drop_page(page);
 +              }
 +      } else {
 +              /* busy check failed: reference was acquired by concurrent
@@ -20336,7 +20053,7 @@ Index: linux-2.6.16/fs/reiser4/jnode.c
 +   functionality (these j-nodes are not in any hash table) just for reading
 +   from and writing to disk. */
 +
-+jnode *alloc_io_head(const reiser4_block_nr * block)
++jnode *reiser4_alloc_io_head(const reiser4_block_nr * block)
 +{
 +      jnode *jal = jalloc();
 +
@@ -20350,7 +20067,7 @@ Index: linux-2.6.16/fs/reiser4/jnode.c
 +      return jal;
 +}
 +
-+void drop_io_head(jnode * node)
++void reiser4_drop_io_head(jnode * node)
 +{
 +      assert("zam-648", jnode_get_type(node) == JNODE_IO_HEAD);
 +
@@ -20458,7 +20175,7 @@ Index: linux-2.6.16/fs/reiser4/jnode.c
 +          ("%s: %p: state: %lx: [%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s], level: %i,"
 +           " block: %s, d_count: %d, x_count: %d, "
 +           "pg: %p, atom: %p, lock: %i:%i, type: %s, ", prefix, node,
-+           node->state, 
++           node->state,
 +           jnode_state_name(node, JNODE_PARSED),
 +           jnode_state_name(node, JNODE_HEARD_BANSHEE),
 +           jnode_state_name(node, JNODE_LEFT_CONNECTED),
@@ -20525,11 +20242,10 @@ Index: linux-2.6.16/fs/reiser4/jnode.c
 +   fill-column: 80
 +   End:
 +*/
-Index: linux-2.6.16/fs/reiser4/jnode.h
-===================================================================
---- /dev/null
-+++ linux-2.6.16/fs/reiser4/jnode.h
-@@ -0,0 +1,711 @@
+diff -urN linux-2.6.22.orig/fs/reiser4/jnode.h linux-2.6.22/fs/reiser4/jnode.h
+--- linux-2.6.22.orig/fs/reiser4/jnode.h       1970-01-01 03:00:00.000000000 +0300
++++ linux-2.6.22/fs/reiser4/jnode.h    2007-07-29 00:25:34.876696477 +0400
+@@ -0,0 +1,702 @@
 +/* Copyright 2001, 2002, 2003, 2004 by Hans Reiser, licensing governed by
 + * reiser4/README */
 +
@@ -20544,6 +20260,7 @@ Index: linux-2.6.16/fs/reiser4/jnode.h
 +#include "key.h"
 +#include "debug.h"
 +#include "dformat.h"
++#include "page_cache.h"
 +#include "context.h"
 +
 +#include "plugin/plugin.h"
@@ -20563,11 +20280,11 @@ Index: linux-2.6.16/fs/reiser4/jnode.h
 +/* declare hash table of znodes */
 +TYPE_SAFE_HASH_DECLARE(z, znode);
 +
-+typedef struct {
++struct jnode_key {
 +      __u64 objectid;
 +      unsigned long index;
 +      struct address_space *mapping;
-+} jnode_key_t;
++};
 +
 +/*
 +   Jnode is the "base class" of other nodes in reiser4. It is also happens to
@@ -20657,7 +20374,7 @@ Index: linux-2.6.16/fs/reiser4/jnode.h
 +              /* znodes are hashed by block number */
 +              reiser4_block_nr z;
 +              /* unformatted nodes are hashed by mapping plus offset */
-+              jnode_key_t j;
++              struct jnode_key j;
 +      } key;
 +
 +      /* THIRD CACHE LINE */
@@ -20701,9 +20418,6 @@ Index: linux-2.6.16/fs/reiser4/jnode.h
 +      /*   88 */ reiser4_plugin_id parent_item_id;
 +      /*   92 */
 +#if REISER4_DEBUG
-+      /* number of pages referenced by the jnode (meaningful while capturing of
-+         page clusters) */
-+      int page_count;
 +      /* list of all jnodes for debugging purposes. */
 +      struct list_head jnodes;
 +      /* how many times this jnode was written in one transaction */
@@ -20881,12 +20595,8 @@ Index: linux-2.6.16/fs/reiser4/jnode.h
 +extern jnode *jnode_by_page(struct page *pg) NONNULL;
 +extern jnode *jnode_of_page(struct page *pg) NONNULL;
 +void jnode_attach_page(jnode * node, struct page *pg);
-+jnode *find_get_jnode(reiser4_tree * tree,
-+                    struct address_space *mapping, oid_t oid,
-+                    unsigned long index);
 +
 +void unhash_unformatted_jnode(jnode *);
-+struct page *jnode_get_page_locked(jnode *, gfp_t gfp_flags);
 +extern jnode *page_next_jnode(jnode * node) NONNULL;
 +extern void jnode_init(jnode * node, reiser4_tree * tree, jnode_type) NONNULL;
 +extern void jnode_make_dirty(jnode * node) NONNULL;
@@ -20934,8 +20644,8 @@ Index: linux-2.6.16/fs/reiser4/jnode.h
 +}
 +
 +/* Jnode flush interface. */
-+extern reiser4_blocknr_hint *pos_hint(flush_pos_t * pos);
-+extern flush_queue_t *pos_fq(flush_pos_t * pos);
++extern reiser4_blocknr_hint *reiser4_pos_hint(flush_pos_t * pos);
++extern flush_queue_t *reiser4_pos_fq(flush_pos_t * pos);
 +
 +/* FIXME-VS: these are used in plugin/item/extent.c */
 +
@@ -21022,9 +20732,6 @@ Index: linux-2.6.16/fs/reiser4/jnode.h
 +      return atomic_read(&node->d_count) > 0;
 +}
 +
-+extern void page_detach_jnode(struct page *page,
-+                            struct address_space *mapping,
-+                            unsigned long index) NONNULL;
 +extern void page_clear_jnode(struct page *page, jnode * node) NONNULL;
 +
 +static inline void jnode_set_reloc(jnode * node)
@@ -21040,7 +20747,7 @@ Index: linux-2.6.16/fs/reiser4/jnode.h
 +
 +static inline int jload(jnode *node)
 +{
-+      return jload_gfp(node, get_gfp_mask(), 1);
++      return jload_gfp(node, reiser4_ctx_gfp_mask_get(), 1);
 +}
 +
 +extern int jinit_new(jnode *, gfp_t) NONNULL;
@@ -21051,8 +20758,8 @@ Index: linux-2.6.16/fs/reiser4/jnode.h
 +
 +void jload_prefetch(jnode *);
 +
-+extern jnode *alloc_io_head(const reiser4_block_nr * block) NONNULL;
-+extern void drop_io_head(jnode * node) NONNULL;
++extern jnode *reiser4_alloc_io_head(const reiser4_block_nr * block) NONNULL;
++extern void reiser4_drop_io_head(jnode * node) NONNULL;
 +
 +static inline reiser4_tree *jnode_get_tree(const jnode * node)
 +{
@@ -21194,7 +20901,7 @@ Index: linux-2.6.16/fs/reiser4/jnode.h
 +{
 +      assert("jmacd-509", node != NULL);
 +      assert("jmacd-510", atomic_read(&node->x_count) > 0);
-+      assert("zam-926", schedulable());
++      assert("zam-926", reiser4_schedulable());
 +      LOCK_CNT_DEC(x_refs);
 +
 +      rcu_read_lock();
@@ -21205,7 +20912,7 @@ Index: linux-2.6.16/fs/reiser4/jnode.h
 +              jput_final(node);
 +      } else
 +              rcu_read_unlock();
-+      assert("nikita-3473", schedulable());
++      assert("nikita-3473", reiser4_schedulable());
 +}
 +
 +extern void jrelse(jnode * node);
@@ -21241,11 +20948,10 @@ Index: linux-2.6.16/fs/reiser4/jnode.h
 +   fill-column: 120
 +   End:
 +*/
-Index: linux-2.6.16/fs/reiser4/kassign.c
-===================================================================
---- /dev/null
-+++ linux-2.6.16/fs/reiser4/kassign.c
-@@ -0,0 +1,659 @@
+diff -urN linux-2.6.22.orig/fs/reiser4/kassign.c linux-2.6.22/fs/reiser4/kassign.c
+--- linux-2.6.22.orig/fs/reiser4/kassign.c     1970-01-01 03:00:00.000000000 +0300
++++ linux-2.6.22/fs/reiser4/kassign.c  2007-07-29 00:25:34.880697512 +0400
+@@ -0,0 +1,661 @@
 +/* Copyright 2001, 2002, 2003, 2004 by Hans Reiser, licensing governed by
 + * reiser4/README */
 +
@@ -21465,7 +21171,7 @@ Index: linux-2.6.16/fs/reiser4/kassign.c
 +
 +      assert("nikita-2863", key != NULL);
 +      if (get_key_type(key) != KEY_FILE_NAME_MINOR)
-+              print_key("oops", key);
++              reiser4_print_key("oops", key);
 +      assert("nikita-2864", get_key_type(key) == KEY_FILE_NAME_MINOR);
 +
 +      if (REISER4_LARGE_KEY)
@@ -21510,7 +21216,7 @@ Index: linux-2.6.16/fs/reiser4/kassign.c
 +
 +/* opposite to pack_string(). Takes value produced by pack_string(), restores
 + * string encoded in it and stores result in @buf */
-+char *unpack_string(__u64 value, char *buf)
++char * reiser4_unpack_string(__u64 value, char *buf)
 +{
 +      do {
 +              *buf = value >> (64 - 8);
@@ -21531,11 +21237,13 @@ Index: linux-2.6.16/fs/reiser4/kassign.c
 +
 +      c = buf;
 +      if (REISER4_LARGE_KEY) {
-+              c = unpack_string(get_key_ordering(key) & ~fibration_mask, c);
-+              c = unpack_string(get_key_fulloid(key), c);
++              c = reiser4_unpack_string(get_key_ordering(key) &
++                                        ~fibration_mask, c);
++              c = reiser4_unpack_string(get_key_fulloid(key), c);
 +      } else
-+              c = unpack_string(get_key_fulloid(key) & ~fibration_mask, c);
-+      unpack_string(get_key_offset(key), c);
++              c = reiser4_unpack_string(get_key_fulloid(key) &
++                                        ~fibration_mask, c);
++      reiser4_unpack_string(get_key_offset(key), c);
 +      return buf;
 +}
 +
@@ -21905,10 +21613,9 @@ Index: linux-2.6.16/fs/reiser4/kassign.c
 +   fill-column: 120
 +   End:
 +*/
-Index: linux-2.6.16/fs/reiser4/kassign.h
-===================================================================
---- /dev/null
-+++ linux-2.6.16/fs/reiser4/kassign.h
+diff -urN linux-2.6.22.orig/fs/reiser4/kassign.h linux-2.6.22/fs/reiser4/kassign.h
+--- linux-2.6.22.orig/fs/reiser4/kassign.h     1970-01-01 03:00:00.000000000 +0300
++++ linux-2.6.22/fs/reiser4/kassign.h  2007-07-29 00:25:34.880697512 +0400
 @@ -0,0 +1,110 @@
 +/* Copyright 2001, 2002, 2003, 2004 by Hans Reiser, licensing governed by
 + * reiser4/README */
@@ -22004,7 +21711,7 @@ Index: linux-2.6.16/fs/reiser4/kassign.h
 +extern int is_longname_key(const reiser4_key * key);
 +extern int is_longname(const char *name, int len);
 +extern char *extract_name_from_key(const reiser4_key * key, char *buf);
-+extern char *unpack_string(__u64 value, char *buf);
++extern char *reiser4_unpack_string(__u64 value, char *buf);
 +extern void complete_entry_key(const struct inode *dir, const char *name,
 +                             int len, reiser4_key *result);
 +
@@ -22020,10 +21727,45 @@ Index: linux-2.6.16/fs/reiser4/kassign.h
 +   fill-column: 120
 +   End:
 +*/
-Index: linux-2.6.16/fs/reiser4/key.c
-===================================================================
---- /dev/null
-+++ linux-2.6.16/fs/reiser4/key.c
+diff -urN linux-2.6.22.orig/fs/reiser4/Kconfig linux-2.6.22/fs/reiser4/Kconfig
+--- linux-2.6.22.orig/fs/reiser4/Kconfig       1970-01-01 03:00:00.000000000 +0300
++++ linux-2.6.22/fs/reiser4/Kconfig    2007-07-29 00:25:34.880697512 +0400
+@@ -0,0 +1,32 @@
++config REISER4_FS
++      tristate "Reiser4 (EXPERIMENTAL)"
++      depends on EXPERIMENTAL
++      select ZLIB_INFLATE
++      select ZLIB_DEFLATE
++      select CRYPTO
++      help
++        Reiser4 is a filesystem that performs all filesystem operations
++        as atomic transactions, which means that it either performs a
++        write, or it does not, and in the event of a crash it does not
++        partially perform it or corrupt it.
++
++        It stores files in dancing trees, which are like balanced trees but
++        faster.  It packs small files together so that they share blocks
++        without wasting space.  This means you can use it to store really
++        small files.  It also means that it saves you disk space.  It avoids
++        hassling you with anachronisms like having a maximum number of
++        inodes, and wasting space if you use less than that number.
++
++        Reiser4 is a distinct filesystem type from reiserfs (V3).
++        It's therefore not possible to use reiserfs file systems
++        with reiser4.
++
++        To learn more about reiser4, go to http://www.namesys.com
++
++config REISER4_DEBUG
++      bool "Enable reiser4 debug mode"
++      depends on REISER4_FS
++      help
++        Don't use this unless you are debugging reiser4.
++
++        If unsure, say N.
+diff -urN linux-2.6.22.orig/fs/reiser4/key.c linux-2.6.22/fs/reiser4/key.c
+--- linux-2.6.22.orig/fs/reiser4/key.c 1970-01-01 03:00:00.000000000 +0300
++++ linux-2.6.22/fs/reiser4/key.c      2007-07-29 00:25:34.880697512 +0400
 @@ -0,0 +1,137 @@
 +/* Copyright 2001, 2002, 2003 by Hans Reiser, licensing governed by reiser4/README */
 +
@@ -22066,13 +21808,13 @@ Index: linux-2.6.16/fs/reiser4/key.c
 +}
 +
 +/* minimal possible key in the tree. Return pointer to the static storage. */
-+const reiser4_key *min_key(void)
++const reiser4_key *reiser4_min_key(void)
 +{
 +      return &MINIMAL_KEY;
 +}
 +
 +/* maximum possible key in the tree. Return pointer to the static storage. */
-+const reiser4_key *max_key(void)
++const reiser4_key *reiser4_max_key(void)
 +{
 +      return &MAXIMAL_KEY;
 +}
@@ -22098,7 +21840,7 @@ Index: linux-2.6.16/fs/reiser4/key.c
 +}
 +
 +/* debugging aid: print human readable information about key */
-+void print_key(const char *prefix /* prefix to print */ ,
++void reiser4_print_key(const char *prefix /* prefix to print */ ,
 +             const reiser4_key * key /* key to print */ )
 +{
 +      /* turn bold on */
@@ -22128,8 +21870,8 @@ Index: linux-2.6.16/fs/reiser4/key.c
 +                      char *c;
 +
 +                      c = buf;
-+                      c = unpack_string(get_key_ordering(key), c);
-+                      unpack_string(get_key_fulloid(key), c);
++                      c = reiser4_unpack_string(get_key_ordering(key), c);
++                      reiser4_unpack_string(get_key_fulloid(key), c);
 +                      printk("[%s", buf);
 +                      if (is_longname_key(key))
 +                              /*
@@ -22140,7 +21882,7 @@ Index: linux-2.6.16/fs/reiser4/key.c
 +                              /*
 +                               * whole name is stored in the key.
 +                               */
-+                              unpack_string(get_key_offset(key), buf);
++                              reiser4_unpack_string(get_key_offset(key), buf);
 +                              printk("%s]\n", buf);
 +                      }
 +              } else {
@@ -22162,10 +21904,9 @@ Index: linux-2.6.16/fs/reiser4/key.c
 +   fill-column: 120
 +   End:
 +*/
-Index: linux-2.6.16/fs/reiser4/key.h
-===================================================================
---- /dev/null
-+++ linux-2.6.16/fs/reiser4/key.h
+diff -urN linux-2.6.22.orig/fs/reiser4/key.h linux-2.6.22/fs/reiser4/key.h
+--- linux-2.6.22.orig/fs/reiser4/key.h 1970-01-01 03:00:00.000000000 +0300
++++ linux-2.6.22/fs/reiser4/key.h      2007-07-29 00:25:34.884698547 +0400
 @@ -0,0 +1,384 @@
 +/* Copyright 2000, 2001, 2002, 2003 by Hans Reiser, licensing governed by reiser4/README */
 +
@@ -22395,8 +22136,8 @@ Index: linux-2.6.16/fs/reiser4/key.h
 +void reiser4_key_init(reiser4_key * key);
 +
 +/* minimal possible key in the tree. Return pointer to the static storage. */
-+extern const reiser4_key *min_key(void);
-+extern const reiser4_key *max_key(void);
++extern const reiser4_key *reiser4_min_key(void);
++extern const reiser4_key *reiser4_max_key(void);
 +
 +/* helper macro for keycmp() */
 +#define KEY_DIFF(k1, k2, field)                                                       \
@@ -22534,9 +22275,9 @@ Index: linux-2.6.16/fs/reiser4/key.h
 +#define KEY_BUF_LEN (80)
 +
 +#if REISER4_DEBUG
-+extern void print_key(const char *prefix, const reiser4_key * key);
++extern void reiser4_print_key(const char *prefix, const reiser4_key * key);
 +#else
-+#define print_key(p,k) noop
++#define reiser4_print_key(p,k) noop
 +#endif
 +
 +/* __FS_REISERFS_KEY_H__ */
@@ -22551,11 +22292,10 @@ Index: linux-2.6.16/fs/reiser4/key.h
 +   fill-column: 120
 +   End:
 +*/
-Index: linux-2.6.16/fs/reiser4/ktxnmgrd.c
-===================================================================
---- /dev/null
-+++ linux-2.6.16/fs/reiser4/ktxnmgrd.c
-@@ -0,0 +1,214 @@
+diff -urN linux-2.6.22.orig/fs/reiser4/ktxnmgrd.c linux-2.6.22/fs/reiser4/ktxnmgrd.c
+--- linux-2.6.22.orig/fs/reiser4/ktxnmgrd.c    1970-01-01 03:00:00.000000000 +0300
++++ linux-2.6.22/fs/reiser4/ktxnmgrd.c 2007-07-29 00:25:34.884698547 +0400
+@@ -0,0 +1,215 @@
 +/* Copyright 2002, 2003 by Hans Reiser, licensing governed by reiser4/README */
 +/* Transaction manager daemon. */
 +
@@ -22593,6 +22333,7 @@ Index: linux-2.6.16/fs/reiser4/ktxnmgrd.c
 +#include <linux/kernel.h>
 +#include <linux/writeback.h>
 +#include <linux/kthread.h>
++#include <linux/freezer.h>
 +
 +static int scan_mgr(struct super_block *);
 +
@@ -22672,13 +22413,13 @@ Index: linux-2.6.16/fs/reiser4/ktxnmgrd.c
 +#undef set_comm
 +
 +/**
-+ * init_ktxnmgrd - initialize ktxnmgrd context and start kernel daemon
++ * reiser4_init_ktxnmgrd - initialize ktxnmgrd context and start kernel daemon
 + * @super: pointer to super block
 + *
 + * Allocates and initializes ktxnmgrd_context, attaches it to transaction
 + * manager. Starts kernel txnmgr daemon. This is called on mount.
 + */
-+int init_ktxnmgrd(struct super_block *super)
++int reiser4_init_ktxnmgrd(struct super_block *super)
 +{
 +      txn_mgr *mgr;
 +      ktxnmgrd_context *ctx;
@@ -22687,7 +22428,7 @@ Index: linux-2.6.16/fs/reiser4/ktxnmgrd.c
 +
 +      assert("zam-1014", mgr->daemon == NULL);
 +
-+      ctx = kmalloc(sizeof(ktxnmgrd_context), get_gfp_mask());
++      ctx = kmalloc(sizeof(ktxnmgrd_context), reiser4_ctx_gfp_mask_get());
 +      if (ctx == NULL)
 +              return RETERR(-ENOMEM);
 +
@@ -22744,12 +22485,12 @@ Index: linux-2.6.16/fs/reiser4/ktxnmgrd.c
 +}
 +
 +/**
-+ * done_ktxnmgrd - stop kernel thread and frees ktxnmgrd context
++ * reiser4_done_ktxnmgrd - stop kernel thread and frees ktxnmgrd context
 + * @mgr:
 + *
 + * This is called on umount. Stops ktxnmgrd and free t
 + */
-+void done_ktxnmgrd(struct super_block *super)
++void reiser4_done_ktxnmgrd(struct super_block *super)
 +{
 +      txn_mgr *mgr;
 +
@@ -22770,10 +22511,9 @@ Index: linux-2.6.16/fs/reiser4/ktxnmgrd.c
 + * fill-column: 120
 + * End:
 + */
-Index: linux-2.6.16/fs/reiser4/ktxnmgrd.h
-===================================================================
---- /dev/null
-+++ linux-2.6.16/fs/reiser4/ktxnmgrd.h
+diff -urN linux-2.6.22.orig/fs/reiser4/ktxnmgrd.h linux-2.6.22/fs/reiser4/ktxnmgrd.h
+--- linux-2.6.22.orig/fs/reiser4/ktxnmgrd.h    1970-01-01 03:00:00.000000000 +0300
++++ linux-2.6.22/fs/reiser4/ktxnmgrd.h 2007-07-29 00:25:34.884698547 +0400
 @@ -0,0 +1,52 @@
 +/* Copyright 2001, 2002, 2003 by Hans Reiser, licensing governed by
 + * reiser4/README */
@@ -22809,8 +22549,8 @@ Index: linux-2.6.16/fs/reiser4/ktxnmgrd.h
 +      unsigned int rescan:1;
 +};
 +
-+extern int init_ktxnmgrd(struct super_block *);
-+extern void done_ktxnmgrd(struct super_block *);
++extern int reiser4_init_ktxnmgrd(struct super_block *);
++extern void reiser4_done_ktxnmgrd(struct super_block *);
 +
 +extern void ktxnmgrd_kick(txn_mgr * mgr);
 +extern int is_current_ktxnmgrd(void);
@@ -22827,11 +22567,10 @@ Index: linux-2.6.16/fs/reiser4/ktxnmgrd.h
 +   fill-column: 120
 +   End:
 +*/
-Index: linux-2.6.16/fs/reiser4/lock.c
-===================================================================
---- /dev/null
-+++ linux-2.6.16/fs/reiser4/lock.c
-@@ -0,0 +1,1261 @@
+diff -urN linux-2.6.22.orig/fs/reiser4/lock.c linux-2.6.22/fs/reiser4/lock.c
+--- linux-2.6.22.orig/fs/reiser4/lock.c        1970-01-01 03:00:00.000000000 +0300
++++ linux-2.6.22/fs/reiser4/lock.c     2007-07-29 00:25:34.884698547 +0400
+@@ -0,0 +1,1232 @@
 +/* Copyright 2001, 2002, 2003 by Hans Reiser, licensing governed by
 + * reiser4/README */
 +
@@ -23039,17 +22778,17 @@ Index: linux-2.6.16/fs/reiser4/lock.c
 +
 +/* Znode lock and capturing intertwining. */
 +/* In current implementation we capture formatted nodes before locking
-+   them. Take a look on longterm lock znode, try_capture() request precedes
-+   locking requests.  The longterm_lock_znode function unconditionally captures
-+   znode before even checking of locking conditions.
++   them. Take a look on longterm lock znode, reiser4_try_capture() request
++   precedes locking requests.  The longterm_lock_znode function unconditionally
++   captures znode before even checking of locking conditions.
 +
 +   Another variant is to capture znode after locking it.  It was not tested, but
 +   at least one deadlock condition is supposed to be there.  One thread has
-+   locked a znode (Node-1) and calls try_capture() for it.  Try_capture() sleeps
-+   because znode's atom has CAPTURE_WAIT state.  Second thread is a flushing
-+   thread, its current atom is the atom Node-1 belongs to. Second thread wants
-+   to lock Node-1 and sleeps because Node-1 is locked by the first thread.  The
-+   described situation is a deadlock. */
++   locked a znode (Node-1) and calls reiser4_try_capture() for it.
++   reiser4_try_capture() sleeps because znode's atom has CAPTURE_WAIT state.
++   Second thread is a flushing thread, its current atom is the atom Node-1
++   belongs to. Second thread wants to lock Node-1 and sleeps because Node-1
++   is locked by the first thread.  The described situation is a deadlock. */
 +
 +#include "debug.h"
 +#include "txnmgr.h"
@@ -23110,7 +22849,7 @@ Index: linux-2.6.16/fs/reiser4/lock.c
 +      /* add lock handle to the end of lock_stack's list of locks */
 +      list_add_tail(&handle->locks_link, &owner->locks);
 +      ON_DEBUG(owner->nr_locks++);
-+      set_gfp_mask();
++      reiser4_ctx_gfp_mask_set();
 +
 +      /* add lock handle to the head of znode's list of owners */
 +      list_add(&handle->owners_link, &node->lock.owners);
@@ -23129,7 +22868,7 @@ Index: linux-2.6.16/fs/reiser4/lock.c
 +      /* remove lock handle from lock_stack's list of locks */
 +      list_del(&handle->locks_link);
 +      ON_DEBUG(handle->owner->nr_locks--);
-+      set_gfp_mask();
++      reiser4_ctx_gfp_mask_set();
 +      assert("reiser4-6",
 +             ergo(list_empty_careful(&handle->owner->locks),
 +                  handle->owner->nr_locks == 0));
@@ -23147,7 +22886,7 @@ Index: linux-2.6.16/fs/reiser4/lock.c
 +/* Actually locks an object knowing that we are able to do this */
 +static void lock_object(lock_stack * owner)
 +{
-+      lock_request *request;
++      struct lock_request *request;
 +      znode *node;
 +
 +      request = &owner->request;
@@ -23184,7 +22923,6 @@ Index: linux-2.6.16/fs/reiser4/lock.c
 +      assert("nikita-1841", owner == get_current_lock_stack());
 +      assert_spin_locked(&(node->lock.guard));
 +
-+
 +      lh = list_entry(node->lock.owners.next, lock_handle, owners_link);
 +      ret = (lh->owner == owner);
 +
@@ -23386,7 +23124,6 @@ Index: linux-2.6.16/fs/reiser4/lock.c
 +      list_del(&requestor->requestors_link);
 +}
 +
-+
 +static void invalidate_all_lock_requests(znode * node)
 +{
 +      lock_stack *requestor, *tmp;
@@ -23449,7 +23186,7 @@ Index: linux-2.6.16/fs/reiser4/lock.c
 +       */
 +
 +      /* was this lock of hi or lo priority */
-+      hipri = oldowner->curpri ? -1 : 0;
++      hipri = oldowner->curpri ? 1 : 0;
 +      /* number of readers */
 +      readers = node->lock.nr_readers;
 +      /* +1 if write lock, -1 if read lock */
@@ -23462,8 +23199,8 @@ Index: linux-2.6.16/fs/reiser4/lock.c
 +      assert("zam-101", znode_is_locked(node));
 +
 +      /* Adjust a number of high priority owners of this lock */
-+      node->lock.nr_hipri_owners += hipri;
-+      assert("nikita-1836", node->lock.nr_hipri_owners >= 0);
++      assert("nikita-1836", node->lock.nr_hipri_owners >= hipri);
++      node->lock.nr_hipri_owners -= hipri;
 +
 +      /* Handle znode deallocation on last write-lock release. */
 +      if (znode_is_wlocked_once(node)) {
@@ -23551,7 +23288,7 @@ Index: linux-2.6.16/fs/reiser4/lock.c
 +      node = owner->request.node;
 +      lock = &node->lock;
 +
-+      assert("nikita-3340", schedulable());
++      assert("nikita-3340", reiser4_schedulable());
 +      assert("nikita-3341", request_is_deadlock_safe(node,
 +                                                     ZNODE_READ_LOCK,
 +                                                     ZNODE_LOCK_LOPRI));
@@ -23561,7 +23298,7 @@ Index: linux-2.6.16/fs/reiser4/lock.c
 +
 +      if (likely(result != -EINVAL)) {
 +              spin_lock_znode(node);
-+              result = try_capture(ZJNODE(node), ZNODE_READ_LOCK, 0);
++              result = reiser4_try_capture(ZJNODE(node), ZNODE_READ_LOCK, 0);
 +              spin_unlock_znode(node);
 +              spin_lock_zlock(lock);
 +              if (unlikely(result != 0)) {
@@ -23605,7 +23342,7 @@ Index: linux-2.6.16/fs/reiser4/lock.c
 +      /* Check that the lock handle is initialized and isn't already being
 +       * used. */
 +      assert("jmacd-808", handle->owner == NULL);
-+      assert("nikita-3026", schedulable());
++      assert("nikita-3026", reiser4_schedulable());
 +      assert("nikita-3219", request_is_deadlock_safe(node, mode, request));
 +      assert("zam-1056", atomic_read(&ZJNODE(node)->x_count) > 0);
 +      /* long term locks are not allowed in the VM contexts (->writepage(),
@@ -23689,7 +23426,7 @@ Index: linux-2.6.16/fs/reiser4/lock.c
 +               * 1. read of aligned word is atomic with respect to writes to
 +               * this word
 +               *
-+               * 2. false negatives are handled in try_capture().
++               * 2. false negatives are handled in reiser4_try_capture().
 +               *
 +               * 3. false positives are impossible.
 +               *
@@ -23717,8 +23454,8 @@ Index: linux-2.6.16/fs/reiser4/lock.c
 +               *
 +               * Suppose node->atom == NULL, that is, node was un-captured
 +               * between T1, and T3. But un-capturing of formatted node is
-+               * always preceded by the call to invalidate_lock(), which
-+               * marks znode as JNODE_IS_DYING under zlock spin
++               * always preceded by the call to reiser4_invalidate_lock(),
++               * which marks znode as JNODE_IS_DYING under zlock spin
 +               * lock. Contradiction, because can_lock_object() above checks
 +               * for JNODE_IS_DYING. Hence, node->atom != NULL at T3.
 +               *
@@ -23741,13 +23478,13 @@ Index: linux-2.6.16/fs/reiser4/lock.c
 +                      /*
 +                       * unlock zlock spin lock here. It is possible for
 +                       * longterm_unlock_znode() to sneak in here, but there
-+                       * is no harm: invalidate_lock() will mark znode as
-+                       * JNODE_IS_DYING and this will be noted by
++                       * is no harm: reiser4_invalidate_lock() will mark znode
++                       * as JNODE_IS_DYING and this will be noted by
 +                       * can_lock_object() below.
 +                       */
 +                      spin_unlock_zlock(lock);
 +                      spin_lock_znode(node);
-+                      ret = try_capture(ZJNODE(node), mode, cap_flags);
++                      ret = reiser4_try_capture(ZJNODE(node), mode, cap_flags);
 +                      spin_unlock_znode(node);
 +                      spin_lock_zlock(lock);
 +                      if (unlikely(ret != 0)) {
@@ -23768,19 +23505,13 @@ Index: linux-2.6.16/fs/reiser4/lock.c
 +
 +              /* This time, a return of (ret == 0) means we can lock, so we
 +                 should break out of the loop. */
-+              if (likely(ret != -E_REPEAT || non_blocking)) {
++              if (likely(ret != -E_REPEAT || non_blocking))
 +                      break;
-+              }
 +
 +              /* Lock is unavailable, we have to wait. */
-+
-+              /* By having semaphore initialization here we cannot lose
-+                 wakeup signal even if it comes after `nr_signaled' field
-+                 check. */
-+              ret = prepare_to_sleep(owner);
-+              if (unlikely(ret != 0)) {
++              ret = reiser4_prepare_to_sleep(owner);
++              if (unlikely(ret != 0))
 +                      break;
-+              }
 +
 +              assert_spin_locked(&(node->lock.guard));
 +              if (hipri) {
@@ -23802,7 +23533,7 @@ Index: linux-2.6.16/fs/reiser4/lock.c
 +                 a znode ... */
 +              spin_unlock_zlock(lock);
 +              /* ... and sleep */
-+              go_to_sleep(owner);
++              reiser4_go_to_sleep(owner);
 +              if (owner->request.mode == ZNODE_NO_LOCK)
 +                      goto request_is_done;
 +              spin_lock_zlock(lock);
@@ -23823,10 +23554,10 @@ Index: linux-2.6.16/fs/reiser4/lock.c
 +
 +/* lock object invalidation means changing of lock object state to `INVALID'
 +   and waiting for all other processes to cancel theirs lock requests. */
-+void invalidate_lock(lock_handle * handle     /* path to lock
-+                                               * owner and lock
-+                                               * object is being
-+                                               * invalidated. */ )
++void reiser4_invalidate_lock(lock_handle * handle     /* path to lock
++                                                       * owner and lock
++                                                       * object is being
++                                                       * invalidated. */ )
 +{
 +      znode *node = handle->node;
 +      lock_stack *owner = handle->owner;
@@ -23859,7 +23590,7 @@ Index: linux-2.6.16/fs/reiser4/lock.c
 +      INIT_LIST_HEAD(&owner->requestors_link);
 +      spin_lock_init(&owner->sguard);
 +      owner->curpri = 1;
-+      sema_init(&owner->sema, 0);
++      init_waitqueue_head(&owner->wait);
 +}
 +
 +/* Initializes lock object. */
@@ -23927,7 +23658,7 @@ Index: linux-2.6.16/fs/reiser4/lock.c
 +}
 +
 +/* after getting -E_DEADLOCK we unlock znodes until this function returns false */
-+int check_deadlock(void)
++int reiser4_check_deadlock(void)
 +{
 +      lock_stack *owner = get_current_lock_stack();
 +      return atomic_read(&owner->nr_signaled) != 0;
@@ -23935,32 +23666,9 @@ Index: linux-2.6.16/fs/reiser4/lock.c
 +
 +/* Before going to sleep we re-check "release lock" requests which might come from threads with hi-pri lock
 +   priorities. */
-+int prepare_to_sleep(lock_stack * owner)
++int reiser4_prepare_to_sleep(lock_stack * owner)
 +{
 +      assert("nikita-1847", owner == get_current_lock_stack());
-+      /* NOTE(Zam): We cannot reset the lock semaphore here because it may
-+         clear wake-up signal. The initial design was to re-check all
-+         conditions under which we continue locking, release locks or sleep
-+         until conditions are changed. However, even lock.c does not follow
-+         that design.  So, wake-up signal which is stored in semaphore state
-+         could we loosen by semaphore reset.  The less complex scheme without
-+         resetting the semaphore is enough to not to loose wake-ups.
-+
-+         if (0) {
-+
-+         NOTE-NIKITA: I commented call to sema_init() out hoping
-+         that it is the reason or thread sleeping in
-+         down(&owner->sema) without any other thread running.
-+
-+         Anyway, it is just an optimization: is semaphore is not
-+         reinitialised at this point, in the worst case
-+         longterm_lock_znode() would have to iterate its loop once
-+         more.
-+         spin_lock_stack(owner);
-+         sema_init(&owner->sema, 0);
-+         spin_unlock_stack(owner);
-+         }
-+       */
 +
 +      /* We return -E_DEADLOCK if one or more "give me the lock" messages are
 +       * counted in nr_signaled */
@@ -23974,16 +23682,18 @@ Index: linux-2.6.16/fs/reiser4/lock.c
 +/* Wakes up a single thread */
 +void __reiser4_wake_up(lock_stack * owner)
 +{
-+      up(&owner->sema);
++      atomic_set(&owner->wakeup, 1);
++      wake_up(&owner->wait);
 +}
 +
 +/* Puts a thread to sleep */
-+void go_to_sleep(lock_stack * owner)
++void reiser4_go_to_sleep(lock_stack * owner)
 +{
 +      /* Well, we might sleep here, so holding of any spinlocks is no-no */
-+      assert("nikita-3027", schedulable());
-+      /* return down_interruptible(&owner->sema); */
-+      down(&owner->sema);
++      assert("nikita-3027", reiser4_schedulable());
++
++      wait_event(owner->wait, atomic_read(&owner->wakeup));
++      atomic_set(&owner->wakeup, 0);
 +}
 +
 +int lock_stack_isclean(lock_stack * owner)
@@ -24093,11 +23803,10 @@ Index: linux-2.6.16/fs/reiser4/lock.c
 +   fill-column: 79
 +   End:
 +*/
-Index: linux-2.6.16/fs/reiser4/lock.h
-===================================================================
---- /dev/null
-+++ linux-2.6.16/fs/reiser4/lock.h
-@@ -0,0 +1,272 @@
+diff -urN linux-2.6.22.orig/fs/reiser4/lock.h linux-2.6.22/fs/reiser4/lock.h
+--- linux-2.6.22.orig/fs/reiser4/lock.h        1970-01-01 03:00:00.000000000 +0300
++++ linux-2.6.22/fs/reiser4/lock.h     2007-07-29 00:25:34.888699583 +0400
+@@ -0,0 +1,249 @@
 +/* Copyright 2001, 2002, 2003 by Hans Reiser, licensing governed by reiser4/README */
 +
 +/* Long term locking data structures. See lock.c for details. */
@@ -24118,7 +23827,7 @@ Index: linux-2.6.16/fs/reiser4/lock.h
 +#include <linux/spinlock.h>
 +#include <linux/pagemap.h>    /* for PAGE_CACHE_SIZE */
 +#include <asm/atomic.h>
-+#include <asm/semaphore.h>
++#include <linux/wait.h>
 +
 +/* Per-znode lock object */
 +struct zlock {
@@ -24195,7 +23904,7 @@ Index: linux-2.6.16/fs/reiser4/lock.h
 +      struct list_head owners_link;
 +};
 +
-+typedef struct lock_request {
++struct lock_request {
 +      /* A pointer to uninitialized link object */
 +      lock_handle *handle;
 +      /* A pointer to the object we want to lock */
@@ -24204,7 +23913,7 @@ Index: linux-2.6.16/fs/reiser4/lock.h
 +      znode_lock_mode mode;
 +      /* how dispatch_lock_requests() returns lock request result code */
 +      int ret_code;
-+} lock_request;
++};
 +
 +/* A lock stack structure for accumulating locks owned by a process */
 +struct lock_stack {
@@ -24230,40 +23939,18 @@ Index: linux-2.6.16/fs/reiser4/lock.h
 +         This is only accessed by the current thread and thus requires no
 +         locking.
 +       */
-+      lock_request request;
-+      /* It is a lock_stack's synchronization object for when process sleeps
-+         when requested lock not on this lock_stack but which it wishes to
-+         add to this lock_stack is not immediately available. It is used
-+         instead of wait_queue_t object due to locking problems (lost wake
-+         up). "lost wakeup" occurs when process is waken up before he actually
-+         becomes 'sleepy' (through sleep_on()). Using of semaphore object is
-+         simplest way to avoid that problem.
-+
-+         A semaphore is used in the following way: only the process that is
-+         the owner of the lock_stack initializes it (to zero) and calls
-+         down(sema) on it. Usually this causes the process to sleep on the
-+         semaphore. Other processes may wake him up by calling up(sema). The
-+         advantage to a semaphore is that up() and down() calls are not
-+         required to preserve order. Unlike wait_queue it works when process
-+         is woken up before getting to sleep.
-+
-+         NOTE-NIKITA: Transaction manager is going to have condition variables
-+         (&kcondvar_t) anyway, so this probably will be replaced with
-+         one in the future.
-+
-+         After further discussion, Nikita has shown me that Zam's implementation is
-+         exactly a condition variable.  The znode's {zguard,requestors_list} represents
-+         condition variable and the lock_stack's {sguard,semaphore} guards entry and
-+         exit from the condition variable's wait queue.  But the existing code can't
-+         just be replaced with a more general abstraction, and I think its fine the way
-+         it is. */
-+      struct semaphore sema;
++      struct lock_request request;
++      /* the following two fields are the lock stack's
++       * synchronization object to use with the standard linux/wait.h
++       * interface. See reiser4_go_to_sleep and __reiser4_wake_up for
++       * usage details. */
++      wait_queue_head_t wait;
++      atomic_t wakeup;
 +#if REISER4_DEBUG
 +      int nr_locks;           /* number of lock handles in the above list */
 +#endif
 +};
 +
-+
 +/*
 +  User-visible znode locking functions
 +*/
@@ -24275,7 +23962,7 @@ Index: linux-2.6.16/fs/reiser4/lock.h
 +
 +extern void longterm_unlock_znode(lock_handle * handle);
 +
-+extern int check_deadlock(void);
++extern int reiser4_check_deadlock(void);
 +
 +extern lock_stack *get_current_lock_stack(void);
 +
@@ -24303,8 +23990,8 @@ Index: linux-2.6.16/fs/reiser4/lock.h
 +extern void move_lh(lock_handle * new, lock_handle * old);
 +extern void copy_lh(lock_handle * new, lock_handle * old);
 +
-+extern int prepare_to_sleep(lock_stack * owner);
-+extern void go_to_sleep(lock_stack * owner);
++extern int reiser4_prepare_to_sleep(lock_stack * owner);
++extern void reiser4_go_to_sleep(lock_stack * owner);
 +extern void __reiser4_wake_up(lock_stack * owner);
 +
 +extern int lock_stack_isclean(lock_stack * owner);
@@ -24312,7 +23999,7 @@ Index: linux-2.6.16/fs/reiser4/lock.h
 +/* zlock object state check macros: only used in assertions.  Both forms imply that the
 +   lock is held by the current thread. */
 +extern int znode_is_write_locked(const znode *);
-+extern void invalidate_lock(lock_handle *);
++extern void reiser4_invalidate_lock(lock_handle *);
 +
 +/* lock ordering is: first take zlock spin lock, then lock stack spin lock */
 +#define spin_ordering_pred_stack(stack)                       \
@@ -24340,7 +24027,6 @@ Index: linux-2.6.16/fs/reiser4/lock.h
 +      spin_unlock(&(stack->sguard));
 +}
 +
-+
 +static inline void reiser4_wake_up(lock_stack * owner)
 +{
 +      spin_lock_stack(owner);
@@ -24370,10 +24056,112 @@ Index: linux-2.6.16/fs/reiser4/lock.h
 +   fill-column: 120
 +   End:
 +*/
-Index: linux-2.6.16/fs/reiser4/oid.c
-===================================================================
---- /dev/null
-+++ linux-2.6.16/fs/reiser4/oid.c
+diff -urN linux-2.6.22.orig/fs/reiser4/Makefile linux-2.6.22/fs/reiser4/Makefile
+--- linux-2.6.22.orig/fs/reiser4/Makefile      1970-01-01 03:00:00.000000000 +0300
++++ linux-2.6.22/fs/reiser4/Makefile   2007-07-29 00:25:34.888699583 +0400
+@@ -0,0 +1,99 @@
++#
++# reiser4/Makefile
++#
++
++obj-$(CONFIG_REISER4_FS) += reiser4.o
++
++reiser4-y := \
++                 debug.o \
++                 jnode.o \
++                 znode.o \
++                 key.o \
++                 pool.o \
++                 tree_mod.o \
++                 estimate.o \
++                 carry.o \
++                 carry_ops.o \
++                 lock.o \
++                 tree.o \
++                 context.o \
++                 tap.o \
++                 coord.o \
++                 block_alloc.o \
++                 txnmgr.o \
++                 kassign.o \
++                 flush.o \
++                 wander.o \
++                 eottl.o \
++                 search.o \
++                 page_cache.o \
++                 seal.o \
++                 dscale.o \
++                 flush_queue.o \
++                 ktxnmgrd.o \
++                 blocknrset.o \
++                 super.o \
++                 super_ops.o \
++                 fsdata.o \
++                 export_ops.o \
++                 oid.o \
++                 tree_walk.o \
++                 inode.o \
++                 vfs_ops.o \
++                 as_ops.o \
++                 entd.o\
++                 readahead.o \
++                 status_flags.o \
++                 init_super.o \
++                 safe_link.o \
++           \
++                 plugin/plugin.o \
++                 plugin/plugin_set.o \
++                 plugin/node/node.o \
++                 plugin/object.o \
++                 plugin/cluster.o \
++                 plugin/inode_ops.o \
++                 plugin/inode_ops_rename.o \
++                 plugin/file_ops.o \
++                 plugin/file_ops_readdir.o \
++                 plugin/file_plugin_common.o \
++                 plugin/file/file.o \
++                 plugin/file/tail_conversion.o \
++                 plugin/file/file_conversion.o \
++                 plugin/file/symlink.o \
++                 plugin/file/cryptcompress.o \
++                 plugin/dir_plugin_common.o \
++                 plugin/dir/hashed_dir.o \
++                 plugin/dir/seekable_dir.o \
++                 plugin/node/node40.o \
++           \
++                 plugin/crypto/cipher.o \
++                 plugin/crypto/digest.o \
++           \
++                 plugin/compress/minilzo.o \
++                 plugin/compress/compress.o \
++                 plugin/compress/compress_mode.o \
++           \
++                 plugin/item/static_stat.o \
++                 plugin/item/sde.o \
++                 plugin/item/cde.o \
++                 plugin/item/blackbox.o \
++                 plugin/item/internal.o \
++                 plugin/item/tail.o \
++                 plugin/item/ctail.o \
++                 plugin/item/extent.o \
++                 plugin/item/extent_item_ops.o \
++                 plugin/item/extent_file_ops.o \
++                 plugin/item/extent_flush_ops.o \
++           \
++                 plugin/hash.o \
++                 plugin/fibration.o \
++                 plugin/tail_policy.o \
++                 plugin/item/item.o \
++           \
++                 plugin/security/perm.o \
++                 plugin/space/bitmap.o \
++           \
++                 plugin/disk_format/disk_format40.o \
++                 plugin/disk_format/disk_format.o
++
+diff -urN linux-2.6.22.orig/fs/reiser4/oid.c linux-2.6.22/fs/reiser4/oid.c
+--- linux-2.6.22.orig/fs/reiser4/oid.c 1970-01-01 03:00:00.000000000 +0300
++++ linux-2.6.22/fs/reiser4/oid.c      2007-07-29 00:25:34.888699583 +0400
 @@ -0,0 +1,141 @@
 +/* Copyright 2003 by Hans Reiser, licensing governed by reiser4/README */
 +
@@ -24516,15 +24304,34 @@ Index: linux-2.6.16/fs/reiser4/oid.c
 +   scroll-step: 1
 +   End:
 +*/
-Index: linux-2.6.16/fs/reiser4/page_cache.c
-===================================================================
---- /dev/null
-+++ linux-2.6.16/fs/reiser4/page_cache.c
-@@ -0,0 +1,712 @@
+diff -urN linux-2.6.22.orig/fs/reiser4/page_cache.c linux-2.6.22/fs/reiser4/page_cache.c
+--- linux-2.6.22.orig/fs/reiser4/page_cache.c  1970-01-01 03:00:00.000000000 +0300
++++ linux-2.6.22/fs/reiser4/page_cache.c       2007-07-29 00:25:34.888699583 +0400
+@@ -0,0 +1,730 @@
 +/* Copyright 2001, 2002, 2003 by Hans Reiser, licensing governed by
 + * reiser4/README */
 +
 +/* Memory pressure hooks. Fake inodes handling. */
++
++/*   GLOSSARY
++
++   . Formatted and unformatted nodes.
++     Elements of reiser4 balanced tree to store data and metadata.
++     Unformatted nodes are pointed to by extent pointers. Such nodes
++     are used to store data of large objects. Unlike unformatted nodes,
++     formatted ones have associated format described by node4X plugin.
++
++   . Jnode (or journal node)
++     The in-memory header which is used to track formatted and unformatted
++     nodes, bitmap nodes, etc. In particular, jnodes are used to track
++     transactional information associated with each block(see reiser4/jnode.c
++     for details).
++
++   . Znode
++     The in-memory header which is used to track formatted nodes. Contains
++     embedded jnode (see reiser4/znode.c for details).
++*/
++
 +/* We store all file system meta data (and data, of course) in the page cache.
 +
 +   What does this mean? In stead of using bread/brelse we create special
@@ -24555,8 +24362,8 @@ Index: linux-2.6.16/fs/reiser4/page_cache.c
 +   1. when jnode-to-page mapping is established (by jnode_attach_page()), page
 +   reference counter is increased.
 +
-+   2. when jnode-to-page mapping is destroyed (by jnode_detach_page() and
-+   page_detach_jnode()), page reference counter is decreased.
++   2. when jnode-to-page mapping is destroyed (by page_clear_jnode(), page
++   reference counter is decreased.
 +
 +   3. on jload() reference counter on jnode page is increased, page is
 +   kmapped and `referenced'.
@@ -24727,13 +24534,13 @@ Index: linux-2.6.16/fs/reiser4/page_cache.c
 +}
 +
 +/**
-+ * init_formatted_fake - iget inodes for formatted nodes and bitmaps
++ * reiser4_init_formatted_fake - iget inodes for formatted nodes and bitmaps
 + * @super: super block to init fake inode for
 + *
 + * Initializes fake inode to which formatted nodes are bound in the page cache
 + * and inode for bitmaps.
 + */
-+int init_formatted_fake(struct super_block *super)
++int reiser4_init_formatted_fake(struct super_block *super)
 +{
 +      struct inode *fake;
 +      struct inode *bitmap;
@@ -24771,20 +24578,19 @@ Index: linux-2.6.16/fs/reiser4/page_cache.c
 +}
 +
 +/**
-+ * done_formatted_fake - release inode used by formatted nodes and bitmaps
++ * reiser4_done_formatted_fake - release inode used by formatted nodes and bitmaps
 + * @super: super block to init fake inode for
 + *
 + * Releases inodes which were used as address spaces of bitmap and formatted
 + * nodes.
 + */
-+void done_formatted_fake(struct super_block *super)
++void reiser4_done_formatted_fake(struct super_block *super)
 +{
 +      reiser4_super_info_data *sinfo;
 +
 +      sinfo = get_super_private_nocheck(super);
 +
 +      if (sinfo->fake != NULL) {
-+              assert("vs-1426", sinfo->fake->i_data.nrpages == 0);
 +              iput(sinfo->fake);
 +              sinfo->fake = NULL;
 +      }
@@ -24813,7 +24619,7 @@ Index: linux-2.6.16/fs/reiser4/page_cache.c
 +}
 +
 +/* return tree @page is in */
-+reiser4_tree *tree_by_page(const struct page *page /* page to query */ )
++reiser4_tree *reiser4_tree_by_page(const struct page *page /* page to query */ )
 +{
 +      assert("nikita-2461", page != NULL);
 +      return &get_super_private(page->mapping->host->i_sb)->tree;
@@ -24880,11 +24686,12 @@ Index: linux-2.6.16/fs/reiser4/page_cache.c
 +                            struct page *page /* page to read */ )
 +{
 +      assert("nikita-2412", PagePrivate(page) && jprivate(page));
-+      return page_io(page, jprivate(page), READ, get_gfp_mask());
++      return reiser4_page_io(page, jprivate(page), READ,
++                             reiser4_ctx_gfp_mask_get());
 +}
 +
 +/**
-+ * page_io - submit single-page bio request
++ * reiser4_page_io - submit single-page bio request
 + * @page: page to perform io for
 + * @node: jnode of page
 + * @rw: read or write
@@ -24892,7 +24699,7 @@ Index: linux-2.6.16/fs/reiser4/page_cache.c
 + *
 + * Submits single page read or write.
 + */
-+int page_io(struct page *page, jnode *node, int rw, gfp_t gfp)
++int reiser4_page_io(struct page *page, jnode *node, int rw, gfp_t gfp)
 +{
 +      struct bio *bio;
 +      int result;
@@ -24912,7 +24719,7 @@ Index: linux-2.6.16/fs/reiser4/page_cache.c
 +      bio = page_bio(page, node, rw, gfp);
 +      if (!IS_ERR(bio)) {
 +              if (rw == WRITE) {
-+                      SetPageWriteback(page);
++                      set_page_writeback(page);
 +                      unlock_page(page);
 +              }
 +              reiser4_submit_bio(rw, bio);
@@ -24954,7 +24761,7 @@ Index: linux-2.6.16/fs/reiser4/page_cache.c
 +              spin_unlock_jnode(node);
 +
 +              assert("nikita-2275", blocknr != (reiser4_block_nr) 0);
-+              assert("nikita-2276", !blocknr_is_fake(&blocknr));
++              assert("nikita-2276", !reiser4_blocknr_is_fake(&blocknr));
 +
 +              bio->bi_bdev = super->s_bdev;
 +              /* fill bio->bi_sector before calling bio_add_page(), because
@@ -24978,7 +24785,7 @@ Index: linux-2.6.16/fs/reiser4/page_cache.c
 +}
 +
 +/* this function is internally called by jnode_make_dirty() */
-+int set_page_dirty_internal(struct page *page)
++int reiser4_set_page_dirty_internal(struct page *page)
 +{
 +      struct address_space *mapping;
 +
@@ -24987,24 +24794,18 @@ Index: linux-2.6.16/fs/reiser4/page_cache.c
 +
 +      if (!TestSetPageDirty(page)) {
 +              if (mapping_cap_account_dirty(mapping))
-+                      inc_page_state(nr_dirty);
++                      inc_zone_page_state(page, NR_FILE_DIRTY);
 +
 +              __mark_inode_dirty(mapping->host, I_DIRTY_PAGES);
 +      }
 +
 +      /* znode must be dirty ? */
-+      if (mapping->host == get_super_fake(mapping->host->i_sb))
++      if (mapping->host == reiser4_get_super_fake(mapping->host->i_sb))
 +              assert("", JF_ISSET(jprivate(page), JNODE_DIRTY));
 +      return 0;
 +}
 +
-+#if REISER4_DEBUG
-+
-+/**
-+ * can_hit_entd
-+ *
-+ * This is used on 
-+ */
++#if 0
 +static int can_hit_entd(reiser4_context *ctx, struct super_block *s)
 +{
 +      if (ctx == NULL || ((unsigned long)ctx->magic) != context_magic)
@@ -25019,7 +24820,6 @@ Index: linux-2.6.16/fs/reiser4/page_cache.c
 +              return 0;
 +      return 1;
 +}
-+
 +#endif
 +
 +/**
@@ -25041,8 +24841,7 @@ Index: linux-2.6.16/fs/reiser4/page_cache.c
 +      s = page->mapping->host->i_sb;
 +      ctx = get_current_context_check();
 +
-+      assert("", can_hit_entd(ctx, s));
-+
++      //assert("", can_hit_entd(ctx, s));
 +      return write_page_by_ent(page, wbc);
 +}
 +
@@ -25104,7 +24903,7 @@ Index: linux-2.6.16/fs/reiser4/page_cache.c
 +
 +/* called just before page is released (no longer used by reiser4). Callers:
 +   jdelete() and extent2tail(). */
-+void drop_page(struct page *page)
++void reiser4_drop_page(struct page *page)
 +{
 +      assert("nikita-2181", PageLocked(page));
 +      clear_page_dirty_for_io(page);
@@ -25112,45 +24911,12 @@ Index: linux-2.6.16/fs/reiser4/page_cache.c
 +#if defined(PG_skipped)
 +      ClearPageSkipped(page);
 +#endif
-+      if (page->mapping != NULL) {
-+              remove_from_page_cache(page);
-+              unlock_page(page);
-+              page_cache_release(page);
-+      } else
-+              unlock_page(page);
-+}
-+
-+/* this is called by truncate_jnodes_range which in its turn is always called
-+   after truncate_mapping_pages_range. Therefore, here jnode can not have
-+   page. New pages can not be created because truncate_jnodes_range goes under
-+   exclusive access on file obtained, where as new page creation requires
-+   non-exclusive access obtained */
-+static void invalidate_unformatted(jnode * node)
-+{
-+      struct page *page;
-+
-+      spin_lock_jnode(node);
-+      page = node->pg;
-+      if (page) {
-+              loff_t from, to;
-+
-+              page_cache_get(page);
-+              spin_unlock_jnode(node);
-+              /* FIXME: use truncate_complete_page instead */
-+              from = (loff_t) page->index << PAGE_CACHE_SHIFT;
-+              to = from + PAGE_CACHE_SIZE - 1;
-+              truncate_inode_pages_range(page->mapping, from, to);
-+              page_cache_release(page);
-+      } else {
-+              JF_SET(node, JNODE_HEARD_BANSHEE);
-+              uncapture_jnode(node);
-+              unhash_unformatted_jnode(node);
-+      }
++      unlock_page(page);
 +}
 +
 +#define JNODE_GANG_SIZE (16)
 +
-+/* find all eflushed jnodes from range specified and invalidate them */
++/* find all jnodes from range specified and invalidate them */
 +static int
 +truncate_jnodes_range(struct inode *inode, pgoff_t from, pgoff_t count)
 +{
@@ -25160,10 +24926,20 @@ Index: linux-2.6.16/fs/reiser4/page_cache.c
 +      unsigned long index;
 +      unsigned long end;
 +
++      if (inode_file_plugin(inode) ==
++          file_plugin_by_id(CRYPTCOMPRESS_FILE_PLUGIN_ID))
++              /*
++               * No need to get rid of jnodes here: if the single jnode of
++               * page cluster did not have page, then it was found and killed
++               * before in
++               * truncate_complete_page_cluster()->jput()->jput_final(),
++               * otherwise it will be dropped by reiser4_invalidatepage()
++               */
++              return 0;
 +      truncated_jnodes = 0;
 +
 +      info = reiser4_inode_data(inode);
-+      tree = tree_by_inode(inode);
++      tree = reiser4_tree_by_inode(inode);
 +
 +      index = from;
 +      end = from + count;
@@ -25194,7 +24970,18 @@ Index: linux-2.6.16/fs/reiser4/page_cache.c
 +                      node = gang[i];
 +                      if (node != NULL) {
 +                              index = max(index, index_jnode(node));
-+                              invalidate_unformatted(node);
++                              spin_lock_jnode(node);
++                              assert("edward-1457", node->pg == NULL);
++                              /* this is always called after
++                                 truncate_inode_pages_range(). Therefore, here
++                                 jnode can not have page. New pages can not be
++                                 created because truncate_jnodes_range goes
++                                 under exclusive access on file obtained,
++                                 where as new page creation requires
++                                 non-exclusive access obtained */
++                              JF_SET(node, JNODE_HEARD_BANSHEE);
++                              reiser4_uncapture_jnode(node);
++                              unhash_unformatted_jnode(node);
 +                              truncated_jnodes++;
 +                              jput(node);
 +                      } else
@@ -25206,9 +24993,27 @@ Index: linux-2.6.16/fs/reiser4/page_cache.c
 +      return truncated_jnodes;
 +}
 +
-+void
-+reiser4_invalidate_pages(struct address_space *mapping, pgoff_t from,
-+                       unsigned long count, int even_cows)
++/* Truncating files in reiser4: problems and solutions.
++
++   VFS calls fs's truncate after it has called truncate_inode_pages()
++   to get rid of pages corresponding to part of file being truncated.
++   In reiser4 it may cause existence of unallocated extents which do
++   not have jnodes. Flush code does not expect that. Solution of this
++   problem is straightforward. As vfs's truncate is implemented using
++   setattr operation, it seems reasonable to have ->setattr() that
++   will cut file body. However, flush code also does not expect dirty
++   pages without parent items, so it is impossible to cut all items,
++   then truncate all pages in two steps. We resolve this problem by
++   cutting items one-by-one. Each such fine-grained step performed
++   under longterm znode lock calls at the end ->kill_hook() method of
++   a killed item to remove its binded pages and jnodes.
++
++   The following function is a common part of mentioned kill hooks.
++   Also, this is called before tail-to-extent conversion (to not manage
++   few copies of the data).
++*/
++void reiser4_invalidate_pages(struct address_space *mapping, pgoff_t from,
++                            unsigned long count, int even_cows)
 +{
 +      loff_t from_bytes, count_bytes;
 +
@@ -25233,11 +25038,10 @@ Index: linux-2.6.16/fs/reiser4/page_cache.c
 + * scroll-step: 1
 + * End:
 + */
-Index: linux-2.6.16/fs/reiser4/page_cache.h
-===================================================================
---- /dev/null
-+++ linux-2.6.16/fs/reiser4/page_cache.h
-@@ -0,0 +1,62 @@
+diff -urN linux-2.6.22.orig/fs/reiser4/page_cache.h linux-2.6.22/fs/reiser4/page_cache.h
+--- linux-2.6.22.orig/fs/reiser4/page_cache.h  1970-01-01 03:00:00.000000000 +0300
++++ linux-2.6.22/fs/reiser4/page_cache.h       2007-07-29 00:25:34.888699583 +0400
+@@ -0,0 +1,68 @@
 +/* Copyright 2001, 2002, 2003 by Hans Reiser, licensing governed by
 + * reiser4/README */
 +/* Memory pressure hooks. Fake inodes handling. See page_cache.c. */
@@ -25246,19 +25050,19 @@ Index: linux-2.6.16/fs/reiser4/page_cache.h
 +#define __REISER4_PAGE_CACHE_H__
 +
 +#include "forward.h"
-+#include "debug.h"
++#include "context.h"            /* for reiser4_ctx_gfp_mask_get() */
 +
 +#include <linux/fs.h>         /* for struct super_block, address_space  */
 +#include <linux/mm.h>         /* for struct page  */
 +#include <linux/pagemap.h>    /* for lock_page()  */
++#include <linux/vmalloc.h>    /* for __vmalloc()  */
 +
++extern int reiser4_init_formatted_fake(struct super_block *);
++extern void reiser4_done_formatted_fake(struct super_block *);
 +
-+extern int init_formatted_fake(struct super_block *);
-+extern void done_formatted_fake(struct super_block *);
-+
-+extern reiser4_tree *tree_by_page(const struct page *);
++extern reiser4_tree *reiser4_tree_by_page(const struct page *);
 +
-+extern int set_page_dirty_internal(struct page *);
++extern int reiser4_set_page_dirty_internal(struct page *);
 +
 +#define reiser4_submit_bio(rw, bio) submit_bio((rw), (bio))
 +
@@ -25272,12 +25076,18 @@ Index: linux-2.6.16/fs/reiser4/page_cache.h
 +
 +#define jprivate(page) ((jnode *)page_private(page))
 +
-+extern int page_io(struct page *, jnode *, int rw, gfp_t);
-+extern void drop_page(struct page *);
++extern int reiser4_page_io(struct page *, jnode *, int rw, gfp_t);
++extern void reiser4_drop_page(struct page *);
 +extern void reiser4_invalidate_pages(struct address_space *, pgoff_t from,
 +                                   unsigned long count, int even_cows);
 +extern void capture_reiser4_inodes(struct super_block *,
 +                                 struct writeback_control *);
++static inline void * reiser4_vmalloc (unsigned long size)
++{
++      return __vmalloc(size,
++                       reiser4_ctx_gfp_mask_get() | __GFP_HIGHMEM,
++                       PAGE_KERNEL);
++}
 +
 +#define PAGECACHE_TAG_REISER4_MOVED PAGECACHE_TAG_DIRTY
 +
@@ -25300,42 +25110,10 @@ Index: linux-2.6.16/fs/reiser4/page_cache.h
 +   scroll-step: 1
 +   End:
 +*/
-Index: linux-2.6.16/fs/reiser4/plugin/Makefile
-===================================================================
---- /dev/null
-+++ linux-2.6.16/fs/reiser4/plugin/Makefile
-@@ -0,0 +1,26 @@
-+obj-$(CONFIG_REISER4_FS) += plugins.o
-+
-+plugins-objs :=                       \
-+      plugin.o                \
-+      plugin_set.o            \
-+      object.o                \
-+      inode_ops.o             \
-+      inode_ops_rename.o      \
-+      file_ops.o              \
-+      file_ops_readdir.o      \
-+      file_plugin_common.o    \
-+      dir_plugin_common.o     \
-+      digest.o                \
-+      hash.o                  \
-+      fibration.o             \
-+      tail_policy.o           \
-+      regular.o
-+
-+obj-$(CONFIG_REISER4_FS) += item/
-+obj-$(CONFIG_REISER4_FS) += file/
-+obj-$(CONFIG_REISER4_FS) += dir/
-+obj-$(CONFIG_REISER4_FS) += node/
-+obj-$(CONFIG_REISER4_FS) += compress/
-+obj-$(CONFIG_REISER4_FS) += space/
-+obj-$(CONFIG_REISER4_FS) += disk_format/
-+obj-$(CONFIG_REISER4_FS) += security/
-Index: linux-2.6.16/fs/reiser4/plugin/cluster.c
-===================================================================
---- /dev/null
-+++ linux-2.6.16/fs/reiser4/plugin/cluster.c
-@@ -0,0 +1,66 @@
+diff -urN linux-2.6.22.orig/fs/reiser4/plugin/cluster.c linux-2.6.22/fs/reiser4/plugin/cluster.c
+--- linux-2.6.22.orig/fs/reiser4/plugin/cluster.c      1970-01-01 03:00:00.000000000 +0300
++++ linux-2.6.22/fs/reiser4/plugin/cluster.c   2007-07-29 00:25:34.892700618 +0400
+@@ -0,0 +1,71 @@
 +/* Copyright 2001, 2002, 2003 by Hans Reiser, licensing governed by reiser4/README */
 +
 +/* Contains reiser4 cluster plugins (see
@@ -25346,21 +25124,26 @@ Index: linux-2.6.16/fs/reiser4/plugin/cluster.c
 +#include "plugin.h"
 +#include "../inode.h"
 +
-+static int change_cluster(struct inode *inode, reiser4_plugin * plugin)
++static int change_cluster(struct inode *inode,
++                        reiser4_plugin * plugin,
++                        pset_member memb)
 +{
-+      int result = 0;
-+
 +      assert("edward-1324", inode != NULL);
 +      assert("edward-1325", plugin != NULL);
 +      assert("edward-1326", is_reiser4_inode(inode));
 +      assert("edward-1327", plugin->h.type_id == REISER4_CLUSTER_PLUGIN_TYPE);
 +
-+      if (inode_file_plugin(inode)->h.id == DIRECTORY_FILE_PLUGIN_ID)
-+              result = plugin_set_cluster(&reiser4_inode_data(inode)->pset,
-+                                          &plugin->clust);
-+      else
-+              result = RETERR(-EINVAL);
-+      return result;
++      /* Can't change the cluster plugin for already existent regular files. */
++      if (!plugin_of_group(inode_file_plugin(inode), REISER4_DIRECTORY_FILE))
++              return RETERR(-EINVAL);
++
++      /* If matches, nothing to change. */
++      if (inode_hash_plugin(inode) != NULL &&
++          inode_hash_plugin(inode)->h.id == plugin->h.id)
++              return 0;
++
++      return aset_set_unsafe(&reiser4_inode_data(inode)->pset,
++                             PSET_CLUSTER, plugin);
 +}
 +
 +static reiser4_plugin_ops cluster_plugin_ops = {
@@ -25402,15 +25185,14 @@ Index: linux-2.6.16/fs/reiser4/plugin/cluster.c
 +  scroll-step: 1
 +  End:
 +*/
-Index: linux-2.6.16/fs/reiser4/plugin/cluster.h
-===================================================================
---- /dev/null
-+++ linux-2.6.16/fs/reiser4/plugin/cluster.h
-@@ -0,0 +1,316 @@
+diff -urN linux-2.6.22.orig/fs/reiser4/plugin/cluster.h linux-2.6.22/fs/reiser4/plugin/cluster.h
+--- linux-2.6.22.orig/fs/reiser4/plugin/cluster.h      1970-01-01 03:00:00.000000000 +0300
++++ linux-2.6.22/fs/reiser4/plugin/cluster.h   2007-07-29 00:25:34.892700618 +0400
+@@ -0,0 +1,399 @@
 +/* Copyright 2002, 2003 by Hans Reiser, licensing governed by reiser4/README */
 +
-+/* This file contains page/cluster index translators and offset modulators
-+   See http://www.namesys.com/cryptcompress_design.html for details */
++/* This file contains size/offset translators, modulators
++   and other helper functions. */
 +
 +#if !defined( __FS_REISER4_CLUSTER_H__ )
 +#define __FS_REISER4_CLUSTER_H__
@@ -25478,47 +25260,43 @@ Index: linux-2.6.16/fs/reiser4/plugin/cluster.h
 +      return (loff_t) idx << inode_cluster_shift(inode);
 +}
 +
-+static inline unsigned long count_to_nr(loff_t count, unsigned shift)
++static inline loff_t off_to_clust_to_off(loff_t off, struct inode *inode)
 +{
-+      return (count + (1UL << shift) - 1) >> shift;
++      return clust_to_off(off_to_clust(off, inode), inode);
 +}
 +
-+/* number of pages occupied by @count bytes */
-+static inline pgoff_t count_to_nrpages(loff_t count)
++static inline pgoff_t off_to_clust_to_pg(loff_t off, struct inode *inode)
 +{
-+      return count_to_nr(count, PAGE_CACHE_SHIFT);
++      return clust_to_pg(off_to_clust(off, inode), inode);
 +}
 +
-+/* number of clusters occupied by @count bytes */
-+static inline cloff_t count_to_nrclust(loff_t count, struct inode *inode)
++static inline unsigned off_to_pgoff(loff_t off)
 +{
-+      return count_to_nr(count, inode_cluster_shift(inode));
++      return off & (PAGE_CACHE_SIZE - 1);
 +}
 +
-+/* number of clusters occupied by @count pages */
-+static inline cloff_t pgcount_to_nrclust(pgoff_t count, struct inode *inode)
++static inline unsigned off_to_cloff(loff_t off, struct inode *inode)
 +{
-+      return count_to_nr(count, cluster_nrpages_shift(inode));
++      return off & ((loff_t) (inode_cluster_size(inode)) - 1);
 +}
 +
-+static inline loff_t off_to_clust_to_off(loff_t off, struct inode *inode)
++static inline  pgoff_t offset_in_clust(struct page * page)
 +{
-+      return clust_to_off(off_to_clust(off, inode), inode);
-+}
++      assert("edward-1488", page != NULL);
++      assert("edward-1489", page->mapping != NULL);
 +
-+static inline pgoff_t off_to_clust_to_pg(loff_t off, struct inode *inode)
-+{
-+      return clust_to_pg(off_to_clust(off, inode), inode);
++      return page_index(page) & ((cluster_nrpages(page->mapping->host)) - 1);
 +}
 +
-+static inline unsigned off_to_pgoff(loff_t off)
++static inline int first_page_in_cluster(struct page * page)
 +{
-+      return off & (PAGE_CACHE_SIZE - 1);
++      return offset_in_clust(page) == 0;
 +}
 +
-+static inline unsigned off_to_cloff(loff_t off, struct inode *inode)
++static inline int last_page_in_cluster(struct page * page)
 +{
-+      return off & ((loff_t) (inode_cluster_size(inode)) - 1);
++      return offset_in_clust(page) ==
++              cluster_nrpages(page->mapping->host) - 1;
 +}
 +
 +static inline unsigned
@@ -25527,108 +25305,192 @@ Index: linux-2.6.16/fs/reiser4/plugin/cluster.h
 +      return off_to_cloff(pg_to_off(idx), inode);
 +}
 +
-+/* if @size != 0, returns index of the page
-+   which contains the last byte of the file */
-+static inline pgoff_t size_to_pg(loff_t size)
++/*********************** Size translators **************************/
++
++/* Translate linear size.
++ * New units are (1 << @blk_shift) times larger, then old ones.
++ * In other words, calculate number of logical blocks, occupied
++ * by @count elements
++ */
++static inline unsigned long size_in_blocks(loff_t count, unsigned blkbits)
 +{
-+      return (size ? off_to_pg(size - 1) : 0);
++      return (count + (1UL << blkbits) - 1) >> blkbits;
 +}
 +
-+/* minimal index of the page which doesn't contain
-+   file data */
-+static inline pgoff_t size_to_next_pg(loff_t size)
++/* size in pages */
++static inline pgoff_t size_in_pages(loff_t size)
 +{
-+      return (size ? off_to_pg(size - 1) + 1 : 0);
++      return size_in_blocks(size, PAGE_CACHE_SHIFT);
 +}
 +
-+/* how many bytes of file of size @cnt can be contained
-+   in page of index @idx */
-+static inline unsigned cnt_to_pgcnt(loff_t cnt, pgoff_t idx)
++/* size in logical clusters */
++static inline cloff_t size_in_lc(loff_t size, struct inode *inode)
 +{
-+      if (idx > off_to_pg(cnt))
-+              return 0;
-+      if (idx < off_to_pg(cnt))
-+              return PAGE_CACHE_SIZE;
-+      return off_to_pgoff(cnt);
++      return size_in_blocks(size, inode_cluster_shift(inode));
 +}
 +
-+/* how many bytes of file of size @cnt can be contained
-+   in logical cluster of index @idx */
-+static inline unsigned cnt_to_clcnt(loff_t cnt, cloff_t idx,
-+                                  struct inode *inode)
++/* size in pages to the size in page clusters */
++static inline cloff_t sp_to_spcl(pgoff_t size, struct inode *inode)
++{
++      return size_in_blocks(size, cluster_nrpages_shift(inode));
++}
++
++/*********************** Size modulators ***************************/
++
++/*
++  Modulate linear size by nominated block size and offset.
++
++  The "finite" function (which is zero almost everywhere).
++  How much is a height of the figure at a position @pos,
++  when trying to construct rectangle of height (1 << @blkbits),
++  and square @size.
++
++  ******
++  *******
++  *******
++  *******
++  ----------> pos
++*/
++static inline unsigned __mbb(loff_t size, unsigned long pos, int blkbits)
 +{
-+      if (idx > off_to_clust(cnt, inode))
++      unsigned end = size >> blkbits;
++      if (pos < end)
++              return 1U << blkbits;
++      if (unlikely(pos > end))
 +              return 0;
-+      if (idx < off_to_clust(cnt, inode))
-+              return inode_cluster_size(inode);
-+      return off_to_cloff(cnt, inode);
++      return size & ~(~0ull << blkbits);
 +}
 +
-+static inline unsigned
-+fsize_to_count(reiser4_cluster_t * clust, struct inode *inode)
++/* the same as above, but block size is page size */
++static inline unsigned __mbp(loff_t size, pgoff_t pos)
++{
++      return __mbb(size, pos, PAGE_CACHE_SHIFT);
++}
++
++/* number of file's bytes in the nominated logical cluster */
++static inline unsigned lbytes(cloff_t index, struct inode * inode)
 +{
-+      assert("edward-288", clust != NULL);
-+      assert("edward-289", inode != NULL);
++      return __mbb(i_size_read(inode), index, inode_cluster_shift(inode));
++}
 +
-+      return cnt_to_clcnt(inode->i_size, clust->index, inode);
++/* number of file's bytes in the nominated page */
++static inline unsigned pbytes(pgoff_t index, struct inode * inode)
++{
++      return __mbp(i_size_read(inode), index);
 +}
 +
-+static inline int
-+cluster_is_complete(reiser4_cluster_t * clust, struct inode * inode)
++/* return true, if logical cluster is not occupied by the file */
++static inline int new_logical_cluster(struct cluster_handle * clust,
++                                    struct inode *inode)
++{
++      return clust_to_off(clust->index, inode) >= i_size_read(inode);
++}
++
++/* return true, if pages @p1 and @p2 are of the same page cluster */
++static inline int same_page_cluster(struct page * p1, struct page * p2)
++{
++      assert("edward-1490", p1 != NULL);
++      assert("edward-1491", p2 != NULL);
++      assert("edward-1492", p1->mapping != NULL);
++      assert("edward-1493", p2->mapping != NULL);
++
++      return (pg_to_clust(page_index(p1), p1->mapping->host) ==
++              pg_to_clust(page_index(p2), p2->mapping->host));
++}
++
++static inline int cluster_is_complete(struct cluster_handle * clust,
++                                    struct inode * inode)
 +{
 +      return clust->tc.lsize == inode_cluster_size(inode);
 +}
 +
-+static inline void reiser4_slide_init(reiser4_slide_t * win)
++static inline void reiser4_slide_init(struct reiser4_slide * win)
 +{
 +      assert("edward-1084", win != NULL);
 +      memset(win, 0, sizeof *win);
 +}
 +
++static inline tfm_action
++cluster_get_tfm_act(struct tfm_cluster * tc)
++{
++      assert("edward-1356", tc != NULL);
++      return tc->act;
++}
++
 +static inline void
-+tfm_cluster_init_act(tfm_cluster_t * tc, tfm_action act)
++cluster_set_tfm_act(struct tfm_cluster * tc, tfm_action act)
 +{
 +      assert("edward-1356", tc != NULL);
 +      tc->act = act;
 +}
 +
-+static inline void
-+cluster_init_act (reiser4_cluster_t * clust, tfm_action act, reiser4_slide_t * window){
++static inline void cluster_init_act(struct cluster_handle * clust,
++                                  tfm_action act,
++                                  struct reiser4_slide * window)
++{
 +      assert("edward-84", clust != NULL);
 +      memset(clust, 0, sizeof *clust);
-+      tfm_cluster_init_act(&clust->tc, act);
++      cluster_set_tfm_act(&clust->tc, act);
 +      clust->dstat = INVAL_DISK_CLUSTER;
 +      clust->win = window;
 +}
 +
-+static inline void
-+cluster_init_read(reiser4_cluster_t * clust, reiser4_slide_t * window)
++static inline void cluster_init_read(struct cluster_handle * clust,
++                                   struct reiser4_slide * window)
 +{
-+      cluster_init_act (clust, TFM_READ_ACT, window);
++      cluster_init_act (clust, TFMA_READ, window);
 +}
 +
-+static inline void
-+cluster_init_write(reiser4_cluster_t * clust, reiser4_slide_t * window)
++static inline void cluster_init_write(struct cluster_handle * clust,
++                                    struct reiser4_slide * window)
 +{
-+      cluster_init_act (clust, TFM_WRITE_ACT, window);
++      cluster_init_act (clust, TFMA_WRITE, window);
 +}
 +
-+static inline int dclust_get_extension(hint_t * hint)
++/* true if @p1 and @p2 are items of the same disk cluster */
++static inline int same_disk_cluster(const coord_t * p1, const coord_t * p2)
++{
++      /* drop this if you have other items to aggregate */
++      assert("edward-1494", item_id_by_coord(p1) == CTAIL_ID);
++
++      return item_plugin_by_coord(p1)->b.mergeable(p1, p2);
++}
++
++static inline int dclust_get_extension_dsize(hint_t * hint)
++{
++      return hint->ext_coord.extension.ctail.dsize;
++}
++
++static inline void dclust_set_extension_dsize(hint_t * hint, int dsize)
++{
++      hint->ext_coord.extension.ctail.dsize = dsize;
++}
++
++static inline int dclust_get_extension_shift(hint_t * hint)
 +{
 +      return hint->ext_coord.extension.ctail.shift;
 +}
 +
-+static inline void dclust_set_extension(hint_t * hint)
++static inline int dclust_get_extension_ncount(hint_t * hint)
 +{
-+      assert("edward-1270",
-+             item_id_by_coord(&hint->ext_coord.coord) == CTAIL_ID);
-+      hint->ext_coord.extension.ctail.shift =
-+          cluster_shift_by_coord(&hint->ext_coord.coord);
++      return hint->ext_coord.extension.ctail.ncount;
++}
++
++static inline void dclust_inc_extension_ncount(hint_t * hint)
++{
++      hint->ext_coord.extension.ctail.ncount ++;
++}
++
++static inline void dclust_init_extension(hint_t * hint)
++{
++      memset(&hint->ext_coord.extension.ctail, 0,
++             sizeof(hint->ext_coord.extension.ctail));
 +}
 +
 +static inline int hint_is_unprepped_dclust(hint_t * hint)
 +{
-+      return dclust_get_extension(hint) == (int)UCTAIL_SHIFT;
++      assert("edward-1451", hint_is_valid(hint));
++      return dclust_get_extension_shift(hint) == (int)UCTAIL_SHIFT;
 +}
 +
 +static inline void coord_set_between_clusters(coord_t * coord)
@@ -25647,66 +25509,69 @@ Index: linux-2.6.16/fs/reiser4/plugin/cluster.h
 +#endif
 +}
 +
-+int inflate_cluster(reiser4_cluster_t *, struct inode *);
-+int find_cluster(reiser4_cluster_t *, struct inode *, int read, int write);
-+void forget_cluster_pages(struct page **page, int nrpages);
-+int flush_cluster_pages(reiser4_cluster_t *, jnode *, struct inode *);
-+int deflate_cluster(reiser4_cluster_t *, struct inode *);
-+void truncate_page_cluster(struct inode *inode, cloff_t start);
-+void invalidate_hint_cluster(reiser4_cluster_t * clust);
-+void put_hint_cluster(reiser4_cluster_t * clust, struct inode *inode,
++int reiser4_inflate_cluster(struct cluster_handle *, struct inode *);
++int find_disk_cluster(struct cluster_handle *, struct inode *, int read,
 +                    znode_lock_mode mode);
-+int get_disk_cluster_locked(reiser4_cluster_t * clust, struct inode *inode,
++int checkout_logical_cluster(struct cluster_handle *, jnode *, struct inode *);
++int reiser4_deflate_cluster(struct cluster_handle *, struct inode *);
++void truncate_complete_page_cluster(struct inode *inode, cloff_t start,
++                                       int even_cows);
++void invalidate_hint_cluster(struct cluster_handle * clust);
++void put_hint_cluster(struct cluster_handle * clust, struct inode *inode,
++                    znode_lock_mode mode);
++int get_disk_cluster_locked(struct cluster_handle * clust, struct inode * inode,
 +                          znode_lock_mode lock_mode);
-+void reset_cluster_params(reiser4_cluster_t * clust);
-+int set_cluster_by_page(reiser4_cluster_t * clust, struct page * page,
++void reset_cluster_params(struct cluster_handle * clust);
++int set_cluster_by_page(struct cluster_handle * clust, struct page * page,
 +                      int count);
-+int prepare_page_cluster(struct inode *inode, reiser4_cluster_t * clust,
-+                       int capture);
-+void release_cluster_pages(reiser4_cluster_t *);
-+void put_cluster_handle(reiser4_cluster_t * clust);
-+int grab_tfm_stream(struct inode *inode, tfm_cluster_t * tc, tfm_stream_id id);
-+int tfm_cluster_is_uptodate(tfm_cluster_t * tc);
-+void tfm_cluster_set_uptodate(tfm_cluster_t * tc);
-+void tfm_cluster_clr_uptodate(tfm_cluster_t * tc);
++int prepare_page_cluster(struct inode *inode, struct cluster_handle * clust,
++                       rw_op rw);
++void __put_page_cluster(int from, int to, struct page ** pages,
++                      struct inode * inode);
++void put_page_cluster(struct cluster_handle * clust,
++                    struct inode  * inode, rw_op rw);
++void put_cluster_handle(struct cluster_handle * clust);
++int grab_tfm_stream(struct inode *inode, struct tfm_cluster * tc, tfm_stream_id id);
++int tfm_cluster_is_uptodate(struct tfm_cluster * tc);
++void tfm_cluster_set_uptodate(struct tfm_cluster * tc);
++void tfm_cluster_clr_uptodate(struct tfm_cluster * tc);
 +
 +/* move cluster handle to the target position
-+   specified by the page of index @pgidx
-+*/
-+static inline void
-+move_cluster_forward(reiser4_cluster_t * clust, struct inode *inode,
-+                   pgoff_t pgidx, int *progress)
++   specified by the page of index @pgidx */
++static inline void move_cluster_forward(struct cluster_handle * clust,
++                                      struct inode *inode,
++                                      pgoff_t pgidx)
 +{
 +      assert("edward-1297", clust != NULL);
 +      assert("edward-1298", inode != NULL);
 +
 +      reset_cluster_params(clust);
-+      if (*progress &&
++      if (clust->index_valid &&
 +          /* Hole in the indices. Hint became invalid and can not be
 +             used by find_cluster_item() even if seal/node versions
 +             will coincide */
 +          pg_to_clust(pgidx, inode) != clust->index + 1) {
-+              unset_hint(clust->hint);
++              reiser4_unset_hint(clust->hint);
 +              invalidate_hint_cluster(clust);
 +      }
-+      *progress = 1;
 +      clust->index = pg_to_clust(pgidx, inode);
++      clust->index_valid = 1;
 +}
 +
-+static inline int
-+alloc_clust_pages(reiser4_cluster_t * clust, struct inode *inode)
++static inline int alloc_clust_pages(struct cluster_handle * clust,
++                                  struct inode *inode)
 +{
 +      assert("edward-791", clust != NULL);
 +      assert("edward-792", inode != NULL);
 +      clust->pages =
 +              kmalloc(sizeof(*clust->pages) << inode_cluster_shift(inode),
-+                      GFP_KERNEL);
++                      reiser4_ctx_gfp_mask_get());
 +      if (!clust->pages)
 +              return -ENOMEM;
 +      return 0;
 +}
 +
-+static inline void free_clust_pages(reiser4_cluster_t * clust)
++static inline void free_clust_pages(struct cluster_handle * clust)
 +{
 +      kfree(clust->pages);
 +}
@@ -25723,22 +25588,10 @@ Index: linux-2.6.16/fs/reiser4/plugin/cluster.h
 +   scroll-step: 1
 +   End:
 +*/
-Index: linux-2.6.16/fs/reiser4/plugin/compress/Makefile
-===================================================================
---- /dev/null
-+++ linux-2.6.16/fs/reiser4/plugin/compress/Makefile
-@@ -0,0 +1,6 @@
-+obj-$(CONFIG_REISER4_FS) += compress_plugins.o
-+
-+compress_plugins-objs :=      \
-+      compress.o              \
-+      minilzo.o               \
-+      compress_mode.o
-Index: linux-2.6.16/fs/reiser4/plugin/compress/compress.c
-===================================================================
---- /dev/null
-+++ linux-2.6.16/fs/reiser4/plugin/compress/compress.c
-@@ -0,0 +1,370 @@
+diff -urN linux-2.6.22.orig/fs/reiser4/plugin/compress/compress.c linux-2.6.22/fs/reiser4/plugin/compress/compress.c
+--- linux-2.6.22.orig/fs/reiser4/plugin/compress/compress.c    1970-01-01 03:00:00.000000000 +0300
++++ linux-2.6.22/fs/reiser4/plugin/compress/compress.c 2007-07-29 00:25:34.892700618 +0400
+@@ -0,0 +1,381 @@
 +/* Copyright 2001, 2002, 2003 by Hans Reiser, licensing governed by reiser4/README */
 +/* reiser4 compression transform plugins */
 +
@@ -25747,20 +25600,31 @@ Index: linux-2.6.16/fs/reiser4/plugin/compress/compress.c
 +#include "../plugin.h"
 +#include "minilzo.h"
 +
-+#include <linux/config.h>
 +#include <linux/zlib.h>
 +#include <linux/types.h>
 +#include <linux/hardirq.h>
 +
-+static int change_compression(struct inode *inode, reiser4_plugin * plugin)
++static int change_compression(struct inode *inode,
++                            reiser4_plugin * plugin,
++                            pset_member memb)
 +{
 +      assert("edward-1316", inode != NULL);
 +      assert("edward-1317", plugin != NULL);
 +      assert("edward-1318", is_reiser4_inode(inode));
 +      assert("edward-1319",
 +             plugin->h.type_id == REISER4_COMPRESSION_PLUGIN_TYPE);
-+      /* cannot change compression plugin of already existing object */
-+      return RETERR(-EINVAL);
++
++      /* cannot change compression plugin of already existing regular object */
++      if (!plugin_of_group(inode_file_plugin(inode), REISER4_DIRECTORY_FILE))
++              return RETERR(-EINVAL);
++
++      /* If matches, nothing to change. */
++      if (inode_hash_plugin(inode) != NULL &&
++          inode_hash_plugin(inode)->h.id == plugin->h.id)
++              return 0;
++
++      return aset_set_unsafe(&reiser4_inode_data(inode)->pset,
++                             PSET_COMPRESSION, plugin);
 +}
 +
 +static reiser4_plugin_ops compression_plugin_ops = {
@@ -25801,16 +25665,16 @@ Index: linux-2.6.16/fs/reiser4/plugin/compress/compress.c
 +#if REISER4_ZLIB
 +      int ret = 0;
 +      switch (act) {
-+      case TFM_WRITE_ACT:     /* compress */
-+              coa = vmalloc(zlib_deflate_workspacesize());
++      case TFMA_WRITE:        /* compress */
++              coa = reiser4_vmalloc(zlib_deflate_workspacesize());
 +              if (!coa) {
 +                      ret = -ENOMEM;
 +                      break;
 +              }
 +              memset(coa, 0, zlib_deflate_workspacesize());
 +              break;
-+      case TFM_READ_ACT:      /* decompress */
-+              coa = vmalloc(zlib_inflate_workspacesize());
++      case TFMA_READ: /* decompress */
++              coa = reiser4_vmalloc(zlib_inflate_workspacesize());
 +              if (!coa) {
 +                      ret = -ENOMEM;
 +                      break;
@@ -25836,10 +25700,10 @@ Index: linux-2.6.16/fs/reiser4/plugin/compress/compress.c
 +      assert("edward-769", coa != NULL);
 +
 +      switch (act) {
-+      case TFM_WRITE_ACT:     /* compress */
++      case TFMA_WRITE:        /* compress */
 +              vfree(coa);
 +              break;
-+      case TFM_READ_ACT:              /* decompress */
++      case TFMA_READ:         /* decompress */
 +              vfree(coa);
 +              break;
 +      default:
@@ -25977,14 +25841,14 @@ Index: linux-2.6.16/fs/reiser4/plugin/compress/compress.c
 +      coa_t coa = NULL;
 +
 +      switch (act) {
-+      case TFM_WRITE_ACT:     /* compress */
-+              coa = vmalloc(LZO_HEAP_SIZE(LZO1X_1_MEM_COMPRESS));
++      case TFMA_WRITE:        /* compress */
++              coa = reiser4_vmalloc(LZO_HEAP_SIZE(LZO1X_1_MEM_COMPRESS));
 +              if (!coa) {
 +                      ret = -ENOMEM;
 +                      break;
 +              }
 +              memset(coa, 0, LZO_HEAP_SIZE(LZO1X_1_MEM_COMPRESS));
-+      case TFM_READ_ACT:              /* decompress */
++      case TFMA_READ:         /* decompress */
 +              break;
 +      default:
 +              impossible("edward-877",
@@ -26004,10 +25868,10 @@ Index: linux-2.6.16/fs/reiser4/plugin/compress/compress.c
 +      assert("edward-879", coa != NULL);
 +
 +      switch (act) {
-+      case TFM_WRITE_ACT:     /* compress */
++      case TFMA_WRITE:        /* compress */
 +              vfree(coa);
 +              break;
-+      case TFM_READ_ACT:              /* decompress */
++      case TFMA_READ:         /* decompress */
 +              impossible("edward-1304",
 +                         "trying to free non-allocated workspace");
 +      default:
@@ -26093,7 +25957,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/compress/compress.c
 +              .alloc = gzip1_alloc,
 +              .free = gzip1_free,
 +              .min_size_deflate = gzip1_min_size_deflate,
-+              .checksum = NULL,
++              .checksum = reiser4_adler32,
 +              .compress = gzip1_compress,
 +              .decompress = gzip1_decompress
 +      }
@@ -26109,34 +25973,38 @@ Index: linux-2.6.16/fs/reiser4/plugin/compress/compress.c
 +  scroll-step: 1
 +  End:
 +*/
-Index: linux-2.6.16/fs/reiser4/plugin/compress/compress.h
-===================================================================
---- /dev/null
-+++ linux-2.6.16/fs/reiser4/plugin/compress/compress.h
-@@ -0,0 +1,38 @@
+diff -urN linux-2.6.22.orig/fs/reiser4/plugin/compress/compress.h linux-2.6.22/fs/reiser4/plugin/compress/compress.h
+--- linux-2.6.22.orig/fs/reiser4/plugin/compress/compress.h    1970-01-01 03:00:00.000000000 +0300
++++ linux-2.6.22/fs/reiser4/plugin/compress/compress.h 2007-07-29 00:25:34.892700618 +0400
+@@ -0,0 +1,43 @@
 +#if !defined( __FS_REISER4_COMPRESS_H__ )
 +#define __FS_REISER4_COMPRESS_H__
 +
 +#include <linux/types.h>
 +#include <linux/string.h>
 +
++/* transform direction */
 +typedef enum {
-+      TFM_READ_ACT,
-+      TFM_WRITE_ACT,
-+      TFM_LAST_ACT
++      TFMA_READ,   /* decrypt, decompress */
++      TFMA_WRITE,  /* encrypt, compress */
++      TFMA_LAST
 +} tfm_action;
 +
-+/* builtin compression plugins */
-+
++/* supported compression algorithms */
 +typedef enum {
 +      LZO1_COMPRESSION_ID,
 +      GZIP1_COMPRESSION_ID,
 +      LAST_COMPRESSION_ID,
 +} reiser4_compression_id;
 +
++/* the same as pgoff, but units are page clusters */
 +typedef unsigned long cloff_t;
++
++/* working data of a (de)compression algorithm */
 +typedef void *coa_t;
-+typedef coa_t coa_set[LAST_COMPRESSION_ID][TFM_LAST_ACT];
++
++/* table for all supported (de)compression algorithms */
++typedef coa_t coa_set[LAST_COMPRESSION_ID][TFMA_LAST];
 +
 +__u32 reiser4_adler32(char *data, __u32 len);
 +
@@ -26152,11 +26020,10 @@ Index: linux-2.6.16/fs/reiser4/plugin/compress/compress.h
 +   scroll-step: 1
 +   End:
 +*/
-Index: linux-2.6.16/fs/reiser4/plugin/compress/compress_mode.c
-===================================================================
---- /dev/null
-+++ linux-2.6.16/fs/reiser4/plugin/compress/compress_mode.c
-@@ -0,0 +1,163 @@
+diff -urN linux-2.6.22.orig/fs/reiser4/plugin/compress/compress_mode.c linux-2.6.22/fs/reiser4/plugin/compress/compress_mode.c
+--- linux-2.6.22.orig/fs/reiser4/plugin/compress/compress_mode.c       1970-01-01 03:00:00.000000000 +0300
++++ linux-2.6.22/fs/reiser4/plugin/compress/compress_mode.c    2007-07-29 00:25:34.892700618 +0400
+@@ -0,0 +1,162 @@
 +/* Copyright 2001, 2002, 2003 by Hans Reiser, licensing governed by reiser4/README */
 +/* This file contains Reiser4 compression mode plugins.
 +
@@ -26168,11 +26035,6 @@ Index: linux-2.6.16/fs/reiser4/plugin/compress/compress_mode.c
 +#include "../../inode.h"
 +#include "../plugin.h"
 +
-+static int should_deflate_test(struct inode * inode, cloff_t index)
-+{
-+      return !test_bit(0, &index);
-+}
-+
 +static int should_deflate_none(struct inode * inode, cloff_t index)
 +{
 +      return 0;
@@ -26183,71 +26045,58 @@ Index: linux-2.6.16/fs/reiser4/plugin/compress/compress_mode.c
 +      return compression_is_on(cryptcompress_inode_data(inode));
 +}
 +
-+static int turn_off_compression(struct inode *inode, cloff_t index)
++static int discard_hook_ultim(struct inode *inode, cloff_t index)
 +{
-+      toggle_compression(cryptcompress_inode_data(inode), 0);
++      turn_off_compression(cryptcompress_inode_data(inode));
 +      return 0;
 +}
 +
-+static int turn_on_compression(struct inode *inode, cloff_t index)
++static int discard_hook_lattd(struct inode *inode, cloff_t index)
 +{
-+      toggle_compression(cryptcompress_inode_data(inode), 1);
++      struct cryptcompress_info * info = cryptcompress_inode_data(inode);
++
++      assert("edward-1462",
++             get_lattice_factor(info) >= MIN_LATTICE_FACTOR &&
++             get_lattice_factor(info) <= MAX_LATTICE_FACTOR);
++
++      turn_off_compression(info);
++      if (get_lattice_factor(info) < MAX_LATTICE_FACTOR)
++              set_lattice_factor(info, get_lattice_factor(info) << 1);
 +      return 0;
 +}
 +
-+static int turn_off_compression_on_zero(struct inode *inode, cloff_t index)
++static int accept_hook_lattd(struct inode *inode, cloff_t index)
 +{
-+      assert("edward-1308", inode != NULL);
-+      if (index == 0)
-+              toggle_compression(cryptcompress_inode_data(inode), 0);
++      turn_on_compression(cryptcompress_inode_data(inode));
++      set_lattice_factor(cryptcompress_inode_data(inode), MIN_LATTICE_FACTOR);
 +      return 0;
 +}
 +
-+/* Check on lattice (COL) of some sparseness factor,
-+   the family of adaptive compression modes which define
-+   the following behavior:
-+   
++/* Check on dynamic lattice, the adaptive compression modes which
++   defines the following behavior:
++
 +   Compression is on: try to compress everything and turn
 +   it off, whenever cluster is incompressible.
-+   
-+   Compression is off: try to compress clusters of indexes 
++
++   Compression is off: try to compress clusters of indexes
 +   k * FACTOR (k = 0, 1, 2, ...) and turn it on, if some of
-+   them is compressible. */
++   them is compressible. If incompressible, then increase FACTOR */
 +
 +/* check if @index belongs to one-dimensional lattice
 +   of sparce factor @factor */
-+static int check_on_lattice(cloff_t index, int factor)
++static int is_on_lattice(cloff_t index, int factor)
 +{
 +      return (factor ? index % factor == 0: index == 0);
 +}
 +
-+#define DEFINE_CHECK_ON_LATTICE(FACTOR)                                 \
-+      static int check_on_lattice_ ## FACTOR (struct inode * inode,   \
-+                                              cloff_t index)          \
-+{                                                                       \
-+      return should_deflate_common(inode, index) ||                   \
-+              check_on_lattice(index, FACTOR);                        \
-+}
-+
-+#define SUPPORT_COL_COMPRESSION_MODE(FACTOR, LABEL)                     \
-+[COL_ ## FACTOR ## _COMPRESSION_MODE_ID] = {                            \
-+      .h = {                                                          \
-+              .type_id = REISER4_COMPRESSION_MODE_PLUGIN_TYPE,        \
-+              .id = COL_ ## FACTOR ## _COMPRESSION_MODE_ID,           \
-+              .pops = NULL,                                           \
-+              .label = LABEL,                                         \
-+              .desc = LABEL,                                          \
-+              .linkage = {NULL, NULL}                                 \
-+      },                                                              \
-+      .should_deflate = check_on_lattice_ ## FACTOR,                  \
-+      .accept_hook =  turn_on_compression,                            \
-+      .discard_hook = turn_off_compression                            \
++static int should_deflate_lattd(struct inode * inode, cloff_t index)
++{
++      return should_deflate_common(inode, index) ||
++              is_on_lattice(index,
++                            get_lattice_factor
++                            (cryptcompress_inode_data(inode)));
 +}
 +
-+DEFINE_CHECK_ON_LATTICE(8)
-+DEFINE_CHECK_ON_LATTICE(16)
-+DEFINE_CHECK_ON_LATTICE(32)
-+
 +/* compression mode_plugins */
 +compression_mode_plugin compression_mode_plugins[LAST_COMPRESSION_MODE_ID] = {
 +      [NONE_COMPRESSION_MODE_ID] = {
@@ -26256,55 +26105,72 @@ Index: linux-2.6.16/fs/reiser4/plugin/compress/compress_mode.c
 +                      .id = NONE_COMPRESSION_MODE_ID,
 +                      .pops = NULL,
 +                      .label = "none",
-+                      .desc = "Don't compress",
++                      .desc = "Compress nothing",
 +                      .linkage = {NULL, NULL}
 +              },
 +              .should_deflate = should_deflate_none,
 +              .accept_hook = NULL,
 +              .discard_hook = NULL
 +      },
-+      /* Check-on-lattice adaptive compression modes */
-+      SUPPORT_COL_COMPRESSION_MODE(8, "col8"),
-+      SUPPORT_COL_COMPRESSION_MODE(16, "col16"),
-+      SUPPORT_COL_COMPRESSION_MODE(32, "col32"),
-+      /* Turn off compression if logical cluster of index == 0
-+         is incompressible, then don't check anymore */
-+      [COZ_COMPRESSION_MODE_ID] = {
++      /* Check-on-dynamic-lattice adaptive compression mode */
++      [LATTD_COMPRESSION_MODE_ID] = {
++              .h = {
++                      .type_id = REISER4_COMPRESSION_MODE_PLUGIN_TYPE,
++                      .id = LATTD_COMPRESSION_MODE_ID,
++                      .pops = NULL,
++                      .label = "lattd",
++                      .desc = "Check on dynamic lattice",
++                      .linkage = {NULL, NULL}
++              },
++              .should_deflate = should_deflate_lattd,
++              .accept_hook = accept_hook_lattd,
++              .discard_hook = discard_hook_lattd
++      },
++      /* Check-ultimately compression mode:
++         Turn off compression forever as soon as we meet
++         incompressible data */
++      [ULTIM_COMPRESSION_MODE_ID] = {
 +              .h = {
 +                      .type_id = REISER4_COMPRESSION_MODE_PLUGIN_TYPE,
-+                      .id = COZ_COMPRESSION_MODE_ID,
++                      .id = ULTIM_COMPRESSION_MODE_ID,
 +                      .pops = NULL,
-+                      .label = "coz",
-+                      .desc = "Check on zero",
++                      .label = "ultim",
++                      .desc = "Check ultimately",
 +                      .linkage = {NULL, NULL}
 +              },
 +              .should_deflate = should_deflate_common,
 +              .accept_hook = NULL,
-+              .discard_hook = turn_off_compression_on_zero
++              .discard_hook = discard_hook_ultim
 +      },
++      /* Force-to-compress-everything compression mode */
 +      [FORCE_COMPRESSION_MODE_ID] = {
 +              .h = {
 +                      .type_id = REISER4_COMPRESSION_MODE_PLUGIN_TYPE,
 +                      .id = FORCE_COMPRESSION_MODE_ID,
 +                      .pops = NULL,
 +                      .label = "force",
-+                      .desc = "Compress everything",
++                      .desc = "Force to compress everything",
 +                      .linkage = {NULL, NULL}
 +              },
 +              .should_deflate = NULL,
 +              .accept_hook = NULL,
 +              .discard_hook = NULL
 +      },
-+      [TEST_COMPRESSION_MODE_ID] = {
++      /* Convert-to-extent compression mode.
++         In this mode items will be converted to extents and management
++         will be passed to (classic) unix file plugin as soon as ->write()
++         detects that the first complete logical cluster (of index #0) is
++         incompressible. */
++      [CONVX_COMPRESSION_MODE_ID] = {
 +              .h = {
 +                      .type_id = REISER4_COMPRESSION_MODE_PLUGIN_TYPE,
-+                      .id = TEST_COMPRESSION_MODE_ID,
++                      .id = CONVX_COMPRESSION_MODE_ID,
 +                      .pops = NULL,
-+                      .label = "test", /* This mode is for benchmarks only */
-+                      .desc = "Don't compress odd clusters",
++                      .label = "conv",
++                      .desc = "Convert to extent",
 +                      .linkage = {NULL, NULL}
 +              },
-+              .should_deflate = should_deflate_test,
++              .should_deflate = should_deflate_common,
 +              .accept_hook = NULL,
 +              .discard_hook = NULL
 +      }
@@ -26320,11 +26186,10 @@ Index: linux-2.6.16/fs/reiser4/plugin/compress/compress_mode.c
 +  scroll-step: 1
 +  End:
 +*/
-Index: linux-2.6.16/fs/reiser4/plugin/compress/lzoconf.h
-===================================================================
---- /dev/null
-+++ linux-2.6.16/fs/reiser4/plugin/compress/lzoconf.h
-@@ -0,0 +1,420 @@
+diff -urN linux-2.6.22.orig/fs/reiser4/plugin/compress/lzoconf.h linux-2.6.22/fs/reiser4/plugin/compress/lzoconf.h
+--- linux-2.6.22.orig/fs/reiser4/plugin/compress/lzoconf.h     1970-01-01 03:00:00.000000000 +0300
++++ linux-2.6.22/fs/reiser4/plugin/compress/lzoconf.h  2007-07-29 00:25:34.896701653 +0400
+@@ -0,0 +1,216 @@
 +/* lzoconf.h -- configuration for the LZO real-time data compression library
 +   adopted for reiser4 compression transform plugin.
 +
@@ -26370,12 +26235,6 @@ Index: linux-2.6.16/fs/reiser4/plugin/compress/lzoconf.h
 +#define LZO_VERSION_DATE        "Jul 12 2002"
 +
 +/* internal Autoconf configuration file - only used when building LZO */
-+#if defined(LZO_HAVE_CONFIG_H)
-+#  include <config.h>
-+#endif
-+#ifdef __cplusplus
-+extern "C" {
-+#endif
 +
 +/***********************************************************************
 +// LZO requires a conforming <limits.h>
@@ -26391,52 +26250,9 @@ Index: linux-2.6.16/fs/reiser4/plugin/compress/lzoconf.h
 +// architecture defines
 +************************************************************************/
 +
-+#if !defined(__LZO_WIN) && !defined(__LZO_DOS) && !defined(__LZO_OS2)
-+#  if defined(__WINDOWS__) || defined(_WINDOWS) || defined(_Windows)
-+#    define __LZO_WIN
-+#  elif defined(__WIN32__) || defined(_WIN32) || defined(WIN32)
-+#    define __LZO_WIN
-+#  elif defined(__NT__) || defined(__NT_DLL__) || defined(__WINDOWS_386__)
-+#    define __LZO_WIN
-+#  elif defined(__DOS__) || defined(__MSDOS__) || defined(MSDOS)
-+#    define __LZO_DOS
-+#  elif defined(__OS2__) || defined(__OS2V2__) || defined(OS2)
-+#    define __LZO_OS2
-+#  elif defined(__palmos__)
-+#    define __LZO_PALMOS
-+#  elif defined(__TOS__) || defined(__atarist__)
-+#    define __LZO_TOS
-+#  endif
-+#endif
-+
-+#if (UINT_MAX < LZO_0xffffffffL)
-+#  if defined(__LZO_WIN)
-+#    define __LZO_WIN16
-+#  elif defined(__LZO_DOS)
-+#    define __LZO_DOS16
-+#  elif defined(__LZO_PALMOS)
-+#    define __LZO_PALMOS16
-+#  elif defined(__LZO_TOS)
-+#    define __LZO_TOS16
-+#  elif defined(__C166__)
-+#  else
-+      /* porting hint: for pure 16-bit architectures try compiling
-+       * everything with -D__LZO_STRICT_16BIT */
-+#    error "16-bit target not supported - contact me for porting hints"
-+#  endif
-+#endif
-+
 +#if !defined(__LZO_i386)
-+#  if defined(__LZO_DOS) || defined(__LZO_WIN16)
++#  if defined(__i386__) || defined(__386__) || defined(_M_IX86)
 +#    define __LZO_i386
-+#  elif defined(__i386__) || defined(__386__) || defined(_M_IX86)
-+#    define __LZO_i386
-+#  endif
-+#endif
-+
-+#if defined(__LZO_STRICT_16BIT)
-+#  if (UINT_MAX < LZO_0xffffffffL)
-+#    include <lzo16bit.h>
 +#  endif
 +#endif
 +
@@ -26501,37 +26317,10 @@ Index: linux-2.6.16/fs/reiser4/plugin/compress/lzoconf.h
 +// memory models
 +************************************************************************/
 +
-+/* Memory model for the public code segment. */
-+#if !defined(__LZO_CMODEL)
-+#  if defined(__LZO_DOS16) || defined(__LZO_WIN16)
-+#    define __LZO_CMODEL        __far
-+#  elif defined(__LZO_i386) && defined(__WATCOMC__)
-+#    define __LZO_CMODEL        __near
-+#  else
-+#    define __LZO_CMODEL
-+#  endif
-+#endif
-+
-+/* Memory model for the public data segment. */
-+#if !defined(__LZO_DMODEL)
-+#  if defined(__LZO_DOS16) || defined(__LZO_WIN16)
-+#    define __LZO_DMODEL        __far
-+#  elif defined(__LZO_i386) && defined(__WATCOMC__)
-+#    define __LZO_DMODEL        __near
-+#  else
-+#    define __LZO_DMODEL
-+#  endif
-+#endif
-+
 +/* Memory model that allows to access memory at offsets of lzo_uint. */
 +#if !defined(__LZO_MMODEL)
 +#  if (LZO_UINT_MAX <= UINT_MAX)
 +#    define __LZO_MMODEL
-+#  elif defined(__LZO_DOS16) || defined(__LZO_WIN16)
-+#    define __LZO_MMODEL        __huge
-+#    define LZO_999_UNSUPPORTED
-+#  elif defined(__LZO_PALMOS16) || defined(__LZO_TOS16)
-+#    define __LZO_MMODEL
 +#  else
 +#    error "__LZO_MMODEL"
 +#  endif
@@ -26555,134 +26344,10 @@ Index: linux-2.6.16/fs/reiser4/plugin/compress/lzoconf.h
 +#  define lzo_sizeof_dict_t     sizeof(lzo_bytep)
 +#endif
 +
-+/***********************************************************************
-+// calling conventions and function types
-+************************************************************************/
-+
-+/* linkage */
-+#if !defined(__LZO_EXTERN_C)
-+#  ifdef __cplusplus
-+#    define __LZO_EXTERN_C      extern "C"
-+#  else
-+#    define __LZO_EXTERN_C      extern
-+#  endif
-+#endif
-+
-+/* calling convention */
-+#if !defined(__LZO_CDECL)
-+#  if defined(__LZO_DOS16) || defined(__LZO_WIN16)
-+#    define __LZO_CDECL         __LZO_CMODEL __cdecl
-+#  elif defined(__LZO_i386) && defined(_MSC_VER)
-+#    define __LZO_CDECL         __LZO_CMODEL __cdecl
-+#  elif defined(__LZO_i386) && defined(__WATCOMC__)
-+#    define __LZO_CDECL         __LZO_CMODEL __cdecl
-+#  else
-+#    define __LZO_CDECL         __LZO_CMODEL
-+#  endif
-+#endif
-+#if !defined(__LZO_ENTRY)
-+#  define __LZO_ENTRY           __LZO_CDECL
-+#endif
-+
-+/* C++ exception specification for extern "C" function types */
-+#if !defined(__cplusplus)
-+#  undef LZO_NOTHROW
-+#  define LZO_NOTHROW
-+#elif !defined(LZO_NOTHROW)
-+#  define LZO_NOTHROW
-+#endif
-+
-+      typedef int
-+       (__LZO_ENTRY * lzo_compress_t) (const lzo_byte * src, lzo_uint src_len,
-+                                       lzo_byte * dst, lzo_uintp dst_len,
-+                                       lzo_voidp wrkmem);
-+
-+      typedef int
-+       (__LZO_ENTRY * lzo_decompress_t) (const lzo_byte * src,
-+                                         lzo_uint src_len, lzo_byte * dst,
-+                                         lzo_uintp dst_len, lzo_voidp wrkmem);
-+
-+      typedef int
-+       (__LZO_ENTRY * lzo_optimize_t) (lzo_byte * src, lzo_uint src_len,
-+                                       lzo_byte * dst, lzo_uintp dst_len,
-+                                       lzo_voidp wrkmem);
-+
-+      typedef int
-+       (__LZO_ENTRY * lzo_compress_dict_t) (const lzo_byte * src,
-+                                            lzo_uint src_len, lzo_byte * dst,
-+                                            lzo_uintp dst_len,
-+                                            lzo_voidp wrkmem,
-+                                            const lzo_byte * dict,
-+                                            lzo_uint dict_len);
-+
-+      typedef int
-+       (__LZO_ENTRY * lzo_decompress_dict_t) (const lzo_byte * src,
-+                                              lzo_uint src_len,
-+                                              lzo_byte * dst,
-+                                              lzo_uintp dst_len,
-+                                              lzo_voidp wrkmem,
-+                                              const lzo_byte * dict,
-+                                              lzo_uint dict_len);
-+
-+/* assembler versions always use __cdecl */
-+      typedef int
-+       (__LZO_CDECL * lzo_compress_asm_t) (const lzo_byte * src,
-+                                           lzo_uint src_len, lzo_byte * dst,
-+                                           lzo_uintp dst_len,
-+                                           lzo_voidp wrkmem);
-+
-+      typedef int
-+       (__LZO_CDECL * lzo_decompress_asm_t) (const lzo_byte * src,
-+                                             lzo_uint src_len, lzo_byte * dst,
-+                                             lzo_uintp dst_len,
-+                                             lzo_voidp wrkmem);
-+
-+/* a progress indicator callback function */
-+      typedef void (__LZO_ENTRY * lzo_progress_callback_t) (lzo_uint,
-+                                                            lzo_uint);
-+
-+/***********************************************************************
-+// export information
-+************************************************************************/
-+
-+/* DLL export information */
-+#if !defined(__LZO_EXPORT1)
-+#  define __LZO_EXPORT1
-+#endif
-+#if !defined(__LZO_EXPORT2)
-+#  define __LZO_EXPORT2
-+#endif
-+
-+/* exported calling convention for C functions */
-+#if !defined(LZO_PUBLIC)
-+#  define LZO_PUBLIC(_rettype) \
-+                __LZO_EXPORT1 _rettype __LZO_EXPORT2 __LZO_ENTRY
-+#endif
-+#if !defined(LZO_EXTERN)
-+#  define LZO_EXTERN(_rettype)          __LZO_EXTERN_C LZO_PUBLIC(_rettype)
-+#endif
-+#if !defined(LZO_PRIVATE)
-+#  define LZO_PRIVATE(_rettype)         static _rettype __LZO_ENTRY
-+#endif
-+
-+/* exported __cdecl calling convention for assembler functions */
-+#if !defined(LZO_PUBLIC_CDECL)
-+#  define LZO_PUBLIC_CDECL(_rettype) \
-+                __LZO_EXPORT1 _rettype __LZO_EXPORT2 __LZO_CDECL
-+#endif
-+#if !defined(LZO_EXTERN_CDECL)
-+#  define LZO_EXTERN_CDECL(_rettype)    __LZO_EXTERN_C LZO_PUBLIC_CDECL(_rettype)
-+#endif
++typedef int (*lzo_compress_t) (const lzo_byte * src, lzo_uint src_len,
++                             lzo_byte * dst, lzo_uintp dst_len,
++                             lzo_voidp wrkmem);
 +
-+/* exported global variables (LZO currently uses no static variables and
-+ * is fully thread safe) */
-+#if !defined(LZO_PUBLIC_VAR)
-+#  define LZO_PUBLIC_VAR(_type) \
-+                __LZO_EXPORT1 _type __LZO_EXPORT2 __LZO_DMODEL
-+#endif
-+#if !defined(LZO_EXTERN_VAR)
-+#  define LZO_EXTERN_VAR(_type)         extern LZO_PUBLIC_VAR(_type)
-+#endif
 +
 +/***********************************************************************
 +// error codes and prototypes
@@ -26712,13 +26377,12 @@ Index: linux-2.6.16/fs/reiser4/plugin/compress/lzoconf.h
 +    (int)sizeof(long),(int)sizeof(lzo_uint32),(int)sizeof(lzo_uint),\
 +    (int)lzo_sizeof_dict_t,(int)sizeof(char *),(int)sizeof(lzo_voidp),\
 +    (int)sizeof(lzo_compress_t))
-+       LZO_EXTERN(int) __lzo_init2(unsigned, int, int, int, int, int, int,
-+                                   int, int, int);
++       extern int __lzo_init2(unsigned, int, int, int, int, int, int,
++                              int, int, int);
 +
 +/* checksum functions */
-+       LZO_EXTERN(lzo_uint32)
-+       lzo_crc32(lzo_uint32 _c, const lzo_byte * _buf, lzo_uint _len);
-+
++extern lzo_uint32 lzo_crc32(lzo_uint32 _c, const lzo_byte * _buf,
++                          lzo_uint _len);
 +/* misc. */
 +      typedef union {
 +              lzo_bytep p;
@@ -26741,15 +26405,21 @@ Index: linux-2.6.16/fs/reiser4/plugin/compress/lzoconf.h
 +/* deprecated - only for backward compatibility */
 +#define LZO_ALIGN(_ptr,_size) LZO_PTR_ALIGN_UP(_ptr,_size)
 +
-+#ifdef __cplusplus
-+}                             /* extern "C" */
-+#endif
 +#endif                                /* already included */
-Index: linux-2.6.16/fs/reiser4/plugin/compress/minilzo.c
-===================================================================
---- /dev/null
-+++ linux-2.6.16/fs/reiser4/plugin/compress/minilzo.c
-@@ -0,0 +1,2155 @@
+diff -urN linux-2.6.22.orig/fs/reiser4/plugin/compress/Makefile linux-2.6.22/fs/reiser4/plugin/compress/Makefile
+--- linux-2.6.22.orig/fs/reiser4/plugin/compress/Makefile      1970-01-01 03:00:00.000000000 +0300
++++ linux-2.6.22/fs/reiser4/plugin/compress/Makefile   2007-07-29 00:25:34.896701653 +0400
+@@ -0,0 +1,6 @@
++obj-$(CONFIG_REISER4_FS) += compress_plugins.o
++
++compress_plugins-objs :=      \
++      compress.o              \
++      minilzo.o               \
++      compress_mode.o
+diff -urN linux-2.6.22.orig/fs/reiser4/plugin/compress/minilzo.c linux-2.6.22/fs/reiser4/plugin/compress/minilzo.c
+--- linux-2.6.22.orig/fs/reiser4/plugin/compress/minilzo.c     1970-01-01 03:00:00.000000000 +0300
++++ linux-2.6.22/fs/reiser4/plugin/compress/minilzo.c  2007-07-29 00:25:34.900702689 +0400
+@@ -0,0 +1,1967 @@
 +/* minilzo.c -- mini subset of the LZO real-time data compression library
 +   adopted for reiser4 compression transform plugin.
 +
@@ -26796,48 +26466,23 @@ Index: linux-2.6.16/fs/reiser4/plugin/compress/minilzo.c
 +#define __LZO_IN_MINILZO
 +#define LZO_BUILD
 +
-+#ifdef MINILZO_HAVE_CONFIG_H
-+#  include <config.h>
-+#endif
-+
-+#undef LZO_HAVE_CONFIG_H
 +#include "minilzo.h"
 +
 +#if !defined(MINILZO_VERSION) || (MINILZO_VERSION != 0x1080)
 +#  error "version mismatch in miniLZO source files"
 +#endif
 +
-+#ifdef MINILZO_HAVE_CONFIG_H
-+#  define LZO_HAVE_CONFIG_H
-+#endif
-+
-+
 +#ifndef __LZO_CONF_H
 +#define __LZO_CONF_H
 +
-+#if !defined(__LZO_IN_MINILZO)
-+#  ifndef __LZOCONF_H
-+#    include <lzoconf.h>
-+#  endif
-+#endif
-+
-+#if defined(__BOUNDS_CHECKING_ON)
-+#  include <unchecked.h>
-+#else
 +#  define BOUNDS_CHECKING_OFF_DURING(stmt)      stmt
 +#  define BOUNDS_CHECKING_OFF_IN_EXPR(expr)     (expr)
-+#endif
 +
 +#  define HAVE_MEMCMP
 +#  define HAVE_MEMCPY
 +#  define HAVE_MEMMOVE
 +#  define HAVE_MEMSET
 +
-+#if defined(__LZO_DOS16) || defined(__LZO_WIN16)
-+#  define HAVE_MALLOC_H
-+#  define HAVE_HALLOC
-+#endif
-+
 +#undef NDEBUG
 +#if !defined(LZO_DEBUG)
 +#  define NDEBUG
@@ -26847,9 +26492,6 @@ Index: linux-2.6.16/fs/reiser4/plugin/compress/minilzo.c
 +#    include <stdio.h>
 +#  endif
 +#endif
-+# if 0                                /* edward */
-+#include <assert.h>
-+#endif                                /* edward */
 +
 +#if !defined(LZO_COMPILE_TIME_ASSERT)
 +#  define LZO_COMPILE_TIME_ASSERT(expr) \
@@ -26866,14 +26508,6 @@ Index: linux-2.6.16/fs/reiser4/plugin/compress/minilzo.c
 +#  endif
 +#endif
 +
-+#if !defined(__inline__) && !defined(__GNUC__)
-+#  if defined(__cplusplus)
-+#    define __inline__      inline
-+#  else
-+#    define __inline__
-+#  endif
-+#endif
-+
 +#if defined(NO_MEMCMP)
 +#  undef HAVE_MEMCMP
 +#endif
@@ -27008,7 +26642,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/compress/minilzo.c
 +#  endif
 +#endif
 +
-+__LZO_EXTERN_C const lzo_uint32 _lzo_crc32_table[256];
++extern const lzo_uint32 _lzo_crc32_table[256];
 +
 +#define _LZO_STRINGIZE(x)           #x
 +#define _LZO_MEXPAND(x)             _LZO_STRINGIZE(x)
@@ -27026,37 +26660,11 @@ Index: linux-2.6.16/fs/reiser4/plugin/compress/minilzo.c
 +#ifndef __LZO_PTR_H
 +#define __LZO_PTR_H
 +
-+#ifdef __cplusplus
-+extern "C" {
-+#endif
-+
-+#if defined(__LZO_DOS16) || defined(__LZO_WIN16)
-+#  include <dos.h>
-+#  if 1 && defined(__WATCOMC__)
-+#    include <i86.h>
-+      __LZO_EXTERN_C unsigned char _HShift;
-+#    define __LZO_HShift    _HShift
-+#  elif 1 && defined(_MSC_VER)
-+      __LZO_EXTERN_C unsigned short __near _AHSHIFT;
-+#    define __LZO_HShift    ((unsigned) &_AHSHIFT)
-+#  elif defined(__LZO_WIN16)
-+#    define __LZO_HShift    3
-+#  else
-+#    define __LZO_HShift    12
-+#  endif
-+#  if !defined(_FP_SEG) && defined(FP_SEG)
-+#    define _FP_SEG         FP_SEG
-+#  endif
-+#  if !defined(_FP_OFF) && defined(FP_OFF)
-+#    define _FP_OFF         FP_OFF
-+#  endif
-+#endif
-+
 +#if !defined(lzo_ptrdiff_t)
 +#  if (UINT_MAX >= LZO_0xffffffffL)
-+      typedef ptrdiff_t lzo_ptrdiff_t;
++typedef ptrdiff_t lzo_ptrdiff_t;
 +#  else
-+      typedef long lzo_ptrdiff_t;
++typedef long lzo_ptrdiff_t;
 +#  endif
 +#endif
 +
@@ -27068,8 +26676,8 @@ Index: linux-2.6.16/fs/reiser4/plugin/compress/minilzo.c
 +#if !defined(__LZO_HAVE_PTR_T)
 +#  if defined(SIZEOF_CHAR_P) && defined(SIZEOF_UNSIGNED_LONG)
 +#    if (SIZEOF_CHAR_P == SIZEOF_UNSIGNED_LONG)
-+      typedef unsigned long lzo_ptr_t;
-+      typedef long lzo_sptr_t;
++typedef unsigned long lzo_ptr_t;
++typedef long lzo_sptr_t;
 +#      define __LZO_HAVE_PTR_T
 +#    endif
 +#  endif
@@ -27077,8 +26685,8 @@ Index: linux-2.6.16/fs/reiser4/plugin/compress/minilzo.c
 +#if !defined(__LZO_HAVE_PTR_T)
 +#  if defined(SIZEOF_CHAR_P) && defined(SIZEOF_UNSIGNED)
 +#    if (SIZEOF_CHAR_P == SIZEOF_UNSIGNED)
-+      typedef unsigned int lzo_ptr_t;
-+      typedef int lzo_sptr_t;
++typedef unsigned int lzo_ptr_t;
++typedef int lzo_sptr_t;
 +#      define __LZO_HAVE_PTR_T
 +#    endif
 +#  endif
@@ -27086,8 +26694,8 @@ Index: linux-2.6.16/fs/reiser4/plugin/compress/minilzo.c
 +#if !defined(__LZO_HAVE_PTR_T)
 +#  if defined(SIZEOF_CHAR_P) && defined(SIZEOF_UNSIGNED_SHORT)
 +#    if (SIZEOF_CHAR_P == SIZEOF_UNSIGNED_SHORT)
-+      typedef unsigned short lzo_ptr_t;
-+      typedef short lzo_sptr_t;
++typedef unsigned short lzo_ptr_t;
++typedef short lzo_sptr_t;
 +#      define __LZO_HAVE_PTR_T
 +#    endif
 +#  endif
@@ -27096,90 +26704,64 @@ Index: linux-2.6.16/fs/reiser4/plugin/compress/minilzo.c
 +#  if defined(LZO_HAVE_CONFIG_H) || defined(SIZEOF_CHAR_P)
 +#    error "no suitable type for lzo_ptr_t"
 +#  else
-+      typedef unsigned long lzo_ptr_t;
-+      typedef long lzo_sptr_t;
++typedef unsigned long lzo_ptr_t;
++typedef long lzo_sptr_t;
 +#    define __LZO_HAVE_PTR_T
 +#  endif
 +#endif
 +
-+#if defined(__LZO_DOS16) || defined(__LZO_WIN16)
-+#define PTR(a)              ((lzo_bytep) (a))
-+#define PTR_ALIGNED_4(a)    ((_FP_OFF(a) & 3) == 0)
-+#define PTR_ALIGNED2_4(a,b) (((_FP_OFF(a) | _FP_OFF(b)) & 3) == 0)
-+#else
 +#define PTR(a)              ((lzo_ptr_t) (a))
 +#define PTR_LINEAR(a)       PTR(a)
 +#define PTR_ALIGNED_4(a)    ((PTR_LINEAR(a) & 3) == 0)
 +#define PTR_ALIGNED_8(a)    ((PTR_LINEAR(a) & 7) == 0)
 +#define PTR_ALIGNED2_4(a,b) (((PTR_LINEAR(a) | PTR_LINEAR(b)) & 3) == 0)
 +#define PTR_ALIGNED2_8(a,b) (((PTR_LINEAR(a) | PTR_LINEAR(b)) & 7) == 0)
-+#endif
 +
 +#define PTR_LT(a,b)         (PTR(a) < PTR(b))
 +#define PTR_GE(a,b)         (PTR(a) >= PTR(b))
 +#define PTR_DIFF(a,b)       ((lzo_ptrdiff_t) (PTR(a) - PTR(b)))
 +#define pd(a,b)             ((lzo_uint) ((a)-(b)))
 +
-+      typedef union {
-+              char a_char;
-+              unsigned char a_uchar;
-+              short a_short;
-+              unsigned short a_ushort;
-+              int a_int;
-+              unsigned int a_uint;
-+              long a_long;
-+              unsigned long a_ulong;
-+              lzo_int a_lzo_int;
-+              lzo_uint a_lzo_uint;
-+              lzo_int32 a_lzo_int32;
-+              lzo_uint32 a_lzo_uint32;
-+              ptrdiff_t a_ptrdiff_t;
-+              lzo_ptrdiff_t a_lzo_ptrdiff_t;
-+              lzo_ptr_t a_lzo_ptr_t;
-+              lzo_voidp a_lzo_voidp;
-+              void *a_void_p;
-+              lzo_bytep a_lzo_bytep;
-+              lzo_bytepp a_lzo_bytepp;
-+              lzo_uintp a_lzo_uintp;
-+              lzo_uint *a_lzo_uint_p;
-+              lzo_uint32p a_lzo_uint32p;
-+              lzo_uint32 *a_lzo_uint32_p;
-+              unsigned char *a_uchar_p;
-+              char *a_char_p;
-+      } lzo_full_align_t;
++typedef union {
++      char a_char;
++      unsigned char a_uchar;
++      short a_short;
++      unsigned short a_ushort;
++      int a_int;
++      unsigned int a_uint;
++      long a_long;
++      unsigned long a_ulong;
++      lzo_int a_lzo_int;
++      lzo_uint a_lzo_uint;
++      lzo_int32 a_lzo_int32;
++      lzo_uint32 a_lzo_uint32;
++      ptrdiff_t a_ptrdiff_t;
++      lzo_ptrdiff_t a_lzo_ptrdiff_t;
++      lzo_ptr_t a_lzo_ptr_t;
++      lzo_voidp a_lzo_voidp;
++      void *a_void_p;
++      lzo_bytep a_lzo_bytep;
++      lzo_bytepp a_lzo_bytepp;
++      lzo_uintp a_lzo_uintp;
++      lzo_uint *a_lzo_uint_p;
++      lzo_uint32p a_lzo_uint32p;
++      lzo_uint32 *a_lzo_uint32_p;
++      unsigned char *a_uchar_p;
++      char *a_char_p;
++} lzo_full_align_t;
 +
-+#ifdef __cplusplus
-+}
-+#endif
 +#endif
 +#define LZO_DETERMINISTIC
 +#define LZO_DICT_USE_PTR
-+#if defined(__LZO_DOS16) || defined(__LZO_WIN16) || defined(__LZO_STRICT_16BIT)
-+#  undef LZO_DICT_USE_PTR
-+#endif
-+#if defined(LZO_DICT_USE_PTR)
 +#  define lzo_dict_t    const lzo_bytep
 +#  define lzo_dict_p    lzo_dict_t __LZO_MMODEL *
-+#else
-+#  define lzo_dict_t    lzo_uint
-+#  define lzo_dict_p    lzo_dict_t __LZO_MMODEL *
-+#endif
 +#if !defined(lzo_moff_t)
 +#define lzo_moff_t      lzo_uint
 +#endif
 +#endif
 +static lzo_ptr_t __lzo_ptr_linear(const lzo_voidp ptr)
 +{
-+      lzo_ptr_t p;
-+
-+#if defined(__LZO_DOS16) || defined(__LZO_WIN16)
-+      p = (((lzo_ptr_t) (_FP_SEG(ptr))) << (16 - __LZO_HShift)) +
-+          (_FP_OFF(ptr));
-+#else
-+      p = PTR_LINEAR(ptr);
-+#endif
-+
-+      return p;
++      return PTR_LINEAR(ptr);
 +}
 +
 +static unsigned __lzo_align_gap(const lzo_voidp ptr, lzo_uint size)
@@ -27204,19 +26786,11 @@ Index: linux-2.6.16/fs/reiser4/plugin/compress/minilzo.c
 +#ifndef __LZO_CONF_H
 +#endif
 +
-+#ifdef __cplusplus
-+extern "C" {
-+#endif
-+
 +#if 1 && defined(HAVE_MEMCPY)
-+#if !defined(__LZO_DOS16) && !defined(__LZO_WIN16)
-+
 +#define MEMCPY8_DS(dest,src,len) \
 +    memcpy(dest,src,len); \
 +    dest += len; \
 +    src += len
-+
-+#endif
 +#endif
 +
 +#if !defined(MEMCPY8_DS)
@@ -27244,7 +26818,6 @@ Index: linux-2.6.16/fs/reiser4/plugin/compress/minilzo.c
 +    do *dest++ = *src++; \
 +    while (--len > 0)
 +
-+
 +#if (LZO_UINT_MAX <= SIZE_T_MAX) && defined(HAVE_MEMSET)
 +
 +#define BZERO8_PTR(s,l,n)   memset((s),0,(lzo_uint)(l)*(n))
@@ -27255,11 +26828,6 @@ Index: linux-2.6.16/fs/reiser4/plugin/compress/minilzo.c
 +    lzo_memset((lzo_voidp)(s),0,(lzo_uint)(l)*(n))
 +
 +#endif
-+
-+#ifdef __cplusplus
-+}
-+#endif
-+
 +#endif
 +
 +/* If you use the LZO library in a product, you *must* keep this
@@ -27396,37 +26964,6 @@ Index: linux-2.6.16/fs/reiser4/plugin/compress/minilzo.c
 +#elif (USHRT_MAX >= LZO_0xffffffffL)
 +      COMPILE_TIME_ASSERT(sizeof(short) > 4);
 +#endif
-+#if 0                         /* to make gcc happy -edward */
-+#if (UINT_MAX == 65535u)
-+      COMPILE_TIME_ASSERT(sizeof(int) == 2);
-+#elif (UINT_MAX == LZO_0xffffffffL)
-+      COMPILE_TIME_ASSERT(sizeof(int) == 4);
-+#elif (UINT_MAX >= LZO_0xffffffffL)
-+      COMPILE_TIME_ASSERT(sizeof(int) > 4);
-+#endif
-+#if (ULONG_MAX == 65535ul)
-+      COMPILE_TIME_ASSERT(sizeof(long) == 2);
-+#elif (ULONG_MAX == LZO_0xffffffffL)
-+      COMPILE_TIME_ASSERT(sizeof(long) == 4);
-+#elif (ULONG_MAX >= LZO_0xffffffffL)
-+      COMPILE_TIME_ASSERT(sizeof(long) > 4);
-+#endif
-+#if defined(SIZEOF_UNSIGNED)
-+      COMPILE_TIME_ASSERT(SIZEOF_UNSIGNED == sizeof(unsigned));
-+#endif
-+#if defined(SIZEOF_UNSIGNED_LONG)
-+      COMPILE_TIME_ASSERT(SIZEOF_UNSIGNED_LONG == sizeof(unsigned long));
-+#endif
-+#if defined(SIZEOF_UNSIGNED_SHORT)
-+      COMPILE_TIME_ASSERT(SIZEOF_UNSIGNED_SHORT == sizeof(unsigned short));
-+#endif
-+#if !defined(__LZO_IN_MINILZO)
-+#if defined(SIZEOF_SIZE_T)
-+      COMPILE_TIME_ASSERT(SIZEOF_SIZE_T == sizeof(size_t));
-+#endif
-+#endif
-+#endif                                /* -edward */
-+
 +      COMPILE_TIME_ASSERT(IS_UNSIGNED(unsigned char));
 +      COMPILE_TIME_ASSERT(IS_UNSIGNED(unsigned short));
 +      COMPILE_TIME_ASSERT(IS_UNSIGNED(unsigned));
@@ -27444,14 +26981,10 @@ Index: linux-2.6.16/fs/reiser4/plugin/compress/minilzo.c
 +      COMPILE_TIME_ASSERT(UINT_MAX == LZO_UTYPE_MAX(sizeof(unsigned)));
 +      COMPILE_TIME_ASSERT(LONG_MAX == LZO_STYPE_MAX(sizeof(long)));
 +      COMPILE_TIME_ASSERT(ULONG_MAX == LZO_UTYPE_MAX(sizeof(unsigned long)));
-+      //    COMPILE_TIME_ASSERT(SHRT_MAX   == LZO_STYPE_MAX(sizeof(short))); /* edward */
 +      COMPILE_TIME_ASSERT(USHRT_MAX == LZO_UTYPE_MAX(sizeof(unsigned short)));
 +      COMPILE_TIME_ASSERT(LZO_UINT32_MAX ==
 +                          LZO_UTYPE_MAX(sizeof(lzo_uint32)));
 +      COMPILE_TIME_ASSERT(LZO_UINT_MAX == LZO_UTYPE_MAX(sizeof(lzo_uint)));
-+#if !defined(__LZO_IN_MINILZO)
-+      COMPILE_TIME_ASSERT(SIZE_T_MAX == LZO_UTYPE_MAX(sizeof(size_t)));
-+#endif
 +
 +      r &= __lzo_assert(LZO_BYTE(257) == 1);
 +
@@ -27603,8 +27136,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/compress/minilzo.c
 +              unsigned short b;
 +              lzo_uint32 aa[4];
 +              unsigned char x[4 * sizeof(lzo_full_align_t)];
-+      }
-+      u;
++      } u;
 +
 +      COMPILE_TIME_ASSERT((int)((unsigned char)((signed char)-1)) == 255);
 +      COMPILE_TIME_ASSERT((((unsigned char)128) << (int)(8 * sizeof(int) - 8))
@@ -27728,9 +27260,8 @@ Index: linux-2.6.16/fs/reiser4/plugin/compress/minilzo.c
 +
 +#undef COMPILE_TIME_ASSERT
 +
-+LZO_PUBLIC(int)
-+    __lzo_init2(unsigned v, int s1, int s2, int s3, int s4, int s5,
-+          int s6, int s7, int s8, int s9)
++int __lzo_init2(unsigned v, int s1, int s2, int s3, int s4, int s5,
++              int s6, int s7, int s8, int s9)
 +{
 +      int r;
 +
@@ -27756,21 +27287,6 @@ Index: linux-2.6.16/fs/reiser4/plugin/compress/minilzo.c
 +      return r;
 +}
 +
-+#if !defined(__LZO_IN_MINILZO)
-+
-+LZO_EXTERN(int)
-+    __lzo_init(unsigned v, int s1, int s2, int s3, int s4, int s5, int s6, int s7);
-+
-+LZO_PUBLIC(int)
-+__lzo_init(unsigned v, int s1, int s2, int s3, int s4, int s5, int s6, int s7)
-+{
-+      if (v == 0 || v > 0x1010)
-+              return LZO_E_ERROR;
-+      return __lzo_init2(v, s1, s2, s3, s4, s5, -1, -1, s6, s7);
-+}
-+
-+#endif
-+
 +#define do_compress         _lzo1x_1_do_compress
 +
 +#define LZO_NEED_DICT_H
@@ -27785,10 +27301,6 @@ Index: linux-2.6.16/fs/reiser4/plugin/compress/minilzo.c
 +#  define LZO1X
 +#endif
 +
-+#if !defined(__LZO_IN_MINILZO)
-+#include <lzo1x.h>
-+#endif
-+
 +#define LZO_EOF_CODE
 +#undef LZO_DETERMINISTIC
 +
@@ -27831,10 +27343,6 @@ Index: linux-2.6.16/fs/reiser4/plugin/compress/minilzo.c
 +#ifndef __LZO_DICT_H
 +#define __LZO_DICT_H
 +
-+#ifdef __cplusplus
-+extern "C" {
-+#endif
-+
 +#if !defined(D_BITS) && defined(DBITS)
 +#  define D_BITS        DBITS
 +#endif
@@ -27973,23 +27481,19 @@ Index: linux-2.6.16/fs/reiser4/plugin/compress/minilzo.c
 +
 +#if !defined(DVAL_ASSERT)
 +#if defined(__LZO_HASH_INCREMENTAL) && !defined(NDEBUG)
-+      static void DVAL_ASSERT(lzo_uint32 dv, const lzo_byte * p) {
-+              lzo_uint32 df;
-+               DVAL_FIRST(df, (p));
-+               assert(DINDEX(dv, p) == DINDEX(df, p));
-+      }
++static void DVAL_ASSERT(lzo_uint32 dv, const lzo_byte * p)
++{
++      lzo_uint32 df;
++      DVAL_FIRST(df, (p));
++      assert(DINDEX(dv, p) == DINDEX(df, p));
++}
 +#else
 +#  define DVAL_ASSERT(dv,p) ((void) 0)
 +#endif
 +#endif
 +
-+#if defined(LZO_DICT_USE_PTR)
 +#  define DENTRY(p,in)                          (p)
 +#  define GINDEX(m_pos,m_off,dict,dindex,in)    m_pos = dict[dindex]
-+#else
-+#  define DENTRY(p,in)                          ((lzo_uint) ((p)-(in)))
-+#  define GINDEX(m_pos,m_off,dict,dindex,in)    m_off = dict[dindex]
-+#endif
 +
 +#if (DD_BITS == 0)
 +
@@ -28008,8 +27512,6 @@ Index: linux-2.6.16/fs/reiser4/plugin/compress/minilzo.c
 +
 +#endif
 +
-+#if defined(LZO_DICT_USE_PTR)
-+
 +#define LZO_CHECK_MPOS_DET(m_pos,m_off,in,ip,max_offset) \
 +      (m_pos == NULL || (m_off = (lzo_moff_t) (ip - m_pos)) > max_offset)
 +
@@ -28019,29 +27521,11 @@ Index: linux-2.6.16/fs/reiser4/plugin/compress/minilzo.c
 +       (m_off = (lzo_moff_t) PTR_DIFF(ip,m_pos)) <= 0 || \
 +        m_off > max_offset) ))
 +
-+#else
-+
-+#define LZO_CHECK_MPOS_DET(m_pos,m_off,in,ip,max_offset) \
-+      (m_off == 0 || \
-+       ((m_off = (lzo_moff_t) ((ip)-(in)) - m_off) > max_offset) || \
-+       (m_pos = (ip) - (m_off), 0) )
-+
-+#define LZO_CHECK_MPOS_NON_DET(m_pos,m_off,in,ip,max_offset) \
-+      ((lzo_moff_t) ((ip)-(in)) <= m_off || \
-+       ((m_off = (lzo_moff_t) ((ip)-(in)) - m_off) > max_offset) || \
-+       (m_pos = (ip) - (m_off), 0) )
-+
-+#endif
-+
 +#if defined(LZO_DETERMINISTIC)
 +#  define LZO_CHECK_MPOS    LZO_CHECK_MPOS_DET
 +#else
 +#  define LZO_CHECK_MPOS    LZO_CHECK_MPOS_NON_DET
 +#endif
-+
-+#ifdef __cplusplus
-+}
-+#endif
 +#endif
 +#endif
 +#endif
@@ -28240,9 +27724,8 @@ Index: linux-2.6.16/fs/reiser4/plugin/compress/minilzo.c
 +      return pd(in_end, ii);
 +}
 +
-+LZO_PUBLIC(int)
-+    DO_COMPRESS(const lzo_byte * in, lzo_uint in_len,
-+          lzo_byte * out, lzo_uintp out_len, lzo_voidp wrkmem)
++int DO_COMPRESS(const lzo_byte * in, lzo_uint in_len,
++              lzo_byte * out, lzo_uintp out_len, lzo_voidp wrkmem)
 +{
 +      lzo_byte *op = out;
 +      lzo_uint t;
@@ -28399,9 +27882,8 @@ Index: linux-2.6.16/fs/reiser4/plugin/compress/minilzo.c
 +#endif
 +
 +#if defined(DO_DECOMPRESS)
-+LZO_PUBLIC(int)
-+    DO_DECOMPRESS(const lzo_byte * in, lzo_uint in_len,
-+            lzo_byte * out, lzo_uintp out_len, lzo_voidp wrkmem)
++int DO_DECOMPRESS(const lzo_byte * in, lzo_uint in_len,
++                lzo_byte * out, lzo_uintp out_len, lzo_voidp wrkmem)
 +#endif
 +{
 +      register lzo_byte *op;
@@ -28905,11 +28387,10 @@ Index: linux-2.6.16/fs/reiser4/plugin/compress/minilzo.c
 +#endif
 +
 +/***** End of minilzo.c *****/
-Index: linux-2.6.16/fs/reiser4/plugin/compress/minilzo.h
-===================================================================
---- /dev/null
-+++ linux-2.6.16/fs/reiser4/plugin/compress/minilzo.h
-@@ -0,0 +1,94 @@
+diff -urN linux-2.6.22.orig/fs/reiser4/plugin/compress/minilzo.h linux-2.6.22/fs/reiser4/plugin/compress/minilzo.h
+--- linux-2.6.22.orig/fs/reiser4/plugin/compress/minilzo.h     1970-01-01 03:00:00.000000000 +0300
++++ linux-2.6.22/fs/reiser4/plugin/compress/minilzo.h  2007-07-29 00:25:34.900702689 +0400
+@@ -0,0 +1,70 @@
 +/* minilzo.h -- mini subset of the LZO real-time data compression library
 +   adopted for reiser4 compression transform plugin.
 +
@@ -28956,25 +28437,8 @@ Index: linux-2.6.16/fs/reiser4/plugin/compress/minilzo.h
 +
 +#define MINILZO_VERSION         0x1080
 +
-+#ifdef __LZOCONF_H
-+#  error "you cannot use both LZO and miniLZO"
-+#endif
-+
-+#undef LZO_HAVE_CONFIG_H
 +#include "lzoconf.h"
 +
-+#if !defined(LZO_VERSION) || (LZO_VERSION != MINILZO_VERSION)
-+#  error "version mismatch in header files"
-+#endif
-+
-+#ifdef __cplusplus
-+extern "C" {
-+#endif
-+
-+/***********************************************************************
-+//
-+************************************************************************/
-+
 +/* Memory required for the wrkmem parameter.
 + * When the required size is 0, you can also pass a NULL pointer.
 + */
@@ -28984,99 +28448,29 @@ Index: linux-2.6.16/fs/reiser4/plugin/compress/minilzo.h
 +#define LZO1X_MEM_DECOMPRESS    (0)
 +
 +/* compression */
-+      LZO_EXTERN(int)
-+       lzo1x_1_compress(const lzo_byte * src, lzo_uint src_len,
-+                        lzo_byte * dst, lzo_uintp dst_len, lzo_voidp wrkmem);
-+
++extern int lzo1x_1_compress(const lzo_byte * src, lzo_uint src_len,
++                          lzo_byte * dst, lzo_uintp dst_len,
++                          lzo_voidp wrkmem);
 +/* decompression */
-+       LZO_EXTERN(int)
-+       lzo1x_decompress(const lzo_byte * src, lzo_uint src_len,
-+                        lzo_byte * dst, lzo_uintp dst_len,
-+                        lzo_voidp wrkmem /* NOT USED */ );
-+
++extern int lzo1x_decompress(const lzo_byte * src, lzo_uint src_len,
++                          lzo_byte * dst, lzo_uintp dst_len,
++                          lzo_voidp wrkmem /* NOT USED */);
 +/* safe decompression with overrun testing */
-+       LZO_EXTERN(int)
-+       lzo1x_decompress_safe(const lzo_byte * src, lzo_uint src_len,
-+                             lzo_byte * dst, lzo_uintp dst_len,
-+                             lzo_voidp wrkmem /* NOT USED */ );
++extern int lzo1x_decompress_safe(const lzo_byte * src, lzo_uint src_len,
++                               lzo_byte * dst, lzo_uintp dst_len,
++                               lzo_voidp wrkmem /* NOT USED */ );
 +
-+#ifdef __cplusplus
-+}                             /* extern "C" */
-+#endif
 +#endif                                /* already included */
-Index: linux-2.6.16/fs/reiser4/plugin/crypto/cipher.c
-===================================================================
---- /dev/null
-+++ linux-2.6.16/fs/reiser4/plugin/crypto/cipher.c
-@@ -0,0 +1,116 @@
+diff -urN linux-2.6.22.orig/fs/reiser4/plugin/crypto/cipher.c linux-2.6.22/fs/reiser4/plugin/crypto/cipher.c
+--- linux-2.6.22.orig/fs/reiser4/plugin/crypto/cipher.c        1970-01-01 03:00:00.000000000 +0300
++++ linux-2.6.22/fs/reiser4/plugin/crypto/cipher.c     2007-07-29 00:25:34.900702689 +0400
+@@ -0,0 +1,37 @@
 +/* Copyright 2001, 2002, 2003 by Hans Reiser,
 +   licensing governed by reiser4/README */
 +/* Reiser4 cipher transform plugins */
 +
 +#include "../../debug.h"
 +#include "../plugin.h"
-+#include "../file/cryptcompress.h"
-+#include <linux/types.h>
-+#include <linux/random.h>
-+
-+#define MIN_CIPHER_BLOCKSIZE 8
-+#define MAX_CIPHER_BLOCKSIZE 128
-+
-+/*
-+  Default align() method of the cipher plugin (look for description of this
-+  method in plugin/plugin.h)
-+
-+  1) creates the aligning armored format of the input flow before encryption.
-+     "armored" means that padding is filled by private data (for example,
-+     pseudo-random sequence of bytes is not private data).
-+  2) returns length of appended padding
-+
-+   [ flow | aligning_padding ]
-+            ^
-+            |
-+        @pad
-+*/
-+static int align_stream_common(__u8 * pad,
-+                             int flow_size /* size of non-aligned flow */,
-+                             int blocksize /* cipher block size */)
-+{
-+      int pad_size;
-+
-+      assert("edward-01", pad != NULL);
-+      assert("edward-02", flow_size != 0);
-+      assert("edward-03", blocksize != 0
-+             || blocksize <= MAX_CIPHER_BLOCKSIZE);
-+
-+      pad_size = blocksize - (flow_size % blocksize);
-+      get_random_bytes(pad, pad_size);
-+      return pad_size;
-+}
-+
-+/* This is used for all the cipher algorithms which do not inflate
-+   block-aligned data */
-+static loff_t scale_common(struct inode *inode, size_t blocksize,
-+                         loff_t src_off /* offset to scale */ )
-+{
-+      return src_off;
-+}
-+
-+static void free_aes (struct crypto_tfm * tfm)
-+{
-+#if REISER4_AES
-+      crypto_free_tfm(tfm);
-+#endif
-+      return;
-+}
-+
-+static struct crypto_tfm * alloc_aes (void)
-+{
-+#if REISER4_AES
-+      return crypto_alloc_tfm ("aes", 0);
-+#else
-+      warning("edward-1417", "aes unsupported");
-+      return ERR_PTR(-EINVAL);
-+#endif /* REISER4_AES */
-+}
 +
 +cipher_plugin cipher_plugins[LAST_CIPHER_ID] = {
 +      [NONE_CIPHER_ID] = {
@@ -29095,23 +28489,6 @@ Index: linux-2.6.16/fs/reiser4/plugin/crypto/cipher.c
 +              .setkey = NULL,
 +              .encrypt = NULL,
 +              .decrypt = NULL
-+      },
-+      [AES_CIPHER_ID] = {
-+              .h = {
-+                      .type_id = REISER4_CIPHER_PLUGIN_TYPE,
-+                      .id = AES_CIPHER_ID,
-+                      .pops = NULL,
-+                      .label = "aes",
-+                      .desc = "aes cipher transform",
-+                      .linkage = {NULL, NULL}
-+              },
-+              .alloc = alloc_aes,
-+              .free = free_aes,
-+              .scale = scale_common,
-+              .align_stream = align_stream_common,
-+              .setkey = NULL,
-+              .encrypt = NULL,
-+              .decrypt = NULL
 +      }
 +};
 +
@@ -29125,11 +28502,10 @@ Index: linux-2.6.16/fs/reiser4/plugin/crypto/cipher.c
 +   scroll-step: 1
 +   End:
 +*/
-Index: linux-2.6.16/fs/reiser4/plugin/crypto/cipher.h
-===================================================================
---- /dev/null
-+++ linux-2.6.16/fs/reiser4/plugin/crypto/cipher.h
-@@ -0,0 +1,67 @@
+diff -urN linux-2.6.22.orig/fs/reiser4/plugin/crypto/cipher.h linux-2.6.22/fs/reiser4/plugin/crypto/cipher.h
+--- linux-2.6.22.orig/fs/reiser4/plugin/crypto/cipher.h        1970-01-01 03:00:00.000000000 +0300
++++ linux-2.6.22/fs/reiser4/plugin/crypto/cipher.h     2007-07-29 00:25:34.900702689 +0400
+@@ -0,0 +1,55 @@
 +/* Copyright 2002, 2003 by Hans Reiser, licensing governed by reiser4/README */
 +/* This file contains definitions for the objects operated
 +   by reiser4 key manager, which is something like keyring
@@ -29140,40 +28516,28 @@ Index: linux-2.6.16/fs/reiser4/plugin/crypto/cipher.h
 +
 +#include <linux/crypto.h>
 +
-+
-+/* Transform actions involved in ciphering process and
-+   supported by reiser4 via appropriate transform plugins */
-+typedef enum {
-+      CIPHER_TFM,       /* cipher transform */
-+      DIGEST_TFM,       /* digest transform */
-+      LAST_TFM
-+} reiser4_tfm;
-+
-+/* This represents a transform action in reiser4 */
-+typedef struct reiser4_tfma {
-+      reiser4_plugin * plug;     /* transform plugin */
-+      struct crypto_tfm * tfm;   /* low-level info, operated by
-+                                    linux crypto-api (see linux/crypto) */
-+} reiser4_tfma_t;
-+
 +/* key info imported from user space */
-+typedef struct crypto_data {
++struct reiser4_crypto_data {
 +      int keysize;    /* uninstantiated key size */
 +      __u8 * key;     /* uninstantiated key */
 +      int keyid_size; /* size of passphrase */
 +      __u8 * keyid;   /* passphrase */
-+} crypto_data_t;
++};
 +
 +/* This object contains all needed infrastructure to implement
 +   cipher transform. This is operated (allocating, inheriting,
 +   validating, binding to host inode, etc..) by reiser4 key manager.
 +
 +   This info can be allocated in two cases:
-+   1. importing a key from user space. 
++   1. importing a key from user space.
 +   2. reading inode from disk */
-+typedef struct crypto_stat {
-+      reiser4_tfma_t tfma[LAST_TFM];
-+//      cipher_key_plugin * kplug; /* key manager */
++struct reiser4_crypto_info {
++      struct inode * host;
++      struct crypto_hash      * digest;
++      struct crypto_blkcipher * cipher;
++#if 0
++      cipher_key_plugin * kplug; /* key manager */
++#endif
 +      __u8 * keyid;              /* key fingerprint, created by digest plugin,
 +                                    using uninstantiated key and passphrase.
 +                                    supposed to be stored in disk stat-data */
@@ -29183,7 +28547,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/crypto/cipher.h
 +                                    to be stored in disk stat-data */
 +      int keyload_count;         /* number of the objects which has this
 +                                    crypto-stat attached */
-+} crypto_stat_t;
++};
 +
 +#endif /* __FS_REISER4_CRYPT_H__ */
 +
@@ -29197,10 +28561,9 @@ Index: linux-2.6.16/fs/reiser4/plugin/crypto/cipher.h
 +   scroll-step: 1
 +   End:
 +*/
-Index: linux-2.6.16/fs/reiser4/plugin/crypto/digest.c
-===================================================================
---- /dev/null
-+++ linux-2.6.16/fs/reiser4/plugin/crypto/digest.c
+diff -urN linux-2.6.22.orig/fs/reiser4/plugin/crypto/digest.c linux-2.6.22/fs/reiser4/plugin/crypto/digest.c
+--- linux-2.6.22.orig/fs/reiser4/plugin/crypto/digest.c        1970-01-01 03:00:00.000000000 +0300
++++ linux-2.6.22/fs/reiser4/plugin/crypto/digest.c     2007-07-29 00:25:34.900702689 +0400
 @@ -0,0 +1,58 @@
 +/* Copyright 2001, 2002, 2003 by Hans Reiser, licensing governed by reiser4/README */
 +
@@ -29215,20 +28578,20 @@ Index: linux-2.6.16/fs/reiser4/plugin/crypto/digest.c
 +
 +extern digest_plugin digest_plugins[LAST_DIGEST_ID];
 +
-+static struct crypto_tfm * alloc_sha256 (void)
++static struct crypto_hash * alloc_sha256 (void)
 +{
 +#if REISER4_SHA256
-+      return crypto_alloc_tfm ("sha256", 0);
++      return crypto_alloc_hash ("sha256", 0, CRYPTO_ALG_ASYNC);
 +#else
 +      warning("edward-1418", "sha256 unsupported");
 +      return ERR_PTR(-EINVAL);
 +#endif
 +}
 +
-+static void free_sha256 (struct crypto_tfm * tfm)
++static void free_sha256 (struct crypto_hash * tfm)
 +{
 +#if REISER4_SHA256
-+      crypto_free_tfm(tfm);
++      crypto_free_hash(tfm);
 +#endif
 +      return;
 +}
@@ -29260,20 +28623,9 @@ Index: linux-2.6.16/fs/reiser4/plugin/crypto/digest.c
 +  scroll-step: 1
 +  End:
 +*/
-Index: linux-2.6.16/fs/reiser4/plugin/dir/Makefile
-===================================================================
---- /dev/null
-+++ linux-2.6.16/fs/reiser4/plugin/dir/Makefile
-@@ -0,0 +1,5 @@
-+obj-$(CONFIG_REISER4_FS) += dir_plugins.o
-+
-+dir_plugins-objs :=   \
-+      hashed_dir.o    \
-+      seekable_dir.o
-Index: linux-2.6.16/fs/reiser4/plugin/dir/dir.h
-===================================================================
---- /dev/null
-+++ linux-2.6.16/fs/reiser4/plugin/dir/dir.h
+diff -urN linux-2.6.22.orig/fs/reiser4/plugin/dir/dir.h linux-2.6.22/fs/reiser4/plugin/dir/dir.h
+--- linux-2.6.22.orig/fs/reiser4/plugin/dir/dir.h      1970-01-01 03:00:00.000000000 +0300
++++ linux-2.6.22/fs/reiser4/plugin/dir/dir.h   2007-07-29 00:25:34.900702689 +0400
 @@ -0,0 +1,36 @@
 +/* Copyright 2001, 2002, 2003, 2004 by Hans Reiser, licensing governed by
 + * reiser4/README */
@@ -29311,10 +28663,9 @@ Index: linux-2.6.16/fs/reiser4/plugin/dir/dir.h
 +   fill-column: 120
 +   End:
 +*/
-Index: linux-2.6.16/fs/reiser4/plugin/dir/hashed_dir.c
-===================================================================
---- /dev/null
-+++ linux-2.6.16/fs/reiser4/plugin/dir/hashed_dir.c
+diff -urN linux-2.6.22.orig/fs/reiser4/plugin/dir/hashed_dir.c linux-2.6.22/fs/reiser4/plugin/dir/hashed_dir.c
+--- linux-2.6.22.orig/fs/reiser4/plugin/dir/hashed_dir.c       1970-01-01 03:00:00.000000000 +0300
++++ linux-2.6.22/fs/reiser4/plugin/dir/hashed_dir.c    2007-07-29 00:25:34.900702689 +0400
 @@ -0,0 +1,81 @@
 +/* Copyright 2001, 2002, 2003, 2004 by Hans Reiser, licensing governed by
 + * reiser4/README */
@@ -29397,10 +28748,18 @@ Index: linux-2.6.16/fs/reiser4/plugin/dir/hashed_dir.c
 +   fill-column: 120
 +   End:
 +*/
-Index: linux-2.6.16/fs/reiser4/plugin/dir/seekable_dir.c
-===================================================================
---- /dev/null
-+++ linux-2.6.16/fs/reiser4/plugin/dir/seekable_dir.c
+diff -urN linux-2.6.22.orig/fs/reiser4/plugin/dir/Makefile linux-2.6.22/fs/reiser4/plugin/dir/Makefile
+--- linux-2.6.22.orig/fs/reiser4/plugin/dir/Makefile   1970-01-01 03:00:00.000000000 +0300
++++ linux-2.6.22/fs/reiser4/plugin/dir/Makefile        2007-07-29 00:25:34.900702689 +0400
+@@ -0,0 +1,5 @@
++obj-$(CONFIG_REISER4_FS) += dir_plugins.o
++
++dir_plugins-objs :=   \
++      hashed_dir.o    \
++      seekable_dir.o
+diff -urN linux-2.6.22.orig/fs/reiser4/plugin/dir/seekable_dir.c linux-2.6.22/fs/reiser4/plugin/dir/seekable_dir.c
+--- linux-2.6.22.orig/fs/reiser4/plugin/dir/seekable_dir.c     1970-01-01 03:00:00.000000000 +0300
++++ linux-2.6.22/fs/reiser4/plugin/dir/seekable_dir.c  2007-07-29 00:25:34.904703724 +0400
 @@ -0,0 +1,46 @@
 +/* Copyright 2005 by Hans Reiser, licensing governed by
 + * reiser4/README */
@@ -29448,11 +28807,10 @@ Index: linux-2.6.16/fs/reiser4/plugin/dir/seekable_dir.c
 +      set_key_offset(result, (__u64) 0);
 +      return;
 +}
-Index: linux-2.6.16/fs/reiser4/plugin/dir_plugin_common.c
-===================================================================
---- /dev/null
-+++ linux-2.6.16/fs/reiser4/plugin/dir_plugin_common.c
-@@ -0,0 +1,864 @@
+diff -urN linux-2.6.22.orig/fs/reiser4/plugin/dir_plugin_common.c linux-2.6.22/fs/reiser4/plugin/dir_plugin_common.c
+--- linux-2.6.22.orig/fs/reiser4/plugin/dir_plugin_common.c    1970-01-01 03:00:00.000000000 +0300
++++ linux-2.6.22/fs/reiser4/plugin/dir_plugin_common.c 2007-07-29 00:25:34.904703724 +0400
+@@ -0,0 +1,872 @@
 +/* Copyright 2005 by Hans Reiser, licensing governed by
 +   reiser4/README */
 +
@@ -29462,9 +28820,9 @@ Index: linux-2.6.16/fs/reiser4/plugin/dir_plugin_common.c
 +
 +#include "../inode.h"
 +
-+int find_entry(struct inode *dir, struct dentry *name,
++int reiser4_find_entry(struct inode *dir, struct dentry *name,
 +             lock_handle *, znode_lock_mode, reiser4_dir_entry_desc *);
-+int lookup_name(struct inode *parent, struct dentry *dentry, reiser4_key * key);
++int reiser4_lookup_name(struct inode *parent, struct dentry *dentry, reiser4_key * key);
 +void check_light_weight(struct inode *inode, struct inode *parent);
 +
 +/* this is common implementation of get_parent method of dir plugin
@@ -29490,7 +28848,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/dir_plugin_common.c
 +      dotdot.d_name.len = 2;
 +      dotdot.d_op = &get_super_private(s)->ops.dentry;
 +
-+      result = lookup_name(child, &dotdot, &key);
++      result = reiser4_lookup_name(child, &dotdot, &key);
 +      if (result != 0)
 +              return ERR_PTR(result);
 +
@@ -29543,7 +28901,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/dir_plugin_common.c
 +
 +/* this is common implementation of build_readdir_key method of dir
 +   plugin
-+   see readdir_common for more details
++   see reiser4_readdir_common for more details
 +*/
 +int build_readdir_key_common(struct file *dir /* directory being read */ ,
 +                           reiser4_key * result /* where to store key */ )
@@ -29567,24 +28925,24 @@ Index: linux-2.6.16/fs/reiser4/plugin/dir_plugin_common.c
 +
 +}
 +
-+void adjust_dir_file(struct inode *, const struct dentry *, int offset,
-+                   int adj);
++void reiser4_adjust_dir_file(struct inode *, const struct dentry *, int offset,
++                           int adj);
 +
 +/* this is common implementation of add_entry method of dir plugin
 +*/
-+int add_entry_common(struct inode *object,    /* directory to add new name
-+                                               * in */
-+                   struct dentry *where,      /* new name */
-+                   reiser4_object_create_data * data UNUSED_ARG,      /* parameters
-+                                                                       * of new
-+                                                                       * object */
-+                   reiser4_dir_entry_desc * entry     /* parameters of new
-+                                                       * directory entry */ )
++int reiser4_add_entry_common(struct inode *object, /* directory to add new name
++                                                  * in */
++                           struct dentry *where,      /* new name */
++                           reiser4_object_create_data * data, /* parameters of
++                                                              *  new object */
++                           reiser4_dir_entry_desc * entry /* parameters of
++                                                           * new directory
++                                                           * entry */)
 +{
 +      int result;
 +      coord_t *coord;
 +      lock_handle lh;
-+      reiser4_dentry_fsdata *fsdata;
++      struct reiser4_dentry_fsdata *fsdata;
 +      reiser4_block_nr reserve;
 +
 +      assert("nikita-1114", object != NULL);
@@ -29603,20 +28961,22 @@ Index: linux-2.6.16/fs/reiser4/plugin/dir_plugin_common.c
 +      coord_clear_iplug(coord);
 +
 +      /* check for this entry in a directory. This is plugin method. */
-+      result = find_entry(object, where, &lh, ZNODE_WRITE_LOCK, entry);
++      result = reiser4_find_entry(object, where, &lh, ZNODE_WRITE_LOCK,
++                                  entry);
 +      if (likely(result == -ENOENT)) {
 +              /* add new entry. Just pass control to the directory
 +                 item plugin. */
 +              assert("nikita-1709", inode_dir_item_plugin(object));
 +              assert("nikita-2230", coord->node == lh.node);
-+              seal_done(&fsdata->dec.entry_seal);
++              reiser4_seal_done(&fsdata->dec.entry_seal);
 +              result =
 +                  inode_dir_item_plugin(object)->s.dir.add_entry(object,
 +                                                                 coord, &lh,
 +                                                                 where,
 +                                                                 entry);
 +              if (result == 0) {
-+                      adjust_dir_file(object, where, fsdata->dec.pos + 1, +1);
++                      reiser4_adjust_dir_file(object, where,
++                                              fsdata->dec.pos + 1, +1);
 +                      INODE_INC_FIELD(object, i_size);
 +              }
 +      } else if (result == 0) {
@@ -29670,21 +29030,21 @@ Index: linux-2.6.16/fs/reiser4/plugin/dir_plugin_common.c
 +}
 +
 +/**
-+ * rem_entry_common - remove entry from a directory
++ * reiser4_rem_entry_common - remove entry from a directory
 + * @dir: directory to remove entry from
 + * @where: name that is being removed
 + * @entry: description of entry being removed
 + *
 + * This is common implementation of rem_entry method of dir plugin.
 + */
-+int rem_entry_common(struct inode *dir,
-+                   struct dentry *dentry,
-+                   reiser4_dir_entry_desc *entry)
++int reiser4_rem_entry_common(struct inode *dir,
++                           struct dentry *dentry,
++                           reiser4_dir_entry_desc *entry)
 +{
 +      int result;
 +      coord_t *coord;
 +      lock_handle lh;
-+      reiser4_dentry_fsdata *fsdata;
++      struct reiser4_dentry_fsdata *fsdata;
 +      __u64 tograb;
 +
 +      assert("nikita-1124", dir != NULL);
@@ -29698,7 +29058,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/dir_plugin_common.c
 +      init_lh(&lh);
 +
 +      /* check for this entry in a directory. This is plugin method. */
-+      result = find_entry(dir, dentry, &lh, ZNODE_WRITE_LOCK, entry);
++      result = reiser4_find_entry(dir, dentry, &lh, ZNODE_WRITE_LOCK, entry);
 +      fsdata = reiser4_get_dentry_fsdata(dentry);
 +      if (IS_ERR(fsdata)) {
 +              done_lh(&lh);
@@ -29716,8 +29076,8 @@ Index: linux-2.6.16/fs/reiser4/plugin/dir_plugin_common.c
 +              /* remove entry. Just pass control to the directory item
 +                 plugin. */
 +              assert("vs-542", inode_dir_item_plugin(dir));
-+              seal_done(&fsdata->dec.entry_seal);
-+              adjust_dir_file(dir, dentry, fsdata->dec.pos, -1);
++              reiser4_seal_done(&fsdata->dec.entry_seal);
++              reiser4_adjust_dir_file(dir, dentry, fsdata->dec.pos, -1);
 +              result =
 +                  WITH_COORD(coord,
 +                             rem_entry(dir, dentry, entry, coord, &lh));
@@ -29748,14 +29108,14 @@ Index: linux-2.6.16/fs/reiser4/plugin/dir_plugin_common.c
 +/* this is common implementation of init method of dir plugin
 +   create "." and ".." entries
 +*/
-+int init_common(struct inode *object, /* new directory */
-+              struct inode *parent,   /* parent directory */
-+              reiser4_object_create_data * data UNUSED_ARG    /* info passed
-+                                                               * to us, this
-+                                                               * is filled by
-+                                                               * reiser4()
-+                                                               * syscall in
-+                                                               * particular */ )
++int reiser4_dir_init_common(struct inode *object,     /* new directory */
++                          struct inode *parent,       /* parent directory */
++                          reiser4_object_create_data * data /* info passed
++                                                             * to us, this
++                                                             * is filled by
++                                                             * reiser4()
++                                                             * syscall in
++                                                             * particular */)
 +{
 +      reiser4_block_nr reserve;
 +
@@ -29776,7 +29136,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/dir_plugin_common.c
 +/* this is common implementation of done method of dir plugin
 +   remove "." entry
 +*/
-+int done_common(struct inode *object /* object being deleted */ )
++int reiser4_dir_done_common(struct inode *object /* object being deleted */ )
 +{
 +      int result;
 +      reiser4_block_nr reserve;
@@ -29785,14 +29145,14 @@ Index: linux-2.6.16/fs/reiser4/plugin/dir_plugin_common.c
 +
 +      assert("nikita-1449", object != NULL);
 +
-+      if (inode_get_flag(object, REISER4_NO_SD))
++      if (reiser4_inode_get_flag(object, REISER4_NO_SD))
 +              return 0;
 +
 +      /* of course, this can be rewritten to sweep everything in one
-+         cut_tree(). */
++         reiser4_cut_tree(). */
 +      memset(&entry, 0, sizeof entry);
 +
-+      /* FIXME: this done method is called from delete_directory_common which
++      /* FIXME: this done method is called from reiser4_delete_dir_common which
 +       * reserved space already */
 +      reserve = inode_dir_plugin(object)->estimate.rem_entry(object);
 +      if (reiser4_grab_space(reserve, BA_CAN_COMMIT | BA_RESERVED))
@@ -29802,7 +29162,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/dir_plugin_common.c
 +      entry.obj = goodby_dots.d_inode = object;
 +      goodby_dots.d_name.name = ".";
 +      goodby_dots.d_name.len = 1;
-+      result = rem_entry_common(object, &goodby_dots, &entry);
++      result = reiser4_rem_entry_common(object, &goodby_dots, &entry);
 +      reiser4_free_dentry_fsdata(&goodby_dots);
 +      if (unlikely(result != 0 && result != -ENOMEM && result != -ENOENT))
 +              /* only worth a warning
@@ -29817,8 +29177,8 @@ Index: linux-2.6.16/fs/reiser4/plugin/dir_plugin_common.c
 +
 +/* this is common implementation of attach method of dir plugin
 +*/
-+int
-+attach_common(struct inode *child UNUSED_ARG, struct inode *parent UNUSED_ARG)
++int reiser4_attach_common(struct inode *child UNUSED_ARG,
++                        struct inode *parent UNUSED_ARG)
 +{
 +      assert("nikita-2647", child != NULL);
 +      assert("nikita-2648", parent != NULL);
@@ -29829,14 +29189,14 @@ Index: linux-2.6.16/fs/reiser4/plugin/dir_plugin_common.c
 +/* this is common implementation of detach method of dir plugin
 +   remove "..", decrease nlink on parent
 +*/
-+int detach_common(struct inode *object, struct inode *parent)
++int reiser4_detach_common(struct inode *object, struct inode *parent)
 +{
 +      int result;
 +      struct dentry goodby_dots;
 +      reiser4_dir_entry_desc entry;
 +
 +      assert("nikita-2885", object != NULL);
-+      assert("nikita-2886", !inode_get_flag(object, REISER4_NO_SD));
++      assert("nikita-2886", !reiser4_inode_get_flag(object, REISER4_NO_SD));
 +
 +      memset(&entry, 0, sizeof entry);
 +
@@ -29847,12 +29207,12 @@ Index: linux-2.6.16/fs/reiser4/plugin/dir_plugin_common.c
 +      entry.obj = goodby_dots.d_inode = parent;
 +      goodby_dots.d_name.name = "..";
 +      goodby_dots.d_name.len = 2;
-+      result = rem_entry_common(object, &goodby_dots, &entry);
++      result = reiser4_rem_entry_common(object, &goodby_dots, &entry);
 +      reiser4_free_dentry_fsdata(&goodby_dots);
 +      if (result == 0) {
 +              /* the dot should be the only entry remaining at this time... */
-+              assert("nikita-3400", object->i_size == 1 &&
-+                     (object->i_nlink >= 0 && object->i_nlink <= 2));
++              assert("nikita-3400",
++                     object->i_size == 1 && object->i_nlink <= 2);
 +#if 0
 +              /* and, together with the only name directory can have, they
 +               * provides for the last 2 remaining references. If we get
@@ -29878,7 +29238,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/dir_plugin_common.c
 +*/
 +reiser4_block_nr estimate_add_entry_common(const struct inode * inode)
 +{
-+      return estimate_one_insert_into_item(tree_by_inode(inode));
++      return estimate_one_insert_into_item(reiser4_tree_by_inode(inode));
 +}
 +
 +/* this is common implementation of estimate.rem_entry method of dir
@@ -29886,7 +29246,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/dir_plugin_common.c
 +*/
 +reiser4_block_nr estimate_rem_entry_common(const struct inode * inode)
 +{
-+      return estimate_one_item_removal(tree_by_inode(inode));
++      return estimate_one_item_removal(reiser4_tree_by_inode(inode));
 +}
 +
 +/* this is common implementation of estimate.unlink method of dir
@@ -29913,18 +29273,18 @@ Index: linux-2.6.16/fs/reiser4/plugin/dir_plugin_common.c
 + */
 +void check_light_weight(struct inode *inode, struct inode *parent)
 +{
-+      if (inode_get_flag(inode, REISER4_LIGHT_WEIGHT)) {
++      if (reiser4_inode_get_flag(inode, REISER4_LIGHT_WEIGHT)) {
 +              inode->i_uid = parent->i_uid;
 +              inode->i_gid = parent->i_gid;
 +              /* clear light-weight flag. If inode would be read by any
 +                 other name, [ug]id wouldn't change. */
-+              inode_clr_flag(inode, REISER4_LIGHT_WEIGHT);
++              reiser4_inode_clr_flag(inode, REISER4_LIGHT_WEIGHT);
 +      }
 +}
 +
 +/* looks for name specified in @dentry in directory @parent and if name is
 +   found - key of object found entry points to is stored in @entry->key */
-+int lookup_name(struct inode *parent, /* inode of directory to lookup for
++int reiser4_lookup_name(struct inode *parent, /* inode of directory to lookup for
 +                                       * name in */
 +              struct dentry *dentry,  /* name to look for */
 +              reiser4_key * key /* place to store key */ )
@@ -29935,7 +29295,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/dir_plugin_common.c
 +      const char *name;
 +      int len;
 +      reiser4_dir_entry_desc entry;
-+      reiser4_dentry_fsdata *fsdata;
++      struct reiser4_dentry_fsdata *fsdata;
 +
 +      assert("nikita-1247", parent != NULL);
 +      assert("nikita-1248", dentry != NULL);
@@ -29959,7 +29319,8 @@ Index: linux-2.6.16/fs/reiser4/plugin/dir_plugin_common.c
 +      init_lh(&lh);
 +
 +      /* find entry in a directory. This is plugin method. */
-+      result = find_entry(parent, dentry, &lh, ZNODE_READ_LOCK, &entry);
++      result = reiser4_find_entry(parent, dentry, &lh, ZNODE_READ_LOCK,
++                                  &entry);
 +      if (result == 0) {
 +              /* entry was found, extract object key from it. */
 +              result =
@@ -29972,7 +29333,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/dir_plugin_common.c
 +
 +}
 +
-+/* helper for init_common(): estimate number of blocks to reserve */
++/* helper for reiser4_dir_init_common(): estimate number of blocks to reserve */
 +static reiser4_block_nr
 +estimate_init(struct inode *parent, struct inode *object)
 +{
@@ -29993,10 +29354,10 @@ Index: linux-2.6.16/fs/reiser4/plugin/dir_plugin_common.c
 +      return 0;
 +}
 +
-+/* helper function for init_common(). Create "." and ".." */
-+static int create_dot_dotdot(struct inode *object     /* object to create dot and
-+                                                       * dotdot for */ ,
-+                           struct inode *parent /* parent of @object */ )
++/* helper function for reiser4_dir_init_common(). Create "." and ".." */
++static int create_dot_dotdot(struct inode *object /* object to create dot and
++                                                 * dotdot for */ ,
++                           struct inode *parent /* parent of @object */)
 +{
 +      int result;
 +      struct dentry dots_entry;
@@ -30026,7 +29387,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/dir_plugin_common.c
 +      entry.obj = dots_entry.d_inode = object;
 +      dots_entry.d_name.name = ".";
 +      dots_entry.d_name.len = 1;
-+      result = add_entry_common(object, &dots_entry, NULL, &entry);
++      result = reiser4_add_entry_common(object, &dots_entry, NULL, &entry);
 +      reiser4_free_dentry_fsdata(&dots_entry);
 +
 +      if (result == 0) {
@@ -30035,7 +29396,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/dir_plugin_common.c
 +                      entry.obj = dots_entry.d_inode = parent;
 +                      dots_entry.d_name.name = "..";
 +                      dots_entry.d_name.len = 2;
-+                      result = add_entry_common(object,
++                      result = reiser4_add_entry_common(object,
 +                                                &dots_entry, NULL, &entry);
 +                      reiser4_free_dentry_fsdata(&dots_entry);
 +                      /* if creation of ".." failed, iput() will delete
@@ -30047,7 +29408,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/dir_plugin_common.c
 +                                       * if we failed to bump i_nlink, try
 +                                       * to remove ".."
 +                                       */
-+                                      detach_common(object, parent);
++                                      reiser4_detach_common(object, parent);
 +                      }
 +              }
 +      }
@@ -30106,7 +29467,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/dir_plugin_common.c
 +/*
 + * argument package used by entry_actor to scan entries with identical keys.
 + */
-+typedef struct entry_actor_args {
++struct entry_actor_args {
 +      /* name we are looking for */
 +      const char *name;
 +      /* key of directory entry. entry_actor() scans through sequence of
@@ -30130,16 +29491,17 @@ Index: linux-2.6.16/fs/reiser4/plugin/dir_plugin_common.c
 +      lock_handle last_lh;
 +      /* inode of directory */
 +      const struct inode *inode;
-+} entry_actor_args;
++};
 +
-+/* Function called by find_entry() to look for given name in the directory. */
++/* Function called by reiser4_find_entry() to look for given name
++   in the directory. */
 +static int entry_actor(reiser4_tree * tree UNUSED_ARG /* tree being scanned */ ,
 +                     coord_t * coord /* current coord */ ,
 +                     lock_handle * lh /* current lock handle */ ,
 +                     void *entry_actor_arg /* argument to scan */ )
 +{
 +      reiser4_key unit_key;
-+      entry_actor_args *args;
++      struct entry_actor_args *args;
 +
 +      assert("nikita-1131", tree != NULL);
 +      assert("nikita-1132", coord != NULL);
@@ -30190,26 +29552,26 @@ Index: linux-2.6.16/fs/reiser4/plugin/dir_plugin_common.c
 +/* Look for given @name within directory @dir.
 +
 +   This is called during lookup, creation and removal of directory
-+   entries and on rename_common
++   entries and on reiser4_rename_common
 +
 +   First calculate key that directory entry for @name would have. Search
 +   for this key in the tree. If such key is found, scan all items with
 +   the same key, checking name in each directory entry along the way.
 +*/
-+int find_entry(struct inode *dir,     /* directory to scan */
-+             struct dentry *de,       /* name to search for */
-+             lock_handle * lh,        /* resulting lock handle */
-+             znode_lock_mode mode,    /* required lock mode */
-+             reiser4_dir_entry_desc * entry   /* parameters of found directory
-+                                               * entry */ )
++int reiser4_find_entry(struct inode *dir,     /* directory to scan */
++                     struct dentry *de,       /* name to search for */
++                     lock_handle * lh,        /* resulting lock handle */
++                     znode_lock_mode mode,    /* required lock mode */
++                     reiser4_dir_entry_desc * entry   /* parameters of found
++                                                         directory entry */)
 +{
 +      const struct qstr *name;
 +      seal_t *seal;
 +      coord_t *coord;
 +      int result;
 +      __u32 flags;
-+      de_location *dec;
-+      reiser4_dentry_fsdata *fsdata;
++      struct de_location *dec;
++      struct reiser4_dentry_fsdata *fsdata;
 +
 +      assert("nikita-1130", lh != NULL);
 +      assert("nikita-1128", dir != NULL);
@@ -30234,10 +29596,10 @@ Index: linux-2.6.16/fs/reiser4/plugin/dir_plugin_common.c
 +      /* compose key of directory entry for @name */
 +      inode_dir_plugin(dir)->build_entry_key(dir, name, &entry->key);
 +
-+      if (seal_is_set(seal)) {
++      if (reiser4_seal_is_set(seal)) {
 +              /* check seal */
-+              result = seal_validate(seal, coord, &entry->key,
-+                                     lh, mode, ZNODE_LOCK_LOPRI);
++              result = reiser4_seal_validate(seal, coord, &entry->key,
++                                             lh, mode, ZNODE_LOCK_LOPRI);
 +              if (result == 0) {
 +                      /* key was found. Check that it is really item we are
 +                         looking for. */
@@ -30250,16 +29612,16 @@ Index: linux-2.6.16/fs/reiser4/plugin/dir_plugin_common.c
 +      /*
 +       * find place in the tree where directory item should be located.
 +       */
-+      result = object_lookup(dir, &entry->key, coord, lh, mode,
-+                             FIND_EXACT, LEAF_LEVEL, LEAF_LEVEL, flags,
-+                             NULL /*ra_info */ );
++      result = reiser4_object_lookup(dir, &entry->key, coord, lh, mode,
++                                     FIND_EXACT, LEAF_LEVEL, LEAF_LEVEL,
++                                     flags, NULL /*ra_info */ );
 +      if (result == CBK_COORD_FOUND) {
-+              entry_actor_args arg;
++              struct entry_actor_args arg;
 +
 +              /* fast path: no hash collisions */
 +              result = check_entry(dir, coord, name);
 +              if (result == 0) {
-+                      seal_init(seal, coord, &entry->key);
++                      reiser4_seal_init(seal, coord, &entry->key);
 +                      dec->pos = 0;
 +              } else if (result > 0) {
 +                      /* Iterate through all units with the same keys. */
@@ -30276,8 +29638,10 @@ Index: linux-2.6.16/fs/reiser4/plugin/dir_plugin_common.c
 +                      coord_init_zero(&arg.last_coord);
 +                      init_lh(&arg.last_lh);
 +
-+                      result = iterate_tree(tree_by_inode(dir), coord, lh,
-+                                            entry_actor, &arg, mode, 1);
++                      result = reiser4_iterate_tree
++                              (reiser4_tree_by_inode(dir),
++                               coord, lh,
++                               entry_actor, &arg, mode, 1);
 +                      /* if end of the tree or extent was reached during
 +                         scanning. */
 +                      if (arg.not_found || (result == -E_NO_NEIGHBOR)) {
@@ -30297,7 +29661,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/dir_plugin_common.c
 +
 +                      done_lh(&arg.last_lh);
 +                      if (result == 0)
-+                              seal_init(seal, coord, &entry->key);
++                              reiser4_seal_init(seal, coord, &entry->key);
 +
 +                      if (result == 0 || result == -ENOENT) {
 +                              assert("nikita-2580", arg.non_uniq > 0);
@@ -30309,89 +29673,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/dir_plugin_common.c
 +      return result;
 +}
 +
-+/* Local variables:
-+   c-indentation-style: "K&R"
-+   mode-name: "LC"
-+   c-basic-offset: 8
-+   tab-width: 8
-+   fill-column: 120
-+   End:
-+*/
-Index: linux-2.6.16/fs/reiser4/plugin/disk_format/Makefile
-===================================================================
---- /dev/null
-+++ linux-2.6.16/fs/reiser4/plugin/disk_format/Makefile
-@@ -0,0 +1,5 @@
-+obj-$(CONFIG_REISER4_FS) += df_plugins.o
-+
-+df_plugins-objs :=    \
-+      disk_format40.o \
-+      disk_format.o
-Index: linux-2.6.16/fs/reiser4/plugin/disk_format/disk_format.c
-===================================================================
---- /dev/null
-+++ linux-2.6.16/fs/reiser4/plugin/disk_format/disk_format.c
-@@ -0,0 +1,37 @@
-+/* Copyright 2002, 2003 by Hans Reiser, licensing governed by reiser4/README */
-+
-+#include "../../debug.h"
-+#include "../plugin_header.h"
-+#include "disk_format40.h"
-+#include "disk_format.h"
-+#include "../plugin.h"
-+
-+/* initialization of disk layout plugins */
-+disk_format_plugin format_plugins[LAST_FORMAT_ID] = {
-+      [FORMAT40_ID] = {
-+              .h = {
-+                      .type_id = REISER4_FORMAT_PLUGIN_TYPE,
-+                      .id = FORMAT40_ID,
-+                      .pops = NULL,
-+                      .label = "reiser40",
-+                      .desc = "standard disk layout for reiser40",
-+                      .linkage = {NULL, NULL}
-+              },
-+              .init_format = init_format_format40,
-+              .root_dir_key = root_dir_key_format40,
-+              .release = release_format40,
-+              .log_super = log_super_format40,
-+              .check_open = check_open_format40
-+      }
-+};
-+
-+/* Make Linus happy.
-+   Local variables:
-+   c-indentation-style: "K&R"
-+   mode-name: "LC"
-+   c-basic-offset: 8
-+   tab-width: 8
-+   fill-column: 120
-+   scroll-step: 1
-+   End:
-+*/
-Index: linux-2.6.16/fs/reiser4/plugin/disk_format/disk_format.h
-===================================================================
---- /dev/null
-+++ linux-2.6.16/fs/reiser4/plugin/disk_format/disk_format.h
-@@ -0,0 +1,27 @@
-+/* Copyright 2002, 2003 by Hans Reiser, licensing governed by reiser4/README */
-+
-+/* identifiers for disk layouts, they are also used as indexes in array of disk
-+   plugins */
-+
-+#if !defined( __REISER4_DISK_FORMAT_H__ )
-+#define __REISER4_DISK_FORMAT_H__
-+
-+typedef enum {
-+      /* standard reiser4 disk layout plugin id */
-+      FORMAT40_ID,
-+      LAST_FORMAT_ID
-+} disk_format_id;
-+
-+/* __REISER4_DISK_FORMAT_H__ */
-+#endif
-+
-+/* Make Linus happy.
++/*
 +   Local variables:
 +   c-indentation-style: "K&R"
 +   mode-name: "LC"
@@ -30401,11 +29683,10 @@ Index: linux-2.6.16/fs/reiser4/plugin/disk_format/disk_format.h
 +   scroll-step: 1
 +   End:
 +*/
-Index: linux-2.6.16/fs/reiser4/plugin/disk_format/disk_format40.c
-===================================================================
---- /dev/null
-+++ linux-2.6.16/fs/reiser4/plugin/disk_format/disk_format40.c
-@@ -0,0 +1,556 @@
+diff -urN linux-2.6.22.orig/fs/reiser4/plugin/disk_format/disk_format40.c linux-2.6.22/fs/reiser4/plugin/disk_format/disk_format40.c
+--- linux-2.6.22.orig/fs/reiser4/plugin/disk_format/disk_format40.c    1970-01-01 03:00:00.000000000 +0300
++++ linux-2.6.22/fs/reiser4/plugin/disk_format/disk_format40.c 2007-07-29 00:25:34.904703724 +0400
+@@ -0,0 +1,655 @@
 +/* Copyright 2002, 2003 by Hans Reiser, licensing governed by reiser4/README */
 +
 +#include "../../debug.h"
@@ -30435,6 +29716,13 @@ Index: linux-2.6.16/fs/reiser4/plugin/disk_format/disk_format40.c
 +   & tx record. */
 +#define RELEASE_RESERVED 4
 +
++/* The greatest supported format40 version number */
++#define FORMAT40_VERSION PLUGIN_LIBRARY_VERSION
++
++/* This flag indicates that backup should be updated
++   (the update is performed by fsck) */
++#define FORMAT40_UPDATE_BACKUP (1 << 31)
++
 +/* functions to access fields of format40_disk_super_block */
 +static __u64 get_format40_block_count(const format40_disk_super_block * sb)
 +{
@@ -30476,6 +29764,28 @@ Index: linux-2.6.16/fs/reiser4/plugin/disk_format/disk_format40.c
 +      return le64_to_cpu(get_unaligned(&sb->flags));
 +}
 +
++static __u32 get_format40_version(const format40_disk_super_block * sb)
++{
++      return le32_to_cpu(get_unaligned(&sb->version)) &
++              ~FORMAT40_UPDATE_BACKUP;
++}
++
++static int update_backup_version(const format40_disk_super_block * sb)
++{
++      return (le32_to_cpu(get_unaligned(&sb->version)) &
++              FORMAT40_UPDATE_BACKUP);
++}
++
++static int update_disk_version(const format40_disk_super_block * sb)
++{
++      return (get_format40_version(sb) < FORMAT40_VERSION);
++}
++
++static int incomplete_compatibility(const format40_disk_super_block * sb)
++{
++      return (get_format40_version(sb) > FORMAT40_VERSION);
++}
++
 +static format40_super_info *get_sb_info(struct super_block *super)
 +{
 +      return &get_super_private(super)->u.format40;
@@ -30552,12 +29862,12 @@ Index: linux-2.6.16/fs/reiser4/plugin/disk_format/disk_format40.c
 +      jnode *sb_jnode;
 +      int ret;
 +
-+      sb_jnode = alloc_io_head(&get_sb_info(s)->loc.super);
++      sb_jnode = reiser4_alloc_io_head(&get_sb_info(s)->loc.super);
 +
 +      ret = jload(sb_jnode);
 +
 +      if (ret) {
-+              drop_io_head(sb_jnode);
++              reiser4_drop_io_head(sb_jnode);
 +              return ret;
 +      }
 +
@@ -30575,7 +29885,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/disk_format/disk_format40.c
 +
 +      if (sb_jnode) {
 +              unpin_jnode_data(sb_jnode);
-+              drop_io_head(sb_jnode);
++              reiser4_drop_io_head(sb_jnode);
 +      }
 +}
 +
@@ -30600,7 +29910,8 @@ Index: linux-2.6.16/fs/reiser4/plugin/disk_format/disk_format40.c
 +{
 +      format40_disk_super_block *sb_copy;
 +
-+      sb_copy = kmalloc(sizeof(format40_disk_super_block), get_gfp_mask());
++      sb_copy = kmalloc(sizeof(format40_disk_super_block),
++                        reiser4_ctx_gfp_mask_get());
 +      if (sb_copy == NULL)
 +              return ERR_PTR(RETERR(-ENOMEM));
 +      memcpy(sb_copy, ((format40_disk_super_block *) super_bh->b_data),
@@ -30653,8 +29964,10 @@ Index: linux-2.6.16/fs/reiser4/plugin/disk_format/disk_format40.c
 +      brelse(super_bh);
 +      *stage = FIND_A_SUPER;
 +
++      /* ok, we are sure that filesystem format is a format40 format */
++
 +      /* map jnodes for journal control blocks (header, footer) to disk  */
-+      result = init_journal_info(super);
++      result = reiser4_init_journal_info(super);
 +      if (result)
 +              return result;
 +      *stage = INIT_JOURNAL_INFO;
@@ -30670,14 +29983,11 @@ Index: linux-2.6.16/fs/reiser4/plugin/disk_format/disk_format40.c
 +
 +      result = reiser4_status_query(NULL, NULL);
 +      if (result == REISER4_STATUS_MOUNT_WARN)
-+              printk("Warning, mounting filesystem with errors\n");
-+      if (result == REISER4_STATUS_MOUNT_RO) {
-+              printk
-+                  ("Warning, mounting filesystem with fatal errors, forcing read-only mount\n");
-+              /* FIXME: here we should actually enforce read-only mount,
-+               * only it is unsupported yet. */
-+      }
-+
++              notice("vpf-1363", "Warning: mounting %s with errors.",
++                     super->s_id);
++      if (result == REISER4_STATUS_MOUNT_RO)
++              notice("vpf-1364", "Warning: mounting %s with fatal errors,"
++                     " forcing read-only mount.", super->s_id);
 +      result = reiser4_journal_replay(super);
 +      if (result)
 +              return result;
@@ -30691,10 +30001,18 @@ Index: linux-2.6.16/fs/reiser4/plugin/disk_format/disk_format40.c
 +      /* allocate and make a copy of format40_disk_super_block */
 +      sb_copy = copy_sb(super_bh);
 +      brelse(super_bh);
++
 +      if (IS_ERR(sb_copy))
 +              return PTR_ERR(sb_copy);
-+
-+      /* make sure that key format of kernel and filesyste match */
++      printk("reiser4: %s: found disk format 4.0.%u.\n",
++             super->s_id,
++             get_format40_version(sb_copy));
++      if (incomplete_compatibility(sb_copy))
++              printk("reiser4: Warning: The last completely supported "
++                     "version of disk format40 is %u. Some objects of "
++                     "the semantic tree can be unaccessible.\n",
++                     FORMAT40_VERSION);
++      /* make sure that key format of kernel and filesystem match */
 +      result = check_key_format(sb_copy);
 +      if (result) {
 +              kfree(sb_copy);
@@ -30715,12 +30033,11 @@ Index: linux-2.6.16/fs/reiser4/plugin/disk_format/disk_format40.c
 +      height = get_format40_tree_height(sb_copy);
 +      nplug = node_plugin_by_id(NODE40_ID);
 +
-+
 +      /* initialize reiser4_super_info_data */
 +      sbinfo = get_super_private(super);
 +      assert("", sbinfo->tree.super == super);
 +      /* init reiser4_tree for the filesystem */
-+      result = init_tree(&sbinfo->tree, &root_block, height, nplug);
++      result = reiser4_init_tree(&sbinfo->tree, &root_block, height, nplug);
 +      if (result) {
 +              kfree(sb_copy);
 +              return result;
@@ -30737,8 +30054,14 @@ Index: linux-2.6.16/fs/reiser4/plugin/disk_format/disk_format40.c
 +      /* number of blocks in filesystem and reserved space */
 +      reiser4_set_block_count(super, get_format40_block_count(sb_copy));
 +      sbinfo->blocks_free = get_format40_free_blocks(sb_copy);
++      sbinfo->version = get_format40_version(sb_copy);
 +      kfree(sb_copy);
 +
++      if (update_backup_version(sb_copy))
++              printk("reiser4: Warning: metadata backup is not updated. "
++                     "Please run 'fsck.reiser4 --fix' on %s.\n",
++                     super->s_id);
++
 +      sbinfo->fsuid = 0;
 +      sbinfo->fs_flags |= (1 << REISER4_ADG); /* hard links for directories
 +                                               * are not supported */
@@ -30776,7 +30099,8 @@ Index: linux-2.6.16/fs/reiser4/plugin/disk_format/disk_format40.c
 +#endif
 +
 +      /* init disk space allocator */
-+      result = sa_init_allocator(get_space_allocator(super), super, NULL);
++      result = sa_init_allocator(reiser4_get_space_allocator(super),
++                                 super, NULL);
 +      if (result)
 +              return result;
 +      *stage = INIT_SA;
@@ -30801,10 +30125,10 @@ Index: linux-2.6.16/fs/reiser4/plugin/disk_format/disk_format40.c
 +      case INIT_JNODE:
 +              done_super_jnode(s);
 +      case INIT_SA:
-+              sa_destroy_allocator(get_space_allocator(s), s);
++              sa_destroy_allocator(reiser4_get_space_allocator(s), s);
 +      case JOURNAL_RECOVER:
 +      case INIT_TREE:
-+              done_tree(&get_super_private(s)->tree);
++              reiser4_done_tree(&get_super_private(s)->tree);
 +      case INIT_OID:
 +      case KEY_CHECK:
 +      case READ_SUPER:
@@ -30812,7 +30136,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/disk_format/disk_format40.c
 +      case INIT_STATUS:
 +              reiser4_status_finish();
 +      case INIT_JOURNAL_INFO:
-+              done_journal_info(s);
++              reiser4_done_journal_info(s);
 +      case FIND_A_SUPER:
 +      case CONSULT_DISKMAP:
 +      case NONE_DONE:
@@ -30831,18 +30155,31 @@ Index: linux-2.6.16/fs/reiser4/plugin/disk_format/disk_format40.c
 +{
 +      format40_disk_super_block *super_data =
 +          (format40_disk_super_block *) data;
++
 +      reiser4_super_info_data *sbinfo = get_super_private(s);
 +
 +      assert("zam-591", data != NULL);
 +
 +      put_unaligned(cpu_to_le64(reiser4_free_committed_blocks(s)),
 +                    &super_data->free_blocks);
-+      put_unaligned(cpu_to_le64(sbinfo->tree.root_block), &super_data->root_block);
 +
-+      put_unaligned(cpu_to_le64(oid_next(s)), &super_data->oid);
-+      put_unaligned(cpu_to_le64(oids_used(s)), &super_data->file_count);
++      put_unaligned(cpu_to_le64(sbinfo->tree.root_block),
++                    &super_data->root_block);
++
++      put_unaligned(cpu_to_le64(oid_next(s)),
++                    &super_data->oid);
++
++      put_unaligned(cpu_to_le64(oids_used(s)),
++                    &super_data->file_count);
++
++      put_unaligned(cpu_to_le16(sbinfo->tree.height),
++                    &super_data->tree_height);
 +
-+      put_unaligned(cpu_to_le16(sbinfo->tree.height), &super_data->tree_height);
++      if (update_disk_version(super_data)) {
++              __u32 version = FORMAT40_VERSION | FORMAT40_UPDATE_BACKUP;
++
++              put_unaligned(cpu_to_le32(version), &super_data->version);
++      }
 +}
 +
 +/* plugin->u.format.log_super
@@ -30873,9 +30210,10 @@ Index: linux-2.6.16/fs/reiser4/plugin/disk_format/disk_format40.c
 +      assert("zam-579", sbinfo != NULL);
 +
 +      if (!rofs_super(s)) {
-+              ret = capture_super_block(s);
++              ret = reiser4_capture_super_block(s);
 +              if (ret != 0)
-+                      warning("vs-898", "capture_super_block failed: %d",
++                      warning("vs-898",
++                              "reiser4_capture_super_block failed: %d",
 +                              ret);
 +
 +              ret = txnmgr_force_commit_all(s, 1);
@@ -30886,13 +30224,13 @@ Index: linux-2.6.16/fs/reiser4/plugin/disk_format/disk_format40.c
 +      }
 +
 +      sa_destroy_allocator(&sbinfo->space_allocator, s);
-+      done_journal_info(s);
++      reiser4_done_journal_info(s);
 +      done_super_jnode(s);
 +
 +      rcu_barrier();
-+      done_tree(&sbinfo->tree);
++      reiser4_done_tree(&sbinfo->tree);
 +      /* call finish_rcu(), because some znode were "released" in
-+       * done_tree(). */
++       * reiser4_done_tree(). */
 +      rcu_barrier();
 +
 +      return 0;
@@ -30942,7 +30280,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/disk_format/disk_format40.c
 +      /* Check the locality. */
 +      oid = reiser4_inode_data(object)->locality_id;
 +      if (oid > max) {
-+              warning("vpf-1360", "The object with the locality %llu "
++              warning("vpf-1361", "The object with the locality %llu "
 +                      "greater then the max used oid %llu found.",
 +                      (unsigned long long)oid, (unsigned long long)max);
 +
@@ -30952,6 +30290,48 @@ Index: linux-2.6.16/fs/reiser4/plugin/disk_format/disk_format40.c
 +      return 0;
 +}
 +
++/* plugin->u.format.version_update.
++   Perform all version update operations from the on-disk
++   format40_disk_super_block.version on disk to FORMAT40_VERSION.
++ */
++int version_update_format40(struct super_block *super) {
++      txn_handle * trans;
++      lock_handle lh;
++      txn_atom *atom;
++      int ret;
++
++      /* Nothing to do if RO mount or the on-disk version is not less. */
++      if (super->s_flags & MS_RDONLY)
++              return 0;
++
++      if (get_super_private(super)->version >= FORMAT40_VERSION)
++              return 0;
++
++      printk("reiser4: Updating disk format to 4.0.%u. The reiser4 metadata "
++             "backup is left unchanged. Please run 'fsck.reiser4 --fix' "
++             "on %s to update it too.\n", FORMAT40_VERSION, super->s_id);
++
++      /* Mark the uber znode dirty to call log_super on write_logs. */
++      init_lh(&lh);
++      ret = get_uber_znode(reiser4_get_tree(super), ZNODE_WRITE_LOCK,
++                           ZNODE_LOCK_HIPRI, &lh);
++      if (ret != 0)
++              return ret;
++
++      znode_make_dirty(lh.node);
++      done_lh(&lh);
++
++      /* Update the backup blocks. */
++
++      /* Force write_logs immediately. */
++      trans = get_current_context()->trans;
++      atom = get_current_atom_locked();
++      assert("vpf-1906", atom != NULL);
++
++      spin_lock_txnh(trans);
++      return force_commit_atom(trans);
++}
++
 +/* Make Linus happy.
 +   Local variables:
 +   c-indentation-style: "K&R"
@@ -30962,11 +30342,10 @@ Index: linux-2.6.16/fs/reiser4/plugin/disk_format/disk_format40.c
 +   scroll-step: 1
 +   End:
 +*/
-Index: linux-2.6.16/fs/reiser4/plugin/disk_format/disk_format40.h
-===================================================================
---- /dev/null
-+++ linux-2.6.16/fs/reiser4/plugin/disk_format/disk_format40.h
-@@ -0,0 +1,99 @@
+diff -urN linux-2.6.22.orig/fs/reiser4/plugin/disk_format/disk_format40.h linux-2.6.22/fs/reiser4/plugin/disk_format/disk_format40.h
+--- linux-2.6.22.orig/fs/reiser4/plugin/disk_format/disk_format40.h    1970-01-01 03:00:00.000000000 +0300
++++ linux-2.6.22/fs/reiser4/plugin/disk_format/disk_format40.h 2007-07-29 00:25:34.908704759 +0400
+@@ -0,0 +1,109 @@
 +/* Copyright 2002, 2003 by Hans Reiser, licensing governed by reiser4/README */
 +
 +/* this file contains:
@@ -31016,8 +30395,17 @@ Index: linux-2.6.16/fs/reiser4/plugin/disk_format/disk_format40.h
 +      /*  68 */ d16 tree_height;
 +      /* height of filesystem tree */
 +      /*  70 */ d16 formatting_policy;
++      /* not used anymore */
 +      /*  72 */ d64 flags;
-+      /*  72 */ char not_used[432];
++      /*  80 */ d32 version;
++      /* on-disk format version number
++         initially assigned by mkfs as the greatest format40
++         version number supported by reiser4progs and updated
++         in mount time in accordance with the greatest format40
++         version number supported by kernel.
++         Is used by fsck to catch possible corruption and
++         for various compatibility issues */
++      /*  84 */ char not_used[428];
 +} format40_disk_super_block;
 +
 +/* format 40 specific part of reiser4_super_info_data */
@@ -31047,11 +30435,12 @@ Index: linux-2.6.16/fs/reiser4/plugin/disk_format/disk_format40.h
 +
 +/* declarations of functions implementing methods of layout plugin for
 +   format 40. The functions theirself are in disk_format40.c */
-+int init_format_format40(struct super_block *, void *data);
-+const reiser4_key *root_dir_key_format40(const struct super_block *);
-+int release_format40(struct super_block *s);
-+jnode *log_super_format40(struct super_block *s);
-+int check_open_format40(const struct inode *object);
++extern int init_format_format40(struct super_block *, void *data);
++extern const reiser4_key *root_dir_key_format40(const struct super_block *);
++extern int release_format40(struct super_block *s);
++extern jnode *log_super_format40(struct super_block *s);
++extern int check_open_format40(const struct inode *object);
++extern int version_update_format40(struct super_block *super);
 +
 +/* __DISK_FORMAT40_H__ */
 +#endif
@@ -31066,11 +30455,92 @@ Index: linux-2.6.16/fs/reiser4/plugin/disk_format/disk_format40.h
 +   scroll-step: 1
 +   End:
 +*/
-Index: linux-2.6.16/fs/reiser4/plugin/fibration.c
-===================================================================
---- /dev/null
-+++ linux-2.6.16/fs/reiser4/plugin/fibration.c
-@@ -0,0 +1,174 @@
+diff -urN linux-2.6.22.orig/fs/reiser4/plugin/disk_format/disk_format.c linux-2.6.22/fs/reiser4/plugin/disk_format/disk_format.c
+--- linux-2.6.22.orig/fs/reiser4/plugin/disk_format/disk_format.c      1970-01-01 03:00:00.000000000 +0300
++++ linux-2.6.22/fs/reiser4/plugin/disk_format/disk_format.c   2007-07-29 00:25:34.908704759 +0400
+@@ -0,0 +1,38 @@
++/* Copyright 2002, 2003 by Hans Reiser, licensing governed by reiser4/README */
++
++#include "../../debug.h"
++#include "../plugin_header.h"
++#include "disk_format40.h"
++#include "disk_format.h"
++#include "../plugin.h"
++
++/* initialization of disk layout plugins */
++disk_format_plugin format_plugins[LAST_FORMAT_ID] = {
++      [FORMAT40_ID] = {
++              .h = {
++                      .type_id = REISER4_FORMAT_PLUGIN_TYPE,
++                      .id = FORMAT40_ID,
++                      .pops = NULL,
++                      .label = "reiser40",
++                      .desc = "standard disk layout for reiser40",
++                      .linkage = {NULL, NULL}
++              },
++              .init_format = init_format_format40,
++              .root_dir_key = root_dir_key_format40,
++              .release = release_format40,
++              .log_super = log_super_format40,
++              .check_open = check_open_format40,
++              .version_update = version_update_format40
++      }
++};
++
++/* Make Linus happy.
++   Local variables:
++   c-indentation-style: "K&R"
++   mode-name: "LC"
++   c-basic-offset: 8
++   tab-width: 8
++   fill-column: 120
++   scroll-step: 1
++   End:
++*/
+diff -urN linux-2.6.22.orig/fs/reiser4/plugin/disk_format/disk_format.h linux-2.6.22/fs/reiser4/plugin/disk_format/disk_format.h
+--- linux-2.6.22.orig/fs/reiser4/plugin/disk_format/disk_format.h      1970-01-01 03:00:00.000000000 +0300
++++ linux-2.6.22/fs/reiser4/plugin/disk_format/disk_format.h   2007-07-29 00:25:34.908704759 +0400
+@@ -0,0 +1,27 @@
++/* Copyright 2002, 2003 by Hans Reiser, licensing governed by reiser4/README */
++
++/* identifiers for disk layouts, they are also used as indexes in array of disk
++   plugins */
++
++#if !defined( __REISER4_DISK_FORMAT_H__ )
++#define __REISER4_DISK_FORMAT_H__
++
++typedef enum {
++      /* standard reiser4 disk layout plugin id */
++      FORMAT40_ID,
++      LAST_FORMAT_ID
++} disk_format_id;
++
++/* __REISER4_DISK_FORMAT_H__ */
++#endif
++
++/* Make Linus happy.
++   Local variables:
++   c-indentation-style: "K&R"
++   mode-name: "LC"
++   c-basic-offset: 8
++   tab-width: 8
++   fill-column: 120
++   scroll-step: 1
++   End:
++*/
+diff -urN linux-2.6.22.orig/fs/reiser4/plugin/disk_format/Makefile linux-2.6.22/fs/reiser4/plugin/disk_format/Makefile
+--- linux-2.6.22.orig/fs/reiser4/plugin/disk_format/Makefile   1970-01-01 03:00:00.000000000 +0300
++++ linux-2.6.22/fs/reiser4/plugin/disk_format/Makefile        2007-07-29 00:25:34.908704759 +0400
+@@ -0,0 +1,5 @@
++obj-$(CONFIG_REISER4_FS) += df_plugins.o
++
++df_plugins-objs :=    \
++      disk_format40.o \
++      disk_format.o
+diff -urN linux-2.6.22.orig/fs/reiser4/plugin/fibration.c linux-2.6.22/fs/reiser4/plugin/fibration.c
+--- linux-2.6.22.orig/fs/reiser4/plugin/fibration.c    1970-01-01 03:00:00.000000000 +0300
++++ linux-2.6.22/fs/reiser4/plugin/fibration.c 2007-07-29 00:25:34.908704759 +0400
+@@ -0,0 +1,175 @@
 +/* Copyright 2004 by Hans Reiser, licensing governed by
 + * reiser4/README */
 +
@@ -31154,7 +30624,9 @@ Index: linux-2.6.16/fs/reiser4/plugin/fibration.c
 +              return FIBRE_NO(0);
 +}
 +
-+static int change_fibration(struct inode *inode, reiser4_plugin * plugin)
++static int change_fibration(struct inode *inode,
++                          reiser4_plugin * plugin,
++                          pset_member memb)
 +{
 +      int result;
 +
@@ -31170,9 +30642,8 @@ Index: linux-2.6.16/fs/reiser4/plugin/fibration.c
 +      if (inode_fibration_plugin(inode) == NULL ||
 +          inode_fibration_plugin(inode)->h.id != plugin->h.id) {
 +              if (is_dir_empty(inode) == 0)
-+                      result =
-+                          plugin_set_fibration(&reiser4_inode_data(inode)->
-+                                               pset, &plugin->fibration);
++                      result = aset_set_unsafe(&reiser4_inode_data(inode)->pset,
++                                               PSET_FIBRATION, plugin);
 +              else
 +                      result = RETERR(-ENOTEMPTY);
 +
@@ -31245,10 +30716,9 @@ Index: linux-2.6.16/fs/reiser4/plugin/fibration.c
 + * fill-column: 79
 + * End:
 + */
-Index: linux-2.6.16/fs/reiser4/plugin/fibration.h
-===================================================================
---- /dev/null
-+++ linux-2.6.16/fs/reiser4/plugin/fibration.h
+diff -urN linux-2.6.22.orig/fs/reiser4/plugin/fibration.h linux-2.6.22/fs/reiser4/plugin/fibration.h
+--- linux-2.6.22.orig/fs/reiser4/plugin/fibration.h    1970-01-01 03:00:00.000000000 +0300
++++ linux-2.6.22/fs/reiser4/plugin/fibration.h 2007-07-29 00:25:34.908704759 +0400
 @@ -0,0 +1,37 @@
 +/* Copyright 2004 by Hans Reiser, licensing governed by reiser4/README */
 +
@@ -31287,33 +30757,21 @@ Index: linux-2.6.16/fs/reiser4/plugin/fibration.h
 +   fill-column: 120
 +   End:
 +*/
-Index: linux-2.6.16/fs/reiser4/plugin/file/Makefile
-===================================================================
---- /dev/null
-+++ linux-2.6.16/fs/reiser4/plugin/file/Makefile
-@@ -0,0 +1,7 @@
-+obj-$(CONFIG_REISER4_FS) += file_plugins.o
-+
-+file_plugins-objs :=          \
-+      file.o                  \
-+      tail_conversion.o       \
-+      symlink.o               \
-+      cryptcompress.o
-Index: linux-2.6.16/fs/reiser4/plugin/file/cryptcompress.c
-===================================================================
---- /dev/null
-+++ linux-2.6.16/fs/reiser4/plugin/file/cryptcompress.c
-@@ -0,0 +1,3817 @@
-+/* Copyright 2001, 2002, 2003 by Hans Reiser, licensing governed by 
+diff -urN linux-2.6.22.orig/fs/reiser4/plugin/file/cryptcompress.c linux-2.6.22/fs/reiser4/plugin/file/cryptcompress.c
+--- linux-2.6.22.orig/fs/reiser4/plugin/file/cryptcompress.c   1970-01-01 03:00:00.000000000 +0300
++++ linux-2.6.22/fs/reiser4/plugin/file/cryptcompress.c        2007-07-29 00:25:34.916706830 +0400
+@@ -0,0 +1,3832 @@
++/* Copyright 2001, 2002, 2003 by Hans Reiser, licensing governed by
 +   reiser4/README */
-+
-+/* This file contains implementations of inode/file/address_space/file plugin
-+ * operations specific for cryptcompress file plugin which manages files with
-+ * compressed and encrypted bodies. "Cryptcompress file" is built of items of
-+ * CTAIL_ID (see http://www.namesys.com/cryptcompress_design.html for details).
++/*
++ * Written by Edward Shishkin.
++ *
++ * Implementations of inode/file/address_space operations
++ * specific for cryptcompress file plugin which manages
++ * regular files built of compressed and(or) encrypted bodies.
++ * See http://dev.namesys.com/CryptcompressPlugin for details.
 + */
 +
-+#include "../../page_cache.h"
 +#include "../../inode.h"
 +#include "../cluster.h"
 +#include "../object.h"
@@ -31327,180 +30785,185 @@ Index: linux-2.6.16/fs/reiser4/plugin/file/cryptcompress.c
 +#include <linux/writeback.h>
 +#include <linux/random.h>
 +
++/*
++               Managing primary and secondary caches by Reiser4
++               cryptcompress file plugin. Synchronization scheme.
++
++
++                                             +------------------+
++                        +------------------->|    tfm stream    |
++                        |                    | (compressed data)|
++                  flush |                    +------------------+
++                        +-----------------+           |
++                        |(->)longterm lock|           V
++--+        writepages() |                 |        +-***-+  reiser4        +---+
++  |                     |                 +--+     | *** |  storage tree   |   |
++  |                     |                    |     +-***-+  (primary cache)|   |
++u | write()   (secondary| cache)             V    /   |   \                |   |
++s | ---->  +----+ +----+ +----+ +----+     +-***** ******* **----+  ---->  | d |
++e |        |    | |page cluster |    |     | **disk cluster**    |         | i |
++r | <----  +----+ +----+ +----+ +----+     +-***** **********----+  <----  | s |
++  | read()              ^                      ^      |                    | k |
++  |                     |     (->)longterm lock|      |           page_io()|   |
++  |                     |                      +------+                    |   |
++--+         readpages() |                             |                    +---+
++                        |                             V
++                        |                    +------------------+
++                        +--------------------|    tfm stream    |
++                                             |   (plain text)   |
++                                             +------------------+
++*/
++
 +/* get cryptcompress specific portion of inode */
-+cryptcompress_info_t *cryptcompress_inode_data(const struct inode *inode)
++struct cryptcompress_info *cryptcompress_inode_data(const struct inode *inode)
 +{
 +      return &reiser4_inode_data(inode)->file_plugin_data.cryptcompress_info;
 +}
 +
 +/* plugin->u.file.init_inode_data */
-+void
-+init_inode_data_cryptcompress(struct inode *inode,
-+                            reiser4_object_create_data * crd, int create)
++void init_inode_data_cryptcompress(struct inode *inode,
++                                 reiser4_object_create_data * crd,
++                                 int create)
 +{
-+      cryptcompress_info_t *data;
++      struct cryptcompress_info *data;
 +
 +      data = cryptcompress_inode_data(inode);
 +      assert("edward-685", data != NULL);
 +
 +      memset(data, 0, sizeof(*data));
 +
-+      init_rwsem(&data->lock);
-+      toggle_compression(data, 1);
++      mutex_init(&data->checkin_mutex);
++      data->trunc_index = ULONG_MAX;
++      turn_on_compression(data);
++      set_lattice_factor(data, MIN_LATTICE_FACTOR);
 +      init_inode_ordering(inode, crd, create);
 +}
 +
-+#if REISER4_DEBUG
-+int crc_inode_ok(struct inode *inode)
-+{
-+      if (cluster_shift_ok(inode_cluster_shift(inode)))
-+              return 1;
-+      assert("edward-686", 0);
-+      return 0;
-+}
-+#endif
-+
-+static int check_cryptcompress(struct inode *inode)
-+{
-+      int result = 0;
-+      assert("edward-1307", inode_compression_plugin(inode) != NULL);
-+
-+      if (inode_cluster_size(inode) < PAGE_CACHE_SIZE) {
-+              warning("edward-1331",
-+                      "%s clusters are unsupported",
-+                      inode_cluster_plugin(inode)->h.label);
-+              return RETERR(-EINVAL);
-+      }
-+
-+      /* FIXME-EDWARD: init? or check? */
-+      if (inode_compression_plugin(inode)->init)
-+              result = inode_compression_plugin(inode)->init();
-+      return result;
-+}
-+
 +/* The following is a part of reiser4 cipher key manager
 +   which is called when opening/creating a cryptcompress file */
 +
 +/* get/set cipher key info */
-+crypto_stat_t * inode_crypto_stat (struct inode * inode)
++struct reiser4_crypto_info * inode_crypto_info (struct inode * inode)
 +{
 +      assert("edward-90", inode != NULL);
 +      assert("edward-91", reiser4_inode_data(inode) != NULL);
 +      return cryptcompress_inode_data(inode)->crypt;
 +}
 +
-+static void set_inode_crypto_stat (struct inode * inode, crypto_stat_t * stat)
++static void set_inode_crypto_info (struct inode * inode,
++                                 struct reiser4_crypto_info * info)
 +{
-+      cryptcompress_inode_data(inode)->crypt = stat;
++      cryptcompress_inode_data(inode)->crypt = info;
 +}
 +
 +/* allocate a cipher key info */
-+crypto_stat_t * alloc_crypto_stat (struct inode * inode)
++struct reiser4_crypto_info * reiser4_alloc_crypto_info (struct inode * inode)
 +{
-+      crypto_stat_t * info;
++      struct reiser4_crypto_info * info;
 +      int fipsize;
 +
-+      assert("edward-1421", 0);
-+      info = kmalloc(sizeof(*info), GFP_KERNEL);
++      info = kmalloc(sizeof(*info), reiser4_ctx_gfp_mask_get());
 +      if (!info)
 +              return ERR_PTR(-ENOMEM);
 +      memset(info, 0, sizeof (*info));
 +      fipsize = inode_digest_plugin(inode)->fipsize;
-+      info->keyid = kmalloc(fipsize, GFP_KERNEL);
++      info->keyid = kmalloc(fipsize, reiser4_ctx_gfp_mask_get());
 +      if (!info->keyid) {
 +              kfree(info);
 +              return ERR_PTR(-ENOMEM);
 +      }
++      info->host = inode;
 +      return info;
 +}
 +
 +#if 0
 +/* allocate/free low-level info for cipher and digest
 +   transforms */
-+static int
-+alloc_crypto_tfms(plugin_set * pset, crypto_stat_t * info)
++static int alloc_crypto_tfms(struct reiser4_crypto_info * info)
 +{
-+      struct crypto_tfm * ret = NULL;
-+      cipher_plugin * cplug = pset->cipher;
-+      digest_plugin * dplug = pset->digest;
-+
-+      assert("edward-1363", info != NULL);
-+      assert("edward-414", cplug != NULL);
-+      assert("edward-415", dplug != NULL);
++      struct crypto_blkcipher * ctfm = NULL;
++      struct crypto_hash      * dtfm = NULL;
++      cipher_plugin * cplug = inode_cipher_plugin(info->host);
++      digest_plugin * dplug = inode_digest_plugin(info->host);
 +
 +      if (cplug->alloc) {
-+              ret = cplug->alloc();
-+              if (ret == NULL) {
++              ctfm = cplug->alloc();
++              if (IS_ERR(ctfm)) {
 +                      warning("edward-1364",
 +                              "Can not allocate info for %s\n",
 +                              cplug->h.desc);
-+                      return RETERR(-EINVAL);
++                      return RETERR(PTR_ERR(ctfm));
 +              }
 +      }
-+      info_set_tfm(info, CIPHER_TFM, ret);
++      info_set_cipher(info, ctfm);
 +      if (dplug->alloc) {
-+              ret = dplug->alloc();
-+              if (ret == NULL) {
++              dtfm = dplug->alloc();
++              if (IS_ERR(dtfm)) {
 +                      warning("edward-1365",
 +                              "Can not allocate info for %s\n",
 +                              dplug->h.desc);
-+                      goto err;
++                      goto unhappy_with_digest;
 +              }
 +      }
-+      info_set_tfm(info, DIGEST_TFM, ret);
++      info_set_digest(info, dtfm);
 +      return 0;
-+ err:
++ unhappy_with_digest:
 +      if (cplug->free) {
-+              cplug->free(info->tfma[CIPHER_TFM].tfm);
-+              info_set_tfm(info, CIPHER_TFM, NULL);
++              cplug->free(ctfm);
++              info_set_cipher(info, NULL);
 +      }
-+      return RETERR(-EINVAL);
++      return RETERR(PTR_ERR(dtfm));
 +}
 +#endif
 +
 +static void
-+free_crypto_tfms(crypto_stat_t * info)
++free_crypto_tfms(struct reiser4_crypto_info * info)
 +{
 +      assert("edward-1366", info != NULL);
-+      if (!info_cipher_tfm(info))
++      if (!info_get_cipher(info)) {
++              assert("edward-1601", !info_get_digest(info));
 +              return;
-+      info_cipher_plugin(info)->free(info_cipher_tfm(info));
-+      info_set_tfm(info, CIPHER_TFM, NULL);
-+      info_digest_plugin(info)->free(info_digest_tfm(info));
-+      info_set_tfm(info, DIGEST_TFM, NULL);
++      }
++      inode_cipher_plugin(info->host)->free(info_get_cipher(info));
++      info_set_cipher(info, NULL);
++      inode_digest_plugin(info->host)->free(info_get_digest(info));
++      info_set_digest(info, NULL);
 +      return;
 +}
 +
 +#if 0
 +/* create a key fingerprint for disk stat-data */
-+static int create_keyid (crypto_stat_t * info, crypto_data_t * data)
++static int create_keyid (struct reiser4_crypto_info * info,
++                       struct reiser4_crypto_data * data)
 +{
 +      int ret = -ENOMEM;
 +      size_t blk, pad;
 +      __u8 * dmem;
 +      __u8 * cmem;
-+      struct crypto_tfm * dtfm;
-+      struct crypto_tfm * ctfm;
++      struct hash_desc      ddesc;
++      struct blkcipher_desc cdesc;
 +      struct scatterlist sg;
 +
-+      assert("edward-1422", 0);
 +      assert("edward-1367", info != NULL);
 +      assert("edward-1368", info->keyid != NULL);
 +
-+      dtfm = info_digest_tfm(info);
-+      ctfm = info_cipher_tfm(info);
++      ddesc.tfm = info_get_digest(info);
++      ddesc.flags = 0;
++      cdesc.tfm = info_get_cipher(info);
++      cdesc.flags = 0;
 +
-+      dmem = kmalloc((size_t)crypto_tfm_alg_digestsize(dtfm),
-+                             GFP_KERNEL);
++      dmem = kmalloc((size_t)crypto_hash_digestsize(ddesc.tfm),
++                     reiser4_ctx_gfp_mask_get());
 +      if (!dmem)
 +              goto exit1;
 +
-+      blk = crypto_tfm_alg_blocksize(ctfm);
++      blk = crypto_blkcipher_blocksize(cdesc.tfm);
 +
 +      pad = data->keyid_size % blk;
 +      pad = (pad ? blk - pad : 0);
 +
-+      cmem = kmalloc((size_t)data->keyid_size + pad, GFP_KERNEL);
++      cmem = kmalloc((size_t)data->keyid_size + pad,
++                     reiser4_ctx_gfp_mask_get());
 +      if (!cmem)
 +              goto exit2;
 +      memcpy(cmem, data->keyid, data->keyid_size);
@@ -31510,16 +30973,20 @@ Index: linux-2.6.16/fs/reiser4/plugin/file/cryptcompress.c
 +      sg.offset = offset_in_page(cmem);
 +      sg.length = data->keyid_size + pad;
 +
-+      ret = crypto_cipher_encrypt(ctfm, &sg, &sg, data->keyid_size + pad);
++      ret = crypto_blkcipher_encrypt(&cdesc, &sg, &sg,
++                                     data->keyid_size + pad);
 +      if (ret) {
 +              warning("edward-1369",
-+                      "encryption failed flags=%x\n", ctfm->crt_flags);
++                      "encryption failed flags=%x\n", cdesc.flags);
 +              goto exit3;
 +      }
-+      crypto_digest_init (dtfm);
-+      crypto_digest_update (dtfm, &sg, 1);
-+      crypto_digest_final (dtfm, dmem);
-+      memcpy(info->keyid, dmem, info_digest_plugin(info)->fipsize);
++      ret = crypto_hash_digest(&ddesc, &sg, sg.length, dmem);
++      if (ret) {
++              warning("edward-1602",
++                      "digest failed flags=%x\n", ddesc.flags);
++              goto exit3;
++      }
++      memcpy(info->keyid, dmem, inode_digest_plugin(info->host)->fipsize);
 + exit3:
 +      kfree(cmem);
 + exit2:
@@ -31529,7 +30996,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/file/cryptcompress.c
 +}
 +#endif
 +
-+static void destroy_keyid(crypto_stat_t * info)
++static void destroy_keyid(struct reiser4_crypto_info * info)
 +{
 +      assert("edward-1370", info != NULL);
 +      assert("edward-1371", info->keyid != NULL);
@@ -31537,8 +31004,9 @@ Index: linux-2.6.16/fs/reiser4/plugin/file/cryptcompress.c
 +      return;
 +}
 +
-+static void free_crypto_stat (crypto_stat_t * info)
++static void __free_crypto_info (struct inode * inode)
 +{
++      struct reiser4_crypto_info * info = inode_crypto_info(inode);
 +      assert("edward-1372", info != NULL);
 +
 +      free_crypto_tfms(info);
@@ -31547,7 +31015,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/file/cryptcompress.c
 +}
 +
 +#if 0
-+static void instantiate_crypto_stat(crypto_stat_t * info)
++static void instantiate_crypto_info(struct reiser4_crypto_info * info)
 +{
 +      assert("edward-1373", info != NULL);
 +      assert("edward-1374", info->inst == 0);
@@ -31555,13 +31023,13 @@ Index: linux-2.6.16/fs/reiser4/plugin/file/cryptcompress.c
 +}
 +#endif
 +
-+static void uninstantiate_crypto_stat(crypto_stat_t * info)
++static void uninstantiate_crypto_info(struct reiser4_crypto_info * info)
 +{
 +      assert("edward-1375", info != NULL);
 +      info->inst = 0;
 +}
 +
-+static int crypto_stat_instantiated(crypto_stat_t * info)
++static int is_crypto_info_instantiated(struct reiser4_crypto_info * info)
 +{
 +      return info->inst;
 +}
@@ -31569,14 +31037,14 @@ Index: linux-2.6.16/fs/reiser4/plugin/file/cryptcompress.c
 +static int inode_has_cipher_key(struct inode * inode)
 +{
 +      assert("edward-1376", inode != NULL);
-+      return inode_crypto_stat(inode) &&
-+              crypto_stat_instantiated(inode_crypto_stat(inode));
++      return inode_crypto_info(inode) &&
++              is_crypto_info_instantiated(inode_crypto_info(inode));
 +}
 +
-+static void inode_free_crypto_stat (struct inode * inode)
++static void free_crypto_info (struct inode * inode)
 +{
-+      uninstantiate_crypto_stat(inode_crypto_stat(inode));
-+      free_crypto_stat(inode_crypto_stat(inode));
++      uninstantiate_crypto_info(inode_crypto_info(inode));
++      __free_crypto_info(inode);
 +}
 +
 +static int need_cipher(struct inode * inode)
@@ -31585,18 +31053,15 @@ Index: linux-2.6.16/fs/reiser4/plugin/file/cryptcompress.c
 +              cipher_plugin_by_id(NONE_CIPHER_ID);
 +}
 +
-+/* Create a crypto-stat and attach result to the @object.
-+   If success is returned, then low-level cipher info contains
-+   an instantiated key */
++/* Parse @data which contains a (uninstantiated) cipher key imported
++   from user space, create a low-level cipher info and attach it to
++   the @object. If success, then info contains an instantiated key */
 +#if 0
-+crypto_stat_t * 
-+create_crypto_stat(struct inode * object, 
-+                 crypto_data_t * data /* this contains a (uninstantiated) 
-+                                         cipher key imported from user
-+                                         space */)
++struct reiser4_crypto_info * create_crypto_info(struct inode * object,
++                                struct reiser4_crypto_data * data)
 +{
 +      int ret;
-+      crypto_stat_t * info;
++      struct reiser4_crypto_info * info;
 +
 +      assert("edward-1377", data != NULL);
 +      assert("edward-1378", need_cipher(object));
@@ -31605,78 +31070,74 @@ Index: linux-2.6.16/fs/reiser4/plugin/file/cryptcompress.c
 +          file_plugin_by_id(DIRECTORY_FILE_PLUGIN_ID))
 +              return ERR_PTR(-EINVAL);
 +
-+      info = alloc_crypto_stat(object);
++      info = reiser4_alloc_crypto_info(object);
 +      if (IS_ERR(info))
 +              return info;
-+      ret = alloc_crypto_tfms(reiser4_inode_data(object)->pset, info);
++      ret = alloc_crypto_tfms(info);
 +      if (ret)
 +              goto err;
-+      /* Someone can change plugins of the host (for example if
-+         the host is a directory), so we keep the original ones
-+         in the crypto-stat. */
-+      info_set_cipher_plugin(info, inode_cipher_plugin(object));
-+      info_set_digest_plugin(info, inode_digest_plugin(object));
 +      /* instantiating a key */
-+      ret = crypto_cipher_setkey(info_cipher_tfm(info),
-+                                 data->key,
-+                                 data->keysize);
++      ret = crypto_blkcipher_setkey(info_get_cipher(info),
++                                    data->key,
++                                    data->keysize);
 +      if (ret) {
 +              warning("edward-1379",
-+                      "setkey failed flags=%x\n",
-+                      info_cipher_tfm(info)->crt_flags);
++                      "setkey failed flags=%x",
++                      crypto_blkcipher_get_flags(info_get_cipher(info)));
 +              goto err;
 +      }
 +      info->keysize = data->keysize;
 +      ret = create_keyid(info, data);
 +      if (ret)
 +              goto err;
-+      instantiate_crypto_stat(info);
++      instantiate_crypto_info(info);
 +      return info;
 + err:
-+      free_crypto_stat(info);
++      __free_crypto_info(object);
 +      return ERR_PTR(ret);
 +}
 +#endif
 +
-+/* increment/decrement a load counter when 
++/* increment/decrement a load counter when
 +   attaching/detaching the crypto-stat to any object */
-+static void load_crypto_stat(crypto_stat_t * info)
++static void load_crypto_info(struct reiser4_crypto_info * info)
 +{
 +      assert("edward-1380", info != NULL);
 +      inc_keyload_count(info);
 +}
 +
-+static void unload_crypto_stat(struct inode * inode)
++static void unload_crypto_info(struct inode * inode)
 +{
-+      crypto_stat_t * info = inode_crypto_stat(inode);
++      struct reiser4_crypto_info * info = inode_crypto_info(inode);
 +      assert("edward-1381", info->keyload_count > 0);
 +
-+      dec_keyload_count(inode_crypto_stat(inode));
++      dec_keyload_count(inode_crypto_info(inode));
 +      if (info->keyload_count == 0)
 +              /* final release */
-+              inode_free_crypto_stat(inode);
++              free_crypto_info(inode);
 +}
 +
 +/* attach/detach an existing crypto-stat */
-+void attach_crypto_stat(struct inode * inode, crypto_stat_t * info)
++void reiser4_attach_crypto_info(struct inode * inode,
++                              struct reiser4_crypto_info * info)
 +{
 +      assert("edward-1382", inode != NULL);
 +      assert("edward-1383", info != NULL);
-+      assert("edward-1384", inode_crypto_stat(inode) == NULL);
++      assert("edward-1384", inode_crypto_info(inode) == NULL);
 +
-+      set_inode_crypto_stat(inode, info);
-+      load_crypto_stat(info);
++      set_inode_crypto_info(inode, info);
++      load_crypto_info(info);
 +}
 +
 +/* returns true, if crypto stat can be attached to the @host */
 +#if REISER4_DEBUG
-+static int host_allows_crypto_stat(struct inode * host)
++static int host_allows_crypto_info(struct inode * host)
 +{
 +      int ret;
 +      file_plugin * fplug = inode_file_plugin(host);
 +
 +      switch (fplug->h.id) {
-+      case CRC_FILE_PLUGIN_ID:
++      case CRYPTCOMPRESS_FILE_PLUGIN_ID:
 +              ret = 1;
 +              break;
 +      default:
@@ -31686,39 +31147,43 @@ Index: linux-2.6.16/fs/reiser4/plugin/file/cryptcompress.c
 +}
 +#endif  /*  REISER4_DEBUG  */
 +
-+void detach_crypto_stat(struct inode * inode)
++static void reiser4_detach_crypto_info(struct inode * inode)
 +{
 +      assert("edward-1385", inode != NULL);
-+      assert("edward-1386", host_allows_crypto_stat(inode));
++      assert("edward-1386", host_allows_crypto_info(inode));
 +
-+      if (inode_crypto_stat(inode))
-+              unload_crypto_stat(inode);
-+      set_inode_crypto_stat(inode, NULL);
++      if (inode_crypto_info(inode))
++              unload_crypto_info(inode);
++      set_inode_crypto_info(inode, NULL);
 +}
 +
 +#if 0
 +
 +/* compare fingerprints of @child and @parent */
-+static int keyid_eq(crypto_stat_t * child, crypto_stat_t * parent)
++static int keyid_eq(struct reiser4_crypto_info * child,
++                  struct reiser4_crypto_info * parent)
 +{
-+      return !memcmp(child->keyid, parent->keyid, info_digest_plugin(parent)->fipsize);
++      return !memcmp(child->keyid,
++                     parent->keyid,
++                     info_digest_plugin(parent)->fipsize);
 +}
 +
 +/* check if a crypto-stat (which is bound to @parent) can be inherited */
-+int can_inherit_crypto_crc(struct inode *child, struct inode *parent)
++int can_inherit_crypto_cryptcompress(struct inode *child, struct inode *parent)
 +{
 +      if (!need_cipher(child))
 +              return 0;
 +      /* the child is created */
-+      if (!inode_crypto_stat(child))
++      if (!inode_crypto_info(child))
 +              return 1;
 +      /* the child is looked up */
-+      if (!inode_crypto_stat(parent))
++      if (!inode_crypto_info(parent))
 +              return 0;
 +      return (inode_cipher_plugin(child) == inode_cipher_plugin(parent) &&
 +              inode_digest_plugin(child) == inode_digest_plugin(parent) &&
-+              inode_crypto_stat(child)->keysize == inode_crypto_stat(parent)->keysize &&
-+              keyid_eq(inode_crypto_stat(child), inode_crypto_stat(parent)));
++              inode_crypto_info(child)->keysize ==
++              inode_crypto_info(parent)->keysize &&
++              keyid_eq(inode_crypto_info(child), inode_crypto_info(parent)));
 +}
 +#endif
 +
@@ -31726,7 +31191,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/file/cryptcompress.c
 +static int inode_set_crypto(struct inode * object)
 +{
 +      reiser4_inode * info;
-+      if (!inode_crypto_stat(object)) {
++      if (!inode_crypto_info(object)) {
 +              if (need_cipher(object))
 +                      return RETERR(-EINVAL);
 +              /* the file is not to be encrypted */
@@ -31734,63 +31199,42 @@ Index: linux-2.6.16/fs/reiser4/plugin/file/cryptcompress.c
 +      }
 +      info = reiser4_inode_data(object);
 +      info->extmask |= (1 << CRYPTO_STAT);
-+      info->plugin_mask |= (1 << PSET_CIPHER) | (1 << PSET_DIGEST);
 +      return 0;
 +}
 +
-+static int
-+inode_set_compression(struct inode * object)
++static int inode_init_compression(struct inode * object)
 +{
 +      int result = 0;
-+      compression_plugin * cplug;
-+      reiser4_inode * info = reiser4_inode_data(object);
-+
-+      cplug = inode_compression_plugin(object);
-+
-+      if (cplug->init != NULL) {
-+              result = cplug->init();
-+              if (result)
-+                      return result;
-+      }
-+      info->plugin_mask |= (1 << PSET_COMPRESSION);
-+
-+      return 0;
-+}
-+
-+static void
-+inode_set_compression_mode(struct inode * object)
-+{
-+      reiser4_inode * info = reiser4_inode_data(object);
-+
-+      info->plugin_mask |= (1 << PSET_COMPRESSION_MODE);
-+      return;
++      assert("edward-1461", object != NULL);
++      if (inode_compression_plugin(object)->init)
++              result = inode_compression_plugin(object)->init();
++      return result;
 +}
 +
-+static int inode_set_cluster(struct inode *object)
++static int inode_check_cluster(struct inode * object)
 +{
-+      reiser4_inode *info;
-+      cluster_plugin *cplug;
-+
 +      assert("edward-696", object != NULL);
 +
-+      info = reiser4_inode_data(object);
-+      cplug = inode_cluster_plugin(object);
-+
-+      if (cplug->shift < PAGE_CACHE_SHIFT) {
-+              warning("edward-1320",
-+                      "Can not support %p clusters (less then page size)",
-+                      cplug->h.label);
++      if (unlikely(inode_cluster_size(object) < PAGE_CACHE_SIZE)) {
++              warning("edward-1320", "Can not support '%s' "
++                      "logical clusters (less then page size)",
++                      inode_cluster_plugin(object)->h.label);
++              return RETERR(-EINVAL);
++      }
++      if (unlikely(inode_cluster_shift(object)) >= BITS_PER_BYTE*sizeof(int)){
++              warning("edward-1463", "Can not support '%s' "
++                      "logical clusters (too big for transform)",
++                      inode_cluster_plugin(object)->h.label);
 +              return RETERR(-EINVAL);
 +      }
-+      info->plugin_mask |= (1 << PSET_CLUSTER);
 +      return 0;
 +}
 +
 +/* ->destroy_inode() method of the cryptcompress plugin */
 +void destroy_inode_cryptcompress(struct inode * inode)
 +{
-+      assert("edward-23", cryptcompress_inode_data(inode)->pgcount == 0);
-+      detach_crypto_stat(inode);
++      assert("edward-1464", INODE_PGCOUNT(inode) == 0);
++      reiser4_detach_crypto_info(inode);
 +      return;
 +}
 +
@@ -31801,9 +31245,8 @@ Index: linux-2.6.16/fs/reiser4/plugin/file/cryptcompress.c
 +. attach compression info if specified
 +. attach cluster info
 +*/
-+int
-+create_cryptcompress(struct inode *object, struct inode *parent,
-+                   reiser4_object_create_data * data)
++int create_cryptcompress(struct inode *object, struct inode *parent,
++                       reiser4_object_create_data * data)
 +{
 +      int result;
 +      reiser4_inode *info;
@@ -31811,8 +31254,8 @@ Index: linux-2.6.16/fs/reiser4/plugin/file/cryptcompress.c
 +      assert("edward-23", object != NULL);
 +      assert("edward-24", parent != NULL);
 +      assert("edward-30", data != NULL);
-+      assert("edward-26", inode_get_flag(object, REISER4_NO_SD));
-+      assert("edward-27", data->id == CRC_FILE_PLUGIN_ID);
++      assert("edward-26", reiser4_inode_get_flag(object, REISER4_NO_SD));
++      assert("edward-27", data->id == CRYPTCOMPRESS_FILE_PLUGIN_ID);
 +
 +      info = reiser4_inode_data(object);
 +
@@ -31826,30 +31269,27 @@ Index: linux-2.6.16/fs/reiser4/plugin/file/cryptcompress.c
 +      if (result)
 +              goto error;
 +      /* set compression */
-+      result = inode_set_compression(object);
++      result = inode_init_compression(object);
 +      if (result)
 +              goto error;
-+      inode_set_compression_mode(object);
-+
-+      /* set cluster info */
-+      result = inode_set_cluster(object);
++      /* set cluster */
++      result = inode_check_cluster(object);
 +      if (result)
 +              goto error;
-+      /* set plugin mask */
-+      info->extmask |= (1 << PLUGIN_STAT);
 +
 +      /* save everything in disk stat-data */
 +      result = write_sd_by_inode_common(object);
 +      if (!result)
 +              return 0;
 + error:
-+      detach_crypto_stat(object);
++      reiser4_detach_crypto_info(object);
 +      return result;
 +}
 +
-+/* ->open() method of the cryptcompress plugin */
-+int open_cryptcompress(struct inode * inode, struct file * file)
++/* ->open_object() method of the cryptcompress plugin */
++int open_object_cryptcompress(struct inode * inode, struct file * file)
 +{
++      int result;
 +      struct inode * parent;
 +
 +      assert("edward-1394", inode != NULL);
@@ -31860,8 +31300,13 @@ Index: linux-2.6.16/fs/reiser4/plugin/file/cryptcompress.c
 +      assert("edward-1399", file->f_dentry->d_parent->d_inode != NULL);
 +      assert("edward-698",
 +             inode_file_plugin(inode) ==
-+             file_plugin_by_id(CRC_FILE_PLUGIN_ID));
-+
++             file_plugin_by_id(CRYPTCOMPRESS_FILE_PLUGIN_ID));
++      result = inode_check_cluster(inode);
++      if (result)
++              return result;
++      result = inode_init_compression(inode);
++      if (result)
++              return result;
 +      if (!need_cipher(inode))
 +              /* the file is not to be ciphered */
 +              return 0;
@@ -31876,9 +31321,9 @@ Index: linux-2.6.16/fs/reiser4/plugin/file/cryptcompress.c
 +cipher_blocksize(struct inode * inode)
 +{
 +      assert("edward-758", need_cipher(inode));
-+      assert("edward-1400", inode_crypto_stat(inode) != NULL);
-+      return crypto_tfm_alg_blocksize
-+              (info_cipher_tfm(inode_crypto_stat(inode)));
++      assert("edward-1400", inode_crypto_info(inode) != NULL);
++      return crypto_blkcipher_blocksize
++              (info_get_cipher(inode_crypto_info(inode)));
 +}
 +
 +/* returns offset translated by scale factor of the crypto-algorithm */
@@ -31888,8 +31333,8 @@ Index: linux-2.6.16/fs/reiser4/plugin/file/cryptcompress.c
 +      assert("edward-97", inode != NULL);
 +
 +      if (!need_cipher(inode) ||
-+          src_off == get_key_offset(min_key()) ||
-+          src_off == get_key_offset(max_key()))
++          src_off == get_key_offset(reiser4_min_key()) ||
++          src_off == get_key_offset(reiser4_max_key()))
 +              return src_off;
 +
 +      return inode_cipher_plugin(inode)->scale(inode,
@@ -31905,100 +31350,84 @@ Index: linux-2.6.16/fs/reiser4/plugin/file/cryptcompress.c
 +      return inode_scaled_offset(inode, inode_cluster_size(inode));
 +}
 +
-+static int new_cluster(reiser4_cluster_t * clust, struct inode *inode)
-+{
-+      return (clust_to_off(clust->index, inode) >= inode->i_size);
-+}
-+
 +/* set number of cluster pages */
-+static void set_cluster_nrpages(reiser4_cluster_t * clust, struct inode *inode)
++static void set_cluster_nrpages(struct cluster_handle * clust,
++                              struct inode *inode)
 +{
-+      reiser4_slide_t *win;
++      struct reiser4_slide * win;
 +
 +      assert("edward-180", clust != NULL);
 +      assert("edward-1040", inode != NULL);
 +
++      clust->old_nrpages = size_in_pages(lbytes(clust->index, inode));
 +      win = clust->win;
 +      if (!win) {
-+              /* NOTE-EDWARD: i_size should be protected */
-+              clust->nr_pages =
-+                  count_to_nrpages(fsize_to_count(clust, inode));
++              clust->nr_pages = size_in_pages(lbytes(clust->index, inode));
 +              return;
 +      }
-+      assert("edward-1176", clust->op != PCL_UNKNOWN);
++      assert("edward-1176", clust->op != LC_INVAL);
 +      assert("edward-1064", win->off + win->count + win->delta != 0);
 +
 +      if (win->stat == HOLE_WINDOW &&
 +          win->off == 0 && win->count == inode_cluster_size(inode)) {
-+              /* special case: we start write hole from fake cluster */
++              /* special case: writing a "fake" logical cluster */
 +              clust->nr_pages = 0;
 +              return;
 +      }
-+      clust->nr_pages =
-+          count_to_nrpages(max_count(win->off + win->count + win->delta,
-+                                     fsize_to_count(clust, inode)));
++      clust->nr_pages = size_in_pages(max(win->off + win->count + win->delta,
++                                          lbytes(clust->index, inode)));
 +      return;
 +}
 +
-+/* ->key_by_inode() method of the cryptcompress plugin */
-+/* see plugin/plugin.h for details */
-+int
-+key_by_inode_cryptcompress(struct inode *inode, loff_t off, reiser4_key * key)
++/* plugin->key_by_inode()
++   build key of a disk cluster */
++int key_by_inode_cryptcompress(struct inode *inode, loff_t off,
++                             reiser4_key * key)
 +{
-+      loff_t clust_off;
-+
 +      assert("edward-64", inode != 0);
-+      //      assert("edward-112", ergo(off != get_key_offset(max_key()), !off_to_cloff(off, inode)));
-+      /* don't come here with other offsets */
 +
-+      clust_off =
-+          (off ==
-+           get_key_offset(max_key())? get_key_offset(max_key()) :
-+           off_to_clust_to_off(off, inode));
++      if (likely(off != get_key_offset(reiser4_max_key())))
++              off = off_to_clust_to_off(off, inode);
++      if (inode_crypto_info(inode))
++              off = inode_scaled_offset(inode, off);
 +
 +      key_by_inode_and_offset_common(inode, 0, key);
-+      set_key_offset(key,
-+                     (__u64) (!inode_crypto_stat(inode) ? clust_off :
-+                              inode_scaled_offset(inode, clust_off)));
++      set_key_offset(key, (__u64)off);
 +      return 0;
 +}
 +
-+/* plugin->flow_by_inode */
-+int
-+flow_by_inode_cryptcompress(struct inode *inode /* file to build flow for */ ,
-+                          const char __user *buf /* user level buffer */ ,
-+                          int user    /* 1 if @buf is of user space, 0 - if it is
-+                                         kernel space */ ,
-+                          loff_t size /* buffer size */ ,
-+                          loff_t off /* offset to start io from */ ,
-+                          rw_op op /* READ or WRITE */ ,
-+                          flow_t * f /* resulting flow */ )
++/* plugin->flow_by_inode() */
++/* flow is used to read/write disk clusters */
++int flow_by_inode_cryptcompress(struct inode *inode, const char __user * buf,
++                              int user,       /* 1: @buf is of user space,
++                                                 0: kernel space */
++                              loff_t size,    /* @buf size */
++                              loff_t off,     /* offset to start io from */
++                              rw_op op,       /* READ or WRITE */
++                              flow_t * f      /* resulting flow */)
 +{
 +      assert("edward-436", f != NULL);
 +      assert("edward-149", inode != NULL);
 +      assert("edward-150", inode_file_plugin(inode) != NULL);
-+      assert("edward-151",
-+             inode_file_plugin(inode)->key_by_inode ==
-+             key_by_inode_cryptcompress);
-+
++      assert("edward-1465", user == 0); /* we use flow to read/write
++                                          disk clusters located in
++                                          kernel space */
 +      f->length = size;
 +      memcpy(&f->data, &buf, sizeof(buf));
 +      f->user = user;
 +      f->op = op;
 +
-+      if (op == WRITE_OP && user == 1)
-+              return 0;
 +      return key_by_inode_cryptcompress(inode, off, &f->key);
 +}
 +
 +static int
-+crc_hint_validate(hint_t * hint, const reiser4_key * key,
-+                znode_lock_mode lock_mode)
++cryptcompress_hint_validate(hint_t * hint, const reiser4_key * key,
++                          znode_lock_mode lock_mode)
 +{
 +      coord_t *coord;
 +
 +      assert("edward-704", hint != NULL);
-+      assert("edward-1089", !hint->ext_coord.valid);
++      assert("edward-1089", !hint_is_valid(hint));
 +      assert("edward-706", hint->lh.owner == NULL);
 +
 +      coord = &hint->ext_coord.coord;
@@ -32011,27 +31440,27 @@ Index: linux-2.6.16/fs/reiser4/plugin/file/cryptcompress.c
 +              /* hint is set for different key */
 +              return RETERR(-E_REPEAT);
 +
-+      assert("edward-707", schedulable());
++      assert("edward-707", reiser4_schedulable());
 +
-+      return seal_validate(&hint->seal, &hint->ext_coord.coord,
-+                           key, &hint->lh, lock_mode, ZNODE_LOCK_LOPRI);
++      return reiser4_seal_validate(&hint->seal, &hint->ext_coord.coord,
++                                   key, &hint->lh, lock_mode,
++                                   ZNODE_LOCK_LOPRI);
 +}
 +
 +/* reserve disk space when writing a logical cluster */
-+static int reserve4cluster(struct inode *inode, reiser4_cluster_t *clust)
++static int reserve4cluster(struct inode *inode, struct cluster_handle *clust)
 +{
 +      int result = 0;
 +
-+      assert("edward-965", schedulable());
++      assert("edward-965", reiser4_schedulable());
 +      assert("edward-439", inode != NULL);
 +      assert("edward-440", clust != NULL);
 +      assert("edward-441", clust->pages != NULL);
-+      assert("edward-1261", get_current_context()->grabbed_blocks == 0);
 +
 +      if (clust->nr_pages == 0) {
 +              assert("edward-1152", clust->win != NULL);
 +              assert("edward-1153", clust->win->stat == HOLE_WINDOW);
-+              /* don't reserve space for fake disk clusteer */
++              /* don't reserve disk space for fake logical cluster */
 +              return 0;
 +      }
 +      assert("edward-442", jprivate(clust->pages[0]) != NULL);
@@ -32049,23 +31478,22 @@ Index: linux-2.6.16/fs/reiser4/plugin/file/cryptcompress.c
 +      clust->reserved_unprepped = estimate_insert_cluster(inode);
 +#endif
 +      /* there can be space grabbed by txnmgr_force_commit_all */
-+      all_grabbed2free();
 +      return 0;
 +}
 +
 +/* free reserved disk space if writing a logical cluster fails */
-+static void
-+free_reserved4cluster(struct inode *inode, reiser4_cluster_t * clust, int count)
++static void free_reserved4cluster(struct inode *inode,
++                                struct cluster_handle *ch, int count)
 +{
-+      assert("edward-967", clust->reserved == 1);
++      assert("edward-967", ch->reserved == 1);
 +
 +      cluster_reserved2free(count);
-+      clust->reserved = 0;
++      ch->reserved = 0;
 +}
 +
 +/* The core search procedure of the cryptcompress plugin.
 +   If returned value is not cbk_errored, then current znode is locked */
-+static int find_cluster_item(hint_t * hint, 
++static int find_cluster_item(hint_t * hint,
 +                           const reiser4_key * key, /* key of the item we are
 +                                                       looking for */
 +                           znode_lock_mode lock_mode /* which lock */ ,
@@ -32073,20 +31501,21 @@ Index: linux-2.6.16/fs/reiser4/plugin/file/cryptcompress.c
 +{
 +      int result;
 +      reiser4_key ikey;
++      int went_right = 0;
 +      coord_t *coord = &hint->ext_coord.coord;
 +      coord_t orig = *coord;
 +
 +      assert("edward-152", hint != NULL);
 +
-+      if (hint->ext_coord.valid == 0) {
-+              result = crc_hint_validate(hint, key, lock_mode);
++      if (!hint_is_valid(hint)) {
++              result = cryptcompress_hint_validate(hint, key, lock_mode);
 +              if (result == -E_REPEAT)
 +                      goto traverse_tree;
 +              else if (result) {
 +                      assert("edward-1216", 0);
 +                      return result;
 +              }
-+              hint->ext_coord.valid = 1;
++              hint_set_valid(hint);
 +      }
 +      assert("edward-709", znode_is_any_locked(coord->node));
 +
@@ -32102,6 +31531,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/file/cryptcompress.c
 +              if (result)
 +                      return result;
 +              assert("edward-1218", equal_to_ldk(coord->node, key));
++              went_right = 1;
 +      } else {
 +              coord->item_pos++;
 +              coord->unit_pos = 0;
@@ -32120,9 +31550,12 @@ Index: linux-2.6.16/fs/reiser4/plugin/file/cryptcompress.c
 +      zrelse(coord->node);
 +      if (!keyeq(key, &ikey))
 +              goto not_found;
++      /* Ok, item is found, update node counts */
++      if (went_right)
++              dclust_inc_extension_ncount(hint);
 +      return CBK_COORD_FOUND;
 +
-+      not_found:
++ not_found:
 +      assert("edward-1220", coord->item_pos > 0);
 +      //coord->item_pos--;
 +      /* roll back */
@@ -32130,18 +31563,21 @@ Index: linux-2.6.16/fs/reiser4/plugin/file/cryptcompress.c
 +      ON_DEBUG(coord_update_v(coord));
 +      return CBK_COORD_NOTFOUND;
 +
-+      traverse_tree:
++ traverse_tree:
 +      assert("edward-713", hint->lh.owner == NULL);
-+      assert("edward-714", schedulable());
++      assert("edward-714", reiser4_schedulable());
 +
-+      unset_hint(hint);
++      reiser4_unset_hint(hint);
++      dclust_init_extension(hint);
 +      coord_init_zero(coord);
 +      result = coord_by_key(current_tree, key, coord, &hint->lh,
 +                            lock_mode, bias, LEAF_LEVEL, LEAF_LEVEL,
 +                            CBK_UNIQUE | flags, ra_info);
 +      if (cbk_errored(result))
 +              return result;
-+      hint->ext_coord.valid = 1;
++      if(result == CBK_COORD_FOUND)
++              dclust_inc_extension_ncount(hint);
++      hint_set_valid(hint);
 +      return result;
 +}
 +
@@ -32150,11 +31586,10 @@ Index: linux-2.6.16/fs/reiser4/plugin/file/cryptcompress.c
 +   create/cut some overhead. If this returns true, then @oh
 +   contains the size of this overhead.
 + */
-+static int
-+need_cut_or_align(struct inode * inode, reiser4_cluster_t * clust,
-+                rw_op rw, int * oh)
++static int need_cut_or_align(struct inode * inode,
++                           struct cluster_handle * ch, rw_op rw, int * oh)
 +{
-+      tfm_cluster_t * tc = &clust->tc;
++      struct tfm_cluster * tc = &ch->tc;
 +      switch (rw) {
 +      case WRITE_OP: /* estimate align */
 +              *oh = tc->len % cipher_blocksize(inode);
@@ -32162,7 +31597,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/file/cryptcompress.c
 +                      return 1;
 +              break;
 +      case READ_OP:  /* estimate cut */
-+              *oh = *(tfm_output_data(clust) + tc->len - 1);
++              *oh = *(tfm_output_data(ch) + tc->len - 1);
 +              break;
 +      default:
 +              impossible("edward-1401", "bad option");
@@ -32171,28 +31606,28 @@ Index: linux-2.6.16/fs/reiser4/plugin/file/cryptcompress.c
 +}
 +
 +/* create/cut an overhead of transformed/plain stream */
-+static void
-+align_or_cut_overhead(struct inode * inode, reiser4_cluster_t * clust, rw_op rw)
++static void align_or_cut_overhead(struct inode * inode,
++                                struct cluster_handle * ch, rw_op rw)
 +{
 +      int oh;
 +      cipher_plugin * cplug = inode_cipher_plugin(inode);
 +
 +      assert("edward-1402", need_cipher(inode));
 +
-+      if (!need_cut_or_align(inode, clust, rw, &oh))
++      if (!need_cut_or_align(inode, ch, rw, &oh))
 +              return;
 +      switch (rw) {
 +      case WRITE_OP: /* do align */
-+              clust->tc.len +=
-+                      cplug->align_stream(tfm_input_data(clust) +
-+                                          clust->tc.len, clust->tc.len,
++              ch->tc.len +=
++                      cplug->align_stream(tfm_input_data(ch) +
++                                          ch->tc.len, ch->tc.len,
 +                                          cipher_blocksize(inode));
-+              *(tfm_input_data(clust) + clust->tc.len - 1) =
++              *(tfm_input_data(ch) + ch->tc.len - 1) =
 +                      cipher_blocksize(inode) - oh;
 +              break;
 +      case READ_OP: /* do cut */
 +              assert("edward-1403", oh <= cipher_blocksize(inode));
-+              clust->tc.len -= oh;
++              ch->tc.len -= oh;
 +              break;
 +      default:
 +              impossible("edward-1404", "bad option");
@@ -32200,10 +31635,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/file/cryptcompress.c
 +      return;
 +}
 +
-+/* the following two functions are to evaluate results
-+   of compression transform */
-+static unsigned
-+max_cipher_overhead(struct inode * inode)
++static unsigned max_cipher_overhead(struct inode * inode)
 +{
 +      if (!need_cipher(inode) || !inode_cipher_plugin(inode)->align_stream)
 +              return 0;
@@ -32226,7 +31658,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/file/cryptcompress.c
 +   If this returns false, then compressor won't be called for
 +   the cluster of index @index.
 +*/
-+static int should_compress(tfm_cluster_t * tc, cloff_t index,
++static int should_compress(struct tfm_cluster * tc, cloff_t index,
 +                         struct inode *inode)
 +{
 +      compression_plugin *cplug = inode_compression_plugin(inode);
@@ -32248,19 +31680,17 @@ Index: linux-2.6.16/fs/reiser4/plugin/file/cryptcompress.c
 +
 +/* Evaluating results of compression transform.
 +   Returns true, if we need to accept this results */
-+static int
-+save_compressed(int size_before, int size_after, struct inode * inode)
++static int save_compressed(int size_before, int size_after, struct inode *inode)
 +{
 +      return (size_after + deflate_overhead(inode) +
 +              max_cipher_overhead(inode) < size_before);
 +}
 +
 +/* Guess result of the evaluation above */
-+static int
-+need_inflate(reiser4_cluster_t * clust, struct inode *inode,
-+           int encrypted /* is cluster encrypted */ )
++static int need_inflate(struct cluster_handle * ch, struct inode * inode,
++                      int encrypted /* is cluster encrypted */ )
 +{
-+      tfm_cluster_t *tc = &clust->tc;
++      struct tfm_cluster * tc = &ch->tc;
 +
 +      assert("edward-142", tc != 0);
 +      assert("edward-143", inode != NULL);
@@ -32289,7 +31719,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/file/cryptcompress.c
 +                                         1 <= overhead <= cipher_blksize
 +*/
 +/* Append a checksum at the end of a transformed stream */
-+static void dc_set_checksum(compression_plugin * cplug, tfm_cluster_t * tc)
++static void dc_set_checksum(compression_plugin * cplug, struct tfm_cluster * tc)
 +{
 +      __u32 checksum;
 +
@@ -32305,7 +31735,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/file/cryptcompress.c
 +
 +/* Check a disk cluster checksum.
 +   Returns 0 if checksum is correct, otherwise returns 1 */
-+static int dc_check_checksum(compression_plugin * cplug, tfm_cluster_t * tc)
++static int dc_check_checksum(compression_plugin * cplug, struct tfm_cluster * tc)
 +{
 +      assert("edward-1312", tc != NULL);
 +      assert("edward-1313", tc->len > (int)DC_CHECKSUM_SIZE);
@@ -32332,7 +31762,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/file/cryptcompress.c
 +}
 +
 +/* get input/output stream for some transform action */
-+int grab_tfm_stream(struct inode * inode, tfm_cluster_t * tc,
++int grab_tfm_stream(struct inode * inode, struct tfm_cluster * tc,
 +                  tfm_stream_id id)
 +{
 +      size_t size = inode_scaled_cluster_size(inode);
@@ -32340,12 +31770,12 @@ Index: linux-2.6.16/fs/reiser4/plugin/file/cryptcompress.c
 +      assert("edward-901", tc != NULL);
 +      assert("edward-1027", inode_compression_plugin(inode) != NULL);
 +
-+      if (tc->act == TFM_WRITE_ACT)
++      if (cluster_get_tfm_act(tc) == TFMA_WRITE)
 +              size += deflate_overrun(inode, inode_cluster_size(inode));
 +
-+      if (!tfm_stream(tc, id) && id == INPUT_STREAM)
++      if (!get_tfm_stream(tc, id) && id == INPUT_STREAM)
 +              alternate_streams(tc);
-+      if (!tfm_stream(tc, id))
++      if (!get_tfm_stream(tc, id))
 +              return alloc_tfm_stream(tc, size, id);
 +
 +      assert("edward-902", tfm_stream_is_set(tc, id));
@@ -32356,17 +31786,17 @@ Index: linux-2.6.16/fs/reiser4/plugin/file/cryptcompress.c
 +}
 +
 +/* Common deflate manager */
-+int deflate_cluster(reiser4_cluster_t * clust, struct inode * inode)
++int reiser4_deflate_cluster(struct cluster_handle * clust, struct inode * inode)
 +{
 +      int result = 0;
 +      int compressed = 0;
 +      int encrypted = 0;
-+      tfm_cluster_t * tc = &clust->tc;
++      struct tfm_cluster * tc = &clust->tc;
 +      compression_plugin * coplug;
 +
 +      assert("edward-401", inode != NULL);
 +      assert("edward-903", tfm_stream_is_set(tc, INPUT_STREAM));
-+      assert("edward-1348", tc->act == TFM_WRITE_ACT);
++      assert("edward-1348", cluster_get_tfm_act(tc) == TFMA_WRITE);
 +      assert("edward-498", !tfm_cluster_is_uptodate(tc));
 +
 +      coplug = inode_compression_plugin(inode);
@@ -32415,9 +31845,9 @@ Index: linux-2.6.16/fs/reiser4/plugin/file/cryptcompress.c
 +              }
 +              else {
 +                      /* bad result, discard */
-+#if REISER4_DEBUG
++#if 0
 +                      if (cluster_is_complete(clust, inode))
-+                            warning("edward-1338",
++                            warning("edward-1496",
 +                                    "incompressible cluster %lu (inode %llu)",
 +                                    clust->index,
 +                                    (unsigned long long)get_inode_oid(inode));
@@ -32436,12 +31866,13 @@ Index: linux-2.6.16/fs/reiser4/plugin/file/cryptcompress.c
 + cipher:
 +      if (need_cipher(inode)) {
 +              cipher_plugin * ciplug;
-+              struct crypto_tfm * tfm;
++              struct blkcipher_desc desc;
 +              struct scatterlist src;
 +              struct scatterlist dst;
 +
 +              ciplug = inode_cipher_plugin(inode);
-+              tfm = info_cipher_tfm(inode_crypto_stat(inode));
++              desc.tfm = info_get_cipher(inode_crypto_info(inode));
++              desc.flags = 0;
 +              if (compressed)
 +                      alternate_streams(tc);
 +              result = grab_tfm_stream(inode, tc, OUTPUT_STREAM);
@@ -32457,10 +31888,10 @@ Index: linux-2.6.16/fs/reiser4/plugin/file/cryptcompress.c
 +              dst.offset = offset_in_page(tfm_output_data(clust));
 +              dst.length = tc->len;
 +
-+              result = crypto_cipher_encrypt(tfm, &dst, &src, tc->len);
++              result = crypto_blkcipher_encrypt(&desc, &dst, &src, tc->len);
 +              if (result) {
 +                      warning("edward-1405",
-+                              "encryption failed flags=%x\n", tfm->crt_flags);
++                              "encryption failed flags=%x\n", desc.flags);
 +                      return result;
 +              }
 +              encrypted = 1;
@@ -32473,17 +31904,17 @@ Index: linux-2.6.16/fs/reiser4/plugin/file/cryptcompress.c
 +}
 +
 +/* Common inflate manager. */
-+int inflate_cluster(reiser4_cluster_t * clust, struct inode * inode)
++int reiser4_inflate_cluster(struct cluster_handle * clust, struct inode * inode)
 +{
 +      int result = 0;
 +      int transformed = 0;
-+      tfm_cluster_t * tc = &clust->tc;
++      struct tfm_cluster * tc = &clust->tc;
 +      compression_plugin * coplug;
 +
 +      assert("edward-905", inode != NULL);
 +      assert("edward-1178", clust->dstat == PREP_DISK_CLUSTER);
 +      assert("edward-906", tfm_stream_is_set(&clust->tc, INPUT_STREAM));
-+      assert("edward-1349", tc->act == TFM_READ_ACT);
++      assert("edward-1349", tc->act == TFMA_READ);
 +      assert("edward-907", !tfm_cluster_is_uptodate(tc));
 +
 +      /* Handle a checksum (if any) */
@@ -32491,17 +31922,23 @@ Index: linux-2.6.16/fs/reiser4/plugin/file/cryptcompress.c
 +      if (need_inflate(clust, inode, need_cipher(inode)) &&
 +          coplug->checksum != NULL) {
 +              result = dc_check_checksum(coplug, tc);
-+              if (result)
++              if (unlikely(result)) {
++                      warning("edward-1460",
++                              "Inode %llu: disk cluster %lu looks corrupted",
++                              (unsigned long long)get_inode_oid(inode),
++                              clust->index);
 +                      return RETERR(-EIO);
++              }
 +      }
 +      if (need_cipher(inode)) {
 +              cipher_plugin * ciplug;
-+              struct crypto_tfm * tfm;
++              struct blkcipher_desc desc;
 +              struct scatterlist src;
 +              struct scatterlist dst;
 +
 +              ciplug = inode_cipher_plugin(inode);
-+              tfm = info_cipher_tfm(inode_crypto_stat(inode));
++              desc.tfm = info_get_cipher(inode_crypto_info(inode));
++              desc.flags = 0;
 +              result = grab_tfm_stream(inode, tc, OUTPUT_STREAM);
 +              if (result)
 +                      return result;
@@ -32515,9 +31952,12 @@ Index: linux-2.6.16/fs/reiser4/plugin/file/cryptcompress.c
 +              dst.offset = offset_in_page(tfm_output_data(clust));
 +              dst.length = tc->len;
 +
-+              result = crypto_cipher_decrypt(tfm, &dst, &src, tc->len);
-+              if (result)
++              result = crypto_blkcipher_decrypt(&desc, &dst, &src, tc->len);
++              if (result) {
++                      warning("edward-1600", "decrypt failed flags=%x\n",
++                              desc.flags);
 +                      return result;
++              }
 +              align_or_cut_overhead(inode, clust, READ_OP);
 +              transformed = 1;
 +      }
@@ -32550,7 +31990,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/file/cryptcompress.c
 +int readpage_cryptcompress(struct file *file, struct page *page)
 +{
 +      reiser4_context *ctx;
-+      reiser4_cluster_t clust;
++      struct cluster_handle clust;
 +      item_plugin *iplug;
 +      int result;
 +
@@ -32558,14 +31998,10 @@ Index: linux-2.6.16/fs/reiser4/plugin/file/cryptcompress.c
 +      assert("vs-976", !PageUptodate(page));
 +      assert("edward-89", page->mapping && page->mapping->host);
 +
-+      ctx = init_context(page->mapping->host->i_sb);
-+      if (IS_ERR(ctx))
-+              return PTR_ERR(ctx);
-+      result = check_cryptcompress(page->mapping->host);
-+      if (result) {
++      ctx = reiser4_init_context(page->mapping->host->i_sb);
++      if (IS_ERR(ctx)) {
 +              unlock_page(page);
-+              reiser4_exit_context(ctx);
-+              return result;
++              return PTR_ERR(ctx);
 +      }
 +      assert("edward-113",
 +             ergo(file != NULL,
@@ -32573,6 +32009,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/file/cryptcompress.c
 +
 +      if (PageUptodate(page)) {
 +              warning("edward-1338", "page is already uptodate\n");
++              unlock_page(page);
 +              reiser4_exit_context(ctx);
 +              return 0;
 +      }
@@ -32586,35 +32023,34 @@ Index: linux-2.6.16/fs/reiser4/plugin/file/cryptcompress.c
 +              return -EINVAL;
 +      }
 +      result = iplug->s.file.readpage(&clust, page);
-+      if (result)
-+              unlock_page(page);
-+      assert("edward-64",
-+             ergo(result == 0, (PageLocked(page) || PageUptodate(page))));
++
 +      put_cluster_handle(&clust);
++      reiser4_txn_restart(ctx);
 +      reiser4_exit_context(ctx);
 +      return result;
 +}
 +
-+/* how much pages will be captured */
-+static int cluster_nrpages_to_capture(reiser4_cluster_t * clust)
++/* number of pages to check in */
++static int get_new_nrpages(struct cluster_handle * clust)
 +{
 +      switch (clust->op) {
-+      case PCL_APPEND:
++      case LC_APPOV:
 +              return clust->nr_pages;
-+      case PCL_TRUNCATE:
++      case LC_TRUNC:
 +              assert("edward-1179", clust->win != NULL);
-+              return count_to_nrpages(clust->win->off + clust->win->count);
++              return size_in_pages(clust->win->off + clust->win->count);
 +      default:
 +              impossible("edward-1180", "bad page cluster option");
 +              return 0;
 +      }
 +}
 +
-+static void set_cluster_pages_dirty(reiser4_cluster_t * clust)
++static void set_cluster_pages_dirty(struct cluster_handle * clust,
++                                  struct inode * inode)
 +{
 +      int i;
 +      struct page *pg;
-+      int nrpages = cluster_nrpages_to_capture(clust);
++      int nrpages = get_new_nrpages(clust);
 +
 +      for (i = 0; i < nrpages; i++) {
 +
@@ -32622,179 +32058,23 @@ Index: linux-2.6.16/fs/reiser4/plugin/file/cryptcompress.c
 +              assert("edward-968", pg != NULL);
 +              lock_page(pg);
 +              assert("edward-1065", PageUptodate(pg));
-+              set_page_dirty_internal(pg);
++              reiser4_set_page_dirty_internal(pg);
 +              unlock_page(pg);
 +              mark_page_accessed(pg);
 +      }
 +}
 +
-+static void clear_cluster_pages_dirty(reiser4_cluster_t * clust)
-+{
-+      int i;
-+      assert("edward-1275", clust != NULL);
-+
-+      for (i = 0; i < clust->nr_pages; i++) {
-+              assert("edward-1276", clust->pages[i] != NULL);
-+
-+              lock_page(clust->pages[i]);
-+              if (PageDirty(clust->pages[i])) {
-+                      assert("edward-1277", PageUptodate(clust->pages[i]));
-+                      clear_page_dirty_for_io(clust->pages[i]);
-+              }
-+#if REISER4_DEBUG
-+              else
-+                      /* Race between flush and write:
-+                         some pages became clean when write() (or another
-+                         process which modifies data) capture the cluster. */
-+                      warning("edward-985", "Page of index %lu (inode %llu)"
-+                              " is not dirty\n", clust->pages[i]->index,
-+                              (unsigned long long)get_inode_oid(clust->
-+                                                                pages[i]->
-+                                                                mapping->
-+                                                                host));
-+#endif
-+              unlock_page(clust->pages[i]);
-+      }
-+}
-+
-+/* update i_size by window */
-+static void inode_set_new_size(reiser4_cluster_t * clust, struct inode *inode)
-+{
-+      loff_t size;
-+      reiser4_slide_t *win;
-+
-+      assert("edward-1181", clust != NULL);
-+      assert("edward-1182", inode != NULL);
-+
-+      win = clust->win;
-+      assert("edward-1183", win != NULL);
-+
-+      size = clust_to_off(clust->index, inode) + win->off;
-+
-+      switch (clust->op) {
-+      case PCL_APPEND:
-+              if (size + win->count <= inode->i_size)
-+                      /* overwrite only */
-+                      return;
-+              size += win->count;
-+              break;
-+      case PCL_TRUNCATE:
-+              break;
-+      default:
-+              impossible("edward-1184", "bad page cluster option");
-+              break;
-+      }
-+      inode_check_scale_nolock(inode, inode->i_size, size);
-+      inode->i_size = size;
-+      return;
-+}
-+
-+/* Check in page cluster modifications.
-+   . Make jnode dirty, if it wasn't;
-+   . Reserve space for a disk cluster update by flush algorithm, if needed;
-+   . Clean up old references (if any).
-+   . Put pages (grabbed in this thread) which will be truncated
-+*/
-+static void
-+make_cluster_jnode_dirty_locked(reiser4_cluster_t * clust, jnode * node,
-+                              loff_t * old_isize, struct inode *inode)
-+{
-+      int i;
-+      int old_nrpages;
-+      int new_nrpages = cluster_nrpages_to_capture(clust);
-+
-+      assert("edward-973", new_nrpages > 0);
-+      assert("edward-221", node != NULL);
-+      assert("edward-971", clust->reserved == 1);
-+      assert_spin_locked(&(node->guard));
-+      assert("edward-972", node->page_count < cluster_nrpages(inode));
-+      assert("edward-1263",
-+             clust->reserved_prepped == estimate_update_cluster(inode));
-+      assert("edward-1264", clust->reserved_unprepped == 0);
++/* Grab a page cluster for read/write operations.
++   Attach a jnode for write operations (when preparing for modifications, which
++   are supposed to be committed).
 +
-+      if (JF_ISSET(node, JNODE_DIRTY)) {
-+              /* someone has modified this cluster, but
-+                 the modifications are not committed yet */
-+              old_nrpages =
-+                      count_to_nrpages(cnt_to_clcnt(*old_isize,
-+                                                    clust->index, inode));
-+              /* free space which is already reserved */
-+              free_reserved4cluster(inode, clust,
-+                                    estimate_update_cluster(inode));
-+              /* put old references */
-+              for (i = 0; i < old_nrpages; i++) {
-+                      assert("edward-975", clust->pages[i]);
-+                      assert("edward-1185", PageUptodate(clust->pages[i]));
-+
-+                      page_cache_release(clust->pages[i]);
-+#if REISER4_DEBUG
-+                      cryptcompress_inode_data(inode)->pgcount --;
-+#endif
-+              }
-+      } else {
-+              /* no captured pages */
-+              assert("edward-1043", node->page_count == 0);
-+              jnode_make_dirty_locked(node);
-+              clust->reserved = 0;
-+      }
-+      /* put pages that will be truncated (if any) */
-+      for (i = new_nrpages; i < clust->nr_pages; i++) {
-+              assert("edward-1433", clust->pages[i]);
-+              assert("edward-1434", PageUptodate(clust->pages[i]));
-+              page_cache_release(clust->pages[i]);
-+#if REISER4_DEBUG
-+              cryptcompress_inode_data(inode)->pgcount --;
-+#endif
-+      }
-+#if REISER4_DEBUG
-+      clust->reserved_prepped -= estimate_update_cluster(inode);
-+      node->page_count = new_nrpages - 1;
-+#endif
-+      return;
-+}
-+
-+/* This function spawns a transaction and
-+   is called by any thread as a final step in page cluster modification.
-+*/
-+static int try_capture_cluster(reiser4_cluster_t * clust, struct inode *inode)
-+{
-+      int result = 0;
-+      loff_t old_size;
-+      jnode *node;
-+
-+      assert("edward-1029", clust != NULL);
-+      assert("edward-1030", clust->reserved == 1);
-+      assert("edward-1031", clust->nr_pages != 0);
-+      assert("edward-1032", clust->pages != NULL);
-+      assert("edward-1033", clust->pages[0] != NULL);
-+
-+      node = jprivate(clust->pages[0]);
-+
-+      assert("edward-1035", node != NULL);
-+
-+      spin_lock_jnode(node);
-+      old_size = inode->i_size;
-+      if (clust->win)
-+              inode_set_new_size(clust, inode);
-+
-+      result = try_capture(node, ZNODE_WRITE_LOCK, 0);
-+      if (result)
-+              goto exit;
-+      make_cluster_jnode_dirty_locked(clust, node, &old_size, inode);
-+      exit:
-+      assert("edward-1034", !result);
-+      spin_unlock_jnode(node);
-+      jput(node);
-+      return result;
-+}
-+
-+/* Collect unlocked cluster pages for any modifications and attach a jnode.
-+   We allocate only one jnode per cluster, this jnode is binded to the first
-+   page of this cluster, so we have an extra-reference that will exist with
-+   this jnode, other references will be cleaned up in flush time.
++   We allocate only one jnode per page cluster; this jnode is binded to the
++   first page of this cluster, so we have an extra-reference that will be put
++   as soon as jnode is evicted from memory), other references will be cleaned
++   up in flush time (assume that check in page cluster was successful).
 +*/
-+static int
-+grab_cluster_pages_jnode(struct inode *inode, reiser4_cluster_t * clust)
++int grab_page_cluster(struct inode * inode,
++                    struct cluster_handle * clust, rw_op rw)
 +{
 +      int i;
 +      int result = 0;
@@ -32802,6 +32082,9 @@ Index: linux-2.6.16/fs/reiser4/plugin/file/cryptcompress.c
 +
 +      assert("edward-182", clust != NULL);
 +      assert("edward-183", clust->pages != NULL);
++      assert("edward-1466", clust->node == NULL);
++      assert("edward-1428", inode != NULL);
++      assert("edward-1429", inode->i_mapping != NULL);
 +      assert("edward-184", clust->nr_pages <= cluster_nrpages(inode));
 +
 +      if (clust->nr_pages == 0)
@@ -32812,13 +32095,14 @@ Index: linux-2.6.16/fs/reiser4/plugin/file/cryptcompress.c
 +              assert("edward-1044", clust->pages[i] == NULL);
 +
 +              clust->pages[i] =
-+                  grab_cache_page(inode->i_mapping,
-+                                  clust_to_pg(clust->index, inode) + i);
++                     find_or_create_page(inode->i_mapping,
++                                         clust_to_pg(clust->index, inode) + i,
++                                         reiser4_ctx_gfp_mask_get());
 +              if (!clust->pages[i]) {
 +                      result = RETERR(-ENOMEM);
 +                      break;
 +              }
-+              if (i == 0) {
++              if (i == 0 && rw == WRITE_OP) {
 +                      node = jnode_of_page(clust->pages[i]);
 +                      if (IS_ERR(node)) {
 +                              result = PTR_ERR(node);
@@ -32826,117 +32110,90 @@ Index: linux-2.6.16/fs/reiser4/plugin/file/cryptcompress.c
 +                              break;
 +                      }
 +                      JF_SET(node, JNODE_CLUSTER_PAGE);
-+                      unlock_page(clust->pages[i]);
-+                      assert("edward-919", node);
-+                      continue;
++                      assert("edward-920", jprivate(clust->pages[0]));
 +              }
++              INODE_PGCOUNT_INC(inode);
 +              unlock_page(clust->pages[i]);
 +      }
-+      if (result) {
-+              while (i)
-+                      page_cache_release(clust->pages[--i]);
++      if (unlikely(result)) {
++              while (i) {
++                      put_cluster_page(clust->pages[--i]);
++                      INODE_PGCOUNT_DEC(inode);
++              }
 +              if (node && !IS_ERR(node))
 +                      jput(node);
 +              return result;
 +      }
-+      assert("edward-920", jprivate(clust->pages[0]));
-+#if REISER4_DEBUG
-+      cryptcompress_inode_data(inode)->pgcount += clust->nr_pages;
-+#endif
++      clust->node = node;
 +      return 0;
 +}
 +
-+/* Collect unlocked cluster pages only for read (not to modify) */
-+static int grab_cluster_pages(struct inode *inode, reiser4_cluster_t * clust)
++static void truncate_page_cluster_range(struct inode * inode,
++                                      struct page ** pages,
++                                      cloff_t index,
++                                      int from, int count,
++                                      int even_cows)
 +{
-+      int i;
-+      int result = 0;
-+
-+      assert("edward-1428", inode != NULL);
-+      assert("edward-1429", inode->i_mapping != NULL);        
-+      assert("edward-787", clust != NULL);
-+      assert("edward-788", clust->pages != NULL);
-+      assert("edward-789", clust->nr_pages != 0);
-+      assert("edward-790", clust->nr_pages <= cluster_nrpages(inode));
-+
-+      for (i = 0; i < clust->nr_pages; i++) {
-+              clust->pages[i] =
-+                  grab_cache_page(inode->i_mapping,
-+                                  clust_to_pg(clust->index, inode) + i);
-+              if (!clust->pages[i]) {
-+                      result = RETERR(-ENOMEM);
-+                      break;
-+              }
-+              unlock_page(clust->pages[i]);
-+      }
-+      if (result)
-+              while (i)
-+                      page_cache_release(clust->pages[--i]);
-+      return result;
++      assert("edward-1467", count > 0);
++      reiser4_invalidate_pages(inode->i_mapping,
++                               clust_to_pg(index, inode) + from,
++                               count, even_cows);
 +}
 +
-+/* @node might be attached by reiser4_writepage(), not by
-+   cryptcompress plugin code, but emergency flush should
-+   understand that pages of cryptcompress files are not
-+   flushable.
-+*/
-+int jnode_of_cluster(const jnode * node, struct page * page)
-+{
-+      assert("edward-1339", node != NULL);
-+      assert("edward-1340", page != NULL);
-+      assert("edward-1341", page->mapping != NULL);
-+      assert("edward-1342", page->mapping->host != NULL);
-+      assert("edward-1343",
-+             ergo(jnode_is_unformatted(node),
-+                  get_inode_oid(page->mapping->host) ==
-+                  node->key.j.objectid));
-+      if (inode_file_plugin(page->mapping->host) ==
-+          file_plugin_by_id(CRC_FILE_PLUGIN_ID)) {
-+#if REISER4_DEBUG
-+              if (!jnode_is_cluster_page(node))
-+                      warning("edward-1345",
-+                      "inode %llu: cluster page of index %lu became private",
-+                      (unsigned long long)get_inode_oid(page->mapping->host),
-+                      page->index);
-+#endif
-+              return 1;
-+      }
-+      return 0;
-+}
-+
-+/* put cluster pages */
-+void release_cluster_pages(reiser4_cluster_t * clust)
++/* Put @count pages starting from @from offset */
++void __put_page_cluster(int from, int count,
++                      struct page ** pages, struct inode  * inode)
 +{
 +      int i;
++      assert("edward-1468", pages != NULL);
++      assert("edward-1469", inode != NULL);
++      assert("edward-1470", from >= 0 && count >= 0);
 +
-+      assert("edward-447", clust != NULL);    
-+      for (i = 0; i < clust->nr_pages; i++) {
-+
-+              assert("edward-449", clust->pages[i] != NULL);
++      for (i = 0; i < count; i++) {
++              assert("edward-1471", pages[from + i] != NULL);
++              assert("edward-1472",
++                     pages[from + i]->index == pages[from]->index + i);
 +
-+              page_cache_release(clust->pages[i]);
++              put_cluster_page(pages[from + i]);
++              INODE_PGCOUNT_DEC(inode);
 +      }
 +}
 +
-+/* this is called when something is failed */
-+static void release_cluster_pages_and_jnode(reiser4_cluster_t * clust)
++/*
++ * This is dual to grab_page_cluster,
++ * however if @rw == WRITE_OP, then we call this function
++ * only if something is failed before checkin page cluster.
++ */
++void put_page_cluster(struct cluster_handle * clust,
++                    struct inode * inode, rw_op rw)
 +{
-+      jnode *node;
-+
 +      assert("edward-445", clust != NULL);
 +      assert("edward-922", clust->pages != NULL);
-+      assert("edward-446", clust->pages[0] != NULL);
-+
-+      node = jprivate(clust->pages[0]);
-+
-+      assert("edward-447", node != NULL);
++      assert("edward-446",
++             ergo(clust->nr_pages != 0, clust->pages[0] != NULL));
 +
-+      release_cluster_pages(clust);
-+      jput(node);
++      __put_page_cluster(0, clust->nr_pages, clust->pages, inode);
++      if (rw == WRITE_OP) {
++              if (unlikely(clust->node)) {
++                      assert("edward-447",
++                             clust->node == jprivate(clust->pages[0]));
++                      jput(clust->node);
++                      clust->node = NULL;
++              }
++      }
 +}
 +
 +#if REISER4_DEBUG
-+static int window_ok(reiser4_slide_t * win, struct inode *inode)
++int cryptcompress_inode_ok(struct inode *inode)
++{
++      if (!(reiser4_inode_data(inode)->plugin_mask & (1 << PSET_FILE)))
++              return 0;
++      if (!cluster_shift_ok(inode_cluster_shift(inode)))
++              return 0;
++      return 1;
++}
++
++static int window_ok(struct reiser4_slide * win, struct inode *inode)
 +{
 +      assert("edward-1115", win != NULL);
 +      assert("edward-1116", ergo(win->delta, win->stat == HOLE_WINDOW));
@@ -32945,7 +32202,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/file/cryptcompress.c
 +          (win->off + win->count + win->delta <= inode_cluster_size(inode));
 +}
 +
-+static int cluster_ok(reiser4_cluster_t * clust, struct inode *inode)
++static int cluster_ok(struct cluster_handle * clust, struct inode *inode)
 +{
 +      assert("edward-279", clust != NULL);
 +
@@ -32953,22 +32210,58 @@ Index: linux-2.6.16/fs/reiser4/plugin/file/cryptcompress.c
 +              return 0;
 +      return (clust->win ? window_ok(clust->win, inode) : 1);
 +}
++#if 0
++static int pages_truncate_ok(struct inode *inode, pgoff_t start)
++{
++      int found;
++      struct page * page;
++
++      found = find_get_pages(inode->i_mapping, start, 1, &page);
++      if (found)
++              put_cluster_page(page);
++      return !found;
++}
++#else
++#define pages_truncate_ok(inode, start) 1
++#endif
++
++static int jnode_truncate_ok(struct inode *inode, cloff_t index)
++{
++      jnode *node;
++      node = jlookup(current_tree, get_inode_oid(inode),
++                     clust_to_pg(index, inode));
++      if (likely(!node))
++              return 1;
++      jput(node);
++      return 0;
++}
++
++static int find_fake_appended(struct inode *inode, cloff_t * index);
++
++static int body_truncate_ok(struct inode *inode, cloff_t aidx)
++{
++      int result;
++      cloff_t raidx;
++
++      result = find_fake_appended(inode, &raidx);
++      return !result && (aidx == raidx);
++}
 +#endif
 +
 +/* guess next window stat */
-+static inline window_stat next_window_stat(reiser4_slide_t * win)
++static inline window_stat next_window_stat(struct reiser4_slide * win)
 +{
 +      assert("edward-1130", win != NULL);
 +      return ((win->stat == HOLE_WINDOW && win->delta == 0) ?
 +              HOLE_WINDOW : DATA_WINDOW);
 +}
 +
-+/* guess next cluster index and window params */
-+static void
-+update_cluster(struct inode *inode, reiser4_cluster_t * clust, loff_t file_off,
-+             loff_t to_file)
++/* guess and set next cluster index and window params */
++static void move_update_window(struct inode * inode,
++                             struct cluster_handle * clust,
++                             loff_t file_off, loff_t to_file)
 +{
-+      reiser4_slide_t *win;
++      struct reiser4_slide * win;
 +
 +      assert("edward-185", clust != NULL);
 +      assert("edward-438", clust->pages != NULL);
@@ -32980,28 +32273,27 @@ Index: linux-2.6.16/fs/reiser4/plugin/file/cryptcompress.c
 +
 +      switch (win->stat) {
 +      case DATA_WINDOW:
-+              /* increment window position */
++              /* increment */
 +              clust->index++;
 +              win->stat = DATA_WINDOW;
 +              win->off = 0;
-+              win->count = min_count(inode_cluster_size(inode), to_file);
++              win->count = min((loff_t)inode_cluster_size(inode), to_file);
 +              break;
 +      case HOLE_WINDOW:
 +              switch (next_window_stat(win)) {
 +              case HOLE_WINDOW:
-+                      /* set window to fit the offset we start write from */
++                      /* skip */
 +                      clust->index = off_to_clust(file_off, inode);
 +                      win->stat = HOLE_WINDOW;
 +                      win->off = 0;
 +                      win->count = off_to_cloff(file_off, inode);
-+                      win->delta =
-+                          min_count(inode_cluster_size(inode) - win->count,
-+                                    to_file);
++                      win->delta = min((loff_t)(inode_cluster_size(inode) -
++                                                win->count), to_file);
 +                      break;
 +              case DATA_WINDOW:
-+                      /* do not move the window, just change its state,
-+                         off+count+delta=inv */
++                      /* stay */
 +                      win->stat = DATA_WINDOW;
++                      /* off+count+delta=inv */
 +                      win->off = win->off + win->count;
 +                      win->count = win->delta;
 +                      win->delta = 0;
@@ -33020,127 +32312,402 @@ Index: linux-2.6.16/fs/reiser4/plugin/file/cryptcompress.c
 +{
 +      int result = 0;
 +
-+      assert("edward-978", schedulable());
-+      assert("edward-1265", get_current_context()->grabbed_blocks == 0);
++      assert("edward-978", reiser4_schedulable());
 +
-+      result = reiser4_grab_space_force(      /* one for stat data update */
-+                                               estimate_update_common(inode),
-+                                               BA_CAN_COMMIT);
-+      assert("edward-979", !result);
++      result = reiser4_grab_space_force(/* one for stat data update */
++                                        estimate_update_common(inode),
++                                        BA_CAN_COMMIT);
 +      if (result)
 +              return result;
 +      inode->i_ctime = inode->i_mtime = CURRENT_TIME;
 +      result = reiser4_update_sd(inode);
 +
-+      all_grabbed2free();
 +      return result;
 +}
 +
-+
-+/* NOTE-Edward: this is too similar to reiser4/txnmgr.c:uncapture_jnode() */
 +static void uncapture_cluster_jnode(jnode * node)
 +{
 +      txn_atom *atom;
 +
 +      assert_spin_locked(&(node->guard));
 +
-+      /*jnode_make_clean(node); */
 +      atom = jnode_get_atom(node);
 +      if (atom == NULL) {
 +              assert("jmacd-7111", !JF_ISSET(node, JNODE_DIRTY));
 +              spin_unlock_jnode(node);
 +              return;
 +      }
-+
-+      uncapture_block(node);
++      reiser4_uncapture_block(node);
 +      spin_unlock_atom(atom);
 +      jput(node);
 +}
 +
-+void forget_cluster_pages(struct page **pages, int nr)
++static void put_found_pages(struct page **pages, int nr)
 +{
 +      int i;
 +      for (i = 0; i < nr; i++) {
-+
 +              assert("edward-1045", pages[i] != NULL);
-+              page_cache_release(pages[i]);
-+      }
++              put_cluster_page(pages[i]);
++      }
++}
++
++/*             Lifecycle of a logical cluster in the system.
++ *
++ *
++ * Logical cluster of a cryptcompress file is represented in the system by
++ * . page cluster (in memory, primary cache, contains plain text);
++ * . disk cluster (in memory, secondary cache, contains transformed text).
++ * Primary cache is to reduce number of transform operations (compression,
++ * encryption), i.e. to implement transform-caching strategy.
++ * Secondary cache is to reduce number of I/O operations, i.e. for usual
++ * write-caching strategy. Page cluster is a set of pages, i.e. mapping of
++ * a logical cluster to the primary cache. Disk cluster is a set of items
++ * of the same type defined by some reiser4 item plugin id.
++ *
++ *              1. Performing modifications
++ *
++ * Every modification of a cryptcompress file is considered as a set of
++ * operations performed on file's logical clusters. Every such "atomic"
++ * modification is truncate, append and(or) overwrite some bytes of a
++ * logical cluster performed in the primary cache with the following
++ * synchronization with the secondary cache (in flush time). Disk clusters,
++ * which live in the secondary cache, are supposed to be synchronized with
++ * disk. The mechanism of synchronization of primary and secondary caches
++ * includes so-called checkin/checkout technique described below.
++ *
++ *              2. Submitting modifications
++ *
++ * Each page cluster has associated jnode (a special in-memory header to
++ * keep a track of transactions in reiser4), which is attached to its first
++ * page when grabbing page cluster for modifications (see grab_page_cluster).
++ * Submitting modifications (see checkin_logical_cluster) is going per logical
++ * cluster and includes:
++ * . checkin_cluster_size;
++ * . checkin_page_cluster.
++ * checkin_cluster_size() is resolved to file size update (which completely
++ * defines new size of logical cluster (number of file's bytes in a logical
++ * cluster).
++ * checkin_page_cluster() captures jnode of a page cluster and installs
++ * jnode's dirty flag (if needed) to indicate that modifications are
++ * successfully checked in.
++ *
++ *              3. Checking out modifications
++ *
++ * Is going per logical cluster in flush time (see checkout_logical_cluster).
++ * This is the time of synchronizing primary and secondary caches.
++ * checkout_logical_cluster() includes:
++ * . checkout_page_cluster (retrieving checked in pages).
++ * . uncapture jnode (including clear dirty flag and unlock)
++ *
++ *              4. Committing modifications
++ *
++ * Proceeding a synchronization of primary and secondary caches. When checking
++ * out page cluster (the phase above) pages are locked/flushed/unlocked
++ * one-by-one in ascending order of their indexes to contiguous stream, which
++ * is supposed to be transformed (compressed, encrypted), chopped up into items
++ * and committed to disk as a disk cluster.
++ *
++ *              5. Managing page references
++ *
++ * Every checked in page have a special additional "control" reference,
++ * which is dropped at checkout. We need this to avoid unexpected evicting
++ * pages from memory before checkout. Control references are managed so
++ * they are not accumulated with every checkin:
++ *
++ *            0
++ * checkin -> 1
++ *            0 -> checkout
++ * checkin -> 1
++ * checkin -> 1
++ * checkin -> 1
++ *            0 -> checkout
++ *           ...
++ *
++ * Every page cluster has its own unique "cluster lock". Update/drop
++ * references are serialized via this lock. Number of checked in cluster
++ * pages is calculated by i_size under cluster lock. File size is updated
++ * at every checkin action also under cluster lock (except cases of
++ * appending/truncating fake logical clusters).
++ *
++ * Proof of correctness:
++ *
++ * Since we update file size under cluster lock, in the case of non-fake
++ * logical cluster with its lock held we do have expected number of checked
++ * in pages. On the other hand, append/truncate of fake logical clusters
++ * doesn't change number of checked in pages of any cluster.
++ *
++ * NOTE-EDWARD: As cluster lock we use guard (spinlock_t) of its jnode.
++ * Currently, I don't see any reason to create a special lock for those
++ * needs.
++ */
++
++static inline void lock_cluster(jnode * node)
++{
++      spin_lock_jnode(node);
 +}
 +
-+/* Check out last modifications we are about to commit,
-+   and prepare input stream for transform operations.
-+*/
-+int
-+flush_cluster_pages(reiser4_cluster_t * clust, jnode * node,
-+                  struct inode *inode)
++static inline void unlock_cluster(jnode * node)
 +{
-+      int result = 0;
-+      int i;
-+      int nr_pages = 0;
-+      tfm_cluster_t *tc = &clust->tc;
++      spin_unlock_jnode(node);
++}
 +
-+      assert("edward-980", node != NULL);
-+      assert("edward-236", inode != NULL);
-+      assert("edward-237", clust != NULL);
-+      assert("edward-240", !clust->win);
-+      assert("edward-241", schedulable());
-+      assert("edward-718", crc_inode_ok(inode));
++static inline void unlock_cluster_uncapture(jnode * node)
++{
++      uncapture_cluster_jnode(node);
++}
 +
-+      result = grab_tfm_stream(inode, tc, INPUT_STREAM);
-+      if (result) {
-+              warning("edward-1430",
-+                      "alloc stream failed with ret=%d", result);
-+              return result;
++/* Set new file size by window. Cluster lock is required. */
++static void checkin_file_size(struct cluster_handle * clust,
++                            struct inode * inode)
++{
++      loff_t new_size;
++      struct reiser4_slide * win;
++
++      assert("edward-1181", clust != NULL);
++      assert("edward-1182", inode != NULL);
++      assert("edward-1473", clust->pages != NULL);
++      assert("edward-1474", clust->pages[0] != NULL);
++      assert("edward-1475", jprivate(clust->pages[0]) != NULL);
++      assert_spin_locked(&(jprivate(clust->pages[0])->guard));
++
++
++      win = clust->win;
++      assert("edward-1183", win != NULL);
++
++      new_size = clust_to_off(clust->index, inode) + win->off;
++
++      switch (clust->op) {
++      case LC_APPOV:
++              if (new_size + win->count <= i_size_read(inode))
++                      /* overwrite only */
++                      return;
++              new_size += win->count;
++              break;
++      case LC_TRUNC:
++              break;
++      default:
++              impossible("edward-1184", "bad page cluster option");
++              break;
 +      }
-+      spin_lock_jnode(node);
-+      assert("edward-1435", JF_ISSET(node, JNODE_DIRTY));
++      inode_check_scale_nolock(inode, i_size_read(inode), new_size);
++      i_size_write(inode, new_size);
++      return;
++}
 +
-+      /* Check out a size of logical cluster and 
-+         set a number of cluster pages to commit. */
-+      tc->len = tc->lsize = fsize_to_count(clust, inode);
-+      clust->nr_pages = count_to_nrpages(tc->len);
++static inline void checkin_cluster_size(struct cluster_handle * clust,
++                                      struct inode * inode)
++{
++      if (clust->win)
++              checkin_file_size(clust, inode);
++}
 +
-+      assert("edward-983", clust->nr_pages == node->page_count + 1);
++static int checkin_page_cluster(struct cluster_handle * clust,
++                              struct inode * inode)
++{
++      int result;
++      jnode * node;
++      int old_nrpages = clust->old_nrpages;
++      int new_nrpages = get_new_nrpages(clust);
++
++      node = clust->node;
++
++      assert("edward-221", node != NULL);
++      assert("edward-971", clust->reserved == 1);
++      assert("edward-1263",
++             clust->reserved_prepped == estimate_update_cluster(inode));
++      assert("edward-1264", clust->reserved_unprepped == 0);
++
++      if (JF_ISSET(node, JNODE_DIRTY)) {
++              /*
++               * page cluster was checked in, but not yet
++               * checked out, so release related resources
++               */
++              free_reserved4cluster(inode, clust,
++                                    estimate_update_cluster(inode));
++              __put_page_cluster(0, clust->old_nrpages,
++                                 clust->pages, inode);
++      } else {
++              result = capture_cluster_jnode(node);
++              if (unlikely(result)) {
++                      unlock_cluster(node);
++                      return result;
++              }
++              jnode_make_dirty_locked(node);
++              clust->reserved = 0;
++      }
++      unlock_cluster(node);
++
++      if (new_nrpages < old_nrpages) {
++              /* truncate >= 1 complete pages */
++              __put_page_cluster(new_nrpages,
++                                 old_nrpages - new_nrpages,
++                                 clust->pages, inode);
++              truncate_page_cluster_range(inode,
++                                          clust->pages, clust->index,
++                                          new_nrpages,
++                                          old_nrpages - new_nrpages,
++                                          0);
++      }
 +#if REISER4_DEBUG
-+      node->page_count = 0;
++      clust->reserved_prepped -= estimate_update_cluster(inode);
 +#endif
-+      cluster_reserved2grabbed(estimate_update_cluster(inode));
-+      uncapture_cluster_jnode(node);
++      return 0;
++}
 +
-+      assert("edward-1224", schedulable());
-+      /* Check out cluster pages to commit */
-+      nr_pages =
-+            find_get_pages(inode->i_mapping, clust_to_pg(clust->index, inode),
-+                           clust->nr_pages, clust->pages);
++/* Submit modifications of a logical cluster */
++static int checkin_logical_cluster(struct cluster_handle * clust,
++                                 struct inode *inode)
++{
++      int result = 0;
++      jnode * node;
 +
-+      assert("edward-1280", nr_pages == clust->nr_pages);
-+      /* Construct input stream from the checked out pages */
-+      for (i = 0; i < clust->nr_pages; i++) {
-+              char *data;
++      node = clust->node;
++
++      assert("edward-1035", node != NULL);
++      assert("edward-1029", clust != NULL);
++      assert("edward-1030", clust->reserved == 1);
++      assert("edward-1031", clust->nr_pages != 0);
++      assert("edward-1032", clust->pages != NULL);
++      assert("edward-1033", clust->pages[0] != NULL);
++      assert("edward-1446", jnode_is_cluster_page(node));
++      assert("edward-1476", node == jprivate(clust->pages[0]));
++
++      lock_cluster(node);
++      checkin_cluster_size(clust, inode);
++      /* this will unlock cluster */
++      result = checkin_page_cluster(clust, inode);
++      jput(node);
++      clust->node = NULL;
++      return result;
++}
++
++/*
++ * Retrieve size of logical cluster that was checked in at
++ * the latest modifying session (cluster lock is required)
++ */
++static inline void checkout_cluster_size(struct cluster_handle * clust,
++                                       struct inode * inode)
++{
++      struct tfm_cluster *tc = &clust->tc;
++
++      tc->len = lbytes(clust->index, inode);
++      assert("edward-1478", tc->len != 0);
++}
++
++/*
++ * Retrieve a page cluster with the latest submitted modifications
++ * and flush its pages to previously allocated contiguous stream.
++ */
++static void checkout_page_cluster(struct cluster_handle * clust,
++                                jnode * node, struct inode * inode)
++{
++      int i;
++      int found;
++      int to_put;
++      struct tfm_cluster *tc = &clust->tc;
++
++      /* find and put checked in pages: cluster is locked,
++       * so we must get expected number (to_put) of pages
++       */
++      to_put = size_in_pages(lbytes(clust->index, inode));
++      found = find_get_pages(inode->i_mapping,
++                             clust_to_pg(clust->index, inode),
++                             to_put, clust->pages);
++      BUG_ON(found != to_put);
++
++      __put_page_cluster(0, to_put, clust->pages, inode);
++      unlock_cluster_uncapture(node);
++
++      /* Flush found pages.
++       *
++       * Note, that we don't disable modifications while flushing,
++       * moreover, some found pages can be truncated, as we have
++       * released cluster lock.
++       */
++      for (i = 0; i < found; i++) {
++              int in_page;
++              char * data;
++              assert("edward-1479",
++                     clust->pages[i]->index == clust->pages[0]->index + i);
 +
-+              assert("edward-242", clust->pages[i] != NULL);
-+              assert("edward-1436", clust->pages[i]->index ==
-+                     clust_to_pg(clust->index, inode) + i); 
-+              assert("edward-1437", PageUptodate(clust->pages[i]));
-+              /* flush the page into the input stream */
 +              lock_page(clust->pages[i]);
-+              data = kmap(clust->pages[i]);
++              if (!PageUptodate(clust->pages[i])) {
++                      /* page was truncated */
++                      assert("edward-1480",
++                             i_size_read(inode) <= page_offset(clust->pages[i]));
++                      assert("edward-1481",
++                             clust->pages[i]->mapping != inode->i_mapping);
++                      unlock_page(clust->pages[i]);
++                      break;
++              }
++              /* Update the number of bytes in the logical cluster,
++               * as it could be partially truncated. Note, that only
++               * partial truncate is possible (complete truncate can
++               * not go here, as it is performed via ->kill_hook()
++                 * called by cut_file_items(), and the last one must
++                 * wait for znode locked with parent coord).
++               */
++              checkout_cluster_size(clust, inode);
 +
-+              assert("edward-986", cnt_to_pgcnt(tc->len, i) != 0);
++              /* this can be zero, as new file size is
++                 checked in before truncating pages */
++              in_page = __mbp(tc->len, i);
 +
++              data = kmap(clust->pages[i]);
 +              memcpy(tfm_stream_data(tc, INPUT_STREAM) + pg_to_off(i),
-+                     data, cnt_to_pgcnt(tc->len, i));
++                     data, in_page);
 +              kunmap(clust->pages[i]);
++
++              if (PageDirty(clust->pages[i]))
++                      cancel_dirty_page(clust->pages[i], PAGE_CACHE_SIZE);
++
 +              unlock_page(clust->pages[i]);
++
++              if (in_page < PAGE_CACHE_SIZE)
++                      /* end of the file */
++                      break;
 +      }
-+      clear_cluster_pages_dirty(clust);
-+              release_cluster_pages(clust);
-+#if REISER4_DEBUG
-+      cryptcompress_inode_data(inode)->pgcount -= clust->nr_pages;
-+#endif
-+      /* put pages that were found here */
-+      release_cluster_pages(clust);
-+      return result;
++      put_found_pages(clust->pages, found); /* find_get_pages */
++      tc->lsize = tc->len;
++      return;
++}
++
++/* Check out modifications of a logical cluster */
++int checkout_logical_cluster(struct cluster_handle * clust,
++                           jnode * node, struct inode *inode)
++{
++      int result;
++      struct tfm_cluster *tc = &clust->tc;
++
++      assert("edward-980", node != NULL);
++      assert("edward-236", inode != NULL);
++      assert("edward-237", clust != NULL);
++      assert("edward-240", !clust->win);
++      assert("edward-241", reiser4_schedulable());
++      assert("edward-718", cryptcompress_inode_ok(inode));
++
++      result = grab_tfm_stream(inode, tc, INPUT_STREAM);
++      if (result) {
++              warning("edward-1430", "alloc stream failed with ret=%d",
++                      result);
++              return RETERR(-E_REPEAT);
++      }
++      lock_cluster(node);
++
++      if (unlikely(!JF_ISSET(node, JNODE_DIRTY))) {
++              /* race with another flush */
++              warning("edward-982",
++                      "checking out logical cluster %lu of inode %llu: "
++                      "jnode is not dirty", clust->index,
++                      (unsigned long long)get_inode_oid(inode));
++              unlock_cluster(node);
++              return RETERR(-E_REPEAT);
++      }
++      cluster_reserved2grabbed(estimate_update_cluster(inode));
++
++      /* this will unlock cluster */
++      checkout_page_cluster(clust, node, inode);
++      return 0;
 +}
 +
 +/* set hint for the cluster of the index @index */
@@ -33148,31 +32715,31 @@ Index: linux-2.6.16/fs/reiser4/plugin/file/cryptcompress.c
 +                           cloff_t index, znode_lock_mode mode)
 +{
 +      reiser4_key key;
-+      assert("edward-722", crc_inode_ok(inode));
++      assert("edward-722", cryptcompress_inode_ok(inode));
 +      assert("edward-723",
 +             inode_file_plugin(inode) ==
-+             file_plugin_by_id(CRC_FILE_PLUGIN_ID));
++             file_plugin_by_id(CRYPTCOMPRESS_FILE_PLUGIN_ID));
 +
 +      inode_file_plugin(inode)->key_by_inode(inode,
 +                                             clust_to_off(index, inode),
 +                                             &key);
 +
-+      seal_init(&hint->seal, &hint->ext_coord.coord, &key);
++      reiser4_seal_init(&hint->seal, &hint->ext_coord.coord, &key);
 +      hint->offset = get_key_offset(&key);
 +      hint->mode = mode;
 +}
 +
-+void invalidate_hint_cluster(reiser4_cluster_t * clust)
++void invalidate_hint_cluster(struct cluster_handle * clust)
 +{
 +      assert("edward-1291", clust != NULL);
 +      assert("edward-1292", clust->hint != NULL);
 +
 +      done_lh(&clust->hint->lh);
-+      clust->hint->ext_coord.valid = 0;
++      hint_clr_valid(clust->hint);
 +}
 +
-+void put_hint_cluster(reiser4_cluster_t * clust, struct inode *inode,
-+               znode_lock_mode mode)
++void put_hint_cluster(struct cluster_handle * clust, struct inode *inode,
++                    znode_lock_mode mode)
 +{
 +      assert("edward-1286", clust != NULL);
 +      assert("edward-1287", clust->hint != NULL);
@@ -33181,45 +32748,45 @@ Index: linux-2.6.16/fs/reiser4/plugin/file/cryptcompress.c
 +      invalidate_hint_cluster(clust);
 +}
 +
-+static int
-+balance_dirty_page_cluster(reiser4_cluster_t * clust, struct inode *inode,
-+                         loff_t off, loff_t to_file)
++static int balance_dirty_page_cluster(struct cluster_handle * clust,
++                                    struct inode *inode, loff_t off,
++                                    loff_t to_file)
 +{
 +      int result;
++      struct cryptcompress_info * info;
 +
 +      assert("edward-724", inode != NULL);
-+      assert("edward-725", crc_inode_ok(inode));
-+      assert("edward-1272", get_current_context()->grabbed_blocks == 0);
++      assert("edward-725", cryptcompress_inode_ok(inode));
 +
 +      /* set next window params */
-+      update_cluster(inode, clust, off, to_file);
++      move_update_window(inode, clust, off, to_file);
 +
 +      result = update_sd_cryptcompress(inode);
-+      assert("edward-988", !result);
 +      if (result)
 +              return result;
 +      assert("edward-726", clust->hint->lh.owner == NULL);
++      info = cryptcompress_inode_data(inode);
 +
++      mutex_unlock(&info->checkin_mutex);
 +      reiser4_throttle_write(inode);
-+      all_grabbed2free();
++      mutex_lock(&info->checkin_mutex);
 +      return 0;
 +}
 +
-+/* set zeroes to the cluster, update it, and maybe, try to capture its pages */
-+static int
-+write_hole(struct inode *inode, reiser4_cluster_t * clust, loff_t file_off,
-+         loff_t to_file)
++/* set zeroes to the page cluster, proceed it, and maybe, try to capture
++   its pages */
++static int write_hole(struct inode *inode, struct cluster_handle * clust,
++                    loff_t file_off, loff_t to_file)
 +{
-+      char *data;
 +      int result = 0;
 +      unsigned cl_off, cl_count = 0;
 +      unsigned to_pg, pg_off;
-+      reiser4_slide_t *win;
++      struct reiser4_slide * win;
 +
 +      assert("edward-190", clust != NULL);
 +      assert("edward-1069", clust->win != NULL);
 +      assert("edward-191", inode != NULL);
-+      assert("edward-727", crc_inode_ok(inode));
++      assert("edward-727", cryptcompress_inode_ok(inode));
 +      assert("edward-1171", clust->dstat != INVAL_DISK_CLUSTER);
 +      assert("edward-1154",
 +             ergo(clust->dstat != FAKE_DISK_CLUSTER, clust->reserved == 1));
@@ -33231,8 +32798,13 @@ Index: linux-2.6.16/fs/reiser4/plugin/file/cryptcompress.c
 +      assert("edward-192", cluster_ok(clust, inode));
 +
 +      if (win->off == 0 && win->count == inode_cluster_size(inode)) {
-+              /* the hole will be represented by fake disk cluster */
-+              update_cluster(inode, clust, file_off, to_file);
++              /* This part of the hole will be represented by "fake"
++               * logical cluster, i.e. which doesn't have appropriate
++               * disk cluster until someone modify this logical cluster
++               * and make it dirty.
++               * So go forward here..
++               */
++              move_update_window(inode, clust, file_off, to_file);
 +              return 0;
 +      }
 +      cl_count = win->count;  /* number of zeroes to write */
@@ -33245,13 +32817,12 @@ Index: linux-2.6.16/fs/reiser4/plugin/file/cryptcompress.c
 +
 +              assert("edward-284", page != NULL);
 +
-+              to_pg = min_count(PAGE_CACHE_SIZE - pg_off, cl_count);
++              to_pg = min((typeof(pg_off))PAGE_CACHE_SIZE - pg_off, cl_count);
 +              lock_page(page);
-+              data = kmap_atomic(page, KM_USER0);
-+              memset(data + pg_off, 0, to_pg);
-+              flush_dcache_page(page);
-+              kunmap_atomic(data, KM_USER0);
++              zero_user_page(page, pg_off, to_pg, KM_USER0);
 +              SetPageUptodate(page);
++              reiser4_set_page_dirty_internal(page);
++              mark_page_accessed(page);
 +              unlock_page(page);
 +
 +              cl_off += to_pg;
@@ -33259,92 +32830,88 @@ Index: linux-2.6.16/fs/reiser4/plugin/file/cryptcompress.c
 +              pg_off = 0;
 +      }
 +      if (!win->delta) {
-+              /* only zeroes, try to capture */
-+
-+              set_cluster_pages_dirty(clust);
-+              result = try_capture_cluster(clust, inode);
++              /* only zeroes in this window, try to capture
++               */
++              result = checkin_logical_cluster(clust, inode);
 +              if (result)
 +                      return result;
 +              put_hint_cluster(clust, inode, ZNODE_WRITE_LOCK);
 +              result =
 +                  balance_dirty_page_cluster(clust, inode, file_off, to_file);
 +      } else
-+              update_cluster(inode, clust, file_off, to_file);
++              move_update_window(inode, clust, file_off, to_file);
 +      return result;
 +}
 +
 +/*
-+  The main disk search procedure for cryptcompress plugins, which
-+  . scans all items of disk cluster
-+  . maybe reads each one (if @read != 0)
-+  . maybe makes its znode dirty  (if @write != 0)
++  The main disk search procedure for cryptcompress plugin, which
++  . scans all items of disk cluster with the lock mode @mode
++  . maybe reads each one (if @read)
++  . maybe makes its znode dirty (if write lock mode was specified)
 +
 +  NOTE-EDWARD: Callers should handle the case when disk cluster
 +  is incomplete (-EIO)
 +*/
-+int
-+find_cluster(reiser4_cluster_t * clust,
-+           struct inode *inode, int read, int write)
++int find_disk_cluster(struct cluster_handle * clust,
++                    struct inode *inode, int read, znode_lock_mode mode)
 +{
 +      flow_t f;
 +      hint_t *hint;
 +      int result = 0;
-+      unsigned long cl_idx;
++      int was_grabbed;
 +      ra_info_t ra_info;
 +      file_plugin *fplug;
 +      item_plugin *iplug;
-+      tfm_cluster_t *tc;
-+      int was_grabbed;
++      struct tfm_cluster *tc;
++      struct cryptcompress_info * info;
 +
 +      assert("edward-138", clust != NULL);
 +      assert("edward-728", clust->hint != NULL);
-+      assert("edward-225", read || write);
-+      assert("edward-226", schedulable());
++      assert("edward-226", reiser4_schedulable());
 +      assert("edward-137", inode != NULL);
-+      assert("edward-729", crc_inode_ok(inode));
++      assert("edward-729", cryptcompress_inode_ok(inode));
 +
 +      hint = clust->hint;
-+      cl_idx = clust->index;
 +      fplug = inode_file_plugin(inode);
 +      was_grabbed = get_current_context()->grabbed_blocks;
++      info = cryptcompress_inode_data(inode);
 +      tc = &clust->tc;
 +
 +      assert("edward-462", !tfm_cluster_is_uptodate(tc));
 +      assert("edward-461", ergo(read, tfm_stream_is_set(tc, INPUT_STREAM)));
 +
++      dclust_init_extension(hint);
++
 +      /* set key of the first disk cluster item */
 +      fplug->flow_by_inode(inode,
 +                           (read ? (char __user *)tfm_stream_data(tc, INPUT_STREAM) : NULL),
 +                           0 /* kernel space */ ,
 +                           inode_scaled_cluster_size(inode),
-+                           clust_to_off(cl_idx, inode), READ_OP, &f);
-+      if (write) {
++                           clust_to_off(clust->index, inode), READ_OP, &f);
++      if (mode == ZNODE_WRITE_LOCK) {
 +              /* reserve for flush to make dirty all the leaf nodes
 +                 which contain disk cluster */
 +              result =
 +                  reiser4_grab_space_force(estimate_dirty_cluster(inode),
 +                                           BA_CAN_COMMIT);
-+              assert("edward-990", !result);
 +              if (result)
 +                      goto out;
 +      }
 +
 +      ra_info.key_to_stop = f.key;
-+      set_key_offset(&ra_info.key_to_stop, get_key_offset(max_key()));
++      set_key_offset(&ra_info.key_to_stop, get_key_offset(reiser4_max_key()));
 +
 +      while (f.length) {
-+              result = find_cluster_item(hint,
-+                                         &f.key,
-+                                         (write ? ZNODE_WRITE_LOCK :
-+                                          ZNODE_READ_LOCK), NULL, FIND_EXACT,
-+                                         (write ? CBK_FOR_INSERT : 0));
++              result = find_cluster_item(hint, &f.key, mode,
++                                         NULL, FIND_EXACT,
++                                         (mode == ZNODE_WRITE_LOCK ?
++                                          CBK_FOR_INSERT : 0));
 +              switch (result) {
 +              case CBK_COORD_NOTFOUND:
 +                      result = 0;
 +                      if (inode_scaled_offset
-+                          (inode,
-+                           clust_to_off(cl_idx,
-+                                        inode)) == get_key_offset(&f.key)) {
++                          (inode, clust_to_off(clust->index, inode)) ==
++                          get_key_offset(&f.key)) {
 +                              /* first item not found, this is treated
 +                                 as disk cluster is absent */
 +                              clust->dstat = FAKE_DISK_CLUSTER;
@@ -33374,8 +32941,16 @@ Index: linux-2.6.16/fs/reiser4/plugin/file/cryptcompress.c
 +                              zrelse(hint->ext_coord.coord.node);
 +                              goto out;
 +                      }
-+                      if (write) {
-+                              znode_make_dirty(hint->ext_coord.coord.node);
++                      if (mode == ZNODE_WRITE_LOCK) {
++                              /* Don't make dirty more nodes then it was
++                                 estimated (see comments before
++                                 estimate_dirty_cluster). Missed nodes will be
++                                 read up in flush time if they are evicted from
++                                 memory */
++                              if (dclust_get_extension_ncount(hint) <=
++                                  estimate_dirty_cluster(inode))
++                                 znode_make_dirty(hint->ext_coord.coord.node);
++
 +                              znode_set_convertible(hint->ext_coord.coord.
 +                                                    node);
 +                      }
@@ -33390,14 +32965,18 @@ Index: linux-2.6.16/fs/reiser4/plugin/file/cryptcompress.c
 +      /* NOTE-EDWARD: Callers should handle the case
 +         when disk cluster is incomplete (-EIO) */
 +      tc->len = inode_scaled_cluster_size(inode) - f.length;
-+      tc->lsize = fsize_to_count(clust, inode);
++      tc->lsize = lbytes(clust->index, inode);
 +      assert("edward-1196", tc->len > 0);
 +      assert("edward-1406", tc->lsize > 0);
 +
-+      if (hint_is_unprepped_dclust(clust->hint))
++      if (hint_is_unprepped_dclust(clust->hint)) {
 +              clust->dstat = UNPR_DISK_CLUSTER;
-+      else
++      } else if (clust->index == info->trunc_index) {
++              clust->dstat = TRNC_DISK_CLUSTER;
++      } else {
 +              clust->dstat = PREP_DISK_CLUSTER;
++              dclust_set_extension_dsize(clust->hint, tc->len);
++      }
 + out:
 +      assert("edward-1339",
 +             get_current_context()->grabbed_blocks >= was_grabbed);
@@ -33407,18 +32986,17 @@ Index: linux-2.6.16/fs/reiser4/plugin/file/cryptcompress.c
 +      return result;
 +}
 +
-+int
-+get_disk_cluster_locked(reiser4_cluster_t * clust, struct inode *inode,
-+                      znode_lock_mode lock_mode)
++int get_disk_cluster_locked(struct cluster_handle * clust, struct inode *inode,
++                          znode_lock_mode lock_mode)
 +{
 +      reiser4_key key;
 +      ra_info_t ra_info;
 +
-+      assert("edward-730", schedulable());
++      assert("edward-730", reiser4_schedulable());
 +      assert("edward-731", clust != NULL);
 +      assert("edward-732", inode != NULL);
 +
-+      if (clust->hint->ext_coord.valid) {
++      if (hint_is_valid(clust->hint)) {
 +              assert("edward-1293", clust->dstat != INVAL_DISK_CLUSTER);
 +              assert("edward-1294",
 +                     znode_is_write_locked(clust->hint->lh.node));
@@ -33430,7 +33008,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/file/cryptcompress.c
 +      key_by_inode_cryptcompress(inode, clust_to_off(clust->index, inode),
 +                                 &key);
 +      ra_info.key_to_stop = key;
-+      set_key_offset(&ra_info.key_to_stop, get_key_offset(max_key()));
++      set_key_offset(&ra_info.key_to_stop, get_key_offset(reiser4_max_key()));
 +
 +      return find_cluster_item(clust->hint, &key, lock_mode, NULL, FIND_EXACT,
 +                               CBK_FOR_INSERT);
@@ -33442,17 +33020,17 @@ Index: linux-2.6.16/fs/reiser4/plugin/file/cryptcompress.c
 +   . find and set disk cluster state
 +   . make disk cluster dirty if its state is not FAKE_DISK_CLUSTER.
 +*/
-+static int
-+read_some_cluster_pages(struct inode *inode, reiser4_cluster_t * clust)
++static int read_some_cluster_pages(struct inode * inode,
++                                 struct cluster_handle * clust)
 +{
 +      int i;
 +      int result = 0;
 +      item_plugin *iplug;
-+      reiser4_slide_t *win = clust->win;
++      struct reiser4_slide * win = clust->win;
++      znode_lock_mode mode = ZNODE_WRITE_LOCK;
 +
 +      iplug = item_plugin_by_id(CTAIL_ID);
 +
-+      assert("edward-733", get_current_context()->grabbed_blocks == 0);
 +      assert("edward-924", !tfm_cluster_is_uptodate(&clust->tc));
 +
 +#if REISER4_DEBUG
@@ -33460,19 +33038,18 @@ Index: linux-2.6.16/fs/reiser4/plugin/file/cryptcompress.c
 +              /* start write hole from fake disk cluster */
 +              assert("edward-1117", win != NULL);
 +              assert("edward-1118", win->stat == HOLE_WINDOW);
-+              assert("edward-1119", new_cluster(clust, inode));
++              assert("edward-1119", new_logical_cluster(clust, inode));
 +      }
 +#endif
-+      if (new_cluster(clust, inode)) {
++      if (new_logical_cluster(clust, inode)) {
 +              /*
 +                 new page cluster is about to be written, nothing to read,
 +               */
-+              assert("edward-734", schedulable());
++              assert("edward-734", reiser4_schedulable());
 +              assert("edward-735", clust->hint->lh.owner == NULL);
 +
 +              if (clust->nr_pages) {
 +                      int off;
-+                      char *data;
 +                      struct page * pg;
 +                      assert("edward-1419", clust->pages != NULL);
 +                      pg = clust->pages[clust->nr_pages - 1];
@@ -33480,10 +33057,8 @@ Index: linux-2.6.16/fs/reiser4/plugin/file/cryptcompress.c
 +                      off = off_to_pgoff(win->off+win->count+win->delta);
 +                      if (off) {
 +                              lock_page(pg);
-+                              data = kmap_atomic(pg, KM_USER0);
-+                              memset(data + off, 0, PAGE_CACHE_SIZE - off);
-+                              flush_dcache_page(pg);
-+                              kunmap_atomic(data, KM_USER0);
++                              zero_user_page(pg, off, PAGE_CACHE_SIZE - off,
++                                              KM_USER0);
 +                              unlock_page(pg);
 +                      }
 +              }
@@ -33510,7 +33085,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/file/cryptcompress.c
 +              unlock_page(pg);
 +
 +              if (win &&
-+                  i >= count_to_nrpages(win->off) &&
++                  i >= size_in_pages(win->off) &&
 +                  i < off_to_pg(win->off + win->count + win->delta))
 +                      /* page will be completely overwritten */
 +                      continue;
@@ -33519,60 +33094,48 @@ Index: linux-2.6.16/fs/reiser4/plugin/file/cryptcompress.c
 +                  /* the last page is
 +                     partially modified,
 +                     not uptodate .. */
-+                  (count_to_nrpages(inode->i_size) <= pg->index)) {
++                  (size_in_pages(i_size_read(inode)) <= pg->index)) {
 +                      /* .. and appended,
 +                         so set zeroes to the rest */
-+                      char *data;
 +                      int offset;
 +                      lock_page(pg);
-+                      data = kmap_atomic(pg, KM_USER0);
-+
 +                      assert("edward-1260",
-+                             count_to_nrpages(win->off + win->count +
-+                                              win->delta) - 1 == i);
++                             size_in_pages(win->off + win->count +
++                                           win->delta) - 1 == i);
 +
 +                      offset =
 +                          off_to_pgoff(win->off + win->count + win->delta);
-+                      memset(data + offset, 0, PAGE_CACHE_SIZE - offset);
-+                      flush_dcache_page(pg);
-+                      kunmap_atomic(data, KM_USER0);
++                      zero_user_page(pg, offset, PAGE_CACHE_SIZE - offset,
++                                      KM_USER0);
 +                      unlock_page(pg);
 +                      /* still not uptodate */
 +                      break;
 +              }
-+              if (!tfm_cluster_is_uptodate(&clust->tc)) {
-+                      result = ctail_read_disk_cluster(clust, inode, 1);
-+                      assert("edward-992", !result);
-+                      if (result)
-+                              goto out;
-+                      assert("edward-925",
-+                             tfm_cluster_is_uptodate(&clust->tc));
-+              }
 +              lock_page(pg);
-+              result = do_readpage_ctail(inode, clust, pg);
++              result = do_readpage_ctail(inode, clust, pg, mode);
++
++              assert("edward-1526", ergo(!result, PageUptodate(pg)));
 +              unlock_page(pg);
-+              assert("edward-993", !result);
 +              if (result) {
-+                      impossible("edward-219",
-+                                 "do_readpage_ctail returned crap");
++                      warning("edward-219", "do_readpage_ctail failed");
 +                      goto out;
 +              }
 +      }
 +      if (!tfm_cluster_is_uptodate(&clust->tc)) {
 +              /* disk cluster unclaimed, but we need to make its znodes dirty
-+                 to make flush update convert its content */
-+              result =
-+                  find_cluster(clust, inode, 0 /* do not read */ ,
-+                               1 /* write */ );
-+              assert("edward-994", !result);
++               * to make flush update convert its content
++               */
++              result = find_disk_cluster(clust, inode,
++                                         0 /* do not read items */,
++                                         mode);
 +      }
 + out:
 +      tfm_cluster_clr_uptodate(&clust->tc);
 +      return result;
 +}
 +
-+static int
-+should_create_unprepped_cluster(reiser4_cluster_t * clust, struct inode *inode)
++static int should_create_unprepped_cluster(struct cluster_handle * clust,
++                                         struct inode * inode)
 +{
 +      assert("edward-737", clust != NULL);
 +
@@ -33583,7 +33146,8 @@ Index: linux-2.6.16/fs/reiser4/plugin/file/cryptcompress.c
 +      case FAKE_DISK_CLUSTER:
 +              if (clust->win &&
 +                  clust->win->stat == HOLE_WINDOW && clust->nr_pages == 0) {
-+                      assert("edward-1172", new_cluster(clust, inode));
++                      assert("edward-1172",
++                             new_logical_cluster(clust, inode));
 +                      return 0;
 +              }
 +              return 1;
@@ -33593,182 +33157,171 @@ Index: linux-2.6.16/fs/reiser4/plugin/file/cryptcompress.c
 +      }
 +}
 +
-+static int
-+crc_make_unprepped_cluster(reiser4_cluster_t * clust, struct inode *inode)
++static int cryptcompress_make_unprepped_cluster(struct cluster_handle * clust,
++                                              struct inode *inode)
 +{
 +      int result;
 +
-+      assert("edward-1123", schedulable());
++      assert("edward-1123", reiser4_schedulable());
 +      assert("edward-737", clust != NULL);
 +      assert("edward-738", inode != NULL);
-+      assert("edward-739", crc_inode_ok(inode));
++      assert("edward-739", cryptcompress_inode_ok(inode));
 +      assert("edward-1053", clust->hint != NULL);
-+      assert("edward-1266", get_current_context()->grabbed_blocks == 0);
 +
-+      if (clust->reserved) {
-+              cluster_reserved2grabbed(estimate_insert_cluster(inode));
++      if (!should_create_unprepped_cluster(clust, inode)) {
++              if (clust->reserved) {
++                      cluster_reserved2free(estimate_insert_cluster(inode));
 +#if REISER4_DEBUG
-+              assert("edward-1267",
-+                     clust->reserved_unprepped ==
-+                     estimate_insert_cluster(inode));
-+              clust->reserved_unprepped -= estimate_insert_cluster(inode);
++                      assert("edward-1267",
++                             clust->reserved_unprepped ==
++                             estimate_insert_cluster(inode));
++                      clust->reserved_unprepped -=
++                              estimate_insert_cluster(inode);
 +#endif
-+      }
-+      if (!should_create_unprepped_cluster(clust, inode)) {
-+              all_grabbed2free();
++              }
 +              return 0;
-+      } else {
-+              assert("edward-1268", clust->reserved == 1);
 +      }
++      assert("edward-1268", clust->reserved);
++      cluster_reserved2grabbed(estimate_insert_cluster(inode));
++#if REISER4_DEBUG
++      assert("edward-1441",
++             clust->reserved_unprepped == estimate_insert_cluster(inode));
++      clust->reserved_unprepped -= estimate_insert_cluster(inode);
++#endif
 +      result = ctail_insert_unprepped_cluster(clust, inode);
-+      all_grabbed2free();
 +      if (result)
 +              return result;
 +
-+      assert("edward-743", crc_inode_ok(inode));
-+      assert("edward-1269", get_current_context()->grabbed_blocks == 0);
++      inode_add_bytes(inode, inode_cluster_size(inode));
++
++      assert("edward-743", cryptcompress_inode_ok(inode));
 +      assert("edward-744", znode_is_write_locked(clust->hint->lh.node));
 +
 +      clust->dstat = UNPR_DISK_CLUSTER;
 +      return 0;
 +}
 +
-+#if REISER4_DEBUG
-+static int jnode_truncate_ok(struct inode *inode, cloff_t index)
-+{
-+      jnode *node;
-+      node =
-+          jlookup(current_tree, get_inode_oid(inode),
-+                  clust_to_pg(index, inode));
-+      if (likely(!node))
-+              return 1;
-+      /* someone got this jnode */
-+      warning("edward-1315", "jnode %p is untruncated\n", node);
-+      jput(node);
-+      return (atomic_read(&node->x_count));
-+}
-+#endif
-+
-+/* Collect unlocked cluster pages and jnode (the last is in the
-+   case when the page cluster will be modified and captured) */
-+int
-+prepare_page_cluster(struct inode *inode, reiser4_cluster_t * clust,
-+                   int capture)
++/* . Grab page cluster for read, write, setattr, etc. operations;
++ * . Truncate its complete pages, if needed;
++ */
++int prepare_page_cluster(struct inode * inode, struct cluster_handle * clust,
++                       rw_op rw)
 +{
 +      assert("edward-177", inode != NULL);
-+      assert("edward-741", crc_inode_ok(inode));
++      assert("edward-741", cryptcompress_inode_ok(inode));
 +      assert("edward-740", clust->pages != NULL);
 +
 +      set_cluster_nrpages(clust, inode);
 +      reset_cluster_pgset(clust, cluster_nrpages(inode));
-+      return (capture ?
-+              grab_cluster_pages_jnode(inode, clust) :
-+              grab_cluster_pages(inode, clust));
++      return grab_page_cluster(inode, clust, rw);
 +}
 +
-+/* Truncate all pages of the cluster of index @index.
-+   This is called by ->kill_hook() method of item plugin */
-+void truncate_page_cluster(struct inode *inode, cloff_t index)
++/* Truncate complete page cluster of index @index.
++ * This is called by ->kill_hook() method of item
++ * plugin when deleting a disk cluster of such index.
++ */
++void truncate_complete_page_cluster(struct inode *inode, cloff_t index,
++                                  int even_cows)
 +{
-+      int i;
-+      int found = 0;
++      int found;
 +      int nr_pages;
 +      jnode *node;
 +      struct page *pages[MAX_CLUSTER_NRPAGES];
 +
-+      node =
-+          jlookup(current_tree, get_inode_oid(inode),
-+                  clust_to_pg(index, inode));
-+      /* jnode is absent, just drop pages which can not
-+         acquire jnode because of exclusive access */
-+      if (!node) {
-+              truncate_inode_pages_range(inode->i_mapping,
-+                                         clust_to_off(index, inode),
-+                                         clust_to_off(index,
-+                                                      inode) +
-+                                         inode_cluster_size(inode) - 1);
++      node = jlookup(current_tree, get_inode_oid(inode),
++                     clust_to_pg(index, inode));
++      nr_pages = size_in_pages(lbytes(index, inode));
++      assert("edward-1483", nr_pages != 0);
++      if (!node)
++              goto truncate;
++      found = find_get_pages(inode->i_mapping,
++                             clust_to_pg(index, inode),
++                             cluster_nrpages(inode), pages);
++      if (!found) {
++              assert("edward-1484", jnode_truncate_ok(inode, index));
 +              return;
 +      }
-+      /* jnode is present and may be dirty */
-+      nr_pages = count_to_nrpages(cnt_to_clcnt(inode->i_size, index, inode));
++      lock_cluster(node);
 +
-+      found = find_get_pages(inode->i_mapping, clust_to_pg(index, inode),
-+                             nr_pages, pages);
-+      spin_lock_jnode(node);
++      if (reiser4_inode_get_flag(inode, REISER4_FILE_CONV_IN_PROGRESS)
++          && index == 0)
++              /* converting to unix_file is in progress */
++              JF_CLR(node, JNODE_CLUSTER_PAGE);
 +      if (JF_ISSET(node, JNODE_DIRTY)) {
-+              /* someone has done modifications which are not
-+                 yet committed, so we need to release some resources */
-+              
++              /*
++               * @nr_pages were checked in, but not yet checked out -
++               * we need to release them. (also there can be pages
++               * attached to page cache by read(), etc. - don't take
++               * them into account).
++               */
++              assert("edward-1198", found >= nr_pages);
++
 +              /* free disk space grabbed for disk cluster converting */
 +              cluster_reserved2grabbed(estimate_update_cluster(inode));
 +              grabbed2free(get_current_context(),
 +                           get_current_super_private(),
 +                           estimate_update_cluster(inode));
++              __put_page_cluster(0, nr_pages, pages, inode);
 +
-+              assert("edward-1198", found == nr_pages);
-+              assert("edward-1199", node->page_count + 1 == nr_pages);
-+#if REISER4_DEBUG
-+              node->page_count = 0;
-+#endif
-+              /* This will clear dirty bit */ 
-+              uncapture_cluster_jnode(node);
-+
-+              /* put pages grabbed for last uncommitted modifications */
-+              for (i = 0; i < nr_pages; i++) {
-+                      assert("edward-1200", PageUptodate(pages[i]));
-+                      page_cache_release(pages[i]);
-+#if REISER4_DEBUG
-+                      cryptcompress_inode_data(inode)->pgcount --;
-+#endif
-+              }
++              /* This will clear dirty bit, uncapture and unlock jnode */
++              unlock_cluster_uncapture(node);
 +      } else
-+              spin_unlock_jnode(node);
-+      /* FIXME-EDWARD: Use truncate_complete_page in the loop above instead */
-+
-+      jput(node);
-+      /* put pages found here */
-+      forget_cluster_pages(pages, found);
-+      truncate_inode_pages_range(inode->i_mapping,
-+                                 clust_to_off(index, inode),
-+                                 clust_to_off(index,
-+                                              inode) +
-+                                 inode_cluster_size(inode) - 1);
-+      assert("edward-1201", jnode_truncate_ok(inode, index));
++              unlock_cluster(node);
++      jput(node);                         /* jlookup */
++      put_found_pages(pages, found); /* find_get_pages */
++ truncate:
++      if (reiser4_inode_get_flag(inode, REISER4_FILE_CONV_IN_PROGRESS) &&
++          index == 0)
++              return;
++      truncate_page_cluster_range(inode, pages, index, 0,
++                                  cluster_nrpages(inode),
++                                  even_cows);
++      assert("edward-1201",
++             ergo(!reiser4_inode_get_flag(inode,
++                                          REISER4_FILE_CONV_IN_PROGRESS),
++                  jnode_truncate_ok(inode, index)));
 +      return;
 +}
 +
-+/* Prepare cluster handle before(after) modifications
-+   which are supposed to be committed.
-+
-+   . grab cluster pages;
-+   . reserve disk space;
-+   . maybe read pages from disk and set the disk cluster dirty;
-+   . maybe write hole;
-+   . maybe create 'unprepped' disk cluster if the last one is fake
-+     (i.e. is not represenred by any items)
-+*/
-+
-+static int
-+prepare_cluster(struct inode *inode,
-+              loff_t file_off /* write position in the file */ ,
-+              loff_t to_file, /* bytes of users data to write to the file */
-+              reiser4_cluster_t * clust, page_cluster_op op)
++/*
++ * Set cluster handle @clust of a logical cluster before
++ * modifications which are supposed to be committed.
++ *
++ * . grab cluster pages;
++ * . reserve disk space;
++ * . maybe read pages from disk and set the disk cluster dirty;
++ * . maybe write hole and check in (partially zeroed) logical cluster;
++ * . create 'unprepped' disk cluster for new or fake logical one.
++ */
++static int prepare_logical_cluster(struct inode *inode,
++                                 loff_t file_off, /* write position
++                                                     in the file */
++                                 loff_t to_file, /* bytes of users data
++                                                    to write to the file */
++                                 struct cluster_handle * clust,
++                                 logical_cluster_op op)
 +{
 +      int result = 0;
-+      reiser4_slide_t *win = clust->win;
++      struct reiser4_slide * win = clust->win;
 +
-+      assert("edward-1273", get_current_context()->grabbed_blocks == 0);
 +      reset_cluster_params(clust);
++      cluster_set_tfm_act(&clust->tc, TFMA_READ);
 +#if REISER4_DEBUG
 +      clust->ctx = get_current_context();
 +#endif
-+      assert("edward-1190", op != PCL_UNKNOWN);
++      assert("edward-1190", op != LC_INVAL);
 +
 +      clust->op = op;
 +
-+      result = prepare_page_cluster(inode, clust, 1);
++      result = prepare_page_cluster(inode, clust, WRITE_OP);
 +      if (result)
 +              return result;
++      assert("edward-1447",
++             ergo(clust->nr_pages != 0, jprivate(clust->pages[0])));
++      assert("edward-1448",
++             ergo(clust->nr_pages != 0,
++                  jnode_is_cluster_page(jprivate(clust->pages[0]))));
++
 +      result = reserve4cluster(inode, clust);
 +      if (result)
 +              goto err1;
@@ -33782,7 +33335,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/file/cryptcompress.c
 +      }
 +      assert("edward-1124", clust->dstat != INVAL_DISK_CLUSTER);
 +
-+      result = crc_make_unprepped_cluster(clust, inode);
++      result = cryptcompress_make_unprepped_cluster(clust, inode);
 +      if (result)
 +              goto err2;
 +      if (win && win->stat == HOLE_WINDOW) {
@@ -33791,19 +33344,19 @@ Index: linux-2.6.16/fs/reiser4/plugin/file/cryptcompress.c
 +                      goto err2;
 +      }
 +      return 0;
-+      err2:
++ err2:
 +      free_reserved4cluster(inode, clust,
 +                            estimate_update_cluster(inode));
-+      err1:
-+      release_cluster_pages_and_jnode(clust);
++ err1:
++      put_page_cluster(clust, inode, WRITE_OP);
 +      assert("edward-1125", result == -ENOSPC);
 +      return result;
 +}
 +
 +/* set window by two offsets */
-+static void
-+set_window(reiser4_cluster_t * clust, reiser4_slide_t * win,
-+         struct inode *inode, loff_t o1, loff_t o2)
++static void set_window(struct cluster_handle * clust,
++                     struct reiser4_slide * win, struct inode *inode,
++                     loff_t o1, loff_t o2)
 +{
 +      assert("edward-295", clust != NULL);
 +      assert("edward-296", inode != NULL);
@@ -33813,15 +33366,17 @@ Index: linux-2.6.16/fs/reiser4/plugin/file/cryptcompress.c
 +      clust->index = off_to_clust(o1, inode);
 +
 +      win->off = off_to_cloff(o1, inode);
-+      win->count = min_count(inode_cluster_size(inode) - win->off, o2 - o1);
++      win->count = min((loff_t)(inode_cluster_size(inode) - win->off),
++                       o2 - o1);
 +      win->delta = 0;
 +
 +      clust->win = win;
 +}
 +
-+static int
-+set_cluster_by_window(struct inode *inode, reiser4_cluster_t * clust,
-+                    reiser4_slide_t * win, flow_t * f, loff_t file_off)
++static int set_cluster_by_window(struct inode *inode,
++                               struct cluster_handle * clust,
++                               struct reiser4_slide * win, size_t length,
++                               loff_t file_off)
 +{
 +      int result;
 +
@@ -33833,7 +33388,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/file/cryptcompress.c
 +      if (result)
 +              return result;
 +
-+      if (file_off > inode->i_size) {
++      if (file_off > i_size_read(inode)) {
 +              /* Uhmm, hole in cryptcompress file... */
 +              loff_t hole_size;
 +              hole_size = file_off - inode->i_size;
@@ -33842,35 +33397,35 @@ Index: linux-2.6.16/fs/reiser4/plugin/file/cryptcompress.c
 +              win->stat = HOLE_WINDOW;
 +              if (win->off + hole_size < inode_cluster_size(inode))
 +                      /* there is also user's data to append to the hole */
-+                      win->delta =
-+                          min_count(inode_cluster_size(inode) -
-+                                    (win->off + win->count), f->length);
++                      win->delta = min(inode_cluster_size(inode) -
++                                       (win->off + win->count), length);
 +              return 0;
 +      }
-+      set_window(clust, win, inode, file_off, file_off + f->length);
++      set_window(clust, win, inode, file_off, file_off + length);
 +      win->stat = DATA_WINDOW;
 +      return 0;
 +}
 +
-+int set_cluster_by_page(reiser4_cluster_t * clust, struct page * page,
++int set_cluster_by_page(struct cluster_handle * clust, struct page * page,
 +                      int count)
 +{
 +      int result = 0;
-+      int (*setting_actor)(reiser4_cluster_t * clust, int count);
++      int (*setting_actor)(struct cluster_handle * clust, int count);
 +
 +      assert("edward-1358", clust != NULL);
 +      assert("edward-1359", page != NULL);
 +      assert("edward-1360", page->mapping != NULL);
 +      assert("edward-1361", page->mapping->host != NULL);
 +
-+      setting_actor  = (clust->pages ? reset_cluster_pgset : alloc_cluster_pgset);
++      setting_actor =
++              (clust->pages ? reset_cluster_pgset : alloc_cluster_pgset);
 +      result = setting_actor(clust, count);
 +      clust->index = pg_to_clust(page->index, page->mapping->host);
 +      return result;
 +}
 +
 +/* reset all the params that not get updated */
-+void reset_cluster_params(reiser4_cluster_t * clust)
++void reset_cluster_params(struct cluster_handle * clust)
 +{
 +      assert("edward-197", clust != NULL);
 +
@@ -33879,34 +33434,24 @@ Index: linux-2.6.16/fs/reiser4/plugin/file/cryptcompress.c
 +      clust->tc.len = 0;
 +}
 +
-+/* Core write procedure of cryptcompress plugin, which slices user's
-+   flow into logical clusters, maps the last ones to the appropriate
-+   page clusters, and tries to capture them.
-+   If @buf != NULL, returns number of successfully written bytes,
-+   otherwise returns error
-+*/
-+static loff_t
-+write_cryptcompress_flow(struct file *file, struct inode *inode,
-+                       const char __user *buf, size_t count, loff_t pos)
++static loff_t do_write_cryptcompress(struct file *file, struct inode *inode,
++                                   const char __user *buf, size_t to_write,
++                                   loff_t pos, int *conv_occured)
 +{
 +      int i;
-+      flow_t f;
 +      hint_t *hint;
 +      int result = 0;
-+      size_t to_write = 0;
-+      loff_t file_off;
-+      reiser4_slide_t win;
-+      reiser4_cluster_t clust;
++      size_t count;
++      struct reiser4_slide win;
++      struct cluster_handle clust;
++      struct cryptcompress_info * info;
 +
-+      assert("edward-161", schedulable());
-+      assert("edward-748", crc_inode_ok(inode));
++      assert("edward-161", reiser4_schedulable());
++      assert("edward-748", cryptcompress_inode_ok(inode));
 +      assert("edward-159", current_blocksize == PAGE_CACHE_SIZE);
 +      assert("edward-1274", get_current_context()->grabbed_blocks == 0);
 +
-+      result = check_cryptcompress(inode);
-+      if (result)
-+              return result;
-+      hint = kmalloc(sizeof(*hint), GFP_KERNEL);
++      hint = kmalloc(sizeof(*hint), reiser4_ctx_gfp_mask_get());
 +      if (hint == NULL)
 +              return RETERR(-ENOMEM);
 +
@@ -33915,69 +33460,75 @@ Index: linux-2.6.16/fs/reiser4/plugin/file/cryptcompress.c
 +              kfree(hint);
 +              return result;
 +      }
++      count = to_write;
 +
-+      result =
-+          flow_by_inode_cryptcompress(inode, buf, 1 /* user space */ ,
-+                                      count, pos, WRITE_OP, &f);
-+      if (result)
-+              goto out;
-+      to_write = f.length;
-+
-+      /* current write position in file */
-+      file_off = pos;
 +      reiser4_slide_init(&win);
 +      cluster_init_read(&clust, &win);
 +      clust.hint = hint;
++      info = cryptcompress_inode_data(inode);
++
++      mutex_lock(&info->checkin_mutex);
 +
-+      result = set_cluster_by_window(inode, &clust, &win, &f, file_off);
++      result = set_cluster_by_window(inode, &clust, &win, to_write, pos);
 +      if (result)
 +              goto out;
 +
 +      if (next_window_stat(&win) == HOLE_WINDOW) {
-+              result =
-+                  prepare_cluster(inode, file_off, f.length, &clust,
-+                                  PCL_APPEND);
++              /* write hole in this iteration
++                 separated from the loop below */
++              result = write_conversion_hook(file, inode,
++                                             pos,
++                                             &clust,
++                                             NULL);
++              if (result)
++                      goto out;
++              result = prepare_logical_cluster(inode, pos, count, &clust,
++                                               LC_APPOV);
 +              if (result)
 +                      goto out;
 +      }
 +      do {
-+              char *src;
-+              unsigned page_off, page_count;
++              const char __user * src;
++              unsigned page_off, to_page;
 +
-+              assert("edward-750", schedulable());
++              assert("edward-750", reiser4_schedulable());
 +
-+              result =
-+                  prepare_cluster(inode, file_off, f.length, &clust,
-+                                  PCL_APPEND);
++              result = write_conversion_hook(file, inode,
++                                             pos + to_write - count,
++                                             &clust,
++                                             conv_occured);
++              if (result || *conv_occured)
++                      goto out;
++              result = prepare_logical_cluster(inode, pos, count, &clust,
++                                               LC_APPOV);
 +              if (result)
 +                      goto out;
 +
-+              assert("edward-751", crc_inode_ok(inode));
++              assert("edward-751", cryptcompress_inode_ok(inode));
 +              assert("edward-204", win.stat == DATA_WINDOW);
-+              assert("edward-1288", clust.hint->ext_coord.valid);
++              assert("edward-1288", hint_is_valid(clust.hint));
 +              assert("edward-752",
 +                     znode_is_write_locked(hint->ext_coord.coord.node));
-+
 +              put_hint_cluster(&clust, inode, ZNODE_WRITE_LOCK);
 +
 +              /* set write position in page */
 +              page_off = off_to_pgoff(win.off);
 +
 +              /* copy user's data to cluster pages */
-+              for (i = off_to_pg(win.off), src = f.data;
-+                   i < count_to_nrpages(win.off + win.count);
-+                   i++, src += page_count) {
-+                      page_count =
-+                          cnt_to_pgcnt(win.off + win.count, i) - page_off;
-+
++              for (i = off_to_pg(win.off), src = buf;
++                   i < size_in_pages(win.off + win.count);
++                   i++, src += to_page) {
++                      to_page = __mbp(win.off + win.count, i) - page_off;
 +                      assert("edward-1039",
-+                             page_off + page_count <= PAGE_CACHE_SIZE);
++                             page_off + to_page <= PAGE_CACHE_SIZE);
 +                      assert("edward-287", clust.pages[i] != NULL);
 +
++                      fault_in_pages_readable(src, to_page);
++
 +                      lock_page(clust.pages[i]);
 +                      result =
 +                          __copy_from_user((char *)kmap(clust.pages[i]) +
-+                                           page_off, (char __user *)src, page_count);
++                                           page_off, src, to_page);
 +                      kunmap(clust.pages[i]);
 +                      if (unlikely(result)) {
 +                              unlock_page(clust.pages[i]);
@@ -33985,45 +33536,41 @@ Index: linux-2.6.16/fs/reiser4/plugin/file/cryptcompress.c
 +                              goto err2;
 +                      }
 +                      SetPageUptodate(clust.pages[i]);
++                      reiser4_set_page_dirty_internal(clust.pages[i]);
++                      flush_dcache_page(clust.pages[i]);
++                      mark_page_accessed(clust.pages[i]);
 +                      unlock_page(clust.pages[i]);
 +                      page_off = 0;
 +              }
-+              assert("edward-753", crc_inode_ok(inode));
++              assert("edward-753", cryptcompress_inode_ok(inode));
 +
-+              set_cluster_pages_dirty(&clust);
-+
-+              result = try_capture_cluster(&clust, inode);
++              result = checkin_logical_cluster(&clust, inode);
 +              if (result)
 +                      goto err2;
 +
-+              assert("edward-998", f.user == 1);
-+
-+              move_flow_forward(&f, win.count);
++              buf   += win.count;
++              count -= win.count;
 +
-+              /* disk cluster may be already clean at this point */
-+
-+              /* . update cluster
-+                 . set hint for new offset
-+                 . unlock znode
-+                 . update inode
-+                 . balance dirty pages
-+               */
-+              result = balance_dirty_page_cluster(&clust, inode, 0, f.length);
++              result = balance_dirty_page_cluster(&clust, inode, 0, count);
 +              if (result)
 +                      goto err1;
 +              assert("edward-755", hint->lh.owner == NULL);
 +              reset_cluster_params(&clust);
 +              continue;
-+            err2:
-+              release_cluster_pages_and_jnode(&clust);
-+            err1:
++      err2:
++              put_page_cluster(&clust, inode, WRITE_OP);
++      err1:
 +              if (clust.reserved)
 +                      free_reserved4cluster(inode,
 +                                            &clust,
 +                                            estimate_update_cluster(inode));
 +              break;
-+      } while (f.length);
-+      out:
++      } while (count);
++ out:
++      /*
++       * NOTE: at this point file may have
++       * another (unix-file) plugin installed
++       */
 +      done_lh(&hint->lh);
 +      if (result == -EEXIST)
 +              warning("edward-1407", "write returns EEXIST!\n");
@@ -34031,56 +33578,21 @@ Index: linux-2.6.16/fs/reiser4/plugin/file/cryptcompress.c
 +      put_cluster_handle(&clust);
 +      save_file_hint(file, hint);
 +      kfree(hint);
++      /*
++       * don't release cryptcompress-specific
++       * checkin_mutex, if conversion occured
++       */
++      if (*conv_occured == 0)
++              mutex_unlock(&info->checkin_mutex);
 +      if (buf) {
 +              /* if nothing were written - there must be an error */
-+              assert("edward-195", ergo((to_write == f.length), result < 0));
-+              return (to_write - f.length) ? (to_write - f.length) : result;
++              assert("edward-195", ergo((to_write == count),
++                                        (result < 0 || *conv_occured)));
++              return (to_write - count) ? (to_write - count) : result;
 +      }
 +      return result;
 +}
 +
-+static ssize_t write_crc_file(struct file *file,      /* file to write to */
-+                            struct inode *inode,      /* inode */
-+                            const char __user *buf,   /* address of user-space buffer */
-+                            size_t count,     /* number of bytes to write */
-+                            loff_t * off /* position to write which */ )
-+{
-+
-+      int result;
-+      loff_t pos;
-+      ssize_t written;
-+      cryptcompress_info_t *info = cryptcompress_inode_data(inode);
-+
-+      assert("edward-196", crc_inode_ok(inode));
-+
-+      result = generic_write_checks(file, off, &count, 0);
-+      if (unlikely(result != 0))
-+              return result;
-+
-+      if (unlikely(count == 0))
-+              return 0;
-+
-+      down_write(&info->lock);
-+      LOCK_CNT_INC(inode_sem_w);
-+
-+      pos = *off;
-+      written =
-+          write_cryptcompress_flow(file, inode, buf, count, pos);
-+
-+      up_write(&info->lock);
-+      LOCK_CNT_DEC(inode_sem_w);
-+
-+      if (written < 0) {
-+              if (written == -EEXIST)
-+                      printk("write_crc_file returns EEXIST!\n");
-+              return written;
-+      }
-+      /* update position in a file */
-+      *off = pos + written;
-+      /* return number of written bytes */
-+      return written;
-+}
-+
 +/**
 + * write_cryptcompress - write of struct file_operations
 + * @file: file to write to
@@ -34092,22 +33604,45 @@ Index: linux-2.6.16/fs/reiser4/plugin/file/cryptcompress.c
 + * cryptcompress plugin.
 + */
 +ssize_t write_cryptcompress(struct file *file, const char __user *buf,
-+                          size_t count, loff_t *off)
++                          size_t count, loff_t *off, int *conv)
 +{
 +      ssize_t result;
 +      struct inode *inode;
 +      reiser4_context *ctx;
++      loff_t pos = *off;
++      struct cryptcompress_info *info;
++
++      assert("edward-1449", *conv == 0);
 +
 +      inode = file->f_dentry->d_inode;
++      assert("edward-196", cryptcompress_inode_ok(inode));
++
++      info = cryptcompress_inode_data(inode);
 +
-+      ctx = init_context(inode->i_sb);
++      ctx = reiser4_init_context(inode->i_sb);
 +      if (IS_ERR(ctx))
 +              return PTR_ERR(ctx);
 +
-+      mutex_lock(&inode->i_mutex);
++      mutex_lock(&inode->i_mutex);
++
++      result = generic_write_checks(file, &pos, &count, 0);
++      if (unlikely(result != 0))
++              goto out;
++      if (unlikely(count == 0))
++              goto out;
++      result = remove_suid(file->f_dentry);
++      if (unlikely(result != 0))
++              goto out;
++      /* remove_suid might create a transaction */
++      reiser4_txn_restart(ctx);
 +
-+      result = write_crc_file(file, inode, buf, count, off);
++      result = do_write_cryptcompress(file, inode, buf, count, pos, conv);
 +
++      if (result < 0)
++              goto out;
++      /* update position in a file */
++      *off = pos + result;
++ out:
 +      mutex_unlock(&inode->i_mutex);
 +
 +      context_set_commit_async(ctx);
@@ -34115,23 +33650,26 @@ Index: linux-2.6.16/fs/reiser4/plugin/file/cryptcompress.c
 +      return result;
 +}
 +
-+static void
-+readpages_crc(struct address_space *mapping, struct list_head *pages,
-+            void *data)
++int readpages_cryptcompress(struct file *file, struct address_space *mapping,
++                          struct list_head *pages, unsigned nr_pages)
 +{
-+      file_plugin *fplug;
-+      item_plugin *iplug;
-+
-+      assert("edward-1112", mapping != NULL);
-+      assert("edward-1113", mapping->host != NULL);
-+
-+      fplug = inode_file_plugin(mapping->host);
-+      assert("edward-1114", fplug == file_plugin_by_id(CRC_FILE_PLUGIN_ID));
-+      iplug = item_plugin_by_id(CTAIL_ID);
-+
-+      iplug->s.file.readpages(data, mapping, pages);
++      reiser4_context * ctx;
++      int ret;
 +
-+      return;
++      ctx = reiser4_init_context(mapping->host->i_sb);
++      if (IS_ERR(ctx)) {
++              ret = PTR_ERR(ctx);
++              goto err;
++      }
++      /* cryptcompress file can be built of ctail items only */
++      ret = readpages_ctail(file, mapping, pages);
++      reiser4_txn_restart(ctx);
++      reiser4_exit_context(ctx);
++      if (ret) {
++err:
++              put_pages_list(pages);
++      }
++      return ret;
 +}
 +
 +static reiser4_block_nr cryptcompress_estimate_read(struct inode *inode)
@@ -34159,38 +33697,25 @@ Index: linux-2.6.16/fs/reiser4/plugin/file/cryptcompress.c
 +      ssize_t result;
 +      struct inode *inode;
 +      reiser4_context *ctx;
-+      reiser4_file_fsdata *fsdata;
-+      cryptcompress_info_t *info;
++      struct cryptcompress_info *info;
 +      reiser4_block_nr needed;
 +
 +      inode = file->f_dentry->d_inode;
-+      assert("edward-1194", !inode_get_flag(inode, REISER4_NO_SD));
++      assert("edward-1194", !reiser4_inode_get_flag(inode, REISER4_NO_SD));
 +
-+      ctx = init_context(inode->i_sb);
++      ctx = reiser4_init_context(inode->i_sb);
 +      if (IS_ERR(ctx))
 +              return PTR_ERR(ctx);
 +
 +      info = cryptcompress_inode_data(inode);
 +      needed = cryptcompress_estimate_read(inode);
 +
-+      /* FIXME-EDWARD:
-+         Grab space for sd_update so find_cluster will be happy */
 +      result = reiser4_grab_space(needed, BA_CAN_COMMIT);
 +      if (result != 0) {
 +              reiser4_exit_context(ctx);
 +              return result;
 +      }
-+      fsdata = reiser4_get_file_fsdata(file);
-+      fsdata->ra2.data = file;
-+      fsdata->ra2.readpages = readpages_crc;
-+
-+      down_read(&info->lock);
-+      LOCK_CNT_INC(inode_sem_r);
-+
-+      result = generic_file_read(file, buf, size, off);
-+
-+      up_read(&info->lock);
-+      LOCK_CNT_DEC(inode_sem_r);
++      result = do_sync_read(file, buf, size, off);
 +
 +      context_set_commit_async(ctx);
 +      reiser4_exit_context(ctx);
@@ -34198,17 +33723,15 @@ Index: linux-2.6.16/fs/reiser4/plugin/file/cryptcompress.c
 +      return result;
 +}
 +
-+/* If @index > 0, find real disk cluster of the index (@index - 1),
-+   If @index == 0 find the real disk cluster of the object of maximal index.
-+   Keep incremented index of the result in @found.
-+   It succes was returned:
-+   (@index == 0 && @found == 0) means that the object doesn't have real disk
-+   clusters.
-+   (@index != 0 && @found == 0) means that disk cluster of (@index -1) doesn't
-+   exist.
-+*/
-+static int
-+find_real_disk_cluster(struct inode *inode, cloff_t * found, cloff_t index)
++/* Look for a disk cluster and keep lookup result in @found.
++ * If @index > 0, then find disk cluster of the index (@index - 1);
++ * If @index == 0, then find the rightmost disk cluster.
++ * Keep incremented index of the found disk cluster in @found.
++ * @found == 0 means that disk cluster was not found (in the last
++ * case (@index == 0) it means that file doesn't have disk clusters).
++ */
++static int lookup_disk_cluster(struct inode *inode, cloff_t * found,
++                             cloff_t index)
 +{
 +      int result;
 +      reiser4_key key;
@@ -34220,9 +33743,9 @@ Index: linux-2.6.16/fs/reiser4/plugin/file/cryptcompress.c
 +      item_plugin *iplug;
 +
 +      assert("edward-1131", inode != NULL);
-+      assert("edward-95", crc_inode_ok(inode));
++      assert("edward-95", cryptcompress_inode_ok(inode));
 +
-+      hint = kmalloc(sizeof(*hint), GFP_KERNEL);
++      hint = kmalloc(sizeof(*hint), reiser4_ctx_gfp_mask_get());
 +      if (hint == NULL)
 +              return RETERR(-ENOMEM);
 +      hint_init_zero(hint);
@@ -34231,7 +33754,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/file/cryptcompress.c
 +      bias = (index ? FIND_EXACT : FIND_MAX_NOT_MORE_THAN);
 +      offset =
 +          (index ? clust_to_off(index, inode) -
-+           1 : get_key_offset(max_key()));
++           1 : get_key_offset(reiser4_max_key()));
 +
 +      key_by_inode_cryptcompress(inode, offset, &key);
 +
@@ -34277,8 +33800,8 @@ Index: linux-2.6.16/fs/reiser4/plugin/file/cryptcompress.c
 +
 +static int find_fake_appended(struct inode *inode, cloff_t * index)
 +{
-+      return find_real_disk_cluster(inode, index,
-+                                    0 /* find last real one */ );
++      return lookup_disk_cluster(inode, index,
++                                 0 /* find last real one */ );
 +}
 +
 +/* Set left coord when unit is not found after node_lookup()
@@ -34300,11 +33823,11 @@ Index: linux-2.6.16/fs/reiser4/plugin/file/cryptcompress.c
 +}
 +
 +#define CRC_CUT_TREE_MIN_ITERATIONS 64
-+int
-+cut_tree_worker_cryptcompress(tap_t * tap, const reiser4_key * from_key,
-+                            const reiser4_key * to_key,
-+                            reiser4_key * smallest_removed,
-+                            struct inode *object, int truncate, int *progress)
++int cut_tree_worker_cryptcompress(tap_t * tap, const reiser4_key * from_key,
++                                const reiser4_key * to_key,
++                                reiser4_key * smallest_removed,
++                                struct inode *object, int truncate,
++                                int *progress)
 +{
 +      lock_handle next_node_lock;
 +      coord_t left_coord;
@@ -34331,7 +33854,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/file/cryptcompress.c
 +              if (result != 0 && result != -E_NO_NEIGHBOR)
 +                      break;
 +              /* FIXME-EDWARD: Check can we delete the node as a whole. */
-+              result = tap_load(tap);
++              result = reiser4_tap_load(tap);
 +              if (result)
 +                      return result;
 +
@@ -34372,7 +33895,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/file/cryptcompress.c
 +              }
 +
 +              /* cut data from one node */
-+              *smallest_removed = *min_key();
++              *smallest_removed = *reiser4_min_key();
 +              result = kill_node_content(&left_coord,
 +                                         tap->coord,
 +                                         from_key,
@@ -34380,10 +33903,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/file/cryptcompress.c
 +                                         smallest_removed,
 +                                         next_node_lock.node,
 +                                         object, truncate);
-+#if REISER4_DEBUG
-+              /*node_check(node, ~0U); */
-+#endif
-+              tap_relse(tap);
++              reiser4_tap_relse(tap);
 +
 +              if (result)
 +                      break;
@@ -34399,7 +33919,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/file/cryptcompress.c
 +              if (next_node_lock.node == NULL)
 +                      break;
 +
-+              result = tap_move(tap, &next_node_lock);
++              result = reiser4_tap_move(tap, &next_node_lock);
 +              done_lh(&next_node_lock);
 +              if (result)
 +                      break;
@@ -34416,28 +33936,29 @@ Index: linux-2.6.16/fs/reiser4/plugin/file/cryptcompress.c
 +      return result;
 +}
 +
-+/* Append or expand hole in two steps (exclusive access should be aquired!)
-+   1) write zeroes to the current real cluster,
-+   2) expand hole via fake clusters (just increase i_size) */
-+static int
-+cryptcompress_append_hole(struct inode *inode /*contains old i_size */ ,
-+                        loff_t new_size)
++/* Append or expand hole in two steps:
++ * 1) set zeroes to the rightmost page of the rightmost non-fake
++ *    logical cluster;
++ * 2) expand hole via fake logical clusters (just increase i_size)
++ */
++static int cryptcompress_append_hole(struct inode *inode /* with old size */,
++                                   loff_t new_size)
 +{
 +      int result = 0;
 +      hint_t *hint;
 +      lock_handle *lh;
 +      loff_t hole_size;
 +      int nr_zeroes;
-+      reiser4_slide_t win;
-+      reiser4_cluster_t clust;
++      struct reiser4_slide win;
++      struct cluster_handle clust;
 +
 +      assert("edward-1133", inode->i_size < new_size);
-+      assert("edward-1134", schedulable());
-+      assert("edward-1135", crc_inode_ok(inode));
++      assert("edward-1134", reiser4_schedulable());
++      assert("edward-1135", cryptcompress_inode_ok(inode));
 +      assert("edward-1136", current_blocksize == PAGE_CACHE_SIZE);
 +      assert("edward-1333", off_to_cloff(inode->i_size, inode) != 0);
 +
-+      hint = kmalloc(sizeof(*hint), GFP_KERNEL);
++      hint = kmalloc(sizeof(*hint), reiser4_ctx_gfp_mask_get());
 +      if (hint == NULL)
 +              return RETERR(-ENOMEM);
 +      hint_init_zero(hint);
@@ -34451,9 +33972,9 @@ Index: linux-2.6.16/fs/reiser4/plugin/file/cryptcompress.c
 +      if (result)
 +              goto out;
 +      if (off_to_cloff(inode->i_size, inode) == 0)
-+              goto fake_append;
++              goto append_fake;
 +      hole_size = new_size - inode->i_size;
-+      nr_zeroes = 
++      nr_zeroes =
 +              inode_cluster_size(inode) - off_to_cloff(inode->i_size, inode);
 +      if (hole_size < nr_zeroes)
 +              nr_zeroes = hole_size;
@@ -34464,7 +33985,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/file/cryptcompress.c
 +      assert("edward-1137",
 +             clust.index == off_to_clust(inode->i_size, inode));
 +
-+      result = prepare_cluster(inode, 0, 0, &clust, PCL_APPEND);
++      result = prepare_logical_cluster(inode, 0, 0, &clust, LC_APPOV);
 +
 +      assert("edward-1271", !result || result == -ENOSPC);
 +      if (result)
@@ -34477,73 +33998,32 @@ Index: linux-2.6.16/fs/reiser4/plugin/file/cryptcompress.c
 +      if (hole_size == nr_zeroes)
 +      /* nothing to append anymore */
 +              goto out;
-+      fake_append:
-+      INODE_SET_FIELD(inode, i_size, new_size);
-+      out:
++ append_fake:
++      INODE_SET_SIZE(inode, new_size);
++ out:
 +      done_lh(lh);
 +      kfree(hint);
 +      put_cluster_handle(&clust);
 +      return result;
 +}
 +
-+#if REISER4_DEBUG
-+static int
-+pages_truncate_ok(struct inode *inode, loff_t old_size, pgoff_t start)
-+{
-+      struct pagevec pvec;
-+      int i;
-+      int count;
-+      int rest;
-+
-+      rest = count_to_nrpages(old_size) - start;
-+
-+      pagevec_init(&pvec, 0);
-+      count = min_count(pagevec_space(&pvec), rest);
-+
-+      while (rest) {
-+              count = min_count(pagevec_space(&pvec), rest);
-+              pvec.nr = find_get_pages(inode->i_mapping, start,
-+                                       count, pvec.pages);
-+              for (i = 0; i < pagevec_count(&pvec); i++) {
-+                      if (PageUptodate(pvec.pages[i])) {
-+                              warning("edward-1205",
-+                                      "truncated page of index %lu is uptodate",
-+                                      pvec.pages[i]->index);
-+                              return 0;
-+                      }
-+              }
-+              start += count;
-+              rest -= count;
-+              pagevec_release(&pvec);
-+      }
-+      return 1;
-+}
-+
-+static int body_truncate_ok(struct inode *inode, cloff_t aidx)
-+{
-+      int result;
-+      cloff_t raidx;
-+
-+      result = find_fake_appended(inode, &raidx);
-+      return !result && (aidx == raidx);
-+}
-+#endif
-+
 +static int
 +update_cryptcompress_size(struct inode *inode, reiser4_key * key, int update_sd)
 +{
 +      return (get_key_offset(key) & ((loff_t) (inode_cluster_size(inode)) - 1)
-+              ? 0 : update_file_size(inode, key, update_sd));
++              ? 0 : reiser4_update_file_size(inode, key, update_sd));
 +}
 +
-+/* prune cryptcompress file in two steps (exclusive access should be acquired!)
-+   1) cut all disk clusters but the last one partially truncated,
-+   2) set zeroes and capture last partially truncated page cluster if the last
-+      one exists, otherwise truncate via prune fake cluster (just decrease i_size)
-+*/
-+static int
-+prune_cryptcompress(struct inode *inode, loff_t new_size, int update_sd,
-+                  cloff_t aidx)
++/* Prune cryptcompress file in two steps:
++ * 1) cut all nominated logical clusters except the leftmost one which
++ *    is to be partially truncated. Note, that there can be "holes"
++ *    represented by fake logical clusters.
++ * 2) set zeroes and capture leftmost partially truncated logical
++ *    cluster, if it is not fake; otherwise prune fake logical cluster
++ *    (just decrease i_size).
++ */
++static int prune_cryptcompress(struct inode *inode, loff_t new_size,
++                             int update_sd, cloff_t aidx)
 +{
 +      int result = 0;
 +      unsigned nr_zeroes;
@@ -34553,15 +34033,17 @@ Index: linux-2.6.16/fs/reiser4/plugin/file/cryptcompress.c
 +
 +      hint_t *hint;
 +      lock_handle *lh;
-+      reiser4_slide_t win;
-+      reiser4_cluster_t clust;
++      struct reiser4_slide win;
++      struct cluster_handle clust;
 +
 +      assert("edward-1140", inode->i_size >= new_size);
-+      assert("edward-1141", schedulable());
-+      assert("edward-1142", crc_inode_ok(inode));
++      assert("edward-1141", reiser4_schedulable());
++      assert("edward-1142", cryptcompress_inode_ok(inode));
 +      assert("edward-1143", current_blocksize == PAGE_CACHE_SIZE);
 +
-+      hint = kmalloc(sizeof(*hint), GFP_KERNEL);
++      old_size = inode->i_size;
++
++      hint = kmalloc(sizeof(*hint), reiser4_ctx_gfp_mask_get());
 +      if (hint == NULL)
 +              return RETERR(-ENOMEM);
 +      hint_init_zero(hint);
@@ -34571,42 +34053,55 @@ Index: linux-2.6.16/fs/reiser4/plugin/file/cryptcompress.c
 +      cluster_init_read(&clust, &win);
 +      clust.hint = hint;
 +
-+      /* rightmost completely truncated cluster */
-+      ridx = count_to_nrclust(new_size, inode);
++      /* calculate index of the rightmost logical cluster
++         that will be completely truncated */
++      ridx = size_in_lc(new_size, inode);
 +
++      /* truncate all disk clusters starting from @ridx */
 +      assert("edward-1174", ridx <= aidx);
 +      old_size = inode->i_size;
 +      if (ridx != aidx) {
++              struct cryptcompress_info * info;
++              info = cryptcompress_inode_data(inode);
 +              result = cut_file_items(inode,
 +                                      clust_to_off(ridx, inode),
 +                                      update_sd,
 +                                      clust_to_off(aidx, inode),
 +                                      update_cryptcompress_size);
++              info->trunc_index = ULONG_MAX;
 +              if (result)
 +                      goto out;
 +      }
++      /*
++       * there can be pages of fake logical clusters, truncate them
++       */
++      truncate_inode_pages(inode->i_mapping, clust_to_off(ridx, inode));
++      assert("edward-1524",
++             pages_truncate_ok(inode, clust_to_pg(ridx, inode)));
++      /*
++       * now perform partial truncate of last logical cluster
++       */
 +      if (!off_to_cloff(new_size, inode)) {
-+              /* no partially truncated clusters */
++              /* no partial truncate is needed */
 +              assert("edward-1145", inode->i_size == new_size);
-+              goto finish;
++              goto truncate_fake;
 +      }
 +      assert("edward-1146", new_size < inode->i_size);
 +
 +      to_prune = inode->i_size - new_size;
 +
-+      /* partial truncate of leftmost cluster, 
-+         first check if it is fake */
-+      result = find_real_disk_cluster(inode, &aidx, ridx);
++      /* check if the last logical cluster is fake */
++      result = lookup_disk_cluster(inode, &aidx, ridx);
 +      if (result)
 +              goto out;
 +      if (!aidx)
 +              /* yup, this is fake one */
-+              goto finish;
++              goto truncate_fake;
 +
 +      assert("edward-1148", aidx == ridx);
 +
-+      /* do partial truncate of the leftmost page cluster,
-+         then try to capture this one */
++      /* do partial truncate of the last page cluster,
++         and try to capture this one */
 +      result = alloc_cluster_pgset(&clust, cluster_nrpages(inode));
 +      if (result)
 +              goto out;
@@ -34617,7 +34112,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/file/cryptcompress.c
 +
 +      assert("edward-1149", clust.index == ridx - 1);
 +
-+      result = prepare_cluster(inode, 0, 0, &clust, PCL_TRUNCATE);
++      result = prepare_logical_cluster(inode, 0, 0, &clust, LC_TRUNC);
 +      if (result)
 +              goto out;
 +      assert("edward-1151",
@@ -34626,18 +34121,19 @@ Index: linux-2.6.16/fs/reiser4/plugin/file/cryptcompress.c
 +
 +      assert("edward-1191", inode->i_size == new_size);
 +      assert("edward-1206", body_truncate_ok(inode, ridx));
-+      finish:
++ truncate_fake:
 +      /* drop all the pages that don't have jnodes (i.e. pages
 +         which can not be truncated by cut_file_items() because
 +         of holes represented by fake disk clusters) including
 +         the pages of partially truncated cluster which was
-+         released by prepare_cluster() */
++         released by prepare_logical_cluster() */
++      INODE_SET_SIZE(inode, new_size);
 +      truncate_inode_pages(inode->i_mapping, new_size);
-+      INODE_SET_FIELD(inode, i_size, new_size);
-+      out:
++ out:
 +      assert("edward-1334", !result || result == -ENOSPC);
-+      assert("edward-1209",
-+             pages_truncate_ok(inode, old_size, count_to_nrpages(new_size)));
++      assert("edward-1497",
++             pages_truncate_ok(inode, size_in_pages(new_size)));
++
 +      done_lh(lh);
 +      kfree(hint);
 +      put_cluster_handle(&clust);
@@ -34645,11 +34141,10 @@ Index: linux-2.6.16/fs/reiser4/plugin/file/cryptcompress.c
 +}
 +
 +/* Prepare cryptcompress file for truncate:
-+   prune or append rightmost fake logical clusters (if any)
-+*/
-+static int
-+start_truncate_fake(struct inode *inode, cloff_t aidx, loff_t new_size,
-+                  int update_sd)
++ * prune or append rightmost fake logical clusters (if any)
++ */
++static int start_truncate_fake(struct inode *inode, cloff_t aidx,
++                             loff_t new_size, int update_sd)
 +{
 +      int result = 0;
 +      int bytes;
@@ -34660,18 +34155,17 @@ Index: linux-2.6.16/fs/reiser4/plugin/file/cryptcompress.c
 +                      /* no fake bytes */
 +                      return 0;
 +              bytes = new_size - inode->i_size;
-+              INODE_SET_FIELD(inode, i_size, inode->i_size + bytes);
++              INODE_SET_SIZE(inode, inode->i_size + bytes);
 +      } else {
 +              /* prune */
 +              if (inode->i_size <= clust_to_off(aidx, inode))
 +                      /* no fake bytes */
 +                      return 0;
-+              bytes =
-+                  inode->i_size - max_count(new_size,
-+                                            clust_to_off(aidx, inode));
++              bytes = inode->i_size -
++                      max(new_size, clust_to_off(aidx, inode));
 +              if (!bytes)
 +                      return 0;
-+              INODE_SET_FIELD(inode, i_size, inode->i_size - bytes);
++              INODE_SET_SIZE(inode, inode->i_size - bytes);
 +              /* In the case of fake prune we need to drop page cluster.
 +                 There are only 2 cases for partially truncated page:
 +                 1. If is is dirty, therefore it is anonymous
@@ -34689,7 +34183,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/file/cryptcompress.c
 +}
 +
 +/* This is called in setattr_cryptcompress when it is used to truncate,
-+   and in delete_cryptcompress */
++ * and in delete_cryptcompress */
 +static int cryptcompress_truncate(struct inode *inode,        /* old size */
 +                                loff_t new_size,      /* new size */
 +                                int update_sd)
@@ -34709,31 +34203,19 @@ Index: linux-2.6.16/fs/reiser4/plugin/file/cryptcompress.c
 +      if (inode->i_size == new_size)
 +              /* nothing to truncate anymore */
 +              return 0;
-+      return (inode->i_size < new_size ?
-+              cryptcompress_append_hole(inode, new_size) :
-+              prune_cryptcompress(inode, new_size, update_sd, aidx));
-+}
-+
-+static void clear_moved_tag_cluster(struct address_space * mapping,
-+                                  reiser4_cluster_t * clust)
-+{
-+      int i;
-+      void * ret;
-+      read_lock_irq(&mapping->tree_lock);
-+      for (i = 0; i < clust->nr_pages; i++) {
-+              assert("edward-1438", clust->pages[i] != NULL);
-+              ret = radix_tree_tag_clear(&mapping->page_tree, 
-+                                         clust->pages[i]->index,
-+                                         PAGECACHE_TAG_REISER4_MOVED);
-+              assert("edward-1439", ret == clust->pages[i]);
-+      }
-+      read_unlock_irq(&mapping->tree_lock);
++      result = (inode->i_size < new_size ?
++                cryptcompress_append_hole(inode, new_size) :
++                prune_cryptcompress(inode, new_size, update_sd, aidx));
++      if (!result && update_sd)
++              result = update_sd_cryptcompress(inode);
++      return result;
 +}
 +
 +/* Capture an anonymous pager cluster. (Page cluser is
-+   anonymous if it contains at least one anonymous page */
-+static int
-+capture_page_cluster(reiser4_cluster_t * clust, struct inode *inode)
++ * anonymous if it contains at least one anonymous page
++ */
++static int capture_anon_page_cluster(struct cluster_handle * clust,
++                                   struct inode * inode)
 +{
 +      int result;
 +
@@ -34741,48 +34223,72 @@ Index: linux-2.6.16/fs/reiser4/plugin/file/cryptcompress.c
 +      assert("edward-1074", inode != NULL);
 +      assert("edward-1075", clust->dstat == INVAL_DISK_CLUSTER);
 +
-+      result = prepare_cluster(inode, 0, 0, clust, PCL_APPEND);
++      result = prepare_logical_cluster(inode, 0, 0, clust, LC_APPOV);
 +      if (result)
 +              return result;
-+      set_cluster_pages_dirty(clust);
-+      clear_moved_tag_cluster(inode->i_mapping, clust);
-+
-+      result = try_capture_cluster(clust, inode);
++      set_cluster_pages_dirty(clust, inode);
++      result = checkin_logical_cluster(clust, inode);
 +      put_hint_cluster(clust, inode, ZNODE_WRITE_LOCK);
-+      if (unlikely(result)) {
-+              /* set cleared tag back, so it will be
-+                 possible to capture it again later */
-+              read_lock_irq(&inode->i_mapping->tree_lock);
-+              radix_tree_tag_set(&inode->i_mapping->page_tree,
-+                                 clust_to_pg(clust->index, inode),
-+                                 PAGECACHE_TAG_REISER4_MOVED);
-+              read_unlock_irq(&inode->i_mapping->tree_lock);
-+              
-+              release_cluster_pages_and_jnode(clust);
-+      }
++      if (unlikely(result))
++              put_page_cluster(clust, inode, WRITE_OP);
 +      return result;
 +}
 +
-+#define MAX_CLUSTERS_TO_CAPTURE(inode)    (1024 >> cluster_nrpages_shift(inode))
++/* Starting from @index find tagged pages of the same page cluster.
++ * Clear the tag for each of them. Return number of found pages.
++ */
++static int find_anon_page_cluster(struct address_space * mapping,
++                                pgoff_t * index, struct page ** pages)
++{
++      int i = 0;
++      int found;
++      write_lock_irq(&mapping->tree_lock);
++      do {
++              /* looking for one page */
++              found = radix_tree_gang_lookup_tag(&mapping->page_tree,
++                                                 (void **)&pages[i],
++                                                 *index, 1,
++                                                 PAGECACHE_TAG_REISER4_MOVED);
++              if (!found)
++                      break;
++              if (!same_page_cluster(pages[0], pages[i]))
++                      break;
 +
-+/* read lock should be acquired */
-+static int
-+capture_anonymous_clusters(struct address_space *mapping, pgoff_t * index,
-+                         int to_capture)
++              /* found */
++              page_cache_get(pages[i]);
++              *index = pages[i]->index + 1;
++
++              radix_tree_tag_clear(&mapping->page_tree,
++                                   pages[i]->index,
++                                   PAGECACHE_TAG_REISER4_MOVED);
++              if (last_page_in_cluster(pages[i++]))
++                      break;
++      } while (1);
++      write_unlock_irq(&mapping->tree_lock);
++      return i;
++}
++
++#define MAX_PAGES_TO_CAPTURE  (1024)
++
++/* Capture anonymous page clusters */
++static int capture_anon_pages(struct address_space * mapping, pgoff_t * index,
++                            int to_capture)
 +{
++      int count = 0;
++      int found = 0;
 +      int result = 0;
-+      int found;
-+      int progress = 0;
-+      struct page *page = NULL;
 +      hint_t *hint;
 +      lock_handle *lh;
-+      reiser4_cluster_t clust;
++      struct inode * inode;
++      struct cluster_handle clust;
++      struct page * pages[MAX_CLUSTER_NRPAGES];
 +
 +      assert("edward-1127", mapping != NULL);
 +      assert("edward-1128", mapping->host != NULL);
-+      assert("edward-1440",  mapping->host->i_mapping == mapping);
++      assert("edward-1440", mapping->host->i_mapping == mapping);
 +
-+      hint = kmalloc(sizeof(*hint), GFP_KERNEL);
++      inode = mapping->host;
++      hint = kmalloc(sizeof(*hint), reiser4_ctx_gfp_mask_get());
 +      if (hint == NULL)
 +              return RETERR(-ENOMEM);
 +      hint_init_zero(hint);
@@ -34791,41 +34297,35 @@ Index: linux-2.6.16/fs/reiser4/plugin/file/cryptcompress.c
 +      cluster_init_read(&clust, NULL);
 +      clust.hint = hint;
 +
-+      result = alloc_cluster_pgset(&clust, cluster_nrpages(mapping->host));
++      result = alloc_cluster_pgset(&clust, cluster_nrpages(inode));
 +      if (result)
 +              goto out;
 +
 +      while (to_capture > 0) {
-+              found =
-+                  find_get_pages_tag(mapping, index,
-+                                     PAGECACHE_TAG_REISER4_MOVED, 1, &page);
++              found = find_anon_page_cluster(mapping, index, pages);
 +              if (!found) {
 +                      *index = (pgoff_t) - 1;
 +                      break;
 +              }
-+              assert("edward-1109", page != NULL);
++              move_cluster_forward(&clust, inode, pages[0]->index);
++              result = capture_anon_page_cluster(&clust, inode);
 +
-+              move_cluster_forward(&clust, mapping->host, page->index,
-+                                   &progress);
-+              result = capture_page_cluster(&clust, mapping->host);
-+              page_cache_release(page);
++              put_found_pages(pages, found); /* find_anon_page_cluster */
 +              if (result)
 +                      break;
-+              to_capture--;
++              to_capture -= clust.nr_pages;
++              count += clust.nr_pages;
 +      }
 +      if (result) {
 +              warning("edward-1077",
-+                      "Cannot capture anon pages: result=%i (captured=%d)\n",
-+                      result,
-+                      ((__u32) MAX_CLUSTERS_TO_CAPTURE(mapping->host)) -
-+                      to_capture);
++                      "Capture failed (inode %llu, result=%i, captured=%d)\n",
++                      (unsigned long long)get_inode_oid(inode), result, count);
 +      } else {
-+              /* something had to be found */
-+              assert("edward-1078",
-+                     to_capture <= MAX_CLUSTERS_TO_CAPTURE(mapping->host));
++              assert("edward-1078", ergo(found > 0, count > 0));
 +              if (to_capture <= 0)
 +                      /* there may be left more pages */
-+                      __mark_inode_dirty(mapping->host, I_DIRTY_PAGES);
++                      __mark_inode_dirty(inode, I_DIRTY_PAGES);
++              result = count;
 +      }
 +      out:
 +      done_lh(lh);
@@ -34834,91 +34334,90 @@ Index: linux-2.6.16/fs/reiser4/plugin/file/cryptcompress.c
 +      return result;
 +}
 +
-+/* Check mapping for existence of not captured dirty pages.
-+   This returns !0 if either page tree contains pages tagged
-+   PAGECACHE_TAG_REISER4_MOVED */
-+static int crc_inode_has_anon_pages(struct inode *inode)
++/* Returns true if inode's mapping has dirty pages
++   which do not belong to any atom */
++static int cryptcompress_inode_has_anon_pages(struct inode *inode)
 +{
-+      return mapping_tagged(inode->i_mapping, PAGECACHE_TAG_REISER4_MOVED);
++      int result;
++      read_lock_irq(&inode->i_mapping->tree_lock);
++      result = radix_tree_tagged(&inode->i_mapping->page_tree,
++                                 PAGECACHE_TAG_REISER4_MOVED);
++      read_unlock_irq(&inode->i_mapping->tree_lock);
++      return result;
 +}
 +
-+/* this is implementation of vfs's writepages method of struct
++/* This is implementation of vfs's writepages method of struct
 +   address_space_operations */
-+int
-+writepages_cryptcompress(struct address_space *mapping,
-+                       struct writeback_control *wbc)
++int writepages_cryptcompress(struct address_space *mapping,
++                           struct writeback_control *wbc)
 +{
-+      int result;
-+      int to_capture;
++      int result = 0;
++      long to_capture;
 +      pgoff_t nrpages;
 +      pgoff_t index = 0;
-+      cryptcompress_info_t *info;
 +      struct inode *inode;
++      struct cryptcompress_info *info;
 +
 +      inode = mapping->host;
-+      if (!crc_inode_has_anon_pages(inode)) {
-+              result = 0;
++      if (!cryptcompress_inode_has_anon_pages(inode))
 +              goto end;
-+      }
-+
 +      info = cryptcompress_inode_data(inode);
-+      nrpages = count_to_nrpages(i_size_read(inode));
++      nrpages = size_in_pages(i_size_read(inode));
 +
 +      if (wbc->sync_mode != WB_SYNC_ALL)
-+              to_capture =
-+                  min_count(wbc->nr_to_write, MAX_CLUSTERS_TO_CAPTURE(inode));
++              to_capture = min(wbc->nr_to_write, (long)MAX_PAGES_TO_CAPTURE);
 +      else
-+              to_capture = MAX_CLUSTERS_TO_CAPTURE(inode);
++              to_capture = MAX_PAGES_TO_CAPTURE;
 +      do {
 +              reiser4_context *ctx;
 +
-+              if (is_in_reiser4_context()) {
-+                      /* FIXME-EDWARD: REMOVEME */
-+                      all_grabbed2free();
-+
-+                      /* It can be in the context of write system call from
-+                         balance_dirty_pages() */
-+                      if (down_read_trylock(&info->lock) == 0) {
-+                              result = RETERR(-EBUSY);
-+                              break;
-+                      }
-+              } else
-+                      down_read(&info->lock);
-+
-+              ctx = init_context(inode->i_sb);
++              ctx = reiser4_init_context(inode->i_sb);
 +              if (IS_ERR(ctx)) {
 +                      result = PTR_ERR(ctx);
 +                      break;
 +              }
++              /* avoid recursive calls to ->sync_inodes */
 +              ctx->nobalance = 1;
 +
 +              assert("edward-1079",
 +                     lock_stack_isclean(get_current_lock_stack()));
 +
-+              LOCK_CNT_INC(inode_sem_r);
-+
-+              result =
-+                  capture_anonymous_clusters(inode->i_mapping, &index,
-+                                             to_capture);
++              reiser4_txn_restart_current();
 +
-+              up_read(&info->lock);
++              if (get_current_context()->entd) {
++                      if (mutex_trylock(&info->checkin_mutex) == 0) {
++                              /* the mutex might be occupied by
++                                 entd caller */
++                              result = RETERR(-EBUSY);
++                              reiser4_exit_context(ctx);
++                              break;
++                      }
++              } else
++                      mutex_lock(&info->checkin_mutex);
 +
-+              LOCK_CNT_DEC(inode_sem_r);
++              result = capture_anon_pages(inode->i_mapping, &index,
++                                          to_capture);
++              mutex_unlock(&info->checkin_mutex);
 +
-+              if (result != 0 || wbc->sync_mode != WB_SYNC_ALL) {
++              if (result < 0) {
++                      reiser4_exit_context(ctx);
++                      break;
++              }
++              wbc->nr_to_write -= result;
++              if (wbc->sync_mode != WB_SYNC_ALL) {
 +                      reiser4_exit_context(ctx);
 +                      break;
 +              }
 +              result = txnmgr_force_commit_all(inode->i_sb, 0);
 +              reiser4_exit_context(ctx);
-+      } while (result == 0 && index < nrpages);
++      } while (result >= 0 && index < nrpages);
 +
-+      end:
++ end:
 +      if (is_in_reiser4_context()) {
 +              if (get_current_context()->nr_captured >= CAPTURE_APAGE_BURST) {
-+                      /* there are already pages to flush, flush them out, do
-+                         not delay until end of reiser4_sync_inodes */
-+                      writeout(inode->i_sb, wbc);
++                      /* there are already pages to flush, flush them out,
++                         do not delay until end of reiser4_sync_inodes */
++                      reiser4_writeout(inode->i_sb, wbc);
 +                      get_current_context()->nr_captured = 0;
 +              }
 +      }
@@ -34928,104 +34427,104 @@ Index: linux-2.6.16/fs/reiser4/plugin/file/cryptcompress.c
 +/* plugin->u.file.mmap */
 +int mmap_cryptcompress(struct file *file, struct vm_area_struct *vma)
 +{
-+      //return -ENOSYS;
-+      return generic_file_mmap(file, vma);
++      int result;
++      struct inode *inode;
++      reiser4_context *ctx;
++
++      inode = file->f_dentry->d_inode;
++      ctx = reiser4_init_context(inode->i_sb);
++      if (IS_ERR(ctx))
++              return PTR_ERR(ctx);
++      /*
++       * generic_file_mmap will do update_atime. Grab space for stat data
++       * update.
++       */
++      result = reiser4_grab_space_force
++              (inode_file_plugin(inode)->estimate.update(inode),
++               BA_CAN_COMMIT);
++      if (result) {
++              reiser4_exit_context(ctx);
++              return result;
++      }
++      result = generic_file_mmap(file, vma);
++      reiser4_exit_context(ctx);
++      return result;
 +}
 +
 +/* plugin->u.file.release */
 +/* plugin->u.file.get_block */
 +
 +/* this is implementation of delete method of file plugin for
-+   cryptcompress objects */
-+int delete_cryptcompress(struct inode *inode)
++ * cryptcompress objects
++ */
++int delete_object_cryptcompress(struct inode *inode)
 +{
 +      int result;
++      struct cryptcompress_info * info;
 +
 +      assert("edward-429", inode->i_nlink == 0);
 +
-+      if (inode->i_size) {
-+              result = cryptcompress_truncate(inode, 0, 0);
-+              if (result) {
-+                      warning("edward-430",
-+                              "cannot truncate cryptcompress file  %lli: %i",
-+                              (unsigned long long)get_inode_oid(inode),
-+                              result);
-+                      return result;
-+              }
++      reiser4_txn_restart_current();
++      info = cryptcompress_inode_data(inode);
++
++      mutex_lock(&info->checkin_mutex);
++      result = cryptcompress_truncate(inode, 0, 0);
++      mutex_unlock(&info->checkin_mutex);
++
++      if (result) {
++              warning("edward-430",
++                      "cannot truncate cryptcompress file  %lli: %i",
++                      (unsigned long long)get_inode_oid(inode),
++                      result);
 +      }
++      truncate_inode_pages(inode->i_mapping, 0);
++      assert("edward-1487", pages_truncate_ok(inode, 0));
 +      /* and remove stat data */
-+      return delete_object_common(inode);
++      return reiser4_delete_object_common(inode);
 +}
 +
 +/* plugin->u.file.setattr method
-+   see plugin.h for description */
-+int setattr_cryptcompress(struct dentry *dentry,      /* Object to change attributes */
-+                        struct iattr *attr /* change description */ )
++   This implements actual truncate (see comments in reiser4/page_cache.c) */
++int setattr_cryptcompress(struct dentry *dentry, struct iattr *attr)
 +{
 +      int result;
 +      struct inode *inode;
++      struct cryptcompress_info * info;
 +
 +      inode = dentry->d_inode;
-+      result = check_cryptcompress(inode);
-+      if (result)
-+              return result;
-+      if (attr->ia_valid & ATTR_SIZE) {
-+              /* EDWARD-FIXME-HANS: VS-FIXME-HANS:
-+                 Q: this case occurs when? truncate?
-+                 A: yes
-+
-+                 Q: If so, why isn't this code in truncate itself instead of here?
-+
-+                 A: because vfs calls fs's truncate after it has called truncate_inode_pages to get rid of pages
-+                 corresponding to part of file being truncated. In reiser4 it may cause existence of unallocated
-+                 extents which do not have jnodes. Flush code does not expect that. Solution of this problem is
-+                 straightforward. As vfs's truncate is implemented using setattr operation (common implementaion of
-+                 which calls truncate_inode_pages and fs's truncate in case when size of file changes) - it seems
-+                 reasonable to have reiser4_setattr which will take care of removing pages, jnodes and extents
-+                 simultaneously in case of truncate.
-+                 Q: do you think implementing truncate using setattr is ugly,
-+                 and vfs needs improving, or is there some sense in which this is a good design?
-+
-+                 A: VS-FIXME-HANS:
-+               */
++      info = cryptcompress_inode_data(inode);
 +
-+              /* truncate does reservation itself and requires exclusive access obtained */
-+              if (inode->i_size != attr->ia_size) {
++      if (attr->ia_valid & ATTR_SIZE) {
++              if (i_size_read(inode) != attr->ia_size) {
 +                      reiser4_context *ctx;
 +                      loff_t old_size;
-+                      cryptcompress_info_t *info =
-+                          cryptcompress_inode_data(inode);
 +
-+                      ctx = init_context(dentry->d_inode->i_sb);
++                      ctx = reiser4_init_context(dentry->d_inode->i_sb);
 +                      if (IS_ERR(ctx))
 +                              return PTR_ERR(ctx);
 +
-+                      down_write(&info->lock);
-+                      LOCK_CNT_INC(inode_sem_w);
++                      old_size = i_size_read(inode);
++                      inode_check_scale(inode, old_size, attr->ia_size);
 +
-+                      inode_check_scale(inode, inode->i_size, attr->ia_size);
-+
-+                      old_size = inode->i_size;
-+
-+                      result =
-+                          cryptcompress_truncate(inode, attr->ia_size,
-+                                                 1 /* update stat data */ );
++                      mutex_lock(&info->checkin_mutex);
++                      result = cryptcompress_truncate(inode,
++                                                      attr->ia_size,
++                                                      1/* update sd */);
++                      mutex_unlock(&info->checkin_mutex);
 +                      if (result) {
-+                              warning("edward-1192",
-+                                      "truncate_cryptcompress failed: oid %lli, "
-+                                      "old size %lld, new size %lld, retval %d",
-+                                      (unsigned long long)
-+                                      get_inode_oid(inode), old_size,
-+                                      attr->ia_size, result);
++                           warning("edward-1192",
++                                   "truncate_cryptcompress failed: oid %lli, "
++                                   "old size %lld, new size %lld, retval %d",
++                                   (unsigned long long)
++                                   get_inode_oid(inode), old_size,
++                                   attr->ia_size, result);
 +                      }
-+                      up_write(&info->lock);
-+                      LOCK_CNT_DEC(inode_sem_w);
 +                      context_set_commit_async(ctx);
 +                      reiser4_exit_context(ctx);
 +              } else
 +                      result = 0;
 +      } else
-+              result = setattr_common(dentry, attr);
++              result = reiser4_setattr_common(dentry, attr);
 +      return result;
 +}
 +
@@ -35037,10 +34536,10 @@ Index: linux-2.6.16/fs/reiser4/plugin/file/cryptcompress.c
 +      reiser4_context *ctx;
 +      ssize_t result;
 +      struct inode *inode;
-+      cryptcompress_info_t *info;
++      struct cryptcompress_info *info;
 +
 +      inode = file->f_dentry->d_inode;
-+      ctx = init_context(inode->i_sb);
++      ctx = reiser4_init_context(inode->i_sb);
 +      if (IS_ERR(ctx))
 +              return PTR_ERR(ctx);
 +      /*
@@ -35052,9 +34551,8 @@ Index: linux-2.6.16/fs/reiser4/plugin/file/cryptcompress.c
 +      if (result)
 +              goto exit;
 +      info = cryptcompress_inode_data(inode);
-+      down_read(&info->lock);
++
 +      result = generic_file_sendfile(file, ppos, count, actor, target);
-+      up_read(&info->lock);
 + exit:
 +      reiser4_exit_context(ctx);
 +      return result;
@@ -35067,7 +34565,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/file/cryptcompress.c
 + */
 +int release_cryptcompress(struct inode *inode, struct file *file)
 +{
-+      reiser4_context *ctx = init_context(inode->i_sb);
++      reiser4_context *ctx = reiser4_init_context(inode->i_sb);
 +
 +      if (IS_ERR(ctx))
 +              return PTR_ERR(ctx);
@@ -35076,40 +34574,14 @@ Index: linux-2.6.16/fs/reiser4/plugin/file/cryptcompress.c
 +      return 0;
 +}
 +
-+static int
-+save_len_cryptcompress_plugin(struct inode *inode, reiser4_plugin * plugin)
-+{
-+      assert("edward-457", inode != NULL);
-+      assert("edward-458", plugin != NULL);
-+      assert("edward-459", plugin->h.id == CRC_FILE_PLUGIN_ID);
-+      return 0;
-+}
-+
-+static int
-+load_cryptcompress_plugin(struct inode *inode, reiser4_plugin * plugin,
-+                        char **area, int *len)
++#if 0
++int prepare_write_cryptcompress(struct file *file, struct page *page,
++                              unsigned from, unsigned to)
 +{
-+      assert("edward-455", inode != NULL);
-+      assert("edward-456", (reiser4_inode_data(inode)->pset != NULL));
-+
-+      plugin_set_file(&reiser4_inode_data(inode)->pset,
-+                      file_plugin_by_id(CRC_FILE_PLUGIN_ID));
-+      return 0;
++      return prepare_write_common(file, page, from, to);
 +}
++#endif  /*  0  */
 +
-+static int change_cryptcompress(struct inode *inode, reiser4_plugin * plugin)
-+{
-+      /* cannot change object plugin of already existing object */
-+      return RETERR(-EINVAL);
-+}
-+
-+struct reiser4_plugin_ops cryptcompress_plugin_ops = {
-+      .load = load_cryptcompress_plugin,
-+      .save_len = save_len_cryptcompress_plugin,
-+      .save = NULL,
-+      .alignment = 8,
-+      .change = change_cryptcompress
-+};
 +
 +/*
 +  Local variables:
@@ -35121,38 +34593,40 @@ Index: linux-2.6.16/fs/reiser4/plugin/file/cryptcompress.c
 +  scroll-step: 1
 +  End:
 +*/
-Index: linux-2.6.16/fs/reiser4/plugin/file/cryptcompress.h
-===================================================================
---- /dev/null
-+++ linux-2.6.16/fs/reiser4/plugin/file/cryptcompress.h
-@@ -0,0 +1,551 @@
+diff -urN linux-2.6.22.orig/fs/reiser4/plugin/file/cryptcompress.h linux-2.6.22/fs/reiser4/plugin/file/cryptcompress.h
+--- linux-2.6.22.orig/fs/reiser4/plugin/file/cryptcompress.h   1970-01-01 03:00:00.000000000 +0300
++++ linux-2.6.22/fs/reiser4/plugin/file/cryptcompress.h        2007-07-29 00:26:21.804839975 +0400
+@@ -0,0 +1,607 @@
 +/* Copyright 2002, 2003 by Hans Reiser, licensing governed by reiser4/README */
 +/* See http://www.namesys.com/cryptcompress_design.html */
 +
 +#if !defined( __FS_REISER4_CRYPTCOMPRESS_H__ )
 +#define __FS_REISER4_CRYPTCOMPRESS_H__
 +
++#include "../../page_cache.h"
 +#include "../compress/compress.h"
 +#include "../crypto/cipher.h"
 +
 +#include <linux/pagemap.h>
-+#include <linux/vmalloc.h>
 +
-+#define MIN_CLUSTER_SIZE PAGE_CACHE_SIZE
 +#define MIN_CLUSTER_SHIFT PAGE_CACHE_SHIFT
 +#define MAX_CLUSTER_SHIFT 16
 +#define MAX_CLUSTER_NRPAGES (1U << MAX_CLUSTER_SHIFT >> PAGE_CACHE_SHIFT)
 +#define DC_CHECKSUM_SIZE 4
 +
-+static inline loff_t min_count(loff_t a, loff_t b)
-+{
-+      return (a < b ? a : b);
-+}
++#define MIN_LATTICE_FACTOR 1
++#define MAX_LATTICE_FACTOR 32
 +
-+static inline loff_t max_count(loff_t a, loff_t b)
-+{
-+      return (a > b ? a : b);
-+}
++/* this mask contains all non-standard plugins that might
++   be present in reiser4-specific part of inode managed by
++   cryptcompress file plugin */
++#define cryptcompress_mask                            \
++      ((1 << PSET_FILE) |                             \
++       (1 << PSET_CLUSTER) |                          \
++       (1 << PSET_CIPHER) |                           \
++       (1 << PSET_DIGEST) |                           \
++       (1 << PSET_COMPRESSION) |                      \
++       (1 << PSET_COMPRESSION_MODE))
 +
 +#if REISER4_DEBUG
 +static inline int cluster_shift_ok(int shift)
@@ -35161,10 +34635,35 @@ Index: linux-2.6.16/fs/reiser4/plugin/file/cryptcompress.h
 +}
 +#endif
 +
-+typedef struct tfm_stream {
++#if REISER4_DEBUG
++#define INODE_PGCOUNT(inode)                                          \
++({                                                                    \
++      assert("edward-1530", inode_file_plugin(inode) ==               \
++             file_plugin_by_id(CRYPTCOMPRESS_FILE_PLUGIN_ID));        \
++      atomic_read(&cryptcompress_inode_data(inode)->pgcount);         \
++ })
++#define INODE_PGCOUNT_INC(inode)                                      \
++do {                                                                  \
++      assert("edward-1531", inode_file_plugin(inode) ==               \
++             file_plugin_by_id(CRYPTCOMPRESS_FILE_PLUGIN_ID));        \
++      atomic_inc(&cryptcompress_inode_data(inode)->pgcount);          \
++} while (0)
++#define INODE_PGCOUNT_DEC(inode)                                      \
++do {                                                                  \
++      if (inode_file_plugin(inode) ==                                 \
++          file_plugin_by_id(CRYPTCOMPRESS_FILE_PLUGIN_ID))            \
++              atomic_dec(&cryptcompress_inode_data(inode)->pgcount);  \
++} while (0)
++#else
++#define INODE_PGCOUNT(inode) (0)
++#define INODE_PGCOUNT_INC(inode)
++#define INODE_PGCOUNT_DEC(inode)
++#endif /* REISER4_DEBUG */
++
++struct tfm_stream {
 +      __u8 *data;
 +      size_t size;
-+} tfm_stream_t;
++};
 +
 +typedef enum {
 +      INPUT_STREAM,
@@ -35172,40 +34671,40 @@ Index: linux-2.6.16/fs/reiser4/plugin/file/cryptcompress.h
 +      LAST_STREAM
 +} tfm_stream_id;
 +
-+typedef tfm_stream_t *tfm_unit[LAST_STREAM];
++typedef struct tfm_stream * tfm_unit[LAST_STREAM];
 +
-+static inline __u8 *ts_data(tfm_stream_t * stm)
++static inline __u8 *ts_data(struct tfm_stream * stm)
 +{
 +      assert("edward-928", stm != NULL);
 +      return stm->data;
 +}
 +
-+static inline size_t ts_size(tfm_stream_t * stm)
++static inline size_t ts_size(struct tfm_stream * stm)
 +{
 +      assert("edward-929", stm != NULL);
 +      return stm->size;
 +}
 +
-+static inline void set_ts_size(tfm_stream_t * stm, size_t size)
++static inline void set_ts_size(struct tfm_stream * stm, size_t size)
 +{
 +      assert("edward-930", stm != NULL);
 +
 +      stm->size = size;
 +}
 +
-+static inline int alloc_ts(tfm_stream_t ** stm)
++static inline int alloc_ts(struct tfm_stream ** stm)
 +{
 +      assert("edward-931", stm);
 +      assert("edward-932", *stm == NULL);
 +
-+      *stm = kmalloc(sizeof **stm, GFP_KERNEL);
++      *stm = kmalloc(sizeof **stm, reiser4_ctx_gfp_mask_get());
 +      if (*stm == NULL)
 +              return -ENOMEM;
 +      memset(*stm, 0, sizeof **stm);
 +      return 0;
 +}
 +
-+static inline void free_ts(tfm_stream_t * stm)
++static inline void free_ts(struct tfm_stream * stm)
 +{
 +      assert("edward-933", !ts_data(stm));
 +      assert("edward-934", !ts_size(stm));
@@ -35213,20 +34712,20 @@ Index: linux-2.6.16/fs/reiser4/plugin/file/cryptcompress.h
 +      kfree(stm);
 +}
 +
-+static inline int alloc_ts_data(tfm_stream_t * stm, size_t size)
++static inline int alloc_ts_data(struct tfm_stream * stm, size_t size)
 +{
 +      assert("edward-935", !ts_data(stm));
 +      assert("edward-936", !ts_size(stm));
 +      assert("edward-937", size != 0);
 +
-+      stm->data = vmalloc(size);
++      stm->data = reiser4_vmalloc(size);
 +      if (!stm->data)
 +              return -ENOMEM;
 +      set_ts_size(stm, size);
 +      return 0;
 +}
 +
-+static inline void free_ts_data(tfm_stream_t * stm)
++static inline void free_ts_data(struct tfm_stream * stm)
 +{
 +      assert("edward-938", equi(ts_data(stm), ts_size(stm)));
 +
@@ -35240,42 +34739,40 @@ Index: linux-2.6.16/fs/reiser4/plugin/file/cryptcompress.h
 +      CRC_APPEND_ITEM = 1,
 +      CRC_OVERWRITE_ITEM = 2,
 +      CRC_CUT_ITEM = 3
-+} crc_write_mode_t;
++} cryptcompress_write_mode_t;
 +
 +typedef enum {
-+      PCL_UNKNOWN = 0,        /* invalid option */
-+      PCL_APPEND = 1,         /* append and/or overwrite */
-+      PCL_TRUNCATE = 2        /* truncate */
-+} page_cluster_op;
-+
-+/* Reiser4 file write/read transforms page cluster into disk cluster (and back)
-+   using crypto/compression transforms implemented by reiser4 transform plugins.
-+   Before each transform we allocate a pair of streams (tfm_unit) and assemble
-+   page cluster into the input one. After transform we split output stream into
-+   a set of items (disk cluster).
-+*/
-+typedef struct tfm_cluster {
-+      coa_set coa;
-+      tfm_unit tun;
++      LC_INVAL  = 0,   /* invalid value */
++      LC_APPOV = 1,    /* append and/or overwrite */
++      LC_TRUNC = 2     /* truncate */
++} logical_cluster_op;
++
++/* Transform cluster.
++ * Intermediate state between page cluster and disk cluster
++ * Is used for data transform (compression/encryption)
++ */
++struct tfm_cluster {
++      coa_set coa;      /* compression algorithms info */
++      tfm_unit tun;     /* plain and transformed streams */
 +      tfm_action act;
 +      int uptodate;
-+      int lsize;        /* size of the logical cluster */
++      int lsize;        /* number of bytes in logical cluster */
 +      int len;          /* length of the transform stream */
-+} tfm_cluster_t;
++};
 +
-+static inline coa_t get_coa(tfm_cluster_t * tc, reiser4_compression_id id, tfm_action act)
++static inline coa_t get_coa(struct tfm_cluster * tc, reiser4_compression_id id,
++                          tfm_action act)
 +{
 +      return tc->coa[id][act];
 +}
 +
-+static inline void
-+set_coa(tfm_cluster_t * tc, reiser4_compression_id id, tfm_action act, coa_t coa)
++static inline void set_coa(struct tfm_cluster * tc, reiser4_compression_id id,
++                         tfm_action act, coa_t coa)
 +{
 +      tc->coa[id][act] = coa;
 +}
 +
-+static inline int
-+alloc_coa(tfm_cluster_t * tc, compression_plugin * cplug)
++static inline int alloc_coa(struct tfm_cluster * tc, compression_plugin * cplug)
 +{
 +      coa_t coa;
 +
@@ -35287,13 +34784,13 @@ Index: linux-2.6.16/fs/reiser4/plugin/file/cryptcompress.h
 +}
 +
 +static inline int
-+grab_coa(tfm_cluster_t * tc, compression_plugin * cplug)
++grab_coa(struct tfm_cluster * tc, compression_plugin * cplug)
 +{
 +      return (cplug->alloc && !get_coa(tc, cplug->h.id, tc->act) ?
 +              alloc_coa(tc, cplug) : 0);
 +}
 +
-+static inline void free_coa_set(tfm_cluster_t * tc)
++static inline void free_coa_set(struct tfm_cluster * tc)
 +{
 +      tfm_action j;
 +      reiser4_compression_id i;
@@ -35301,7 +34798,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/file/cryptcompress.h
 +
 +      assert("edward-810", tc != NULL);
 +
-+      for (j = 0; j < LAST_TFM; j++)
++      for (j = 0; j < TFMA_LAST; j++)
 +              for (i = 0; i < LAST_COMPRESSION_ID; i++) {
 +                      if (!get_coa(tc, i, j))
 +                              continue;
@@ -35313,64 +34810,65 @@ Index: linux-2.6.16/fs/reiser4/plugin/file/cryptcompress.h
 +      return;
 +}
 +
-+static inline tfm_stream_t *tfm_stream(tfm_cluster_t * tc, tfm_stream_id id)
++static inline struct tfm_stream * get_tfm_stream(struct tfm_cluster * tc,
++                                               tfm_stream_id id)
 +{
 +      return tc->tun[id];
 +}
 +
-+static inline void
-+set_tfm_stream(tfm_cluster_t * tc, tfm_stream_id id, tfm_stream_t * ts)
++static inline void set_tfm_stream(struct tfm_cluster * tc,
++                                tfm_stream_id id, struct tfm_stream * ts)
 +{
 +      tc->tun[id] = ts;
 +}
 +
-+static inline __u8 *tfm_stream_data(tfm_cluster_t * tc, tfm_stream_id id)
++static inline __u8 *tfm_stream_data(struct tfm_cluster * tc, tfm_stream_id id)
 +{
-+      return ts_data(tfm_stream(tc, id));
++      return ts_data(get_tfm_stream(tc, id));
 +}
 +
-+static inline void
-+set_tfm_stream_data(tfm_cluster_t * tc, tfm_stream_id id, __u8 * data)
++static inline void set_tfm_stream_data(struct tfm_cluster * tc,
++                                     tfm_stream_id id, __u8 * data)
 +{
-+      tfm_stream(tc, id)->data = data;
++      get_tfm_stream(tc, id)->data = data;
 +}
 +
-+static inline size_t tfm_stream_size(tfm_cluster_t * tc, tfm_stream_id id)
++static inline size_t tfm_stream_size(struct tfm_cluster * tc, tfm_stream_id id)
 +{
-+      return ts_size(tfm_stream(tc, id));
++      return ts_size(get_tfm_stream(tc, id));
 +}
 +
 +static inline void
-+set_tfm_stream_size(tfm_cluster_t * tc, tfm_stream_id id, size_t size)
++set_tfm_stream_size(struct tfm_cluster * tc, tfm_stream_id id, size_t size)
 +{
-+      tfm_stream(tc, id)->size = size;
++      get_tfm_stream(tc, id)->size = size;
 +}
 +
 +static inline int
-+alloc_tfm_stream(tfm_cluster_t * tc, size_t size, tfm_stream_id id)
++alloc_tfm_stream(struct tfm_cluster * tc, size_t size, tfm_stream_id id)
 +{
 +      assert("edward-939", tc != NULL);
-+      assert("edward-940", !tfm_stream(tc, id));
++      assert("edward-940", !get_tfm_stream(tc, id));
 +
-+      tc->tun[id] = kmalloc(sizeof(tfm_stream_t), GFP_KERNEL);
++      tc->tun[id] = kzalloc(sizeof(struct tfm_stream),
++                            reiser4_ctx_gfp_mask_get());
 +      if (!tc->tun[id])
 +              return -ENOMEM;
-+      memset(tfm_stream(tc, id), 0, sizeof(tfm_stream_t));
-+      return alloc_ts_data(tfm_stream(tc, id), size);
++      return alloc_ts_data(get_tfm_stream(tc, id), size);
 +}
 +
 +static inline int
-+realloc_tfm_stream(tfm_cluster_t * tc, size_t size, tfm_stream_id id)
++realloc_tfm_stream(struct tfm_cluster * tc, size_t size, tfm_stream_id id)
 +{
 +      assert("edward-941", tfm_stream_size(tc, id) < size);
-+      free_ts_data(tfm_stream(tc, id));
-+      return alloc_ts_data(tfm_stream(tc, id), size);
++      free_ts_data(get_tfm_stream(tc, id));
++      return alloc_ts_data(get_tfm_stream(tc, id), size);
 +}
 +
-+static inline void free_tfm_stream(tfm_cluster_t * tc, tfm_stream_id id)
++static inline void free_tfm_stream(struct tfm_cluster * tc, tfm_stream_id id)
 +{
-+      free_ts_data(tfm_stream(tc, id));
-+      free_ts(tfm_stream(tc, id));
++      free_ts_data(get_tfm_stream(tc, id));
++      free_ts(get_tfm_stream(tc, id));
 +      set_tfm_stream(tc, id, 0);
 +}
 +
@@ -35379,31 +34877,31 @@ Index: linux-2.6.16/fs/reiser4/plugin/file/cryptcompress.h
 +      return (cplug->overrun != NULL ? cplug->overrun(ilen) : 0);
 +}
 +
-+static inline void free_tfm_unit(tfm_cluster_t * tc)
++static inline void free_tfm_unit(struct tfm_cluster * tc)
 +{
 +      tfm_stream_id id;
 +      for (id = 0; id < LAST_STREAM; id++) {
-+              if (!tfm_stream(tc, id))
++              if (!get_tfm_stream(tc, id))
 +                      continue;
 +              free_tfm_stream(tc, id);
 +      }
 +}
 +
-+static inline void put_tfm_cluster(tfm_cluster_t * tc)
++static inline void put_tfm_cluster(struct tfm_cluster * tc)
 +{
 +      assert("edward-942", tc != NULL);
 +      free_coa_set(tc);
 +      free_tfm_unit(tc);
 +}
 +
-+static inline int tfm_cluster_is_uptodate(tfm_cluster_t * tc)
++static inline int tfm_cluster_is_uptodate(struct tfm_cluster * tc)
 +{
 +      assert("edward-943", tc != NULL);
 +      assert("edward-944", tc->uptodate == 0 || tc->uptodate == 1);
 +      return (tc->uptodate == 1);
 +}
 +
-+static inline void tfm_cluster_set_uptodate(tfm_cluster_t * tc)
++static inline void tfm_cluster_set_uptodate(struct tfm_cluster * tc)
 +{
 +      assert("edward-945", tc != NULL);
 +      assert("edward-946", tc->uptodate == 0 || tc->uptodate == 1);
@@ -35411,7 +34909,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/file/cryptcompress.h
 +      return;
 +}
 +
-+static inline void tfm_cluster_clr_uptodate(tfm_cluster_t * tc)
++static inline void tfm_cluster_clr_uptodate(struct tfm_cluster * tc)
 +{
 +      assert("edward-947", tc != NULL);
 +      assert("edward-948", tc->uptodate == 0 || tc->uptodate == 1);
@@ -35419,13 +34917,13 @@ Index: linux-2.6.16/fs/reiser4/plugin/file/cryptcompress.h
 +      return;
 +}
 +
-+static inline int tfm_stream_is_set(tfm_cluster_t * tc, tfm_stream_id id)
++static inline int tfm_stream_is_set(struct tfm_cluster * tc, tfm_stream_id id)
 +{
-+      return (tfm_stream(tc, id) &&
++      return (get_tfm_stream(tc, id) &&
 +              tfm_stream_data(tc, id) && tfm_stream_size(tc, id));
 +}
 +
-+static inline int tfm_cluster_is_set(tfm_cluster_t * tc)
++static inline int tfm_cluster_is_set(struct tfm_cluster * tc)
 +{
 +      int i;
 +      for (i = 0; i < LAST_STREAM; i++)
@@ -35434,108 +34932,130 @@ Index: linux-2.6.16/fs/reiser4/plugin/file/cryptcompress.h
 +      return 1;
 +}
 +
-+static inline void alternate_streams(tfm_cluster_t * tc)
++static inline void alternate_streams(struct tfm_cluster * tc)
 +{
-+      tfm_stream_t *tmp = tfm_stream(tc, INPUT_STREAM);
++      struct tfm_stream *tmp = get_tfm_stream(tc, INPUT_STREAM);
 +
-+      set_tfm_stream(tc, INPUT_STREAM, tfm_stream(tc, OUTPUT_STREAM));
++      set_tfm_stream(tc, INPUT_STREAM, get_tfm_stream(tc, OUTPUT_STREAM));
 +      set_tfm_stream(tc, OUTPUT_STREAM, tmp);
 +}
 +
-+/* a kind of data that we can write to the window */
++/* Set of states to indicate a kind of data
++ * that will be written to the window */
 +typedef enum {
-+      DATA_WINDOW,            /* the data we copy form user space */
-+      HOLE_WINDOW             /* zeroes if we write hole */
++      DATA_WINDOW,            /* user's data */
++      HOLE_WINDOW             /* zeroes (such kind of data can be written
++                               * if we start to write from offset > i_size) */
 +} window_stat;
 +
-+/* Sliding window of cluster size which should be set to the approprite position
-+   (defined by cluster index) in a file before page cluster modification by
-+   file_write. Then we translate file size, offset to write from, number of
-+   bytes to write, etc.. to the following configuration needed to estimate
-+   number of pages to read before write, etc...
-+*/
-+typedef struct reiser4_slide {
-+      unsigned off;           /* offset we start to write/truncate from */
-+      unsigned count;         /* number of bytes (zeroes) to write/truncate */
++/* Window (of logical cluster size) discretely sliding along a file.
++ * Is used to locate hole region in a logical cluster to be properly
++ * represented on disk.
++ * We split a write to cryptcompress file into writes to its logical
++ * clusters. Before writing to a logical cluster we set a window, i.e.
++ * calculate values of the following fields:
++ */
++struct reiser4_slide {
++      unsigned off;           /* offset to write from */
++      unsigned count;         /* number of bytes to write */
 +      unsigned delta;         /* number of bytes to append to the hole */
-+      window_stat stat;       /* a kind of data to write to the window */
-+} reiser4_slide_t;
++      window_stat stat;       /* what kind of data will be written starting
++                                 from @off */
++};
 +
-+/* The following is a set of possible disk cluster states */
++/* Possible states of a disk cluster */
 +typedef enum {
 +      INVAL_DISK_CLUSTER,     /* unknown state */
 +      PREP_DISK_CLUSTER,      /* disk cluster got converted by flush
-+                                 at least 1 time */
++                               * at least 1 time */
 +      UNPR_DISK_CLUSTER,      /* disk cluster just created and should be
-+                                 converted by flush */
-+      FAKE_DISK_CLUSTER       /* disk cluster doesn't exist neither in memory
-+                                 nor on disk */
++                               * converted by flush */
++      FAKE_DISK_CLUSTER,      /* disk cluster doesn't exist neither in memory
++                               * nor on disk */
++      TRNC_DISK_CLUSTER       /* disk cluster is partially truncated */
 +} disk_cluster_stat;
 +
-+/*
-+   While implementing all transforms (from page to disk cluster, and back)
-+   reiser4 cluster manager fills the following structure incapsulating pointers
-+   to all the clusters for the same index including the sliding window above
-+*/
-+typedef struct reiser4_cluster {
-+      tfm_cluster_t tc;       /* transform cluster */
-+      int nr_pages;           /* number of pages */
-+      struct page **pages;    /* page cluster */
-+      page_cluster_op op;     /* page cluster operation */
-+      struct file *file;
-+      hint_t *hint;           /* disk cluster item for traversal */
-+      disk_cluster_stat dstat;        /* state of the current disk cluster */
-+      cloff_t index;          /* offset in the units of cluster size */
-+      reiser4_slide_t *win;   /* sliding window of cluster size */
-+      int reserved;           /* this indicates that space for disk
-+                                 cluster modification is reserved */
++/* The following structure represents various stages of the same logical
++ * cluster of index @index:
++ * . fixed slide
++ * . page cluster         (stage in primary cache)
++ * . transform cluster    (transition stage)
++ * . disk cluster         (stage in secondary cache)
++ * This structure is used in transition and synchronizing operations, e.g.
++ * transform cluster is a transition state when synchronizing page cluster
++ * and disk cluster.
++ * FIXME: Encapsulate page cluster, disk cluster.
++ */
++struct cluster_handle {
++      cloff_t index;           /* offset in a file (unit is a cluster size) */
++      int index_valid;         /* for validating the index above, if needed */
++      struct file *file;       /* host file */
++
++      /* logical cluster */
++      struct reiser4_slide *win; /* sliding window to locate holes */
++      logical_cluster_op op;   /* logical cluster operation (truncate or
++                                  append/overwrite) */
++      /* transform cluster */
++      struct tfm_cluster tc;   /* contains all needed info to synchronize
++                                  page cluster and disk cluster) */
++        /* page cluster */
++      int nr_pages;            /* number of pages of current checkin action */
++      int old_nrpages;         /* number of pages of last checkin action */
++      struct page **pages;     /* attached pages */
++      jnode * node;            /* jnode for capture */
++
++      /* disk cluster */
++      hint_t *hint;            /* current position in the tree */
++      disk_cluster_stat dstat; /* state of the current disk cluster */
++      int reserved;            /* is space for disk cluster reserved */
 +#if REISER4_DEBUG
 +      reiser4_context *ctx;
 +      int reserved_prepped;
 +      int reserved_unprepped;
 +#endif
 +
-+} reiser4_cluster_t;
++};
 +
-+static inline __u8 * tfm_input_data (reiser4_cluster_t * clust)
++static inline __u8 * tfm_input_data (struct cluster_handle * clust)
 +{
 +      return tfm_stream_data(&clust->tc, INPUT_STREAM);
 +}
 +
-+static inline __u8 * tfm_output_data (reiser4_cluster_t * clust)
++static inline __u8 * tfm_output_data (struct cluster_handle * clust)
 +{
 +      return tfm_stream_data(&clust->tc, OUTPUT_STREAM);
 +}
 +
-+static inline int reset_cluster_pgset(reiser4_cluster_t * clust, int nrpages)
++static inline int reset_cluster_pgset(struct cluster_handle * clust,
++                                    int nrpages)
 +{
 +      assert("edward-1057", clust->pages != NULL);
 +      memset(clust->pages, 0, sizeof(*clust->pages) * nrpages);
 +      return 0;
 +}
 +
-+static inline int alloc_cluster_pgset(reiser4_cluster_t * clust, int nrpages)
++static inline int alloc_cluster_pgset(struct cluster_handle * clust,
++                                    int nrpages)
 +{
 +      assert("edward-949", clust != NULL);
 +      assert("edward-1362", clust->pages == NULL);
 +      assert("edward-950", nrpages != 0 && nrpages <= MAX_CLUSTER_NRPAGES);
 +
-+      clust->pages =
-+              kmalloc(sizeof(*clust->pages) * nrpages, GFP_KERNEL);
++      clust->pages = kzalloc(sizeof(*clust->pages) * nrpages,
++                             reiser4_ctx_gfp_mask_get());
 +      if (!clust->pages)
 +              return RETERR(-ENOMEM);
-+      reset_cluster_pgset(clust, nrpages);
 +      return 0;
 +}
 +
-+static inline void free_cluster_pgset(reiser4_cluster_t * clust)
++static inline void free_cluster_pgset(struct cluster_handle * clust)
 +{
 +      assert("edward-951", clust->pages != NULL);
 +      kfree(clust->pages);
 +      clust->pages = NULL;
 +}
 +
-+static inline void put_cluster_handle(reiser4_cluster_t * clust)
++static inline void put_cluster_handle(struct cluster_handle * clust)
 +{
 +      assert("edward-435", clust != NULL);
 +
@@ -35545,127 +35065,134 @@ Index: linux-2.6.16/fs/reiser4/plugin/file/cryptcompress.h
 +      memset(clust, 0, sizeof *clust);
 +}
 +
-+static inline void inc_keyload_count(crypto_stat_t * data)
++static inline void inc_keyload_count(struct reiser4_crypto_info * data)
 +{
 +      assert("edward-1410", data != NULL);
 +      data->keyload_count++;
 +}
 +
-+static inline void dec_keyload_count(crypto_stat_t * data)
++static inline void dec_keyload_count(struct reiser4_crypto_info * data)
 +{
 +      assert("edward-1411", data != NULL);
 +      assert("edward-1412", data->keyload_count > 0);
 +      data->keyload_count--;
 +}
 +
++static inline int capture_cluster_jnode(jnode * node)
++{
++      return reiser4_try_capture(node, ZNODE_WRITE_LOCK, 0);
++}
++
 +/* cryptcompress specific part of reiser4_inode */
-+typedef struct cryptcompress_info {
-+      struct rw_semaphore lock;
-+      crypto_stat_t *crypt;
-+      int compress_toggle;      /* current status of compressibility
-+                                   is set by compression mode plugin */
++struct cryptcompress_info {
++      struct mutex checkin_mutex;  /* This is to serialize
++                                    * checkin_logical_cluster operations */
++      cloff_t trunc_index;         /* Index of the leftmost truncated disk
++                                    * cluster (to resolve races with read) */
++      struct reiser4_crypto_info *crypt;
++      /*
++       * the following 2 fields are controlled by compression mode plugin
++       */
++      int compress_toggle;          /* Current status of compressibility */
++      int lattice_factor;           /* Factor of dynamic lattice. FIXME: Have
++                                     * a compression_toggle to keep the factor
++                                     */
 +#if REISER4_DEBUG
-+      int pgcount;              /* number of captured pages */
++      atomic_t pgcount;             /* number of grabbed pages */
 +#endif
-+} cryptcompress_info_t;
-+
++};
 +
-+static inline void toggle_compression (cryptcompress_info_t * info, int val)
++static inline void set_compression_toggle (struct cryptcompress_info * info, int val)
 +{
 +      info->compress_toggle = val;
 +}
 +
-+static inline int compression_is_on (cryptcompress_info_t * info)
++static inline int get_compression_toggle (struct cryptcompress_info * info)
 +{
 +      return info->compress_toggle;
 +}
 +
-+cryptcompress_info_t *cryptcompress_inode_data(const struct inode *);
-+int equal_to_rdk(znode *, const reiser4_key *);
-+int goto_right_neighbor(coord_t *, lock_handle *);
-+int load_file_hint(struct file *, hint_t *);
-+void save_file_hint(struct file *, const hint_t *);
-+void hint_init_zero(hint_t *);
-+int crc_inode_ok(struct inode *inode);
-+int jnode_of_cluster(const jnode * node, struct page * page);
-+extern int ctail_read_disk_cluster (reiser4_cluster_t *, struct inode *, int);
-+extern int do_readpage_ctail(struct inode *, reiser4_cluster_t *,
-+                           struct page * page);
-+extern int ctail_insert_unprepped_cluster(reiser4_cluster_t * clust,
-+                                        struct inode * inode);
-+int bind_cryptcompress(struct inode *child, struct inode *parent);
-+void destroy_inode_cryptcompress(struct inode * inode);
-+crypto_stat_t * inode_crypto_stat (struct inode * inode);
-+void inherit_crypto_stat_common(struct inode * parent, struct inode * object,
-+                              int (*can_inherit)(struct inode * child,
-+                                                 struct inode * parent));
-+void attach_crypto_stat(struct inode * inode, crypto_stat_t * info);
-+void detach_crypto_stat(struct inode * inode);
-+void change_crypto_stat(struct inode * inode, crypto_stat_t * new);
-+crypto_stat_t * alloc_crypto_stat (struct inode * inode);
-+
-+
-+static inline reiser4_tfma_t *
-+info_get_tfma (crypto_stat_t * info, reiser4_tfm id)
++static inline int compression_is_on(struct cryptcompress_info * info)
 +{
-+      return &info->tfma[id];
++      return get_compression_toggle(info) == 1;
 +}
 +
-+static inline struct crypto_tfm *
-+info_get_tfm (crypto_stat_t * info, reiser4_tfm id)
++static inline void turn_on_compression(struct cryptcompress_info * info)
 +{
-+      return info_get_tfma(info, id)->tfm;
++      set_compression_toggle(info, 1);
 +}
 +
-+static inline void
-+info_set_tfm (crypto_stat_t * info, reiser4_tfm id, struct crypto_tfm * tfm)
++static inline void turn_off_compression(struct cryptcompress_info * info)
 +{
-+      info_get_tfma(info, id)->tfm = tfm;
++      set_compression_toggle(info, 0);
 +}
 +
-+static inline struct crypto_tfm *
-+info_cipher_tfm (crypto_stat_t * info)
++static inline void set_lattice_factor(struct cryptcompress_info * info, int val)
 +{
-+      return info_get_tfm(info, CIPHER_TFM);
++      info->lattice_factor = val;
 +}
 +
-+static inline struct crypto_tfm *
-+info_digest_tfm (crypto_stat_t * info)
++static inline int get_lattice_factor(struct cryptcompress_info * info)
 +{
-+      return info_get_tfm(info, DIGEST_TFM);
++      return info->lattice_factor;
 +}
 +
-+static inline cipher_plugin *
-+info_cipher_plugin (crypto_stat_t * info)
++struct cryptcompress_info *cryptcompress_inode_data(const struct inode *);
++int equal_to_rdk(znode *, const reiser4_key *);
++int goto_right_neighbor(coord_t *, lock_handle *);
++int cryptcompress_inode_ok(struct inode *inode);
++int coord_is_unprepped_ctail(const coord_t * coord);
++extern int ctail_read_disk_cluster (struct cluster_handle *, struct inode *,
++                                  struct page *, znode_lock_mode mode);
++extern int do_readpage_ctail(struct inode *, struct cluster_handle *,
++                           struct page * page, znode_lock_mode mode);
++extern int ctail_insert_unprepped_cluster(struct cluster_handle * clust,
++                                        struct inode * inode);
++extern int readpages_cryptcompress(struct file*, struct address_space*,
++                                 struct list_head*, unsigned);
++int bind_cryptcompress(struct inode *child, struct inode *parent);
++void destroy_inode_cryptcompress(struct inode * inode);
++int grab_page_cluster(struct inode *inode, struct cluster_handle * clust,
++                    rw_op rw);
++int write_conversion_hook(struct file *file, struct inode * inode, loff_t pos,
++                        struct cluster_handle * clust, int * progress);
++struct reiser4_crypto_info * inode_crypto_info(struct inode * inode);
++void inherit_crypto_info_common(struct inode * parent, struct inode * object,
++                              int (*can_inherit)(struct inode * child,
++                                                 struct inode * parent));
++void reiser4_attach_crypto_info(struct inode * inode,
++                              struct reiser4_crypto_info * info);
++void change_crypto_info(struct inode * inode, struct reiser4_crypto_info * new);
++struct reiser4_crypto_info * reiser4_alloc_crypto_info (struct inode * inode);
++
++static inline struct crypto_blkcipher * info_get_cipher(struct reiser4_crypto_info * info)
 +{
-+      return &info_get_tfma(info, CIPHER_TFM)->plug->cipher;
++      return info->cipher;
 +}
 +
-+static inline digest_plugin *
-+info_digest_plugin (crypto_stat_t * info)
++static inline void info_set_cipher(struct reiser4_crypto_info * info,
++                                 struct crypto_blkcipher * tfm)
 +{
-+      return &info_get_tfma(info, DIGEST_TFM)->plug->digest;
++      info->cipher = tfm;
 +}
 +
-+static inline void
-+info_set_plugin(crypto_stat_t * info, reiser4_tfm id, reiser4_plugin * plugin)
++static inline struct crypto_hash * info_get_digest(struct reiser4_crypto_info * info)
 +{
-+      info_get_tfma(info, id)->plug = plugin;
++      return info->digest;
 +}
 +
-+static inline void
-+info_set_cipher_plugin(crypto_stat_t * info, cipher_plugin * cplug)
++static inline void info_set_digest(struct reiser4_crypto_info * info,
++                                 struct crypto_hash * tfm)
 +{
-+      info_set_plugin(info, CIPHER_TFM, cipher_plugin_to_plugin(cplug));
++      info->digest = tfm;
 +}
 +
-+static inline void
-+info_set_digest_plugin(crypto_stat_t * info, digest_plugin * plug)
++static inline void put_cluster_page(struct page * page)
 +{
-+      info_set_plugin(info, DIGEST_TFM, digest_plugin_to_plugin(plug));
++      page_cache_release(page);
 +}
 +
-+#endif                                /* __FS_REISER4_CRYPTCOMPRESS_H__ */
++#endif /* __FS_REISER4_CRYPTCOMPRESS_H__ */
 +
 +/* Make Linus happy.
 +   Local variables:
@@ -35677,11 +35204,10 @@ Index: linux-2.6.16/fs/reiser4/plugin/file/cryptcompress.h
 +   scroll-step: 1
 +   End:
 +*/
-Index: linux-2.6.16/fs/reiser4/plugin/file/file.c
-===================================================================
---- /dev/null
-+++ linux-2.6.16/fs/reiser4/plugin/file/file.c
-@@ -0,0 +1,2712 @@
+diff -urN linux-2.6.22.orig/fs/reiser4/plugin/file/file.c linux-2.6.22/fs/reiser4/plugin/file/file.c
+--- linux-2.6.22.orig/fs/reiser4/plugin/file/file.c    1970-01-01 03:00:00.000000000 +0300
++++ linux-2.6.22/fs/reiser4/plugin/file/file.c 2007-07-29 00:25:34.924708901 +0400
+@@ -0,0 +1,2817 @@
 +/* Copyright 2001, 2002, 2003, 2004 by Hans Reiser, licensing governed by
 + * reiser4/README */
 +
@@ -35700,6 +35226,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/file/file.c
 +#include "../../page_cache.h"
 +#include "../../ioctl.h"
 +#include "../object.h"
++#include "../cluster.h"
 +#include "../../safe_link.h"
 +
 +#include <linux/writeback.h>
@@ -35708,9 +35235,28 @@ Index: linux-2.6.16/fs/reiser4/plugin/file/file.c
 +
 +
 +static int unpack(struct file *file, struct inode *inode, int forever);
++static void drop_access(struct unix_file_info *);
++static int hint_validate(hint_t * hint, const reiser4_key * key, int check_key,
++                       znode_lock_mode lock_mode);
++
++/* Get exclusive access and make sure that file is not partially
++ * converted (It may happen that another process is doing tail
++ * conversion. If so, wait until it completes)
++ */
++static inline void get_exclusive_access_careful(struct unix_file_info * uf_info,
++                                              struct inode *inode)
++{
++        do {
++              get_exclusive_access(uf_info);
++              if (!reiser4_inode_get_flag(inode, REISER4_PART_IN_CONV))
++                      break;
++              drop_exclusive_access(uf_info);
++              schedule();
++      } while (1);
++}
 +
 +/* get unix file plugin specific portion of inode */
-+unix_file_info_t *unix_file_inode_data(const struct inode *inode)
++struct unix_file_info *unix_file_inode_data(const struct inode *inode)
 +{
 +      return &reiser4_inode_data(inode)->file_plugin_data.unix_file_info;
 +}
@@ -35787,7 +35333,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/file/file.c
 +      uf_coord->valid = 0;
 +}
 +
-+void validate_extended_coord(uf_coord_t *uf_coord, loff_t offset)
++static void validate_extended_coord(uf_coord_t *uf_coord, loff_t offset)
 +{
 +      assert("vs-1333", uf_coord->valid == 0);
 +
@@ -35849,7 +35395,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/file/file.c
 + * This is to be used by find_file_item and in find_file_state to
 + * determine real state of file
 + */
-+static void set_file_state(unix_file_info_t *uf_info, int cbk_result,
++static void set_file_state(struct unix_file_info *uf_info, int cbk_result,
 +                         tree_level level)
 +{
 +      if (cbk_errored(cbk_result))
@@ -35859,12 +35405,6 @@ Index: linux-2.6.16/fs/reiser4/plugin/file/file.c
 +      assert("vs-1164", level == LEAF_LEVEL || level == TWIG_LEVEL);
 +
 +      if (uf_info->container == UF_CONTAINER_UNKNOWN) {
-+              /*
-+               * container is unknown, therefore conversion can not be in
-+               * progress
-+               */
-+              assert("", !inode_get_flag(unix_file_info_to_inode(uf_info),
-+                                         REISER4_PART_IN_CONV));
 +              if (cbk_result == CBK_COORD_NOTFOUND)
 +                      uf_info->container = UF_CONTAINER_EMPTY;
 +              else if (level == LEAF_LEVEL)
@@ -35876,8 +35416,8 @@ Index: linux-2.6.16/fs/reiser4/plugin/file/file.c
 +               * file state is known, check whether it is set correctly if
 +               * file is not being tail converted
 +               */
-+              if (!inode_get_flag(unix_file_info_to_inode(uf_info),
-+                                  REISER4_PART_IN_CONV)) {
++              if (!reiser4_inode_get_flag(unix_file_info_to_inode(uf_info),
++                                          REISER4_PART_IN_CONV)) {
 +                      assert("vs-1162",
 +                             ergo(level == LEAF_LEVEL &&
 +                                  cbk_result == CBK_COORD_FOUND,
@@ -35894,12 +35434,12 @@ Index: linux-2.6.16/fs/reiser4/plugin/file/file.c
 +                        const reiser4_key *key, znode_lock_mode lock_mode,
 +                        struct inode *inode)
 +{
-+      return object_lookup(inode, key, coord, lh, lock_mode,
-+                           FIND_MAX_NOT_MORE_THAN,
-+                           TWIG_LEVEL, LEAF_LEVEL,
-+                           (lock_mode == ZNODE_READ_LOCK) ? CBK_UNIQUE :
-+                           (CBK_UNIQUE | CBK_FOR_INSERT),
-+                           NULL /* ra_info */ );
++      return reiser4_object_lookup(inode, key, coord, lh, lock_mode,
++                                   FIND_MAX_NOT_MORE_THAN,
++                                   TWIG_LEVEL, LEAF_LEVEL,
++                                   (lock_mode == ZNODE_READ_LOCK) ? CBK_UNIQUE :
++                                   (CBK_UNIQUE | CBK_FOR_INSERT),
++                                   NULL /* ra_info */ );
 +}
 +
 +/**
@@ -35921,7 +35461,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/file/file.c
 +      coord_t *coord;
 +      lock_handle *lh;
 +
-+      assert("nikita-3030", schedulable());
++      assert("nikita-3030", reiser4_schedulable());
 +      assert("vs-1707", hint != NULL);
 +      assert("vs-47", inode != NULL);
 +
@@ -35948,7 +35488,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/file/file.c
 +
 +              set_file_state(unix_file_inode_data(inode), CBK_COORD_FOUND,
 +                             znode_get_level(coord->node));
-+              
++
 +              return CBK_COORD_FOUND;
 +      }
 +
@@ -35972,7 +35512,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/file/file.c
 +      hint->ext_coord.lh = &hint->lh;
 +}
 +
-+static int find_file_state(struct inode *inode, unix_file_info_t *uf_info)
++static int find_file_state(struct inode *inode, struct unix_file_info *uf_info)
 +{
 +      int result;
 +      reiser4_key key;
@@ -35994,7 +35534,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/file/file.c
 +              result = 0;
 +      assert("vs-1074",
 +             ergo(result == 0, uf_info->container != UF_CONTAINER_UNKNOWN));
-+      txn_restart_current();
++      reiser4_txn_restart_current();
 +      return result;
 +}
 +
@@ -36025,11 +35565,12 @@ Index: linux-2.6.16/fs/reiser4/plugin/file/file.c
 +                                   BA_CAN_COMMIT);
 +}
 +
-+int update_file_size(struct inode *inode, reiser4_key * key, int update_sd)
++int reiser4_update_file_size(struct inode *inode, reiser4_key * key,
++                           int update_sd)
 +{
 +      int result = 0;
 +
-+      INODE_SET_FIELD(inode, i_size, get_key_offset(key));
++      INODE_SET_SIZE(inode, get_key_offset(key));
 +      if (update_sd) {
 +              inode->i_ctime = inode->i_mtime = CURRENT_TIME;
 +              result = reiser4_update_sd(inode);
@@ -36052,20 +35593,20 @@ Index: linux-2.6.16/fs/reiser4/plugin/file/file.c
 +
 +      assert("vs-1248",
 +             fplug == file_plugin_by_id(UNIX_FILE_PLUGIN_ID) ||
-+             fplug == file_plugin_by_id(CRC_FILE_PLUGIN_ID));
++             fplug == file_plugin_by_id(CRYPTCOMPRESS_FILE_PLUGIN_ID));
 +
 +      fplug->key_by_inode(inode, new_size, &from_key);
 +      to_key = from_key;
-+      set_key_offset(&to_key, cur_size - 1 /*get_key_offset(max_key()) */ );
++      set_key_offset(&to_key, cur_size - 1 /*get_key_offset(reiser4_max_key()) */ );
 +      /* this loop normally runs just once */
 +      while (1) {
-+              result = reserve_cut_iteration(tree_by_inode(inode));
++              result = reserve_cut_iteration(reiser4_tree_by_inode(inode));
 +              if (result)
 +                      break;
 +
-+              result = cut_tree_object(current_tree, &from_key, &to_key,
-+                                       &smallest_removed, inode, 1,
-+                                       &progress);
++              result = reiser4_cut_tree_object(current_tree, &from_key, &to_key,
++                                               &smallest_removed, inode, 1,
++                                               &progress);
 +              if (result == -E_REPEAT) {
 +                      /* -E_REPEAT is a signal to interrupt a long file truncation process */
 +                      if (progress) {
@@ -36076,13 +35617,13 @@ Index: linux-2.6.16/fs/reiser4/plugin/file/file.c
 +                                      break;
 +                      }
 +
-+                      /* the below does up(sbinfo->delete_sema). Do not get folled */
++                      /* the below does up(sbinfo->delete_mutex). Do not get folled */
 +                      reiser4_release_reserved(inode->i_sb);
 +
-+                      /* cut_tree_object() was interrupted probably because
++                      /* reiser4_cut_tree_object() was interrupted probably because
 +                       * current atom requires commit, we have to release
 +                       * transaction handle to allow atom commit. */
-+                      txn_restart_current();
++                      reiser4_txn_restart_current();
 +                      continue;
 +              }
 +              if (result
@@ -36096,7 +35637,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/file/file.c
 +              break;
 +      }
 +
-+      /* the below does up(sbinfo->delete_sema). Do not get folled */
++      /* the below does up(sbinfo->delete_mutex). Do not get folled */
 +      reiser4_release_reserved(inode->i_sb);
 +
 +      return result;
@@ -36104,11 +35645,6 @@ Index: linux-2.6.16/fs/reiser4/plugin/file/file.c
 +
 +int find_or_create_extent(struct page *page);
 +
-+static int filler(void *vp, struct page *page)
-+{
-+      return readpage_unix_file_nolock(vp, page);
-+}
-+
 +/* part of truncate_file_body: it is called when truncate is used to make file
 +   shorter */
 +static int shorten_file(struct inode *inode, loff_t new_size)
@@ -36117,16 +35653,16 @@ Index: linux-2.6.16/fs/reiser4/plugin/file/file.c
 +      struct page *page;
 +      int padd_from;
 +      unsigned long index;
-+      char *kaddr;
-+      unix_file_info_t *uf_info;
++      struct unix_file_info *uf_info;
 +
 +      /*
 +       * all items of ordinary reiser4 file are grouped together. That is why
-+       * we can use cut_tree. Plan B files (for instance) can not be
++       * we can use reiser4_cut_tree. Plan B files (for instance) can not be
 +       * truncated that simply
 +       */
 +      result = cut_file_items(inode, new_size, 1 /*update_sd */ ,
-+                              get_key_offset(max_key()), update_file_size);
++                              get_key_offset(reiser4_max_key()),
++                              reiser4_update_file_size);
 +      if (result)
 +              return result;
 +
@@ -36152,7 +35688,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/file/file.c
 +              /* file is truncated to page boundary */
 +              return 0;
 +
-+      result = reserve_partial_page(tree_by_inode(inode));
++      result = reserve_partial_page(reiser4_tree_by_inode(inode));
 +      if (result) {
 +              reiser4_release_reserved(inode->i_sb);
 +              return result;
@@ -36160,10 +35696,10 @@ Index: linux-2.6.16/fs/reiser4/plugin/file/file.c
 +
 +      /* last page is partially truncated - zero its content */
 +      index = (inode->i_size >> PAGE_CACHE_SHIFT);
-+      page = read_cache_page(inode->i_mapping, index, filler, NULL);
++      page = read_mapping_page(inode->i_mapping, index, NULL);
 +      if (IS_ERR(page)) {
 +              /*
-+               * the below does up(sbinfo->delete_sema). Do not get
++               * the below does up(sbinfo->delete_mutex). Do not get
 +               * confused
 +               */
 +              reiser4_release_reserved(inode->i_sb);
@@ -36177,7 +35713,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/file/file.c
 +      if (!PageUptodate(page)) {
 +              page_cache_release(page);
 +              /*
-+               * the below does up(sbinfo->delete_sema). Do not get
++               * the below does up(sbinfo->delete_mutex). Do not get
 +               * confused
 +               */
 +              reiser4_release_reserved(inode->i_sb);
@@ -36197,7 +35733,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/file/file.c
 +      if (result) {
 +              page_cache_release(page);
 +              /*
-+               * the below does up(sbinfo->delete_sema). Do not get
++               * the below does up(sbinfo->delete_mutex). Do not get
 +               * confused
 +               */
 +              reiser4_release_reserved(inode->i_sb);
@@ -36206,13 +35742,10 @@ Index: linux-2.6.16/fs/reiser4/plugin/file/file.c
 +
 +      lock_page(page);
 +      assert("vs-1066", PageLocked(page));
-+      kaddr = kmap_atomic(page, KM_USER0);
-+      memset(kaddr + padd_from, 0, PAGE_CACHE_SIZE - padd_from);
-+      flush_dcache_page(page);
-+      kunmap_atomic(kaddr, KM_USER0);
++      zero_user_page(page, padd_from, PAGE_CACHE_SIZE - padd_from, KM_USER0);
 +      unlock_page(page);
 +      page_cache_release(page);
-+      /* the below does up(sbinfo->delete_sema). Do not get confused */
++      /* the below does up(sbinfo->delete_mutex). Do not get confused */
 +      reiser4_release_reserved(inode->i_sb);
 +      return 0;
 +}
@@ -36225,7 +35758,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/file/file.c
 + * Calls formatting plugin to see whether file of size @new_size has to be
 + * stored in unformatted nodes or in tail items. 0 is returned for later case.
 + */
-+static int should_have_notail(const unix_file_info_t *uf_info, loff_t new_size)
++static int should_have_notail(const struct unix_file_info *uf_info, loff_t new_size)
 +{
 +      if (!uf_info->tplug)
 +              return 1;
@@ -36251,7 +35784,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/file/file.c
 +              /* expanding truncate */
 +              struct dentry dentry;
 +              struct file file;
-+              unix_file_info_t *uf_info;
++              struct unix_file_info *uf_info;
 +
 +              dentry.d_inode = inode;
 +              file.f_dentry = &dentry;
@@ -36262,7 +35795,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/file/file.c
 +              result = find_file_state(inode, uf_info);
 +              if (result)
 +                      return result;
-+              
++
 +              if (should_have_notail(uf_info, new_size)) {
 +                      /*
 +                       * file of size @new_size has to be built of
@@ -36275,7 +35808,8 @@ Index: linux-2.6.16/fs/reiser4/plugin/file/file.c
 +                               * - wait until it completes
 +                               */
 +                              while (1) {
-+                                      if (inode_get_flag(inode, REISER4_PART_IN_CONV)) {
++                                      if (reiser4_inode_get_flag(inode,
++                                                                 REISER4_PART_IN_CONV)) {
 +                                              drop_exclusive_access(uf_info);
 +                                              schedule();
 +                                              get_exclusive_access(uf_info);
@@ -36283,24 +35817,27 @@ Index: linux-2.6.16/fs/reiser4/plugin/file/file.c
 +                                      }
 +                                      break;
 +                              }
-+                              
++
 +                              if (uf_info->container ==  UF_CONTAINER_TAILS) {
 +                                      result = tail2extent(uf_info);
 +                                      if (result)
 +                                              return result;
 +                              }
 +                      }
-+                      result = write_extent(&file, NULL, 0, &new_size);
++                      result = reiser4_write_extent(&file, NULL, 0,
++                                                    &new_size);
 +                      if (result)
 +                              return result;
 +                      uf_info->container = UF_CONTAINER_EXTENTS;
 +              } else {
 +                      if (uf_info->container ==  UF_CONTAINER_EXTENTS) {
-+                              result = write_extent(&file, NULL, 0, &new_size);
++                              result = reiser4_write_extent(&file, NULL, 0,
++                                                            &new_size);
 +                              if (result)
 +                                      return result;
 +                      } else {
-+                              result = write_tail(&file, NULL, 0, &new_size);
++                              result = reiser4_write_tail(&file, NULL, 0,
++                                                          &new_size);
 +                              if (result)
 +                                      return result;
 +                              uf_info->container = UF_CONTAINER_TAILS;
@@ -36340,7 +35877,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/file/file.c
 +                      return PTR_ERR(fsdata);
 +
 +              spin_lock_inode(file->f_dentry->d_inode);
-+              if (seal_is_set(&fsdata->reg.hint.seal)) {
++              if (reiser4_seal_is_set(&fsdata->reg.hint.seal)) {
 +                      *hint = fsdata->reg.hint;
 +                      init_lh(&hint->lh);
 +                      hint->ext_coord.lh = &hint->lh;
@@ -36376,7 +35913,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/file/file.c
 +
 +      assert("edward-1337", hint != NULL);
 +
-+      if (!file || !seal_is_set(&hint->seal))
++      if (!file || !reiser4_seal_is_set(&hint->seal))
 +              return;
 +      fsdata = reiser4_get_file_fsdata(file);
 +      assert("vs-965", !IS_ERR(fsdata));
@@ -36389,21 +35926,23 @@ Index: linux-2.6.16/fs/reiser4/plugin/file/file.c
 +      return;
 +}
 +
-+void unset_hint(hint_t * hint)
++void reiser4_unset_hint(hint_t * hint)
 +{
 +      assert("vs-1315", hint);
 +      hint->ext_coord.valid = 0;
-+      seal_done(&hint->seal);
++      reiser4_seal_done(&hint->seal);
 +      done_lh(&hint->lh);
 +}
 +
-+/* coord must be set properly. So, that set_hint has nothing to do */
-+void set_hint(hint_t * hint, const reiser4_key * key, znode_lock_mode mode)
++/* coord must be set properly. So, that reiser4_set_hint
++   has nothing to do */
++void reiser4_set_hint(hint_t * hint, const reiser4_key * key,
++                    znode_lock_mode mode)
 +{
 +      ON_DEBUG(coord_t * coord = &hint->ext_coord.coord);
 +      assert("vs-1207", WITH_DATA(coord->node, check_coord(coord, key)));
 +
-+      seal_init(&hint->seal, &hint->ext_coord.coord, key);
++      reiser4_seal_init(&hint->seal, &hint->ext_coord.coord, key);
 +      hint->offset = get_key_offset(key);
 +      hint->mode = mode;
 +      done_lh(&hint->lh);
@@ -36411,7 +35950,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/file/file.c
 +
 +int hint_is_set(const hint_t * hint)
 +{
-+      return seal_is_set(&hint->seal);
++      return reiser4_seal_is_set(&hint->seal);
 +}
 +
 +#if REISER4_DEBUG
@@ -36425,7 +35964,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/file/file.c
 +}
 +#endif
 +
-+int
++static int
 +hint_validate(hint_t * hint, const reiser4_key * key, int check_key,
 +            znode_lock_mode lock_mode)
 +{
@@ -36440,15 +35979,14 @@ Index: linux-2.6.16/fs/reiser4/plugin/file/file.c
 +              return RETERR(-E_REPEAT);
 +
 +      assert("vs-31", hint->ext_coord.lh == &hint->lh);
-+      return seal_validate(&hint->seal, &hint->ext_coord.coord, key,
-+                           hint->ext_coord.lh, lock_mode, ZNODE_LOCK_LOPRI);
++      return reiser4_seal_validate(&hint->seal, &hint->ext_coord.coord, key,
++                                   hint->ext_coord.lh, lock_mode,
++                                   ZNODE_LOCK_LOPRI);
 +}
 +
-+int xversion;
-+
 +/**
-+ * find_or_create_extent - 
-+ * @page: 
++ * find_or_create_extent -
++ * @page:
 + *
 + *
 + */
@@ -36467,31 +36005,35 @@ Index: linux-2.6.16/fs/reiser4/plugin/file/file.c
 +
 +      lock_page(page);
 +      node = jnode_of_page(page);
-+      unlock_page(page);
-+      if (IS_ERR(node))
++      if (IS_ERR(node)) {
++              unlock_page(page);
 +              return PTR_ERR(node);
++      }
++      JF_SET(node, JNODE_WRITE_PREPARED);
++      unlock_page(page);
 +
 +      if (node->blocknr == 0) {
 +              plugged_hole = 0;
-+              result = update_extent(inode, node,
-+                                     (loff_t)page->index << PAGE_CACHE_SHIFT,
-+                                     &plugged_hole);
++              result = reiser4_update_extent(inode, node, page_offset(page),
++                                             &plugged_hole);
 +              if (result) {
++                      JF_CLR(node, JNODE_WRITE_PREPARED);
 +                      jput(node);
-+                      warning("", "update_extent failed: %d", result);
++                      warning("", "reiser4_update_extent failed: %d", result);
 +                      return result;
 +              }
 +              if (plugged_hole)
 +                      reiser4_update_sd(inode);
 +      } else {
 +              spin_lock_jnode(node);
-+              result = try_capture(node, ZNODE_WRITE_LOCK, 0);
++              result = reiser4_try_capture(node, ZNODE_WRITE_LOCK, 0);
 +              BUG_ON(result != 0);
 +              jnode_make_dirty_locked(node);
 +              spin_unlock_jnode(node);
 +      }
 +
 +      BUG_ON(node->atom == NULL);
++      JF_CLR(node, JNODE_WRITE_PREPARED);
 +      jput(node);
 +
 +      if (get_current_context()->entd) {
@@ -36540,17 +36082,15 @@ Index: linux-2.6.16/fs/reiser4/plugin/file/file.c
 +             unix_file_inode_data(inode)->container == UF_CONTAINER_EXTENTS);
 +      /* page belongs to file */
 +      assert("vs-1393",
-+             inode->i_size > ((loff_t) page->index << PAGE_CACHE_SHIFT));
++             inode->i_size > page_offset(page));
 +
 +      /* page capture may require extent creation (if it does not exist yet)
 +         and stat data's update (number of blocks changes on extent
 +         creation) */
 +      grab_space_enable();
-+      result =
-+          reiser4_grab_space(2 *
-+                             estimate_one_insert_into_item(tree_by_inode
-+                                                           (inode)),
-+                             BA_CAN_COMMIT);
++      result = reiser4_grab_space(2 * estimate_one_insert_into_item
++                                  (reiser4_tree_by_inode(inode)),
++                                  BA_CAN_COMMIT);
 +      if (likely(!result))
 +              result = find_or_create_extent(page);
 +
@@ -36576,7 +36116,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/file/file.c
 +      SetPageUptodate(page);
 +
 +      inode = page->mapping->host;
-+      ctx = init_context(page->mapping->host->i_sb);
++      ctx = reiser4_init_context(page->mapping->host->i_sb);
 +      if (IS_ERR(ctx))
 +              return PTR_ERR(ctx);
 +      page_cache_get(page);
@@ -36695,7 +36235,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/file/file.c
 +      for (i = 0; i < pagevec_count(&pvec); i++) {
 +              /*
 +               * tag PAGECACHE_TAG_REISER4_MOVED will be cleared by
-+               * set_page_dirty_internal which is called when jnode is
++               * reiser4_set_page_dirty_internal which is called when jnode is
 +               * captured
 +               */
 +              result = capture_anonymous_page(pvec.pages[i]);
@@ -36782,7 +36322,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/file/file.c
 +              } else
 +                      atom = NULL;
 +              unlock_page(page);
-+              result = sync_atom(atom);
++              result = reiser4_sync_atom(atom);
 +      } while (result == -E_REPEAT);
 +      /*
 +       * ZAM-FIXME-HANS: document the logic of this loop, is it just to
@@ -36839,7 +36379,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/file/file.c
 +static int commit_file_atoms(struct inode *inode)
 +{
 +      int result;
-+      unix_file_info_t *uf_info;
++      struct unix_file_info *uf_info;
 +
 +      uf_info = unix_file_inode_data(inode);
 +
@@ -36858,7 +36398,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/file/file.c
 +      switch (uf_info->container) {
 +      case UF_CONTAINER_EXTENTS:
 +              /* find_file_state might open join an atom */
-+              txn_restart_current();
++              reiser4_txn_restart_current();
 +              result =
 +                  /*
 +                   * when we are called by
@@ -36898,7 +36438,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/file/file.c
 +       * commit current transaction: there can be captured nodes from
 +       * find_file_state() and finish_conversion().
 +       */
-+      txn_restart_current();
++      reiser4_txn_restart_current();
 +      return result;
 +}
 +
@@ -36915,7 +36455,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/file/file.c
 +                   struct writeback_control *wbc)
 +{
 +      int result;
-+      unix_file_info_t *uf_info;
++      struct unix_file_info *uf_info;
 +      pgoff_t pindex, jindex, nr_pages;
 +      long to_capture;
 +      struct inode *inode;
@@ -36925,10 +36465,10 @@ Index: linux-2.6.16/fs/reiser4/plugin/file/file.c
 +              result = 0;
 +              goto end;
 +      }
-+      jindex = pindex = wbc->start >> PAGE_CACHE_SHIFT;
++      jindex = pindex = wbc->range_start >> PAGE_CACHE_SHIFT;
 +      result = 0;
-+      nr_pages =
-+          (i_size_read(inode) + PAGE_CACHE_SIZE - 1) >> PAGE_CACHE_SHIFT;
++      nr_pages = size_in_pages(i_size_read(inode));
++
 +      uf_info = unix_file_inode_data(inode);
 +
 +      do {
@@ -36939,7 +36479,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/file/file.c
 +              else
 +                      to_capture = CAPTURE_APAGE_BURST;
 +
-+              ctx = init_context(inode->i_sb);
++              ctx = reiser4_init_context(inode->i_sb);
 +              if (IS_ERR(ctx)) {
 +                      result = PTR_ERR(ctx);
 +                      break;
@@ -36950,7 +36490,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/file/file.c
 +              assert("", LOCK_CNT_NIL(inode_sem_w));
 +              assert("", LOCK_CNT_NIL(inode_sem_r));
 +
-+              txn_restart_current();
++              reiser4_txn_restart_current();
 +
 +              /* we have to get nonexclusive access to the file */
 +              if (get_current_context()->entd) {
@@ -37039,7 +36579,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/file/file.c
 +                       * there are already pages to flush, flush them out, do
 +                       * not delay until end of reiser4_sync_inodes
 +                       */
-+                      writeout(inode->i_sb, wbc);
++                      reiser4_writeout(inode->i_sb, wbc);
 +                      get_current_context()->nr_captured = 0;
 +              }
 +      }
@@ -37064,7 +36604,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/file/file.c
 +      txn_atom *atom;
 +      reiser4_block_nr reserve;
 +
-+      ctx = init_context(dentry->d_inode->i_sb);
++      ctx = reiser4_init_context(dentry->d_inode->i_sb);
 +      if (IS_ERR(ctx))
 +              return PTR_ERR(ctx);
 +
@@ -37090,7 +36630,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/file/file.c
 + * Compose a key and search for item containing information about @page
 + * data. If item is found - its readpage method is called.
 + */
-+int readpage_unix_file_nolock(struct file *file, struct page *page)
++int readpage_unix_file(struct file *file, struct page *page)
 +{
 +      reiser4_context *ctx;
 +      int result;
@@ -37105,21 +36645,20 @@ Index: linux-2.6.16/fs/reiser4/plugin/file/file.c
 +      assert("vs-976", !PageUptodate(page));
 +      assert("vs-1061", page->mapping && page->mapping->host);
 +
-+      if ((page->mapping->host->i_size <=
-+           ((loff_t) page->index << PAGE_CACHE_SHIFT))) {
++      if (page->mapping->host->i_size <= page_offset(page)) {
 +              /* page is out of file already */
 +              unlock_page(page);
 +              return -EINVAL;
 +      }
 +
 +      inode = page->mapping->host;
-+      ctx = init_context(inode->i_sb);
++      ctx = reiser4_init_context(inode->i_sb);
 +      if (IS_ERR(ctx)) {
 +              unlock_page(page);
 +              return PTR_ERR(ctx);
 +      }
 +
-+      hint = kmalloc(sizeof(*hint), get_gfp_mask());
++      hint = kmalloc(sizeof(*hint), reiser4_ctx_gfp_mask_get());
 +      if (hint == NULL) {
 +              unlock_page(page);
 +              reiser4_exit_context(ctx);
@@ -37136,9 +36675,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/file/file.c
 +      lh = &hint->lh;
 +
 +      /* get key of first byte of the page */
-+      key_by_inode_and_offset_common(inode,
-+                                     (loff_t) page->index << PAGE_CACHE_SHIFT,
-+                                     &key);
++      key_by_inode_and_offset_common(inode, page_offset(page), &key);
 +
 +      /* look for file metadata corresponding to first byte of page */
 +      page_cache_get(page);
@@ -37155,7 +36692,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/file/file.c
 +              done_lh(lh);
 +              kfree(hint);
 +              unlock_page(page);
-+              txn_restart(ctx);
++              reiser4_txn_restart(ctx);
 +              reiser4_exit_context(ctx);
 +              return -EINVAL;
 +      }
@@ -37168,7 +36705,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/file/file.c
 +              done_lh(lh);
 +              kfree(hint);
 +              unlock_page(page);
-+              txn_restart(ctx);
++              reiser4_txn_restart(ctx);
 +              reiser4_exit_context(ctx);
 +              return result;
 +      }
@@ -37181,7 +36718,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/file/file.c
 +              done_lh(lh);
 +              kfree(hint);
 +              unlock_page(page);
-+              txn_restart(ctx);
++              reiser4_txn_restart(ctx);
 +              reiser4_exit_context(ctx);
 +              return 0;
 +      }
@@ -37192,13 +36729,12 @@ Index: linux-2.6.16/fs/reiser4/plugin/file/file.c
 +              done_lh(lh);
 +              kfree(hint);
 +              unlock_page(page);
-+              txn_restart(ctx);
++              reiser4_txn_restart(ctx);
 +              reiser4_exit_context(ctx);
 +              return result;
 +      }
 +
-+      validate_extended_coord(&hint->ext_coord,
-+                              (loff_t) page->index << PAGE_CACHE_SHIFT);
++      validate_extended_coord(&hint->ext_coord, page_offset(page));
 +
 +      if (!coord_is_existing_unit(coord)) {
 +              /* this indicates corruption */
@@ -37211,7 +36747,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/file/file.c
 +              done_lh(lh);
 +              kfree(hint);
 +              unlock_page(page);
-+              txn_restart(ctx);
++              reiser4_txn_restart(ctx);
 +              reiser4_exit_context(ctx);
 +              return RETERR(-EIO);
 +      }
@@ -37229,11 +36765,11 @@ Index: linux-2.6.16/fs/reiser4/plugin/file/file.c
 +      if (!result) {
 +              set_key_offset(&key,
 +                             (loff_t) (page->index + 1) << PAGE_CACHE_SHIFT);
-+              /* FIXME should call set_hint() */
-+              unset_hint(hint);
++              /* FIXME should call reiser4_set_hint() */
++              reiser4_unset_hint(hint);
 +      } else {
 +              unlock_page(page);
-+              unset_hint(hint);
++              reiser4_unset_hint(hint);
 +      }
 +      assert("vs-979",
 +             ergo(result == 0, (PageLocked(page) || PageUptodate(page))));
@@ -37250,22 +36786,126 @@ Index: linux-2.6.16/fs/reiser4/plugin/file/file.c
 +       * not be done when atom is not NULL because reiser4_writepage can not
 +       * kick entd and have to eflush
 +       */
-+      txn_restart(ctx);
++      reiser4_txn_restart(ctx);
 +      reiser4_exit_context(ctx);
 +      return result;
 +}
 +
-+/**
-+ * readpage_unix_file - readpage of struct address_space_operations
-+ * @file: file @page belongs to
-+ * @page: page to read
++struct uf_readpages_context {
++      lock_handle lh;
++      coord_t coord;
++};
++
++/* A callback function for readpages_unix_file/read_cache_pages.
++ * If the file is build of tails, then return error (-ENOENT).
 + *
-+ * Get non exclusive access to a file to avoid races with truncate. If page is
-+ * out of file - return error. Call readpage_unix_file_nolock to do the rest.
++ * @data -- a pointer to reiser4_readpages_context object,
++ *            to save the twig lock and the coord between
++ *            read_cache_page iterations.
++ * @page -- page to start read.
 + */
-+int readpage_unix_file(struct file *file, struct page *page)
++static int uf_readpages_filler(void * data, struct page * page)
 +{
-+      return readpage_unix_file_nolock(file, page);
++      struct uf_readpages_context *rc = data;
++      jnode * node;
++      int ret = 0;
++      reiser4_extent *ext;
++      __u64 ext_index;
++      int cbk_done = 0;
++      struct address_space * mapping = page->mapping;
++
++      if (PageUptodate(page)) {
++              unlock_page(page);
++              return 0;
++      }
++      page_cache_get(page);
++
++      if (rc->lh.node == 0) {
++              /* no twig lock  - have to do tree search. */
++              reiser4_key key;
++      repeat:
++              unlock_page(page);
++              key_by_inode_and_offset_common(
++                      mapping->host, page_offset(page), &key);
++              ret = coord_by_key(
++                      &get_super_private(mapping->host->i_sb)->tree,
++                      &key, &rc->coord, &rc->lh,
++                      ZNODE_READ_LOCK, FIND_EXACT,
++                      TWIG_LEVEL, TWIG_LEVEL, CBK_UNIQUE, NULL);
++              if (unlikely(ret))
++                      goto exit;
++              lock_page(page);
++              cbk_done = 1;
++      }
++      ret = zload(rc->coord.node);
++      if (unlikely(ret))
++              goto unlock;
++      if (!coord_is_existing_item(&rc->coord) ||
++          !item_is_extent(&rc->coord)) {
++              zrelse(rc->coord.node);
++              ret = RETERR(-EIO);
++              goto unlock;
++      }
++      ext = extent_by_coord(&rc->coord);
++      ext_index = extent_unit_index(&rc->coord);
++      if (page->index < ext_index ||
++          page->index >= ext_index + extent_get_width(ext)) {
++              /* the page index doesn't belong to the extent unit
++                 which the coord points to - release the lock and
++                 repeat with tree search. */
++              zrelse(rc->coord.node);
++              done_lh(&rc->lh);
++              /* we can be here after a CBK call only in case of
++                 corruption of the tree or the tree lookup algorithm bug. */
++              if (unlikely(cbk_done)) {
++                      ret = RETERR(-EIO);
++                      goto unlock;
++              }
++              goto repeat;
++      }
++      node = jnode_of_page(page);
++      if (unlikely(IS_ERR(node))) {
++              zrelse(rc->coord.node);
++              ret = PTR_ERR(node);
++              goto unlock;
++      }
++      ret = reiser4_do_readpage_extent(ext, page->index - ext_index, page);
++      jput(node);
++      zrelse(rc->coord.node);
++      if (likely(!ret))
++              goto exit;
++ unlock:
++      unlock_page(page);
++ exit:
++      page_cache_release(page);
++      return ret;
++}
++
++/**
++ * readpages_unix_file - called by the readahead code, starts reading for each
++ * page of given list of pages
++ */
++int readpages_unix_file(
++      struct file *file, struct address_space *mapping,
++      struct list_head *pages, unsigned nr_pages)
++{
++      reiser4_context *ctx;
++      struct uf_readpages_context rc;
++      int ret;
++
++      ctx = reiser4_init_context(mapping->host->i_sb);
++      if (IS_ERR(ctx)) {
++              put_pages_list(pages);
++              return PTR_ERR(ctx);
++      }
++      init_lh(&rc.lh);
++      ret = read_cache_pages(mapping, pages,  uf_readpages_filler, &rc);
++      done_lh(&rc.lh);
++      context_set_commit_async(ctx);
++      /* close the transaction to protect further page allocation from deadlocks */
++      reiser4_txn_restart(ctx);
++      reiser4_exit_context(ctx);
++      return ret;
 +}
 +
 +static reiser4_block_nr unix_file_estimate_read(struct inode *inode,
@@ -37280,10 +36920,10 @@ Index: linux-2.6.16/fs/reiser4/plugin/file/file.c
 +}
 +
 +/* this is called with nonexclusive access obtained, file's container can not change */
-+static size_t read_file(hint_t * hint, struct file *file,     /* file to read from to */
-+                      char __user *buf,       /* address of user-space buffer */
-+                      size_t count,   /* number of bytes to read */
-+                      loff_t * off)
++static ssize_t read_file(hint_t *hint, struct file *file,     /* file to read from to */
++                       char __user *buf,      /* address of user-space buffer */
++                       size_t count,  /* number of bytes to read */
++                       loff_t *off)
 +{
 +      int result;
 +      struct inode *inode;
@@ -37346,6 +36986,8 @@ Index: linux-2.6.16/fs/reiser4/plugin/file/file.c
 +      return (count - flow.length) ? (count - flow.length) : result;
 +}
 +
++static ssize_t read_unix_file_container_tails(struct file*, char __user*, size_t, loff_t*);
++
 +/**
 + * read_unix_file - read of struct file_operations
 + * @file: file to read from
@@ -37360,13 +37002,9 @@ Index: linux-2.6.16/fs/reiser4/plugin/file/file.c
 +                     loff_t *off)
 +{
 +      reiser4_context *ctx;
-+      int result;
++      ssize_t result;
 +      struct inode *inode;
-+      hint_t *hint;
-+      unix_file_info_t *uf_info;
-+      size_t count, read, left;
-+      reiser4_block_nr needed;
-+      loff_t size;
++      struct unix_file_info *uf_info;
 +
 +      if (unlikely(read_amount == 0))
 +              return 0;
@@ -37374,24 +37012,62 @@ Index: linux-2.6.16/fs/reiser4/plugin/file/file.c
 +      assert("umka-072", file != NULL);
 +      assert("umka-074", off != NULL);
 +      inode = file->f_dentry->d_inode;
-+      assert("vs-972", !inode_get_flag(inode, REISER4_NO_SD));
++      assert("vs-972", !reiser4_inode_get_flag(inode, REISER4_NO_SD));
 +
-+      ctx = init_context(inode->i_sb);
++      ctx = reiser4_init_context(inode->i_sb);
 +      if (IS_ERR(ctx))
 +              return PTR_ERR(ctx);
++      uf_info = unix_file_inode_data(inode);
++      if (uf_info->container == UF_CONTAINER_UNKNOWN) {
++              get_exclusive_access(uf_info);
++              result = find_file_state(inode, uf_info);
++              if (unlikely(result != 0))
++                      goto out;
++      } else
++              get_nonexclusive_access(uf_info);
++      result = reiser4_grab_space_force(unix_file_estimate_read(inode, read_amount),
++                                        BA_CAN_COMMIT);
++      if (unlikely(result != 0))
++              goto out;
++      if (uf_info->container == UF_CONTAINER_EXTENTS){
++              result = do_sync_read(file, buf, read_amount, off);
++      } else if (uf_info->container == UF_CONTAINER_TAILS ||
++                 reiser4_inode_get_flag(inode, REISER4_PART_IN_CONV) ||
++                 reiser4_inode_get_flag(inode, REISER4_PART_MIXED)) {
++              result = read_unix_file_container_tails(file, buf, read_amount, off);
++      } else {
++              assert("zam-1085", uf_info->container == UF_CONTAINER_EMPTY);
++              result = 0;
++      }
++out:
++       drop_access(uf_info);
++       context_set_commit_async(ctx);
++       reiser4_exit_context(ctx);
++       return result;
++}
 +
-+      hint = kmalloc(sizeof(*hint), get_gfp_mask());
-+      if (hint == NULL) {
-+              context_set_commit_async(ctx);
-+              reiser4_exit_context(ctx);
++static ssize_t read_unix_file_container_tails(
++      struct file *file, char __user *buf, size_t read_amount, loff_t *off)
++{
++      int result;
++      struct inode *inode;
++      hint_t *hint;
++      struct unix_file_info *uf_info;
++      size_t count, read, left;
++      loff_t size;
++
++      assert("umka-072", file != NULL);
++      assert("umka-074", off != NULL);
++      inode = file->f_dentry->d_inode;
++      assert("vs-972", !reiser4_inode_get_flag(inode, REISER4_NO_SD));
++
++      hint = kmalloc(sizeof(*hint), reiser4_ctx_gfp_mask_get());
++      if (hint == NULL)
 +              return RETERR(-ENOMEM);
-+      }
 +
 +      result = load_file_hint(file, hint);
 +      if (result) {
 +              kfree(hint);
-+              context_set_commit_async(ctx);
-+              reiser4_exit_context(ctx);
 +              return result;
 +      }
 +
@@ -37399,32 +37075,21 @@ Index: linux-2.6.16/fs/reiser4/plugin/file/file.c
 +      count = 0;
 +      uf_info = unix_file_inode_data(inode);
 +      while (left > 0) {
-+              txn_restart_current();
-+
-+              get_nonexclusive_access(uf_info);
-+
++              reiser4_txn_restart_current();
 +              size = i_size_read(inode);
-+              if (*off >= size) {
++              if (*off >= size)
 +                      /* position to read from is past the end of file */
-+                      drop_nonexclusive_access(uf_info);
 +                      break;
-+              }
 +              if (*off + left > size)
 +                      left = size - *off;
-+
 +              /* faultin user page */
-+              if(fault_in_pages_writeable(buf, left > PAGE_CACHE_SIZE ? PAGE_CACHE_SIZE : left)) {
-+                      drop_nonexclusive_access(uf_info);
-+                      result = RETERR(-EFAULT);
-+                      break;
-+              }
++              result = fault_in_pages_writeable(buf, left > PAGE_CACHE_SIZE ? PAGE_CACHE_SIZE : left);
++              if (result)
++                      return RETERR(-EFAULT);
 +
 +              read = read_file(hint, file, buf,
 +                               left > PAGE_CACHE_SIZE ? PAGE_CACHE_SIZE : left,
 +                               off);
-+
-+              drop_nonexclusive_access(uf_info);
-+
 +              if (read < 0) {
 +                      result = read;
 +                      break;
@@ -37437,26 +37102,11 @@ Index: linux-2.6.16/fs/reiser4/plugin/file/file.c
 +              /* total number of read bytes */
 +              count += read;
 +      }
-+      save_file_hint(file, hint);
 +      done_lh(&hint->lh);
++      save_file_hint(file, hint);
 +      kfree(hint);
-+
-+      if (count) {
-+              /*
-+               * something was read. Grab space for stat data update and
-+               * update atime
-+               */
-+              needed = unix_file_estimate_read(inode, read_amount);
-+              result = reiser4_grab_space_force(needed, BA_CAN_COMMIT);
-+              if (result == 0)
-+                      file_accessed(file);
-+              else
-+                      warning("", "failed to grab space for atime update");
-+      }
-+
-+      context_set_commit_async(ctx);
-+      reiser4_exit_context(ctx);
-+
++      if (count)
++              file_accessed(file);
 +      /* return number of read bytes or error code if nothing is read */
 +      return count ? count : result;
 +}
@@ -37493,18 +37143,17 @@ Index: linux-2.6.16/fs/reiser4/plugin/file/file.c
 +      reiser4_context *ctx;
 +      int result;
 +      struct inode *inode;
-+      unix_file_info_t *uf_info;
++      struct unix_file_info *uf_info;
 +      reiser4_block_nr needed;
 +
 +      inode = file->f_dentry->d_inode;
-+      ctx = init_context(inode->i_sb);
++      ctx = reiser4_init_context(inode->i_sb);
 +      if (IS_ERR(ctx))
 +              return PTR_ERR(ctx);
 +
 +      uf_info = unix_file_inode_data(inode);
 +
-+      down(&uf_info->write);
-+      get_exclusive_access(uf_info);
++      get_exclusive_access_careful(uf_info, inode);
 +
 +      if (!IS_RDONLY(inode) && (vma->vm_flags & (VM_MAYWRITE | VM_SHARED))) {
 +              /*
@@ -37515,7 +37164,6 @@ Index: linux-2.6.16/fs/reiser4/plugin/file/file.c
 +              result = find_file_state(inode, uf_info);
 +              if (result != 0) {
 +                      drop_exclusive_access(uf_info);
-+                      up(&uf_info->write);
 +                      reiser4_exit_context(ctx);
 +                      return result;
 +              }
@@ -37531,7 +37179,6 @@ Index: linux-2.6.16/fs/reiser4/plugin/file/file.c
 +                      result = check_pages_unix_file(file, inode);
 +                      if (result) {
 +                              drop_exclusive_access(uf_info);
-+                              up(&uf_info->write);
 +                              reiser4_exit_context(ctx);
 +                              return result;
 +                      }
@@ -37546,7 +37193,6 @@ Index: linux-2.6.16/fs/reiser4/plugin/file/file.c
 +      result = reiser4_grab_space_force(needed, BA_CAN_COMMIT);
 +      if (result) {
 +              drop_exclusive_access(uf_info);
-+              up(&uf_info->write);
 +              reiser4_exit_context(ctx);
 +              return result;
 +      }
@@ -37554,11 +37200,10 @@ Index: linux-2.6.16/fs/reiser4/plugin/file/file.c
 +      result = generic_file_mmap(file, vma);
 +      if (result == 0) {
 +              /* mark file as having mapping. */
-+              inode_set_flag(inode, REISER4_HAS_MMAP);
++              reiser4_inode_set_flag(inode, REISER4_HAS_MMAP);
 +      }
 +
 +      drop_exclusive_access(uf_info);
-+      up(&uf_info->write);
 +      reiser4_exit_context(ctx);
 +      return result;
 +}
@@ -37610,36 +37255,23 @@ Index: linux-2.6.16/fs/reiser4/plugin/file/file.c
 +{
 +      int result;
 +      reiser4_context *ctx;
-+      unix_file_info_t *uf_info;
++      struct unix_file_info *uf_info;
 +
 +      if (IS_RDONLY(inode))
 +              return 0;
 +
-+      if (!inode_get_flag(inode, REISER4_PART_MIXED))
++      if (!reiser4_inode_get_flag(inode, REISER4_PART_MIXED))
 +              return 0;
 +
-+      ctx = init_context(inode->i_sb);
++      ctx = reiser4_init_context(inode->i_sb);
 +      if (IS_ERR(ctx))
 +              return PTR_ERR(ctx);
 +
 +      uf_info = unix_file_inode_data(inode);
-+      get_exclusive_access(uf_info);
 +
-+      /*
-+       * it may happen that another process is doing tail conversion. Wait
-+       * until it completes
-+       */
-+      while (1) {
-+              if (inode_get_flag(inode, REISER4_PART_IN_CONV)) {
-+                      drop_exclusive_access(uf_info);
-+                      schedule();
-+                      get_exclusive_access(uf_info);
-+                      continue;
-+              }
-+              break;
-+      }
++      get_exclusive_access_careful(uf_info, inode);
 +
-+      if (!inode_get_flag(inode, REISER4_PART_MIXED)) {
++      if (!reiser4_inode_get_flag(inode, REISER4_PART_MIXED)) {
 +              /*
 +               * other process completed the conversion
 +               */
@@ -37670,8 +37302,9 @@ Index: linux-2.6.16/fs/reiser4/plugin/file/file.c
 +              result = -EIO;
 +
 +      assert("vs-1712",
-+             ergo(result == 0, (!inode_get_flag(inode, REISER4_PART_MIXED) &&
-+                                !inode_get_flag(inode, REISER4_PART_IN_CONV))));
++             ergo(result == 0,
++                  (!reiser4_inode_get_flag(inode, REISER4_PART_MIXED) &&
++                   !reiser4_inode_get_flag(inode, REISER4_PART_IN_CONV))));
 +      drop_exclusive_access(uf_info);
 +      reiser4_exit_context(ctx);
 +      return result;
@@ -37681,7 +37314,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/file/file.c
 +#define EA_OBTAINED 1
 +#define NEA_OBTAINED 2
 +
-+static void drop_access(unix_file_info_t *uf_info)
++static void drop_access(struct unix_file_info *uf_info)
 +{
 +      if (uf_info->exclusive_use)
 +              drop_exclusive_access(uf_info);
@@ -37692,8 +37325,6 @@ Index: linux-2.6.16/fs/reiser4/plugin/file/file.c
 +#define debug_wuf(format, ...) printk("%s: %d: %s: " format "\n", \
 +                            __FILE__, __LINE__, __FUNCTION__, ## __VA_ARGS__)
 +
-+void balance_dirty_pages(struct address_space *mapping);
-+
 +/**
 + * write_unix_file - write of struct file_operations
 + * @file: file to write to
@@ -37710,7 +37341,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/file/file.c
 +      int result;
 +      reiser4_context *ctx;
 +      struct inode *inode;
-+      unix_file_info_t *uf_info;
++      struct unix_file_info *uf_info;
 +      ssize_t written;
 +      int try_free_space;
 +      int to_write = PAGE_CACHE_SIZE * WRITE_GRANULARITY;
@@ -37721,14 +37352,14 @@ Index: linux-2.6.16/fs/reiser4/plugin/file/file.c
 +      loff_t new_size;
 +
 +      inode = file->f_dentry->d_inode;
-+      ctx = init_context(inode->i_sb);
++      ctx = reiser4_init_context(inode->i_sb);
 +      if (IS_ERR(ctx))
 +              return PTR_ERR(ctx);
 +
 +      mutex_lock(&inode->i_mutex);
 +
-+      assert("vs-947", !inode_get_flag(inode, REISER4_NO_SD));
-+      assert("vs-9471", (!inode_get_flag(inode, REISER4_PART_MIXED)));
++      assert("vs-947", !reiser4_inode_get_flag(inode, REISER4_NO_SD));
++      assert("vs-9471", (!reiser4_inode_get_flag(inode, REISER4_PART_MIXED)));
 +
 +      /* check amount of bytes to write and writing position */
 +      result = generic_write_checks(file, pos, &count, 0);
@@ -37746,6 +37377,8 @@ Index: linux-2.6.16/fs/reiser4/plugin/file/file.c
 +              reiser4_exit_context(ctx);
 +              return result;
 +      }
++      /* remove_suid might create a transaction */
++      reiser4_txn_restart(ctx);
 +
 +      uf_info = unix_file_inode_data(inode);
 +
@@ -37793,13 +37426,13 @@ Index: linux-2.6.16/fs/reiser4/plugin/file/file.c
 +              /* either EA or NEA is obtained. Choose item write method */
 +              if (uf_info->container == UF_CONTAINER_EXTENTS) {
 +                      /* file is built of extent items */
-+                      write_op = write_extent;
++                      write_op = reiser4_write_extent;
 +              } else if (uf_info->container == UF_CONTAINER_EMPTY) {
 +                      /* file is empty */
 +                      if (should_have_notail(uf_info, new_size))
-+                              write_op = write_extent;
++                              write_op = reiser4_write_extent;
 +                      else
-+                              write_op = write_tail;
++                              write_op = reiser4_write_tail;
 +              } else {
 +                      /* file is built of tail items */
 +                      if (should_have_notail(uf_info, new_size)) {
@@ -37814,14 +37447,15 @@ Index: linux-2.6.16/fs/reiser4/plugin/file/file.c
 +                                       * process - wait until it completes
 +                                       */
 +                                      while (1) {
-+                                              if (inode_get_flag(inode, REISER4_PART_IN_CONV)) {
++                                              if (reiser4_inode_get_flag(inode,
++                                                                         REISER4_PART_IN_CONV)) {
 +                                                      drop_exclusive_access(uf_info);
 +                                                      schedule();
 +                                                      get_exclusive_access(uf_info);
 +                                                      continue;
 +                                              }
 +                                              break;
-+                                      }                                       
++                                      }
 +                                      if (uf_info->container ==  UF_CONTAINER_TAILS) {
 +                                              result = tail2extent(uf_info);
 +                                              if (result)
@@ -37832,7 +37466,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/file/file.c
 +                              ea = NEITHER_OBTAINED;
 +                              continue;
 +                      }
-+                      write_op = write_tail;
++                      write_op = reiser4_write_tail;
 +              }
 +
 +              written = write_op(file, buf, to_write, pos);
@@ -37850,13 +37484,14 @@ Index: linux-2.6.16/fs/reiser4/plugin/file/file.c
 +              /* something is written. */
 +              if (uf_info->container == UF_CONTAINER_EMPTY) {
 +                      assert("", ea == EA_OBTAINED);
-+                      uf_info->container = (write_op == write_extent) ? 
++                      uf_info->container =
++                              (write_op == reiser4_write_extent) ?
 +                              UF_CONTAINER_EXTENTS : UF_CONTAINER_TAILS;
 +              } else {
 +                      assert("", ergo(uf_info->container == UF_CONTAINER_EXTENTS,
-+                                      write_op == write_extent));
++                                      write_op == reiser4_write_extent));
 +                      assert("", ergo(uf_info->container == UF_CONTAINER_TAILS,
-+                                      write_op == write_tail));
++                                      write_op == reiser4_write_tail));
 +              }
 +              if (*pos + written > inode->i_size)
 +                      INODE_SET_FIELD(inode, i_size, *pos + written);
@@ -37872,13 +37507,14 @@ Index: linux-2.6.16/fs/reiser4/plugin/file/file.c
 +              }
 +              drop_access(uf_info);
 +              ea = NEITHER_OBTAINED;
-+              txn_restart(ctx);
++              reiser4_txn_restart(ctx);
 +              current->journal_info = NULL;
 +              /*
 +               * tell VM how many pages were dirtied. Maybe number of pages
 +               * which were dirty already should not be counted
 +               */
-+              balance_dirty_pages(inode->i_mapping);
++              balance_dirty_pages_ratelimited_nr(inode->i_mapping,
++                                                 (written + PAGE_CACHE_SIZE - 1) / PAGE_CACHE_SIZE);
 +              current->journal_info = ctx;
 +
 +              left -= written;
@@ -37889,7 +37525,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/file/file.c
 +      mutex_unlock(&inode->i_mutex);
 +
 +      if (result == 0 && ((file->f_flags & O_SYNC) || IS_SYNC(inode))) {
-+              txn_restart_current();
++              reiser4_txn_restart_current();
 +              grab_space_enable();
 +              result = sync_unix_file(file, file->f_dentry,
 +                                      0 /* data and stat data */ );
@@ -37922,13 +37558,13 @@ Index: linux-2.6.16/fs/reiser4/plugin/file/file.c
 +int release_unix_file(struct inode *inode, struct file *file)
 +{
 +      reiser4_context *ctx;
-+      unix_file_info_t *uf_info;
++      struct unix_file_info *uf_info;
 +      int result;
 +      int in_reiser4;
 +
 +      in_reiser4 = is_in_reiser4_context();
 +
-+      ctx = init_context(inode->i_sb);
++      ctx = reiser4_init_context(inode->i_sb);
 +      if (IS_ERR(ctx))
 +              return PTR_ERR(ctx);
 +
@@ -37936,8 +37572,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/file/file.c
 +      if (in_reiser4 == 0) {
 +              uf_info = unix_file_inode_data(inode);
 +
-+              down(&uf_info->write);
-+              get_exclusive_access(uf_info);
++              get_exclusive_access_careful(uf_info, inode);
 +              if (atomic_read(&file->f_dentry->d_count) == 1 &&
 +                  uf_info->container == UF_CONTAINER_EXTENTS &&
 +                  !should_have_notail(uf_info, inode->i_size) &&
@@ -37952,7 +37587,6 @@ Index: linux-2.6.16/fs/reiser4/plugin/file/file.c
 +                      }
 +              }
 +              drop_exclusive_access(uf_info);
-+              up(&uf_info->write);
 +      } else {
 +              /*
 +                 we are within reiser4 context already. How latter is
@@ -37976,7 +37610,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/file/file.c
 +                 #15 0xc01131e5 in do_page_fault ()
 +                 #16 0xc0104935 in error_code ()
 +                 #17 0xc025c0c6 in __copy_to_user_ll ()
-+                 #18 0xc01d496f in read_tail ()
++                 #18 0xc01d496f in reiser4_read_tail ()
 +                 #19 0xc01e4def in read_unix_file ()
 +                 #20 0xc01c3504 in reiser4_read ()
 +                 #21 0xc014bd4f in vfs_read ()
@@ -37998,16 +37632,14 @@ Index: linux-2.6.16/fs/reiser4/plugin/file/file.c
 +
 +      state = reiser4_inode_data(inode);
 +      tplug = formatting_plugin_by_id(NEVER_TAILS_FORMATTING_ID);
-+      plugin_set_formatting(&state->pset, tplug);
-+      inode_set_plugin(inode,
-+                       formatting_plugin_to_plugin(tplug), PSET_FORMATTING);
++      force_plugin_pset(inode, PSET_FORMATTING, (reiser4_plugin *)tplug);
 +}
 +
 +/* if file is built of tails - convert it to extents */
 +static int unpack(struct file *filp, struct inode *inode, int forever)
 +{
 +      int result = 0;
-+      unix_file_info_t *uf_info;
++      struct unix_file_info *uf_info;
 +
 +      uf_info = unix_file_inode_data(inode);
 +      assert("vs-1628", ea_obtained(uf_info));
@@ -38023,7 +37655,8 @@ Index: linux-2.6.16/fs/reiser4/plugin/file/file.c
 +               * completes
 +               */
 +              while (1) {
-+                      if (inode_get_flag(inode, REISER4_PART_IN_CONV)) {
++                      if (reiser4_inode_get_flag(inode,
++                                                 REISER4_PART_IN_CONV)) {
 +                              drop_exclusive_access(uf_info);
 +                              schedule();
 +                              get_exclusive_access(uf_info);
@@ -38040,15 +37673,15 @@ Index: linux-2.6.16/fs/reiser4/plugin/file/file.c
 +      if (forever) {
 +              /* safe new formatting plugin in stat data */
 +              __u64 tograb;
-+              
++
 +              set_file_notail(inode);
-+              
++
 +              grab_space_enable();
 +              tograb = inode_file_plugin(inode)->estimate.update(inode);
 +              result = reiser4_grab_space(tograb, BA_CAN_COMMIT);
 +              result = reiser4_update_sd(inode);
 +      }
-+      
++
 +      return result;
 +}
 +
@@ -38062,7 +37695,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/file/file.c
 +      reiser4_context *ctx;
 +      int result;
 +
-+      ctx = init_context(inode->i_sb);
++      ctx = reiser4_init_context(inode->i_sb);
 +      if (IS_ERR(ctx))
 +              return PTR_ERR(ctx);
 +
@@ -38097,7 +37730,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/file/file.c
 +
 +      inode = mapping->host;
 +
-+      ctx = init_context(inode->i_sb);
++      ctx = reiser4_init_context(inode->i_sb);
 +      if (IS_ERR(ctx))
 +              return PTR_ERR(ctx);
 +      key_by_inode_and_offset_common(inode,
@@ -38170,7 +37803,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/file/file.c
 +   plugin->u.file.create_blank_sd = NULL */
 +/* plugin->u.file.delete */
 +/*
-+   plugin->u.file.add_link = add_link_common
++   plugin->u.file.add_link = reiser4_add_link_common
 +   plugin->u.file.rem_link = NULL */
 +
 +/* plugin->u.file.owns_item
@@ -38185,7 +37818,8 @@ Index: linux-2.6.16/fs/reiser4/plugin/file/file.c
 +      result = owns_item_common(inode, coord);
 +      if (!result)
 +              return 0;
-+      if (item_type_by_coord(coord) != UNIX_FILE_METADATA_ITEM_TYPE)
++      if (!plugin_of_group(item_plugin_by_coord(coord),
++                           UNIX_FILE_METADATA_ITEM_TYPE))
 +              return 0;
 +      assert("vs-547",
 +             item_id_by_coord(coord) == EXTENT_POINTER_ID ||
@@ -38203,7 +37837,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/file/file.c
 +      inode_check_scale(inode, inode->i_size, attr->ia_size);
 +
 +      old_size = inode->i_size;
-+      tree = tree_by_inode(inode);
++      tree = reiser4_tree_by_inode(inode);
 +
 +      result = safe_link_grab(tree, BA_CAN_COMMIT);
 +      if (result == 0)
@@ -38238,24 +37872,22 @@ Index: linux-2.6.16/fs/reiser4/plugin/file/file.c
 +
 +      if (attr->ia_valid & ATTR_SIZE) {
 +              reiser4_context *ctx;
-+              unix_file_info_t *uf_info;
++              struct unix_file_info *uf_info;
 +
 +              /* truncate does reservation itself and requires exclusive
 +                 access obtained */
-+              ctx = init_context(dentry->d_inode->i_sb);
++              ctx = reiser4_init_context(dentry->d_inode->i_sb);
 +              if (IS_ERR(ctx))
 +                      return PTR_ERR(ctx);
 +
 +              uf_info = unix_file_inode_data(dentry->d_inode);
-+              down(&uf_info->write);
-+              get_exclusive_access(uf_info);
++              get_exclusive_access_careful(uf_info, dentry->d_inode);
 +              result = setattr_truncate(dentry->d_inode, attr);
 +              drop_exclusive_access(uf_info);
-+              up(&uf_info->write);
 +              context_set_commit_async(ctx);
 +              reiser4_exit_context(ctx);
 +      } else
-+              result = setattr_common(dentry, attr);
++              result = reiser4_setattr_common(dentry, attr);
 +
 +      return result;
 +}
@@ -38265,12 +37897,11 @@ Index: linux-2.6.16/fs/reiser4/plugin/file/file.c
 +init_inode_data_unix_file(struct inode *inode,
 +                        reiser4_object_create_data * crd, int create)
 +{
-+      unix_file_info_t *data;
++      struct unix_file_info *data;
 +
 +      data = unix_file_inode_data(inode);
 +      data->container = create ? UF_CONTAINER_EMPTY : UF_CONTAINER_UNKNOWN;
 +      init_rwsem(&data->latch);
-+      sema_init(&data->write, 1);
 +      data->tplug = inode_formatting_plugin(inode);
 +      data->exclusive_use = 0;
 +
@@ -38289,10 +37920,10 @@ Index: linux-2.6.16/fs/reiser4/plugin/file/file.c
 + */
 +int delete_object_unix_file(struct inode *inode)
 +{
-+      unix_file_info_t *uf_info;
++      struct unix_file_info *uf_info;
 +      int result;
 +
-+      if (inode_get_flag(inode, REISER4_NO_SD))
++      if (reiser4_inode_get_flag(inode, REISER4_NO_SD))
 +              return 0;
 +
 +      /* truncate file bogy first */
@@ -38306,7 +37937,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/file/file.c
 +                      get_inode_oid(inode), result);
 +
 +      /* remove stat data and safe link */
-+      return delete_object_common(inode);
++      return reiser4_delete_object_common(inode);
 +}
 +
 +/**
@@ -38327,10 +37958,10 @@ Index: linux-2.6.16/fs/reiser4/plugin/file/file.c
 +      reiser4_context *ctx;
 +      ssize_t result;
 +      struct inode *inode;
-+      unix_file_info_t *uf_info;
++      struct unix_file_info *uf_info;
 +
 +      inode = file->f_dentry->d_inode;
-+      ctx = init_context(inode->i_sb);
++      ctx = reiser4_init_context(inode->i_sb);
 +      if (IS_ERR(ctx))
 +              return PTR_ERR(ctx);
 +
@@ -38343,7 +37974,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/file/file.c
 +      if (result)
 +              goto error;
 +      mutex_lock(&inode->i_mutex);
-+      inode_set_flag(inode, REISER4_HAS_MMAP);
++      reiser4_inode_set_flag(inode, REISER4_HAS_MMAP);
 +      mutex_unlock(&inode->i_mutex);
 +
 +      uf_info = unix_file_inode_data(inode);
@@ -38360,10 +37991,10 @@ Index: linux-2.6.16/fs/reiser4/plugin/file/file.c
 +                      unsigned from, unsigned to)
 +{
 +      reiser4_context *ctx;
-+      unix_file_info_t *uf_info;
++      struct unix_file_info *uf_info;
 +      int ret;
 +
-+      ctx = init_context(file->f_dentry->d_inode->i_sb);
++      ctx = reiser4_init_context(file->f_dentry->d_inode->i_sb);
 +      if (IS_ERR(ctx))
 +              return PTR_ERR(ctx);
 +
@@ -38394,16 +38025,629 @@ Index: linux-2.6.16/fs/reiser4/plugin/file/file.c
 + * scroll-step: 1
 + * End:
 + */
-Index: linux-2.6.16/fs/reiser4/plugin/file/file.h
-===================================================================
---- /dev/null
-+++ linux-2.6.16/fs/reiser4/plugin/file/file.h
-@@ -0,0 +1,257 @@
+diff -urN linux-2.6.22.orig/fs/reiser4/plugin/file/file_conversion.c linux-2.6.22/fs/reiser4/plugin/file/file_conversion.c
+--- linux-2.6.22.orig/fs/reiser4/plugin/file/file_conversion.c 1970-01-01 03:00:00.000000000 +0300
++++ linux-2.6.22/fs/reiser4/plugin/file/file_conversion.c      2007-07-29 00:25:34.928709936 +0400
+@@ -0,0 +1,609 @@
++/* Copyright 2001, 2002, 2003 by Hans Reiser,
++   licensing governed by reiser4/README */
++
++/* This file contains hooks that converts (*) cryptcompress files to unix-files,
++   and a set of protected (**) methods of a cryptcompress file plugin to perform
++   such conversion.
++
++(*)
++   The conversion is performed for incompressible files to reduce cpu and memory
++   usage. If first logical cluster (64K by default) of a file is incompressible,
++   then we make a desicion, that the whole file is incompressible.
++   The conversion can be enabled via installing a special compression mode
++   plugin (CONVX_COMPRESSION_MODE_ID, see plugin/compress/compress_mode.c for
++   details).
++
++(**)
++   The protection means serialization of critical sections (readers and writers
++   of @pset->file)
++*/
++
++#include "../../inode.h"
++#include "../cluster.h"
++#include "file.h"
++
++#define conversion_enabled(inode)                                      \
++       (inode_compression_mode_plugin(inode) ==                      \
++        compression_mode_plugin_by_id(CONVX_COMPRESSION_MODE_ID))
++
++
++/* Located sections (readers and writers of @pset->file) are not
++   permanently critical: cryptcompress file can be converted only
++   if the conversion is enabled (see the macrio above). And we don't
++   convert unix files at all.
++   The following helper macro is a sanity check to decide if we
++   need to protect a located section.
++*/
++#define should_protect(inode)                                         \
++      (inode_file_plugin(inode) ==                                    \
++       file_plugin_by_id(CRYPTCOMPRESS_FILE_PLUGIN_ID) &&             \
++       conversion_enabled(inode))
++
++/* All protected methods have prefix "prot" in their names.
++   It is convenient to construct them by usual (unprotected) ones
++   using the following common macros:
++*/
++
++/* Macro for passive protection.
++   method_cryptcompress contains only readers */
++#define PROT_PASSIVE(type, method, args)                              \
++({                                                                    \
++      type _result;                                                   \
++      struct rw_semaphore * guard =                                   \
++              &reiser4_inode_data(inode)->conv_sem;                   \
++                                                                      \
++      if (should_protect(inode)) {                                    \
++              down_read(guard);                                       \
++              if (!should_protect(inode))                             \
++                      up_read(guard);                                 \
++      }                                                               \
++      if (inode_file_plugin(inode) ==                                 \
++          file_plugin_by_id(UNIX_FILE_PLUGIN_ID))                     \
++              _result = method ## _unix_file args;                    \
++      else                                                            \
++              _result = method ## _cryptcompress args;                \
++      if (should_protect(inode))                                      \
++              up_read(guard);                                         \
++      _result;                                                        \
++})
++
++#define PROT_PASSIVE_VOID(method, args)                                       \
++({                                                                    \
++      struct rw_semaphore * guard =                                   \
++              &reiser4_inode_data(inode)->conv_sem;                   \
++                                                                      \
++      if (should_protect(inode)) {                                    \
++              down_read(guard);                                       \
++              if (!should_protect(inode))                             \
++                      up_read(guard);                                 \
++      }                                                               \
++      if (inode_file_plugin(inode) ==                                 \
++          file_plugin_by_id(UNIX_FILE_PLUGIN_ID))                     \
++              method ## _unix_file args;                              \
++      else                                                            \
++              method ## _cryptcompress args;                          \
++      if (should_protect(inode))                                      \
++              up_read(guard);                                         \
++})
++
++/* Macro for active protection.
++   active_expr contains readers and writers; after its
++   evaluation conversion should be disabled */
++#define PROT_ACTIVE(type, method, args, active_expr)                  \
++({                                                                    \
++      type _result = 0;                                               \
++      struct rw_semaphore * guard =                                   \
++              &reiser4_inode_data(inode)->conv_sem;                   \
++      reiser4_context * ctx = reiser4_init_context(inode->i_sb);      \
++      if (IS_ERR(ctx))                                                \
++              return PTR_ERR(ctx);                                    \
++                                                                      \
++      if (should_protect(inode)) {                                    \
++              down_write(guard);                                      \
++              if (should_protect(inode))                              \
++                      _result = active_expr;                          \
++              up_write(guard);                                        \
++      }                                                               \
++      if (_result == 0) {                                             \
++              if (inode_file_plugin(inode) ==                         \
++                  file_plugin_by_id(UNIX_FILE_PLUGIN_ID))             \
++                      _result =  method ## _unix_file args;           \
++              else                                                    \
++                      _result =  method ## _cryptcompress args;       \
++      }                                                               \
++      reiser4_exit_context(ctx);                                      \
++      _result;                                                        \
++})
++
++/* Pass management to the unix-file plugin with "notail" policy */
++static int __cryptcompress2unixfile(struct file *file, struct inode * inode)
++{
++      int result;
++      reiser4_inode *info;
++      struct unix_file_info * uf;
++      info = reiser4_inode_data(inode);
++
++      result = aset_set_unsafe(&info->pset,
++                          PSET_FILE,
++                          (reiser4_plugin *)
++                          file_plugin_by_id(UNIX_FILE_PLUGIN_ID));
++      if (result)
++              return result;
++      result = aset_set_unsafe(&info->pset,
++                          PSET_FORMATTING,
++                          (reiser4_plugin *)
++                          formatting_plugin_by_id(NEVER_TAILS_FORMATTING_ID));
++      if (result)
++              return result;
++      /* get rid of non-standard plugins */
++      info->plugin_mask &= ~cryptcompress_mask;
++      /* get rid of plugin stat-data extension */
++      info->extmask &= ~(1 << PLUGIN_STAT);
++
++      reiser4_inode_clr_flag(inode, REISER4_SDLEN_KNOWN);
++
++      /* FIXME use init_inode_data_unix_file() instead,
++         but aviod init_inode_ordering() */
++      /* Init unix-file specific part of inode */
++      uf = unix_file_inode_data(inode);
++      uf->container = UF_CONTAINER_UNKNOWN;
++      init_rwsem(&uf->latch);
++      uf->tplug = inode_formatting_plugin(inode);
++      uf->exclusive_use = 0;
++#if REISER4_DEBUG
++      uf->ea_owner = NULL;
++      atomic_set(&uf->nr_neas, 0);
++#endif
++      inode->i_op =
++              &file_plugin_by_id(UNIX_FILE_PLUGIN_ID)->inode_ops;
++      inode->i_fop =
++              &file_plugin_by_id(UNIX_FILE_PLUGIN_ID)->file_ops;
++      inode->i_mapping->a_ops =
++              &file_plugin_by_id(UNIX_FILE_PLUGIN_ID)->as_ops;
++      file->f_op = inode->i_fop;
++      return 0;
++}
++
++#if REISER4_DEBUG
++static int disabled_conversion_inode_ok(struct inode * inode)
++{
++      __u64 extmask = reiser4_inode_data(inode)->extmask;
++      __u16 plugin_mask = reiser4_inode_data(inode)->plugin_mask;
++
++      return ((extmask & (1 << LIGHT_WEIGHT_STAT)) &&
++              (extmask & (1 << UNIX_STAT)) &&
++              (extmask & (1 << LARGE_TIMES_STAT)) &&
++              (extmask & (1 << PLUGIN_STAT)) &&
++              (plugin_mask & (1 << PSET_COMPRESSION_MODE)));
++}
++#endif
++
++/* Assign another mode that will control
++   compression at flush time only */
++static int disable_conversion_no_update_sd(struct inode * inode)
++{
++      int result;
++      result =
++             force_plugin_pset(inode,
++                               PSET_COMPRESSION_MODE,
++                               (reiser4_plugin *)compression_mode_plugin_by_id
++                               (LATTD_COMPRESSION_MODE_ID));
++      assert("edward-1500",
++             ergo(!result, disabled_conversion_inode_ok(inode)));
++      return result;
++}
++
++/* Disable future attempts to check/convert. This function is called by
++   conversion hooks. */
++static int disable_conversion(struct inode * inode)
++{
++      return disable_conversion_no_update_sd(inode);
++}
++
++static int check_position(struct inode * inode,
++                        loff_t pos /* position in the file to write from */,
++                        struct cluster_handle * clust,
++                        int * check_compress)
++{
++      assert("edward-1505", conversion_enabled(inode));
++      /*
++       * if file size is more then cluster size, then compressible
++       * status must be figured out (i.e. compression was disabled,
++       * or file plugin was converted to unix_file)
++       */
++      assert("edward-1506", inode->i_size <= inode_cluster_size(inode));
++
++      if (pos > inode->i_size)
++              /* first logical cluster will contain a (partial) hole */
++              return disable_conversion(inode);
++      if (pos < inode_cluster_size(inode))
++              /* writing to the first logical cluster */
++              return 0;
++      /*
++       * here we have:
++       * cluster_size <= pos <= i_size <= cluster_size,
++       * and, hence,  pos == i_size == cluster_size
++       */
++      assert("edward-1498",
++             pos == inode->i_size &&
++             pos == inode_cluster_size(inode));
++
++      *check_compress = 1;
++      return 0;
++}
++
++static void start_check_compressibility(struct inode * inode,
++                                      struct cluster_handle * clust,
++                                      hint_t * hint)
++{
++      assert("edward-1507", clust->index == 1);
++      assert("edward-1508", !tfm_cluster_is_uptodate(&clust->tc));
++      assert("edward-1509", cluster_get_tfm_act(&clust->tc) == TFMA_READ);
++
++      hint_init_zero(hint);
++      clust->hint = hint;
++      clust->index --;
++      clust->nr_pages = size_in_pages(lbytes(clust->index, inode));
++
++      /* first logical cluster (of index #0) must be complete */
++      assert("edward-1510", lbytes(clust->index, inode) ==
++             inode_cluster_size(inode));
++}
++
++static void finish_check_compressibility(struct inode * inode,
++                                       struct cluster_handle * clust,
++                                       hint_t * hint)
++{
++      reiser4_unset_hint(clust->hint);
++      clust->hint = hint;
++      clust->index ++;
++}
++
++#if REISER4_DEBUG
++static int prepped_dclust_ok(hint_t * hint)
++{
++      reiser4_key key;
++      coord_t * coord = &hint->ext_coord.coord;
++
++      item_key_by_coord(coord, &key);
++      return (item_id_by_coord(coord) == CTAIL_ID &&
++              !coord_is_unprepped_ctail(coord) &&
++              (get_key_offset(&key) + nr_units_ctail(coord) ==
++               dclust_get_extension_dsize(hint)));
++}
++#endif
++
++#define fifty_persent(size) (size >> 1)
++/* evaluation of data compressibility */
++#define data_is_compressible(osize, isize)            \
++      (osize < fifty_persent(isize))
++
++/* This is called only once per file life.
++   Read first logical cluster (of index #0) and estimate its compressibility.
++   Save estimation result in @compressible */
++static int read_check_compressibility(struct inode * inode,
++                                    struct cluster_handle * clust,
++                                    int * compressible)
++{
++      int i;
++      int result;
++      __u32 dst_len;
++      hint_t tmp_hint;
++      hint_t * cur_hint = clust->hint;
++
++      start_check_compressibility(inode, clust, &tmp_hint);
++
++      reset_cluster_pgset(clust, cluster_nrpages(inode));
++      result = grab_page_cluster(inode, clust, READ_OP);
++      if (result)
++              return result;
++      /* Read page cluster here */
++      for (i = 0; i < clust->nr_pages; i++) {
++              struct page *page = clust->pages[i];
++              lock_page(page);
++              result = do_readpage_ctail(inode, clust, page,
++                                         ZNODE_READ_LOCK);
++              unlock_page(page);
++              if (result)
++                      goto error;
++      }
++      tfm_cluster_clr_uptodate(&clust->tc);
++
++      cluster_set_tfm_act(&clust->tc, TFMA_WRITE);
++
++      if (hint_is_valid(&tmp_hint) && !hint_is_unprepped_dclust(&tmp_hint)) {
++              /* lenght of compressed data is known, no need to compress */
++              assert("edward-1511",
++                     znode_is_any_locked(tmp_hint.lh.node));
++              assert("edward-1512",
++                     WITH_DATA(tmp_hint.ext_coord.coord.node,
++                               prepped_dclust_ok(&tmp_hint)));
++              dst_len = dclust_get_extension_dsize(&tmp_hint);
++      }
++      else {
++              struct tfm_cluster * tc = &clust->tc;
++              compression_plugin * cplug = inode_compression_plugin(inode);
++              result = grab_tfm_stream(inode, tc, INPUT_STREAM);
++              if (result)
++                      goto error;
++              for (i = 0; i < clust->nr_pages; i++) {
++                      char *data;
++                      lock_page(clust->pages[i]);
++                      BUG_ON(!PageUptodate(clust->pages[i]));
++                      data = kmap(clust->pages[i]);
++                      memcpy(tfm_stream_data(tc, INPUT_STREAM) + pg_to_off(i),
++                             data, PAGE_CACHE_SIZE);
++                      kunmap(clust->pages[i]);
++                      unlock_page(clust->pages[i]);
++              }
++              result = grab_tfm_stream(inode, tc, OUTPUT_STREAM);
++              if (result)
++                      goto error;
++              result = grab_coa(tc, cplug);
++              if (result)
++                      goto error;
++              tc->len = tc->lsize = lbytes(clust->index, inode);
++              assert("edward-1513", tc->len == inode_cluster_size(inode));
++              dst_len = tfm_stream_size(tc, OUTPUT_STREAM);
++              cplug->compress(get_coa(tc, cplug->h.id, tc->act),
++                              tfm_input_data(clust), tc->len,
++                              tfm_output_data(clust), &dst_len);
++              assert("edward-1514",
++                     dst_len <= tfm_stream_size(tc, OUTPUT_STREAM));
++      }
++      finish_check_compressibility(inode, clust, cur_hint);
++      *compressible = data_is_compressible(dst_len,
++                                           inode_cluster_size(inode));
++      return 0;
++ error:
++      put_page_cluster(clust, inode, READ_OP);
++      return result;
++}
++
++/* Cut disk cluster of index @idx */
++static int cut_disk_cluster(struct inode * inode, cloff_t idx)
++{
++      reiser4_key from, to;
++      assert("edward-1515", inode_file_plugin(inode) ==
++             file_plugin_by_id(CRYPTCOMPRESS_FILE_PLUGIN_ID));
++      key_by_inode_cryptcompress(inode, clust_to_off(idx, inode), &from);
++      to = from;
++      set_key_offset(&to,
++                     get_key_offset(&from) + inode_cluster_size(inode) - 1);
++      return reiser4_cut_tree(reiser4_tree_by_inode(inode),
++                              &from, &to, inode, 0);
++}
++
++static int reserve_cryptcompress2unixfile(struct inode *inode)
++{
++      reiser4_block_nr unformatted_nodes;
++      reiser4_tree *tree;
++
++      tree = reiser4_tree_by_inode(inode);
++
++      /* number of unformatted nodes which will be created */
++      unformatted_nodes = cluster_nrpages(inode); /* N */
++
++      /*
++       * space required for one iteration of extent->tail conversion:
++       *
++       *     1. kill ctail items
++       *
++       *     2. insert N unformatted nodes
++       *
++       *     3. insert N (worst-case single-block
++       *     extents) extent units.
++       *
++       *     4. drilling to the leaf level by coord_by_key()
++       *
++       *     5. possible update of stat-data
++       *
++       */
++      grab_space_enable();
++      return reiser4_grab_space
++              (2 * tree->height +
++               unformatted_nodes  +
++               unformatted_nodes * estimate_one_insert_into_item(tree) +
++               1 + estimate_one_insert_item(tree) +
++               inode_file_plugin(inode)->estimate.update(inode),
++               BA_CAN_COMMIT);
++}
++
++/* clear flag that indicated conversion and update
++   stat-data with new (unix-file - specific) info */
++static int complete_file_conversion(struct inode *inode)
++{
++      int result;
++
++      grab_space_enable();
++      result =
++          reiser4_grab_space(inode_file_plugin(inode)->estimate.update(inode),
++                             BA_CAN_COMMIT);
++      if (result == 0) {
++              reiser4_inode_clr_flag(inode, REISER4_FILE_CONV_IN_PROGRESS);
++              result = reiser4_update_sd(inode);
++      }
++      if (result)
++              warning("edward-1452",
++                      "Converting %llu to unix-file: update sd failed (%i)",
++                      (unsigned long long)get_inode_oid(inode), result);
++      return 0;
++}
++
++
++/* do conversion */
++static int cryptcompress2unixfile(struct file * file, struct inode * inode,
++                                struct cluster_handle * clust)
++{
++      int i;
++      int result = 0;
++      struct cryptcompress_info *cr_info;
++      struct unix_file_info *uf_info;
++
++      assert("edward-1516", clust->pages[0]->index == 0);
++      assert("edward-1517", clust->hint != NULL);
++
++      /* release all cryptcompress-specific recources */
++      cr_info = cryptcompress_inode_data(inode);
++      result = reserve_cryptcompress2unixfile(inode);
++      if (result)
++              goto out;
++      reiser4_inode_set_flag(inode, REISER4_FILE_CONV_IN_PROGRESS);
++      reiser4_unset_hint(clust->hint);
++      result = cut_disk_cluster(inode, 0);
++      if (result)
++              goto out;
++      /* captured jnode of cluster and assotiated resources (pages,
++         reserved disk space) were released by ->kill_hook() method
++         of the item plugin */
++
++      result = __cryptcompress2unixfile(file, inode);
++      if (result)
++              goto out;
++      /* At this point file is managed by unix file plugin */
++
++      uf_info = unix_file_inode_data(inode);
++
++      assert("edward-1518",
++             ergo(jprivate(clust->pages[0]),
++                  !jnode_is_cluster_page(jprivate(clust->pages[0]))));
++      for(i = 0; i < clust->nr_pages; i++) {
++              assert("edward-1519", clust->pages[i]);
++              assert("edward-1520", PageUptodate(clust->pages[i]));
++
++              result = find_or_create_extent(clust->pages[i]);
++              if (result)
++                      break;
++      }
++      if (!result) {
++              uf_info->container = UF_CONTAINER_EXTENTS;
++              complete_file_conversion(inode);
++      }
++ out:
++      all_grabbed2free();
++      if (result)
++              warning("edward-1453", "Failed to convert file %llu: ret=%i",
++                      (unsigned long long)get_inode_oid(inode), result);
++      return result;
++}
++
++/* Check, then perform or disable conversion if needed */
++int write_conversion_hook(struct file * file, struct inode * inode, loff_t pos,
++                        struct cluster_handle * clust, int * progress)
++{
++      int result;
++      int check_compress = 0;
++      int compressible = 0;
++
++      if (!conversion_enabled(inode))
++              return 0;
++      result = check_position(inode, pos, clust, &check_compress);
++      if (result || !check_compress)
++              return result;
++      result = read_check_compressibility(inode, clust, &compressible);
++      if (result)
++              return result;
++
++      /* At this point page cluster is grabbed and uptodate */
++      if (!compressible) {
++              result = cryptcompress2unixfile(file, inode, clust);
++              if (result == 0)
++                      *progress = 1;
++      }
++      else
++              result = disable_conversion(inode);
++
++      reiser4_txn_restart_current();
++      put_page_cluster(clust, inode, READ_OP);
++      return result;
++}
++
++static int setattr_conversion_hook(struct inode * inode, struct iattr *attr)
++{
++      return (attr->ia_valid & ATTR_SIZE ? disable_conversion(inode) : 0);
++}
++
++/* Protected methods of cryptcompress file plugin constructed
++   by the macros above */
++
++/* Wrappers with active protection for:
++   . write_cryptcompress;
++   . setattr_cryptcompress;
++*/
++
++ssize_t prot_write_cryptcompress(struct file *file, const char __user *buf,
++                               size_t count, loff_t *off)
++{
++      int prot = 0;
++      int conv = 0;
++      ssize_t written_cr = 0;
++      ssize_t written_uf = 0;
++      struct inode * inode = file->f_dentry->d_inode;
++      struct rw_semaphore * guard = &reiser4_inode_data(inode)->conv_sem;
++
++      if (should_protect(inode)) {
++              prot = 1;
++              down_write(guard);
++      }
++      written_cr = write_cryptcompress(file, buf, count, off, &conv);
++      if (prot)
++              up_write(guard);
++      if (written_cr < 0)
++              return written_cr;
++      if (conv)
++              written_uf = write_unix_file(file, buf + written_cr,
++                                           count - written_cr, off);
++      return written_cr + (written_uf < 0 ? 0 : written_uf);
++}
++
++int prot_setattr_cryptcompress(struct dentry *dentry, struct iattr *attr)
++{
++      struct inode * inode = dentry->d_inode;
++      return PROT_ACTIVE(int, setattr, (dentry, attr),
++                         setattr_conversion_hook(inode, attr));
++}
++
++/* Wrappers with passive protection for:
++   . read_cryptcomperess;
++   . mmap_cryptcompress;
++   . release_cryptcompress;
++   . sendfile_cryptcompress;
++   . delete_object_cryptcompress.
++*/
++ssize_t prot_read_cryptcompress(struct file * file, char __user * buf,
++                              size_t size, loff_t * off)
++{
++      struct inode * inode = file->f_dentry->d_inode;
++      return PROT_PASSIVE(ssize_t, read, (file, buf, size, off));
++}
++
++int prot_mmap_cryptcompress(struct file *file, struct vm_area_struct *vma)
++{
++      struct inode *inode = file->f_dentry->d_inode;
++      return PROT_PASSIVE(int, mmap, (file, vma));
++}
++
++int prot_release_cryptcompress(struct inode *inode, struct file *file)
++{
++      return PROT_PASSIVE(int, release, (inode, file));
++}
++
++ssize_t prot_sendfile_cryptcompress(struct file *file, loff_t *ppos,
++                                  size_t count, read_actor_t actor,
++                                  void *target)
++{
++      struct inode * inode = file->f_dentry->d_inode;
++      return PROT_PASSIVE(ssize_t, sendfile,
++                          (file, ppos, count, actor, target));
++}
++
++/*
++  Local variables:
++  c-indentation-style: "K&R"
++  mode-name: "LC"
++  c-basic-offset: 8
++  tab-width: 8
++  fill-column: 80
++  scroll-step: 1
++  End:
++*/
+diff -urN linux-2.6.22.orig/fs/reiser4/plugin/file/file.h linux-2.6.22/fs/reiser4/plugin/file/file.h
+--- linux-2.6.22.orig/fs/reiser4/plugin/file/file.h    1970-01-01 03:00:00.000000000 +0300
++++ linux-2.6.22/fs/reiser4/plugin/file/file.h 2007-07-29 00:25:34.928709936 +0400
+@@ -0,0 +1,272 @@
 +/* Copyright 2001, 2002, 2003, 2004 by Hans Reiser, licensing governed by
 + * reiser4/README */
 +
-+/* this file contains declarations of methods implementing file plugins
-+   (UNIX_FILE_PLUGIN_ID, SYMLINK_FILE_PLUGIN_ID and CRC_FILE_PLUGIN_ID) */
++/* this file contains declarations of methods implementing
++   file plugins (UNIX_FILE_PLUGIN_ID, CRYPTCOMPRESS_FILE_PLUGIN_ID
++   and SYMLINK_FILE_PLUGIN_ID) */
 +
 +#if !defined( __REISER4_FILE_H__ )
 +#define __REISER4_FILE_H__
@@ -38429,7 +38673,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/file/file.h
 +
 +/* address space operations */
 +int readpage_unix_file(struct file *, struct page *);
-+int readpage_unix_file_nolock(struct file *, struct page *);
++int readpages_unix_file(struct file*, struct address_space*, struct list_head*, unsigned);
 +int writepages_unix_file(struct address_space *, struct writeback_control *);
 +int prepare_write_unix_file(struct file *, struct page *, unsigned from,
 +                          unsigned to);
@@ -38468,7 +38712,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/file/file.h
 +struct inode;
 +
 +/* unix file plugin specific part of reiser4 inode */
-+typedef struct unix_file_info {
++struct unix_file_info {
 +      /*
 +       * this read-write lock protects file containerization change. Accesses
 +       * which do not change file containerization (see file_container_t)
@@ -38478,14 +38722,6 @@ Index: linux-2.6.16/fs/reiser4/plugin/file/file.h
 +       * take write-lock.
 +       */
 +      struct rw_semaphore latch;
-+      /*
-+       * this semaphore is used to serialize writes instead of inode->i_mutex,
-+       * because write_unix_file uses get_user_pages which is to be used
-+       * under mm->mmap_sem and because it is required to take mm->mmap_sem
-+       * before inode->i_mutex, so inode->i_mutex would have to be unlocked
-+       * before calling to get_user_pages which is unacceptable
-+       */
-+      struct semaphore write;
 +      /* this enum specifies which items are used to build the file */
 +      file_container_t container;
 +      /*
@@ -38501,25 +38737,23 @@ Index: linux-2.6.16/fs/reiser4/plugin/file/file.h
 +      atomic_t nr_neas;
 +      void *last_reader;
 +#endif
-+} unix_file_info_t;
++};
 +
 +struct unix_file_info *unix_file_inode_data(const struct inode *inode);
-+void get_exclusive_access(unix_file_info_t *);
-+void drop_exclusive_access(unix_file_info_t *);
-+void get_nonexclusive_access(unix_file_info_t *);
-+void drop_nonexclusive_access(unix_file_info_t *);
-+int try_to_get_nonexclusive_access(unix_file_info_t *);
++void get_exclusive_access(struct unix_file_info *);
++void drop_exclusive_access(struct unix_file_info *);
++void get_nonexclusive_access(struct unix_file_info *);
++void drop_nonexclusive_access(struct unix_file_info *);
++int try_to_get_nonexclusive_access(struct unix_file_info *);
 +int find_file_item(hint_t *, const reiser4_key *, znode_lock_mode,
 +                 struct inode *);
 +int find_file_item_nohint(coord_t *, lock_handle *,
 +                        const reiser4_key *, znode_lock_mode,
 +                        struct inode *);
 +
-+void validate_extended_coord(uf_coord_t *, loff_t offset);
 +int load_file_hint(struct file *, hint_t *);
 +void save_file_hint(struct file *, const hint_t *);
 +
-+
 +#include "../item/extent.h"
 +#include "../item/tail.h"
 +#include "../item/ctail.h"
@@ -38529,9 +38763,9 @@ Index: linux-2.6.16/fs/reiser4/plugin/file/file.h
 +      lock_handle *lh;
 +      int valid;
 +      union {
-+              extent_coord_extension_t extent;
-+              tail_coord_extension_t tail;
-+              ctail_coord_extension_t ctail;
++              struct extent_coord_extension extent;
++              struct tail_coord_extension tail;
++              struct ctail_coord_extension ctail;
 +      } extension;
 +};
 +
@@ -38554,23 +38788,36 @@ Index: linux-2.6.16/fs/reiser4/plugin/file/file.h
 +      lock_handle lh;
 +};
 +
-+void set_hint(hint_t *, const reiser4_key *, znode_lock_mode);
-+int hint_is_set(const hint_t *);
-+void unset_hint(hint_t *);
-+int hint_validate(hint_t *, const reiser4_key *, int check_key,
-+                znode_lock_mode);
++static inline int hint_is_valid(hint_t * hint)
++{
++      return hint->ext_coord.valid;
++}
++
++static inline void hint_set_valid(hint_t * hint)
++{
++      hint->ext_coord.valid = 1;
++}
++
++static inline void hint_clr_valid(hint_t * hint)
++{
++      hint->ext_coord.valid = 0;
++}
++
++int load_file_hint(struct file *, hint_t *);
++void save_file_hint(struct file *, const hint_t *);
 +void hint_init_zero(hint_t *);
++void reiser4_set_hint(hint_t *, const reiser4_key *, znode_lock_mode);
++int hint_is_set(const hint_t *);
++void reiser4_unset_hint(hint_t *);
 +
-+int update_file_size(struct inode *, reiser4_key *, int update_sd);
++int reiser4_update_file_size(struct inode *, reiser4_key *, int update_sd);
 +int cut_file_items(struct inode *, loff_t new_size, int update_sd,
 +                 loff_t cur_size, int (*update_actor) (struct inode *,
 +                                                       reiser4_key *, int));
-+
-+
 +#if REISER4_DEBUG
 +
 +/* return 1 is exclusive access is obtained, 0 - otherwise */
-+static inline int ea_obtained(unix_file_info_t * uf_info)
++static inline int ea_obtained(struct unix_file_info * uf_info)
 +{
 +      int ret;
 +
@@ -38583,38 +38830,48 @@ Index: linux-2.6.16/fs/reiser4/plugin/file/file.h
 +#endif
 +
 +/* declarations of functions implementing SYMLINK_FILE_PLUGIN_ID file plugin */
-+int create_symlink(struct inode *symlink, struct inode *dir,
-+                 reiser4_object_create_data *);
++int reiser4_create_symlink(struct inode *symlink, struct inode *dir,
++                         reiser4_object_create_data *);
 +void destroy_inode_symlink(struct inode *);
 +
-+/* declarations of functions implementing CRC_FILE_PLUGIN_ID file plugin */
++/* declarations of functions implementing CRYPTCOMPRESS_FILE_PLUGIN_ID
++   file plugin */
 +
 +/* inode operations */
 +int setattr_cryptcompress(struct dentry *, struct iattr *);
++int prot_setattr_cryptcompress(struct dentry *, struct iattr *);
 +
 +/* file operations */
 +ssize_t read_cryptcompress(struct file *, char __user *buf, size_t read_amount,
 +                         loff_t * off);
++ssize_t prot_read_cryptcompress(struct file *, char __user *buf,
++                              size_t read_amount, loff_t * off);
++
 +ssize_t write_cryptcompress(struct file *, const char __user *buf, size_t write_amount,
-+                          loff_t * off);
++                          loff_t * off, int * conv);
++ssize_t prot_write_cryptcompress(struct file *, const char __user *buf, size_t write_amount,
++                               loff_t * off);
 +int mmap_cryptcompress(struct file *, struct vm_area_struct *);
++int prot_mmap_cryptcompress(struct file *, struct vm_area_struct *);
 +ssize_t sendfile_cryptcompress(struct file *file, loff_t *ppos, size_t count,
 +                             read_actor_t actor, void *target);
++ssize_t prot_sendfile_cryptcompress(struct file *file, loff_t *ppos, size_t count,
++                                  read_actor_t actor, void *target);
++
 +int release_cryptcompress(struct inode *, struct file *);
++int prot_release_cryptcompress(struct inode *, struct file *);
 +
 +/* address space operations */
 +extern int readpage_cryptcompress(struct file *, struct page *);
 +extern int writepages_cryptcompress(struct address_space *,
 +                                   struct writeback_control *);
-+
-+
 +/* file plugin operations */
 +int flow_by_inode_cryptcompress(struct inode *, const char __user *buf,
 +                              int user, loff_t, loff_t, rw_op, flow_t *);
 +int key_by_inode_cryptcompress(struct inode *, loff_t off, reiser4_key *);
 +int create_cryptcompress(struct inode *, struct inode *,
 +                       reiser4_object_create_data *);
-+int delete_cryptcompress(struct inode *);
++int delete_object_cryptcompress(struct inode *);
 +void init_inode_data_cryptcompress(struct inode *, reiser4_object_create_data *,
 +                                 int create);
 +int cut_tree_worker_cryptcompress(tap_t *, const reiser4_key * from_key,
@@ -38623,21 +38880,22 @@ Index: linux-2.6.16/fs/reiser4/plugin/file/file.h
 +                                struct inode *object, int truncate,
 +                                int *progress);
 +void destroy_inode_cryptcompress(struct inode *);
++int open_object_cryptcompress(struct inode * inode, struct file * file);
 +
 +extern reiser4_plugin_ops cryptcompress_plugin_ops;
 +
 +#define WRITE_GRANULARITY 32
 +
-+
-+int tail2extent(unix_file_info_t *);
-+int extent2tail(unix_file_info_t *);
++int tail2extent(struct unix_file_info *);
++int extent2tail(struct unix_file_info *);
 +
 +int goto_right_neighbor(coord_t *, lock_handle *);
 +int find_or_create_extent(struct page *);
 +int equal_to_ldk(znode *, const reiser4_key *);
 +
++void init_uf_coord(uf_coord_t *uf_coord, lock_handle *lh);
 +
-+extern inline int cbk_errored(int cbk_result)
++static inline int cbk_errored(int cbk_result)
 +{
 +      return (cbk_result != CBK_COORD_NOTFOUND
 +              && cbk_result != CBK_COORD_FOUND);
@@ -38656,508 +38914,20 @@ Index: linux-2.6.16/fs/reiser4/plugin/file/file.h
 + * scroll-step: 1
 + * End:
 +*/
-Index: linux-2.6.16/fs/reiser4/plugin/file/invert.c
-===================================================================
---- /dev/null
-+++ linux-2.6.16/fs/reiser4/plugin/file/invert.c
-@@ -0,0 +1,493 @@
-+/* Copyright 2001, 2002, 2003 by Hans Reiser, licensing governed by reiser4/README */
-+
-+/* Suppose you want to conveniently read and write a large variety of small files conveniently within a single emacs
-+   buffer, without having a separate buffer for each 8 byte or so file.  Inverts are the way to do that.  An invert
-+   provides you with the contents of a set of subfiles plus its own contents.  It is a file which inherits other files
-+   when you read it, and allows you to write to it and through it to the files that it inherits from.  In order for it
-+   to know which subfiles each part of your write should go into, there must be delimiters indicating that.  It tries to
-+   make that easy for you by providing those delimiters in what you read from it.
-+
-+  When you read it, an invert performs an inverted assignment.  Instead of taking an assignment command and writing a
-+  bunch of files, it takes a bunch of files and composes an assignment command for you to read from it that if executed
-+  would create those files.  But which files?  Well, that must be specified in the body of the invert using a special
-+  syntax, and that specification is called the invert of the assignment.
-+
-+  When written to, an invert performs the assignment command that is written
-+  to it, and modifies its own body to contain the invert of that
-+  assignment.
-+
-+  In other words, writing to an invert file what you have read from it
-+  is the identity operation.
-+
-+  Malformed assignments cause write errors.  Partial writes are not
-+  supported in v4.0, but will be.
-+
-+  Example:
-+
-+    If an invert contains:
-+
-+    /filenameA/<>+"(some text stored in the invert)+/filenameB/<>
-+
-+======================
-+Each element in this definition should be an invert, and all files
-+should be called recursively - too.  This is bad. If one of the
-+included files in not a regular or invert file, then we can't read
-+main file.
-+
-+I think to make it is possible easier:
-+
-+internal structure of invert file should be like symlink file. But
-+read and write method should be explitely indicated in i/o operation..
-+
-+By default we read and write (if probably) as symlink and if we
-+specify ..invert at reading time that too we can specify it at write time.
-+
-+example:
-+/my_invert_file/..invert<- ( (/filenameA<-"(The contents of filenameA))+"(some text stored in the invert)+(/filenameB<-"(The contents of filenameB) ) )
-+will create  /my_invert_file as invert, and will creat /filenameA and /filenameB with specified body.
-+
-+read of /my_invert_file/..invert will be
-+/filenameA<-"(The contents of filenameA)+"(some text stored in the invert)+/filenameB<-"(The contents of filenameB)
-+
-+but read of /my_invert_file/ will be
-+The contents of filenameAsome text stored in the invertThe contents of filenameB
-+
-+we also can creat this file as
-+/my_invert_file/<-/filenameA+"(some text stored in the invert)+/filenameB
-+will create  /my_invert_file , and use existing files /filenameA and /filenameB.
-+
-+and when we will read it will be as previously invert file.
-+
-+This is correct?
-+
-+ vv
-+DEMIDOV-FIXME-HANS:
-+
-+Maybe you are right, but then you must disable writes to /my_invert_file/ and only allow writes to /my_invert_file/..invert
-+
-+Do you agree?  Discuss it on reiserfs-list....
-+
-+-Hans
-+=======================
-+
-+  Then a read will return:
-+
-+    /filenameA<-"(The contents of filenameA)+"(some text stored in the invert)+/filenameB<-"(The contents of filenameB)
-+
-+    and a write of the line above to the invert will set the contents of
-+    the invert and filenameA and filenameB to their original values.
-+
-+  Note that the contents of an invert have no influence on the effect
-+  of a write unless the write is a partial write (and a write of a
-+  shorter file without using truncate first is a partial write).
-+
-+  truncate() has no effect on filenameA and filenameB, it merely
-+  resets the value of the invert.
-+
-+  Writes to subfiles via the invert are implemented by preceding them
-+  with truncates.
-+
-+  Parse failures cause write failures.
-+
-+  Questions to ponder: should the invert be acted on prior to file
-+  close when writing to an open filedescriptor?
-+
-+ Example:
-+
-+ If an invert contains:
-+
-+   "(This text and a pair of quotes are all that is here.)
-+
-+Then a read will return:
-+
-+   "(This text and a pair of quotes are all that is here.)
-+
-+*/
-+
-+/* OPEN method places a struct file in memory associated with invert body
-+  and returns something like file descriptor to the user for the future access
-+  to the invert file.
-+  During opening we parse the body of invert and get a list of the 'entryes'
-+  (that describes all its subfiles) and place pointer on the first struct in
-+  reiserfs-specific part of invert inode (arbitrary decision).
-+
-+  Each subfile is described by the struct inv_entry that has a pointer @sd on
-+  in-core based stat-data and  a pointer on struct file @f (if we find that the
-+  subfile uses more then one unformated node (arbitrary decision), we load
-+  struct file in memory, otherwise we load base stat-data (and maybe 1-2 bytes
-+  of some other information we need)
-+
-+  Since READ and WRITE methods for inverts were formulated in assignment
-+  language, they don't contain arguments 'size' and 'offset' that make sense
-+  only in ordinary read/write methods.
-+
-+  READ method is a combination of two methods:
-+  1) ordinary read method (with offset=0, lenght = @f->...->i_size) for entries
-+  with @f != 0, this method uses pointer on struct file as an argument
-+  2) read method for inode-less files with @sd != 0, this method uses
-+  in-core based stat-data instead struct file as an argument.
-+  in the first case we don't use pagecache, just copy data that we got after
-+  cbk() into userspace.
-+
-+  WRITE method for invert files is more complex.
-+  Besides declared WRITE-interface in assignment languageb above we need
-+  to have an opportunity to edit unwrapped body of invert file with some
-+  text editor, it means we need GENERIC WRITE METHOD for invert file:
-+
-+  my_invert_file/..invert <- "string"
-+
-+  this method parses "string" and looks for correct subfile signatures, also
-+  the parsing process splits this "string" on the set of flows in  accordance
-+  with the set of subfiles specified by this signarure.
-+  The found list of signatures #S is compared with the opened one #I of invert
-+  file. If it doesn't have this one (#I==0, it will be so for instance if we
-+  have just create this invert file) the write method assignes found signature
-+  (#I=#S;) to the invert file. Then if #I==#S, generic write method splits
-+  itself to the some write methods for ordinary or light-weight, or call itself
-+  recursively for invert files with corresponding flows.
-+  I am not sure, but the list of signatures looks like what mr.Demidov means
-+  by 'delimiters'.
-+
-+  The cases when #S<#I (#I<#S) (in the sense of set-theory) are also available
-+  and cause delete (create new) subfiles (arbitrary decision - it may looks
-+  too complex, but this interface will be the completest). The order of entries
-+  of list #S (#I) and inherited order on #I (#S) must coincide.
-+  The other parsing results give malformed signature that aborts READ method
-+  and releases all resources.
-+
-+  Format of subfile (entry) signature:
-+
-+  "START_MAGIC"<>(TYPE="...",LOOKUP_ARG="...")SUBFILE_BODY"END_MAGIC"
-+
-+  Legend:
-+
-+    START_MAGIC - keyword indicates the start of subfile signature;
-+
-+    <> indicates the start of 'subfile metadata', that is the pair
-+  (TYPE="...",LOOKUP_ARG="...") in parenthesis separated by comma.
-+
-+    TYPE - the string "type" indicates the start of one of the three words:
-+  - ORDINARY_FILE,
-+  - LIGHT_WEIGHT_FILE,
-+  - INVERT_FILE;
-+
-+    LOOKUP_ARG - lookup argument depends on previous type:
-+  */
-+
-+ /************************************************************/
-+ /*       TYPE        *          LOOKUP ARGUMENT             */
-+ /************************************************************/
-+ /* LIGH_WEIGHT_FILE  *           stat-data key              */
-+ /************************************************************/
-+ /*   ORDINARY_FILE   *             filename                 */
-+ /************************************************************/
-+ /*   INVERT_FILE     *             filename                 */
-+ /************************************************************/
-+
-+ /* where:
-+  *stat-data key - the string contains stat data key of this subfile, it will be
-+  passed to fast-access lookup method for light-weight files;
-+  *filename - pathname of this subfile, iyt well be passed to VFS lookup methods
-+  for ordinary and invert files;
-+
-+  SUBFILE_BODY - data of this subfile (it will go to the flow)
-+  END_MAGIC - the keyword indicates the end of subfile signature.
-+
-+  The other simbols inside the signature interpreted as 'unformatted content',
-+  which is available with VFS's read_link() (arbitraruy decision).
-+
-+  NOTE: Parse method for a body of invert file uses mentioned signatures _without_
-+  subfile bodies.
-+
-+  Now the only unclear thing is WRITE in regular light-weight subfile A that we
-+  can describe only in  assignment language:
-+
-+  A <- "some_string"
-+
-+  I guess we don't want to change stat-data and body items of file A
-+  if this file exist, and size(A) != size("some_string") because this operation is
-+  expencive, so we only do the partial write if size(A) > size("some_string")
-+  and do truncate of the "some_string", and then do A <- "truncated string", if
-+  size(A) < size("some_string"). This decision is also arbitrary..
-+  */
-+
-+/* here is infrastructure for formated flows */
-+
-+#define SUBFILE_HEADER_MAGIC 0x19196605
-+#define FLOW_HEADER_MAGIC 0x01194304
-+
-+#include "../plugin.h"
-+#include "../../debug.h"
-+#include "../../forward.h"
-+#include "../object.h"
-+#include "../item/item.h"
-+#include "../item/static_stat.h"
-+#include "../../dformat.h"
-+#include "../znode.h"
-+#include "../inode.h"
-+
-+#include <linux/types.h>
-+#include <linux/fs.h>         /* for struct file  */
-+#include <linux/list.h>               /* for struct list_head */
-+
-+typedef enum {
-+      LIGHT_WEIGHT_FILE,
-+      ORDINARY_FILE,
-+      INVERT_FILE
-+} inv_entry_type;
-+
-+typedef struct flow_header {
-+      d32 fl_magic;
-+      d16 fl_nr;              /* number of subfiles in the flow */
-+};
-+
-+typedef struct subfile_header {
-+      d32 sh_magic;           /* subfile magic */
-+      d16 sh_type;            /* type of subfile: light-weight, ordinary, invert */
-+      d16 sh_arg_len;         /* lenght of lookup argument (filename, key) */
-+      d32 sh_body_len;        /* lenght of subfile body */
-+};
-+
-+/* functions to get/set fields of flow header */
-+
-+static void fl_set_magic(flow_header * fh, __u32 value)
-+{
-+      cputod32(value, &fh->fh_magic);
-+}
-+
-+static __u32 fl_get_magic(flow_header * fh)
-+{
-+      return d32tocpu(&fh->fh_magic);
-+}
-+static void fl_set_number(flow_header * fh, __u16 value)
-+{
-+      cputod16(value, &fh->fh_nr);
-+}
-+static unsigned fl_get_number(flow_header * fh)
-+{
-+      return d16tocpu(&fh->fh_nr);
-+}
-+
-+/* functions to get/set fields of subfile header */
-+
-+static void sh_set_magic(subfile_header * sh, __u32 value)
-+{
-+      cputod32(value, &sh->sh_magic);
-+}
-+
-+static __u32 sh_get_magic(subfile_header * sh)
-+{
-+      return d32tocpu(&sh->sh_magic);
-+}
-+static void sh_set_type(subfile_header * sh, __u16 value)
-+{
-+      cputod16(value, &sh->sh_magic);
-+}
-+static unsigned sh_get_type(subfile_header * sh)
-+{
-+      return d16tocpu(&sh->sh_magic);
-+}
-+static void sh_set_arg_len(subfile_header * sh, __u16 value)
-+{
-+      cputod16(value, &sh->sh_arg_len);
-+}
-+static unsigned sh_get_arg_len(subfile_header * sh)
-+{
-+      return d16tocpu(&sh->sh_arg_len);
-+}
-+static void sh_set_body_len(subfile_header * sh, __u32 value)
-+{
-+      cputod32(value, &sh->sh_body_len);
-+}
-+
-+static __u32 sh_get_body_len(subfile_header * sh)
-+{
-+      return d32tocpu(&sh->sh_body_len);
-+}
-+
-+/* in-core minimal stat-data, light-weight analog of inode */
-+
-+struct incore_sd_base {
-+      umode_t isd_mode;
-+      nlink_t isd_nlink;
-+      loff_t isd_size;
-+      char *isd_data;         /* 'subflow' to write */
-+};
-+
-+/* open invert create a list of invert entries,
-+   every entry is represented by structure inv_entry */
-+
-+struct inv_entry {
-+      struct list_head *ie_list;
-+      struct file *ie_file;   /* this is NULL if the file doesn't
-+                                 have unformated nodes */
-+      struct incore_sd_base *ie_sd;   /* inode-less analog of struct file */
-+};
-+
-+/* allocate and init invert entry */
-+
-+static struct inv_entry *allocate_inv_entry(void)
-+{
-+      struct inv_entry *inv_entry;
-+
-+      inv_entry = reiser4_kmalloc(sizeof(struct inv_entry), GFP_KERNEL);
-+      if (!inv_entry)
-+              return ERR_PTR(RETERR(-ENOMEM));
-+      inv_entry->ie_file = NULL;
-+      inv_entry->ie_sd = NULL;
-+      INIT_LIST_HEAD(&inv_entry->ie_list);
-+      return inv_entry;
-+}
-+
-+static int put_inv_entry(struct inv_entry *ientry)
-+{
-+      int result = 0;
-+
-+      assert("edward-96", ientry != NULL);
-+      assert("edward-97", ientry->ie_list != NULL);
-+
-+      list_del(ientry->ie_list);
-+      if (ientry->ie_sd != NULL) {
-+              kfree(ientry->ie_sd);
-+              kfree(ientry);
-+      }
-+      if (ientry->ie_file != NULL)
-+              result = filp_close(ientry->file, NULL);
-+      return result;
-+}
-+
-+static int allocate_incore_sd_base(struct inv_entry *inv_entry)
-+{
-+      struct incore_sd_base *isd_base assert("edward-98", inv_entry != NULL);
-+      assert("edward-99", inv_entry->ie_inode = NULL);
-+      assert("edward-100", inv_entry->ie_sd = NULL);
-+
-+      isd_base = reiser4_kmalloc(sizeof(struct incore_sd_base), GFP_KERNEL);
-+      if (!isd_base)
-+              return RETERR(-ENOMEM);
-+      inv_entry->ie_sd = isd_base;
-+      return 0;
-+}
-+
-+/* this can be installed as ->init_inv_entry () method of
-+   item_plugins[ STATIC_STAT_DATA_IT ] (fs/reiser4/plugin/item/item.c).
-+   Copies data from on-disk stat-data format into light-weight analog of inode .
-+   Doesn't hanlde stat-data extensions. */
-+
-+static void sd_base_load(struct inv_entry *inv_entry, char *sd)
-+{
-+      reiser4_stat_data_base *sd_base;
-+
-+      assert("edward-101", inv_entry != NULL);
-+      assert("edward-101", inv_entry->ie_sd != NULL);
-+      assert("edward-102", sd != NULL);
-+
-+      sd_base = (reiser4_stat_data_base *) sd;
-+      inv_entry->incore_sd_base->isd_mode = d16tocpu(&sd_base->mode);
-+      inv_entry->incore_sd_base->isd_nlink = d32tocpu(&sd_base->nlink);
-+      inv_entry->incore_sd_base->isd_size = d64tocpu(&sd_base->size);
-+      inv_entry->incore_sd_base->isd_data = NULL;
-+}
-+
-+/* initialise incore stat-data */
-+
-+static void init_incore_sd_base(struct inv_entry *inv_entry, coord_t * coord)
-+{
-+      reiser4_plugin *plugin = item_plugin_by_coord(coord);
-+      void *body = item_body_by_coord(coord);
-+
-+      assert("edward-103", inv_entry != NULL);
-+      assert("edward-104", plugin != NULL);
-+      assert("edward-105", body != NULL);
-+
-+      sd_base_load(inv_entry, body);
-+}
-+
-+/* takes a key or filename and allocates new invert_entry,
-+   init and adds it into the list,
-+   we use lookup_sd_by_key() for light-weight files and VFS lookup by filename */
-+
-+int get_inv_entry(struct inode *invert_inode, /* inode of invert's body */
-+                inv_entry_type type,  /* LIGHT-WEIGHT or ORDINARY */
-+                const reiser4_key * key,      /* key of invert entry stat-data */
-+                char *filename,       /* filename of the file to be opened */
-+                int flags, int mode)
-+{
-+      int result;
-+      struct inv_entry *ientry;
-+
-+      assert("edward-107", invert_inode != NULL);
-+
-+      ientry = allocate_inv_entry();
-+      if (IS_ERR(ientry))
-+              return (PTR_ERR(ientry));
-+
-+      if (type == LIGHT_WEIGHT_FILE) {
-+              coord_t coord;
-+              lock_handle lh;
-+
-+              assert("edward-108", key != NULL);
-+
-+              init_coord(&coord);
-+              init_lh(&lh);
-+              result =
-+                  lookup_sd_by_key(tree_by_inode(invert_inode),
-+                                   ZNODE_READ_LOCK, &coord, &lh, key);
-+              if (result == 0)
-+                      init_incore_sd_base(ientry, coord);
-+
-+              done_lh(&lh);
-+              done_coord(&coord);
-+              return (result);
-+      } else {
-+              struct file *file = filp_open(filename, flags, mode);
-+              /* FIXME_EDWARD here we need to check if we
-+                 did't follow to any mount point */
-+
-+              assert("edward-108", filename != NULL);
-+
-+              if (IS_ERR(file))
-+                      return (PTR_ERR(file));
-+              ientry->ie_file = file;
-+              return 0;
-+      }
-+}
-+
-+/* takes inode of invert, reads the body of this invert, parses it,
-+   opens all invert entries and return pointer on the first inv_entry */
-+
-+struct inv_entry *open_invert(struct file *invert_file)
-+{
-+
-+}
-+
-+ssize_t subfile_read(struct *invert_entry, flow * f)
-+{
-+
-+}
-+
-+ssize_t subfile_write(struct *invert_entry, flow * f)
-+{
-+
-+}
-+
-+ssize_t invert_read(struct *file, flow * f)
-+{
-+
-+}
-+
-+ssize_t invert_write(struct *file, flow * f)
-+{
-+
-+}
+diff -urN linux-2.6.22.orig/fs/reiser4/plugin/file/Makefile linux-2.6.22/fs/reiser4/plugin/file/Makefile
+--- linux-2.6.22.orig/fs/reiser4/plugin/file/Makefile  1970-01-01 03:00:00.000000000 +0300
++++ linux-2.6.22/fs/reiser4/plugin/file/Makefile       2007-07-29 00:25:34.928709936 +0400
+@@ -0,0 +1,7 @@
++obj-$(CONFIG_REISER4_FS) += file_plugins.o
 +
-+/* Make Linus happy.
-+   Local variables:
-+   c-indentation-style: "K&R"
-+   mode-name: "LC"
-+   c-basic-offset: 8
-+   tab-width: 8
-+   fill-column: 120
-+   scroll-step: 1
-+   End:
-+*/
-Index: linux-2.6.16/fs/reiser4/plugin/file/symfile.c
-===================================================================
---- /dev/null
-+++ linux-2.6.16/fs/reiser4/plugin/file/symfile.c
++file_plugins-objs :=          \
++      file.o                  \
++      tail_conversion.o       \
++      symlink.o               \
++      cryptcompress.o
+diff -urN linux-2.6.22.orig/fs/reiser4/plugin/file/symfile.c linux-2.6.22/fs/reiser4/plugin/file/symfile.c
+--- linux-2.6.22.orig/fs/reiser4/plugin/file/symfile.c 1970-01-01 03:00:00.000000000 +0300
++++ linux-2.6.22/fs/reiser4/plugin/file/symfile.c      2007-07-29 00:25:34.928709936 +0400
 @@ -0,0 +1,87 @@
 +/* Copyright 2001, 2002, 2003 by Hans Reiser, licensing governed by reiser4/README */
 +
@@ -39246,11 +39016,10 @@ Index: linux-2.6.16/fs/reiser4/plugin/file/symfile.c
 +   sophisticated symfile syntax that we are not planning to write for
 +   version 4.0.
 +*/
-Index: linux-2.6.16/fs/reiser4/plugin/file/symlink.c
-===================================================================
---- /dev/null
-+++ linux-2.6.16/fs/reiser4/plugin/file/symlink.c
-@@ -0,0 +1,92 @@
+diff -urN linux-2.6.22.orig/fs/reiser4/plugin/file/symlink.c linux-2.6.22/fs/reiser4/plugin/file/symlink.c
+--- linux-2.6.22.orig/fs/reiser4/plugin/file/symlink.c 1970-01-01 03:00:00.000000000 +0300
++++ linux-2.6.22/fs/reiser4/plugin/file/symlink.c      2007-07-29 00:25:34.928709936 +0400
+@@ -0,0 +1,95 @@
 +/* Copyright 2002, 2003, 2005 by Hans Reiser, licensing governed by reiser4/README */
 +
 +#include "../../inode.h"
@@ -39266,25 +39035,25 @@ Index: linux-2.6.16/fs/reiser4/plugin/file/symlink.c
 + */
 +
 +/**
-+ * create_symlink - create_object of file plugin for SYMLINK_FILE_PLUGIN_ID
++ * reiser4_create_symlink - create_object of file plugin for SYMLINK_FILE_PLUGIN_ID
 + * @symlink: inode of symlink object
 + * @dir: inode of parent directory
 + * @info:  parameters of new object
 + *
 + * Inserts stat data with symlink extension where into the tree.
 + */
-+int create_symlink(struct inode *symlink,
-+                 struct inode *dir UNUSED_ARG,
-+                 reiser4_object_create_data *data     /* info passed to us,
-+                                                       * this is filled by
-+                                                       * reiser4() syscall
-+                                                       * in particular */ )
++int reiser4_create_symlink(struct inode *symlink,
++                         struct inode *dir UNUSED_ARG,
++                         reiser4_object_create_data *data /* info passed to us
++                                                           * this is filled by
++                                                           * reiser4() syscall
++                                                           * in particular */)
 +{
 +      int result;
 +
 +      assert("nikita-680", symlink != NULL);
 +      assert("nikita-681", S_ISLNK(symlink->i_mode));
-+      assert("nikita-685", inode_get_flag(symlink, REISER4_NO_SD));
++      assert("nikita-685", reiser4_inode_get_flag(symlink, REISER4_NO_SD));
 +      assert("nikita-682", dir != NULL);
 +      assert("nikita-684", data != NULL);
 +      assert("nikita-686", data->id == SYMLINK_FILE_PLUGIN_ID);
@@ -39295,8 +39064,8 @@ Index: linux-2.6.16/fs/reiser4/plugin/file/symlink.c
 +       */
 +      reiser4_inode_data(symlink)->extmask |= (1 << SYMLINK_STAT);
 +
-+      assert("vs-838", symlink->u.generic_ip == NULL);
-+      symlink->u.generic_ip = (void *)data->name;
++      assert("vs-838", symlink->i_private == NULL);
++      symlink->i_private = (void *)data->name;
 +
 +      assert("vs-843", symlink->i_size == 0);
 +      INODE_SET_FIELD(symlink, i_size, strlen(data->name));
@@ -39304,14 +39073,15 @@ Index: linux-2.6.16/fs/reiser4/plugin/file/symlink.c
 +      /* insert stat data appended with data->name */
 +      result = inode_file_plugin(symlink)->write_sd_by_inode(symlink);
 +      if (result) {
-+              /* FIXME-VS: Make sure that symlink->u.generic_ip is not attached
++              /* FIXME-VS: Make sure that symlink->i_private is not attached
 +                 to kmalloced data */
 +              INODE_SET_FIELD(symlink, i_size, 0);
 +      } else {
-+              assert("vs-849", symlink->u.generic_ip
-+                     && inode_get_flag(symlink, REISER4_GENERIC_PTR_USED));
++              assert("vs-849", symlink->i_private
++                     && reiser4_inode_get_flag(symlink,
++                                               REISER4_GENERIC_PTR_USED));
 +              assert("vs-850",
-+                     !memcmp((char *)symlink->u.generic_ip, data->name,
++                     !memcmp((char *)symlink->i_private, data->name,
 +                             (size_t) symlink->i_size + 1));
 +      }
 +      return result;
@@ -39326,28 +39096,29 @@ Index: linux-2.6.16/fs/reiser4/plugin/file/symlink.c
 +             inode_file_plugin(inode) ==
 +             file_plugin_by_id(SYMLINK_FILE_PLUGIN_ID));
 +      assert("edward-800", !is_bad_inode(inode) && is_inode_loaded(inode));
-+      assert("edward-801", inode_get_flag(inode, REISER4_GENERIC_PTR_USED));
++      assert("edward-801", reiser4_inode_get_flag(inode,
++                                                  REISER4_GENERIC_PTR_USED));
 +      assert("vs-839", S_ISLNK(inode->i_mode));
 +
-+      kfree(inode->u.generic_ip);
-+      inode->u.generic_ip = NULL;
-+      inode_clr_flag(inode, REISER4_GENERIC_PTR_USED);
++      kfree(inode->i_private);
++      inode->i_private = NULL;
++      reiser4_inode_clr_flag(inode, REISER4_GENERIC_PTR_USED);
 +}
 +
-+/* Local variables:
-+   c-indentation-style: "K&R"
-+   mode-name: "LC"
-+   c-basic-offset: 8
-+   tab-width: 8
-+   fill-column: 120
-+   scroll-step: 1
-+   End:
++/*
++  Local variables:
++  c-indentation-style: "K&R"
++  mode-name: "LC"
++  c-basic-offset: 8
++  tab-width: 8
++  fill-column: 80
++  scroll-step: 1
++  End:
 +*/
-Index: linux-2.6.16/fs/reiser4/plugin/file/tail_conversion.c
-===================================================================
---- /dev/null
-+++ linux-2.6.16/fs/reiser4/plugin/file/tail_conversion.c
-@@ -0,0 +1,728 @@
+diff -urN linux-2.6.22.orig/fs/reiser4/plugin/file/tail_conversion.c linux-2.6.22/fs/reiser4/plugin/file/tail_conversion.c
+--- linux-2.6.22.orig/fs/reiser4/plugin/file/tail_conversion.c 1970-01-01 03:00:00.000000000 +0300
++++ linux-2.6.22/fs/reiser4/plugin/file/tail_conversion.c      2007-07-29 00:25:34.932710971 +0400
+@@ -0,0 +1,729 @@
 +/* Copyright 2001, 2002, 2003 by Hans Reiser, licensing governed by reiser4/README */
 +
 +#include "../../inode.h"
@@ -39363,9 +39134,9 @@ Index: linux-2.6.16/fs/reiser4/plugin/file/tail_conversion.c
 +   tail2extent and extent2tail */
 +
 +/* exclusive access to a file is acquired when file state changes: tail2extent, empty2tail, extent2tail, etc */
-+void get_exclusive_access(unix_file_info_t * uf_info)
++void get_exclusive_access(struct unix_file_info * uf_info)
 +{
-+      assert("nikita-3028", schedulable());
++      assert("nikita-3028", reiser4_schedulable());
 +      assert("nikita-3047", LOCK_CNT_NIL(inode_sem_w));
 +      assert("nikita-3048", LOCK_CNT_NIL(inode_sem_r));
 +      /*
@@ -39374,7 +39145,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/file/tail_conversion.c
 +       * thread that captured some block (hence preventing atom from being
 +       * committed) and waits on rw-semaphore.
 +       */
-+      txn_restart_current();
++      reiser4_txn_restart_current();
 +      LOCK_CNT_INC(inode_sem_w);
 +      down_write(&uf_info->latch);
 +      uf_info->exclusive_use = 1;
@@ -39383,7 +39154,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/file/tail_conversion.c
 +      ON_DEBUG(uf_info->ea_owner = current);
 +}
 +
-+void drop_exclusive_access(unix_file_info_t * uf_info)
++void drop_exclusive_access(struct unix_file_info * uf_info)
 +{
 +      assert("vs-1714", uf_info->ea_owner == current);
 +      assert("vs-1715", atomic_read(&uf_info->nr_neas) == 0);
@@ -39393,7 +39164,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/file/tail_conversion.c
 +      assert("nikita-3049", LOCK_CNT_NIL(inode_sem_r));
 +      assert("nikita-3049", LOCK_CNT_GTZ(inode_sem_w));
 +      LOCK_CNT_DEC(inode_sem_w);
-+      txn_restart_current();
++      reiser4_txn_restart_current();
 +}
 +
 +/**
@@ -39403,7 +39174,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/file/tail_conversion.c
 + * This is called when nonexclisive access is obtained on file. All it does is
 + * for debugging purposes.
 + */
-+static void nea_grabbed(unix_file_info_t *uf_info)
++static void nea_grabbed(struct unix_file_info *uf_info)
 +{
 +#if REISER4_DEBUG
 +      LOCK_CNT_INC(inode_sem_r);
@@ -39419,9 +39190,9 @@ Index: linux-2.6.16/fs/reiser4/plugin/file/tail_conversion.c
 + *
 + * Nonexclusive access is obtained on a file before read, write, readpage.
 + */
-+void get_nonexclusive_access(unix_file_info_t *uf_info)
++void get_nonexclusive_access(struct unix_file_info *uf_info)
 +{
-+      assert("nikita-3029", schedulable());
++      assert("nikita-3029", reiser4_schedulable());
 +      assert("nikita-3361", get_current_context()->trans->atom == NULL);
 +
 +      down_read(&uf_info->latch);
@@ -39434,7 +39205,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/file/tail_conversion.c
 + *
 + * Non-blocking version of nonexclusive access obtaining.
 + */
-+int try_to_get_nonexclusive_access(unix_file_info_t *uf_info)
++int try_to_get_nonexclusive_access(struct unix_file_info *uf_info)
 +{
 +      int result;
 +
@@ -39444,7 +39215,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/file/tail_conversion.c
 +      return result;
 +}
 +
-+void drop_nonexclusive_access(unix_file_info_t * uf_info)
++void drop_nonexclusive_access(struct unix_file_info * uf_info)
 +{
 +      assert("vs-1718", uf_info->ea_owner == NULL);
 +      assert("vs-1719", atomic_read(&uf_info->nr_neas) > 0);
@@ -39453,7 +39224,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/file/tail_conversion.c
 +      up_read(&uf_info->latch);
 +
 +      LOCK_CNT_DEC(inode_sem_r);
-+      txn_restart_current();
++      reiser4_txn_restart_current();
 +}
 +
 +/* part of tail2extent. Cut all items covering @count bytes starting from
@@ -39473,7 +39244,8 @@ Index: linux-2.6.16/fs/reiser4/plugin/file/tail_conversion.c
 +      set_key_offset(&to, (__u64) (offset + count - 1));
 +
 +      /* cut everything between those keys */
-+      return cut_tree(tree_by_inode(inode), &from, &to, inode, 0);
++      return reiser4_cut_tree(reiser4_tree_by_inode(inode), &from, &to,
++                              inode, 0);
 +}
 +
 +static void release_all_pages(struct page **pages, unsigned nr_pages)
@@ -39508,10 +39280,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/file/tail_conversion.c
 +      assert("vs-596", pages[0]);
 +
 +      /* cut copied items */
-+      result =
-+          cut_formatting_items(inode,
-+                               (loff_t) pages[0]->index << PAGE_CACHE_SHIFT,
-+                               count);
++      result = cut_formatting_items(inode, page_offset(pages[0]), count);
 +      if (result)
 +              return result;
 +
@@ -39542,7 +39311,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/file/tail_conversion.c
 +      reiser4_block_nr unformatted_nodes;
 +      reiser4_tree *tree;
 +
-+      tree = tree_by_inode(inode);
++      tree = reiser4_tree_by_inode(inode);
 +
 +      /* number of unformatted nodes which will be created */
 +      unformatted_nodes = TAIL2EXTENT_PAGE_NUM;
@@ -39581,7 +39350,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/file/tail_conversion.c
 +          reiser4_grab_space(inode_file_plugin(inode)->estimate.update(inode),
 +                             BA_CAN_COMMIT);
 +      if (result == 0) {
-+              inode_clr_flag(inode, REISER4_PART_MIXED);
++              reiser4_inode_clr_flag(inode, REISER4_PART_MIXED);
 +              result = reiser4_update_sd(inode);
 +      }
 +      if (result)
@@ -39604,7 +39373,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/file/tail_conversion.c
 +      int result;
 +      lock_handle lh;
 +      coord_t coord;
-+      unix_file_info_t *ufo;
++      struct unix_file_info *ufo;
 +      int found;
 +      reiser4_key key;
 +
@@ -39646,7 +39415,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/file/tail_conversion.c
 + *
 + *
 + */
-+int tail2extent(unix_file_info_t *uf_info)
++int tail2extent(struct unix_file_info *uf_info)
 +{
 +      int result;
 +      reiser4_key key;        /* key of next byte to be moved to page */
@@ -39668,12 +39437,12 @@ Index: linux-2.6.16/fs/reiser4/plugin/file/tail_conversion.c
 +      inode = unix_file_info_to_inode(uf_info);
 +      assert("nikita-3412", !IS_RDONLY(inode));
 +      assert("vs-1649", uf_info->container != UF_CONTAINER_EXTENTS);
-+      assert("", !inode_get_flag(inode, REISER4_PART_IN_CONV));
++      assert("", !reiser4_inode_get_flag(inode, REISER4_PART_IN_CONV));
 +
 +      offset = 0;
 +      first_iteration = 1;
 +      result = 0;
-+      if (inode_get_flag(inode, REISER4_PART_MIXED)) {
++      if (reiser4_inode_get_flag(inode, REISER4_PART_MIXED)) {
 +              /*
 +               * file is marked on disk as there was a conversion which did
 +               * not complete due to either crash or some error. Find which
@@ -39691,7 +39460,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/file/tail_conversion.c
 +              first_iteration = 0;
 +      }
 +
-+      inode_set_flag(inode, REISER4_PART_IN_CONV);
++      reiser4_inode_set_flag(inode, REISER4_PART_IN_CONV);
 +
 +      /* get key of first byte of a file */
 +      inode_file_plugin(inode)->key_by_inode(inode, offset, &key);
@@ -39703,7 +39472,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/file/tail_conversion.c
 +              if (result != 0)
 +                      goto out;
 +              if (first_iteration) {
-+                      inode_set_flag(inode, REISER4_PART_MIXED);
++                      reiser4_inode_set_flag(inode, REISER4_PART_MIXED);
 +                      reiser4_update_sd(inode);
 +                      first_iteration = 0;
 +              }
@@ -39711,7 +39480,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/file/tail_conversion.c
 +              for (i = 0; i < sizeof_array(pages) && done == 0; i++) {
 +                      assert("vs-598",
 +                             (get_key_offset(&key) & ~PAGE_CACHE_MASK) == 0);
-+                      page = alloc_page(get_gfp_mask());
++                      page = alloc_page(reiser4_ctx_gfp_mask_get());
 +                      if (!page) {
 +                              result = RETERR(-ENOMEM);
 +                              goto error;
@@ -39820,15 +39589,18 @@ Index: linux-2.6.16/fs/reiser4/plugin/file/tail_conversion.c
 +                      if (result)
 +                              goto error;
 +                      /*
-+                       * we have to drop exclusive access to avoid deadlock
-+                       * which may happen because called by
-+                       * reiser4_writepages capture_unix_file requires to get
-+                       * non-exclusive access to a file. It is safe to drop
-+                       * EA in the middle of tail2extent conversion because
-+                       * write_unix_file/unix_setattr(truncate)/release_unix_file(extent2tail)
-+                       * are serialized by uf_info->write semaphore and
-+                       * because read_unix_file works (should at least) on
-+                       * partially converted files
++                       * We have to drop exclusive access to avoid deadlock
++                       * which may happen because called by reiser4_writepages
++                       * capture_unix_file requires to get non-exclusive
++                       * access to a file. It is safe to drop EA in the middle
++                       * of tail2extent conversion because write_unix_file,
++                       * setattr_unix_file(truncate), mmap_unix_file,
++                       * release_unix_file(extent2tail) checks if conversion
++                       * is not in progress (see comments before
++                       * get_exclusive_access_careful().
++                       * Other processes that acquire non-exclusive access
++                       * (read_unix_file, reiser4_writepages, etc) should work
++                       * on partially converted files.
 +                       */
 +                      drop_exclusive_access(uf_info);
 +                      /* throttle the conversion */
@@ -39839,15 +39611,17 @@ Index: linux-2.6.16/fs/reiser4/plugin/file/tail_conversion.c
 +                       * nobody is allowed to complete conversion but a
 +                       * process which started it
 +                       */
-+                      assert("", inode_get_flag(inode, REISER4_PART_MIXED));
++                      assert("", reiser4_inode_get_flag(inode,
++                                                        REISER4_PART_MIXED));
 +              }
 +      }
 +
-+      inode_clr_flag(inode, REISER4_PART_IN_CONV);
++      reiser4_inode_clr_flag(inode, REISER4_PART_IN_CONV);
 +
 +      if (result == 0) {
 +              /* file is converted to extent items */
-+              assert("vs-1697", inode_get_flag(inode, REISER4_PART_MIXED));
++              assert("vs-1697", reiser4_inode_get_flag(inode,
++                                                       REISER4_PART_MIXED));
 +
 +              uf_info->container = UF_CONTAINER_EXTENTS;
 +              complete_conversion(inode);
@@ -39871,7 +39645,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/file/tail_conversion.c
 +{
 +      reiser4_tree *tree;
 +
-+      tree = tree_by_inode(inode);
++      tree = reiser4_tree_by_inode(inode);
 +      /*
 +       * reserve blocks for (in this order):
 +       *
@@ -39891,14 +39665,9 @@ Index: linux-2.6.16/fs/reiser4/plugin/file/tail_conversion.c
 +           inode_file_plugin(inode)->estimate.update(inode), BA_CAN_COMMIT);
 +}
 +
-+static int filler(void *vp, struct page *page)
-+{
-+      return readpage_unix_file_nolock(vp, page);
-+}
-+
 +/* for every page of file: read page, cut part of extent pointing to this page,
 +   put data of page tree by tail item */
-+int extent2tail(unix_file_info_t *uf_info)
++int extent2tail(struct unix_file_info *uf_info)
 +{
 +      int result;
 +      struct inode *inode;
@@ -39914,10 +39683,10 @@ Index: linux-2.6.16/fs/reiser4/plugin/file/tail_conversion.c
 +      inode = unix_file_info_to_inode(uf_info);
 +      assert("nikita-3412", !IS_RDONLY(inode));
 +      assert("vs-1649", uf_info->container != UF_CONTAINER_TAILS);
-+      assert("", !inode_get_flag(inode, REISER4_PART_IN_CONV));
++      assert("", !reiser4_inode_get_flag(inode, REISER4_PART_IN_CONV));
 +
 +      offset = 0;
-+      if (inode_get_flag(inode, REISER4_PART_MIXED)) {
++      if (reiser4_inode_get_flag(inode, REISER4_PART_MIXED)) {
 +              /*
 +               * file is marked on disk as there was a conversion which did
 +               * not complete due to either crash or some error. Find which
@@ -39934,7 +39703,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/file/tail_conversion.c
 +                      return result;
 +      }
 +
-+      inode_set_flag(inode, REISER4_PART_IN_CONV);
++      reiser4_inode_set_flag(inode, REISER4_PART_IN_CONV);
 +
 +      /* number of pages in the file */
 +      num_pages =
@@ -39952,12 +39721,12 @@ Index: linux-2.6.16/fs/reiser4/plugin/file/tail_conversion.c
 +              if (result != 0)
 +                      break;
 +              if (i == 0 && offset == 0) {
-+                      inode_set_flag(inode, REISER4_PART_MIXED);
++                      reiser4_inode_set_flag(inode, REISER4_PART_MIXED);
 +                      reiser4_update_sd(inode);
 +              }
 +
-+              page = read_cache_page(inode->i_mapping,
-+                                     (unsigned)(i + start_page), filler, NULL);
++              page = read_mapping_page(inode->i_mapping,
++                                       (unsigned)(i + start_page), NULL);
 +              if (IS_ERR(page)) {
 +                      result = PTR_ERR(page);
 +                      break;
@@ -39972,16 +39741,17 @@ Index: linux-2.6.16/fs/reiser4/plugin/file/tail_conversion.c
 +              }
 +
 +              /* cut part of file we have read */
-+              start_byte = (__u64) (i << PAGE_CACHE_SHIFT);
++              start_byte = (__u64) ((i + start_page) << PAGE_CACHE_SHIFT);
 +              set_key_offset(&from, start_byte);
 +              set_key_offset(&to, start_byte + PAGE_CACHE_SIZE - 1);
 +              /*
-+               * cut_tree_object() returns -E_REPEAT to allow atom
++               * reiser4_cut_tree_object() returns -E_REPEAT to allow atom
 +               * commits during over-long truncates. But
 +               * extent->tail conversion should be performed in one
 +               * transaction.
 +               */
-+              result = cut_tree(tree_by_inode(inode), &from, &to, inode, 0);
++              result = reiser4_cut_tree(reiser4_tree_by_inode(inode), &from,
++                                        &to, inode, 0);
 +
 +              if (result) {
 +                      page_cache_release(page);
@@ -40005,13 +39775,14 @@ Index: linux-2.6.16/fs/reiser4/plugin/file/tail_conversion.c
 +                      file.f_pos = start_byte;
 +                      file.private_data = NULL;
 +                      pos = start_byte;
-+                      result = write_tail(&file, (char __user *)kmap(page),
-+                                          count, &pos);
++                      result = reiser4_write_tail(&file,
++                                                  (char __user *)kmap(page),
++                                                  count, &pos);
 +                      reiser4_free_file_fsdata(&file);
 +                      if (result <= 0) {
-+                              warning("", "write_tail failed");
++                              warning("", "reiser4_write_tail failed");
 +                              page_cache_release(page);
-+                              inode_clr_flag(inode, REISER4_PART_IN_CONV);
++                              reiser4_inode_clr_flag(inode, REISER4_PART_IN_CONV);
 +                              return result;
 +                      }
 +                      count -= result;
@@ -40026,7 +39797,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/file/tail_conversion.c
 +              /* waiting for writeback completion with page lock held is
 +               * perfectly valid. */
 +              wait_on_page_writeback(page);
-+              drop_page(page);
++              reiser4_drop_page(page);
 +              /* release reference taken by read_cache_page() above */
 +              page_cache_release(page);
 +
@@ -40038,14 +39809,15 @@ Index: linux-2.6.16/fs/reiser4/plugin/file/tail_conversion.c
 +               * nobody is allowed to complete conversion but a process which
 +               * started it
 +               */
-+              assert("", inode_get_flag(inode, REISER4_PART_MIXED));
++              assert("", reiser4_inode_get_flag(inode, REISER4_PART_MIXED));
 +      }
 +
-+      inode_clr_flag(inode, REISER4_PART_IN_CONV);
++      reiser4_inode_clr_flag(inode, REISER4_PART_IN_CONV);
 +
 +      if (i == num_pages) {
 +              /* file is converted to formatted items */
-+              assert("vs-1698", inode_get_flag(inode, REISER4_PART_MIXED));
++              assert("vs-1698", reiser4_inode_get_flag(inode,
++                                                       REISER4_PART_MIXED));
 +              assert("vs-1260",
 +                     inode_has_no_jnodes(reiser4_inode_data(inode)));
 +
@@ -40076,11 +39848,10 @@ Index: linux-2.6.16/fs/reiser4/plugin/file/tail_conversion.c
 + * scroll-step: 1
 + * End:
 + */
-Index: linux-2.6.16/fs/reiser4/plugin/file_ops.c
-===================================================================
---- /dev/null
-+++ linux-2.6.16/fs/reiser4/plugin/file_ops.c
-@@ -0,0 +1,167 @@
+diff -urN linux-2.6.22.orig/fs/reiser4/plugin/file_ops.c linux-2.6.22/fs/reiser4/plugin/file_ops.c
+--- linux-2.6.22.orig/fs/reiser4/plugin/file_ops.c     1970-01-01 03:00:00.000000000 +0300
++++ linux-2.6.22/fs/reiser4/plugin/file_ops.c  2007-07-29 00:25:34.932710971 +0400
+@@ -0,0 +1,168 @@
 +/* Copyright 2005 by Hans Reiser, licensing governed by
 +   reiser4/README */
 +
@@ -40096,26 +39867,26 @@ Index: linux-2.6.16/fs/reiser4/plugin/file_ops.c
 +/* implementation of vfs's llseek method of struct file_operations for
 +   typical directory can be found in readdir_common.c
 +*/
-+loff_t llseek_common_dir(struct file *, loff_t, int origin);
++loff_t reiser4_llseek_dir_common(struct file *, loff_t, int origin);
 +
 +/* implementation of vfs's readdir method of struct file_operations for
 +   typical directory can be found in readdir_common.c
 +*/
-+int readdir_common(struct file *, void *dirent, filldir_t);
++int reiser4_readdir_common(struct file *, void *dirent, filldir_t);
 +
 +/**
-+ * release_dir_common - release of struct file_operations
++ * reiser4_release_dir_common - release of struct file_operations
 + * @inode: inode of released file
 + * @file: file to release
 + *
 + * Implementation of release method of struct file_operations for typical
 + * directory. All it does is freeing of reiser4 specific file data.
 +*/
-+int release_dir_common(struct inode *inode, struct file *file)
++int reiser4_release_dir_common(struct inode *inode, struct file *file)
 +{
 +      reiser4_context *ctx;
 +
-+      ctx = init_context(inode->i_sb);
++      ctx = reiser4_init_context(inode->i_sb);
 +      if (IS_ERR(ctx))
 +              return PTR_ERR(ctx);
 +      reiser4_free_file_fsdata(file);
@@ -40126,12 +39897,12 @@ Index: linux-2.6.16/fs/reiser4/plugin/file_ops.c
 +/* this is common implementation of vfs's fsync method of struct
 +   file_operations
 +*/
-+int sync_common(struct file *file, struct dentry *dentry, int datasync)
++int reiser4_sync_common(struct file *file, struct dentry *dentry, int datasync)
 +{
 +      reiser4_context *ctx;
 +      int result;
 +
-+      ctx = init_context(dentry->d_inode->i_sb);
++      ctx = reiser4_init_context(dentry->d_inode->i_sb);
 +      if (IS_ERR(ctx))
 +              return PTR_ERR(ctx);
 +      result = txnmgr_force_commit_all(dentry->d_inode->i_sb, 0);
@@ -40155,7 +39926,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/file_ops.c
 +      reiser4_context *ctx;
 +      ssize_t result;
 +
-+      ctx = init_context(file->f_dentry->d_inode->i_sb);
++      ctx = reiser4_init_context(file->f_dentry->d_inode->i_sb);
 +      if (IS_ERR(ctx))
 +              return PTR_ERR(ctx);
 +      result = generic_file_sendfile(file, ppos, count, actor, target);
@@ -40176,7 +39947,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/file_ops.c
 +      reiser4_context *ctx;
 +      int result;
 +
-+      ctx = init_context(page->mapping->host->i_sb);
++      ctx = reiser4_init_context(page->mapping->host->i_sb);
 +      result = do_prepare_write(file, page, from, to);
 +
 +      /* don't commit transaction under inode semaphore */
@@ -40246,13 +40017,13 @@ Index: linux-2.6.16/fs/reiser4/plugin/file_ops.c
 + * c-basic-offset: 8
 + * tab-width: 8
 + * fill-column: 79
++ * scroll-step: 1
 + * End:
 + */
-Index: linux-2.6.16/fs/reiser4/plugin/file_ops_readdir.c
-===================================================================
---- /dev/null
-+++ linux-2.6.16/fs/reiser4/plugin/file_ops_readdir.c
-@@ -0,0 +1,654 @@
+diff -urN linux-2.6.22.orig/fs/reiser4/plugin/file_ops_readdir.c linux-2.6.22/fs/reiser4/plugin/file_ops_readdir.c
+--- linux-2.6.22.orig/fs/reiser4/plugin/file_ops_readdir.c     1970-01-01 03:00:00.000000000 +0300
++++ linux-2.6.22/fs/reiser4/plugin/file_ops_readdir.c  2007-07-29 00:25:34.932710971 +0400
+@@ -0,0 +1,658 @@
 +/* Copyright 2005 by Hans Reiser, licensing governed by
 + * reiser4/README */
 +
@@ -40262,13 +40033,13 @@ Index: linux-2.6.16/fs/reiser4/plugin/file_ops_readdir.c
 + * @inode directory. */
 +static int is_valid_dir_coord(struct inode *inode, coord_t * coord)
 +{
-+      return
-+          item_type_by_coord(coord) == DIR_ENTRY_ITEM_TYPE &&
-+          inode_file_plugin(inode)->owns_item(inode, coord);
++      return plugin_of_group(item_plugin_by_coord(coord),
++                             DIR_ENTRY_ITEM_TYPE) &&
++             inode_file_plugin(inode)->owns_item(inode, coord);
 +}
 +
 +/* compare two logical positions within the same directory */
-+static cmp_t dir_pos_cmp(const dir_pos * p1, const dir_pos * p2)
++static cmp_t dir_pos_cmp(const struct dir_pos * p1, const struct dir_pos * p2)
 +{
 +      cmp_t result;
 +
@@ -40286,14 +40057,13 @@ Index: linux-2.6.16/fs/reiser4/plugin/file_ops_readdir.c
 +      return result;
 +}
 +
-+
-+/* see comment before readdir_common() for overview of why "adjustment" is
++/* see comment before reiser4_readdir_common() for overview of why "adjustment" is
 + * necessary. */
 +static void
-+adjust_dir_pos(struct file *dir,
-+             readdir_pos * readdir_spot, const dir_pos * mod_point, int adj)
++adjust_dir_pos(struct file *dir, struct readdir_pos * readdir_spot,
++             const struct dir_pos * mod_point, int adj)
 +{
-+      dir_pos *pos;
++      struct dir_pos *pos;
 +
 +      /*
 +       * new directory entry was added (adj == +1) or removed (adj == -1) at
@@ -40315,7 +40085,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/file_ops_readdir.c
 +               * changes */
 +              readdir_spot->entry_no += adj;
 +              assert("nikita-2577",
-+                     ergo(dir != NULL, get_dir_fpos(dir) + adj >= 0));
++                     ergo(dir != NULL, reiser4_get_dir_fpos(dir) + adj >= 0));
 +              if (de_id_cmp(&pos->dir_entry_key,
 +                            &mod_point->dir_entry_key) == EQUAL_TO) {
 +                      assert("nikita-2575", mod_point->pos < pos->pos);
@@ -40353,11 +40123,11 @@ Index: linux-2.6.16/fs/reiser4/plugin/file_ops_readdir.c
 +/* scan all file-descriptors for this directory and adjust their
 +   positions respectively. Should be used by implementations of
 +   add_entry and rem_entry of dir plugin */
-+void
-+adjust_dir_file(struct inode *dir, const struct dentry *de, int offset, int adj)
++void reiser4_adjust_dir_file(struct inode *dir, const struct dentry *de,
++                           int offset, int adj)
 +{
 +      reiser4_file_fsdata *scan;
-+      dir_pos mod_point;
++      struct dir_pos mod_point;
 +
 +      assert("nikita-2536", dir != NULL);
 +      assert("nikita-2538", de != NULL);
@@ -40383,7 +40153,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/file_ops_readdir.c
 +/*
 + * traverse tree to start/continue readdir from the readdir position @pos.
 + */
-+static int dir_go_to(struct file *dir, readdir_pos * pos, tap_t * tap)
++static int dir_go_to(struct file *dir, struct readdir_pos * pos, tap_t * tap)
 +{
 +      reiser4_key key;
 +      int result;
@@ -40395,13 +40165,14 @@ Index: linux-2.6.16/fs/reiser4/plugin/file_ops_readdir.c
 +      result = inode_dir_plugin(inode)->build_readdir_key(dir, &key);
 +      if (result != 0)
 +              return result;
-+      result = object_lookup(inode,
-+                             &key,
-+                             tap->coord,
-+                             tap->lh,
-+                             tap->mode,
-+                             FIND_EXACT,
-+                             LEAF_LEVEL, LEAF_LEVEL, 0, &tap->ra_info);
++      result = reiser4_object_lookup(inode,
++                                     &key,
++                                     tap->coord,
++                                     tap->lh,
++                                     tap->mode,
++                                     FIND_EXACT,
++                                     LEAF_LEVEL, LEAF_LEVEL,
++                                     0, &tap->ra_info);
 +      if (result == CBK_COORD_FOUND)
 +              result = rewind_right(tap, (int)pos->position.pos);
 +      else {
@@ -40416,7 +40187,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/file_ops_readdir.c
 + * handling of non-unique keys: calculate at what ordinal position within
 + * sequence of directory items with identical keys @pos is.
 + */
-+static int set_pos(struct inode *inode, readdir_pos * pos, tap_t * tap)
++static int set_pos(struct inode *inode, struct readdir_pos * pos, tap_t * tap)
 +{
 +      int result;
 +      coord_t coord;
@@ -40427,9 +40198,9 @@ Index: linux-2.6.16/fs/reiser4/plugin/file_ops_readdir.c
 +
 +      coord_init_zero(&coord);
 +      init_lh(&lh);
-+      tap_init(&scan, &coord, &lh, ZNODE_READ_LOCK);
-+      tap_copy(&scan, tap);
-+      tap_load(&scan);
++      reiser4_tap_init(&scan, &coord, &lh, ZNODE_READ_LOCK);
++      reiser4_tap_copy(&scan, tap);
++      reiser4_tap_load(&scan);
 +      pos->position.pos = 0;
 +
 +      did = &pos->position.dir_entry_key;
@@ -40459,15 +40230,15 @@ Index: linux-2.6.16/fs/reiser4/plugin/file_ops_readdir.c
 +              }
 +      } else
 +              result = RETERR(-ENOENT);
-+      tap_relse(&scan);
-+      tap_done(&scan);
++      reiser4_tap_relse(&scan);
++      reiser4_tap_done(&scan);
 +      return result;
 +}
 +
 +/*
 + * "rewind" directory to @offset, i.e., set @pos and @tap correspondingly.
 + */
-+static int dir_rewind(struct file *dir, readdir_pos * pos, tap_t * tap)
++static int dir_rewind(struct file *dir, struct readdir_pos * pos, tap_t * tap)
 +{
 +      __u64 destination;
 +      __s64 shift;
@@ -40480,7 +40251,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/file_ops_readdir.c
 +      assert("nikita-2551", tap->coord != NULL);
 +      assert("nikita-2552", tap->lh != NULL);
 +
-+      dirpos = get_dir_fpos(dir);
++      dirpos = reiser4_get_dir_fpos(dir);
 +      shift = dirpos - pos->fpos;
 +      /* this is logical directory entry within @dir which we are rewinding
 +       * to */
@@ -40513,7 +40284,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/file_ops_readdir.c
 +                              if (result == 0) {
 +                                      result = rewind_left(tap, shift);
 +                                      if (result == -E_DEADLOCK) {
-+                                              tap_done(tap);
++                                              reiser4_tap_done(tap);
 +                                              continue;
 +                                      }
 +                              }
@@ -40550,8 +40321,8 @@ Index: linux-2.6.16/fs/reiser4/plugin/file_ops_readdir.c
 + * unlocked.
 + */
 +static int
-+feed_entry(struct file *f,
-+         readdir_pos * pos, tap_t * tap, filldir_t filldir, void *dirent)
++feed_entry(struct file *f, struct readdir_pos * pos, tap_t * tap,
++         filldir_t filldir, void *dirent)
 +{
 +      item_plugin *iplug;
 +      char *name;
@@ -40580,7 +40351,8 @@ Index: linux-2.6.16/fs/reiser4/plugin/file_ops_readdir.c
 +         deadlock which may happen if filldir causes page fault. So, copy
 +         name to intermediate buffer */
 +      if (strlen(name) + 1 > sizeof(name_buf)) {
-+              local_name = kmalloc(strlen(name) + 1, get_gfp_mask());
++              local_name = kmalloc(strlen(name) + 1,
++                                   reiser4_ctx_gfp_mask_get());
 +              if (local_name == NULL)
 +                      return RETERR(-ENOMEM);
 +      } else
@@ -40590,7 +40362,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/file_ops_readdir.c
 +      file_type = iplug->s.dir.extract_file_type(coord);
 +
 +      unit_key_by_coord(coord, &entry_key);
-+      seal_init(&seal, coord, &entry_key);
++      reiser4_seal_init(&seal, coord, &entry_key);
 +
 +      longterm_unlock_znode(tap->lh);
 +
@@ -40604,6 +40376,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/file_ops_readdir.c
 +       */
 +      assert("nikita-3436", lock_stack_isclean(get_current_lock_stack()));
 +
++      reiser4_txn_restart_current();
 +      result = filldir(dirent, name, (int)strlen(name),
 +                       /* offset of this entry */
 +                       f->f_pos,
@@ -40615,12 +40388,13 @@ Index: linux-2.6.16/fs/reiser4/plugin/file_ops_readdir.c
 +              /* ->filldir() is satisfied. (no space in buffer, IOW) */
 +              result = 1;
 +      else
-+              result = seal_validate(&seal, coord, &entry_key,
-+                                     tap->lh, tap->mode, ZNODE_LOCK_HIPRI);
++              result = reiser4_seal_validate(&seal, coord, &entry_key,
++                                             tap->lh, tap->mode,
++                                             ZNODE_LOCK_HIPRI);
 +      return result;
 +}
 +
-+static void move_entry(readdir_pos * pos, coord_t * coord)
++static void move_entry(struct readdir_pos * pos, coord_t * coord)
 +{
 +      reiser4_key de_key;
 +      de_id *did;
@@ -40648,8 +40422,8 @@ Index: linux-2.6.16/fs/reiser4/plugin/file_ops_readdir.c
 + *
 + * readdir support in reiser4 relies on ability to update readdir_pos embedded
 + * into reiser4_file_fsdata on each directory modification (name insertion and
-+ * removal), see readdir_common() function below. This obviously doesn't work
-+ * when reiser4 is accessed over NFS, because NFS doesn't keep any state
++ * removal), see reiser4_readdir_common() function below. This obviously doesn't
++ * work when reiser4 is accessed over NFS, because NFS doesn't keep any state
 + * across client READDIR requests for the same directory.
 + *
 + * To address this we maintain a "pool" of detached reiser4_file_fsdata
@@ -40681,11 +40455,11 @@ Index: linux-2.6.16/fs/reiser4/plugin/file_ops_readdir.c
 + *
 + */
 +
-+
 +/*
 + * prepare for readdir.
 + */
-+static int dir_readdir_init(struct file *f, tap_t * tap, readdir_pos ** pos)
++static int dir_readdir_init(struct file *f, tap_t * tap,
++                          struct readdir_pos ** pos)
 +{
 +      struct inode *inode;
 +      reiser4_file_fsdata *fsdata;
@@ -40699,7 +40473,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/file_ops_readdir.c
 +              return RETERR(-ENOTDIR);
 +
 +      /* try to find detached readdir state */
-+      result = try_to_attach_fsdata(f, inode);
++      result = reiser4_attach_fsdata(f, inode);
 +      if (result != 0)
 +              return result;
 +
@@ -40723,9 +40497,9 @@ Index: linux-2.6.16/fs/reiser4/plugin/file_ops_readdir.c
 +
 +/* this is implementation of vfs's llseek method of struct file_operations for
 +   typical directory
-+   See comment before readdir_common() for explanation.
++   See comment before reiser4_readdir_common() for explanation.
 +*/
-+loff_t llseek_common_dir(struct file * file, loff_t off, int origin)
++loff_t reiser4_llseek_dir_common(struct file * file, loff_t off, int origin)
 +{
 +      reiser4_context *ctx;
 +      loff_t result;
@@ -40733,7 +40507,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/file_ops_readdir.c
 +
 +      inode = file->f_dentry->d_inode;
 +
-+      ctx = init_context(inode->i_sb);
++      ctx = reiser4_init_context(inode->i_sb);
 +      if (IS_ERR(ctx))
 +              return PTR_ERR(ctx);
 +
@@ -40746,19 +40520,19 @@ Index: linux-2.6.16/fs/reiser4/plugin/file_ops_readdir.c
 +              coord_t coord;
 +              lock_handle lh;
 +              tap_t tap;
-+              readdir_pos *pos;
++              struct readdir_pos *pos;
 +
 +              coord_init_zero(&coord);
 +              init_lh(&lh);
-+              tap_init(&tap, &coord, &lh, ZNODE_READ_LOCK);
++              reiser4_tap_init(&tap, &coord, &lh, ZNODE_READ_LOCK);
 +
 +              ff = dir_readdir_init(file, &tap, &pos);
-+              detach_fsdata(file);
++              reiser4_detach_fsdata(file);
 +              if (ff != 0)
 +                      result = (loff_t) ff;
-+              tap_done(&tap);
++              reiser4_tap_done(&tap);
 +      }
-+      detach_fsdata(file);
++      reiser4_detach_fsdata(file);
 +      mutex_unlock(&inode->i_mutex);
 +
 +      reiser4_exit_context(ctx);
@@ -40808,9 +40582,10 @@ Index: linux-2.6.16/fs/reiser4/plugin/file_ops_readdir.c
 +   entry all file descriptors for directory inode are scanned and their
 +   readdir_pos are updated accordingly (adjust_dir_pos()).
 +*/
-+int readdir_common(struct file *f /* directory file being read */ ,
-+                 void *dirent /* opaque data passed to us by VFS */ ,
-+                 filldir_t filld /* filler function passed to us by VFS */ )
++int reiser4_readdir_common(struct file *f /* directory file being read */,
++                         void *dirent /* opaque data passed to us by VFS */,
++                         filldir_t filld /* filler function passed to us
++                                          * by VFS */)
 +{
 +      reiser4_context *ctx;
 +      int result;
@@ -40818,7 +40593,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/file_ops_readdir.c
 +      coord_t coord;
 +      lock_handle lh;
 +      tap_t tap;
-+      readdir_pos *pos;
++      struct readdir_pos *pos;
 +
 +      assert("nikita-1359", f != NULL);
 +      inode = f->f_dentry->d_inode;
@@ -40827,20 +40602,20 @@ Index: linux-2.6.16/fs/reiser4/plugin/file_ops_readdir.c
 +      if (!S_ISDIR(inode->i_mode))
 +              return RETERR(-ENOTDIR);
 +
-+      ctx = init_context(inode->i_sb);
++      ctx = reiser4_init_context(inode->i_sb);
 +      if (IS_ERR(ctx))
 +              return PTR_ERR(ctx);
 +
 +      coord_init_zero(&coord);
 +      init_lh(&lh);
-+      tap_init(&tap, &coord, &lh, ZNODE_READ_LOCK);
++      reiser4_tap_init(&tap, &coord, &lh, ZNODE_READ_LOCK);
 +
 +      reiser4_readdir_readahead_init(inode, &tap);
 +
 +      repeat:
 +      result = dir_readdir_init(f, &tap, &pos);
 +      if (result == 0) {
-+              result = tap_load(&tap);
++              result = reiser4_tap_load(&tap);
 +              /* scan entries one by one feeding them to @filld */
 +              while (result == 0) {
 +                      coord_t *coord;
@@ -40868,24 +40643,24 @@ Index: linux-2.6.16/fs/reiser4/plugin/file_ops_readdir.c
 +                      } else if (result == -E_REPEAT) {
 +                              /* feed_entry() had to restart. */
 +                              ++f->f_pos;
-+                              tap_relse(&tap);
++                              reiser4_tap_relse(&tap);
 +                              goto repeat;
 +                      } else
 +                              warning("vs-1617",
-+                                      "readdir_common: unexpected error %d",
++                                      "reiser4_readdir_common: unexpected error %d",
 +                                      result);
 +              }
-+              tap_relse(&tap);
++              reiser4_tap_relse(&tap);
 +
 +              if (result >= 0)
 +                      f->f_version = inode->i_version;
 +      } else if (result == -E_NO_NEIGHBOR || result == -ENOENT)
 +              result = 0;
-+      tap_done(&tap);
-+      detach_fsdata(f);
++      reiser4_tap_done(&tap);
++      reiser4_detach_fsdata(f);
 +
 +      /* try to update directory's atime */
-+      if (reiser4_grab_space(inode_file_plugin(inode)->estimate.update(inode),
++      if (reiser4_grab_space_force(inode_file_plugin(inode)->estimate.update(inode),
 +                             BA_CAN_COMMIT) != 0)
 +              warning("", "failed to update atime on readdir: %llu",
 +                      get_inode_oid(inode));
@@ -40907,11 +40682,10 @@ Index: linux-2.6.16/fs/reiser4/plugin/file_ops_readdir.c
 + * fill-column: 79
 + * End:
 + */
-Index: linux-2.6.16/fs/reiser4/plugin/file_plugin_common.c
-===================================================================
---- /dev/null
-+++ linux-2.6.16/fs/reiser4/plugin/file_plugin_common.c
-@@ -0,0 +1,929 @@
+diff -urN linux-2.6.22.orig/fs/reiser4/plugin/file_plugin_common.c linux-2.6.22/fs/reiser4/plugin/file_plugin_common.c
+--- linux-2.6.22.orig/fs/reiser4/plugin/file_plugin_common.c   1970-01-01 03:00:00.000000000 +0300
++++ linux-2.6.22/fs/reiser4/plugin/file_plugin_common.c        2007-07-29 00:25:34.936712007 +0400
+@@ -0,0 +1,1007 @@
 +/* Copyright 2005 by Hans Reiser, licensing governed by
 +   reiser4/README */
 +
@@ -40937,7 +40711,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/file_plugin_common.c
 +
 +      assert("nikita-730", inode != NULL);
 +
-+      if (inode_get_flag(inode, REISER4_NO_SD))
++      if (reiser4_inode_get_flag(inode, REISER4_NO_SD))
 +              /* object doesn't have stat-data yet */
 +              result = insert_new_sd(inode);
 +      else
@@ -40992,7 +40766,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/file_plugin_common.c
 +              object->i_gid = current->fsgid;
 +
 +      /* this object doesn't have stat-data yet */
-+      inode_set_flag(object, REISER4_NO_SD);
++      reiser4_inode_set_flag(object, REISER4_NO_SD);
 +#if 0
 +      /* this is now called after all inode plugins are initialized:
 +         do_create_vfs_child after adjust_to_parent */
@@ -41000,7 +40774,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/file_plugin_common.c
 +      setup_inode_ops(object, data);
 +#endif
 +      object->i_nlink = 0;
-+      seal_init(&reiser4_inode_data(object)->sd_seal, NULL, NULL);
++      reiser4_seal_init(&reiser4_inode_data(object)->sd_seal, NULL, NULL);
 +      mask = (1 << UNIX_STAT) | (1 << LIGHT_WEIGHT_STAT);
 +      if (!reiser4_is_set(object->i_sb, REISER4_32_BIT_TIMES))
 +              mask |= (1 << LARGE_TIMES_STAT);
@@ -41025,10 +40799,10 @@ Index: linux-2.6.16/fs/reiser4/plugin/file_plugin_common.c
 +       * inherit missing plugins from parent
 +       */
 +
-+      grab_plugin(object, parent, PSET_FILE);
-+      grab_plugin(object, parent, PSET_SD);
-+      grab_plugin(object, parent, PSET_FORMATTING);
-+      grab_plugin(object, parent, PSET_PERM);
++      grab_plugin_pset(object, parent, PSET_FILE);
++      grab_plugin_pset(object, parent, PSET_SD);
++      grab_plugin_pset(object, parent, PSET_FORMATTING);
++      grab_plugin_pset(object, parent, PSET_PERM);
 +      return 0;
 +}
 +
@@ -41051,7 +40825,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/file_plugin_common.c
 +       * inherit missing plugins from parent
 +       */
 +      for (memb = 0; memb < PSET_LAST; ++memb) {
-+              result = grab_plugin(object, parent, memb);
++              result = grab_plugin_pset(object, parent, memb);
 +              if (result != 0)
 +                      break;
 +      }
@@ -41068,26 +40842,25 @@ Index: linux-2.6.16/fs/reiser4/plugin/file_plugin_common.c
 +              return result;
 +      assert("edward-1416", parent != NULL);
 +
-+      grab_plugin(object, parent, PSET_CLUSTER);
-+      grab_plugin(object, parent, PSET_CIPHER);
-+      grab_plugin(object, parent, PSET_DIGEST);
-+      grab_plugin(object, parent, PSET_COMPRESSION);
-+      grab_plugin(object, parent, PSET_COMPRESSION_MODE);
++      grab_plugin_pset(object, parent, PSET_CLUSTER);
++      grab_plugin_pset(object, parent, PSET_CIPHER);
++      grab_plugin_pset(object, parent, PSET_DIGEST);
++      grab_plugin_pset(object, parent, PSET_COMPRESSION);
++      grab_plugin_pset(object, parent, PSET_COMPRESSION_MODE);
 +
 +      return 0;
 +}
 +
 +/* this is common implementation of create_object method of file plugin
 + */
-+int
-+create_object_common(struct inode *object, struct inode *parent UNUSED_ARG,
-+                   reiser4_object_create_data * data UNUSED_ARG)
++int reiser4_create_object_common(struct inode *object, struct inode *parent,
++                               reiser4_object_create_data * data)
 +{
 +      reiser4_block_nr reserve;
 +      assert("nikita-744", object != NULL);
 +      assert("nikita-745", parent != NULL);
 +      assert("nikita-747", data != NULL);
-+      assert("nikita-748", inode_get_flag(object, REISER4_NO_SD));
++      assert("nikita-748", reiser4_inode_get_flag(object, REISER4_NO_SD));
 +
 +      reserve = estimate_create_common(object);
 +      if (reiser4_grab_space(reserve, BA_CAN_COMMIT))
@@ -41098,14 +40871,14 @@ Index: linux-2.6.16/fs/reiser4/plugin/file_plugin_common.c
 +static int common_object_delete_no_reserve(struct inode *inode);
 +
 +/**
-+ * delete_object_common - delete_object of file_plugin
++ * reiser4_delete_object_common - delete_object of file_plugin
 + * @inode: inode to be deleted
 + *
 + * This is common implementation of delete_object method of file_plugin. It
 + * applies to object its deletion consists of removing two items - stat data
 + * and safe-link.
 + */
-+int delete_object_common(struct inode *inode)
++int reiser4_delete_object_common(struct inode *inode)
 +{
 +      int result;
 +
@@ -41115,13 +40888,13 @@ Index: linux-2.6.16/fs/reiser4/plugin/file_plugin_common.c
 +      assert("nikita-3420", inode->i_size == 0 || S_ISLNK(inode->i_mode));
 +      assert("nikita-3421", inode->i_nlink == 0);
 +
-+
-+      if (!inode_get_flag(inode, REISER4_NO_SD)) {
++      if (!reiser4_inode_get_flag(inode, REISER4_NO_SD)) {
 +              reiser4_block_nr reserve;
 +
 +              /* grab space which is needed to remove 2 items from the tree:
 +                 stat data and safe-link */
-+              reserve = 2 * estimate_one_item_removal(tree_by_inode(inode));
++              reserve = 2 *
++                estimate_one_item_removal(reiser4_tree_by_inode(inode));
 +              if (reiser4_grab_space_force(reserve,
 +                                           BA_RESERVED | BA_CAN_COMMIT))
 +                      return RETERR(-ENOSPC);
@@ -41132,14 +40905,14 @@ Index: linux-2.6.16/fs/reiser4/plugin/file_plugin_common.c
 +}
 +
 +/**
-+ * delete_directory_common - delete_object of file_plugin
++ * reiser4_delete_dir_common - delete_object of file_plugin
 + * @inode: inode to be deleted
 + *
 + * This is common implementation of delete_object method of file_plugin for
 + * typical directory. It calls done method of dir_plugin to remove "." and
 + * removes stat data and safe-link.
 + */
-+int delete_directory_common(struct inode *inode)
++int reiser4_delete_dir_common(struct inode *inode)
 +{
 +      int result;
 +      dir_plugin *dplug;
@@ -41151,11 +40924,11 @@ Index: linux-2.6.16/fs/reiser4/plugin/file_plugin_common.c
 +      assert("vs-1101", dplug && dplug->done);
 +
 +      /* kill cursors which might be attached to inode */
-+      kill_cursors(inode);
++      reiser4_kill_cursors(inode);
 +
 +      /* grab space enough for removing two items */
 +      if (reiser4_grab_space
-+          (2 * estimate_one_item_removal(tree_by_inode(inode)),
++          (2 * estimate_one_item_removal(reiser4_tree_by_inode(inode)),
 +           BA_RESERVED | BA_CAN_COMMIT))
 +              return RETERR(-ENOSPC);
 +
@@ -41167,7 +40940,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/file_plugin_common.c
 +
 +/* this is common implementation of add_link method of file plugin
 + */
-+int add_link_common(struct inode *object, struct inode *parent UNUSED_ARG)
++int reiser4_add_link_common(struct inode *object, struct inode *parent)
 +{
 +      /*
 +       * increment ->i_nlink and update ->i_ctime
@@ -41180,7 +40953,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/file_plugin_common.c
 +
 +/* this is common implementation of rem_link method of file plugin
 + */
-+int rem_link_common(struct inode *object, struct inode *parent UNUSED_ARG)
++int reiser4_rem_link_common(struct inode *object, struct inode *parent)
 +{
 +      assert("nikita-2021", object != NULL);
 +      assert("nikita-2163", object->i_nlink > 0);
@@ -41240,7 +41013,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/file_plugin_common.c
 +      assert("nikita-1335", inode != NULL);
 +      assert("nikita-1334", coord != NULL);
 +
-+      if (item_type_by_coord(coord) == DIR_ENTRY_ITEM_TYPE)
++      if (plugin_of_group(item_plugin_by_coord(coord), DIR_ENTRY_ITEM_TYPE))
 +              return get_key_locality(item_key_by_coord(coord, &item_key)) ==
 +                  get_inode_oid(inode);
 +      else
@@ -41271,7 +41044,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/file_plugin_common.c
 +/* this is common implementation of detach method of file plugin for typical
 +   directory
 +*/
-+int detach_common_dir(struct inode *child, struct inode *parent)
++int reiser4_detach_common_dir(struct inode *child, struct inode *parent)
 +{
 +      dir_plugin *dplug;
 +
@@ -41284,7 +41057,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/file_plugin_common.c
 +/* this is common implementation of bind method of file plugin for typical
 +   directory
 +*/
-+int bind_common_dir(struct inode *child, struct inode *parent)
++int reiser4_bind_common_dir(struct inode *child, struct inode *parent)
 +{
 +      dir_plugin *dplug;
 +
@@ -41321,7 +41094,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/file_plugin_common.c
 +*/
 +reiser4_block_nr estimate_create_common(const struct inode * object)
 +{
-+      return estimate_one_insert_item(tree_by_inode(object));
++      return estimate_one_insert_item(reiser4_tree_by_inode(object));
 +}
 +
 +/* this is common implementation of estimate.create method of file plugin for
@@ -41331,7 +41104,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/file_plugin_common.c
 +*/
 +reiser4_block_nr estimate_create_common_dir(const struct inode * object)
 +{
-+      return 2 * estimate_one_insert_item(tree_by_inode(object));
++      return 2 * estimate_one_insert_item(reiser4_tree_by_inode(object));
 +}
 +
 +/* this is common implementation of estimate.update method of file plugin
@@ -41340,7 +41113,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/file_plugin_common.c
 +*/
 +reiser4_block_nr estimate_update_common(const struct inode * inode)
 +{
-+      return estimate_one_insert_into_item(tree_by_inode(inode));
++      return estimate_one_insert_into_item(reiser4_tree_by_inode(inode));
 +}
 +
 +/* this is common implementation of estimate.unlink method of file plugin
@@ -41425,7 +41198,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/file_plugin_common.c
 +      if (code != -ENOMEM) {
 +              warning("nikita-717", "Error for inode %llu (%i)",
 +                      (unsigned long long)get_key_objectid(key), code);
-+              print_key("for key", key);
++              reiser4_print_key("for key", key);
 +      }
 +}
 +
@@ -41457,7 +41230,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/file_plugin_common.c
 +          (znode_get_level(coord->node) != LEAF_LEVEL) ||
 +          !item_is_statdata(coord)) {
 +              warning("nikita-1901", "Conspicuous seal");
-+              print_key("key", key);
++              reiser4_print_key("key", key);
 +              print_coord("coord", coord, 1);
 +              impossible("nikita-2877", "no way");
 +      }
@@ -41483,7 +41256,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/file_plugin_common.c
 +      oid_t oid;
 +
 +      assert("nikita-723", inode != NULL);
-+      assert("nikita-3406", inode_get_flag(inode, REISER4_NO_SD));
++      assert("nikita-3406", reiser4_inode_get_flag(inode, REISER4_NO_SD));
 +
 +      ref = reiser4_inode_data(inode);
 +      spin_lock_inode(inode);
@@ -41504,7 +41277,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/file_plugin_common.c
 +/* could be optimized for case where there is only one node format in
 + * use in the filesystem, probably there are lots of such
 + * places we could optimize for only one node layout.... -Hans */
-+      if (data.length > tree_by_inode(inode)->nplug->max_item_size()) {
++      if (data.length > reiser4_tree_by_inode(inode)->nplug->max_item_size()){
 +              /* This is silly check, but we don't know actual node where
 +                 insertion will go into. */
 +              return RETERR(-ENAMETOOLONG);
@@ -41519,7 +41292,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/file_plugin_common.c
 +      coord_init_zero(&coord);
 +      init_lh(&lh);
 +
-+      result = insert_by_key(tree_by_inode(inode),
++      result = insert_by_key(reiser4_tree_by_inode(inode),
 +                             build_sd_key(inode, &key), &data, &coord, &lh,
 +                             /* stat data lives on a leaf level */
 +                             LEAF_LEVEL, CBK_UNIQUE);
@@ -41556,10 +41329,10 @@ Index: linux-2.6.16/fs/reiser4/plugin/file_plugin_common.c
 +                      znode_make_dirty(coord.node);
 +                      if (result == 0) {
 +                              /* object has stat-data now */
-+                              inode_clr_flag(inode, REISER4_NO_SD);
-+                              inode_set_flag(inode, REISER4_SDLEN_KNOWN);
++                              reiser4_inode_clr_flag(inode, REISER4_NO_SD);
++                              reiser4_inode_set_flag(inode, REISER4_SDLEN_KNOWN);
 +                              /* initialise stat-data seal */
-+                              seal_init(&ref->sd_seal, &coord, &key);
++                              reiser4_seal_init(&ref->sd_seal, &coord, &key);
 +                              ref->sd_coord = coord;
 +                              check_inode_seal(inode, &coord, &key);
 +                      } else if (result != -ENOMEM)
@@ -41608,7 +41381,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/file_plugin_common.c
 +       * it only covers _body_ of the file, and stat data don't belong
 +       * there.
 +       */
-+      result = coord_by_key(tree_by_inode(inode),
++      result = coord_by_key(reiser4_tree_by_inode(inode),
 +                            key,
 +                            coord,
 +                            lh,
@@ -41640,12 +41413,13 @@ Index: linux-2.6.16/fs/reiser4/plugin/file_plugin_common.c
 +      spin_unlock_inode(inode);
 +
 +      build_sd_key(inode, key);
-+      if (seal_is_set(&seal)) {
++      if (reiser4_seal_is_set(&seal)) {
 +              /* first, try to use seal */
-+              result = seal_validate(&seal,
-+                                     coord,
-+                                     key,
-+                                     lh, ZNODE_WRITE_LOCK, ZNODE_LOCK_LOPRI);
++              result = reiser4_seal_validate(&seal,
++                                             coord,
++                                             key,
++                                             lh, ZNODE_WRITE_LOCK,
++                                             ZNODE_LOCK_LOPRI);
 +              if (result == 0)
 +                      check_sd_coord(coord, key);
 +      } else
@@ -41658,6 +41432,64 @@ Index: linux-2.6.16/fs/reiser4/plugin/file_plugin_common.c
 +      return result;
 +}
 +
++#if REISER4_DEBUG
++static int all_but_offset_key_eq(const reiser4_key * k1, const reiser4_key * k2)
++{
++      return (get_key_locality(k1) == get_key_locality(k2) &&
++              get_key_type(k1) == get_key_type(k2) &&
++              get_key_band(k1) == get_key_band(k2) &&
++              get_key_ordering(k1) == get_key_ordering(k2) &&
++              get_key_objectid(k1) == get_key_objectid(k2));
++}
++
++#include "../tree_walk.h"
++
++/* make some checks before and after stat-data resize operation */
++static int check_sd_resize(struct inode * inode, coord_t * coord,
++                         int length, int progress /* 1 means after resize */)
++{
++      int ret = 0;
++      lock_handle left_lock;
++      coord_t left_coord;
++      reiser4_key left_key;
++      reiser4_key key;
++
++      if (inode_file_plugin(inode) !=
++          file_plugin_by_id(CRYPTCOMPRESS_FILE_PLUGIN_ID))
++              return 0;
++      if (!length)
++              return 0;
++      if (coord->item_pos != 0)
++              return 0;
++
++      init_lh(&left_lock);
++      ret = reiser4_get_left_neighbor(&left_lock,
++                                      coord->node,
++                                      ZNODE_WRITE_LOCK,
++                                      GN_CAN_USE_UPPER_LEVELS);
++      if (ret == -E_REPEAT || ret == -E_NO_NEIGHBOR ||
++          ret == -ENOENT || ret == -EINVAL
++          || ret == -E_DEADLOCK) {
++              ret = 0;
++              goto exit;
++      }
++      ret = zload(left_lock.node);
++      if (ret)
++              goto exit;
++      coord_init_last_unit(&left_coord, left_lock.node);
++      item_key_by_coord(&left_coord, &left_key);
++      item_key_by_coord(coord, &key);
++
++      if (all_but_offset_key_eq(&key, &left_key))
++              /* corruption occured */
++              ret = 1;
++      zrelse(left_lock.node);
++ exit:
++      done_lh(&left_lock);
++      return ret;
++}
++#endif
++
 +/* update stat-data at @coord */
 +static int
 +update_sd_at(struct inode *inode, coord_t * coord, reiser4_key * key,
@@ -41683,39 +41515,54 @@ Index: linux-2.6.16/fs/reiser4/plugin/file_plugin_common.c
 +
 +      /* if inode has non-standard plugins, add appropriate stat data
 +       * extension */
-+      if (state->plugin_mask != 0)
++      if (state->extmask & (1 << PLUGIN_STAT)) {
++              if (state->plugin_mask == 0)
++                      inode_clr_extension(inode, PLUGIN_STAT);
++      } else if (state->plugin_mask != 0)
 +              inode_set_extension(inode, PLUGIN_STAT);
 +
++      if (state->extmask & (1 << HEIR_STAT)) {
++              if (state->heir_mask == 0)
++                      inode_clr_extension(inode, HEIR_STAT);
++      } else if (state->heir_mask != 0)
++                      inode_set_extension(inode, HEIR_STAT);
++
 +      /* data.length is how much space to add to (or remove
 +         from if negative) sd */
-+      if (!inode_get_flag(inode, REISER4_SDLEN_KNOWN)) {
++      if (!reiser4_inode_get_flag(inode, REISER4_SDLEN_KNOWN)) {
 +              /* recalculate stat-data length */
 +              data.length =
 +                  data.iplug->s.sd.save_len(inode) -
 +                  item_length_by_coord(coord);
-+              inode_set_flag(inode, REISER4_SDLEN_KNOWN);
++              reiser4_inode_set_flag(inode, REISER4_SDLEN_KNOWN);
 +      } else
 +              data.length = 0;
 +      spin_unlock_inode(inode);
 +
 +      /* if on-disk stat data is of different length than required
 +         for this inode, resize it */
++
 +      if (data.length != 0) {
 +              data.data = NULL;
 +              data.user = 0;
 +
++              assert("edward-1441",
++                     !check_sd_resize(inode, coord,
++                                      data.length, 0/* before resize */));
++
 +              /* insertion code requires that insertion point (coord) was
 +               * between units. */
 +              coord->between = AFTER_UNIT;
-+              result = resize_item(coord,
-+                                   &data, key, lh, COPI_DONT_SHIFT_LEFT);
++              result = reiser4_resize_item(coord, &data, key, lh,
++                                           COPI_DONT_SHIFT_LEFT);
 +              if (result != 0) {
 +                      key_warning(key, inode, result);
 +                      zrelse(loaded);
 +                      return result;
 +              }
 +              if (loaded != coord->node) {
-+                      /* resize_item moved coord to another node. Zload it */
++                /* reiser4_resize_item moved coord to another node.
++                   Zload it */
 +                      zrelse(loaded);
 +                      coord_clear_iplug(coord);
 +                      result = zload(coord->node);
@@ -41723,8 +41570,10 @@ Index: linux-2.6.16/fs/reiser4/plugin/file_plugin_common.c
 +                              return result;
 +                      loaded = coord->node;
 +              }
++              assert("edward-1442",
++                     !check_sd_resize(inode, coord,
++                                      data.length, 1/* after resize */));
 +      }
-+
 +      area = item_body_by_coord(coord);
 +      spin_lock_inode(inode);
 +      result = data.iplug->s.sd.save(inode, &area);
@@ -41737,7 +41586,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/file_plugin_common.c
 +       * was changed and new extensions were pasted into item.
 +       */
 +      coord->between = AT_UNIT;
-+      seal_init(&state->sd_seal, coord, key);
++      reiser4_seal_init(&state->sd_seal, coord, key);
 +      state->sd_coord = *coord;
 +      spin_unlock_inode(inode);
 +      check_inode_seal(inode, coord, key);
@@ -41757,7 +41606,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/file_plugin_common.c
 +      assert("nikita-726", inode != NULL);
 +
 +      /* no stat-data, nothing to update?! */
-+      assert("nikita-3482", !inode_get_flag(inode, REISER4_NO_SD));
++      assert("nikita-3482", !reiser4_inode_get_flag(inode, REISER4_NO_SD));
 +
 +      init_lh(&lh);
 +
@@ -41769,8 +41618,8 @@ Index: linux-2.6.16/fs/reiser4/plugin/file_plugin_common.c
 +      return result;
 +}
 +
-+/* helper for delete_object_common and delete_directory_common. Remove object
-+   stat data. Space for that must be reserved by caller before
++/* helper for reiser4_delete_object_common and reiser4_delete_dir_common.
++   Remove object stat data. Space for that must be reserved by caller before
 +*/
 +static int
 +common_object_delete_no_reserve(struct inode *inode /* object to remove */ )
@@ -41779,7 +41628,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/file_plugin_common.c
 +
 +      assert("nikita-1477", inode != NULL);
 +
-+      if (!inode_get_flag(inode, REISER4_NO_SD)) {
++      if (!reiser4_inode_get_flag(inode, REISER4_NO_SD)) {
 +              reiser4_key sd_key;
 +
 +              DQUOT_FREE_INODE(inode);
@@ -41787,14 +41636,15 @@ Index: linux-2.6.16/fs/reiser4/plugin/file_plugin_common.c
 +
 +              build_sd_key(inode, &sd_key);
 +              result =
-+                  cut_tree(tree_by_inode(inode), &sd_key, &sd_key, NULL, 0);
++                  reiser4_cut_tree(reiser4_tree_by_inode(inode),
++                                   &sd_key, &sd_key, NULL, 0);
 +              if (result == 0) {
-+                      inode_set_flag(inode, REISER4_NO_SD);
++                      reiser4_inode_set_flag(inode, REISER4_NO_SD);
 +                      result = oid_release(inode->i_sb, get_inode_oid(inode));
 +                      if (result == 0) {
 +                              oid_count_released();
 +
-+                              result = safe_link_del(tree_by_inode(inode),
++                              result = safe_link_del(reiser4_tree_by_inode(inode),
 +                                                     get_inode_oid(inode),
 +                                                     SAFE_UNLINK);
 +                      }
@@ -41814,7 +41664,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/file_plugin_common.c
 +      struct dentry dentry;
 +
 +      assert("vs-21", is_in_reiser4_context());
-+      ctx = init_context(inode->i_sb);
++      ctx = reiser4_init_context(inode->i_sb);
 +      assert("vs-22", !IS_ERR(ctx));
 +
 +      attr.ia_size = size;
@@ -41833,19 +41683,20 @@ Index: linux-2.6.16/fs/reiser4/plugin/file_plugin_common.c
 +      return result;
 +}
 +
-+/* Local variables:
-+   c-indentation-style: "K&R"
-+   mode-name: "LC"
-+   c-basic-offset: 8
-+   tab-width: 8
-+   fill-column: 120
-+   End:
++/*
++  Local variables:
++  c-indentation-style: "K&R"
++  mode-name: "LC"
++  c-basic-offset: 8
++  tab-width: 8
++  fill-column: 80
++  scroll-step: 1
++  End:
 +*/
-Index: linux-2.6.16/fs/reiser4/plugin/hash.c
-===================================================================
---- /dev/null
-+++ linux-2.6.16/fs/reiser4/plugin/hash.c
-@@ -0,0 +1,350 @@
+diff -urN linux-2.6.22.orig/fs/reiser4/plugin/hash.c linux-2.6.22/fs/reiser4/plugin/hash.c
+--- linux-2.6.22.orig/fs/reiser4/plugin/hash.c 1970-01-01 03:00:00.000000000 +0300
++++ linux-2.6.22/fs/reiser4/plugin/hash.c      2007-07-29 00:25:34.936712007 +0400
+@@ -0,0 +1,353 @@
 +/* Copyright 2001, 2002, 2003 by Hans Reiser, licensing governed by
 + * reiser4/README */
 +
@@ -42095,7 +41946,9 @@ Index: linux-2.6.16/fs/reiser4/plugin/hash.c
 +      return 0xc0c0c0c010101010ull;
 +}
 +
-+static int change_hash(struct inode *inode, reiser4_plugin * plugin)
++static int change_hash(struct inode *inode,
++                     reiser4_plugin * plugin,
++                     pset_member memb)
 +{
 +      int result;
 +
@@ -42103,16 +41956,17 @@ Index: linux-2.6.16/fs/reiser4/plugin/hash.c
 +      assert("nikita-3504", plugin != NULL);
 +
 +      assert("nikita-3505", is_reiser4_inode(inode));
-+      assert("nikita-3506", inode_dir_plugin(inode) != NULL);
 +      assert("nikita-3507", plugin->h.type_id == REISER4_HASH_PLUGIN_TYPE);
 +
++      if (!plugin_of_group(inode_file_plugin(inode), REISER4_DIRECTORY_FILE))
++              return RETERR(-EINVAL);
++
 +      result = 0;
 +      if (inode_hash_plugin(inode) == NULL ||
 +          inode_hash_plugin(inode)->h.id != plugin->h.id) {
 +              if (is_dir_empty(inode) == 0)
-+                      result =
-+                          plugin_set_hash(&reiser4_inode_data(inode)->pset,
-+                                          &plugin->hash);
++                      result = aset_set_unsafe(&reiser4_inode_data(inode)->pset,
++                                               PSET_HASH, plugin);
 +              else
 +                      result = RETERR(-ENOTEMPTY);
 +
@@ -42196,11 +42050,10 @@ Index: linux-2.6.16/fs/reiser4/plugin/hash.c
 +   fill-column: 120
 +   End:
 +*/
-Index: linux-2.6.16/fs/reiser4/plugin/inode_ops.c
-===================================================================
---- /dev/null
-+++ linux-2.6.16/fs/reiser4/plugin/inode_ops.c
-@@ -0,0 +1,886 @@
+diff -urN linux-2.6.22.orig/fs/reiser4/plugin/inode_ops.c linux-2.6.22/fs/reiser4/plugin/inode_ops.c
+--- linux-2.6.22.orig/fs/reiser4/plugin/inode_ops.c    1970-01-01 03:00:00.000000000 +0300
++++ linux-2.6.22/fs/reiser4/plugin/inode_ops.c 2007-07-29 00:25:34.936712007 +0400
+@@ -0,0 +1,897 @@
 +/*
 + * Copyright 2005 by Hans Reiser, licensing governed by reiser4/README
 + */
@@ -42216,12 +42069,11 @@ Index: linux-2.6.16/fs/reiser4/plugin/inode_ops.c
 +#include <linux/quotaops.h>
 +#include <linux/namei.h>
 +
-+
 +static int create_vfs_object(struct inode *parent, struct dentry *dentry,
 +                    reiser4_object_create_data *data);
 +
 +/**
-+ * create_common - create of inode operations
++ * reiser4_create_common - create of inode operations
 + * @parent: inode of parent directory
 + * @dentry: dentry of new object to create
 + * @mode: the permissions to use
@@ -42231,22 +42083,29 @@ Index: linux-2.6.16/fs/reiser4/plugin/inode_ops.c
 + * inode_operations.
 + * Creates regular file using file plugin from parent directory plugin set.
 + */
-+int create_common(struct inode *parent, struct dentry *dentry,
-+                int mode, struct nameidata *nameidata)
++int reiser4_create_common(struct inode *parent, struct dentry *dentry,
++                        int mode, struct nameidata *nameidata)
 +{
 +      reiser4_object_create_data data;
++      file_plugin *fplug;
 +
 +      memset(&data, 0, sizeof data);
 +      data.mode = S_IFREG | mode;
-+      data.id = inode_regular_plugin(parent)->id;
++      fplug = child_create_plugin(parent) ? : inode_create_plugin(parent);
++      if (!plugin_of_group(fplug, REISER4_REGULAR_FILE)) {
++              warning("vpf-1900", "'%s' is not a regular file plugin.",
++                      fplug->h.label);
++              return RETERR(-EIO);
++      }
++      data.id = fplug->h.id;
 +      return create_vfs_object(parent, dentry, &data);
 +}
 +
-+int lookup_name(struct inode *dir, struct dentry *, reiser4_key *);
++int reiser4_lookup_name(struct inode *dir, struct dentry *, reiser4_key *);
 +void check_light_weight(struct inode *inode, struct inode *parent);
 +
 +/**
-+ * lookup_common - lookup of inode operations
++ * reiser4_lookup_common - lookup of inode operations
 + * @parent: inode of directory to lookup into
 + * @dentry: name to look for
 + * @nameidata:
@@ -42254,8 +42113,9 @@ Index: linux-2.6.16/fs/reiser4/plugin/inode_ops.c
 + * This is common implementation of vfs's lookup method of struct
 + * inode_operations.
 + */
-+struct dentry *lookup_common(struct inode *parent, struct dentry *dentry,
-+                           struct nameidata *nameidata)
++struct dentry *reiser4_lookup_common(struct inode *parent,
++                                   struct dentry *dentry,
++                                   struct nameidata *nameidata)
 +{
 +      reiser4_context *ctx;
 +      int result;
@@ -42263,14 +42123,14 @@ Index: linux-2.6.16/fs/reiser4/plugin/inode_ops.c
 +      struct inode *inode;
 +      reiser4_dir_entry_desc entry;
 +
-+      ctx = init_context(parent->i_sb);
++      ctx = reiser4_init_context(parent->i_sb);
 +      if (IS_ERR(ctx))
 +              return (struct dentry *)ctx;
 +
 +      /* set up operations on dentry. */
 +      dentry->d_op = &get_super_private(parent->i_sb)->ops.dentry;
 +
-+      result = lookup_name(parent, dentry, &entry.key);
++      result = reiser4_lookup_name(parent, dentry, &entry.key);
 +      if (result) {
 +              context_set_commit_async(ctx);
 +              reiser4_exit_context(ctx);
@@ -42307,7 +42167,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/inode_ops.c
 +int reiser4_update_dir(struct inode *);
 +
 +/**
-+ * link_common - link of inode operations
++ * reiser4_link_common - link of inode operations
 + * @existing: dentry of object which is to get new name
 + * @parent: directory where new name is to be created
 + * @newname: new name
@@ -42315,8 +42175,8 @@ Index: linux-2.6.16/fs/reiser4/plugin/inode_ops.c
 + * This is common implementation of vfs's link method of struct
 + * inode_operations.
 + */
-+int link_common(struct dentry *existing, struct inode *parent,
-+              struct dentry *newname)
++int reiser4_link_common(struct dentry *existing, struct inode *parent,
++                      struct dentry *newname)
 +{
 +      reiser4_context *ctx;
 +      int result;
@@ -42326,7 +42186,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/inode_ops.c
 +      reiser4_object_create_data data;
 +      reiser4_block_nr reserve;
 +
-+      ctx = init_context(parent->i_sb);
++      ctx = reiser4_init_context(parent->i_sb);
 +      if (IS_ERR(ctx))
 +              return PTR_ERR(ctx);
 +
@@ -42338,7 +42198,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/inode_ops.c
 +      assert("nikita-1434", object != NULL);
 +
 +      /* check for race with create_object() */
-+      if (inode_get_flag(object, REISER4_IMMUTABLE)) {
++      if (reiser4_inode_get_flag(object, REISER4_IMMUTABLE)) {
 +              context_set_commit_async(ctx);
 +              reiser4_exit_context(ctx);
 +              return RETERR(-E_REPEAT);
@@ -42374,7 +42234,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/inode_ops.c
 +       * reiser4_unlink() viz. creation of safe-link.
 +       */
 +      if (unlikely(object->i_nlink == 0)) {
-+              result = safe_link_del(tree_by_inode(object),
++              result = safe_link_del(reiser4_tree_by_inode(object),
 +                                     get_inode_oid(object), SAFE_UNLINK);
 +              if (result != 0) {
 +                      context_set_commit_async(ctx);
@@ -42421,21 +42281,21 @@ Index: linux-2.6.16/fs/reiser4/plugin/inode_ops.c
 +static int unlink_check_and_grab(struct inode *parent, struct dentry *victim);
 +
 +/**
-+ * unlink_common - unlink of inode operations
++ * reiser4_unlink_common - unlink of inode operations
 + * @parent: inode of directory to remove name from
 + * @victim: name to be removed
 + *
 + * This is common implementation of vfs's unlink method of struct
 + * inode_operations.
 + */
-+int unlink_common(struct inode *parent, struct dentry *victim)
++int reiser4_unlink_common(struct inode *parent, struct dentry *victim)
 +{
 +      reiser4_context *ctx;
 +      int result;
 +      struct inode *object;
 +      file_plugin *fplug;
 +
-+      ctx = init_context(parent->i_sb);
++      ctx = reiser4_init_context(parent->i_sb);
 +      if (IS_ERR(ctx))
 +              return PTR_ERR(ctx);
 +
@@ -42516,7 +42376,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/inode_ops.c
 +}
 +
 +/**
-+ * symlink_common - symlink of inode operations
++ * reiser4_symlink_common - symlink of inode operations
 + * @parent: inode of parent directory
 + * @dentry: dentry of object to be created
 + * @linkname: string symlink is to contain
@@ -42525,8 +42385,8 @@ Index: linux-2.6.16/fs/reiser4/plugin/inode_ops.c
 + * inode_operations.
 + * Creates object using file plugin SYMLINK_FILE_PLUGIN_ID.
 + */
-+int symlink_common(struct inode *parent, struct dentry *dentry,
-+                 const char *linkname)
++int reiser4_symlink_common(struct inode *parent, struct dentry *dentry,
++                         const char *linkname)
 +{
 +      reiser4_object_create_data data;
 +
@@ -42538,7 +42398,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/inode_ops.c
 +}
 +
 +/**
-+ * mkdir_common - mkdir of inode operations
++ * reiser4_mkdir_common - mkdir of inode operations
 + * @parent: inode of parent directory
 + * @dentry: dentry of object to be created
 + * @mode: the permissions to use
@@ -42547,7 +42407,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/inode_ops.c
 + * inode_operations.
 + * Creates object using file plugin DIRECTORY_FILE_PLUGIN_ID.
 + */
-+int mkdir_common(struct inode *parent, struct dentry *dentry, int mode)
++int reiser4_mkdir_common(struct inode *parent, struct dentry *dentry, int mode)
 +{
 +      reiser4_object_create_data data;
 +
@@ -42558,7 +42418,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/inode_ops.c
 +}
 +
 +/**
-+ * mknod_common - mknod of inode operations
++ * reiser4_mknod_common - mknod of inode operations
 + * @parent: inode of parent directory
 + * @dentry: dentry of object to be created
 + * @mode: the permissions to use and file type
@@ -42568,8 +42428,8 @@ Index: linux-2.6.16/fs/reiser4/plugin/inode_ops.c
 + * inode_operations.
 + * Creates object using file plugin SPECIAL_FILE_PLUGIN_ID.
 + */
-+int mknod_common(struct inode *parent, struct dentry *dentry,
-+               int mode, dev_t rdev)
++int reiser4_mknod_common(struct inode *parent, struct dentry *dentry,
++                       int mode, dev_t rdev)
 +{
 +      reiser4_object_create_data data;
 +
@@ -42586,35 +42446,36 @@ Index: linux-2.6.16/fs/reiser4/plugin/inode_ops.c
 + */
 +
 +/**
-+ * follow_link_common - follow_link of inode operations
++ * reiser4_follow_link_common - follow_link of inode operations
 + * @dentry: dentry of symlink
 + * @data:
 + *
 + * This is common implementation of vfs's followlink method of struct
 + * inode_operations.
-+ * Assumes that inode's generic_ip points to the content of symbolic link.
++ * Assumes that inode's i_private points to the content of symbolic link.
 + */
-+void *follow_link_common(struct dentry *dentry, struct nameidata *nd)
++void *reiser4_follow_link_common(struct dentry *dentry, struct nameidata *nd)
 +{
 +      assert("vs-851", S_ISLNK(dentry->d_inode->i_mode));
 +
-+      if (!dentry->d_inode->u.generic_ip
-+          || !inode_get_flag(dentry->d_inode, REISER4_GENERIC_PTR_USED))
++      if (!dentry->d_inode->i_private
++          || !reiser4_inode_get_flag(dentry->d_inode,
++                                     REISER4_GENERIC_PTR_USED))
 +              return ERR_PTR(RETERR(-EINVAL));
-+      nd_set_link(nd, dentry->d_inode->u.generic_ip);
++      nd_set_link(nd, dentry->d_inode->i_private);
 +      return NULL;
 +}
 +
 +/**
-+ * permission_common - permission of inode operations
++ * reiser4_permission_common - permission of inode operations
 + * @inode: inode to check permissions for
 + * @mask: mode bits to check permissions for
 + * @nameidata:
 + *
 + * Uses generic function to check for rwx permissions.
 + */
-+int permission_common(struct inode *inode, int mask,
-+                    struct nameidata *nameidata)
++int reiser4_permission_common(struct inode *inode, int mask,
++                            struct nameidata *nameidata)
 +{
 +      return generic_permission(inode, mask, NULL);
 +}
@@ -42624,7 +42485,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/inode_ops.c
 +/* this is common implementation of vfs's setattr method of struct
 +   inode_operations
 +*/
-+int setattr_common(struct dentry *dentry, struct iattr *attr)
++int reiser4_setattr_common(struct dentry *dentry, struct iattr *attr)
 +{
 +      reiser4_context *ctx;
 +      struct inode *inode;
@@ -42635,7 +42496,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/inode_ops.c
 +      if (result)
 +              return result;
 +
-+      ctx = init_context(inode->i_sb);
++      ctx = reiser4_init_context(inode->i_sb);
 +      if (IS_ERR(ctx))
 +              return PTR_ERR(ctx);
 +
@@ -42644,7 +42505,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/inode_ops.c
 +      /*
 +       * grab disk space and call standard inode_setattr().
 +       */
-+      result = setattr_reserve(tree_by_inode(inode));
++      result = setattr_reserve(reiser4_tree_by_inode(inode));
 +      if (!result) {
 +              if ((attr->ia_valid & ATTR_UID && attr->ia_uid != inode->i_uid)
 +                  || (attr->ia_valid & ATTR_GID
@@ -42669,9 +42530,8 @@ Index: linux-2.6.16/fs/reiser4/plugin/inode_ops.c
 +/* this is common implementation of vfs's getattr method of struct
 +   inode_operations
 +*/
-+int
-+getattr_common(struct vfsmount *mnt UNUSED_ARG, struct dentry *dentry,
-+             struct kstat *stat)
++int reiser4_getattr_common(struct vfsmount *mnt UNUSED_ARG,
++                         struct dentry *dentry, struct kstat *stat)
 +{
 +      struct inode *obj;
 +
@@ -42797,7 +42657,8 @@ Index: linux-2.6.16/fs/reiser4/plugin/inode_ops.c
 +      memset(&entry, 0, sizeof entry);
 +      entry.obj = object;
 +
-+      plugin_set_file(&reiser4_inode_data(object)->pset, obj_plug);
++      set_plugin(&reiser4_inode_data(object)->pset, PSET_FILE,
++                 file_plugin_to_plugin(obj_plug));
 +      result = obj_plug->set_plug_in_inode(object, parent, data);
 +      if (result) {
 +              warning("nikita-431", "Cannot install plugin %i on %llx",
@@ -42824,6 +42685,8 @@ Index: linux-2.6.16/fs/reiser4/plugin/inode_ops.c
 +      result = obj_plug->adjust_to_parent(object,
 +                                          parent,
 +                                          object->i_sb->s_root->d_inode);
++      if (result == 0)
++              result = finish_pset(object);
 +      if (result != 0) {
 +              warning("nikita-432", "Cannot inherit from %llx to %llx",
 +                      (unsigned long long)get_inode_oid(parent),
@@ -42867,19 +42730,19 @@ Index: linux-2.6.16/fs/reiser4/plugin/inode_ops.c
 +         crash. This all only matters if it's possible to access file
 +         without name, for example, by inode number
 +       */
-+      inode_set_flag(object, REISER4_IMMUTABLE);
++      reiser4_inode_set_flag(object, REISER4_IMMUTABLE);
 +
 +      /* create empty object, this includes allocation of new objectid. For
 +         directories this implies creation of dot and dotdot  */
-+      assert("nikita-2265", inode_get_flag(object, REISER4_NO_SD));
++      assert("nikita-2265", reiser4_inode_get_flag(object, REISER4_NO_SD));
 +
 +      /* mark inode as `loaded'. From this point onward
 +         reiser4_delete_inode() will try to remove its stat-data. */
-+      inode_set_flag(object, REISER4_LOADED);
++      reiser4_inode_set_flag(object, REISER4_LOADED);
 +
 +      result = obj_plug->create_object(object, parent, data);
 +      if (result != 0) {
-+              inode_clr_flag(object, REISER4_IMMUTABLE);
++              reiser4_inode_clr_flag(object, REISER4_IMMUTABLE);
 +              if (result != -ENAMETOOLONG && result != -ENOMEM)
 +                      warning("nikita-2219",
 +                              "Failed to create sd for %llu",
@@ -42892,7 +42755,8 @@ Index: linux-2.6.16/fs/reiser4/plugin/inode_ops.c
 +      if (obj_dir != NULL)
 +              result = obj_dir->init(object, parent, data);
 +      if (result == 0) {
-+              assert("nikita-434", !inode_get_flag(object, REISER4_NO_SD));
++              assert("nikita-434", !reiser4_inode_get_flag(object,
++                                                           REISER4_NO_SD));
 +              /* insert inode into VFS hash table */
 +              insert_inode_hash(object);
 +              /* create entry */
@@ -42936,7 +42800,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/inode_ops.c
 +      }
 +
 +      /* file has name now, clear immutable flag */
-+      inode_clr_flag(object, REISER4_IMMUTABLE);
++      reiser4_inode_clr_flag(object, REISER4_IMMUTABLE);
 +
 +      /* on error, iput() will call ->delete_inode(). We should keep track
 +         of the existence of stat-data for this inode and avoid attempt to
@@ -42957,7 +42821,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/inode_ops.c
 +      int result;
 +      struct inode *child;
 +
-+      ctx = init_context(parent->i_sb);
++      ctx = reiser4_init_context(parent->i_sb);
 +      if (IS_ERR(ctx))
 +              return PTR_ERR(ctx);
 +      context_set_commit_async(ctx);
@@ -43005,7 +42869,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/inode_ops.c
 +      /* update_dir(parent) */
 +      res += inode_file_plugin(parent)->estimate.update(parent);
 +      /* safe-link */
-+      res += estimate_one_item_removal(tree_by_inode(object));
++      res += estimate_one_item_removal(reiser4_tree_by_inode(object));
 +
 +      return res;
 +}
@@ -43037,12 +42901,12 @@ Index: linux-2.6.16/fs/reiser4/plugin/inode_ops.c
 +      /* fplug->unlink */
 +      res += fplug->estimate.unlink(object, parent);
 +      /* safe-link */
-+      res += estimate_one_insert_item(tree_by_inode(object));
++      res += estimate_one_insert_item(reiser4_tree_by_inode(object));
 +
 +      return res;
 +}
 +
-+/* helper for unlink_common. Estimate and grab space for unlink. */
++/* helper for reiser4_unlink_common. Estimate and grab space for unlink. */
 +static int unlink_check_and_grab(struct inode *parent, struct dentry *victim)
 +{
 +      file_plugin *fplug;
@@ -43054,10 +42918,10 @@ Index: linux-2.6.16/fs/reiser4/plugin/inode_ops.c
 +      fplug = inode_file_plugin(child);
 +
 +      /* check for race with create_object() */
-+      if (inode_get_flag(child, REISER4_IMMUTABLE))
++      if (reiser4_inode_get_flag(child, REISER4_IMMUTABLE))
 +              return RETERR(-E_REPEAT);
 +      /* object being deleted should have stat data */
-+      assert("vs-949", !inode_get_flag(child, REISER4_NO_SD));
++      assert("vs-949", !reiser4_inode_get_flag(child, REISER4_NO_SD));
 +
 +      /* ask object plugin */
 +      if (fplug->can_rem_link != NULL && !fplug->can_rem_link(child))
@@ -43070,7 +42934,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/inode_ops.c
 +      return reiser4_grab_reserved(child->i_sb, result, BA_CAN_COMMIT);
 +}
 +
-+/* helper for setattr_common */
++/* helper for reiser4_setattr_common */
 +static int setattr_reserve(reiser4_tree * tree)
 +{
 +      assert("vs-1096", is_grab_enabled(get_current_context()));
@@ -43087,11 +42951,10 @@ Index: linux-2.6.16/fs/reiser4/plugin/inode_ops.c
 +      dir->i_ctime = dir->i_mtime = CURRENT_TIME;
 +      return reiser4_update_sd(dir);
 +}
-Index: linux-2.6.16/fs/reiser4/plugin/inode_ops_rename.c
-===================================================================
---- /dev/null
-+++ linux-2.6.16/fs/reiser4/plugin/inode_ops_rename.c
-@@ -0,0 +1,904 @@
+diff -urN linux-2.6.22.orig/fs/reiser4/plugin/inode_ops_rename.c linux-2.6.22/fs/reiser4/plugin/inode_ops_rename.c
+--- linux-2.6.22.orig/fs/reiser4/plugin/inode_ops_rename.c     1970-01-01 03:00:00.000000000 +0300
++++ linux-2.6.22/fs/reiser4/plugin/inode_ops_rename.c  2007-07-29 00:25:34.940713042 +0400
+@@ -0,0 +1,914 @@
 +/* Copyright 2001, 2002, 2003, 2004 by Hans Reiser, licensing governed by
 + * reiser4/README */
 +
@@ -43123,7 +42986,9 @@ Index: linux-2.6.16/fs/reiser4/plugin/inode_ops_rename.c
 +      if (result != 0)
 +              return result;
 +      from_item = item_plugin_by_coord(from_coord);
-+      if (item_type_by_coord(from_coord) == DIR_ENTRY_ITEM_TYPE) {
++      if (plugin_of_group(item_plugin_by_coord(from_coord),
++                          DIR_ENTRY_ITEM_TYPE))
++      {
 +              reiser4_key to_key;
 +
 +              build_sd_key(to_inode, &to_key);
@@ -43363,7 +43228,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/inode_ops_rename.c
 +      return 0;
 +}
 +
-+int find_entry(struct inode *, struct dentry *, lock_handle *,
++int reiser4_find_entry(struct inode *, struct dentry *, lock_handle *,
 +             znode_lock_mode, reiser4_dir_entry_desc *);
 +int reiser4_update_dir(struct inode *);
 +
@@ -43378,10 +43243,12 @@ Index: linux-2.6.16/fs/reiser4/plugin/inode_ops_rename.c
 +   entry. This should be re-considered when more than one different
 +   directory plugin will be implemented.
 +*/
-+int rename_common(struct inode *old_dir /* directory where @old is located */ ,
-+                struct dentry *old_name /* old name */ ,
-+                struct inode *new_dir /* directory where @new is located */ ,
-+                struct dentry *new_name /* new name */ )
++int reiser4_rename_common(struct inode *old_dir /* directory where @old
++                                               * is located */ ,
++                        struct dentry *old_name /* old name */ ,
++                        struct inode *new_dir /* directory where @new
++                                               * is located */ ,
++                        struct dentry *new_name /* new name */ )
 +{
 +      /* From `The Open Group Base Specifications Issue 6'
 +
@@ -43469,22 +43336,22 @@ Index: linux-2.6.16/fs/reiser4/plugin/inode_ops_rename.c
 +      struct inode *new_inode;
 +      coord_t *new_coord;
 +
-+      reiser4_dentry_fsdata *new_fsdata;
++      struct reiser4_dentry_fsdata *new_fsdata;
 +      dir_plugin *dplug;
 +      file_plugin *fplug;
 +
 +      reiser4_dir_entry_desc *old_entry, *new_entry, *dotdot_entry;
 +      lock_handle *new_lh, *dotdot_lh;
 +      struct dentry *dotdot_name;
-+      reiser4_dentry_fsdata *dataonstack;
++      struct reiser4_dentry_fsdata *dataonstack;
 +
-+      ctx = init_context(old_dir->i_sb);
++      ctx = reiser4_init_context(old_dir->i_sb);
 +      if (IS_ERR(ctx))
 +              return PTR_ERR(ctx);
 +
 +      old_entry = kmalloc(3 * sizeof(*old_entry) + 2 * sizeof(*new_lh) +
 +                          sizeof(*dotdot_name) + sizeof(*dataonstack),
-+                          GFP_KERNEL);
++                          reiser4_ctx_gfp_mask_get());
 +      if (old_entry == NULL) {
 +              context_set_commit_async(ctx);
 +              reiser4_exit_context(ctx);
@@ -43498,7 +43365,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/inode_ops_rename.c
 +      new_lh = (lock_handle *)(old_entry + 3);
 +      dotdot_lh = new_lh + 1;
 +      dotdot_name = (struct dentry *)(new_lh + 2);
-+      dataonstack = (reiser4_dentry_fsdata *)(dotdot_name + 1);
++      dataonstack = (struct reiser4_dentry_fsdata *)(dotdot_name + 1);
 +
 +      assert("nikita-2318", old_dir != NULL);
 +      assert("nikita-2319", new_dir != NULL);
@@ -43558,8 +43425,8 @@ Index: linux-2.6.16/fs/reiser4/plugin/inode_ops_rename.c
 +      init_lh(new_lh);
 +
 +      /* find entry for @new_name */
-+      result = find_entry(new_dir,
-+                          new_name, new_lh, ZNODE_WRITE_LOCK, new_entry);
++      result = reiser4_find_entry(new_dir, new_name, new_lh, ZNODE_WRITE_LOCK,
++                                  new_entry);
 +
 +      if (IS_CBKERR(result)) {
 +              done_lh(new_lh);
@@ -43569,7 +43436,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/inode_ops_rename.c
 +              return result;
 +      }
 +
-+      seal_done(&new_fsdata->dec.entry_seal);
++      reiser4_seal_done(&new_fsdata->dec.entry_seal);
 +
 +      /* add or replace name for @old_inode as @new_name */
 +      if (new_inode != NULL) {
@@ -43668,8 +43535,9 @@ Index: linux-2.6.16/fs/reiser4/plugin/inode_ops_rename.c
 +                      dotdot_coord = &dataonstack->dec.entry_coord;
 +                      coord_clear_iplug(dotdot_coord);
 +
-+                      result = find_entry(old_inode, dotdot_name, dotdot_lh,
-+                                          ZNODE_WRITE_LOCK, dotdot_entry);
++                      result = reiser4_find_entry(old_inode, dotdot_name,
++                                                  dotdot_lh, ZNODE_WRITE_LOCK,
++                                                  dotdot_entry);
 +                      if (result == 0) {
 +                              /* replace_name() decreases i_nlink on
 +                               * @old_dir */
@@ -43703,10 +43571,12 @@ Index: linux-2.6.16/fs/reiser4/plugin/inode_ops_rename.c
 +}
 +
 +#if 0
-+int rename_common(struct inode *old_dir /* directory where @old is located */ ,
-+                struct dentry *old_name /* old name */ ,
-+                struct inode *new_dir /* directory where @new is located */ ,
-+                struct dentry *new_name /* new name */ )
++int reiser4_rename_common(struct inode *old_dir /* directory where @old
++                                               * is located */ ,
++                        struct dentry *old_name /* old name */ ,
++                        struct inode *new_dir /* directory where @new
++                                               * is located */ ,
++                        struct dentry *new_name /* new name */ )
 +{
 +      /* From `The Open Group Base Specifications Issue 6'
 +
@@ -43794,12 +43664,12 @@ Index: linux-2.6.16/fs/reiser4/plugin/inode_ops_rename.c
 +      reiser4_dir_entry_desc old_entry;
 +      reiser4_dir_entry_desc new_entry;
 +      coord_t *new_coord;
-+      reiser4_dentry_fsdata *new_fsdata;
++      struct reiser4_dentry_fsdata *new_fsdata;
 +      lock_handle new_lh;
 +      dir_plugin *dplug;
 +      file_plugin *fplug;
 +
-+      ctx = init_context(old_dir->i_sb);
++      ctx = reiser4_init_context(old_dir->i_sb);
 +      if (IS_ERR(ctx))
 +              return PTR_ERR(ctx);
 +
@@ -43847,15 +43717,15 @@ Index: linux-2.6.16/fs/reiser4/plugin/inode_ops_rename.c
 +      init_lh(&new_lh);
 +
 +      /* find entry for @new_name */
-+      result = find_entry(new_dir,
-+                          new_name, &new_lh, ZNODE_WRITE_LOCK, &new_entry);
++      result = reiser4_find_entry(new_dir, new_name, &new_lh,
++                                  ZNODE_WRITE_LOCK, &new_entry);
 +
 +      if (IS_CBKERR(result)) {
 +              done_lh(&new_lh);
 +              goto exit;
 +      }
 +
-+      seal_done(&new_fsdata->dec.entry_seal);
++      reiser4_seal_done(&new_fsdata->dec.entry_seal);
 +
 +      /* add or replace name for @old_inode as @new_name */
 +      if (new_inode != NULL) {
@@ -43941,8 +43811,8 @@ Index: linux-2.6.16/fs/reiser4/plugin/inode_ops_rename.c
 +                      lock_handle dotdot_lh;
 +                      struct dentry dotdot_name;
 +                      reiser4_dir_entry_desc dotdot_entry;
-+                      reiser4_dentry_fsdata dataonstack;
-+                      reiser4_dentry_fsdata *fsdata;
++                      struct reiser4_dentry_fsdata dataonstack;
++                      struct reiser4_dentry_fsdata *fsdata;
 +
 +                      memset(&dataonstack, 0, sizeof dataonstack);
 +                      memset(&dotdot_entry, 0, sizeof dotdot_entry);
@@ -43962,8 +43832,11 @@ Index: linux-2.6.16/fs/reiser4/plugin/inode_ops_rename.c
 +                      dotdot_coord = &fsdata->dec.entry_coord;
 +                      coord_clear_iplug(dotdot_coord);
 +
-+                      result = find_entry(old_inode, &dotdot_name, &dotdot_lh,
-+                                          ZNODE_WRITE_LOCK, &dotdot_entry);
++                      result = reiser4_find_entry(old_inode,
++                                                  &dotdot_name,
++                                                  &dotdot_lh,
++                                                  ZNODE_WRITE_LOCK,
++                                                  &dotdot_entry);
 +                      if (result == 0) {
 +                              /* replace_name() decreases i_nlink on
 +                               * @old_dir */
@@ -43996,33 +43869,9 @@ Index: linux-2.6.16/fs/reiser4/plugin/inode_ops_rename.c
 +      return result;
 +}
 +#endif
-Index: linux-2.6.16/fs/reiser4/plugin/item/Makefile
-===================================================================
---- /dev/null
-+++ linux-2.6.16/fs/reiser4/plugin/item/Makefile
-@@ -0,0 +1,18 @@
-+obj-$(CONFIG_REISER4_FS) += item_plugins.o
-+
-+item_plugins-objs :=          \
-+      item.o                  \
-+      static_stat.o           \
-+      sde.o                   \
-+      cde.o                   \
-+      blackbox.o              \
-+      internal.o              \
-+      tail.o                  \
-+      ctail.o                 \
-+      extent.o                \
-+      extent_item_ops.o       \
-+      extent_file_ops.o       \
-+      extent_flush_ops.o
-+
-+
-+
-Index: linux-2.6.16/fs/reiser4/plugin/item/acl.h
-===================================================================
---- /dev/null
-+++ linux-2.6.16/fs/reiser4/plugin/item/acl.h
+diff -urN linux-2.6.22.orig/fs/reiser4/plugin/item/acl.h linux-2.6.22/fs/reiser4/plugin/item/acl.h
+--- linux-2.6.22.orig/fs/reiser4/plugin/item/acl.h     1970-01-01 03:00:00.000000000 +0300
++++ linux-2.6.22/fs/reiser4/plugin/item/acl.h  2007-07-29 00:25:34.940713042 +0400
 @@ -0,0 +1,66 @@
 +/* Copyright 2001, 2002, 2003 by Hans Reiser, licensing governed by reiser4/README */
 +
@@ -44090,10 +43939,9 @@ Index: linux-2.6.16/fs/reiser4/plugin/item/acl.h
 +   fill-column: 120
 +   End:
 +*/
-Index: linux-2.6.16/fs/reiser4/plugin/item/blackbox.c
-===================================================================
---- /dev/null
-+++ linux-2.6.16/fs/reiser4/plugin/item/blackbox.c
+diff -urN linux-2.6.22.orig/fs/reiser4/plugin/item/blackbox.c linux-2.6.22/fs/reiser4/plugin/item/blackbox.c
+--- linux-2.6.22.orig/fs/reiser4/plugin/item/blackbox.c        1970-01-01 03:00:00.000000000 +0300
++++ linux-2.6.22/fs/reiser4/plugin/item/blackbox.c     2007-07-29 00:25:34.940713042 +0400
 @@ -0,0 +1,142 @@
 +/* Copyright 2003 by Hans Reiser, licensing governed by
 + * reiser4/README */
@@ -44225,7 +44073,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/item/blackbox.c
 +
 +int kill_black_box(reiser4_tree * tree, const reiser4_key * key)
 +{
-+      return cut_tree(tree, key, key, NULL, 1);
++      return reiser4_cut_tree(tree, key, key, NULL, 1);
 +}
 +
 +/* Make Linus happy.
@@ -44237,10 +44085,9 @@ Index: linux-2.6.16/fs/reiser4/plugin/item/blackbox.c
 +   fill-column: 120
 +   End:
 +*/
-Index: linux-2.6.16/fs/reiser4/plugin/item/blackbox.h
-===================================================================
---- /dev/null
-+++ linux-2.6.16/fs/reiser4/plugin/item/blackbox.h
+diff -urN linux-2.6.22.orig/fs/reiser4/plugin/item/blackbox.h linux-2.6.22/fs/reiser4/plugin/item/blackbox.h
+--- linux-2.6.22.orig/fs/reiser4/plugin/item/blackbox.h        1970-01-01 03:00:00.000000000 +0300
++++ linux-2.6.22/fs/reiser4/plugin/item/blackbox.h     2007-07-29 00:25:34.940713042 +0400
 @@ -0,0 +1,33 @@
 +/* Copyright 2003 by Hans Reiser, licensing governed by
 + * reiser4/README */
@@ -44275,11 +44122,10 @@ Index: linux-2.6.16/fs/reiser4/plugin/item/blackbox.h
 +   fill-column: 120
 +   End:
 +*/
-Index: linux-2.6.16/fs/reiser4/plugin/item/cde.c
-===================================================================
---- /dev/null
-+++ linux-2.6.16/fs/reiser4/plugin/item/cde.c
-@@ -0,0 +1,1007 @@
+diff -urN linux-2.6.22.orig/fs/reiser4/plugin/item/cde.c linux-2.6.22/fs/reiser4/plugin/item/cde.c
+--- linux-2.6.22.orig/fs/reiser4/plugin/item/cde.c     1970-01-01 03:00:00.000000000 +0300
++++ linux-2.6.22/fs/reiser4/plugin/item/cde.c  2007-07-29 00:25:34.944714077 +0400
+@@ -0,0 +1,1008 @@
 +/* Copyright 2001, 2002, 2003 by Hans Reiser, licensing governed by reiser4/README */
 +
 +/* Directory entry implementation */
@@ -44567,7 +44413,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/item/cde.c
 +
 +/* insert new @entry into item */
 +static int expand(const coord_t * coord /* coord of item */ ,
-+                cde_entry * entry /* entry to insert */ ,
++                struct cde_entry * entry /* entry to insert */ ,
 +                int len /* length of @entry data */ ,
 +                int *pos /* position to insert */ ,
 +                reiser4_dir_entry_desc * dir_entry    /* parameters for new
@@ -44591,7 +44437,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/item/cde.c
 +
 +/* paste body of @entry into item */
 +static int paste_entry(const coord_t * coord /* coord of item */ ,
-+                     cde_entry * entry /* new entry */ ,
++                     struct cde_entry * entry /* new entry */ ,
 +                     int pos /* position to insert */ ,
 +                     reiser4_dir_entry_desc * dir_entry       /* parameters for
 +                                                               * new entry */ )
@@ -44627,11 +44473,11 @@ Index: linux-2.6.16/fs/reiser4/plugin/item/cde.c
 +int estimate_cde(const coord_t * coord /* coord of item */ ,
 +               const reiser4_item_data * data /* parameters for new item */ )
 +{
-+      cde_entry_data *e;
++      struct cde_entry_data *e;
 +      int result;
 +      int i;
 +
-+      e = (cde_entry_data *) data->data;
++      e = (struct cde_entry_data *) data->data;
 +
 +      assert("nikita-1288", e != NULL);
 +      assert("nikita-1289", e->num_of_entries >= 0);
@@ -44708,9 +44554,9 @@ Index: linux-2.6.16/fs/reiser4/plugin/item/cde.c
 +      assert("nikita-1342", coord != NULL);
 +
 +      item_key_by_coord(coord, result);
-+      set_key_ordering(result, get_key_ordering(max_key()));
-+      set_key_fulloid(result, get_key_fulloid(max_key()));
-+      set_key_offset(result, get_key_offset(max_key()));
++      set_key_ordering(result, get_key_ordering(reiser4_max_key()));
++      set_key_fulloid(result, get_key_fulloid(reiser4_max_key()));
++      set_key_offset(result, get_key_offset(reiser4_max_key()));
 +      return result;
 +}
 +
@@ -44741,8 +44587,8 @@ Index: linux-2.6.16/fs/reiser4/plugin/item/cde.c
 +   possible check of the consistency of the item that the inventor can
 +   construct
 +*/
-+int check_cde(const coord_t * coord /* coord of item to check */ ,
-+            const char **error /* where to store error message */ )
++int reiser4_check_cde(const coord_t * coord /* coord of item to check */,
++                    const char **error /* where to store error message */)
 +{
 +      int i;
 +      int result;
@@ -44850,12 +44696,12 @@ Index: linux-2.6.16/fs/reiser4/plugin/item/cde.c
 +                                       * inserted */ ,
 +            carry_plugin_info * info UNUSED_ARG /* todo carry queue */ )
 +{
-+      cde_entry_data *e;
++      struct cde_entry_data *e;
 +      int result;
 +      int i;
 +
 +      CHECKME(coord);
-+      e = (cde_entry_data *) data->data;
++      e = (struct cde_entry_data *) data->data;
 +
 +      result = 0;
 +      for (i = 0; i < e->num_of_entries; ++i) {
@@ -45190,8 +45036,8 @@ Index: linux-2.6.16/fs/reiser4/plugin/item/cde.c
 +                                                       * directory entry */ )
 +{
 +      reiser4_item_data data;
-+      cde_entry entry;
-+      cde_entry_data edata;
++      struct cde_entry entry;
++      struct cde_entry_data edata;
 +      int result;
 +
 +      assert("nikita-1656", coord->node == lh->node);
@@ -45220,7 +45066,8 @@ Index: linux-2.6.16/fs/reiser4/plugin/item/cde.c
 +      if (result)
 +              result = insert_by_coord(coord, &data, &dir_entry->key, lh, 0);
 +      else
-+              result = resize_item(coord, &data, &dir_entry->key, lh, 0);
++              result = reiser4_resize_item(coord, &data, &dir_entry->key,
++                                           lh, 0);
 +      return result;
 +}
 +
@@ -45273,9 +45120,9 @@ Index: linux-2.6.16/fs/reiser4/plugin/item/cde.c
 +int max_name_len_cde(const struct inode *dir /* directory */ )
 +{
 +      return
-+          tree_by_inode(dir)->nplug->max_item_size() -
-+          sizeof(directory_entry_format) - sizeof(cde_item_format) -
-+          sizeof(cde_unit_header) - 2;
++              reiser4_tree_by_inode(dir)->nplug->max_item_size() -
++              sizeof(directory_entry_format) - sizeof(cde_item_format) -
++              sizeof(cde_unit_header) - 2;
 +}
 +
 +/* Make Linus happy.
@@ -45287,10 +45134,9 @@ Index: linux-2.6.16/fs/reiser4/plugin/item/cde.c
 +   fill-column: 120
 +   End:
 +*/
-Index: linux-2.6.16/fs/reiser4/plugin/item/cde.h
-===================================================================
---- /dev/null
-+++ linux-2.6.16/fs/reiser4/plugin/item/cde.h
+diff -urN linux-2.6.22.orig/fs/reiser4/plugin/item/cde.h linux-2.6.22/fs/reiser4/plugin/item/cde.h
+--- linux-2.6.22.orig/fs/reiser4/plugin/item/cde.h     1970-01-01 03:00:00.000000000 +0300
++++ linux-2.6.22/fs/reiser4/plugin/item/cde.h  2007-07-29 00:25:34.944714077 +0400
 @@ -0,0 +1,87 @@
 +/* Copyright 2001, 2002, 2003 by Hans Reiser, licensing governed by reiser4/README */
 +
@@ -45316,16 +45162,16 @@ Index: linux-2.6.16/fs/reiser4/plugin/item/cde.h
 +      cde_unit_header entry[0];
 +} cde_item_format;
 +
-+typedef struct cde_entry {
++struct cde_entry {
 +      const struct inode *dir;
 +      const struct inode *obj;
 +      const struct qstr *name;
-+} cde_entry;
++};
 +
-+typedef struct cde_entry_data {
++struct cde_entry_data {
 +      int num_of_entries;
-+      cde_entry *entry;
-+} cde_entry_data;
++      struct cde_entry *entry;
++};
 +
 +/* plugin->item.b.* */
 +reiser4_key *max_key_inside_cde(const coord_t * coord, reiser4_key * result);
@@ -45353,7 +45199,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/item/cde.h
 +                 struct carry_kill_data *, reiser4_key * smallest_removed,
 +                 reiser4_key * new_first);
 +void print_cde(const char *prefix, coord_t * coord);
-+int check_cde(const coord_t * coord, const char **error);
++int reiser4_check_cde(const coord_t * coord, const char **error);
 +
 +/* plugin->u.item.s.dir.* */
 +int extract_key_cde(const coord_t * coord, reiser4_key * key);
@@ -45379,11 +45225,10 @@ Index: linux-2.6.16/fs/reiser4/plugin/item/cde.h
 +   fill-column: 120
 +   End:
 +*/
-Index: linux-2.6.16/fs/reiser4/plugin/item/ctail.c
-===================================================================
---- /dev/null
-+++ linux-2.6.16/fs/reiser4/plugin/item/ctail.c
-@@ -0,0 +1,1588 @@
+diff -urN linux-2.6.22.orig/fs/reiser4/plugin/item/ctail.c linux-2.6.22/fs/reiser4/plugin/item/ctail.c
+--- linux-2.6.22.orig/fs/reiser4/plugin/item/ctail.c   1970-01-01 03:00:00.000000000 +0300
++++ linux-2.6.22/fs/reiser4/plugin/item/ctail.c        2007-07-29 00:25:34.948715113 +0400
+@@ -0,0 +1,1614 @@
 +/* Copyright 2001, 2002, 2003 by Hans Reiser, licensing governed by reiser4/README */
 +
 +/* ctails (aka "clustered tails") are items for cryptcompress objects */
@@ -45431,18 +45276,26 @@ Index: linux-2.6.16/fs/reiser4/plugin/item/ctail.c
 +      return item_body_by_coord(coord);
 +}
 +
-+int cluster_shift_by_coord(const coord_t * coord)
++static int cluster_shift_by_coord(const coord_t * coord)
 +{
 +      return get_unaligned(&ctail_formatted_at(coord)->cluster_shift);
 +}
 +
++static inline void dclust_set_extension_shift(hint_t * hint)
++{
++      assert("edward-1270",
++             item_id_by_coord(&hint->ext_coord.coord) == CTAIL_ID);
++      hint->ext_coord.extension.ctail.shift =
++          cluster_shift_by_coord(&hint->ext_coord.coord);
++}
++
 +static loff_t off_by_coord(const coord_t * coord)
 +{
 +      reiser4_key key;
 +      return get_key_offset(item_key_by_coord(coord, &key));
 +}
 +
-+static int coord_is_unprepped_ctail(const coord_t * coord)
++int coord_is_unprepped_ctail(const coord_t * coord)
 +{
 +      assert("edward-1233", coord != NULL);
 +      assert("edward-1234", item_id_by_coord(coord) == CTAIL_ID);
@@ -45521,15 +45374,14 @@ Index: linux-2.6.16/fs/reiser4/plugin/item/ctail.c
 +      return 1;
 +}
 +
-+/* plugin->u.item.b.mergeable
-+   c-tails of different clusters are not mergeable */
++/* plugin->u.item.b.mergeable */
 +int mergeable_ctail(const coord_t * p1, const coord_t * p2)
 +{
 +      reiser4_key key1, key2;
 +
 +      assert("edward-62", item_id_by_coord(p1) == CTAIL_ID);
-+      assert("edward-61",
-+             item_type_by_coord(p1) == UNIX_FILE_METADATA_ITEM_TYPE);
++      assert("edward-61", plugin_of_group(item_plugin_by_coord(p1),
++                                          UNIX_FILE_METADATA_ITEM_TYPE));
 +
 +      if (item_id_by_coord(p2) != CTAIL_ID) {
 +              /* second item is of another type */
@@ -45740,9 +45592,8 @@ Index: linux-2.6.16/fs/reiser4/plugin/item/ctail.c
 +}
 +
 +/* plugin->u.item.b.kill_hook */
-+int
-+kill_hook_ctail(const coord_t * coord, pos_in_node_t from, pos_in_node_t count,
-+              carry_kill_data * kdata)
++int kill_hook_ctail(const coord_t * coord, pos_in_node_t from,
++                  pos_in_node_t count, carry_kill_data * kdata)
 +{
 +      struct inode *inode;
 +
@@ -45752,12 +45603,24 @@ Index: linux-2.6.16/fs/reiser4/plugin/item/ctail.c
 +      inode = kdata->inode;
 +      if (inode) {
 +              reiser4_key key;
++              struct cryptcompress_info * info;
++              cloff_t index;
++
 +              item_key_by_coord(coord, &key);
++              info = cryptcompress_inode_data(inode);
++              index = off_to_clust(get_key_offset(&key), inode);
 +
-+              if (from == 0 && is_disk_cluster_key(&key, coord)) {
-+                      cloff_t start =
-+                          off_to_clust(get_key_offset(&key), inode);
-+                      truncate_page_cluster(inode, start);
++              if (from == 0) {
++                      info->trunc_index = index;
++                      if (is_disk_cluster_key(&key, coord)) {
++                              /*
++                               * first item of disk cluster is to be killed
++                               */
++                              truncate_complete_page_cluster(
++                                      inode, index, kdata->params.truncate);
++                              inode_sub_bytes(inode,
++                                              inode_cluster_size(inode));
++                      }
 +              }
 +      }
 +      return 0;
@@ -45901,127 +45764,164 @@ Index: linux-2.6.16/fs/reiser4/plugin/item/ctail.c
 +      /* read only whole ctails */
 +      assert("edward-135", nr_units_ctail(coord) <= f->length);
 +
-+      assert("edward-136", schedulable());
++      assert("edward-136", reiser4_schedulable());
 +      assert("edward-886", ctail_ok(coord));
 +
 +      if (f->data)
 +              memcpy(f->data, (char *)first_unit(coord),
 +                     (size_t) nr_units_ctail(coord));
 +
-+      dclust_set_extension(hint);
++      dclust_set_extension_shift(hint);
 +      mark_page_accessed(znode_page(coord->node));
 +      move_flow_forward(f, nr_units_ctail(coord));
 +
 +      return 0;
 +}
 +
-+/* Reads a disk cluster consists of ctail items,
-+   attaches a transform stream with plain text */
-+int ctail_read_disk_cluster(reiser4_cluster_t * clust, struct inode *inode,
-+                          int write)
++/**
++ * Prepare transform stream with plain text for page
++ * @page taking into account synchronization issues.
++ */
++int ctail_read_disk_cluster(struct cluster_handle * clust, struct inode * inode,
++                          struct page * page, znode_lock_mode mode)
 +{
 +      int result;
++
++      assert("edward-1450", mode == ZNODE_READ_LOCK || ZNODE_WRITE_LOCK);
 +      assert("edward-671", clust->hint != NULL);
 +      assert("edward-140", clust->dstat == INVAL_DISK_CLUSTER);
-+      assert("edward-672", crc_inode_ok(inode));
++      assert("edward-672", cryptcompress_inode_ok(inode));
++      assert("edward-1527", PageLocked(page));
++
++      unlock_page(page);
 +
 +      /* set input stream */
 +      result = grab_tfm_stream(inode, &clust->tc, INPUT_STREAM);
-+      if (result)
++      if (result) {
++              lock_page(page);
 +              return result;
-+
-+      result = find_cluster(clust, inode, 1 /* read */ , write);
-+      assert("edward-1340", !result);
++      }
++      result = find_disk_cluster(clust, inode, 1 /* read items */, mode);
++      lock_page(page);
 +      if (result)
 +              return result;
-+      if (!write)
-+              /* write still need the lock to insert unprepped
-+                 items, etc... */
-+              put_hint_cluster(clust, inode, ZNODE_READ_LOCK);
-+
-+      assert("edward-673",
-+             ergo(write, znode_is_write_locked(clust->hint->lh.node)));
++      /*
++       * at this point we have locked position in the tree
++       */
++      assert("edward-1528", znode_is_any_locked(clust->hint->lh.node));
 +
++      if (page->mapping != inode->i_mapping) {
++              /* page was truncated */
++              reiser4_unset_hint(clust->hint);
++              reset_cluster_params(clust);
++              return AOP_TRUNCATED_PAGE;
++      }
++      if (PageUptodate(page)) {
++              /* disk cluster can be obsolete, don't use it! */
++              reiser4_unset_hint(clust->hint);
++              reset_cluster_params(clust);
++              return 0;
++      }
 +      if (clust->dstat == FAKE_DISK_CLUSTER ||
-+          clust->dstat == UNPR_DISK_CLUSTER) {
++          clust->dstat == UNPR_DISK_CLUSTER ||
++          clust->dstat == TRNC_DISK_CLUSTER) {
++              /*
++               * this information about disk cluster will be valid
++               * as long as we keep the position in the tree locked
++               */
 +              tfm_cluster_set_uptodate(&clust->tc);
 +              return 0;
 +      }
++      /* now prepare output stream.. */
 +      result = grab_coa(&clust->tc, inode_compression_plugin(inode));
 +      if (result)
 +              return result;
-+      result = inflate_cluster(clust, inode);
++      /* ..and fill this with plain text */
++      result = reiser4_inflate_cluster(clust, inode);
 +      if (result)
 +              return result;
++      /*
++       * The stream is ready! It won't be obsolete as
++       * long as we keep last disk cluster item locked.
++       */
 +      tfm_cluster_set_uptodate(&clust->tc);
 +      return 0;
 +}
 +
-+/* read one locked page */
-+int do_readpage_ctail(struct inode * inode, reiser4_cluster_t * clust,
-+                    struct page *page)
++/*
++ * fill one page with plain text.
++ */
++int do_readpage_ctail(struct inode * inode, struct cluster_handle * clust,
++                    struct page *page, znode_lock_mode mode)
 +{
 +      int ret;
 +      unsigned cloff;
 +      char *data;
-+      size_t pgcnt;
-+      tfm_cluster_t *tc = &clust->tc;
++      size_t to_page;
++      struct tfm_cluster * tc = &clust->tc;
 +
 +      assert("edward-212", PageLocked(page));
 +
++      if (unlikely(page->mapping != inode->i_mapping))
++              return AOP_TRUNCATED_PAGE;
 +      if (PageUptodate(page))
 +              goto exit;
-+
++      to_page = pbytes(page_index(page), inode);
++      if (to_page == 0) {
++              zero_user_page(page, 0, PAGE_CACHE_SIZE, KM_USER0);
++              SetPageUptodate(page);
++              goto exit;
++      }
 +      if (!tfm_cluster_is_uptodate(&clust->tc)) {
 +              clust->index = pg_to_clust(page->index, inode);
-+              unlock_page(page);
-+              ret = ctail_read_disk_cluster(clust, inode, 0 /* read */ );
-+              lock_page(page);
++
++              /* this will unlock/lock the page */
++              ret = ctail_read_disk_cluster(clust, inode, page, mode);
++
++              assert("edward-212", PageLocked(page));
 +              if (ret)
 +                      return ret;
++
++              /* refresh bytes */
++              to_page = pbytes(page_index(page), inode);
++              if (to_page == 0) {
++                      zero_user_page(page, 0, PAGE_CACHE_SIZE, KM_USER0);
++                      SetPageUptodate(page);
++                      goto exit;
++              }
 +      }
 +      if (PageUptodate(page))
-+              /* races with another read/write */
++              /* somebody else fill it already */
 +              goto exit;
 +
-+      /* bytes in the page */
-+      pgcnt = cnt_to_pgcnt(i_size_read(inode), page->index);
-+
-+      if (pgcnt == 0) {
-+              assert("edward-1290", 0);
-+              return RETERR(-EINVAL);
-+      }
 +      assert("edward-119", tfm_cluster_is_uptodate(tc));
++      assert("edward-1529", znode_is_any_locked(clust->hint->lh.node));
 +
 +      switch (clust->dstat) {
 +      case UNPR_DISK_CLUSTER:
-+              assert("edward-1285", 0);
-+#if REISER4_DEBUG
-+              warning("edward-1168",
-+                      "page %lu is not uptodate and disk cluster %lu (inode %llu) is unprepped\n",
-+                      page->index, clust->index,
-+                      (unsigned long long)get_inode_oid(inode));
-+#endif
++              BUG_ON(1);
++      case TRNC_DISK_CLUSTER:
++              /*
++               * Race with truncate!
++               * We resolve it in favour of the last one (the only way,
++                 * as in this case plain text is unrecoverable)
++               */
 +      case FAKE_DISK_CLUSTER:
 +              /* fill the page by zeroes */
-+              data = kmap_atomic(page, KM_USER0);
-+
-+              memset(data, 0, PAGE_CACHE_SIZE);
-+              flush_dcache_page(page);
-+              kunmap_atomic(data, KM_USER0);
++              zero_user_page(page, 0, PAGE_CACHE_SIZE, KM_USER0);
 +              SetPageUptodate(page);
 +              break;
 +      case PREP_DISK_CLUSTER:
-+              /* fill the page by transformed data */
++              /* fill page by transformed stream with plain text */
 +              assert("edward-1058", !PageUptodate(page));
 +              assert("edward-120", tc->len <= inode_cluster_size(inode));
 +
-+              /* start page offset in the cluster */
++              /* page index in this logical cluster */
 +              cloff = pg_to_off_to_cloff(page->index, inode);
 +
 +              data = kmap(page);
-+              memcpy(data, tfm_stream_data(tc, OUTPUT_STREAM) + cloff, pgcnt);
-+              memset(data + pgcnt, 0, (size_t) PAGE_CACHE_SIZE - pgcnt);
++              memcpy(data, tfm_stream_data(tc, OUTPUT_STREAM) + cloff, to_page);
++              memset(data + to_page, 0, (size_t) PAGE_CACHE_SIZE - to_page);
 +              flush_dcache_page(page);
 +              kunmap(page);
 +              SetPageUptodate(page);
@@ -46037,32 +45937,33 @@ Index: linux-2.6.16/fs/reiser4/plugin/item/ctail.c
 +int readpage_ctail(void *vp, struct page *page)
 +{
 +      int result;
-+      hint_t *hint;
-+      reiser4_cluster_t *clust = vp;
++      hint_t * hint;
++      struct cluster_handle * clust = vp;
 +
 +      assert("edward-114", clust != NULL);
 +      assert("edward-115", PageLocked(page));
 +      assert("edward-116", !PageUptodate(page));
-+      assert("edward-117", !jprivate(page) && !PagePrivate(page));
 +      assert("edward-118", page->mapping && page->mapping->host);
 +      assert("edward-867", !tfm_cluster_is_uptodate(&clust->tc));
 +
-+      hint = kmalloc(sizeof(*hint), GFP_KERNEL);
-+      if (hint == NULL)
++      hint = kmalloc(sizeof(*hint), reiser4_ctx_gfp_mask_get());
++      if (hint == NULL) {
++              unlock_page(page);
 +              return RETERR(-ENOMEM);
++      }
 +      clust->hint = hint;
 +      result = load_file_hint(clust->file, hint);
 +      if (result) {
 +              kfree(hint);
++              unlock_page(page);
 +              return result;
 +      }
 +      assert("vs-25", hint->ext_coord.lh == &hint->lh);
-+      result = do_readpage_ctail(page->mapping->host, clust, page);
 +
++      result = do_readpage_ctail(page->mapping->host, clust, page,
++                                 ZNODE_READ_LOCK);
 +      assert("edward-213", PageLocked(page));
 +      assert("edward-1163", ergo(!result, PageUptodate(page)));
-+      assert("edward-868",
-+             ergo(!result, tfm_cluster_is_uptodate(&clust->tc)));
 +
 +      unlock_page(page);
 +      done_lh(&hint->lh);
@@ -46074,10 +45975,9 @@ Index: linux-2.6.16/fs/reiser4/plugin/item/ctail.c
 +      return result;
 +}
 +
-+/* This unconditionally reads a disk cluster.
-+   Helper function for ->readpages() */
-+static int
-+ctail_read_page_cluster(reiser4_cluster_t * clust, struct inode *inode)
++/* Helper function for ->readpages() */
++static int ctail_read_page_cluster(struct cluster_handle * clust,
++                                 struct inode *inode)
 +{
 +      int i;
 +      int result;
@@ -46085,132 +45985,102 @@ Index: linux-2.6.16/fs/reiser4/plugin/item/ctail.c
 +      assert("edward-1059", clust->win == NULL);
 +      assert("edward-780", inode != NULL);
 +
-+      result = prepare_page_cluster(inode, clust, 0 /* do not capture */ );
++      result = prepare_page_cluster(inode, clust, READ_OP);
 +      if (result)
 +              return result;
-+      result = ctail_read_disk_cluster(clust, inode, 0 /* read */ );
-+      if (result)
-+              goto out;
-+      /* at this point stream with valid plain text is attached */
-+      assert("edward-781", tfm_cluster_is_uptodate(&clust->tc));
++
++      assert("edward-781", !tfm_cluster_is_uptodate(&clust->tc));
 +
 +      for (i = 0; i < clust->nr_pages; i++) {
 +              struct page *page = clust->pages[i];
 +              lock_page(page);
-+              result = do_readpage_ctail(inode, clust, page);
++              result = do_readpage_ctail(inode, clust, page, ZNODE_READ_LOCK);
 +              unlock_page(page);
 +              if (result)
 +                      break;
 +      }
 +      tfm_cluster_clr_uptodate(&clust->tc);
-+      out:
-+      release_cluster_pages(clust);
++      put_page_cluster(clust, inode, READ_OP);
 +      return result;
 +}
 +
-+#define list_to_page(head) (list_entry((head)->prev, struct page, lru))
-+#define list_to_next_page(head) (list_entry((head)->prev->prev, struct page, lru))
++/* filler for read_cache_pages() */
++static int ctail_readpages_filler(void * data, struct page * page)
++{
++      int ret = 0;
++      struct cluster_handle * clust = data;
++      struct inode * inode = clust->file->f_dentry->d_inode;
 +
-+#if REISER4_DEBUG
-+#define check_order(pages)                                                    \
-+assert("edward-214", ergo(!list_empty(pages) && pages->next != pages->prev,   \
-+       list_to_page(pages)->index < list_to_next_page(pages)->index))
-+#endif
++      assert("edward-1525", page->mapping == inode->i_mapping);
 +
-+/* plugin->u.item.s.file.readpages
-+   Populate an address space with some page clusters,
-+   and start reads against them.
-+   FIXME-EDWARD: this function should return errors?
-+*/
-+void
-+readpages_ctail(void *vp, struct address_space *mapping,
-+              struct list_head *pages)
++      if (PageUptodate(page)) {
++              unlock_page(page);
++              return 0;
++      }
++      if (pbytes(page_index(page), inode) == 0) {
++              zero_user_page(page, 0, PAGE_CACHE_SIZE, KM_USER0);
++              SetPageUptodate(page);
++              unlock_page(page);
++              return 0;
++      }
++      move_cluster_forward(clust, inode, page->index);
++      unlock_page(page);
++      /*
++       * read the whole page cluster
++       */
++      ret = ctail_read_page_cluster(clust, inode);
++
++      assert("edward-869", !tfm_cluster_is_uptodate(&clust->tc));
++      return ret;
++}
++
++/*
++ * We populate a bit more then upper readahead suggests:
++ * with each nominated page we read the whole page cluster
++ * this page belongs to.
++ */
++int readpages_ctail(struct file *file, struct address_space *mapping,
++                  struct list_head *pages)
 +{
 +      int ret = 0;
 +      hint_t *hint;
-+      reiser4_cluster_t clust;
-+      struct page *page;
-+      struct pagevec lru_pvec;
++      struct cluster_handle clust;
 +      struct inode *inode = mapping->host;
-+      int progress = 0;
 +
-+      assert("edward-214", ergo(!list_empty(pages) &&
-+                                pages->next != pages->prev,
-+                                list_to_page(pages)->index <
-+                                list_to_next_page(pages)->index));
-+      pagevec_init(&lru_pvec, 0);
++      assert("edward-1521", inode == file->f_dentry->d_inode);
++
 +      cluster_init_read(&clust, NULL);
-+      clust.file = vp;
-+      hint = kmalloc(sizeof(*hint), GFP_KERNEL);
++      clust.file = file;
++      hint = kmalloc(sizeof(*hint), reiser4_ctx_gfp_mask_get());
 +      if (hint == NULL) {
 +              warning("vs-28", "failed to allocate hint");
++              ret = RETERR(-ENOMEM);
 +              goto exit1;
 +      }
 +      clust.hint = hint;
 +      ret = load_file_hint(clust.file, hint);
-+      if (ret)
++      if (ret) {
++              warning("edward-1522", "failed to load hint");
 +              goto exit2;
++      }
++      assert("vs-26", hint->ext_coord.lh == &hint->lh);
 +      ret = alloc_cluster_pgset(&clust, cluster_nrpages(inode));
-+      if (ret)
++      if (ret) {
++              warning("edward-1523", "failed to alloc pgset");
 +              goto exit3;
-+      assert("vs-26", hint->ext_coord.lh == &hint->lh);
-+
-+      /* address_space-level file readahead doesn't know about
-+         reiser4 concept of clustering, so we work around this
-+         fact: with each page of the list @pages address space
-+         will be populated with the whole page cluster.
-+      */
-+      while (!list_empty(pages)) {
-+              page = list_to_page(pages);
-+              list_del(&page->lru);
-+              if (add_to_page_cache(page, mapping, page->index, GFP_KERNEL)) {
-+                      page_cache_release(page);
-+                      continue;
-+              }
-+              if (PageUptodate(page)) {
-+                      if (!pagevec_add(&lru_pvec, page))
-+                              __pagevec_lru_add(&lru_pvec);
-+                      unlock_page(page);
-+                      continue;
-+              }
-+              unlock_page(page);
-+
-+              move_cluster_forward(&clust, inode, page->index, &progress);
-+              ret = ctail_read_page_cluster(&clust, inode);
-+              if (ret)
-+                      break;
-+              assert("edward-869", !tfm_cluster_is_uptodate(&clust.tc));
-+              lock_page(page);
-+
-+              ret = do_readpage_ctail(inode, &clust, page);
-+              if (!pagevec_add(&lru_pvec, page))
-+                      __pagevec_lru_add(&lru_pvec);
-+              if (ret) {
-+                      warning("edward-215", "do_readpage_ctail failed");
-+                      unlock_page(page);
-+                      break;
-+              }
-+              assert("edward-1061", PageUptodate(page));
-+
-+              unlock_page(page);
 +      }
++      ret = read_cache_pages(mapping, pages, ctail_readpages_filler, &clust);
++
 +      assert("edward-870", !tfm_cluster_is_uptodate(&clust.tc));
 + exit3:
 +      done_lh(&hint->lh);
-+      save_file_hint(clust.file, hint);
++      save_file_hint(file, hint);
 +      hint->ext_coord.valid = 0;
 + exit2:
 +      kfree(hint);
 + exit1:
-+      while (!list_empty(pages)) {
-+              struct page *victim;
-+              victim = list_to_page(pages);
-+              list_del(&victim->lru);
-+              page_cache_release(victim);
-+      }
 +      put_cluster_handle(&clust);
-+      pagevec_lru_add(&lru_pvec);
-+      return;
++      return ret;
 +}
 +
 +/*
@@ -46223,14 +46093,13 @@ Index: linux-2.6.16/fs/reiser4/plugin/item/ctail.c
 +      assert("edward-1242", cluster_shift_ok(cluster_shift_by_coord(coord)));
 +
 +      item_key_by_coord(coord, key);
-+      set_key_offset(key,
-+                     ((__u64) (clust_by_coord(coord, NULL)) +
-+                      1) << cluster_shift_by_coord(coord));
++      set_key_offset(key, ((__u64) (clust_by_coord(coord, NULL)) + 1)
++                     << cluster_shift_by_coord(coord));
 +      return key;
 +}
 +
-+static int
-+insert_unprepped_ctail(reiser4_cluster_t * clust, struct inode *inode)
++static int insert_unprepped_ctail(struct cluster_handle * clust,
++                                struct inode *inode)
 +{
 +      int result;
 +      char buf[UCTAIL_NR_UNITS];
@@ -46256,8 +46125,8 @@ Index: linux-2.6.16/fs/reiser4/plugin/item/ctail.c
 +}
 +
 +static int
-+insert_crc_flow(coord_t * coord, lock_handle * lh, flow_t * f,
-+              struct inode *inode)
++insert_cryptcompress_flow(coord_t * coord, lock_handle * lh, flow_t * f,
++                        struct inode *inode)
 +{
 +      int result;
 +      carry_pool *pool;
@@ -46284,8 +46153,8 @@ Index: linux-2.6.16/fs/reiser4/plugin/item/ctail.c
 +              coord->unit_pos = 0;
 +              coord->between = AFTER_ITEM;
 +      }
-+      op = post_carry(lowest_level, COP_INSERT_FLOW, coord->node,
-+                      0 /* operate directly on coord -> node */ );
++      op = reiser4_post_carry(lowest_level, COP_INSERT_FLOW, coord->node,
++                              0 /* operate directly on coord -> node */);
 +      if (IS_ERR(op) || (op == NULL)) {
 +              done_carry_pool(pool);
 +              return RETERR(op ? PTR_ERR(op) : -EIO);
@@ -46306,16 +46175,16 @@ Index: linux-2.6.16/fs/reiser4/plugin/item/ctail.c
 +      lowest_level->track_type = CARRY_TRACK_CHANGE;
 +      lowest_level->tracked = lh;
 +
-+      result = carry(lowest_level, NULL);
++      result = reiser4_carry(lowest_level, NULL);
 +      done_carry_pool(pool);
 +
 +      return result;
 +}
 +
 +/* Implementation of CRC_APPEND_ITEM mode of ctail conversion */
-+static int
-+insert_crc_flow_in_place(coord_t * coord, lock_handle * lh, flow_t * f,
-+                       struct inode *inode)
++static int insert_cryptcompress_flow_in_place(coord_t * coord,
++                                            lock_handle * lh, flow_t * f,
++                                            struct inode *inode)
 +{
 +      int ret;
 +      coord_t pos;
@@ -46333,7 +46202,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/item/ctail.c
 +      init_lh(&lock);
 +      copy_lh(&lock, lh);
 +
-+      ret = insert_crc_flow(&pos, &lock, f, inode);
++      ret = insert_cryptcompress_flow(&pos, &lock, f, inode);
 +      done_lh(&lock);
 +      assert("edward-1347", znode_is_write_locked(lh->node));
 +      assert("edward-1228", !ret);
@@ -46351,7 +46220,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/item/ctail.c
 +      assert("edward-272", coord_is_existing_unit(coord));
 +      assert("edward-273", coord->unit_pos == 0);
 +      assert("edward-274", znode_is_write_locked(coord->node));
-+      assert("edward-275", schedulable());
++      assert("edward-275", reiser4_schedulable());
 +      assert("edward-467", item_id_by_coord(coord) == CTAIL_ID);
 +      assert("edward-1243", ctail_ok(coord));
 +
@@ -46384,16 +46253,14 @@ Index: linux-2.6.16/fs/reiser4/plugin/item/ctail.c
 +      return cut_node_content(coord, &stop, NULL, NULL, NULL);
 +}
 +
-+int
-+ctail_insert_unprepped_cluster(reiser4_cluster_t * clust, struct inode *inode)
++int ctail_insert_unprepped_cluster(struct cluster_handle * clust,
++                                 struct inode * inode)
 +{
 +      int result;
 +      assert("edward-1244", inode != NULL);
 +      assert("edward-1245", clust->hint != NULL);
 +      assert("edward-1246", clust->dstat == FAKE_DISK_CLUSTER);
 +      assert("edward-1247", clust->reserved == 1);
-+      assert("edward-1248", get_current_context()->grabbed_blocks ==
-+             estimate_insert_cluster(inode));
 +
 +      result = get_disk_cluster_locked(clust, inode, ZNODE_WRITE_LOCK);
 +      if (cbk_errored(result))
@@ -46411,7 +46278,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/item/ctail.c
 +      all_grabbed2free();
 +
 +      assert("edward-1251", !result);
-+      assert("edward-1252", crc_inode_ok(inode));
++      assert("edward-1252", cryptcompress_inode_ok(inode));
 +      assert("edward-1253", znode_is_write_locked(clust->hint->lh.node));
 +      assert("edward-1254",
 +             reiser4_clustered_blocks(reiser4_get_current_sb()));
@@ -46421,10 +46288,10 @@ Index: linux-2.6.16/fs/reiser4/plugin/item/ctail.c
 +      return result;
 +}
 +
-+static int do_convert_ctail(flush_pos_t * pos, crc_write_mode_t mode)
++static int do_convert_ctail(flush_pos_t * pos, cryptcompress_write_mode_t mode)
 +{
 +      int result = 0;
-+      convert_item_info_t *info;
++      struct convert_item_info * info;
 +
 +      assert("edward-468", pos != NULL);
 +      assert("edward-469", pos->sq != NULL);
@@ -46439,8 +46306,10 @@ Index: linux-2.6.16/fs/reiser4/plugin/item/ctail.c
 +              assert("edward-1256",
 +                     cluster_shift_ok(cluster_shift_by_coord(&pos->coord)));
 +              result =
-+                  insert_crc_flow_in_place(&pos->coord, &pos->lock,
-+                                           &info->flow, info->inode);
++                  insert_cryptcompress_flow_in_place(&pos->coord,
++                                                     &pos->lock,
++                                                     &info->flow,
++                                                     info->inode);
 +              break;
 +      case CRC_OVERWRITE_ITEM:
 +              assert("edward-1230", info->flow.length != 0);
@@ -46473,7 +46342,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/item/ctail.c
 +      page = jnode_page(node);
 +      inode = page->mapping->host;
 +
-+      if (!scanning_left(scan))
++      if (!reiser4_scanning_left(scan))
 +              return result;
 +      if (!ZF_ISSET(scan->parent_lock.node, JNODE_DIRTY))
 +              znode_make_dirty(scan->parent_lock.node);
@@ -46520,7 +46389,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/item/ctail.c
 +
 +/* plugin->init_convert_data() */
 +static int
-+init_convert_data_ctail(convert_item_info_t * idata, struct inode *inode)
++init_convert_data_ctail(struct convert_item_info * idata, struct inode *inode)
 +{
 +      assert("edward-813", idata != NULL);
 +      assert("edward-814", inode != NULL);
@@ -46532,18 +46401,18 @@ Index: linux-2.6.16/fs/reiser4/plugin/item/ctail.c
 +      return 0;
 +}
 +
-+static int alloc_item_convert_data(convert_info_t * sq)
++static int alloc_item_convert_data(struct convert_info * sq)
 +{
 +      assert("edward-816", sq != NULL);
 +      assert("edward-817", sq->itm == NULL);
 +
-+      sq->itm = kmalloc(sizeof(*sq->itm), GFP_KERNEL);
++      sq->itm = kmalloc(sizeof(*sq->itm), reiser4_ctx_gfp_mask_get());
 +      if (sq->itm == NULL)
 +              return RETERR(-ENOMEM);
 +      return 0;
 +}
 +
-+static void free_item_convert_data(convert_info_t * sq)
++static void free_item_convert_data(struct convert_info * sq)
 +{
 +      assert("edward-818", sq != NULL);
 +      assert("edward-819", sq->itm != NULL);
@@ -46559,17 +46428,17 @@ Index: linux-2.6.16/fs/reiser4/plugin/item/ctail.c
 +      assert("edward-821", pos != NULL);
 +      assert("edward-822", pos->sq == NULL);
 +
-+      pos->sq = kmalloc(sizeof(*pos->sq), GFP_KERNEL);
++      pos->sq = kmalloc(sizeof(*pos->sq), reiser4_ctx_gfp_mask_get());
 +      if (!pos->sq)
 +              return RETERR(-ENOMEM);
 +      memset(pos->sq, 0, sizeof(*pos->sq));
-+      cluster_init_write(&pos->sq->clust, 0);
++      cluster_init_write(&pos->sq->clust, NULL);
 +      return 0;
 +}
 +
 +void free_convert_data(flush_pos_t * pos)
 +{
-+      convert_info_t *sq;
++      struct convert_info *sq;
 +
 +      assert("edward-823", pos != NULL);
 +      assert("edward-824", pos->sq != NULL);
@@ -46585,7 +46454,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/item/ctail.c
 +
 +static int init_item_convert_data(flush_pos_t * pos, struct inode *inode)
 +{
-+      convert_info_t *sq;
++      struct convert_info *sq;
 +
 +      assert("edward-825", pos != NULL);
 +      assert("edward-826", pos->sq != NULL);
@@ -46605,16 +46474,17 @@ Index: linux-2.6.16/fs/reiser4/plugin/item/ctail.c
 +static int attach_convert_idata(flush_pos_t * pos, struct inode *inode)
 +{
 +      int ret = 0;
-+      convert_item_info_t *info;
-+      reiser4_cluster_t *clust;
++      struct convert_item_info *info;
++      struct cluster_handle *clust;
 +      file_plugin *fplug = inode_file_plugin(inode);
 +      compression_plugin *cplug = inode_compression_plugin(inode);
 +
 +      assert("edward-248", pos != NULL);
 +      assert("edward-249", pos->child != NULL);
 +      assert("edward-251", inode != NULL);
-+      assert("edward-682", crc_inode_ok(inode));
-+      assert("edward-252", fplug == file_plugin_by_id(CRC_FILE_PLUGIN_ID));
++      assert("edward-682", cryptcompress_inode_ok(inode));
++      assert("edward-252",
++             fplug == file_plugin_by_id(CRYPTCOMPRESS_FILE_PLUGIN_ID));
 +      assert("edward-473",
 +             item_plugin_by_coord(&pos->coord) ==
 +             item_plugin_by_id(CTAIL_ID));
@@ -46647,14 +46517,14 @@ Index: linux-2.6.16/fs/reiser4/plugin/item/ctail.c
 +              goto err;
 +      info = item_convert_data(pos);
 +
-+      ret = flush_cluster_pages(clust, pos->child, inode);
++      ret = checkout_logical_cluster(clust, pos->child, inode);
 +      if (ret)
 +              goto err;
 +
-+      deflate_cluster(clust, inode);
++      reiser4_deflate_cluster(clust, inode);
 +      inc_item_convert_count(pos);
 +
-+      /* make flow by transformed stream */
++      /* prepare flow for insertion */
 +      fplug->flow_by_inode(info->inode,
 +                           (const char __user *)tfm_stream_data(&clust->tc, OUTPUT_STREAM),
 +                           0 /* kernel space */ ,
@@ -46663,7 +46533,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/item/ctail.c
 +                           WRITE_OP, &info->flow);
 +      jput(pos->child);
 +
-+      assert("edward-683", crc_inode_ok(inode));
++      assert("edward-683", cryptcompress_inode_ok(inode));
 +      return 0;
 +      err:
 +      jput(pos->child);
@@ -46672,9 +46542,9 @@ Index: linux-2.6.16/fs/reiser4/plugin/item/ctail.c
 +}
 +
 +/* clear up disk cluster info */
-+static void detach_convert_idata(convert_info_t * sq)
++static void detach_convert_idata(struct convert_info * sq)
 +{
-+      convert_item_info_t *info;
++      struct convert_item_info *info;
 +
 +      assert("edward-253", sq != NULL);
 +      assert("edward-840", sq->itm != NULL);
@@ -46720,18 +46590,14 @@ Index: linux-2.6.16/fs/reiser4/plugin/item/ctail.c
 +   Disk cluster is a set of items. If ->clustered() != NULL,
 +   with each item the whole disk cluster should be read/modified
 +*/
-+static int clustered_ctail(const coord_t * p1, const coord_t * p2)
-+{
-+      return mergeable_ctail(p1, p2);
-+}
 +
 +/* Go rightward and check for next disk cluster item, set
-+   d_next to DC_CHAINED_ITEM, if the last one exists.
-+   If the current position is last item, go to right neighbor.
-+   Skip empty nodes. Note, that right neighbors may be not in
-+   the slum because of races. If so, make it dirty and
-+   convertible.
-+*/
++ * d_next to DC_CHAINED_ITEM, if the last one exists.
++ * If the current position is last item, go to right neighbor.
++ * Skip empty nodes. Note, that right neighbors may be not in
++ * the slum because of races. If so, make it dirty and
++ * convertible.
++ */
 +static int next_item_dc_stat(flush_pos_t * pos)
 +{
 +      int ret = 0;
@@ -46755,7 +46621,10 @@ Index: linux-2.6.16/fs/reiser4/plugin/item/ctail.c
 +      if (pos->coord.item_pos < coord_num_items(&pos->coord) - 1)
 +              return ret;
 +
-+      /* check next slum item */
++      /* Check next slum item.
++       * Note, that it can not be killed by concurrent truncate,
++       * as the last one will want the lock held by us.
++       */
 +      init_lh(&right_lock);
 +      cur = pos->coord.node;
 +
@@ -46778,7 +46647,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/item/ctail.c
 +                      znode_make_dirty(lh.node);
 +                      znode_set_convertible(lh.node);
 +                      stop = 0;
-+              } else if (clustered_ctail(&pos->coord, &coord)) {
++              } else if (same_disk_cluster(&pos->coord, &coord)) {
 +
 +                      item_convert_data(pos)->d_next = DC_CHAINED_ITEM;
 +
@@ -46817,7 +46686,8 @@ Index: linux-2.6.16/fs/reiser4/plugin/item/ctail.c
 +}
 +
 +static int
-+assign_convert_mode(convert_item_info_t * idata, crc_write_mode_t * mode)
++assign_convert_mode(struct convert_item_info * idata,
++                  cryptcompress_write_mode_t * mode)
 +{
 +      int result = 0;
 +
@@ -46859,7 +46729,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/item/ctail.c
 +{
 +      int result;
 +      int nr_items;
-+      crc_write_mode_t mode = CRC_OVERWRITE_ITEM;
++      cryptcompress_write_mode_t mode = CRC_OVERWRITE_ITEM;
 +
 +      assert("edward-1020", pos != NULL);
 +      assert("edward-1213", coord_num_items(&pos->coord) != 0);
@@ -46900,7 +46770,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/item/ctail.c
 +      } else {
 +              /* use old convert info */
 +
-+              convert_item_info_t *idata;
++              struct convert_item_info *idata;
 +
 +              idata = item_convert_data(pos);
 +
@@ -46917,6 +46787,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/item/ctail.c
 +      assert("edward-1022",
 +             pos->coord.item_pos < coord_num_items(&pos->coord));
 +
++      /* check if next item is of current disk cluster */
 +      result = next_item_dc_stat(pos);
 +      if (result) {
 +              detach_convert_idata(pos->sq);
@@ -46972,28 +46843,36 @@ Index: linux-2.6.16/fs/reiser4/plugin/item/ctail.c
 +   fill-column: 120
 +   End:
 +*/
-Index: linux-2.6.16/fs/reiser4/plugin/item/ctail.h
-===================================================================
---- /dev/null
-+++ linux-2.6.16/fs/reiser4/plugin/item/ctail.h
-@@ -0,0 +1,89 @@
+diff -urN linux-2.6.22.orig/fs/reiser4/plugin/item/ctail.h linux-2.6.22/fs/reiser4/plugin/item/ctail.h
+--- linux-2.6.22.orig/fs/reiser4/plugin/item/ctail.h   1970-01-01 03:00:00.000000000 +0300
++++ linux-2.6.22/fs/reiser4/plugin/item/ctail.h        2007-07-29 00:25:34.948715113 +0400
+@@ -0,0 +1,102 @@
 +/* Copyright 2001, 2002, 2003 by Hans Reiser, licensing governed by reiser4/README */
 +
-+#if !defined( __FS_REISER4_CTAIL_H__ )
-+#define __FS_REISER4_CTAIL_H__
++/* Ctail items are fragments (or bodies) of special tipe to provide
++   optimal storage of encrypted and(or) compressed files. */
 +
-+/* cryptcompress object item. See ctail.c for description. */
 +
-+#define UCTAIL_NR_UNITS 1
-+#define UCTAIL_SHIFT 0xff
++#if !defined( __FS_REISER4_CTAIL_H__ )
++#define __FS_REISER4_CTAIL_H__
 +
++/* Disk format of ctail item */
 +typedef struct ctail_item_format {
-+      /* cluster shift */
++      /* packed shift;
++         if its value is different from UCTAIL_SHIFT (see below), then
++         size of disk cluster is calculated as (1 << cluster_shift) */
 +      d8 cluster_shift;
 +      /* ctail body */
 +      d8 body[0];
 +} __attribute__ ((packed)) ctail_item_format;
 +
++/* "Unprepped" disk cluster is represented by a single ctail item
++   with the following "magic" attributes: */
++/* "magic" cluster_shift */
++#define UCTAIL_SHIFT 0xff
++/* How many units unprepped ctail item has */
++#define UCTAIL_NR_UNITS 1
++
 +/* The following is a set of various item states in a disk cluster.
 +   Disk cluster is a set of items whose keys belong to the interval
 +   [dc_key , dc_key + disk_cluster_size - 1] */
@@ -47004,10 +46883,15 @@ Index: linux-2.6.16/fs/reiser4/plugin/item/ctail.h
 +      DC_AFTER_CLUSTER = 3
 +} dc_item_stat;
 +
-+typedef struct {
-+      int shift;              /* we keep here a cpu value of cluster_shift field
-+                                 of ctail_item_format (see above) */
-+} ctail_coord_extension_t;
++/* ctail-specific extension.
++   In particular this describes parameters of disk cluster an item belongs to */
++struct ctail_coord_extension {
++      int shift; /* this contains cluster_shift extracted from
++                    ctail_item_format (above), or UCTAIL_SHIFT
++                    (the last one is the "magic" of unprepped disk clusters)*/
++      int dsize; /* size of a prepped disk cluster */
++      int ncount; /* count of nodes occupied by a disk cluster */
++};
 +
 +struct cut_list;
 +
@@ -47041,7 +46925,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/item/ctail.h
 +/* plugin->u.item.s.* */
 +int read_ctail(struct file *, flow_t *, hint_t *);
 +int readpage_ctail(void *, struct page *);
-+void readpages_ctail(void *, struct address_space *, struct list_head *);
++int readpages_ctail(struct file *, struct address_space *, struct list_head *);
 +reiser4_key *append_key_ctail(const coord_t *, reiser4_key *);
 +int create_hook_ctail(const coord_t * coord, void *arg);
 +int kill_hook_ctail(const coord_t *, pos_in_node_t, pos_in_node_t,
@@ -47053,7 +46937,6 @@ Index: linux-2.6.16/fs/reiser4/plugin/item/ctail.h
 +int scan_ctail(flush_scan *);
 +int convert_ctail(flush_pos_t *);
 +size_t inode_scaled_cluster_size(struct inode *);
-+int cluster_shift_by_coord(const coord_t * coord);
 +
 +#endif                                /* __FS_REISER4_CTAIL_H__ */
 +
@@ -47066,10 +46949,9 @@ Index: linux-2.6.16/fs/reiser4/plugin/item/ctail.h
 +   fill-column: 120
 +   End:
 +*/
-Index: linux-2.6.16/fs/reiser4/plugin/item/extent.c
-===================================================================
---- /dev/null
-+++ linux-2.6.16/fs/reiser4/plugin/item/extent.c
+diff -urN linux-2.6.22.orig/fs/reiser4/plugin/item/extent.c linux-2.6.22/fs/reiser4/plugin/item/extent.c
+--- linux-2.6.22.orig/fs/reiser4/plugin/item/extent.c  1970-01-01 03:00:00.000000000 +0300
++++ linux-2.6.22/fs/reiser4/plugin/item/extent.c       2007-07-29 00:25:34.948715113 +0400
 @@ -0,0 +1,197 @@
 +/* Copyright 2001, 2002, 2003 by Hans Reiser, licensing governed by reiser4/README */
 +
@@ -47097,7 +46979,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/item/extent.c
 +}
 +
 +/* how many bytes are addressed by @nr first extents of the extent item */
-+reiser4_block_nr extent_size(const coord_t * coord, pos_in_node_t nr)
++reiser4_block_nr reiser4_extent_size(const coord_t * coord, pos_in_node_t nr)
 +{
 +      pos_in_node_t i;
 +      reiser4_block_nr blocks;
@@ -47135,16 +47017,15 @@ Index: linux-2.6.16/fs/reiser4/plugin/item/extent.c
 +}
 +
 +/* set extent's start and width */
-+void
-+set_extent(reiser4_extent * ext, reiser4_block_nr start, reiser4_block_nr width)
++void reiser4_set_extent(reiser4_extent * ext, reiser4_block_nr start,
++                      reiser4_block_nr width)
 +{
 +      extent_set_start(ext, start);
 +      extent_set_width(ext, width);
 +}
 +
-+
 +/**
-+ * replace_extent - replace extent and paste 1 or 2 after it
++ * reiser4_replace_extent - replace extent and paste 1 or 2 after it
 + * @un_extent: coordinate of extent to be overwritten
 + * @lh: need better comment
 + * @key: need better comment
@@ -47158,7 +47039,8 @@ Index: linux-2.6.16/fs/reiser4/plugin/item/extent.c
 + * first of newly inserted units, if it is 0 - @un_extent and @lh are returned
 + * set to extent which was overwritten.
 + */
-+int replace_extent(struct replace_handle *h, int return_inserted_position)
++int reiser4_replace_extent(struct replace_handle *h,
++                         int return_inserted_position)
 +{
 +      int result;
 +      znode *orig_znode;
@@ -47177,8 +47059,8 @@ Index: linux-2.6.16/fs/reiser4/plugin/item/extent.c
 +      coord_dup(&h->coord_after, h->coord);
 +      init_lh(&h->lh_after);
 +      copy_lh(&h->lh_after, h->lh);
-+      tap_init(&h->watch, &h->coord_after, &h->lh_after, ZNODE_WRITE_LOCK);
-+      tap_monitor(&h->watch);
++      reiser4_tap_init(&h->watch, &h->coord_after, &h->lh_after, ZNODE_WRITE_LOCK);
++      reiser4_tap_monitor(&h->watch);
 +
 +      ON_DEBUG(h->orig_ext = *extent_by_coord(h->coord));
 +      orig_znode = h->coord->node;
@@ -47246,7 +47128,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/item/extent.c
 +                      }
 +              }
 +      }
-+      tap_done(&h->watch);
++      reiser4_tap_done(&h->watch);
 +
 +      return result;
 +}
@@ -47268,244 +47150,10 @@ Index: linux-2.6.16/fs/reiser4/plugin/item/extent.c
 + * scroll-step: 1
 + * End:
 + */
-Index: linux-2.6.16/fs/reiser4/plugin/item/extent.h
-===================================================================
---- /dev/null
-+++ linux-2.6.16/fs/reiser4/plugin/item/extent.h
-@@ -0,0 +1,228 @@
-+/* Copyright 2001, 2002, 2003 by Hans Reiser, licensing governed by reiser4/README */
-+
-+#ifndef __REISER4_EXTENT_H__
-+#define __REISER4_EXTENT_H__
-+
-+/* on disk extent */
-+typedef struct {
-+      reiser4_dblock_nr start;
-+      reiser4_dblock_nr width;
-+} reiser4_extent;
-+
-+typedef struct extent_stat {
-+      int unallocated_units;
-+      int unallocated_blocks;
-+      int allocated_units;
-+      int allocated_blocks;
-+      int hole_units;
-+      int hole_blocks;
-+} extent_stat;
-+
-+/* extents in an extent item can be either holes, or unallocated or allocated
-+   extents */
-+typedef enum {
-+      HOLE_EXTENT,
-+      UNALLOCATED_EXTENT,
-+      ALLOCATED_EXTENT
-+} extent_state;
-+
-+#define HOLE_EXTENT_START 0
-+#define UNALLOCATED_EXTENT_START 1
-+#define UNALLOCATED_EXTENT_START2 2
-+
-+typedef struct {
-+      reiser4_block_nr pos_in_unit;
-+      reiser4_block_nr width; /* width of current unit */
-+      pos_in_node_t nr_units; /* number of units */
-+      int ext_offset;         /* offset from the beginning of zdata() */
-+      unsigned long expected_page;
-+#if REISER4_DEBUG
-+      reiser4_extent extent;
-+#endif
-+} extent_coord_extension_t;
-+
-+/* macros to set/get fields of on-disk extent */
-+static inline reiser4_block_nr extent_get_start(const reiser4_extent * ext)
-+{
-+      return le64_to_cpu(ext->start);
-+}
-+
-+static inline reiser4_block_nr extent_get_width(const reiser4_extent * ext)
-+{
-+      return le64_to_cpu(ext->width);
-+}
-+
-+extern __u64 reiser4_current_block_count(void);
-+
-+static inline void
-+extent_set_start(reiser4_extent * ext, reiser4_block_nr start)
-+{
-+      cassert(sizeof(ext->start) == 8);
-+      assert("nikita-2510",
-+             ergo(start > 1, start < reiser4_current_block_count()));
-+      put_unaligned(cpu_to_le64(start), &ext->start);
-+}
-+
-+static inline void
-+extent_set_width(reiser4_extent * ext, reiser4_block_nr width)
-+{
-+      cassert(sizeof(ext->width) == 8);
-+      assert("", width > 0);
-+      put_unaligned(cpu_to_le64(width), &ext->width);
-+      assert("nikita-2511",
-+             ergo(extent_get_start(ext) > 1,
-+                  extent_get_start(ext) + width <=
-+                  reiser4_current_block_count()));
-+}
-+
-+#define extent_item(coord)                                    \
-+({                                                            \
-+      assert("nikita-3143", item_is_extent(coord));           \
-+      ((reiser4_extent *)item_body_by_coord (coord));         \
-+})
-+
-+#define extent_by_coord(coord)                                        \
-+({                                                            \
-+      assert("nikita-3144", item_is_extent(coord));           \
-+      (extent_item (coord) + (coord)->unit_pos);              \
-+})
-+
-+#define width_by_coord(coord)                                         \
-+({                                                            \
-+      assert("nikita-3145", item_is_extent(coord));           \
-+      extent_get_width (extent_by_coord(coord));              \
-+})
-+
-+struct carry_cut_data;
-+struct carry_kill_data;
-+
-+/* plugin->u.item.b.* */
-+reiser4_key *max_key_inside_extent(const coord_t *, reiser4_key *);
-+int can_contain_key_extent(const coord_t * coord, const reiser4_key * key,
-+                         const reiser4_item_data *);
-+int mergeable_extent(const coord_t * p1, const coord_t * p2);
-+pos_in_node_t nr_units_extent(const coord_t *);
-+lookup_result lookup_extent(const reiser4_key *, lookup_bias, coord_t *);
-+void init_coord_extent(coord_t *);
-+int init_extent(coord_t *, reiser4_item_data *);
-+int paste_extent(coord_t *, reiser4_item_data *, carry_plugin_info *);
-+int can_shift_extent(unsigned free_space,
-+                   coord_t * source, znode * target, shift_direction,
-+                   unsigned *size, unsigned want);
-+void copy_units_extent(coord_t * target, coord_t * source, unsigned from,
-+                     unsigned count, shift_direction where_is_free_space,
-+                     unsigned free_space);
-+int kill_hook_extent(const coord_t *, pos_in_node_t from, pos_in_node_t count,
-+                   struct carry_kill_data *);
-+int create_hook_extent(const coord_t * coord, void *arg);
-+int cut_units_extent(coord_t * coord, pos_in_node_t from, pos_in_node_t to,
-+                   struct carry_cut_data *, reiser4_key * smallest_removed,
-+                   reiser4_key * new_first);
-+int kill_units_extent(coord_t * coord, pos_in_node_t from, pos_in_node_t to,
-+                    struct carry_kill_data *, reiser4_key * smallest_removed,
-+                    reiser4_key * new_first);
-+reiser4_key *unit_key_extent(const coord_t *, reiser4_key *);
-+reiser4_key *max_unit_key_extent(const coord_t *, reiser4_key *);
-+void print_extent(const char *, coord_t *);
-+int utmost_child_extent(const coord_t * coord, sideof side, jnode ** child);
-+int utmost_child_real_block_extent(const coord_t * coord, sideof side,
-+                                 reiser4_block_nr * block);
-+void item_stat_extent(const coord_t * coord, void *vp);
-+int check_extent(const coord_t * coord, const char **error);
-+
-+/* plugin->u.item.s.file.* */
-+ssize_t write_extent(struct file *, const char __user *, size_t, loff_t *);
-+int read_extent(struct file *, flow_t *, hint_t *);
-+int readpage_extent(void *, struct page *);
-+void readpages_extent(void *, struct address_space *, struct list_head *pages);
-+reiser4_key *append_key_extent(const coord_t *, reiser4_key *);
-+void init_coord_extension_extent(uf_coord_t *, loff_t offset);
-+int get_block_address_extent(const coord_t *, sector_t block,
-+                           sector_t * result);
-+
-+/* these are used in flush.c
-+   FIXME-VS: should they be somewhere in item_plugin? */
-+int allocate_extent_item_in_place(coord_t *, lock_handle *, flush_pos_t * pos);
-+int allocate_and_copy_extent(znode * left, coord_t * right, flush_pos_t * pos,
-+                           reiser4_key * stop_key);
-+
-+int extent_is_unallocated(const coord_t * item);      /* True if this extent is unallocated (i.e., not a hole, not allocated). */
-+__u64 extent_unit_index(const coord_t * item);        /* Block offset of this unit. */
-+__u64 extent_unit_width(const coord_t * item);        /* Number of blocks in this unit. */
-+
-+/* plugin->u.item.f. */
-+int scan_extent(flush_scan * scan);
-+extern int key_by_offset_extent(struct inode *, loff_t, reiser4_key *);
-+
-+reiser4_item_data *init_new_extent(reiser4_item_data * data, void *ext_unit,
-+                                 int nr_extents);
-+reiser4_block_nr extent_size(const coord_t * coord, pos_in_node_t nr);
-+extent_state state_of_extent(reiser4_extent * ext);
-+void set_extent(reiser4_extent *, reiser4_block_nr start,
-+              reiser4_block_nr width);
-+int update_extent(struct inode *, jnode *, loff_t pos, int *plugged_hole);
-+
-+#include "../../coord.h"
-+#include "../../lock.h"
-+#include "../../tap.h"
-+
-+struct replace_handle {
-+      /* these are to be set before calling replace_extent */
-+      coord_t *coord;
-+      lock_handle *lh;
-+      reiser4_key key;
-+      reiser4_key *pkey;
-+      reiser4_extent overwrite;
-+      reiser4_extent new_extents[2];
-+      int nr_new_extents;
-+      unsigned flags;
-+
-+      /* these are used by replace_extent */
-+      reiser4_item_data item;
-+      coord_t coord_after;
-+      lock_handle lh_after;
-+      tap_t watch;
-+      reiser4_key paste_key;
-+#if REISER4_DEBUG
-+      reiser4_extent orig_ext;
-+      reiser4_key tmp;
-+#endif
-+};
-+
-+/* this structure is kmalloced before calling make_extent to avoid excessive
-+   stack consumption on plug_hole->replace_extent */
-+struct make_extent_handle {
-+      uf_coord_t *uf_coord;
-+      reiser4_block_nr blocknr;
-+      int created;
-+      struct inode *inode;
-+      union {
-+              struct {
-+              } append;
-+              struct replace_handle replace;
-+      } u;
-+};
-+
-+int replace_extent(struct replace_handle *, int return_inserted_position);
-+lock_handle *znode_lh(znode *);
-+
-+/* the reiser4 repacker support */
-+struct repacker_cursor;
-+extern int process_extent_backward_for_repacking(tap_t *,
-+                                               struct repacker_cursor *);
-+extern int mark_extent_for_repacking(tap_t *, int);
-+
-+#define coord_by_uf_coord(uf_coord) (&((uf_coord)->coord))
-+#define ext_coord_by_uf_coord(uf_coord) (&((uf_coord)->extension.extent))
-+
-+/* __REISER4_EXTENT_H__ */
-+#endif
-+/*
-+   Local variables:
-+   c-indentation-style: "K&R"
-+   mode-name: "LC"
-+   c-basic-offset: 8
-+   tab-width: 8
-+   fill-column: 120
-+   End:
-+*/
-Index: linux-2.6.16/fs/reiser4/plugin/item/extent_file_ops.c
-===================================================================
---- /dev/null
-+++ linux-2.6.16/fs/reiser4/plugin/item/extent_file_ops.c
-@@ -0,0 +1,1712 @@
+diff -urN linux-2.6.22.orig/fs/reiser4/plugin/item/extent_file_ops.c linux-2.6.22/fs/reiser4/plugin/item/extent_file_ops.c
+--- linux-2.6.22.orig/fs/reiser4/plugin/item/extent_file_ops.c 1970-01-01 03:00:00.000000000 +0300
++++ linux-2.6.22/fs/reiser4/plugin/item/extent_file_ops.c      2007-07-29 00:25:34.952716148 +0400
+@@ -0,0 +1,1453 @@
 +/* COPYRIGHT 2001, 2002, 2003 by Hans Reiser, licensing governed by reiser4/README */
 +
 +#include "item.h"
@@ -47515,8 +47163,6 @@ Index: linux-2.6.16/fs/reiser4/plugin/item/extent_file_ops.c
 +
 +#include <linux/quotaops.h>
 +#include <linux/swap.h>
-+#include "../../../../mm/filemap.h"
-+
 +
 +static inline reiser4_extent *ext_by_offset(const znode *node, int offset)
 +{
@@ -47538,7 +47184,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/item/extent_file_ops.c
 +{
 +#if REISER4_DEBUG
 +      const coord_t *coord;
-+      const extent_coord_extension_t *ext_coord;
++      const struct extent_coord_extension *ext_coord;
 +      reiser4_extent *ext;
 +
 +      coord = &uf_coord->coord;
@@ -47559,7 +47205,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/item/extent_file_ops.c
 +                               sizeof(reiser4_extent)) == 0)));
 +      if (key) {
 +              reiser4_key coord_key;
-+              
++
 +              unit_key_by_coord(&uf_coord->coord, &coord_key);
 +              set_key_offset(&coord_key,
 +                             get_key_offset(&coord_key) +
@@ -47620,7 +47266,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/item/extent_file_ops.c
 +#endif
 +
 +/**
-+ * can_append - 
++ * can_append -
 + * @key:
 + * @coord:
 + *
@@ -47656,7 +47302,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/item/extent_file_ops.c
 +      append_key_extent(coord, &append_key);
 +
 +      assert("", keyle(&append_key, key));
-+      
++
 +      /*
 +       * extent item has to be appended with hole. Calculate length of that
 +       * hole
@@ -47676,8 +47322,8 @@ Index: linux-2.6.16/fs/reiser4/plugin/item/extent_file_ops.c
 +               * @hole_width blocks. Note that we do not worry about
 +               * overflowing - extent width is 64 bits
 +               */
-+              set_extent(ext, HOLE_EXTENT_START,
-+                         extent_get_width(ext) + hole_width);
++              reiser4_set_extent(ext, HOLE_EXTENT_START,
++                                 extent_get_width(ext) + hole_width);
 +              znode_make_dirty(coord->node);
 +              return 0;
 +      }
@@ -47686,7 +47332,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/item/extent_file_ops.c
 +      assert("vs-713", (state_of_extent(ext) == ALLOCATED_EXTENT ||
 +                        state_of_extent(ext) == UNALLOCATED_EXTENT));
 +
-+      set_extent(&new_ext, HOLE_EXTENT_START, hole_width);
++      reiser4_set_extent(&new_ext, HOLE_EXTENT_START, hole_width);
 +      init_new_extent(&idata, &new_ext, 1);
 +      return insert_into_item(coord, lh, &append_key, &idata, 0);
 +}
@@ -47694,7 +47340,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/item/extent_file_ops.c
 +/**
 + * check_jnodes
 + * @twig: longterm locked twig node
-+ * @key: 
++ * @key:
 + *
 + */
 +static void check_jnodes(znode *twig, const reiser4_key *key, int count)
@@ -47743,7 +47389,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/item/extent_file_ops.c
 +      reiser4_extent new_ext;
 +      reiser4_item_data idata;
 +      coord_t *coord;
-+      extent_coord_extension_t *ext_coord;
++      struct extent_coord_extension *ext_coord;
 +      reiser4_extent *ext;
 +      reiser4_block_nr block;
 +      jnode *node;
@@ -47780,8 +47426,8 @@ Index: linux-2.6.16/fs/reiser4/plugin/item/extent_file_ops.c
 +               * last extent unit of the file is unallocated one. Increase
 +               * its width by @count
 +               */
-+              set_extent(ext, UNALLOCATED_EXTENT_START,
-+                         extent_get_width(ext) + count);
++              reiser4_set_extent(ext, UNALLOCATED_EXTENT_START,
++                                 extent_get_width(ext) + count);
 +              znode_make_dirty(coord->node);
 +
 +              /* update coord extension */
@@ -47797,7 +47443,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/item/extent_file_ops.c
 +               * last extent unit of the file is either hole or allocated
 +               * one. Append one unallocated extent of width @count
 +               */
-+              set_extent(&new_ext, UNALLOCATED_EXTENT_START, count);
++              reiser4_set_extent(&new_ext, UNALLOCATED_EXTENT_START, count);
 +              init_new_extent(&idata, &new_ext, 1);
 +              result = insert_into_item(coord, uf_coord->lh, key, &idata, 0);
 +              uf_coord->valid = 0;
@@ -47825,10 +47471,10 @@ Index: linux-2.6.16/fs/reiser4/plugin/item/extent_file_ops.c
 +              spin_lock_jnode(node);
 +              JF_SET(node, JNODE_CREATED);
 +              jnode_set_block(node, &block);
-+              result = try_capture(node, ZNODE_WRITE_LOCK, 0);
++              result = reiser4_try_capture(node, ZNODE_WRITE_LOCK, 0);
 +              BUG_ON(result != 0);
 +              jnode_make_dirty_locked(node);
-+              spin_unlock_jnode(node);                
++              spin_unlock_jnode(node);
 +      }
 +      return count;
 +}
@@ -47854,13 +47500,13 @@ Index: linux-2.6.16/fs/reiser4/plugin/item/extent_file_ops.c
 +
 +      item_key = *key;
 +      set_key_offset(&item_key, 0ull);
-+      
++
 +      hole_width = ((get_key_offset(key) + current_blocksize - 1) >>
 +                    current_blocksize_bits);
 +      assert("vs-710", hole_width > 0);
 +
 +      /* compose body of hole extent and insert item into tree */
-+      set_extent(&new_ext, HOLE_EXTENT_START, hole_width);
++      reiser4_set_extent(&new_ext, HOLE_EXTENT_START, hole_width);
 +      init_new_extent(&idata, &new_ext, 1);
 +      return insert_extent_by_coord(coord, &idata, &item_key, lh);
 +}
@@ -47888,7 +47534,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/item/extent_file_ops.c
 +      reiser4_extent new_ext;
 +      reiser4_item_data idata;
 +      reiser4_block_nr block;
-+      unix_file_info_t *uf_info;
++      struct unix_file_info *uf_info;
 +      jnode *node;
 +
 +      /* first extent insertion starts at leaf level */
@@ -47905,9 +47551,10 @@ Index: linux-2.6.16/fs/reiser4/plugin/item/extent_file_ops.c
 +               * file or performing tail conversion
 +               */
 +              assert("", (uf_info->container == UF_CONTAINER_EMPTY ||
-+                          (inode_get_flag(inode, REISER4_PART_MIXED) &&
-+                           inode_get_flag(inode, REISER4_PART_IN_CONV))));
-+
++                          (reiser4_inode_get_flag(inode,
++                                                  REISER4_PART_MIXED) &&
++                           reiser4_inode_get_flag(inode,
++                                                  REISER4_PART_IN_CONV))));
 +              /* if file was empty - update its state */
 +              if (result == 0 && uf_info->container == UF_CONTAINER_EMPTY)
 +                      uf_info->container = UF_CONTAINER_EXTENTS;
@@ -47924,7 +47571,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/item/extent_file_ops.c
 +       * prepare for tree modification: compose body of item and item data
 +       * structure needed for insertion
 +       */
-+      set_extent(&new_ext, UNALLOCATED_EXTENT_START, count);
++      reiser4_set_extent(&new_ext, UNALLOCATED_EXTENT_START, count);
 +      init_new_extent(&idata, &new_ext, 1);
 +
 +      /* insert extent item into the tree */
@@ -47947,10 +47594,10 @@ Index: linux-2.6.16/fs/reiser4/plugin/item/extent_file_ops.c
 +              spin_lock_jnode(node);
 +              JF_SET(node, JNODE_CREATED);
 +              jnode_set_block(node, &block);
-+              result = try_capture(node, ZNODE_WRITE_LOCK, 0);
++              result = reiser4_try_capture(node, ZNODE_WRITE_LOCK, 0);
 +              BUG_ON(result != 0);
 +              jnode_make_dirty_locked(node);
-+              spin_unlock_jnode(node);                
++              spin_unlock_jnode(node);
 +      }
 +
 +      /*
@@ -47977,7 +47624,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/item/extent_file_ops.c
 +      reiser4_extent *ext;
 +      reiser4_block_nr width, pos_in_unit;
 +      coord_t *coord;
-+      extent_coord_extension_t *ext_coord;
++      struct extent_coord_extension *ext_coord;
 +      int return_inserted_position;
 +
 +      check_uf_coord(uf_coord, key);
@@ -47995,7 +47642,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/item/extent_file_ops.c
 +
 +      *how = 0;
 +      if (width == 1) {
-+              set_extent(ext, UNALLOCATED_EXTENT_START, 1);
++              reiser4_set_extent(ext, UNALLOCATED_EXTENT_START, 1);
 +              znode_make_dirty(coord->node);
 +              /* update uf_coord */
 +              ON_DEBUG(ext_coord->extent = *ext);
@@ -48028,13 +47675,14 @@ Index: linux-2.6.16/fs/reiser4/plugin/item/extent_file_ops.c
 +                      }
 +              }
 +              /* extent for replace */
-+              set_extent(&rh.overwrite, UNALLOCATED_EXTENT_START, 1);
++              reiser4_set_extent(&rh.overwrite, UNALLOCATED_EXTENT_START, 1);
 +              /* extent to be inserted */
-+              set_extent(&rh.new_extents[0], HOLE_EXTENT_START, width - 1);
++              reiser4_set_extent(&rh.new_extents[0], HOLE_EXTENT_START,
++                                 width - 1);
 +              rh.nr_new_extents = 1;
 +
-+              /* have replace_extent to return with @coord and @uf_coord->lh
-+                 set to unit which was replaced */
++              /* have reiser4_replace_extent to return with @coord and
++                 @uf_coord->lh set to unit which was replaced */
 +              return_inserted_position = 0;
 +              *how = 3;
 +      } else if (pos_in_unit == width - 1) {
@@ -48064,26 +47712,29 @@ Index: linux-2.6.16/fs/reiser4/plugin/item/extent_file_ops.c
 +                      }
 +              }
 +              /* extent for replace */
-+              set_extent(&rh.overwrite, HOLE_EXTENT_START, width - 1);
++              reiser4_set_extent(&rh.overwrite, HOLE_EXTENT_START, width - 1);
 +              /* extent to be inserted */
-+              set_extent(&rh.new_extents[0], UNALLOCATED_EXTENT_START, 1);
++              reiser4_set_extent(&rh.new_extents[0], UNALLOCATED_EXTENT_START,
++                                 1);
 +              rh.nr_new_extents = 1;
 +
-+              /* have replace_extent to return with @coord and @uf_coord->lh
-+                 set to unit which was inserted */
++              /* have reiser4_replace_extent to return with @coord and
++                 @uf_coord->lh set to unit which was inserted */
 +              return_inserted_position = 1;
 +              *how = 5;
 +      } else {
 +              /* extent for replace */
-+              set_extent(&rh.overwrite, HOLE_EXTENT_START, pos_in_unit);
++              reiser4_set_extent(&rh.overwrite, HOLE_EXTENT_START,
++                                 pos_in_unit);
 +              /* extents to be inserted */
-+              set_extent(&rh.new_extents[0], UNALLOCATED_EXTENT_START, 1);
-+              set_extent(&rh.new_extents[1], HOLE_EXTENT_START,
-+                         width - pos_in_unit - 1);
++              reiser4_set_extent(&rh.new_extents[0], UNALLOCATED_EXTENT_START,
++                                 1);
++              reiser4_set_extent(&rh.new_extents[1], HOLE_EXTENT_START,
++                                 width - pos_in_unit - 1);
 +              rh.nr_new_extents = 2;
 +
-+              /* have replace_extent to return with @coord and @uf_coord->lh
-+                 set to first of units which were inserted */
++              /* have reiser4_replace_extent to return with @coord and
++                 @uf_coord->lh set to first of units which were inserted */
 +              return_inserted_position = 1;
 +              *how = 6;
 +      }
@@ -48092,7 +47743,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/item/extent_file_ops.c
 +                     extent_get_width(&rh.overwrite) * current_blocksize);
 +
 +      uf_coord->valid = 0;
-+      return replace_extent(&rh, return_inserted_position);
++      return reiser4_replace_extent(&rh, return_inserted_position);
 +}
 +
 +/**
@@ -48109,7 +47760,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/item/extent_file_ops.c
 +                             jnode *node, int *hole_plugged)
 +{
 +      int result;
-+      extent_coord_extension_t *ext_coord;
++      struct extent_coord_extension *ext_coord;
 +      reiser4_extent *ext;
 +      reiser4_block_nr block;
 +      int how;
@@ -48155,7 +47806,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/item/extent_file_ops.c
 + */
 +static int move_coord(uf_coord_t *uf_coord)
 +{
-+      extent_coord_extension_t *ext_coord;
++      struct extent_coord_extension *ext_coord;
 +
 +      if (uf_coord->valid == 0)
 +              return 1;
@@ -48186,7 +47837,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/item/extent_file_ops.c
 +}
 +
 +/**
-+ * overwrite_extent - 
++ * overwrite_extent -
 + * @inode:
 + *
 + * Returns number of handled jnodes.
@@ -48217,7 +47868,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/item/extent_file_ops.c
 +               * them dirty
 +               */
 +              spin_lock_jnode(node);
-+              result = try_capture(node, ZNODE_WRITE_LOCK, 0);
++              result = reiser4_try_capture(node, ZNODE_WRITE_LOCK, 0);
 +              BUG_ON(result != 0);
 +              jnode_make_dirty_locked(node);
 +              spin_unlock_jnode(node);
@@ -48242,17 +47893,15 @@ Index: linux-2.6.16/fs/reiser4/plugin/item/extent_file_ops.c
 +      return count;
 +}
 +
-+void init_uf_coord(uf_coord_t *uf_coord, lock_handle *lh);
-+
 +/**
-+ * update_extent
++ * reiser4_update_extent
 + * @file:
 + * @jnodes:
 + * @count:
 + * @off:
-+ * 
++ *
 + */
-+int update_extent(struct inode *inode, jnode *node, loff_t pos,
++int reiser4_update_extent(struct inode *inode, jnode *node, loff_t pos,
 +                int *plugged_hole)
 +{
 +      int result;
@@ -48262,7 +47911,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/item/extent_file_ops.c
 +      lock_handle lh;
 +      reiser4_key key;
 +
-+      assert("", lock_counters()->d_refs == 0);
++      assert("", reiser4_lock_counters()->d_refs == 0);
 +
 +      key_by_inode_and_offset_common(inode, pos, &key);
 +
@@ -48271,10 +47920,10 @@ Index: linux-2.6.16/fs/reiser4/plugin/item/extent_file_ops.c
 +      result = find_file_item_nohint(coord, &lh, &key,
 +                                     ZNODE_WRITE_LOCK, inode);
 +      if (IS_CBKERR(result)) {
-+              assert("", lock_counters()->d_refs == 0);
++              assert("", reiser4_lock_counters()->d_refs == 0);
 +              return result;
 +      }
-+      
++
 +      result = zload(coord->node);
 +      BUG_ON(result != 0);
 +      loaded = coord->node;
@@ -48309,7 +47958,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/item/extent_file_ops.c
 +      assert("", result == 1 || result < 0);
 +      zrelse(loaded);
 +      done_lh(&lh);
-+      assert("", lock_counters()->d_refs == 0);
++      assert("", reiser4_lock_counters()->d_refs == 0);
 +      return (result == 1) ? 0 : result;
 +}
 +
@@ -48319,7 +47968,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/item/extent_file_ops.c
 + * @jnodes:
 + * @count:
 + * @off:
-+ * 
++ *
 + */
 +static int update_extents(struct file *file, jnode **jnodes, int count, loff_t pos)
 +{
@@ -48328,10 +47977,10 @@ Index: linux-2.6.16/fs/reiser4/plugin/item/extent_file_ops.c
 +      reiser4_key key;
 +      int result;
 +      znode *loaded;
-+      
++
 +      result = load_file_hint(file, &hint);
 +      BUG_ON(result != 0);
-+      
++
 +      inode = file->f_dentry->d_inode;
 +      if (count != 0)
 +              /*
@@ -48340,12 +47989,12 @@ Index: linux-2.6.16/fs/reiser4/plugin/item/extent_file_ops.c
 +              pos = (loff_t)index_jnode(jnodes[0]) << PAGE_CACHE_SHIFT;
 +      key_by_inode_and_offset_common(inode, pos, &key);
 +
-+      assert("", lock_counters()->d_refs == 0);
-+      
++      assert("", reiser4_lock_counters()->d_refs == 0);
++
 +      do {
 +              result = find_file_item(&hint, &key, ZNODE_WRITE_LOCK, inode);
 +              if (IS_CBKERR(result)) {
-+                      assert("", lock_counters()->d_refs == 0);
++                      assert("", reiser4_lock_counters()->d_refs == 0);
 +                      return result;
 +              }
 +
@@ -48397,14 +48046,14 @@ Index: linux-2.6.16/fs/reiser4/plugin/item/extent_file_ops.c
 +
 +              /* seal and unlock znode */
 +              if (hint.ext_coord.valid)
-+                      set_hint(&hint, &key, ZNODE_WRITE_LOCK);
++                      reiser4_set_hint(&hint, &key, ZNODE_WRITE_LOCK);
 +              else
-+                      unset_hint(&hint);
++                      reiser4_unset_hint(&hint);
 +
 +      } while (count > 0);
 +
 +      save_file_hint(file, &hint);
-+      assert("", lock_counters()->d_refs == 0);
++      assert("", reiser4_lock_counters()->d_refs == 0);
 +      return result;
 +}
 +
@@ -48422,8 +48071,8 @@ Index: linux-2.6.16/fs/reiser4/plugin/item/extent_file_ops.c
 +
 +      /*
 +       * to write WRITE_GRANULARITY pages to a file by extents we have to
-+       * reserve disk space for: 
-+ 
++       * reserve disk space for:
++
 +       * 1. find_file_item may have to insert empty node to the tree (empty
 +       * leaf node between two extent items). This requires 1 block and
 +       * number of blocks which are necessary to perform insertion of an
@@ -48435,7 +48084,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/item/extent_file_ops.c
 +
 +       * 3. stat data update
 +       */
-+      tree = tree_by_inode(inode);
++      tree = reiser4_tree_by_inode(inode);
 +      count = estimate_one_insert_item(tree) +
 +              WRITE_GRANULARITY * (1 + estimate_one_insert_into_item(tree)) +
 +              estimate_one_insert_item(tree);
@@ -48443,19 +48092,44 @@ Index: linux-2.6.16/fs/reiser4/plugin/item/extent_file_ops.c
 +      return reiser4_grab_space(count, 0 /* flags */);
 +}
 +
++/*
++ * filemap_copy_from_user no longer exists in generic code, because it
++ * is deadlocky (copying from user while holding the page lock is bad).
++ * As a temporary fix for reiser4, just define it here.
++ */
++static inline size_t
++filemap_copy_from_user(struct page *page, unsigned long offset,
++                      const char __user *buf, unsigned bytes)
++{
++      char *kaddr;
++      int left;
++
++      kaddr = kmap_atomic(page, KM_USER0);
++      left = __copy_from_user_inatomic_nocache(kaddr + offset, buf, bytes);
++      kunmap_atomic(kaddr, KM_USER0);
++
++      if (left != 0) {
++              /* Do it the slow way */
++              kaddr = kmap(page);
++              left = __copy_from_user_nocache(kaddr + offset, buf, bytes);
++              kunmap(page);
++      }
++      return bytes - left;
++}
++
 +/**
-+ * write_extent - write method of extent item plugin
++ * reiser4_write_extent - write method of extent item plugin
 + * @file: file to write to
 + * @buf: address of user-space buffer
-+ * @write_amount: number of bytes to write
-+ * @off: position in file to write to
++ * @count: number of bytes to write
++ * @pos: position in file to write to
 + *
 + */
-+ssize_t write_extent(struct file *file, const char __user *buf, size_t count,
-+                   loff_t *pos)
++ssize_t reiser4_write_extent(struct file *file, const char __user *buf,
++                           size_t count, loff_t *pos)
 +{
 +      int have_to_update_extent;
-+      int nr_pages;
++      int nr_pages, nr_dirty;
 +      struct page *page;
 +      jnode *jnodes[WRITE_GRANULARITY + 1];
 +      struct inode *inode;
@@ -48464,7 +48138,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/item/extent_file_ops.c
 +      int i;
 +      int to_page, page_off;
 +      size_t left, written;
-+      int result;
++      int result = 0;
 +
 +      inode = file->f_dentry->d_inode;
 +      if (write_extent_reserve_space(inode))
@@ -48478,32 +48152,31 @@ Index: linux-2.6.16/fs/reiser4/plugin/item/extent_file_ops.c
 +
 +      BUG_ON(get_current_context()->trans->atom != NULL);
 +
++      left = count;
 +      index = *pos >> PAGE_CACHE_SHIFT;
 +      /* calculate number of pages which are to be written */
 +              end = ((*pos + count - 1) >> PAGE_CACHE_SHIFT);
 +      nr_pages = end - index + 1;
++      nr_dirty = 0;
 +      assert("", nr_pages <= WRITE_GRANULARITY + 1);
 +
 +      /* get pages and jnodes */
 +      for (i = 0; i < nr_pages; i ++) {
-+              page = find_or_create_page(inode->i_mapping, index + i, get_gfp_mask());
++              page = find_or_create_page(inode->i_mapping, index + i,
++                                         reiser4_ctx_gfp_mask_get());
 +              if (page == NULL) {
-+                      while(i --) {
-+                              unlock_page(jnode_page(jnodes[i]));
-+                              page_cache_release(jnode_page(jnodes[i]));
-+                      }
-+                      return RETERR(-ENOMEM);                 
++                      nr_pages = i;
++                      result = RETERR(-ENOMEM);
++                      goto out;
 +              }
 +
 +              jnodes[i] = jnode_of_page(page);
 +              if (IS_ERR(jnodes[i])) {
 +                      unlock_page(page);
 +                      page_cache_release(page);
-+                      while (i --) {
-+                              jput(jnodes[i]);
-+                              page_cache_release(jnode_page(jnodes[i]));
-+                      }
-+                      return RETERR(-ENOMEM);                 
++                      nr_pages = i;
++                      result = RETERR(-ENOMEM);
++                      goto out;
 +              }
 +              /* prevent jnode and page from disconnecting */
 +              JF_SET(jnodes[i], JNODE_WRITE_PREPARED);
@@ -48514,14 +48187,13 @@ Index: linux-2.6.16/fs/reiser4/plugin/item/extent_file_ops.c
 +
 +      have_to_update_extent = 0;
 +
-+      left = count;
 +      page_off = (*pos & (PAGE_CACHE_SIZE - 1));
 +      for (i = 0; i < nr_pages; i ++) {
 +              to_page = PAGE_CACHE_SIZE - page_off;
 +              if (to_page > left)
 +                      to_page = left;
 +              page = jnode_page(jnodes[i]);
-+              if (((loff_t)page->index << PAGE_CACHE_SHIFT) < inode->i_size &&
++              if (page_offset(page) < inode->i_size &&
 +                  !PageUptodate(page) && to_page != PAGE_CACHE_SIZE) {
 +                      /*
 +                       * the above is not optimal for partial write to last
@@ -48535,9 +48207,9 @@ Index: linux-2.6.16/fs/reiser4/plugin/item/extent_file_ops.c
 +                              /* wait for read completion */
 +                              lock_page(page);
 +                              BUG_ON(!PageUptodate(page));
-+                              unlock_page(page);
 +                      } else
 +                              result = 0;
++                      unlock_page(page);
 +              }
 +
 +              BUG_ON(get_current_context()->trans->atom != NULL);
@@ -48545,32 +48217,24 @@ Index: linux-2.6.16/fs/reiser4/plugin/item/extent_file_ops.c
 +              BUG_ON(get_current_context()->trans->atom != NULL);
 +
 +              lock_page(page);
-+              if (!PageUptodate(page) && to_page != PAGE_CACHE_SIZE) {
-+                      void *kaddr;
-+
-+                      kaddr = kmap_atomic(page, KM_USER0);
-+                      memset(kaddr, 0, page_off);
-+                      memset(kaddr + page_off + to_page, 0,
-+                             PAGE_CACHE_SIZE - (page_off + to_page));
-+                      flush_dcache_page(page);
-+                      kunmap_atomic(kaddr, KM_USER0);
-+              }
++              if (!PageUptodate(page) && to_page != PAGE_CACHE_SIZE)
++                      simple_prepare_write(file, page, page_off,
++                                           page_off + to_page);
 +
 +              written = filemap_copy_from_user(page, page_off, buf, to_page);
-+              if (written != to_page) {
++              if (unlikely(written != to_page)) {
 +                      unlock_page(page);
-+                      page_cache_release(page);
-+                      nr_pages = i;
-+                      jput(jnodes[i]);
 +                      result = RETERR(-EFAULT);
 +                      break;
 +              }
++
 +              flush_dcache_page(page);
-+              set_page_dirty_internal(page);
++              reiser4_set_page_dirty_internal(page);
 +              unlock_page(page);
++              nr_dirty++;
++
 +              mark_page_accessed(page);
 +              SetPageUptodate(page);
-+              page_cache_release(page);
 +
 +              if (jnodes[i]->blocknr == 0)
 +                      have_to_update_extent ++;
@@ -48580,42 +48244,35 @@ Index: linux-2.6.16/fs/reiser4/plugin/item/extent_file_ops.c
 +              left -= to_page;
 +              BUG_ON(get_current_context()->trans->atom != NULL);
 +      }
-+ 
++
 +      if (have_to_update_extent) {
-+              update_extents(file, jnodes, nr_pages, *pos);
++              update_extents(file, jnodes, nr_dirty, *pos);
 +      } else {
-+              for (i = 0; i < nr_pages; i ++) {
++              for (i = 0; i < nr_dirty; i ++) {
++                      int ret;
 +                      spin_lock_jnode(jnodes[i]);
-+                      result = try_capture(jnodes[i], ZNODE_WRITE_LOCK, 0);
-+                      BUG_ON(result != 0);
++                      ret = reiser4_try_capture(jnodes[i],
++                                                   ZNODE_WRITE_LOCK, 0);
++                      BUG_ON(ret != 0);
 +                      jnode_make_dirty_locked(jnodes[i]);
 +                      spin_unlock_jnode(jnodes[i]);
 +              }
 +      }
-+
++out:
 +      for (i = 0; i < nr_pages; i ++) {
++              page_cache_release(jnode_page(jnodes[i]));
 +              JF_CLR(jnodes[i], JNODE_WRITE_PREPARED);
 +              jput(jnodes[i]);
 +      }
 +
-+      /* the only error handled so far is EFAULT on copy_from_user  */
-+      return (count - left) ? (count - left) : -EFAULT;
-+}
++      /* the only errors handled so far is ENOMEM and
++         EFAULT on copy_from_user  */
 +
-+static inline void zero_page(struct page *page)
-+{
-+      char *kaddr = kmap_atomic(page, KM_USER0);
-+
-+      memset(kaddr, 0, PAGE_CACHE_SIZE);
-+      flush_dcache_page(page);
-+      kunmap_atomic(kaddr, KM_USER0);
-+      SetPageUptodate(page);
-+      unlock_page(page);
++      return (count - left) ? (count - left) : result;
 +}
 +
-+static int
-+do_readpage_extent(reiser4_extent * ext, reiser4_block_nr pos,
-+                 struct page *page)
++int reiser4_do_readpage_extent(reiser4_extent * ext, reiser4_block_nr pos,
++                             struct page *page)
 +{
 +      jnode *j;
 +      struct address_space *mapping;
@@ -48635,7 +48292,9 @@ Index: linux-2.6.16/fs/reiser4/plugin/item/extent_file_ops.c
 +               */
 +              j = jfind(mapping, index);
 +              if (j == NULL) {
-+                      zero_page(page);
++                      zero_user_page(page, 0, PAGE_CACHE_SIZE, KM_USER0);
++                      SetPageUptodate(page);
++                      unlock_page(page);
 +                      return 0;
 +              }
 +              spin_lock_jnode(j);
@@ -48648,7 +48307,9 @@ Index: linux-2.6.16/fs/reiser4/plugin/item/extent_file_ops.c
 +              block = *jnode_get_io_block(j);
 +              spin_unlock_jnode(j);
 +              if (block == 0) {
-+                      zero_page(page);
++                      zero_user_page(page, 0, PAGE_CACHE_SIZE, KM_USER0);
++                      SetPageUptodate(page);
++                      unlock_page(page);
 +                      jput(j);
 +                      return 0;
 +              }
@@ -48684,242 +48345,13 @@ Index: linux-2.6.16/fs/reiser4/plugin/item/extent_file_ops.c
 +      }
 +
 +      BUG_ON(j == 0);
-+      page_io(page, j, READ, get_gfp_mask());
++      reiser4_page_io(page, j, READ, reiser4_ctx_gfp_mask_get());
 +      jput(j);
 +      return 0;
 +}
 +
-+static int
-+move_coord_pages(coord_t * coord, extent_coord_extension_t * ext_coord,
-+               unsigned count)
-+{
-+      reiser4_extent *ext;
-+
-+      ext_coord->expected_page += count;
-+
-+      ext = ext_by_offset(coord->node, ext_coord->ext_offset);
-+
-+      do {
-+              if (ext_coord->pos_in_unit + count < ext_coord->width) {
-+                      ext_coord->pos_in_unit += count;
-+                      break;
-+              }
-+
-+              if (coord->unit_pos == ext_coord->nr_units - 1) {
-+                      coord->between = AFTER_UNIT;
-+                      return 1;
-+              }
-+
-+              /* shift to next unit */
-+              count -= (ext_coord->width - ext_coord->pos_in_unit);
-+              coord->unit_pos++;
-+              ext_coord->pos_in_unit = 0;
-+              ext_coord->ext_offset += sizeof(reiser4_extent);
-+              ext++;
-+              ON_DEBUG(ext_coord->extent = *ext);
-+              ext_coord->width = extent_get_width(ext);
-+      } while (1);
-+
-+      return 0;
-+}
-+
-+static int readahead_readpage_extent(void *vp, struct page *page)
-+{
-+      int result;
-+      uf_coord_t *uf_coord;
-+      coord_t *coord;
-+      extent_coord_extension_t *ext_coord;
-+
-+      uf_coord = vp;
-+      coord = &uf_coord->coord;
-+
-+      if (coord->between != AT_UNIT) {
-+              unlock_page(page);
-+              return RETERR(-EINVAL);
-+      }
-+
-+      ext_coord = &uf_coord->extension.extent;
-+      if (ext_coord->expected_page != page->index) {
-+              /* read_cache_pages skipped few pages. Try to adjust coord to page */
-+              assert("vs-1269", page->index > ext_coord->expected_page);
-+              if (move_coord_pages
-+                  (coord, ext_coord,
-+                   page->index - ext_coord->expected_page)) {
-+                      /* extent pointing to this page is not here */
-+                      unlock_page(page);
-+                      return RETERR(-EINVAL);
-+              }
-+
-+              assert("vs-1274", offset_is_in_unit(coord,
-+                                                  (loff_t) page->
-+                                                  index << PAGE_CACHE_SHIFT));
-+              ext_coord->expected_page = page->index;
-+      }
-+
-+      assert("vs-1281", page->index == ext_coord->expected_page);
-+      result =
-+          do_readpage_extent(ext_by_ext_coord(uf_coord),
-+                             ext_coord->pos_in_unit, page);
-+      if (!result)
-+              move_coord_pages(coord, ext_coord, 1);
-+      return result;
-+}
-+
-+static int move_coord_forward(uf_coord_t *ext_coord)
-+{
-+      coord_t *coord;
-+      extent_coord_extension_t *extension;
-+
-+      check_uf_coord(ext_coord, NULL);
-+
-+      extension = &ext_coord->extension.extent;
-+      extension->pos_in_unit++;
-+      if (extension->pos_in_unit < extension->width)
-+              /* stay within the same extent unit */
-+              return 0;
-+
-+      coord = &ext_coord->coord;
-+
-+      /* try to move to the next extent unit */
-+      coord->unit_pos++;
-+      if (coord->unit_pos < extension->nr_units) {
-+              /* went to the next extent unit */
-+              reiser4_extent *ext;
-+
-+              extension->pos_in_unit = 0;
-+              extension->ext_offset += sizeof(reiser4_extent);
-+              ext = ext_by_offset(coord->node, extension->ext_offset);
-+              ON_DEBUG(extension->extent = *ext);
-+              extension->width = extent_get_width(ext);
-+              return 0;
-+      }
-+
-+      /* there is no units in the item anymore */
-+      return 1;
-+}
-+
-+/* this is called by read_cache_pages for each of readahead pages */
-+static int extent_readpage_filler(void *data, struct page *page)
-+{
-+      hint_t *hint;
-+      loff_t offset;
-+      reiser4_key key;
-+      uf_coord_t *ext_coord;
-+      int result;
-+
-+      offset = (loff_t) page->index << PAGE_CACHE_SHIFT;
-+      key_by_inode_and_offset_common(page->mapping->host, offset, &key);
-+
-+      hint = (hint_t *) data;
-+      ext_coord = &hint->ext_coord;
-+
-+      BUG_ON(PageUptodate(page));
-+      unlock_page(page);
-+
-+      if (hint_validate(hint, &key, 1 /* check key */ , ZNODE_READ_LOCK) != 0) {
-+              result = coord_by_key(current_tree, &key, &ext_coord->coord,
-+                                    ext_coord->lh, ZNODE_READ_LOCK,
-+                                    FIND_EXACT, TWIG_LEVEL,
-+                                    TWIG_LEVEL, CBK_UNIQUE, NULL);
-+              if (result != CBK_COORD_FOUND) {
-+                      unset_hint(hint);
-+                      return result;
-+              }
-+              ext_coord->valid = 0;
-+      }
-+
-+      if (zload(ext_coord->coord.node)) {
-+              unset_hint(hint);
-+              return RETERR(-EIO);
-+      }
-+      if (!item_is_extent(&ext_coord->coord)) {
-+              /* tail conversion is running in parallel */
-+              zrelse(ext_coord->coord.node);
-+              unset_hint(hint);
-+              return RETERR(-EIO);
-+      }
-+
-+      if (ext_coord->valid == 0)
-+              init_coord_extension_extent(ext_coord, offset);
-+
-+      check_uf_coord(ext_coord, &key);
-+
-+      lock_page(page);
-+      if (!PageUptodate(page)) {
-+              result = do_readpage_extent(ext_by_ext_coord(ext_coord),
-+                                          ext_coord->extension.extent.
-+                                          pos_in_unit, page);
-+              if (result)
-+                      unlock_page(page);
-+      } else {
-+              unlock_page(page);
-+              result = 0;
-+      }
-+      if (!result && move_coord_forward(ext_coord) == 0) {
-+              set_key_offset(&key, offset + PAGE_CACHE_SIZE);
-+              set_hint(hint, &key, ZNODE_READ_LOCK);
-+      } else
-+              unset_hint(hint);
-+      zrelse(ext_coord->coord.node);
-+      return result;
-+}
-+
-+/* this is called by reiser4_readpages */
-+static void
-+extent_readpages_hook(struct address_space *mapping, struct list_head *pages,
-+                    void *data)
-+{
-+      /* FIXME: try whether having reiser4_read_cache_pages improves anything */
-+      read_cache_pages(mapping, pages, extent_readpage_filler, data);
-+}
-+
-+static int
-+call_page_cache_readahead(struct address_space *mapping, struct file *file,
-+                        hint_t * hint,
-+                        unsigned long page_nr,
-+                        unsigned long ra_pages, struct file_ra_state *ra)
-+{
-+      reiser4_file_fsdata *fsdata;
-+      int result;
-+
-+      fsdata = reiser4_get_file_fsdata(file);
-+      if (IS_ERR(fsdata))
-+              return page_nr;
-+      fsdata->ra2.data = hint;
-+      fsdata->ra2.readpages = extent_readpages_hook;
-+
-+      result = page_cache_readahead(mapping, ra, file, page_nr, ra_pages);
-+      fsdata->ra2.readpages = NULL;
-+      return result;
-+}
-+
-+/* this is called when readahead did not */
-+static int call_readpage(struct file *file, struct page *page)
-+{
-+      int result;
-+
-+      result = readpage_unix_file_nolock(file, page);
-+      if (result)
-+              return result;
-+
-+      lock_page(page);
-+      if (!PageUptodate(page)) {
-+              unlock_page(page);
-+              page_detach_jnode(page, page->mapping, page->index);
-+              warning("jmacd-97178", "page is not up to date");
-+              return RETERR(-EIO);
-+      }
-+      unlock_page(page);
-+      return 0;
-+}
-+
-+static int filler(void *vp, struct page *page)
-+{
-+      return readpage_unix_file_nolock(vp, page);
-+}
-+
 +/* Implements plugin->u.item.s.file.read operation for extent items. */
-+int read_extent(struct file *file, flow_t *flow, hint_t *hint)
++int reiser4_read_extent(struct file *file, flow_t *flow, hint_t *hint)
 +{
 +      int result;
 +      struct page *page;
@@ -48929,9 +48361,8 @@ Index: linux-2.6.16/fs/reiser4/plugin/item/extent_file_ops.c
 +      loff_t file_off;
 +      uf_coord_t *uf_coord;
 +      coord_t *coord;
-+      extent_coord_extension_t *ext_coord;
-+      unsigned long nr_pages, prev_page;
-+      struct file_ra_state ra;
++      struct extent_coord_extension *ext_coord;
++      unsigned long nr_pages;
 +      char *kaddr;
 +
 +      assert("vs-1353", current_blocksize == PAGE_CACHE_SIZE);
@@ -48939,7 +48370,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/item/extent_file_ops.c
 +      assert("vs-1351", flow->length > 0);
 +
 +      uf_coord = &hint->ext_coord;
-+      
++
 +      check_uf_coord(uf_coord, NULL);
 +      assert("vs-33", uf_coord->lh == &hint->lh);
 +
@@ -48969,53 +48400,23 @@ Index: linux-2.6.16/fs/reiser4/plugin/item/extent_file_ops.c
 +      /* we start having twig node read locked. However, we do not want to
 +         keep that lock all the time readahead works. So, set a sel and
 +         release twig node. */
-+      set_hint(hint, &flow->key, ZNODE_READ_LOCK);
++      reiser4_set_hint(hint, &flow->key, ZNODE_READ_LOCK);
 +      /* &hint->lh is done-ed */
 +
-+      ra = file->f_ra;
-+      prev_page = ra.prev_page;
 +      do {
-+              txn_restart_current();
-+              if (next_page == cur_page)
-+                      next_page =
-+                          call_page_cache_readahead(mapping, file, hint,
-+                                                    cur_page, nr_pages, &ra);
-+
-+              page = find_get_page(mapping, cur_page);
-+              if (unlikely(page == NULL)) {
-+                      handle_ra_miss(mapping, &ra, cur_page);
-+                      page = read_cache_page(mapping, cur_page, filler, file);
-+                      if (IS_ERR(page))
-+                              return PTR_ERR(page);
-+                      lock_page(page);
-+                      if (!PageUptodate(page)) {
-+                              unlock_page(page);
-+                              page_detach_jnode(page, mapping, cur_page);
-+                              page_cache_release(page);
-+                              warning("jmacd-97178",
-+                                      "extent_read: page is not up to date");
-+                              return RETERR(-EIO);
-+                      }
++              reiser4_txn_restart_current();
++              page = read_mapping_page(mapping, cur_page, file);
++              if (IS_ERR(page))
++                      return PTR_ERR(page);
++              lock_page(page);
++              if (!PageUptodate(page)) {
 +                      unlock_page(page);
-+              } else {
-+                      if (!PageUptodate(page)) {
-+                              lock_page(page);
-+
-+                              assert("", page->mapping == mapping);
-+                              if (PageUptodate(page))
-+                                      unlock_page(page);
-+                              else {
-+                                      result = call_readpage(file, page);
-+                                      if (result) {
-+                                              page_cache_release(page);
-+                                              return RETERR(result);
-+                                      }
-+                              }
-+                      }
-+                      if (prev_page != cur_page)
-+                              mark_page_accessed(page);
-+                      prev_page = cur_page;
++                      page_cache_release(page);
++                      warning("jmacd-97178", "extent_read: page is not up to date");
++                      return RETERR(-EIO);
 +              }
++              mark_page_accessed(page);
++              unlock_page(page);
 +
 +              /* If users can be writing to this page using arbitrary virtual
 +                 addresses, take care about potential aliasing before reading
@@ -49024,7 +48425,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/item/extent_file_ops.c
 +              if (mapping_writably_mapped(mapping))
 +                      flush_dcache_page(page);
 +
-+              assert("nikita-3034", schedulable());
++              assert("nikita-3034", reiser4_schedulable());
 +
 +              /* number of bytes which are to be read from the page */
 +              if (count > flow->length)
@@ -49059,23 +48460,10 @@ Index: linux-2.6.16/fs/reiser4/plugin/item/extent_file_ops.c
 +              nr_pages--;
 +      } while (flow->length);
 +
-+      file->f_ra = ra;
 +      return 0;
 +}
 +
 +/*
-+  plugin->u.item.s.file.readpages
-+*/
-+void
-+readpages_extent(void *vp, struct address_space *mapping,
-+               struct list_head *pages)
-+{
-+      assert("vs-1739", 0);
-+      if (vp)
-+              read_cache_pages(mapping, pages, readahead_readpage_extent, vp);
-+}
-+
-+/*
 +   plugin->s.file.readpage
 +   reiser4_read->unix_file_read->page_cache_readahead->reiser4_readpage->unix_file_readpage->extent_readpage
 +   or
@@ -49084,7 +48472,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/item/extent_file_ops.c
 +   At the beginning: coord->node is read locked, zloaded, page is
 +   locked, coord is set to existing unit inside of extent item (it is not necessary that coord matches to page->index)
 +*/
-+int readpage_extent(void *vp, struct page *page)
++int reiser4_readpage_extent(void *vp, struct page *page)
 +{
 +      uf_coord_t *uf_coord = vp;
 +      ON_DEBUG(coord_t * coord = &uf_coord->coord);
@@ -49103,8 +48491,9 @@ Index: linux-2.6.16/fs/reiser4/plugin/item/extent_file_ops.c
 +             get_key_objectid(item_key_by_coord(coord, &key)));
 +      check_uf_coord(uf_coord, NULL);
 +
-+      return do_readpage_extent(ext_by_ext_coord(uf_coord),
-+                                uf_coord->extension.extent.pos_in_unit, page);
++      return reiser4_do_readpage_extent(
++              ext_by_ext_coord(uf_coord),
++              uf_coord->extension.extent.pos_in_unit, page);
 +}
 +
 +/**
@@ -49154,9 +48543,9 @@ Index: linux-2.6.16/fs/reiser4/plugin/item/extent_file_ops.c
 +{
 +      item_key_by_coord(coord, key);
 +      set_key_offset(key,
-+                     get_key_offset(key) + extent_size(coord,
-+                                                       nr_units_extent
-+                                                       (coord)));
++                     get_key_offset(key) + reiser4_extent_size(coord,
++                                                               nr_units_extent
++                                                               (coord)));
 +
 +      assert("vs-610", get_key_offset(key)
 +             && (get_key_offset(key) & (current_blocksize - 1)) == 0);
@@ -49167,7 +48556,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/item/extent_file_ops.c
 +void init_coord_extension_extent(uf_coord_t * uf_coord, loff_t lookuped)
 +{
 +      coord_t *coord;
-+      extent_coord_extension_t *ext_coord;
++      struct extent_coord_extension *ext_coord;
 +      reiser4_key key;
 +      loff_t offset;
 +
@@ -49218,11 +48607,10 @@ Index: linux-2.6.16/fs/reiser4/plugin/item/extent_file_ops.c
 + * scroll-step: 1
 + * End:
 + */
-Index: linux-2.6.16/fs/reiser4/plugin/item/extent_flush_ops.c
-===================================================================
---- /dev/null
-+++ linux-2.6.16/fs/reiser4/plugin/item/extent_flush_ops.c
-@@ -0,0 +1,1018 @@
+diff -urN linux-2.6.22.orig/fs/reiser4/plugin/item/extent_flush_ops.c linux-2.6.22/fs/reiser4/plugin/item/extent_flush_ops.c
+--- linux-2.6.22.orig/fs/reiser4/plugin/item/extent_flush_ops.c        1970-01-01 03:00:00.000000000 +0300
++++ linux-2.6.22/fs/reiser4/plugin/item/extent_flush_ops.c     2007-07-29 00:25:34.964719254 +0400
+@@ -0,0 +1,1028 @@
 +/* Copyright 2001, 2002, 2003 by Hans Reiser, licensing governed by reiser4/README */
 +
 +#include "item.h"
@@ -49349,10 +48737,10 @@ Index: linux-2.6.16/fs/reiser4/plugin/item/extent_flush_ops.c
 +   any case, the code below asserts this case for unallocated extents.  Unallocated
 +   extents are thus optimized because we can skip to the endpoint when scanning.
 +
-+   It returns control to scan_extent, handles these terminating conditions, e.g., by
-+   loading the next twig.
++   It returns control to reiser4_scan_extent, handles these terminating conditions,
++   e.g., by loading the next twig.
 +*/
-+int scan_extent(flush_scan * scan)
++int reiser4_scan_extent(flush_scan * scan)
 +{
 +      coord_t coord;
 +      jnode *neighbor;
@@ -49371,7 +48759,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/item/extent_flush_ops.c
 +
 +      coord_dup(&coord, &scan->parent_coord);
 +
-+      assert("jmacd-1404", !scan_finished(scan));
++      assert("jmacd-1404", !reiser4_scan_finished(scan));
 +      assert("jmacd-1405", jnode_get_level(scan->node) == LEAF_LEVEL);
 +      assert("jmacd-1406", jnode_is_unformatted(scan->node));
 +
@@ -49399,7 +48787,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/item/extent_flush_ops.c
 +         (scan_max) and the number of nodes that would be passed if the scan goes the
 +         entire way (scan_dist).  Incr is an integer reflecting the incremental
 +         direction of scan_index. */
-+      if (scanning_left(scan)) {
++      if (reiser4_scanning_left(scan)) {
 +              scan_max = unit_index;
 +              scan_dist = scan_index - unit_index;
 +              incr = -1;
@@ -49420,8 +48808,8 @@ Index: linux-2.6.16/fs/reiser4/plugin/item/extent_flush_ops.c
 +                              goto stop_same_parent;
 +
 +                      if (scan->node != neighbor
-+                          && !scan_goto(scan, neighbor)) {
-+                              /* @neighbor was jput() by scan_goto(). */
++                          && !reiser4_scan_goto(scan, neighbor)) {
++                              /* @neighbor was jput() by reiser4_scan_goto */
 +                              goto stop_same_parent;
 +                      }
 +
@@ -49446,7 +48834,8 @@ Index: linux-2.6.16/fs/reiser4/plugin/item/extent_flush_ops.c
 +                      goto exit;
 +              }
 +
-+              assert("zam-1043", blocknr_is_fake(jnode_get_block(neighbor)));
++              assert("zam-1043",
++                     reiser4_blocknr_is_fake(jnode_get_block(neighbor)));
 +
 +              ret = scan_set_current(scan, neighbor, scan_dist, &coord);
 +              if (ret != 0) {
@@ -49460,7 +48849,8 @@ Index: linux-2.6.16/fs/reiser4/plugin/item/extent_flush_ops.c
 +
 +              scan_index =
 +                  extent_unit_index(&coord) +
-+                  (scanning_left(scan) ? extent_unit_width(&coord) - 1 : 0);
++                  (reiser4_scanning_left(scan) ?
++                   extent_unit_width(&coord) - 1 : 0);
 +              goto repeat;
 +      }
 +
@@ -49470,7 +48860,8 @@ Index: linux-2.6.16/fs/reiser4/plugin/item/extent_flush_ops.c
 +              /* If we are scanning left and we stop in the middle of an allocated
 +                 extent, we know the preceder immediately.. */
 +              /* middle of extent is (scan_index - unit_index) != 0. */
-+              if (scanning_left(scan) && (scan_index - unit_index) != 0) {
++              if (reiser4_scanning_left(scan) &&
++                  (scan_index - unit_index) != 0) {
 +                      /* FIXME(B): Someone should step-through and verify that this preceder
 +                         calculation is indeed correct. */
 +                      /* @unit_start is starting block (number) of extent
@@ -49588,7 +48979,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/item/extent_flush_ops.c
 +      assert("vs-1410", state_of_extent(ext) == ALLOCATED_EXTENT);
 +      assert("vs-1411", extent_get_width(ext) > pos_in_unit);
 +
-+      h = kmalloc(sizeof(*h), get_gfp_mask());
++      h = kmalloc(sizeof(*h), reiser4_ctx_gfp_mask_get());
 +      if (h == NULL)
 +              return RETERR(-ENOMEM);
 +      h->coord = coord;
@@ -49598,17 +48989,19 @@ Index: linux-2.6.16/fs/reiser4/plugin/item/extent_flush_ops.c
 +      set_key_offset(h->pkey,
 +                     (get_key_offset(h->pkey) +
 +                      pos_in_unit * current_blocksize));
-+      set_extent(&h->overwrite, extent_get_start(ext), pos_in_unit);
-+      set_extent(&h->new_extents[0], extent_get_start(ext) + pos_in_unit,
-+                 extent_get_width(ext) - pos_in_unit);
++      reiser4_set_extent(&h->overwrite, extent_get_start(ext),
++                         pos_in_unit);
++      reiser4_set_extent(&h->new_extents[0],
++                         extent_get_start(ext) + pos_in_unit,
++                         extent_get_width(ext) - pos_in_unit);
 +      h->nr_new_extents = 1;
 +      h->flags = COPI_DONT_SHIFT_LEFT;
 +      h->paste_key = h->key;
 +
 +      /* reserve space for extent unit paste, @grabbed is reserved before */
 +      grabbed = reserve_replace();
-+      result = replace_extent(h, 0 /* leave @coord set to overwritten
-+                                      extent */);
++      result = reiser4_replace_extent(h, 0 /* leave @coord set to overwritten
++                                              extent */);
 +      /* restore reserved */
 +      free_replace_reserved(grabbed);
 +      kfree(h);
@@ -49705,7 +49098,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/item/extent_flush_ops.c
 +              return 0;
 +      }
 +
-+      h = kmalloc(sizeof(*h), get_gfp_mask());
++      h = kmalloc(sizeof(*h), reiser4_ctx_gfp_mask_get());
 +      if (h == NULL)
 +              return RETERR(-ENOMEM);
 +      h->coord = coord;
@@ -49717,17 +49110,19 @@ Index: linux-2.6.16/fs/reiser4/plugin/item/extent_flush_ops.c
 +      h->overwrite = *replace;
 +
 +      /* replace @ext with @replace and padding extent */
-+      set_extent(&h->new_extents[0],
-+                 (state == ALLOCATED_EXTENT) ? (start + new_width) : UNALLOCATED_EXTENT_START,
-+                 width - new_width);
++      reiser4_set_extent(&h->new_extents[0],
++                         (state == ALLOCATED_EXTENT) ?
++                         (start + new_width) :
++                         UNALLOCATED_EXTENT_START,
++                         width - new_width);
 +      h->nr_new_extents = 1;
 +      h->flags = COPI_DONT_SHIFT_LEFT;
 +      h->paste_key = h->key;
 +
 +      /* reserve space for extent unit paste, @grabbed is reserved before */
 +      grabbed = reserve_replace();
-+      result = replace_extent(h, 0 /* leave @coord set to overwritten
-+                                      extent */);
++      result = reiser4_replace_extent(h, 0 /* leave @coord set to overwritten
++                                              extent */);
 +
 +      /* restore reserved */
 +      free_replace_reserved(grabbed);
@@ -49742,7 +49137,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/item/extent_flush_ops.c
 + * @index: first jnode on the range
 + * @count: number of jnodes to assign block numbers to
 + * @first: start of allocated block range
-+ * 
++ *
 + * Assigns block numbers to each of @count jnodes. Index of first jnode is
 + * @index. Jnodes get lookuped with jlookup.
 + */
@@ -49835,7 +49230,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/item/extent_flush_ops.c
 +
 +      tree = current_tree;
 +
-+      atom = atom_locked_by_fq(pos_fq(flush_pos));
++      atom = atom_locked_by_fq(reiser4_pos_fq(flush_pos));
 +      assert("vs-1478", atom);
 +
 +      for (i = flush_pos->pos_in_unit; i < width; i++, index++) {
@@ -49879,7 +49274,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/item/extent_flush_ops.c
 +      txn_atom *atom;
 +      int nr;
 +
-+      atom = atom_locked_by_fq(pos_fq(flush_pos));
++      atom = atom_locked_by_fq(reiser4_pos_fq(flush_pos));
 +      assert("vs-1468", atom);
 +
 +      nr = 0;
@@ -49903,7 +49298,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/item/extent_flush_ops.c
 +                       * any formatted nodes.
 +                       */
 +                      atomic_dec(&node->x_count);
-+                      break;                  
++                      break;
 +              }
 +
 +              assert("vs-1476", atomic_read(&node->x_count) > 1);
@@ -49926,7 +49321,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/item/extent_flush_ops.c
 + * within the extent. Slum gets to relocate set if flush_pos->leaf_relocate is
 + * set to 1 and to overwrite set otherwise
 + */
-+int alloc_extent(flush_pos_t *flush_pos)
++int reiser4_alloc_extent(flush_pos_t *flush_pos)
 +{
 +      coord_t *coord;
 +      reiser4_extent *ext;
@@ -50003,11 +49398,13 @@ Index: linux-2.6.16/fs/reiser4/plugin/item/extent_flush_ops.c
 +               */
 +              if (coord->unit_pos &&
 +                  (state_of_extent(ext - 1) == ALLOCATED_EXTENT))
-+                      pos_hint(flush_pos)->blk = extent_get_start(ext - 1) +
++                      reiser4_pos_hint(flush_pos)->blk =
++                              extent_get_start(ext - 1) +
 +                              extent_get_width(ext - 1);
 +
 +              /* allocate new block numbers for protected nodes */
-+              extent_allocate_blocks(pos_hint(flush_pos), protected,
++              extent_allocate_blocks(reiser4_pos_hint(flush_pos),
++                                     protected,
 +                                     &first_allocated, &allocated,
 +                                     block_stage);
 +
@@ -50022,9 +49419,8 @@ Index: linux-2.6.16/fs/reiser4/plugin/item/extent_flush_ops.c
 +              /* assign new block numbers to protected nodes */
 +              assign_real_blocknrs(flush_pos, oid, index, allocated, first_allocated);
 +
-+
 +              /* prepare extent which will replace current one */
-+              set_extent(&replace_ext, first_allocated, allocated);
++              reiser4_set_extent(&replace_ext, first_allocated, allocated);
 +
 +              /* adjust extent item */
 +              result = conv_extent(coord, &replace_ext);
@@ -50162,16 +49558,18 @@ Index: linux-2.6.16/fs/reiser4/plugin/item/extent_flush_ops.c
 +               */
 +              if (coord->unit_pos &&
 +                  (state_of_extent(ext - 1) == ALLOCATED_EXTENT))
-+                      pos_hint(flush_pos)->blk = extent_get_start(ext - 1) +
++                      reiser4_pos_hint(flush_pos)->blk =
++                              extent_get_start(ext - 1) +
 +                              extent_get_width(ext - 1);
 +
 +              /* allocate new block numbers for protected nodes */
-+              extent_allocate_blocks(pos_hint(flush_pos), protected,
++              extent_allocate_blocks(reiser4_pos_hint(flush_pos),
++                                     protected,
 +                                     &first_allocated, &allocated,
 +                                     block_stage);
 +
 +              /* prepare extent which will be copied to left */
-+              set_extent(&copy_extent, first_allocated, allocated);
++              reiser4_set_extent(&copy_extent, first_allocated, allocated);
 +
 +              result = put_unit_to_end(left, &key, &copy_extent);
 +              if (result == -E_NODE_FULL) {
@@ -50211,7 +49609,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/item/extent_flush_ops.c
 +               * overwrite: try to copy unit as it is to left neighbor and
 +               * make all first not flushprepped nodes overwrite nodes
 +               */
-+              set_extent(&copy_extent, start, width);
++              reiser4_set_extent(&copy_extent, start, width);
 +              result = put_unit_to_end(left, &key, &copy_extent);
 +              if (result == -E_NODE_FULL)
 +                      return SQUEEZE_TARGET_FULL;
@@ -50241,11 +49639,245 @@ Index: linux-2.6.16/fs/reiser4/plugin/item/extent_flush_ops.c
 + * scroll-step: 1
 + * End:
 + */
-Index: linux-2.6.16/fs/reiser4/plugin/item/extent_item_ops.c
-===================================================================
---- /dev/null
-+++ linux-2.6.16/fs/reiser4/plugin/item/extent_item_ops.c
-@@ -0,0 +1,882 @@
+diff -urN linux-2.6.22.orig/fs/reiser4/plugin/item/extent.h linux-2.6.22/fs/reiser4/plugin/item/extent.h
+--- linux-2.6.22.orig/fs/reiser4/plugin/item/extent.h  1970-01-01 03:00:00.000000000 +0300
++++ linux-2.6.22/fs/reiser4/plugin/item/extent.h       2007-07-29 00:25:34.968720289 +0400
+@@ -0,0 +1,231 @@
++/* Copyright 2001, 2002, 2003 by Hans Reiser, licensing governed by reiser4/README */
++
++#ifndef __REISER4_EXTENT_H__
++#define __REISER4_EXTENT_H__
++
++/* on disk extent */
++typedef struct {
++      reiser4_dblock_nr start;
++      reiser4_dblock_nr width;
++} reiser4_extent;
++
++struct extent_stat {
++      int unallocated_units;
++      int unallocated_blocks;
++      int allocated_units;
++      int allocated_blocks;
++      int hole_units;
++      int hole_blocks;
++};
++
++/* extents in an extent item can be either holes, or unallocated or allocated
++   extents */
++typedef enum {
++      HOLE_EXTENT,
++      UNALLOCATED_EXTENT,
++      ALLOCATED_EXTENT
++} extent_state;
++
++#define HOLE_EXTENT_START 0
++#define UNALLOCATED_EXTENT_START 1
++#define UNALLOCATED_EXTENT_START2 2
++
++struct extent_coord_extension {
++      reiser4_block_nr pos_in_unit;
++      reiser4_block_nr width; /* width of current unit */
++      pos_in_node_t nr_units; /* number of units */
++      int ext_offset;         /* offset from the beginning of zdata() */
++      unsigned long expected_page;
++#if REISER4_DEBUG
++      reiser4_extent extent;
++#endif
++};
++
++/* macros to set/get fields of on-disk extent */
++static inline reiser4_block_nr extent_get_start(const reiser4_extent * ext)
++{
++      return le64_to_cpu(ext->start);
++}
++
++static inline reiser4_block_nr extent_get_width(const reiser4_extent * ext)
++{
++      return le64_to_cpu(ext->width);
++}
++
++extern __u64 reiser4_current_block_count(void);
++
++static inline void
++extent_set_start(reiser4_extent * ext, reiser4_block_nr start)
++{
++      cassert(sizeof(ext->start) == 8);
++      assert("nikita-2510",
++             ergo(start > 1, start < reiser4_current_block_count()));
++      put_unaligned(cpu_to_le64(start), &ext->start);
++}
++
++static inline void
++extent_set_width(reiser4_extent * ext, reiser4_block_nr width)
++{
++      cassert(sizeof(ext->width) == 8);
++      assert("", width > 0);
++      put_unaligned(cpu_to_le64(width), &ext->width);
++      assert("nikita-2511",
++             ergo(extent_get_start(ext) > 1,
++                  extent_get_start(ext) + width <=
++                  reiser4_current_block_count()));
++}
++
++#define extent_item(coord)                                    \
++({                                                            \
++      assert("nikita-3143", item_is_extent(coord));           \
++      ((reiser4_extent *)item_body_by_coord (coord));         \
++})
++
++#define extent_by_coord(coord)                                        \
++({                                                            \
++      assert("nikita-3144", item_is_extent(coord));           \
++      (extent_item (coord) + (coord)->unit_pos);              \
++})
++
++#define width_by_coord(coord)                                         \
++({                                                            \
++      assert("nikita-3145", item_is_extent(coord));           \
++      extent_get_width (extent_by_coord(coord));              \
++})
++
++struct carry_cut_data;
++struct carry_kill_data;
++
++/* plugin->u.item.b.* */
++reiser4_key *max_key_inside_extent(const coord_t *, reiser4_key *);
++int can_contain_key_extent(const coord_t * coord, const reiser4_key * key,
++                         const reiser4_item_data *);
++int mergeable_extent(const coord_t * p1, const coord_t * p2);
++pos_in_node_t nr_units_extent(const coord_t *);
++lookup_result lookup_extent(const reiser4_key *, lookup_bias, coord_t *);
++void init_coord_extent(coord_t *);
++int init_extent(coord_t *, reiser4_item_data *);
++int paste_extent(coord_t *, reiser4_item_data *, carry_plugin_info *);
++int can_shift_extent(unsigned free_space,
++                   coord_t * source, znode * target, shift_direction,
++                   unsigned *size, unsigned want);
++void copy_units_extent(coord_t * target, coord_t * source, unsigned from,
++                     unsigned count, shift_direction where_is_free_space,
++                     unsigned free_space);
++int kill_hook_extent(const coord_t *, pos_in_node_t from, pos_in_node_t count,
++                   struct carry_kill_data *);
++int create_hook_extent(const coord_t * coord, void *arg);
++int cut_units_extent(coord_t * coord, pos_in_node_t from, pos_in_node_t to,
++                   struct carry_cut_data *, reiser4_key * smallest_removed,
++                   reiser4_key * new_first);
++int kill_units_extent(coord_t * coord, pos_in_node_t from, pos_in_node_t to,
++                    struct carry_kill_data *, reiser4_key * smallest_removed,
++                    reiser4_key * new_first);
++reiser4_key *unit_key_extent(const coord_t *, reiser4_key *);
++reiser4_key *max_unit_key_extent(const coord_t *, reiser4_key *);
++void print_extent(const char *, coord_t *);
++int utmost_child_extent(const coord_t * coord, sideof side, jnode ** child);
++int utmost_child_real_block_extent(const coord_t * coord, sideof side,
++                                 reiser4_block_nr * block);
++void item_stat_extent(const coord_t * coord, void *vp);
++int reiser4_check_extent(const coord_t * coord, const char **error);
++
++/* plugin->u.item.s.file.* */
++ssize_t reiser4_write_extent(struct file *, const char __user *,
++                           size_t, loff_t *);
++int reiser4_read_extent(struct file *, flow_t *, hint_t *);
++int reiser4_readpage_extent(void *, struct page *);
++int reiser4_do_readpage_extent(reiser4_extent*, reiser4_block_nr, struct page*);
++reiser4_key *append_key_extent(const coord_t *, reiser4_key *);
++void init_coord_extension_extent(uf_coord_t *, loff_t offset);
++int get_block_address_extent(const coord_t *, sector_t block,
++                           sector_t * result);
++
++/* these are used in flush.c
++   FIXME-VS: should they be somewhere in item_plugin? */
++int allocate_extent_item_in_place(coord_t *, lock_handle *, flush_pos_t * pos);
++int allocate_and_copy_extent(znode * left, coord_t * right, flush_pos_t * pos,
++                           reiser4_key * stop_key);
++
++int extent_is_unallocated(const coord_t * item);      /* True if this extent is unallocated (i.e., not a hole, not allocated). */
++__u64 extent_unit_index(const coord_t * item);        /* Block offset of this unit. */
++__u64 extent_unit_width(const coord_t * item);        /* Number of blocks in this unit. */
++
++/* plugin->u.item.f. */
++int reiser4_scan_extent(flush_scan * scan);
++extern int key_by_offset_extent(struct inode *, loff_t, reiser4_key *);
++
++reiser4_item_data *init_new_extent(reiser4_item_data * data, void *ext_unit,
++                                 int nr_extents);
++reiser4_block_nr reiser4_extent_size(const coord_t * coord, pos_in_node_t nr);
++extent_state state_of_extent(reiser4_extent * ext);
++void reiser4_set_extent(reiser4_extent *, reiser4_block_nr start,
++                      reiser4_block_nr width);
++int reiser4_update_extent(struct inode *, jnode *, loff_t pos,
++                        int *plugged_hole);
++
++#include "../../coord.h"
++#include "../../lock.h"
++#include "../../tap.h"
++
++struct replace_handle {
++      /* these are to be set before calling reiser4_replace_extent */
++      coord_t *coord;
++      lock_handle *lh;
++      reiser4_key key;
++      reiser4_key *pkey;
++      reiser4_extent overwrite;
++      reiser4_extent new_extents[2];
++      int nr_new_extents;
++      unsigned flags;
++
++      /* these are used by reiser4_replace_extent */
++      reiser4_item_data item;
++      coord_t coord_after;
++      lock_handle lh_after;
++      tap_t watch;
++      reiser4_key paste_key;
++#if REISER4_DEBUG
++      reiser4_extent orig_ext;
++      reiser4_key tmp;
++#endif
++};
++
++/* this structure is kmalloced before calling make_extent to avoid excessive
++   stack consumption on plug_hole->reiser4_replace_extent */
++struct make_extent_handle {
++      uf_coord_t *uf_coord;
++      reiser4_block_nr blocknr;
++      int created;
++      struct inode *inode;
++      union {
++              struct {
++              } append;
++              struct replace_handle replace;
++      } u;
++};
++
++int reiser4_replace_extent(struct replace_handle *,
++                         int return_inserted_position);
++lock_handle *znode_lh(znode *);
++
++/* the reiser4 repacker support */
++struct repacker_cursor;
++extern int process_extent_backward_for_repacking(tap_t *,
++                                               struct repacker_cursor *);
++extern int mark_extent_for_repacking(tap_t *, int);
++
++#define coord_by_uf_coord(uf_coord) (&((uf_coord)->coord))
++#define ext_coord_by_uf_coord(uf_coord) (&((uf_coord)->extension.extent))
++
++/* __REISER4_EXTENT_H__ */
++#endif
++/*
++   Local variables:
++   c-indentation-style: "K&R"
++   mode-name: "LC"
++   c-basic-offset: 8
++   tab-width: 8
++   fill-column: 120
++   End:
++*/
+diff -urN linux-2.6.22.orig/fs/reiser4/plugin/item/extent_item_ops.c linux-2.6.22/fs/reiser4/plugin/item/extent_item_ops.c
+--- linux-2.6.22.orig/fs/reiser4/plugin/item/extent_item_ops.c 1970-01-01 03:00:00.000000000 +0300
++++ linux-2.6.22/fs/reiser4/plugin/item/extent_item_ops.c      2007-07-29 00:25:34.968720289 +0400
+@@ -0,0 +1,889 @@
 +/* Copyright 2001, 2002, 2003 by Hans Reiser, licensing governed by reiser4/README */
 +
 +#include "item.h"
@@ -50260,7 +49892,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/item/extent_item_ops.c
 +reiser4_key *max_key_inside_extent(const coord_t * coord, reiser4_key * key)
 +{
 +      item_key_by_coord(coord, key);
-+      set_key_offset(key, get_key_offset(max_key()));
++      set_key_offset(key, get_key_offset(reiser4_max_key()));
 +      return key;
 +}
 +
@@ -50304,7 +49936,8 @@ Index: linux-2.6.16/fs/reiser4/plugin/item/extent_item_ops.c
 +          get_key_ordering(&key1) != get_key_ordering(&key2) ||
 +          get_key_type(&key1) != get_key_type(&key2))
 +              return 0;
-+      if (get_key_offset(&key1) + extent_size(p1, nr_units_extent(p1)) !=
++      if (get_key_offset(&key1) +
++          reiser4_extent_size(p1, nr_units_extent(p1)) !=
 +          get_key_offset(&key2))
 +              return 0;
 +      return 1;
@@ -50695,7 +50328,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/item/extent_item_ops.c
 +      ext = extent_item(coord) + from;
 +      offset =
 +          (get_key_offset(min_item_key) +
-+           extent_size(coord, from)) >> PAGE_CACHE_SHIFT;
++           reiser4_extent_size(coord, from)) >> PAGE_CACHE_SHIFT;
 +
 +      assert("vs-1551", from_off >= offset);
 +      assert("vs-1552", from_off - offset <= extent_get_width(ext));
@@ -50819,10 +50452,12 @@ Index: linux-2.6.16/fs/reiser4/plugin/item/extent_item_ops.c
 +      if (result == ITEM_TAIL_KILLED) {
 +              assert("vs-1553",
 +                     get_key_offset(pfrom_key) >=
-+                     get_key_offset(&item_key) + extent_size(coord, from));
++                     get_key_offset(&item_key) +
++                     reiser4_extent_size(coord, from));
 +              off =
-+                  get_key_offset(pfrom_key) - (get_key_offset(&item_key) +
-+                                               extent_size(coord, from));
++                  get_key_offset(pfrom_key) -
++                      (get_key_offset(&item_key) +
++                       reiser4_extent_size(coord, from));
 +              if (off) {
 +                      /* unit @from is to be cut partially. Its width decreases */
 +                      ext = extent_item(coord) + from;
@@ -50842,9 +50477,11 @@ Index: linux-2.6.16/fs/reiser4/plugin/item/extent_item_ops.c
 +                                                       1)) == 0);
 +              assert("",
 +                     get_key_offset(pto_key) + 1 >
-+                     get_key_offset(&item_key) + extent_size(coord, to));
++                     get_key_offset(&item_key) +
++                     reiser4_extent_size(coord, to));
 +              max_to_offset =
-+                  get_key_offset(&item_key) + extent_size(coord, to + 1) - 1;
++                  get_key_offset(&item_key) +
++                      reiser4_extent_size(coord, to + 1) - 1;
 +              assert("", get_key_offset(pto_key) <= max_to_offset);
 +
 +              rest =
@@ -50957,10 +50594,10 @@ Index: linux-2.6.16/fs/reiser4/plugin/item/extent_item_ops.c
 +
 +      assert("vs-1553",
 +             get_key_offset(pfrom_key) >=
-+             get_key_offset(&item_key) + extent_size(coord, from));
++             get_key_offset(&item_key) + reiser4_extent_size(coord, from));
 +      off =
 +          get_key_offset(pfrom_key) - (get_key_offset(&item_key) +
-+                                       extent_size(coord, from));
++                                       reiser4_extent_size(coord, from));
 +      if (off) {
 +              /* tail of unit @from is to be cut partially. Its width decreases */
 +              assert("vs-1582", new_first == NULL);
@@ -50971,10 +50608,12 @@ Index: linux-2.6.16/fs/reiser4/plugin/item/extent_item_ops.c
 +
 +      assert("vs-1554",
 +             get_key_offset(pto_key) <=
-+             get_key_offset(&item_key) + extent_size(coord, to + 1) - 1);
++             get_key_offset(&item_key) +
++             reiser4_extent_size(coord, to + 1) - 1);
 +      off =
-+          (get_key_offset(&item_key) + extent_size(coord, to + 1) - 1) -
-+          get_key_offset(pto_key);
++              (get_key_offset(&item_key) +
++               reiser4_extent_size(coord, to + 1) - 1) -
++              get_key_offset(pto_key);
 +      if (off) {
 +              /* @to_key is smaller than max key of unit @to. Unit @to will not be removed. It gets start increased
 +                 and width decreased. */
@@ -51000,7 +50639,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/item/extent_item_ops.c
 +      item_key_by_coord(coord, key);
 +      set_key_offset(key,
 +                     (get_key_offset(key) +
-+                      extent_size(coord, coord->unit_pos)));
++                      reiser4_extent_size(coord, coord->unit_pos)));
 +
 +      return key;
 +}
@@ -51013,7 +50652,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/item/extent_item_ops.c
 +      item_key_by_coord(coord, key);
 +      set_key_offset(key,
 +                     (get_key_offset(key) +
-+                      extent_size(coord, coord->unit_pos + 1) - 1));
++                      reiser4_extent_size(coord, coord->unit_pos + 1) - 1));
 +      return key;
 +}
 +
@@ -51027,8 +50666,8 @@ Index: linux-2.6.16/fs/reiser4/plugin/item/extent_item_ops.c
 +   possible check of the consistency of the item that the inventor can
 +   construct
 +*/
-+int check_extent(const coord_t * coord /* coord of item to check */ ,
-+               const char **error /* where to store error message */ )
++int reiser4_check_extent(const coord_t * coord /* coord of item to check */,
++                       const char **error /* where to store error message */)
 +{
 +      reiser4_extent *ext, *first;
 +      unsigned i, j;
@@ -51128,11 +50767,10 @@ Index: linux-2.6.16/fs/reiser4/plugin/item/extent_item_ops.c
 +   scroll-step: 1
 +   End:
 +*/
-Index: linux-2.6.16/fs/reiser4/plugin/item/internal.c
-===================================================================
---- /dev/null
-+++ linux-2.6.16/fs/reiser4/plugin/item/internal.c
-@@ -0,0 +1,392 @@
+diff -urN linux-2.6.22.orig/fs/reiser4/plugin/item/internal.c linux-2.6.22/fs/reiser4/plugin/item/internal.c
+--- linux-2.6.22.orig/fs/reiser4/plugin/item/internal.c        1970-01-01 03:00:00.000000000 +0300
++++ linux-2.6.22/fs/reiser4/plugin/item/internal.c     2007-07-29 00:25:34.968720289 +0400
+@@ -0,0 +1,396 @@
 +/* Copyright 2001, 2002, 2003 by Hans Reiser, licensing governed by reiser4/README */
 +
 +/* Implementation of internal-item plugin methods. */
@@ -51197,7 +50835,8 @@ Index: linux-2.6.16/fs/reiser4/plugin/item/internal.c
 +      return (internal_item_layout *) item_body_by_coord(coord);
 +}
 +
-+void update_internal(const coord_t * coord, const reiser4_block_nr * blocknr)
++void reiser4_update_internal(const coord_t * coord,
++                           const reiser4_block_nr * blocknr)
 +{
 +      internal_item_layout *item = internal_at(coord);
 +      assert("nikita-2959", reiser4_blocknr_is_sane(blocknr));
@@ -51249,7 +50888,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/item/internal.c
 +      *block = pointer_at(coord);
 +      assert("nikita-2961", reiser4_blocknr_is_sane(block));
 +
-+      if (blocknr_is_fake(block)) {
++      if (reiser4_blocknr_is_fake(block)) {
 +              *block = 0;
 +      }
 +
@@ -51278,6 +50917,8 @@ Index: linux-2.6.16/fs/reiser4/plugin/item/internal.c
 +      return 0;
 +}
 +
++#if REISER4_DEBUG
++
 +static void check_link(znode * left, znode * right)
 +{
 +      znode *scan;
@@ -51343,6 +50984,8 @@ Index: linux-2.6.16/fs/reiser4/plugin/item/internal.c
 +      return 0;
 +}
 +
++#endif  /*  REISER4_DEBUG  */
++
 +/* return true only if this item really points to "block" */
 +/* Audited by: green(2002.06.14) */
 +int has_pointer_to_internal(const coord_t * coord /* coord of item */ ,
@@ -51381,7 +51024,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/item/internal.c
 +       * item to little endian byte order.
 +       */
 +      child_ptr = get_unaligned((__u64 *)item_body_by_coord(item));
-+      update_internal(item, &child_ptr);
++      reiser4_update_internal(item, &child_ptr);
 +
 +      child = znode_at(item, item->node);
 +      if (child != NULL && !IS_ERR(child)) {
@@ -51431,7 +51074,6 @@ Index: linux-2.6.16/fs/reiser4/plugin/item/internal.c
 +    . when last reference to this node will be dropped, bitmap will be updated
 +    and node will be actually removed from the memory.
 +
-+
 +*/
 +int kill_hook_internal(const coord_t * item /* coord of item */ ,
 +                     pos_in_node_t from UNUSED_ARG /* start unit */ ,
@@ -51525,10 +51167,9 @@ Index: linux-2.6.16/fs/reiser4/plugin/item/internal.c
 +   fill-column: 120
 +   End:
 +*/
-Index: linux-2.6.16/fs/reiser4/plugin/item/internal.h
-===================================================================
---- /dev/null
-+++ linux-2.6.16/fs/reiser4/plugin/item/internal.h
+diff -urN linux-2.6.22.orig/fs/reiser4/plugin/item/internal.h linux-2.6.22/fs/reiser4/plugin/item/internal.h
+--- linux-2.6.22.orig/fs/reiser4/plugin/item/internal.h        1970-01-01 03:00:00.000000000 +0300
++++ linux-2.6.22/fs/reiser4/plugin/item/internal.h     2007-07-29 00:25:34.968720289 +0400
 @@ -0,0 +1,57 @@
 +/* Copyright 2001, 2002, 2003 by Hans Reiser, licensing governed by reiser4/README */
 +/* Internal item contains down-link to the child of the internal/twig
@@ -51563,15 +51204,15 @@ Index: linux-2.6.16/fs/reiser4/plugin/item/internal.h
 +                            pos_in_node_t count, struct carry_kill_data *);
 +extern int shift_hook_internal(const coord_t * item, unsigned from,
 +                             unsigned count, znode * old_node);
-+extern void print_internal(const char *prefix, coord_t * coord);
++extern void reiser4_print_internal(const char *prefix, coord_t * coord);
 +
 +extern int utmost_child_internal(const coord_t * coord, sideof side,
 +                               jnode ** child);
 +int utmost_child_real_block_internal(const coord_t * coord, sideof side,
 +                                   reiser4_block_nr * block);
 +
-+extern void update_internal(const coord_t * coord,
-+                          const reiser4_block_nr * blocknr);
++extern void reiser4_update_internal(const coord_t * coord,
++                                  const reiser4_block_nr * blocknr);
 +/* FIXME: reiserfs has check_internal */
 +extern int check__internal(const coord_t * coord, const char **error);
 +
@@ -51587,11 +51228,10 @@ Index: linux-2.6.16/fs/reiser4/plugin/item/internal.h
 +   fill-column: 120
 +   End:
 +*/
-Index: linux-2.6.16/fs/reiser4/plugin/item/item.c
-===================================================================
---- /dev/null
-+++ linux-2.6.16/fs/reiser4/plugin/item/item.c
-@@ -0,0 +1,727 @@
+diff -urN linux-2.6.22.orig/fs/reiser4/plugin/item/item.c linux-2.6.22/fs/reiser4/plugin/item/item.c
+--- linux-2.6.22.orig/fs/reiser4/plugin/item/item.c    1970-01-01 03:00:00.000000000 +0300
++++ linux-2.6.22/fs/reiser4/plugin/item/item.c 2007-07-29 00:25:34.972721325 +0400
+@@ -0,0 +1,719 @@
 +/* Copyright 2001, 2002, 2003 by Hans Reiser, licensing governed by reiser4/README */
 +
 +/* definition of item plugins. */
@@ -51669,17 +51309,6 @@ Index: linux-2.6.16/fs/reiser4/plugin/item/item.c
 +             node_plugin_by_node(coord->node)->plugin_by_coord(coord));
 +}
 +
-+/* return type of item at @coord */
-+item_type_id item_type_by_coord(const coord_t * coord /* coord to query */ )
-+{
-+      assert("nikita-333", coord != NULL);
-+      assert("nikita-334", coord->node != NULL);
-+      assert("nikita-335", znode_is_loaded(coord->node));
-+      assert("nikita-336", item_plugin_by_coord(coord) != NULL);
-+
-+      return item_plugin_by_coord(coord)->b.item_type;
-+}
-+
 +/* return id of item */
 +/* Audited by: green(2002.06.15) */
 +item_id item_id_by_coord(const coord_t * coord /* coord to query */ )
@@ -51768,7 +51397,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/item/item.c
 +}
 +
 +/* ->nr_units() method for items consisting of exactly one unit always */
-+static pos_in_node_t
++pos_in_node_t
 +nr_units_single_unit(const coord_t * coord UNUSED_ARG /* coord of item */ )
 +{
 +      return 1;
@@ -51876,10 +51505,12 @@ Index: linux-2.6.16/fs/reiser4/plugin/item/item.c
 +      return item_id_by_coord(item) == FORMATTING_ID;
 +}
 +
++#if REISER4_DEBUG
++
 +int item_is_statdata(const coord_t * item)
 +{
 +      assert("vs-516", coord_is_existing_item(item));
-+      return item_type_by_coord(item) == STAT_DATA_ITEM_TYPE;
++      return plugin_of_group(item_plugin_by_coord(item), STAT_DATA_ITEM_TYPE);
 +}
 +
 +int item_is_ctail(const coord_t * item)
@@ -51888,7 +51519,11 @@ Index: linux-2.6.16/fs/reiser4/plugin/item/item.c
 +      return item_id_by_coord(item) == CTAIL_ID;
 +}
 +
-+static int change_item(struct inode *inode, reiser4_plugin * plugin)
++#endif  /*  REISER4_DEBUG  */
++
++static int change_item(struct inode *inode,
++                     reiser4_plugin * plugin,
++                     pset_member memb)
 +{
 +      /* cannot change constituent item (sd, or dir_item) */
 +      return RETERR(-EINVAL);
@@ -51907,13 +51542,13 @@ Index: linux-2.6.16/fs/reiser4/plugin/item/item.c
 +              .h = {
 +                      .type_id = REISER4_ITEM_PLUGIN_TYPE,
 +                      .id = STATIC_STAT_DATA_ID,
++                      .groups = (1 << STAT_DATA_ITEM_TYPE),
 +                      .pops = &item_plugin_ops,
 +                      .label = "sd",
 +                      .desc = "stat-data",
 +                      .linkage = {NULL, NULL}
 +              },
 +              .b = {
-+                      .item_type = STAT_DATA_ITEM_TYPE,
 +                      .max_key_inside = max_key_inside_single_key,
 +                      .can_contain_key = NULL,
 +                      .mergeable = not_mergeable,
@@ -51956,13 +51591,13 @@ Index: linux-2.6.16/fs/reiser4/plugin/item/item.c
 +              .h = {
 +                      .type_id = REISER4_ITEM_PLUGIN_TYPE,
 +                      .id = SIMPLE_DIR_ENTRY_ID,
++                      .groups = (1 << DIR_ENTRY_ITEM_TYPE),
 +                      .pops = &item_plugin_ops,
 +                      .label = "de",
 +                      .desc = "directory entry",
 +                      .linkage = {NULL, NULL}
 +              },
 +              .b = {
-+                      .item_type = DIR_ENTRY_ITEM_TYPE,
 +                      .max_key_inside = max_key_inside_single_key,
 +                      .can_contain_key = NULL,
 +                      .mergeable = NULL,
@@ -52009,13 +51644,13 @@ Index: linux-2.6.16/fs/reiser4/plugin/item/item.c
 +              .h = {
 +                      .type_id = REISER4_ITEM_PLUGIN_TYPE,
 +                      .id = COMPOUND_DIR_ID,
++                      .groups = (1 << DIR_ENTRY_ITEM_TYPE),
 +                      .pops = &item_plugin_ops,
 +                      .label = "cde",
 +                      .desc = "compressed directory entry",
 +                      .linkage = {NULL, NULL}
 +              },
 +              .b = {
-+                      .item_type = DIR_ENTRY_ITEM_TYPE,
 +                      .max_key_inside = max_key_inside_cde,
 +                      .can_contain_key = can_contain_key_cde,
 +                      .mergeable = mergeable_cde,
@@ -52036,7 +51671,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/item/item.c
 +                      .estimate = estimate_cde,
 +                      .item_data_by_flow = NULL,
 +#if REISER4_DEBUG
-+                      .check = check_cde
++                      .check = reiser4_check_cde
 +#endif
 +              },
 +              .f = {
@@ -52062,13 +51697,13 @@ Index: linux-2.6.16/fs/reiser4/plugin/item/item.c
 +              .h = {
 +                      .type_id = REISER4_ITEM_PLUGIN_TYPE,
 +                      .id = NODE_POINTER_ID,
++                      .groups = (1 << INTERNAL_ITEM_TYPE),
 +                      .pops = NULL,
 +                      .label = "internal",
 +                      .desc = "internal item",
 +                      .linkage = {NULL, NULL}
 +              },
 +              .b = {
-+                      .item_type = INTERNAL_ITEM_TYPE,
 +                      .max_key_inside = NULL,
 +                      .can_contain_key = NULL,
 +                      .mergeable = mergeable_internal,
@@ -52096,7 +51731,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/item/item.c
 +                      .utmost_child = utmost_child_internal,
 +                      .utmost_child_real_block =
 +                      utmost_child_real_block_internal,
-+                      .update = update_internal,
++                      .update = reiser4_update_internal,
 +                      .scan = NULL,
 +                      .convert = NULL
 +              },
@@ -52111,13 +51746,13 @@ Index: linux-2.6.16/fs/reiser4/plugin/item/item.c
 +              .h = {
 +                      .type_id = REISER4_ITEM_PLUGIN_TYPE,
 +                      .id = EXTENT_POINTER_ID,
++                      .groups = (1 << UNIX_FILE_METADATA_ITEM_TYPE),
 +                      .pops = NULL,
 +                      .label = "extent",
 +                      .desc = "extent item",
 +                      .linkage = {NULL, NULL}
 +              },
 +              .b = {
-+                      .item_type = UNIX_FILE_METADATA_ITEM_TYPE,
 +                      .max_key_inside = max_key_inside_extent,
 +                      .can_contain_key = can_contain_key_extent,
 +                      .mergeable = mergeable_extent,
@@ -52138,7 +51773,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/item/item.c
 +                      .estimate = NULL,
 +                      .item_data_by_flow = NULL,
 +#if REISER4_DEBUG
-+                      .check = check_extent
++                      .check = reiser4_check_extent
 +#endif
 +              },
 +              .f = {
@@ -52146,17 +51781,16 @@ Index: linux-2.6.16/fs/reiser4/plugin/item/item.c
 +                      .utmost_child_real_block =
 +                      utmost_child_real_block_extent,
 +                      .update = NULL,
-+                      .scan = scan_extent,
++                      .scan = reiser4_scan_extent,
 +                      .convert = NULL,
 +                      .key_by_offset = key_by_offset_extent
 +              },
 +              .s = {
 +                      .file = {
-+                              .write = write_extent,
-+                              .read = read_extent,
-+                              .readpage = readpage_extent,
++                              .write = reiser4_write_extent,
++                              .read = reiser4_read_extent,
++                              .readpage = reiser4_readpage_extent,
 +                              .get_block = get_block_address_extent,
-+                              .readpages = readpages_extent,
 +                              .append_key = append_key_extent,
 +                              .init_coord_extension =
 +                              init_coord_extension_extent
@@ -52167,13 +51801,13 @@ Index: linux-2.6.16/fs/reiser4/plugin/item/item.c
 +              .h = {
 +                      .type_id = REISER4_ITEM_PLUGIN_TYPE,
 +                      .id = FORMATTING_ID,
++                      .groups = (1 << UNIX_FILE_METADATA_ITEM_TYPE),
 +                      .pops = NULL,
 +                      .label = "body",
 +                      .desc = "body (or tail?) item",
 +                      .linkage = {NULL, NULL}
 +              },
 +              .b = {
-+                      .item_type = UNIX_FILE_METADATA_ITEM_TYPE,
 +                      .max_key_inside = max_key_inside_tail,
 +                      .can_contain_key = can_contain_key_tail,
 +                      .mergeable = mergeable_tail,
@@ -52206,11 +51840,10 @@ Index: linux-2.6.16/fs/reiser4/plugin/item/item.c
 +              },
 +              .s = {
 +                      .file = {
-+                              .write = write_tail,
-+                              .read = read_tail,
++                              .write = reiser4_write_tail,
++                              .read = reiser4_read_tail,
 +                              .readpage = readpage_tail,
-+                              .get_block = NULL,
-+                              .readpages = NULL,
++                              .get_block = get_block_address_tail,
 +                              .append_key = append_key_tail,
 +                              .init_coord_extension =
 +                              init_coord_extension_tail
@@ -52221,13 +51854,13 @@ Index: linux-2.6.16/fs/reiser4/plugin/item/item.c
 +              .h = {
 +                      .type_id = REISER4_ITEM_PLUGIN_TYPE,
 +                      .id = CTAIL_ID,
++                      .groups = (1 << UNIX_FILE_METADATA_ITEM_TYPE),
 +                      .pops = NULL,
 +                      .label = "ctail",
 +                      .desc = "cryptcompress tail item",
 +                      .linkage = {NULL, NULL}
 +              },
 +              .b = {
-+                      .item_type = UNIX_FILE_METADATA_ITEM_TYPE,
 +                      .max_key_inside = max_key_inside_tail,
 +                      .can_contain_key = can_contain_key_ctail,
 +                      .mergeable = mergeable_ctail,
@@ -52265,7 +51898,6 @@ Index: linux-2.6.16/fs/reiser4/plugin/item/item.c
 +                              .read = read_ctail,
 +                              .readpage = readpage_ctail,
 +                              .get_block = get_block_address_tail,
-+                              .readpages = readpages_ctail,
 +                              .append_key = append_key_ctail,
 +                              .init_coord_extension =
 +                              init_coord_extension_tail
@@ -52276,13 +51908,13 @@ Index: linux-2.6.16/fs/reiser4/plugin/item/item.c
 +              .h = {
 +                      .type_id = REISER4_ITEM_PLUGIN_TYPE,
 +                      .id = BLACK_BOX_ID,
++                      .groups = (1 << OTHER_ITEM_TYPE),
 +                      .pops = NULL,
 +                      .label = "blackbox",
 +                      .desc = "black box item",
 +                      .linkage = {NULL, NULL}
 +              },
 +              .b = {
-+                      .item_type = OTHER_ITEM_TYPE,
 +                      .max_key_inside = NULL,
 +                      .can_contain_key = NULL,
 +                      .mergeable = not_mergeable,
@@ -52319,11 +51951,10 @@ Index: linux-2.6.16/fs/reiser4/plugin/item/item.c
 +   fill-column: 120
 +   End:
 +*/
-Index: linux-2.6.16/fs/reiser4/plugin/item/item.h
-===================================================================
---- /dev/null
-+++ linux-2.6.16/fs/reiser4/plugin/item/item.h
-@@ -0,0 +1,399 @@
+diff -urN linux-2.6.22.orig/fs/reiser4/plugin/item/item.h linux-2.6.22/fs/reiser4/plugin/item/item.h
+--- linux-2.6.22.orig/fs/reiser4/plugin/item/item.h    1970-01-01 03:00:00.000000000 +0300
++++ linux-2.6.22/fs/reiser4/plugin/item/item.h 2007-07-29 00:25:34.972721325 +0400
+@@ -0,0 +1,397 @@
 +/* Copyright 2001, 2002, 2003 by Hans Reiser, licensing governed by reiser4/README */
 +
 +/* first read balance.c comments before reading this */
@@ -52360,9 +51991,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/item/item.h
 +/* this is the part of each item plugin that all items are expected to
 +   support or at least explicitly fail to support by setting the
 +   pointer to null. */
-+typedef struct {
-+      item_type_id item_type;
-+
++struct balance_ops {
 +      /* operations called by balancing
 +
 +         It is interesting to consider that some of these item
@@ -52382,7 +52011,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/item/item.h
 +         For items that occupy exactly one key (like stat-data)
 +         this method should return this key. For items that can
 +         grow indefinitely (extent, directory item) this should
-+         return max_key().
++         return reiser4_max_key().
 +
 +         For example extent with the key
 +
@@ -52402,8 +52031,12 @@ Index: linux-2.6.16/fs/reiser4/plugin/item/item.h
 +       */
 +      int (*mergeable) (const coord_t *, const coord_t *);
 +
-+      /* number of atomic things in an item */
-+       pos_in_node_t(*nr_units) (const coord_t *);
++      /* number of atomic things in an item.
++         NOTE FOR CONTRIBUTORS: use a generic method
++         nr_units_single_unit() for solid (atomic) items, as
++         tree operations use it as a criterion of solidness
++         (see is_solid_item macro) */
++      pos_in_node_t(*nr_units) (const coord_t *);
 +
 +      /* search within item for a unit within the item, and return a
 +         pointer to it.  This can be used to calculate how many
@@ -52417,8 +52050,8 @@ Index: linux-2.6.16/fs/reiser4/plugin/item/item.h
 +         item */
 +      int (*init) (coord_t * target, coord_t * from,
 +                   reiser4_item_data * data);
-+      /* method called (e.g., by resize_item()) to place new data into
-+         item when it grows */
++      /* method called (e.g., by reiser4_resize_item()) to place new data
++         into item when it grows */
 +      int (*paste) (coord_t *, reiser4_item_data *, carry_plugin_info *);
 +      /* return true if paste into @coord is allowed to skip
 +         carry. That is, if such paste would require any changes
@@ -52513,9 +52146,9 @@ Index: linux-2.6.16/fs/reiser4/plugin/item/item.h
 +      int (*check) (const coord_t *, const char **error);
 +#endif
 +
-+} balance_ops;
++};
 +
-+typedef struct {
++struct flush_ops {
 +      /* return the right or left child of @coord, only if it is in memory */
 +      int (*utmost_child) (const coord_t *, sideof side, jnode ** child);
 +
@@ -52531,10 +52164,10 @@ Index: linux-2.6.16/fs/reiser4/plugin/item/item.h
 +      int (*convert) (flush_pos_t * pos);
 +      /* backward mapping from jnode offset to a key.  */
 +      int (*key_by_offset) (struct inode *, loff_t, reiser4_key *);
-+} flush_ops;
++};
 +
 +/* operations specific to the directory item */
-+typedef struct {
++struct dir_entry_iops {
 +      /* extract stat-data key from directory entry at @coord and place it
 +         into @key. */
 +      int (*extract_key) (const coord_t *, reiser4_key * key);
@@ -52553,16 +52186,14 @@ Index: linux-2.6.16/fs/reiser4/plugin/item/item.h
 +                        coord_t *, lock_handle *,
 +                        reiser4_dir_entry_desc * entry);
 +      int (*max_name_len) (const struct inode * dir);
-+} dir_entry_ops;
++};
 +
 +/* operations specific to items regular (unix) file metadata are built of */
-+typedef struct {
++struct file_iops{
 +      int (*write) (struct file *, const char __user *, size_t, loff_t *pos);
 +      int (*read) (struct file *, flow_t *, hint_t *);
 +      int (*readpage) (void *, struct page *);
 +      int (*get_block) (const coord_t *, sector_t, sector_t *);
-+      void (*readpages) (void *, struct address_space *,
-+                         struct list_head * pages);
 +      /*
 +       * key of first byte which is not addressed by the item @coord is set
 +       * to.
@@ -52577,17 +52208,17 @@ Index: linux-2.6.16/fs/reiser4/plugin/item/item.h
 +      reiser4_key *(*append_key) (const coord_t *, reiser4_key *);
 +
 +      void (*init_coord_extension) (uf_coord_t *, loff_t);
-+} file_ops;
++};
 +
 +/* operations specific to items of stat data type */
-+typedef struct {
++struct sd_iops {
 +      int (*init_inode) (struct inode * inode, char *sd, int len);
 +      int (*save_len) (struct inode * inode);
 +      int (*save) (struct inode * inode, char **area);
-+} sd_ops;
++};
 +
 +/* operations specific to internal item */
-+typedef struct {
++struct internal_iops{
 +      /* all tree traversal want to know from internal item is where
 +         to go next. */
 +      void (*down_link) (const coord_t * coord,
@@ -52595,27 +52226,26 @@ Index: linux-2.6.16/fs/reiser4/plugin/item/item.h
 +      /* check that given internal item contains given pointer. */
 +      int (*has_pointer_to) (const coord_t * coord,
 +                             const reiser4_block_nr * block);
-+} internal_item_ops;
++};
 +
 +struct item_plugin {
 +      /* generic fields */
 +      plugin_header h;
-+
 +      /* methods common for all item types */
-+      balance_ops b;
-+      /* methods used during flush */
-+      flush_ops f;
++      struct balance_ops b; /* balance operations */
++      struct flush_ops f;   /* flush operates with items via this methods */
 +
 +      /* methods specific to particular type of item */
 +      union {
-+              dir_entry_ops dir;
-+              file_ops file;
-+              sd_ops sd;
-+              internal_item_ops internal;
++              struct dir_entry_iops dir;
++              struct      file_iops file;
++              struct        sd_iops sd;
++              struct  internal_iops internal;
 +      } s;
-+
 +};
 +
++#define is_solid_item(iplug) ((iplug)->b.nr_units == nr_units_single_unit)
++
 +static inline item_id item_id_by_plugin(item_plugin * plugin)
 +{
 +      return plugin->h.id;
@@ -52656,14 +52286,13 @@ Index: linux-2.6.16/fs/reiser4/plugin/item/item.h
 +extern int item_is_ctail(const coord_t *);
 +
 +extern pos_in_node_t item_length_by_coord(const coord_t * coord);
-+extern item_type_id item_type_by_coord(const coord_t * coord);
++extern pos_in_node_t nr_units_single_unit(const coord_t * coord);
 +extern item_id item_id_by_coord(const coord_t * coord /* coord to query */ );
 +extern reiser4_key *item_key_by_coord(const coord_t * coord, reiser4_key * key);
 +extern reiser4_key *max_item_key_by_coord(const coord_t *, reiser4_key *);
 +extern reiser4_key *unit_key_by_coord(const coord_t * coord, reiser4_key * key);
 +extern reiser4_key *max_unit_key_by_coord(const coord_t * coord,
 +                                        reiser4_key * key);
-+
 +extern void obtain_item_plugin(const coord_t * coord);
 +
 +#if defined(REISER4_DEBUG)
@@ -52687,7 +52316,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/item/item.h
 +static inline int item_is_internal(const coord_t * item)
 +{
 +      assert("vs-483", coord_is_existing_item(item));
-+      return item_type_by_coord(item) == INTERNAL_ITEM_TYPE;
++      return plugin_of_group(item_plugin_by_coord(item), INTERNAL_ITEM_TYPE);
 +}
 +
 +extern void item_body_by_coord_hard(coord_t * coord);
@@ -52723,10 +52352,31 @@ Index: linux-2.6.16/fs/reiser4/plugin/item/item.h
 +   scroll-step: 1
 +   End:
 +*/
-Index: linux-2.6.16/fs/reiser4/plugin/item/sde.c
-===================================================================
---- /dev/null
-+++ linux-2.6.16/fs/reiser4/plugin/item/sde.c
+diff -urN linux-2.6.22.orig/fs/reiser4/plugin/item/Makefile linux-2.6.22/fs/reiser4/plugin/item/Makefile
+--- linux-2.6.22.orig/fs/reiser4/plugin/item/Makefile  1970-01-01 03:00:00.000000000 +0300
++++ linux-2.6.22/fs/reiser4/plugin/item/Makefile       2007-07-29 00:25:34.972721325 +0400
+@@ -0,0 +1,18 @@
++obj-$(CONFIG_REISER4_FS) += item_plugins.o
++
++item_plugins-objs :=          \
++      item.o                  \
++      static_stat.o           \
++      sde.o                   \
++      cde.o                   \
++      blackbox.o              \
++      internal.o              \
++      tail.o                  \
++      ctail.o                 \
++      extent.o                \
++      extent_item_ops.o       \
++      extent_file_ops.o       \
++      extent_flush_ops.o
++
++
++
+diff -urN linux-2.6.22.orig/fs/reiser4/plugin/item/sde.c linux-2.6.22/fs/reiser4/plugin/item/sde.c
+--- linux-2.6.22.orig/fs/reiser4/plugin/item/sde.c     1970-01-01 03:00:00.000000000 +0300
++++ linux-2.6.22/fs/reiser4/plugin/item/sde.c  2007-07-29 00:25:34.972721325 +0400
 @@ -0,0 +1,190 @@
 +/* Copyright 2001, 2002, 2003 by Hans Reiser, licensing governed by reiser4/README */
 +
@@ -52905,8 +52555,8 @@ Index: linux-2.6.16/fs/reiser4/plugin/item/sde.c
 +
 +int max_name_len_de(const struct inode *dir)
 +{
-+      return tree_by_inode(dir)->nplug->max_item_size() -
-+          sizeof(directory_entry_format) - 2;
++      return reiser4_tree_by_inode(dir)->nplug->max_item_size() -
++              sizeof(directory_entry_format) - 2;
 +}
 +
 +/* Make Linus happy.
@@ -52918,10 +52568,9 @@ Index: linux-2.6.16/fs/reiser4/plugin/item/sde.c
 +   fill-column: 120
 +   End:
 +*/
-Index: linux-2.6.16/fs/reiser4/plugin/item/sde.h
-===================================================================
---- /dev/null
-+++ linux-2.6.16/fs/reiser4/plugin/item/sde.h
+diff -urN linux-2.6.22.orig/fs/reiser4/plugin/item/sde.h linux-2.6.22/fs/reiser4/plugin/item/sde.h
+--- linux-2.6.22.orig/fs/reiser4/plugin/item/sde.h     1970-01-01 03:00:00.000000000 +0300
++++ linux-2.6.22/fs/reiser4/plugin/item/sde.h  2007-07-29 00:25:34.976722360 +0400
 @@ -0,0 +1,66 @@
 +/* Copyright 2001, 2002, 2003 by Hans Reiser, licensing governed by reiser4/README */
 +
@@ -52989,11 +52638,10 @@ Index: linux-2.6.16/fs/reiser4/plugin/item/sde.h
 +   fill-column: 120
 +   End:
 +*/
-Index: linux-2.6.16/fs/reiser4/plugin/item/static_stat.c
-===================================================================
---- /dev/null
-+++ linux-2.6.16/fs/reiser4/plugin/item/static_stat.c
-@@ -0,0 +1,1040 @@
+diff -urN linux-2.6.22.orig/fs/reiser4/plugin/item/static_stat.c linux-2.6.22/fs/reiser4/plugin/item/static_stat.c
+--- linux-2.6.22.orig/fs/reiser4/plugin/item/static_stat.c     1970-01-01 03:00:00.000000000 +0300
++++ linux-2.6.22/fs/reiser4/plugin/item/static_stat.c  2007-07-29 00:25:34.976722360 +0400
+@@ -0,0 +1,1107 @@
 +/* Copyright 2001, 2002, 2003 by Hans Reiser, licensing governed by reiser4/README */
 +
 +/* stat data manipulation. */
@@ -53081,7 +52729,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/item/static_stat.c
 +      state = reiser4_inode_data(inode);
 +      mask = le16_to_cpu(get_unaligned(&sd_base->extmask));
 +      bigmask = mask;
-+      inode_set_flag(inode, REISER4_SDLEN_KNOWN);
++      reiser4_inode_set_flag(inode, REISER4_SDLEN_KNOWN);
 +
 +      move_on(&len, &sd, sizeof *sd_base);
 +      for (bit = 0, chunk = 0;
@@ -53165,7 +52813,6 @@ Index: linux-2.6.16/fs/reiser4/plugin/item/static_stat.c
 +      }
 +      state->extmask = bigmask;
 +      /* common initialisations */
-+      inode->i_blksize = get_super_private(inode->i_sb)->optimal_io_size;
 +      if (len - (bit / 16 * sizeof(d16)) > 0) {
 +              /* alignment in save_len_static_sd() is taken into account
 +                 -edward */
@@ -53271,7 +52918,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/item/static_stat.c
 +              if ((inode->i_mode & S_IFMT) == (S_IFREG | S_IFIFO)) {
 +                      inode->i_mode &= ~S_IFIFO;
 +                      warning("", "partially converted file is encountered");
-+                      inode_set_flag(inode, REISER4_PART_MIXED);
++                      reiser4_inode_set_flag(inode, REISER4_PART_MIXED);
 +              }
 +              move_on(len, area, sizeof *sd_lw);
 +              return 0;
@@ -53297,7 +52944,8 @@ Index: linux-2.6.16/fs/reiser4/plugin/item/static_stat.c
 +
 +      sd = (reiser4_light_weight_stat *) * area;
 +
-+      delta = (inode_get_flag(inode, REISER4_PART_MIXED) ? S_IFIFO : 0);
++      delta = (reiser4_inode_get_flag(inode,
++                                      REISER4_PART_MIXED) ? S_IFIFO : 0);
 +      put_unaligned(cpu_to_le16(inode->i_mode | delta), &sd->mode);
 +      put_unaligned(cpu_to_le32(inode->i_nlink), &sd->nlink);
 +      put_unaligned(cpu_to_le64((__u64) inode->i_size), &sd->size);
@@ -53341,9 +52989,9 @@ Index: linux-2.6.16/fs/reiser4/plugin/item/static_stat.c
 +      inode->i_gid = get_super_private(inode->i_sb)->default_gid;
 +      inode->i_atime = inode->i_mtime = inode->i_ctime = CURRENT_TIME;
 +      inode_set_bytes(inode, inode->i_size);
-+      /* mark inode as lightweight, so that caller (reiser4_lookup) will
++      /* mark inode as lightweight, so that caller (lookup_common) will
 +         complete initialisation by copying [ug]id from a parent. */
-+      inode_set_flag(inode, REISER4_LIGHT_WEIGHT);
++      reiser4_inode_set_flag(inode, REISER4_LIGHT_WEIGHT);
 +      return 0;
 +}
 +
@@ -53426,22 +53074,23 @@ Index: linux-2.6.16/fs/reiser4/plugin/item/static_stat.c
 +
 +/* symlink stat data extension */
 +
-+/* allocate memory for symlink target and attach it to inode->u.generic_ip */
++/* allocate memory for symlink target and attach it to inode->i_private */
 +static int
 +symlink_target_to_inode(struct inode *inode, const char *target, int len)
 +{
-+      assert("vs-845", inode->u.generic_ip == NULL);
-+      assert("vs-846", !inode_get_flag(inode, REISER4_GENERIC_PTR_USED));
-+
++      assert("vs-845", inode->i_private == NULL);
++      assert("vs-846", !reiser4_inode_get_flag(inode,
++                                               REISER4_GENERIC_PTR_USED));
 +      /* FIXME-VS: this is prone to deadlock. Not more than other similar
 +         places, though */
-+      inode->u.generic_ip = kmalloc((size_t) len + 1, get_gfp_mask());
-+      if (!inode->u.generic_ip)
++      inode->i_private = kmalloc((size_t) len + 1,
++                                 reiser4_ctx_gfp_mask_get());
++      if (!inode->i_private)
 +              return RETERR(-ENOMEM);
 +
-+      memcpy((char *)(inode->u.generic_ip), target, (size_t) len);
-+      ((char *)(inode->u.generic_ip))[len] = 0;
-+      inode_set_flag(inode, REISER4_GENERIC_PTR_USED);
++      memcpy((char *)(inode->i_private), target, (size_t) len);
++      ((char *)(inode->i_private))[len] = 0;
++      reiser4_inode_set_flag(inode, REISER4_GENERIC_PTR_USED);
 +      return 0;
 +}
 +
@@ -53492,11 +53141,11 @@ Index: linux-2.6.16/fs/reiser4/plugin/item/static_stat.c
 +
 +      result = 0;
 +      sd = (reiser4_symlink_stat *) * area;
-+      if (!inode_get_flag(inode, REISER4_GENERIC_PTR_USED)) {
++      if (!reiser4_inode_get_flag(inode, REISER4_GENERIC_PTR_USED)) {
 +              const char *target;
 +
-+              target = (const char *)(inode->u.generic_ip);
-+              inode->u.generic_ip = NULL;
++              target = (const char *)(inode->i_private);
++              inode->i_private = NULL;
 +
 +              result = symlink_target_to_inode(inode, target, length);
 +
@@ -53506,7 +53155,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/item/static_stat.c
 +      } else {
 +              /* there is nothing to do in update but move area */
 +              assert("vs-844",
-+                     !memcmp(inode->u.generic_ip, sd->body,
++                     !memcmp(inode->i_private, sd->body,
 +                             (size_t) length + 1));
 +      }
 +
@@ -53560,10 +53209,12 @@ Index: linux-2.6.16/fs/reiser4/plugin/item/static_stat.c
 +static int absent_plugin_sd(struct inode *inode);
 +static int present_plugin_sd(struct inode *inode /* object being processed */ ,
 +                           char **area /* position in stat-data */ ,
-+                           int *len /* remaining length */ )
++                           int *len /* remaining length */,
++                           int is_pset /* 1 if plugin set, 0 if heir set. */)
 +{
 +      reiser4_plugin_stat *sd;
 +      reiser4_plugin *plugin;
++      reiser4_inode *info;
 +      int i;
 +      __u16 mask;
 +      int result;
@@ -53579,6 +53230,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/item/static_stat.c
 +              return not_enough_space(inode, "plugin");
 +
 +      sd = (reiser4_plugin_stat *) * area;
++      info = reiser4_inode_data(inode);
 +
 +      mask = 0;
 +      num_of_plugins = le16_to_cpu(get_unaligned(&sd->plugins_no));
@@ -53594,14 +53246,16 @@ Index: linux-2.6.16/fs/reiser4/plugin/item/static_stat.c
 +                      return not_enough_space(inode, "additional plugin");
 +
 +              memb = le16_to_cpu(get_unaligned(&slot->pset_memb));
-+              type = pset_member_to_type_unsafe(memb);
++              type = aset_member_to_type_unsafe(memb);
++
 +              if (type == REISER4_PLUGIN_TYPES) {
 +                      warning("nikita-3502",
-+                              "wrong pset member (%i) for %llu", memb,
++                              "wrong %s member (%i) for %llu", is_pset ?
++                              "pset" : "hset", memb,
 +                              (unsigned long long)get_inode_oid(inode));
 +                      return RETERR(-EINVAL);
 +              }
-+              plugin = plugin_by_disk_id(tree_by_inode(inode),
++              plugin = plugin_by_disk_id(reiser4_tree_by_inode(inode),
 +                                         type, &slot->id);
 +              if (plugin == NULL)
 +                      return unknown_plugin(le16_to_cpu(get_unaligned(&slot->id)), inode);
@@ -53617,23 +53271,31 @@ Index: linux-2.6.16/fs/reiser4/plugin/item/static_stat.c
 +              }
 +              move_on(len, area, sizeof *slot);
 +              /* load plugin data, if any */
-+              if (plugin->h.pops != NULL && plugin->h.pops->load) {
++              if (plugin->h.pops != NULL && plugin->h.pops->load)
 +                      result = plugin->h.pops->load(inode, plugin, area, len);
-+                      if (result != 0)
-+                              return result;
-+              } else
-+                      result = grab_plugin_from(inode, memb, plugin);
++              else
++                      result = aset_set_unsafe(is_pset ? &info->pset :
++                                               &info->hset, memb, plugin);
++              if (result)
++                      return result;
 +      }
-+      /* if object plugin wasn't loaded from stat-data, guess it by
-+         mode bits */
-+      plugin = file_plugin_to_plugin(inode_file_plugin(inode));
-+      if (plugin == NULL)
-+              result = absent_plugin_sd(inode);
++      if (is_pset) {
++              /* if object plugin wasn't loaded from stat-data, guess it by
++                 mode bits */
++              plugin = file_plugin_to_plugin(inode_file_plugin(inode));
++              if (plugin == NULL)
++                      result = absent_plugin_sd(inode);
++              info->plugin_mask = mask;
++      } else
++              info->heir_mask = mask;
 +
-+      reiser4_inode_data(inode)->plugin_mask = mask;
 +      return result;
 +}
 +
++static int present_pset_sd(struct inode *inode, char **area, int *len) {
++      return present_plugin_sd(inode, area, len, 1 /* pset */);
++}
++
 +/* Determine object plugin for @inode based on i_mode.
 +
 +   Many objects in reiser4 file system are controlled by standard object
@@ -53676,10 +53338,10 @@ Index: linux-2.6.16/fs/reiser4/plugin/item/static_stat.c
 +              break;
 +      }
 +      info = reiser4_inode_data(inode);
-+      plugin_set_file(&info->pset,
-+                      (fplug_id >= 0) ? file_plugin_by_id(fplug_id) : NULL);
-+      plugin_set_dir(&info->pset,
-+                     (dplug_id >= 0) ? dir_plugin_by_id(dplug_id) : NULL);
++      set_plugin(&info->pset, PSET_FILE, (fplug_id >= 0) ?
++                 plugin_by_id(REISER4_FILE_PLUGIN_TYPE, fplug_id) : NULL);
++      set_plugin(&info->pset, PSET_DIR, (dplug_id >= 0) ?
++                 plugin_by_id(REISER4_DIR_PLUGIN_TYPE, dplug_id) : NULL);
 +      return 0;
 +}
 +
@@ -53704,13 +53366,19 @@ Index: linux-2.6.16/fs/reiser4/plugin/item/static_stat.c
 +/* Audited by: green(2002.06.14) */
 +static int len_for(reiser4_plugin * plugin /* plugin to save */ ,
 +                 struct inode *inode /* object being processed */ ,
-+                 pset_member memb, int len)
++                 pset_member memb,
++                 int len, int is_pset)
 +{
 +      reiser4_inode *info;
 +      assert("nikita-661", inode != NULL);
 +
++      if (plugin == NULL)
++              return len;
++
 +      info = reiser4_inode_data(inode);
-+      if (plugin != NULL && (info->plugin_mask & (1 << memb))) {
++      if (is_pset ?
++          info->plugin_mask & (1 << memb) :
++          info->heir_mask & (1 << memb)) {
 +              len += sizeof(reiser4_plugin_slot);
 +              if (plugin->h.pops && plugin->h.pops->save_len != NULL) {
 +                      /* non-standard plugin, call method */
@@ -53725,33 +53393,44 @@ Index: linux-2.6.16/fs/reiser4/plugin/item/static_stat.c
 +
 +/* calculate how much space is required to save state of all plugins,
 +    associated with inode */
-+static int save_len_plugin_sd(struct inode *inode /* object being processed */ )
++static int save_len_plugin_sd(struct inode *inode /* object being processed */,
++                            int is_pset)
 +{
 +      int len;
++      int last;
 +      reiser4_inode *state;
 +      pset_member memb;
 +
 +      assert("nikita-663", inode != NULL);
 +
 +      state = reiser4_inode_data(inode);
++
 +      /* common case: no non-standard plugins */
-+      if (state->plugin_mask == 0)
++      if (is_pset ? state->plugin_mask == 0 : state->heir_mask == 0)
 +              return 0;
 +      len = sizeof(reiser4_plugin_stat);
-+      for (memb = 0; memb < PSET_LAST; ++memb)
-+              len = len_for(pset_get(state->pset, memb), inode, memb, len);
++      last = PSET_LAST;
++
++      for (memb = 0; memb < last; ++memb) {
++            len = len_for(aset_get(is_pset ? state->pset : state->hset, memb),
++                          inode, memb, len, is_pset);
++      }
 +      assert("nikita-664", len > (int)sizeof(reiser4_plugin_stat));
 +      return len;
 +}
 +
++static int save_len_pset_sd(struct inode *inode) {
++      return save_len_plugin_sd(inode, 1 /* pset */);
++}
++
 +/* helper function for plugin_sd_save(): save plugin, associated with
 +    inode. */
 +static int save_plug(reiser4_plugin * plugin /* plugin to save */ ,
 +                   struct inode *inode /* object being processed */ ,
-+                   pset_member memb /* what element of pset is saved */ ,
++                   int memb /* what element of pset is saved */ ,
 +                   char **area /* position in stat-data */ ,
-+                   int *count /* incremented if plugin were actually
-+                               * saved. */ )
++                   int *count /* incremented if plugin were actually saved. */,
++                   int is_pset /* 1 for plugin set, 0 for heir set */)
 +{
 +      reiser4_plugin_slot *slot;
 +      int fake_len;
@@ -53763,7 +53442,10 @@ Index: linux-2.6.16/fs/reiser4/plugin/item/static_stat.c
 +
 +      if (plugin == NULL)
 +              return 0;
-+      if (!(reiser4_inode_data(inode)->plugin_mask & (1 << memb)))
++
++      if (is_pset ?
++          !(reiser4_inode_data(inode)->plugin_mask & (1 << memb)) :
++          !(reiser4_inode_data(inode)->heir_mask & (1 << memb)))
 +              return 0;
 +      slot = (reiser4_plugin_slot *) * area;
 +      put_unaligned(cpu_to_le16(memb), &slot->pset_memb);
@@ -53781,13 +53463,14 @@ Index: linux-2.6.16/fs/reiser4/plugin/item/static_stat.c
 +
 +/* save state of all non-standard plugins associated with inode */
 +static int save_plugin_sd(struct inode *inode /* object being processed */ ,
-+                        char **area /* position in stat-data */ )
++                        char **area /* position in stat-data */,
++                        int is_pset /* 1 for pset, 0 for hset */)
 +{
++      int fake_len;
 +      int result = 0;
 +      int num_of_plugins;
 +      reiser4_plugin_stat *sd;
 +      reiser4_inode *state;
-+      int fake_len;
 +      pset_member memb;
 +
 +      assert("nikita-669", inode != NULL);
@@ -53795,7 +53478,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/item/static_stat.c
 +      assert("nikita-671", *area != NULL);
 +
 +      state = reiser4_inode_data(inode);
-+      if (state->plugin_mask == 0)
++      if (is_pset ? state->plugin_mask == 0 : state->heir_mask == 0)
 +              return 0;
 +      sd = (reiser4_plugin_stat *) * area;
 +      fake_len = (int)0xffff;
@@ -53803,8 +53486,9 @@ Index: linux-2.6.16/fs/reiser4/plugin/item/static_stat.c
 +
 +      num_of_plugins = 0;
 +      for (memb = 0; memb < PSET_LAST; ++memb) {
-+              result = save_plug(pset_get(state->pset, memb),
-+                                 inode, memb, area, &num_of_plugins);
++              result = save_plug(aset_get(is_pset ? state->pset : state->hset,
++                                          memb),
++                                 inode, memb, area, &num_of_plugins, is_pset);
 +              if (result != 0)
 +                      break;
 +      }
@@ -53813,23 +53497,39 @@ Index: linux-2.6.16/fs/reiser4/plugin/item/static_stat.c
 +      return result;
 +}
 +
++static int save_pset_sd(struct inode *inode, char **area) {
++      return save_plugin_sd(inode, area, 1 /* pset */);
++}
++
++static int present_hset_sd(struct inode *inode, char **area, int *len) {
++      return present_plugin_sd(inode, area, len, 0 /* hset */);
++}
++
++static int save_len_hset_sd(struct inode *inode) {
++      return save_len_plugin_sd(inode, 0 /* pset */);
++}
++
++static int save_hset_sd(struct inode *inode, char **area) {
++      return save_plugin_sd(inode, area, 0 /* hset */);
++}
++
 +/* helper function for crypto_sd_present(), crypto_sd_save.
-+   Allocates memory for crypto stat, keyid and attaches it to the inode */
-+static int extract_crypto_stat (struct inode * inode,
++   Extract crypto info from stat-data and attach it to inode */
++static int extract_crypto_info (struct inode * inode,
 +                              reiser4_crypto_stat * sd)
 +{
-+      crypto_stat_t * info;
-+      assert("edward-11", !inode_crypto_stat(inode));
++      struct reiser4_crypto_info * info;
++      assert("edward-11", !inode_crypto_info(inode));
 +      assert("edward-1413",
-+             !inode_get_flag(inode, REISER4_CRYPTO_STAT_LOADED));
++             !reiser4_inode_get_flag(inode, REISER4_CRYPTO_STAT_LOADED));
 +      /* create and attach a crypto-stat without secret key loaded */
-+      info = alloc_crypto_stat(inode);
++      info = reiser4_alloc_crypto_info(inode);
 +      if (IS_ERR(info))
 +              return PTR_ERR(info);
 +      info->keysize = le16_to_cpu(get_unaligned(&sd->keysize));
 +      memcpy(info->keyid, sd->keyid, inode_digest_plugin(inode)->fipsize);
-+      attach_crypto_stat(inode, info);
-+      inode_set_flag(inode, REISER4_CRYPTO_STAT_LOADED);
++      reiser4_attach_crypto_info(inode, info);
++      reiser4_inode_set_flag(inode, REISER4_CRYPTO_STAT_LOADED);
 +      return 0;
 +}
 +
@@ -53856,7 +53556,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/item/static_stat.c
 +      assert("edward-75", sizeof(*sd) + dplug->fipsize <= *len);
 +
 +      sd = (reiser4_crypto_stat *) * area;
-+      result = extract_crypto_stat(inode, sd);
++      result = extract_crypto_info(inode, sd);
 +      move_on(len, area, sizeof(*sd) + dplug->fipsize);
 +
 +      return result;
@@ -53872,7 +53572,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/item/static_stat.c
 +{
 +      int result = 0;
 +      reiser4_crypto_stat *sd;
-+      crypto_stat_t * info = inode_crypto_stat(inode);
++      struct reiser4_crypto_info * info = inode_crypto_info(inode);
 +      digest_plugin *dplug = inode_digest_plugin(inode);
 +
 +      assert("edward-12", dplug != NULL);
@@ -53883,13 +53583,13 @@ Index: linux-2.6.16/fs/reiser4/plugin/item/static_stat.c
 +      assert("edward-1415", info->keysize != 0);
 +      assert("edward-76", reiser4_inode_data(inode) != NULL);
 +
-+      if (!inode_get_flag(inode, REISER4_CRYPTO_STAT_LOADED)) {
++      if (!reiser4_inode_get_flag(inode, REISER4_CRYPTO_STAT_LOADED)) {
 +              /* file is just created */
 +              sd = (reiser4_crypto_stat *) *area;
 +              /* copy everything but private key to the disk stat-data */
 +              put_unaligned(cpu_to_le16(info->keysize), &sd->keysize);
 +              memcpy(sd->keyid, info->keyid, (size_t) dplug->fipsize);
-+              inode_set_flag(inode, REISER4_CRYPTO_STAT_LOADED);
++              reiser4_inode_set_flag(inode, REISER4_CRYPTO_STAT_LOADED);
 +      }
 +      *area += (sizeof(*sd) + dplug->fipsize);
 +      return result;
@@ -53972,10 +53672,25 @@ Index: linux-2.6.16/fs/reiser4/plugin/item/static_stat.c
 +                      .desc = "plugin stat-data fields",
 +                      .linkage = {NULL,NULL}
 +              },
-+              .present = present_plugin_sd,
++              .present = present_pset_sd,
 +              .absent = absent_plugin_sd,
-+              .save_len = save_len_plugin_sd,
-+              .save = save_plugin_sd,
++              .save_len = save_len_pset_sd,
++              .save = save_pset_sd,
++              .alignment = 8
++      },
++      [HEIR_STAT] = {
++              .h = {
++                      .type_id = REISER4_SD_EXT_PLUGIN_TYPE,
++                      .id = HEIR_STAT,
++                      .pops = NULL,
++                      .label = "heir-plugin-sd",
++                      .desc = "heir plugin stat-data fields",
++                      .linkage = {NULL,NULL}
++              },
++              .present = present_hset_sd,
++              .absent = NULL,
++              .save_len = save_len_hset_sd,
++              .save = save_hset_sd,
 +              .alignment = 8
 +      },
 +      [FLAGS_STAT] = {
@@ -54034,11 +53749,10 @@ Index: linux-2.6.16/fs/reiser4/plugin/item/static_stat.c
 +   fill-column: 120
 +   End:
 +*/
-Index: linux-2.6.16/fs/reiser4/plugin/item/static_stat.h
-===================================================================
---- /dev/null
-+++ linux-2.6.16/fs/reiser4/plugin/item/static_stat.h
-@@ -0,0 +1,219 @@
+diff -urN linux-2.6.22.orig/fs/reiser4/plugin/item/static_stat.h linux-2.6.22/fs/reiser4/plugin/item/static_stat.h
+--- linux-2.6.22.orig/fs/reiser4/plugin/item/static_stat.h     1970-01-01 03:00:00.000000000 +0300
++++ linux-2.6.22/fs/reiser4/plugin/item/static_stat.h  2007-07-29 00:25:34.976722360 +0400
+@@ -0,0 +1,224 @@
 +/* Copyright 2001, 2002, 2003 by Hans Reiser, licensing governed by reiser4/README */
 +
 +/* This describes the static_stat item, used to hold all information needed by the stat() syscall.
@@ -54109,9 +53823,9 @@ Index: linux-2.6.16/fs/reiser4/plugin/item/static_stat.h
 +      LARGE_TIMES_STAT,
 +      /* stat data has link name included */
 +      SYMLINK_STAT,
-+      /* if this is present, file is controlled by non-standard
-+         plugin (that is, plugin that cannot be deduced from file
-+         mode bits), for example, aggregation, interpolation etc. */
++      /* on-disk slots of non-standard plugins for main plugin table
++         (@reiser4_inode->pset), that is, plugins that cannot be deduced
++         from file mode bits), for example, aggregation, interpolation etc. */
 +      PLUGIN_STAT,
 +      /* this extension contains persistent inode flags. These flags are
 +         single bits: immutable, append, only, etc. Layout is in
@@ -54123,6 +53837,11 @@ Index: linux-2.6.16/fs/reiser4/plugin/item/static_stat.h
 +      /* this extension contains size and public id of the secret key.
 +         Layout is in reiser4_crypto_stat */
 +      CRYPTO_STAT,
++      /* on-disk slots of non-default plugins for inheritance, which
++         are extracted to special plugin table (@reiser4_inode->hset).
++         By default, children of the object will inherit plugins from
++         its main plugin table (pset). */
++      HEIR_STAT,
 +      LAST_SD_EXTENSION,
 +      /*
 +       * init_inode_static_sd() iterates over extension mask until all
@@ -54136,7 +53855,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/item/static_stat.h
 +       * ->present(), or ->absent() method will be called, independently of
 +       * what other extensions are present.
 +       */
-+      LAST_IMPORTANT_SD_EXTENSION = PLUGIN_STAT,
++      LAST_IMPORTANT_SD_EXTENSION = PLUGIN_STAT
 +} sd_ext_bits;
 +
 +/* minimal stat-data. This allows to support light-weight files. */
@@ -54148,9 +53867,9 @@ Index: linux-2.6.16/fs/reiser4/plugin/item/static_stat.h
 +typedef struct reiser4_light_weight_stat {
 +      /*  0 */ __le16 mode;
 +      /*  2 */ __le32 nlink;
-+      /*  8 */ __le64 size;
++      /*  6 */ __le64 size;
 +      /* size in bytes */
-+      /* 16 */
++      /* 14 */
 +} PACKED reiser4_light_weight_stat;
 +
 +typedef struct reiser4_unix_stat {
@@ -54222,12 +53941,12 @@ Index: linux-2.6.16/fs/reiser4/plugin/item/static_stat.h
 +
 +typedef struct reiser4_large_times_stat {
 +      /* access time */
-+      /*  0 */ d32 atime;
++      /* 0 */ d32 atime;
 +      /* modification time */
-+      /*  8 */ d32 mtime;
++      /* 4 */ d32 mtime;
 +      /* change time */
-+      /* 16 */ d32 ctime;
-+      /* 24 */
++      /* 8 */ d32 ctime;
++      /* 12 */
 +} PACKED reiser4_large_times_stat;
 +
 +/* this structure is filled by sd_item_stat */
@@ -54258,11 +53977,10 @@ Index: linux-2.6.16/fs/reiser4/plugin/item/static_stat.h
 +   fill-column: 120
 +   End:
 +*/
-Index: linux-2.6.16/fs/reiser4/plugin/item/tail.c
-===================================================================
---- /dev/null
-+++ linux-2.6.16/fs/reiser4/plugin/item/tail.c
-@@ -0,0 +1,805 @@
+diff -urN linux-2.6.22.orig/fs/reiser4/plugin/item/tail.c linux-2.6.22/fs/reiser4/plugin/item/tail.c
+--- linux-2.6.22.orig/fs/reiser4/plugin/item/tail.c    1970-01-01 03:00:00.000000000 +0300
++++ linux-2.6.22/fs/reiser4/plugin/item/tail.c 2007-07-29 00:25:34.980723395 +0400
+@@ -0,0 +1,809 @@
 +/* Copyright 2001, 2002, 2003 by Hans Reiser, licensing governed by reiser4/README */
 +
 +#include "item.h"
@@ -54280,7 +53998,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/item/tail.c
 +reiser4_key *max_key_inside_tail(const coord_t *coord, reiser4_key *key)
 +{
 +      item_key_by_coord(coord, key);
-+      set_key_offset(key, get_key_offset(max_key()));
++      set_key_offset(key, get_key_offset(reiser4_max_key()));
 +      return key;
 +}
 +
@@ -54308,8 +54026,8 @@ Index: linux-2.6.16/fs/reiser4/plugin/item/tail.c
 +{
 +      reiser4_key key1, key2;
 +
-+      assert("vs-535",
-+             item_type_by_coord(p1) == UNIX_FILE_METADATA_ITEM_TYPE);
++      assert("vs-535", plugin_of_group(item_plugin_by_coord(p1),
++                                       UNIX_FILE_METADATA_ITEM_TYPE));
 +      assert("vs-365", item_id_by_coord(p1) == FORMATTING_ID);
 +
 +      if (item_id_by_coord(p2) != FORMATTING_ID) {
@@ -54404,7 +54122,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/item/tail.c
 +      if (data->data) {
 +              assert("vs-554", data->user == 0 || data->user == 1);
 +              if (data->user) {
-+                      assert("nikita-3035", schedulable());
++                      assert("nikita-3035", reiser4_schedulable());
 +                      /* copy from user space */
 +                      if (__copy_from_user(item + coord->unit_pos,
 +                                           (const char __user *)data->data,
@@ -54585,9 +54303,9 @@ Index: linux-2.6.16/fs/reiser4/plugin/item/tail.c
 +      inode = page->mapping->host;
 +      coord_dup(&coord, &uf_coord->coord);
 +
-+      tap_init(&tap, &coord, &lh, ZNODE_READ_LOCK);
++      reiser4_tap_init(&tap, &coord, &lh, ZNODE_READ_LOCK);
 +
-+      if ((result = tap_load(&tap)))
++      if ((result = reiser4_tap_load(&tap)))
 +              goto out_tap_done;
 +
 +      /* lookup until page is filled up. */
@@ -54656,19 +54374,16 @@ Index: linux-2.6.16/fs/reiser4/plugin/item/tail.c
 +      }
 +
 + done:
-+      if (mapped != PAGE_CACHE_SIZE) {
-+              pagedata = kmap_atomic(page, KM_USER0);
-+              memset(pagedata + mapped, 0, PAGE_CACHE_SIZE - mapped);
-+              flush_dcache_page(page);
-+              kunmap_atomic(pagedata, KM_USER0);
-+      }
++      if (mapped != PAGE_CACHE_SIZE)
++              zero_user_page(page, mapped, PAGE_CACHE_SIZE - mapped,
++                              KM_USER0);
 +      SetPageUptodate(page);
 + out_unlock_page:
 +      unlock_page(page);
 + out_tap_relse:
-+      tap_relse(&tap);
++      reiser4_tap_relse(&tap);
 + out_tap_done:
-+      tap_done(&tap);
++      reiser4_tap_done(&tap);
 +      return result;
 +}
 +
@@ -54718,7 +54433,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/item/tail.c
 +      assert("vs-946", flow->data);
 +      assert("vs-947", coord_is_existing_unit(coord));
 +      assert("vs-948", znode_is_write_locked(coord->node));
-+      assert("nikita-3036", schedulable());
++      assert("nikita-3036", reiser4_schedulable());
 +
 +      count = item_length_by_coord(coord) - coord->unit_pos;
 +      if (count > flow->length)
@@ -54746,7 +54461,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/item/tail.c
 +{
 +      int result;
 +      loff_t to_write;
-+      unix_file_info_t *uf_info;
++      struct unix_file_info *uf_info;
 +
 +      if (get_key_offset(&flow->key) != 0) {
 +              /*
@@ -54765,7 +54480,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/item/tail.c
 +               */
 +              if (DQUOT_ALLOC_SPACE_NODIRTY(inode, flow->length))
 +                      return RETERR(-EDQUOT);
-+              result = insert_flow(coord, lh, flow);
++              result = reiser4_insert_flow(coord, lh, flow);
 +              if (flow->length)
 +                      DQUOT_FREE_SPACE_NODIRTY(inode, flow->length);
 +
@@ -54776,9 +54491,10 @@ Index: linux-2.6.16/fs/reiser4/plugin/item/tail.c
 +               * file or performing tail conversion
 +               */
 +              assert("", (uf_info->container == UF_CONTAINER_EMPTY ||
-+                          (inode_get_flag(inode, REISER4_PART_MIXED) &&
-+                           inode_get_flag(inode, REISER4_PART_IN_CONV))));
-+
++                          (reiser4_inode_get_flag(inode,
++                                                  REISER4_PART_MIXED) &&
++                           reiser4_inode_get_flag(inode,
++                                                  REISER4_PART_IN_CONV))));
 +              /* if file was empty - update its state */
 +              if (result == 0 && uf_info->container == UF_CONTAINER_EMPTY)
 +                      uf_info->container = UF_CONTAINER_TAILS;
@@ -54790,7 +54506,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/item/tail.c
 +              return RETERR(-EDQUOT);
 +
 +      to_write = flow->length;
-+      result = insert_flow(coord, lh, flow);
++      result = reiser4_insert_flow(coord, lh, flow);
 +      if (flow->length)
 +              DQUOT_FREE_SPACE_NODIRTY(inode, flow->length);
 +      return (to_write - flow->length) ? (to_write - flow->length) : result;
@@ -54811,7 +54527,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/item/tail.c
 +      int result;
 +      reiser4_key append_key;
 +      loff_t to_write;
-+      
++
 +      if (!keyeq(&flow->key, append_key_tail(coord, &append_key))) {
 +              flow->data = NULL;
 +              flow->length = get_key_offset(&flow->key) - get_key_offset(&append_key);
@@ -54823,7 +54539,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/item/tail.c
 +               */
 +              if (DQUOT_ALLOC_SPACE_NODIRTY(inode, flow->length))
 +                      return RETERR(-EDQUOT);
-+              result = insert_flow(coord, lh, flow);
++              result = reiser4_insert_flow(coord, lh, flow);
 +              if (flow->length)
 +                      DQUOT_FREE_SPACE_NODIRTY(inode, flow->length);
 +              return result;
@@ -54834,7 +54550,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/item/tail.c
 +              return RETERR(-EDQUOT);
 +
 +      to_write = flow->length;
-+      result = insert_flow(coord, lh, flow);
++      result = reiser4_insert_flow(coord, lh, flow);
 +      if (flow->length)
 +              DQUOT_FREE_SPACE_NODIRTY(inode, flow->length);
 +      return (to_write - flow->length) ? (to_write - flow->length) : result;
@@ -54854,7 +54570,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/item/tail.c
 +
 +      /*
 +       * to write one flow to a file by tails we have to reserve disk space for:
-+ 
++
 +       * 1. find_file_item may have to insert empty node to the tree (empty
 +       * leaf node between two extent items). This requires 1 block and
 +       * number of blocks which are necessary to perform insertion of an
@@ -54864,8 +54580,8 @@ Index: linux-2.6.16/fs/reiser4/plugin/item/tail.c
 +       *
 +       * 3. stat data update
 +       */
-+      tree = tree_by_inode(inode);
-+      count = estimate_one_insert_item(tree) + 
++      tree = reiser4_tree_by_inode(inode);
++      count = estimate_one_insert_item(tree) +
 +              estimate_insert_flow(tree->height) +
 +              estimate_one_insert_item(tree);
 +      grab_space_enable();
@@ -54876,7 +54592,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/item/tail.c
 +
 +static loff_t faultin_user_pages(const char __user *buf, size_t count)
 +{
-+      loff_t faulted; 
++      loff_t faulted;
 +      int to_fault;
 +
 +      if (count > PAGE_PER_FLOW * PAGE_CACHE_SIZE)
@@ -54894,7 +54610,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/item/tail.c
 +}
 +
 +/**
-+ * write_extent - write method of tail item plugin
++ * reiser4_write_extent - write method of tail item plugin
 + * @file: file to write to
 + * @buf: address of user-space buffer
 + * @count: number of bytes to write
@@ -54902,8 +54618,8 @@ Index: linux-2.6.16/fs/reiser4/plugin/item/tail.c
 + *
 + * Returns number of written bytes or error code.
 + */
-+ssize_t write_tail(struct file *file, const char __user *buf, size_t count,
-+                 loff_t *pos)
++ssize_t reiser4_write_tail(struct file *file, const char __user *buf,
++                         size_t count, loff_t *pos)
 +{
 +      struct inode *inode;
 +      struct hint hint;
@@ -54937,7 +54653,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/item/tail.c
 +      result = zload(coord->node);
 +      BUG_ON(result != 0);
 +      loaded = coord->node;
-+      
++
 +      if (coord->between == AFTER_UNIT) {
 +              /* append with data or hole */
 +              result = append_tail(inode, &flow, coord, lh);
@@ -54953,13 +54669,13 @@ Index: linux-2.6.16/fs/reiser4/plugin/item/tail.c
 +              done_lh(lh);
 +              return result;
 +      }
-+      
++
 +      /* seal and unlock znode */
 +      hint.ext_coord.valid = 0;
 +      if (hint.ext_coord.valid)
-+              set_hint(&hint, &flow.key, ZNODE_WRITE_LOCK);
++              reiser4_set_hint(&hint, &flow.key, ZNODE_WRITE_LOCK);
 +      else
-+              unset_hint(&hint);
++              reiser4_unset_hint(&hint);
 +
 +      save_file_hint(file, &hint);
 +      return result;
@@ -54983,7 +54699,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/item/tail.c
 +#endif
 +
 +/* plugin->u.item.s.file.read */
-+int read_tail(struct file *file UNUSED_ARG, flow_t *f, hint_t *hint)
++int reiser4_read_tail(struct file *file UNUSED_ARG, flow_t *f, hint_t *hint)
 +{
 +      unsigned count;
 +      int item_length;
@@ -54999,7 +54715,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/item/tail.c
 +      assert("vs-1117", znode_is_rlocked(coord->node));
 +      assert("vs-1118", znode_is_loaded(coord->node));
 +
-+      assert("nikita-3037", schedulable());
++      assert("nikita-3037", reiser4_schedulable());
 +      assert("vs-1357", coord_matches_key_tail(coord, &f->key));
 +
 +      /* calculate number of bytes to read off the item */
@@ -55025,7 +54741,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/item/tail.c
 +              coord->unit_pos--;
 +              coord->between = AFTER_UNIT;
 +      }
-+
++      reiser4_set_hint(hint, &f->key, ZNODE_READ_LOCK);
 +      return 0;
 +}
 +
@@ -55054,7 +54770,13 @@ Index: linux-2.6.16/fs/reiser4/plugin/item/tail.c
 +{
 +      assert("nikita-3252", znode_get_level(coord->node) == LEAF_LEVEL);
 +
-+      *block = *znode_get_block(coord->node);
++      if (reiser4_blocknr_is_fake(znode_get_block(coord->node)))
++              /* if node has'nt obtainet its block number yet, return 0.
++               * Lets avoid upsetting users with some cosmic numbers beyond
++               * the device capacity.*/
++              *block = 0;
++      else
++              *block = *znode_get_block(coord->node);
 +      return 0;
 +}
 +
@@ -55068,19 +54790,18 @@ Index: linux-2.6.16/fs/reiser4/plugin/item/tail.c
 + * scroll-step: 1
 + * End:
 + */
-Index: linux-2.6.16/fs/reiser4/plugin/item/tail.h
-===================================================================
---- /dev/null
-+++ linux-2.6.16/fs/reiser4/plugin/item/tail.h
+diff -urN linux-2.6.22.orig/fs/reiser4/plugin/item/tail.h linux-2.6.22/fs/reiser4/plugin/item/tail.h
+--- linux-2.6.22.orig/fs/reiser4/plugin/item/tail.h    1970-01-01 03:00:00.000000000 +0300
++++ linux-2.6.22/fs/reiser4/plugin/item/tail.h 2007-07-29 00:25:34.980723395 +0400
 @@ -0,0 +1,58 @@
 +/* Copyright 2002, 2003 by Hans Reiser, licensing governed by reiser4/README */
 +
 +#if !defined( __REISER4_TAIL_H__ )
 +#define __REISER4_TAIL_H__
 +
-+typedef struct {
++struct tail_coord_extension {
 +      int not_used;
-+} tail_coord_extension_t;
++};
 +
 +struct cut_list;
 +
@@ -55108,9 +54829,9 @@ Index: linux-2.6.16/fs/reiser4/plugin/item/tail.h
 +reiser4_key *unit_key_tail(const coord_t *, reiser4_key *);
 +
 +/* plugin->u.item.s.* */
-+ssize_t write_tail(struct file *file, const char __user *buf, size_t count,
-+                 loff_t *pos);
-+int read_tail(struct file *, flow_t *, hint_t *);
++ssize_t reiser4_write_tail(struct file *file, const char __user *buf,
++                         size_t count, loff_t *pos);
++int reiser4_read_tail(struct file *, flow_t *, hint_t *);
 +int readpage_tail(void *vp, struct page *page);
 +reiser4_key *append_key_tail(const coord_t *, reiser4_key *);
 +void init_coord_extension_tail(uf_coord_t *, loff_t offset);
@@ -55131,433 +54852,48 @@ Index: linux-2.6.16/fs/reiser4/plugin/item/tail.h
 +   scroll-step: 1
 +   End:
 +*/
-Index: linux-2.6.16/fs/reiser4/plugin/node/Makefile
-===================================================================
---- /dev/null
-+++ linux-2.6.16/fs/reiser4/plugin/node/Makefile
+diff -urN linux-2.6.22.orig/fs/reiser4/plugin/Makefile linux-2.6.22/fs/reiser4/plugin/Makefile
+--- linux-2.6.22.orig/fs/reiser4/plugin/Makefile       1970-01-01 03:00:00.000000000 +0300
++++ linux-2.6.22/fs/reiser4/plugin/Makefile    2007-07-29 00:25:34.980723395 +0400
+@@ -0,0 +1,26 @@
++obj-$(CONFIG_REISER4_FS) += plugins.o
++
++plugins-objs :=                       \
++      plugin.o                \
++      plugin_set.o            \
++      object.o                \
++      inode_ops.o             \
++      inode_ops_rename.o      \
++      file_ops.o              \
++      file_ops_readdir.o      \
++      file_plugin_common.o    \
++      dir_plugin_common.o     \
++      digest.o                \
++      hash.o                  \
++      fibration.o             \
++      tail_policy.o           \
++      regular.o
++
++obj-$(CONFIG_REISER4_FS) += item/
++obj-$(CONFIG_REISER4_FS) += file/
++obj-$(CONFIG_REISER4_FS) += dir/
++obj-$(CONFIG_REISER4_FS) += node/
++obj-$(CONFIG_REISER4_FS) += compress/
++obj-$(CONFIG_REISER4_FS) += space/
++obj-$(CONFIG_REISER4_FS) += disk_format/
++obj-$(CONFIG_REISER4_FS) += security/
+diff -urN linux-2.6.22.orig/fs/reiser4/plugin/node/Makefile linux-2.6.22/fs/reiser4/plugin/node/Makefile
+--- linux-2.6.22.orig/fs/reiser4/plugin/node/Makefile  1970-01-01 03:00:00.000000000 +0300
++++ linux-2.6.22/fs/reiser4/plugin/node/Makefile       2007-07-29 00:25:34.980723395 +0400
 @@ -0,0 +1,5 @@
 +obj-$(CONFIG_REISER4_FS) += node_plugins.o
 +
 +node_plugins-objs :=  \
 +      node.o          \
 +      node40.o
-Index: linux-2.6.16/fs/reiser4/plugin/node/node.c
-===================================================================
---- /dev/null
-+++ linux-2.6.16/fs/reiser4/plugin/node/node.c
-@@ -0,0 +1,131 @@
-+/* Copyright 2001, 2002, 2003 by Hans Reiser, licensing governed by reiser4/README */
-+
-+/* Node plugin interface.
-+
-+   Description: The tree provides the abstraction of flows, which it
-+   internally fragments into items which it stores in nodes.
-+
-+   A key_atom is a piece of data bound to a single key.
-+
-+   For reasonable space efficiency to be achieved it is often
-+   necessary to store key_atoms in the nodes in the form of items, where
-+   an item is a sequence of key_atoms of the same or similar type. It is
-+   more space-efficient, because the item can implement (very)
-+   efficient compression of key_atom's bodies using internal knowledge
-+   about their semantics, and it can often avoid having a key for each
-+   key_atom. Each type of item has specific operations implemented by its
-+   item handler (see balance.c).
-+
-+   Rationale: the rest of the code (specifically balancing routines)
-+   accesses leaf level nodes through this interface. This way we can
-+   implement various block layouts and even combine various layouts
-+   within the same tree. Balancing/allocating algorithms should not
-+   care about peculiarities of splitting/merging specific item types,
-+   but rather should leave that to the item's item handler.
-+
-+   Items, including those that provide the abstraction of flows, have
-+   the property that if you move them in part or in whole to another
-+   node, the balancing code invokes their is_left_mergeable()
-+   item_operation to determine if they are mergeable with their new
-+   neighbor in the node you have moved them to.  For some items the
-+   is_left_mergeable() function always returns null.
-+
-+   When moving the bodies of items from one node to another:
-+
-+     if a partial item is shifted to another node the balancing code invokes
-+     an item handler method to handle the item splitting.
-+
-+     if the balancing code needs to merge with an item in the node it
-+     is shifting to, it will invoke an item handler method to handle
-+     the item merging.
-+
-+     if it needs to move whole item bodies unchanged, the balancing code uses xmemcpy()
-+     adjusting the item headers after the move is done using the node handler.
-+*/
-+
-+#include "../../forward.h"
-+#include "../../debug.h"
-+#include "../../key.h"
-+#include "../../coord.h"
-+#include "../plugin_header.h"
-+#include "../item/item.h"
-+#include "node.h"
-+#include "../plugin.h"
-+#include "../../znode.h"
-+#include "../../tree.h"
-+#include "../../super.h"
-+#include "../../reiser4.h"
-+
-+/**
-+ * leftmost_key_in_node - get the smallest key in node
-+ * @node:
-+ * @key: store result here
-+ *
-+ * Stores the leftmost key of @node in @key.
-+ */
-+reiser4_key *leftmost_key_in_node(const znode *node, reiser4_key *key)
-+{
-+      assert("nikita-1634", node != NULL);
-+      assert("nikita-1635", key != NULL);
-+
-+      if (!node_is_empty(node)) {
-+              coord_t first_item;
-+
-+              coord_init_first_unit(&first_item, (znode *) node);
-+              item_key_by_coord(&first_item, key);
-+      } else
-+              *key = *max_key();
-+      return key;
-+}
-+
-+node_plugin node_plugins[LAST_NODE_ID] = {
-+      [NODE40_ID] = {
-+              .h = {
-+                      .type_id = REISER4_NODE_PLUGIN_TYPE,
-+                      .id = NODE40_ID,
-+                      .pops = NULL,
-+                      .label = "unified",
-+                      .desc = "unified node layout",
-+                      .linkage = {NULL, NULL}
-+              },
-+              .item_overhead = item_overhead_node40,
-+              .free_space = free_space_node40,
-+              .lookup = lookup_node40,
-+              .num_of_items = num_of_items_node40,
-+              .item_by_coord = item_by_coord_node40,
-+              .length_by_coord = length_by_coord_node40,
-+              .plugin_by_coord = plugin_by_coord_node40,
-+              .key_at = key_at_node40,
-+              .estimate = estimate_node40,
-+              .check = check_node40,
-+              .parse = parse_node40,
-+              .init = init_node40,
-+#ifdef GUESS_EXISTS
-+              .guess = guess_node40,
-+#endif
-+              .change_item_size = change_item_size_node40,
-+              .create_item = create_item_node40,
-+              .update_item_key = update_item_key_node40,
-+              .cut_and_kill = kill_node40,
-+              .cut = cut_node40,
-+              .shift = shift_node40,
-+              .shrink_item = shrink_item_node40,
-+              .fast_insert = fast_insert_node40,
-+              .fast_paste = fast_paste_node40,
-+              .fast_cut = fast_cut_node40,
-+              .max_item_size = max_item_size_node40,
-+              .prepare_removal = prepare_removal_node40,
-+              .set_item_plugin = set_item_plugin_node40
-+      }
-+};
-+
-+/*
-+   Local variables:
-+   c-indentation-style: "K&R"
-+   mode-name: "LC"
-+   c-basic-offset: 8
-+   tab-width: 8
-+   fill-column: 120
-+   scroll-step: 1
-+   End:
-+*/
-Index: linux-2.6.16/fs/reiser4/plugin/node/node.h
-===================================================================
---- /dev/null
-+++ linux-2.6.16/fs/reiser4/plugin/node/node.h
-@@ -0,0 +1,272 @@
-+/* Copyright 2001, 2002, 2003 by Hans Reiser, licensing governed by reiser4/README */
-+
-+/* We need a definition of the default node layout here. */
-+
-+/* Generally speaking, it is best to have free space in the middle of the
-+   node so that two sets of things can grow towards it, and to have the
-+   item bodies on the left so that the last one of them grows into free
-+   space.  We optimize for the case where we append new items to the end
-+   of the node, or grow the last item, because it hurts nothing to so
-+   optimize and it is a common special case to do massive insertions in
-+   increasing key order (and one of cases more likely to have a real user
-+   notice the delay time for).
-+
-+   formatted leaf default layout: (leaf1)
-+
-+   |node header:item bodies:free space:key + pluginid + item offset|
-+
-+   We grow towards the middle, optimizing layout for the case where we
-+   append new items to the end of the node.  The node header is fixed
-+   length.  Keys, and item offsets plus pluginids for the items
-+   corresponding to them are in increasing key order, and are fixed
-+   length.  Item offsets are relative to start of node (16 bits creating
-+   a node size limit of 64k, 12 bits might be a better choice....).  Item
-+   bodies are in decreasing key order.  Item bodies have a variable size.
-+   There is a one to one to one mapping of keys to item offsets to item
-+   bodies.  Item offsets consist of pointers to the zeroth byte of the
-+   item body.  Item length equals the start of the next item minus the
-+   start of this item, except the zeroth item whose length equals the end
-+   of the node minus the start of that item (plus a byte).  In other
-+   words, the item length is not recorded anywhere, and it does not need
-+   to be since it is computable.
-+
-+   Leaf variable length items and keys layout : (lvar)
-+
-+   |node header:key offset + item offset + pluginid triplets:free space:key bodies:item bodies|
-+
-+   We grow towards the middle, optimizing layout for the case where we
-+   append new items to the end of the node.  The node header is fixed
-+   length.  Keys and item offsets for the items corresponding to them are
-+   in increasing key order, and keys are variable length.  Item offsets
-+   are relative to start of node (16 bits).  Item bodies are in
-+   decreasing key order.  Item bodies have a variable size.  There is a
-+   one to one to one mapping of keys to item offsets to item bodies.
-+   Item offsets consist of pointers to the zeroth byte of the item body.
-+   Item length equals the start of the next item's key minus the start of
-+   this item, except the zeroth item whose length equals the end of the
-+   node minus the start of that item (plus a byte).
-+
-+   leaf compressed keys layout: (lcomp)
-+
-+   |node header:key offset + key inherit + item offset pairs:free space:key bodies:item bodies|
-+
-+   We grow towards the middle, optimizing layout for the case where we
-+   append new items to the end of the node.  The node header is fixed
-+   length.  Keys and item offsets for the items corresponding to them are
-+   in increasing key order, and keys are variable length.  The "key
-+   inherit" field indicates how much of the key prefix is identical to
-+   the previous key (stem compression as described in "Managing
-+   Gigabytes" is used).  key_inherit is a one byte integer.  The
-+   intra-node searches performed through this layout are linear searches,
-+   and this is theorized to not hurt performance much due to the high
-+   cost of processor stalls on modern CPUs, and the small number of keys
-+   in a single node.  Item offsets are relative to start of node (16
-+   bits).  Item bodies are in decreasing key order.  Item bodies have a
-+   variable size.  There is a one to one to one mapping of keys to item
-+   offsets to item bodies.  Item offsets consist of pointers to the
-+   zeroth byte of the item body.  Item length equals the start of the
-+   next item minus the start of this item, except the zeroth item whose
-+   length equals the end of the node minus the start of that item (plus a
-+   byte).  In other words, item length and key length is not recorded
-+   anywhere, and it does not need to be since it is computable.
-+
-+   internal node default layout: (idef1)
-+
-+   just like ldef1 except that item bodies are either blocknrs of
-+   children or extents, and moving them may require updating parent
-+   pointers in the nodes that they point to.
-+*/
-+
-+/* There is an inherent 3-way tradeoff between optimizing and
-+   exchanging disks between different architectures and code
-+   complexity.  This is optimal and simple and inexchangeable.
-+   Someone else can do the code for exchanging disks and make it
-+   complex. It would not be that hard.  Using other than the PAGE_SIZE
-+   might be suboptimal.
-+*/
-+
-+#if !defined( __REISER4_NODE_H__ )
-+#define __REISER4_NODE_H__
-+
-+#define LEAF40_NODE_SIZE PAGE_CACHE_SIZE
-+
-+#include "../../dformat.h"
-+#include "../plugin_header.h"
-+
-+#include <linux/types.h>
-+
-+typedef enum {
-+      NS_FOUND = 0,
-+      NS_NOT_FOUND = -ENOENT
-+} node_search_result;
-+
-+/* Maximal possible space overhead for creation of new item in a node */
-+#define REISER4_NODE_MAX_OVERHEAD ( sizeof( reiser4_key ) + 32 )
-+
-+typedef enum {
-+      REISER4_NODE_DKEYS = (1 << 0),
-+      REISER4_NODE_TREE_STABLE = (1 << 1)
-+} reiser4_node_check_flag;
-+
-+/* cut and cut_and_kill have too long list of parameters. This structure is just to safe some space on stack */
-+struct cut_list {
-+      coord_t *from;
-+      coord_t *to;
-+      const reiser4_key *from_key;
-+      const reiser4_key *to_key;
-+      reiser4_key *smallest_removed;
-+      carry_plugin_info *info;
-+      __u32 flags;
-+      struct inode *inode;    /* this is to pass list of eflushed jnodes down to extent_kill_hook */
-+      lock_handle *left;
-+      lock_handle *right;
-+};
-+
-+struct carry_cut_data;
-+struct carry_kill_data;
-+
-+/* The responsibility of the node plugin is to store and give access
-+   to the sequence of items within the node.  */
-+typedef struct node_plugin {
-+      /* generic plugin fields */
-+      plugin_header h;
-+
-+      /* calculates the amount of space that will be required to store an
-+         item which is in addition to the space consumed by the item body.
-+         (the space consumed by the item body can be gotten by calling
-+         item->estimate) */
-+       size_t(*item_overhead) (const znode * node, flow_t * f);
-+
-+      /* returns free space by looking into node (i.e., without using
-+         znode->free_space). */
-+       size_t(*free_space) (znode * node);
-+      /* search within the node for the one item which might
-+         contain the key, invoking item->search_within to search within
-+         that item to see if it is in there */
-+       node_search_result(*lookup) (znode * node, const reiser4_key * key,
-+                                    lookup_bias bias, coord_t * coord);
-+      /* number of items in node */
-+      int (*num_of_items) (const znode * node);
-+
-+      /* store information about item in @coord in @data */
-+      /* break into several node ops, don't add any more uses of this before doing so */
-+      /*int ( *item_at )( const coord_t *coord, reiser4_item_data *data ); */
-+      char *(*item_by_coord) (const coord_t * coord);
-+      int (*length_by_coord) (const coord_t * coord);
-+      item_plugin *(*plugin_by_coord) (const coord_t * coord);
-+
-+      /* store item key in @key */
-+      reiser4_key *(*key_at) (const coord_t * coord, reiser4_key * key);
-+      /* conservatively estimate whether unit of what size can fit
-+         into node. This estimation should be performed without
-+         actually looking into the node's content (free space is saved in
-+         znode). */
-+       size_t(*estimate) (znode * node);
-+
-+      /* performs every consistency check the node plugin author could
-+         imagine. Optional. */
-+      int (*check) (const znode * node, __u32 flags, const char **error);
-+
-+      /* Called when node is read into memory and node plugin is
-+         already detected. This should read some data into znode (like free
-+         space counter) and, optionally, check data consistency.
-+       */
-+      int (*parse) (znode * node);
-+      /* This method is called on a new node to initialise plugin specific
-+         data (header, etc.) */
-+      int (*init) (znode * node);
-+      /* Check whether @node content conforms to this plugin format.
-+         Probably only useful after support for old V3.x formats is added.
-+         Uncomment after 4.0 only.
-+       */
-+      /*      int ( *guess )( const znode *node ); */
-+#if REISER4_DEBUG
-+      void (*print) (const char *prefix, const znode * node, __u32 flags);
-+#endif
-+      /* change size of @item by @by bytes. @item->node has enough free
-+         space. When @by > 0 - free space is appended to end of item. When
-+         @by < 0 - item is truncated - it is assumed that last @by bytes if
-+         the item are freed already */
-+      void (*change_item_size) (coord_t * item, int by);
-+
-+      /* create new item @length bytes long in coord @target */
-+      int (*create_item) (coord_t * target, const reiser4_key * key,
-+                          reiser4_item_data * data, carry_plugin_info * info);
-+
-+      /* update key of item. */
-+      void (*update_item_key) (coord_t * target, const reiser4_key * key,
-+                               carry_plugin_info * info);
-+
-+      int (*cut_and_kill) (struct carry_kill_data *, carry_plugin_info *);
-+      int (*cut) (struct carry_cut_data *, carry_plugin_info *);
-+
-+      /*
-+       * shrink item pointed to by @coord by @delta bytes.
-+       */
-+      int (*shrink_item) (coord_t * coord, int delta);
-+
-+      /* copy as much as possible but not more than up to @stop from
-+         @stop->node to @target. If (pend == append) then data from beginning of
-+         @stop->node are copied to the end of @target. If (pend == prepend) then
-+         data from the end of @stop->node are copied to the beginning of
-+         @target. Copied data are removed from @stop->node. Information
-+         about what to do on upper level is stored in @todo */
-+      int (*shift) (coord_t * stop, znode * target, shift_direction pend,
-+                    int delete_node, int including_insert_coord,
-+                    carry_plugin_info * info);
-+      /* return true if this node allows skip carry() in some situations
-+         (see fs/reiser4/tree.c:insert_by_coord()). Reiser3.x format
-+         emulation doesn't.
-+
-+         This will speedup insertions that doesn't require updates to the
-+         parent, by bypassing initialisation of carry() structures. It's
-+         believed that majority of insertions will fit there.
-+
-+       */
-+      int (*fast_insert) (const coord_t * coord);
-+      int (*fast_paste) (const coord_t * coord);
-+      int (*fast_cut) (const coord_t * coord);
-+      /* this limits max size of item which can be inserted into a node and
-+         number of bytes item in a node may be appended with */
-+      int (*max_item_size) (void);
-+      int (*prepare_removal) (znode * empty, carry_plugin_info * info);
-+      /* change plugin id of items which are in a node already. Currently it is Used in tail conversion for regular
-+       * files */
-+      int (*set_item_plugin) (coord_t * coord, item_id);
-+} node_plugin;
-+
-+typedef enum {
-+      /* standard unified node layout used for both leaf and internal
-+         nodes */
-+      NODE40_ID,
-+      LAST_NODE_ID
-+} reiser4_node_id;
-+
-+extern reiser4_key *leftmost_key_in_node(const znode * node, reiser4_key * key);
-+#if REISER4_DEBUG
-+extern void print_node_content(const char *prefix, const znode * node,
-+                             __u32 flags);
-+#endif
-+
-+extern void indent_znode(const znode * node);
-+
-+typedef struct common_node_header {
-+      /*
-+       * identifier of node plugin. Must be located at the very beginning of
-+       * a node.
-+       */
-+      __le16 plugin_id;
-+} common_node_header;
-+
-+/* __REISER4_NODE_H__ */
-+#endif
-+/*
-+ * Local variables:
-+ * c-indentation-style: "K&R"
-+ * mode-name: "LC"
-+ * c-basic-offset: 8
-+ * tab-width: 8
-+ * fill-column: 79
-+ * scroll-step: 1
-+ * End:
-+ */
-Index: linux-2.6.16/fs/reiser4/plugin/node/node40.c
-===================================================================
---- /dev/null
-+++ linux-2.6.16/fs/reiser4/plugin/node/node40.c
+diff -urN linux-2.6.22.orig/fs/reiser4/plugin/node/node40.c linux-2.6.22/fs/reiser4/plugin/node/node40.c
+--- linux-2.6.22.orig/fs/reiser4/plugin/node/node40.c  1970-01-01 03:00:00.000000000 +0300
++++ linux-2.6.22/fs/reiser4/plugin/node/node40.c       2007-07-29 00:25:34.988725466 +0400
 @@ -0,0 +1,2924 @@
 +/* Copyright 2001, 2002, 2003 by Hans Reiser, licensing governed by reiser4/README */
 +
@@ -55625,7 +54961,6 @@ Index: linux-2.6.16/fs/reiser4/plugin/node/node40.c
 +#define nh40_set_num_items(nh, value) put_unaligned(cpu_to_le16(value), &(nh)->nr_items)
 +#define nh40_set_mkfs_id(nh, value) put_unaligned(cpu_to_le32(value), &(nh)->mkfs_id)
 +
-+
 +/* plugin field of node header should be read/set by
 +   plugin_by_disk_id/save_disk_plugin */
 +
@@ -55950,8 +55285,8 @@ Index: linux-2.6.16/fs/reiser4/plugin/node/node40.c
 +                      /* screw up */
 +                      warning("nikita-587", "Key less than %i key in a node",
 +                              left);
-+                      print_key("key", key);
-+                      print_key("min", &bstop->key);
++                      reiser4_print_key("key", key);
++                      reiser4_print_key("min", &bstop->key);
 +                      print_coord_content("coord", coord);
 +                      return RETERR(-EIO);
 +              } else {
@@ -55965,7 +55300,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/node/node40.c
 +      if (unlikely(iplug == NULL)) {
 +              warning("nikita-588", "Unknown plugin %i",
 +                      le16_to_cpu(get_unaligned(&bstop->plugin_id)));
-+              print_key("key", key);
++              reiser4_print_key("key", key);
 +              print_coord_content("coord", coord);
 +              return RETERR(-EIO);
 +      }
@@ -56054,7 +55389,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/node/node40.c
 +      if (flags & REISER4_NODE_DKEYS)
 +              prev = *znode_get_ld_key((znode *) node);
 +      else
-+              prev = *min_key();
++              prev = *reiser4_min_key();
 +
 +      old_offset = 0;
 +      coord_init_zero(&coord);
@@ -56240,8 +55575,6 @@ Index: linux-2.6.16/fs/reiser4/plugin/node/node40.c
 +              node->nr_items = node40_num_of_items_internal(node);
 +              result = 0;
 +      }
-+      if (unlikely(result != 0))
-+              /* print_znode("node", node) */ ;
 +      return RETERR(result);
 +}
 +
@@ -56411,7 +55744,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/node/node40.c
 +                         from userspace was valid and data bytes were
 +                         available? How will we return -EFAULT of some kind
 +                         without this check? */
-+                      assert("nikita-3038", schedulable());
++                      assert("nikita-3038", reiser4_schedulable());
 +                      /* copy data from user space */
 +                      __copy_from_user(zdata(target->node) + offset,
 +                                       (const char __user *)data->data,
@@ -57628,7 +56961,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/node/node40.c
 +              else
 +                      reference = op->node;
 +              assert("nikita-2992", reference != NULL);
-+              cn = add_carry(info->todo, POOLO_BEFORE, reference);
++              cn = reiser4_add_carry(info->todo, POOLO_BEFORE, reference);
 +              if (IS_ERR(cn))
 +                      return PTR_ERR(cn);
 +              cn->parent = 1;
@@ -58047,7 +57380,8 @@ Index: linux-2.6.16/fs/reiser4/plugin/node/node40.c
 +          node40_num_of_items_internal(left) +
 +          node40_num_of_items_internal(right) - (mergeable ? 1 : 0);
 +      data =
-+              kmalloc(sizeof(struct shift_check) * nr_items, get_gfp_mask());
++              kmalloc(sizeof(struct shift_check) * nr_items,
++                      reiser4_ctx_gfp_mask_get());
 +      if (data != NULL) {
 +              coord_t coord;
 +              pos_in_node_t item_pos;
@@ -58071,8 +57405,8 @@ Index: linux-2.6.16/fs/reiser4/plugin/node/node40.c
 +                              break;
 +                      case EXTENT_POINTER_ID:
 +                              data[i].u.bytes =
-+                                  extent_size(&coord,
-+                                              coord_num_units(&coord));
++                                      reiser4_extent_size(&coord,
++                                                     coord_num_units(&coord));
 +                              break;
 +                      case COMPOUND_DIR_ID:
 +                              data[i].u.entries = coord_num_units(&coord);
@@ -58101,7 +57435,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/node/node40.c
 +                              break;
 +                      case EXTENT_POINTER_ID:
 +                              data[i - 1].u.bytes +=
-+                                  extent_size(&coord,
++                                  reiser4_extent_size(&coord,
 +                                              coord_num_units(&coord));
 +                              break;
 +                      case COMPOUND_DIR_ID:
@@ -58131,7 +57465,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/node/node40.c
 +                              break;
 +                      case EXTENT_POINTER_ID:
 +                              data[i].u.bytes =
-+                                  extent_size(&coord,
++                                  reiser4_extent_size(&coord,
 +                                              coord_num_units(&coord));
 +                              break;
 +                      case COMPOUND_DIR_ID:
@@ -58203,9 +57537,10 @@ Index: linux-2.6.16/fs/reiser4/plugin/node/node40.c
 +                              break;
 +                      case EXTENT_POINTER_ID:
 +                              assert("vs-1593",
-+                                     data[i].u.bytes == extent_size(&coord,
-+                                                                    coord_num_units
-+                                                                    (&coord)));
++                                     data[i].u.bytes ==
++                                     reiser4_extent_size(&coord,
++                                                         coord_num_units
++                                                         (&coord)));
 +                              break;
 +                      case COMPOUND_DIR_ID:
 +                              assert("vs-1594",
@@ -58225,7 +57560,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/node/node40.c
 +                              break;
 +                      case EXTENT_POINTER_ID:
 +                              last_bytes =
-+                                  extent_size(&coord,
++                                  reiser4_extent_size(&coord,
 +                                              coord_num_units(&coord));
 +                              break;
 +                      case COMPOUND_DIR_ID:
@@ -58257,9 +57592,9 @@ Index: linux-2.6.16/fs/reiser4/plugin/node/node40.c
 +              case EXTENT_POINTER_ID:
 +                      assert("vs-1597",
 +                             data[i - 1].u.bytes ==
-+                             last_bytes + extent_size(&coord,
-+                                                      coord_num_units
-+                                                      (&coord)));
++                             last_bytes + reiser4_extent_size(&coord,
++                                                              coord_num_units
++                                                              (&coord)));
 +                      break;
 +
 +              case COMPOUND_DIR_ID:
@@ -58291,9 +57626,10 @@ Index: linux-2.6.16/fs/reiser4/plugin/node/node40.c
 +                      break;
 +              case EXTENT_POINTER_ID:
 +                      assert("vs-1601",
-+                             data[i].u.bytes == extent_size(&coord,
-+                                                            coord_num_units
-+                                                            (&coord)));
++                             data[i].u.bytes ==
++                             reiser4_extent_size(&coord,
++                                                 coord_num_units
++                                                 (&coord)));
 +                      break;
 +              case COMPOUND_DIR_ID:
 +                      assert("vs-1602",
@@ -58455,169 +57791,578 @@ Index: linux-2.6.16/fs/reiser4/plugin/node/node40.c
 +
 +/* plugin->u.node.modify - not defined */
 +
-+/* plugin->u.node.max_item_size */
-+int max_item_size_node40(void)
-+{
-+      return reiser4_get_current_sb()->s_blocksize - sizeof(node40_header) -
-+          sizeof(item_header40);
-+}
++/* plugin->u.node.max_item_size */
++int max_item_size_node40(void)
++{
++      return reiser4_get_current_sb()->s_blocksize - sizeof(node40_header) -
++          sizeof(item_header40);
++}
++
++/* plugin->u.node.set_item_plugin */
++int set_item_plugin_node40(coord_t *coord, item_id id)
++{
++      item_header40 *ih;
++
++      ih = node40_ih_at_coord(coord);
++      put_unaligned(cpu_to_le16(id), &ih->plugin_id);
++      coord->iplugid = id;
++      return 0;
++}
++
++/*
++   Local variables:
++   c-indentation-style: "K&R"
++   mode-name: "LC"
++   c-basic-offset: 8
++   tab-width: 8
++   fill-column: 120
++   scroll-step: 1
++   End:
++*/
+diff -urN linux-2.6.22.orig/fs/reiser4/plugin/node/node40.h linux-2.6.22/fs/reiser4/plugin/node/node40.h
+--- linux-2.6.22.orig/fs/reiser4/plugin/node/node40.h  1970-01-01 03:00:00.000000000 +0300
++++ linux-2.6.22/fs/reiser4/plugin/node/node40.h       2007-07-29 00:25:34.988725466 +0400
+@@ -0,0 +1,125 @@
++/* Copyright 2001, 2002, 2003 by Hans Reiser, licensing governed by reiser4/README */
++
++#if !defined( __REISER4_NODE40_H__ )
++#define __REISER4_NODE40_H__
++
++#include "../../forward.h"
++#include "../../dformat.h"
++#include "node.h"
++
++#include <linux/types.h>
++
++/* format of node header for 40 node layouts. Keep bloat out of this struct.  */
++typedef struct node40_header {
++      /* identifier of node plugin. Must be located at the very beginning
++         of a node. */
++      common_node_header common_header;       /* this is 16 bits */
++      /* number of items. Should be first element in the node header,
++         because we haven't yet finally decided whether it shouldn't go into
++         common_header.
++       */
++/* NIKITA-FIXME-HANS: Create a macro such that if there is only one
++ * node format at compile time, and it is this one, accesses do not function dereference when
++ * accessing these fields (and otherwise they do).  Probably 80% of users will only have one node format at a time throughout the life of reiser4.  */
++      d16 nr_items;
++      /* free space in node measured in bytes */
++      d16 free_space;
++      /* offset to start of free space in node */
++      d16 free_space_start;
++      /* for reiser4_fsck.  When information about what is a free
++         block is corrupted, and we try to recover everything even
++         if marked as freed, then old versions of data may
++         duplicate newer versions, and this field allows us to
++         restore the newer version.  Also useful for when users
++         who don't have the new trashcan installed on their linux distro
++         delete the wrong files and send us desperate emails
++         offering $25 for them back.  */
++
++      /* magic field we need to tell formatted nodes NIKITA-FIXME-HANS: improve this comment */
++      d32 magic;
++      /* flushstamp is made of mk_id and write_counter. mk_id is an
++         id generated randomly at mkreiserfs time. So we can just
++         skip all nodes with different mk_id. write_counter is d64
++         incrementing counter of writes on disk. It is used for
++         choosing the newest data at fsck time. NIKITA-FIXME-HANS: why was field name changed but not comment? */
++
++      d32 mkfs_id;
++      d64 flush_id;
++      /* node flags to be used by fsck (reiser4ck or reiser4fsck?)
++         and repacker NIKITA-FIXME-HANS: say more or reference elsewhere that says more */
++      d16 flags;
++
++      /* 1 is leaf level, 2 is twig level, root is the numerically
++         largest level */
++      d8 level;
++
++      d8 pad;
++} PACKED node40_header;
++
++/* item headers are not standard across all node layouts, pass
++   pos_in_node to functions instead */
++typedef struct item_header40 {
++      /* key of item */
++      /*  0 */ reiser4_key key;
++      /* offset from start of a node measured in 8-byte chunks */
++      /* 24 */ d16 offset;
++      /* 26 */ d16 flags;
++      /* 28 */ d16 plugin_id;
++} PACKED item_header40;
++
++size_t item_overhead_node40(const znode * node, flow_t * aflow);
++size_t free_space_node40(znode * node);
++node_search_result lookup_node40(znode * node, const reiser4_key * key,
++                               lookup_bias bias, coord_t * coord);
++int num_of_items_node40(const znode * node);
++char *item_by_coord_node40(const coord_t * coord);
++int length_by_coord_node40(const coord_t * coord);
++item_plugin *plugin_by_coord_node40(const coord_t * coord);
++reiser4_key *key_at_node40(const coord_t * coord, reiser4_key * key);
++size_t estimate_node40(znode * node);
++int check_node40(const znode * node, __u32 flags, const char **error);
++int parse_node40(znode * node);
++int init_node40(znode * node);
++#ifdef GUESS_EXISTS
++int guess_node40(const znode * node);
++#endif
++void change_item_size_node40(coord_t * coord, int by);
++int create_item_node40(coord_t * target, const reiser4_key * key,
++                     reiser4_item_data * data, carry_plugin_info * info);
++void update_item_key_node40(coord_t * target, const reiser4_key * key,
++                          carry_plugin_info * info);
++int kill_node40(struct carry_kill_data *, carry_plugin_info *);
++int cut_node40(struct carry_cut_data *, carry_plugin_info *);
++int shift_node40(coord_t * from, znode * to, shift_direction pend,
++               /* if @from->node becomes
++                  empty - it will be deleted from
++                  the tree if this is set to 1
++                */
++               int delete_child, int including_stop_coord,
++               carry_plugin_info * info);
++
++int fast_insert_node40(const coord_t * coord);
++int fast_paste_node40(const coord_t * coord);
++int fast_cut_node40(const coord_t * coord);
++int max_item_size_node40(void);
++int prepare_removal_node40(znode * empty, carry_plugin_info * info);
++int set_item_plugin_node40(coord_t * coord, item_id id);
++int shrink_item_node40(coord_t * coord, int delta);
++
++#if REISER4_DEBUG
++void *shift_check_prepare(const znode *left, const znode *right);
++void shift_check(void *vp, const znode *left, const znode *right);
++#endif
++
++/* __REISER4_NODE40_H__ */
++#endif
++/*
++   Local variables:
++   c-indentation-style: "K&R"
++   mode-name: "LC"
++   c-basic-offset: 8
++   tab-width: 8
++   fill-column: 120
++   scroll-step: 1
++   End:
++*/
+diff -urN linux-2.6.22.orig/fs/reiser4/plugin/node/node.c linux-2.6.22/fs/reiser4/plugin/node/node.c
+--- linux-2.6.22.orig/fs/reiser4/plugin/node/node.c    1970-01-01 03:00:00.000000000 +0300
++++ linux-2.6.22/fs/reiser4/plugin/node/node.c 2007-07-29 00:25:34.988725466 +0400
+@@ -0,0 +1,131 @@
++/* Copyright 2001, 2002, 2003 by Hans Reiser, licensing governed by reiser4/README */
++
++/* Node plugin interface.
++
++   Description: The tree provides the abstraction of flows, which it
++   internally fragments into items which it stores in nodes.
++
++   A key_atom is a piece of data bound to a single key.
++
++   For reasonable space efficiency to be achieved it is often
++   necessary to store key_atoms in the nodes in the form of items, where
++   an item is a sequence of key_atoms of the same or similar type. It is
++   more space-efficient, because the item can implement (very)
++   efficient compression of key_atom's bodies using internal knowledge
++   about their semantics, and it can often avoid having a key for each
++   key_atom. Each type of item has specific operations implemented by its
++   item handler (see balance.c).
++
++   Rationale: the rest of the code (specifically balancing routines)
++   accesses leaf level nodes through this interface. This way we can
++   implement various block layouts and even combine various layouts
++   within the same tree. Balancing/allocating algorithms should not
++   care about peculiarities of splitting/merging specific item types,
++   but rather should leave that to the item's item handler.
++
++   Items, including those that provide the abstraction of flows, have
++   the property that if you move them in part or in whole to another
++   node, the balancing code invokes their is_left_mergeable()
++   item_operation to determine if they are mergeable with their new
++   neighbor in the node you have moved them to.  For some items the
++   is_left_mergeable() function always returns null.
++
++   When moving the bodies of items from one node to another:
++
++     if a partial item is shifted to another node the balancing code invokes
++     an item handler method to handle the item splitting.
++
++     if the balancing code needs to merge with an item in the node it
++     is shifting to, it will invoke an item handler method to handle
++     the item merging.
++
++     if it needs to move whole item bodies unchanged, the balancing code uses xmemcpy()
++     adjusting the item headers after the move is done using the node handler.
++*/
++
++#include "../../forward.h"
++#include "../../debug.h"
++#include "../../key.h"
++#include "../../coord.h"
++#include "../plugin_header.h"
++#include "../item/item.h"
++#include "node.h"
++#include "../plugin.h"
++#include "../../znode.h"
++#include "../../tree.h"
++#include "../../super.h"
++#include "../../reiser4.h"
++
++/**
++ * leftmost_key_in_node - get the smallest key in node
++ * @node:
++ * @key: store result here
++ *
++ * Stores the leftmost key of @node in @key.
++ */
++reiser4_key *leftmost_key_in_node(const znode *node, reiser4_key *key)
++{
++      assert("nikita-1634", node != NULL);
++      assert("nikita-1635", key != NULL);
++
++      if (!node_is_empty(node)) {
++              coord_t first_item;
++
++              coord_init_first_unit(&first_item, (znode *) node);
++              item_key_by_coord(&first_item, key);
++      } else
++              *key = *reiser4_max_key();
++      return key;
++}
++
++node_plugin node_plugins[LAST_NODE_ID] = {
++      [NODE40_ID] = {
++              .h = {
++                      .type_id = REISER4_NODE_PLUGIN_TYPE,
++                      .id = NODE40_ID,
++                      .pops = NULL,
++                      .label = "unified",
++                      .desc = "unified node layout",
++                      .linkage = {NULL, NULL}
++              },
++              .item_overhead = item_overhead_node40,
++              .free_space = free_space_node40,
++              .lookup = lookup_node40,
++              .num_of_items = num_of_items_node40,
++              .item_by_coord = item_by_coord_node40,
++              .length_by_coord = length_by_coord_node40,
++              .plugin_by_coord = plugin_by_coord_node40,
++              .key_at = key_at_node40,
++              .estimate = estimate_node40,
++              .check = check_node40,
++              .parse = parse_node40,
++              .init = init_node40,
++#ifdef GUESS_EXISTS
++              .guess = guess_node40,
++#endif
++              .change_item_size = change_item_size_node40,
++              .create_item = create_item_node40,
++              .update_item_key = update_item_key_node40,
++              .cut_and_kill = kill_node40,
++              .cut = cut_node40,
++              .shift = shift_node40,
++              .shrink_item = shrink_item_node40,
++              .fast_insert = fast_insert_node40,
++              .fast_paste = fast_paste_node40,
++              .fast_cut = fast_cut_node40,
++              .max_item_size = max_item_size_node40,
++              .prepare_removal = prepare_removal_node40,
++              .set_item_plugin = set_item_plugin_node40
++      }
++};
++
++/*
++   Local variables:
++   c-indentation-style: "K&R"
++   mode-name: "LC"
++   c-basic-offset: 8
++   tab-width: 8
++   fill-column: 120
++   scroll-step: 1
++   End:
++*/
+diff -urN linux-2.6.22.orig/fs/reiser4/plugin/node/node.h linux-2.6.22/fs/reiser4/plugin/node/node.h
+--- linux-2.6.22.orig/fs/reiser4/plugin/node/node.h    1970-01-01 03:00:00.000000000 +0300
++++ linux-2.6.22/fs/reiser4/plugin/node/node.h 2007-07-29 00:25:34.988725466 +0400
+@@ -0,0 +1,272 @@
++/* Copyright 2001, 2002, 2003 by Hans Reiser, licensing governed by reiser4/README */
++
++/* We need a definition of the default node layout here. */
++
++/* Generally speaking, it is best to have free space in the middle of the
++   node so that two sets of things can grow towards it, and to have the
++   item bodies on the left so that the last one of them grows into free
++   space.  We optimize for the case where we append new items to the end
++   of the node, or grow the last item, because it hurts nothing to so
++   optimize and it is a common special case to do massive insertions in
++   increasing key order (and one of cases more likely to have a real user
++   notice the delay time for).
++
++   formatted leaf default layout: (leaf1)
++
++   |node header:item bodies:free space:key + pluginid + item offset|
++
++   We grow towards the middle, optimizing layout for the case where we
++   append new items to the end of the node.  The node header is fixed
++   length.  Keys, and item offsets plus pluginids for the items
++   corresponding to them are in increasing key order, and are fixed
++   length.  Item offsets are relative to start of node (16 bits creating
++   a node size limit of 64k, 12 bits might be a better choice....).  Item
++   bodies are in decreasing key order.  Item bodies have a variable size.
++   There is a one to one to one mapping of keys to item offsets to item
++   bodies.  Item offsets consist of pointers to the zeroth byte of the
++   item body.  Item length equals the start of the next item minus the
++   start of this item, except the zeroth item whose length equals the end
++   of the node minus the start of that item (plus a byte).  In other
++   words, the item length is not recorded anywhere, and it does not need
++   to be since it is computable.
++
++   Leaf variable length items and keys layout : (lvar)
++
++   |node header:key offset + item offset + pluginid triplets:free space:key bodies:item bodies|
++
++   We grow towards the middle, optimizing layout for the case where we
++   append new items to the end of the node.  The node header is fixed
++   length.  Keys and item offsets for the items corresponding to them are
++   in increasing key order, and keys are variable length.  Item offsets
++   are relative to start of node (16 bits).  Item bodies are in
++   decreasing key order.  Item bodies have a variable size.  There is a
++   one to one to one mapping of keys to item offsets to item bodies.
++   Item offsets consist of pointers to the zeroth byte of the item body.
++   Item length equals the start of the next item's key minus the start of
++   this item, except the zeroth item whose length equals the end of the
++   node minus the start of that item (plus a byte).
++
++   leaf compressed keys layout: (lcomp)
++
++   |node header:key offset + key inherit + item offset pairs:free space:key bodies:item bodies|
++
++   We grow towards the middle, optimizing layout for the case where we
++   append new items to the end of the node.  The node header is fixed
++   length.  Keys and item offsets for the items corresponding to them are
++   in increasing key order, and keys are variable length.  The "key
++   inherit" field indicates how much of the key prefix is identical to
++   the previous key (stem compression as described in "Managing
++   Gigabytes" is used).  key_inherit is a one byte integer.  The
++   intra-node searches performed through this layout are linear searches,
++   and this is theorized to not hurt performance much due to the high
++   cost of processor stalls on modern CPUs, and the small number of keys
++   in a single node.  Item offsets are relative to start of node (16
++   bits).  Item bodies are in decreasing key order.  Item bodies have a
++   variable size.  There is a one to one to one mapping of keys to item
++   offsets to item bodies.  Item offsets consist of pointers to the
++   zeroth byte of the item body.  Item length equals the start of the
++   next item minus the start of this item, except the zeroth item whose
++   length equals the end of the node minus the start of that item (plus a
++   byte).  In other words, item length and key length is not recorded
++   anywhere, and it does not need to be since it is computable.
++
++   internal node default layout: (idef1)
++
++   just like ldef1 except that item bodies are either blocknrs of
++   children or extents, and moving them may require updating parent
++   pointers in the nodes that they point to.
++*/
++
++/* There is an inherent 3-way tradeoff between optimizing and
++   exchanging disks between different architectures and code
++   complexity.  This is optimal and simple and inexchangeable.
++   Someone else can do the code for exchanging disks and make it
++   complex. It would not be that hard.  Using other than the PAGE_SIZE
++   might be suboptimal.
++*/
++
++#if !defined( __REISER4_NODE_H__ )
++#define __REISER4_NODE_H__
++
++#define LEAF40_NODE_SIZE PAGE_CACHE_SIZE
++
++#include "../../dformat.h"
++#include "../plugin_header.h"
++
++#include <linux/types.h>
++
++typedef enum {
++      NS_FOUND = 0,
++      NS_NOT_FOUND = -ENOENT
++} node_search_result;
++
++/* Maximal possible space overhead for creation of new item in a node */
++#define REISER4_NODE_MAX_OVERHEAD ( sizeof( reiser4_key ) + 32 )
++
++typedef enum {
++      REISER4_NODE_DKEYS = (1 << 0),
++      REISER4_NODE_TREE_STABLE = (1 << 1)
++} reiser4_node_check_flag;
++
++/* cut and cut_and_kill have too long list of parameters. This structure is just to safe some space on stack */
++struct cut_list {
++      coord_t *from;
++      coord_t *to;
++      const reiser4_key *from_key;
++      const reiser4_key *to_key;
++      reiser4_key *smallest_removed;
++      carry_plugin_info *info;
++      __u32 flags;
++      struct inode *inode;    /* this is to pass list of eflushed jnodes down to extent_kill_hook */
++      lock_handle *left;
++      lock_handle *right;
++};
++
++struct carry_cut_data;
++struct carry_kill_data;
 +
-+/* plugin->u.node.set_item_plugin */
-+int set_item_plugin_node40(coord_t *coord, item_id id)
-+{
-+      item_header40 *ih;
++/* The responsibility of the node plugin is to store and give access
++   to the sequence of items within the node.  */
++typedef struct node_plugin {
++      /* generic plugin fields */
++      plugin_header h;
 +
-+      ih = node40_ih_at_coord(coord);
-+      put_unaligned(cpu_to_le16(id), &ih->plugin_id);
-+      coord->iplugid = id;
-+      return 0;
-+}
++      /* calculates the amount of space that will be required to store an
++         item which is in addition to the space consumed by the item body.
++         (the space consumed by the item body can be gotten by calling
++         item->estimate) */
++       size_t(*item_overhead) (const znode * node, flow_t * f);
 +
-+/*
-+   Local variables:
-+   c-indentation-style: "K&R"
-+   mode-name: "LC"
-+   c-basic-offset: 8
-+   tab-width: 8
-+   fill-column: 120
-+   scroll-step: 1
-+   End:
-+*/
-Index: linux-2.6.16/fs/reiser4/plugin/node/node40.h
-===================================================================
---- /dev/null
-+++ linux-2.6.16/fs/reiser4/plugin/node/node40.h
-@@ -0,0 +1,125 @@
-+/* Copyright 2001, 2002, 2003 by Hans Reiser, licensing governed by reiser4/README */
++      /* returns free space by looking into node (i.e., without using
++         znode->free_space). */
++       size_t(*free_space) (znode * node);
++      /* search within the node for the one item which might
++         contain the key, invoking item->search_within to search within
++         that item to see if it is in there */
++       node_search_result(*lookup) (znode * node, const reiser4_key * key,
++                                    lookup_bias bias, coord_t * coord);
++      /* number of items in node */
++      int (*num_of_items) (const znode * node);
 +
-+#if !defined( __REISER4_NODE40_H__ )
-+#define __REISER4_NODE40_H__
++      /* store information about item in @coord in @data */
++      /* break into several node ops, don't add any more uses of this before doing so */
++      /*int ( *item_at )( const coord_t *coord, reiser4_item_data *data ); */
++      char *(*item_by_coord) (const coord_t * coord);
++      int (*length_by_coord) (const coord_t * coord);
++      item_plugin *(*plugin_by_coord) (const coord_t * coord);
 +
-+#include "../../forward.h"
-+#include "../../dformat.h"
-+#include "node.h"
++      /* store item key in @key */
++      reiser4_key *(*key_at) (const coord_t * coord, reiser4_key * key);
++      /* conservatively estimate whether unit of what size can fit
++         into node. This estimation should be performed without
++         actually looking into the node's content (free space is saved in
++         znode). */
++       size_t(*estimate) (znode * node);
 +
-+#include <linux/types.h>
++      /* performs every consistency check the node plugin author could
++         imagine. Optional. */
++      int (*check) (const znode * node, __u32 flags, const char **error);
 +
-+/* format of node header for 40 node layouts. Keep bloat out of this struct.  */
-+typedef struct node40_header {
-+      /* identifier of node plugin. Must be located at the very beginning
-+         of a node. */
-+      common_node_header common_header;       /* this is 16 bits */
-+      /* number of items. Should be first element in the node header,
-+         because we haven't yet finally decided whether it shouldn't go into
-+         common_header.
++      /* Called when node is read into memory and node plugin is
++         already detected. This should read some data into znode (like free
++         space counter) and, optionally, check data consistency.
 +       */
-+/* NIKITA-FIXME-HANS: Create a macro such that if there is only one
-+ * node format at compile time, and it is this one, accesses do not function dereference when
-+ * accessing these fields (and otherwise they do).  Probably 80% of users will only have one node format at a time throughout the life of reiser4.  */
-+      d16 nr_items;
-+      /* free space in node measured in bytes */
-+      d16 free_space;
-+      /* offset to start of free space in node */
-+      d16 free_space_start;
-+      /* for reiser4_fsck.  When information about what is a free
-+         block is corrupted, and we try to recover everything even
-+         if marked as freed, then old versions of data may
-+         duplicate newer versions, and this field allows us to
-+         restore the newer version.  Also useful for when users
-+         who don't have the new trashcan installed on their linux distro
-+         delete the wrong files and send us desperate emails
-+         offering $25 for them back.  */
++      int (*parse) (znode * node);
++      /* This method is called on a new node to initialise plugin specific
++         data (header, etc.) */
++      int (*init) (znode * node);
++      /* Check whether @node content conforms to this plugin format.
++         Probably only useful after support for old V3.x formats is added.
++         Uncomment after 4.0 only.
++       */
++      /*      int ( *guess )( const znode *node ); */
++#if REISER4_DEBUG
++      void (*print) (const char *prefix, const znode * node, __u32 flags);
++#endif
++      /* change size of @item by @by bytes. @item->node has enough free
++         space. When @by > 0 - free space is appended to end of item. When
++         @by < 0 - item is truncated - it is assumed that last @by bytes if
++         the item are freed already */
++      void (*change_item_size) (coord_t * item, int by);
 +
-+      /* magic field we need to tell formatted nodes NIKITA-FIXME-HANS: improve this comment */
-+      d32 magic;
-+      /* flushstamp is made of mk_id and write_counter. mk_id is an
-+         id generated randomly at mkreiserfs time. So we can just
-+         skip all nodes with different mk_id. write_counter is d64
-+         incrementing counter of writes on disk. It is used for
-+         choosing the newest data at fsck time. NIKITA-FIXME-HANS: why was field name changed but not comment? */
++      /* create new item @length bytes long in coord @target */
++      int (*create_item) (coord_t * target, const reiser4_key * key,
++                          reiser4_item_data * data, carry_plugin_info * info);
 +
-+      d32 mkfs_id;
-+      d64 flush_id;
-+      /* node flags to be used by fsck (reiser4ck or reiser4fsck?)
-+         and repacker NIKITA-FIXME-HANS: say more or reference elsewhere that says more */
-+      d16 flags;
++      /* update key of item. */
++      void (*update_item_key) (coord_t * target, const reiser4_key * key,
++                               carry_plugin_info * info);
 +
-+      /* 1 is leaf level, 2 is twig level, root is the numerically
-+         largest level */
-+      d8 level;
++      int (*cut_and_kill) (struct carry_kill_data *, carry_plugin_info *);
++      int (*cut) (struct carry_cut_data *, carry_plugin_info *);
 +
-+      d8 pad;
-+} PACKED node40_header;
++      /*
++       * shrink item pointed to by @coord by @delta bytes.
++       */
++      int (*shrink_item) (coord_t * coord, int delta);
 +
-+/* item headers are not standard across all node layouts, pass
-+   pos_in_node to functions instead */
-+typedef struct item_header40 {
-+      /* key of item */
-+      /*  0 */ reiser4_key key;
-+      /* offset from start of a node measured in 8-byte chunks */
-+      /* 24 */ d16 offset;
-+      /* 26 */ d16 flags;
-+      /* 28 */ d16 plugin_id;
-+} PACKED item_header40;
++      /* copy as much as possible but not more than up to @stop from
++         @stop->node to @target. If (pend == append) then data from beginning of
++         @stop->node are copied to the end of @target. If (pend == prepend) then
++         data from the end of @stop->node are copied to the beginning of
++         @target. Copied data are removed from @stop->node. Information
++         about what to do on upper level is stored in @todo */
++      int (*shift) (coord_t * stop, znode * target, shift_direction pend,
++                    int delete_node, int including_insert_coord,
++                    carry_plugin_info * info);
++      /* return true if this node allows skip carry() in some situations
++         (see fs/reiser4/tree.c:insert_by_coord()). Reiser3.x format
++         emulation doesn't.
 +
-+size_t item_overhead_node40(const znode * node, flow_t * aflow);
-+size_t free_space_node40(znode * node);
-+node_search_result lookup_node40(znode * node, const reiser4_key * key,
-+                               lookup_bias bias, coord_t * coord);
-+int num_of_items_node40(const znode * node);
-+char *item_by_coord_node40(const coord_t * coord);
-+int length_by_coord_node40(const coord_t * coord);
-+item_plugin *plugin_by_coord_node40(const coord_t * coord);
-+reiser4_key *key_at_node40(const coord_t * coord, reiser4_key * key);
-+size_t estimate_node40(znode * node);
-+int check_node40(const znode * node, __u32 flags, const char **error);
-+int parse_node40(znode * node);
-+int init_node40(znode * node);
-+#ifdef GUESS_EXISTS
-+int guess_node40(const znode * node);
-+#endif
-+void change_item_size_node40(coord_t * coord, int by);
-+int create_item_node40(coord_t * target, const reiser4_key * key,
-+                     reiser4_item_data * data, carry_plugin_info * info);
-+void update_item_key_node40(coord_t * target, const reiser4_key * key,
-+                          carry_plugin_info * info);
-+int kill_node40(struct carry_kill_data *, carry_plugin_info *);
-+int cut_node40(struct carry_cut_data *, carry_plugin_info *);
-+int shift_node40(coord_t * from, znode * to, shift_direction pend,
-+               /* if @from->node becomes
-+                  empty - it will be deleted from
-+                  the tree if this is set to 1
-+                */
-+               int delete_child, int including_stop_coord,
-+               carry_plugin_info * info);
++         This will speedup insertions that doesn't require updates to the
++         parent, by bypassing initialisation of carry() structures. It's
++         believed that majority of insertions will fit there.
 +
-+int fast_insert_node40(const coord_t * coord);
-+int fast_paste_node40(const coord_t * coord);
-+int fast_cut_node40(const coord_t * coord);
-+int max_item_size_node40(void);
-+int prepare_removal_node40(znode * empty, carry_plugin_info * info);
-+int set_item_plugin_node40(coord_t * coord, item_id id);
-+int shrink_item_node40(coord_t * coord, int delta);
++       */
++      int (*fast_insert) (const coord_t * coord);
++      int (*fast_paste) (const coord_t * coord);
++      int (*fast_cut) (const coord_t * coord);
++      /* this limits max size of item which can be inserted into a node and
++         number of bytes item in a node may be appended with */
++      int (*max_item_size) (void);
++      int (*prepare_removal) (znode * empty, carry_plugin_info * info);
++      /* change plugin id of items which are in a node already. Currently it is Used in tail conversion for regular
++       * files */
++      int (*set_item_plugin) (coord_t * coord, item_id);
++} node_plugin;
++
++typedef enum {
++      /* standard unified node layout used for both leaf and internal
++         nodes */
++      NODE40_ID,
++      LAST_NODE_ID
++} reiser4_node_id;
 +
++extern reiser4_key *leftmost_key_in_node(const znode * node, reiser4_key * key);
 +#if REISER4_DEBUG
-+void *shift_check_prepare(const znode *left, const znode *right);
-+void shift_check(void *vp, const znode *left, const znode *right);
++extern void print_node_content(const char *prefix, const znode * node,
++                             __u32 flags);
 +#endif
 +
-+/* __REISER4_NODE40_H__ */
++extern void indent_znode(const znode * node);
++
++typedef struct common_node_header {
++      /*
++       * identifier of node plugin. Must be located at the very beginning of
++       * a node.
++       */
++      __le16 plugin_id;
++} common_node_header;
++
++/* __REISER4_NODE_H__ */
 +#endif
 +/*
-+   Local variables:
-+   c-indentation-style: "K&R"
-+   mode-name: "LC"
-+   c-basic-offset: 8
-+   tab-width: 8
-+   fill-column: 120
-+   scroll-step: 1
-+   End:
-+*/
-Index: linux-2.6.16/fs/reiser4/plugin/object.c
-===================================================================
---- /dev/null
-+++ linux-2.6.16/fs/reiser4/plugin/object.c
-@@ -0,0 +1,501 @@
++ * Local variables:
++ * c-indentation-style: "K&R"
++ * mode-name: "LC"
++ * c-basic-offset: 8
++ * tab-width: 8
++ * fill-column: 79
++ * scroll-step: 1
++ * End:
++ */
+diff -urN linux-2.6.22.orig/fs/reiser4/plugin/object.c linux-2.6.22/fs/reiser4/plugin/object.c
+--- linux-2.6.22.orig/fs/reiser4/plugin/object.c       1970-01-01 03:00:00.000000000 +0300
++++ linux-2.6.22/fs/reiser4/plugin/object.c    2007-07-29 00:25:34.992726502 +0400
+@@ -0,0 +1,516 @@
 +/* Copyright 2001, 2002, 2003 by Hans Reiser, licensing governed by
 + * reiser4/README */
 +
@@ -58688,10 +58433,16 @@ Index: linux-2.6.16/fs/reiser4/plugin/object.c
 +
 +#define dummyop ((void *)_dummyop)
 +
-+static int change_file(struct inode *inode, reiser4_plugin * plugin)
++static int change_file(struct inode *inode,
++                     reiser4_plugin * plugin,
++                     pset_member memb)
 +{
 +      /* cannot change object plugin of already existing object */
-+      return RETERR(-EINVAL);
++      if (memb == PSET_FILE)
++              return RETERR(-EINVAL);
++
++      /* Change PSET_CREATE */
++      return aset_set_unsafe(&reiser4_inode_data(inode)->pset, memb, plugin);
 +}
 +
 +static reiser4_plugin_ops file_plugin_ops = {
@@ -58707,20 +58458,22 @@ Index: linux-2.6.16/fs/reiser4/plugin/object.c
 +              .h = {
 +                      .type_id = REISER4_FILE_PLUGIN_TYPE,
 +                      .id = UNIX_FILE_PLUGIN_ID,
++                      .groups = (1 << REISER4_REGULAR_FILE),
 +                      .pops = &file_plugin_ops,
 +                      .label = "reg",
 +                      .desc = "regular file",
 +                      .linkage = {NULL, NULL},
 +              },
 +              .inode_ops = {
-+                      .permission = permission_common,
++                      .permission = reiser4_permission_common,
 +                      .setattr = setattr_unix_file,
-+                      .getattr = getattr_common
++                      .getattr = reiser4_getattr_common
 +              },
 +              .file_ops = {
 +                      .llseek = generic_file_llseek,
 +                      .read = read_unix_file,
 +                      .write = write_unix_file,
++                      .aio_read = generic_file_aio_read,
 +                      .ioctl = ioctl_unix_file,
 +                      .mmap = mmap_unix_file,
 +                      .open = open_unix_file,
@@ -58734,7 +58487,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/object.c
 +                      .sync_page = block_sync_page,
 +                      .writepages = writepages_unix_file,
 +                      .set_page_dirty = reiser4_set_page_dirty,
-+                      .readpages = reiser4_readpages,
++                      .readpages = readpages_unix_file,
 +                      .prepare_write = prepare_write_unix_file,
 +                      .commit_write = commit_write_unix_file,
 +                      .bmap = bmap_unix_file,
@@ -58746,10 +58499,10 @@ Index: linux-2.6.16/fs/reiser4/plugin/object.c
 +              .key_by_inode = key_by_inode_and_offset_common,
 +              .set_plug_in_inode = set_plug_in_inode_common,
 +              .adjust_to_parent = adjust_to_parent_common,
-+              .create_object = create_object_common,  /* this is not inode_operations's create */
++              .create_object = reiser4_create_object_common,
 +              .delete_object = delete_object_unix_file,
-+              .add_link = add_link_common,
-+              .rem_link = rem_link_common,
++              .add_link = reiser4_add_link_common,
++              .rem_link = reiser4_rem_link_common,
 +              .owns_item = owns_item_unix_file,
 +              .can_add_link = can_add_link_common,
 +              .detach = dummyop,
@@ -58774,29 +58527,30 @@ Index: linux-2.6.16/fs/reiser4/plugin/object.c
 +              .h = {
 +                      .type_id = REISER4_FILE_PLUGIN_TYPE,
 +                      .id = DIRECTORY_FILE_PLUGIN_ID,
++                      .groups = (1 << REISER4_DIRECTORY_FILE),
 +                      .pops = &file_plugin_ops,
 +                      .label = "dir",
 +                      .desc = "directory",
 +                      .linkage = {NULL, NULL}
 +              },
-+              .inode_ops = {NULL,},
-+              .file_ops = {NULL,},
-+              .as_ops = {NULL,},
++              .inode_ops = {.create = NULL},
++              .file_ops = {.owner = NULL},
++              .as_ops = {.writepage = NULL},
 +
 +              .write_sd_by_inode = write_sd_by_inode_common,
 +              .flow_by_inode = bugop,
 +              .key_by_inode = bugop,
 +              .set_plug_in_inode = set_plug_in_inode_common,
 +              .adjust_to_parent = adjust_to_parent_common_dir,
-+              .create_object = create_object_common,
-+              .delete_object = delete_directory_common,
-+              .add_link = add_link_common,
++              .create_object = reiser4_create_object_common,
++              .delete_object = reiser4_delete_dir_common,
++              .add_link = reiser4_add_link_common,
 +              .rem_link = rem_link_common_dir,
 +              .owns_item = owns_item_common_dir,
 +              .can_add_link = can_add_link_common,
 +              .can_rem_link = can_rem_link_common_dir,
-+              .detach = detach_common_dir,
-+              .bind = bind_common_dir,
++              .detach = reiser4_detach_common_dir,
++              .bind = reiser4_bind_common_dir,
 +              .safelink = safelink_common,
 +              .estimate = {
 +                      .create = estimate_create_common_dir,
@@ -58817,6 +58571,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/object.c
 +              .h = {
 +                      .type_id = REISER4_FILE_PLUGIN_TYPE,
 +                      .id = SYMLINK_FILE_PLUGIN_ID,
++                      .groups = (1 << REISER4_SYMLINK_FILE),
 +                      .pops = &file_plugin_ops,
 +                      .label = "symlink",
 +                      .desc = "symbolic link",
@@ -58824,22 +58579,22 @@ Index: linux-2.6.16/fs/reiser4/plugin/object.c
 +              },
 +              .inode_ops = {
 +                      .readlink = generic_readlink,
-+                      .follow_link = follow_link_common,
-+                      .permission = permission_common,
-+                      .setattr = setattr_common,
-+                      .getattr = getattr_common
++                      .follow_link = reiser4_follow_link_common,
++                      .permission = reiser4_permission_common,
++                      .setattr = reiser4_setattr_common,
++                      .getattr = reiser4_getattr_common
 +              },
 +              /* inode->i_fop of symlink is initialized by NULL in setup_inode_ops */
-+              .file_ops = {NULL,},
-+              .as_ops = {NULL,},
++              .file_ops = {.owner = NULL},
++              .as_ops = {.writepage = NULL},
 +
 +              .write_sd_by_inode = write_sd_by_inode_common,
 +              .set_plug_in_inode = set_plug_in_inode_common,
 +              .adjust_to_parent = adjust_to_parent_common,
-+              .create_object = create_symlink,
-+              .delete_object = delete_object_common,
-+              .add_link = add_link_common,
-+              .rem_link = rem_link_common,
++              .create_object = reiser4_create_symlink,
++              .delete_object = reiser4_delete_object_common,
++              .add_link = reiser4_add_link_common,
++              .rem_link = reiser4_rem_link_common,
 +              .can_add_link = can_add_link_common,
 +              .detach = dummyop,
 +              .bind = dummyop,
@@ -58864,6 +58619,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/object.c
 +              .h = {
 +                      .type_id = REISER4_FILE_PLUGIN_TYPE,
 +                      .id = SPECIAL_FILE_PLUGIN_ID,
++                      .groups = (1 << REISER4_SPECIAL_FILE),
 +                      .pops = &file_plugin_ops,
 +                      .label = "special",
 +                      .desc =
@@ -58871,22 +58627,22 @@ Index: linux-2.6.16/fs/reiser4/plugin/object.c
 +                      .linkage = {NULL, NULL}
 +              },
 +              .inode_ops = {
-+                      .permission = permission_common,
-+                      .setattr = setattr_common,
-+                      .getattr = getattr_common
++                      .permission = reiser4_permission_common,
++                      .setattr = reiser4_setattr_common,
++                      .getattr = reiser4_getattr_common
 +              },
 +              /* file_ops of special files (sockets, block, char, fifo) are
 +                 initialized by init_special_inode. */
-+              .file_ops = {NULL,},
-+              .as_ops = {NULL,},
++              .file_ops = {.owner = NULL},
++              .as_ops = {.writepage = NULL},
 +
 +              .write_sd_by_inode = write_sd_by_inode_common,
 +              .set_plug_in_inode = set_plug_in_inode_common,
 +              .adjust_to_parent = adjust_to_parent_common,
-+              .create_object = create_object_common,
-+              .delete_object = delete_object_common,
-+              .add_link = add_link_common,
-+              .rem_link = rem_link_common,
++              .create_object = reiser4_create_object_common,
++              .delete_object = reiser4_delete_object_common,
++              .add_link = reiser4_add_link_common,
++              .rem_link = reiser4_rem_link_common,
 +              .owns_item = owns_item_common,
 +              .can_add_link = can_add_link_common,
 +              .detach = dummyop,
@@ -58907,28 +58663,30 @@ Index: linux-2.6.16/fs/reiser4/plugin/object.c
 +                      .done = wire_done_common
 +              }
 +      },
-+      [CRC_FILE_PLUGIN_ID] = {
++      [CRYPTCOMPRESS_FILE_PLUGIN_ID] = {
 +              .h = {
 +                      .type_id = REISER4_FILE_PLUGIN_TYPE,
-+                      .id = CRC_FILE_PLUGIN_ID,
-+                      .pops = &cryptcompress_plugin_ops,
++                      .id = CRYPTCOMPRESS_FILE_PLUGIN_ID,
++                      .groups = (1 << REISER4_REGULAR_FILE),
++                      .pops = &file_plugin_ops,
 +                      .label = "cryptcompress",
 +                      .desc = "cryptcompress file",
 +                      .linkage = {NULL, NULL}
 +              },
 +              .inode_ops = {
-+                      .permission = permission_common,
-+                      .setattr = setattr_cryptcompress,
-+                      .getattr = getattr_common
++                      .permission = reiser4_permission_common,
++                      .setattr = prot_setattr_cryptcompress,
++                      .getattr = reiser4_getattr_common
 +              },
 +              .file_ops = {
 +                      .llseek = generic_file_llseek,
-+                      .read = read_cryptcompress,
-+                      .write = write_cryptcompress,
-+                      .mmap = mmap_cryptcompress,
-+                      .release = release_cryptcompress,
-+                      .fsync = sync_common,
-+                      .sendfile = sendfile_cryptcompress
++                      .read = prot_read_cryptcompress,
++                      .write = prot_write_cryptcompress,
++                      .aio_read = generic_file_aio_read,
++                      .mmap = prot_mmap_cryptcompress,
++                      .release = prot_release_cryptcompress,
++                      .fsync = reiser4_sync_common,
++                      .sendfile = prot_sendfile_cryptcompress
 +              },
 +              .as_ops = {
 +                      .writepage = reiser4_writepage,
@@ -58936,7 +58694,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/object.c
 +                      .sync_page = block_sync_page,
 +                      .writepages = writepages_cryptcompress,
 +                      .set_page_dirty = reiser4_set_page_dirty,
-+                      .readpages = reiser4_readpages,
++                      .readpages = readpages_cryptcompress,
 +                      .prepare_write = prepare_write_common,
 +                      .invalidatepage = reiser4_invalidatepage,
 +                      .releasepage = reiser4_releasepage
@@ -58947,10 +58705,10 @@ Index: linux-2.6.16/fs/reiser4/plugin/object.c
 +              .set_plug_in_inode = set_plug_in_inode_common,
 +              .adjust_to_parent = adjust_to_parent_cryptcompress,
 +              .create_object = create_cryptcompress,
-+              .open_object = open_cryptcompress,
-+              .delete_object = delete_cryptcompress,
-+              .add_link = add_link_common,
-+              .rem_link = rem_link_common,
++              .open_object = open_object_cryptcompress,
++              .delete_object = delete_object_cryptcompress,
++              .add_link = reiser4_add_link_common,
++              .rem_link = reiser4_rem_link_common,
 +              .owns_item = owns_item_common,
 +              .can_add_link = can_add_link_common,
 +              .detach = dummyop,
@@ -58974,7 +58732,9 @@ Index: linux-2.6.16/fs/reiser4/plugin/object.c
 +      }
 +};
 +
-+static int change_dir(struct inode *inode, reiser4_plugin * plugin)
++static int change_dir(struct inode *inode,
++                    reiser4_plugin * plugin,
++                    pset_member memb)
 +{
 +      /* cannot change dir plugin of already existing object */
 +      return RETERR(-EINVAL);
@@ -59000,25 +58760,25 @@ Index: linux-2.6.16/fs/reiser4/plugin/object.c
 +                      .linkage = {NULL, NULL}
 +              },
 +              .inode_ops = {
-+                      .create = create_common,
-+                      .lookup = lookup_common,
-+                      .link = link_common,
-+                      .unlink = unlink_common,
-+                      .symlink = symlink_common,
-+                      .mkdir = mkdir_common,
-+                      .rmdir = unlink_common,
-+                      .mknod = mknod_common,
-+                      .rename = rename_common,
-+                      .permission = permission_common,
-+                      .setattr = setattr_common,
-+                      .getattr = getattr_common
++                      .create = reiser4_create_common,
++                      .lookup = reiser4_lookup_common,
++                      .link = reiser4_link_common,
++                      .unlink = reiser4_unlink_common,
++                      .symlink = reiser4_symlink_common,
++                      .mkdir = reiser4_mkdir_common,
++                      .rmdir = reiser4_unlink_common,
++                      .mknod = reiser4_mknod_common,
++                      .rename = reiser4_rename_common,
++                      .permission = reiser4_permission_common,
++                      .setattr = reiser4_setattr_common,
++                      .getattr = reiser4_getattr_common
 +              },
 +              .file_ops = {
-+                      .llseek = llseek_common_dir,
++                      .llseek = reiser4_llseek_dir_common,
 +                      .read = generic_read_dir,
-+                      .readdir = readdir_common,
-+                      .release = release_dir_common,
-+                      .fsync = sync_common
++                      .readdir = reiser4_readdir_common,
++                      .release = reiser4_release_dir_common,
++                      .fsync = reiser4_sync_common
 +              },
 +              .as_ops = {
 +                      .writepage = bugop,
@@ -59036,12 +58796,12 @@ Index: linux-2.6.16/fs/reiser4/plugin/object.c
 +              .is_name_acceptable = is_name_acceptable_common,
 +              .build_entry_key = build_entry_key_hashed,
 +              .build_readdir_key = build_readdir_key_common,
-+              .add_entry = add_entry_common,
-+              .rem_entry = rem_entry_common,
-+              .init = init_common,
-+              .done = done_common,
-+              .attach = attach_common,
-+              .detach = detach_common,
++              .add_entry = reiser4_add_entry_common,
++              .rem_entry = reiser4_rem_entry_common,
++              .init = reiser4_dir_init_common,
++              .done = reiser4_dir_done_common,
++              .attach = reiser4_attach_common,
++              .detach = reiser4_detach_common,
 +              .estimate = {
 +                      .add_entry = estimate_add_entry_common,
 +                      .rem_entry = estimate_rem_entry_common,
@@ -59060,25 +58820,25 @@ Index: linux-2.6.16/fs/reiser4/plugin/object.c
 +                      .linkage = {NULL, NULL}
 +              },
 +              .inode_ops = {
-+                      .create = create_common,
-+                      .lookup = lookup_common,
-+                      .link = link_common,
-+                      .unlink = unlink_common,
-+                      .symlink = symlink_common,
-+                      .mkdir = mkdir_common,
-+                      .rmdir = unlink_common,
-+                      .mknod = mknod_common,
-+                      .rename = rename_common,
-+                      .permission = permission_common,
-+                      .setattr = setattr_common,
-+                      .getattr = getattr_common
++                      .create = reiser4_create_common,
++                      .lookup = reiser4_lookup_common,
++                      .link = reiser4_link_common,
++                      .unlink = reiser4_unlink_common,
++                      .symlink = reiser4_symlink_common,
++                      .mkdir = reiser4_mkdir_common,
++                      .rmdir = reiser4_unlink_common,
++                      .mknod = reiser4_mknod_common,
++                      .rename = reiser4_rename_common,
++                      .permission = reiser4_permission_common,
++                      .setattr = reiser4_setattr_common,
++                      .getattr = reiser4_getattr_common
 +              },
 +              .file_ops = {
-+                      .llseek = llseek_common_dir,
++                      .llseek = reiser4_llseek_dir_common,
 +                      .read = generic_read_dir,
-+                      .readdir = readdir_common,
-+                      .release = release_dir_common,
-+                      .fsync = sync_common
++                      .readdir = reiser4_readdir_common,
++                      .release = reiser4_release_dir_common,
++                      .fsync = reiser4_sync_common
 +              },
 +              .as_ops = {
 +                      .writepage = bugop,
@@ -59096,12 +58856,12 @@ Index: linux-2.6.16/fs/reiser4/plugin/object.c
 +              .is_name_acceptable = is_name_acceptable_common,
 +              .build_entry_key = build_entry_key_seekable,
 +              .build_readdir_key = build_readdir_key_common,
-+              .add_entry = add_entry_common,
-+              .rem_entry = rem_entry_common,
-+              .init = init_common,
-+              .done = done_common,
-+              .attach = attach_common,
-+              .detach = detach_common,
++              .add_entry = reiser4_add_entry_common,
++              .rem_entry = reiser4_rem_entry_common,
++              .init = reiser4_dir_init_common,
++              .done = reiser4_dir_done_common,
++              .attach = reiser4_attach_common,
++              .detach = reiser4_detach_common,
 +              .estimate = {
 +                      .add_entry = estimate_add_entry_common,
 +                      .rem_entry = estimate_rem_entry_common,
@@ -59119,10 +58879,9 @@ Index: linux-2.6.16/fs/reiser4/plugin/object.c
 +   fill-column: 120
 +   End:
 +*/
-Index: linux-2.6.16/fs/reiser4/plugin/object.h
-===================================================================
---- /dev/null
-+++ linux-2.6.16/fs/reiser4/plugin/object.h
+diff -urN linux-2.6.22.orig/fs/reiser4/plugin/object.h linux-2.6.22/fs/reiser4/plugin/object.h
+--- linux-2.6.22.orig/fs/reiser4/plugin/object.h       1970-01-01 03:00:00.000000000 +0300
++++ linux-2.6.22/fs/reiser4/plugin/object.h    2007-07-29 00:25:34.992726502 +0400
 @@ -0,0 +1,121 @@
 +/* Copyright 2002, 2003 by Hans Reiser, licensing governed by
 + * reiser4/README */
@@ -59135,31 +58894,33 @@ Index: linux-2.6.16/fs/reiser4/plugin/object.h
 +#include "../type_safe_hash.h"
 +
 +/* common implementations of inode operations */
-+int create_common(struct inode *parent, struct dentry *dentry,
-+                int mode, struct nameidata *);
-+struct dentry *lookup_common(struct inode *parent, struct dentry *dentry,
-+                           struct nameidata *nameidata);
-+int link_common(struct dentry *existing, struct inode *parent,
-+              struct dentry *newname);
-+int unlink_common(struct inode *parent, struct dentry *victim);
-+int mkdir_common(struct inode *parent, struct dentry *dentry, int mode);
-+int symlink_common(struct inode *parent, struct dentry *dentry,
++int reiser4_create_common(struct inode *parent, struct dentry *dentry,
++                        int mode, struct nameidata *);
++struct dentry * reiser4_lookup_common(struct inode *parent,
++                                    struct dentry *dentry,
++                                    struct nameidata *nameidata);
++int reiser4_link_common(struct dentry *existing, struct inode *parent,
++                      struct dentry *newname);
++int reiser4_unlink_common(struct inode *parent, struct dentry *victim);
++int reiser4_mkdir_common(struct inode *parent, struct dentry *dentry, int mode);
++int reiser4_symlink_common(struct inode *parent, struct dentry *dentry,
 +                 const char *linkname);
-+int mknod_common(struct inode *parent, struct dentry *dentry,
++int reiser4_mknod_common(struct inode *parent, struct dentry *dentry,
 +               int mode, dev_t rdev);
-+int rename_common(struct inode *old_dir, struct dentry *old_name,
-+                struct inode *new_dir, struct dentry *new_name);
-+void *follow_link_common(struct dentry *, struct nameidata *data);
-+int permission_common(struct inode *, int mask,       /* mode bits to check permissions for */
-+                    struct nameidata *nameidata);
-+int setattr_common(struct dentry *, struct iattr *);
-+int getattr_common(struct vfsmount *mnt, struct dentry *, struct kstat *);
++int reiser4_rename_common(struct inode *old_dir, struct dentry *old_name,
++                        struct inode *new_dir, struct dentry *new_name);
++void *reiser4_follow_link_common(struct dentry *, struct nameidata *data);
++int reiser4_permission_common(struct inode *, int mask,
++                            struct nameidata *nameidata);
++int reiser4_setattr_common(struct dentry *, struct iattr *);
++int reiser4_getattr_common(struct vfsmount *mnt, struct dentry *,
++                         struct kstat *);
 +
 +/* common implementations of file operations */
-+loff_t llseek_common_dir(struct file *, loff_t off, int origin);
-+int readdir_common(struct file *, void *dirent, filldir_t);
-+int release_dir_common(struct inode *, struct file *);
-+int sync_common(struct file *, struct dentry *, int datasync);
++loff_t reiser4_llseek_dir_common(struct file *, loff_t off, int origin);
++int reiser4_readdir_common(struct file *, void *dirent, filldir_t);
++int reiser4_release_dir_common(struct inode *, struct file *);
++int reiser4_sync_common(struct file *, struct dentry *, int datasync);
 +
 +/* common implementations of address space operations */
 +int prepare_write_common(struct file *, struct page *, unsigned from,
@@ -59176,20 +58937,19 @@ Index: linux-2.6.16/fs/reiser4/plugin/object.h
 +                              struct inode *root);
 +int adjust_to_parent_cryptcompress(struct inode *object, struct inode *parent,
 +                                 struct inode *root);
-+int create_object_common(struct inode *object, struct inode *parent,
-+                       reiser4_object_create_data *);
-+int delete_object_common(struct inode *);
-+int delete_directory_common(struct inode *);
-+int add_link_common(struct inode *object, struct inode *parent);
-+int rem_link_common(struct inode *object, struct inode *parent);
++int reiser4_create_object_common(struct inode *object, struct inode *parent,
++                               reiser4_object_create_data *);
++int reiser4_delete_object_common(struct inode *);
++int reiser4_delete_dir_common(struct inode *);
++int reiser4_add_link_common(struct inode *object, struct inode *parent);
++int reiser4_rem_link_common(struct inode *object, struct inode *parent);
 +int rem_link_common_dir(struct inode *object, struct inode *parent);
 +int owns_item_common(const struct inode *, const coord_t *);
 +int owns_item_common_dir(const struct inode *, const coord_t *);
 +int can_add_link_common(const struct inode *);
 +int can_rem_link_common_dir(const struct inode *);
-+int detach_common_dir(struct inode *child, struct inode *parent);
-+int open_cryptcompress(struct inode * inode, struct file * file);
-+int bind_common_dir(struct inode *child, struct inode *parent);
++int reiser4_detach_common_dir(struct inode *child, struct inode *parent);
++int reiser4_bind_common_dir(struct inode *child, struct inode *parent);
 +int safelink_common(struct inode *, reiser4_safe_link_t, __u64 value);
 +reiser4_block_nr estimate_create_common(const struct inode *);
 +reiser4_block_nr estimate_create_common_dir(const struct inode *);
@@ -59210,15 +58970,15 @@ Index: linux-2.6.16/fs/reiser4/plugin/object.h
 +void build_entry_key_common(const struct inode *,
 +                          const struct qstr *qname, reiser4_key *);
 +int build_readdir_key_common(struct file *dir, reiser4_key *);
-+int add_entry_common(struct inode *object, struct dentry *where,
++int reiser4_add_entry_common(struct inode *object, struct dentry *where,
 +                   reiser4_object_create_data *, reiser4_dir_entry_desc *);
-+int rem_entry_common(struct inode *object, struct dentry *where,
++int reiser4_rem_entry_common(struct inode *object, struct dentry *where,
 +                   reiser4_dir_entry_desc *);
-+int init_common(struct inode *object, struct inode *parent,
-+              reiser4_object_create_data *);
-+int done_common(struct inode *);
-+int attach_common(struct inode *child, struct inode *parent);
-+int detach_common(struct inode *object, struct inode *parent);
++int reiser4_dir_init_common(struct inode *object, struct inode *parent,
++                          reiser4_object_create_data *);
++int reiser4_dir_done_common(struct inode *);
++int reiser4_attach_common(struct inode *child, struct inode *parent);
++int reiser4_detach_common(struct inode *object, struct inode *parent);
 +reiser4_block_nr estimate_add_entry_common(const struct inode *);
 +reiser4_block_nr estimate_rem_entry_common(const struct inode *);
 +reiser4_block_nr dir_estimate_unlink_common(const struct inode *,
@@ -59232,7 +58992,6 @@ Index: linux-2.6.16/fs/reiser4/plugin/object.h
 +int lookup_sd(struct inode *, znode_lock_mode, coord_t *, lock_handle *,
 +            const reiser4_key *, int silent);
 +
-+
 +/* __FS_REISER4_PLUGIN_OBJECT_H__ */
 +#endif
 +
@@ -59245,11 +59004,10 @@ Index: linux-2.6.16/fs/reiser4/plugin/object.h
 +   fill-column: 120
 +   End:
 +*/
-Index: linux-2.6.16/fs/reiser4/plugin/plugin.c
-===================================================================
---- /dev/null
-+++ linux-2.6.16/fs/reiser4/plugin/plugin.c
-@@ -0,0 +1,533 @@
+diff -urN linux-2.6.22.orig/fs/reiser4/plugin/plugin.c linux-2.6.22/fs/reiser4/plugin/plugin.c
+--- linux-2.6.22.orig/fs/reiser4/plugin/plugin.c       1970-01-01 03:00:00.000000000 +0300
++++ linux-2.6.22/fs/reiser4/plugin/plugin.c    2007-07-29 00:25:34.992726502 +0400
+@@ -0,0 +1,559 @@
 +/* Copyright 2001, 2002, 2003 by Hans Reiser, licensing governed by
 + * reiser4/README */
 +
@@ -59263,14 +59021,8 @@ Index: linux-2.6.16/fs/reiser4/plugin/plugin.c
 +
 +   Plugins are classified into several disjoint "types". Plugins
 +   belonging to the particular plugin type are termed "instances" of
-+   this type. Currently the following types are present:
-+
-+    . object plugin
-+    . hash plugin
-+    . tail plugin
-+    . perm plugin
-+    . item plugin
-+    . node layout plugin
++   this type. Existing types are listed by enum reiser4_plugin_type
++   (see plugin/plugin_header.h)
 +
 +NIKITA-FIXME-HANS: update this list, and review this entire comment for currency
 +
@@ -59287,8 +59039,6 @@ Index: linux-2.6.16/fs/reiser4/plugin/plugin.c
 +   Tail plugins (or, more precisely, tail policy plugins) determine
 +   when last part of the file should be stored in a formatted item.
 +
-+   Perm plugins control permissions granted for a process accessing a file.
-+
 +   Scope and lookup:
 +
 +   label such that pair ( type_label, plugin_label ) is unique.  This
@@ -59301,20 +59051,15 @@ Index: linux-2.6.16/fs/reiser4/plugin/plugin.c
 +   store the offset into the plugin array for that plugin type as the
 +   plugin id in the stat data of the filesystem object.
 +
-+   plugin_labels have meaning for the user interface that assigns
-+   plugins to files, and may someday have meaning for dynamic loading of
-+   plugins and for copying of plugins from one fs instance to
-+   another by utilities like cp and tar.
-+
 +   Internal kernel plugin type identifier (index in plugins[] array) is
 +   of type reiser4_plugin_type. Set of available plugin types is
 +   currently static, but dynamic loading doesn't seem to pose
 +   insurmountable problems.
 +
 +   Within each type plugins are addressed by the identifiers of type
-+   reiser4_plugin_id (indices in
-+   reiser4_plugin_type_data.builtin[]). Such identifiers are only
-+   required to be unique within one type, not globally.
++   reiser4_plugin_id (indices in reiser4_plugin_type_data.builtin[]).
++   Such identifiers are only required to be unique within one type,
++   not globally.
 +
 +   Thus, plugin in memory is uniquely identified by the pair (type_id,
 +   id).
@@ -59335,9 +59080,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/plugin.c
 +
 +   With each subject the plugin possibly stores some state. For example,
 +   the state of a directory plugin (instance of object plugin type) is pointer
-+   to hash plugin (if directories always use hashing that is). State of
-+   audit plugin is file descriptor (struct file) of log file or some
-+   magic value to do logging through printk().
++   to hash plugin (if directories always use hashing that is).
 +
 +   Interface:
 +
@@ -59349,7 +59092,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/plugin.c
 +   .desc fields of reiser4_plugin_header respectively. It's possible to
 +   locate plugin by the pair of labels.
 +
-+   Features:
++   Features (not implemented):
 +
 +    . user-level plugin manipulations:
 +      + reiser4("filename/..file_plugin<='audit'");
@@ -59359,7 +59102,9 @@ Index: linux-2.6.16/fs/reiser4/plugin/plugin.c
 +      Utilities are not of primary priority. Possibly they will be not
 +      working on v4.0
 +
-+NIKITA-FIXME-HANS: this should be a mkreiserfs option not a mount option, do you agree?  I don't think that specifying it at mount time, and then changing it with each mount, is a good model for usage.
++   NIKITA-FIXME-HANS: this should be a mkreiserfs option not a mount
++   option, do you agree?  I don't think that specifying it at mount time,
++   and then changing it with each mount, is a good model for usage.
 +
 +    . mount option "plug" to set-up plugins of root-directory.
 +      "plug=foo:bar" will set "bar" as default plugin of type "foo".
@@ -59387,7 +59132,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/plugin.c
 +
 +    . perm:acl
 +
-+    d audi---audit plugin intercepting and possibly logging all
++    . audi---audit plugin intercepting and possibly logging all
 +      accesses to object. Requires to put stub functions in file_operations
 +      in stead of generic_file_*.
 +
@@ -59412,10 +59157,10 @@ Index: linux-2.6.16/fs/reiser4/plugin/plugin.c
 +   but not for directories, how such plugins would be inherited?
 +    . always store them with directories also
 +
-+NIKTIA-FIXME-HANS: Do the line above.  It is not exclusive of doing the line below which is also useful.
++NIKTIA-FIXME-HANS: Do the line above.  It is not exclusive of doing
++the line below which is also useful.
 +
 +    . use inheritance hierarchy, independent of file-system namespace
-+
 +*/
 +
 +#include "../debug.h"
@@ -59433,16 +59178,9 @@ Index: linux-2.6.16/fs/reiser4/plugin/plugin.c
 +
 +#include <linux/fs.h>         /* for struct super_block  */
 +
-+/* public interface */
-+
-+/* initialise plugin sub-system. Just call this once on reiser4 startup. */
-+int init_plugins(void);
-+int setup_plugins(struct super_block *super, reiser4_plugin ** area);
-+int locate_plugin(struct inode *inode, plugin_locator * loc);
-+
-+
-+/**
-+ * init_plugins - initialize plugins
++/*
++ * init_plugins - initialize plugin sub-system.
++ * Just call this once on reiser4 startup.
 + *
 + * Initializes plugin sub-system. It is part of reiser4 module
 + * initialization. For each plugin of each type init method is called and each
@@ -59453,7 +59191,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/plugin.c
 +      reiser4_plugin_type type_id;
 +
 +      for (type_id = 0; type_id < REISER4_PLUGIN_TYPES; ++type_id) {
-+              reiser4_plugin_type_data *ptype;
++              struct reiser4_plugin_type_data *ptype;
 +              int i;
 +
 +              ptype = &plugins[type_id];
@@ -59488,22 +59226,21 @@ Index: linux-2.6.16/fs/reiser4/plugin/plugin.c
 +}
 +
 +/* true if plugin type id is valid */
-+int is_type_id_valid(reiser4_plugin_type type_id /* plugin type id */ )
++int is_plugin_type_valid(reiser4_plugin_type type)
 +{
-+      /* "type_id" is unsigned, so no comparison with 0 is
++      /* "type" is unsigned, so no comparison with 0 is
 +         necessary */
-+      return (type_id < REISER4_PLUGIN_TYPES);
++      return (type < REISER4_PLUGIN_TYPES);
 +}
 +
 +/* true if plugin id is valid */
-+int is_plugin_id_valid(reiser4_plugin_type type_id /* plugin type id */ ,
-+                     reiser4_plugin_id id /* plugin id */ )
++int is_plugin_id_valid(reiser4_plugin_type type, reiser4_plugin_id id)
 +{
-+      assert("nikita-1653", is_type_id_valid(type_id));
-+      return id < plugins[type_id].builtin_num;
++      assert("nikita-1653", is_plugin_type_valid(type));
++      return id < plugins[type].builtin_num;
 +}
 +
-+/* return plugin by its @type_id and @id.
++/* return plugin by its @type and @id.
 +
 +   Both arguments are checked for validness: this is supposed to be called
 +   from user-level.
@@ -59513,22 +59250,21 @@ Index: linux-2.6.16/fs/reiser4/plugin/plugin.c
 +comment really confused me on the first reading....
 +
 +*/
-+reiser4_plugin *plugin_by_unsafe_id(reiser4_plugin_type type_id       /* plugin
-+                                                               * type id,
-+                                                               * unchecked */ ,
++reiser4_plugin *plugin_by_unsafe_id(reiser4_plugin_type type /* plugin type
++                                                               * unchecked */,
 +                                  reiser4_plugin_id id        /* plugin id,
-+                                                               * unchecked */ )
++                                                               * unchecked */)
 +{
-+      if (is_type_id_valid(type_id)) {
-+              if (is_plugin_id_valid(type_id, id))
-+                      return plugin_at(&plugins[type_id], id);
++      if (is_plugin_type_valid(type)) {
++              if (is_plugin_id_valid(type, id))
++                      return plugin_at(&plugins[type], id);
 +              else
 +                      /* id out of bounds */
 +                      warning("nikita-2913",
-+                              "Invalid plugin id: [%i:%i]", type_id, id);
++                              "Invalid plugin id: [%i:%i]", type, id);
 +      } else
 +              /* type_id out of bounds */
-+              warning("nikita-2914", "Invalid type_id: %i", type_id);
++              warning("nikita-2914", "Invalid type_id: %i", type);
 +      return NULL;
 +}
 +
@@ -59550,28 +59286,19 @@ Index: linux-2.6.16/fs/reiser4/plugin/plugin.c
 +}
 +
 +/* list of all plugins of given type */
-+struct list_head *get_plugin_list(reiser4_plugin_type type_id /* plugin type
-+                                                               * id */ )
++struct list_head *get_plugin_list(reiser4_plugin_type type)
 +{
-+      assert("nikita-1056", is_type_id_valid(type_id));
-+      return &plugins[type_id].plugins_list;
-+}
-+
-+int grab_plugin(struct inode *self, struct inode *ancestor, pset_member memb)
-+{
-+      reiser4_plugin *plug;
-+      reiser4_inode *parent;
-+
-+      parent = reiser4_inode_data(ancestor);
-+      plug = pset_get(parent->hset, memb) ? : pset_get(parent->pset, memb);
-+      return grab_plugin_from(self, memb, plug);
++      assert("nikita-1056", is_plugin_type_valid(type));
++      return &plugins[type].plugins_list;
 +}
 +
-+static void update_plugin_mask(reiser4_inode * info, pset_member memb)
++static void update_pset_mask(reiser4_inode * info, pset_member memb)
 +{
 +      struct dentry *rootdir;
 +      reiser4_inode *root;
 +
++      assert("edward-1443", memb != PSET_FILE);
++
 +      rootdir = inode_by_reiser4_inode(info)->i_sb->s_root;
 +      if (rootdir != NULL) {
 +              root = reiser4_inode_data(rootdir->d_inode);
@@ -59579,43 +59306,110 @@ Index: linux-2.6.16/fs/reiser4/plugin/plugin.c
 +               * if inode is different from the default one, or we are
 +               * changing plugin of root directory, update plugin_mask
 +               */
-+              if (pset_get(info->pset, memb) != pset_get(root->pset, memb) ||
++              if (aset_get(info->pset, memb) !=
++                  aset_get(root->pset, memb) ||
 +                  info == root)
 +                      info->plugin_mask |= (1 << memb);
++              else
++                      info->plugin_mask &= ~(1 << memb);
 +      }
 +}
 +
-+int
-+grab_plugin_from(struct inode *self, pset_member memb, reiser4_plugin * plug)
++/* Get specified plugin set member from parent,
++   or from fs-defaults (if no parent is given) and
++   install the result to pset of @self */
++int grab_plugin_pset(struct inode *self,
++                   struct inode *ancestor,
++                   pset_member memb)
 +{
++      reiser4_plugin *plug;
 +      reiser4_inode *info;
 +      int result = 0;
 +
++      /* Do not grab if initialised already. */
 +      info = reiser4_inode_data(self);
-+      if (pset_get(info->pset, memb) == NULL) {
-+              result = pset_set(&info->pset, memb, plug);
-+              if (result == 0)
-+                      update_plugin_mask(info, memb);
++      if (aset_get(info->pset, memb) != NULL)
++              return 0;
++      if (ancestor) {
++              reiser4_inode *parent;
++
++              parent = reiser4_inode_data(ancestor);
++              plug = aset_get(parent->hset, memb) ? :
++                      aset_get(parent->pset, memb);
++      }
++      else
++              plug = get_default_plugin(memb);
++
++      result = set_plugin(&info->pset, memb, plug);
++      if (result == 0) {
++              if (!ancestor || self->i_sb->s_root->d_inode != self)
++                      update_pset_mask(info, memb);
++      }
++      return result;
++}
++
++/* Take missing pset members from root inode */
++int finish_pset(struct inode *inode)
++{
++      reiser4_plugin *plug;
++      reiser4_inode *root;
++      reiser4_inode *info;
++      pset_member memb;
++      int result = 0;
++
++      root = reiser4_inode_data(inode->i_sb->s_root->d_inode);
++      info = reiser4_inode_data(inode);
++
++      assert("edward-1455", root != NULL);
++      assert("edward-1456", info != NULL);
++
++      /* file and directory plugins are already initialized. */
++      for (memb = PSET_DIR + 1; memb < PSET_LAST; ++memb) {
++
++              /* Do not grab if initialised already. */
++              if (aset_get(info->pset, memb) != NULL)
++                      continue;
++
++              plug = aset_get(root->pset, memb);
++              result = set_plugin(&info->pset, memb, plug);
++              if (result != 0)
++                      break;
++      }
++      if (result != 0) {
++              warning("nikita-3447",
++                      "Cannot set up plugins for %lli",
++                      (unsigned long long)
++                      get_inode_oid(inode));
 +      }
 +      return result;
 +}
 +
-+int force_plugin(struct inode *self, pset_member memb, reiser4_plugin * plug)
++int force_plugin_pset(struct inode *self, pset_member memb, reiser4_plugin * plug)
 +{
 +      reiser4_inode *info;
 +      int result = 0;
 +
++      if (!self->i_sb->s_root || self->i_sb->s_root->d_inode == self) {
++              /* Changing pset in the root object. */
++              return RETERR(-EINVAL);
++      }
++
 +      info = reiser4_inode_data(self);
 +      if (plug->h.pops != NULL && plug->h.pops->change != NULL)
-+              result = plug->h.pops->change(self, plug);
++              result = plug->h.pops->change(self, plug, memb);
 +      else
-+              result = pset_set(&info->pset, memb, plug);
-+      if (result == 0)
-+              update_plugin_mask(info, memb);
++              result = aset_set_unsafe(&info->pset, memb, plug);
++      if (result == 0) {
++              __u16 oldmask = info->plugin_mask;
++
++              update_pset_mask(info, memb);
++              if (oldmask != info->plugin_mask)
++                      reiser4_inode_clr_flag(self, REISER4_SDLEN_KNOWN);
++      }
 +      return result;
 +}
 +
-+reiser4_plugin_type_data plugins[REISER4_PLUGIN_TYPES] = {
++struct reiser4_plugin_type_data plugins[REISER4_PLUGIN_TYPES] = {
 +      /* C90 initializers */
 +      [REISER4_FILE_PLUGIN_TYPE] = {
 +              .type_id = REISER4_FILE_PLUGIN_TYPE,
@@ -59761,16 +59555,6 @@ Index: linux-2.6.16/fs/reiser4/plugin/plugin.c
 +              .builtin = cluster_plugins,
 +              .plugins_list = {NULL, NULL},
 +              .size = sizeof(cluster_plugin)
-+      },
-+      [REISER4_REGULAR_PLUGIN_TYPE] = {
-+              .type_id = REISER4_REGULAR_PLUGIN_TYPE,
-+              .label = "regular",
-+              .desc = "Defines kind of regular file",
-+              .builtin_num =
-+              sizeof_array(regular_plugins),
-+              .builtin = regular_plugins,
-+              .plugins_list = {NULL, NULL},
-+              .size = sizeof(regular_plugin)
 +      }
 +};
 +
@@ -59783,11 +59567,10 @@ Index: linux-2.6.16/fs/reiser4/plugin/plugin.c
 + * fill-column: 120
 + * End:
 + */
-Index: linux-2.6.16/fs/reiser4/plugin/plugin.h
-===================================================================
---- /dev/null
-+++ linux-2.6.16/fs/reiser4/plugin/plugin.h
-@@ -0,0 +1,936 @@
+diff -urN linux-2.6.22.orig/fs/reiser4/plugin/plugin.h linux-2.6.22/fs/reiser4/plugin/plugin.h
+--- linux-2.6.22.orig/fs/reiser4/plugin/plugin.h       1970-01-01 03:00:00.000000000 +0300
++++ linux-2.6.22/fs/reiser4/plugin/plugin.h    2007-07-29 00:25:34.996727537 +0400
+@@ -0,0 +1,899 @@
 +/* Copyright 2001, 2002, 2003 by Hans Reiser, licensing governed by reiser4/README */
 +
 +/* Basic plugin data-types.
@@ -59940,6 +59723,32 @@ Index: linux-2.6.16/fs/reiser4/plugin/plugin.h
 + * them, and which are only invoked by other plugins.
 + */
 +
++/* This should be incremented with each new contributed
++   pair (plugin type, plugin id).
++   NOTE: Make sure there is a release of reiser4progs
++   with the corresponding version number */
++#define PLUGIN_LIBRARY_VERSION 0
++
++ /* enumeration of fields within plugin_set */
++typedef enum {
++      PSET_FILE,
++      PSET_DIR,               /* PSET_FILE and PSET_DIR should be first elements:
++                               * inode.c:read_inode() depends on this. */
++      PSET_PERM,
++      PSET_FORMATTING,
++      PSET_HASH,
++      PSET_FIBRATION,
++      PSET_SD,
++      PSET_DIR_ITEM,
++      PSET_CIPHER,
++      PSET_DIGEST,
++      PSET_COMPRESSION,
++      PSET_COMPRESSION_MODE,
++      PSET_CLUSTER,
++      PSET_CREATE,
++      PSET_LAST
++} pset_member;
++
 +/* builtin file-plugins */
 +typedef enum {
 +      /* regular file */
@@ -59952,7 +59761,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/plugin.h
 +         sockets  */
 +      SPECIAL_FILE_PLUGIN_ID,
 +      /* regular cryptcompress file */
-+      CRC_FILE_PLUGIN_ID,
++      CRYPTCOMPRESS_FILE_PLUGIN_ID,
 +      /* number of file plugins. Used as size of arrays to hold
 +         file plugins. */
 +      LAST_FILE_PLUGIN_ID
@@ -60239,8 +60048,8 @@ Index: linux-2.6.16/fs/reiser4/plugin/plugin.h
 +typedef struct cipher_plugin {
 +      /* generic fields */
 +      plugin_header h;
-+      struct crypto_tfm * (*alloc) (void);
-+      void (*free) (struct crypto_tfm * tfm);
++      struct crypto_blkcipher * (*alloc) (void);
++      void (*free) (struct crypto_blkcipher * tfm);
 +      /* Offset translator. For each offset this returns (k * offset), where
 +         k (k >= 1) is an expansion factor of the cipher algorithm.
 +         For all symmetric algorithms k == 1. For asymmetric algorithms (which
@@ -60266,8 +60075,8 @@ Index: linux-2.6.16/fs/reiser4/plugin/plugin.h
 +      plugin_header h;
 +      /* fingerprint size in bytes */
 +      int fipsize;
-+      struct crypto_tfm * (*alloc) (void);
-+      void (*free) (struct crypto_tfm * tfm);
++      struct crypto_hash * (*alloc) (void);
++      void (*free) (struct crypto_hash * tfm);
 +} digest_plugin;
 +
 +typedef struct compression_plugin {
@@ -60301,13 +60110,6 @@ Index: linux-2.6.16/fs/reiser4/plugin/plugin.h
 +      int (*discard_hook) (struct inode * inode, cloff_t index);
 +} compression_mode_plugin;
 +
-+typedef struct regular_plugin {
-+      /* generic fields */
-+      plugin_header h;
-+      /* file plugin id which implements regular file */
-+      reiser4_file_id id;
-+} regular_plugin;
-+
 +typedef struct cluster_plugin {
 +      /* generic fields */
 +      plugin_header h;
@@ -60366,6 +60168,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/plugin.h
 +      int (*release) (struct super_block *);
 +      jnode *(*log_super) (struct super_block *);
 +      int (*check_open) (const struct inode * object);
++      int (*version_update) (struct super_block *);
 +} disk_format_plugin;
 +
 +struct jnode_plugin {
@@ -60428,8 +60231,6 @@ Index: linux-2.6.16/fs/reiser4/plugin/plugin.h
 +      compression_mode_plugin compression_mode;
 +      /* cluster plugin, used by object plugin */
 +      cluster_plugin clust;
-+      /* regular plugin, used by directory plugin */
-+      regular_plugin regular;
 +      /* place-holder for new plugin types that can be registered
 +         dynamically, and used by other dynamically loaded plugins.  */
 +      void *generic;
@@ -60454,7 +60255,8 @@ Index: linux-2.6.16/fs/reiser4/plugin/plugin.h
 +      int alignment;
 +      /* install itself into given inode. This can return error
 +         (e.g., you cannot change hash of non-empty directory). */
-+      int (*change) (struct inode * inode, reiser4_plugin * plugin);
++      int (*change) (struct inode * inode, reiser4_plugin * plugin,
++                     pset_member memb);
 +      /* install itself into given inode. This can return error
 +         (e.g., you cannot change hash of non-empty directory). */
 +      int (*inherit) (struct inode * inode, struct inode * parent,
@@ -60465,7 +60267,6 @@ Index: linux-2.6.16/fs/reiser4/plugin/plugin.h
 +
 +/* stores plugin reference in reiser4-specific part of inode */
 +extern int set_object_plugin(struct inode *inode, reiser4_plugin_id id);
-+extern int setup_plugins(struct super_block *super, reiser4_plugin ** area);
 +extern int init_plugins(void);
 +
 +/* builtin plugins */
@@ -60485,7 +60286,6 @@ Index: linux-2.6.16/fs/reiser4/plugin/plugin.h
 +
 +typedef enum {
 +      NONE_CIPHER_ID,
-+      AES_CIPHER_ID,
 +      LAST_CIPHER_ID
 +} reiser4_cipher_id;
 +
@@ -60499,13 +60299,11 @@ Index: linux-2.6.16/fs/reiser4/plugin/plugin.h
 +/* builtin compression mode plugins */
 +typedef enum {
 +      NONE_COMPRESSION_MODE_ID,
-+      COL_8_COMPRESSION_MODE_ID,
-+      COL_16_COMPRESSION_MODE_ID,
-+      COL_32_COMPRESSION_MODE_ID,
-+      COZ_COMPRESSION_MODE_ID,
++      LATTD_COMPRESSION_MODE_ID,
++      ULTIM_COMPRESSION_MODE_ID,
 +      FORCE_COMPRESSION_MODE_ID,
-+      TEST_COMPRESSION_MODE_ID,
-+      LAST_COMPRESSION_MODE_ID
++      CONVX_COMPRESSION_MODE_ID,
++      LAST_COMPRESSION_MODE_ID
 +} reiser4_compression_mode_id;
 +
 +/* builtin cluster plugins */
@@ -60518,13 +60316,6 @@ Index: linux-2.6.16/fs/reiser4/plugin/plugin.h
 +      LAST_CLUSTER_ID
 +} reiser4_cluster_id;
 +
-+/* builtin regular plugins */
-+typedef enum {
-+      UF_REGULAR_ID,
-+      CRC_REGULAR_ID,
-+      LAST_REGULAR_ID
-+} reiser4_regular_id;
-+
 +/* builtin tail-plugins */
 +
 +typedef enum {
@@ -60534,13 +60325,6 @@ Index: linux-2.6.16/fs/reiser4/plugin/plugin.h
 +      LAST_TAIL_FORMATTING_ID
 +} reiser4_formatting_id;
 +
-+/* compression/clustering specific data */
-+typedef struct compression_data {
-+      reiser4_compression_id coa;     /* id of the compression algorithm */
-+} compression_data_t;
-+
-+typedef __u8 cluster_data_t;  /* cluster info */
-+
 +/* data type used to pack parameters that we pass to vfs object creation
 +   function create_object() */
 +struct reiser4_object_create_data {
@@ -60556,9 +60340,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/plugin.h
 +      /* add here something for non-standard objects you invent, like
 +         query for interpolation file etc. */
 +
-+      crypto_stat_t * crypto;
-+      compression_data_t *compression;
-+      cluster_data_t *cluster;
++      struct reiser4_crypto_info * crypto;
 +
 +      struct inode *parent;
 +      struct dentry *dentry;
@@ -60586,18 +60368,6 @@ Index: linux-2.6.16/fs/reiser4/plugin/plugin.h
 +#define MAX_PLUGIN_TYPE_LABEL_LEN  32
 +#define MAX_PLUGIN_PLUG_LABEL_LEN  32
 +
-+/* used for interface with user-land: table-driven parsing in
-+    reiser4(). */
-+typedef struct plugin_locator {
-+      reiser4_plugin_type type_id;
-+      reiser4_plugin_id id;
-+      char type_label[MAX_PLUGIN_TYPE_LABEL_LEN];
-+      char plug_label[MAX_PLUGIN_PLUG_LABEL_LEN];
-+} plugin_locator;
-+
-+extern int locate_plugin(struct inode *inode, plugin_locator * loc);
-+
-+
 +#define PLUGIN_BY_ID(TYPE,ID,FIELD)                                   \
 +static inline TYPE *TYPE ## _by_id( reiser4_plugin_id id )            \
 +{                                                                     \
@@ -60641,7 +60411,6 @@ Index: linux-2.6.16/fs/reiser4/plugin/plugin.h
 +PLUGIN_BY_ID(compression_mode_plugin, REISER4_COMPRESSION_MODE_PLUGIN_TYPE,
 +           compression_mode);
 +PLUGIN_BY_ID(cluster_plugin, REISER4_CLUSTER_PLUGIN_TYPE, clust);
-+PLUGIN_BY_ID(regular_plugin, REISER4_REGULAR_PLUGIN_TYPE, regular);
 +
 +extern int save_plugin_id(reiser4_plugin * plugin, d16 * area);
 +
@@ -60653,30 +60422,9 @@ Index: linux-2.6.16/fs/reiser4/plugin/plugin.h
 +     plugin = list_entry(plugin->h.linkage.next, reiser4_plugin, h.linkage))
 +
 +
-+/* enumeration of fields within plugin_set */
-+typedef enum {
-+      PSET_FILE,
-+      PSET_DIR,               /* PSET_FILE and PSET_DIR should be first elements:
-+                               * inode.c:read_inode() depends on this. */
-+      PSET_PERM,
-+      PSET_FORMATTING,
-+      PSET_HASH,
-+      PSET_FIBRATION,
-+      PSET_SD,
-+      PSET_DIR_ITEM,
-+      PSET_CIPHER,
-+      PSET_DIGEST,
-+      PSET_COMPRESSION,
-+      PSET_COMPRESSION_MODE,
-+      PSET_CLUSTER,
-+      PSET_REGULAR_ENTRY,
-+      PSET_LAST
-+} pset_member;
-+
-+int grab_plugin(struct inode *self, struct inode *ancestor, pset_member memb);
-+int grab_plugin_from(struct inode *self, pset_member memb,
-+                   reiser4_plugin * plug);
-+int force_plugin(struct inode *self, pset_member memb, reiser4_plugin * plug);
++extern int grab_plugin_pset(struct inode *self, struct inode *ancestor, pset_member memb);
++extern int force_plugin_pset(struct inode *self, pset_member memb, reiser4_plugin *plug);
++extern int finish_pset(struct inode *inode);
 +
 +/* defined in fs/reiser4/plugin/object.c */
 +extern file_plugin file_plugins[LAST_FILE_PLUGIN_ID];
@@ -60699,8 +60447,6 @@ Index: linux-2.6.16/fs/reiser4/plugin/plugin.h
 +compression_mode_plugins[LAST_COMPRESSION_MODE_ID];
 +/* defined in fs/reiser4/plugin/cluster.c */
 +extern cluster_plugin cluster_plugins[LAST_CLUSTER_ID];
-+/* defined in fs/reiser4/plugin/regular.c */
-+extern regular_plugin regular_plugins[LAST_REGULAR_ID];
 +/* defined in fs/reiser4/plugin/tail.c */
 +extern formatting_plugin formatting_plugins[LAST_TAIL_FORMATTING_ID];
 +/* defined in fs/reiser4/plugin/security/security.c */
@@ -60724,11 +60470,10 @@ Index: linux-2.6.16/fs/reiser4/plugin/plugin.h
 +   fill-column: 120
 +   End:
 +*/
-Index: linux-2.6.16/fs/reiser4/plugin/plugin_header.h
-===================================================================
---- /dev/null
-+++ linux-2.6.16/fs/reiser4/plugin/plugin_header.h
-@@ -0,0 +1,136 @@
+diff -urN linux-2.6.22.orig/fs/reiser4/plugin/plugin_header.h linux-2.6.22/fs/reiser4/plugin/plugin_header.h
+--- linux-2.6.22.orig/fs/reiser4/plugin/plugin_header.h        1970-01-01 03:00:00.000000000 +0300
++++ linux-2.6.22/fs/reiser4/plugin/plugin_header.h     2007-07-29 00:25:34.996727537 +0400
+@@ -0,0 +1,155 @@
 +/* Copyright 2002, 2003 by Hans Reiser, licensing governed by reiser4/README */
 +
 +/* plugin header. Data structures required by all plugin types. */
@@ -60741,27 +60486,43 @@ Index: linux-2.6.16/fs/reiser4/plugin/plugin_header.h
 +#include "../debug.h"
 +#include "../dformat.h"
 +
++/* Every plugin type can be considered as a class of virtual objects
++   {(type, i) | i = 0, 1, ...}, which has one the following categories
++   of virtualization:
++   A - no virtualization;
++   F - per-file virtualization;
++   S - per-superblock virtualization;
++   FIXME-EDWARD: Define every such category */
++
++/* Supported plugin types: (id, (virtualization category), short description) */
 +typedef enum {
-+      REISER4_FILE_PLUGIN_TYPE,
-+      REISER4_DIR_PLUGIN_TYPE,
-+      REISER4_ITEM_PLUGIN_TYPE,
-+      REISER4_NODE_PLUGIN_TYPE,
-+      REISER4_HASH_PLUGIN_TYPE,
-+      REISER4_FIBRATION_PLUGIN_TYPE,
-+      REISER4_FORMATTING_PLUGIN_TYPE,
-+      REISER4_PERM_PLUGIN_TYPE,
-+      REISER4_SD_EXT_PLUGIN_TYPE,
-+      REISER4_FORMAT_PLUGIN_TYPE,
-+      REISER4_JNODE_PLUGIN_TYPE,
-+      REISER4_CIPHER_PLUGIN_TYPE,
-+      REISER4_DIGEST_PLUGIN_TYPE,
-+      REISER4_COMPRESSION_PLUGIN_TYPE,
-+      REISER4_COMPRESSION_MODE_PLUGIN_TYPE,
-+      REISER4_CLUSTER_PLUGIN_TYPE,
-+      REISER4_REGULAR_PLUGIN_TYPE,
++      REISER4_FILE_PLUGIN_TYPE,             /* (F) service VFS enry-points */
++      REISER4_DIR_PLUGIN_TYPE,              /* (F) service VFS enry-points */
++      REISER4_ITEM_PLUGIN_TYPE,             /* (F) manage items */
++      REISER4_NODE_PLUGIN_TYPE,             /* (S) manage formatted nodes */
++      REISER4_HASH_PLUGIN_TYPE,             /* (F) compute hash */
++      REISER4_FIBRATION_PLUGIN_TYPE,        /* (F) directory fibrations */
++      REISER4_FORMATTING_PLUGIN_TYPE,       /* (F) tail-packing policy */
++      REISER4_PERM_PLUGIN_TYPE,             /*       stub (vacancy)     */
++      REISER4_SD_EXT_PLUGIN_TYPE,           /* (A) stat-data extensions */
++      REISER4_FORMAT_PLUGIN_TYPE,           /* (S) specify disk format */
++      REISER4_JNODE_PLUGIN_TYPE,            /* (A) in-memory node headers */
++      REISER4_CIPHER_PLUGIN_TYPE,           /* (F) cipher transform algs */
++      REISER4_DIGEST_PLUGIN_TYPE,           /* (F) digest transform algs */
++      REISER4_COMPRESSION_PLUGIN_TYPE,      /* (F) compression tfm algs */
++      REISER4_COMPRESSION_MODE_PLUGIN_TYPE, /* (F) compression heuristic */
++      REISER4_CLUSTER_PLUGIN_TYPE,          /* (F) size of logical cluster */
 +      REISER4_PLUGIN_TYPES
 +} reiser4_plugin_type;
 +
++/* Supported plugin groups */
++typedef enum {
++      REISER4_DIRECTORY_FILE,
++      REISER4_REGULAR_FILE,
++      REISER4_SYMLINK_FILE,
++      REISER4_SPECIAL_FILE,
++} file_plugin_group;
++
 +struct reiser4_plugin_ops;
 +/* generic plugin operations, supported by each
 +    plugin type. */
@@ -60773,6 +60534,8 @@ Index: linux-2.6.16/fs/reiser4/plugin/plugin_header.h
 +      reiser4_plugin_type type_id;
 +      /* id of this plugin */
 +      reiser4_plugin_id id;
++      /* bitmask of groups the plugin belongs to. */
++      reiser4_plugin_groups groups;
 +      /* plugin operations */
 +      reiser4_plugin_ops *pops;
 +/* NIKITA-FIXME-HANS: usage of and access to label and desc is not commented and defined. */
@@ -60784,10 +60547,12 @@ Index: linux-2.6.16/fs/reiser4/plugin/plugin_header.h
 +      struct list_head linkage;
 +} plugin_header;
 +
++#define plugin_of_group(plug, group) (plug->h.groups & (1 << group))
++
 +/* PRIVATE INTERFACES */
 +/* NIKITA-FIXME-HANS: what is this for and why does it duplicate what is in plugin_header? */
 +/* plugin type representation. */
-+typedef struct reiser4_plugin_type_data {
++struct reiser4_plugin_type_data {
 +      /* internal plugin type identifier. Should coincide with
 +         index of this item in plugins[] array. */
 +      reiser4_plugin_type type_id;
@@ -60804,14 +60569,15 @@ Index: linux-2.6.16/fs/reiser4/plugin/plugin_header.h
 +      void *builtin;
 +      struct list_head plugins_list;
 +      size_t size;
-+} reiser4_plugin_type_data;
++};
 +
-+extern reiser4_plugin_type_data plugins[REISER4_PLUGIN_TYPES];
++extern struct reiser4_plugin_type_data plugins[REISER4_PLUGIN_TYPES];
 +
-+int is_type_id_valid(reiser4_plugin_type type_id);
-+int is_plugin_id_valid(reiser4_plugin_type type_id, reiser4_plugin_id id);
++int is_plugin_type_valid(reiser4_plugin_type type);
++int is_plugin_id_valid(reiser4_plugin_type type, reiser4_plugin_id id);
 +
-+static inline reiser4_plugin *plugin_at(reiser4_plugin_type_data * ptype, int i)
++static inline reiser4_plugin *plugin_at(struct reiser4_plugin_type_data * ptype,
++                                      int i)
 +{
 +      char *builtin;
 +
@@ -60820,14 +60586,12 @@ Index: linux-2.6.16/fs/reiser4/plugin/plugin_header.h
 +}
 +
 +/* return plugin by its @type_id and @id */
-+static inline reiser4_plugin *plugin_by_id(reiser4_plugin_type type_id
-+                                         /* plugin type id */ ,
-+                                         reiser4_plugin_id id /* plugin id */
-+                                         )
++static inline reiser4_plugin *plugin_by_id(reiser4_plugin_type type,
++                                         reiser4_plugin_id id)
 +{
-+      assert("nikita-1651", is_type_id_valid(type_id));
-+      assert("nikita-1652", is_plugin_id_valid(type_id, id));
-+      return plugin_at(&plugins[type_id], id);
++      assert("nikita-1651", is_plugin_type_valid(type));
++      assert("nikita-1652", is_plugin_id_valid(type, id));
++      return plugin_at(&plugins[type], id);
 +}
 +
 +extern reiser4_plugin *plugin_by_unsafe_id(reiser4_plugin_type type_id,
@@ -60865,32 +60629,33 @@ Index: linux-2.6.16/fs/reiser4/plugin/plugin_header.h
 + * fill-column: 79
 + * End:
 + */
-Index: linux-2.6.16/fs/reiser4/plugin/plugin_set.c
-===================================================================
---- /dev/null
-+++ linux-2.6.16/fs/reiser4/plugin/plugin_set.c
-@@ -0,0 +1,378 @@
+diff -urN linux-2.6.22.orig/fs/reiser4/plugin/plugin_set.c linux-2.6.22/fs/reiser4/plugin/plugin_set.c
+--- linux-2.6.22.orig/fs/reiser4/plugin/plugin_set.c   1970-01-01 03:00:00.000000000 +0300
++++ linux-2.6.22/fs/reiser4/plugin/plugin_set.c        2007-07-29 00:25:35.000728572 +0400
+@@ -0,0 +1,379 @@
 +/* Copyright 2001, 2002, 2003 by Hans Reiser, licensing governed by
 + * reiser4/README */
-+/* NIKITA-FIXME-HANS: you didn't discuss this with me before coding it did you?  Remove plugin-sets from code by March 15th, 2004 */
-+/* plugin-sets */
-+
-+/*
-+ * Each inode comes with a whole set of plugins: file plugin, directory
-+ * plugin, hash plugin, tail policy plugin, security plugin, etc.
-+ *
-+ * Storing them (pointers to them, that is) in inode is a waste of
-+ * space. Especially, given that on average file system plugins of vast
-+ * majority of files will belong to few sets (e.g., one set for regular files,
-+ * another set for standard directory, etc.)
-+ *
-+ * Plugin set (pset) is an object containing pointers to all plugins required
-+ * by inode. Inode only stores a pointer to pset. psets are "interned", that
-+ * is, different inodes with the same set of plugins point to the same
-+ * pset. This is archived by storing psets in global hash table. Races are
-+ * avoided by simple (and efficient so far) solution of never recycling psets,
-+ * even when last inode pointing to it is destroyed.
-+ *
++/* This file contains Reiser4 plugin set operations */
++
++/* plugin sets
++ *
++ * Each file in reiser4 is controlled by a whole set of plugins (file plugin,
++ * directory plugin, hash plugin, tail policy plugin, security plugin, etc.)
++ * assigned (inherited, deduced from mode bits, etc.) at creation time. This
++ * set of plugins (so called pset) is described by structure plugin_set (see
++ * plugin/plugin_set.h), which contains pointers to all required plugins.
++ *
++ * Children can inherit some pset members from their parent, however sometimes
++ * it is useful to specify members different from parent ones. Since object's
++ * pset can not be easily changed without fatal consequences, we use for this
++ * purpose another special plugin table (so called hset, or heir set) described
++ * by the same structure.
++ *
++ * Inode only stores a pointers to pset and hset. Different inodes with the
++ * same set of pset (hset) members point to the same pset (hset). This is
++ * archived by storing psets and hsets in global hash table. Races are avoided
++ * by simple (and efficient so far) solution of never recycling psets, even
++ * when last inode pointing to it is destroyed.
 + */
 +
 +#include "../debug.h"
@@ -60901,7 +60666,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/plugin_set.c
 +#include <linux/stddef.h>
 +
 +/* slab for plugin sets */
-+static kmem_cache_t *plugin_set_slab;
++static struct kmem_cache *plugin_set_slab;
 +
 +static spinlock_t plugin_set_lock[8] __cacheline_aligned_in_smp = {
 +      [0 ... 7] = SPIN_LOCK_UNLOCKED
@@ -60937,7 +60702,8 @@ Index: linux-2.6.16/fs/reiser4/plugin/plugin_set.c
 +              sizeof set1->digest +
 +              sizeof set1->compression +
 +              sizeof set1->compression_mode +
-+              sizeof set1->cluster + sizeof set1->regular_entry);
++              sizeof set1->cluster +
++              sizeof set1->create);
 +
 +      set1 = cast_to(a1);
 +      set2 = cast_to(a2);
@@ -60956,7 +60722,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/plugin_set.c
 +          set1->compression == set2->compression &&
 +          set1->compression_mode == set2->compression_mode &&
 +          set1->cluster == set2->cluster &&
-+          set1->regular_entry == set2->regular_entry;
++          set1->create == set2->create;
 +}
 +
 +#define HASH_FIELD(hash, set, field)          \
@@ -60982,7 +60748,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/plugin_set.c
 +      HASH_FIELD(result, set, compression);
 +      HASH_FIELD(result, set, compression_mode);
 +      HASH_FIELD(result, set, cluster);
-+      HASH_FIELD(result, set, regular_entry);
++      HASH_FIELD(result, set, create);
 +      return result & (PS_TABLE_SIZE - 1);
 +}
 +
@@ -60993,7 +60759,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/plugin_set.c
 +}
 +
 +/* The hash table definition */
-+#define KMALLOC(size) kmalloc((size), get_gfp_mask())
++#define KMALLOC(size) kmalloc((size), reiser4_ctx_gfp_mask_get())
 +#define KFREE(ptr, size) kfree(ptr)
 +TYPE_SAFE_HASH_DEFINE(ps, plugin_set, unsigned long, hashval, link, pshash,
 +                    pseq);
@@ -61016,7 +60782,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/plugin_set.c
 +      .compression = NULL,
 +      .compression_mode = NULL,
 +      .cluster = NULL,
-+      .regular_entry = NULL,
++      .create = NULL,
 +      .link = {NULL}
 +};
 +
@@ -61058,7 +60824,8 @@ Index: linux-2.6.16/fs/reiser4/plugin/plugin_set.c
 +      twin = ps_hash_find(&ps_table, &replica.hashval);
 +      if (unlikely(twin == NULL)) {
 +              rcu_read_unlock();
-+              psal = kmem_cache_alloc(plugin_set_slab, get_gfp_mask());
++              psal = kmem_cache_alloc(plugin_set_slab,
++                                      reiser4_ctx_gfp_mask_get());
 +              if (psal == NULL)
 +                      return RETERR(-ENOMEM);
 +              *psal = replica;
@@ -61082,126 +60849,123 @@ Index: linux-2.6.16/fs/reiser4/plugin/plugin_set.c
 +
 +static struct {
 +      int offset;
++      reiser4_plugin_groups groups;
 +      reiser4_plugin_type type;
 +} pset_descr[PSET_LAST] = {
 +      [PSET_FILE] = {
 +              .offset = offsetof(plugin_set, file),
-+              .type = REISER4_FILE_PLUGIN_TYPE
++              .type = REISER4_FILE_PLUGIN_TYPE,
++              .groups = 0
 +      },
 +      [PSET_DIR] = {
 +              .offset = offsetof(plugin_set, dir),
-+              .type = REISER4_DIR_PLUGIN_TYPE
++              .type = REISER4_DIR_PLUGIN_TYPE,
++              .groups = 0
 +      },
 +      [PSET_PERM] = {
 +              .offset = offsetof(plugin_set, perm),
-+              .type = REISER4_PERM_PLUGIN_TYPE
++              .type = REISER4_PERM_PLUGIN_TYPE,
++              .groups = 0
 +      },
 +      [PSET_FORMATTING] = {
 +              .offset = offsetof(plugin_set, formatting),
-+              .type = REISER4_FORMATTING_PLUGIN_TYPE
++              .type = REISER4_FORMATTING_PLUGIN_TYPE,
++              .groups = 0
 +      },
 +      [PSET_HASH] = {
 +              .offset = offsetof(plugin_set, hash),
-+              .type = REISER4_HASH_PLUGIN_TYPE
++              .type = REISER4_HASH_PLUGIN_TYPE,
++              .groups = 0
 +      },
 +      [PSET_FIBRATION] = {
 +              .offset = offsetof(plugin_set, fibration),
-+              .type = REISER4_FIBRATION_PLUGIN_TYPE
++              .type = REISER4_FIBRATION_PLUGIN_TYPE,
++              .groups = 0
 +      },
 +      [PSET_SD] = {
 +              .offset = offsetof(plugin_set, sd),
-+              .type = REISER4_ITEM_PLUGIN_TYPE
++              .type = REISER4_ITEM_PLUGIN_TYPE,
++              .groups = (1 << STAT_DATA_ITEM_TYPE)
 +      },
 +      [PSET_DIR_ITEM] = {
 +              .offset = offsetof(plugin_set, dir_item),
-+              .type = REISER4_ITEM_PLUGIN_TYPE
++              .type = REISER4_ITEM_PLUGIN_TYPE,
++              .groups = (1 << DIR_ENTRY_ITEM_TYPE)
 +      },
 +      [PSET_CIPHER] = {
 +              .offset = offsetof(plugin_set, cipher),
-+              .type = REISER4_CIPHER_PLUGIN_TYPE
++              .type = REISER4_CIPHER_PLUGIN_TYPE,
++              .groups = 0
 +      },
 +      [PSET_DIGEST] = {
 +              .offset = offsetof(plugin_set, digest),
-+              .type = REISER4_DIGEST_PLUGIN_TYPE
++              .type = REISER4_DIGEST_PLUGIN_TYPE,
++              .groups = 0
 +      },
 +      [PSET_COMPRESSION] = {
 +              .offset = offsetof(plugin_set, compression),
-+              .type = REISER4_COMPRESSION_PLUGIN_TYPE
++              .type = REISER4_COMPRESSION_PLUGIN_TYPE,
++              .groups = 0
 +      },
 +      [PSET_COMPRESSION_MODE] = {
 +              .offset = offsetof(plugin_set, compression_mode),
-+              .type = REISER4_COMPRESSION_MODE_PLUGIN_TYPE
++              .type = REISER4_COMPRESSION_MODE_PLUGIN_TYPE,
++              .groups = 0
 +      },
 +      [PSET_CLUSTER] = {
 +              .offset = offsetof(plugin_set, cluster),
-+              .type = REISER4_CLUSTER_PLUGIN_TYPE
++              .type = REISER4_CLUSTER_PLUGIN_TYPE,
++              .groups = 0
 +      },
-+      [PSET_REGULAR_ENTRY] = {
-+              .offset = offsetof(plugin_set, regular_entry),
-+              .type = REISER4_REGULAR_PLUGIN_TYPE
++      [PSET_CREATE] = {
++              .offset = offsetof(plugin_set, create),
++              .type = REISER4_FILE_PLUGIN_TYPE,
++              .groups = (1 << REISER4_REGULAR_FILE)
 +      }
 +};
 +
-+#if REISER4_DEBUG
-+static reiser4_plugin_type pset_member_to_type(pset_member memb)
-+{
-+      assert("nikita-3501", 0 <= memb && memb < PSET_LAST);
-+      return pset_descr[memb].type;
-+}
-+#endif
-+
-+reiser4_plugin_type pset_member_to_type_unsafe(pset_member memb)
-+{
-+      if (0 <= memb && memb < PSET_LAST)
-+              return pset_descr[memb].type;
-+      else
-+              return REISER4_PLUGIN_TYPES;
-+}
-+
-+int pset_set(plugin_set ** set, pset_member memb, reiser4_plugin * plugin)
-+{
-+      assert("nikita-3492", set != NULL);
-+      assert("nikita-3493", *set != NULL);
-+      assert("nikita-3494", plugin != NULL);
-+      assert("nikita-3495", 0 <= memb && memb < PSET_LAST);
-+      assert("nikita-3496", plugin->h.type_id == pset_member_to_type(memb));
-+
++#define DEFINE_PSET_OPS(PREFIX)                                                      \
++      reiser4_plugin_type PREFIX##_member_to_type_unsafe(pset_member memb)   \
++{                                                                            \
++      if (memb > PSET_LAST)                                                  \
++              return REISER4_PLUGIN_TYPES;                                   \
++      return pset_descr[memb].type;                                          \
++}                                                                            \
++                                                                             \
++int PREFIX##_set_unsafe(plugin_set ** set, pset_member memb,                 \
++                   reiser4_plugin * plugin)                                  \
++{                                                                            \
++      assert("nikita-3492", set != NULL);                                    \
++      assert("nikita-3493", *set != NULL);                                   \
++      assert("nikita-3494", plugin != NULL);                                 \
++      assert("nikita-3495", 0 <= memb && memb < PSET_LAST);                  \
++      assert("nikita-3496", plugin->h.type_id == pset_descr[memb].type);     \
++                                                                             \
++      if (pset_descr[memb].groups)                                           \
++              if (!(pset_descr[memb].groups & plugin->h.groups))             \
++                      return -EINVAL;                                        \
++                                                                             \
++      return plugin_set_field(set,                                           \
++                      (unsigned long)plugin, pset_descr[memb].offset);       \
++}                                                                            \
++                                                                             \
++reiser4_plugin *PREFIX##_get(plugin_set * set, pset_member memb)             \
++{                                                                            \
++      assert("nikita-3497", set != NULL);                                    \
++      assert("nikita-3498", 0 <= memb && memb < PSET_LAST);                  \
++                                                                             \
++      return *(reiser4_plugin **) (((char *)set) + pset_descr[memb].offset); \
++}
++
++DEFINE_PSET_OPS(aset);
++
++int set_plugin(plugin_set ** set, pset_member memb, reiser4_plugin * plugin) {
 +      return plugin_set_field(set,
-+                              (unsigned long)plugin, pset_descr[memb].offset);
++              (unsigned long)plugin, pset_descr[memb].offset);
 +}
 +
-+reiser4_plugin *pset_get(plugin_set * set, pset_member memb)
-+{
-+      assert("nikita-3497", set != NULL);
-+      assert("nikita-3498", 0 <= memb && memb < PSET_LAST);
-+
-+      return *(reiser4_plugin **) (((char *)set) + pset_descr[memb].offset);
-+}
-+
-+#define DEFINE_PLUGIN_SET(type, field)                                        \
-+int plugin_set_ ## field(plugin_set **set, type *val) \
-+{                                                                     \
-+      cassert(sizeof val == sizeof(unsigned long));                   \
-+      return plugin_set_field(set, (unsigned long)val,                \
-+                              offsetof(plugin_set, field));           \
-+}
-+
-+DEFINE_PLUGIN_SET(file_plugin, file)
-+    DEFINE_PLUGIN_SET(dir_plugin, dir)
-+    DEFINE_PLUGIN_SET(formatting_plugin, formatting)
-+    DEFINE_PLUGIN_SET(hash_plugin, hash)
-+    DEFINE_PLUGIN_SET(fibration_plugin, fibration)
-+    DEFINE_PLUGIN_SET(item_plugin, sd)
-+    /* DEFINE_PLUGIN_SET(cipher_plugin, cipher) */
-+    /* DEFINE_PLUGIN_SET(digest_plugin, digest) */
-+    DEFINE_PLUGIN_SET(compression_plugin, compression)
-+    /* DEFINE_PLUGIN_SET(compression_mode_plugin, compression_mode) */
-+    DEFINE_PLUGIN_SET(cluster_plugin, cluster)
-+    /* DEFINE_PLUGIN_SET(regular_plugin, regular_entry) */
-+
-+
 +/**
-+ * init_plugin_set - create pset cache and hash table
++ * init_plugin_set - create plugin set cache and hash table
 + *
 + * Initializes slab cache of plugin_set-s and their hash table. It is part of
 + * reiser4 module initialization.
@@ -61248,14 +61012,14 @@ Index: linux-2.6.16/fs/reiser4/plugin/plugin_set.c
 + * fill-column: 120
 + * End:
 + */
-Index: linux-2.6.16/fs/reiser4/plugin/plugin_set.h
-===================================================================
---- /dev/null
-+++ linux-2.6.16/fs/reiser4/plugin/plugin_set.h
-@@ -0,0 +1,83 @@
+diff -urN linux-2.6.22.orig/fs/reiser4/plugin/plugin_set.h linux-2.6.22/fs/reiser4/plugin/plugin_set.h
+--- linux-2.6.22.orig/fs/reiser4/plugin/plugin_set.h   1970-01-01 03:00:00.000000000 +0300
++++ linux-2.6.22/fs/reiser4/plugin/plugin_set.h        2007-07-29 00:25:35.000728572 +0400
+@@ -0,0 +1,77 @@
 +/* Copyright 2001, 2002, 2003 by Hans Reiser, licensing governed by reiser4/README */
 +
-+/* plugin-sets. see fs/reiser4/plugin/plugin_set.c for details */
++/* Reiser4 plugin set definition.
++   See fs/reiser4/plugin/plugin_set.c for details */
 +
 +#if !defined( __PLUGIN_SET_H__ )
 +#define __PLUGIN_SET_H__
@@ -61298,31 +61062,24 @@ Index: linux-2.6.16/fs/reiser4/plugin/plugin_set.h
 +      compression_mode_plugin *compression_mode;
 +      /* cluster plugin */
 +      cluster_plugin *cluster;
-+      /* plugin of regular child should be created */
-+      regular_plugin *regular_entry;
++      /* this specifies file plugin of regular children.
++         only meaningful for directories */
++      file_plugin *create;
 +      ps_hash_link link;
 +};
 +
 +extern plugin_set *plugin_set_get_empty(void);
 +extern void plugin_set_put(plugin_set * set);
 +
-+extern int plugin_set_file(plugin_set ** set, file_plugin * plug);
-+extern int plugin_set_dir(plugin_set ** set, dir_plugin * plug);
-+extern int plugin_set_formatting(plugin_set ** set, formatting_plugin * plug);
-+extern int plugin_set_hash(plugin_set ** set, hash_plugin * plug);
-+extern int plugin_set_fibration(plugin_set ** set, fibration_plugin * plug);
-+extern int plugin_set_sd(plugin_set ** set, item_plugin * plug);
-+extern int plugin_set_compression(plugin_set ** set, compression_plugin * plug);
-+extern int plugin_set_cluster(plugin_set ** set, cluster_plugin * plug);
-+
 +extern int init_plugin_set(void);
 +extern void done_plugin_set(void);
 +
-+extern int pset_set(plugin_set ** set, pset_member memb,
-+                  reiser4_plugin * plugin);
-+extern reiser4_plugin *pset_get(plugin_set * set, pset_member memb);
-+
-+extern reiser4_plugin_type pset_member_to_type_unsafe(pset_member memb);
++extern reiser4_plugin *aset_get(plugin_set * set, pset_member memb);
++extern int set_plugin(plugin_set ** set, pset_member memb,
++                    reiser4_plugin * plugin);
++extern int aset_set_unsafe(plugin_set ** set, pset_member memb,
++                         reiser4_plugin * plugin);
++extern reiser4_plugin_type aset_member_to_type_unsafe(pset_member memb);
 +
 +/* __PLUGIN_SET_H__ */
 +#endif
@@ -61336,74 +61093,23 @@ Index: linux-2.6.16/fs/reiser4/plugin/plugin_set.h
 +   fill-column: 120
 +   End:
 +*/
-Index: linux-2.6.16/fs/reiser4/plugin/regular.c
-===================================================================
---- /dev/null
-+++ linux-2.6.16/fs/reiser4/plugin/regular.c
-@@ -0,0 +1,44 @@
-+/* Copyright 2001, 2002, 2003 by Hans Reiser, licensing governed by reiser4/README */
-+
-+/* Contains Reiser4 regular plugins which:
-+   . specify a set of reiser4 regular object plugins,
-+   . used by directory plugin to create entries powered by specified
-+     regular plugins */
-+
-+#include "plugin.h"
-+
-+regular_plugin regular_plugins[LAST_REGULAR_ID] = {
-+      [UF_REGULAR_ID] = {
-+              .h = {
-+                      .type_id = REISER4_REGULAR_PLUGIN_TYPE,
-+                      .id = UF_REGULAR_ID,
-+                      .pops = NULL,
-+                      .label = "unixfile",
-+                      .desc = "Unix file regular plugin",
-+                      .linkage = {NULL, NULL}
-+              },
-+              .id = UNIX_FILE_PLUGIN_ID
-+      },
-+      [CRC_REGULAR_ID] = {
-+              .h = {
-+                      .type_id = REISER4_REGULAR_PLUGIN_TYPE,
-+                      .id = CRC_REGULAR_ID,
-+                      .pops = NULL,
-+                      .label = "cryptcompress",
-+                      .desc = "Cryptcompress regular plugin",
-+                      .linkage = {NULL, NULL}
-+              },
-+              .id = CRC_FILE_PLUGIN_ID
-+      }
-+};
-+
-+/*
-+  Local variables:
-+  c-indentation-style: "K&R"
-+  mode-name: "LC"
-+  c-basic-offset: 8
-+  tab-width: 8
-+  fill-column: 120
-+  scroll-step: 1
-+  End:
-+*/
-Index: linux-2.6.16/fs/reiser4/plugin/security/Makefile
-===================================================================
---- /dev/null
-+++ linux-2.6.16/fs/reiser4/plugin/security/Makefile
+diff -urN linux-2.6.22.orig/fs/reiser4/plugin/security/Makefile linux-2.6.22/fs/reiser4/plugin/security/Makefile
+--- linux-2.6.22.orig/fs/reiser4/plugin/security/Makefile      1970-01-01 03:00:00.000000000 +0300
++++ linux-2.6.22/fs/reiser4/plugin/security/Makefile   2007-07-29 00:25:35.000728572 +0400
 @@ -0,0 +1,4 @@
 +obj-$(CONFIG_REISER4_FS) += security_plugins.o
 +
 +security_plugins-objs :=      \
 +      perm.o
-Index: linux-2.6.16/fs/reiser4/plugin/security/perm.c
-===================================================================
---- /dev/null
-+++ linux-2.6.16/fs/reiser4/plugin/security/perm.c
-@@ -0,0 +1,44 @@
+diff -urN linux-2.6.22.orig/fs/reiser4/plugin/security/perm.c linux-2.6.22/fs/reiser4/plugin/security/perm.c
+--- linux-2.6.22.orig/fs/reiser4/plugin/security/perm.c        1970-01-01 03:00:00.000000000 +0300
++++ linux-2.6.22/fs/reiser4/plugin/security/perm.c     2007-07-29 00:25:35.000728572 +0400
+@@ -0,0 +1,33 @@
 +/* Copyright 2001, 2002, 2003 by Hans Reiser, licensing governed by reiser4/README */
 +
 +/*
-+ * this file contains implementation of permission plugins. Currently, only
-+ * RWX_PERM_ID is implemented
++ * This file contains implementation of permission plugins.
++ * See the comments in perm.h
 + */
 +
 +#include "../plugin.h"
@@ -61419,18 +61125,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/security/perm.c
 +                      .label = "null",
 +                      .desc = "stub permission plugin",
 +                      .linkage = {NULL, NULL}
-+              },
-+              .read_ok = NULL,
-+              .write_ok = NULL,
-+              .lookup_ok = NULL,
-+              .create_ok = NULL,
-+              .link_ok = NULL,
-+              .unlink_ok = NULL,
-+              .delete_ok = NULL,
-+              .mask_ok = NULL,
-+              .setattr_ok = NULL,
-+              .getattr_ok = NULL,
-+              .rename_ok = NULL,
++              }
 +      }
 +};
 +
@@ -61443,11 +61138,10 @@ Index: linux-2.6.16/fs/reiser4/plugin/security/perm.c
 + * fill-column: 79
 + * End:
 + */
-Index: linux-2.6.16/fs/reiser4/plugin/security/perm.h
-===================================================================
---- /dev/null
-+++ linux-2.6.16/fs/reiser4/plugin/security/perm.h
-@@ -0,0 +1,82 @@
+diff -urN linux-2.6.22.orig/fs/reiser4/plugin/security/perm.h linux-2.6.22/fs/reiser4/plugin/security/perm.h
+--- linux-2.6.22.orig/fs/reiser4/plugin/security/perm.h        1970-01-01 03:00:00.000000000 +0300
++++ linux-2.6.22/fs/reiser4/plugin/security/perm.h     2007-07-29 00:25:35.000728572 +0400
+@@ -0,0 +1,38 @@
 +/* Copyright 2001, 2002, 2003 by Hans Reiser, licensing governed by reiser4/README */
 +
 +/* Perm (short for "permissions") plugins common stuff. */
@@ -61459,61 +61153,17 @@ Index: linux-2.6.16/fs/reiser4/plugin/security/perm.h
 +#include "../plugin_header.h"
 +
 +#include <linux/types.h>
-+#include <linux/fs.h>         /* for struct file  */
-+#include <linux/dcache.h>     /* for struct dentry */
-+
-+/* interface for perm plugin.
-+
-+   Perm plugin method can be implemented through:
-+
-+    1. consulting ->i_mode bits in stat data
 +
-+    2. obtaining acl from the tree and inspecting it
++/* Definition of permission plugin */
++/* NIKITA-FIXME-HANS: define what this is targeted for.
++   It does not seem to be intended for use with sys_reiser4.  Explain. */
 +
-+    3. asking some kernel module or user-level program to authorize access.
-+
-+   This allows for integration with things like capabilities, SELinux-style
-+   secutiry contexts, etc.
-+
-+*/
-+/* NIKITA-FIXME-HANS: define what this is targeted for.  It does not seem to be intended for use with sys_reiser4.  Explain. */
++/* NOTE-EDWARD: This seems to be intended for deprecated sys_reiser4.
++   Consider it like a temporary "seam" and reserved pset member.
++   If you have something usefull to add, then rename this plugin and add here */
 +typedef struct perm_plugin {
 +      /* generic plugin fields */
 +      plugin_header h;
-+
-+      /* check permissions for read/write */
-+      int (*read_ok) (struct file *file, const char __user *buf,
-+                      size_t size, loff_t *off);
-+      int (*write_ok) (struct file *file, const char __user *buf,
-+                       size_t size, loff_t *off);
-+
-+      /* check permissions for lookup */
-+      int (*lookup_ok) (struct inode * parent, struct dentry * dentry);
-+
-+      /* check permissions for create */
-+      int (*create_ok) (struct inode * parent, struct dentry * dentry,
-+                        reiser4_object_create_data * data);
-+
-+      /* check permissions for linking @where to @existing */
-+      int (*link_ok) (struct dentry * existing, struct inode * parent,
-+                      struct dentry * where);
-+
-+      /* check permissions for unlinking @victim from @parent */
-+      int (*unlink_ok) (struct inode * parent, struct dentry * victim);
-+
-+      /* check permissions for deletion of @object whose last reference is
-+         by @parent */
-+      int (*delete_ok) (struct inode * parent, struct dentry * victim);
-+      int (*mask_ok) (struct inode * inode, int mask);
-+      /* check whether attribute change is acceptable */
-+      int (*setattr_ok) (struct dentry * dentry, struct iattr * attr);
-+
-+      /* check whether stat(2) is allowed */
-+      int (*getattr_ok) (struct vfsmount * mnt UNUSED_ARG,
-+                         struct dentry * dentry, struct kstat * stat);
-+      /* check whether rename(2) is allowed */
-+      int (*rename_ok) (struct inode * old_dir, struct dentry * old,
-+                        struct inode * new_dir, struct dentry * new);
 +} perm_plugin;
 +
 +typedef enum { NULL_PERM_ID, LAST_PERM_ID } reiser4_perm_id;
@@ -61530,20 +61180,10 @@ Index: linux-2.6.16/fs/reiser4/plugin/security/perm.h
 +   fill-column: 120
 +   End:
 +*/
-Index: linux-2.6.16/fs/reiser4/plugin/space/Makefile
-===================================================================
---- /dev/null
-+++ linux-2.6.16/fs/reiser4/plugin/space/Makefile
-@@ -0,0 +1,4 @@
-+obj-$(CONFIG_REISER4_FS) += space_plugins.o
-+
-+space_plugins-objs := \
-+      bitmap.o
-Index: linux-2.6.16/fs/reiser4/plugin/space/bitmap.c
-===================================================================
---- /dev/null
-+++ linux-2.6.16/fs/reiser4/plugin/space/bitmap.c
-@@ -0,0 +1,1592 @@
+diff -urN linux-2.6.22.orig/fs/reiser4/plugin/space/bitmap.c linux-2.6.22/fs/reiser4/plugin/space/bitmap.c
+--- linux-2.6.22.orig/fs/reiser4/plugin/space/bitmap.c 1970-01-01 03:00:00.000000000 +0300
++++ linux-2.6.22/fs/reiser4/plugin/space/bitmap.c      2007-07-29 00:25:35.004729608 +0400
+@@ -0,0 +1,1585 @@
 +/* Copyright 2001, 2002, 2003 by Hans Reiser, licensing governed by reiser4/README */
 +
 +#include "../../debug.h"
@@ -61559,8 +61199,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/space/bitmap.c
 +
 +#include <linux/types.h>
 +#include <linux/fs.h>         /* for struct super_block  */
-+#include <asm/semaphore.h>
-+#include <linux/vmalloc.h>
++#include <linux/mutex.h>
 +#include <asm/div64.h>
 +
 +/* Proposed (but discarded) optimization: dynamic loading/unloading of bitmap
@@ -61618,7 +61257,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/space/bitmap.c
 +/* Block allocation/deallocation are done through special bitmap objects which
 +   are allocated in an array at fs mount. */
 +struct bitmap_node {
-+      struct semaphore sema;  /* long term lock object */
++      struct mutex mutex;     /* long term lock object */
 +
 +      jnode *wjnode;          /* j-nodes for WORKING ... */
 +      jnode *cjnode;          /* ... and COMMIT bitmap blocks */
@@ -61854,7 +61493,6 @@ Index: linux-2.6.16/fs/reiser4/plugin/space/bitmap.c
 +      int last_bit;
 +      int nr;
 +
-+      assert("zam-961", high_off >= 0);
 +      assert("zam-962", high_off >= low_off);
 +
 +      last_word = high_off >> LONG_INT_SHIFT;
@@ -62164,7 +61802,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/space/bitmap.c
 +
 +      assert("zam-455", start != NULL);
 +      assert("zam-437", *start != 0);
-+      assert("zam-541", !blocknr_is_fake(start));
++      assert("zam-541", !reiser4_blocknr_is_fake(start));
 +      assert("zam-441", *start < reiser4_block_count(sb));
 +
 +      if (len != NULL) {
@@ -62249,7 +61887,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/space/bitmap.c
 +{
 +      memset(bnode, 0, sizeof(struct bitmap_node));
 +
-+      sema_init(&bnode->sema, 1);
++      mutex_init(&bnode->mutex);
 +      atomic_set(&bnode->loaded, 0);
 +}
 +
@@ -62275,9 +61913,8 @@ Index: linux-2.6.16/fs/reiser4/plugin/space/bitmap.c
 +}
 +
 +/* ZAM-FIXME-HANS: comment this.  Called only by load_and_lock_bnode()*/
-+static int
-+prepare_bnode(struct bitmap_node *bnode, jnode ** cjnode_ret,
-+            jnode ** wjnode_ret)
++static int prepare_bnode(struct bitmap_node *bnode, jnode **cjnode_ret,
++                       jnode **wjnode_ret)
 +{
 +      struct super_block *super;
 +      jnode *cjnode;
@@ -62365,7 +62002,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/space/bitmap.c
 +      jnode *cjnode;
 +      jnode *wjnode;
 +
-+      assert("nikita-3040", schedulable());
++      assert("nikita-3040", reiser4_schedulable());
 +
 +/* ZAM-FIXME-HANS: since bitmaps are never unloaded, this does not
 + * need to be atomic, right? Just leave a comment that if bitmaps were
@@ -62373,14 +62010,14 @@ Index: linux-2.6.16/fs/reiser4/plugin/space/bitmap.c
 +      if (atomic_read(&bnode->loaded)) {
 +              /* bitmap is already loaded, nothing to do */
 +              check_bnode_loaded(bnode);
-+              down(&bnode->sema);
++              mutex_lock(&bnode->mutex);
 +              assert("nikita-2827", atomic_read(&bnode->loaded));
 +              return 0;
 +      }
 +
 +      ret = prepare_bnode(bnode, &cjnode, &wjnode);
 +      if (ret == 0) {
-+              down(&bnode->sema);
++              mutex_lock(&bnode->mutex);
 +
 +              if (!atomic_read(&bnode->loaded)) {
 +                      assert("nikita-2822", cjnode != NULL);
@@ -62397,13 +62034,12 @@ Index: linux-2.6.16/fs/reiser4/plugin/space/bitmap.c
 +                              atomic_set(&bnode->loaded, 1);
 +                              /* working bitmap is initialized by on-disk
 +                               * commit bitmap. This should be performed
-+                               * under semaphore. */
++                               * under mutex. */
 +                              memcpy(bnode_working_data(bnode),
 +                                     bnode_commit_data(bnode),
 +                                     bmap_size(current_blocksize));
-+                      } else {
-+                              up(&bnode->sema);
-+                      }
++                      } else
++                              mutex_unlock(&bnode->mutex);
 +              } else
 +                      /* race: someone already loaded bitmap while we were
 +                       * busy initializing data. */
@@ -62425,7 +62061,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/space/bitmap.c
 +static void release_and_unlock_bnode(struct bitmap_node *bnode)
 +{
 +      check_bnode_loaded(bnode);
-+      up(&bnode->sema);
++      mutex_unlock(&bnode->mutex);
 +}
 +
 +/* This function does all block allocation work but only for one bitmap
@@ -62727,10 +62363,9 @@ Index: linux-2.6.16/fs/reiser4/plugin/space/bitmap.c
 +}
 +
 +/* plugin->u.space_allocator.alloc_blocks() */
-+int
-+alloc_blocks_bitmap(reiser4_space_allocator * allocator UNUSED_ARG,
-+                  reiser4_blocknr_hint * hint, int needed,
-+                  reiser4_block_nr * start, reiser4_block_nr * len)
++int reiser4_alloc_blocks_bitmap(reiser4_space_allocator * allocator,
++                              reiser4_blocknr_hint * hint, int needed,
++                              reiser4_block_nr * start, reiser4_block_nr * len)
 +{
 +      if (hint->backward)
 +              return alloc_blocks_backward(hint, needed, start, len);
@@ -62742,9 +62377,8 @@ Index: linux-2.6.16/fs/reiser4/plugin/space/bitmap.c
 +   nodes deletion is deferred until transaction commit.  However, deallocation
 +   of temporary objects like wandered blocks and transaction commit records
 +   requires immediate node deletion from WORKING BITMAP.*/
-+void
-+dealloc_blocks_bitmap(reiser4_space_allocator * allocator UNUSED_ARG,
-+                    reiser4_block_nr start, reiser4_block_nr len)
++void reiser4_dealloc_blocks_bitmap(reiser4_space_allocator * allocator,
++                                 reiser4_block_nr start, reiser4_block_nr len)
 +{
 +      struct super_block *super = reiser4_get_current_sb();
 +
@@ -62777,9 +62411,8 @@ Index: linux-2.6.16/fs/reiser4/plugin/space/bitmap.c
 +}
 +
 +/* plugin->u.space_allocator.check_blocks(). */
-+void
-+check_blocks_bitmap(const reiser4_block_nr * start,
-+                  const reiser4_block_nr * len, int desired)
++void reiser4_check_blocks_bitmap(const reiser4_block_nr * start,
++                               const reiser4_block_nr * len, int desired)
 +{
 +#if REISER4_DEBUG
 +      struct super_block *super = reiser4_get_current_sb();
@@ -62914,7 +62547,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/space/bitmap.c
 +   only one transaction can be committed a time, therefore it is safe to access
 +   some global variables without any locking */
 +
-+int pre_commit_hook_bitmap(void)
++int reiser4_pre_commit_hook_bitmap(void)
 +{
 +      struct super_block *super = reiser4_get_current_sb();
 +      txn_atom *atom;
@@ -62945,7 +62578,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/space/bitmap.c
 +
 +                              assert("zam-559", !JF_ISSET(node, JNODE_OVRWR));
 +                              assert("zam-460",
-+                                     !blocknr_is_fake(&node->blocknr));
++                                     !reiser4_blocknr_is_fake(&node->blocknr));
 +
 +                              parse_blocknr(&node->blocknr, &bmap, &offset);
 +                              bn = get_bnode(super, bmap);
@@ -63006,19 +62639,19 @@ Index: linux-2.6.16/fs/reiser4/plugin/space/bitmap.c
 +
 +/* plugin->u.space_allocator.init_allocator
 +    constructor of reiser4_space_allocator object. It is called on fs mount */
-+int
-+init_allocator_bitmap(reiser4_space_allocator * allocator,
-+                    struct super_block *super, void *arg UNUSED_ARG)
++int reiser4_init_allocator_bitmap(reiser4_space_allocator * allocator,
++                                struct super_block *super, void *arg)
 +{
 +      struct bitmap_allocator_data *data = NULL;
 +      bmap_nr_t bitmap_blocks_nr;
 +      bmap_nr_t i;
 +
-+      assert("nikita-3039", schedulable());
++      assert("nikita-3039", reiser4_schedulable());
 +
 +      /* getting memory for bitmap allocator private data holder */
 +      data =
-+              kmalloc(sizeof(struct bitmap_allocator_data), GFP_KERNEL);
++              kmalloc(sizeof(struct bitmap_allocator_data),
++                      reiser4_ctx_gfp_mask_get());
 +
 +      if (data == NULL)
 +              return RETERR(-ENOMEM);
@@ -63034,7 +62667,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/space/bitmap.c
 +         probably, another dynamic data structure should replace a static
 +         array of bnodes. */
 +      /*data->bitmap = reiser4_kmalloc((size_t) (sizeof (struct bitmap_node) * bitmap_blocks_nr), GFP_KERNEL); */
-+      data->bitmap = vmalloc(sizeof(struct bitmap_node) * bitmap_blocks_nr);
++      data->bitmap = reiser4_vmalloc(sizeof(struct bitmap_node) * bitmap_blocks_nr);
 +      if (data->bitmap == NULL) {
 +              kfree(data);
 +              return RETERR(-ENOMEM);
@@ -63064,7 +62697,8 @@ Index: linux-2.6.16/fs/reiser4/plugin/space/bitmap.c
 +                      bnode = data->bitmap + i;
 +                      ret = load_and_lock_bnode(bnode);
 +                      if (ret) {
-+                              destroy_allocator_bitmap(allocator, super);
++                              reiser4_destroy_allocator_bitmap(allocator,
++                                                               super);
 +                              return ret;
 +                      }
 +                      release_and_unlock_bnode(bnode);
@@ -63081,9 +62715,8 @@ Index: linux-2.6.16/fs/reiser4/plugin/space/bitmap.c
 +
 +/* plugin->u.space_allocator.destroy_allocator
 +   destructor. It is called on fs unmount */
-+int
-+destroy_allocator_bitmap(reiser4_space_allocator * allocator,
-+                       struct super_block *super)
++int reiser4_destroy_allocator_bitmap(reiser4_space_allocator * allocator,
++                                   struct super_block *super)
 +{
 +      bmap_nr_t bitmap_blocks_nr;
 +      bmap_nr_t i;
@@ -63098,7 +62731,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/space/bitmap.c
 +      for (i = 0; i < bitmap_blocks_nr; i++) {
 +              struct bitmap_node *bnode = data->bitmap + i;
 +
-+              down(&bnode->sema);
++              mutex_lock(&bnode->mutex);
 +
 +#if REISER4_DEBUG
 +              if (atomic_read(&bnode->loaded)) {
@@ -63115,7 +62748,7 @@ Index: linux-2.6.16/fs/reiser4/plugin/space/bitmap.c
 +              }
 +#endif
 +              done_bnode(bnode);
-+              up(&bnode->sema);
++              mutex_unlock(&bnode->mutex);
 +      }
 +
 +      vfree(data->bitmap);
@@ -63127,19 +62760,18 @@ Index: linux-2.6.16/fs/reiser4/plugin/space/bitmap.c
 +}
 +
 +/*
-+   Local variables:
-+   c-indentation-style: "K&R"
-+   mode-name: "LC"
-+   c-basic-offset: 8
-+   tab-width: 8
-+   fill-column: 80
-+   scroll-step: 1
-+   End:
-+*/
-Index: linux-2.6.16/fs/reiser4/plugin/space/bitmap.h
-===================================================================
---- /dev/null
-+++ linux-2.6.16/fs/reiser4/plugin/space/bitmap.h
++ * Local variables:
++ * c-indentation-style: "K&R"
++ * mode-name: "LC"
++ * c-basic-offset: 8
++ * tab-width: 8
++ * fill-column: 79
++ * scroll-step: 1
++ * End:
++ */
+diff -urN linux-2.6.22.orig/fs/reiser4/plugin/space/bitmap.h linux-2.6.22/fs/reiser4/plugin/space/bitmap.h
+--- linux-2.6.22.orig/fs/reiser4/plugin/space/bitmap.h 1970-01-01 03:00:00.000000000 +0300
++++ linux-2.6.22/fs/reiser4/plugin/space/bitmap.h      2007-07-29 00:25:35.004729608 +0400
 @@ -0,0 +1,47 @@
 +/* Copyright 2002, 2003 by Hans Reiser, licensing governed by reiser4/README */
 +
@@ -63154,24 +62786,24 @@ Index: linux-2.6.16/fs/reiser4/plugin/space/bitmap.h
 +/* EDWARD-FIXME-HANS: write something as informative as the below for every .h file lacking it. */
 +/* declarations of functions implementing methods of space allocator plugin for
 +   bitmap based allocator. The functions themselves are in bitmap.c */
-+extern int init_allocator_bitmap(reiser4_space_allocator *,
-+                               struct super_block *, void *);
-+extern int destroy_allocator_bitmap(reiser4_space_allocator *,
-+                                  struct super_block *);
-+extern int alloc_blocks_bitmap(reiser4_space_allocator *,
-+                             reiser4_blocknr_hint *, int needed,
-+                             reiser4_block_nr * start,
-+                             reiser4_block_nr * len);
-+extern void check_blocks_bitmap(const reiser4_block_nr *,
-+                              const reiser4_block_nr *, int);
-+
-+extern void dealloc_blocks_bitmap(reiser4_space_allocator *, reiser4_block_nr,
-+                                reiser4_block_nr);
-+extern int pre_commit_hook_bitmap(void);
-+
-+#define post_commit_hook_bitmap() do{}while(0)
-+#define post_write_back_hook_bitmap() do{}while(0)
-+#define print_info_bitmap(pref, al) do{}while(0)
++extern int reiser4_init_allocator_bitmap(reiser4_space_allocator *,
++                                       struct super_block *, void *);
++extern int reiser4_destroy_allocator_bitmap(reiser4_space_allocator *,
++                                          struct super_block *);
++extern int reiser4_alloc_blocks_bitmap(reiser4_space_allocator *,
++                                     reiser4_blocknr_hint *, int needed,
++                                     reiser4_block_nr * start,
++                                     reiser4_block_nr * len);
++extern void reiser4_check_blocks_bitmap(const reiser4_block_nr *,
++                                      const reiser4_block_nr *, int);
++extern void reiser4_dealloc_blocks_bitmap(reiser4_space_allocator *,
++                                        reiser4_block_nr,
++                                        reiser4_block_nr);
++extern int reiser4_pre_commit_hook_bitmap(void);
++
++#define reiser4_post_commit_hook_bitmap() do{}while(0)
++#define reiser4_post_write_back_hook_bitmap() do{}while(0)
++#define reiser4_print_info_bitmap(pref, al) do{}while(0)
 +
 +typedef __u64 bmap_nr_t;
 +typedef __u32 bmap_off_t;
@@ -63188,10 +62820,17 @@ Index: linux-2.6.16/fs/reiser4/plugin/space/bitmap.h
 +   scroll-step: 1
 +   End:
 +*/
-Index: linux-2.6.16/fs/reiser4/plugin/space/space_allocator.h
-===================================================================
---- /dev/null
-+++ linux-2.6.16/fs/reiser4/plugin/space/space_allocator.h
+diff -urN linux-2.6.22.orig/fs/reiser4/plugin/space/Makefile linux-2.6.22/fs/reiser4/plugin/space/Makefile
+--- linux-2.6.22.orig/fs/reiser4/plugin/space/Makefile 1970-01-01 03:00:00.000000000 +0300
++++ linux-2.6.22/fs/reiser4/plugin/space/Makefile      2007-07-29 00:25:35.004729608 +0400
+@@ -0,0 +1,4 @@
++obj-$(CONFIG_REISER4_FS) += space_plugins.o
++
++space_plugins-objs := \
++      bitmap.o
+diff -urN linux-2.6.22.orig/fs/reiser4/plugin/space/space_allocator.h linux-2.6.22/fs/reiser4/plugin/space/space_allocator.h
+--- linux-2.6.22.orig/fs/reiser4/plugin/space/space_allocator.h        1970-01-01 03:00:00.000000000 +0300
++++ linux-2.6.22/fs/reiser4/plugin/space/space_allocator.h     2007-07-29 00:25:35.004729608 +0400
 @@ -0,0 +1,80 @@
 +/* Copyright 2002, 2003 by Hans Reiser, licensing governed by reiser4/README */
 +
@@ -63206,47 +62845,47 @@ Index: linux-2.6.16/fs/reiser4/plugin/space/space_allocator.h
 +                                                                                                                      \
 +static inline int sa_init_allocator (reiser4_space_allocator * al, struct super_block *s, void * opaque)              \
 +{                                                                                                                     \
-+      return init_allocator_##allocator (al, s, opaque);                                                              \
++      return reiser4_init_allocator_##allocator (al, s, opaque);                                                      \
 +}                                                                                                                     \
 +                                                                                                                      \
 +static inline void sa_destroy_allocator (reiser4_space_allocator *al, struct super_block *s)                          \
 +{                                                                                                                     \
-+      destroy_allocator_##allocator (al, s);                                                                          \
++      reiser4_destroy_allocator_##allocator (al, s);                                                                  \
 +}                                                                                                                     \
 +                                                                                                                      \
 +static inline int sa_alloc_blocks (reiser4_space_allocator *al, reiser4_blocknr_hint * hint,                          \
 +                                 int needed, reiser4_block_nr * start, reiser4_block_nr * len)                        \
 +{                                                                                                                     \
-+      return alloc_blocks_##allocator (al, hint, needed, start, len);                                                 \
++      return reiser4_alloc_blocks_##allocator (al, hint, needed, start, len);                                         \
 +}                                                                                                                     \
 +static inline void sa_dealloc_blocks (reiser4_space_allocator * al, reiser4_block_nr start, reiser4_block_nr len)     \
 +{                                                                                                                     \
-+      dealloc_blocks_##allocator (al, start, len);                                                                    \
++      reiser4_dealloc_blocks_##allocator (al, start, len);                                                            \
 +}                                                                                                                     \
 +                                                                                                                      \
 +static inline void sa_check_blocks (const reiser4_block_nr * start, const reiser4_block_nr * end, int desired)                \
 +{                                                                                                                     \
-+      check_blocks_##allocator (start, end, desired);                                                                 \
++      reiser4_check_blocks_##allocator (start, end, desired);                                                         \
 +}                                                                                                                     \
 +                                                                                                                      \
 +static inline void sa_pre_commit_hook (void)                                                                          \
 +{                                                                                                                     \
-+      pre_commit_hook_##allocator ();                                                                                 \
++      reiser4_pre_commit_hook_##allocator ();                                                                         \
 +}                                                                                                                     \
 +                                                                                                                      \
 +static inline void sa_post_commit_hook (void)                                                                                 \
 +{                                                                                                                     \
-+      post_commit_hook_##allocator ();                                                                                \
++      reiser4_post_commit_hook_##allocator ();                                                                        \
 +}                                                                                                                     \
 +                                                                                                                      \
 +static inline void sa_post_write_back_hook (void)                                                                     \
 +{                                                                                                                     \
-+      post_write_back_hook_##allocator();                                                                             \
++      reiser4_post_write_back_hook_##allocator();                                                                     \
 +}                                                                                                                     \
 +                                                                                                                      \
 +static inline void sa_print_info(const char * prefix, reiser4_space_allocator * al)                                   \
 +{                                                                                                                     \
-+      print_info_##allocator (prefix, al);                                                                            \
++      reiser4_print_info_##allocator (prefix, al);                                                                    \
 +}
 +
 +DEF_SPACE_ALLOCATOR(bitmap)
@@ -63273,10 +62912,9 @@ Index: linux-2.6.16/fs/reiser4/plugin/space/space_allocator.h
 +   scroll-step: 1
 +   End:
 +*/
-Index: linux-2.6.16/fs/reiser4/plugin/tail_policy.c
-===================================================================
---- /dev/null
-+++ linux-2.6.16/fs/reiser4/plugin/tail_policy.c
+diff -urN linux-2.6.22.orig/fs/reiser4/plugin/tail_policy.c linux-2.6.22/fs/reiser4/plugin/tail_policy.c
+--- linux-2.6.22.orig/fs/reiser4/plugin/tail_policy.c  1970-01-01 03:00:00.000000000 +0300
++++ linux-2.6.22/fs/reiser4/plugin/tail_policy.c       2007-07-29 00:25:35.008730643 +0400
 @@ -0,0 +1,113 @@
 +/* Copyright 2001, 2002, 2003 by Hans Reiser, licensing governed by
 + * reiser4/README */
@@ -63391,11 +63029,10 @@ Index: linux-2.6.16/fs/reiser4/plugin/tail_policy.c
 + * fill-column: 79
 + * End:
 + */
-Index: linux-2.6.16/fs/reiser4/pool.c
-===================================================================
---- /dev/null
-+++ linux-2.6.16/fs/reiser4/pool.c
-@@ -0,0 +1,236 @@
+diff -urN linux-2.6.22.orig/fs/reiser4/pool.c linux-2.6.22/fs/reiser4/pool.c
+--- linux-2.6.22.orig/fs/reiser4/pool.c        1970-01-01 03:00:00.000000000 +0300
++++ linux-2.6.22/fs/reiser4/pool.c     2007-07-29 00:25:35.008730643 +0400
+@@ -0,0 +1,231 @@
 +/* Copyright 2001, 2002, 2003 by Hans Reiser, licensing governed by
 + * reiser4/README */
 +
@@ -63439,7 +63076,6 @@ Index: linux-2.6.16/fs/reiser4/pool.c
 +   functions in the style of tslist/tshash, i.e., make them unreadable, but
 +   type-safe.
 +
-+
 +*/
 +
 +#include "debug.h"
@@ -63449,9 +63085,8 @@ Index: linux-2.6.16/fs/reiser4/pool.c
 +#include <linux/types.h>
 +#include <linux/err.h>
 +
-+/* initialize new pool object */
-+static void reiser4_init_pool_obj(reiser4_pool_header * h     /* pool object to
-+                                                               * initialize */ )
++/* initialize new pool object @h */
++static void reiser4_init_pool_obj(struct reiser4_pool_header * h)
 +{
 +      INIT_LIST_HEAD(&h->usage_linkage);
 +      INIT_LIST_HEAD(&h->level_linkage);
@@ -63459,12 +63094,12 @@ Index: linux-2.6.16/fs/reiser4/pool.c
 +}
 +
 +/* initialize new pool */
-+void reiser4_init_pool(reiser4_pool * pool /* pool to initialize */ ,
++void reiser4_init_pool(struct reiser4_pool * pool /* pool to initialize */ ,
 +                     size_t obj_size /* size of objects in @pool */ ,
 +                     int num_of_objs /* number of preallocated objects */ ,
 +                     char *data /* area for preallocated objects */ )
 +{
-+      reiser4_pool_header *h;
++      struct reiser4_pool_header *h;
 +      int i;
 +
 +      assert("nikita-955", pool != NULL);
@@ -63480,7 +63115,7 @@ Index: linux-2.6.16/fs/reiser4/pool.c
 +      INIT_LIST_HEAD(&pool->extra);
 +      memset(data, 0, obj_size * num_of_objs);
 +      for (i = 0; i < num_of_objs; ++i) {
-+              h = (reiser4_pool_header *) (data + i * obj_size);
++              h = (struct reiser4_pool_header *) (data + i * obj_size);
 +              reiser4_init_pool_obj(h);
 +              /* add pool header to the end of pool's free list */
 +              list_add_tail(&h->usage_linkage, &pool->free);
@@ -63493,20 +63128,19 @@ Index: linux-2.6.16/fs/reiser4/pool.c
 +   allocated objects.
 +
 +*/
-+void reiser4_done_pool(reiser4_pool * pool UNUSED_ARG /* pool to destroy */ )
++void reiser4_done_pool(struct reiser4_pool * pool UNUSED_ARG)
 +{
 +}
 +
-+/* allocate carry object from pool
++/* allocate carry object from @pool
 +
 +   First, try to get preallocated object. If this fails, resort to dynamic
 +   allocation.
 +
 +*/
-+static void *reiser4_pool_alloc(reiser4_pool * pool   /* pool to allocate object
-+                                                       * from */ )
++static void *reiser4_pool_alloc(struct reiser4_pool * pool)
 +{
-+      reiser4_pool_header *result;
++      struct reiser4_pool_header *result;
 +
 +      assert("nikita-959", pool != NULL);
 +
@@ -63516,13 +63150,14 @@ Index: linux-2.6.16/fs/reiser4/pool.c
 +              linkage = pool->free.next;
 +              list_del(linkage);
 +              INIT_LIST_HEAD(linkage);
-+              result = list_entry(linkage, reiser4_pool_header, usage_linkage);
++              result = list_entry(linkage, struct reiser4_pool_header,
++                                  usage_linkage);
 +              BUG_ON(!list_empty(&result->level_linkage) ||
 +                     !list_empty(&result->extra_linkage));
 +      } else {
 +              /* pool is empty. Extra allocations don't deserve dedicated
 +                 slab to be served from, as they are expected to be rare. */
-+              result = kmalloc(pool->obj_size, get_gfp_mask());
++              result = kmalloc(pool->obj_size, reiser4_ctx_gfp_mask_get());
 +              if (result != 0) {
 +                      reiser4_init_pool_obj(result);
 +                      list_add(&result->extra_linkage, &pool->extra);
@@ -63538,8 +63173,8 @@ Index: linux-2.6.16/fs/reiser4/pool.c
 +}
 +
 +/* return object back to the pool */
-+void reiser4_pool_free(reiser4_pool * pool, reiser4_pool_header * h   /* pool to return object back
-+                                                                       * into */ )
++void reiser4_pool_free(struct reiser4_pool * pool,
++                     struct reiser4_pool_header * h)
 +{
 +      assert("nikita-961", h != NULL);
 +      assert("nikita-962", pool != NULL);
@@ -63578,19 +63213,16 @@ Index: linux-2.6.16/fs/reiser4/pool.c
 +   supplied with at least node whose left delimiting key is to be updated
 +   (that is "right" node).
 +
++   @pool - from which to allocate new object;
++   @list - where to add object;
++   @reference - after (or before) which existing object to add
 +*/
-+reiser4_pool_header *add_obj(reiser4_pool * pool      /* pool from which to
-+                                                       * allocate new object */ ,
-+                           struct list_head *list,    /* list where to add
-+                                                       * object */
-+                           pool_ordering order /* where to add */ ,
-+                           reiser4_pool_header * reference    /* after (or
-+                                                               * before) which
-+                                                               * existing
-+                                                               * object to
-+                                                               * add */ )
-+{
-+      reiser4_pool_header *result;
++struct reiser4_pool_header *reiser4_add_obj(struct reiser4_pool * pool,
++                                       struct list_head *list,
++                                       pool_ordering order,
++                                       struct reiser4_pool_header * reference)
++{
++      struct reiser4_pool_header *result;
 +
 +      assert("nikita-972", pool != NULL);
 +
@@ -63632,11 +63264,10 @@ Index: linux-2.6.16/fs/reiser4/pool.c
 +   fill-column: 120
 +   End:
 +*/
-Index: linux-2.6.16/fs/reiser4/pool.h
-===================================================================
---- /dev/null
-+++ linux-2.6.16/fs/reiser4/pool.h
-@@ -0,0 +1,54 @@
+diff -urN linux-2.6.22.orig/fs/reiser4/pool.h linux-2.6.22/fs/reiser4/pool.h
+--- linux-2.6.22.orig/fs/reiser4/pool.h        1970-01-01 03:00:00.000000000 +0300
++++ linux-2.6.22/fs/reiser4/pool.h     2007-07-29 00:25:35.008730643 +0400
+@@ -0,0 +1,56 @@
 +/* Copyright 2001, 2002, 2003 by Hans Reiser, licensing governed by reiser4/README */
 +
 +/* Fast pool allocation */
@@ -63646,21 +63277,21 @@ Index: linux-2.6.16/fs/reiser4/pool.h
 +
 +#include <linux/types.h>
 +
-+typedef struct reiser4_pool {
++struct reiser4_pool {
 +      size_t obj_size;
 +      int objs;
 +      char *data;
 +      struct list_head free;
 +      struct list_head used;
 +      struct list_head extra;
-+} reiser4_pool;
++};
 +
-+typedef struct reiser4_pool_header {
++struct reiser4_pool_header {
 +      /* object is either on free or "used" lists */
 +      struct list_head usage_linkage;
 +      struct list_head level_linkage;
 +      struct list_head extra_linkage;
-+} reiser4_pool_header;
++};
 +
 +typedef enum {
 +      POOLO_BEFORE,
@@ -63671,13 +63302,15 @@ Index: linux-2.6.16/fs/reiser4/pool.h
 +
 +/* pool manipulation functions */
 +
-+extern void reiser4_init_pool(reiser4_pool * pool, size_t obj_size,
++extern void reiser4_init_pool(struct reiser4_pool * pool, size_t obj_size,
 +                            int num_of_objs, char *data);
-+extern void reiser4_done_pool(reiser4_pool * pool);
-+extern void reiser4_pool_free(reiser4_pool * pool, reiser4_pool_header * h);
-+reiser4_pool_header *add_obj(reiser4_pool * pool, struct list_head * list,
-+                           pool_ordering order,
-+                           reiser4_pool_header * reference);
++extern void reiser4_done_pool(struct reiser4_pool * pool);
++extern void reiser4_pool_free(struct reiser4_pool * pool,
++                            struct reiser4_pool_header * h);
++struct reiser4_pool_header *reiser4_add_obj(struct reiser4_pool * pool,
++                                       struct list_head * list,
++                                       pool_ordering order,
++                                       struct reiser4_pool_header *reference);
 +
 +/* __REISER4_POOL_H__ */
 +#endif
@@ -63691,10 +63324,9 @@ Index: linux-2.6.16/fs/reiser4/pool.h
 +   fill-column: 120
 +   End:
 +*/
-Index: linux-2.6.16/fs/reiser4/readahead.c
-===================================================================
---- /dev/null
-+++ linux-2.6.16/fs/reiser4/readahead.c
+diff -urN linux-2.6.22.orig/fs/reiser4/readahead.c linux-2.6.22/fs/reiser4/readahead.c
+--- linux-2.6.22.orig/fs/reiser4/readahead.c   1970-01-01 03:00:00.000000000 +0300
++++ linux-2.6.22/fs/reiser4/readahead.c        2007-07-29 00:25:35.008730643 +0400
 @@ -0,0 +1,138 @@
 +/* Copyright 2001, 2002, 2003 by Hans Reiser, licensing governed by
 + * reiser4/README */
@@ -63709,9 +63341,9 @@ Index: linux-2.6.16/fs/reiser4/readahead.c
 +
 +#include <linux/swap.h>               /* for totalram_pages */
 +
-+void init_ra_info(ra_info_t * rai)
++void reiser4_init_ra_info(ra_info_t * rai)
 +{
-+      rai->key_to_stop = *min_key();
++      rai->key_to_stop = *reiser4_min_key();
 +}
 +
 +/* global formatted node readahead parameter. It can be set by mount option -o readahead:NUM:1 */
@@ -63745,14 +63377,14 @@ Index: linux-2.6.16/fs/reiser4/readahead.c
 +/* start read for @node and for a few of its right neighbors */
 +void formatted_readahead(znode * node, ra_info_t * info)
 +{
-+      ra_params_t *ra_params;
++      struct formatted_ra_params *ra_params;
 +      znode *cur;
 +      int i;
 +      int grn_flags;
 +      lock_handle next_lh;
 +
 +      /* do nothing if node block number has not been assigned to node (which means it is still in cache). */
-+      if (blocknr_is_fake(znode_get_block(node)))
++      if (reiser4_blocknr_is_fake(znode_get_block(node)))
 +              return;
 +
 +      ra_params = get_current_super_ra_params();
@@ -63786,7 +63418,7 @@ Index: linux-2.6.16/fs/reiser4/readahead.c
 +                      break;
 +
 +              nextblk = znode_get_block(next_lh.node);
-+              if (blocknr_is_fake(nextblk) ||
++              if (reiser4_blocknr_is_fake(nextblk) ||
 +                  (ra_adjacent_only(ra_params->flags)
 +                   && *nextblk != *znode_get_block(cur) + 1)) {
 +                      break;
@@ -63820,9 +63452,9 @@ Index: linux-2.6.16/fs/reiser4/readahead.c
 +       * stat data of all files of the directory */
 +      set_key_locality(stop_key, get_inode_oid(dir));
 +      set_key_type(stop_key, KEY_SD_MINOR);
-+      set_key_ordering(stop_key, get_key_ordering(max_key()));
-+      set_key_objectid(stop_key, get_key_objectid(max_key()));
-+      set_key_offset(stop_key, get_key_offset(max_key()));
++      set_key_ordering(stop_key, get_key_ordering(reiser4_max_key()));
++      set_key_objectid(stop_key, get_key_objectid(reiser4_max_key()));
++      set_key_offset(stop_key, get_key_offset(reiser4_max_key()));
 +}
 +
 +/*
@@ -63834,11 +63466,10 @@ Index: linux-2.6.16/fs/reiser4/readahead.c
 +   fill-column: 80
 +   End:
 +*/
-Index: linux-2.6.16/fs/reiser4/readahead.h
-===================================================================
---- /dev/null
-+++ linux-2.6.16/fs/reiser4/readahead.h
-@@ -0,0 +1,48 @@
+diff -urN linux-2.6.22.orig/fs/reiser4/readahead.h linux-2.6.22/fs/reiser4/readahead.h
+--- linux-2.6.22.orig/fs/reiser4/readahead.h   1970-01-01 03:00:00.000000000 +0300
++++ linux-2.6.22/fs/reiser4/readahead.h        2007-07-29 00:25:35.008730643 +0400
+@@ -0,0 +1,51 @@
 +/* Copyright 2001, 2002, 2003 by Hans Reiser, licensing governed by reiser4/README */
 +
 +#ifndef __READAHEAD_H__
@@ -63847,21 +63478,24 @@ Index: linux-2.6.16/fs/reiser4/readahead.h
 +#include "key.h"
 +
 +typedef enum {
-+      RA_ADJACENT_ONLY = 1,   /* only requests nodes which are adjacent. Default is NO (not only adjacent) */
++      RA_ADJACENT_ONLY = 1,   /* only requests nodes which are adjacent.
++                                 Default is NO (not only adjacent) */
 +} ra_global_flags;
 +
-+/* reiser4 super block has a field of this type. It controls readahead during tree traversals */
-+typedef struct formatted_read_ahead_params {
-+      unsigned long max;      /* request not more than this amount of nodes. Default is totalram_pages / 4 */
++/* reiser4 super block has a field of this type.
++   It controls readahead during tree traversals */
++struct formatted_ra_params {
++      unsigned long max;      /* request not more than this amount of nodes.
++                                 Default is totalram_pages / 4 */
 +      int flags;
-+} ra_params_t;
++};
 +
 +typedef struct {
 +      reiser4_key key_to_stop;
 +} ra_info_t;
 +
 +void formatted_readahead(znode *, ra_info_t *);
-+void init_ra_info(ra_info_t * rai);
++void reiser4_init_ra_info(ra_info_t * rai);
 +
 +struct reiser4_file_ra_state {
 +      loff_t start;           /* Current window */
@@ -63887,11 +63521,142 @@ Index: linux-2.6.16/fs/reiser4/readahead.h
 +   fill-column: 120
 +   End:
 +*/
-Index: linux-2.6.16/fs/reiser4/reiser4.h
-===================================================================
---- /dev/null
-+++ linux-2.6.16/fs/reiser4/reiser4.h
-@@ -0,0 +1,276 @@
+diff -urN linux-2.6.22.orig/fs/reiser4/README linux-2.6.22/fs/reiser4/README
+--- linux-2.6.22.orig/fs/reiser4/README        1970-01-01 03:00:00.000000000 +0300
++++ linux-2.6.22/fs/reiser4/README     2007-07-29 00:25:35.008730643 +0400
+@@ -0,0 +1,128 @@
++[LICENSING]
++
++Reiser4 is hereby licensed under the GNU General
++Public License version 2.
++
++Source code files that contain the phrase "licensing governed by
++reiser4/README" are "governed files" throughout this file.  Governed
++files are licensed under the GPL.  The portions of them owned by Hans
++Reiser, or authorized to be licensed by him, have been in the past,
++and likely will be in the future, licensed to other parties under
++other licenses.  If you add your code to governed files, and don't
++want it to be owned by Hans Reiser, put your copyright label on that
++code so the poor blight and his customers can keep things straight.
++All portions of governed files not labeled otherwise are owned by Hans
++Reiser, and by adding your code to it, widely distributing it to
++others or sending us a patch, and leaving the sentence in stating that
++licensing is governed by the statement in this file, you accept this.
++It will be a kindness if you identify whether Hans Reiser is allowed
++to license code labeled as owned by you on your behalf other than
++under the GPL, because he wants to know if it is okay to do so and put
++a check in the mail to you (for non-trivial improvements) when he
++makes his next sale.  He makes no guarantees as to the amount if any,
++though he feels motivated to motivate contributors, and you can surely
++discuss this with him before or after contributing.  You have the
++right to decline to allow him to license your code contribution other
++than under the GPL.
++
++Further licensing options are available for commercial and/or other
++interests directly from Hans Reiser: reiser@namesys.com.  If you interpret
++the GPL as not allowing those additional licensing options, you read
++it wrongly, and Richard Stallman agrees with me, when carefully read
++you can see that those restrictions on additional terms do not apply
++to the owner of the copyright, and my interpretation of this shall
++govern for this license.
++
++[END LICENSING]
++
++Reiser4 is a file system based on dancing tree algorithms, and is
++described at http://www.namesys.com
++
++mkfs.reiser4 and other utilities are on our webpage or wherever your
++Linux provider put them.  You really want to be running the latest
++version off the website if you use fsck.
++
++Yes, if you update your reiser4 kernel module you do have to
++recompile your kernel, most of the time.  The errors you get will be
++quite cryptic if your forget to do so.
++
++Hideous Commercial Pitch: Spread your development costs across other OS
++vendors.  Select from the best in the world, not the best in your
++building, by buying from third party OS component suppliers.  Leverage
++the software component development power of the internet.  Be the most
++aggressive in taking advantage of the commercial possibilities of
++decentralized internet development, and add value through your branded
++integration that you sell as an operating system.  Let your competitors
++be the ones to compete against the entire internet by themselves.  Be
++hip, get with the new economic trend, before your competitors do.  Send
++email to reiser@namesys.com
++
++Hans Reiser was the primary architect of Reiser4, but a whole team
++chipped their ideas in.  He invested everything he had into Namesys
++for 5.5 dark years of no money before Reiser3 finally started to work well
++enough to bring in money.  He owns the copyright.
++
++DARPA was the primary sponsor of Reiser4.  DARPA does not endorse
++Reiser4, it merely sponsors it.  DARPA is, in solely Hans's personal
++opinion, unique in its willingness to invest into things more
++theoretical than the VC community can readily understand, and more
++longterm than allows them to be sure that they will be the ones to
++extract the economic benefits from.  DARPA also integrated us into a
++security community that transformed our security worldview.
++
++Vladimir Saveliev is our lead programmer, with us from the beginning,
++and he worked long hours writing the cleanest code.  This is why he is
++now the lead programmer after years of commitment to our work.  He
++always made the effort to be the best he could be, and to make his
++code the best that it could be.  What resulted was quite remarkable. I
++don't think that money can ever motivate someone to work the way he
++did, he is one of the most selfless men I know.
++
++Alexander Lyamin was our sysadmin, and helped to educate us in
++security issues.  Moscow State University and IMT were very generous
++in the internet access they provided us, and in lots of other little
++ways that a generous institution can be.
++
++Alexander Zarochentcev (sometimes known as zam, or sasha), wrote the
++locking code, the block allocator, and finished the flushing code.
++His code is always crystal clean and well structured.
++
++Nikita Danilov wrote the core of the balancing code, the core of the
++plugins code, and the directory code.  He worked a steady pace of long
++hours that produced a whole lot of well abstracted code.  He is our
++senior computer scientist.
++
++Vladimir Demidov wrote the parser.  Writing an in kernel parser is
++something very few persons have the skills for, and it is thanks to
++him that we can say that the parser is really not so big compared to
++various bits of our other code, and making a parser work in the kernel
++was not so complicated as everyone would imagine mainly because it was
++him doing it...
++
++Joshua McDonald wrote the transaction manager, and the flush code.
++The flush code unexpectedly turned out be extremely hairy for reasons
++you can read about on our web page, and he did a great job on an
++extremely difficult task.
++
++Nina Reiser handled our accounting, government relations, and much
++more.
++
++Ramon Reiser developed our website.
++
++Beverly Palmer drew our graphics.
++
++Vitaly Fertman developed librepair, userspace plugins repair code, fsck
++and worked with Umka on developing libreiser4 and userspace plugins.
++
++Yury Umanets (aka Umka) developed libreiser4, userspace plugins and
++userspace tools (reiser4progs).
++
++Oleg Drokin (aka Green) is the release manager who fixes everything.
++It is so nice to have someone like that on the team.  He (plus Chris
++and Jeff) make it possible for the entire rest of the Namesys team to
++focus on Reiser4, and he fixed a whole lot of Reiser4 bugs also.  It
++is just amazing to watch his talent for spotting bugs in action.
++
++Edward Shishkin wrote cryptcompress file plugin (which manages files
++built of encrypted and(or) compressed bodies) and other plugins related
++to transparent encryption and compression support.
+diff -urN linux-2.6.22.orig/fs/reiser4/reiser4.h linux-2.6.22/fs/reiser4/reiser4.h
+--- linux-2.6.22.orig/fs/reiser4/reiser4.h     1970-01-01 03:00:00.000000000 +0300
++++ linux-2.6.22/fs/reiser4/reiser4.h  2007-07-29 00:25:35.012731678 +0400
+@@ -0,0 +1,269 @@
 +/* Copyright 2001, 2002, 2003 by Hans Reiser, licensing governed by
 + * reiser4/README */
 +
@@ -63900,12 +63665,11 @@ Index: linux-2.6.16/fs/reiser4/reiser4.h
 +#if !defined( __REISER4_H__ )
 +#define __REISER4_H__
 +
-+#include <linux/config.h>
 +#include <asm/param.h>                /* for HZ */
 +#include <linux/errno.h>
 +#include <linux/types.h>
 +#include <linux/fs.h>
-+#include <asm/hardirq.h>
++#include <linux/hardirq.h>
 +#include <linux/sched.h>
 +
 +/*
@@ -63932,12 +63696,6 @@ Index: linux-2.6.16/fs/reiser4/reiser4.h
 +#define REISER4_SHA256 (0)
 +#endif
 +
-+#if defined(CONFIG_CRYPTO_AES_586)
-+#define REISER4_AES (1)
-+#else
-+#define REISER4_AES (0)
-+#endif
-+
 +/*
 + * Turn on large keys mode. In his mode (which is default), reiser4 key has 4
 + * 8-byte components. In the old "small key" mode, it's 3 8-byte
@@ -64168,11 +63926,10 @@ Index: linux-2.6.16/fs/reiser4/reiser4.h
 +   fill-column: 120
 +   End:
 +*/
-Index: linux-2.6.16/fs/reiser4/safe_link.c
-===================================================================
---- /dev/null
-+++ linux-2.6.16/fs/reiser4/safe_link.c
-@@ -0,0 +1,351 @@
+diff -urN linux-2.6.22.orig/fs/reiser4/safe_link.c linux-2.6.22/fs/reiser4/safe_link.c
+--- linux-2.6.22.orig/fs/reiser4/safe_link.c   1970-01-01 03:00:00.000000000 +0300
++++ linux-2.6.22/fs/reiser4/safe_link.c        2007-07-29 00:25:35.012731678 +0400
+@@ -0,0 +1,352 @@
 +/* Copyright 2003, 2004 by Hans Reiser, licensing governed by
 + * reiser4/README */
 +
@@ -64306,7 +64063,7 @@ Index: linux-2.6.16/fs/reiser4/safe_link.c
 +      int result;
 +
 +      grab_space_enable();
-+      /* The sbinfo->delete semaphore can be taken here.
++      /* The sbinfo->delete_mutex can be taken here.
 +       * safe_link_release() should be called before leaving reiser4
 +       * context. */
 +      result =
@@ -64345,7 +64102,7 @@ Index: linux-2.6.16/fs/reiser4/safe_link.c
 +              length += sizeof(sl.size);
 +              put_unaligned(cpu_to_le64(inode->i_size), &sl.size);
 +      }
-+      tree = tree_by_inode(inode);
++      tree = reiser4_tree_by_inode(inode);
 +      build_link_key(tree, get_inode_oid(inode), link, &key);
 +
 +      result = store_black_box(tree, &key, &sl, length);
@@ -64369,31 +64126,32 @@ Index: linux-2.6.16/fs/reiser4/safe_link.c
 + * in-memory structure to keep information extracted from safe-link. This is
 + * used to iterate over all safe-links.
 + */
-+typedef struct {
++struct safe_link_context {
 +      reiser4_tree *tree;     /* internal tree */
 +      reiser4_key key;        /* safe-link key */
 +      reiser4_key sdkey;      /* key of object stat-data */
 +      reiser4_safe_link_t link;       /* safe-link type */
 +      oid_t oid;              /* object oid */
 +      __u64 size;             /* final size for truncate */
-+} safe_link_context;
++};
 +
 +/*
 + * start iterating over all safe-links.
 + */
-+static void safe_link_iter_begin(reiser4_tree * tree, safe_link_context * ctx)
++static void safe_link_iter_begin(reiser4_tree * tree,
++                               struct safe_link_context * ctx)
 +{
 +      ctx->tree = tree;
 +      reiser4_key_init(&ctx->key);
 +      set_key_locality(&ctx->key, safe_link_locality(tree));
-+      set_key_objectid(&ctx->key, get_key_objectid(max_key()));
-+      set_key_offset(&ctx->key, get_key_offset(max_key()));
++      set_key_objectid(&ctx->key, get_key_objectid(reiser4_max_key()));
++      set_key_offset(&ctx->key, get_key_offset(reiser4_max_key()));
 +}
 +
 +/*
 + * return next safe-link.
 + */
-+static int safe_link_iter_next(safe_link_context * ctx)
++static int safe_link_iter_next(struct safe_link_context * ctx)
 +{
 +      int result;
 +      safelink_t sl;
@@ -64412,7 +64170,7 @@ Index: linux-2.6.16/fs/reiser4/safe_link.c
 +/*
 + * check are there any more safe-links left in the tree.
 + */
-+static int safe_link_iter_finished(safe_link_context * ctx)
++static int safe_link_iter_finished(struct safe_link_context * ctx)
 +{
 +      return get_key_locality(&ctx->key) != safe_link_locality(ctx->tree);
 +}
@@ -64420,7 +64178,7 @@ Index: linux-2.6.16/fs/reiser4/safe_link.c
 +/*
 + * finish safe-link iteration.
 + */
-+static void safe_link_iter_end(safe_link_context * ctx)
++static void safe_link_iter_end(struct safe_link_context * ctx)
 +{
 +      /* nothing special */
 +}
@@ -64447,17 +64205,17 @@ Index: linux-2.6.16/fs/reiser4/safe_link.c
 +              assert("nikita-3428", fplug != NULL);
 +              assert("", oid == get_inode_oid(inode));
 +              if (fplug->safelink != NULL) {
-+                      /* txn_restart_current is not necessary because
++                      /* reiser4_txn_restart_current is not necessary because
 +                       * mounting is signle thread. However, without it
 +                       * deadlock detection code will complain (see
 +                       * nikita-3361). */
-+                      txn_restart_current();
++                      reiser4_txn_restart_current();
 +                      result = fplug->safelink(inode, link, size);
 +              } else {
 +                      warning("nikita-3430",
 +                              "Cannot handle safelink for %lli",
 +                              (unsigned long long)oid);
-+                      print_key("key", sdkey);
++                      reiser4_print_key("key", sdkey);
 +                      result = 0;
 +              }
 +              if (result != 0) {
@@ -64468,18 +64226,18 @@ Index: linux-2.6.16/fs/reiser4/safe_link.c
 +              reiser4_iget_complete(inode);
 +              iput(inode);
 +              if (result == 0) {
-+                      result = safe_link_grab(get_tree(super), BA_CAN_COMMIT);
++                      result = safe_link_grab(reiser4_get_tree(super), BA_CAN_COMMIT);
 +                      if (result == 0)
 +                              result =
-+                                  safe_link_del(get_tree(super), oid, link);
-+                      safe_link_release(get_tree(super));
++                                  safe_link_del(reiser4_get_tree(super), oid, link);
++                      safe_link_release(reiser4_get_tree(super));
 +                      /*
 +                       * restart transaction: if there was large number of
 +                       * safe-links, their processing may fail to fit into
 +                       * single transaction.
 +                       */
 +                      if (result == 0)
-+                              txn_restart_current();
++                              reiser4_txn_restart_current();
 +              }
 +      } else
 +              result = PTR_ERR(inode);
@@ -64491,7 +64249,7 @@ Index: linux-2.6.16/fs/reiser4/safe_link.c
 + */
 +int process_safelinks(struct super_block *super)
 +{
-+      safe_link_context ctx;
++      struct safe_link_context ctx;
 +      int result;
 +
 +      if (rofs_super(super))
@@ -64524,10 +64282,9 @@ Index: linux-2.6.16/fs/reiser4/safe_link.c
 +   scroll-step: 1
 +   End:
 +*/
-Index: linux-2.6.16/fs/reiser4/safe_link.h
-===================================================================
---- /dev/null
-+++ linux-2.6.16/fs/reiser4/safe_link.h
+diff -urN linux-2.6.22.orig/fs/reiser4/safe_link.h linux-2.6.22/fs/reiser4/safe_link.h
+--- linux-2.6.22.orig/fs/reiser4/safe_link.h   1970-01-01 03:00:00.000000000 +0300
++++ linux-2.6.22/fs/reiser4/safe_link.h        2007-07-29 00:25:35.012731678 +0400
 @@ -0,0 +1,29 @@
 +/* Copyright 2003 by Hans Reiser, licensing governed by
 + * reiser4/README */
@@ -64558,11 +64315,10 @@ Index: linux-2.6.16/fs/reiser4/safe_link.h
 +   fill-column: 120
 +   End:
 +*/
-Index: linux-2.6.16/fs/reiser4/seal.c
-===================================================================
---- /dev/null
-+++ linux-2.6.16/fs/reiser4/seal.c
-@@ -0,0 +1,217 @@
+diff -urN linux-2.6.22.orig/fs/reiser4/seal.c linux-2.6.22/fs/reiser4/seal.c
+--- linux-2.6.22.orig/fs/reiser4/seal.c        1970-01-01 03:00:00.000000000 +0300
++++ linux-2.6.22/fs/reiser4/seal.c     2007-07-29 00:25:35.012731678 +0400
+@@ -0,0 +1,218 @@
 +/* Copyright 2002, 2003 by Hans Reiser, licensing governed by reiser4/README */
 +/* Seals implementation. */
 +/* Seals are "weak" tree pointers. They are analogous to tree coords in
@@ -64571,9 +64327,9 @@ Index: linux-2.6.16/fs/reiser4/seal.c
 +   even a reference) to znode. In stead, each znode contains a version number,
 +   increased on each znode modification. This version number is copied into a
 +   seal when seal is created. Later, one can "validate" seal by calling
-+   seal_validate(). If znode is in cache and its version number is still the
-+   same, seal is "pristine" and coord associated with it can be re-used
-+   immediately.
++   reiser4_seal_validate(). If znode is in cache and its version number is
++   still the same, seal is "pristine" and coord associated with it can be
++   re-used immediately.
 +
 +   If, on the other hand, znode is out of cache, or it is obviously different
 +   one from the znode seal was initially attached to (for example, it is on
@@ -64613,10 +64369,11 @@ Index: linux-2.6.16/fs/reiser4/seal.c
 +
 +/* initialise seal. This can be called several times on the same seal. @coord
 +   and @key can be NULL.  */
-+void seal_init(seal_t * seal /* seal to initialise */ ,
-+             const coord_t * coord /* coord @seal will be attached to */ ,
-+             const reiser4_key * key UNUSED_ARG       /* key @seal will be
-+                                                       * attached to */ )
++void reiser4_seal_init(seal_t * seal /* seal to initialise */ ,
++                     const coord_t * coord /* coord @seal will be
++                                            * attached to */ ,
++                     const reiser4_key * key UNUSED_ARG /* key @seal will be
++                                                         * attached to */ )
 +{
 +      assert("nikita-1886", seal != NULL);
 +      memset(seal, 0, sizeof *seal);
@@ -64639,22 +64396,22 @@ Index: linux-2.6.16/fs/reiser4/seal.c
 +}
 +
 +/* finish with seal */
-+void seal_done(seal_t * seal /* seal to clear */ )
++void reiser4_seal_done(seal_t * seal /* seal to clear */ )
 +{
 +      assert("nikita-1887", seal != NULL);
 +      seal->version = 0;
 +}
 +
 +/* true if seal was initialised */
-+int seal_is_set(const seal_t * seal /* seal to query */ )
++int reiser4_seal_is_set(const seal_t * seal /* seal to query */ )
 +{
 +      assert("nikita-1890", seal != NULL);
 +      return seal->version != 0;
 +}
 +
 +#if REISER4_DEBUG
-+/* helper function for seal_validate(). It checks that item at @coord has
-+ * expected key. This is to detect cases where node was modified but wasn't
++/* helper function for reiser4_seal_validate(). It checks that item at @coord
++ * has expected key. This is to detect cases where node was modified but wasn't
 + * marked dirty. */
 +static inline int check_seal_match(const coord_t * coord /* coord to check */ ,
 +                                 const reiser4_key * k /* expected key */ )
@@ -64672,12 +64429,12 @@ Index: linux-2.6.16/fs/reiser4/seal.c
 +}
 +#endif
 +
-+/* this is used by seal_validate. It accepts return value of
++/* this is used by reiser4_seal_validate. It accepts return value of
 + * longterm_lock_znode and returns 1 if it can be interpreted as seal
 + * validation failure. For instance, when longterm_lock_znode returns -EINVAL,
-+ * seal_validate returns -E_REPEAT and caller will call tre search. We cannot
-+ * do this in longterm_lock_znode(), because sometimes we want to distinguish
-+ * between -EINVAL and -E_REPEAT. */
++ * reiser4_seal_validate returns -E_REPEAT and caller will call tre search.
++ * We cannot do this in longterm_lock_znode(), because sometimes we want to
++ * distinguish between -EINVAL and -E_REPEAT. */
 +static int should_repeat(int return_code)
 +{
 +      return return_code == -EINVAL;
@@ -64689,24 +64446,24 @@ Index: linux-2.6.16/fs/reiser4/seal.c
 +
 +   If seal was burned, or broken irreparably, return -E_REPEAT.
 +
-+   NOTE-NIKITA currently seal_validate() returns -E_REPEAT if key we are
++   NOTE-NIKITA currently reiser4_seal_validate() returns -E_REPEAT if key we are
 +   looking for is in range of keys covered by the sealed node, but item wasn't
 +   found by node ->lookup() method. Alternative is to return -ENOENT in this
 +   case, but this would complicate callers logic.
 +
 +*/
-+int seal_validate(seal_t * seal /* seal to validate */ ,
-+                coord_t * coord /* coord to validate against */ ,
-+                const reiser4_key * key /* key to validate against */ ,
-+                lock_handle * lh /* resulting lock handle */ ,
-+                znode_lock_mode mode /* lock node */ ,
-+                znode_lock_request request /* locking priority */ )
++int reiser4_seal_validate(seal_t * seal /* seal to validate */,
++                        coord_t * coord /* coord to validate against */,
++                        const reiser4_key * key /* key to validate against */,
++                        lock_handle * lh /* resulting lock handle */,
++                        znode_lock_mode mode /* lock node */,
++                        znode_lock_request request /* locking priority */)
 +{
 +      znode *node;
 +      int result;
 +
 +      assert("nikita-1889", seal != NULL);
-+      assert("nikita-1881", seal_is_set(seal));
++      assert("nikita-1881", reiser4_seal_is_set(seal));
 +      assert("nikita-1882", key != NULL);
 +      assert("nikita-1883", coord != NULL);
 +      assert("nikita-1884", lh != NULL);
@@ -64780,10 +64537,9 @@ Index: linux-2.6.16/fs/reiser4/seal.c
 +   scroll-step: 1
 +   End:
 +*/
-Index: linux-2.6.16/fs/reiser4/seal.h
-===================================================================
---- /dev/null
-+++ linux-2.6.16/fs/reiser4/seal.h
+diff -urN linux-2.6.22.orig/fs/reiser4/seal.h linux-2.6.22/fs/reiser4/seal.h
+--- linux-2.6.22.orig/fs/reiser4/seal.h        1970-01-01 03:00:00.000000000 +0300
++++ linux-2.6.22/fs/reiser4/seal.h     2007-07-29 00:25:35.012731678 +0400
 @@ -0,0 +1,49 @@
 +/* Copyright 2002, 2003 by Hans Reiser, licensing governed by reiser4/README */
 +
@@ -64815,10 +64571,10 @@ Index: linux-2.6.16/fs/reiser4/seal.h
 +#endif
 +} seal_t;
 +
-+extern void seal_init(seal_t *, const coord_t *, const reiser4_key *);
-+extern void seal_done(seal_t *);
-+extern int seal_is_set(const seal_t *);
-+extern int seal_validate(seal_t *, coord_t *,
++extern void reiser4_seal_init(seal_t *, const coord_t *, const reiser4_key *);
++extern void reiser4_seal_done(seal_t *);
++extern int reiser4_seal_is_set(const seal_t *);
++extern int reiser4_seal_validate(seal_t *, coord_t *,
 +                       const reiser4_key *, lock_handle *,
 +                       znode_lock_mode mode, znode_lock_request request);
 +
@@ -64834,10 +64590,9 @@ Index: linux-2.6.16/fs/reiser4/seal.h
 +   fill-column: 120
 +   End:
 +*/
-Index: linux-2.6.16/fs/reiser4/search.c
-===================================================================
---- /dev/null
-+++ linux-2.6.16/fs/reiser4/search.c
+diff -urN linux-2.6.22.orig/fs/reiser4/search.c linux-2.6.22/fs/reiser4/search.c
+--- linux-2.6.22.orig/fs/reiser4/search.c      1970-01-01 03:00:00.000000000 +0300
++++ linux-2.6.22/fs/reiser4/search.c   2007-07-29 00:25:35.016732714 +0400
 @@ -0,0 +1,1611 @@
 +/* Copyright 2001, 2002, 2003 by Hans Reiser, licensing governed by
 + * reiser4/README */
@@ -64896,7 +64651,8 @@ Index: linux-2.6.16/fs/reiser4/search.c
 +      assert("nikita-346", cache != NULL);
 +
 +      cache->slot =
-+          kmalloc(sizeof(cbk_cache_slot) * cache->nr_slots, GFP_KERNEL);
++              kmalloc(sizeof(cbk_cache_slot) * cache->nr_slots,
++                      reiser4_ctx_gfp_mask_get());
 +      if (cache->slot == NULL)
 +              return RETERR(-ENOMEM);
 +
@@ -64925,7 +64681,6 @@ Index: linux-2.6.16/fs/reiser4/search.c
 +           &(cache)->lru != &(slot)->lru;                                     \
 +           (slot) = list_entry(slot->lru.next, cbk_cache_slot, lru))
 +
-+
 +#if REISER4_DEBUG
 +/* this function assures that [cbk-cache-invariant] invariant holds */
 +static int cbk_cache_invariant(const cbk_cache *cache)
@@ -65136,7 +64891,7 @@ Index: linux-2.6.16/fs/reiser4/search.c
 +      init_lh(lh);
 +      init_lh(&parent_lh);
 +
-+      assert("nikita-3023", schedulable());
++      assert("nikita-3023", reiser4_schedulable());
 +
 +      assert("nikita-353", tree != NULL);
 +      assert("nikita-354", key != NULL);
@@ -65163,15 +64918,15 @@ Index: linux-2.6.16/fs/reiser4/search.c
 +
 +/* like coord_by_key(), but starts traversal from vroot of @object rather than
 + * from tree root. */
-+lookup_result
-+object_lookup(struct inode * object,
-+            const reiser4_key * key,
-+            coord_t * coord,
-+            lock_handle * lh,
-+            znode_lock_mode lock_mode,
-+            lookup_bias bias,
-+            tree_level lock_level,
-+            tree_level stop_level, __u32 flags, ra_info_t * info)
++lookup_result reiser4_object_lookup(struct inode * object,
++                                  const reiser4_key * key,
++                                  coord_t * coord,
++                                  lock_handle * lh,
++                                  znode_lock_mode lock_mode,
++                                  lookup_bias bias,
++                                  tree_level lock_level,
++                                  tree_level stop_level, __u32 flags,
++                                  ra_info_t * info)
 +{
 +      cbk_handle handle;
 +      lock_handle parent_lh;
@@ -65180,7 +64935,7 @@ Index: linux-2.6.16/fs/reiser4/search.c
 +      init_lh(lh);
 +      init_lh(&parent_lh);
 +
-+      assert("nikita-3023", schedulable());
++      assert("nikita-3023", reiser4_schedulable());
 +
 +      assert("nikita-354", key != NULL);
 +      assert("nikita-355", coord != NULL);
@@ -65191,7 +64946,7 @@ Index: linux-2.6.16/fs/reiser4/search.c
 +      assert("nikita-2104", lock_stack_isclean(get_current_lock_stack()));
 +
 +      cbk_pack(&handle,
-+               object != NULL ? tree_by_inode(object) : current_tree,
++               object != NULL ? reiser4_tree_by_inode(object) : current_tree,
 +               key,
 +               coord,
 +               lh,
@@ -65205,7 +64960,8 @@ Index: linux-2.6.16/fs/reiser4/search.c
 +      return result;
 +}
 +
-+/* lookup by cbk_handle. Common part of coord_by_key() and object_lookup(). */
++/* lookup by cbk_handle. Common part of coord_by_key() and
++   reiser4_object_lookup(). */
 +static lookup_result coord_by_handle(cbk_handle * handle)
 +{
 +      /*
@@ -65229,19 +64985,19 @@ Index: linux-2.6.16/fs/reiser4/search.c
 +
 +   Error code, or last actor return value is returned.
 +
-+   This is used by plugin/dir/hashe_dir.c:find_entry() to move through
++   This is used by plugin/dir/hashe_dir.c:reiser4_find_entry() to move through
 +   sequence of entries with identical keys and alikes.
 +*/
-+int iterate_tree(reiser4_tree * tree /* tree to scan */ ,
-+               coord_t * coord /* coord to start from */ ,
-+               lock_handle * lh       /* lock handle to start with and to
-+                                       * update along the way */ ,
-+               tree_iterate_actor_t actor     /* function to call on each
-+                                               * item/unit */ ,
-+               void *arg /* argument to pass to @actor */ ,
-+               znode_lock_mode mode /* lock mode on scanned nodes */ ,
-+               int through_units_p    /* call @actor on each item or on each
-+                                       * unit */ )
++int reiser4_iterate_tree(reiser4_tree * tree /* tree to scan */ ,
++                       coord_t * coord /* coord to start from */ ,
++                       lock_handle * lh /* lock handle to start with and to
++                                         * update along the way */ ,
++                       tree_iterate_actor_t actor /* function to call on each
++                                                   * item/unit */ ,
++                       void *arg /* argument to pass to @actor */ ,
++                       znode_lock_mode mode /* lock mode on scanned nodes */ ,
++                       int through_units_p /* call @actor on each item or on
++                                            * each unit */ )
 +{
 +      int result;
 +
@@ -65454,9 +65210,7 @@ Index: linux-2.6.16/fs/reiser4/search.c
 +                              }
 +                      }
 +              }
-+      } else
-+              /* long-term locking failed. Restart. */
-+              ;
++      }
 +
 +      zput(vroot);
 +
@@ -65490,12 +65244,12 @@ Index: linux-2.6.16/fs/reiser4/search.c
 +      /* loop for restarts */
 +      restart:
 +
-+      assert("nikita-3024", schedulable());
++      assert("nikita-3024", reiser4_schedulable());
 +
 +      h->result = CBK_COORD_FOUND;
 +      /* connect_znode() needs it */
-+      h->ld_key = *min_key();
-+      h->rd_key = *max_key();
++      h->ld_key = *reiser4_min_key();
++      h->rd_key = *reiser4_max_key();
 +      h->flags |= CBK_DKSET;
 +      h->error = NULL;
 +
@@ -65529,7 +65283,7 @@ Index: linux-2.6.16/fs/reiser4/search.c
 +                           IS_POW(iterations))) {
 +                      warning("nikita-1481", "Too many iterations: %i",
 +                              iterations);
-+                      print_key("key", h->key);
++                      reiser4_print_key("key", h->key);
 +                      ++iterations;
 +              } else if (unlikely(iterations > REISER4_MAX_CBK_ITERATIONS)) {
 +                      h->error =
@@ -65551,7 +65305,7 @@ Index: linux-2.6.16/fs/reiser4/search.c
 +                      /* deadlock avoidance is normal case. */
 +                      if (h->result != -E_DEADLOCK)
 +                              ++iterations;
-+                      preempt_point();
++                      reiser4_preempt_point();
 +                      goto restart;
 +              }
 +      }
@@ -65563,7 +65317,7 @@ Index: linux-2.6.16/fs/reiser4/search.c
 +                      h->error, h->level, h->lock_level, h->stop_level,
 +                      lock_mode_name(h->lock_mode), bias_name(h->bias));
 +              reiser4_print_address("block", &h->block);
-+              print_key("key", h->key);
++              reiser4_print_key("key", h->key);
 +              print_coord_content("coord", h->coord);
 +      }
 +      /* `unlikely' error case */
@@ -65678,11 +65432,12 @@ Index: linux-2.6.16/fs/reiser4/search.c
 +      reiser4_key key;
 +      znode *active;
 +
-+      assert("nikita-3025", schedulable());
++      assert("nikita-3025", reiser4_schedulable());
 +
 +      /* acquire reference to @active node */
 +      active =
-+          zget(h->tree, &h->block, h->parent_lh->node, h->level, get_gfp_mask());
++          zget(h->tree, &h->block, h->parent_lh->node, h->level,
++               reiser4_ctx_gfp_mask_get());
 +
 +      if (IS_ERR(active)) {
 +              h->result = PTR_ERR(active);
@@ -65800,8 +65555,8 @@ Index: linux-2.6.16/fs/reiser4/search.c
 +      if (ldkeyset && !node_is_empty(active) &&
 +          !keyeq(leftmost_key_in_node(active, &key), &ldkey)) {
 +              warning("vs-3533", "Keys are inconsistent. Fsck?");
-+              print_key("inparent", &ldkey);
-+              print_key("inchild", &key);
++              reiser4_print_key("inparent", &ldkey);
++              reiser4_print_key("inchild", &key);
 +              h->result = RETERR(-EIO);
 +              zrelse(active);
 +              return LOOKUP_DONE;
@@ -66030,7 +65785,7 @@ Index: linux-2.6.16/fs/reiser4/search.c
 +               * are rechecked under dk lock below.
 +               */
 +              if (znode_get_level(node) == level &&
-+                  /* min_key < key < max_key */
++                  /* reiser4_min_key < key < reiser4_max_key */
 +                  znode_contains_key_strict(node, key, isunique)) {
 +                      zref(node);
 +                      result = 0;
@@ -66338,7 +66093,7 @@ Index: linux-2.6.16/fs/reiser4/search.c
 +                     item_body_by_coord(p), item_length_by_coord(p));
 +      if (znode_is_loaded(p->node)) {
 +              item_key_by_coord(p, &key);
-+              print_key(prefix, &key);
++              reiser4_print_key(prefix, &key);
 +      }
 +}
 +
@@ -66358,7 +66113,7 @@ Index: linux-2.6.16/fs/reiser4/search.c
 +
 +      if (block == NULL)
 +              sprintf(address, "null");
-+      else if (blocknr_is_fake(block))
++      else if (reiser4_blocknr_is_fake(block))
 +              sprintf(address, "%llx", (unsigned long long)(*block));
 +      else
 +              sprintf(address, "%llu", (unsigned long long)(*block));
@@ -66450,11 +66205,10 @@ Index: linux-2.6.16/fs/reiser4/search.c
 +   scroll-step: 1
 +   End:
 +*/
-Index: linux-2.6.16/fs/reiser4/status_flags.c
-===================================================================
---- /dev/null
-+++ linux-2.6.16/fs/reiser4/status_flags.c
-@@ -0,0 +1,176 @@
+diff -urN linux-2.6.22.orig/fs/reiser4/status_flags.c linux-2.6.22/fs/reiser4/status_flags.c
+--- linux-2.6.22.orig/fs/reiser4/status_flags.c        1970-01-01 03:00:00.000000000 +0300
++++ linux-2.6.22/fs/reiser4/status_flags.c     2007-07-29 00:25:35.016732714 +0400
+@@ -0,0 +1,175 @@
 +/* Copyright 2001, 2002, 2003 by Hans Reiser, licensing governed by
 + * reiser4/README */
 +
@@ -66497,15 +66251,14 @@ Index: linux-2.6.16/fs/reiser4/status_flags.c
 +      struct bio *bio;
 +      struct page *page;
 +
-+
 +      get_super_private(sb)->status_page = NULL;
 +      get_super_private(sb)->status_bio = NULL;
 +
-+      page = alloc_pages(GFP_KERNEL, 0);
++      page = alloc_pages(reiser4_ctx_gfp_mask_get(), 0);
 +      if (!page)
 +              return -ENOMEM;
 +
-+      bio = bio_alloc(GFP_KERNEL, 1);
++      bio = bio_alloc(reiser4_ctx_gfp_mask_get(), 1);
 +      if (bio != NULL) {
 +              bio->bi_sector = block * (sb->s_blocksize >> 9);
 +              bio->bi_bdev = sb->s_bdev;
@@ -66521,7 +66274,7 @@ Index: linux-2.6.16/fs/reiser4/status_flags.c
 +      }
 +      lock_page(page);
 +      submit_bio(READ, bio);
-+      blk_run_address_space(get_super_fake(sb)->i_mapping);
++      blk_run_address_space(reiser4_get_super_fake(sb)->i_mapping);
 +      wait_on_page_locked(page);
 +      if (!PageUptodate(page)) {
 +              warning("green-2007",
@@ -66616,7 +66369,7 @@ Index: linux-2.6.16/fs/reiser4/status_flags.c
 +      lock_page(get_super_private(sb)->status_page);  // Safe as nobody should touch our page.
 +      /* We can block now, but we have no other choice anyway */
 +      submit_bio(WRITE, bio);
-+      blk_run_address_space(get_super_fake(sb)->i_mapping);
++      blk_run_address_space(reiser4_get_super_fake(sb)->i_mapping);
 +      return 0;               // We do not wait for io to finish.
 +}
 +
@@ -66631,10 +66384,9 @@ Index: linux-2.6.16/fs/reiser4/status_flags.c
 +      get_super_private(sb)->status_bio = NULL;
 +      return 0;
 +}
-Index: linux-2.6.16/fs/reiser4/status_flags.h
-===================================================================
---- /dev/null
-+++ linux-2.6.16/fs/reiser4/status_flags.h
+diff -urN linux-2.6.22.orig/fs/reiser4/status_flags.h linux-2.6.22/fs/reiser4/status_flags.h
+--- linux-2.6.22.orig/fs/reiser4/status_flags.h        1970-01-01 03:00:00.000000000 +0300
++++ linux-2.6.22/fs/reiser4/status_flags.h     2007-07-29 00:25:35.016732714 +0400
 @@ -0,0 +1,43 @@
 +/* Copyright 2001, 2002, 2003 by Hans Reiser, licensing governed by
 + * reiser4/README */
@@ -66679,11 +66431,10 @@ Index: linux-2.6.16/fs/reiser4/status_flags.h
 +int reiser4_status_finish(void);
 +
 +#endif
-Index: linux-2.6.16/fs/reiser4/super.c
-===================================================================
---- /dev/null
-+++ linux-2.6.16/fs/reiser4/super.c
-@@ -0,0 +1,313 @@
+diff -urN linux-2.6.22.orig/fs/reiser4/super.c linux-2.6.22/fs/reiser4/super.c
+--- linux-2.6.22.orig/fs/reiser4/super.c       1970-01-01 03:00:00.000000000 +0300
++++ linux-2.6.22/fs/reiser4/super.c    2007-07-29 00:25:35.020733749 +0400
+@@ -0,0 +1,316 @@
 +/* Copyright 2001, 2002, 2003, 2004 by Hans Reiser, licensing governed by
 + * reiser4/README */
 +
@@ -66703,7 +66454,6 @@ Index: linux-2.6.16/fs/reiser4/super.c
 +#include <linux/types.h>      /* for __u??  */
 +#include <linux/fs.h>         /* for struct super_block  */
 +
-+
 +static __u64 reserved_for_gid(const struct super_block *super, gid_t gid);
 +static __u64 reserved_for_uid(const struct super_block *super, uid_t uid);
 +static __u64 reserved_for_root(const struct super_block *super);
@@ -66716,8 +66466,7 @@ Index: linux-2.6.16/fs/reiser4/super.c
 +}
 +
 +/* Return reiser4 fstype: value that is returned in ->f_type field by statfs() */
-+long statfs_type(const struct super_block *super UNUSED_ARG   /* super block
-+                                                               * queried */ )
++long reiser4_statfs_type(const struct super_block *super UNUSED_ARG)
 +{
 +      assert("nikita-448", super != NULL);
 +      assert("nikita-449", is_reiser4_super(super));
@@ -66735,6 +66484,7 @@ Index: linux-2.6.16/fs/reiser4/super.c
 +      return get_super_private(super)->block_count;
 +}
 +
++#if REISER4_DEBUG
 +/*
 + * number of blocks in the current file system
 + */
@@ -66742,6 +66492,7 @@ Index: linux-2.6.16/fs/reiser4/super.c
 +{
 +      return get_current_super_private()->block_count;
 +}
++#endif  /*  REISER4_DEBUG  */
 +
 +/* set number of block in filesystem */
 +void reiser4_set_block_count(const struct super_block *super, __u64 nr)
@@ -66844,7 +66595,7 @@ Index: linux-2.6.16/fs/reiser4/super.c
 +      return get_super_private(super)->blocks_grabbed;
 +}
 +
-+__u64 flush_reserved(const struct super_block * super)
++__u64 reiser4_flush_reserved(const struct super_block * super)
 +{
 +      assert("vpf-285", super != NULL);
 +      assert("vpf-286", is_reiser4_super(super));
@@ -66880,7 +66631,8 @@ Index: linux-2.6.16/fs/reiser4/super.c
 +}
 +
 +/* space allocator used by this file system */
-+reiser4_space_allocator *get_space_allocator(const struct super_block * super)
++reiser4_space_allocator * reiser4_get_space_allocator(const struct super_block
++                                                    *super)
 +{
 +      assert("nikita-1965", super != NULL);
 +      assert("nikita-1966", is_reiser4_super(super));
@@ -66888,7 +66640,7 @@ Index: linux-2.6.16/fs/reiser4/super.c
 +}
 +
 +/* return fake inode used to bind formatted nodes in the page cache */
-+struct inode *get_super_fake(const struct super_block *super  /* super block
++struct inode *reiser4_get_super_fake(const struct super_block *super  /* super block
 +                                                                 queried */ )
 +{
 +      assert("nikita-1757", super != NULL);
@@ -66896,7 +66648,7 @@ Index: linux-2.6.16/fs/reiser4/super.c
 +}
 +
 +/* return fake inode used to bind copied on capture nodes in the page cache */
-+struct inode *get_cc_fake(const struct super_block *super     /* super block
++struct inode *reiser4_get_cc_fake(const struct super_block *super     /* super block
 +                                                                 queried */ )
 +{
 +      assert("nikita-1757", super != NULL);
@@ -66904,14 +66656,14 @@ Index: linux-2.6.16/fs/reiser4/super.c
 +}
 +
 +/* return fake inode used to bind bitmaps and journlal heads */
-+struct inode *get_bitmap_fake(const struct super_block *super)
++struct inode *reiser4_get_bitmap_fake(const struct super_block *super)
 +{
 +      assert("nikita-17571", super != NULL);
 +      return get_super_private(super)->bitmap;
 +}
 +
 +/* tree used by this file system */
-+reiser4_tree *get_tree(const struct super_block * super       /* super block
++reiser4_tree *reiser4_get_tree(const struct super_block * super       /* super block
 +                                                       * queried */ )
 +{
 +      assert("nikita-460", super != NULL);
@@ -66973,13 +66725,14 @@ Index: linux-2.6.16/fs/reiser4/super.c
 +      assert("nikita-2957", super != NULL);
 +      assert("nikita-2958", blk != NULL);
 +
-+      if (blocknr_is_fake(blk))
++      if (reiser4_blocknr_is_fake(blk))
 +              return 1;
 +
 +      sbinfo = get_super_private(super);
 +      return *blk < sbinfo->block_count;
 +}
 +
++#if REISER4_DEBUG
 +/*
 + * true, if block number @blk makes sense for the current file system
 + */
@@ -66987,6 +66740,7 @@ Index: linux-2.6.16/fs/reiser4/super.c
 +{
 +      return reiser4_blocknr_is_sane_for(reiser4_get_current_sb(), blk);
 +}
++#endif  /*  REISER4_DEBUG  */
 +
 +/* Make Linus happy.
 +   Local variables:
@@ -66997,11 +66751,10 @@ Index: linux-2.6.16/fs/reiser4/super.c
 +   fill-column: 120
 +   End:
 +*/
-Index: linux-2.6.16/fs/reiser4/super.h
-===================================================================
---- /dev/null
-+++ linux-2.6.16/fs/reiser4/super.h
-@@ -0,0 +1,468 @@
+diff -urN linux-2.6.22.orig/fs/reiser4/super.h linux-2.6.22/fs/reiser4/super.h
+--- linux-2.6.22.orig/fs/reiser4/super.h       1970-01-01 03:00:00.000000000 +0300
++++ linux-2.6.22/fs/reiser4/super.h    2007-07-29 00:25:35.020733749 +0400
+@@ -0,0 +1,464 @@
 +/* Copyright 2001, 2002, 2003, 2004 by Hans Reiser, licensing governed by
 + * reiser4/README */
 +
@@ -67020,12 +66773,12 @@ Index: linux-2.6.16/fs/reiser4/super.h
 +/*
 + * Flush algorithms parameters.
 + */
-+typedef struct {
++struct flush_params {
 +      unsigned relocate_threshold;
 +      unsigned relocate_distance;
 +      unsigned written_threshold;
 +      unsigned scan_maxnodes;
-+} flush_params;
++};
 +
 +typedef enum {
 +      /*
@@ -67048,25 +66801,22 @@ Index: linux-2.6.16/fs/reiser4/super.h
 +      REISER4_BSD_GID = 2,
 +      /* [mac]_time are 32 bit in inode */
 +      REISER4_32_BIT_TIMES = 3,
-+      /* allow concurrent flushes */
-+      REISER4_MTFLUSH = 4,
 +      /* load all bitmap blocks at mount time */
 +      REISER4_DONT_LOAD_BITMAP = 5,
 +      /* enforce atomicity during write(2) */
 +      REISER4_ATOMIC_WRITE = 6,
 +      /* don't use write barriers in the log writer code. */
 +      REISER4_NO_WRITE_BARRIER = 7
-+
 +} reiser4_fs_flag;
 +
 +/*
 + * VFS related operation vectors.
 + */
-+typedef struct object_ops {
++struct object_ops {
 +      struct super_operations super;
 +      struct dentry_operations dentry;
 +      struct export_operations export;
-+} object_ops;
++};
 +
 +/* reiser4-specific part of super block
 +
@@ -67113,7 +66863,7 @@ Index: linux-2.6.16/fs/reiser4/super.h
 +
 +    ->last_committed_tx
 +
-+   is protected by ->tmgr.commit_semaphore
++   is protected by ->tmgr.commit_mutex
 +
 +   Invariants involving this data-type:
 +
@@ -67195,6 +66945,11 @@ Index: linux-2.6.16/fs/reiser4/super.h
 +      /* unique file-system identifier */
 +      __u32 fsuid;
 +
++      /* On-disk format version. If does not equal to the disk_format
++         plugin version, some format updates (e.g. enlarging plugin
++         set, etc) may have place on mount. */
++      int version;
++
 +      /* file-system wide flags. See reiser4_fs_flag enum */
 +      unsigned long fs_flags;
 +
@@ -67223,7 +66978,7 @@ Index: linux-2.6.16/fs/reiser4/super.h
 +      unsigned long optimal_io_size;
 +
 +      /* parameters for the flush algorithm */
-+      flush_params flush;
++      struct flush_params flush;
 +
 +      /* pointers to jnodes for journal header and footer */
 +      jnode *journal_header;
@@ -67243,19 +66998,16 @@ Index: linux-2.6.16/fs/reiser4/super.h
 +      /* committed number of files (oid allocator state variable ) */
 +      __u64 nr_files_committed;
 +
-+      ra_params_t ra_params;
++      struct formatted_ra_params ra_params;
 +
 +      /*
-+       * A semaphore for serializing cut tree operation if out-of-free-space:
++       * A mutex for serializing cut tree operation if out-of-free-space:
 +       * the only one cut_tree thread is allowed to grab space from reserved
 +       * area (it is 5% of disk space)
 +       */
-+      struct semaphore delete_sema;
-+      /* task owning ->delete_sema */
-+      struct task_struct *delete_sema_owner;
-+
-+      /* serialize semaphore */
-+      struct semaphore flush_sema;
++      struct mutex delete_mutex;
++      /* task owning ->delete_mutex */
++      struct task_struct *delete_mutex_owner;
 +
 +      /* Diskmap's blocknumber */
 +      __u64 diskmap_block;
@@ -67264,13 +67016,13 @@ Index: linux-2.6.16/fs/reiser4/super.h
 +      int onerror;
 +
 +      /* operations for objects on this file system */
-+      object_ops ops;
++      struct object_ops ops;
 +
 +      /*
 +       * structure to maintain d_cursors. See plugin/file_ops_readdir.c for
 +       * more details
 +       */
-+      d_cursor_info d_info;
++      struct d_cursor_info d_info;
 +
 +#ifdef CONFIG_REISER4_BADBLOCKS
 +      /* Alternative master superblock offset (in bytes) */
@@ -67304,7 +67056,6 @@ Index: linux-2.6.16/fs/reiser4/super.h
 +extern reiser4_super_info_data *get_super_private_nocheck(const struct
 +                                                        super_block *super);
 +
-+
 +/* Return reiser4-specific part of super block */
 +static inline reiser4_super_info_data *get_super_private(const struct
 +                                                       super_block *super)
@@ -67320,7 +67071,6 @@ Index: linux-2.6.16/fs/reiser4/super.h
 +      return &get_super_private(super)->entd;
 +}
 +
-+
 +/* "Current" super-block: main super block used during current system
 +   call. Reference to this super block is stored in reiser4_context. */
 +static inline struct super_block *reiser4_get_current_sb(void)
@@ -67336,7 +67086,7 @@ Index: linux-2.6.16/fs/reiser4/super.h
 +      return get_super_private(reiser4_get_current_sb());
 +}
 +
-+static inline ra_params_t *get_current_super_ra_params(void)
++static inline struct formatted_ra_params *get_current_super_ra_params(void)
 +{
 +      return &(get_current_super_private()->ra_params);
 +}
@@ -67375,7 +67125,7 @@ Index: linux-2.6.16/fs/reiser4/super.h
 +
 +extern __u64 reiser4_current_block_count(void);
 +
-+extern void build_object_ops(struct super_block *super, object_ops * ops);
++extern void build_object_ops(struct super_block *super, struct object_ops * ops);
 +
 +#define REISER4_SUPER_MAGIC 0x52345362        /* (*(__u32 *)"R4Sb"); */
 +
@@ -67390,9 +67140,9 @@ Index: linux-2.6.16/fs/reiser4/super.h
 +      spin_unlock(&(sbinfo->guard));
 +}
 +
-+extern __u64 flush_reserved(const struct super_block *);
++extern __u64 reiser4_flush_reserved(const struct super_block *);
 +extern int reiser4_is_set(const struct super_block *super, reiser4_fs_flag f);
-+extern long statfs_type(const struct super_block *super);
++extern long reiser4_statfs_type(const struct super_block *super);
 +extern __u64 reiser4_block_count(const struct super_block *super);
 +extern void reiser4_set_block_count(const struct super_block *super, __u64 nr);
 +extern __u64 reiser4_data_blocks(const struct super_block *super);
@@ -67411,14 +67161,14 @@ Index: linux-2.6.16/fs/reiser4/super.h
 +extern long reiser4_reserved_blocks(const struct super_block *super, uid_t uid,
 +                                  gid_t gid);
 +
-+extern reiser4_space_allocator *get_space_allocator(const struct super_block
-+                                                  *super);
-+extern reiser4_oid_allocator *get_oid_allocator(const struct super_block
-+                                              *super);
-+extern struct inode *get_super_fake(const struct super_block *super);
-+extern struct inode *get_cc_fake(const struct super_block *super);
-+extern struct inode *get_bitmap_fake(const struct super_block *super);
-+extern reiser4_tree *get_tree(const struct super_block *super);
++extern reiser4_space_allocator *
++reiser4_get_space_allocator(const struct super_block *super);
++extern reiser4_oid_allocator *
++reiser4_get_oid_allocator(const struct super_block *super);
++extern struct inode *reiser4_get_super_fake(const struct super_block *super);
++extern struct inode *reiser4_get_cc_fake(const struct super_block *super);
++extern struct inode *reiser4_get_bitmap_fake(const struct super_block *super);
++extern reiser4_tree *reiser4_get_tree(const struct super_block *super);
 +extern int is_reiser4_super(const struct super_block *super);
 +
 +extern int reiser4_blocknr_is_sane(const reiser4_block_nr * blk);
@@ -67428,12 +67178,12 @@ Index: linux-2.6.16/fs/reiser4/super.h
 +extern int reiser4_done_super(struct super_block *s);
 +
 +/* step of fill super */
-+extern int init_fs_info(struct super_block *);
-+extern void done_fs_info(struct super_block *);
-+extern int init_super_data(struct super_block *, char *opt_string);
-+extern int init_read_super(struct super_block *, int silent);
-+extern int init_root_inode(struct super_block *);
-+
++extern int reiser4_init_fs_info(struct super_block *);
++extern void reiser4_done_fs_info(struct super_block *);
++extern int reiser4_init_super_data(struct super_block *, char *opt_string);
++extern int reiser4_init_read_super(struct super_block *, int silent);
++extern int reiser4_init_root_inode(struct super_block *);
++extern reiser4_plugin *get_default_plugin(pset_member memb);
 +
 +/* Maximal possible object id. */
 +#define  ABSOLUTE_MAX_OID ((oid_t)~0)
@@ -67451,12 +67201,11 @@ Index: linux-2.6.16/fs/reiser4/super.h
 +void print_fs_info(const char *prefix, const struct super_block *);
 +#endif
 +
-+extern void destroy_reiser4_cache(kmem_cache_t **);
++extern void destroy_reiser4_cache(struct kmem_cache **);
 +
 +extern struct super_operations reiser4_super_operations;
 +extern struct export_operations reiser4_export_operations;
 +extern struct dentry_operations reiser4_dentry_operations;
-+extern struct dentry *reiser4_debugfs_root;
 +
 +/* __REISER4_SUPER_H__ */
 +#endif
@@ -67470,11 +67219,10 @@ Index: linux-2.6.16/fs/reiser4/super.h
 + * fill-column: 120
 + * End:
 + */
-Index: linux-2.6.16/fs/reiser4/super_ops.c
-===================================================================
---- /dev/null
-+++ linux-2.6.16/fs/reiser4/super_ops.c
-@@ -0,0 +1,721 @@
+diff -urN linux-2.6.22.orig/fs/reiser4/super_ops.c linux-2.6.22/fs/reiser4/super_ops.c
+--- linux-2.6.22.orig/fs/reiser4/super_ops.c   1970-01-01 03:00:00.000000000 +0300
++++ linux-2.6.22/fs/reiser4/super_ops.c        2007-07-29 00:25:35.020733749 +0400
+@@ -0,0 +1,725 @@
 +/* Copyright 2005 by Hans Reiser, licensing governed by
 + * reiser4/README */
 +
@@ -67491,7 +67239,9 @@ Index: linux-2.6.16/fs/reiser4/super_ops.c
 +#include <linux/debugfs.h>
 +
 +/* slab cache for inodes */
-+static kmem_cache_t *inode_cache;
++static struct kmem_cache *inode_cache;
++
++static struct dentry *reiser4_debugfs_root = NULL;
 +
 +/**
 + * init_once - constructor for reiser4 inodes
@@ -67502,31 +67252,29 @@ Index: linux-2.6.16/fs/reiser4/super_ops.c
 + * Initialization function to be called when new page is allocated by reiser4
 + * inode cache. It is set on inode cache creation.
 + */
-+static void init_once(void *obj, kmem_cache_t *cache, unsigned long flags)
++static void init_once(void *obj, struct kmem_cache *cache, unsigned long flags)
 +{
-+      reiser4_inode_object *info;
++      struct reiser4_inode_object *info;
 +
 +      info = obj;
 +
-+      if ((flags & (SLAB_CTOR_VERIFY | SLAB_CTOR_CONSTRUCTOR)) ==
-+          SLAB_CTOR_CONSTRUCTOR) {
-+              /* initialize vfs inode */
-+              inode_init_once(&info->vfs_inode);
++      /* initialize vfs inode */
++      inode_init_once(&info->vfs_inode);
 +
-+              /*
-+               * initialize reiser4 specific part fo inode.
-+               * NOTE-NIKITA add here initializations for locks, list heads,
-+               * etc. that will be added to our private inode part.
-+               */
-+              INIT_LIST_HEAD(get_readdir_list(&info->vfs_inode));
-+              /* init semaphore which is used during inode loading */
-+              loading_init_once(&info->p);
-+              INIT_RADIX_TREE(jnode_tree_by_reiser4_inode(&info->p),
-+                              GFP_ATOMIC);
++      /*
++       * initialize reiser4 specific part fo inode.
++       * NOTE-NIKITA add here initializations for locks, list heads,
++       * etc. that will be added to our private inode part.
++       */
++      INIT_LIST_HEAD(get_readdir_list(&info->vfs_inode));
++      init_rwsem(&info->p.conv_sem);
++      /* init semaphore which is used during inode loading */
++      loading_init_once(&info->p);
++      INIT_RADIX_TREE(jnode_tree_by_reiser4_inode(&info->p),
++                      GFP_ATOMIC);
 +#if REISER4_DEBUG
-+              info->p.nr_jnodes = 0;
++      info->p.nr_jnodes = 0;
 +#endif
-+      }
 +}
 +
 +/**
@@ -67537,7 +67285,7 @@ Index: linux-2.6.16/fs/reiser4/super_ops.c
 +static int init_inodes(void)
 +{
 +      inode_cache = kmem_cache_create("reiser4_inode",
-+                                      sizeof(reiser4_inode_object),
++                                      sizeof(struct reiser4_inode_object),
 +                                      0,
 +                                      SLAB_HWCACHE_ALIGN |
 +                                      SLAB_RECLAIM_ACCOUNT, init_once, NULL);
@@ -67564,23 +67312,25 @@ Index: linux-2.6.16/fs/reiser4/super_ops.c
 + */
 +static struct inode *reiser4_alloc_inode(struct super_block *super)
 +{
-+      reiser4_inode_object *obj;
++      struct reiser4_inode_object *obj;
 +
 +      assert("nikita-1696", super != NULL);
-+      obj = kmem_cache_alloc(inode_cache, SLAB_KERNEL);
++      obj = kmem_cache_alloc(inode_cache, reiser4_ctx_gfp_mask_get());
 +      if (obj != NULL) {
 +              reiser4_inode *info;
 +
 +              info = &obj->p;
 +
-+              info->hset = info->pset = plugin_set_get_empty();
++              info->pset = plugin_set_get_empty();
++              info->hset = plugin_set_get_empty();
 +              info->extmask = 0;
 +              info->locality_id = 0ull;
 +              info->plugin_mask = 0;
++              info->heir_mask = 0;
 +#if !REISER4_INO_IS_OID
 +              info->oid_hi = 0;
 +#endif
-+              seal_init(&info->sd_seal, NULL, NULL);
++              reiser4_seal_init(&info->sd_seal, NULL, NULL);
 +              coord_init_invalid(&info->sd_coord, NULL);
 +              info->flags = 0;
 +              spin_lock_init(&info->guard);
@@ -67611,9 +67361,11 @@ Index: linux-2.6.16/fs/reiser4/super_ops.c
 +              if (fplug->destroy_inode != NULL)
 +                      fplug->destroy_inode(inode);
 +      }
-+      dispose_cursors(inode);
++      reiser4_dispose_cursors(inode);
 +      if (info->pset)
 +              plugin_set_put(info->pset);
++      if (info->hset)
++              plugin_set_put(info->hset);
 +
 +      /*
 +       * cannot add similar assertion about ->i_list as prune_icache return
@@ -67628,7 +67380,7 @@ Index: linux-2.6.16/fs/reiser4/super_ops.c
 +      loading_destroy(info);
 +
 +      kmem_cache_free(inode_cache,
-+                      container_of(info, reiser4_inode_object, p));
++                      container_of(info, struct reiser4_inode_object, p));
 +}
 +
 +/**
@@ -67665,7 +67417,7 @@ Index: linux-2.6.16/fs/reiser4/super_ops.c
 +      reiser4_context *ctx;
 +      file_plugin *fplug;
 +
-+      ctx = init_context(inode->i_sb);
++      ctx = reiser4_init_context(inode->i_sb);
 +      if (IS_ERR(ctx)) {
 +              warning("vs-15", "failed to init context");
 +              return;
@@ -67677,6 +67429,7 @@ Index: linux-2.6.16/fs/reiser4/super_ops.c
 +                      fplug->delete_object(inode);
 +      }
 +
++      truncate_inode_pages(&inode->i_data, 0);
 +      inode->i_blocks = 0;
 +      clear_inode(inode);
 +      reiser4_exit_context(ctx);
@@ -67700,24 +67453,24 @@ Index: linux-2.6.16/fs/reiser4/super_ops.c
 +      debugfs_remove(sbinfo->tmgr.debugfs_id_count);
 +      debugfs_remove(sbinfo->debugfs_root);
 +
-+      ctx = init_context(super);
++      ctx = reiser4_init_context(super);
 +      if (IS_ERR(ctx)) {
 +              warning("vs-17", "failed to init context");
 +              return;
-+      }       
++      }
 +
 +      /* have disk format plugin to free its resources */
 +      if (get_super_private(super)->df_plug->release)
 +              get_super_private(super)->df_plug->release(super);
 +
-+      done_formatted_fake(super);
++      reiser4_done_formatted_fake(super);
 +
 +      /* stop daemons: ktxnmgr and entd */
-+      done_entd(super);
-+      done_ktxnmgrd(super);
-+      done_txnmgr(&sbinfo->tmgr);
++      reiser4_done_entd(super);
++      reiser4_done_ktxnmgrd(super);
++      reiser4_done_txnmgr(&sbinfo->tmgr);
 +
-+      done_fs_info(super);
++      reiser4_done_fs_info(super);
 +      reiser4_exit_context(ctx);
 +}
 +
@@ -67734,16 +67487,17 @@ Index: linux-2.6.16/fs/reiser4/super_ops.c
 +
 +      assert("vs-1700", !rofs_super(super));
 +
-+      ctx = init_context(super);
++      ctx = reiser4_init_context(super);
 +      if (IS_ERR(ctx)) {
 +              warning("vs-16", "failed to init context");
 +              return;
 +      }
 +
-+      ret = capture_super_block(super);
++      ret = reiser4_capture_super_block(super);
 +      if (ret != 0)
 +              warning("vs-1701",
-+                      "capture_super_block failed in write_super: %d", ret);
++                      "reiser4_capture_super_block failed in write_super: %d",
++                      ret);
 +      ret = txnmgr_force_commit_all(super, 0);
 +      if (ret != 0)
 +              warning("jmacd-77113",
@@ -67761,7 +67515,7 @@ Index: linux-2.6.16/fs/reiser4/super_ops.c
 + *
 + * Returns information about filesystem.
 + */
-+static int reiser4_statfs(struct super_block *super, struct kstatfs *statfs)
++static int reiser4_statfs(struct dentry *dentry, struct kstatfs *statfs)
 +{
 +      sector_t total;
 +      sector_t reserved;
@@ -67769,15 +67523,16 @@ Index: linux-2.6.16/fs/reiser4/super_ops.c
 +      sector_t forroot;
 +      sector_t deleted;
 +      reiser4_context *ctx;
++      struct super_block *super = dentry->d_sb;
 +
 +      assert("nikita-408", super != NULL);
 +      assert("nikita-409", statfs != NULL);
 +
-+      ctx = init_context(super);
++      ctx = reiser4_init_context(super);
 +      if (IS_ERR(ctx))
 +              return PTR_ERR(ctx);
 +
-+      statfs->f_type = statfs_type(super);
++      statfs->f_type = reiser4_statfs_type(super);
 +      statfs->f_bsize = super->s_blocksize;
 +
 +      /*
@@ -67873,7 +67628,7 @@ Index: linux-2.6.16/fs/reiser4/super_ops.c
 +      to_write = wbc->nr_to_write;
 +      assert("vs-49", wbc->older_than_this == NULL);
 +
-+      ctx = init_context(super);
++      ctx = reiser4_init_context(super);
 +      if (IS_ERR(ctx)) {
 +              warning("vs-13", "failed to init context");
 +              return;
@@ -67887,7 +67642,7 @@ Index: linux-2.6.16/fs/reiser4/super_ops.c
 +
 +      /* flush goes here */
 +      wbc->nr_to_write = to_write;
-+      writeout(super, wbc);
++      reiser4_writeout(super, wbc);
 +
 +      /* avoid recursive calls to ->sync_inodes */
 +      context_set_commit_async(ctx);
@@ -67953,31 +67708,31 @@ Index: linux-2.6.16/fs/reiser4/super_ops.c
 +      init_stack_context(&ctx, super);
 +
 +      /* allocate reiser4 specific super block */
-+      if ((result = init_fs_info(super)) != 0)
++      if ((result = reiser4_init_fs_info(super)) != 0)
 +              goto failed_init_sinfo;
 +
 +      sbinfo = get_super_private(super);
 +      /* initialize various reiser4 parameters, parse mount options */
-+      if ((result = init_super_data(super, data)) != 0)
++      if ((result = reiser4_init_super_data(super, data)) != 0)
 +              goto failed_init_super_data;
 +
 +      /* read reiser4 master super block, initialize disk format plugin */
-+      if ((result = init_read_super(super, silent)) != 0)
++      if ((result = reiser4_init_read_super(super, silent)) != 0)
 +              goto failed_init_read_super;
 +
 +      /* initialize transaction manager */
-+      init_txnmgr(&sbinfo->tmgr);
++      reiser4_init_txnmgr(&sbinfo->tmgr);
 +
 +      /* initialize ktxnmgrd context and start kernel thread ktxnmrgd */
-+      if ((result = init_ktxnmgrd(super)) != 0)
++      if ((result = reiser4_init_ktxnmgrd(super)) != 0)
 +              goto failed_init_ktxnmgrd;
 +
 +      /* initialize entd context and start kernel thread entd */
-+      if ((result = init_entd(super)) != 0)
++      if ((result = reiser4_init_entd(super)) != 0)
 +              goto failed_init_entd;
 +
 +      /* initialize address spaces for formatted nodes and bitmaps */
-+      if ((result = init_formatted_fake(super)) != 0)
++      if ((result = reiser4_init_formatted_fake(super)) != 0)
 +              goto failed_init_formatted_fake;
 +
 +      /* initialize disk format plugin */
@@ -67993,9 +67748,12 @@ Index: linux-2.6.16/fs/reiser4/super_ops.c
 +      sbinfo->nr_files_committed = oids_used(super);
 +
 +      /* get inode of root directory */
-+      if ((result = init_root_inode(super)) != 0)
++      if ((result = reiser4_init_root_inode(super)) != 0)
 +              goto failed_init_root_inode;
 +
++      if ((result = get_super_private(super)->df_plug->version_update(super)) != 0 )
++              goto failed_update_format_version;
++
 +      process_safelinks(super);
 +      reiser4_exit_context(&ctx);
 +
@@ -68013,20 +67771,21 @@ Index: linux-2.6.16/fs/reiser4/super_ops.c
 +      }
 +      return 0;
 +
++ failed_update_format_version:
 + failed_init_root_inode:
 +      if (sbinfo->df_plug->release)
 +              sbinfo->df_plug->release(super);
 + failed_init_disk_format:
-+      done_formatted_fake(super);
++      reiser4_done_formatted_fake(super);
 + failed_init_formatted_fake:
-+      done_entd(super);
++      reiser4_done_entd(super);
 + failed_init_entd:
-+      done_ktxnmgrd(super);
++      reiser4_done_ktxnmgrd(super);
 + failed_init_ktxnmgrd:
-+      done_txnmgr(&sbinfo->tmgr);
++      reiser4_done_txnmgr(&sbinfo->tmgr);
 + failed_init_read_super:
 + failed_init_super_data:
-+      done_fs_info(super);
++      reiser4_done_fs_info(super);
 + failed_init_sinfo:
 +      reiser4_exit_context(&ctx);
 +      return result;
@@ -68041,12 +67800,10 @@ Index: linux-2.6.16/fs/reiser4/super_ops.c
 + *
 + * Reiser4 mount entry.
 + */
-+static struct super_block *reiser4_get_sb(struct file_system_type *fs_type,
-+                                        int flags,
-+                                        const char *dev_name,
-+                                        void *data)
++static int reiser4_get_sb(struct file_system_type *fs_type, int flags,
++                      const char *dev_name, void *data, struct vfsmount *mnt)
 +{
-+      return get_sb_bdev(fs_type, flags, dev_name, data, fill_super);
++      return get_sb_bdev(fs_type, flags, dev_name, data, fill_super, mnt);
 +}
 +
 +/* structure describing the reiser4 filesystem implementation */
@@ -68059,18 +67816,13 @@ Index: linux-2.6.16/fs/reiser4/super_ops.c
 +      .next = NULL
 +};
 +
-+void destroy_reiser4_cache(kmem_cache_t **cachep)
++void destroy_reiser4_cache(struct kmem_cache **cachep)
 +{
-+      int result;
-+
 +      BUG_ON(*cachep == NULL);
-+      result = kmem_cache_destroy(*cachep);
-+      BUG_ON(result != 0);
++      kmem_cache_destroy(*cachep);
 +      *cachep = NULL;
 +}
 +
-+struct dentry *reiser4_debugfs_root = NULL;
-+
 +/**
 + * init_reiser4 - reiser4 initialization entry point
 + *
@@ -68110,22 +67862,22 @@ Index: linux-2.6.16/fs/reiser4/super_ops.c
 +              goto failed_init_jnodes;
 +
 +      /* initialize cache of flush queues */
-+      if ((result = init_fqs()) != 0)
++      if ((result = reiser4_init_fqs()) != 0)
 +              goto failed_init_fqs;
 +
 +      /* initialize cache of structures attached to dentry->d_fsdata */
-+      if ((result = init_dentry_fsdata()) != 0)
++      if ((result = reiser4_init_dentry_fsdata()) != 0)
 +              goto failed_init_dentry_fsdata;
 +
 +      /* initialize cache of structures attached to file->private_data */
-+      if ((result = init_file_fsdata()) != 0)
++      if ((result = reiser4_init_file_fsdata()) != 0)
 +              goto failed_init_file_fsdata;
 +
 +      /*
 +       * initialize cache of d_cursors. See plugin/file_ops_readdir.c for
 +       * more details
 +       */
-+      if ((result = init_d_cursor()) != 0)
++      if ((result = reiser4_init_d_cursor()) != 0)
 +              goto failed_init_d_cursor;
 +
 +      if ((result = register_filesystem(&reiser4_fs_type)) == 0) {
@@ -68133,13 +67885,13 @@ Index: linux-2.6.16/fs/reiser4/super_ops.c
 +              return 0;
 +      }
 +
-+      done_d_cursor();
++      reiser4_done_d_cursor();
 + failed_init_d_cursor:
-+      done_file_fsdata();
++      reiser4_done_file_fsdata();
 + failed_init_file_fsdata:
-+      done_dentry_fsdata();
++      reiser4_done_dentry_fsdata();
 + failed_init_dentry_fsdata:
-+      done_fqs();
++      reiser4_done_fqs();
 + failed_init_fqs:
 +      done_jnodes();
 + failed_init_jnodes:
@@ -68168,10 +67920,10 @@ Index: linux-2.6.16/fs/reiser4/super_ops.c
 +      debugfs_remove(reiser4_debugfs_root);
 +      result = unregister_filesystem(&reiser4_fs_type);
 +      BUG_ON(result != 0);
-+      done_d_cursor();
-+      done_file_fsdata();
-+      done_dentry_fsdata();
-+      done_fqs();
++      reiser4_done_d_cursor();
++      reiser4_done_file_fsdata();
++      reiser4_done_dentry_fsdata();
++      reiser4_done_fqs();
 +      done_jnodes();
 +      done_txnmgr_static();
 +      done_plugin_set();
@@ -68196,10 +67948,9 @@ Index: linux-2.6.16/fs/reiser4/super_ops.c
 + * fill-column: 79
 + * End:
 + */
-Index: linux-2.6.16/fs/reiser4/tap.c
-===================================================================
---- /dev/null
-+++ linux-2.6.16/fs/reiser4/tap.c
+diff -urN linux-2.6.22.orig/fs/reiser4/tap.c linux-2.6.22/fs/reiser4/tap.c
+--- linux-2.6.22.orig/fs/reiser4/tap.c 1970-01-01 03:00:00.000000000 +0300
++++ linux-2.6.22/fs/reiser4/tap.c      2007-07-29 00:25:35.024734784 +0400
 @@ -0,0 +1,377 @@
 +/* Copyright 2001, 2002, 2003 by Hans Reiser, licensing governed by
 + * reiser4/README */
@@ -68233,7 +67984,7 @@ Index: linux-2.6.16/fs/reiser4/tap.c
 +#endif
 +
 +/** load node tap is pointing to, if not loaded already */
-+int tap_load(tap_t * tap)
++int reiser4_tap_load(tap_t * tap)
 +{
 +      tap_check(tap);
 +      if (tap->loaded == 0) {
@@ -68250,7 +68001,7 @@ Index: linux-2.6.16/fs/reiser4/tap.c
 +}
 +
 +/** release node tap is pointing to. Dual to tap_load() */
-+void tap_relse(tap_t * tap)
++void reiser4_tap_relse(tap_t * tap)
 +{
 +      tap_check(tap);
 +      if (tap->loaded > 0) {
@@ -68266,29 +68017,29 @@ Index: linux-2.6.16/fs/reiser4/tap.c
 + * init tap to consist of @coord and @lh. Locks on nodes will be acquired with
 + * @mode
 + */
-+void
-+tap_init(tap_t * tap, coord_t * coord, lock_handle * lh, znode_lock_mode mode)
++void reiser4_tap_init(tap_t * tap, coord_t * coord, lock_handle * lh,
++                    znode_lock_mode mode)
 +{
 +      tap->coord = coord;
 +      tap->lh = lh;
 +      tap->mode = mode;
 +      tap->loaded = 0;
 +      INIT_LIST_HEAD(&tap->linkage);
-+      init_ra_info(&tap->ra_info);
++      reiser4_init_ra_info(&tap->ra_info);
 +}
 +
 +/** add @tap to the per-thread list of all taps */
-+void tap_monitor(tap_t * tap)
++void reiser4_tap_monitor(tap_t * tap)
 +{
 +      assert("nikita-2623", tap != NULL);
 +      tap_check(tap);
-+      list_add(&tap->linkage, taps_list());
++      list_add(&tap->linkage, reiser4_taps_list());
 +      tap_check(tap);
 +}
 +
 +/* duplicate @src into @dst. Copy lock handle. @dst is not initially
 + * loaded. */
-+void tap_copy(tap_t * dst, tap_t * src)
++void reiser4_tap_copy(tap_t * dst, tap_t * src)
 +{
 +      assert("nikita-3193", src != NULL);
 +      assert("nikita-3194", dst != NULL);
@@ -68303,7 +68054,7 @@ Index: linux-2.6.16/fs/reiser4/tap.c
 +}
 +
 +/** finish with @tap */
-+void tap_done(tap_t * tap)
++void reiser4_tap_done(tap_t * tap)
 +{
 +      assert("nikita-2565", tap != NULL);
 +      tap_check(tap);
@@ -68319,7 +68070,7 @@ Index: linux-2.6.16/fs/reiser4/tap.c
 + * move @tap to the new node, locked with @target. Load @target, if @tap was
 + * already loaded.
 + */
-+int tap_move(tap_t * tap, lock_handle * target)
++int reiser4_tap_move(tap_t * tap, lock_handle * target)
 +{
 +      int result = 0;
 +
@@ -68364,7 +68115,7 @@ Index: linux-2.6.16/fs/reiser4/tap.c
 +              result = longterm_lock_znode(&here, target,
 +                                           tap->mode, ZNODE_LOCK_HIPRI);
 +              if (result == 0) {
-+                      result = tap_move(tap, &here);
++                      result = reiser4_tap_move(tap, &here);
 +                      done_lh(&here);
 +              }
 +      }
@@ -68389,7 +68140,7 @@ Index: linux-2.6.16/fs/reiser4/tap.c
 +}
 +
 +/** return list of all taps */
-+struct list_head *taps_list(void)
++struct list_head *reiser4_taps_list(void)
 +{
 +      return &get_current_context()->taps;
 +}
@@ -68437,7 +68188,7 @@ Index: linux-2.6.16/fs/reiser4/tap.c
 +                          get_dir_neighbor(&dup, coord->node, (int)tap->mode,
 +                                           GN_CAN_USE_UPPER_LEVELS);
 +                      if (result == 0) {
-+                              result = tap_move(tap, &dup);
++                              result = reiser4_tap_move(tap, &dup);
 +                              if (result == 0)
 +                                      coord_init(tap->coord, dup.node);
 +                              done_lh(&dup);
@@ -68483,7 +68234,7 @@ Index: linux-2.6.16/fs/reiser4/tap.c
 +      assert("nikita-2562", tap->coord->node == tap->lh->node);
 +
 +      tap_check(tap);
-+      result = tap_load(tap);
++      result = reiser4_tap_load(tap);
 +      if (result != 0)
 +              return result;
 +
@@ -68493,7 +68244,7 @@ Index: linux-2.6.16/fs/reiser4/tap.c
 +              if (result != 0)
 +                      break;
 +      }
-+      tap_relse(tap);
++      reiser4_tap_relse(tap);
 +      tap_check(tap);
 +      return result;
 +}
@@ -68578,11 +68329,10 @@ Index: linux-2.6.16/fs/reiser4/tap.c
 +   scroll-step: 1
 +   End:
 +*/
-Index: linux-2.6.16/fs/reiser4/tap.h
-===================================================================
---- /dev/null
-+++ linux-2.6.16/fs/reiser4/tap.h
-@@ -0,0 +1,69 @@
+diff -urN linux-2.6.22.orig/fs/reiser4/tap.h linux-2.6.22/fs/reiser4/tap.h
+--- linux-2.6.22.orig/fs/reiser4/tap.h 1970-01-01 03:00:00.000000000 +0300
++++ linux-2.6.22/fs/reiser4/tap.h      2007-07-29 00:25:35.024734784 +0400
+@@ -0,0 +1,70 @@
 +/* Copyright 2002, 2003 by Hans Reiser, licensing governed by reiser4/README */
 +
 +/* Tree Access Pointers. See tap.c for more details. */
@@ -68607,7 +68357,8 @@ Index: linux-2.6.16/fs/reiser4/tap.h
 +      lock_handle *lh;
 +      /* mode of lock acquired by this tap */
 +      znode_lock_mode mode;
-+      /* incremented by tap_load(). Decremented by tap_relse(). */
++      /* incremented by reiser4_tap_load().
++         Decremented by reiser4_tap_relse(). */
 +      int loaded;
 +      /* list of taps */
 +      struct list_head linkage;
@@ -68617,14 +68368,14 @@ Index: linux-2.6.16/fs/reiser4/tap.h
 +
 +typedef int (*go_actor_t) (tap_t * tap);
 +
-+extern int tap_load(tap_t * tap);
-+extern void tap_relse(tap_t * tap);
-+extern void tap_init(tap_t * tap, coord_t * coord, lock_handle * lh,
++extern int reiser4_tap_load(tap_t * tap);
++extern void reiser4_tap_relse(tap_t * tap);
++extern void reiser4_tap_init(tap_t * tap, coord_t * coord, lock_handle * lh,
 +                   znode_lock_mode mode);
-+extern void tap_monitor(tap_t * tap);
-+extern void tap_copy(tap_t * dst, tap_t * src);
-+extern void tap_done(tap_t * tap);
-+extern int tap_move(tap_t * tap, lock_handle * target);
++extern void reiser4_tap_monitor(tap_t * tap);
++extern void reiser4_tap_copy(tap_t * dst, tap_t * src);
++extern void reiser4_tap_done(tap_t * tap);
++extern int reiser4_tap_move(tap_t * tap, lock_handle * target);
 +extern int tap_to_coord(tap_t * tap, coord_t * target);
 +
 +extern int go_dir_el(tap_t * tap, sideof dir, int units_p);
@@ -68633,11 +68384,11 @@ Index: linux-2.6.16/fs/reiser4/tap.h
 +extern int rewind_right(tap_t * tap, int shift);
 +extern int rewind_left(tap_t * tap, int shift);
 +
-+extern struct list_head *taps_list(void);
++extern struct list_head *reiser4_taps_list(void);
 +
-+#define for_all_taps(tap)                                             \
-+      for (tap = list_entry(taps_list()->next, tap_t, linkage);       \
-+           taps_list() != &tap->linkage;                              \
++#define for_all_taps(tap)                                                    \
++      for (tap = list_entry(reiser4_taps_list()->next, tap_t, linkage);      \
++           reiser4_taps_list() != &tap->linkage;                             \
 +           tap = list_entry(tap->linkage.next, tap_t, linkage))
 +
 +/* __REISER4_TAP_H__ */
@@ -68652,11 +68403,10 @@ Index: linux-2.6.16/fs/reiser4/tap.h
 +   scroll-step: 1
 +   End:
 +*/
-Index: linux-2.6.16/fs/reiser4/tree.c
-===================================================================
---- /dev/null
-+++ linux-2.6.16/fs/reiser4/tree.c
-@@ -0,0 +1,1875 @@
+diff -urN linux-2.6.22.orig/fs/reiser4/tree.c linux-2.6.22/fs/reiser4/tree.c
+--- linux-2.6.22.orig/fs/reiser4/tree.c        1970-01-01 03:00:00.000000000 +0300
++++ linux-2.6.22/fs/reiser4/tree.c     2007-07-29 00:25:35.028735820 +0400
+@@ -0,0 +1,1876 @@
 +/* Copyright 2001, 2002, 2003 by Hans Reiser, licensing governed by
 + * reiser4/README */
 +
@@ -68706,7 +68456,7 @@ Index: linux-2.6.16/fs/reiser4/tree.c
 + * ->max_key_inside() can be larger that any key actually located in the item,
 + * intervals
 + *
-+ * [ min_key( item ), ->max_key_inside( item ) ]
++ * [ reiser4_min_key( item ), ->max_key_inside( item ) ]
 + *
 + * are still disjoint for all items within the _same_ node.
 + *
@@ -68939,7 +68689,7 @@ Index: linux-2.6.16/fs/reiser4/tree.c
 +      lowest_level = (carry_level *) (pool + 1);
 +      init_carry_level(lowest_level, pool);
 +
-+      op = post_carry(lowest_level, cop, coord->node, 0);
++      op = reiser4_post_carry(lowest_level, cop, coord->node, 0);
 +      if (IS_ERR(op) || (op == NULL)) {
 +              done_carry_pool(pool);
 +              return RETERR(op ? PTR_ERR(op) : -EIO);
@@ -68960,7 +68710,7 @@ Index: linux-2.6.16/fs/reiser4/tree.c
 +              lowest_level->tracked = lh;
 +      }
 +
-+      result = carry(lowest_level, NULL);
++      result = reiser4_carry(lowest_level, NULL);
 +      done_carry_pool(pool);
 +
 +      return result;
@@ -68999,7 +68749,7 @@ Index: linux-2.6.16/fs/reiser4/tree.c
 +      lowest_level = (carry_level *) (pool + 1);
 +      init_carry_level(lowest_level, pool);
 +
-+      op = post_carry(lowest_level, COP_PASTE, coord->node, 0);
++      op = reiser4_post_carry(lowest_level, COP_PASTE, coord->node, 0);
 +      if (IS_ERR(op) || (op == NULL)) {
 +              done_carry_pool(pool);
 +              return RETERR(op ? PTR_ERR(op) : -EIO);
@@ -69018,7 +68768,7 @@ Index: linux-2.6.16/fs/reiser4/tree.c
 +              lowest_level->tracked = lh;
 +      }
 +
-+      result = carry(lowest_level, NULL);
++      result = reiser4_carry(lowest_level, NULL);
 +      done_carry_pool(pool);
 +
 +      return result;
@@ -69195,12 +68945,12 @@ Index: linux-2.6.16/fs/reiser4/tree.c
 +}
 +
 +/* this either appends or truncates item @coord */
-+int resize_item(coord_t * coord /* coord of item being resized */ ,
-+              reiser4_item_data * data /* parameters of resize */ ,
-+              reiser4_key * key /* key of new unit */ ,
-+              lock_handle * lh        /* lock handle of node
-+                                       * being modified */ ,
-+              cop_insert_flag flags /* carry flags */ )
++int reiser4_resize_item(coord_t * coord /* coord of item being resized */ ,
++                      reiser4_item_data * data /* parameters of resize */ ,
++                      reiser4_key * key /* key of new unit */ ,
++                      lock_handle * lh        /* lock handle of node
++                                               * being modified */ ,
++                      cop_insert_flag flags /* carry flags */ )
 +{
 +      int result;
 +      znode *node;
@@ -69226,7 +68976,7 @@ Index: linux-2.6.16/fs/reiser4/tree.c
 +}
 +
 +/* insert flow @f */
-+int insert_flow(coord_t * coord, lock_handle * lh, flow_t * f)
++int reiser4_insert_flow(coord_t * coord, lock_handle * lh, flow_t * f)
 +{
 +      int result;
 +      carry_pool *pool;
@@ -69242,7 +68992,7 @@ Index: linux-2.6.16/fs/reiser4/tree.c
 +      lowest_level = (carry_level *) (pool + 1);
 +      init_carry_level(lowest_level, pool);
 +
-+      op = post_carry(lowest_level, COP_INSERT_FLOW, coord->node,
++      op = reiser4_post_carry(lowest_level, COP_INSERT_FLOW, coord->node,
 +                      0 /* operate directly on coord -> node */ );
 +      if (IS_ERR(op) || (op == NULL)) {
 +              done_carry_pool(pool);
@@ -69268,7 +69018,7 @@ Index: linux-2.6.16/fs/reiser4/tree.c
 +      lowest_level->track_type = CARRY_TRACK_CHANGE;
 +      lowest_level->tracked = lh;
 +
-+      result = carry(lowest_level, NULL);
++      result = reiser4_carry(lowest_level, NULL);
 +      done_carry_pool(pool);
 +
 +      return result;
@@ -69313,7 +69063,8 @@ Index: linux-2.6.16/fs/reiser4/tree.c
 +              else
 +                      child =
 +                          zget(tree, &addr, parent,
-+                               znode_get_level(parent) - 1, get_gfp_mask());
++                               znode_get_level(parent) - 1,
++                               reiser4_ctx_gfp_mask_get());
 +              if ((child != NULL) && !IS_ERR(child) && setup_dkeys_p)
 +                      set_child_delimiting_keys(parent, parent_coord, child);
 +      } else {
@@ -69330,7 +69081,7 @@ Index: linux-2.6.16/fs/reiser4/tree.c
 +
 +      assert("zam-1001", ZF_ISSET(node, JNODE_HEARD_BANSHEE));
 +
-+      if (!blocknr_is_fake(znode_get_block(node))) {
++      if (!reiser4_blocknr_is_fake(znode_get_block(node))) {
 +              int ret;
 +
 +              /* An already allocated block goes right to the atom's delete set. */
@@ -69366,21 +69117,21 @@ Index: linux-2.6.16/fs/reiser4/tree.c
 +       * uncapture page from transaction. There is a possibility of a race
 +       * with ->releasepage(): reiser4_releasepage() detaches page from this
 +       * jnode and we have nothing to uncapture. To avoid this, get
-+       * reference of node->pg under jnode spin lock. uncapture_page() will
-+       * deal with released page itself.
++       * reference of node->pg under jnode spin lock. reiser4_uncapture_page()
++       * will deal with released page itself.
 +       */
 +      spin_lock_znode(node);
 +      page = znode_page(node);
 +      if (likely(page != NULL)) {
 +              /*
-+               * uncapture_page() can only be called when we are sure that
-+               * znode is pinned in memory, which we are, because
++               * reiser4_uncapture_page() can only be called when we are sure
++               * that znode is pinned in memory, which we are, because
 +               * forget_znode() is only called from longterm_unlock_znode().
 +               */
 +              page_cache_get(page);
 +              spin_unlock_znode(node);
 +              lock_page(page);
-+              uncapture_page(page);
++              reiser4_uncapture_page(page);
 +              unlock_page(page);
 +              page_cache_release(page);
 +      } else {
@@ -69396,11 +69147,11 @@ Index: linux-2.6.16/fs/reiser4/tree.c
 +                              break;
 +
 +                      spin_unlock_znode(node);
-+                      atom_wait_event(atom);
++                      reiser4_atom_wait_event(atom);
 +                      spin_lock_znode(node);
 +              }
 +
-+              uncapture_block(ZJNODE(node));
++              reiser4_uncapture_block(ZJNODE(node));
 +              spin_unlock_atom(atom);
 +              zput(node);
 +      }
@@ -69444,7 +69195,7 @@ Index: linux-2.6.16/fs/reiser4/tree.c
 +       * invalidation does not allow other threads to waste cpu time is a busy
 +       * loop, trying to lock dying object.  The exception is in the flush
 +       * code when we take node directly from atom's capture list.*/
-+      invalidate_lock(handle);
++      reiser4_invalidate_lock(handle);
 +      uncapture_znode(node);
 +}
 +
@@ -69901,7 +69652,7 @@ Index: linux-2.6.16/fs/reiser4/tree.c
 +
 +/* this is used to remove part of node content between coordinates @from and @to. Units to which @from and @to are set
 +   are to be cut completely */
-+/* for try_to_merge_with_left, delete_copied, delete_node */
++/* for try_to_merge_with_left, delete_copied, reiser4_delete_node */
 +int cut_node_content(coord_t * from, coord_t * to, const reiser4_key * from_key,      /* first key to be removed */
 +                   const reiser4_key * to_key,        /* last key to be removed */
 +                   reiser4_key *
@@ -69923,7 +69674,7 @@ Index: linux-2.6.16/fs/reiser4/tree.c
 +      lowest_level = (carry_level *) (pool + 1);
 +      init_carry_level(lowest_level, pool);
 +
-+      op = post_carry(lowest_level, COP_CUT, from->node, 0);
++      op = reiser4_post_carry(lowest_level, COP_CUT, from->node, 0);
 +      assert("vs-1509", op != 0);
 +      if (IS_ERR(op)) {
 +              done_carry_pool(pool);
@@ -69940,7 +69691,7 @@ Index: linux-2.6.16/fs/reiser4/tree.c
 +      op->u.cut_or_kill.is_cut = 1;
 +      op->u.cut_or_kill.u.cut = cut_data;
 +
-+      result = carry(lowest_level, NULL);
++      result = reiser4_carry(lowest_level, NULL);
 +      done_carry_pool(pool);
 +
 +      return result;
@@ -70023,7 +69774,7 @@ Index: linux-2.6.16/fs/reiser4/tree.c
 +              }
 +      }
 +
-+      op = post_carry(lowest_level, COP_CUT, from->node, 0);
++      op = reiser4_post_carry(lowest_level, COP_CUT, from->node, 0);
 +      if (IS_ERR(op) || (op == NULL)) {
 +              done_children(kdata);
 +              done_carry_pool(pool);
@@ -70033,7 +69784,7 @@ Index: linux-2.6.16/fs/reiser4/tree.c
 +      op->u.cut_or_kill.is_cut = 0;
 +      op->u.cut_or_kill.u.kill = kdata;
 +
-+      result = carry(lowest_level, NULL);
++      result = reiser4_carry(lowest_level, NULL);
 +
 +      done_children(kdata);
 +      done_carry_pool(pool);
@@ -70043,7 +69794,7 @@ Index: linux-2.6.16/fs/reiser4/tree.c
 +void
 +fake_kill_hook_tail(struct inode *inode, loff_t start, loff_t end, int truncate)
 +{
-+      if (inode_get_flag(inode, REISER4_HAS_MMAP)) {
++      if (reiser4_inode_get_flag(inode, REISER4_HAS_MMAP)) {
 +              pgoff_t start_pg, end_pg;
 +
 +              start_pg = start >> PAGE_CACHE_SHIFT;
@@ -70084,8 +69835,8 @@ Index: linux-2.6.16/fs/reiser4/tree.c
 + * cut_worker() iteration.  This is needed for proper accounting of
 + * "i_blocks" and "i_bytes" fields of the @object.
 + */
-+int delete_node(znode * node, reiser4_key * smallest_removed,
-+              struct inode *object, int truncate)
++int reiser4_delete_node(znode * node, reiser4_key * smallest_removed,
++                      struct inode *object, int truncate)
 +{
 +      lock_handle parent_lock;
 +      coord_t cut_from;
@@ -70204,8 +69955,8 @@ Index: linux-2.6.16/fs/reiser4/tree.c
 + * @progress: return true if a progress in file items deletions was made,
 + *            @smallest_removed value is actual in that case.
 + *
-+ * @return: 0 if success, error code otherwise, -E_REPEAT means that long cut_tree
-+ * operation was interrupted for allowing atom commit .
++ * @return: 0 if success, error code otherwise, -E_REPEAT means that long
++ * reiser4_cut_tree operation was interrupted for allowing atom commit.
 + */
 +int
 +cut_tree_worker_common(tap_t * tap, const reiser4_key * from_key,
@@ -70239,10 +69990,10 @@ Index: linux-2.6.16/fs/reiser4/tree.c
 +              /* Check can we delete the node as a whole. */
 +              if (*progress && znode_get_level(node) == LEAF_LEVEL &&
 +                  can_delete(from_key, node)) {
-+                      result = delete_node(node, smallest_removed, object,
-+                                           truncate);
++                      result = reiser4_delete_node(node, smallest_removed,
++                                                   object, truncate);
 +              } else {
-+                      result = tap_load(tap);
++                      result = reiser4_tap_load(tap);
 +                      if (result)
 +                              return result;
 +
@@ -70296,13 +70047,13 @@ Index: linux-2.6.16/fs/reiser4/tree.c
 +                      }
 +
 +                      /* cut data from one node */
-+                      // *smallest_removed = *min_key();
++                      // *smallest_removed = *reiser4_min_key();
 +                      result =
 +                          kill_node_content(&left_coord, tap->coord, from_key,
 +                                            to_key, smallest_removed,
 +                                            next_node_lock.node, object,
 +                                            truncate);
-+                      tap_relse(tap);
++                      reiser4_tap_relse(tap);
 +              }
 +              if (result)
 +                      break;
@@ -70318,13 +70069,13 @@ Index: linux-2.6.16/fs/reiser4/tree.c
 +              if (next_node_lock.node == NULL)
 +                      break;
 +
-+              result = tap_move(tap, &next_node_lock);
++              result = reiser4_tap_move(tap, &next_node_lock);
 +              done_lh(&next_node_lock);
 +              if (result)
 +                      break;
 +
-+              /* Break long cut_tree operation (deletion of a large file) if
-+               * atom requires commit. */
++              /* Break long reiser4_cut_tree operation (deletion of a large
++                 file) if atom requires commit. */
 +              if (*progress > CUT_TREE_MIN_ITERATIONS
 +                  && current_atom_should_commit()) {
 +                      result = -E_REPEAT;
@@ -70332,7 +70083,7 @@ Index: linux-2.6.16/fs/reiser4/tree.c
 +              }
 +      }
 +      done_lh(&next_node_lock);
-+      // assert("vs-301", !keyeq(&smallest_removed, min_key()));
++      // assert("vs-301", !keyeq(&smallest_removed, reiser4_min_key()));
 +      return result;
 +}
 +
@@ -70379,10 +70130,10 @@ Index: linux-2.6.16/fs/reiser4/tree.c
 + * operation was interrupted for allowing atom commit .
 + */
 +
-+int
-+cut_tree_object(reiser4_tree * tree, const reiser4_key * from_key,
-+              const reiser4_key * to_key, reiser4_key * smallest_removed_p,
-+              struct inode *object, int truncate, int *progress)
++int reiser4_cut_tree_object(reiser4_tree * tree, const reiser4_key * from_key,
++                          const reiser4_key * to_key,
++                          reiser4_key * smallest_removed_p,
++                          struct inode *object, int truncate, int *progress)
 +{
 +      lock_handle lock;
 +      int result;
@@ -70406,10 +70157,11 @@ Index: linux-2.6.16/fs/reiser4/tree.c
 +
 +      do {
 +              /* Find rightmost item to cut away from the tree. */
-+              result = object_lookup(object, to_key, &right_coord, &lock,
-+                                     ZNODE_WRITE_LOCK, FIND_MAX_NOT_MORE_THAN,
-+                                     TWIG_LEVEL, LEAF_LEVEL, CBK_UNIQUE,
-+                                     NULL /*ra_info */ );
++              result = reiser4_object_lookup(object, to_key, &right_coord,
++                                             &lock, ZNODE_WRITE_LOCK,
++                                             FIND_MAX_NOT_MORE_THAN,
++                                             TWIG_LEVEL, LEAF_LEVEL,
++                                             CBK_UNIQUE, NULL /*ra_info */);
 +              if (result != CBK_COORD_FOUND)
 +                      break;
 +              if (object == NULL
@@ -70418,13 +70170,13 @@ Index: linux-2.6.16/fs/reiser4/tree.c
 +              else
 +                      cut_tree_worker =
 +                          inode_file_plugin(object)->cut_tree_worker;
-+              tap_init(&tap, &right_coord, &lock, ZNODE_WRITE_LOCK);
++              reiser4_tap_init(&tap, &right_coord, &lock, ZNODE_WRITE_LOCK);
 +              result =
 +                  cut_tree_worker(&tap, from_key, to_key, smallest_removed_p,
 +                                  object, truncate, progress);
-+              tap_done(&tap);
++              reiser4_tap_done(&tap);
 +
-+              preempt_point();
++              reiser4_preempt_point();
 +
 +      } while (0);
 +
@@ -70450,27 +70202,25 @@ Index: linux-2.6.16/fs/reiser4/tree.c
 +      return result;
 +}
 +
-+/* repeat cut_tree_object until everything is deleted. unlike cut_file_items, it
-+ * does not end current transaction if -E_REPEAT is returned by
-+ * cut_tree_object. */
-+int
-+cut_tree(reiser4_tree * tree, const reiser4_key * from, const reiser4_key * to,
-+       struct inode *inode, int truncate)
++/* repeat reiser4_cut_tree_object until everything is deleted.
++ * unlike cut_file_items, it does not end current transaction if -E_REPEAT
++ * is returned by cut_tree_object. */
++int reiser4_cut_tree(reiser4_tree * tree, const reiser4_key * from,
++                   const reiser4_key * to, struct inode *inode, int truncate)
 +{
 +      int result;
 +      int progress;
 +
 +      do {
-+              result =
-+                  cut_tree_object(tree, from, to, NULL, inode, truncate,
-+                                  &progress);
++              result = reiser4_cut_tree_object(tree, from, to, NULL,
++                                               inode, truncate, &progress);
 +      } while (result == -E_REPEAT);
 +
 +      return result;
 +}
 +
 +/* finishing reiser4 initialization */
-+int init_tree(reiser4_tree * tree     /* pointer to structure being
++int reiser4_init_tree(reiser4_tree * tree     /* pointer to structure being
 +                                       * initialized */ ,
 +            const reiser4_block_nr * root_block       /* address of a root block
 +                                                       * on a disk */ ,
@@ -70498,7 +70248,8 @@ Index: linux-2.6.16/fs/reiser4/tree.c
 +      if (result == 0)
 +              result = jnodes_tree_init(tree);
 +      if (result == 0) {
-+              tree->uber = zget(tree, &UBER_TREE_ADDR, NULL, 0, get_gfp_mask());
++              tree->uber = zget(tree, &UBER_TREE_ADDR, NULL, 0,
++                                reiser4_ctx_gfp_mask_get());
 +              if (IS_ERR(tree->uber)) {
 +                      result = PTR_ERR(tree->uber);
 +                      tree->uber = NULL;
@@ -70508,7 +70259,7 @@ Index: linux-2.6.16/fs/reiser4/tree.c
 +}
 +
 +/* release resources associated with @tree */
-+void done_tree(reiser4_tree * tree /* tree to release */ )
++void reiser4_done_tree(reiser4_tree * tree /* tree to release */ )
 +{
 +      if (tree == NULL)
 +              return;
@@ -70532,11 +70283,10 @@ Index: linux-2.6.16/fs/reiser4/tree.c
 +   scroll-step: 1
 +   End:
 +*/
-Index: linux-2.6.16/fs/reiser4/tree.h
-===================================================================
---- /dev/null
-+++ linux-2.6.16/fs/reiser4/tree.h
-@@ -0,0 +1,579 @@
+diff -urN linux-2.6.22.orig/fs/reiser4/tree.h linux-2.6.22/fs/reiser4/tree.h
+--- linux-2.6.22.orig/fs/reiser4/tree.h        1970-01-01 03:00:00.000000000 +0300
++++ linux-2.6.22/fs/reiser4/tree.h     2007-07-29 00:25:35.028735820 +0400
+@@ -0,0 +1,577 @@
 +/* Copyright 2001, 2002, 2003 by Hans Reiser, licensing governed by
 + * reiser4/README */
 +
@@ -70605,7 +70355,6 @@ Index: linux-2.6.16/fs/reiser4/tree.h
 +      cbk_cache_slot *slot;
 +} cbk_cache;
 +
-+
 +/* level_lookup_result - possible outcome of looking up key at some level.
 +   This is used by coord_by_key when traversing tree downward. */
 +typedef enum {
@@ -70699,10 +70448,10 @@ Index: linux-2.6.16/fs/reiser4/tree.h
 +      } carry;
 +};
 +
-+extern int init_tree(reiser4_tree * tree,
-+                   const reiser4_block_nr * root_block, tree_level height,
-+                   node_plugin * default_plugin);
-+extern void done_tree(reiser4_tree * tree);
++extern int reiser4_init_tree(reiser4_tree * tree,
++                           const reiser4_block_nr * root_block,
++                           tree_level height, node_plugin * default_plugin);
++extern void reiser4_done_tree(reiser4_tree * tree);
 +
 +/* cbk flags: options for coord_by_key() */
 +typedef enum {
@@ -70744,9 +70493,10 @@ Index: linux-2.6.16/fs/reiser4/tree.h
 +
 +typedef int (*tree_iterate_actor_t) (reiser4_tree * tree, coord_t * coord,
 +                                   lock_handle * lh, void *arg);
-+extern int iterate_tree(reiser4_tree * tree, coord_t * coord, lock_handle * lh,
-+                      tree_iterate_actor_t actor, void *arg,
-+                      znode_lock_mode mode, int through_units_p);
++extern int reiser4_iterate_tree(reiser4_tree * tree, coord_t * coord,
++                              lock_handle * lh,
++                              tree_iterate_actor_t actor, void *arg,
++                              znode_lock_mode mode, int through_units_p);
 +extern int get_uber_znode(reiser4_tree * tree, znode_lock_mode mode,
 +                        znode_lock_request pri, lock_handle * lh);
 +
@@ -70831,15 +70581,15 @@ Index: linux-2.6.16/fs/reiser4/tree.h
 +                         tree_level lock_level, tree_level stop_level,
 +                         __u32 flags, ra_info_t *);
 +
-+lookup_result object_lookup(struct inode *object,
-+                          const reiser4_key * key,
-+                          coord_t * coord,
-+                          lock_handle * lh,
-+                          znode_lock_mode lock_mode,
-+                          lookup_bias bias,
-+                          tree_level lock_level,
-+                          tree_level stop_level,
-+                          __u32 flags, ra_info_t * info);
++lookup_result reiser4_object_lookup(struct inode *object,
++                                  const reiser4_key * key,
++                                  coord_t * coord,
++                                  lock_handle * lh,
++                                  znode_lock_mode lock_mode,
++                                  lookup_bias bias,
++                                  tree_level lock_level,
++                                  tree_level stop_level,
++                                  __u32 flags, ra_info_t * info);
 +
 +insert_result insert_by_key(reiser4_tree * tree, const reiser4_key * key,
 +                          reiser4_item_data * data, coord_t * coord,
@@ -70860,11 +70610,11 @@ Index: linux-2.6.16/fs/reiser4/tree.h
 +                    znode * locked_left_neighbor, struct inode *inode,
 +                    int truncate);
 +
-+int resize_item(coord_t * coord, reiser4_item_data * data,
-+              reiser4_key * key, lock_handle * lh, cop_insert_flag);
++int reiser4_resize_item(coord_t * coord, reiser4_item_data * data,
++                      reiser4_key * key, lock_handle * lh, cop_insert_flag);
 +int insert_into_item(coord_t * coord, lock_handle * lh, const reiser4_key * key,
 +                   reiser4_item_data * data, unsigned);
-+int insert_flow(coord_t * coord, lock_handle * lh, flow_t * f);
++int reiser4_insert_flow(coord_t * coord, lock_handle * lh, flow_t * f);
 +int find_new_child_ptr(znode * parent, znode * child, znode * left,
 +                     coord_t * result);
 +
@@ -70876,13 +70626,13 @@ Index: linux-2.6.16/fs/reiser4/tree.h
 +extern int cut_tree_worker_common(tap_t *, const reiser4_key *,
 +                                const reiser4_key *, reiser4_key *,
 +                                struct inode *, int, int *);
-+extern int cut_tree_object(reiser4_tree *, const reiser4_key *,
-+                         const reiser4_key *, reiser4_key *, struct inode *,
-+                         int, int *);
-+extern int cut_tree(reiser4_tree * tree, const reiser4_key * from,
-+                  const reiser4_key * to, struct inode *, int);
++extern int reiser4_cut_tree_object(reiser4_tree *, const reiser4_key *,
++                                 const reiser4_key *, reiser4_key *,
++                                 struct inode *, int, int *);
++extern int reiser4_cut_tree(reiser4_tree * tree, const reiser4_key * from,
++                          const reiser4_key * to, struct inode *, int);
 +
-+extern int delete_node(znode * node, reiser4_key *, struct inode *, int);
++extern int reiser4_delete_node(znode *, reiser4_key *, struct inode *, int);
 +extern int check_tree_pointer(const coord_t * pointer, const znode * child);
 +extern int find_new_child_ptr(znode * parent, znode * child UNUSED_ARG,
 +                            znode * left, coord_t * result);
@@ -70971,7 +70721,6 @@ Index: linux-2.6.16/fs/reiser4/tree.h
 +                tree_level lock_level, tree_level stop_level, __u32 flags,
 +                int *result1, int *result2);
 +
-+
 +static inline void read_lock_tree(reiser4_tree *tree)
 +{
 +      /* check that tree is not locked */
@@ -71102,7 +70851,6 @@ Index: linux-2.6.16/fs/reiser4/tree.h
 +reiser4_block_nr estimate_insert_cluster(struct inode *);
 +reiser4_block_nr estimate_update_cluster(struct inode *);
 +
-+
 +/* __REISER4_TREE_H__ */
 +#endif
 +
@@ -71116,11 +70864,10 @@ Index: linux-2.6.16/fs/reiser4/tree.h
 +   scroll-step: 1
 +   End:
 +*/
-Index: linux-2.6.16/fs/reiser4/tree_mod.c
-===================================================================
---- /dev/null
-+++ linux-2.6.16/fs/reiser4/tree_mod.c
-@@ -0,0 +1,383 @@
+diff -urN linux-2.6.22.orig/fs/reiser4/tree_mod.c linux-2.6.22/fs/reiser4/tree_mod.c
+--- linux-2.6.22.orig/fs/reiser4/tree_mod.c    1970-01-01 03:00:00.000000000 +0300
++++ linux-2.6.22/fs/reiser4/tree_mod.c 2007-07-29 00:25:35.032736855 +0400
+@@ -0,0 +1,386 @@
 +/* Copyright 2001, 2002, 2003 by Hans Reiser, licensing governed by
 + * reiser4/README */
 +
@@ -71160,9 +70907,10 @@ Index: linux-2.6.16/fs/reiser4/tree_mod.c
 +              warning( __VA_ARGS__ )
 +
 +/* allocate new node on the @level and immediately on the right of @brother. */
-+znode *new_node(znode * brother /* existing left neighbor of new node */ ,
-+              tree_level level        /* tree level at which new node is to
-+                                       * be allocated */ )
++znode * reiser4_new_node(znode * brother /* existing left neighbor
++                                        *  of new node */,
++                       tree_level level /* tree level at which new node is to
++                                         * be allocated */)
 +{
 +      znode *result;
 +      int retcode;
@@ -71175,7 +70923,7 @@ Index: linux-2.6.16/fs/reiser4/tree_mod.c
 +      if (retcode == 0) {
 +              result =
 +                  zget(znode_get_tree(brother), &blocknr, NULL, level,
-+                       get_gfp_mask());
++                       reiser4_ctx_gfp_mask_get());
 +              if (IS_ERR(result)) {
 +                      ewarning(PTR_ERR(result), "nikita-929",
 +                               "Cannot allocate znode for carry: %li",
@@ -71195,7 +70943,7 @@ Index: linux-2.6.16/fs/reiser4/tree_mod.c
 +              result->nplug = znode_get_tree(brother)->nplug;
 +              assert("nikita-933", result->nplug != NULL);
 +
-+              retcode = zinit_new(result, get_gfp_mask());
++              retcode = zinit_new(result, reiser4_ctx_gfp_mask_get());
 +              if (retcode == 0) {
 +                      ZF_SET(result, JNODE_CREATED);
 +                      zrelse(result);
@@ -71222,7 +70970,7 @@ Index: linux-2.6.16/fs/reiser4/tree_mod.c
 +   This helper function is called by add_new_root().
 +
 +*/
-+znode *add_tree_root(znode * old_root /* existing tree root */ ,
++znode *reiser4_add_tree_root(znode * old_root /* existing tree root */ ,
 +                   znode * fake /* "fake" znode */ )
 +{
 +      reiser4_tree *tree = znode_get_tree(old_root);
@@ -71260,7 +71008,7 @@ Index: linux-2.6.16/fs/reiser4/tree_mod.c
 +                 flush can be going here.
 +               */
 +              assert("nikita-1448", znode_is_root(old_root));
-+              new_root = new_node(fake, tree->height + 1);
++              new_root = reiser4_new_node(fake, tree->height + 1);
 +              if (!IS_ERR(new_root) && (result = zload(new_root)) == 0) {
 +                      lock_handle rlh;
 +
@@ -71299,8 +71047,8 @@ Index: linux-2.6.16/fs/reiser4/tree_mod.c
 +                                     WITH_DATA(new_root,
 +                                               node_is_empty(new_root)));
 +                              write_lock_dk(tree);
-+                              znode_set_ld_key(new_root, min_key());
-+                              znode_set_rd_key(new_root, max_key());
++                              znode_set_ld_key(new_root, reiser4_min_key());
++                              znode_set_rd_key(new_root, reiser4_max_key());
 +                              write_unlock_dk(tree);
 +                              if (REISER4_DEBUG) {
 +                                      ZF_CLR(old_root, JNODE_LEFT_CONNECTED);
@@ -71385,13 +71133,14 @@ Index: linux-2.6.16/fs/reiser4/tree_mod.c
 +}
 +
 +/* actually remove tree root */
-+static int kill_root(reiser4_tree * tree      /* tree from which root is being
-+                                               * removed */ ,
-+                   znode * old_root /* root node that is being removed */ ,
-+                   znode * new_root   /* new root---sole child of *
-+                                       * @old_root */ ,
-+                   const reiser4_block_nr * new_root_blk      /* disk address of
-+                                                               * @new_root */ )
++static int reiser4_kill_root(reiser4_tree * tree /* tree from which root is
++                                                * being removed */,
++                           znode * old_root /* root node that is being
++                                             * removed */ ,
++                           znode * new_root   /* new root---sole child of
++                                               * @old_root */,
++                   const reiser4_block_nr * new_root_blk /* disk address of
++                                                          * @new_root */)
 +{
 +      znode *uber;
 +      int result;
@@ -71457,16 +71206,17 @@ Index: linux-2.6.16/fs/reiser4/tree_mod.c
 +   at the entry.
 +
 +   To remove tree root we need to take lock on special "fake" znode that
-+   protects changes of tree height. See comments in add_tree_root() for more
-+   on this.
++   protects changes of tree height. See comments in reiser4_add_tree_root() for
++   more on this.
 +
 +   Also parent pointers have to be updated in
 +   old and new root. To simplify code, function is split into two parts: outer
-+   kill_tree_root() collects all necessary arguments and calls kill_root()
-+   to do the actual job.
++   reiser4_kill_tree_root() collects all necessary arguments and calls
++   reiser4_kill_root() to do the actual job.
 +
 +*/
-+int kill_tree_root(znode * old_root /* tree root that we are removing */ )
++int reiser4_kill_tree_root(znode * old_root /* tree root that we are
++                                             removing*/)
 +{
 +      int result;
 +      coord_t down_link;
@@ -71485,8 +71235,8 @@ Index: linux-2.6.16/fs/reiser4/tree_mod.c
 +      new_root = child_znode(&down_link, old_root, 0, 1);
 +      if (!IS_ERR(new_root)) {
 +              result =
-+                  kill_root(tree, old_root, new_root,
-+                            znode_get_block(new_root));
++                      reiser4_kill_root(tree, old_root, new_root,
++                                        znode_get_block(new_root));
 +              zput(new_root);
 +      } else
 +              result = PTR_ERR(new_root);
@@ -71504,10 +71254,9 @@ Index: linux-2.6.16/fs/reiser4/tree_mod.c
 +   scroll-step: 1
 +   End:
 +*/
-Index: linux-2.6.16/fs/reiser4/tree_mod.h
-===================================================================
---- /dev/null
-+++ linux-2.6.16/fs/reiser4/tree_mod.h
+diff -urN linux-2.6.22.orig/fs/reiser4/tree_mod.h linux-2.6.22/fs/reiser4/tree_mod.h
+--- linux-2.6.22.orig/fs/reiser4/tree_mod.h    1970-01-01 03:00:00.000000000 +0300
++++ linux-2.6.22/fs/reiser4/tree_mod.h 2007-07-29 00:25:35.032736855 +0400
 @@ -0,0 +1,29 @@
 +/* Copyright 2001, 2002, 2003 by Hans Reiser, licensing governed by
 + * reiser4/README */
@@ -71520,9 +71269,9 @@ Index: linux-2.6.16/fs/reiser4/tree_mod.h
 +
 +#include "forward.h"
 +
-+znode *new_node(znode * brother, tree_level level);
-+znode *add_tree_root(znode * old_root, znode * fake);
-+int kill_tree_root(znode * old_root);
++znode *reiser4_new_node(znode * brother, tree_level level);
++znode *reiser4_add_tree_root(znode * old_root, znode * fake);
++int reiser4_kill_tree_root(znode * old_root);
 +void build_child_ptr_data(znode * child, reiser4_item_data * data);
 +
 +/* __REISER4_TREE_MOD_H__ */
@@ -71538,11 +71287,10 @@ Index: linux-2.6.16/fs/reiser4/tree_mod.h
 +   scroll-step: 1
 +   End:
 +*/
-Index: linux-2.6.16/fs/reiser4/tree_walk.c
-===================================================================
---- /dev/null
-+++ linux-2.6.16/fs/reiser4/tree_walk.c
-@@ -0,0 +1,926 @@
+diff -urN linux-2.6.22.orig/fs/reiser4/tree_walk.c linux-2.6.22/fs/reiser4/tree_walk.c
+--- linux-2.6.22.orig/fs/reiser4/tree_walk.c   1970-01-01 03:00:00.000000000 +0300
++++ linux-2.6.22/fs/reiser4/tree_walk.c        2007-07-29 00:25:35.032736855 +0400
+@@ -0,0 +1,927 @@
 +/* Copyright 2001, 2002, 2003 by Hans Reiser, licensing governed by
 + * reiser4/README */
 +
@@ -71968,7 +71716,8 @@ Index: linux-2.6.16/fs/reiser4/tree_walk.c
 +                      neighbor = zlook(tree, &da);
 +              } else {
 +                      neighbor =
-+                          zget(tree, &da, side_parent, level, get_gfp_mask());
++                          zget(tree, &da, side_parent, level,
++                               reiser4_ctx_gfp_mask_get());
 +              }
 +
 +              if (IS_ERR(neighbor)) {
@@ -72311,7 +72060,7 @@ Index: linux-2.6.16/fs/reiser4/tree_walk.c
 +                      /* there was lock request from hi-pri locker. if
 +                         it is possible we unlock last parent node and
 +                         re-lock it again. */
-+                      for (; check_deadlock(); h--) {
++                      for (; reiser4_check_deadlock(); h--) {
 +                              done_lh(&path[h]);
 +                              if (h == 0)
 +                                      goto fail;
@@ -72469,10 +72218,9 @@ Index: linux-2.6.16/fs/reiser4/tree_walk.c
 +   fill-column: 80
 +   End:
 +*/
-Index: linux-2.6.16/fs/reiser4/tree_walk.h
-===================================================================
---- /dev/null
-+++ linux-2.6.16/fs/reiser4/tree_walk.h
+diff -urN linux-2.6.22.orig/fs/reiser4/tree_walk.h linux-2.6.22/fs/reiser4/tree_walk.h
+--- linux-2.6.22.orig/fs/reiser4/tree_walk.h   1970-01-01 03:00:00.000000000 +0300
++++ linux-2.6.22/fs/reiser4/tree_walk.h        2007-07-29 00:25:35.032736855 +0400
 @@ -0,0 +1,125 @@
 +/* Copyright 2001, 2002, 2003 by Hans Reiser, licensing governed by reiser4/README */
 +
@@ -72599,11 +72347,10 @@ Index: linux-2.6.16/fs/reiser4/tree_walk.h
 +   fill-column: 120
 +   End:
 +*/
-Index: linux-2.6.16/fs/reiser4/txnmgr.c
-===================================================================
---- /dev/null
-+++ linux-2.6.16/fs/reiser4/txnmgr.c
-@@ -0,0 +1,3158 @@
+diff -urN linux-2.6.22.orig/fs/reiser4/txnmgr.c linux-2.6.22/fs/reiser4/txnmgr.c
+--- linux-2.6.22.orig/fs/reiser4/txnmgr.c      1970-01-01 03:00:00.000000000 +0300
++++ linux-2.6.22/fs/reiser4/txnmgr.c   2007-07-29 00:25:35.040738926 +0400
+@@ -0,0 +1,3164 @@
 +/* Copyright 2001, 2002, 2003 by Hans Reiser, licensing governed by
 + * reiser4/README */
 +
@@ -72646,7 +72393,7 @@ Index: linux-2.6.16/fs/reiser4/txnmgr.c
 +
 +/* Thoughts on the external transaction interface:
 +
-+   In the current code, a TRANSCRASH handle is created implicitly by init_context() (which
++   In the current code, a TRANSCRASH handle is created implicitly by reiser4_init_context() (which
 +   creates state that lasts for the duration of a system call and is called at the start
 +   of ReiserFS methods implementing VFS operations), and closed by reiser4_exit_context(),
 +   occupying the scope of a single system call.  We wish to give certain applications an
@@ -72696,7 +72443,7 @@ Index: linux-2.6.16/fs/reiser4/txnmgr.c
 +   For actually implementing these out-of-system-call-scopped transcrashes, the
 +   reiser4_context has a "txn_handle *trans" pointer that may be set to an open
 +   transcrash.  Currently there are no dynamically-allocated transcrashes, but there is a
-+   "kmem_cache_t *_txnh_slab" created for that purpose in this file.
++   "struct kmem_cache *_txnh_slab" created for that purpose in this file.
 +*/
 +
 +/* Extending the other system call interfaces for future transaction features:
@@ -72784,7 +72531,8 @@ Index: linux-2.6.16/fs/reiser4/txnmgr.c
 + *     Steps (2) and (3) take place under long term lock on the twig node.
 + *
 + *     When file is accessed through mmap(2) page is always created during
-+ *     page fault. After this (in reiser4_readpage()->readpage_extent()):
++ *     page fault.
++ *     After this (in reiser4_readpage()->reiser4_readpage_extent()):
 + *
 + *         1. if access is made to non-hole page new jnode is created, (if
 + *         necessary)
@@ -72868,7 +72616,7 @@ Index: linux-2.6.16/fs/reiser4/txnmgr.c
 +
 +static void capture_fuse_into(txn_atom * small, txn_atom * large);
 +
-+void invalidate_list(struct list_head *);
++void reiser4_invalidate_list(struct list_head *);
 +
 +/* GENERIC STRUCTURES */
 +
@@ -72884,9 +72632,9 @@ Index: linux-2.6.16/fs/reiser4/txnmgr.c
 +
 +/* FIXME: In theory, we should be using the slab cache init & destructor
 +   methods instead of, e.g., jnode_init, etc. */
-+static kmem_cache_t *_atom_slab = NULL;
++static struct kmem_cache *_atom_slab = NULL;
 +/* this is for user-visible, cross system-call transactions. */
-+static kmem_cache_t *_txnh_slab = NULL;
++static struct kmem_cache *_txnh_slab = NULL;
 +
 +/**
 + * init_txnmgr_static - create transaction manager slab caches
@@ -72935,7 +72683,7 @@ Index: linux-2.6.16/fs/reiser4/txnmgr.c
 + *
 + * This is called on mount. Makes necessary initializations.
 + */
-+void init_txnmgr(txn_mgr *mgr)
++void reiser4_init_txnmgr(txn_mgr *mgr)
 +{
 +      assert("umka-169", mgr != NULL);
 +
@@ -72943,16 +72691,16 @@ Index: linux-2.6.16/fs/reiser4/txnmgr.c
 +      mgr->id_count = 1;
 +      INIT_LIST_HEAD(&mgr->atoms_list);
 +      spin_lock_init(&mgr->tmgr_lock);
-+      sema_init(&mgr->commit_semaphore, 1);
++      mutex_init(&mgr->commit_mutex);
 +}
 +
 +/**
-+ * done_txnmgr - stop transaction manager
++ * reiser4_done_txnmgr - stop transaction manager
 + * @mgr: pointer to transaction manager embedded in reiser4 super block
 + *
 + * This is called on umount. Does sanity checks.
 + */
-+void done_txnmgr(txn_mgr *mgr)
++void reiser4_done_txnmgr(txn_mgr *mgr)
 +{
 +      assert("umka-170", mgr != NULL);
 +      assert("umka-1701", list_empty_careful(&mgr->atoms_list));
@@ -72967,7 +72715,7 @@ Index: linux-2.6.16/fs/reiser4/txnmgr.c
 +
 +      txnh->mode = mode;
 +      txnh->atom = NULL;
-+      set_gfp_mask();
++      reiser4_ctx_gfp_mask_set();
 +      txnh->flags = 0;
 +      spin_lock_init(&txnh->hlock);
 +      INIT_LIST_HEAD(&txnh->txnh_link);
@@ -73002,7 +72750,7 @@ Index: linux-2.6.16/fs/reiser4/txnmgr.c
 +      INIT_LIST_HEAD(ATOM_OVRWR_LIST(atom));
 +      INIT_LIST_HEAD(ATOM_WB_LIST(atom));
 +      INIT_LIST_HEAD(&atom->inodes);
-+      spin_lock_init(&atom->alock);
++      spin_lock_init(&(atom->alock));
 +      /* list of transaction handles */
 +      INIT_LIST_HEAD(&atom->txnh_list);
 +      /* link to transaction manager's list of atoms */
@@ -73049,7 +72797,7 @@ Index: linux-2.6.16/fs/reiser4/txnmgr.c
 +   trans_in_ctx, which means that transaction handles are stack-allocated.  Eventually
 +   this will be extended to allow transaction handles to span several contexts. */
 +/* Audited by: umka (2002.06.13) */
-+void txn_begin(reiser4_context * context)
++void reiser4_txn_begin(reiser4_context * context)
 +{
 +      assert("jmacd-544", context->trans == NULL);
 +
@@ -73064,13 +72812,13 @@ Index: linux-2.6.16/fs/reiser4/txnmgr.c
 +}
 +
 +/* Finish a transaction handle context. */
-+int txn_end(reiser4_context * context)
++int reiser4_txn_end(reiser4_context * context)
 +{
 +      long ret = 0;
 +      txn_handle *txnh;
 +
 +      assert("umka-283", context != NULL);
-+      assert("nikita-3012", schedulable());
++      assert("nikita-3012", reiser4_schedulable());
 +      assert("vs-24", context == get_current_context());
 +      assert("nikita-2967", lock_stack_isclean(get_current_lock_stack()));
 +
@@ -73084,16 +72832,16 @@ Index: linux-2.6.16/fs/reiser4/txnmgr.c
 +      return ret;
 +}
 +
-+void txn_restart(reiser4_context * context)
++void reiser4_txn_restart(reiser4_context * context)
 +{
-+      txn_end(context);
-+      preempt_point();
-+      txn_begin(context);
++      reiser4_txn_end(context);
++      reiser4_preempt_point();
++      reiser4_txn_begin(context);
 +}
 +
-+void txn_restart_current(void)
++void reiser4_txn_restart_current(void)
 +{
-+      txn_restart(get_current_context());
++      reiser4_txn_restart(get_current_context());
 +}
 +
 +/* TXN_ATOM */
@@ -73305,7 +73053,8 @@ Index: linux-2.6.16/fs/reiser4/txnmgr.c
 +      }
 +
 +      if (*atom_alloc == NULL) {
-+              (*atom_alloc) = kmem_cache_alloc(_atom_slab, get_gfp_mask());
++              (*atom_alloc) = kmem_cache_alloc(_atom_slab,
++                                               reiser4_ctx_gfp_mask_get());
 +
 +              if (*atom_alloc == NULL)
 +                      return RETERR(-ENOMEM);
@@ -73320,7 +73069,7 @@ Index: linux-2.6.16/fs/reiser4/txnmgr.c
 +      /* Check whether new atom still needed */
 +      if (txnh->atom != NULL) {
 +              /* NOTE-NIKITA probably it is rather better to free
-+               * atom_alloc here than thread it up to try_capture(). */
++               * atom_alloc here than thread it up to reiser4_try_capture() */
 +
 +              spin_unlock_txnh(txnh);
 +              spin_unlock_txnmgr(mgr);
@@ -73336,10 +73085,12 @@ Index: linux-2.6.16/fs/reiser4/txnmgr.c
 +      assert("jmacd-17", atom_isclean(atom));
 +
 +        /*
-+       * do not use spin_lock_atom because we have broken lock ordering here
-+       * which is ok, as long as @atom is new and inaccessible for others.
++       * lock ordering is broken here. It is ok, as long as @atom is new
++       * and inaccessible for others. We can't use spin_lock_atom or
++       * spin_lock(&atom->alock) because they care about locking
++       * dependencies. spin_trylock_lock doesn't.
 +       */
-+      spin_lock(&(atom->alock));
++      check_me("", spin_trylock_atom(atom));
 +
 +      /* add atom to the end of transaction manager's list of atoms */
 +      list_add_tail(&atom->atom_link, &mgr->atoms_list);
@@ -73355,7 +73106,7 @@ Index: linux-2.6.16/fs/reiser4/txnmgr.c
 +      atom->super = reiser4_get_current_sb();
 +      capture_assign_txnh_nolock(atom, txnh);
 +
-+      spin_unlock(&(atom->alock));
++      spin_unlock_atom(atom);
 +      spin_unlock_txnh(txnh);
 +
 +      return -E_REPEAT;
@@ -73546,8 +73297,8 @@ Index: linux-2.6.16/fs/reiser4/txnmgr.c
 +      dispatch_wb_list(fq->atom, fq);
 +      spin_unlock_atom(fq->atom);
 +
-+      ret = write_fq(fq, NULL, 1);
-+      fq_put(fq);
++      ret = reiser4_write_fq(fq, NULL, 1);
++      reiser4_fq_put(fq);
 +
 +      return ret;
 +}
@@ -73579,6 +73330,28 @@ Index: linux-2.6.16/fs/reiser4/txnmgr.c
 +      return current_atom_finish_all_fq();
 +}
 +
++#if REISER4_DEBUG
++
++static void reiser4_info_atom(const char *prefix, const txn_atom * atom)
++{
++      if (atom == NULL) {
++              printk("%s: no atom\n", prefix);
++              return;
++      }
++
++      printk("%s: refcount: %i id: %i flags: %x txnh_count: %i"
++             " capture_count: %i stage: %x start: %lu, flushed: %i\n", prefix,
++             atomic_read(&atom->refcount), atom->atom_id, atom->flags,
++             atom->txnh_count, atom->capture_count, atom->stage,
++             atom->start_time, atom->flushed);
++}
++
++#else  /*  REISER4_DEBUG  */
++
++static inline void reiser4_info_atom(const char *prefix, const txn_atom * atom) {}
++
++#endif  /*  REISER4_DEBUG  */
++
 +#define TOOMANYFLUSHES (1 << 13)
 +
 +/* Called with the atom locked and no open "active" transaction handlers except
@@ -73606,9 +73379,8 @@ Index: linux-2.6.16/fs/reiser4/txnmgr.c
 +      assert("zam-887", get_current_context()->trans->atom == *atom);
 +      assert("jmacd-151", atom_isopen(*atom));
 +
-+      /* lock ordering: delete_sema and commit_sema are unordered */
 +      assert("nikita-3184",
-+             get_current_super_private()->delete_sema_owner != current);
++             get_current_super_private()->delete_mutex_owner != current);
 +
 +      for (flushiters = 0;; ++flushiters) {
 +              ret =
@@ -73622,13 +73394,13 @@ Index: linux-2.6.16/fs/reiser4/txnmgr.c
 +              /* if atom's dirty list contains one znode which is
 +                 HEARD_BANSHEE and is locked we have to allow lock owner to
 +                 continue and uncapture that znode */
-+              preempt_point();
++              reiser4_preempt_point();
 +
 +              *atom = get_current_atom_locked();
 +              if (flushiters > TOOMANYFLUSHES && IS_POW(flushiters)) {
 +                      warning("nikita-3176",
 +                              "Flushing like mad: %i", flushiters);
-+                      info_atom("atom", *atom);
++                      reiser4_info_atom("atom", *atom);
 +                      DEBUGON(flushiters > (1 << 20));
 +              }
 +      }
@@ -73649,7 +73421,7 @@ Index: linux-2.6.16/fs/reiser4/txnmgr.c
 +      /* Up to this point we have been flushing and after flush is called we
 +         return -E_REPEAT.  Now we can commit.  We cannot return -E_REPEAT
 +         at this point, commit should be successful. */
-+      atom_set_stage(*atom, ASTAGE_PRE_COMMIT);
++      reiser4_atom_set_stage(*atom, ASTAGE_PRE_COMMIT);
 +      ON_DEBUG(((*atom)->committer = current));
 +      spin_unlock_atom(*atom);
 +
@@ -73660,28 +73432,28 @@ Index: linux-2.6.16/fs/reiser4/txnmgr.c
 +      assert("zam-906", list_empty(ATOM_WB_LIST(*atom)));
 +
 +      /* isolate critical code path which should be executed by only one
-+       * thread using tmgr semaphore */
-+      down(&sbinfo->tmgr.commit_semaphore);
++       * thread using tmgr mutex */
++      mutex_lock(&sbinfo->tmgr.commit_mutex);
 +
 +      ret = reiser4_write_logs(nr_submitted);
 +      if (ret < 0)
 +              reiser4_panic("zam-597", "write log failed (%ld)\n", ret);
 +
-+      /* The atom->ovrwr_nodes list is processed under commit semaphore held
++      /* The atom->ovrwr_nodes list is processed under commit mutex held
 +         because of bitmap nodes which are captured by special way in
-+         bitmap_pre_commit_hook(), that way does not include
++         reiser4_pre_commit_hook_bitmap(), that way does not include
 +         capture_fuse_wait() as a capturing of other nodes does -- the commit
-+         semaphore is used for transaction isolation instead. */
-+      invalidate_list(ATOM_OVRWR_LIST(*atom));
-+      up(&sbinfo->tmgr.commit_semaphore);
++         mutex is used for transaction isolation instead. */
++      reiser4_invalidate_list(ATOM_OVRWR_LIST(*atom));
++      mutex_unlock(&sbinfo->tmgr.commit_mutex);
 +
-+      invalidate_list(ATOM_CLEAN_LIST(*atom));
-+      invalidate_list(ATOM_WB_LIST(*atom));
++      reiser4_invalidate_list(ATOM_CLEAN_LIST(*atom));
++      reiser4_invalidate_list(ATOM_WB_LIST(*atom));
 +      assert("zam-927", list_empty(&(*atom)->inodes));
 +
 +      spin_lock_atom(*atom);
 + done:
-+      atom_set_stage(*atom, ASTAGE_DONE);
++      reiser4_atom_set_stage(*atom, ASTAGE_DONE);
 +      ON_DEBUG((*atom)->committer = NULL);
 +
 +      /* Atom's state changes, so wake up everybody waiting for this
@@ -73733,7 +73505,7 @@ Index: linux-2.6.16/fs/reiser4/txnmgr.c
 +      spin_unlock_atom(atom);
 +
 +      /* commit is here */
-+      txn_restart_current();
++      reiser4_txn_restart_current();
 +      return 0;
 +}
 +
@@ -73750,9 +73522,9 @@ Index: linux-2.6.16/fs/reiser4/txnmgr.c
 +      reiser4_context *ctx = get_current_context();
 +
 +      assert("nikita-2965", lock_stack_isclean(get_current_lock_stack()));
-+      assert("nikita-3058", commit_check_locks());
++      assert("nikita-3058", reiser4_commit_check_locks());
 +
-+      txn_restart_current();
++      reiser4_txn_restart_current();
 +
 +      mgr = &get_super_private(super)->tmgr;
 +
@@ -73782,7 +73554,7 @@ Index: linux-2.6.16/fs/reiser4/txnmgr.c
 +                                              return ret;
 +                              } else
 +                                      /* wait atom commit */
-+                                      atom_wait_event(atom);
++                                      reiser4_atom_wait_event(atom);
 +
 +                              goto again;
 +                      }
@@ -73879,7 +73651,7 @@ Index: linux-2.6.16/fs/reiser4/txnmgr.c
 +         has to rescan atoms */
 +      mgr->daemon->rescan = 1;
 +      spin_unlock(&mgr->daemon->guard);
-+      txn_restart_current();
++      reiser4_txn_restart_current();
 +      return 0;
 +}
 +
@@ -74010,7 +73782,7 @@ Index: linux-2.6.16/fs/reiser4/txnmgr.c
 +                                       * makes a progress in flushing or
 +                                       * committing the atom
 +                                       */
-+                                      atom_wait_event(atom);
++                                      reiser4_atom_wait_event(atom);
 +                                      goto repeat;
 +                              }
 +                              spin_unlock_atom(atom);
@@ -74042,7 +73814,7 @@ Index: linux-2.6.16/fs/reiser4/txnmgr.c
 +                          !(atom->flags & ATOM_CANCEL_FUSION)) {
 +                              ret = txn_try_to_fuse_small_atom(tmgr, atom);
 +                              if (ret == -E_REPEAT) {
-+                                      preempt_point();
++                                      reiser4_preempt_point();
 +                                      goto repeat;
 +                              }
 +                      }
@@ -74060,7 +73832,7 @@ Index: linux-2.6.16/fs/reiser4/txnmgr.c
 +              if (*nr_submitted == 0) {
 +                      /* let others who hampers flushing (hold longterm locks,
 +                         for instance) to free the way for flush */
-+                      preempt_point();
++                      reiser4_preempt_point();
 +                      goto repeat;
 +              }
 +              ret = 0;
@@ -74069,20 +73841,20 @@ Index: linux-2.6.16/fs/reiser4/txnmgr.c
 +      if (*nr_submitted > wbc->nr_to_write)
 +              warning("", "asked for %ld, written %ld\n", wbc->nr_to_write, *nr_submitted);
 +*/
-+      txn_restart(ctx);
++      reiser4_txn_restart(ctx);
 +
 +      return ret;
 +}
 +
 +/* Remove processed nodes from atom's clean list (thereby remove them from transaction). */
-+void invalidate_list(struct list_head *head)
++void reiser4_invalidate_list(struct list_head *head)
 +{
 +      while (!list_empty(head)) {
 +              jnode *node;
 +
 +              node = list_entry(head->next, jnode, capture_link);
 +              spin_lock_jnode(node);
-+              uncapture_block(node);
++              reiser4_uncapture_block(node);
 +              jput(node);
 +      }
 +}
@@ -74097,7 +73869,7 @@ Index: linux-2.6.16/fs/reiser4/txnmgr.c
 +}
 +
 +/* Add atom to the atom's waitfor list and wait for somebody to wake us up; */
-+void atom_wait_event(txn_atom * atom)
++void reiser4_atom_wait_event(txn_atom * atom)
 +{
 +      txn_wait_links _wlinks;
 +
@@ -74111,29 +73883,29 @@ Index: linux-2.6.16/fs/reiser4/txnmgr.c
 +      atomic_inc(&atom->refcount);
 +      spin_unlock_atom(atom);
 +
-+      prepare_to_sleep(_wlinks._lock_stack);
-+      go_to_sleep(_wlinks._lock_stack);
++      reiser4_prepare_to_sleep(_wlinks._lock_stack);
++      reiser4_go_to_sleep(_wlinks._lock_stack);
 +
 +      spin_lock_atom(atom);
 +      list_del(&_wlinks._fwaitfor_link);
 +      atom_dec_and_unlock(atom);
 +}
 +
-+void atom_set_stage(txn_atom * atom, txn_stage stage)
++void reiser4_atom_set_stage(txn_atom * atom, txn_stage stage)
 +{
 +      assert("nikita-3535", atom != NULL);
 +      assert_spin_locked(&(atom->alock));
-+      assert("nikita-3536", ASTAGE_FREE <= stage && stage <= ASTAGE_INVALID);
++      assert("nikita-3536", stage <= ASTAGE_INVALID);
 +      /* Excelsior! */
 +      assert("nikita-3537", stage >= atom->stage);
 +      if (atom->stage != stage) {
 +              atom->stage = stage;
-+              atom_send_event(atom);
++              reiser4_atom_send_event(atom);
 +      }
 +}
 +
 +/* wake all threads which wait for an event */
-+void atom_send_event(txn_atom * atom)
++void reiser4_atom_send_event(txn_atom * atom)
 +{
 +      assert_spin_locked(&(atom->alock));
 +      wakeup_atom_waitfor_list(atom);
@@ -74208,7 +73980,8 @@ Index: linux-2.6.16/fs/reiser4/txnmgr.c
 +                       * increase monotonically), hence this check.
 +                       */
 +                      if (cd->atom->stage < ASTAGE_CAPTURE_WAIT)
-+                              atom_set_stage(cd->atom, ASTAGE_CAPTURE_WAIT);
++                              reiser4_atom_set_stage(cd->atom,
++                                                     ASTAGE_CAPTURE_WAIT);
 +                      cd->atom->flags |= ATOM_FORCE_COMMIT;
 +              }
 +              if (cd->txnh->flags & TXNH_DONT_COMMIT) {
@@ -74227,14 +74000,14 @@ Index: linux-2.6.16/fs/reiser4/txnmgr.c
 +                      cd->wake_ktxnmgrd_up =
 +                          cd->atom->txnh_count == 1 &&
 +                          cd->atom->nr_waiters == 0;
-+                      atom_send_event(cd->atom);
++                      reiser4_atom_send_event(cd->atom);
 +                      result = 0;
 +              } else if (!atom_can_be_committed(cd->atom)) {
 +                      if (should_wait_commit(cd->txnh)) {
 +                              /* sync(): wait for commit */
 +                              cd->atom->nr_waiters++;
 +                              cd->wait = 1;
-+                              atom_wait_event(cd->atom);
++                              reiser4_atom_wait_event(cd->atom);
 +                              result = RETERR(-E_REPEAT);
 +                      } else {
 +                              result = 0;
@@ -74261,7 +74034,7 @@ Index: linux-2.6.16/fs/reiser4/txnmgr.c
 +                      /* We change   atom state  to   ASTAGE_CAPTURE_WAIT to
 +                         prevent atom fusion and count  ourself as an active
 +                         flusher */
-+                      atom_set_stage(cd->atom, ASTAGE_CAPTURE_WAIT);
++                      reiser4_atom_set_stage(cd->atom, ASTAGE_CAPTURE_WAIT);
 +                      cd->atom->flags |= ATOM_FORCE_COMMIT;
 +
 +                      result =
@@ -74300,7 +74073,7 @@ Index: linux-2.6.16/fs/reiser4/txnmgr.c
 +      /* calls try_commit_txnh() until either atom commits, or error
 +       * happens */
 +      while (try_commit_txnh(&cd) != 0)
-+              preempt_point();
++              reiser4_preempt_point();
 +
 +      spin_lock_txnh(txnh);
 +
@@ -74356,8 +74129,8 @@ Index: linux-2.6.16/fs/reiser4/txnmgr.c
 +   This function acquires and releases the handle's spinlock.  This function is called
 +   under the jnode lock and if the return value is 0, it returns with the jnode lock still
 +   held.  If the return is -E_REPEAT or some other error condition, the jnode lock is
-+   released.  The external interface (try_capture) manages re-aquiring the jnode lock
-+   in the failure case.
++   released.  The external interface (reiser4_try_capture) manages re-aquiring the jnode
++   lock in the failure case.
 +*/
 +static int try_capture_block(
 +      txn_handle * txnh, jnode * node, txn_capture mode,
@@ -74366,7 +74139,7 @@ Index: linux-2.6.16/fs/reiser4/txnmgr.c
 +      txn_atom *block_atom;
 +      txn_atom *txnh_atom;
 +
-+      /* Should not call capture for READ_NONCOM requests, handled in try_capture. */
++      /* Should not call capture for READ_NONCOM requests, handled in reiser4_try_capture. */
 +      assert("jmacd-567", CAPTURE_TYPE(mode) != TXN_CAPTURE_READ_NONCOM);
 +
 +      /* FIXME-ZAM-HANS: FIXME_LATER_JMACD Should assert that atom->tree ==
@@ -74374,7 +74147,7 @@ Index: linux-2.6.16/fs/reiser4/txnmgr.c
 +      assert("umka-194", txnh != NULL);
 +      assert("umka-195", node != NULL);
 +
-+      /* The jnode is already locked!  Being called from try_capture(). */
++      /* The jnode is already locked!  Being called from reiser4_try_capture(). */
 +      assert_spin_locked(&(node->guard));
 +      block_atom = node->atom;
 +
@@ -74537,8 +74310,8 @@ Index: linux-2.6.16/fs/reiser4/txnmgr.c
 +            cannot be processed immediately as it was requested in flags,
 +          < 0 - other errors.
 +*/
-+int try_capture(jnode *node, znode_lock_mode lock_mode,
-+              txn_capture flags)
++int reiser4_try_capture(jnode *node, znode_lock_mode lock_mode,
++                      txn_capture flags)
 +{
 +      txn_atom *atom_alloc = NULL;
 +      txn_capture cap_mode;
@@ -74715,11 +74488,11 @@ Index: linux-2.6.16/fs/reiser4/txnmgr.c
 +              atomic_inc(&atomf->refcount);
 +              spin_unlock_txnh(ctx->trans);
 +              if (atomf > atomh) {
-+                      spin_lock_atom(atomf);
++                      spin_lock_atom_nested(atomf);
 +              } else {
 +                      spin_unlock_atom(atomh);
 +                      spin_lock_atom(atomf);
-+                      spin_lock_atom(atomh);
++                      spin_lock_atom_nested(atomh);
 +              }
 +              if (atomh == atomf || !atom_isopen(atomh) || !atom_isopen(atomf)) {
 +                      release_two_atoms(atomf, atomh);
@@ -74751,7 +74524,7 @@ Index: linux-2.6.16/fs/reiser4/txnmgr.c
 +      spin_lock_jnode(node);
 +      unlock_page(pg);
 +
-+      ret = try_capture(node, ZNODE_WRITE_LOCK, 0);
++      ret = reiser4_try_capture(node, ZNODE_WRITE_LOCK, 0);
 +      spin_unlock_jnode(node);
 +      jput(node);
 +      lock_page(pg);
@@ -74768,7 +74541,7 @@ Index: linux-2.6.16/fs/reiser4/txnmgr.c
 +
 +VS-FIXME-HANS: can this code be at all streamlined?  In particular, can you lock and unlock the jnode fewer times?
 +  */
-+void uncapture_page(struct page *pg)
++void reiser4_uncapture_page(struct page *pg)
 +{
 +      jnode *node;
 +      txn_atom *atom;
@@ -74794,26 +74567,26 @@ Index: linux-2.6.16/fs/reiser4/txnmgr.c
 +
 +      /* We can remove jnode from transaction even if it is on flush queue
 +       * prepped list, we only need to be sure that flush queue is not being
-+       * written by write_fq().  write_fq() does not use atom spin lock for
-+       * protection of the prepped nodes list, instead write_fq() increments
-+       * atom's nr_running_queues counters for the time when prepped list is
-+       * not protected by spin lock.  Here we check this counter if we want
-+       * to remove jnode from flush queue and, if the counter is not zero,
-+       * wait all write_fq() for this atom to complete. This is not
-+       * significant overhead. */
++       * written by reiser4_write_fq().  reiser4_write_fq() does not use atom
++       * spin lock for protection of the prepped nodes list, instead
++       * write_fq() increments atom's nr_running_queues counters for the time
++       * when prepped list is not protected by spin lock.  Here we check this
++       * counter if we want to remove jnode from flush queue and, if the
++       * counter is not zero, wait all reiser4_write_fq() for this atom to
++       * complete. This is not significant overhead. */
 +      while (JF_ISSET(node, JNODE_FLUSH_QUEUED) && atom->nr_running_queues) {
 +              spin_unlock_jnode(node);
 +              /*
 +               * at this moment we want to wait for "atom event", viz. wait
 +               * until @node can be removed from flush queue. But
-+               * atom_wait_event() cannot be called with page locked, because
-+               * it deadlocks with jnode_extent_write(). Unlock page, after
-+               * making sure (through page_cache_get()) that it cannot be
-+               * released from memory.
++               * reiser4_atom_wait_event() cannot be called with page locked,
++               * because it deadlocks with jnode_extent_write(). Unlock page,
++               * after making sure (through page_cache_get()) that it cannot
++               * be released from memory.
 +               */
 +              page_cache_get(pg);
 +              unlock_page(pg);
-+              atom_wait_event(atom);
++              reiser4_atom_wait_event(atom);
 +              lock_page(pg);
 +              /*
 +               * page may has been detached by ->writepage()->releasepage().
@@ -74828,14 +74601,14 @@ Index: linux-2.6.16/fs/reiser4/txnmgr.c
 +                      return;
 +              }
 +      }
-+      uncapture_block(node);
++      reiser4_uncapture_block(node);
 +      spin_unlock_atom(atom);
 +      jput(node);
 +}
 +
 +/* this is used in extent's kill hook to uncapture and unhash jnodes attached to
 + * inode's tree of jnodes */
-+void uncapture_jnode(jnode * node)
++void reiser4_uncapture_jnode(jnode * node)
 +{
 +      txn_atom *atom;
 +
@@ -74849,7 +74622,7 @@ Index: linux-2.6.16/fs/reiser4/txnmgr.c
 +              return;
 +      }
 +
-+      uncapture_block(node);
++      reiser4_uncapture_block(node);
 +      spin_unlock_atom(atom);
 +      jput(node);
 +}
@@ -74869,7 +74642,7 @@ Index: linux-2.6.16/fs/reiser4/txnmgr.c
 +
 +      atomic_inc(&atom->refcount);
 +      txnh->atom = atom;
-+      set_gfp_mask();
++      reiser4_ctx_gfp_mask_set();
 +      list_add_tail(&txnh->txnh_link, &atom->txnh_list);
 +      atom->txnh_count += 1;
 +}
@@ -74918,7 +74691,7 @@ Index: linux-2.6.16/fs/reiser4/txnmgr.c
 +      if (!JF_ISSET(node, JNODE_CREATED) && !JF_ISSET(node, JNODE_RELOC)
 +          && !JF_ISSET(node, JNODE_OVRWR) && jnode_is_leaf(node)
 +          && !jnode_is_cluster_page(node)) {
-+              assert("vs-1093", !blocknr_is_fake(&node->blocknr));
++              assert("vs-1093", !reiser4_blocknr_is_fake(&node->blocknr));
 +              assert("vs-1506", *jnode_get_block(node) != 0);
 +              grabbed2flush_reserved_nolock(atom, (__u64) 1);
 +              JF_SET(node, JNODE_FLUSH_RESERVED);
@@ -75006,7 +74779,7 @@ Index: linux-2.6.16/fs/reiser4/txnmgr.c
 +              spin_unlock_jnode(node);
 +              /* reiser4 file write code calls set_page_dirty for
 +               * unformatted nodes, for formatted nodes we do it here. */
-+              set_page_dirty_internal(page);
++              reiser4_set_page_dirty_internal(page);
 +              page_cache_release(page);
 +              /* bump version counter in znode */
 +              z->version = znode_build_version(jnode_get_tree(node));
@@ -75019,7 +74792,7 @@ Index: linux-2.6.16/fs/reiser4/txnmgr.c
 +      assert("jmacd-9777", node->atom != NULL);
 +}
 +
-+int sync_atom(txn_atom * atom)
++int reiser4_sync_atom(txn_atom * atom)
 +{
 +      int result;
 +      txn_handle *txnh;
@@ -75034,7 +74807,7 @@ Index: linux-2.6.16/fs/reiser4/txnmgr.c
 +                      result = force_commit_atom(txnh);
 +              } else if (atom->stage < ASTAGE_POST_COMMIT) {
 +                      /* wait atom commit */
-+                      atom_wait_event(atom);
++                      reiser4_atom_wait_event(atom);
 +                      /* try once more */
 +                      result = RETERR(-E_REPEAT);
 +              } else
@@ -75113,7 +74886,7 @@ Index: linux-2.6.16/fs/reiser4/txnmgr.c
 +              count = 0;
 +
 +              /* flush queue list */
-+              /*check_fq(atom); */
++              /* reiser4_check_fq(atom); */
 +
 +              /* dirty list */
 +              count = 0;
@@ -75176,7 +74949,7 @@ Index: linux-2.6.16/fs/reiser4/txnmgr.c
 +      assert("nikita-2432", !JF_ISSET(node, JNODE_RELOC));
 +      assert("nikita-3153", JF_ISSET(node, JNODE_DIRTY));
 +      assert("zam-897", !JF_ISSET(node, JNODE_FLUSH_QUEUED));
-+      assert("nikita-3367", !blocknr_is_fake(jnode_get_block(node)));
++      assert("nikita-3367", !reiser4_blocknr_is_fake(jnode_get_block(node)));
 +
 +      atom = node->atom;
 +
@@ -75213,7 +74986,7 @@ Index: linux-2.6.16/fs/reiser4/txnmgr.c
 +      assert("zam-917", !JF_ISSET(node, JNODE_RELOC));
 +      assert("zam-918", !JF_ISSET(node, JNODE_OVRWR));
 +      assert("zam-920", !JF_ISSET(node, JNODE_FLUSH_QUEUED));
-+      assert("nikita-3367", !blocknr_is_fake(jnode_get_block(node)));
++      assert("nikita-3367", !reiser4_blocknr_is_fake(jnode_get_block(node)));
 +      jnode_set_reloc(node);
 +}
 +
@@ -75246,14 +75019,14 @@ Index: linux-2.6.16/fs/reiser4/txnmgr.c
 +      queue_jnode(fq, node);
 +}
 +
-+int capture_super_block(struct super_block *s)
++int reiser4_capture_super_block(struct super_block *s)
 +{
 +      int result;
 +      znode *uber;
 +      lock_handle lh;
 +
 +      init_lh(&lh);
-+      result = get_uber_znode(get_tree(s),
++      result = get_uber_znode(reiser4_get_tree(s),
 +                              ZNODE_WRITE_LOCK, ZNODE_LOCK_LOPRI, &lh);
 +      if (result)
 +              return result;
@@ -75369,9 +75142,9 @@ Index: linux-2.6.16/fs/reiser4/txnmgr.c
 +      /* Go to sleep. */
 +      spin_unlock_txnh(txnh);
 +
-+      ret = prepare_to_sleep(wlinks._lock_stack);
++      ret = reiser4_prepare_to_sleep(wlinks._lock_stack);
 +      if (ret == 0) {
-+              go_to_sleep(wlinks._lock_stack);
++              reiser4_go_to_sleep(wlinks._lock_stack);
 +              ret = RETERR(-E_REPEAT);
 +      }
 +
@@ -75397,14 +75170,13 @@ Index: linux-2.6.16/fs/reiser4/txnmgr.c
 +      /* lock the atom with lesser address first */
 +      if (one < two) {
 +              spin_lock_atom(one);
-+              spin_lock_atom(two);
++              spin_lock_atom_nested(two);
 +      } else {
 +              spin_lock_atom(two);
-+              spin_lock_atom(one);
++              spin_lock_atom_nested(one);
 +      }
 +}
 +
-+
 +/* Perform the necessary work to prepare for fusing two atoms, which involves
 + * acquiring two atom locks in the proper order.  If one of the node's atom is
 + * blocking fusion (i.e., it is in the CAPTURE_WAIT stage) and the handle's
@@ -75559,7 +75331,7 @@ Index: linux-2.6.16/fs/reiser4/txnmgr.c
 +      small->nr_waiters = 0;
 +
 +      /* splice flush queues */
-+      fuse_fq(large, small);
++      reiser4_fuse_fq(large, small);
 +
 +      /* update counter of jnode on every atom' list */
 +      ON_DEBUG(large->dirty += small->dirty;
@@ -75620,11 +75392,11 @@ Index: linux-2.6.16/fs/reiser4/txnmgr.c
 +
 +      if (large->stage < small->stage) {
 +              /* Large only needs to notify if it has changed state. */
-+              atom_set_stage(large, small->stage);
++              reiser4_atom_set_stage(large, small->stage);
 +              wakeup_atom_waiting_list(large);
 +      }
 +
-+      atom_set_stage(small, ASTAGE_INVALID);
++      reiser4_atom_set_stage(small, ASTAGE_INVALID);
 +
 +      /* Notify any waiters--small needs to unload its wait lists.  Waiters
 +         actually remove themselves from the list before returning from the
@@ -75644,8 +75416,8 @@ Index: linux-2.6.16/fs/reiser4/txnmgr.c
 +
 +   NOTE: this function does not release a (journal) reference to jnode
 +   due to locking optimizations, you should call jput() somewhere after
-+   calling uncapture_block(). */
-+void uncapture_block(jnode * node)
++   calling reiser4_uncapture_block(). */
++void reiser4_uncapture_block(jnode * node)
 +{
 +      txn_atom *atom;
 +
@@ -75697,25 +75469,6 @@ Index: linux-2.6.16/fs/reiser4/txnmgr.c
 +      ON_DEBUG(count_jnode(atom, node, NODE_LIST(node), OVRWR_LIST, 1));
 +}
 +
-+
-+#if REISER4_DEBUG
-+
-+void info_atom(const char *prefix, const txn_atom * atom)
-+{
-+      if (atom == NULL) {
-+              printk("%s: no atom\n", prefix);
-+              return;
-+      }
-+
-+      printk("%s: refcount: %i id: %i flags: %x txnh_count: %i"
-+             " capture_count: %i stage: %x start: %lu, flushed: %i\n", prefix,
-+             atomic_read(&atom->refcount), atom->atom_id, atom->flags,
-+             atom->txnh_count, atom->capture_count, atom->stage,
-+             atom->start_time, atom->flushed);
-+}
-+
-+#endif
-+
 +static int count_deleted_blocks_actor(txn_atom * atom,
 +                                    const reiser4_block_nr * a,
 +                                    const reiser4_block_nr * b, void *data)
@@ -75762,11 +75515,10 @@ Index: linux-2.6.16/fs/reiser4/txnmgr.c
 + * fill-column: 79
 + * End:
 + */
-Index: linux-2.6.16/fs/reiser4/txnmgr.h
-===================================================================
---- /dev/null
-+++ linux-2.6.16/fs/reiser4/txnmgr.h
-@@ -0,0 +1,704 @@
+diff -urN linux-2.6.22.orig/fs/reiser4/txnmgr.h linux-2.6.22/fs/reiser4/txnmgr.h
+--- linux-2.6.22.orig/fs/reiser4/txnmgr.h      1970-01-01 03:00:00.000000000 +0300
++++ linux-2.6.22/fs/reiser4/txnmgr.h   2007-07-29 00:25:35.044739961 +0400
+@@ -0,0 +1,701 @@
 +/* Copyright 2001, 2002, 2003 by Hans Reiser, licensing governed by
 + * reiser4/README */
 +
@@ -75784,11 +75536,11 @@ Index: linux-2.6.16/fs/reiser4/txnmgr.h
 +#include <linux/types.h>
 +#include <linux/spinlock.h>
 +#include <asm/atomic.h>
-+#include <asm/semaphore.h>
++#include <linux/wait.h>
 +
 +/* TYPE DECLARATIONS */
 +
-+/* This enumeration describes the possible types of a capture request (try_capture).
++/* This enumeration describes the possible types of a capture request (reiser4_try_capture).
 +   A capture request dynamically assigns a block to the calling thread's transaction
 +   handle. */
 +typedef enum {
@@ -75822,11 +75574,12 @@ Index: linux-2.6.16/fs/reiser4/txnmgr.h
 +         indicate modification will occur. */
 +      TXN_CAPTURE_WTYPES = (TXN_CAPTURE_READ_MODIFY | TXN_CAPTURE_WRITE),
 +
-+      /* An option to try_capture, NONBLOCKING indicates that the caller would
++      /* An option to reiser4_try_capture, NONBLOCKING indicates that the caller would
 +         prefer not to sleep waiting for an aging atom to commit. */
 +      TXN_CAPTURE_NONBLOCKING = (1 << 4),
 +
-+      /* An option to try_capture to prevent atom fusion, just simple capturing is allowed */
++      /* An option to reiser4_try_capture to prevent atom fusion, just simple
++         capturing is allowed */
 +      TXN_CAPTURE_DONT_FUSE = (1 << 5)
 +
 +      /* This macro selects only the exclusive capture request types, stripping out any
@@ -75960,11 +75713,6 @@ Index: linux-2.6.16/fs/reiser4/txnmgr.h
 +   code above and proceed without restarting if they are still satisfied.
 +*/
 +
-+/* A block number set consists of only the list head. */
-+struct blocknr_set {
-+      struct list_head entries;
-+};
-+
 +/* An atomic transaction: this is the underlying system representation
 +   of a transaction, not the one seen by clients.
 +
@@ -76020,10 +75768,10 @@ Index: linux-2.6.16/fs/reiser4/txnmgr.h
 +
 +      /* The atom's delete set. It collects block numbers of the nodes
 +         which were deleted during the transaction. */
-+      blocknr_set delete_set;
++      struct list_head delete_set;
 +
 +      /* The atom's wandered_block mapping. */
-+      blocknr_set wandered_map;
++      struct list_head wandered_map;
 +
 +      /* The transaction's list of dirty captured nodes--per level.  Index
 +         by (level). dirty_nodes[0] is for znode-above-root */
@@ -76073,7 +75821,7 @@ Index: linux-2.6.16/fs/reiser4/txnmgr.h
 +      /* number of threads which do jnode_flush() over this atom */
 +      int nr_flushers;
 +      /* number of flush queues which are IN_USE and jnodes from fq->prepped
-+         are submitted to disk by the write_fq() routine. */
++         are submitted to disk by the reiser4_write_fq() routine. */
 +      int nr_running_queues;
 +      /* A counter of grabbed unformatted nodes, see a description of the
 +       * reiser4 space reservation scheme at block_alloc.c */
@@ -76096,11 +75844,6 @@ Index: linux-2.6.16/fs/reiser4/txnmgr.h
 +       count_jnode(txn_atom *, jnode *, atom_list old_list,
 +                   atom_list new_list, int check_lists));
 +
-+typedef struct protected_jnodes {
-+      struct list_head inatom; /* link to atom's list these structures */
-+      struct list_head nodes; /* head of list of protected nodes */
-+} protected_jnodes;
-+
 +/* A transaction handle: the client obtains and commits this handle which is assigned by
 +   the system to a txn_atom. */
 +struct txn_handle {
@@ -76135,8 +75878,8 @@ Index: linux-2.6.16/fs/reiser4/txnmgr.h
 +      /* A counter used to assign atom->atom_id values. */
 +      __u32 id_count;
 +
-+      /* a semaphore object for commit serialization */
-+      struct semaphore commit_semaphore;
++      /* a mutex object for commit serialization */
++      struct mutex commit_mutex;
 +
 +      /* a list of all txnmrgs served by particular daemon. */
 +      struct list_head linkage;
@@ -76162,16 +75905,16 @@ Index: linux-2.6.16/fs/reiser4/txnmgr.h
 +extern int init_txnmgr_static(void);
 +extern void done_txnmgr_static(void);
 +
-+extern void init_txnmgr(txn_mgr *);
-+extern void done_txnmgr(txn_mgr *);
++extern void reiser4_init_txnmgr(txn_mgr *);
++extern void reiser4_done_txnmgr(txn_mgr *);
 +
-+extern int txn_reserve(int reserved);
++extern int reiser4_txn_reserve(int reserved);
 +
-+extern void txn_begin(reiser4_context * context);
-+extern int txn_end(reiser4_context * context);
++extern void reiser4_txn_begin(reiser4_context * context);
++extern int reiser4_txn_end(reiser4_context * context);
 +
-+extern void txn_restart(reiser4_context * context);
-+extern void txn_restart_current(void);
++extern void reiser4_txn_restart(reiser4_context * context);
++extern void reiser4_txn_restart_current(void);
 +
 +extern int txnmgr_force_commit_all(struct super_block *, int);
 +extern int current_atom_should_commit(void);
@@ -76184,21 +75927,21 @@ Index: linux-2.6.16/fs/reiser4/txnmgr.h
 +
 +extern int flush_some_atom(jnode *, long *, const struct writeback_control *, int);
 +
-+extern void atom_set_stage(txn_atom * atom, txn_stage stage);
++extern void reiser4_atom_set_stage(txn_atom * atom, txn_stage stage);
 +
 +extern int same_slum_check(jnode * base, jnode * check, int alloc_check,
 +                         int alloc_value);
 +extern void atom_dec_and_unlock(txn_atom * atom);
 +
-+extern int try_capture(jnode * node, znode_lock_mode mode, txn_capture flags);
++extern int reiser4_try_capture(jnode * node, znode_lock_mode mode, txn_capture flags);
 +extern int try_capture_page_to_invalidate(struct page *pg);
 +
-+extern void uncapture_page(struct page *pg);
-+extern void uncapture_block(jnode *);
-+extern void uncapture_jnode(jnode *);
++extern void reiser4_uncapture_page(struct page *pg);
++extern void reiser4_uncapture_block(jnode *);
++extern void reiser4_uncapture_jnode(jnode *);
 +
-+extern int capture_inode(struct inode *);
-+extern int uncapture_inode(struct inode *);
++extern int reiser4_capture_inode(struct inode *);
++extern int reiser4_uncapture_inode(struct inode *);
 +
 +extern txn_atom *get_current_atom_locked_nocheck(void);
 +
@@ -76234,24 +75977,24 @@ Index: linux-2.6.16/fs/reiser4/txnmgr.h
 +
 +extern txn_atom *jnode_get_atom(jnode *);
 +
-+extern void atom_wait_event(txn_atom *);
-+extern void atom_send_event(txn_atom *);
++extern void reiser4_atom_wait_event(txn_atom *);
++extern void reiser4_atom_send_event(txn_atom *);
 +
 +extern void insert_into_atom_ovrwr_list(txn_atom * atom, jnode * node);
-+extern int capture_super_block(struct super_block *s);
++extern int reiser4_capture_super_block(struct super_block *s);
 +int capture_bulk(jnode **, int count);
 +
 +/* See the comment on the function blocknrset.c:blocknr_set_add for the
 +   calling convention of these three routines. */
-+extern void blocknr_set_init(blocknr_set * bset);
-+extern void blocknr_set_destroy(blocknr_set * bset);
-+extern void blocknr_set_merge(blocknr_set * from, blocknr_set * into);
++extern void blocknr_set_init(struct list_head * bset);
++extern void blocknr_set_destroy(struct list_head * bset);
++extern void blocknr_set_merge(struct list_head * from, struct list_head * into);
 +extern int blocknr_set_add_extent(txn_atom * atom,
-+                                blocknr_set * bset,
++                                struct list_head * bset,
 +                                blocknr_set_entry ** new_bsep,
 +                                const reiser4_block_nr * start,
 +                                const reiser4_block_nr * len);
-+extern int blocknr_set_add_pair(txn_atom * atom, blocknr_set * bset,
++extern int blocknr_set_add_pair(txn_atom * atom, struct list_head * bset,
 +                              blocknr_set_entry ** new_bsep,
 +                              const reiser4_block_nr * a,
 +                              const reiser4_block_nr * b);
@@ -76259,7 +76002,7 @@ Index: linux-2.6.16/fs/reiser4/txnmgr.h
 +typedef int (*blocknr_set_actor_f) (txn_atom *, const reiser4_block_nr *,
 +                                  const reiser4_block_nr *, void *);
 +
-+extern int blocknr_set_iterator(txn_atom * atom, blocknr_set * bset,
++extern int blocknr_set_iterator(txn_atom * atom, struct list_head * bset,
 +                              blocknr_set_actor_f actor, void *data,
 +                              int delete);
 +
@@ -76271,6 +76014,7 @@ Index: linux-2.6.16/fs/reiser4/txnmgr.h
 +{
 +      /* check that spinlocks of lower priorities are not held */
 +      assert("", (LOCK_CNT_NIL(spin_locked_txnh) &&
++                  LOCK_CNT_NIL(spin_locked_atom) &&
 +                  LOCK_CNT_NIL(spin_locked_jnode) &&
 +                  LOCK_CNT_NIL(spin_locked_zlock) &&
 +                  LOCK_CNT_NIL(rw_locked_dk) &&
@@ -76282,6 +76026,20 @@ Index: linux-2.6.16/fs/reiser4/txnmgr.h
 +      LOCK_CNT_INC(spin_locked);
 +}
 +
++static inline void spin_lock_atom_nested(txn_atom *atom)
++{
++      assert("", (LOCK_CNT_NIL(spin_locked_txnh) &&
++                  LOCK_CNT_NIL(spin_locked_jnode) &&
++                  LOCK_CNT_NIL(spin_locked_zlock) &&
++                  LOCK_CNT_NIL(rw_locked_dk) &&
++                  LOCK_CNT_NIL(rw_locked_tree)));
++
++      spin_lock_nested(&(atom->alock), SINGLE_DEPTH_NESTING);
++
++      LOCK_CNT_INC(spin_locked_atom);
++      LOCK_CNT_INC(spin_locked);
++}
++
 +static inline int spin_trylock_atom(txn_atom *atom)
 +{
 +      if (spin_trylock(&(atom->alock))) {
@@ -76416,8 +76174,8 @@ Index: linux-2.6.16/fs/reiser4/txnmgr.h
 +      atomic_t nr_errors;
 +      /* An atom this flush queue is attached to */
 +      txn_atom *atom;
-+      /* A semaphore for waiting on i/o completion */
-+      struct semaphore io_sem;
++      /* A wait queue head to wait on i/o completion */
++      wait_queue_head_t wait;
 +#if REISER4_DEBUG
 +      /* A thread which took this fq in exclusive use, NULL if fq is free,
 +       * used for debugging. */
@@ -76425,14 +76183,13 @@ Index: linux-2.6.16/fs/reiser4/txnmgr.h
 +#endif
 +};
 +
-+extern int fq_by_atom(txn_atom *, flush_queue_t **);
-+extern void fq_put_nolock(flush_queue_t *);
-+extern void fq_put(flush_queue_t *);
-+extern void fuse_fq(txn_atom * to, txn_atom * from);
++extern int reiser4_fq_by_atom(txn_atom *, flush_queue_t **);
++extern void reiser4_fq_put_nolock(flush_queue_t *);
++extern void reiser4_fq_put(flush_queue_t *);
++extern void reiser4_fuse_fq(txn_atom * to, txn_atom * from);
 +extern void queue_jnode(flush_queue_t *, jnode *);
-+extern void mark_jnode_queued(flush_queue_t *, jnode *);
 +
-+extern int write_fq(flush_queue_t *, long *, int);
++extern int reiser4_write_fq(flush_queue_t *, long *, int);
 +extern int current_atom_finish_all_fq(void);
 +extern void init_atom_fq_parts(txn_atom *);
 +
@@ -76441,7 +76198,7 @@ Index: linux-2.6.16/fs/reiser4/txnmgr.h
 +extern void znode_make_dirty(znode * node);
 +extern void jnode_make_dirty_locked(jnode * node);
 +
-+extern int sync_atom(txn_atom * atom);
++extern int reiser4_sync_atom(txn_atom * atom);
 +
 +#if REISER4_DEBUG
 +extern int atom_fq_parts_are_clean(txn_atom *);
@@ -76450,15 +76207,7 @@ Index: linux-2.6.16/fs/reiser4/txnmgr.h
 +extern void add_fq_to_bio(flush_queue_t *, struct bio *);
 +extern flush_queue_t *get_fq_for_current_atom(void);
 +
-+void protected_jnodes_init(protected_jnodes * list);
-+void protected_jnodes_done(protected_jnodes * list);
-+void invalidate_list(struct list_head * head);
-+
-+#if REISER4_DEBUG
-+void info_atom(const char *prefix, const txn_atom * atom);
-+#else
-+#define info_atom(p,a) noop
-+#endif
++void reiser4_invalidate_list(struct list_head * head);
 +
 +# endif                               /* __REISER4_TXNMGR_H__ */
 +
@@ -76471,10 +76220,9 @@ Index: linux-2.6.16/fs/reiser4/txnmgr.h
 +   fill-column: 120
 +   End:
 +*/
-Index: linux-2.6.16/fs/reiser4/type_safe_hash.h
-===================================================================
---- /dev/null
-+++ linux-2.6.16/fs/reiser4/type_safe_hash.h
+diff -urN linux-2.6.22.orig/fs/reiser4/type_safe_hash.h linux-2.6.22/fs/reiser4/type_safe_hash.h
+--- linux-2.6.22.orig/fs/reiser4/type_safe_hash.h      1970-01-01 03:00:00.000000000 +0300
++++ linux-2.6.22/fs/reiser4/type_safe_hash.h   2007-07-29 00:25:35.044739961 +0400
 @@ -0,0 +1,320 @@
 +/* Copyright 2001, 2002, 2003 by Hans Reiser, licensing governed by
 + * reiser4/README */
@@ -76796,11 +76544,10 @@ Index: linux-2.6.16/fs/reiser4/type_safe_hash.h
 +   fill-column: 120
 +   End:
 +*/
-Index: linux-2.6.16/fs/reiser4/vfs_ops.c
-===================================================================
---- /dev/null
-+++ linux-2.6.16/fs/reiser4/vfs_ops.c
-@@ -0,0 +1,267 @@
+diff -urN linux-2.6.22.orig/fs/reiser4/vfs_ops.c linux-2.6.22/fs/reiser4/vfs_ops.c
+--- linux-2.6.22.orig/fs/reiser4/vfs_ops.c     1970-01-01 03:00:00.000000000 +0300
++++ linux-2.6.22/fs/reiser4/vfs_ops.c  2007-07-29 00:25:35.044739961 +0400
+@@ -0,0 +1,259 @@
 +/* Copyright 2001, 2002, 2003 by Hans Reiser, licensing governed by
 + * reiser4/README */
 +
@@ -76854,7 +76601,6 @@ Index: linux-2.6.16/fs/reiser4/vfs_ops.c
 +#include <linux/reboot.h>
 +#include <linux/rcupdate.h>
 +
-+
 +/* update inode stat-data by calling plugin */
 +int reiser4_update_sd(struct inode *object)
 +{
@@ -76934,9 +76680,6 @@ Index: linux-2.6.16/fs/reiser4/vfs_ops.c
 +      return result;
 +}
 +
-+
-+
-+
 +/* Release reiser4 dentry. This is d_op->d_release() method. */
 +static void reiser4_d_release(struct dentry *dentry /* dentry released */ )
 +{
@@ -76947,7 +76690,7 @@ Index: linux-2.6.16/fs/reiser4/vfs_ops.c
 + * Called by reiser4_sync_inodes(), during speculative write-back (through
 + * pdflush, or balance_dirty_pages()).
 + */
-+void writeout(struct super_block *sb, struct writeback_control *wbc)
++void reiser4_writeout(struct super_block *sb, struct writeback_control *wbc)
 +{
 +      long written = 0;
 +      int repeats = 0;
@@ -76966,8 +76709,8 @@ Index: linux-2.6.16/fs/reiser4/vfs_ops.c
 +              return;
 +      }
 +
-+      BUG_ON(get_super_fake(sb) == NULL);
-+      mapping = get_super_fake(sb)->i_mapping;
++      BUG_ON(reiser4_get_super_fake(sb) == NULL);
++      mapping = reiser4_get_super_fake(sb)->i_mapping;
 +      do {
 +              long nr_submitted = 0;
 +              jnode *node = NULL;
@@ -77008,10 +76751,9 @@ Index: linux-2.6.16/fs/reiser4/vfs_ops.c
 +      } while (wbc->nr_to_write > 0);
 +}
 +
-+
 +void reiser4_throttle_write(struct inode *inode)
 +{
-+      txn_restart_current();
++      reiser4_txn_restart_current();
 +      balance_dirty_pages_ratelimited(inode->i_mapping);
 +}
 +
@@ -77019,8 +76761,6 @@ Index: linux-2.6.16/fs/reiser4/vfs_ops.c
 +const int REISER4_MAGIC_OFFSET = 16 * 4096;   /* offset to magic string from the
 +                                               * beginning of device */
 +
-+
-+
 +/*
 + * Reiser4 initialization/shutdown.
 + *
@@ -77029,7 +76769,6 @@ Index: linux-2.6.16/fs/reiser4/vfs_ops.c
 + * during reiser4 module load (when compiled as module).
 + */
 +
-+
 +void reiser4_handle_error(void)
 +{
 +      struct super_block *sb = reiser4_get_current_sb();
@@ -77068,11 +76807,10 @@ Index: linux-2.6.16/fs/reiser4/vfs_ops.c
 +   fill-column: 120
 +   End:
 +*/
-Index: linux-2.6.16/fs/reiser4/vfs_ops.h
-===================================================================
---- /dev/null
-+++ linux-2.6.16/fs/reiser4/vfs_ops.h
-@@ -0,0 +1,58 @@
+diff -urN linux-2.6.22.orig/fs/reiser4/vfs_ops.h linux-2.6.22/fs/reiser4/vfs_ops.h
+--- linux-2.6.22.orig/fs/reiser4/vfs_ops.h     1970-01-01 03:00:00.000000000 +0300
++++ linux-2.6.22/fs/reiser4/vfs_ops.h  2007-07-29 00:25:35.044739961 +0400
+@@ -0,0 +1,53 @@
 +/* Copyright 2001, 2002, 2003 by Hans Reiser, licensing governed by
 + * reiser4/README */
 +
@@ -77097,27 +76835,22 @@ Index: linux-2.6.16/fs/reiser4/vfs_ops.h
 +/* address space operations */
 +int reiser4_writepage(struct page *, struct writeback_control *);
 +int reiser4_set_page_dirty(struct page *);
-+int reiser4_readpages(struct file *, struct address_space *,
-+                    struct list_head *pages, unsigned nr_pages);
-+int reiser4_invalidatepage(struct page *, unsigned long offset);
++void reiser4_invalidatepage(struct page *, unsigned long offset);
 +int reiser4_releasepage(struct page *, gfp_t);
 +
 +extern int reiser4_update_sd(struct inode *);
 +extern int reiser4_add_nlink(struct inode *, struct inode *, int);
 +extern int reiser4_del_nlink(struct inode *, struct inode *, int);
 +
-+
 +extern int reiser4_start_up_io(struct page *page);
 +extern void reiser4_throttle_write(struct inode *);
 +extern int jnode_is_releasable(jnode *);
 +
 +#define CAPTURE_APAGE_BURST (1024l)
-+void writeout(struct super_block *, struct writeback_control *);
-+
++void reiser4_writeout(struct super_block *, struct writeback_control *);
 +
 +extern void reiser4_handle_error(void);
 +
-+
 +/* __FS_REISER4_VFS_OPS_H__ */
 +#endif
 +
@@ -77131,11 +76864,10 @@ Index: linux-2.6.16/fs/reiser4/vfs_ops.h
 +   scroll-step: 1
 +   End:
 +*/
-Index: linux-2.6.16/fs/reiser4/wander.c
-===================================================================
---- /dev/null
-+++ linux-2.6.16/fs/reiser4/wander.c
-@@ -0,0 +1,1799 @@
+diff -urN linux-2.6.22.orig/fs/reiser4/wander.c linux-2.6.22/fs/reiser4/wander.c
+--- linux-2.6.22.orig/fs/reiser4/wander.c      1970-01-01 03:00:00.000000000 +0300
++++ linux-2.6.22/fs/reiser4/wander.c   2007-07-29 00:25:35.048740996 +0400
+@@ -0,0 +1,1797 @@
 +/* Copyright 2001, 2002, 2003 by Hans Reiser, licensing governed by
 + * reiser4/README */
 +
@@ -77275,7 +77007,7 @@ Index: linux-2.6.16/fs/reiser4/wander.c
 +   versions in the reiser4 in-memory super block.  They get modified only at
 +   atom commit time.  The atom's commit thread has an exclusive access to those
 +   "committed" fields because the log writer implementation supports only one
-+   atom commit a time (there is a per-fs "commit" semaphore).  At
++   atom commit a time (there is a per-fs "commit" mutex).  At
 +   that time "committed" counters are modified using per-atom information
 +   collected during the transaction. These counters are stored on disk as a
 +   part of tx head block when atom is committed.
@@ -77373,7 +77105,6 @@ Index: linux-2.6.16/fs/reiser4/wander.c
 +      set_bit((int)REISER4_NO_WRITE_BARRIER, &get_super_private(s)->fs_flags);
 +}
 +
-+
 +/* fill journal header block data  */
 +static void format_journal_header(struct commit_handle *ch)
 +{
@@ -77631,7 +77362,7 @@ Index: linux-2.6.16/fs/reiser4/wander.c
 +                                    BA_FORMATTED);
 +
 +              unpin_jnode_data(cur);
-+              drop_io_head(cur);
++              reiser4_drop_io_head(cur);
 +      }
 +}
 +
@@ -77645,7 +77376,7 @@ Index: linux-2.6.16/fs/reiser4/wander.c
 +
 +      assert("zam-499", b != NULL);
 +      assert("zam-500", *b != 0);
-+      assert("zam-501", !blocknr_is_fake(b));
++      assert("zam-501", !reiser4_blocknr_is_fake(b));
 +
 +      reiser4_dealloc_block(b, BLOCK_NOT_COUNTED, BA_FORMATTED);
 +      return 0;
@@ -77674,7 +77405,7 @@ Index: linux-2.6.16/fs/reiser4/wander.c
 +         ZAM-FIXME-HANS: yes, what happened to our discussion of using a fixed
 +         reserved allocation area so as to get the best qualities of fixed
 +         journals? */
-+      blocknr_hint_init(&hint);
++      reiser4_blocknr_hint_init(&hint);
 +      hint.block_stage = BLOCK_GRABBED;
 +
 +      ret = reiser4_alloc_blocks(&hint, start, &wide_len,
@@ -77696,7 +77427,7 @@ Index: linux-2.6.16/fs/reiser4/wander.c
 +              jnode *node;
 +
 +              pg = bio->bi_io_vec[i].bv_page;
-+              ClearPageWriteback(pg);
++              end_page_writeback(pg);
 +              node = jprivate(pg);
 +              spin_lock_jnode(node);
 +              JF_CLR(node, JNODE_WRITEBACK);
@@ -77772,18 +77503,18 @@ Index: linux-2.6.16/fs/reiser4/wander.c
 +                              spin_unlock_jnode(sj);
 +
 +                              /* jload it as the rest of overwrite set */
-+                              jload_gfp(sj, get_gfp_mask(), 0);
++                              jload_gfp(sj, reiser4_ctx_gfp_mask_get(), 0);
 +
 +                              ch->overwrite_set_size++;
 +                      }
 +                      spin_lock_jnode(cur);
-+                      uncapture_block(cur);
++                      reiser4_uncapture_block(cur);
 +                      jput(cur);
 +
 +              } else {
 +                      int ret;
 +                      ch->overwrite_set_size++;
-+                      ret = jload_gfp(cur, get_gfp_mask(), 0);
++                      ret = jload_gfp(cur, reiser4_ctx_gfp_mask_get(), 0);
 +                      if (ret)
 +                              reiser4_panic("zam-783",
 +                                            "cannot load e-flushed jnode back (ret = %d)\n",
@@ -78051,7 +77782,7 @@ Index: linux-2.6.16/fs/reiser4/wander.c
 +              do {
 +                      atom = get_current_atom_locked();
 +                      assert("zam-536",
-+                             !blocknr_is_fake(jnode_get_block(cur)));
++                             !reiser4_blocknr_is_fake(jnode_get_block(cur)));
 +                      ret =
 +                          blocknr_set_add_pair(atom, &atom->wandered_map,
 +                                               &new_bsep,
@@ -78147,7 +77878,7 @@ Index: linux-2.6.16/fs/reiser4/wander.c
 +      while (allocated < (unsigned)ch->tx_size) {
 +              len = (ch->tx_size - allocated);
 +
-+              blocknr_hint_init(&hint);
++              reiser4_blocknr_hint_init(&hint);
 +
 +              hint.block_stage = BLOCK_GRABBED;
 +
@@ -78159,7 +77890,7 @@ Index: linux-2.6.16/fs/reiser4/wander.c
 +              ret = reiser4_alloc_blocks(&hint, &first, &len,
 +                                         BA_FORMATTED | BA_RESERVED |
 +                                         BA_USE_DEFAULT_SEARCH_START);
-+              blocknr_hint_done(&hint);
++              reiser4_blocknr_hint_done(&hint);
 +
 +              if (ret)
 +                      return ret;
@@ -78168,14 +77899,14 @@ Index: linux-2.6.16/fs/reiser4/wander.c
 +
 +              /* create jnodes for all wander records */
 +              while (len--) {
-+                      cur = alloc_io_head(&first);
++                      cur = reiser4_alloc_io_head(&first);
 +
 +                      if (cur == NULL) {
 +                              ret = RETERR(-ENOMEM);
 +                              goto free_not_assigned;
 +                      }
 +
-+                      ret = jinit_new(cur, get_gfp_mask());
++                      ret = jinit_new(cur, reiser4_ctx_gfp_mask_get());
 +
 +                      if (ret != 0) {
 +                              jfree(cur);
@@ -78264,7 +77995,7 @@ Index: linux-2.6.16/fs/reiser4/wander.c
 +                      break;
 +      } while (0);
 +
-+      fq_put(fq);
++      reiser4_fq_put(fq);
 +      if (ret)
 +              return ret;
 + repeat_wo_barrier:
@@ -78288,21 +78019,20 @@ Index: linux-2.6.16/fs/reiser4/wander.c
 +      return ret;
 +}
 +
-+
 +static int write_tx_back(struct commit_handle * ch)
 +{
 +      flush_queue_t *fq;
 +      int ret;
 +      int barrier;
 +
-+      post_commit_hook();
++      reiser4_post_commit_hook();
 +      fq = get_fq_for_current_atom();
 +      if (IS_ERR(fq))
 +              return  PTR_ERR(fq);
 +      spin_unlock_atom(fq->atom);
 +      ret = write_jnode_list(
 +              ch->overwrite_set, fq, NULL, WRITEOUT_FOR_PAGE_RECLAIM);
-+      fq_put(fq);
++      reiser4_fq_put(fq);
 +      if (ret)
 +              return ret;
 + repeat_wo_barrier:
@@ -78325,7 +78055,7 @@ Index: linux-2.6.16/fs/reiser4/wander.c
 +      }
 +      if (ret)
 +              return ret;
-+      post_write_back_hook();
++      reiser4_post_write_back_hook();
 +      return 0;
 +}
 +
@@ -78345,7 +78075,7 @@ Index: linux-2.6.16/fs/reiser4/wander.c
 +      writeout_mode_enable();
 +
 +      /* block allocator may add j-nodes to the clean_list */
-+      ret = pre_commit_hook();
++      ret = reiser4_pre_commit_hook();
 +      if (ret)
 +              return ret;
 +
@@ -78356,17 +78086,17 @@ Index: linux-2.6.16/fs/reiser4/wander.c
 +
 +      /* relocate set is on the atom->clean_nodes list after
 +       * current_atom_complete_writes() finishes. It can be safely
-+       * uncaptured after commit_semaphore is taken, because any atom that
++       * uncaptured after commit_mutex is locked, because any atom that
 +       * captures these nodes is guaranteed to commit after current one.
 +       *
-+       * This can only be done after pre_commit_hook(), because it is where
++       * This can only be done after reiser4_pre_commit_hook(), because it is where
 +       * early flushed jnodes with CREATED bit are transferred to the
 +       * overwrite list. */
-+      invalidate_list(ATOM_CLEAN_LIST(atom));
++      reiser4_invalidate_list(ATOM_CLEAN_LIST(atom));
 +      spin_lock_atom(atom);
 +      /* There might be waiters for the relocate nodes which we have
 +       * released, wake them up. */
-+      atom_send_event(atom);
++      reiser4_atom_send_event(atom);
 +      spin_unlock_atom(atom);
 +
 +      if (REISER4_DEBUG) {
@@ -78409,11 +78139,11 @@ Index: linux-2.6.16/fs/reiser4/wander.c
 +              goto up_and_ret;
 +
 +      spin_lock_atom(atom);
-+      atom_set_stage(atom, ASTAGE_POST_COMMIT);
++      reiser4_atom_set_stage(atom, ASTAGE_POST_COMMIT);
 +      spin_unlock_atom(atom);
 +
 +      ret = write_tx_back(&ch);
-+      post_write_back_hook();
++      reiser4_post_write_back_hook();
 +
 +      up_and_ret:
 +      if (ret) {
@@ -78554,20 +78284,20 @@ Index: linux-2.6.16/fs/reiser4/wander.c
 +                      goto free_ow_set;
 +              }
 +
-+              log = alloc_io_head(&log_rec_block);
++              log = reiser4_alloc_io_head(&log_rec_block);
 +              if (log == NULL)
 +                      return RETERR(-ENOMEM);
 +
 +              ret = jload(log);
 +              if (ret < 0) {
-+                      drop_io_head(log);
++                      reiser4_drop_io_head(log);
 +                      return ret;
 +              }
 +
 +              ret = check_wander_record(log);
 +              if (ret) {
 +                      jrelse(log);
-+                      drop_io_head(log);
++                      reiser4_drop_io_head(log);
 +                      return ret;
 +              }
 +
@@ -78585,26 +78315,26 @@ Index: linux-2.6.16/fs/reiser4/wander.c
 +                      if (block == 0)
 +                              break;
 +
-+                      node = alloc_io_head(&block);
++                      node = reiser4_alloc_io_head(&block);
 +                      if (node == NULL) {
 +                              ret = RETERR(-ENOMEM);
 +                              /*
 +                               * FIXME-VS:???
 +                               */
 +                              jrelse(log);
-+                              drop_io_head(log);
++                              reiser4_drop_io_head(log);
 +                              goto free_ow_set;
 +                      }
 +
 +                      ret = jload(node);
 +
 +                      if (ret < 0) {
-+                              drop_io_head(node);
++                              reiser4_drop_io_head(node);
 +                              /*
 +                               * FIXME-VS:???
 +                               */
 +                              jrelse(log);
-+                              drop_io_head(log);
++                              reiser4_drop_io_head(log);
 +                              goto free_ow_set;
 +                      }
 +
@@ -78620,7 +78350,7 @@ Index: linux-2.6.16/fs/reiser4/wander.c
 +              }
 +
 +              jrelse(log);
-+              drop_io_head(log);
++              reiser4_drop_io_head(log);
 +
 +              --nr_wander_records;
 +      }
@@ -78650,7 +78380,7 @@ Index: linux-2.6.16/fs/reiser4/wander.c
 +              jnode *cur = list_entry(ch.overwrite_set->next, jnode, capture_link);
 +              list_del_init(&cur->capture_link);
 +              jrelse(cur);
-+              drop_io_head(cur);
++              reiser4_drop_io_head(cur);
 +      }
 +
 +      list_del_init(&tx_head->capture_link);
@@ -78700,20 +78430,20 @@ Index: linux-2.6.16/fs/reiser4/wander.c
 +
 +      /* searching for oldest not flushed transaction */
 +      while (1) {
-+              tx_head = alloc_io_head(&prev_tx);
++              tx_head = reiser4_alloc_io_head(&prev_tx);
 +              if (!tx_head)
 +                      return RETERR(-ENOMEM);
 +
 +              ret = jload(tx_head);
 +              if (ret < 0) {
-+                      drop_io_head(tx_head);
++                      reiser4_drop_io_head(tx_head);
 +                      return ret;
 +              }
 +
 +              ret = check_tx_head(tx_head);
 +              if (ret) {
 +                      jrelse(tx_head);
-+                      drop_io_head(tx_head);
++                      reiser4_drop_io_head(tx_head);
 +                      return ret;
 +              }
 +
@@ -78725,7 +78455,7 @@ Index: linux-2.6.16/fs/reiser4/wander.c
 +                      break;
 +
 +              jrelse(tx_head);
-+              drop_io_head(tx_head);
++              reiser4_drop_io_head(tx_head);
 +      }
 +
 +      total = le32_to_cpu(get_unaligned(&T->total));
@@ -78739,7 +78469,7 @@ Index: linux-2.6.16/fs/reiser4/wander.c
 +                             jnode_get_block(tx_head), total - 1);
 +
 +      unpin_jnode_data(tx_head);
-+      drop_io_head(tx_head);
++      reiser4_drop_io_head(tx_head);
 +
 +      if (ret)
 +              return ret;
@@ -78859,14 +78589,14 @@ Index: linux-2.6.16/fs/reiser4/wander.c
 +{
 +      int ret;
 +
-+      *node = alloc_io_head(block);
++      *node = reiser4_alloc_io_head(block);
 +      if (!(*node))
 +              return RETERR(-ENOMEM);
 +
 +      ret = jload(*node);
 +
 +      if (ret) {
-+              drop_io_head(*node);
++              reiser4_drop_io_head(*node);
 +              *node = NULL;
 +              return ret;
 +      }
@@ -78882,13 +78612,13 @@ Index: linux-2.6.16/fs/reiser4/wander.c
 +{
 +      if (*node) {
 +              unpin_jnode_data(*node);
-+              drop_io_head(*node);
++              reiser4_drop_io_head(*node);
 +              *node = NULL;
 +      }
 +}
 +
 +/* release journal control blocks */
-+void done_journal_info(struct super_block *s)
++void reiser4_done_journal_info(struct super_block *s)
 +{
 +      reiser4_super_info_data *sbinfo = get_super_private(s);
 +
@@ -78900,7 +78630,7 @@ Index: linux-2.6.16/fs/reiser4/wander.c
 +}
 +
 +/* load journal control blocks */
-+int init_journal_info(struct super_block *s)
++int reiser4_init_journal_info(struct super_block *s)
 +{
 +      reiser4_super_info_data *sbinfo = get_super_private(s);
 +      journal_location *loc;
@@ -78935,10 +78665,9 @@ Index: linux-2.6.16/fs/reiser4/wander.c
 +   fill-column: 80
 +   End:
 +*/
-Index: linux-2.6.16/fs/reiser4/wander.h
-===================================================================
---- /dev/null
-+++ linux-2.6.16/fs/reiser4/wander.h
+diff -urN linux-2.6.22.orig/fs/reiser4/wander.h linux-2.6.22/fs/reiser4/wander.h
+--- linux-2.6.22.orig/fs/reiser4/wander.h      1970-01-01 03:00:00.000000000 +0300
++++ linux-2.6.22/fs/reiser4/wander.h   2007-07-29 00:25:35.048740996 +0400
 @@ -0,0 +1,135 @@
 +/* Copyright 2002, 2003 by Hans Reiser, licensing governed by reiser4/README */
 +
@@ -79058,8 +78787,8 @@ Index: linux-2.6.16/fs/reiser4/wander.h
 +extern int reiser4_journal_replay(struct super_block *);
 +extern int reiser4_journal_recover_sb_data(struct super_block *);
 +
-+extern int init_journal_info(struct super_block *);
-+extern void done_journal_info(struct super_block *);
++extern int reiser4_init_journal_info(struct super_block *);
++extern void reiser4_done_journal_info(struct super_block *);
 +
 +extern int write_jnode_list(struct list_head *, flush_queue_t *, long *, int);
 +
@@ -79075,10 +78804,9 @@ Index: linux-2.6.16/fs/reiser4/wander.h
 +   scroll-step: 1
 +   End:
 +*/
-Index: linux-2.6.16/fs/reiser4/writeout.h
-===================================================================
---- /dev/null
-+++ linux-2.6.16/fs/reiser4/writeout.h
+diff -urN linux-2.6.22.orig/fs/reiser4/writeout.h linux-2.6.22/fs/reiser4/writeout.h
+--- linux-2.6.22.orig/fs/reiser4/writeout.h    1970-01-01 03:00:00.000000000 +0300
++++ linux-2.6.22/fs/reiser4/writeout.h 2007-07-29 00:25:35.052742032 +0400
 @@ -0,0 +1,21 @@
 +/* Copyright 2002, 2003, 2004 by Hans Reiser, licensing governed by reiser4/README  */
 +
@@ -79088,7 +78816,7 @@ Index: linux-2.6.16/fs/reiser4/writeout.h
 +#define WRITEOUT_FOR_PAGE_RECLAIM  (0x2)
 +#define WRITEOUT_BARRIER (0x4)
 +
-+extern int get_writeout_flags(void);
++extern int reiser4_get_writeout_flags(void);
 +
 +#endif                                /* __FS_REISER4_WRITEOUT_H__ */
 +
@@ -79101,11 +78829,10 @@ Index: linux-2.6.16/fs/reiser4/writeout.h
 +   fill-column: 80
 +   End:
 +*/
-Index: linux-2.6.16/fs/reiser4/znode.c
-===================================================================
---- /dev/null
-+++ linux-2.6.16/fs/reiser4/znode.c
-@@ -0,0 +1,1028 @@
+diff -urN linux-2.6.22.orig/fs/reiser4/znode.c linux-2.6.22/fs/reiser4/znode.c
+--- linux-2.6.22.orig/fs/reiser4/znode.c       1970-01-01 03:00:00.000000000 +0300
++++ linux-2.6.22/fs/reiser4/znode.c    2007-07-29 00:25:35.052742032 +0400
+@@ -0,0 +1,1029 @@
 +/* Copyright 2001, 2002, 2003 by Hans Reiser, licensing governed by
 + * reiser4/README */
 +/* Znode manipulation functions. */
@@ -79198,7 +78925,7 @@ Index: linux-2.6.16/fs/reiser4/znode.c
 +   When we irrevocably commit ourselves to decision to remove node from the
 +   tree, JNODE_HEARD_BANSHEE bit is set in zjnode.state of corresponding
 +   znode. This is done either in ->kill_hook() of internal item or in
-+   kill_root() function when tree root is removed.
++   reiser4_kill_root() function when tree root is removed.
 +
 +   At this moment znode still has:
 +
@@ -79216,9 +78943,9 @@ Index: linux-2.6.16/fs/reiser4/znode.c
 +   parent node due to its nonexistence or proper parent node locking and
 +   nobody uses parent pointers from children due to absence of them. Second we
 +   invalidate all pending lock requests which still are on znode's lock
-+   request queue, this is done by invalidate_lock(). Another JNODE_IS_DYING
-+   znode status bit is used to invalidate pending lock requests. Once it set
-+   all requesters are forced to return -EINVAL from
++   request queue, this is done by reiser4_invalidate_lock(). Another
++   JNODE_IS_DYING znode status bit is used to invalidate pending lock requests.
++   Once it set all requesters are forced to return -EINVAL from
 +   longterm_lock_znode(). Future locking attempts are not possible because all
 +   ways to get references to that znode are removed already. Last, node is
 +   uncaptured from transaction.
@@ -79296,7 +79023,7 @@ Index: linux-2.6.16/fs/reiser4/znode.c
 +}
 +
 +/* The hash table definition */
-+#define KMALLOC(size) kmalloc((size), GFP_KERNEL)
++#define KMALLOC(size) kmalloc((size), reiser4_ctx_gfp_mask_get())
 +#define KFREE(ptr, size) kfree(ptr)
 +TYPE_SAFE_HASH_DEFINE(z, znode, reiser4_block_nr, zjnode.key.z, zjnode.link.z,
 +                    blknrhashfn, blknreq);
@@ -79304,7 +79031,7 @@ Index: linux-2.6.16/fs/reiser4/znode.c
 +#undef KMALLOC
 +
 +/* slab for znodes */
-+static kmem_cache_t *znode_cache;
++static struct kmem_cache *znode_cache;
 +
 +int znode_shift_order;
 +
@@ -79643,7 +79370,7 @@ Index: linux-2.6.16/fs/reiser4/znode.c
 +              write_unlock_tree(tree);
 +      }
 +#if REISER4_DEBUG
-+      if (!blocknr_is_fake(blocknr) && *blocknr != 0)
++      if (!reiser4_blocknr_is_fake(blocknr) && *blocknr != 0)
 +              reiser4_check_block(blocknr, 1);
 +#endif
 +      /* Check for invalid tree level, return -EIO */
@@ -79731,7 +79458,7 @@ Index: linux-2.6.16/fs/reiser4/znode.c
 +      assert("nikita-1377", znode_invariant(node));
 +      assert("jmacd-7771", !znode_above_root(node));
 +      assert("nikita-2125", atomic_read(&ZJNODE(node)->x_count) > 0);
-+      assert("nikita-3016", schedulable());
++      assert("nikita-3016", reiser4_schedulable());
 +
 +      if (info)
 +              formatted_readahead(node, info);
@@ -79803,7 +79530,7 @@ Index: linux-2.6.16/fs/reiser4/znode.c
 +             znode_is_any_locked(node) ||
 +             znode_get_level(node) != LEAF_LEVEL ||
 +             keyge(key, &node->rd_key) ||
-+             keyeq(&node->rd_key, min_key()) ||
++             keyeq(&node->rd_key, reiser4_min_key()) ||
 +             ZF_ISSET(node, JNODE_HEARD_BANSHEE));
 +
 +      node->rd_key = *key;
@@ -79819,7 +79546,8 @@ Index: linux-2.6.16/fs/reiser4/znode.c
 +      assert_rw_write_locked(&(znode_get_tree(node)->dk_lock));
 +      assert("nikita-3070", LOCK_CNT_GTZ(write_locked_dk));
 +      assert("nikita-2943",
-+             znode_is_any_locked(node) || keyeq(&node->ld_key, min_key()));
++             znode_is_any_locked(node) || keyeq(&node->ld_key,
++                                                reiser4_min_key()));
 +
 +      node->ld_key = *key;
 +      ON_DEBUG(node->ld_key_version = atomic_inc_return(&delim_key_version));
@@ -80134,10 +79862,9 @@ Index: linux-2.6.16/fs/reiser4/znode.c
 +   fill-column: 120
 +   End:
 +*/
-Index: linux-2.6.16/fs/reiser4/znode.h
-===================================================================
---- /dev/null
-+++ linux-2.6.16/fs/reiser4/znode.h
+diff -urN linux-2.6.22.orig/fs/reiser4/znode.h linux-2.6.22/fs/reiser4/znode.h
+--- linux-2.6.22.orig/fs/reiser4/znode.h       1970-01-01 03:00:00.000000000 +0300
++++ linux-2.6.22/fs/reiser4/znode.h    2007-07-29 00:25:35.052742032 +0400
 @@ -0,0 +1,434 @@
 +/* Copyright 2001, 2002, 2003, 2004 by Hans Reiser, licensing governed by
 + * reiser4/README */
@@ -80371,7 +80098,6 @@ Index: linux-2.6.16/fs/reiser4/znode.h
 +extern void zinit(znode *, const znode * parent, reiser4_tree *);
 +extern int zparse(znode * node);
 +
-+
 +extern int znode_just_created(const znode * node);
 +
 +extern void zfree(znode * node);
@@ -80544,16 +80270,17 @@ Index: linux-2.6.16/fs/reiser4/znode.h
 +
 +#if REISER4_DEBUG
 +#define STORE_COUNTERS                                                \
-+      lock_counters_info __entry_counters = *lock_counters()
-+#define CHECK_COUNTERS                                                \
-+ON_DEBUG_CONTEXT(                                             \
-+({                                                            \
-+      __entry_counters.x_refs = lock_counters() -> x_refs;    \
-+      __entry_counters.t_refs = lock_counters() -> t_refs;    \
-+      __entry_counters.d_refs = lock_counters() -> d_refs;    \
-+      assert("nikita-2159",                                   \
-+             !memcmp(&__entry_counters, lock_counters(),      \
-+                     sizeof __entry_counters));               \
++      reiser4_lock_cnt_info __entry_counters =                \
++              *reiser4_lock_counters()
++#define CHECK_COUNTERS                                                        \
++ON_DEBUG_CONTEXT(                                                     \
++({                                                                    \
++      __entry_counters.x_refs = reiser4_lock_counters() -> x_refs;    \
++      __entry_counters.t_refs = reiser4_lock_counters() -> t_refs;    \
++      __entry_counters.d_refs = reiser4_lock_counters() -> d_refs;    \
++      assert("nikita-2159",                                           \
++             !memcmp(&__entry_counters, reiser4_lock_counters(),      \
++                     sizeof __entry_counters));                       \
 +}) )
 +
 +#else
@@ -80573,20 +80300,19 @@ Index: linux-2.6.16/fs/reiser4/znode.h
 +   fill-column: 120
 +   End:
 +*/
-Index: linux-2.6.16/include/linux/fs.h
-===================================================================
---- linux-2.6.16.orig/include/linux/fs.h
-+++ linux-2.6.16/include/linux/fs.h
-@@ -1085,6 +1085,8 @@ struct super_operations {
+diff -urN linux-2.6.22.orig/include/linux/fs.h linux-2.6.22/include/linux/fs.h
+--- linux-2.6.22.orig/include/linux/fs.h       2007-07-21 00:33:00.673389540 +0400
++++ linux-2.6.22/include/linux/fs.h    2007-07-29 00:25:35.056743067 +0400
+@@ -1179,6 +1179,8 @@
        void (*clear_inode) (struct inode *);
-       void (*umount_begin) (struct super_block *);
+       void (*umount_begin) (struct vfsmount *, int);
  
 +      void (*sync_inodes) (struct super_block *sb,
 +                              struct writeback_control *wbc);
        int (*show_options)(struct seq_file *, struct vfsmount *);
-       ssize_t (*quota_read)(struct super_block *, int, char *, size_t, loff_t);
-@@ -1449,6 +1451,7 @@ extern int invalidate_inode_pages2(struc
+       int (*show_stats)(struct seq_file *, struct vfsmount *);
+ #ifdef CONFIG_QUOTA
+@@ -1630,6 +1632,7 @@
  extern int invalidate_inode_pages2_range(struct address_space *mapping,
                                         pgoff_t start, pgoff_t end);
  extern int write_inode_now(struct inode *, int);
@@ -80594,31 +80320,29 @@ Index: linux-2.6.16/include/linux/fs.h
  extern int filemap_fdatawrite(struct address_space *);
  extern int filemap_flush(struct address_space *);
  extern int filemap_fdatawait(struct address_space *);
-Index: linux-2.6.16/lib/radix-tree.c
-===================================================================
---- linux-2.6.16.orig/lib/radix-tree.c
-+++ linux-2.6.16/lib/radix-tree.c
-@@ -139,6 +139,7 @@ static inline void tag_set(struct radix_
- {
-       __set_bit(offset, node->tags[tag]);
+diff -urN linux-2.6.22.orig/lib/radix-tree.c linux-2.6.22/lib/radix-tree.c
+--- linux-2.6.22.orig/lib/radix-tree.c 2007-07-21 00:33:01.265543326 +0400
++++ linux-2.6.22/lib/radix-tree.c      2007-07-29 00:25:35.060744102 +0400
+@@ -151,6 +151,7 @@
+ out:
+       return ret;
  }
 +EXPORT_SYMBOL(radix_tree_preload);
  
- static inline void tag_clear(struct radix_tree_node *node, int tag, int offset)
- {
-Index: linux-2.6.16/mm/filemap.c
-===================================================================
---- linux-2.6.16.orig/mm/filemap.c
-+++ linux-2.6.16/mm/filemap.c
-@@ -119,6 +119,7 @@ void __remove_from_page_cache(struct pag
+ static inline void tag_set(struct radix_tree_node *node, unsigned int tag,
+               int offset)
+diff -urN linux-2.6.22.orig/mm/filemap.c linux-2.6.22/mm/filemap.c
+--- linux-2.6.22.orig/mm/filemap.c     2007-07-21 00:33:01.277546443 +0400
++++ linux-2.6.22/mm/filemap.c  2007-07-29 00:25:35.064745138 +0400
+@@ -121,6 +121,7 @@
        mapping->nrpages--;
-       pagecache_acct(-1);
+       __dec_zone_page_state(page, NR_FILE_PAGES);
  }
 +EXPORT_SYMBOL(__remove_from_page_cache);
  
  void remove_from_page_cache(struct page *page)
  {
-@@ -130,6 +131,7 @@ void remove_from_page_cache(struct page 
+@@ -132,6 +133,7 @@
        __remove_from_page_cache(page);
        write_unlock_irq(&mapping->tree_lock);
  }
@@ -80626,72 +80350,26 @@ Index: linux-2.6.16/mm/filemap.c
  
  static int sync_page(void *word)
  {
-@@ -272,6 +274,7 @@ static int wait_on_page_writeback_range(
+@@ -719,6 +721,7 @@
+       read_unlock_irq(&mapping->tree_lock);
        return ret;
  }
 +EXPORT_SYMBOL(add_to_page_cache_lru);
  
- /*
-  * Write and wait upon all the pages in the passed range.  This is a "data
-@@ -632,7 +635,6 @@ repeat:
-               page_cache_release(cached_page);
-       return page;
- }
--
- EXPORT_SYMBOL(find_or_create_page);
  /**
-@@ -665,6 +667,7 @@ unsigned find_get_pages(struct address_s
-       read_unlock_irq(&mapping->tree_lock);
-       return ret;
- }
-+EXPORT_SYMBOL(find_get_pages);
- /*
-  * Like find_get_pages, except we only return pages which are tagged with
-@@ -686,6 +689,7 @@ unsigned find_get_pages_tag(struct addre
-       read_unlock_irq(&mapping->tree_lock);
-       return ret;
- }
-+EXPORT_SYMBOL(find_get_pages_tag);
+  * find_get_pages_contig - gang contiguous pagecache lookup
+@@ -838,6 +841,7 @@
  
- /*
-  * Same as grab_cache_page, but do not wait if the page is unavailable.
-Index: linux-2.6.16/mm/page-writeback.c
-===================================================================
---- linux-2.6.16.orig/mm/page-writeback.c
-+++ linux-2.6.16/mm/page-writeback.c
-@@ -187,7 +187,7 @@ get_dirty_limits(struct writeback_state 
-  * If we're over `background_thresh' then pdflush is woken to perform some
-  * writeout.
-  */
--static void balance_dirty_pages(struct address_space *mapping)
-+void balance_dirty_pages(struct address_space *mapping)
- {
-       struct writeback_state wbs;
-       long nr_reclaimable;
-@@ -253,6 +253,7 @@ static void balance_dirty_pages(struct a
-            (!laptop_mode && (nr_reclaimable > background_thresh)))
-               pdflush_operation(background_writeout, 0);
+       ra->ra_pages /= 4;
  }
-+EXPORT_SYMBOL(balance_dirty_pages);
++EXPORT_SYMBOL(find_get_pages);
  
  /**
-  * balance_dirty_pages_ratelimited - balance dirty memory state
-Index: linux-2.6.16/mm/readahead.c
-===================================================================
---- linux-2.6.16.orig/mm/readahead.c
-+++ linux-2.6.16/mm/readahead.c
-@@ -541,6 +541,7 @@ page_cache_readahead(struct address_spac
- out:
-       return ra->prev_page + 1;
- }
-+EXPORT_SYMBOL_GPL(page_cache_readahead);
- /*
-  * handle_ra_miss() is called when it is known that a page which should have
-@@ -558,6 +559,7 @@ void handle_ra_miss(struct address_space
+  * do_generic_mapping_read - generic file read routine
+diff -urN linux-2.6.22.orig/mm/readahead.c linux-2.6.22/mm/readahead.c
+--- linux-2.6.22.orig/mm/readahead.c   2007-07-21 00:33:01.305553717 +0400
++++ linux-2.6.22/mm/readahead.c        2007-07-29 00:25:35.064745138 +0400
+@@ -571,6 +571,7 @@
        ra->flags &= ~RA_FLAG_INCACHE;
        ra->cache_hit = 0;
  }