-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 @@
+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
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 # pccardctl -V
- o quota-tools 3.09 # quota -V
-@@ -144,6 +145,13 @@
+ o pcmciautils 004
+ o pcmcia-cs 3.1.21 # cardmgr -V
+@@ -163,6 +164,13 @@ The reiserfsprogs package should be used
versions of mkreiserfs, resize_reiserfs, debugreiserfs and
reiserfsck. These utils work on both i386 and alpha platforms.
Xfsprogs
--------
-@@ -322,6 +330,10 @@
+@@ -344,6 +352,10 @@ Reiserfsprogs
-------------
o <http://www.namesys.com/pub/reiserfsprogs/reiserfsprogs-3.6.3.tar.gz>
Xfsprogs
--------
o <ftp://oss.sgi.com/projects/xfs/download/>
-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
+Index: linux-2.6.16/Documentation/filesystems/reiser4.txt
+===================================================================
+--- /dev/null
++++ linux-2.6.16/Documentation/filesystems/reiser4.txt
@@ -0,0 +1,75 @@
+Reiser4 filesystem
+==================
+dont_load_bitmap
+ Don't load all bitmap blocks at mount time, it is useful for
+ machines with tiny RAM and large disks.
-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 @@
+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
* 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().
*
* 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,
-@@ -313,11 +311,13 @@
+@@ -303,11 +301,13 @@ __writeback_single_inode(struct inode *i
* 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.
*/
if (!wbc->for_kupdate || list_empty(&sb->s_io))
list_splice_init(&sb->s_dirty, &sb->s_io);
-@@ -397,8 +397,19 @@
+@@ -387,8 +387,19 @@ sync_sb_inodes(struct super_block *sb, s
if (wbc->nr_to_write <= 0)
break;
}
/*
* Start writeback of dirty pagecache data against all unlocked inodes.
-@@ -439,11 +450,8 @@
+@@ -429,11 +440,8 @@ restart:
* be unmounted by the time it is released.
*/
if (down_read_trylock(&sb->s_umount)) {
up_read(&sb->s_umount);
}
spin_lock(&sb_lock);
-@@ -481,9 +489,7 @@
+@@ -469,9 +477,7 @@ void sync_inodes_sb(struct super_block *
(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 */
}
/*
-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/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.
+
- 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 @@
++ 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.
++
+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 @@
+/* Copyright 2003 by Hans Reiser, licensing governed by reiser4/README */
+
+/* Interface to VFS. Reiser4 address_space_operations are defined here. */
+ * @page: page to be dirtied
+ *
+ * Operation of struct address_space_operations. This implementation is used by
-+ * unix and cryptcompress file plugins.
++ * unix and crc 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.
+ /* this page can be unformatted only */
+ assert("vs-1734", (page->mapping &&
+ page->mapping->host &&
-+ reiser4_get_super_fake(page->mapping->host->i_sb) !=
++ get_super_fake(page->mapping->host->i_sb) !=
+ page->mapping->host
-+ && reiser4_get_cc_fake(page->mapping->host->i_sb) !=
++ && get_cc_fake(page->mapping->host->i_sb) !=
+ page->mapping->host
-+ && reiser4_get_bitmap_fake(page->mapping->host->i_sb) !=
++ && get_bitmap_fake(page->mapping->host->i_sb) !=
+ page->mapping->host));
+
+ if (!TestSetPageDirty(page)) {
+ if (page->mapping) {
+ assert("vs-1652", page->mapping == mapping);
+ if (mapping_cap_account_dirty(mapping))
-+ inc_zone_page_state(page,
-+ NR_FILE_DIRTY);
++ inc_page_state(nr_dirty);
+ radix_tree_tag_set(&mapping->page_tree,
+ page->index,
+ PAGECACHE_TAG_REISER4_MOVED);
+ 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 */
+
+/*
+ * @offset: starting offset for partial invalidation
+ *
+ */
-+void reiser4_invalidatepage(struct page *page, unsigned long offset)
++int reiser4_invalidatepage(struct page *page, unsigned long offset)
+{
+ int ret = 0;
+ reiser4_context *ctx;
+ *
+ * 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 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.
++ * 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.
+ */
+
+ assert("nikita-3137", PageLocked(page));
+ * during mount) it is simpler to let ->invalidatepage to be called on
+ * them. Check for this, and do nothing.
+ */
-+ 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;
++ 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;
+ 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(CRYPTCOMPRESS_FILE_PLUGIN_ID),
-+ offset == 0));
++ file_plugin_by_id(CRC_FILE_PLUGIN_ID), offset == 0));
+
-+ ctx = reiser4_init_context(inode->i_sb);
++ ctx = init_context(inode->i_sb);
+ if (IS_ERR(ctx))
-+ return;
++ return PTR_ERR(ctx);
+
+ node = jprivate(page);
+ spin_lock_jnode(node);
+ jref(node);
+ JF_SET(node, JNODE_HEARD_BANSHEE);
+ page_clear_jnode(page, node);
-+ reiser4_uncapture_jnode(node);
++ uncapture_jnode(node);
+ unhash_unformatted_jnode(node);
+ jput(node);
+ reiser4_exit_context(ctx);
-+ return;
++ return 0;
+ }
+ spin_unlock_jnode(node);
+
+ JF_SET(node, JNODE_HEARD_BANSHEE);
+ /* page cannot be detached from jnode concurrently, because it
+ * is locked */
-+ reiser4_uncapture_page(page);
++ uncapture_page(page);
+
+ /* this detaches page from jnode, so that jdelete will not try
+ * to lock page which is already locked */
+ }
+
+ reiser4_exit_context(ctx);
++ return 0;
+}
+
+/* help function called from reiser4_releasepage(). It returns true if jnode
+ * clean, not it atom yet, and still having fake block number. For
+ * example, node just created in jinit_new().
+ */
-+ if (reiser4_blocknr_is_fake(jnode_get_block(node)))
++ if (blocknr_is_fake(jnode_get_block(node)))
+ return 0;
+
+ /*
+ assert("nikita-2257", PagePrivate(page));
+ assert("nikita-2259", PageLocked(page));
+ assert("nikita-2892", !PageWriteback(page));
-+ assert("nikita-3019", reiser4_schedulable());
++ assert("nikita-3019", 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
+ 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;
+
+ } else {
+ spin_unlock(&(node->load));
+ spin_unlock_jnode(node);
-+ assert("nikita-3020", reiser4_schedulable());
++ assert("nikita-3020", schedulable());
+ return 0;
+ }
+}
+ fill-column: 120
+ End:
+*/
-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 @@
+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 @@
+/* Copyright 2001, 2002, 2003 by Hans Reiser, licensing governed by reiser4/README */
+
+#include "debug.h"
+ impossible to overload this counter during one transaction life. */
+
+/* Initialize a blocknr hint. */
-+void reiser4_blocknr_hint_init(reiser4_blocknr_hint * hint)
++void blocknr_hint_init(reiser4_blocknr_hint * hint)
+{
+ memset(hint, 0, sizeof(reiser4_blocknr_hint));
+}
+
+/* Release any resources of a blocknr hint. */
-+void reiser4_blocknr_hint_done(reiser4_blocknr_hint * hint UNUSED_ARG)
++void 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 reiser4_blocknr_is_fake(const reiser4_block_nr * da)
++int 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
+/* 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 reiser4_check_block_counters(const struct super_block *super)
++int 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) + reiser4_flush_reserved(super) +
++ reiser4_fake_allocated_unformatted(super) + flush_reserved(super) +
+ reiser4_clustered_blocks(super);
+ if (reiser4_block_count(super) != sum) {
+ printk("super block counters: "
+ (unsigned long long)reiser4_fake_allocated(super),
+ (unsigned long long)
+ reiser4_fake_allocated_unformatted(super),
-+ (unsigned long long)reiser4_flush_reserved(super),
++ (unsigned long long)flush_reserved(super),
+ (unsigned long long)reiser4_clustered_blocks(super),
+ (unsigned long long)sum,
+ (unsigned long long)reiser4_block_count(super));
+ ctx->grabbed_initially = count;
+#endif
+
-+ assert("nikita-2986", reiser4_check_block_counters(ctx->super));
++ assert("nikita-2986", check_block_counters(ctx->super));
+
+ /* disable grab space in current context */
+ ctx->grab_enabled = 0;
+ * 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 mutex is used to allow only one
++ * drain it. Per super block delete_sema semaphore 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
+
+ assert("nikita-3175", flags & BA_CAN_COMMIT);
+
-+ /* Check the delete mutex already taken by us, we assume that
++ /* Check the delete semaphore already taken by us, we assume that
+ * reading of machine word is atomic. */
-+ if (sbinfo->delete_mutex_owner == current) {
++ if (sbinfo->delete_sema_owner == current) {
+ if (reiser4_grab_space
+ (count, (flags | BA_RESERVED) & ~BA_CAN_COMMIT)) {
+ warning("zam-1003",
+ }
+
+ if (reiser4_grab_space(count, flags)) {
-+ mutex_lock(&sbinfo->delete_mutex);
-+ assert("nikita-2929", sbinfo->delete_mutex_owner == NULL);
-+ sbinfo->delete_mutex_owner = current;
++ down(&sbinfo->delete_sema);
++ assert("nikita-2929", sbinfo->delete_sema_owner == NULL);
++ sbinfo->delete_sema_owner = current;
+
+ if (reiser4_grab_space(count, flags | BA_RESERVED)) {
+ warning("zam-833",
+ reiser4_super_info_data *info;
+
+ info = get_super_private(super);
-+ if (info->delete_mutex_owner == current) {
-+ info->delete_mutex_owner = NULL;
-+ mutex_unlock(&info->delete_mutex);
++ if (info->delete_sema_owner == current) {
++ info->delete_sema_owner = NULL;
++ up(&info->delete_sema);
+ }
+}
+
+ sbinfo = grabbed2fake_allocated_head(1);
+ sbinfo->blocks_fake_allocated++;
+
-+ assert("vs-922", reiser4_check_block_counters(reiser4_get_current_sb()));
++ assert("vs-922", check_block_counters(reiser4_get_current_sb()));
+
+ spin_unlock_reiser4_super(sbinfo);
+}
+ sbinfo = grabbed2fake_allocated_head(count);
+ sbinfo->blocks_fake_allocated_unformatted += count;
+
-+ assert("vs-9221", reiser4_check_block_counters(reiser4_get_current_sb()));
++ assert("vs-9221", check_block_counters(reiser4_get_current_sb()));
+
+ spin_unlock_reiser4_super(sbinfo);
+}
+ sub_from_sb_grabbed(sbinfo, count);
+ sbinfo->blocks_clustered += count;
+
-+ assert("edward-504", reiser4_check_block_counters(ctx->super));
++ assert("edward-504", check_block_counters(ctx->super));
+
+ spin_unlock_reiser4_super(sbinfo);
+}
+ sub_from_cluster_reserved(sbinfo, count);
+ sbinfo->blocks_grabbed += count;
+
-+ assert("edward-505", reiser4_check_block_counters(ctx->super));
++ assert("edward-505", check_block_counters(ctx->super));
+
+ spin_unlock_reiser4_super(sbinfo);
+ add_to_ctx_grabbed(ctx, count);
+ 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);
+
-+ cluster_reserved2grabbed(count);
-+ grabbed2free(ctx, sbinfo, count);
++ sub_from_cluster_reserved(sbinfo, count);
++ sbinfo->blocks_free += count;
++
++ assert("edward-502", check_block_counters(ctx->super));
++
++ spin_unlock_reiser4_super(sbinfo);
+}
+
+static DEFINE_SPINLOCK(fake_lock);
+
+/* adjust sb block counters, if real (on-disk) block allocation immediately
+ follows grabbing of free disk space. */
-+static void grabbed2used(reiser4_context *ctx, reiser4_super_info_data *sbinfo,
-+ __u64 count)
++void grabbed2used(reiser4_context *ctx, reiser4_super_info_data *sbinfo,
++ __u64 count)
+{
+ sub_from_ctx_grabbed(ctx, count);
+
+ sub_from_sb_grabbed(sbinfo, count);
+ sbinfo->blocks_used += count;
+
-+ assert("nikita-2679", reiser4_check_block_counters(ctx->super));
++ assert("nikita-2679", check_block_counters(ctx->super));
+
+ spin_unlock_reiser4_super(sbinfo);
+}
+
+/* adjust sb block counters when @count unallocated blocks get mapped to disk */
-+static void fake_allocated2used(reiser4_super_info_data *sbinfo, __u64 count,
-+ reiser4_ba_flags_t flags)
++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",
-+ reiser4_check_block_counters(reiser4_get_current_sb()));
++ assert("nikita-2680", check_block_counters(reiser4_get_current_sb()));
+
+ spin_unlock_reiser4_super(sbinfo);
+}
+
-+static void flush_reserved2used(txn_atom * atom, __u64 count)
++void flush_reserved2used(txn_atom * atom, __u64 count)
+{
+ reiser4_super_info_data *sbinfo;
+
+ sub_from_sb_flush_reserved(sbinfo, count);
+ sbinfo->blocks_used += count;
+
-+ assert("zam-789",
-+ reiser4_check_block_counters(reiser4_get_current_sb()));
++ assert("zam-789", check_block_counters(reiser4_get_current_sb()));
+
+ spin_unlock_reiser4_super(sbinfo);
+}
+{
+ reiser4_super_info_data *sbinfo = get_super_private(s);
+
-+ assert("nikita-3342", !reiser4_blocknr_is_fake(block));
++ assert("nikita-3342", !blocknr_is_fake(block));
+
+ spin_lock_reiser4_super(sbinfo);
+ if (*block < sbinfo->block_count) {
+ }
+
+ ret =
-+ sa_alloc_blocks(reiser4_get_space_allocator(ctx->super),
-+ hint, (int)needed, blk, len);
++ sa_alloc_blocks(get_space_allocator(ctx->super), hint, (int)needed,
++ blk, len);
+
+ if (!ret) {
+ assert("zam-680", *blk < reiser4_block_count(ctx->super));
+
+ sub_from_sb_used(sbinfo, count);
+
-+ assert("nikita-2681",
-+ reiser4_check_block_counters(reiser4_get_current_sb()));
++ assert("nikita-2681", check_block_counters(reiser4_get_current_sb()));
+
+ spin_unlock_reiser4_super(sbinfo);
+}
+ /*add_to_sb_flush_reserved(sbinfo, count); */
+ sub_from_sb_used(sbinfo, count);
+
-+ assert("nikita-2681",
-+ reiser4_check_block_counters(reiser4_get_current_sb()));
++ assert("nikita-2681", check_block_counters(reiser4_get_current_sb()));
+
+ spin_unlock_reiser4_super(sbinfo);
+}
+
+ spin_lock_reiser4_super(sbinfo);
+
-+ assert("nikita-2682", reiser4_check_block_counters(ctx->super));
++ assert("nikita-2682", check_block_counters(ctx->super));
+
+ sbinfo->blocks_grabbed += count;
+ sub_from_sb_fake_allocated(sbinfo, count, flags & BA_FORMATTED);
+
-+ assert("nikita-2683", reiser4_check_block_counters(ctx->super));
++ assert("nikita-2683", check_block_counters(ctx->super));
+
+ spin_unlock_reiser4_super(sbinfo);
+}
+
+ sub_from_sb_grabbed(sbinfo, count);
+ sbinfo->blocks_free += count;
-+ assert("nikita-2684", reiser4_check_block_counters(ctx->super));
++ assert("nikita-2684", check_block_counters(ctx->super));
+
+ spin_unlock_reiser4_super(sbinfo);
+}
+ sbinfo->blocks_flush_reserved += count;
+ sub_from_sb_grabbed(sbinfo, count);
+
-+ assert("vpf-292", reiser4_check_block_counters(ctx->super));
++ assert("vpf-292", check_block_counters(ctx->super));
+
+ spin_unlock_reiser4_super(sbinfo);
+}
+ sbinfo->blocks_grabbed += count;
+ sub_from_sb_flush_reserved(sbinfo, count);
+
-+ assert("vpf-292", reiser4_check_block_counters(ctx->super));
++ assert("vpf-292", check_block_counters(ctx->super));
+
+ spin_unlock_reiser4_super(sbinfo);
+}
+ sbinfo->blocks_grabbed += count;
+ sub_from_sb_used(sbinfo, count);
+
-+ assert("nikita-2685", reiser4_check_block_counters(ctx->super));
++ assert("nikita-2685", check_block_counters(ctx->super));
+
+ spin_unlock_reiser4_super(sbinfo);
+}
+ sbinfo->blocks_free += count;
+ sub_from_sb_used(sbinfo, count);
+
-+ assert("nikita-2685",
-+ reiser4_check_block_counters(reiser4_get_current_sb()));
++ assert("nikita-2685", check_block_counters(reiser4_get_current_sb()));
+
+ spin_unlock_reiser4_super(sbinfo);
+}
+ if (REISER4_DEBUG) {
+ assert("zam-431", *len != 0);
+ assert("zam-432", *start != 0);
-+ assert("zam-558", !reiser4_blocknr_is_fake(start));
++ assert("zam-558", !blocknr_is_fake(start));
+
+ spin_lock_reiser4_super(sbinfo);
+ assert("zam-562", *start < sbinfo->block_count);
+
+ } else {
+ assert("zam-425", get_current_super_private() != NULL);
-+ sa_dealloc_blocks(reiser4_get_space_allocator(ctx->super),
-+ *start, *len);
++ sa_dealloc_blocks(get_space_allocator(ctx->super), *start,
++ *len);
+
+ if (flags & BA_PERMANENT) {
+ /* These blocks were counted as allocated, we have to revert it
+}
+
+/* wrappers for block allocator plugin methods */
-+int reiser4_pre_commit_hook(void)
++int pre_commit_hook(void)
+{
+ assert("zam-502", get_current_super_private() != NULL);
+ sa_pre_commit_hook();
+ return 0;
+}
+
-+void reiser4_post_commit_hook(void)
++void post_commit_hook(void)
+{
+ txn_atom *atom;
+
+ sa_post_commit_hook();
+}
+
-+void reiser4_post_write_back_hook(void)
++void post_write_back_hook(void)
+{
+ assert("zam-504", get_current_super_private() != NULL);
+
+ scroll-step: 1
+ End:
+*/
-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
+Index: linux-2.6.16/fs/reiser4/block_alloc.h
+===================================================================
+--- /dev/null
++++ linux-2.6.16/fs/reiser4/block_alloc.h
@@ -0,0 +1,175 @@
+/* Copyright 2002, 2003 by Hans Reiser, licensing governed by reiser4/README */
+
+
+typedef enum reiser4_ba_flags reiser4_ba_flags_t;
+
-+extern void reiser4_blocknr_hint_init(reiser4_blocknr_hint * hint);
-+extern void reiser4_blocknr_hint_done(reiser4_blocknr_hint * hint);
++extern void blocknr_hint_init(reiser4_blocknr_hint * hint);
++extern void 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 *);
+
+extern void flush_reserved2grabbed(txn_atom * atom, __u64 count);
+
-+extern int reiser4_blocknr_is_fake(const reiser4_block_nr * da);
++extern int 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 reiser4_check_block_counters(const struct super_block *);
++extern int check_block_counters(const struct super_block *);
+
+#if REISER4_DEBUG
+
+
+#endif
+
-+extern int reiser4_pre_commit_hook(void);
-+extern void reiser4_post_commit_hook(void);
-+extern void reiser4_post_write_back_hook(void);
++extern int pre_commit_hook(void);
++extern void post_commit_hook(void);
++extern void post_write_back_hook(void);
+
+#endif /* __FS_REISER4_BLOCK_ALLOC_H__ */
+
+ fill-column: 120
+ End:
+*/
-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
+Index: linux-2.6.16/fs/reiser4/blocknrset.c
+===================================================================
+--- /dev/null
++++ linux-2.6.16/fs/reiser4/blocknrset.c
@@ -0,0 +1,368 @@
+/* Copyright 2001, 2002, 2003 by Hans Reiser, licensing governed by reiser4/README */
+
+ * extent; atom's wandered map is also stored as a blocknr set, blocknr pairs
+ * there represent a (real block) -> (wandered block) mapping. */
+
-+/* Protection: blocknr sets belong to reiser4 atom, and
-+ * their modifications are performed with the atom lock held */
++typedef struct blocknr_pair blocknr_pair;
+
+/* The total size of a blocknr_set_entry. */
+#define BLOCKNR_SET_ENTRY_SIZE 128
+ blocknr_set_entry *e;
+
+ if ((e = (blocknr_set_entry *) kmalloc(sizeof(blocknr_set_entry),
-+ reiser4_ctx_gfp_mask_get())) == NULL)
++ get_gfp_mask())) == NULL)
+ return NULL;
+
+ bse_init(e);
+
+/* Get a pair of block numbers */
+/* Audited by: green(2002.06.11) */
-+static inline struct blocknr_pair *bse_get_pair(blocknr_set_entry * bse,
-+ unsigned pno)
++static inline blocknr_pair *bse_get_pair(blocknr_set_entry * bse, unsigned pno)
+{
+ assert("green-1", BLOCKNR_SET_ENTRIES_NUMBER >= 2 * (pno + 1));
+
-+ return (struct blocknr_pair *) (bse->entries +
-+ BLOCKNR_SET_ENTRIES_NUMBER -
-+ 2 * (pno + 1));
++ return (blocknr_pair *) (bse->entries + BLOCKNR_SET_ENTRIES_NUMBER -
++ 2 * (pno + 1));
+}
+
+/* Add a pair of block numbers to a blocknr_set_entry */
+bse_put_pair(blocknr_set_entry * bse, const reiser4_block_nr * a,
+ const reiser4_block_nr * b)
+{
-+ struct blocknr_pair *pair;
++ blocknr_pair *pair;
+
+ assert("jmacd-5100", bse_avail(bse) >= 2 && a != NULL && b != NULL);
+
+ 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, struct list_head *bset,
++static int blocknr_set_add(txn_atom *atom, blocknr_set *bset,
+ blocknr_set_entry **new_bsep, const reiser4_block_nr *a,
+ const reiser4_block_nr *b)
+{
+ assert("jmacd-5101", a != NULL);
+
+ entries_needed = (b == NULL) ? 1 : 2;
-+ if (list_empty(bset) ||
-+ bse_avail(list_entry(bset->next, blocknr_set_entry, link)) < entries_needed) {
++ if (list_empty(&bset->entries) ||
++ bse_avail(list_entry(bset->entries.next, blocknr_set_entry, link)) < entries_needed) {
+ /* See if a bse was previously allocated. */
+ if (*new_bsep == NULL) {
+ spin_unlock_atom(atom);
+ }
+
+ /* Put it on the head of the list. */
-+ list_add(&((*new_bsep)->link), bset);
++ list_add(&((*new_bsep)->link), &bset->entries);
+
+ *new_bsep = NULL;
+ }
+
+ /* Add the single or pair. */
-+ bse = list_entry(bset->next, blocknr_set_entry, link);
++ bse = list_entry(bset->entries.next, blocknr_set_entry, link);
+ if (b == NULL) {
+ bse_put_single(bse, a);
+ } else {
+ properly freed. */
+int
+blocknr_set_add_extent(txn_atom * atom,
-+ struct list_head * bset,
++ blocknr_set * bset,
+ blocknr_set_entry ** new_bsep,
+ const reiser4_block_nr * start,
+ const reiser4_block_nr * len)
+ properly freed. */
+int
+blocknr_set_add_pair(txn_atom * atom,
-+ struct list_head * bset,
++ blocknr_set * bset,
+ blocknr_set_entry ** new_bsep, const reiser4_block_nr * a,
+ const reiser4_block_nr * b)
+{
+}
+
+/* Initialize a blocknr_set. */
-+void blocknr_set_init(struct list_head *bset)
++void blocknr_set_init(blocknr_set *bset)
+{
-+ INIT_LIST_HEAD(bset);
++ INIT_LIST_HEAD(&bset->entries);
+}
+
+/* Release the entries of a blocknr_set. */
-+void blocknr_set_destroy(struct list_head *bset)
++void blocknr_set_destroy(blocknr_set *bset)
+{
+ blocknr_set_entry *bse;
+
-+ while (!list_empty(bset)) {
-+ bse = list_entry(bset->next, blocknr_set_entry, link);
++ while (!list_empty_careful(&bset->entries)) {
++ bse = list_entry(bset->entries.next, blocknr_set_entry, link);
+ list_del_init(&bse->link);
+ bse_free(bse);
+ }
+ 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(struct list_head * from, struct list_head * into)
++void blocknr_set_merge(blocknr_set * from, blocknr_set * into)
+{
+ blocknr_set_entry *bse_into = NULL;
+
+ /* If @from is empty, no work to perform. */
-+ if (list_empty(from))
++ if (list_empty_careful(&from->entries)) {
+ return;
++ }
++
+ /* If @into is not empty, try merging partial-entries. */
-+ if (!list_empty(into)) {
++ if (!list_empty_careful(&into->entries)) {
+
+ /* 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->next, blocknr_set_entry, link);
++ bse_into = list_entry(into->entries.next, blocknr_set_entry, link);
+ list_del_init(&bse_into->link);
-+ bse_from = list_entry(from->next, blocknr_set_entry, link);
++ bse_from = list_entry(from->entries.next, blocknr_set_entry, link);
+ list_del_init(&bse_from->link);
+
+ /* Combine singles. */
+ /* Combine pairs. */
+ for (; into_avail > 1 && bse_from->nr_pairs != 0;
+ into_avail -= 2) {
-+ struct blocknr_pair *pair =
-+ bse_get_pair(bse_from, --bse_from->nr_pairs);
++ blocknr_pair *pair =
++ bse_get_pair(bse_from, --bse_from->nr_pairs);
+ bse_put_pair(bse_into, &pair->a, &pair->b);
+ }
+
+ 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);
++ list_add(&bse_into->link, &into->entries);
+ bse_into = bse_from;
+ }
+ }
+
+ /* Splice lists together. */
-+ list_splice_init(from, into->prev);
++ list_splice_init(&from->entries, into->entries.prev);
+
+ /* Add the partial entry back to the head of the list. */
-+ if (bse_into != NULL)
-+ list_add(&bse_into->link, into);
++ if (bse_into != NULL) {
++ list_add(&bse_into->link, &into->entries);
++ }
+}
+
+/* Iterate over all blocknr set elements. */
-+int blocknr_set_iterator(txn_atom *atom, struct list_head *bset,
++int blocknr_set_iterator(txn_atom *atom, blocknr_set *bset,
+ blocknr_set_actor_f actor, void *data, int delete)
+{
+
+ assert("zam-431", bset != 0);
+ assert("zam-432", actor != NULL);
+
-+ entry = list_entry(bset->next, blocknr_set_entry, link);
-+ while (bset != &entry->link) {
++ entry = list_entry(bset->entries.next, blocknr_set_entry, link);
++ while (&bset->entries != &entry->link) {
+ blocknr_set_entry *tmp = list_entry(entry->link.next, blocknr_set_entry, link);
+ unsigned int i;
+ int ret;
+ * scroll-step: 1
+ * End:
+ */
-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 @@
+Index: linux-2.6.16/fs/reiser4/carry.c
+===================================================================
+--- /dev/null
++++ linux-2.6.16/fs/reiser4/carry.c
+@@ -0,0 +1,1381 @@
+/* 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
+ // COP_UPDATE --- update delimiting key in least
+ // common ancestor of two
+
-+ op = reiser4_post_carry( &lowest_level, operation, node, 0 );
++ op = post_carry( &lowest_level, operation, node, 0 );
+ if( IS_ERR( op ) || ( op == NULL ) ) {
+ handle error
+ } else {
+
+ ....
+
-+ // note, that last argument to reiser4_post_carry() is non-null
++ // note, that last argument to 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.
+
+ 2. whole balancing logic is implemented here, in particular, insertion
+ logic is coded in make_space().
+
-+ 3. special cases like insertion (reiser4_add_tree_root()) or deletion
-+ (reiser4_kill_tree_root()) of tree root and morphing of paste into insert
++ 3. special cases like insertion (add_tree_root()) or deletion
++ (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
+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
+ For usage, see comment at the top of fs/reiser4/carry.c
+
+*/
-+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 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 */
+ init_carry_level(todo, doing->pool);
+
+ /* give other threads chance to run */
-+ reiser4_preempt_point();
++ preempt_point();
+ }
+ done_carry_level(done);
+
+ for_all_nodes(doing, scan, tmp_scan) {
+ znode *node;
+
-+ node = reiser4_carry_real(scan);
++ node = carry_real(scan);
+ assert("nikita-2547", node != NULL);
+ if (node_is_empty(node)) {
+ result =
+ caller to guarantee proper ordering of node queue.
+
+*/
-+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 *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;
+ result = add_op(level, POOLO_LAST, NULL);
+ if (IS_ERR(result))
+ return result;
-+ child = reiser4_add_carry(level, POOLO_LAST, NULL);
++ child = add_carry(level, POOLO_LAST, NULL);
+ if (IS_ERR(child)) {
+ reiser4_pool_free(&level->pool->op_pool, &result->header);
+ return (carry_op *) child;
+ carry_pool *pool;
+
+ assert("", size >= sizeof(carry_pool) + 3 * sizeof(carry_level));
-+ pool = kmalloc(size, reiser4_ctx_gfp_mask_get());
++ pool = kmalloc(size, get_gfp_mask());
+ if (pool == NULL)
+ return ERR_PTR(RETERR(-ENOMEM));
+
+ automatically. To control ordering use @order and @reference parameters.
+
+*/
-+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 */)
++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 */ )
+{
+ ON_DEBUG(carry_node * orig_ref = reference);
+
+ }
+ assert("nikita-2209",
+ ergo(orig_ref != NULL,
-+ reiser4_carry_real(reference) ==
-+ reiser4_carry_real(orig_ref)));
-+ return reiser4_add_carry(level, order, reference);
++ carry_real(reference) == carry_real(orig_ref)));
++ return add_carry(level, order, reference);
+}
+
-+carry_node *reiser4_add_carry(carry_level * level /* &carry_level to add node
++carry_node *add_carry(carry_level * level /* &carry_level to add node
+ * to */ ,
+ pool_ordering order /* where to insert: at the
+ * beginning of @level, before
+ carry_node *result;
+
+ result =
-+ (carry_node *) reiser4_add_obj(&level->pool->node_pool,
-+ &level->nodes,
-+ order, &reference->header);
++ (carry_node *) add_obj(&level->pool->node_pool, &level->nodes,
++ order, &reference->header);
+ if (!IS_ERR(result) && (result != NULL))
+ ++level->nodes_num;
+ return result;
+ carry_op *result;
+
+ result =
-+ (carry_op *) reiser4_add_obj(&level->pool->op_pool, &level->ops,
-+ order, &reference->header);
++ (carry_op *) add_obj(&level->pool->op_pool, &level->ops, order,
++ &reference->header);
+ if (!IS_ERR(result) && (result != NULL))
+ ++level->ops_num;
+ return result;
+ assert("nikita-1614", node != NULL);
+ assert("nikita-1615", kin != NULL);
+ assert("nikita-1616", LOCK_CNT_GTZ(rw_locked_tree));
-+ assert("nikita-1619", ergo(reiser4_carry_real(node) != NULL,
-+ ZF_ISSET(reiser4_carry_real(node),
-+ JNODE_ORPHAN)));
++ assert("nikita-1619", ergo(carry_real(node) != NULL,
++ ZF_ISSET(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", reiser4_carry_real(scan) != NULL);
++ assert("nikita-1618", carry_real(scan) != NULL);
+ break;
+ }
+ }
+ assert("nikita-2203", node != NULL);
+
+ for_all_nodes(level, scan, tmp_scan) {
-+ if (reiser4_carry_real(scan) == node)
++ if (carry_real(scan) == node)
+ return scan;
+ }
+ return NULL;
+}
+
-+znode *reiser4_carry_real(const carry_node * node)
++znode *carry_real(const carry_node * node)
+{
+ assert("nikita-3061", node != NULL);
+
+ reference = insert_carry_node(doing, todo, node);
+ assert("nikita-2997", reference != NULL);
+
-+ return reiser4_add_carry(todo, POOLO_BEFORE, reference);
++ return add_carry(todo, POOLO_BEFORE, reference);
+}
+
-+/* 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. */
++/* 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. */
+carry_op *node_post_carry(carry_plugin_info * info /* carry parameters
+ * passed down to node
+ * plugin */ ,
+ assert("nikita-2208", info->todo != NULL);
+
+ if (info->doing == NULL)
-+ return reiser4_post_carry(info->todo, op, node,
-+ apply_to_parent_p);
++ return post_carry(info->todo, op, node, apply_to_parent_p);
+
+ result = add_op(info->todo, POOLO_LAST, NULL);
+ if (IS_ERR(result))
+ spot = NULL;
+ /* update delimiting keys */
+ for_all_nodes(level, node, tmp_node) {
-+ if (reiser4_carry_real(node) != spot) {
-+ spot = reiser4_carry_real(node);
++ if (carry_real(node) != spot) {
++ spot = carry_real(node);
+ sync_dkeys(spot);
+ }
+ }
+ 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(reiser4_carry_real(node),
-+ JNODE_ORPHAN)));
-+ ON_DEBUG(check_dkeys(reiser4_carry_real(node)));
++ assert("nikita-1631", ergo(!failure, !ZF_ISSET(carry_real(node),
++ JNODE_ORPHAN)));
++ ON_DEBUG(check_dkeys(carry_real(node)));
+ unlock_carry_node(level, node, failure);
+ }
+ level->new_root = NULL;
+int lock_carry_node_tail(carry_node * node /* node to complete locking of */ )
+{
+ assert("nikita-1052", node != NULL);
-+ assert("nikita-1187", reiser4_carry_real(node) != NULL);
++ assert("nikita-1187", carry_real(node) != NULL);
+ assert("nikita-1188", !node->unlock);
+
+ node->unlock = 1;
+
+ Corresponding zrelse() is in unlock_carry_node()
+ */
-+ return zload(reiser4_carry_real(node));
++ return zload(carry_real(node));
+}
+
+/* lock carry node
+
+ assert("nikita-884", node != NULL);
+
-+ real_node = reiser4_carry_real(node);
++ real_node = carry_real(node);
+ /* pair to zload() in lock_carry_node_tail() */
+ zrelse(real_node);
+ if (node->unlock && (real_node != NULL)) {
+
+ 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 reiser4_add_tree_root().
++ sibling pointers to the add_tree_root().
+
+ Locking: old tree root is locked by carry at this point. Fake znode is also
+ locked.
+ tree root right now.
+ */
+ if (level->new_root == NULL)
-+ level->new_root = reiser4_add_tree_root(node->node, fake);
++ level->new_root = add_tree_root(node->node, fake);
+ if (!IS_ERR(level->new_root)) {
+ assert("nikita-1210", znode_is_root(level->new_root));
+ node->deallocate = 1;
+ 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 reiser4_new_node() to allocate new
++ This is carry related routing that calls new_node() to allocate new
+ node.
+*/
+carry_node *add_new_znode(znode * brother /* existing left neighbor of new
+
+ */
+
-+ fresh = reiser4_add_carry_skip(doing,
-+ ref ? POOLO_AFTER : POOLO_LAST, ref);
++ fresh = add_carry_skip(doing, ref ? POOLO_AFTER : POOLO_LAST, ref);
+ if (IS_ERR(fresh))
+ return fresh;
+
+ fresh->deallocate = 1;
+ fresh->free = 1;
+
-+ new_znode = reiser4_new_node(brother, znode_get_level(brother));
++ new_znode = new_node(brother, znode_get_level(brother));
+ if (IS_ERR(new_znode))
+ /* @fresh will be deallocated automatically by error
+ handling code in the caller. */
+ ZF_SET(new_znode, JNODE_ORPHAN);
+ fresh->node = new_znode;
+
-+ while (ZF_ISSET(reiser4_carry_real(ref), JNODE_ORPHAN)) {
++ while (ZF_ISSET(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,
-+ reiser4_carry_real(ref), 1);
++ add_pointer = node_post_carry(&info, COP_INSERT, carry_real(ref), 1);
+ if (IS_ERR(add_pointer)) {
+ /* no need to deallocate @new_znode here: it will be
+ deallocated during carry error handling. */
+ right = node->node;
+ left = carry_node_prev(node)->node;
+ } else {
-+ right = reiser4_carry_real(node);
-+ left = reiser4_carry_real(carry_node_prev(node));
++ right = carry_real(node);
++ left = carry_real(carry_node_prev(node));
+ }
+ if (right == NULL || left == NULL)
+ continue;
+ case COP_PASTE:
+ print_coord("\tcoord",
+ op->u.insert.d ? op->u.insert.d->coord : NULL, 0);
-+ reiser4_print_key("\tkey",
-+ op->u.insert.d ? op->u.insert.d->key : NULL);
++ print_key("\tkey", op->u.insert.d ? op->u.insert.d->key : NULL);
+ print_carry("\tchild", op->u.insert.child);
+ break;
+ case COP_DELETE:
+ scroll-step: 1
+ End:
+*/
-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
+Index: linux-2.6.16/fs/reiser4/carry.h
+===================================================================
+--- /dev/null
++++ linux-2.6.16/fs/reiser4/carry.h
@@ -0,0 +1,442 @@
+/* Copyright 2001, 2002, 2003 by Hans Reiser, licensing governed by reiser4/README */
+
+*/
+typedef struct carry_node {
+ /* pool linkage */
-+ struct reiser4_pool_header header;
++ reiser4_pool_header header;
+
+ /* base node from which real_node is calculated. See
+ fs/reiser4/carry.c:lock_carry_node(). */
+*/
+typedef struct carry_op {
+ /* pool linkage */
-+ struct reiser4_pool_header header;
++ reiser4_pool_header header;
+ carry_opcode op;
+ /* node on which operation is to be performed:
+
+/* &carry_op_pool - preallocated pool of carry operations, and nodes */
+typedef struct carry_pool {
+ carry_op op[CARRIES_POOL_SIZE];
-+ struct reiser4_pool op_pool;
++ reiser4_pool op_pool;
+ carry_node node[NODES_LOCKED_POOL_SIZE];
-+ struct reiser4_pool node_pool;
++ reiser4_pool node_pool;
+} carry_pool;
+
+/* &carry_tree_level - carry process on given level
+ int nodes_num;
+ /* new root created on this level, if any */
+ znode *new_root;
-+ /* This is set by caller (insert_by_key(), rreiser4_esize_item(), etc.)
-+ when they want ->tracked to automagically wander to the node where
++ /* This is set by caller (insert_by_key(), resize_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;
+ carry_level *todo;
+};
+
-+int reiser4_carry(carry_level * doing, carry_level * done);
++int carry(carry_level * doing, carry_level * done);
+
-+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);
++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);
+
+extern carry_node *insert_carry_node(carry_level * doing,
+ carry_level * todo, const znode * node);
+
+extern void init_carry_level(carry_level * level, carry_pool * pool);
+
-+extern carry_op *reiser4_post_carry(carry_level * level, carry_opcode op,
-+ znode * node, int apply_to_parent);
++extern carry_op *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);
+
+
+carry_node *find_carry_node(carry_level * level, const znode * node);
+
-+extern znode *reiser4_carry_real(const carry_node * node);
++extern znode *carry_real(const carry_node * node);
+
+/* helper macros to iterate over carry queues */
+
+ scroll-step: 1
+ End:
+*/
-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 @@
+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 @@
+/* Copyright 2001, 2002, 2003 by Hans Reiser, licensing governed by reiser4/README */
+
+/* implementation of carry operations */
+ tree = current_tree;
+ read_lock_tree(tree);
+ /* first, check whether left neighbor is already in a @doing queue */
-+ if (reiser4_carry_real(node)->left != NULL) {
++ if (carry_real(node)->left != NULL) {
+ /* NOTE: there is locking subtlety here. Look into
+ * find_right_neighbor() for more info */
-+ if (find_carry_node(doing,
-+ reiser4_carry_real(node)->left) != NULL) {
++ if (find_carry_node(doing, carry_real(node)->left) != NULL) {
+ read_unlock_tree(tree);
+ left = node;
+ do {
+ carry_node, header.level_linkage);
+ assert("nikita-3408", !carry_node_end(doing,
+ left));
-+ } while (reiser4_carry_real(left) ==
-+ reiser4_carry_real(node));
++ } while (carry_real(left) == carry_real(node));
+ return left;
+ }
+ }
+ read_unlock_tree(tree);
+
-+ left = reiser4_add_carry_skip(doing, POOLO_BEFORE, node);
++ left = add_carry_skip(doing, POOLO_BEFORE, node);
+ if (IS_ERR(left))
+ return left;
+
+ flags |= GN_NO_ALLOC;
+
+ /* then, feeling lucky, peek left neighbor in the cache. */
-+ result = reiser4_get_left_neighbor(&left->lock_handle,
-+ reiser4_carry_real(node),
++ result = reiser4_get_left_neighbor(&left->lock_handle, carry_real(node),
+ ZNODE_WRITE_LOCK, flags);
+ if (result == 0) {
+ /* ok, node found and locked. */
+ tree = current_tree;
+ read_lock_tree(tree);
+ /* first, check whether right neighbor is already in a @doing queue */
-+ if (reiser4_carry_real(node)->right != NULL) {
++ if (carry_real(node)->right != NULL) {
+ /*
+ * Tree lock is taken here anyway, because, even if _outcome_
+ * of (find_carry_node() != NULL) doesn't depends on
+ * couldn't change, because node cannot be inserted between
+ * locked neighbors.
+ */
-+ if (find_carry_node(doing,
-+ reiser4_carry_real(node)->right) != NULL) {
++ if (find_carry_node(doing, carry_real(node)->right) != NULL) {
+ read_unlock_tree(tree);
+ /*
+ * What we are doing here (this is also applicable to
+ carry_node, header.level_linkage);
+ assert("nikita-3408", !carry_node_end(doing,
+ right));
-+ } while (reiser4_carry_real(right) ==
-+ reiser4_carry_real(node));
++ } while (carry_real(right) == carry_real(node));
+ return right;
+ }
+ }
+
+ /* then, try to lock right neighbor */
+ init_lh(&lh);
-+ result = reiser4_get_right_neighbor(&lh,
-+ reiser4_carry_real(node),
++ result = reiser4_get_right_neighbor(&lh, carry_real(node),
+ ZNODE_WRITE_LOCK, flags);
+ if (result == 0) {
+ /* ok, node found and locked. */
-+ right = reiser4_add_carry_skip(doing, POOLO_AFTER, node);
++ right = add_carry_skip(doing, POOLO_AFTER, node);
+ if (!IS_ERR(right)) {
+ right->node = lh.node;
+ move_lh(&right->lock_handle, &lh);
+ assert("nikita-941", op != NULL);
+ assert("nikita-942", op->op == COP_INSERT);
+
-+ node = reiser4_carry_real(op->node);
++ node = carry_real(op->node);
+ assert("nikita-943", node != NULL);
+ assert("nikita-944", node_plugin_by_node(node) != NULL);
+
-+ child = reiser4_carry_real(op->u.insert.child);
++ child = carry_real(op->u.insert.child);
+ result =
+ find_new_child_ptr(node, child, op->u.insert.brother,
+ op->u.insert.d->coord);
+ 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 != reiser4_carry_real(op->node)) {
++ if (insertion_node != carry_real(op->node)) {
+ op->node = target;
-+ assert("nikita-2540",
-+ reiser4_carry_real(target) == insertion_node);
++ assert("nikita-2540", carry_real(target) == insertion_node);
+ }
+ assert("nikita-2541",
-+ reiser4_carry_real(op->node) == op->u.insert.d->coord->node);
++ carry_real(op->node) == op->u.insert.d->coord->node);
+ return insertion_node;
+}
+
+ op->op == COP_INSERT ||
+ op->op == COP_PASTE || op->op == COP_EXTENT);
+ assert("nikita-1607",
-+ reiser4_carry_real(op->node) == op->u.insert.d->coord->node);
++ carry_real(op->node) == op->u.insert.d->coord->node);
+
+ flags = op->u.insert.flags;
+
+ /* shift everything possible on the left of and
+ including insertion coord into the left neighbor */
+ result = carry_shift_data(LEFT_SIDE, coord,
-+ reiser4_carry_real(left),
-+ doing, todo,
++ carry_real(left), doing, todo,
+ flags & COPI_GO_LEFT);
+
+ /* reget node from coord: shift_left() might move
+ excluding insertion coord into the right neighbor
+ */
+ result = carry_shift_data(RIGHT_SIDE, coord,
-+ reiser4_carry_real(right),
++ carry_real(right),
+ doing, todo,
+ flags & COPI_GO_RIGHT);
+ /* reget node from coord: shift_right() might move
+
+ /* Try to shift into new node. */
+ result = lock_carry_node(doing, fresh);
-+ zput(reiser4_carry_real(fresh));
++ zput(carry_real(fresh));
+ if (result != 0) {
+ warning("nikita-947",
+ "Cannot lock new node: %i", result);
+ (blk_alloc > 0) ||
+ coord_is_after_rightmost(op->u.insert.d->coord);
+
-+ 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),
++ result = carry_shift_data(RIGHT_SIDE, coord, carry_real(fresh),
+ doing, todo, gointo);
+ /* if insertion point was actually moved into new node,
+ update carry node pointer in operation. */
+ result = -E_NODE_FULL;
+ }
+ assert("nikita-1622", ergo(result == 0,
-+ reiser4_carry_real(op->node) == coord->node));
++ 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);
+ /* NOTE-NIKITA Lookup bias is fixed to FIND_EXACT. Complain
+ if you need something else. */
+ op->u.insert.d->coord = coord;
-+ node = reiser4_carry_real(op->node);
++ node = 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);
+ op->u.insert.d = cdata;
+ op->u.insert.d->coord = coord;
+ op->u.insert.d->data = data;
-+ op->u.insert.d->coord->node = reiser4_carry_real(op->node);
++ op->u.insert.d->coord->node = carry_real(op->node);
+ result = find_new_child_coord(op);
-+ child = reiser4_carry_real(op->u.insert.child);
++ child = carry_real(op->u.insert.child);
+ if (result != NS_NOT_FOUND) {
+ warning("nikita-993",
+ "Cannot find a place for child pointer: %i",
+ moved into another node. Handle this by creating new carry
+ node for insertion point if necessary.
+ */
-+ if (reiser4_carry_real(op->node) !=
-+ op->u.insert.d->coord->node) {
++ if (carry_real(op->node) != op->u.insert.d->coord->node) {
+ pool_ordering direction;
+ znode *z1;
+ znode *z2;
+ * moved. Do this by comparing delimiting keys.
+ */
+ z1 = op->u.insert.d->coord->node;
-+ z2 = reiser4_carry_real(op->node);
++ z2 = carry_real(op->node);
+ if (keyle(leftmost_key_in_node(z1, &k1),
+ leftmost_key_in_node(z2, &k2)))
+ /* insertion point moved to the left */
+ /* insertion point moved to the right */
+ direction = POOLO_AFTER;
+
-+ op->node = reiser4_add_carry_skip(doing,
-+ direction, op->node);
++ op->node = 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;
+ 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 = reiser4_carry_real(op->node);
++ op->u.insert.d->coord->node = carry_real(op->node);
+ }
+
+ /* find free space. */
+ 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),
-+ reiser4_carry_real(left), doing, todo,
-+ 1 /* including insert point */);
-+ if (reiser4_carry_real(left) != flow_insert_point(op)->node) {
++ 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) {
+ /* insertion point did not move */
+ return 1;
+ }
+ 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),
-+ reiser4_carry_real(right), doing, todo,
-+ 0 /* not including insert point */);
++ carry_shift_data(RIGHT_SIDE, flow_insert_point(op), carry_real(right), doing, todo, 0 /* not
++ * including
++ * insert
++ * point */ );
+ } else {
+ /* right neighbor either does not exist or is unformatted
+ node */
+ return PTR_ERR(new);
+ }
+ result = lock_carry_node(doing, new);
-+ zput(reiser4_carry_real(new));
++ zput(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),
-+ reiser4_carry_real(new), doing, todo,
-+ 0 /* not including insert point */);
++ carry_shift_data(RIGHT_SIDE, flow_insert_point(op), carry_real(new), doing, todo, 0 /* not
++ * including
++ * insert
++ * point */ );
++
+ assert("vs-901",
+ coord_is_after_rightmost(flow_insert_point(op)));
+
+ return PTR_ERR(new);
+ }
+ result = lock_carry_node(doing, new);
-+ zput(reiser4_carry_real(new));
++ zput(carry_real(new));
+ if (unlikely(result)) {
+ return result;
+ }
+ }
+
+ /* move insertion point to new node */
-+ coord_init_before_first_item(flow_insert_point(op),
-+ reiser4_carry_real(new));
++ coord_init_before_first_item(flow_insert_point(op), carry_real(new));
+ op->node = new;
+ return 0;
+}
+ coord_init_zero(&coord);
+ coord_init_zero(&coord2);
+
-+ parent = reiser4_carry_real(op->node);
++ parent = carry_real(op->node);
+ child = op->u.delete.child ?
-+ reiser4_carry_real(op->u.delete.child) : op->node->node;
++ carry_real(op->u.delete.child) : op->node->node;
+ tree = znode_get_tree(child);
+ read_lock_tree(tree);
+
+ node_num_items(parent) == 1) {
+ /* Delimiting key manipulations. */
+ write_lock_dk(tree);
-+ 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()));
++ znode_set_ld_key(child, znode_set_ld_key(parent, min_key()));
++ znode_set_rd_key(child, znode_set_rd_key(parent, max_key()));
+ ZF_SET(child, JNODE_DKSET);
+ write_unlock_dk(tree);
+
+ /* don't kill roots at and lower than twig level */
+ znode_get_level(parent) > REISER4_MIN_TREE_HEIGHT &&
+ node_num_items(parent) == 1) {
-+ result = reiser4_kill_tree_root(coord.node);
++ result = kill_tree_root(coord.node);
+ }
+
+ return result < 0 ? : 0;
+ info.doing = doing;
+ info.todo = todo;
+
-+ nplug = node_plugin_by_node(reiser4_carry_real(op->node));
++ nplug = node_plugin_by_node(carry_real(op->node));
+ if (op->u.cut_or_kill.is_cut)
+ result = nplug->cut(op->u.cut_or_kill.u.cut, &info);
+ else
+ if (lchild != NULL) {
+ assert("nikita-1001", lchild->parent);
+ assert("nikita-1003", !lchild->left);
-+ left = reiser4_carry_real(lchild);
++ left = carry_real(lchild);
+ } else
+ left = NULL;
+
+ if (carry_node_end(level, neighbor))
+ /* list head is reached */
+ return NULL;
-+ if (reiser4_carry_real(neighbor) != reiser4_carry_real(node))
++ if (carry_real(neighbor) != carry_real(node))
+ return neighbor;
+ }
+}
+ scroll-step: 1
+ End:
+*/
-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
+Index: linux-2.6.16/fs/reiser4/carry_ops.h
+===================================================================
+--- /dev/null
++++ linux-2.6.16/fs/reiser4/carry_ops.h
@@ -0,0 +1,42 @@
+/* Copyright 2001, 2002, 2003 by Hans Reiser, licensing governed by reiser4/README */
+
+ scroll-step: 1
+ End:
+*/
-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 @@
+Index: linux-2.6.16/fs/reiser4/context.c
+===================================================================
+--- /dev/null
++++ linux-2.6.16/fs/reiser4/context.c
+@@ -0,0 +1,278 @@
+/* Copyright 2002, 2003 by Hans Reiser, licensing governed by reiser4/README */
+
+/* Manipulation of reiser4_context */
+ *
+ * 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, reiser4_init_context()/reiser4_done_context() have to be properly
-+ * nested any way.
++ * always returns top level context. Of course, init_context()/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
+#include <linux/writeback.h> /* balance_dirty_pages() */
+#include <linux/hardirq.h>
+
-+static void _reiser4_init_context(reiser4_context * context,
-+ struct super_block *super)
++
++static void _init_context(reiser4_context * context, struct super_block *super)
+{
+ memset(context, 0, sizeof(*context));
+
+
+ init_lock_stack(&context->stack);
+
-+ reiser4_txn_begin(context);
++ txn_begin(context);
+
+ /* initialize head of tap list */
+ INIT_LIST_HEAD(&context->taps);
+ This function should be called at the beginning of reiser4 part of
+ syscall.
+*/
-+reiser4_context * reiser4_init_context(struct super_block * super)
++reiser4_context *init_context(struct super_block *super /* super block we are going to
++ * work with */ )
+{
+ reiser4_context *context;
+
+ if (context == NULL)
+ return ERR_PTR(RETERR(-ENOMEM));
+
-+ _reiser4_init_context(context, super);
++ _init_context(context, super);
+ return context;
+}
+
+ assert("nikita-3358", super->s_op == NULL || is_reiser4_super(super));
+ assert("vs-12", !is_in_reiser4_context());
+
-+ _reiser4_init_context(context, super);
++ _init_context(context, super);
+ context->on_stack = 1;
+ return;
+}
+ thread released all locks and closed transcrash etc.
+
+*/
-+static void reiser4_done_context(reiser4_context * context /* context being released */ )
++static void done_context(reiser4_context * context /* context being released */ )
+{
+ assert("nikita-860", context != NULL);
+ assert("nikita-859", context->magic == context_magic);
+ if (context->nr_children == 0) {
+ assert("jmacd-673", context->trans == NULL);
+ assert("jmacd-1002", lock_stack_isclean(&context->stack));
-+ assert("nikita-1936", reiser4_no_counters_are_held());
-+ assert("nikita-2626", list_empty_careful(reiser4_taps_list()));
++ assert("nikita-1936", no_counters_are_held());
++ assert("nikita-2626", list_empty_careful(taps_list()));
+ assert("zam-1004", ergo(get_super_private(context->super),
-+ get_super_private(context->super)->delete_mutex_owner !=
++ get_super_private(context->super)->delete_sema_owner !=
+ current));
+
+ /* release all grabbed but as yet unused blocks */
+ */
+void reiser4_exit_context(reiser4_context * context)
+{
-+ assert("nikita-3021", reiser4_schedulable());
++ assert("nikita-3021", schedulable());
+
+ if (context->nr_children == 0) {
+ if (!context->nobalance) {
-+ reiser4_txn_restart(context);
++ txn_restart(context);
+ balance_dirty_pages_at(context);
+ }
+
+ spin_unlock_atom(atom);
+ }
+ }
-+ reiser4_txn_end(context);
++ txn_end(context);
+ }
-+ reiser4_done_context(context);
++ done_context(context);
+}
+
-+void reiser4_ctx_gfp_mask_set(void)
++void set_gfp_mask(void)
+{
+ reiser4_context *ctx;
+
+ 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"
+ * scroll-step: 1
+ * End:
+ */
-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
+Index: linux-2.6.16/fs/reiser4/context.h
+===================================================================
+--- /dev/null
++++ linux-2.6.16/fs/reiser4/context.h
@@ -0,0 +1,228 @@
+/* Copyright 2001, 2002, 2003, 2004 by Hans Reiser, licensing governed by
+ * reiser4/README */
+#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. */
+ * ->i_mutex */
+ unsigned int nobalance:1;
+
-+ /* this bit is used on reiser4_done_context to decide whether context is
++ /* this bit is used on done_context to decide whether context is
+ kmalloc-ed and has to be kfree-ed */
+ unsigned int on_stack:1;
+
+#if REISER4_DEBUG
+ /* debugging information about reiser4 locks held by the current
+ * thread */
-+ reiser4_lock_cnt_info locks;
++ lock_counters_info locks;
+ struct task_struct *task; /* so we can easily find owner of the stack */
+
+ /*
+#define current_blocksize reiser4_get_current_sb()->s_blocksize
+#define current_blocksize_bits reiser4_get_current_sb()->s_blocksize_bits
+
-+extern reiser4_context *reiser4_init_context(struct super_block *);
++extern reiser4_context *init_context(struct super_block *);
+extern void init_stack_context(reiser4_context *, struct super_block *);
+extern void reiser4_exit_context(reiser4_context *);
+
+ return get_context(current);
+}
+
-+static inline gfp_t reiser4_ctx_gfp_mask_get(void)
++static inline gfp_t get_gfp_mask(void)
+{
+ reiser4_context *ctx;
+
+ return (ctx == NULL) ? GFP_KERNEL : ctx->gfp_mask;
+}
+
-+void reiser4_ctx_gfp_mask_set(void);
-+void reiser4_ctx_gfp_mask_force (gfp_t mask);
++void set_gfp_mask(void);
+
+/*
+ * true if current thread is in the write-out mode. Thread enters write-out
+ scroll-step: 1
+ End:
+*/
-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 @@
+Index: linux-2.6.16/fs/reiser4/coord.c
+===================================================================
+--- /dev/null
++++ linux-2.6.16/fs/reiser4/coord.c
+@@ -0,0 +1,937 @@
+/* Copyright 2001, 2002, 2003 by Hans Reiser, licensing governed by reiser4/README */
+
+#include "forward.h"
+}
+
+#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);
+ 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. */
+ 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)
+ 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. */
+ scroll-step: 1
+ End:
+*/
-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
+Index: linux-2.6.16/fs/reiser4/coord.h
+===================================================================
+--- /dev/null
++++ linux-2.6.16/fs/reiser4/coord.h
@@ -0,0 +1,389 @@
+/* Copyright 2001, 2002, 2003 by Hans Reiser, licensing governed by reiser4/README */
+
+ scroll-step: 1
+ End:
+*/
-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 @@
+Index: linux-2.6.16/fs/reiser4/debug.c
+===================================================================
+--- /dev/null
++++ linux-2.6.16/fs/reiser4/debug.c
+@@ -0,0 +1,300 @@
+/* Copyright 2001, 2002, 2003 by Hans Reiser, licensing governed by
+ * reiser4/README */
+
+ *
+ * panicking: reiser4_do_panic(), reiser4_print_prefix().
+ *
-+ * locking:
-+ * reiser4_schedulable(), reiser4_lock_counters(), print_lock_counters(),
-+ * reiser4_no_counters_are_held(), reiser4_commit_check_locks()
++ * locking: schedulable(), lock_counters(), print_lock_counters(),
++ * no_counters_are_held(), commit_check_locks()
+ *
-+ * error code monitoring (see comment before RETERR macro):
-+ * reiser4_return_err(), reiser4_report_err().
++ * error code monitoring (see comment before RETERR macro): return_err(),
++ * report_err().
+ *
+ * stack back-tracing: fill_backtrace()
+ *
-+ * miscellaneous: reiser4_preempt_point(), call_on_each_assert(),
-+ * reiser4_debugtrap().
++ * miscellaneous: preempt_point(), call_on_each_assert(), debugtrap().
+ *
+ */
+
+#include <linux/sysctl.h>
+#include <linux/hardirq.h>
+
-+#if 0
+#if REISER4_DEBUG
-+static void reiser4_report_err(void);
++static void report_err(void);
+#else
-+#define reiser4_report_err() noop
++#define report_err() noop
+#endif
-+#endif /* 0 */
+
+/*
+ * global buffer where message given to reiser4_panic is formatted.
+ 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)
+ printk("%sreiser4[%.16s(%i)]: %s (%s:%i)[%s]:\n",
+ level, comm, pid, function, file, lineno, mid);
+ if (reperr)
-+ reiser4_report_err();
++ report_err();
+}
-+#endif /* 0 */
+
+/* Preemption point: this should be called periodically during long running
+ operations (carry, allocate, and squeeze are best examples) */
-+int reiser4_preempt_point(void)
++int preempt_point(void)
+{
-+ assert("nikita-3008", reiser4_schedulable());
++ assert("nikita-3008", schedulable());
+ cond_resched();
+ return signal_pending(current);
+}
+ constraints and various assertions.
+
+*/
-+reiser4_lock_cnt_info *reiser4_lock_counters(void)
++lock_counters_info *lock_counters(void)
+{
+ reiser4_context *ctx = get_current_context();
+ assert("jmacd-1123", ctx != NULL);
+ * print human readable information about locks held by the reiser4 context.
+ */
+static void print_lock_counters(const char *prefix,
-+ const reiser4_lock_cnt_info * info)
++ const lock_counters_info * info)
+{
+ printk("%s: jnode: %i, tree: %i (r:%i,w:%i), dk: %i (r:%i,w:%i)\n"
+ "jload: %i, "
+}
+
+/* check that no spinlocks are held */
-+int reiser4_schedulable(void)
++int schedulable(void)
+{
+ if (get_current_context_check() != NULL) {
+ if (!LOCK_CNT_NIL(spin_locked)) {
-+ print_lock_counters("in atomic", reiser4_lock_counters());
++ print_lock_counters("in atomic", lock_counters());
+ return 0;
+ }
+ }
+/*
+ * return true, iff no locks are held.
+ */
-+int reiser4_no_counters_are_held(void)
++int no_counters_are_held(void)
+{
-+ reiser4_lock_cnt_info *counters;
++ lock_counters_info *counters;
+
-+ counters = reiser4_lock_counters();
++ counters = lock_counters();
+ return
+ (counters->spin_locked_zlock == 0) &&
+ (counters->spin_locked_jnode == 0) &&
+ * return true, iff transaction commit can be done under locks held by the
+ * current thread.
+ */
-+int reiser4_commit_check_locks(void)
++int commit_check_locks(void)
+{
-+ reiser4_lock_cnt_info *counters;
++ lock_counters_info *counters;
+ int inode_sem_r;
+ int inode_sem_w;
+ int result;
+ * held during commit.
+ */
+
-+ counters = reiser4_lock_counters();
++ counters = 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 = reiser4_no_counters_are_held();
++ result = no_counters_are_held();
+ counters->inode_sem_r = inode_sem_r;
+ counters->inode_sem_w = inode_sem_w;
+ return result;
+ * fill "error site" in the current reiser4 context. See comment before RETERR
+ * macro for more details.
+ */
-+void reiser4_return_err(int code, const char *file, int line)
++void return_err(int code, const char *file, int line)
+{
+ if (code < 0 && is_in_reiser4_context()) {
+ reiser4_context *ctx = get_current_context();
+ }
+}
+
-+#if 0
+/*
-+ * report error information recorder by reiser4_return_err().
++ * report error information recorder by return_err().
+ */
-+static void reiser4_report_err(void)
++static void report_err(void)
+{
+ reiser4_context *ctx = get_current_context_check();
+
+ }
+ }
+}
-+#endif /* 0 */
+
+#endif /* REISER4_DEBUG */
+
+ * this functions just drops into kernel debugger. It is a convenient place to
+ * put breakpoint in.
+ */
-+void reiser4_debugtrap(void)
++void debugtrap(void)
+{
+ /* do nothing. Put break point here. */
+#if defined(CONFIG_KGDB) && !defined(CONFIG_REISER4_FS_MODULE)
+ fill-column: 120
+ End:
+*/
-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
+Index: linux-2.6.16/fs/reiser4/debug.h
+===================================================================
+--- /dev/null
++++ linux-2.6.16/fs/reiser4/debug.h
@@ -0,0 +1,350 @@
+/* Copyright 2001, 2002, 2003 by Hans Reiser, licensing governed by reiser4/README */
+
+
+#define ON_DEBUG( exp ) exp
+
-+extern int reiser4_schedulable(void);
++extern int schedulable(void);
+extern void call_on_each_assert(void);
+
+#else
+#define assert( label, cond ) noop
+#define check_me( label, expr ) ( ( void ) ( expr ) )
+#define ON_DEBUG( exp )
-+#define reiser4_schedulable() might_sleep()
++#define schedulable() might_sleep()
+
+/* REISER4_DEBUG */
+#endif
+#if REISER4_DEBUG
+/* per-thread information about lock acquired by this thread. Used by lock
+ * ordering checking in spin_macros.h */
-+typedef struct reiser4_lock_cnt_info {
++typedef struct lock_counters_info {
+ int rw_locked_tree;
+ int read_locked_tree;
+ int write_locked_tree;
+ int d_refs;
+ int x_refs;
+ int t_refs;
-+} reiser4_lock_cnt_info;
++} lock_counters_info;
+
-+extern struct reiser4_lock_cnt_info *reiser4_lock_counters(void);
++extern lock_counters_info *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(++(reiser4_lock_counters()->counter), 0)
++#define LOCK_CNT_INC(counter) IN_CONTEXT(++(lock_counters()->counter), 0)
+
+/* decrement lock-counter @counter, if present */
-+#define LOCK_CNT_DEC(counter) \
-+ IN_CONTEXT(--(reiser4_lock_counters()->counter), 0)
++#define LOCK_CNT_DEC(counter) IN_CONTEXT(--(lock_counters()->counter), 0)
+
+/* check that lock-counter is zero. This is for use in assertions */
-+#define LOCK_CNT_NIL(counter) \
-+ IN_CONTEXT(reiser4_lock_counters()->counter == 0, 1)
++#define LOCK_CNT_NIL(counter) IN_CONTEXT(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(reiser4_lock_counters()->counter > 0, 1)
-+#define LOCK_CNT_LT(counter,n) \
-+ IN_CONTEXT(reiser4_lock_counters()->counter < n, 1)
++#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)
+
+#else /* REISER4_DEBUG */
+
+/* no-op versions on the above */
+
-+typedef struct reiser4_lock_cnt_info {
-+} reiser4_lock_cnt_info;
++typedef struct lock_counters_info {
++} lock_counters_info;
+
-+#define reiser4_lock_counters() ((reiser4_lock_cnt_info *)NULL)
++#define lock_counters() ((lock_counters_info *)NULL)
+#define LOCK_CNT_INC(counter) noop
+#define LOCK_CNT_DEC(counter) noop
+#define LOCK_CNT_NIL(counter) (1)
+extern void reiser4_do_panic(const char *format, ...)
+ __attribute__ ((noreturn, format(printf, 1, 2)));
+
-+extern int reiser4_preempt_point(void);
++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 void reiser4_print_stats(void);
+
++
+#if REISER4_DEBUG
-+extern int reiser4_no_counters_are_held(void);
-+extern int reiser4_commit_check_locks(void);
++extern int no_counters_are_held(void);
++extern int commit_check_locks(void);
+#else
-+#define reiser4_no_counters_are_held() (1)
-+#define reiser4_commit_check_locks() (1)
++#define no_counters_are_held() (1)
++#define commit_check_locks() (1)
+#endif
+
+/* true if @i is power-of-two. Useful for rate-limited warnings, etc. */
+
+#if KERNEL_DEBUGGER
+
-+extern void reiser4_debugtrap(void);
++extern void 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)) \
-+ reiser4_debugtrap(); \
++#define DEBUGON(cond) \
++({ \
++ if (unlikely(cond)) \
++ debugtrap(); \
+})
+#else
+#define DEBUGON(cond) noop
+ *
+ * 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 reiser4_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 return_err (low-level function called by RETERR()
++ * to do the actual work) to break into debugger immediately when particular
++ * error happens.
+ *
+ */
+
+ int line; /* source file line, filled by __LINE__ */
+} err_site;
+
-+extern void reiser4_return_err(int code, const char *file, int line);
++extern void 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); \
-+ reiser4_return_err(__code, __FILE__, __LINE__); \
-+ __code; \
++#define RETERR(code) \
++({ \
++ typeof(code) __code; \
++ \
++ __code = (code); \
++ return_err(__code, __FILE__, __LINE__); \
++ __code; \
+})
+
+#else
+ fill-column: 120
+ End:
+*/
-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 @@
+Index: linux-2.6.16/fs/reiser4/dformat.h
+===================================================================
+--- /dev/null
++++ linux-2.6.16/fs/reiser4/dformat.h
+@@ -0,0 +1,71 @@
+/* Copyright 2001, 2002, 2003 by Hans Reiser, licensing governed by reiser4/README */
+
+/* Formats of on-disk data and conversion functions. */
+#include <asm/unaligned.h>
+#include <linux/types.h>
+
++
+typedef __u8 d8;
+typedef __le16 d16;
+typedef __le32 d32;
+ * fill-column: 79
+ * End:
+ */
-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
+Index: linux-2.6.16/fs/reiser4/dscale.c
+===================================================================
+--- /dev/null
++++ linux-2.6.16/fs/reiser4/dscale.c
@@ -0,0 +1,174 @@
+/* Copyright 2001, 2002, 2003 by Hans Reiser, licensing governed by
+ * reiser4/README */
+ scroll-step: 1
+ End:
+*/
-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
+Index: linux-2.6.16/fs/reiser4/dscale.h
+===================================================================
+--- /dev/null
++++ linux-2.6.16/fs/reiser4/dscale.h
@@ -0,0 +1,27 @@
+/* Copyright 2001, 2002, 2003 by Hans Reiser, licensing governed by
+ * reiser4/README */
+ fill-column: 120
+ End:
+*/
-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 @@
+Index: linux-2.6.16/fs/reiser4/entd.c
+===================================================================
+--- /dev/null
++++ linux-2.6.16/fs/reiser4/entd.c
+@@ -0,0 +1,356 @@
+/* Copyright 2003, 2004 by Hans Reiser, licensing governed by
+ * reiser4/README */
+
+#include <linux/backing-dev.h> /* bdi_write_congested */
+#include <linux/wait.h>
+#include <linux/kthread.h>
-+#include <linux/freezer.h>
++
++#define LLONG_MAX ((long long)(~0ULL>>1))
+
+#define DEF_PRIORITY 12
+#define MAX_ENTD_ITERS 10
+ "ent:%s%s", super->s_id, (state))
+
+/**
-+ * reiser4_init_entd - initialize entd context and start kernel daemon
++ * 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 reiser4_init_entd(struct super_block *super)
++int init_entd(struct super_block *super)
+{
+ entd_context *ctx;
+
+ return 0;
+}
+
-+static void put_wbq(struct wbq *rq)
++static void __put_wbq(entd_context *ent, struct wbq *rq)
+{
-+ iput(rq->mapping->host);
-+ complete(&rq->completion);
++ up(&rq->sem);
+}
+
+/* ent should be locked */
+{
+ struct wbq *wbq;
+
-+ if (list_empty(&ent->todo_list))
++ if (list_empty_careful(&ent->todo_list))
+ return NULL;
+
+ ent->nr_todo_reqs --;
+ 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)
+{
+
+ spin_lock(&ent->guard);
+ while (ent->nr_todo_reqs != 0) {
-+ struct wbq *rq;
++ struct wbq *rq, *next;
+
-+ assert("", list_empty(&ent->done_list));
++ assert("", list_empty_careful(&ent->done_list));
+
+ /* take request from the queue head */
+ rq = __get_wbq(ent);
+ entd_set_comm("!");
+ entd_flush(super, rq);
+
-+ put_wbq(rq);
++ iput(rq->mapping->host);
++ up(&(rq->sem));
+
+ /*
+ * wakeup all requestors and iput their inodes
+ */
+ spin_lock(&ent->guard);
-+ while (!list_empty(&ent->done_list)) {
-+ rq = list_entry(ent->done_list.next, struct wbq, link);
-+ list_del_init(&rq->link);
++ list_for_each_entry_safe(rq, next, &ent->done_list, link) {
++ list_del_init(&(rq->link));
+ ent->nr_done_reqs --;
+ spin_unlock(&ent->guard);
++
+ assert("", rq->written == 1);
-+ put_wbq(rq);
++ iput(rq->mapping->host);
++ up(&(rq->sem));
+ spin_lock(&ent->guard);
+ }
+ }
+ 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;
+}
+
+/**
-+ * reiser4_done_entd - stop entd kernel thread
++ * 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 reiser4_done_entd(struct super_block *super)
++void done_entd(struct super_block *super)
+{
+ entd_context *ent;
+
+
+/* called at the beginning of jnode_flush to register flusher thread with ent
+ * daemon */
-+void reiser4_enter_flush(struct super_block *super)
++void enter_flush(struct super_block *super)
+{
+ entd_context *ent;
+
+}
+
+/* called at the end of jnode_flush */
-+void reiser4_leave_flush(struct super_block *super)
++void leave_flush(struct super_block *super)
+{
+ entd_context *ent;
+ int wake_up_ent;
+ ctx.entd = 1;
+ ctx.gfp_mask = GFP_NOFS;
+
-+ rq->wbc->range_start = page_offset(rq->page);
-+ rq->wbc->range_end = rq->wbc->range_start +
-+ (ENTD_CAPTURE_APAGE_BURST << PAGE_CACHE_SHIFT);
++ rq->wbc->start = rq->page->index << PAGE_CACHE_SHIFT;
++ rq->wbc->end = (rq->page->index + 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->range_start = 0;
-+ rq->wbc->range_end = LLONG_MAX;
++ rq->wbc->start = 0;
++ rq->wbc->end = LLONG_MAX;
+ generic_sync_sb_inodes(super, rq->wbc);
+ }
+ rq->wbc->nr_to_write = ENTD_CAPTURE_APAGE_BURST;
-+ reiser4_writeout(super, rq->wbc);
++ writeout(super, rq->wbc);
+
+ context_set_commit_async(&ctx);
+ reiser4_exit_context(&ctx);
+ * page. Re-dirty page before unlocking so that if ent thread fails to
+ * write it - it will remain dirty
+ */
-+ reiser4_set_page_dirty_internal(page);
++ set_page_dirty_internal(page);
+
+ /*
+ * pin inode in memory, unlock page, entd_flush will iput. We can not
+ rq.mapping = inode->i_mapping;
+ rq.node = NULL;
+ rq.written = 0;
-+ init_completion(&rq.completion);
++ sema_init(&rq.sem, 0);
+
+ /* add request to entd's list of writepage requests */
+ spin_lock(&ent->guard);
+ spin_unlock(&ent->guard);
+
+ /* wait until entd finishes */
-+ wait_for_completion(&rq.completion);
++ 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);
+
+ if (rq.written)
+ /* Eventually ENTD has written the page to disk. */
+ * fill-column: 79
+ * End:
+ */
-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
+Index: linux-2.6.16/fs/reiser4/entd.h
+===================================================================
+--- /dev/null
++++ linux-2.6.16/fs/reiser4/entd.h
@@ -0,0 +1,90 @@
+/* Copyright 2003 by Hans Reiser, licensing governed by reiser4/README */
+
+ struct writeback_control *wbc;
+ struct page *page;
+ struct address_space *mapping;
-+ struct completion completion;
++ struct semaphore sem;
+ jnode *node; /* set if ent thread captured requested page */
+ int written; /* set if ent thread wrote requested page */
+};
+#endif
+} entd_context;
+
-+extern int reiser4_init_entd(struct super_block *);
-+extern void reiser4_done_entd(struct super_block *);
++extern int init_entd(struct super_block *);
++extern void done_entd(struct super_block *);
+
-+extern void reiser4_enter_flush(struct super_block *);
-+extern void reiser4_leave_flush(struct super_block *);
++extern void enter_flush(struct super_block *);
++extern void leave_flush(struct super_block *);
+
+extern int write_page_by_ent(struct page *, struct writeback_control *);
+extern int wbq_available(void);
+ fill-column: 120
+ End:
+*/
-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 @@
+Index: linux-2.6.16/fs/reiser4/eottl.c
+===================================================================
+--- /dev/null
++++ linux-2.6.16/fs/reiser4/eottl.c
+@@ -0,0 +1,510 @@
+/* Copyright 2001, 2002, 2003 by Hans Reiser, licensing governed by reiser4/README */
+
+#include "forward.h"
+
+ assert("vs-49827", znode_contains_key_lock(insert_coord->node, key));
+ tree = znode_get_tree(insert_coord->node);
-+ node = reiser4_new_node(insert_coord->node, LEAF_LEVEL);
++ node = new_node(insert_coord->node, LEAF_LEVEL);
+ if (IS_ERR(node))
+ return PTR_ERR(node);
+
+ item = (reiser4_item_data *) (todo + 3);
+ cdata = (carry_insert_data *) (item + 1);
+
-+ op = reiser4_post_carry(todo, COP_INSERT, insert_coord->node, 0);
++ op = post_carry(todo, COP_INSERT, insert_coord->node, 0);
+ if (!IS_ERR(op)) {
+ cdata->coord = insert_coord;
+ cdata->key = key;
+ todo->track_type = CARRY_TRACK_CHANGE;
+ todo->tracked = lh;
+
-+ result = reiser4_carry(todo, NULL);
++ result = carry(todo, NULL);
+ if (result == 0) {
+ /*
+ * pin node in memory. This is necessary for
+ write_unlock_tree(tree);
+ result =
+ connect_znode(insert_coord, node);
-+ ON_DEBUG(if (result == 0) check_dkeys(node););
++ if (result == 0)
++ ON_DEBUG(check_dkeys(node));
+
+ done_lh(lh);
+ move_lh(lh, &local_lh);
+ * scroll-step: 1
+ * End:
+ */
-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 @@
+Index: linux-2.6.16/fs/reiser4/estimate.c
+===================================================================
+--- /dev/null
++++ linux-2.6.16/fs/reiser4/estimate.c
+@@ -0,0 +1,111 @@
+/* Copyright 2001, 2002, 2003 by Hans Reiser, licensing governed by reiser4/README */
+
+#include "debug.h"
+ return estimate_cluster(inode, 0); /* 44, for 64K-cluster */
+}
+
-+/* 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.
-+*/
++/* how many nodes occupied by a disk cluster might get dirty */
+reiser4_block_nr estimate_dirty_cluster(struct inode * inode)
+{
-+ return cluster_nrpages(inode) + 4;
++ return 2 + cluster_nrpages(inode);
+}
+
+/* Make Linus happy.
+ scroll-step: 1
+ End:
+*/
-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 @@
+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 @@
+/* Copyright 2005 by Hans Reiser, licensing governed by
+ * reiser4/README */
+
+#include "inode.h"
+#include "plugin/plugin.h"
+
++
+/*
+ * Supported file-handle types
+ */
+
+ /* identifier of object plugin is stored in the first two bytes,
+ * followed by... */
-+ fplug = file_plugin_by_disk_id(reiser4_get_tree(s), (d16 *) addr);
++ fplug = file_plugin_by_disk_id(get_tree(s), (d16 *) addr);
+ if (fplug != NULL) {
+ addr += sizeof(d16);
+ obj->plugin = fplug;
+ char *addr;
+ int with_parent;
+
-+ ctx = reiser4_init_context(super);
++ ctx = init_context(super);
+ if (IS_ERR(ctx))
+ return (struct dentry *)ctx;
+
+ need += delta;
+ }
+
-+ ctx = reiser4_init_context(dentry->d_inode->i_sb);
++ ctx = init_context(dentry->d_inode->i_sb);
+ if (IS_ERR(ctx))
+ return PTR_ERR(ctx);
+
+ * fill-column: 79
+ * End:
+ */
-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 @@
+Index: linux-2.6.16/fs/reiser4/flush.c
+===================================================================
+--- /dev/null
++++ linux-2.6.16/fs/reiser4/flush.c
+@@ -0,0 +1,3626 @@
+/* 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. */
+ 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, int expected);
++ znode_lock_mode mode, int check_dirty);
+static int znode_same_parents(znode * a, znode * b);
+
+static int znode_check_flushprepped(znode * node)
+ struct backing_dev_info *bdi;
+
+ sb = reiser4_get_current_sb();
-+ bdi = reiser4_get_super_fake(sb)->i_mapping->backing_dev_info;
++ bdi = get_super_fake(sb)->i_mapping->backing_dev_info;
+ return bdi_write_congested(bdi);
+}
+
+ if (check_write_congestion())
+ return 0;
+
-+ ret = reiser4_write_fq(pos->fq, pos->nr_written,
++ ret = write_fq(pos->fq, pos->nr_written,
+ WRITEOUT_SINGLE_STREAM | WRITEOUT_FOR_PAGE_RECLAIM);
+ return ret;
+}
+ assert("zam-1020", node_is_empty(node));
+ assert("zam-1023", znode_is_wlocked(node));
+
-+ return reiser4_delete_node(node, &smallest_removed, NULL, 1);
++ return delete_node(node, &smallest_removed, NULL, 1);
+}
+
+/* Prepare flush position for alloc_pos_and_ancestors() and squalloc() */
+ jnode *leftmost_in_slum = NULL;
+
+ assert("jmacd-76619", lock_stack_isclean(get_current_lock_stack()));
-+ assert("nikita-3022", reiser4_schedulable());
++ assert("nikita-3022", schedulable());
+
++ /* lock ordering: delete_sema and flush_sema are unordered */
+ assert("nikita-3185",
-+ get_current_super_private()->delete_mutex_owner != current);
++ get_current_super_private()->delete_sema_owner != current);
+
+ /* allocate right_scan, left_scan and flush_pos */
+ right_scan =
-+ kmalloc(2 * sizeof(*right_scan) + sizeof(*flush_pos),
-+ reiser4_ctx_gfp_mask_get());
++ kmalloc(2 * sizeof(*right_scan) + sizeof(*flush_pos), get_gfp_mask());
+ if (right_scan == NULL)
+ return RETERR(-ENOMEM);
+ left_scan = right_scan + 1;
+
+ 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
+
-+ reiser4_enter_flush(sb);
++ enter_flush(sb);
+
+ /* Initialize a flush position. */
+ pos_init(flush_pos);
+
+ ON_DEBUG(atomic_dec(&flush_cnt));
+
-+ reiser4_leave_flush(sb);
++ leave_flush(sb);
++
++ if (!reiser4_is_set(sb, REISER4_MTFLUSH))
++ up(&sbinfo->flush_sema);
+
+ return ret;
+}
+ 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. */
+
+ nr_to_write = LONG_MAX;
+ while (1) {
-+ ret = reiser4_fq_by_atom(*atom, &fq);
++ ret = fq_by_atom(*atom, &fq);
+ if (ret != -E_REPEAT)
+ break;
+ *atom = get_current_atom_locked();
+ /* parallel flushers limit */
+ if (sinfo->tmgr.atom_max_flushers != 0) {
+ while ((*atom)->nr_flushers >= sinfo->tmgr.atom_max_flushers) {
-+ /* 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);
++ /* 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);
+ *atom = get_current_atom_locked();
+ }
+ }
+ if (node == NULL) {
+ if (nr_queued == 0) {
+ (*atom)->nr_flushers--;
-+ reiser4_fq_put_nolock(fq);
-+ reiser4_atom_send_event(*atom);
++ fq_put_nolock(fq);
++ atom_send_event(*atom);
+ /* current atom remains locked */
+ writeout_mode_disable();
+ return 0;
+ }
+
+ ret =
-+ reiser4_write_fq(fq, nr_submitted,
++ write_fq(fq, nr_submitted,
+ WRITEOUT_SINGLE_STREAM | WRITEOUT_FOR_PAGE_RECLAIM);
+
+ *atom = get_current_atom_locked();
+ (*atom)->nr_flushers--;
-+ reiser4_fq_put_nolock(fq);
-+ reiser4_atom_send_event(*atom);
++ fq_put_nolock(fq);
++ atom_send_event(*atom);
+ spin_unlock_atom(*atom);
+
+ writeout_mode_disable();
+ reiser4_block_nr dist;
+
+ assert("jmacd-7710", *pblk != 0 && *nblk != 0);
-+ assert("jmacd-7711", !reiser4_blocknr_is_fake(pblk));
-+ assert("jmacd-7712", !reiser4_blocknr_is_fake(nblk));
++ assert("jmacd-7711", !blocknr_is_fake(pblk));
++ assert("jmacd-7712", !blocknr_is_fake(nblk));
+
+ /* Distance is the absolute value. */
+ dist = (*pblk > *nblk) ? (*pblk - *nblk) : (*nblk - *pblk);
+
+ nblk = *jnode_get_block(node);
+
-+ if (reiser4_blocknr_is_fake(&nblk))
++ if (blocknr_is_fake(&nblk))
+ /* child is unallocated, mark parent dirty */
+ return 1;
+
+ ON_DEBUG(vp = shift_check_prepare(left, coord.node));
+
+ /* stop_key is used to find what was copied and what to cut */
-+ stop_key = *reiser4_min_key();
++ stop_key = *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, reiser4_min_key()));
++ assert("vs-1465", !keyeq(&stop_key, min_key()));
+
+ /* Helper function to do the cutting. */
+ set_key_offset(&stop_key, get_key_offset(&stop_key) - 1);
+ }
+
+ while (1) {
-+ 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);
++ ret =
++ neighbor_in_slum(pos->lock.node, &right_lock, RIGHT_SIDE,
++ ZNODE_WRITE_LOCK,
++ !should_convert_next_node(pos,
++ right_lock.
++ node));
++ if (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
+ * smarter. */
+ if (znode_check_flushprepped(right_lock.node)
+ && !znode_convertible(right_lock.node)) {
-+ assert("edward-1005", !should_convert_next_node(pos));
++ assert("edward-1005",
++ !should_convert_next_node(pos, right_lock.node));
+ pos_stop(pos);
+ break;
+ }
+ 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)
+ break;
+
+ if (znode_check_flushprepped(right_lock.node)) {
-+ if (should_convert_next_node(pos)) {
++ if (should_convert_next_node(pos, right_lock.node)) {
+ /* in spite of flushprepped status of the node,
+ its right slum neighbor should be converted */
+ assert("edward-953", convert_data(pos));
+ 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;
+ if (ret)
+ break;
+ }
-+ check_convert_info(pos);
++
++ assert("edward-1006", !convert_data(pos) || !item_convert_data(pos));
++
+ done_load_count(&right_load);
+ done_lh(&right_lock);
+
+
+ while (pos_valid(pos) && coord_is_existing_unit(&pos->coord)
+ && item_is_extent(&pos->coord)) {
-+ ret = reiser4_alloc_extent(pos);
++ ret = alloc_extent(pos);
+ if (ret) {
+ break;
+ }
+ 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 = reiser4_carry(todo, NULL /* previous level */ );
++ ret = carry(todo, NULL /* previous level */ );
+ grabbed2free_mark(grabbed);
+ } else {
+ /* Shifting impossible, we return appropriate result code */
+ ret = reiser4_grab_space_force(tree->height, BA_RESERVED);
+ assert("nikita-3003", ret == 0); /* reserved space is exhausted. Ask Hans. */
+
-+ ret = reiser4_carry(todo, NULL /* previous level */ );
++ ret = carry(todo, NULL /* previous level */ );
+ grabbed2free_mark(grabbed);
+ }
+
+ reiser4_block_nr dist;
+ reiser4_block_nr nblk = *znode_get_block(node);
+
-+ assert("jmacd-6172", !reiser4_blocknr_is_fake(&nblk));
-+ assert("jmacd-6173", !reiser4_blocknr_is_fake(&pos->preceder.blk));
++ assert("jmacd-6172", !blocknr_is_fake(&nblk));
++ assert("jmacd-6173", !blocknr_is_fake(&pos->preceder.blk));
+ assert("jmacd-6174", pos->preceder.blk != 0);
+
+ if (pos->preceder.blk == nblk - 1) {
+ check_preceder(pos->preceder.blk);
+ pos->alloc_cnt += 1;
+
-+ assert("jmacd-4277", !reiser4_blocknr_is_fake(&pos->preceder.blk));
++ assert("jmacd-4277", !blocknr_is_fake(&pos->preceder.blk));
+
+ return 0;
+}
+ return ret;
+
+ if (ZF_ISSET(node, JNODE_CREATED)) {
-+ assert("zam-816", reiser4_blocknr_is_fake(znode_get_block(node)));
++ assert("zam-816", blocknr_is_fake(znode_get_block(node)));
+ pos->preceder.block_stage = BLOCK_UNALLOCATED;
+ } else {
+ pos->preceder.block_stage = BLOCK_GRABBED;
+ 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 use_upper_levels /* get neighbor by going though
-+ upper levels */)
-+{
++ int check_dirty)
++{ /* true if the neighbor should be dirty */
+ int ret;
-+ int flags;
+
+ assert("jmacd-6334", znode_is_connected(node));
+
-+ 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,
++ GN_SAME_ATOM | (side ==
++ LEFT_SIDE ? GN_GO_LEFT : 0));
+
-+ 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)
+}
+
+/* Returns true if flush scanning is finished. */
-+int reiser4_scan_finished(flush_scan * scan)
++int scan_finished(flush_scan * scan)
+{
+ return scan->stop || (scan->direction == RIGHT_SIDE &&
+ scan->count >= scan->max_count);
+
+/* 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 reiser4_scan_goto(flush_scan * scan, jnode * tonode)
++int scan_goto(flush_scan * scan, jnode * tonode)
+{
+ int go = same_slum_check(scan->node, tonode, 1, 0);
+
+ scan->node = node;
+ scan->count += add_count;
+
-+ /* This next stmt is somewhat inefficient. The reiser4_scan_extent() code could
++ /* This next stmt is somewhat inefficient. The scan_extent_coord 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. */
+}
+
+/* Return true if scanning in the leftward direction. */
-+int reiser4_scanning_left(flush_scan * scan)
++int scanning_left(flush_scan * scan)
+{
+ return scan->direction == LEFT_SIDE;
+}
+ }
+ /* This loop expects to start at a formatted position and performs chaining of
+ formatted regions */
-+ while (!reiser4_scan_finished(scan)) {
++ while (!scan_finished(scan)) {
+
+ ret = scan_formatted(scan);
+ if (ret != 0) {
+ * there is already lock held by this thread,
+ * jnode_lock_parent_coord() should use try-lock.
+ */
-+ try = reiser4_scanning_left(scan)
++ try = 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
+ ret =
+ longterm_lock_znode(&lock, JZNODE(scan->node),
+ ZNODE_WRITE_LOCK,
-+ reiser4_scanning_left(scan) ?
-+ ZNODE_LOCK_LOPRI :
++ 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
+ int ret;
+ znode *neighbor = NULL;
+
-+ assert("jmacd-1401", !reiser4_scan_finished(scan));
++ assert("jmacd-1401", !scan_finished(scan));
+
+ do {
+ znode *node = JZNODE(scan->node);
+ 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 =
-+ reiser4_scanning_left(scan) ? node->left : node->right;
++ neighbor = scanning_left(scan) ? node->left : node->right;
+ if (neighbor != NULL) {
+ zref(neighbor);
+ }
+
+ /* Check the condition for going left, break if it is not met. This also
+ releases (jputs) the neighbor if false. */
-+ if (!reiser4_scan_goto(scan, ZJNODE(neighbor))) {
++ if (!scan_goto(scan, ZJNODE(neighbor))) {
+ break;
+ }
+
+ return ret;
+ }
+
-+ } while (!reiser4_scan_finished(scan));
++ } while (!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
-+ || reiser4_scan_finished(scan)) {
++ || scan_finished(scan)) {
+ scan->stop = 1;
+ return 0;
+ }
+ /* set initial item id */
+ iplug = item_plugin_by_coord(&scan->parent_coord);
+
-+ for (; !reiser4_scan_finished(scan); scan_this_coord = 1) {
++ for (; !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. */
+ if (ret != 0)
+ goto exit;
+
-+ if (reiser4_scan_finished(scan)) {
++ if (scan_finished(scan)) {
+ checkchild(scan);
+ break;
+ }
+ 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 */,
-+ 0 /* don't go though upper
-+ levels */);
++ ret =
++ neighbor_in_slum(next_coord.node, &next_lock,
++ scan->direction, ZNODE_WRITE_LOCK,
++ 1 /* check dirty */ );
+ if (ret == -E_NO_NEIGHBOR) {
+ scan->stop = 1;
+ ret = 0;
+ || jnode_is_znode(child));
+
+ /* See if it is dirty, part of the same atom. */
-+ if (!reiser4_scan_goto(scan, child)) {
++ if (!scan_goto(scan, child)) {
+ checkchild(scan);
+ break;
+ }
+ }
+ }
+
-+ assert("jmacd-6233",
-+ reiser4_scan_finished(scan) || jnode_is_znode(scan->node));
++ assert("jmacd-6233", scan_finished(scan) || jnode_is_znode(scan->node));
+ exit:
+ checkchild(scan);
+ race: /* skip the above check */
+ init_lh(&pos->lock);
+ init_load_count(&pos->load);
+
-+ reiser4_blocknr_hint_init(&pos->preceder);
++ blocknr_hint_init(&pos->preceder);
+}
+
+/* The flush loop inside squalloc periodically checks pos_valid to
+static void pos_done(flush_pos_t * pos)
+{
+ pos_stop(pos);
-+ reiser4_blocknr_hint_done(&pos->preceder);
++ blocknr_hint_done(&pos->preceder);
+ if (convert_data(pos))
+ free_convert_data(pos);
+}
+}
+
+/* Return the flush_position's block allocator hint. */
-+reiser4_blocknr_hint *reiser4_pos_hint(flush_pos_t * pos)
++reiser4_blocknr_hint *pos_hint(flush_pos_t * pos)
+{
+ return &pos->preceder;
+}
+
-+flush_queue_t * reiser4_pos_fq(flush_pos_t * pos)
++flush_queue_t *pos_fq(flush_pos_t * pos)
+{
+ return pos->fq;
+}
+ LocalWords: preceder
+ End:
+*/
-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 @@
+Index: linux-2.6.16/fs/reiser4/flush.h
+===================================================================
+--- /dev/null
++++ linux-2.6.16/fs/reiser4/flush.h
+@@ -0,0 +1,274 @@
+/* Copyright 2002, 2003 by Hans Reiser, licensing governed by reiser4/README */
+
+/* DECLARATIONS: */
+ reiser4_block_nr preceder_blk;
+};
+
-+struct convert_item_info {
++typedef 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;
+
-+struct convert_info {
++typedef struct convert_info {
+ int count; /* for squalloc terminating */
++ reiser4_cluster_t clust; /* transform cluster */
+ item_plugin *iplug; /* current item plugin */
-+ struct convert_item_info *itm; /* current item info */
-+ struct cluster_handle clust; /* transform cluster */
-+};
++ convert_item_info_t *itm; /* current item info */
++} convert_info_t;
+
+typedef enum flush_position_state {
+ POS_INVALID, /* Invalid or stopped pos, do not continue slum
+
+ znode *prev_twig; /* previous parent pointer value, used to catch
+ * processing of new twig node */
-+ struct convert_info *sq; /* convert info */
++ convert_info_t *sq; /* convert info */
+
+ unsigned long pos_in_unit; /* for extents only. Position
+ within an extent unit of first
+ return pos->sq->iplug;
+}
+
-+static inline struct convert_info *convert_data(flush_pos_t * pos)
++static inline convert_info_t *convert_data(flush_pos_t * pos)
+{
+ return pos->sq;
+}
+
-+static inline struct convert_item_info *item_convert_data(flush_pos_t * pos)
++static inline convert_item_info_t *item_convert_data(flush_pos_t * pos)
+{
+ assert("edward-955", convert_data(pos));
+ return pos->sq->itm;
+}
+
-+static inline struct tfm_cluster * tfm_cluster_sq(flush_pos_t * pos)
++static inline tfm_cluster_t *tfm_cluster_sq(flush_pos_t * pos)
+{
+ return &pos->sq->clust.tc;
+}
+
-+static inline struct tfm_stream * tfm_stream_sq(flush_pos_t * pos,
-+ tfm_stream_id id)
++static inline tfm_stream_t *tfm_stream_sq(flush_pos_t * pos, tfm_stream_id id)
+{
+ assert("edward-854", pos->sq != NULL);
-+ return get_tfm_stream(tfm_cluster_sq(pos), id);
++ return tfm_stream(tfm_cluster_sq(pos), id);
+}
+
+static inline int chaining_data_present(flush_pos_t * pos)
+}
+
+/* true if there is attached convert item info */
-+static inline int should_convert_next_node(flush_pos_t * pos)
++static inline int should_convert_next_node(flush_pos_t * pos, znode * node)
+{
+ return convert_data(pos) && item_convert_data(pos);
+}
+ 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 reiser4_scan_finished(flush_scan * scan);
-+int reiser4_scanning_left(flush_scan * scan);
-+int reiser4_scan_goto(flush_scan * scan, jnode * tonode);
++int scan_finished(flush_scan * scan);
++int scanning_left(flush_scan * scan);
++int scan_goto(flush_scan * scan, jnode * tonode);
+txn_atom *atom_locked_by_fq(flush_queue_t * fq);
-+int reiser4_alloc_extent(flush_pos_t *flush_pos);
++int 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 reiser4_init_fqs(void);
-+extern void reiser4_done_fqs(void);
++extern int init_fqs(void);
++extern void done_fqs(void);
+
+#if REISER4_DEBUG
+
-+extern void reiser4_check_fq(const txn_atom *atom);
++extern void check_fq(const txn_atom *atom);
+extern atomic_t flush_cnt;
+
+#define check_preceder(blk) \
+ LocalWords: preceder
+ End:
+*/
-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 @@
+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 @@
+/* Copyright 2001, 2002, 2003 by Hans Reiser, licensing governed by reiser4/README */
+
+#include "debug.h"
+
+ INIT_LIST_HEAD(ATOM_FQ_LIST(fq));
+
-+ init_waitqueue_head(&fq->wait);
++ sema_init(&fq->io_sem, 0);
+ spin_lock_init(&fq->guard);
+}
+
+/* slab for flush queues */
-+static struct kmem_cache *fq_slab;
++static kmem_cache_t *fq_slab;
++
+
+/**
-+ * reiser4_init_fqs - create flush queue cache
++ * init_fqs - create flush queue cache
+ *
+ * Initializes slab cache of flush queues. It is part of reiser4 module
+ * initialization.
+ */
-+int reiser4_init_fqs(void)
++int init_fqs(void)
+{
+ fq_slab = kmem_cache_create("fq",
+ sizeof(flush_queue_t),
+}
+
+/**
-+ * reiser4_done_fqs - delete flush queue cache
++ * done_fqs - delete flush queue cache
+ *
+ * This is called on reiser4 module unloading or system shutdown.
+ */
-+void reiser4_done_fqs(void)
++void done_fqs(void)
+{
+ destroy_reiser4_cache(&fq_slab);
+}
+}
+
+/* */
-+static void mark_jnode_queued(flush_queue_t * fq, jnode * node)
++void mark_jnode_queued(flush_queue_t * fq, jnode * node)
+{
+ JF_SET(node, JNODE_FLUSH_QUEUED);
+ count_enqueued_node(fq);
+
+ spin_unlock_atom(fq->atom);
+
-+ assert("nikita-3013", reiser4_schedulable());
++ assert("nikita-3013", schedulable());
+
+ super = reiser4_get_current_sb();
+
+ /* FIXME: this is instead of blk_run_queues() */
-+ blk_run_address_space(reiser4_get_super_fake(super)->i_mapping);
++ blk_run_address_space(get_super_fake(super)->i_mapping);
+
+ if (!(super->s_flags & MS_RDONLY))
-+ wait_event(fq->wait, atomic_read(&fq->nr_submitted) == 0);
++ down(&fq->io_sem);
+
+ /* Ask the caller to re-acquire the locks and call this
+ function again. Note: this technique is commonly used in
+ detach_fq(fq);
+ done_fq(fq);
+
-+ reiser4_atom_send_event(atom);
++ atom_send_event(atom);
+
+ return 0;
+}
+ reiser4_handle_error();
+
+ if (ret) {
-+ reiser4_fq_put(fq);
++ fq_put(fq);
+ return ret;
+ }
+
+ ret = finish_all_fq(atom, &nr_io_errors);
+ if (ret != -EBUSY)
+ break;
-+ reiser4_atom_wait_event(atom);
++ atom_wait_event(atom);
+ }
+ } while (ret == -E_REPEAT);
+
+}
+
+/* support for atom fusion operation */
-+void reiser4_fuse_fq(txn_atom *to, txn_atom *from)
++void fuse_fq(txn_atom *to, txn_atom *from)
+{
+ flush_queue_t *fq;
+
+ atomic_add(nr_errors, &fq->nr_errors);
+
+ /* If all write requests registered in this "fq" are done we up
-+ * the waiter. */
++ * the semaphore. */
+ if (atomic_sub_and_test(bio->bi_vcnt, &fq->nr_submitted))
-+ wake_up(&fq->wait);
++ up(&fq->io_sem);
+ }
+
+ bio_put(bio);
+ }
+
+ if (--atom->nr_running_queues == 0)
-+ reiser4_atom_send_event(atom);
++ atom_send_event(atom);
+
+ spin_unlock_atom(atom);
+}
+ @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 reiser4_write_fq(flush_queue_t * fq, long *nr_submitted, int flags)
++int write_fq(flush_queue_t * fq, long *nr_submitted, int flags)
+{
+ int ret;
+ txn_atom *atom;
+ if (atom->nr_running_queues == 0
+ || !(flags & WRITEOUT_SINGLE_STREAM))
+ break;
-+ reiser4_atom_wait_event(atom);
++ atom_wait_event(atom);
+ }
+
+ atom->nr_running_queues++;
+ return RETERR(-E_REPEAT);
+}
+
-+int reiser4_fq_by_atom(txn_atom * atom, flush_queue_t ** new_fq)
++int fq_by_atom(txn_atom * atom, flush_queue_t ** new_fq)
+{
-+ return fq_by_atom_gfp(atom, new_fq, reiser4_ctx_gfp_mask_get());
++ return fq_by_atom_gfp(atom, new_fq, get_gfp_mask());
+}
+
-+/* A wrapper around reiser4_fq_by_atom for getting a flush queue
-+ object for current atom, if success fq->atom remains locked. */
++/* A wrapper around 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;
+
+ do {
+ atom = get_current_atom_locked();
-+ ret = reiser4_fq_by_atom(atom, &fq);
++ ret = fq_by_atom(atom, &fq);
+ } while (ret == -E_REPEAT);
+
+ if (ret)
+}
+
+/* Releasing flush queue object after exclusive use */
-+void reiser4_fq_put_nolock(flush_queue_t *fq)
++void fq_put_nolock(flush_queue_t *fq)
+{
+ assert("zam-747", fq->atom != NULL);
+ assert("zam-902", list_empty_careful(ATOM_FQ_LIST(fq)));
+ ON_DEBUG(fq->owner = NULL);
+}
+
-+void reiser4_fq_put(flush_queue_t * fq)
++void fq_put(flush_queue_t * fq)
+{
+ txn_atom *atom;
+
+
+ assert("zam-746", atom != NULL);
+
-+ reiser4_fq_put_nolock(fq);
-+ reiser4_atom_send_event(atom);
++ fq_put_nolock(fq);
++ atom_send_event(atom);
+
+ spin_unlock(&(fq->guard));
+ spin_unlock_atom(atom);
+
+#if REISER4_DEBUG
+
-+void reiser4_check_fq(const txn_atom *atom)
++void check_fq(const txn_atom *atom)
+{
+ /* check number of nodes on all atom's flush queues */
+ flush_queue_t *fq;
+ * scroll-step: 1
+ * End:
+ */
-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 @@
+Index: linux-2.6.16/fs/reiser4/forward.h
+===================================================================
+--- /dev/null
++++ linux-2.6.16/fs/reiser4/forward.h
+@@ -0,0 +1,258 @@
+/* Copyright 2001, 2002, 2003 by Hans Reiser, licensing governed by reiser4/README */
+
+/* Forward declarations. Thank you Kernighan. */
+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;
+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;
+
+typedef struct ktxnmgrd_context ktxnmgrd_context;
+
++typedef struct reiser4_xattr_plugin reiser4_xattr_plugin;
++
+struct inode;
+struct page;
+struct file;
+ OVRWR_LIST
+} atom_list;
+
++
++
+/* __REISER4_FORWARD_H__ */
+#endif
+
+ fill-column: 120
+ End:
+*/
-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 @@
+Index: linux-2.6.16/fs/reiser4/fsdata.c
+===================================================================
+--- /dev/null
++++ linux-2.6.16/fs/reiser4/fsdata.c
+@@ -0,0 +1,803 @@
+/* Copyright 2001, 2002, 2003, 2004, 2005 by Hans Reiser, licensing governed by
+ * reiser4/README */
+
+
+
+/* cache or dir_cursors */
-+static struct kmem_cache *d_cursor_cache;
++static kmem_cache_t *d_cursor_cache;
+static struct shrinker *d_cursor_shrinker;
+
+/* list of unused cursors */
+}
+
+/**
-+ * reiser4_init_d_cursor - create d_cursor cache
++ * init_d_cursor - create d_cursor cache
+ *
+ * Initializes slab cache of d_cursors. It is part of reiser4 module
+ * initialization.
+ */
-+int reiser4_init_d_cursor(void)
++int init_d_cursor(void)
+{
+ d_cursor_cache = kmem_cache_create("d_cursor", sizeof(dir_cursor), 0,
+ SLAB_HWCACHE_ALIGN, NULL, NULL);
+}
+
+/**
-+ * reiser4_done_d_cursor - delete d_cursor cache and d_cursor shrinker
++ * done_d_cursor - delete d_cursor cache and d_cursor shrinker
+ *
+ * This is called on reiser4 module unloading or system shutdown.
+ */
-+void reiser4_done_d_cursor(void)
++void done_d_cursor(void)
+{
+ BUG_ON(d_cursor_shrinker == NULL);
+ remove_shrinker(d_cursor_shrinker);
+#define D_CURSOR_TABLE_SIZE (256)
+
+static inline unsigned long
-+d_cursor_hash(d_cursor_hash_table *table, const struct d_cursor_key *key)
++d_cursor_hash(d_cursor_hash_table *table, const 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 struct d_cursor_key *k1,
-+ const struct d_cursor_key *k2)
++static inline int d_cursor_eq(const d_cursor_key *k1, const d_cursor_key *k2)
+{
+ return k1->cid == k2->cid && k1->oid == k2->oid;
+}
+ * define functions to manipulate reiser4 super block's hash table of
+ * dir_cursors
+ */
-+#define KMALLOC(size) kmalloc((size), reiser4_ctx_gfp_mask_get())
++#define KMALLOC(size) kmalloc((size), get_gfp_mask())
+#define KFREE(ptr, size) kfree(ptr)
+TYPE_SAFE_HASH_DEFINE(d_cursor,
+ dir_cursor,
-+ struct d_cursor_key,
-+ key, hash, d_cursor_hash, d_cursor_eq);
++ d_cursor_key, key, hash, d_cursor_hash, d_cursor_eq);
+#undef KFREE
+#undef KMALLOC
+
+/**
-+ * reiser4_init_super_d_info - initialize per-super-block d_cursor resources
++ * 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 reiser4_init_super_d_info(struct super_block *super)
++int init_super_d_info(struct super_block *super)
+{
-+ struct d_cursor_info *p;
++ d_cursor_info *p;
+
+ p = &get_super_private(super)->d_info;
+
-+ INIT_RADIX_TREE(&p->tree, reiser4_ctx_gfp_mask_get());
++ INIT_RADIX_TREE(&p->tree, get_gfp_mask());
+ return d_cursor_hash_init(&p->table, D_CURSOR_TABLE_SIZE);
+}
+
+/**
-+ * reiser4_done_super_d_info - release per-super-block d_cursor resources
++ * 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 reiser4_done_super_d_info(struct super_block *super)
++void done_super_d_info(struct super_block *super)
+{
-+ struct d_cursor_info *d_info;
++ d_cursor_info *d_info;
+ dir_cursor *cursor, *next;
+
+ d_info = &get_super_private(super)->d_info;
+/*
+ * return d_cursor data for the file system @inode is in.
+ */
-+static inline struct d_cursor_info *d_info(struct inode *inode)
++static inline d_cursor_info *d_info(struct inode *inode)
+{
+ return &get_super_private(inode->i_sb)->d_info;
+}
+/*
+ * lookup d_cursor in the per-super-block radix tree.
+ */
-+static inline dir_cursor *lookup(struct d_cursor_info * info,
-+ unsigned long index)
++static inline dir_cursor *lookup(d_cursor_info * info, unsigned long index)
+{
+ return (dir_cursor *) radix_tree_lookup(&info->tree, index);
+}
+ * cursor. */
+ fsdata = create_fsdata(NULL);
+ if (fsdata != NULL) {
-+ result = radix_tree_preload(reiser4_ctx_gfp_mask_get());
++ result = radix_tree_preload(get_gfp_mask());
+ if (result == 0) {
-+ struct d_cursor_info *info;
++ d_cursor_info *info;
+ oid_t oid;
+
+ info = d_info(inode);
+ dir_cursor *start;
+ struct list_head *head;
+ reiser4_context *ctx;
-+ struct d_cursor_info *info;
++ d_cursor_info *info;
+
+ /* this can be called by
+ *
+ *
+ * without reiser4_context
+ */
-+ ctx = reiser4_init_context(inode->i_sb);
++ ctx = init_context(inode->i_sb);
+ if (IS_ERR(ctx)) {
+ warning("vs-23", "failed to init context");
+ return;
+}
+
+/**
-+ * reiser4_dispose_cursors - removes cursors from inode's list
++ * 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 reiser4_dispose_cursors(struct inode *inode)
++void dispose_cursors(struct inode *inode)
+{
+ process_cursors(inode, CURSOR_DISPOSE);
+}
+
+/**
-+ * reiser4_load_cursors - attach cursors to inode
++ * 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 reiser4_load_cursors(struct inode *inode)
++void load_cursors(struct inode *inode)
+{
+ process_cursors(inode, CURSOR_LOAD);
+}
+
+/**
-+ * reiser4_kill_cursors - kill all inode cursors
++ * 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 reiser4_kill_cursors(struct inode *inode)
++void kill_cursors(struct inode *inode)
+{
+ process_cursors(inode, CURSOR_KILL);
+}
+}
+
+/**
-+ * reiser4_get_dir_fpos -
++ * 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 reiser4_get_dir_fpos(struct file *dir)
++loff_t get_dir_fpos(struct file *dir)
+{
+ if (file_is_stateless(dir))
+ return dir->f_pos & CID_MASK;
+}
+
+/**
-+ * reiser4_attach_fsdata - try to attach fsdata
++ * try_to_attach_fsdata - ???
+ * @file:
+ * @inode:
+ *
+ * Finds or creates cursor for readdir-over-nfs.
+ */
-+int reiser4_attach_fsdata(struct file *file, struct inode *inode)
++int try_to_attach_fsdata(struct file *file, struct inode *inode)
+{
+ loff_t pos;
+ int result;
+ * first call to readdir (or rewind to the beginning of
+ * directory)
+ */
-+ cursor = kmem_cache_alloc(d_cursor_cache,
-+ reiser4_ctx_gfp_mask_get());
++ cursor = kmem_cache_alloc(d_cursor_cache, get_gfp_mask());
+ if (cursor != NULL)
+ result = insert_cursor(cursor, file, inode);
+ else
+ result = RETERR(-ENOMEM);
+ } else {
+ /* try to find existing cursor */
-+ struct d_cursor_key key;
++ d_cursor_key key;
+
+ key.cid = pos >> CID_SHIFT;
+ key.oid = get_inode_oid(inode);
+}
+
+/**
-+ * reiser4_detach_fsdata - ???
++ * detach_fsdata - ???
+ * @file:
+ *
+ * detach fsdata, if necessary
+ */
-+void reiser4_detach_fsdata(struct file *file)
++void detach_fsdata(struct file *file)
+{
+ struct inode *inode;
+
+}
+
+/* slab for reiser4_dentry_fsdata */
-+static struct kmem_cache *dentry_fsdata_cache;
++static kmem_cache_t *dentry_fsdata_cache;
+
+/**
-+ * reiser4_init_dentry_fsdata - create cache of dentry_fsdata
++ * 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 reiser4_init_dentry_fsdata(void)
++int init_dentry_fsdata(void)
+{
+ dentry_fsdata_cache = kmem_cache_create("dentry_fsdata",
-+ sizeof(struct reiser4_dentry_fsdata),
-+ 0,
-+ SLAB_HWCACHE_ALIGN |
-+ SLAB_RECLAIM_ACCOUNT, NULL,
-+ NULL);
++ sizeof(reiser4_dentry_fsdata),
++ 0,
++ SLAB_HWCACHE_ALIGN |
++ SLAB_RECLAIM_ACCOUNT, NULL,
++ NULL);
+ if (dentry_fsdata_cache == NULL)
+ return RETERR(-ENOMEM);
+ return 0;
+}
+
+/**
-+ * reiser4_done_dentry_fsdata - delete cache of dentry_fsdata
++ * done_dentry_fsdata - delete cache of dentry_fsdata
+ *
+ * This is called on reiser4 module unloading or system shutdown.
+ */
-+void reiser4_done_dentry_fsdata(void)
++void done_dentry_fsdata(void)
+{
+ destroy_reiser4_cache(&dentry_fsdata_cache);
+}
+ * Allocates if necessary and returns per-dentry data that we attach to each
+ * dentry.
+ */
-+struct reiser4_dentry_fsdata *reiser4_get_dentry_fsdata(struct dentry *dentry)
++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,
-+ reiser4_ctx_gfp_mask_get());
++ get_gfp_mask());
+ if (dentry->d_fsdata == NULL)
+ return ERR_PTR(RETERR(-ENOMEM));
-+ memset(dentry->d_fsdata, 0,
-+ sizeof(struct reiser4_dentry_fsdata));
++ memset(dentry->d_fsdata, 0, sizeof(reiser4_dentry_fsdata));
+ }
+ return dentry->d_fsdata;
+}
+ }
+}
+
++
+/* slab for reiser4_file_fsdata */
-+static struct kmem_cache *file_fsdata_cache;
++static kmem_cache_t *file_fsdata_cache;
+
+/**
-+ * reiser4_init_file_fsdata - create cache of reiser4_file_fsdata
++ * 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 reiser4_init_file_fsdata(void)
++int init_file_fsdata(void)
+{
+ file_fsdata_cache = kmem_cache_create("file_fsdata",
+ sizeof(reiser4_file_fsdata),
+}
+
+/**
-+ * reiser4_done_file_fsdata - delete cache of reiser4_file_fsdata
++ * done_file_fsdata - delete cache of reiser4_file_fsdata
+ *
+ * This is called on reiser4 module unloading or system shutdown.
+ */
-+void reiser4_done_file_fsdata(void)
++void done_file_fsdata(void)
+{
+ destroy_reiser4_cache(&file_fsdata_cache);
+}
+{
+ reiser4_file_fsdata *fsdata;
+
-+ fsdata = kmem_cache_alloc(file_fsdata_cache,
-+ reiser4_ctx_gfp_mask_get());
++ fsdata = kmem_cache_alloc(file_fsdata_cache, get_gfp_mask());
+ if (fsdata != NULL) {
+ memset(fsdata, 0, sizeof *fsdata);
+ fsdata->ra1.max_window_size = VM_MAX_READAHEAD * 1024;
+ * fill-column: 79
+ * End:
+ */
-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 @@
+Index: linux-2.6.16/fs/reiser4/fsdata.h
+===================================================================
+--- /dev/null
++++ linux-2.6.16/fs/reiser4/fsdata.h
+@@ -0,0 +1,218 @@
+/* Copyright 2001, 2002, 2003 by Hans Reiser, licensing governed by
+ * reiser4/README */
+
+ */
+
+/* logical position within directory */
-+struct dir_pos {
++typedef struct {
+ /* 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;
+
-+struct readdir_pos {
++typedef struct {
+ /* f_pos corresponding to this readdir position */
+ __u64 fpos;
+ /* logical position within directory */
-+ struct dir_pos position;
++ 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.
+ */
-+struct de_location {
++typedef struct de_location {
+ /* seal covering directory entry */
+ seal_t entry_seal;
+ /* coord of directory entry */
+ /* 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
+ * Currently it only contains cached location (hint) of directory entry, but
+ * it is expected that other information will be accumulated here.
+ */
-+struct reiser4_dentry_fsdata {
++typedef 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.
+ */
-+ struct de_location dec;
++ de_location dec;
+ int stateless; /* created through reiser4_decode_fh, needs special
+ * treatment in readdir. */
-+};
++} reiser4_dentry_fsdata;
+
-+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 int init_dentry_fsdata(void);
++extern void done_dentry_fsdata(void);
++extern 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
+ *
+ * position in directory. It is updated each time directory is
+ * modified
+ */
-+ struct readdir_pos readdir;
++ readdir_pos readdir;
+ /* head of this list is reiser4_inode->lists.readdir_list */
+ struct list_head linkage;
+ } dir;
+ 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 reiser4_init_file_fsdata(void);
-+extern void reiser4_done_file_fsdata(void);
++extern int init_file_fsdata(void);
++extern void 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.
+ */
-+struct d_cursor_key{
++typedef struct {
+ __u16 cid;
+ __u64 oid;
-+};
++} d_cursor_key;
+
+/*
+ * define structures d_cursor_hash_table d_cursor_hash_link which are used to
+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;
+ * cursors if there are more than one cursor of the same objectid
+ */
+ struct list_head list;
-+ struct d_cursor_key key;
-+ struct d_cursor_info *info;
++ d_cursor_key key;
++ d_cursor_info *info;
+ /* list of unused cursors */
+ struct list_head alist;
+};
+
-+extern int reiser4_init_d_cursor(void);
-+extern void reiser4_done_d_cursor(void);
++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_super_d_info(struct super_block *);
-+extern void reiser4_done_super_d_info(struct super_block *);
++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 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 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);
++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);
+
+/*
+ * this structure is embedded to reise4_super_info_data. It maintains d_cursors
+ * fill-column: 120
+ * End:
+ */
-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 @@
+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 @@
+/* Copyright by Hans Reiser, 2003 */
+
+#include "super.h"
+
+#include <linux/swap.h>
+
++
+/**
+ * init_fs_info - allocate reiser4 specific super block
+ * @super: super block of filesystem
+ * Allocates and initialize reiser4_super_info_data, attaches it to
+ * super->s_fs_info, initializes structures maintaining d_cursor-s.
+ */
-+int reiser4_init_fs_info(struct super_block *super)
++int init_fs_info(struct super_block *super)
+{
+ reiser4_super_info_data *sbinfo;
+
-+ sbinfo = kmalloc(sizeof(reiser4_super_info_data),
-+ reiser4_ctx_gfp_mask_get());
++ sbinfo = kmalloc(sizeof(reiser4_super_info_data), get_gfp_mask());
+ if (!sbinfo)
+ return RETERR(-ENOMEM);
+
+ ON_DEBUG(INIT_LIST_HEAD(&sbinfo->all_jnodes));
+ ON_DEBUG(spin_lock_init(&sbinfo->all_guard));
+
-+ mutex_init(&sbinfo->delete_mutex);
++ sema_init(&sbinfo->delete_sema, 1);
++ sema_init(&sbinfo->flush_sema, 1);
+ spin_lock_init(&(sbinfo->guard));
+
+ /* initialize per-super-block d_cursor resources */
-+ reiser4_init_super_d_info(super);
++ init_super_d_info(super);
+
+ return 0;
+}
+
+/**
-+ * reiser4_done_fs_info - free reiser4 specific super block
++ * 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 reiser4_done_fs_info(struct super_block *super)
++void done_fs_info(struct super_block *super)
+{
+ assert("zam-990", super->s_fs_info != NULL);
+
+ /* release per-super-block d_cursor resources */
-+ reiser4_done_super_d_info(super);
++ 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);
-+ reiser4_check_block_counters(super);
++ check_block_counters(super);
+ kfree(super->s_fs_info);
+ super->s_fs_info = NULL;
+}
+ OPT_ONEOF,
+} opt_type_t;
+
-+#if 0
-+struct opt_bitmask_bit {
++typedef struct opt_bitmask_bit {
+ const char *bit_name;
+ int bit_nr;
-+};
-+#endif
++} opt_bitmask_bit;
+
+/* description of option parseable by parse_option() */
-+struct opt_desc {
++typedef struct opt_desc {
+ /* option name.
+
+ parsed portion of string has a form "name=value".
+ struct {
+ void *addr;
+ int nr_bits;
-+ //struct opt_bitmask_bit *bits;
++ opt_bitmask_bit *bits;
+ } bitmask;
+ } u;
-+};
++} opt_desc_t;
+
+/**
+ * parse_option - parse one option
+ * +-- opt_string
+ * Figures out option type and handles option correspondingly.
+ */
-+static int parse_option(char *opt_string, struct opt_desc *opt)
++static int parse_option(char *opt_string, opt_desc_t *opt)
+{
+ char *val_start;
+ int result;
+ *
+ * Parses comma separated list of reiser4 mount options.
+ */
-+static int parse_options(char *opt_string, struct opt_desc *opts, int nr_opts)
++static int parse_options(char *opt_string, opt_desc_t *opts, int nr_opts)
+{
+ int result;
+
+#define MAX_NR_OPTIONS (30)
+
+/**
-+ * reiser4_init_super_data - initialize reiser4 private super block
++ * 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 reiser4_init_super_data(struct super_block *super, char *opt_string)
++int init_super_data(struct super_block *super, char *opt_string)
+{
+ int result;
-+ struct opt_desc *opts, *p;
++ opt_desc_t *opts, *p;
+ reiser4_super_info_data *sbinfo = get_super_private(super);
+
+ /* initialize super, export, dentry operations */
+ sbinfo->ra_params.flags = 0;
+
+ /* allocate memory for structure describing reiser4 mount options */
-+ opts = kmalloc(sizeof(struct opt_desc) * MAX_NR_OPTIONS,
-+ reiser4_ctx_gfp_mask_get());
++ opts = kmalloc(sizeof(opt_desc_t) * MAX_NR_OPTIONS, get_gfp_mask());
+ if (opts == NULL)
+ return RETERR(-ENOMEM);
+
+
+#define PUSH_OPT(...) \
+do { \
-+ struct opt_desc o = __VA_ARGS__; \
-+ OPT_ARRAY_CHECK; \
-+ *p ++ = o; \
++ opt_desc_t o = __VA_ARGS__; \
++ OPT_ARRAY_CHECK; \
++ *p ++ = o; \
+} while (0)
+
+#define PUSH_SB_FIELD_OPT(field, format) PUSH_OPT(SB_FIELD_OPT(field, format))
+ 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.
+ 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;
+}
+
+/**
-+ * reiser4_init_read_super - read reiser4 master super block
++ * 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 reiser4_init_read_super(struct super_block *super, int silent)
++int init_read_super(struct super_block *super, int silent)
+{
+ struct buffer_head *super_bh;
+ struct reiser4_master_sb *master_sb;
+ },
+ [PSET_COMPRESSION_MODE] = {
+ .type = REISER4_COMPRESSION_MODE_PLUGIN_TYPE,
-+ .id = CONVX_COMPRESSION_MODE_ID
++ .id = COL_16_COMPRESSION_MODE_ID
+ },
+ [PSET_CLUSTER] = {
+ .type = REISER4_CLUSTER_PLUGIN_TYPE,
+ .id = CLUSTER_64K_ID
+ },
-+ [PSET_CREATE] = {
-+ .type = REISER4_FILE_PLUGIN_TYPE,
-+ .id = UNIX_FILE_PLUGIN_ID
++ [PSET_REGULAR_ENTRY] = {
++ .type = REISER4_REGULAR_PLUGIN_TYPE,
++ .id = UF_REGULAR_ID
+ }
+};
+
+/* access to default plugin table */
-+reiser4_plugin *get_default_plugin(pset_member memb)
++static reiser4_plugin *get_default_plugin(pset_member memb)
+{
+ return plugin_by_id(default_plugins[memb].type,
+ default_plugins[memb].id);
+}
+
+/**
-+ * reiser4_init_root_inode - obtain inode of root directory
++ * 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 reiser4_init_root_inode(struct super_block *super)
++int init_root_inode(struct super_block *super)
+{
+ reiser4_super_info_data *sbinfo = get_super_private(super);
+ struct inode *inode;
+
+ 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;
+
-+ if (aset_get(pset, memb) != NULL)
-+ continue;
-+
-+ result = grab_plugin_pset(inode, NULL, memb);
++ plug = get_default_plugin(memb);
++ result = grab_plugin_from(inode, memb, plug);
+ 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",
-+ aset_get(pset, memb) != NULL);
++ pset_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;
+}
+ * fill-column: 79
+ * End:
+ */
-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 @@
+Index: linux-2.6.16/fs/reiser4/inode.c
+===================================================================
+--- /dev/null
++++ linux-2.6.16/fs/reiser4/inode.c
+@@ -0,0 +1,727 @@
+/* Copyright 2001, 2002, 2003 by Hans Reiser, licensing governed by reiser4/README */
+
+/* Inode specific operations. */
+
+/* return reiser4 internal tree which inode belongs to */
+/* Audited by: green(2002.06.17) */
-+reiser4_tree *reiser4_tree_by_inode(const struct inode *inode /* inode queried */ )
++reiser4_tree *tree_by_inode(const struct inode *inode /* inode queried */ )
+{
+ assert("nikita-256", inode != NULL);
+ assert("nikita-257", inode->i_sb != NULL);
-+ return reiser4_get_tree(inode->i_sb);
++ return get_tree(inode->i_sb);
+}
+
+/* return reiser4-specific inode flags */
+}
+
+/* set reiser4-specific flag @f in @inode */
-+void reiser4_inode_set_flag(struct inode *inode, reiser4_file_plugin_flags f)
++void 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 reiser4_inode_clr_flag(struct inode *inode, reiser4_file_plugin_flags f)
++void 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 reiser4_inode_get_flag(const struct inode *inode,
-+ reiser4_file_plugin_flags f)
++int 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));
+ case S_IFREG:
+ assert("vs-46", fplug != NULL);
+ assert("vs-43", (fplug->h.id == UNIX_FILE_PLUGIN_ID ||
-+ fplug->h.id == CRYPTCOMPRESS_FILE_PLUGIN_ID));
++ fplug->h.id == CRC_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;
+ 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 */ )
+{
+ 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);
-+ set_plugin(&state->pset, PSET_SD, item_plugin_to_plugin(iplug));
++ plugin_set_sd(&state->pset, 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)
-+ result = finish_pset(inode);
++ 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));
++ }
++ }
+ }
+ zrelse(coord->node);
+ return result;
+ if (result == 0) {
+ /* initialize stat-data seal */
+ spin_lock_inode(inode);
-+ reiser4_seal_init(&info->sd_seal, &coord, key);
++ seal_init(&info->sd_seal, &coord, key);
+ info->sd_coord = coord;
+ spin_unlock_inode(inode);
+
+ 0);
+ /* load detached directory cursors for stateless
+ * directory readers (NFS). */
-+ reiser4_load_cursors(inode);
++ load_cursors(inode);
+
+ /* Check the opened inode for consistency. */
+ result =
+/* hook for kmem_cache_create */
+void loading_init_once(reiser4_inode * info)
+{
-+ mutex_init(&info->loading);
++ sema_init(&info->loading, 1);
+}
+
+/* for reiser4_alloc_inode */
+void loading_alloc(reiser4_inode * info)
+{
-+ assert("vs-1717", !mutex_is_locked(&info->loading));
++#if REISER4_DEBUG
++ assert("vs-1717", down_trylock(&info->loading) == 0);
++ up(&info->loading);
++#endif
+}
+
+/* for reiser4_destroy */
+void loading_destroy(reiser4_inode * info)
+{
-+ assert("vs-1717a", !mutex_is_locked(&info->loading));
++#if REISER4_DEBUG
++ assert("vs-1717", down_trylock(&info->loading) == 0);
++ up(&info->loading);
++#endif
+}
+
-+static void loading_begin(reiser4_inode * info)
++static void loading_down(reiser4_inode * info)
+{
-+ mutex_lock(&info->loading);
++ down(&info->loading);
+}
+
-+static void loading_end(reiser4_inode * info)
++static void loading_up(reiser4_inode * info)
+{
-+ mutex_unlock(&info->loading);
++ up(&info->loading);
+}
+
+/**
+ * @silent:
+ *
+ * This is our helper function a la iget(). This is be called by
-+ * lookup_common() and reiser4_read_super(). Return inode locked or error
++ * reiser4_lookup() and reiser4_read_super(). Return inode locked or error
+ * encountered.
+ */
+struct inode *reiser4_iget(struct super_block *super, const reiser4_key *key,
+ return ERR_PTR(RETERR(-ENOMEM));
+ if (is_bad_inode(inode)) {
+ warning("nikita-304", "Bad inode found");
-+ reiser4_print_key("key", key);
++ print_key("key", key);
+ iput(inode);
+ return ERR_PTR(RETERR(-EIO));
+ }
+ is the reiser4 repacker, see repacker-related functions in
+ plugin/item/extent.c */
+ if (!is_inode_loaded(inode)) {
-+ loading_begin(info);
++ loading_down(info);
+ if (!is_inode_loaded(inode)) {
+ /* locking: iget5_locked returns locked inode */
+ assert("nikita-1941", !is_inode_loaded(inode));
+ read_inode() to read stat data from the disk */
+ result = read_inode(inode, key, silent);
+ } else
-+ loading_end(info);
++ loading_up(info);
+ }
+
+ if (inode->i_state & I_NEW)
+
+ if (is_bad_inode(inode)) {
+ assert("vs-1717", result != 0);
-+ loading_end(info);
++ loading_up(info);
+ iput(inode);
+ inode = ERR_PTR(result);
+ } else if (REISER4_DEBUG) {
+ build_sd_key(inode, &found_key);
+ if (!keyeq(&found_key, key)) {
+ warning("nikita-305", "Wrong key in sd");
-+ reiser4_print_key("sought for", key);
-+ reiser4_print_key("found", &found_key);
++ print_key("sought for", key);
++ print_key("found", &found_key);
+ }
+ if (inode->i_nlink == 0) {
+ warning("nikita-3559", "Unlinked inode found: %llu\n",
+ assert("zam-988", is_reiser4_inode(inode));
+
+ if (!is_inode_loaded(inode)) {
-+ reiser4_inode_set_flag(inode, REISER4_LOADED);
-+ loading_end(reiser4_inode_data(inode));
++ inode_set_flag(inode, REISER4_LOADED);
++ loading_up(reiser4_inode_data(inode));
+ }
+}
+
+ assert("nikita-1934", inode != NULL);
+
+ /* clear LOADED bit */
-+ reiser4_inode_clr_flag(inode, REISER4_LOADED);
++ inode_clr_flag(inode, REISER4_LOADED);
+ make_bad_inode(inode);
+ return;
+}
+ 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);
+ return reiser4_inode_data(inode)->pset->cluster;
+}
+
-+file_plugin *inode_create_plugin(const struct inode * inode)
++regular_plugin *inode_regular_plugin(const struct inode * inode)
+{
+ assert("edward-1329", inode != NULL);
-+ return reiser4_inode_data(inode)->pset->create;
++ return reiser4_inode_data(inode)->pset->regular_entry;
+}
+
+digest_plugin *inode_digest_plugin(const struct inode * inode)
+ 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;
+ 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);
++ inode_clr_flag(inode, REISER4_SDLEN_KNOWN);
+}
+
-+void inode_clr_extension(struct inode *inode, sd_ext_bits ext)
++void
++inode_set_plugin(struct inode *inode, reiser4_plugin * plug, pset_member memb)
+{
-+ reiser4_inode *state;
-+
-+ assert("vpf-1926", inode != NULL);
-+ assert("vpf-1927", ext < LAST_SD_EXTENSION);
-+ assert("vpf-1928", spin_inode_is_locked(inode));
++ assert("nikita-2718", inode != NULL);
++ assert("nikita-2719", plug != NULL);
+
-+ 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);
++ reiser4_inode_data(inode)->plugin_mask |= (1 << memb);
+}
+
+void inode_check_scale_nolock(struct inode *inode, __u64 old, __u64 new)
+{
+ assert("edward-1287", inode != NULL);
+ if (!dscale_fit(old, new))
-+ reiser4_inode_clr_flag(inode, REISER4_SDLEN_KNOWN);
++ inode_clr_flag(inode, REISER4_SDLEN_KNOWN);
+ return;
+}
+
+ blk = reiser4_inode_data(inode)->vroot;
+ spin_unlock_inode(inode);
+ if (!disk_addr_eq(&UBER_TREE_ADDR, &blk))
-+ result = zlook(reiser4_tree_by_inode(inode), &blk);
++ result = zlook(tree_by_inode(inode), &blk);
+ else
+ result = NULL;
+ return result;
+
+#if REISER4_DEBUG
+
-+void reiser4_inode_invariant(const struct inode *inode)
++void inode_invariant(const struct inode *inode)
+{
+ assert("nikita-3077", spin_inode_is_locked(inode));
+}
+ fill-column: 120
+ End:
+*/
-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 @@
+Index: linux-2.6.16/fs/reiser4/inode.h
+===================================================================
+--- /dev/null
++++ linux-2.6.16/fs/reiser4/inode.h
+@@ -0,0 +1,430 @@
+/* Copyright 2001, 2002, 2003 by Hans Reiser, licensing governed by reiser4/README */
+
+/* Inode functions. */
+ REISER4_IMMUTABLE = 2,
+ /* inode was read from storage */
+ REISER4_LOADED = 3,
-+ /* this bit is set for symlinks. inode->i_private points to target
++ /* this bit is set for symlinks. inode->u.generic_ip 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
+ * 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,
-+ /* This flag indicates that file plugin conversion is in progress */
-+ REISER4_FILE_CONV_IN_PROGRESS = 11
++ REISER4_PART_IN_CONV = 10
+} reiser4_file_plugin_flags;
+
+/* state associated with each inode.
+struct reiser4_inode {
+ /* spin lock protecting fields of this structure. */
+ spinlock_t guard;
-+ /* main plugin set that control the file
-+ (see comments in plugin/plugin_set.c) */
++ /* object plugins */
+ plugin_set *pset;
-+ /* plugin set for inheritance
-+ (see comments in plugin/plugin_set.c) */
++ /* plugins set for inheritance */
+ plugin_set *hset;
+ /* high 32 bits of object id */
+ oid_hi_t oid_hi;
+ __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;
+ unsigned long flags;
+ union {
+ /* fields specific to unix_file plugin */
-+ struct unix_file_info unix_file_info;
-+ /* fields specific to cryptcompress file plugin */
-+ struct cryptcompress_info cryptcompress_info;
++ unix_file_info_t unix_file_info;
++ /* fields specific to cryptcompress plugin */
++ cryptcompress_info_t 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;
+ /* block number of virtual root for this object. See comment above
+ * fs/reiser4/search.c:handle_vroot() */
+ reiser4_block_nr vroot;
-+ struct mutex loading;
++ struct semaphore loading;
+};
+
+void loading_init_once(reiser4_inode *);
+void loading_alloc(reiser4_inode *);
+void loading_destroy(reiser4_inode *);
+
-+struct reiser4_inode_object {
++typedef 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, struct reiser4_inode_object, vfs_inode)->p;
++ return &container_of(inode, 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, struct reiser4_inode_object, p)->vfs_inode;
++ return &container_of(r4_inode, reiser4_inode_object, p)->vfs_inode;
+}
+
+/*
+#endif
+
+/* return inode in which @uf_info is embedded */
-+static inline struct inode *
-+unix_file_info_to_inode(const struct unix_file_info * uf_info)
++static inline struct inode *unix_file_info_to_inode(const unix_file_info_t *
++ uf_info)
+{
-+ return &container_of(uf_info, struct reiser4_inode_object,
++ return &container_of(uf_info, 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 *reiser4_tree_by_inode(const struct inode *inode);
++extern reiser4_tree *tree_by_inode(const struct inode *inode);
+
+#if REISER4_DEBUG
-+extern void reiser4_inode_invariant(const struct inode *inode);
++extern void inode_invariant(const struct inode *inode);
+extern int inode_has_no_jnodes(reiser4_inode *);
+#else
-+#define reiser4_inode_invariant(inode) noop
++#define inode_invariant(inode) noop
+#endif
+
+static inline int spin_inode_is_locked(const struct inode *inode)
+ LOCK_CNT_INC(spin_locked_inode);
+ LOCK_CNT_INC(spin_locked);
+
-+ reiser4_inode_invariant(inode);
++ inode_invariant(inode);
+}
+
+/**
+ assert("nikita-1375", LOCK_CNT_GTZ(spin_locked_inode));
+ assert("nikita-1376", LOCK_CNT_GTZ(spin_locked));
+
-+ reiser4_inode_invariant(inode);
++ inode_invariant(inode);
+
+ LOCK_CNT_DEC(spin_locked_inode);
+ LOCK_CNT_DEC(spin_locked);
+ 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);
+
+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 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);
++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);
+
+/* has inode been initialized? */
+static inline int
+is_inode_loaded(const struct inode *inode /* inode queried */ )
+{
+ assert("nikita-1120", inode != NULL);
-+ return reiser4_inode_get_flag(inode, REISER4_LOADED);
++ return inode_get_flag(inode, REISER4_LOADED);
+}
+
+extern file_plugin *inode_file_plugin(const struct inode *inode);
+extern compression_mode_plugin *inode_compression_mode_plugin(const struct inode
+ *inode);
+extern cluster_plugin *inode_cluster_plugin(const struct inode *inode);
-+extern file_plugin *inode_create_plugin(const struct inode *inode);
++extern regular_plugin *inode_regular_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.
+ */
+ -- __i->field; \
+})
+
-+/* See comment before reiser4_readdir_common() for description. */
++/* See comment before readdir_common() for description. */
+static inline struct list_head *get_readdir_list(const struct inode *inode)
+{
+ return &reiser4_inode_data(inode)->lists.readdir_list;
+ fill-column: 120
+ End:
+*/
-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
+Index: linux-2.6.16/fs/reiser4/ioctl.h
+===================================================================
+--- /dev/null
++++ linux-2.6.16/fs/reiser4/ioctl.h
@@ -0,0 +1,41 @@
+/* Copyright 2001, 2002, 2003 by Hans Reiser, licensing governed by
+ * reiser4/README */
+ scroll-step: 1
+ End:
+*/
-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 @@
+Index: linux-2.6.16/fs/reiser4/jnode.c
+===================================================================
+--- /dev/null
++++ linux-2.6.16/fs/reiser4/jnode.c
+@@ -0,0 +1,1921 @@
+/* Copyright 2001, 2002, 2003, 2004 by Hans Reiser, licensing governed by
+ * reiser4/README */
+/* Jnode manipulation functions. */
+#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 struct kmem_cache *_jnode_slab = NULL;
++static kmem_cache_t *_jnode_slab = NULL;
+
+static void jnode_set_type(jnode * node, jnode_type type);
+static int jdelete(jnode * node);
+/* hash table support */
+
+/* compare two jnode keys for equality. Used by hash-table macros */
-+static inline int jnode_key_eq(const struct jnode_key * k1,
-+ const struct jnode_key * k2)
++static inline int jnode_key_eq(const jnode_key_t * k1, const jnode_key_t * k2)
+{
+ assert("nikita-2350", k1 != NULL);
+ assert("nikita-2351", k2 != NULL);
+}
+
+/* Hash jnode by its key (inode plus offset). Used by hash-table macros */
-+static inline __u32 jnode_key_hashfn(j_hash_table * table,
-+ const struct jnode_key * key)
++static inline __u32
++jnode_key_hashfn(j_hash_table * table, const jnode_key_t * key)
+{
+ assert("nikita-2352", key != NULL);
+ assert("nikita-3346", IS_POW(table->_buckets));
+}
+
+/* The hash table definition */
-+#define KMALLOC(size) reiser4_vmalloc(size)
++#define KMALLOC(size) vmalloc(size)
+#define KFREE(ptr, size) vfree(ptr)
-+TYPE_SAFE_HASH_DEFINE(j, jnode, struct jnode_key, key.j, link.j,
-+ jnode_key_hashfn, jnode_key_eq);
++TYPE_SAFE_HASH_DEFINE(j, jnode, jnode_key_t, key.j, link.j, jnode_key_hashfn,
++ jnode_key_eq);
+#undef KFREE
+#undef KMALLOC
+
+/* exported functions to allocate/free jnode objects outside this file */
+jnode *jalloc(void)
+{
-+ jnode *jal = kmem_cache_alloc(_jnode_slab, reiser4_ctx_gfp_mask_get());
++ jnode *jal = kmem_cache_alloc(_jnode_slab, get_gfp_mask());
+ return jal;
+}
+
+/* look for jnode with given mapping and offset within hash table */
+jnode *jlookup(reiser4_tree * tree, oid_t objectid, unsigned long index)
+{
-+ struct jnode_key jkey;
++ jnode_key_t jkey;
+ jnode *node;
+
+ assert("nikita-2353", tree != NULL);
+ jnode *node;
+
+ assert("vs-1694", mapping->host != NULL);
-+ tree = reiser4_tree_by_inode(mapping->host);
++ tree = tree_by_inode(mapping->host);
+
+ read_lock_tree(tree);
+ node = jfind_nolock(mapping, index);
+
+/* 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 ->
-+ reiser4_uncapture_jnode */
++ uncapture_jnode */
+void unhash_unformatted_jnode(jnode * node)
+{
+ assert("vs-1445", jnode_is_unformatted(node));
+ * allocate new jnode, insert it, and also insert into radix tree for the
+ * given inode/mapping.
+ */
-+static jnode *find_get_jnode(reiser4_tree * tree,
-+ struct address_space *mapping,
-+ oid_t oid, unsigned long index)
++jnode *find_get_jnode(reiser4_tree * tree, struct address_space *mapping,
++ oid_t oid, unsigned long index)
+{
+ jnode *result;
+ jnode *shadow;
+ if (unlikely(result == NULL))
+ return ERR_PTR(RETERR(-ENOMEM));
+
-+ preload = radix_tree_preload(reiser4_ctx_gfp_mask_get());
++ preload = radix_tree_preload(get_gfp_mask());
+ if (preload != 0)
+ return ERR_PTR(preload);
+
+ if (likely(result != NULL))
+ return jref(result);
+
-+ tree = reiser4_tree_by_page(pg);
++ tree = tree_by_page(pg);
+
+ /* check hash-table first */
+ result = jfind(pg->mapping, pg->index);
+ 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;
+ assert("umka-176", pg != NULL);
+ assert("nikita-2394", PageLocked(pg));
+
-+ result = do_jget(reiser4_tree_by_page(pg), pg);
++ result = do_jget(tree_by_page(pg), pg);
+
+ if (REISER4_DEBUG && !IS_ERR(result)) {
+ assert("nikita-3210", result == jprivate(pg));
+ 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,
+ }
+ unlock_page(page);
+}
-+#endif /* 0 */
+
+/* return @node page locked.
+
+
+/* Lock a page attached to jnode, create and attach page to jnode if it had no
+ * one. */
-+static struct page *jnode_get_page_locked(jnode * node, gfp_t gfp_flags)
++struct page *jnode_get_page_locked(jnode * node, gfp_t gfp_flags)
+{
+ struct page *page;
+
+ unlock_page(page);
+ return 0;
+ }
-+ return reiser4_page_io(page, node, READ, reiser4_ctx_gfp_mask_get());
++ return page_io(page, node, READ, get_gfp_mask());
+}
+
+#if REISER4_DEBUG
+ int result = 0;
+ int parsed;
+
-+ assert("nikita-3010", reiser4_schedulable());
++ assert("nikita-3010", schedulable());
+
+ prefetchw(&node->pg);
+
+{
+ struct page *page;
+
-+ page = jnode_get_page_locked(node, reiser4_ctx_gfp_mask_get());
++ page = jnode_get_page_locked(node, get_gfp_mask());
+ if (IS_ERR(page))
+ return PTR_ERR(page);
+
+ 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
+static struct address_space *mapping_znode(const jnode * node)
+{
+ /* all znodes belong to fake inode */
-+ return reiser4_get_super_fake(jnode_get_tree(node)->super)->i_mapping;
++ return get_super_fake(jnode_get_tree(node)->super)->i_mapping;
+}
+
+/* ->index() method for znodes */
+ znode *clone;
+
+ assert("vs-1430", jnode_is_znode(node));
-+ clone = zalloc(reiser4_ctx_gfp_mask_get());
++ clone = zalloc(get_gfp_mask());
+ if (clone == NULL)
+ return ERR_PTR(RETERR(-ENOMEM));
+ zinit(clone, NULL, current_tree);
+ jnode_free(node, jtype);
+ /* @node is no longer valid pointer */
+ if (page != NULL)
-+ reiser4_drop_page(page);
++ drop_page(page);
+ } else {
+ /* busy check failed: reference was acquired by concurrent
+ * thread. */
+ write_unlock_tree(tree);
+ jnode_free(node, jtype);
+ if (page != NULL) {
-+ reiser4_drop_page(page);
++ drop_page(page);
+ }
+ } else {
+ /* busy check failed: reference was acquired by concurrent
+ functionality (these j-nodes are not in any hash table) just for reading
+ from and writing to disk. */
+
-+jnode *reiser4_alloc_io_head(const reiser4_block_nr * block)
++jnode *alloc_io_head(const reiser4_block_nr * block)
+{
+ jnode *jal = jalloc();
+
+ return jal;
+}
+
-+void reiser4_drop_io_head(jnode * node)
++void drop_io_head(jnode * node)
+{
+ assert("zam-648", jnode_get_type(node) == JNODE_IO_HEAD);
+
+ ("%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),
+ fill-column: 80
+ End:
+*/
-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 @@
+Index: linux-2.6.16/fs/reiser4/jnode.h
+===================================================================
+--- /dev/null
++++ linux-2.6.16/fs/reiser4/jnode.h
+@@ -0,0 +1,711 @@
+/* Copyright 2001, 2002, 2003, 2004 by Hans Reiser, licensing governed by
+ * reiser4/README */
+
+#include "key.h"
+#include "debug.h"
+#include "dformat.h"
-+#include "page_cache.h"
+#include "context.h"
+
+#include "plugin/plugin.h"
+/* declare hash table of znodes */
+TYPE_SAFE_HASH_DECLARE(z, znode);
+
-+struct jnode_key {
++typedef struct {
+ __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
+ /* znodes are hashed by block number */
+ reiser4_block_nr z;
+ /* unformatted nodes are hashed by mapping plus offset */
-+ struct jnode_key j;
++ jnode_key_t j;
+ } key;
+
+ /* THIRD CACHE LINE */
+ /* 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 */
+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;
+}
+
+/* Jnode flush interface. */
-+extern reiser4_blocknr_hint *reiser4_pos_hint(flush_pos_t * pos);
-+extern flush_queue_t *reiser4_pos_fq(flush_pos_t * pos);
++extern reiser4_blocknr_hint *pos_hint(flush_pos_t * pos);
++extern flush_queue_t *pos_fq(flush_pos_t * pos);
+
+/* FIXME-VS: these are used in plugin/item/extent.c */
+
+ 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)
+
+static inline int jload(jnode *node)
+{
-+ return jload_gfp(node, reiser4_ctx_gfp_mask_get(), 1);
++ return jload_gfp(node, get_gfp_mask(), 1);
+}
+
+extern int jinit_new(jnode *, gfp_t) NONNULL;
+
+void jload_prefetch(jnode *);
+
-+extern jnode *reiser4_alloc_io_head(const reiser4_block_nr * block) NONNULL;
-+extern void reiser4_drop_io_head(jnode * node) NONNULL;
++extern jnode *alloc_io_head(const reiser4_block_nr * block) NONNULL;
++extern void drop_io_head(jnode * node) NONNULL;
+
+static inline reiser4_tree *jnode_get_tree(const jnode * node)
+{
+{
+ assert("jmacd-509", node != NULL);
+ assert("jmacd-510", atomic_read(&node->x_count) > 0);
-+ assert("zam-926", reiser4_schedulable());
++ assert("zam-926", schedulable());
+ LOCK_CNT_DEC(x_refs);
+
+ rcu_read_lock();
+ jput_final(node);
+ } else
+ rcu_read_unlock();
-+ assert("nikita-3473", reiser4_schedulable());
++ assert("nikita-3473", schedulable());
+}
+
+extern void jrelse(jnode * node);
+ fill-column: 120
+ End:
+*/
-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 @@
+Index: linux-2.6.16/fs/reiser4/kassign.c
+===================================================================
+--- /dev/null
++++ linux-2.6.16/fs/reiser4/kassign.c
+@@ -0,0 +1,659 @@
+/* Copyright 2001, 2002, 2003, 2004 by Hans Reiser, licensing governed by
+ * reiser4/README */
+
+
+ assert("nikita-2863", key != NULL);
+ if (get_key_type(key) != KEY_FILE_NAME_MINOR)
-+ reiser4_print_key("oops", key);
++ print_key("oops", key);
+ assert("nikita-2864", get_key_type(key) == KEY_FILE_NAME_MINOR);
+
+ if (REISER4_LARGE_KEY)
+
+/* opposite to pack_string(). Takes value produced by pack_string(), restores
+ * string encoded in it and stores result in @buf */
-+char * reiser4_unpack_string(__u64 value, char *buf)
++char *unpack_string(__u64 value, char *buf)
+{
+ do {
+ *buf = value >> (64 - 8);
+
+ c = buf;
+ if (REISER4_LARGE_KEY) {
-+ c = reiser4_unpack_string(get_key_ordering(key) &
-+ ~fibration_mask, c);
-+ c = reiser4_unpack_string(get_key_fulloid(key), c);
++ c = unpack_string(get_key_ordering(key) & ~fibration_mask, c);
++ c = unpack_string(get_key_fulloid(key), c);
+ } else
-+ c = reiser4_unpack_string(get_key_fulloid(key) &
-+ ~fibration_mask, c);
-+ reiser4_unpack_string(get_key_offset(key), c);
++ c = unpack_string(get_key_fulloid(key) & ~fibration_mask, c);
++ unpack_string(get_key_offset(key), c);
+ return buf;
+}
+
+ fill-column: 120
+ End:
+*/
-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
+Index: linux-2.6.16/fs/reiser4/kassign.h
+===================================================================
+--- /dev/null
++++ linux-2.6.16/fs/reiser4/kassign.h
@@ -0,0 +1,110 @@
+/* Copyright 2001, 2002, 2003, 2004 by Hans Reiser, licensing governed by
+ * reiser4/README */
+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 *reiser4_unpack_string(__u64 value, char *buf);
++extern char *unpack_string(__u64 value, char *buf);
+extern void complete_entry_key(const struct inode *dir, const char *name,
+ int len, reiser4_key *result);
+
+ fill-column: 120
+ End:
+*/
-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
+Index: linux-2.6.16/fs/reiser4/key.c
+===================================================================
+--- /dev/null
++++ linux-2.6.16/fs/reiser4/key.c
@@ -0,0 +1,137 @@
+/* Copyright 2001, 2002, 2003 by Hans Reiser, licensing governed by reiser4/README */
+
+}
+
+/* minimal possible key in the tree. Return pointer to the static storage. */
-+const reiser4_key *reiser4_min_key(void)
++const reiser4_key *min_key(void)
+{
+ return &MINIMAL_KEY;
+}
+
+/* maximum possible key in the tree. Return pointer to the static storage. */
-+const reiser4_key *reiser4_max_key(void)
++const reiser4_key *max_key(void)
+{
+ return &MAXIMAL_KEY;
+}
+}
+
+/* debugging aid: print human readable information about key */
-+void reiser4_print_key(const char *prefix /* prefix to print */ ,
++void print_key(const char *prefix /* prefix to print */ ,
+ const reiser4_key * key /* key to print */ )
+{
+ /* turn bold on */
+ char *c;
+
+ c = buf;
-+ c = reiser4_unpack_string(get_key_ordering(key), c);
-+ reiser4_unpack_string(get_key_fulloid(key), c);
++ c = unpack_string(get_key_ordering(key), c);
++ unpack_string(get_key_fulloid(key), c);
+ printk("[%s", buf);
+ if (is_longname_key(key))
+ /*
+ /*
+ * whole name is stored in the key.
+ */
-+ reiser4_unpack_string(get_key_offset(key), buf);
++ unpack_string(get_key_offset(key), buf);
+ printk("%s]\n", buf);
+ }
+ } else {
+ fill-column: 120
+ End:
+*/
-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
+Index: linux-2.6.16/fs/reiser4/key.h
+===================================================================
+--- /dev/null
++++ linux-2.6.16/fs/reiser4/key.h
@@ -0,0 +1,384 @@
+/* Copyright 2000, 2001, 2002, 2003 by Hans Reiser, licensing governed by reiser4/README */
+
+void reiser4_key_init(reiser4_key * key);
+
+/* minimal possible key in the tree. Return pointer to the static storage. */
-+extern const reiser4_key *reiser4_min_key(void);
-+extern const reiser4_key *reiser4_max_key(void);
++extern const reiser4_key *min_key(void);
++extern const reiser4_key *max_key(void);
+
+/* helper macro for keycmp() */
+#define KEY_DIFF(k1, k2, field) \
+#define KEY_BUF_LEN (80)
+
+#if REISER4_DEBUG
-+extern void reiser4_print_key(const char *prefix, const reiser4_key * key);
++extern void print_key(const char *prefix, const reiser4_key * key);
+#else
-+#define reiser4_print_key(p,k) noop
++#define print_key(p,k) noop
+#endif
+
+/* __FS_REISERFS_KEY_H__ */
+ fill-column: 120
+ End:
+*/
-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 @@
+Index: linux-2.6.16/fs/reiser4/ktxnmgrd.c
+===================================================================
+--- /dev/null
++++ linux-2.6.16/fs/reiser4/ktxnmgrd.c
+@@ -0,0 +1,214 @@
+/* Copyright 2002, 2003 by Hans Reiser, licensing governed by reiser4/README */
+/* Transaction manager daemon. */
+
+#include <linux/kernel.h>
+#include <linux/writeback.h>
+#include <linux/kthread.h>
-+#include <linux/freezer.h>
+
+static int scan_mgr(struct super_block *);
+
+#undef set_comm
+
+/**
-+ * reiser4_init_ktxnmgrd - initialize ktxnmgrd context and start kernel daemon
++ * 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 reiser4_init_ktxnmgrd(struct super_block *super)
++int init_ktxnmgrd(struct super_block *super)
+{
+ txn_mgr *mgr;
+ ktxnmgrd_context *ctx;
+
+ assert("zam-1014", mgr->daemon == NULL);
+
-+ ctx = kmalloc(sizeof(ktxnmgrd_context), reiser4_ctx_gfp_mask_get());
++ ctx = kmalloc(sizeof(ktxnmgrd_context), get_gfp_mask());
+ if (ctx == NULL)
+ return RETERR(-ENOMEM);
+
+}
+
+/**
-+ * reiser4_done_ktxnmgrd - stop kernel thread and frees ktxnmgrd context
++ * done_ktxnmgrd - stop kernel thread and frees ktxnmgrd context
+ * @mgr:
+ *
+ * This is called on umount. Stops ktxnmgrd and free t
+ */
-+void reiser4_done_ktxnmgrd(struct super_block *super)
++void done_ktxnmgrd(struct super_block *super)
+{
+ txn_mgr *mgr;
+
+ * fill-column: 120
+ * End:
+ */
-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
+Index: linux-2.6.16/fs/reiser4/ktxnmgrd.h
+===================================================================
+--- /dev/null
++++ linux-2.6.16/fs/reiser4/ktxnmgrd.h
@@ -0,0 +1,52 @@
+/* Copyright 2001, 2002, 2003 by Hans Reiser, licensing governed by
+ * reiser4/README */
+ unsigned int rescan:1;
+};
+
-+extern int reiser4_init_ktxnmgrd(struct super_block *);
-+extern void reiser4_done_ktxnmgrd(struct super_block *);
++extern int init_ktxnmgrd(struct super_block *);
++extern void done_ktxnmgrd(struct super_block *);
+
+extern void ktxnmgrd_kick(txn_mgr * mgr);
+extern int is_current_ktxnmgrd(void);
+ fill-column: 120
+ End:
+*/
-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 @@
+Index: linux-2.6.16/fs/reiser4/lock.c
+===================================================================
+--- /dev/null
++++ linux-2.6.16/fs/reiser4/lock.c
+@@ -0,0 +1,1261 @@
+/* Copyright 2001, 2002, 2003 by Hans Reiser, licensing governed by
+ * reiser4/README */
+
+
+/* Znode lock and capturing intertwining. */
+/* In current implementation we capture formatted nodes before locking
-+ 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.
++ 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.
+
+ 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 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. */
++ 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. */
+
+#include "debug.h"
+#include "txnmgr.h"
+ /* 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++);
-+ reiser4_ctx_gfp_mask_set();
++ set_gfp_mask();
+
+ /* add lock handle to the head of znode's list of owners */
+ list_add(&handle->owners_link, &node->lock.owners);
+ /* remove lock handle from lock_stack's list of locks */
+ list_del(&handle->locks_link);
+ ON_DEBUG(handle->owner->nr_locks--);
-+ reiser4_ctx_gfp_mask_set();
++ set_gfp_mask();
+ assert("reiser4-6",
+ ergo(list_empty_careful(&handle->owner->locks),
+ handle->owner->nr_locks == 0));
+/* Actually locks an object knowing that we are able to do this */
+static void lock_object(lock_stack * owner)
+{
-+ struct lock_request *request;
++ lock_request *request;
+ znode *node;
+
+ request = &owner->request;
+ 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);
+
+ list_del(&requestor->requestors_link);
+}
+
++
+static void invalidate_all_lock_requests(znode * node)
+{
+ lock_stack *requestor, *tmp;
+ */
+
+ /* 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 */
+ assert("zam-101", znode_is_locked(node));
+
+ /* Adjust a number of high priority owners of this lock */
-+ assert("nikita-1836", node->lock.nr_hipri_owners >= hipri);
-+ node->lock.nr_hipri_owners -= hipri;
++ node->lock.nr_hipri_owners += hipri;
++ assert("nikita-1836", node->lock.nr_hipri_owners >= 0);
+
+ /* Handle znode deallocation on last write-lock release. */
+ if (znode_is_wlocked_once(node)) {
+ node = owner->request.node;
+ lock = &node->lock;
+
-+ assert("nikita-3340", reiser4_schedulable());
++ assert("nikita-3340", schedulable());
+ assert("nikita-3341", request_is_deadlock_safe(node,
+ ZNODE_READ_LOCK,
+ ZNODE_LOCK_LOPRI));
+
+ if (likely(result != -EINVAL)) {
+ spin_lock_znode(node);
-+ result = reiser4_try_capture(ZJNODE(node), ZNODE_READ_LOCK, 0);
++ result = try_capture(ZJNODE(node), ZNODE_READ_LOCK, 0);
+ spin_unlock_znode(node);
+ spin_lock_zlock(lock);
+ if (unlikely(result != 0)) {
+ /* Check that the lock handle is initialized and isn't already being
+ * used. */
+ assert("jmacd-808", handle->owner == NULL);
-+ assert("nikita-3026", reiser4_schedulable());
++ assert("nikita-3026", 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(),
+ * 1. read of aligned word is atomic with respect to writes to
+ * this word
+ *
-+ * 2. false negatives are handled in reiser4_try_capture().
++ * 2. false negatives are handled in try_capture().
+ *
+ * 3. false positives are impossible.
+ *
+ *
+ * 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 reiser4_invalidate_lock(),
-+ * which marks znode as JNODE_IS_DYING under zlock spin
++ * always preceded by the call to 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.
+ *
+ /*
+ * unlock zlock spin lock here. It is possible for
+ * longterm_unlock_znode() to sneak in here, but there
-+ * is no harm: reiser4_invalidate_lock() will mark znode
-+ * as JNODE_IS_DYING and this will be noted by
++ * is no harm: 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 = reiser4_try_capture(ZJNODE(node), mode, cap_flags);
++ ret = try_capture(ZJNODE(node), mode, cap_flags);
+ spin_unlock_znode(node);
+ spin_lock_zlock(lock);
+ if (unlikely(ret != 0)) {
+
+ /* 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. */
-+ ret = reiser4_prepare_to_sleep(owner);
-+ if (unlikely(ret != 0))
++
++ /* 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)) {
+ break;
++ }
+
+ assert_spin_locked(&(node->lock.guard));
+ if (hipri) {
+ a znode ... */
+ spin_unlock_zlock(lock);
+ /* ... and sleep */
-+ reiser4_go_to_sleep(owner);
++ go_to_sleep(owner);
+ if (owner->request.mode == ZNODE_NO_LOCK)
+ goto request_is_done;
+ spin_lock_zlock(lock);
+
+/* lock object invalidation means changing of lock object state to `INVALID'
+ and waiting for all other processes to cancel theirs lock requests. */
-+void reiser4_invalidate_lock(lock_handle * handle /* path to lock
-+ * owner and lock
-+ * object is being
-+ * invalidated. */ )
++void invalidate_lock(lock_handle * handle /* path to lock
++ * owner and lock
++ * object is being
++ * invalidated. */ )
+{
+ znode *node = handle->node;
+ lock_stack *owner = handle->owner;
+ INIT_LIST_HEAD(&owner->requestors_link);
+ spin_lock_init(&owner->sguard);
+ owner->curpri = 1;
-+ init_waitqueue_head(&owner->wait);
++ sema_init(&owner->sema, 0);
+}
+
+/* Initializes lock object. */
+}
+
+/* after getting -E_DEADLOCK we unlock znodes until this function returns false */
-+int reiser4_check_deadlock(void)
++int check_deadlock(void)
+{
+ lock_stack *owner = get_current_lock_stack();
+ return atomic_read(&owner->nr_signaled) != 0;
+
+/* Before going to sleep we re-check "release lock" requests which might come from threads with hi-pri lock
+ priorities. */
-+int reiser4_prepare_to_sleep(lock_stack * owner)
++int 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 */
+/* Wakes up a single thread */
+void __reiser4_wake_up(lock_stack * owner)
+{
-+ atomic_set(&owner->wakeup, 1);
-+ wake_up(&owner->wait);
++ up(&owner->sema);
+}
+
+/* Puts a thread to sleep */
-+void reiser4_go_to_sleep(lock_stack * owner)
++void go_to_sleep(lock_stack * owner)
+{
+ /* Well, we might sleep here, so holding of any spinlocks is no-no */
-+ assert("nikita-3027", reiser4_schedulable());
-+
-+ wait_event(owner->wait, atomic_read(&owner->wakeup));
-+ atomic_set(&owner->wakeup, 0);
++ assert("nikita-3027", schedulable());
++ /* return down_interruptible(&owner->sema); */
++ down(&owner->sema);
+}
+
+int lock_stack_isclean(lock_stack * owner)
+ fill-column: 79
+ End:
+*/
-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 @@
+Index: linux-2.6.16/fs/reiser4/lock.h
+===================================================================
+--- /dev/null
++++ linux-2.6.16/fs/reiser4/lock.h
+@@ -0,0 +1,272 @@
+/* Copyright 2001, 2002, 2003 by Hans Reiser, licensing governed by reiser4/README */
+
+/* Long term locking data structures. See lock.c for details. */
+#include <linux/spinlock.h>
+#include <linux/pagemap.h> /* for PAGE_CACHE_SIZE */
+#include <asm/atomic.h>
-+#include <linux/wait.h>
++#include <asm/semaphore.h>
+
+/* Per-znode lock object */
+struct zlock {
+ struct list_head owners_link;
+};
+
-+struct lock_request {
++typedef struct lock_request {
+ /* A pointer to uninitialized link object */
+ lock_handle *handle;
+ /* A pointer to the object we want to lock */
+ 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 {
+ This is only accessed by the current thread and thus requires no
+ locking.
+ */
-+ 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;
++ 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;
+#if REISER4_DEBUG
+ int nr_locks; /* number of lock handles in the above list */
+#endif
+};
+
++
+/*
+ User-visible znode locking functions
+*/
+
+extern void longterm_unlock_znode(lock_handle * handle);
+
-+extern int reiser4_check_deadlock(void);
++extern int check_deadlock(void);
+
+extern lock_stack *get_current_lock_stack(void);
+
+extern void move_lh(lock_handle * new, lock_handle * old);
+extern void copy_lh(lock_handle * new, lock_handle * old);
+
-+extern int reiser4_prepare_to_sleep(lock_stack * owner);
-+extern void reiser4_go_to_sleep(lock_stack * owner);
++extern int prepare_to_sleep(lock_stack * owner);
++extern void go_to_sleep(lock_stack * owner);
+extern void __reiser4_wake_up(lock_stack * owner);
+
+extern int lock_stack_isclean(lock_stack * owner);
+/* 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 reiser4_invalidate_lock(lock_handle *);
++extern void invalidate_lock(lock_handle *);
+
+/* lock ordering is: first take zlock spin lock, then lock stack spin lock */
+#define spin_ordering_pred_stack(stack) \
+ spin_unlock(&(stack->sguard));
+}
+
++
+static inline void reiser4_wake_up(lock_stack * owner)
+{
+ spin_lock_stack(owner);
+ fill-column: 120
+ End:
+*/
-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
+Index: linux-2.6.16/fs/reiser4/oid.c
+===================================================================
+--- /dev/null
++++ linux-2.6.16/fs/reiser4/oid.c
@@ -0,0 +1,141 @@
+/* Copyright 2003 by Hans Reiser, licensing governed by reiser4/README */
+
+ scroll-step: 1
+ End:
+*/
-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 @@
+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 @@
+/* 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
+ 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 page_clear_jnode(), page
-+ reference counter is decreased.
++ 2. when jnode-to-page mapping is destroyed (by jnode_detach_page() and
++ page_detach_jnode()), page reference counter is decreased.
+
+ 3. on jload() reference counter on jnode page is increased, page is
+ kmapped and `referenced'.
+}
+
+/**
-+ * reiser4_init_formatted_fake - iget inodes for formatted nodes and bitmaps
++ * 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 reiser4_init_formatted_fake(struct super_block *super)
++int init_formatted_fake(struct super_block *super)
+{
+ struct inode *fake;
+ struct inode *bitmap;
+}
+
+/**
-+ * reiser4_done_formatted_fake - release inode used by formatted nodes and bitmaps
++ * 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 reiser4_done_formatted_fake(struct super_block *super)
++void 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;
+ }
+}
+
+/* return tree @page is in */
-+reiser4_tree *reiser4_tree_by_page(const struct page *page /* page to query */ )
++reiser4_tree *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;
+ struct page *page /* page to read */ )
+{
+ assert("nikita-2412", PagePrivate(page) && jprivate(page));
-+ return reiser4_page_io(page, jprivate(page), READ,
-+ reiser4_ctx_gfp_mask_get());
++ return page_io(page, jprivate(page), READ, get_gfp_mask());
+}
+
+/**
-+ * reiser4_page_io - submit single-page bio request
++ * page_io - submit single-page bio request
+ * @page: page to perform io for
+ * @node: jnode of page
+ * @rw: read or write
+ *
+ * Submits single page read or write.
+ */
-+int reiser4_page_io(struct page *page, jnode *node, int rw, gfp_t gfp)
++int page_io(struct page *page, jnode *node, int rw, gfp_t gfp)
+{
+ struct bio *bio;
+ int result;
+ bio = page_bio(page, node, rw, gfp);
+ if (!IS_ERR(bio)) {
+ if (rw == WRITE) {
-+ set_page_writeback(page);
++ SetPageWriteback(page);
+ unlock_page(page);
+ }
+ reiser4_submit_bio(rw, bio);
+ spin_unlock_jnode(node);
+
+ assert("nikita-2275", blocknr != (reiser4_block_nr) 0);
-+ assert("nikita-2276", !reiser4_blocknr_is_fake(&blocknr));
++ assert("nikita-2276", !blocknr_is_fake(&blocknr));
+
+ bio->bi_bdev = super->s_bdev;
+ /* fill bio->bi_sector before calling bio_add_page(), because
+}
+
+/* this function is internally called by jnode_make_dirty() */
-+int reiser4_set_page_dirty_internal(struct page *page)
++int set_page_dirty_internal(struct page *page)
+{
+ struct address_space *mapping;
+
+
+ if (!TestSetPageDirty(page)) {
+ if (mapping_cap_account_dirty(mapping))
-+ inc_zone_page_state(page, NR_FILE_DIRTY);
++ inc_page_state(nr_dirty);
+
+ __mark_inode_dirty(mapping->host, I_DIRTY_PAGES);
+ }
+
+ /* znode must be dirty ? */
-+ if (mapping->host == reiser4_get_super_fake(mapping->host->i_sb))
++ if (mapping->host == get_super_fake(mapping->host->i_sb))
+ assert("", JF_ISSET(jprivate(page), JNODE_DIRTY));
+ return 0;
+}
+
-+#if 0
++#if REISER4_DEBUG
++
++/**
++ * can_hit_entd
++ *
++ * This is used on
++ */
+static int can_hit_entd(reiser4_context *ctx, struct super_block *s)
+{
+ if (ctx == NULL || ((unsigned long)ctx->magic) != context_magic)
+ return 0;
+ return 1;
+}
++
+#endif
+
+/**
+ 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);
+}
+
+
+/* called just before page is released (no longer used by reiser4). Callers:
+ jdelete() and extent2tail(). */
-+void reiser4_drop_page(struct page *page)
++void drop_page(struct page *page)
+{
+ assert("nikita-2181", PageLocked(page));
+ clear_page_dirty_for_io(page);
+#if defined(PG_skipped)
+ ClearPageSkipped(page);
+#endif
-+ unlock_page(page);
++ 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);
++ }
+}
+
+#define JNODE_GANG_SIZE (16)
+
-+/* find all jnodes from range specified and invalidate them */
++/* find all eflushed jnodes from range specified and invalidate them */
+static int
+truncate_jnodes_range(struct inode *inode, pgoff_t from, pgoff_t count)
+{
+ 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 = reiser4_tree_by_inode(inode);
++ tree = tree_by_inode(inode);
+
+ index = from;
+ end = from + count;
+ node = gang[i];
+ if (node != NULL) {
+ index = max(index, index_jnode(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);
++ invalidate_unformatted(node);
+ truncated_jnodes++;
+ jput(node);
+ } else
+ return truncated_jnodes;
+}
+
-+/* 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)
++void
++reiser4_invalidate_pages(struct address_space *mapping, pgoff_t from,
++ unsigned long count, int even_cows)
+{
+ loff_t from_bytes, count_bytes;
+
+ * scroll-step: 1
+ * End:
+ */
-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 @@
+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 @@
+/* Copyright 2001, 2002, 2003 by Hans Reiser, licensing governed by
+ * reiser4/README */
+/* Memory pressure hooks. Fake inodes handling. See page_cache.c. */
+#define __REISER4_PAGE_CACHE_H__
+
+#include "forward.h"
-+#include "context.h" /* for reiser4_ctx_gfp_mask_get() */
++#include "debug.h"
+
+#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 reiser4_tree *reiser4_tree_by_page(const struct page *);
++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 int reiser4_set_page_dirty_internal(struct page *);
++extern int set_page_dirty_internal(struct page *);
+
+#define reiser4_submit_bio(rw, bio) submit_bio((rw), (bio))
+
+
+#define jprivate(page) ((jnode *)page_private(page))
+
-+extern int reiser4_page_io(struct page *, jnode *, int rw, gfp_t);
-+extern void reiser4_drop_page(struct page *);
++extern int page_io(struct page *, jnode *, int rw, gfp_t);
++extern void 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
+
+ scroll-step: 1
+ End:
+*/
-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 @@
+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 @@
+/* Copyright 2001, 2002, 2003 by Hans Reiser, licensing governed by reiser4/README */
+
+/* Contains reiser4 cluster plugins (see
+#include "plugin.h"
+#include "../inode.h"
+
-+static int change_cluster(struct inode *inode,
-+ reiser4_plugin * plugin,
-+ pset_member memb)
++static int change_cluster(struct inode *inode, reiser4_plugin * plugin)
+{
++ 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);
+
-+ /* 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);
++ 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;
+}
+
+static reiser4_plugin_ops cluster_plugin_ops = {
+ scroll-step: 1
+ End:
+*/
-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 @@
+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 @@
+/* Copyright 2002, 2003 by Hans Reiser, licensing governed by reiser4/README */
+
-+/* This file contains size/offset translators, modulators
-+ and other helper functions. */
++/* This file contains page/cluster index translators and offset modulators
++ See http://www.namesys.com/cryptcompress_design.html for details */
+
+#if !defined( __FS_REISER4_CLUSTER_H__ )
+#define __FS_REISER4_CLUSTER_H__
+ return (loff_t) idx << inode_cluster_shift(inode);
+}
+
-+static inline loff_t off_to_clust_to_off(loff_t off, struct inode *inode)
++static inline unsigned long count_to_nr(loff_t count, unsigned shift)
+{
-+ return clust_to_off(off_to_clust(off, inode), inode);
++ return (count + (1UL << shift) - 1) >> shift;
+}
+
-+static inline pgoff_t off_to_clust_to_pg(loff_t off, struct inode *inode)
++/* number of pages occupied by @count bytes */
++static inline pgoff_t count_to_nrpages(loff_t count)
+{
-+ return clust_to_pg(off_to_clust(off, inode), inode);
++ return count_to_nr(count, PAGE_CACHE_SHIFT);
+}
+
-+static inline unsigned off_to_pgoff(loff_t off)
++/* number of clusters occupied by @count bytes */
++static inline cloff_t count_to_nrclust(loff_t count, struct inode *inode)
+{
-+ return off & (PAGE_CACHE_SIZE - 1);
++ return count_to_nr(count, inode_cluster_shift(inode));
+}
+
-+static inline unsigned off_to_cloff(loff_t off, struct inode *inode)
++/* number of clusters occupied by @count pages */
++static inline cloff_t pgcount_to_nrclust(pgoff_t count, struct inode *inode)
+{
-+ return off & ((loff_t) (inode_cluster_size(inode)) - 1);
++ return count_to_nr(count, cluster_nrpages_shift(inode));
+}
+
-+static inline pgoff_t offset_in_clust(struct page * page)
++static inline loff_t off_to_clust_to_off(loff_t off, struct inode *inode)
+{
-+ assert("edward-1488", page != NULL);
-+ assert("edward-1489", page->mapping != NULL);
++ return clust_to_off(off_to_clust(off, inode), inode);
++}
+
-+ return page_index(page) & ((cluster_nrpages(page->mapping->host)) - 1);
++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);
+}
+
-+static inline int first_page_in_cluster(struct page * page)
++static inline unsigned off_to_pgoff(loff_t off)
+{
-+ return offset_in_clust(page) == 0;
++ return off & (PAGE_CACHE_SIZE - 1);
+}
+
-+static inline int last_page_in_cluster(struct page * page)
++static inline unsigned off_to_cloff(loff_t off, struct inode *inode)
+{
-+ return offset_in_clust(page) ==
-+ cluster_nrpages(page->mapping->host) - 1;
++ return off & ((loff_t) (inode_cluster_size(inode)) - 1);
+}
+
+static inline unsigned
+ return off_to_cloff(pg_to_off(idx), inode);
+}
+
-+/*********************** 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 (count + (1UL << blkbits) - 1) >> blkbits;
-+}
-+
-+/* size in pages */
-+static inline pgoff_t size_in_pages(loff_t size)
++/* 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)
+{
-+ return size_in_blocks(size, PAGE_CACHE_SHIFT);
++ return (size ? off_to_pg(size - 1) : 0);
+}
+
-+/* size in logical clusters */
-+static inline cloff_t size_in_lc(loff_t size, struct inode *inode)
++/* minimal index of the page which doesn't contain
++ file data */
++static inline pgoff_t size_to_next_pg(loff_t size)
+{
-+ return size_in_blocks(size, inode_cluster_shift(inode));
++ return (size ? off_to_pg(size - 1) + 1 : 0);
+}
+
-+/* size in pages to the size in page clusters */
-+static inline cloff_t sp_to_spcl(pgoff_t size, struct inode *inode)
++/* 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)
+{
-+ 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)
-+{
-+ unsigned end = size >> blkbits;
-+ if (pos < end)
-+ return 1U << blkbits;
-+ if (unlikely(pos > end))
++ if (idx > off_to_pg(cnt))
+ return 0;
-+ return size & ~(~0ull << blkbits);
-+}
-+
-+/* 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)
-+{
-+ return __mbb(i_size_read(inode), index, inode_cluster_shift(inode));
++ if (idx < off_to_pg(cnt))
++ return PAGE_CACHE_SIZE;
++ return off_to_pgoff(cnt);
+}
+
-+/* 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);
-+}
-+
-+/* return true, if logical cluster is not occupied by the file */
-+static inline int new_logical_cluster(struct cluster_handle * clust,
-+ struct inode *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)
+{
-+ return clust_to_off(clust->index, inode) >= i_size_read(inode);
++ if (idx > off_to_clust(cnt, inode))
++ return 0;
++ if (idx < off_to_clust(cnt, inode))
++ return inode_cluster_size(inode);
++ return off_to_cloff(cnt, 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)
++static inline unsigned
++fsize_to_count(reiser4_cluster_t * clust, struct inode *inode)
+{
-+ assert("edward-1490", p1 != NULL);
-+ assert("edward-1491", p2 != NULL);
-+ assert("edward-1492", p1->mapping != NULL);
-+ assert("edward-1493", p2->mapping != NULL);
++ assert("edward-288", clust != NULL);
++ assert("edward-289", inode != NULL);
+
-+ return (pg_to_clust(page_index(p1), p1->mapping->host) ==
-+ pg_to_clust(page_index(p2), p2->mapping->host));
++ return cnt_to_clcnt(inode->i_size, clust->index, inode);
+}
+
-+static inline int cluster_is_complete(struct cluster_handle * clust,
-+ struct inode * inode)
++static inline int
++cluster_is_complete(reiser4_cluster_t * clust, struct inode * inode)
+{
+ return clust->tc.lsize == inode_cluster_size(inode);
+}
+
-+static inline void reiser4_slide_init(struct reiser4_slide * win)
++static inline void reiser4_slide_init(reiser4_slide_t * 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
-+cluster_set_tfm_act(struct tfm_cluster * tc, tfm_action act)
++tfm_cluster_init_act(tfm_cluster_t * tc, tfm_action act)
+{
+ assert("edward-1356", tc != NULL);
+ tc->act = act;
+}
+
-+static inline void cluster_init_act(struct cluster_handle * clust,
-+ tfm_action act,
-+ struct reiser4_slide * window)
-+{
++static inline void
++cluster_init_act (reiser4_cluster_t * clust, tfm_action act, reiser4_slide_t * window){
+ assert("edward-84", clust != NULL);
+ memset(clust, 0, sizeof *clust);
-+ cluster_set_tfm_act(&clust->tc, act);
++ tfm_cluster_init_act(&clust->tc, act);
+ clust->dstat = INVAL_DISK_CLUSTER;
+ clust->win = window;
+}
+
-+static inline void cluster_init_read(struct cluster_handle * clust,
-+ struct reiser4_slide * window)
-+{
-+ cluster_init_act (clust, TFMA_READ, window);
-+}
-+
-+static inline void cluster_init_write(struct cluster_handle * clust,
-+ struct reiser4_slide * window)
-+{
-+ cluster_init_act (clust, TFMA_WRITE, window);
-+}
-+
-+/* 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)
++static inline void
++cluster_init_read(reiser4_cluster_t * clust, reiser4_slide_t * window)
+{
-+ return hint->ext_coord.extension.ctail.dsize;
++ cluster_init_act (clust, TFM_READ_ACT, window);
+}
+
-+static inline void dclust_set_extension_dsize(hint_t * hint, int dsize)
++static inline void
++cluster_init_write(reiser4_cluster_t * clust, reiser4_slide_t * window)
+{
-+ hint->ext_coord.extension.ctail.dsize = dsize;
++ cluster_init_act (clust, TFM_WRITE_ACT, window);
+}
+
-+static inline int dclust_get_extension_shift(hint_t * hint)
++static inline int dclust_get_extension(hint_t * hint)
+{
+ return hint->ext_coord.extension.ctail.shift;
+}
+
-+static inline int dclust_get_extension_ncount(hint_t * hint)
++static inline void dclust_set_extension(hint_t * hint)
+{
-+ 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));
++ 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 inline int hint_is_unprepped_dclust(hint_t * hint)
+{
-+ assert("edward-1451", hint_is_valid(hint));
-+ return dclust_get_extension_shift(hint) == (int)UCTAIL_SHIFT;
++ return dclust_get_extension(hint) == (int)UCTAIL_SHIFT;
+}
+
+static inline void coord_set_between_clusters(coord_t * coord)
+#endif
+}
+
-+int reiser4_inflate_cluster(struct cluster_handle *, struct inode *);
-+int find_disk_cluster(struct cluster_handle *, struct inode *, int read,
++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,
+ znode_lock_mode mode);
-+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,
++int get_disk_cluster_locked(reiser4_cluster_t * clust, struct inode *inode,
+ znode_lock_mode lock_mode);
-+void reset_cluster_params(struct cluster_handle * clust);
-+int set_cluster_by_page(struct cluster_handle * clust, struct page * page,
++void reset_cluster_params(reiser4_cluster_t * clust);
++int set_cluster_by_page(reiser4_cluster_t * clust, struct page * page,
+ int count);
-+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);
++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);
+
+/* move cluster handle to the target position
-+ specified by the page of index @pgidx */
-+static inline void move_cluster_forward(struct cluster_handle * clust,
-+ struct inode *inode,
-+ pgoff_t pgidx)
++ 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)
+{
+ assert("edward-1297", clust != NULL);
+ assert("edward-1298", inode != NULL);
+
+ reset_cluster_params(clust);
-+ if (clust->index_valid &&
++ if (*progress &&
+ /* 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) {
-+ reiser4_unset_hint(clust->hint);
++ 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(struct cluster_handle * clust,
-+ struct inode *inode)
++static inline int
++alloc_clust_pages(reiser4_cluster_t * clust, struct inode *inode)
+{
+ assert("edward-791", clust != NULL);
+ assert("edward-792", inode != NULL);
+ clust->pages =
+ kmalloc(sizeof(*clust->pages) << inode_cluster_shift(inode),
-+ reiser4_ctx_gfp_mask_get());
++ GFP_KERNEL);
+ if (!clust->pages)
+ return -ENOMEM;
+ return 0;
+}
+
-+static inline void free_clust_pages(struct cluster_handle * clust)
++static inline void free_clust_pages(reiser4_cluster_t * clust)
+{
+ kfree(clust->pages);
+}
+ scroll-step: 1
+ End:
+*/
-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 @@
+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 @@
+/* Copyright 2001, 2002, 2003 by Hans Reiser, licensing governed by reiser4/README */
+/* reiser4 compression transform plugins */
+
+#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,
-+ pset_member memb)
++static int change_compression(struct inode *inode, reiser4_plugin * plugin)
+{
+ 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 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);
++ /* cannot change compression plugin of already existing object */
++ return RETERR(-EINVAL);
+}
+
+static reiser4_plugin_ops compression_plugin_ops = {
+#if REISER4_ZLIB
+ int ret = 0;
+ switch (act) {
-+ case TFMA_WRITE: /* compress */
-+ coa = reiser4_vmalloc(zlib_deflate_workspacesize());
++ case TFM_WRITE_ACT: /* compress */
++ coa = vmalloc(zlib_deflate_workspacesize());
+ if (!coa) {
+ ret = -ENOMEM;
+ break;
+ }
+ memset(coa, 0, zlib_deflate_workspacesize());
+ break;
-+ case TFMA_READ: /* decompress */
-+ coa = reiser4_vmalloc(zlib_inflate_workspacesize());
++ case TFM_READ_ACT: /* decompress */
++ coa = vmalloc(zlib_inflate_workspacesize());
+ if (!coa) {
+ ret = -ENOMEM;
+ break;
+ assert("edward-769", coa != NULL);
+
+ switch (act) {
-+ case TFMA_WRITE: /* compress */
++ case TFM_WRITE_ACT: /* compress */
+ vfree(coa);
+ break;
-+ case TFMA_READ: /* decompress */
++ case TFM_READ_ACT: /* decompress */
+ vfree(coa);
+ break;
+ default:
+ coa_t coa = NULL;
+
+ switch (act) {
-+ case TFMA_WRITE: /* compress */
-+ coa = reiser4_vmalloc(LZO_HEAP_SIZE(LZO1X_1_MEM_COMPRESS));
++ case TFM_WRITE_ACT: /* compress */
++ coa = vmalloc(LZO_HEAP_SIZE(LZO1X_1_MEM_COMPRESS));
+ if (!coa) {
+ ret = -ENOMEM;
+ break;
+ }
+ memset(coa, 0, LZO_HEAP_SIZE(LZO1X_1_MEM_COMPRESS));
-+ case TFMA_READ: /* decompress */
++ case TFM_READ_ACT: /* decompress */
+ break;
+ default:
+ impossible("edward-877",
+ assert("edward-879", coa != NULL);
+
+ switch (act) {
-+ case TFMA_WRITE: /* compress */
++ case TFM_WRITE_ACT: /* compress */
+ vfree(coa);
+ break;
-+ case TFMA_READ: /* decompress */
++ case TFM_READ_ACT: /* decompress */
+ impossible("edward-1304",
+ "trying to free non-allocated workspace");
+ default:
+ .alloc = gzip1_alloc,
+ .free = gzip1_free,
+ .min_size_deflate = gzip1_min_size_deflate,
-+ .checksum = reiser4_adler32,
++ .checksum = NULL,
+ .compress = gzip1_compress,
+ .decompress = gzip1_decompress
+ }
+ scroll-step: 1
+ End:
+*/
-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 @@
+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 @@
+#if !defined( __FS_REISER4_COMPRESS_H__ )
+#define __FS_REISER4_COMPRESS_H__
+
+#include <linux/types.h>
+#include <linux/string.h>
+
-+/* transform direction */
+typedef enum {
-+ TFMA_READ, /* decrypt, decompress */
-+ TFMA_WRITE, /* encrypt, compress */
-+ TFMA_LAST
++ TFM_READ_ACT,
++ TFM_WRITE_ACT,
++ TFM_LAST_ACT
+} tfm_action;
+
-+/* supported compression algorithms */
++/* builtin compression plugins */
++
+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;
-+
-+/* table for all supported (de)compression algorithms */
-+typedef coa_t coa_set[LAST_COMPRESSION_ID][TFMA_LAST];
++typedef coa_t coa_set[LAST_COMPRESSION_ID][TFM_LAST_ACT];
+
+__u32 reiser4_adler32(char *data, __u32 len);
+
+ scroll-step: 1
+ End:
+*/
-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 @@
+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 @@
+/* Copyright 2001, 2002, 2003 by Hans Reiser, licensing governed by reiser4/README */
+/* This file contains Reiser4 compression mode plugins.
+
+#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;
+ return compression_is_on(cryptcompress_inode_data(inode));
+}
+
-+static int discard_hook_ultim(struct inode *inode, cloff_t index)
++static int turn_off_compression(struct inode *inode, cloff_t index)
+{
-+ turn_off_compression(cryptcompress_inode_data(inode));
++ toggle_compression(cryptcompress_inode_data(inode), 0);
+ return 0;
+}
+
-+static int discard_hook_lattd(struct inode *inode, cloff_t index)
++static int turn_on_compression(struct inode *inode, cloff_t index)
+{
-+ 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);
++ toggle_compression(cryptcompress_inode_data(inode), 1);
+ return 0;
+}
+
-+static int accept_hook_lattd(struct inode *inode, cloff_t index)
++static int turn_off_compression_on_zero(struct inode *inode, cloff_t index)
+{
-+ turn_on_compression(cryptcompress_inode_data(inode));
-+ set_lattice_factor(cryptcompress_inode_data(inode), MIN_LATTICE_FACTOR);
++ assert("edward-1308", inode != NULL);
++ if (index == 0)
++ toggle_compression(cryptcompress_inode_data(inode), 0);
+ return 0;
+}
+
-+/* Check on dynamic lattice, the adaptive compression modes which
-+ defines the following behavior:
-+
++/* Check on lattice (COL) of some sparseness factor,
++ the family of adaptive compression modes which define
++ 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. If incompressible, then increase FACTOR */
++ them is compressible. */
+
+/* check if @index belongs to one-dimensional lattice
+ of sparce factor @factor */
-+static int is_on_lattice(cloff_t index, int factor)
++static int check_on_lattice(cloff_t index, int factor)
+{
+ return (factor ? index % factor == 0: index == 0);
+}
+
-+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 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 \
+}
+
++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] = {
+ .id = NONE_COMPRESSION_MODE_ID,
+ .pops = NULL,
+ .label = "none",
-+ .desc = "Compress nothing",
++ .desc = "Don't compress",
+ .linkage = {NULL, NULL}
+ },
+ .should_deflate = should_deflate_none,
+ .accept_hook = NULL,
+ .discard_hook = NULL
+ },
-+ /* 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] = {
++ /* 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] = {
+ .h = {
+ .type_id = REISER4_COMPRESSION_MODE_PLUGIN_TYPE,
-+ .id = ULTIM_COMPRESSION_MODE_ID,
++ .id = COZ_COMPRESSION_MODE_ID,
+ .pops = NULL,
-+ .label = "ultim",
-+ .desc = "Check ultimately",
++ .label = "coz",
++ .desc = "Check on zero",
+ .linkage = {NULL, NULL}
+ },
+ .should_deflate = should_deflate_common,
+ .accept_hook = NULL,
-+ .discard_hook = discard_hook_ultim
++ .discard_hook = turn_off_compression_on_zero
+ },
-+ /* 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 = "Force to compress everything",
++ .desc = "Compress everything",
+ .linkage = {NULL, NULL}
+ },
+ .should_deflate = NULL,
+ .accept_hook = NULL,
+ .discard_hook = NULL
+ },
-+ /* 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] = {
++ [TEST_COMPRESSION_MODE_ID] = {
+ .h = {
+ .type_id = REISER4_COMPRESSION_MODE_PLUGIN_TYPE,
-+ .id = CONVX_COMPRESSION_MODE_ID,
++ .id = TEST_COMPRESSION_MODE_ID,
+ .pops = NULL,
-+ .label = "conv",
-+ .desc = "Convert to extent",
++ .label = "test", /* This mode is for benchmarks only */
++ .desc = "Don't compress odd clusters",
+ .linkage = {NULL, NULL}
+ },
-+ .should_deflate = should_deflate_common,
++ .should_deflate = should_deflate_test,
+ .accept_hook = NULL,
+ .discard_hook = NULL
+ }
+ scroll-step: 1
+ End:
+*/
-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 @@
+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 @@
+/* lzoconf.h -- configuration for the LZO real-time data compression library
+ adopted for reiser4 compression transform plugin.
+
+#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>
+// 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(__i386__) || defined(__386__) || defined(_M_IX86)
++# if defined(__LZO_DOS) || defined(__LZO_WIN16)
+# 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
+
+// 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
+# define lzo_sizeof_dict_t sizeof(lzo_bytep)
+#endif
+
-+typedef int (*lzo_compress_t) (const lzo_byte * src, lzo_uint src_len,
-+ lzo_byte * dst, lzo_uintp dst_len,
-+ lzo_voidp wrkmem);
++/***********************************************************************
++// 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
++
++/* 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
+ (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))
-+ extern int __lzo_init2(unsigned, int, int, int, int, int, int,
-+ int, int, int);
++ LZO_EXTERN(int) __lzo_init2(unsigned, int, int, int, int, int, int,
++ int, int, int);
+
+/* checksum functions */
-+extern lzo_uint32 lzo_crc32(lzo_uint32 _c, const lzo_byte * _buf,
-+ lzo_uint _len);
++ LZO_EXTERN(lzo_uint32)
++ lzo_crc32(lzo_uint32 _c, const lzo_byte * _buf, lzo_uint _len);
++
+/* misc. */
+ typedef union {
+ lzo_bytep p;
+/* deprecated - only for backward compatibility */
+#define LZO_ALIGN(_ptr,_size) LZO_PTR_ALIGN_UP(_ptr,_size)
+
++#ifdef __cplusplus
++} /* extern "C" */
++#endif
+#endif /* already included */
-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 @@
+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 @@
+/* minilzo.c -- mini subset of the LZO real-time data compression library
+ adopted for reiser4 compression transform plugin.
+
+#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
+# 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) \
+# 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
+# endif
+#endif
+
-+extern const lzo_uint32 _lzo_crc32_table[256];
++__LZO_EXTERN_C const lzo_uint32 _lzo_crc32_table[256];
+
+#define _LZO_STRINGIZE(x) #x
+#define _LZO_MEXPAND(x) _LZO_STRINGIZE(x)
+#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
+
+#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
+#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
+#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
+# 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)
+{
-+ return PTR_LINEAR(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;
+}
+
+static unsigned __lzo_align_gap(const lzo_voidp ptr, lzo_uint size)
+#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)
+ 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))
+ 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
+#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));
+ 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);
+
+ 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))
+
+#undef COMPILE_TIME_ASSERT
+
-+int __lzo_init2(unsigned v, int s1, int s2, int s3, int s4, int s5,
-+ int s6, int s7, int s8, int s9)
++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 r;
+
+ 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
+# define LZO1X
+#endif
+
++#if !defined(__LZO_IN_MINILZO)
++#include <lzo1x.h>
++#endif
++
+#define LZO_EOF_CODE
+#undef LZO_DETERMINISTIC
+
+#ifndef __LZO_DICT_H
+#define __LZO_DICT_H
+
++#ifdef __cplusplus
++extern "C" {
++#endif
++
+#if !defined(D_BITS) && defined(DBITS)
+# define D_BITS DBITS
+#endif
+
+#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)
+
+
+#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)
+
+ (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
+ return pd(in_end, ii);
+}
+
-+int DO_COMPRESS(const lzo_byte * in, lzo_uint in_len,
-+ lzo_byte * out, lzo_uintp out_len, lzo_voidp wrkmem)
++LZO_PUBLIC(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;
+#endif
+
+#if defined(DO_DECOMPRESS)
-+int DO_DECOMPRESS(const lzo_byte * in, lzo_uint in_len,
-+ lzo_byte * out, lzo_uintp out_len, lzo_voidp wrkmem)
++LZO_PUBLIC(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;
+#endif
+
+/***** End of minilzo.c *****/
-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 @@
+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 @@
+/* minilzo.h -- mini subset of the LZO real-time data compression library
+ adopted for reiser4 compression transform plugin.
+
+
+#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.
+ */
+#define LZO1X_MEM_DECOMPRESS (0)
+
+/* compression */
-+extern int lzo1x_1_compress(const lzo_byte * src, lzo_uint src_len,
-+ lzo_byte * dst, lzo_uintp dst_len,
-+ lzo_voidp wrkmem);
++ LZO_EXTERN(int)
++ lzo1x_1_compress(const lzo_byte * src, lzo_uint src_len,
++ lzo_byte * dst, lzo_uintp dst_len, lzo_voidp wrkmem);
++
+/* decompression */
-+extern int lzo1x_decompress(const lzo_byte * src, lzo_uint src_len,
-+ lzo_byte * dst, lzo_uintp dst_len,
-+ lzo_voidp wrkmem /* NOT USED */);
++ 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 */ );
++
+/* safe decompression with overrun testing */
-+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 */ );
++ 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 */ );
+
++#ifdef __cplusplus
++} /* extern "C" */
++#endif
+#endif /* already included */
-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 @@
+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 @@
+/* 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] = {
+ .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
+ }
+};
+
+ scroll-step: 1
+ End:
+*/
-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 @@
+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 @@
+/* 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
+
+#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 */
-+struct reiser4_crypto_data {
++typedef struct 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 */
-+struct reiser4_crypto_info {
-+ struct inode * host;
-+ struct crypto_hash * digest;
-+ struct crypto_blkcipher * cipher;
-+#if 0
-+ cipher_key_plugin * kplug; /* key manager */
-+#endif
++typedef struct crypto_stat {
++ reiser4_tfma_t tfma[LAST_TFM];
++// cipher_key_plugin * kplug; /* key manager */
+ __u8 * keyid; /* key fingerprint, created by digest plugin,
+ using uninstantiated key and passphrase.
+ supposed to be stored in disk stat-data */
+ 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__ */
+
+ scroll-step: 1
+ End:
+*/
-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
+Index: linux-2.6.16/fs/reiser4/plugin/crypto/digest.c
+===================================================================
+--- /dev/null
++++ linux-2.6.16/fs/reiser4/plugin/crypto/digest.c
@@ -0,0 +1,58 @@
+/* Copyright 2001, 2002, 2003 by Hans Reiser, licensing governed by reiser4/README */
+
+
+extern digest_plugin digest_plugins[LAST_DIGEST_ID];
+
-+static struct crypto_hash * alloc_sha256 (void)
++static struct crypto_tfm * alloc_sha256 (void)
+{
+#if REISER4_SHA256
-+ return crypto_alloc_hash ("sha256", 0, CRYPTO_ALG_ASYNC);
++ return crypto_alloc_tfm ("sha256", 0);
+#else
+ warning("edward-1418", "sha256 unsupported");
+ return ERR_PTR(-EINVAL);
+#endif
+}
+
-+static void free_sha256 (struct crypto_hash * tfm)
++static void free_sha256 (struct crypto_tfm * tfm)
+{
+#if REISER4_SHA256
-+ crypto_free_hash(tfm);
++ crypto_free_tfm(tfm);
+#endif
+ return;
+}
+ scroll-step: 1
+ End:
+*/
-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
+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
@@ -0,0 +1,36 @@
+/* Copyright 2001, 2002, 2003, 2004 by Hans Reiser, licensing governed by
+ * reiser4/README */
+ fill-column: 120
+ End:
+*/
-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
+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
@@ -0,0 +1,81 @@
+/* Copyright 2001, 2002, 2003, 2004 by Hans Reiser, licensing governed by
+ * reiser4/README */
+ fill-column: 120
+ End:
+*/
-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
+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
@@ -0,0 +1,46 @@
+/* Copyright 2005 by Hans Reiser, licensing governed by
+ * reiser4/README */
+ set_key_offset(result, (__u64) 0);
+ return;
+}
-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 @@
+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 @@
+/* Copyright 2005 by Hans Reiser, licensing governed by
+ reiser4/README */
+
+
+#include "../inode.h"
+
-+int reiser4_find_entry(struct inode *dir, struct dentry *name,
++int find_entry(struct inode *dir, struct dentry *name,
+ lock_handle *, znode_lock_mode, reiser4_dir_entry_desc *);
-+int reiser4_lookup_name(struct inode *parent, struct dentry *dentry, reiser4_key * key);
++int 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
+ dotdot.d_name.len = 2;
+ dotdot.d_op = &get_super_private(s)->ops.dentry;
+
-+ result = reiser4_lookup_name(child, &dotdot, &key);
++ result = lookup_name(child, &dotdot, &key);
+ if (result != 0)
+ return ERR_PTR(result);
+
+
+/* this is common implementation of build_readdir_key method of dir
+ plugin
-+ see reiser4_readdir_common for more details
++ see readdir_common for more details
+*/
+int build_readdir_key_common(struct file *dir /* directory being read */ ,
+ reiser4_key * result /* where to store key */ )
+
+}
+
-+void reiser4_adjust_dir_file(struct inode *, const struct dentry *, int offset,
-+ int adj);
++void adjust_dir_file(struct inode *, const struct dentry *, int offset,
++ int adj);
+
+/* this is common implementation of add_entry method of dir plugin
+*/
-+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 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 result;
+ coord_t *coord;
+ lock_handle lh;
-+ struct reiser4_dentry_fsdata *fsdata;
++ reiser4_dentry_fsdata *fsdata;
+ reiser4_block_nr reserve;
+
+ assert("nikita-1114", object != NULL);
+ coord_clear_iplug(coord);
+
+ /* check for this entry in a directory. This is plugin method. */
-+ result = reiser4_find_entry(object, where, &lh, ZNODE_WRITE_LOCK,
-+ entry);
++ result = 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);
-+ reiser4_seal_done(&fsdata->dec.entry_seal);
++ seal_done(&fsdata->dec.entry_seal);
+ result =
+ inode_dir_item_plugin(object)->s.dir.add_entry(object,
+ coord, &lh,
+ where,
+ entry);
+ if (result == 0) {
-+ reiser4_adjust_dir_file(object, where,
-+ fsdata->dec.pos + 1, +1);
++ adjust_dir_file(object, where, fsdata->dec.pos + 1, +1);
+ INODE_INC_FIELD(object, i_size);
+ }
+ } else if (result == 0) {
+}
+
+/**
-+ * reiser4_rem_entry_common - remove entry from a directory
++ * 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 reiser4_rem_entry_common(struct inode *dir,
-+ struct dentry *dentry,
-+ reiser4_dir_entry_desc *entry)
++int rem_entry_common(struct inode *dir,
++ struct dentry *dentry,
++ reiser4_dir_entry_desc *entry)
+{
+ int result;
+ coord_t *coord;
+ lock_handle lh;
-+ struct reiser4_dentry_fsdata *fsdata;
++ reiser4_dentry_fsdata *fsdata;
+ __u64 tograb;
+
+ assert("nikita-1124", dir != NULL);
+ init_lh(&lh);
+
+ /* check for this entry in a directory. This is plugin method. */
-+ result = reiser4_find_entry(dir, dentry, &lh, ZNODE_WRITE_LOCK, entry);
++ result = find_entry(dir, dentry, &lh, ZNODE_WRITE_LOCK, entry);
+ fsdata = reiser4_get_dentry_fsdata(dentry);
+ if (IS_ERR(fsdata)) {
+ done_lh(&lh);
+ /* remove entry. Just pass control to the directory item
+ plugin. */
+ assert("vs-542", inode_dir_item_plugin(dir));
-+ reiser4_seal_done(&fsdata->dec.entry_seal);
-+ reiser4_adjust_dir_file(dir, dentry, fsdata->dec.pos, -1);
++ seal_done(&fsdata->dec.entry_seal);
++ adjust_dir_file(dir, dentry, fsdata->dec.pos, -1);
+ result =
+ WITH_COORD(coord,
+ rem_entry(dir, dentry, entry, coord, &lh));
+/* this is common implementation of init method of dir plugin
+ create "." and ".." entries
+*/
-+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 */)
++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 */ )
+{
+ reiser4_block_nr reserve;
+
+/* this is common implementation of done method of dir plugin
+ remove "." entry
+*/
-+int reiser4_dir_done_common(struct inode *object /* object being deleted */ )
++int done_common(struct inode *object /* object being deleted */ )
+{
+ int result;
+ reiser4_block_nr reserve;
+
+ assert("nikita-1449", object != NULL);
+
-+ if (reiser4_inode_get_flag(object, REISER4_NO_SD))
++ if (inode_get_flag(object, REISER4_NO_SD))
+ return 0;
+
+ /* of course, this can be rewritten to sweep everything in one
-+ reiser4_cut_tree(). */
++ cut_tree(). */
+ memset(&entry, 0, sizeof entry);
+
-+ /* FIXME: this done method is called from reiser4_delete_dir_common which
++ /* FIXME: this done method is called from delete_directory_common which
+ * reserved space already */
+ reserve = inode_dir_plugin(object)->estimate.rem_entry(object);
+ if (reiser4_grab_space(reserve, BA_CAN_COMMIT | BA_RESERVED))
+ entry.obj = goodby_dots.d_inode = object;
+ goodby_dots.d_name.name = ".";
+ goodby_dots.d_name.len = 1;
-+ result = reiser4_rem_entry_common(object, &goodby_dots, &entry);
++ result = 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
+
+/* this is common implementation of attach method of dir plugin
+*/
-+int reiser4_attach_common(struct inode *child UNUSED_ARG,
-+ struct inode *parent UNUSED_ARG)
++int
++attach_common(struct inode *child UNUSED_ARG, struct inode *parent UNUSED_ARG)
+{
+ assert("nikita-2647", child != NULL);
+ assert("nikita-2648", parent != NULL);
+/* this is common implementation of detach method of dir plugin
+ remove "..", decrease nlink on parent
+*/
-+int reiser4_detach_common(struct inode *object, struct inode *parent)
++int 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", !reiser4_inode_get_flag(object, REISER4_NO_SD));
++ assert("nikita-2886", !inode_get_flag(object, REISER4_NO_SD));
+
+ memset(&entry, 0, sizeof entry);
+
+ entry.obj = goodby_dots.d_inode = parent;
+ goodby_dots.d_name.name = "..";
+ goodby_dots.d_name.len = 2;
-+ result = reiser4_rem_entry_common(object, &goodby_dots, &entry);
++ result = 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 <= 2);
++ assert("nikita-3400", object->i_size == 1 &&
++ (object->i_nlink >= 0 && 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
+*/
+reiser4_block_nr estimate_add_entry_common(const struct inode * inode)
+{
-+ return estimate_one_insert_into_item(reiser4_tree_by_inode(inode));
++ return estimate_one_insert_into_item(tree_by_inode(inode));
+}
+
+/* this is common implementation of estimate.rem_entry method of dir
+*/
+reiser4_block_nr estimate_rem_entry_common(const struct inode * inode)
+{
-+ return estimate_one_item_removal(reiser4_tree_by_inode(inode));
++ return estimate_one_item_removal(tree_by_inode(inode));
+}
+
+/* this is common implementation of estimate.unlink method of dir
+ */
+void check_light_weight(struct inode *inode, struct inode *parent)
+{
-+ if (reiser4_inode_get_flag(inode, REISER4_LIGHT_WEIGHT)) {
++ if (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. */
-+ reiser4_inode_clr_flag(inode, REISER4_LIGHT_WEIGHT);
++ 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 reiser4_lookup_name(struct inode *parent, /* inode of directory to lookup for
++int 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 */ )
+ const char *name;
+ int len;
+ reiser4_dir_entry_desc entry;
-+ struct reiser4_dentry_fsdata *fsdata;
++ reiser4_dentry_fsdata *fsdata;
+
+ assert("nikita-1247", parent != NULL);
+ assert("nikita-1248", dentry != NULL);
+ init_lh(&lh);
+
+ /* find entry in a directory. This is plugin method. */
-+ result = reiser4_find_entry(parent, dentry, &lh, ZNODE_READ_LOCK,
-+ &entry);
++ result = find_entry(parent, dentry, &lh, ZNODE_READ_LOCK, &entry);
+ if (result == 0) {
+ /* entry was found, extract object key from it. */
+ result =
+
+}
+
-+/* helper for reiser4_dir_init_common(): estimate number of blocks to reserve */
++/* helper for init_common(): estimate number of blocks to reserve */
+static reiser4_block_nr
+estimate_init(struct inode *parent, struct inode *object)
+{
+ return 0;
+}
+
-+/* 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 */)
++/* 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 */ )
+{
+ int result;
+ struct dentry dots_entry;
+ entry.obj = dots_entry.d_inode = object;
+ dots_entry.d_name.name = ".";
+ dots_entry.d_name.len = 1;
-+ result = reiser4_add_entry_common(object, &dots_entry, NULL, &entry);
++ result = add_entry_common(object, &dots_entry, NULL, &entry);
+ reiser4_free_dentry_fsdata(&dots_entry);
+
+ if (result == 0) {
+ entry.obj = dots_entry.d_inode = parent;
+ dots_entry.d_name.name = "..";
+ dots_entry.d_name.len = 2;
-+ result = reiser4_add_entry_common(object,
++ result = add_entry_common(object,
+ &dots_entry, NULL, &entry);
+ reiser4_free_dentry_fsdata(&dots_entry);
+ /* if creation of ".." failed, iput() will delete
+ * if we failed to bump i_nlink, try
+ * to remove ".."
+ */
-+ reiser4_detach_common(object, parent);
++ detach_common(object, parent);
+ }
+ }
+ }
+/*
+ * argument package used by entry_actor to scan entries with identical keys.
+ */
-+struct entry_actor_args {
++typedef struct entry_actor_args {
+ /* name we are looking for */
+ const char *name;
+ /* key of directory entry. entry_actor() scans through sequence of
+ lock_handle last_lh;
+ /* inode of directory */
+ const struct inode *inode;
-+};
++} entry_actor_args;
+
-+/* Function called by reiser4_find_entry() to look for given name
-+ in the directory. */
++/* Function called by 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;
-+ struct entry_actor_args *args;
++ entry_actor_args *args;
+
+ assert("nikita-1131", tree != NULL);
+ assert("nikita-1132", coord != NULL);
+/* Look for given @name within directory @dir.
+
+ This is called during lookup, creation and removal of directory
-+ entries and on reiser4_rename_common
++ entries and on 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 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 */)
++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 */ )
+{
+ const struct qstr *name;
+ seal_t *seal;
+ coord_t *coord;
+ int result;
+ __u32 flags;
-+ struct de_location *dec;
-+ struct reiser4_dentry_fsdata *fsdata;
++ de_location *dec;
++ reiser4_dentry_fsdata *fsdata;
+
+ assert("nikita-1130", lh != NULL);
+ assert("nikita-1128", dir != NULL);
+ /* compose key of directory entry for @name */
+ inode_dir_plugin(dir)->build_entry_key(dir, name, &entry->key);
+
-+ if (reiser4_seal_is_set(seal)) {
++ if (seal_is_set(seal)) {
+ /* check seal */
-+ result = reiser4_seal_validate(seal, coord, &entry->key,
-+ lh, mode, ZNODE_LOCK_LOPRI);
++ result = 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. */
+ /*
+ * find place in the tree where directory item should be located.
+ */
-+ result = reiser4_object_lookup(dir, &entry->key, coord, lh, mode,
-+ FIND_EXACT, LEAF_LEVEL, LEAF_LEVEL,
-+ flags, NULL /*ra_info */ );
++ result = object_lookup(dir, &entry->key, coord, lh, mode,
++ FIND_EXACT, LEAF_LEVEL, LEAF_LEVEL, flags,
++ NULL /*ra_info */ );
+ if (result == CBK_COORD_FOUND) {
-+ struct entry_actor_args arg;
++ entry_actor_args arg;
+
+ /* fast path: no hash collisions */
+ result = check_entry(dir, coord, name);
+ if (result == 0) {
-+ reiser4_seal_init(seal, coord, &entry->key);
++ seal_init(seal, coord, &entry->key);
+ dec->pos = 0;
+ } else if (result > 0) {
+ /* Iterate through all units with the same keys. */
+ coord_init_zero(&arg.last_coord);
+ init_lh(&arg.last_lh);
+
-+ result = reiser4_iterate_tree
-+ (reiser4_tree_by_inode(dir),
-+ coord, lh,
-+ entry_actor, &arg, mode, 1);
++ result = iterate_tree(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)) {
+
+ done_lh(&arg.last_lh);
+ if (result == 0)
-+ reiser4_seal_init(seal, coord, &entry->key);
++ seal_init(seal, coord, &entry->key);
+
+ if (result == 0 || result == -ENOENT) {
+ assert("nikita-2580", arg.non_uniq > 0);
+ 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"
+ scroll-step: 1
+ End:
+*/
-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 @@
+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"
++ 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_format40.c
+===================================================================
+--- /dev/null
++++ linux-2.6.16/fs/reiser4/plugin/disk_format/disk_format40.c
+@@ -0,0 +1,556 @@
+/* Copyright 2002, 2003 by Hans Reiser, licensing governed by reiser4/README */
+
+#include "../../debug.h"
+ & 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)
+{
+ 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;
+ jnode *sb_jnode;
+ int ret;
+
-+ sb_jnode = reiser4_alloc_io_head(&get_sb_info(s)->loc.super);
++ sb_jnode = alloc_io_head(&get_sb_info(s)->loc.super);
+
+ ret = jload(sb_jnode);
+
+ if (ret) {
-+ reiser4_drop_io_head(sb_jnode);
++ drop_io_head(sb_jnode);
+ return ret;
+ }
+
+
+ if (sb_jnode) {
+ unpin_jnode_data(sb_jnode);
-+ reiser4_drop_io_head(sb_jnode);
++ drop_io_head(sb_jnode);
+ }
+}
+
+{
+ format40_disk_super_block *sb_copy;
+
-+ sb_copy = kmalloc(sizeof(format40_disk_super_block),
-+ reiser4_ctx_gfp_mask_get());
++ sb_copy = kmalloc(sizeof(format40_disk_super_block), get_gfp_mask());
+ if (sb_copy == NULL)
+ return ERR_PTR(RETERR(-ENOMEM));
+ memcpy(sb_copy, ((format40_disk_super_block *) super_bh->b_data),
+ 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 = reiser4_init_journal_info(super);
++ result = init_journal_info(super);
+ if (result)
+ return result;
+ *stage = INIT_JOURNAL_INFO;
+
+ result = reiser4_status_query(NULL, NULL);
+ if (result == REISER4_STATUS_MOUNT_WARN)
-+ 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);
++ 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. */
++ }
++
+ result = reiser4_journal_replay(super);
+ if (result)
+ return result;
+ /* 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);
-+ 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 */
++
++ /* make sure that key format of kernel and filesyste match */
+ result = check_key_format(sb_copy);
+ if (result) {
+ kfree(sb_copy);
+ 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 = reiser4_init_tree(&sbinfo->tree, &root_block, height, nplug);
++ result = init_tree(&sbinfo->tree, &root_block, height, nplug);
+ if (result) {
+ kfree(sb_copy);
+ return result;
+ /* 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 */
+#endif
+
+ /* init disk space allocator */
-+ result = sa_init_allocator(reiser4_get_space_allocator(super),
-+ super, NULL);
++ result = sa_init_allocator(get_space_allocator(super), super, NULL);
+ if (result)
+ return result;
+ *stage = INIT_SA;
+ case INIT_JNODE:
+ done_super_jnode(s);
+ case INIT_SA:
-+ sa_destroy_allocator(reiser4_get_space_allocator(s), s);
++ sa_destroy_allocator(get_space_allocator(s), s);
+ case JOURNAL_RECOVER:
+ case INIT_TREE:
-+ reiser4_done_tree(&get_super_private(s)->tree);
++ done_tree(&get_super_private(s)->tree);
+ case INIT_OID:
+ case KEY_CHECK:
+ case READ_SUPER:
+ case INIT_STATUS:
+ reiser4_status_finish();
+ case INIT_JOURNAL_INFO:
-+ reiser4_done_journal_info(s);
++ done_journal_info(s);
+ case FIND_A_SUPER:
+ case CONSULT_DISKMAP:
+ case NONE_DONE:
+{
+ 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(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_le64(oid_next(s)), &super_data->oid);
++ put_unaligned(cpu_to_le64(oids_used(s)), &super_data->file_count);
+
-+ if (update_disk_version(super_data)) {
-+ __u32 version = FORMAT40_VERSION | FORMAT40_UPDATE_BACKUP;
-+
-+ put_unaligned(cpu_to_le32(version), &super_data->version);
-+ }
++ put_unaligned(cpu_to_le16(sbinfo->tree.height), &super_data->tree_height);
+}
+
+/* plugin->u.format.log_super
+ assert("zam-579", sbinfo != NULL);
+
+ if (!rofs_super(s)) {
-+ ret = reiser4_capture_super_block(s);
++ ret = capture_super_block(s);
+ if (ret != 0)
-+ warning("vs-898",
-+ "reiser4_capture_super_block failed: %d",
++ warning("vs-898", "capture_super_block failed: %d",
+ ret);
+
+ ret = txnmgr_force_commit_all(s, 1);
+ }
+
+ sa_destroy_allocator(&sbinfo->space_allocator, s);
-+ reiser4_done_journal_info(s);
++ done_journal_info(s);
+ done_super_jnode(s);
+
+ rcu_barrier();
-+ reiser4_done_tree(&sbinfo->tree);
++ done_tree(&sbinfo->tree);
+ /* call finish_rcu(), because some znode were "released" in
-+ * reiser4_done_tree(). */
++ * done_tree(). */
+ rcu_barrier();
+
+ return 0;
+ /* Check the locality. */
+ oid = reiser4_inode_data(object)->locality_id;
+ if (oid > max) {
-+ warning("vpf-1361", "The object with the locality %llu "
++ warning("vpf-1360", "The object with the locality %llu "
+ "greater then the max used oid %llu found.",
+ (unsigned long long)oid, (unsigned long long)max);
+
+ 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"
+ scroll-step: 1
+ End:
+*/
-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 @@
+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 @@
+/* Copyright 2002, 2003 by Hans Reiser, licensing governed by reiser4/README */
+
+/* this file contains:
+ /* 68 */ d16 tree_height;
+ /* height of filesystem tree */
+ /* 70 */ d16 formatting_policy;
-+ /* not used anymore */
+ /* 72 */ d64 flags;
-+ /* 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];
++ /* 72 */ char not_used[432];
+} format40_disk_super_block;
+
+/* format 40 specific part of reiser4_super_info_data */
+
+/* declarations of functions implementing methods of layout plugin for
+ format 40. The functions theirself are in disk_format40.c */
-+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);
++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);
+
+/* __DISK_FORMAT40_H__ */
+#endif
+ scroll-step: 1
+ End:
+*/
-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 @@
+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 @@
+/* Copyright 2004 by Hans Reiser, licensing governed by
+ * reiser4/README */
+
+ return FIBRE_NO(0);
+}
+
-+static int change_fibration(struct inode *inode,
-+ reiser4_plugin * plugin,
-+ pset_member memb)
++static int change_fibration(struct inode *inode, reiser4_plugin * plugin)
+{
+ int result;
+
+ if (inode_fibration_plugin(inode) == NULL ||
+ inode_fibration_plugin(inode)->h.id != plugin->h.id) {
+ if (is_dir_empty(inode) == 0)
-+ result = aset_set_unsafe(&reiser4_inode_data(inode)->pset,
-+ PSET_FIBRATION, plugin);
++ result =
++ plugin_set_fibration(&reiser4_inode_data(inode)->
++ pset, &plugin->fibration);
+ else
+ result = RETERR(-ENOTEMPTY);
+
+ * fill-column: 79
+ * End:
+ */
-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
+Index: linux-2.6.16/fs/reiser4/plugin/fibration.h
+===================================================================
+--- /dev/null
++++ linux-2.6.16/fs/reiser4/plugin/fibration.h
@@ -0,0 +1,37 @@
+/* Copyright 2004 by Hans Reiser, licensing governed by reiser4/README */
+
+ fill-column: 120
+ End:
+*/
-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
+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
+ reiser4/README */
-+/*
-+ * 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.
++
++/* 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).
+ */
+
++#include "../../page_cache.h"
+#include "../../inode.h"
+#include "../cluster.h"
+#include "../object.h"
+#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 */
-+struct cryptcompress_info *cryptcompress_inode_data(const struct inode *inode)
++cryptcompress_info_t *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)
+{
-+ struct cryptcompress_info *data;
++ cryptcompress_info_t *data;
+
+ data = cryptcompress_inode_data(inode);
+ assert("edward-685", data != NULL);
+
+ memset(data, 0, sizeof(*data));
+
-+ mutex_init(&data->checkin_mutex);
-+ data->trunc_index = ULONG_MAX;
-+ turn_on_compression(data);
-+ set_lattice_factor(data, MIN_LATTICE_FACTOR);
++ init_rwsem(&data->lock);
++ toggle_compression(data, 1);
+ 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 */
-+struct reiser4_crypto_info * inode_crypto_info (struct inode * inode)
++crypto_stat_t * inode_crypto_stat (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_info (struct inode * inode,
-+ struct reiser4_crypto_info * info)
++static void set_inode_crypto_stat (struct inode * inode, crypto_stat_t * stat)
+{
-+ cryptcompress_inode_data(inode)->crypt = info;
++ cryptcompress_inode_data(inode)->crypt = stat;
+}
+
+/* allocate a cipher key info */
-+struct reiser4_crypto_info * reiser4_alloc_crypto_info (struct inode * inode)
++crypto_stat_t * alloc_crypto_stat (struct inode * inode)
+{
-+ struct reiser4_crypto_info * info;
++ crypto_stat_t * info;
+ int fipsize;
+
-+ info = kmalloc(sizeof(*info), reiser4_ctx_gfp_mask_get());
++ assert("edward-1421", 0);
++ info = kmalloc(sizeof(*info), GFP_KERNEL);
+ if (!info)
+ return ERR_PTR(-ENOMEM);
+ memset(info, 0, sizeof (*info));
+ fipsize = inode_digest_plugin(inode)->fipsize;
-+ info->keyid = kmalloc(fipsize, reiser4_ctx_gfp_mask_get());
++ info->keyid = kmalloc(fipsize, GFP_KERNEL);
+ 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(struct reiser4_crypto_info * info)
++static int
++alloc_crypto_tfms(plugin_set * pset, crypto_stat_t * info)
+{
-+ 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);
++ 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);
+
+ if (cplug->alloc) {
-+ ctfm = cplug->alloc();
-+ if (IS_ERR(ctfm)) {
++ ret = cplug->alloc();
++ if (ret == NULL) {
+ warning("edward-1364",
+ "Can not allocate info for %s\n",
+ cplug->h.desc);
-+ return RETERR(PTR_ERR(ctfm));
++ return RETERR(-EINVAL);
+ }
+ }
-+ info_set_cipher(info, ctfm);
++ info_set_tfm(info, CIPHER_TFM, ret);
+ if (dplug->alloc) {
-+ dtfm = dplug->alloc();
-+ if (IS_ERR(dtfm)) {
++ ret = dplug->alloc();
++ if (ret == NULL) {
+ warning("edward-1365",
+ "Can not allocate info for %s\n",
+ dplug->h.desc);
-+ goto unhappy_with_digest;
++ goto err;
+ }
+ }
-+ info_set_digest(info, dtfm);
++ info_set_tfm(info, DIGEST_TFM, ret);
+ return 0;
-+ unhappy_with_digest:
++ err:
+ if (cplug->free) {
-+ cplug->free(ctfm);
-+ info_set_cipher(info, NULL);
++ cplug->free(info->tfma[CIPHER_TFM].tfm);
++ info_set_tfm(info, CIPHER_TFM, NULL);
+ }
-+ return RETERR(PTR_ERR(dtfm));
++ return RETERR(-EINVAL);
+}
+#endif
+
+static void
-+free_crypto_tfms(struct reiser4_crypto_info * info)
++free_crypto_tfms(crypto_stat_t * info)
+{
+ assert("edward-1366", info != NULL);
-+ if (!info_get_cipher(info)) {
-+ assert("edward-1601", !info_get_digest(info));
++ if (!info_cipher_tfm(info))
+ return;
-+ }
-+ 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);
++ 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);
+ return;
+}
+
+#if 0
+/* create a key fingerprint for disk stat-data */
-+static int create_keyid (struct reiser4_crypto_info * info,
-+ struct reiser4_crypto_data * data)
++static int create_keyid (crypto_stat_t * info, crypto_data_t * data)
+{
+ int ret = -ENOMEM;
+ size_t blk, pad;
+ __u8 * dmem;
+ __u8 * cmem;
-+ struct hash_desc ddesc;
-+ struct blkcipher_desc cdesc;
++ struct crypto_tfm * dtfm;
++ struct crypto_tfm * ctfm;
+ struct scatterlist sg;
+
++ assert("edward-1422", 0);
+ assert("edward-1367", info != NULL);
+ assert("edward-1368", info->keyid != NULL);
+
-+ ddesc.tfm = info_get_digest(info);
-+ ddesc.flags = 0;
-+ cdesc.tfm = info_get_cipher(info);
-+ cdesc.flags = 0;
++ dtfm = info_digest_tfm(info);
++ ctfm = info_cipher_tfm(info);
+
-+ dmem = kmalloc((size_t)crypto_hash_digestsize(ddesc.tfm),
-+ reiser4_ctx_gfp_mask_get());
++ dmem = kmalloc((size_t)crypto_tfm_alg_digestsize(dtfm),
++ GFP_KERNEL);
+ if (!dmem)
+ goto exit1;
+
-+ blk = crypto_blkcipher_blocksize(cdesc.tfm);
++ blk = crypto_tfm_alg_blocksize(ctfm);
+
+ pad = data->keyid_size % blk;
+ pad = (pad ? blk - pad : 0);
+
-+ cmem = kmalloc((size_t)data->keyid_size + pad,
-+ reiser4_ctx_gfp_mask_get());
++ cmem = kmalloc((size_t)data->keyid_size + pad, GFP_KERNEL);
+ if (!cmem)
+ goto exit2;
+ memcpy(cmem, data->keyid, data->keyid_size);
+ sg.offset = offset_in_page(cmem);
+ sg.length = data->keyid_size + pad;
+
-+ ret = crypto_blkcipher_encrypt(&cdesc, &sg, &sg,
-+ data->keyid_size + pad);
++ ret = crypto_cipher_encrypt(ctfm, &sg, &sg, data->keyid_size + pad);
+ if (ret) {
+ warning("edward-1369",
-+ "encryption failed flags=%x\n", cdesc.flags);
++ "encryption failed flags=%x\n", ctfm->crt_flags);
+ goto exit3;
+ }
-+ 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);
++ crypto_digest_init (dtfm);
++ crypto_digest_update (dtfm, &sg, 1);
++ crypto_digest_final (dtfm, dmem);
++ memcpy(info->keyid, dmem, info_digest_plugin(info)->fipsize);
+ exit3:
+ kfree(cmem);
+ exit2:
+}
+#endif
+
-+static void destroy_keyid(struct reiser4_crypto_info * info)
++static void destroy_keyid(crypto_stat_t * info)
+{
+ assert("edward-1370", info != NULL);
+ assert("edward-1371", info->keyid != NULL);
+ return;
+}
+
-+static void __free_crypto_info (struct inode * inode)
++static void free_crypto_stat (crypto_stat_t * info)
+{
-+ struct reiser4_crypto_info * info = inode_crypto_info(inode);
+ assert("edward-1372", info != NULL);
+
+ free_crypto_tfms(info);
+}
+
+#if 0
-+static void instantiate_crypto_info(struct reiser4_crypto_info * info)
++static void instantiate_crypto_stat(crypto_stat_t * info)
+{
+ assert("edward-1373", info != NULL);
+ assert("edward-1374", info->inst == 0);
+}
+#endif
+
-+static void uninstantiate_crypto_info(struct reiser4_crypto_info * info)
++static void uninstantiate_crypto_stat(crypto_stat_t * info)
+{
+ assert("edward-1375", info != NULL);
+ info->inst = 0;
+}
+
-+static int is_crypto_info_instantiated(struct reiser4_crypto_info * info)
++static int crypto_stat_instantiated(crypto_stat_t * info)
+{
+ return info->inst;
+}
+static int inode_has_cipher_key(struct inode * inode)
+{
+ assert("edward-1376", inode != NULL);
-+ return inode_crypto_info(inode) &&
-+ is_crypto_info_instantiated(inode_crypto_info(inode));
++ return inode_crypto_stat(inode) &&
++ crypto_stat_instantiated(inode_crypto_stat(inode));
+}
+
-+static void free_crypto_info (struct inode * inode)
++static void inode_free_crypto_stat (struct inode * inode)
+{
-+ uninstantiate_crypto_info(inode_crypto_info(inode));
-+ __free_crypto_info(inode);
++ uninstantiate_crypto_stat(inode_crypto_stat(inode));
++ free_crypto_stat(inode_crypto_stat(inode));
+}
+
+static int need_cipher(struct inode * inode)
+ cipher_plugin_by_id(NONE_CIPHER_ID);
+}
+
-+/* 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 */
++/* Create a crypto-stat and attach result to the @object.
++ If success is returned, then low-level cipher info contains
++ an instantiated key */
+#if 0
-+struct reiser4_crypto_info * create_crypto_info(struct inode * object,
-+ struct reiser4_crypto_data * data)
++crypto_stat_t *
++create_crypto_stat(struct inode * object,
++ crypto_data_t * data /* this contains a (uninstantiated)
++ cipher key imported from user
++ space */)
+{
+ int ret;
-+ struct reiser4_crypto_info * info;
++ crypto_stat_t * info;
+
+ assert("edward-1377", data != NULL);
+ assert("edward-1378", need_cipher(object));
+ file_plugin_by_id(DIRECTORY_FILE_PLUGIN_ID))
+ return ERR_PTR(-EINVAL);
+
-+ info = reiser4_alloc_crypto_info(object);
++ info = alloc_crypto_stat(object);
+ if (IS_ERR(info))
+ return info;
-+ ret = alloc_crypto_tfms(info);
++ ret = alloc_crypto_tfms(reiser4_inode_data(object)->pset, 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_blkcipher_setkey(info_get_cipher(info),
-+ data->key,
-+ data->keysize);
++ ret = crypto_cipher_setkey(info_cipher_tfm(info),
++ data->key,
++ data->keysize);
+ if (ret) {
+ warning("edward-1379",
-+ "setkey failed flags=%x",
-+ crypto_blkcipher_get_flags(info_get_cipher(info)));
++ "setkey failed flags=%x\n",
++ info_cipher_tfm(info)->crt_flags);
+ goto err;
+ }
+ info->keysize = data->keysize;
+ ret = create_keyid(info, data);
+ if (ret)
+ goto err;
-+ instantiate_crypto_info(info);
++ instantiate_crypto_stat(info);
+ return info;
+ err:
-+ __free_crypto_info(object);
++ free_crypto_stat(info);
+ 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_info(struct reiser4_crypto_info * info)
++static void load_crypto_stat(crypto_stat_t * info)
+{
+ assert("edward-1380", info != NULL);
+ inc_keyload_count(info);
+}
+
-+static void unload_crypto_info(struct inode * inode)
++static void unload_crypto_stat(struct inode * inode)
+{
-+ struct reiser4_crypto_info * info = inode_crypto_info(inode);
++ crypto_stat_t * info = inode_crypto_stat(inode);
+ assert("edward-1381", info->keyload_count > 0);
+
-+ dec_keyload_count(inode_crypto_info(inode));
++ dec_keyload_count(inode_crypto_stat(inode));
+ if (info->keyload_count == 0)
+ /* final release */
-+ free_crypto_info(inode);
++ inode_free_crypto_stat(inode);
+}
+
+/* attach/detach an existing crypto-stat */
-+void reiser4_attach_crypto_info(struct inode * inode,
-+ struct reiser4_crypto_info * info)
++void attach_crypto_stat(struct inode * inode, crypto_stat_t * info)
+{
+ assert("edward-1382", inode != NULL);
+ assert("edward-1383", info != NULL);
-+ assert("edward-1384", inode_crypto_info(inode) == NULL);
++ assert("edward-1384", inode_crypto_stat(inode) == NULL);
+
-+ set_inode_crypto_info(inode, info);
-+ load_crypto_info(info);
++ set_inode_crypto_stat(inode, info);
++ load_crypto_stat(info);
+}
+
+/* returns true, if crypto stat can be attached to the @host */
+#if REISER4_DEBUG
-+static int host_allows_crypto_info(struct inode * host)
++static int host_allows_crypto_stat(struct inode * host)
+{
+ int ret;
+ file_plugin * fplug = inode_file_plugin(host);
+
+ switch (fplug->h.id) {
-+ case CRYPTCOMPRESS_FILE_PLUGIN_ID:
++ case CRC_FILE_PLUGIN_ID:
+ ret = 1;
+ break;
+ default:
+}
+#endif /* REISER4_DEBUG */
+
-+static void reiser4_detach_crypto_info(struct inode * inode)
++void detach_crypto_stat(struct inode * inode)
+{
+ assert("edward-1385", inode != NULL);
-+ assert("edward-1386", host_allows_crypto_info(inode));
++ assert("edward-1386", host_allows_crypto_stat(inode));
+
-+ if (inode_crypto_info(inode))
-+ unload_crypto_info(inode);
-+ set_inode_crypto_info(inode, NULL);
++ if (inode_crypto_stat(inode))
++ unload_crypto_stat(inode);
++ set_inode_crypto_stat(inode, NULL);
+}
+
+#if 0
+
+/* compare fingerprints of @child and @parent */
-+static int keyid_eq(struct reiser4_crypto_info * child,
-+ struct reiser4_crypto_info * parent)
++static int keyid_eq(crypto_stat_t * child, crypto_stat_t * 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_cryptcompress(struct inode *child, struct inode *parent)
++int can_inherit_crypto_crc(struct inode *child, struct inode *parent)
+{
+ if (!need_cipher(child))
+ return 0;
+ /* the child is created */
-+ if (!inode_crypto_info(child))
++ if (!inode_crypto_stat(child))
+ return 1;
+ /* the child is looked up */
-+ if (!inode_crypto_info(parent))
++ if (!inode_crypto_stat(parent))
+ return 0;
+ return (inode_cipher_plugin(child) == inode_cipher_plugin(parent) &&
+ inode_digest_plugin(child) == inode_digest_plugin(parent) &&
-+ inode_crypto_info(child)->keysize ==
-+ inode_crypto_info(parent)->keysize &&
-+ keyid_eq(inode_crypto_info(child), inode_crypto_info(parent)));
++ inode_crypto_stat(child)->keysize == inode_crypto_stat(parent)->keysize &&
++ keyid_eq(inode_crypto_stat(child), inode_crypto_stat(parent)));
+}
+#endif
+
+static int inode_set_crypto(struct inode * object)
+{
+ reiser4_inode * info;
-+ if (!inode_crypto_info(object)) {
++ if (!inode_crypto_stat(object)) {
+ if (need_cipher(object))
+ return RETERR(-EINVAL);
+ /* the file is not to be encrypted */
+ }
+ info = reiser4_inode_data(object);
+ info->extmask |= (1 << CRYPTO_STAT);
++ info->plugin_mask |= (1 << PSET_CIPHER) | (1 << PSET_DIGEST);
+ return 0;
+}
+
-+static int inode_init_compression(struct inode * object)
++static int
++inode_set_compression(struct inode * object)
+{
+ int result = 0;
-+ assert("edward-1461", object != NULL);
-+ if (inode_compression_plugin(object)->init)
-+ result = inode_compression_plugin(object)->init();
-+ return result;
++ 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;
+}
+
-+static int inode_check_cluster(struct inode * object)
++static int inode_set_cluster(struct inode *object)
+{
++ reiser4_inode *info;
++ cluster_plugin *cplug;
++
+ assert("edward-696", object != NULL);
+
-+ 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);
++ 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);
+ 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-1464", INODE_PGCOUNT(inode) == 0);
-+ reiser4_detach_crypto_info(inode);
++ assert("edward-23", cryptcompress_inode_data(inode)->pgcount == 0);
++ detach_crypto_stat(inode);
+ return;
+}
+
+. 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;
+ assert("edward-23", object != NULL);
+ assert("edward-24", parent != NULL);
+ assert("edward-30", data != NULL);
-+ assert("edward-26", reiser4_inode_get_flag(object, REISER4_NO_SD));
-+ assert("edward-27", data->id == CRYPTCOMPRESS_FILE_PLUGIN_ID);
++ assert("edward-26", inode_get_flag(object, REISER4_NO_SD));
++ assert("edward-27", data->id == CRC_FILE_PLUGIN_ID);
+
+ info = reiser4_inode_data(object);
+
+ if (result)
+ goto error;
+ /* set compression */
-+ result = inode_init_compression(object);
++ result = inode_set_compression(object);
+ if (result)
+ goto error;
-+ /* set cluster */
-+ result = inode_check_cluster(object);
++ inode_set_compression_mode(object);
++
++ /* set cluster info */
++ result = inode_set_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:
-+ reiser4_detach_crypto_info(object);
++ detach_crypto_stat(object);
+ return result;
+}
+
-+/* ->open_object() method of the cryptcompress plugin */
-+int open_object_cryptcompress(struct inode * inode, struct file * file)
++/* ->open() method of the cryptcompress plugin */
++int open_cryptcompress(struct inode * inode, struct file * file)
+{
-+ int result;
+ struct inode * parent;
+
+ assert("edward-1394", inode != NULL);
+ assert("edward-1399", file->f_dentry->d_parent->d_inode != NULL);
+ assert("edward-698",
+ inode_file_plugin(inode) ==
-+ 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;
++ file_plugin_by_id(CRC_FILE_PLUGIN_ID));
++
+ if (!need_cipher(inode))
+ /* the file is not to be ciphered */
+ return 0;
+cipher_blocksize(struct inode * inode)
+{
+ assert("edward-758", need_cipher(inode));
-+ assert("edward-1400", inode_crypto_info(inode) != NULL);
-+ return crypto_blkcipher_blocksize
-+ (info_get_cipher(inode_crypto_info(inode)));
++ assert("edward-1400", inode_crypto_stat(inode) != NULL);
++ return crypto_tfm_alg_blocksize
++ (info_cipher_tfm(inode_crypto_stat(inode)));
+}
+
+/* returns offset translated by scale factor of the crypto-algorithm */
+ assert("edward-97", inode != NULL);
+
+ if (!need_cipher(inode) ||
-+ src_off == get_key_offset(reiser4_min_key()) ||
-+ src_off == get_key_offset(reiser4_max_key()))
++ src_off == get_key_offset(min_key()) ||
++ src_off == get_key_offset(max_key()))
+ return src_off;
+
+ return inode_cipher_plugin(inode)->scale(inode,
+ 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(struct cluster_handle * clust,
-+ struct inode *inode)
++static void set_cluster_nrpages(reiser4_cluster_t * clust, struct inode *inode)
+{
-+ struct reiser4_slide * win;
++ reiser4_slide_t *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) {
-+ clust->nr_pages = size_in_pages(lbytes(clust->index, inode));
++ /* NOTE-EDWARD: i_size should be protected */
++ clust->nr_pages =
++ count_to_nrpages(fsize_to_count(clust, inode));
+ return;
+ }
-+ assert("edward-1176", clust->op != LC_INVAL);
++ assert("edward-1176", clust->op != PCL_UNKNOWN);
+ 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: writing a "fake" logical cluster */
++ /* special case: we start write hole from fake cluster */
+ clust->nr_pages = 0;
+ return;
+ }
-+ clust->nr_pages = size_in_pages(max(win->off + win->count + win->delta,
-+ lbytes(clust->index, inode)));
++ clust->nr_pages =
++ count_to_nrpages(max_count(win->off + win->count + win->delta,
++ fsize_to_count(clust, inode)));
+ return;
+}
+
-+/* plugin->key_by_inode()
-+ build key of a disk cluster */
-+int key_by_inode_cryptcompress(struct inode *inode, loff_t off,
-+ reiser4_key * key)
++/* ->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)
+{
++ 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 */
+
-+ 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);
++ clust_off =
++ (off ==
++ get_key_offset(max_key())? get_key_offset(max_key()) :
++ off_to_clust_to_off(off, inode));
+
+ key_by_inode_and_offset_common(inode, 0, key);
-+ set_key_offset(key, (__u64)off);
++ set_key_offset(key,
++ (__u64) (!inode_crypto_stat(inode) ? clust_off :
++ inode_scaled_offset(inode, clust_off)));
+ return 0;
+}
+
-+/* 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 */)
++/* 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 */ )
+{
+ assert("edward-436", f != NULL);
+ assert("edward-149", inode != NULL);
+ assert("edward-150", inode_file_plugin(inode) != NULL);
-+ assert("edward-1465", user == 0); /* we use flow to read/write
-+ disk clusters located in
-+ kernel space */
++ assert("edward-151",
++ inode_file_plugin(inode)->key_by_inode ==
++ key_by_inode_cryptcompress);
++
+ 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
-+cryptcompress_hint_validate(hint_t * hint, const reiser4_key * key,
-+ znode_lock_mode lock_mode)
++crc_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_is_valid(hint));
++ assert("edward-1089", !hint->ext_coord.valid);
+ assert("edward-706", hint->lh.owner == NULL);
+
+ coord = &hint->ext_coord.coord;
+ /* hint is set for different key */
+ return RETERR(-E_REPEAT);
+
-+ assert("edward-707", reiser4_schedulable());
++ assert("edward-707", schedulable());
+
-+ return reiser4_seal_validate(&hint->seal, &hint->ext_coord.coord,
-+ key, &hint->lh, lock_mode,
-+ ZNODE_LOCK_LOPRI);
++ return 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, struct cluster_handle *clust)
++static int reserve4cluster(struct inode *inode, reiser4_cluster_t *clust)
+{
+ int result = 0;
+
-+ assert("edward-965", reiser4_schedulable());
++ assert("edward-965", 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 disk space for fake logical cluster */
++ /* don't reserve space for fake disk clusteer */
+ return 0;
+ }
+ assert("edward-442", jprivate(clust->pages[0]) != NULL);
+ 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,
-+ struct cluster_handle *ch, int count)
++static void
++free_reserved4cluster(struct inode *inode, reiser4_cluster_t * clust, int count)
+{
-+ assert("edward-967", ch->reserved == 1);
++ assert("edward-967", clust->reserved == 1);
+
+ cluster_reserved2free(count);
-+ ch->reserved = 0;
++ clust->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 */ ,
+{
+ 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_is_valid(hint)) {
-+ result = cryptcompress_hint_validate(hint, key, lock_mode);
++ if (hint->ext_coord.valid == 0) {
++ result = crc_hint_validate(hint, key, lock_mode);
+ if (result == -E_REPEAT)
+ goto traverse_tree;
+ else if (result) {
+ assert("edward-1216", 0);
+ return result;
+ }
-+ hint_set_valid(hint);
++ hint->ext_coord.valid = 1;
+ }
+ assert("edward-709", znode_is_any_locked(coord->node));
+
+ if (result)
+ return result;
+ assert("edward-1218", equal_to_ldk(coord->node, key));
-+ went_right = 1;
+ } else {
+ coord->item_pos++;
+ coord->unit_pos = 0;
+ 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 */
+ ON_DEBUG(coord_update_v(coord));
+ return CBK_COORD_NOTFOUND;
+
-+ traverse_tree:
++ traverse_tree:
+ assert("edward-713", hint->lh.owner == NULL);
-+ assert("edward-714", reiser4_schedulable());
++ assert("edward-714", schedulable());
+
-+ reiser4_unset_hint(hint);
-+ dclust_init_extension(hint);
++ unset_hint(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;
-+ if(result == CBK_COORD_FOUND)
-+ dclust_inc_extension_ncount(hint);
-+ hint_set_valid(hint);
++ hint->ext_coord.valid = 1;
+ return result;
+}
+
+ 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,
-+ struct cluster_handle * ch, rw_op rw, int * oh)
++static int
++need_cut_or_align(struct inode * inode, reiser4_cluster_t * clust,
++ rw_op rw, int * oh)
+{
-+ struct tfm_cluster * tc = &ch->tc;
++ tfm_cluster_t * tc = &clust->tc;
+ switch (rw) {
+ case WRITE_OP: /* estimate align */
+ *oh = tc->len % cipher_blocksize(inode);
+ return 1;
+ break;
+ case READ_OP: /* estimate cut */
-+ *oh = *(tfm_output_data(ch) + tc->len - 1);
++ *oh = *(tfm_output_data(clust) + tc->len - 1);
+ break;
+ default:
+ impossible("edward-1401", "bad option");
+}
+
+/* create/cut an overhead of transformed/plain stream */
-+static void align_or_cut_overhead(struct inode * inode,
-+ struct cluster_handle * ch, rw_op rw)
++static void
++align_or_cut_overhead(struct inode * inode, reiser4_cluster_t * clust, rw_op rw)
+{
+ int oh;
+ cipher_plugin * cplug = inode_cipher_plugin(inode);
+
+ assert("edward-1402", need_cipher(inode));
+
-+ if (!need_cut_or_align(inode, ch, rw, &oh))
++ if (!need_cut_or_align(inode, clust, rw, &oh))
+ return;
+ switch (rw) {
+ case WRITE_OP: /* do align */
-+ ch->tc.len +=
-+ cplug->align_stream(tfm_input_data(ch) +
-+ ch->tc.len, ch->tc.len,
++ clust->tc.len +=
++ cplug->align_stream(tfm_input_data(clust) +
++ clust->tc.len, clust->tc.len,
+ cipher_blocksize(inode));
-+ *(tfm_input_data(ch) + ch->tc.len - 1) =
++ *(tfm_input_data(clust) + clust->tc.len - 1) =
+ cipher_blocksize(inode) - oh;
+ break;
+ case READ_OP: /* do cut */
+ assert("edward-1403", oh <= cipher_blocksize(inode));
-+ ch->tc.len -= oh;
++ clust->tc.len -= oh;
+ break;
+ default:
+ impossible("edward-1404", "bad option");
+ return;
+}
+
-+static unsigned max_cipher_overhead(struct inode * inode)
++/* the following two functions are to evaluate results
++ of compression transform */
++static unsigned
++max_cipher_overhead(struct inode * inode)
+{
+ if (!need_cipher(inode) || !inode_cipher_plugin(inode)->align_stream)
+ return 0;
+ If this returns false, then compressor won't be called for
+ the cluster of index @index.
+*/
-+static int should_compress(struct tfm_cluster * tc, cloff_t index,
++static int should_compress(tfm_cluster_t * tc, cloff_t index,
+ struct inode *inode)
+{
+ compression_plugin *cplug = inode_compression_plugin(inode);
+
+/* 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(struct cluster_handle * ch, struct inode * inode,
-+ int encrypted /* is cluster encrypted */ )
++static int
++need_inflate(reiser4_cluster_t * clust, struct inode *inode,
++ int encrypted /* is cluster encrypted */ )
+{
-+ struct tfm_cluster * tc = &ch->tc;
++ tfm_cluster_t *tc = &clust->tc;
+
+ assert("edward-142", tc != 0);
+ assert("edward-143", inode != NULL);
+ 1 <= overhead <= cipher_blksize
+*/
+/* Append a checksum at the end of a transformed stream */
-+static void dc_set_checksum(compression_plugin * cplug, struct tfm_cluster * tc)
++static void dc_set_checksum(compression_plugin * cplug, tfm_cluster_t * tc)
+{
+ __u32 checksum;
+
+
+/* Check a disk cluster checksum.
+ Returns 0 if checksum is correct, otherwise returns 1 */
-+static int dc_check_checksum(compression_plugin * cplug, struct tfm_cluster * tc)
++static int dc_check_checksum(compression_plugin * cplug, tfm_cluster_t * tc)
+{
+ assert("edward-1312", tc != NULL);
+ assert("edward-1313", tc->len > (int)DC_CHECKSUM_SIZE);
+}
+
+/* get input/output stream for some transform action */
-+int grab_tfm_stream(struct inode * inode, struct tfm_cluster * tc,
++int grab_tfm_stream(struct inode * inode, tfm_cluster_t * tc,
+ tfm_stream_id id)
+{
+ size_t size = inode_scaled_cluster_size(inode);
+ assert("edward-901", tc != NULL);
+ assert("edward-1027", inode_compression_plugin(inode) != NULL);
+
-+ if (cluster_get_tfm_act(tc) == TFMA_WRITE)
++ if (tc->act == TFM_WRITE_ACT)
+ size += deflate_overrun(inode, inode_cluster_size(inode));
+
-+ if (!get_tfm_stream(tc, id) && id == INPUT_STREAM)
++ if (!tfm_stream(tc, id) && id == INPUT_STREAM)
+ alternate_streams(tc);
-+ if (!get_tfm_stream(tc, id))
++ if (!tfm_stream(tc, id))
+ return alloc_tfm_stream(tc, size, id);
+
+ assert("edward-902", tfm_stream_is_set(tc, id));
+}
+
+/* Common deflate manager */
-+int reiser4_deflate_cluster(struct cluster_handle * clust, struct inode * inode)
++int deflate_cluster(reiser4_cluster_t * clust, struct inode * inode)
+{
+ int result = 0;
+ int compressed = 0;
+ int encrypted = 0;
-+ struct tfm_cluster * tc = &clust->tc;
++ tfm_cluster_t * tc = &clust->tc;
+ compression_plugin * coplug;
+
+ assert("edward-401", inode != NULL);
+ assert("edward-903", tfm_stream_is_set(tc, INPUT_STREAM));
-+ assert("edward-1348", cluster_get_tfm_act(tc) == TFMA_WRITE);
++ assert("edward-1348", tc->act == TFM_WRITE_ACT);
+ assert("edward-498", !tfm_cluster_is_uptodate(tc));
+
+ coplug = inode_compression_plugin(inode);
+ }
+ else {
+ /* bad result, discard */
-+#if 0
++#if REISER4_DEBUG
+ if (cluster_is_complete(clust, inode))
-+ warning("edward-1496",
++ warning("edward-1338",
+ "incompressible cluster %lu (inode %llu)",
+ clust->index,
+ (unsigned long long)get_inode_oid(inode));
+ cipher:
+ if (need_cipher(inode)) {
+ cipher_plugin * ciplug;
-+ struct blkcipher_desc desc;
++ struct crypto_tfm * tfm;
+ struct scatterlist src;
+ struct scatterlist dst;
+
+ ciplug = inode_cipher_plugin(inode);
-+ desc.tfm = info_get_cipher(inode_crypto_info(inode));
-+ desc.flags = 0;
++ tfm = info_cipher_tfm(inode_crypto_stat(inode));
+ if (compressed)
+ alternate_streams(tc);
+ result = grab_tfm_stream(inode, tc, OUTPUT_STREAM);
+ dst.offset = offset_in_page(tfm_output_data(clust));
+ dst.length = tc->len;
+
-+ result = crypto_blkcipher_encrypt(&desc, &dst, &src, tc->len);
++ result = crypto_cipher_encrypt(tfm, &dst, &src, tc->len);
+ if (result) {
+ warning("edward-1405",
-+ "encryption failed flags=%x\n", desc.flags);
++ "encryption failed flags=%x\n", tfm->crt_flags);
+ return result;
+ }
+ encrypted = 1;
+}
+
+/* Common inflate manager. */
-+int reiser4_inflate_cluster(struct cluster_handle * clust, struct inode * inode)
++int inflate_cluster(reiser4_cluster_t * clust, struct inode * inode)
+{
+ int result = 0;
+ int transformed = 0;
-+ struct tfm_cluster * tc = &clust->tc;
++ tfm_cluster_t * 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 == TFMA_READ);
++ assert("edward-1349", tc->act == TFM_READ_ACT);
+ assert("edward-907", !tfm_cluster_is_uptodate(tc));
+
+ /* Handle a checksum (if any) */
+ if (need_inflate(clust, inode, need_cipher(inode)) &&
+ coplug->checksum != NULL) {
+ result = dc_check_checksum(coplug, tc);
-+ if (unlikely(result)) {
-+ warning("edward-1460",
-+ "Inode %llu: disk cluster %lu looks corrupted",
-+ (unsigned long long)get_inode_oid(inode),
-+ clust->index);
++ if (result)
+ return RETERR(-EIO);
-+ }
+ }
+ if (need_cipher(inode)) {
+ cipher_plugin * ciplug;
-+ struct blkcipher_desc desc;
++ struct crypto_tfm * tfm;
+ struct scatterlist src;
+ struct scatterlist dst;
+
+ ciplug = inode_cipher_plugin(inode);
-+ desc.tfm = info_get_cipher(inode_crypto_info(inode));
-+ desc.flags = 0;
++ tfm = info_cipher_tfm(inode_crypto_stat(inode));
+ result = grab_tfm_stream(inode, tc, OUTPUT_STREAM);
+ if (result)
+ return result;
+ dst.offset = offset_in_page(tfm_output_data(clust));
+ dst.length = tc->len;
+
-+ result = crypto_blkcipher_decrypt(&desc, &dst, &src, tc->len);
-+ if (result) {
-+ warning("edward-1600", "decrypt failed flags=%x\n",
-+ desc.flags);
++ result = crypto_cipher_decrypt(tfm, &dst, &src, tc->len);
++ if (result)
+ return result;
-+ }
+ align_or_cut_overhead(inode, clust, READ_OP);
+ transformed = 1;
+ }
+int readpage_cryptcompress(struct file *file, struct page *page)
+{
+ reiser4_context *ctx;
-+ struct cluster_handle clust;
++ reiser4_cluster_t clust;
+ item_plugin *iplug;
+ int result;
+
+ assert("vs-976", !PageUptodate(page));
+ assert("edward-89", page->mapping && page->mapping->host);
+
-+ ctx = reiser4_init_context(page->mapping->host->i_sb);
-+ if (IS_ERR(ctx)) {
-+ unlock_page(page);
++ ctx = init_context(page->mapping->host->i_sb);
++ if (IS_ERR(ctx))
+ return PTR_ERR(ctx);
++ result = check_cryptcompress(page->mapping->host);
++ if (result) {
++ unlock_page(page);
++ reiser4_exit_context(ctx);
++ return result;
+ }
+ assert("edward-113",
+ ergo(file != NULL,
+
+ if (PageUptodate(page)) {
+ warning("edward-1338", "page is already uptodate\n");
-+ unlock_page(page);
+ reiser4_exit_context(ctx);
+ return 0;
+ }
+ 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;
+}
+
-+/* number of pages to check in */
-+static int get_new_nrpages(struct cluster_handle * clust)
++/* how much pages will be captured */
++static int cluster_nrpages_to_capture(reiser4_cluster_t * clust)
+{
+ switch (clust->op) {
-+ case LC_APPOV:
++ case PCL_APPEND:
+ return clust->nr_pages;
-+ case LC_TRUNC:
++ case PCL_TRUNCATE:
+ assert("edward-1179", clust->win != NULL);
-+ return size_in_pages(clust->win->off + clust->win->count);
++ return count_to_nrpages(clust->win->off + clust->win->count);
+ default:
+ impossible("edward-1180", "bad page cluster option");
+ return 0;
+ }
+}
+
-+static void set_cluster_pages_dirty(struct cluster_handle * clust,
-+ struct inode * inode)
++static void set_cluster_pages_dirty(reiser4_cluster_t * clust)
+{
+ int i;
+ struct page *pg;
-+ int nrpages = get_new_nrpages(clust);
++ int nrpages = cluster_nrpages_to_capture(clust);
+
+ for (i = 0; i < nrpages; i++) {
+
+ assert("edward-968", pg != NULL);
+ lock_page(pg);
+ assert("edward-1065", PageUptodate(pg));
-+ reiser4_set_page_dirty_internal(pg);
++ set_page_dirty_internal(pg);
+ unlock_page(pg);
+ mark_page_accessed(pg);
+ }
+}
+
-+/* Grab a page cluster for read/write operations.
-+ Attach a jnode for write operations (when preparing for modifications, which
-+ are supposed to be committed).
++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);
+
-+ 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).
++ 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.
+*/
-+int grab_page_cluster(struct inode * inode,
-+ struct cluster_handle * clust, rw_op rw)
++static int
++grab_cluster_pages_jnode(struct inode *inode, reiser4_cluster_t * clust)
+{
+ int i;
+ int result = 0;
+
+ 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)
+ assert("edward-1044", clust->pages[i] == NULL);
+
+ clust->pages[i] =
-+ find_or_create_page(inode->i_mapping,
-+ clust_to_pg(clust->index, inode) + i,
-+ reiser4_ctx_gfp_mask_get());
++ grab_cache_page(inode->i_mapping,
++ clust_to_pg(clust->index, inode) + i);
+ if (!clust->pages[i]) {
+ result = RETERR(-ENOMEM);
+ break;
+ }
-+ if (i == 0 && rw == WRITE_OP) {
++ if (i == 0) {
+ node = jnode_of_page(clust->pages[i]);
+ if (IS_ERR(node)) {
+ result = PTR_ERR(node);
+ break;
+ }
+ JF_SET(node, JNODE_CLUSTER_PAGE);
-+ assert("edward-920", jprivate(clust->pages[0]));
++ unlock_page(clust->pages[i]);
++ assert("edward-919", node);
++ continue;
+ }
-+ INODE_PGCOUNT_INC(inode);
+ unlock_page(clust->pages[i]);
+ }
-+ if (unlikely(result)) {
-+ while (i) {
-+ put_cluster_page(clust->pages[--i]);
-+ INODE_PGCOUNT_DEC(inode);
-+ }
++ if (result) {
++ while (i)
++ page_cache_release(clust->pages[--i]);
+ if (node && !IS_ERR(node))
+ jput(node);
+ return result;
+ }
-+ clust->node = node;
++ assert("edward-920", jprivate(clust->pages[0]));
++#if REISER4_DEBUG
++ cryptcompress_inode_data(inode)->pgcount += clust->nr_pages;
++#endif
+ return 0;
+}
+
-+static void truncate_page_cluster_range(struct inode * inode,
-+ struct page ** pages,
-+ cloff_t index,
-+ int from, int count,
-+ int even_cows)
++/* Collect unlocked cluster pages only for read (not to modify) */
++static int grab_cluster_pages(struct inode *inode, reiser4_cluster_t * clust)
+{
-+ assert("edward-1467", count > 0);
-+ reiser4_invalidate_pages(inode->i_mapping,
-+ clust_to_pg(index, inode) + from,
-+ count, 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;
+}
+
-+/* Put @count pages starting from @from offset */
-+void __put_page_cluster(int from, int count,
-+ struct page ** pages, struct inode * inode)
++/* @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)
+{
+ int i;
-+ assert("edward-1468", pages != NULL);
-+ assert("edward-1469", inode != NULL);
-+ assert("edward-1470", from >= 0 && count >= 0);
+
-+ for (i = 0; i < count; i++) {
-+ assert("edward-1471", pages[from + i] != NULL);
-+ assert("edward-1472",
-+ pages[from + i]->index == pages[from]->index + i);
++ assert("edward-447", clust != NULL);
++ for (i = 0; i < clust->nr_pages; i++) {
++
++ assert("edward-449", clust->pages[i] != NULL);
+
-+ put_cluster_page(pages[from + i]);
-+ INODE_PGCOUNT_DEC(inode);
++ page_cache_release(clust->pages[i]);
+ }
+}
+
-+/*
-+ * 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)
++/* this is called when something is failed */
++static void release_cluster_pages_and_jnode(reiser4_cluster_t * clust)
+{
++ jnode *node;
++
+ assert("edward-445", clust != NULL);
+ assert("edward-922", clust->pages != NULL);
-+ assert("edward-446",
-+ ergo(clust->nr_pages != 0, clust->pages[0] != NULL));
++ assert("edward-446", clust->pages[0] != NULL);
+
-+ __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;
-+ }
-+ }
-+}
++ node = jprivate(clust->pages[0]);
+
-+#if REISER4_DEBUG
-+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;
++ assert("edward-447", node != NULL);
++
++ release_cluster_pages(clust);
++ jput(node);
+}
+
-+static int window_ok(struct reiser4_slide * win, struct inode *inode)
++#if REISER4_DEBUG
++static int window_ok(reiser4_slide_t * win, struct inode *inode)
+{
+ assert("edward-1115", win != NULL);
+ assert("edward-1116", ergo(win->delta, win->stat == HOLE_WINDOW));
+ (win->off + win->count + win->delta <= inode_cluster_size(inode));
+}
+
-+static int cluster_ok(struct cluster_handle * clust, struct inode *inode)
++static int cluster_ok(reiser4_cluster_t * clust, struct inode *inode)
+{
+ assert("edward-279", clust != NULL);
+
+ 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(struct reiser4_slide * win)
++static inline window_stat next_window_stat(reiser4_slide_t * win)
+{
+ assert("edward-1130", win != NULL);
+ return ((win->stat == HOLE_WINDOW && win->delta == 0) ?
+ HOLE_WINDOW : DATA_WINDOW);
+}
+
-+/* 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)
++/* 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)
+{
-+ struct reiser4_slide * win;
++ reiser4_slide_t *win;
+
+ assert("edward-185", clust != NULL);
+ assert("edward-438", clust->pages != NULL);
+
+ switch (win->stat) {
+ case DATA_WINDOW:
-+ /* increment */
++ /* increment window position */
+ clust->index++;
+ win->stat = DATA_WINDOW;
+ win->off = 0;
-+ win->count = min((loff_t)inode_cluster_size(inode), to_file);
++ win->count = min_count(inode_cluster_size(inode), to_file);
+ break;
+ case HOLE_WINDOW:
+ switch (next_window_stat(win)) {
+ case HOLE_WINDOW:
-+ /* skip */
++ /* set window to fit the offset we start write from */
+ 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((loff_t)(inode_cluster_size(inode) -
-+ win->count), to_file);
++ win->delta =
++ min_count(inode_cluster_size(inode) - win->count,
++ to_file);
+ break;
+ case DATA_WINDOW:
-+ /* stay */
++ /* do not move the window, just change its state,
++ off+count+delta=inv */
+ win->stat = DATA_WINDOW;
-+ /* off+count+delta=inv */
+ win->off = win->off + win->count;
+ win->count = win->delta;
+ win->delta = 0;
+{
+ int result = 0;
+
-+ assert("edward-978", reiser4_schedulable());
++ assert("edward-978", schedulable());
++ assert("edward-1265", get_current_context()->grabbed_blocks == 0);
+
-+ result = reiser4_grab_space_force(/* one for stat data update */
-+ estimate_update_common(inode),
-+ BA_CAN_COMMIT);
++ result = reiser4_grab_space_force( /* one for stat data update */
++ estimate_update_common(inode),
++ BA_CAN_COMMIT);
++ assert("edward-979", !result);
+ 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;
+ }
-+ reiser4_uncapture_block(node);
++
++ uncapture_block(node);
+ spin_unlock_atom(atom);
+ jput(node);
+}
+
-+static void put_found_pages(struct page **pages, int nr)
++void forget_cluster_pages(struct page **pages, int nr)
+{
+ int i;
+ for (i = 0; i < nr; i++) {
-+ assert("edward-1045", pages[i] != NULL);
-+ 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);
-+}
-+
-+static inline void unlock_cluster(jnode * node)
-+{
-+ spin_unlock_jnode(node);
-+}
-+
-+static inline void unlock_cluster_uncapture(jnode * node)
-+{
-+ uncapture_cluster_jnode(node);
-+}
-+
-+/* 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;
++ assert("edward-1045", pages[i] != NULL);
++ page_cache_release(pages[i]);
+ }
-+ inode_check_scale_nolock(inode, i_size_read(inode), new_size);
-+ i_size_write(inode, new_size);
-+ return;
+}
+
-+static inline void checkin_cluster_size(struct cluster_handle * clust,
-+ struct inode * inode)
++/* 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)
+{
-+ if (clust->win)
-+ checkin_file_size(clust, inode);
-+}
++ int result = 0;
++ int i;
++ int nr_pages = 0;
++ tfm_cluster_t *tc = &clust->tc;
+
-+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);
++ 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));
+
-+ node = clust->node;
++ result = grab_tfm_stream(inode, tc, INPUT_STREAM);
++ if (result) {
++ warning("edward-1430",
++ "alloc stream failed with ret=%d", result);
++ return result;
++ }
++ spin_lock_jnode(node);
++ assert("edward-1435", JF_ISSET(node, JNODE_DIRTY));
+
-+ 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);
++ /* 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);
+
-+ 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);
-+ }
++ assert("edward-983", clust->nr_pages == node->page_count + 1);
+#if REISER4_DEBUG
-+ clust->reserved_prepped -= estimate_update_cluster(inode);
++ node->page_count = 0;
+#endif
-+ return 0;
-+}
-+
-+/* Submit modifications of a logical cluster */
-+static int checkin_logical_cluster(struct cluster_handle * clust,
-+ struct inode *inode)
-+{
-+ int result = 0;
-+ jnode * node;
-+
-+ 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);
++ cluster_reserved2grabbed(estimate_update_cluster(inode));
++ uncapture_cluster_jnode(node);
+
-+ __put_page_cluster(0, to_put, clust->pages, inode);
-+ unlock_cluster_uncapture(node);
++ 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);
+
-+ /* 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-1280", nr_pages == clust->nr_pages);
++ /* Construct input stream from the checked out pages */
++ for (i = 0; i < clust->nr_pages; i++) {
++ char *data;
+
++ 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]);
-+ 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);
++ data = kmap(clust->pages[i]);
+
-+ /* this can be zero, as new file size is
-+ checked in before truncating pages */
-+ in_page = __mbp(tc->len, i);
++ assert("edward-986", cnt_to_pgcnt(tc->len, i) != 0);
+
-+ data = kmap(clust->pages[i]);
+ memcpy(tfm_stream_data(tc, INPUT_STREAM) + pg_to_off(i),
-+ data, in_page);
++ data, cnt_to_pgcnt(tc->len, i));
+ 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;
+ }
-+ 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;
++ 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;
+}
+
+/* set hint for the cluster of the index @index */
+ cloff_t index, znode_lock_mode mode)
+{
+ reiser4_key key;
-+ assert("edward-722", cryptcompress_inode_ok(inode));
++ assert("edward-722", crc_inode_ok(inode));
+ assert("edward-723",
+ inode_file_plugin(inode) ==
-+ file_plugin_by_id(CRYPTCOMPRESS_FILE_PLUGIN_ID));
++ file_plugin_by_id(CRC_FILE_PLUGIN_ID));
+
+ inode_file_plugin(inode)->key_by_inode(inode,
+ clust_to_off(index, inode),
+ &key);
+
-+ reiser4_seal_init(&hint->seal, &hint->ext_coord.coord, &key);
++ seal_init(&hint->seal, &hint->ext_coord.coord, &key);
+ hint->offset = get_key_offset(&key);
+ hint->mode = mode;
+}
+
-+void invalidate_hint_cluster(struct cluster_handle * clust)
++void invalidate_hint_cluster(reiser4_cluster_t * clust)
+{
+ assert("edward-1291", clust != NULL);
+ assert("edward-1292", clust->hint != NULL);
+
+ done_lh(&clust->hint->lh);
-+ hint_clr_valid(clust->hint);
++ clust->hint->ext_coord.valid = 0;
+}
+
-+void put_hint_cluster(struct cluster_handle * clust, struct inode *inode,
-+ znode_lock_mode mode)
++void put_hint_cluster(reiser4_cluster_t * clust, struct inode *inode,
++ znode_lock_mode mode)
+{
+ assert("edward-1286", clust != NULL);
+ assert("edward-1287", clust->hint != NULL);
+ invalidate_hint_cluster(clust);
+}
+
-+static int balance_dirty_page_cluster(struct cluster_handle * clust,
-+ struct inode *inode, loff_t off,
-+ loff_t to_file)
++static int
++balance_dirty_page_cluster(reiser4_cluster_t * 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", cryptcompress_inode_ok(inode));
++ assert("edward-725", crc_inode_ok(inode));
++ assert("edward-1272", get_current_context()->grabbed_blocks == 0);
+
+ /* set next window params */
-+ move_update_window(inode, clust, off, to_file);
++ update_cluster(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);
-+ mutex_lock(&info->checkin_mutex);
++ all_grabbed2free();
+ return 0;
+}
+
-+/* 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)
++/* 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)
+{
++ char *data;
+ int result = 0;
+ unsigned cl_off, cl_count = 0;
+ unsigned to_pg, pg_off;
-+ struct reiser4_slide * win;
++ reiser4_slide_t *win;
+
+ assert("edward-190", clust != NULL);
+ assert("edward-1069", clust->win != NULL);
+ assert("edward-191", inode != NULL);
-+ assert("edward-727", cryptcompress_inode_ok(inode));
++ assert("edward-727", crc_inode_ok(inode));
+ assert("edward-1171", clust->dstat != INVAL_DISK_CLUSTER);
+ assert("edward-1154",
+ ergo(clust->dstat != FAKE_DISK_CLUSTER, clust->reserved == 1));
+ assert("edward-192", cluster_ok(clust, inode));
+
+ if (win->off == 0 && win->count == inode_cluster_size(inode)) {
-+ /* 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);
++ /* the hole will be represented by fake disk cluster */
++ update_cluster(inode, clust, file_off, to_file);
+ return 0;
+ }
+ cl_count = win->count; /* number of zeroes to write */
+
+ assert("edward-284", page != NULL);
+
-+ to_pg = min((typeof(pg_off))PAGE_CACHE_SIZE - pg_off, cl_count);
++ to_pg = min_count(PAGE_CACHE_SIZE - pg_off, cl_count);
+ lock_page(page);
-+ zero_user_page(page, pg_off, to_pg, KM_USER0);
++ data = kmap_atomic(page, KM_USER0);
++ memset(data + pg_off, 0, to_pg);
++ flush_dcache_page(page);
++ kunmap_atomic(data, KM_USER0);
+ SetPageUptodate(page);
-+ reiser4_set_page_dirty_internal(page);
-+ mark_page_accessed(page);
+ unlock_page(page);
+
+ cl_off += to_pg;
+ pg_off = 0;
+ }
+ if (!win->delta) {
-+ /* only zeroes in this window, try to capture
-+ */
-+ result = checkin_logical_cluster(clust, inode);
++ /* only zeroes, try to capture */
++
++ set_cluster_pages_dirty(clust);
++ result = try_capture_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
-+ move_update_window(inode, clust, file_off, to_file);
++ update_cluster(inode, clust, file_off, to_file);
+ return result;
+}
+
+/*
-+ 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)
++ 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)
+
+ NOTE-EDWARD: Callers should handle the case when disk cluster
+ is incomplete (-EIO)
+*/
-+int find_disk_cluster(struct cluster_handle * clust,
-+ struct inode *inode, int read, znode_lock_mode mode)
++int
++find_cluster(reiser4_cluster_t * clust,
++ struct inode *inode, int read, int write)
+{
+ flow_t f;
+ hint_t *hint;
+ int result = 0;
-+ int was_grabbed;
++ unsigned long cl_idx;
+ ra_info_t ra_info;
+ file_plugin *fplug;
+ item_plugin *iplug;
-+ struct tfm_cluster *tc;
-+ struct cryptcompress_info * info;
++ tfm_cluster_t *tc;
++ int was_grabbed;
+
+ assert("edward-138", clust != NULL);
+ assert("edward-728", clust->hint != NULL);
-+ assert("edward-226", reiser4_schedulable());
++ assert("edward-225", read || write);
++ assert("edward-226", schedulable());
+ assert("edward-137", inode != NULL);
-+ assert("edward-729", cryptcompress_inode_ok(inode));
++ assert("edward-729", crc_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(clust->index, inode), READ_OP, &f);
-+ if (mode == ZNODE_WRITE_LOCK) {
++ clust_to_off(cl_idx, inode), READ_OP, &f);
++ if (write) {
+ /* 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(reiser4_max_key()));
++ set_key_offset(&ra_info.key_to_stop, get_key_offset(max_key()));
+
+ while (f.length) {
-+ result = find_cluster_item(hint, &f.key, mode,
-+ NULL, FIND_EXACT,
-+ (mode == ZNODE_WRITE_LOCK ?
-+ CBK_FOR_INSERT : 0));
++ result = find_cluster_item(hint,
++ &f.key,
++ (write ? ZNODE_WRITE_LOCK :
++ ZNODE_READ_LOCK), NULL, FIND_EXACT,
++ (write ? CBK_FOR_INSERT : 0));
+ switch (result) {
+ case CBK_COORD_NOTFOUND:
+ result = 0;
+ if (inode_scaled_offset
-+ (inode, clust_to_off(clust->index, inode)) ==
-+ get_key_offset(&f.key)) {
++ (inode,
++ clust_to_off(cl_idx,
++ inode)) == get_key_offset(&f.key)) {
+ /* first item not found, this is treated
+ as disk cluster is absent */
+ clust->dstat = FAKE_DISK_CLUSTER;
+ zrelse(hint->ext_coord.coord.node);
+ goto out;
+ }
-+ 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);
-+
++ if (write) {
++ znode_make_dirty(hint->ext_coord.coord.node);
+ znode_set_convertible(hint->ext_coord.coord.
+ node);
+ }
+ /* NOTE-EDWARD: Callers should handle the case
+ when disk cluster is incomplete (-EIO) */
+ tc->len = inode_scaled_cluster_size(inode) - f.length;
-+ tc->lsize = lbytes(clust->index, inode);
++ tc->lsize = fsize_to_count(clust, 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 if (clust->index == info->trunc_index) {
-+ clust->dstat = TRNC_DISK_CLUSTER;
-+ } else {
++ 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);
+ return result;
+}
+
-+int get_disk_cluster_locked(struct cluster_handle * clust, struct inode *inode,
-+ znode_lock_mode lock_mode)
++int
++get_disk_cluster_locked(reiser4_cluster_t * clust, struct inode *inode,
++ znode_lock_mode lock_mode)
+{
+ reiser4_key key;
+ ra_info_t ra_info;
+
-+ assert("edward-730", reiser4_schedulable());
++ assert("edward-730", schedulable());
+ assert("edward-731", clust != NULL);
+ assert("edward-732", inode != NULL);
+
-+ if (hint_is_valid(clust->hint)) {
++ if (clust->hint->ext_coord.valid) {
+ assert("edward-1293", clust->dstat != INVAL_DISK_CLUSTER);
+ assert("edward-1294",
+ znode_is_write_locked(clust->hint->lh.node));
+ 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(reiser4_max_key()));
++ set_key_offset(&ra_info.key_to_stop, get_key_offset(max_key()));
+
+ return find_cluster_item(clust->hint, &key, lock_mode, NULL, FIND_EXACT,
+ CBK_FOR_INSERT);
+ . 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,
-+ struct cluster_handle * clust)
++static int
++read_some_cluster_pages(struct inode *inode, reiser4_cluster_t * clust)
+{
+ int i;
+ int result = 0;
+ item_plugin *iplug;
-+ struct reiser4_slide * win = clust->win;
-+ znode_lock_mode mode = ZNODE_WRITE_LOCK;
++ reiser4_slide_t *win = clust->win;
+
+ 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
+ /* start write hole from fake disk cluster */
+ assert("edward-1117", win != NULL);
+ assert("edward-1118", win->stat == HOLE_WINDOW);
-+ assert("edward-1119", new_logical_cluster(clust, inode));
++ assert("edward-1119", new_cluster(clust, inode));
+ }
+#endif
-+ if (new_logical_cluster(clust, inode)) {
++ if (new_cluster(clust, inode)) {
+ /*
+ new page cluster is about to be written, nothing to read,
+ */
-+ assert("edward-734", reiser4_schedulable());
++ assert("edward-734", 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];
+ off = off_to_pgoff(win->off+win->count+win->delta);
+ if (off) {
+ lock_page(pg);
-+ zero_user_page(pg, off, PAGE_CACHE_SIZE - off,
-+ KM_USER0);
++ data = kmap_atomic(pg, KM_USER0);
++ memset(data + off, 0, PAGE_CACHE_SIZE - off);
++ flush_dcache_page(pg);
++ kunmap_atomic(data, KM_USER0);
+ unlock_page(pg);
+ }
+ }
+ unlock_page(pg);
+
+ if (win &&
-+ i >= size_in_pages(win->off) &&
++ i >= count_to_nrpages(win->off) &&
+ i < off_to_pg(win->off + win->count + win->delta))
+ /* page will be completely overwritten */
+ continue;
+ /* the last page is
+ partially modified,
+ not uptodate .. */
-+ (size_in_pages(i_size_read(inode)) <= pg->index)) {
++ (count_to_nrpages(inode->i_size) <= 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",
-+ size_in_pages(win->off + win->count +
-+ win->delta) - 1 == i);
++ count_to_nrpages(win->off + win->count +
++ win->delta) - 1 == i);
+
+ offset =
+ off_to_pgoff(win->off + win->count + win->delta);
-+ zero_user_page(pg, offset, PAGE_CACHE_SIZE - offset,
-+ KM_USER0);
++ memset(data + offset, 0, PAGE_CACHE_SIZE - offset);
++ flush_dcache_page(pg);
++ kunmap_atomic(data, 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, mode);
-+
-+ assert("edward-1526", ergo(!result, PageUptodate(pg)));
++ result = do_readpage_ctail(inode, clust, pg);
+ unlock_page(pg);
++ assert("edward-993", !result);
+ if (result) {
-+ warning("edward-219", "do_readpage_ctail failed");
++ impossible("edward-219",
++ "do_readpage_ctail returned crap");
+ 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_disk_cluster(clust, inode,
-+ 0 /* do not read items */,
-+ mode);
++ to make flush update convert its content */
++ result =
++ find_cluster(clust, inode, 0 /* do not read */ ,
++ 1 /* write */ );
++ assert("edward-994", !result);
+ }
+ out:
+ tfm_cluster_clr_uptodate(&clust->tc);
+ return result;
+}
+
-+static int should_create_unprepped_cluster(struct cluster_handle * clust,
-+ struct inode * inode)
++static int
++should_create_unprepped_cluster(reiser4_cluster_t * clust, struct inode *inode)
+{
+ assert("edward-737", clust != NULL);
+
+ case FAKE_DISK_CLUSTER:
+ if (clust->win &&
+ clust->win->stat == HOLE_WINDOW && clust->nr_pages == 0) {
-+ assert("edward-1172",
-+ new_logical_cluster(clust, inode));
++ assert("edward-1172", new_cluster(clust, inode));
+ return 0;
+ }
+ return 1;
+ }
+}
+
-+static int cryptcompress_make_unprepped_cluster(struct cluster_handle * clust,
-+ struct inode *inode)
++static int
++crc_make_unprepped_cluster(reiser4_cluster_t * clust, struct inode *inode)
+{
+ int result;
+
-+ assert("edward-1123", reiser4_schedulable());
++ assert("edward-1123", schedulable());
+ assert("edward-737", clust != NULL);
+ assert("edward-738", inode != NULL);
-+ assert("edward-739", cryptcompress_inode_ok(inode));
++ assert("edward-739", crc_inode_ok(inode));
+ assert("edward-1053", clust->hint != NULL);
++ assert("edward-1266", get_current_context()->grabbed_blocks == 0);
+
-+ if (!should_create_unprepped_cluster(clust, inode)) {
-+ if (clust->reserved) {
-+ cluster_reserved2free(estimate_insert_cluster(inode));
++ if (clust->reserved) {
++ cluster_reserved2grabbed(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;
+
-+ inode_add_bytes(inode, inode_cluster_size(inode));
-+
-+ assert("edward-743", cryptcompress_inode_ok(inode));
++ assert("edward-743", crc_inode_ok(inode));
++ assert("edward-1269", get_current_context()->grabbed_blocks == 0);
+ assert("edward-744", znode_is_write_locked(clust->hint->lh.node));
+
+ clust->dstat = UNPR_DISK_CLUSTER;
+ return 0;
+}
+
-+/* . 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)
++#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)
+{
+ assert("edward-177", inode != NULL);
-+ assert("edward-741", cryptcompress_inode_ok(inode));
++ assert("edward-741", crc_inode_ok(inode));
+ assert("edward-740", clust->pages != NULL);
+
+ set_cluster_nrpages(clust, inode);
+ reset_cluster_pgset(clust, cluster_nrpages(inode));
-+ return grab_page_cluster(inode, clust, rw);
++ return (capture ?
++ grab_cluster_pages_jnode(inode, clust) :
++ grab_cluster_pages(inode, clust));
+}
+
-+/* 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)
++/* 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)
+{
-+ int found;
++ int i;
++ int found = 0;
+ int nr_pages;
+ jnode *node;
+ struct page *pages[MAX_CLUSTER_NRPAGES];
+
-+ 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));
++ 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);
+ return;
+ }
-+ lock_cluster(node);
++ /* jnode is present and may be dirty */
++ nr_pages = count_to_nrpages(cnt_to_clcnt(inode->i_size, index, inode));
+
-+ 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);
++ found = find_get_pages(inode->i_mapping, clust_to_pg(index, inode),
++ nr_pages, pages);
++ spin_lock_jnode(node);
+ if (JF_ISSET(node, JNODE_DIRTY)) {
-+ /*
-+ * @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);
-+
++ /* someone has done modifications which are not
++ yet committed, so we need to release some resources */
++
+ /* 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);
+
-+ /* This will clear dirty bit, uncapture and unlock jnode */
-+ unlock_cluster_uncapture(node);
++ 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
++ }
+ } else
-+ 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)));
++ 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));
+ return;
+}
+
-+/*
-+ * 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)
++/* 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)
+{
+ int result = 0;
-+ struct reiser4_slide * win = clust->win;
++ reiser4_slide_t *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 != LC_INVAL);
++ assert("edward-1190", op != PCL_UNKNOWN);
+
+ clust->op = op;
+
-+ result = prepare_page_cluster(inode, clust, WRITE_OP);
++ result = prepare_page_cluster(inode, clust, 1);
+ 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;
+ }
+ assert("edward-1124", clust->dstat != INVAL_DISK_CLUSTER);
+
-+ result = cryptcompress_make_unprepped_cluster(clust, inode);
++ result = crc_make_unprepped_cluster(clust, inode);
+ if (result)
+ goto err2;
+ if (win && win->stat == HOLE_WINDOW) {
+ goto err2;
+ }
+ return 0;
-+ err2:
++ err2:
+ free_reserved4cluster(inode, clust,
+ estimate_update_cluster(inode));
-+ err1:
-+ put_page_cluster(clust, inode, WRITE_OP);
++ err1:
++ release_cluster_pages_and_jnode(clust);
+ assert("edward-1125", result == -ENOSPC);
+ return result;
+}
+
+/* set window by two offsets */
-+static void set_window(struct cluster_handle * clust,
-+ struct reiser4_slide * win, struct inode *inode,
-+ loff_t o1, loff_t o2)
++static void
++set_window(reiser4_cluster_t * clust, reiser4_slide_t * win,
++ struct inode *inode, loff_t o1, loff_t o2)
+{
+ assert("edward-295", clust != NULL);
+ assert("edward-296", inode != NULL);
+ clust->index = off_to_clust(o1, inode);
+
+ win->off = off_to_cloff(o1, inode);
-+ win->count = min((loff_t)(inode_cluster_size(inode) - win->off),
-+ o2 - o1);
++ win->count = min_count(inode_cluster_size(inode) - win->off, o2 - o1);
+ win->delta = 0;
+
+ clust->win = win;
+}
+
-+static int set_cluster_by_window(struct inode *inode,
-+ struct cluster_handle * clust,
-+ struct reiser4_slide * win, size_t length,
-+ loff_t file_off)
++static int
++set_cluster_by_window(struct inode *inode, reiser4_cluster_t * clust,
++ reiser4_slide_t * win, flow_t * f, loff_t file_off)
+{
+ int result;
+
+ if (result)
+ return result;
+
-+ if (file_off > i_size_read(inode)) {
++ if (file_off > inode->i_size) {
+ /* Uhmm, hole in cryptcompress file... */
+ loff_t hole_size;
+ hole_size = file_off - inode->i_size;
+ 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(inode_cluster_size(inode) -
-+ (win->off + win->count), length);
++ win->delta =
++ min_count(inode_cluster_size(inode) -
++ (win->off + win->count), f->length);
+ return 0;
+ }
-+ set_window(clust, win, inode, file_off, file_off + length);
++ set_window(clust, win, inode, file_off, file_off + f->length);
+ win->stat = DATA_WINDOW;
+ return 0;
+}
+
-+int set_cluster_by_page(struct cluster_handle * clust, struct page * page,
++int set_cluster_by_page(reiser4_cluster_t * clust, struct page * page,
+ int count)
+{
+ int result = 0;
-+ int (*setting_actor)(struct cluster_handle * clust, int count);
++ int (*setting_actor)(reiser4_cluster_t * 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(struct cluster_handle * clust)
++void reset_cluster_params(reiser4_cluster_t * clust)
+{
+ assert("edward-197", clust != NULL);
+
+ clust->tc.len = 0;
+}
+
-+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)
++/* 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)
+{
+ int i;
++ flow_t f;
+ hint_t *hint;
+ int result = 0;
-+ size_t count;
-+ struct reiser4_slide win;
-+ struct cluster_handle clust;
-+ struct cryptcompress_info * info;
++ size_t to_write = 0;
++ loff_t file_off;
++ reiser4_slide_t win;
++ reiser4_cluster_t clust;
+
-+ assert("edward-161", reiser4_schedulable());
-+ assert("edward-748", cryptcompress_inode_ok(inode));
++ assert("edward-161", schedulable());
++ assert("edward-748", crc_inode_ok(inode));
+ assert("edward-159", current_blocksize == PAGE_CACHE_SIZE);
+ assert("edward-1274", get_current_context()->grabbed_blocks == 0);
+
-+ hint = kmalloc(sizeof(*hint), reiser4_ctx_gfp_mask_get());
++ result = check_cryptcompress(inode);
++ if (result)
++ return result;
++ hint = kmalloc(sizeof(*hint), GFP_KERNEL);
+ if (hint == NULL)
+ return RETERR(-ENOMEM);
+
+ 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, to_write, pos);
++ result = set_cluster_by_window(inode, &clust, &win, &f, file_off);
+ if (result)
+ goto out;
+
+ if (next_window_stat(&win) == HOLE_WINDOW) {
-+ /* 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);
++ result =
++ prepare_cluster(inode, file_off, f.length, &clust,
++ PCL_APPEND);
+ if (result)
+ goto out;
+ }
+ do {
-+ const char __user * src;
-+ unsigned page_off, to_page;
++ char *src;
++ unsigned page_off, page_count;
+
-+ assert("edward-750", reiser4_schedulable());
++ assert("edward-750", schedulable());
+
-+ 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);
++ result =
++ prepare_cluster(inode, file_off, f.length, &clust,
++ PCL_APPEND);
+ if (result)
+ goto out;
+
-+ assert("edward-751", cryptcompress_inode_ok(inode));
++ assert("edward-751", crc_inode_ok(inode));
+ assert("edward-204", win.stat == DATA_WINDOW);
-+ assert("edward-1288", hint_is_valid(clust.hint));
++ assert("edward-1288", clust.hint->ext_coord.valid);
+ 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 = buf;
-+ i < size_in_pages(win.off + win.count);
-+ i++, src += to_page) {
-+ to_page = __mbp(win.off + win.count, i) - page_off;
++ 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;
++
+ assert("edward-1039",
-+ page_off + to_page <= PAGE_CACHE_SIZE);
++ page_off + page_count <= 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, src, to_page);
++ page_off, (char __user *)src, page_count);
+ kunmap(clust.pages[i]);
+ if (unlikely(result)) {
+ unlock_page(clust.pages[i]);
+ 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", cryptcompress_inode_ok(inode));
++ assert("edward-753", crc_inode_ok(inode));
+
-+ result = checkin_logical_cluster(&clust, inode);
++ set_cluster_pages_dirty(&clust);
++
++ result = try_capture_cluster(&clust, inode);
+ if (result)
+ goto err2;
+
-+ buf += win.count;
-+ count -= win.count;
++ assert("edward-998", f.user == 1);
++
++ move_flow_forward(&f, win.count);
+
-+ result = balance_dirty_page_cluster(&clust, inode, 0, 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);
+ if (result)
+ goto err1;
+ assert("edward-755", hint->lh.owner == NULL);
+ reset_cluster_params(&clust);
+ continue;
-+ err2:
-+ put_page_cluster(&clust, inode, WRITE_OP);
-+ err1:
++ err2:
++ release_cluster_pages_and_jnode(&clust);
++ err1:
+ if (clust.reserved)
+ free_reserved4cluster(inode,
+ &clust,
+ estimate_update_cluster(inode));
+ break;
-+ } while (count);
-+ out:
-+ /*
-+ * NOTE: at this point file may have
-+ * another (unix-file) plugin installed
-+ */
++ } while (f.length);
++ out:
+ done_lh(&hint->lh);
+ if (result == -EEXIST)
+ warning("edward-1407", "write returns EEXIST!\n");
+ 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 == count),
-+ (result < 0 || *conv_occured)));
-+ return (to_write - count) ? (to_write - count) : result;
++ assert("edward-195", ergo((to_write == f.length), result < 0));
++ return (to_write - f.length) ? (to_write - f.length) : 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
+ * cryptcompress plugin.
+ */
+ssize_t write_cryptcompress(struct file *file, const char __user *buf,
-+ size_t count, loff_t *off, int *conv)
++ size_t count, loff_t *off)
+{
+ 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 = reiser4_init_context(inode->i_sb);
++ ctx = init_context(inode->i_sb);
+ if (IS_ERR(ctx))
+ return PTR_ERR(ctx);
+
-+ 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);
++ mutex_lock(&inode->i_mutex);
+
-+ result = do_write_cryptcompress(file, inode, buf, count, pos, conv);
++ result = write_crc_file(file, inode, buf, count, off);
+
-+ if (result < 0)
-+ goto out;
-+ /* update position in a file */
-+ *off = pos + result;
-+ out:
+ mutex_unlock(&inode->i_mutex);
+
+ context_set_commit_async(ctx);
+ return result;
+}
+
-+int readpages_cryptcompress(struct file *file, struct address_space *mapping,
-+ struct list_head *pages, unsigned nr_pages)
++static void
++readpages_crc(struct address_space *mapping, struct list_head *pages,
++ void *data)
+{
-+ reiser4_context * ctx;
-+ int ret;
++ file_plugin *fplug;
++ item_plugin *iplug;
+
-+ 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;
++ 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);
++
++ return;
+}
+
+static reiser4_block_nr cryptcompress_estimate_read(struct inode *inode)
+ ssize_t result;
+ struct inode *inode;
+ reiser4_context *ctx;
-+ struct cryptcompress_info *info;
++ reiser4_file_fsdata *fsdata;
++ cryptcompress_info_t *info;
+ reiser4_block_nr needed;
+
+ inode = file->f_dentry->d_inode;
-+ assert("edward-1194", !reiser4_inode_get_flag(inode, REISER4_NO_SD));
++ assert("edward-1194", !inode_get_flag(inode, REISER4_NO_SD));
+
-+ ctx = reiser4_init_context(inode->i_sb);
++ ctx = 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;
+ }
-+ result = do_sync_read(file, buf, size, off);
++ 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);
+
+ context_set_commit_async(ctx);
+ reiser4_exit_context(ctx);
+ return result;
+}
+
-+/* 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)
++/* 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)
+{
+ int result;
+ reiser4_key key;
+ item_plugin *iplug;
+
+ assert("edward-1131", inode != NULL);
-+ assert("edward-95", cryptcompress_inode_ok(inode));
++ assert("edward-95", crc_inode_ok(inode));
+
-+ hint = kmalloc(sizeof(*hint), reiser4_ctx_gfp_mask_get());
++ hint = kmalloc(sizeof(*hint), GFP_KERNEL);
+ if (hint == NULL)
+ return RETERR(-ENOMEM);
+ hint_init_zero(hint);
+ bias = (index ? FIND_EXACT : FIND_MAX_NOT_MORE_THAN);
+ offset =
+ (index ? clust_to_off(index, inode) -
-+ 1 : get_key_offset(reiser4_max_key()));
++ 1 : get_key_offset(max_key()));
+
+ key_by_inode_cryptcompress(inode, offset, &key);
+
+
+static int find_fake_appended(struct inode *inode, cloff_t * index)
+{
-+ return lookup_disk_cluster(inode, index,
-+ 0 /* find last real one */ );
++ return find_real_disk_cluster(inode, index,
++ 0 /* find last real one */ );
+}
+
+/* Set left coord when unit is not found after node_lookup()
+}
+
+#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;
+ if (result != 0 && result != -E_NO_NEIGHBOR)
+ break;
+ /* FIXME-EDWARD: Check can we delete the node as a whole. */
-+ result = reiser4_tap_load(tap);
++ result = tap_load(tap);
+ if (result)
+ return result;
+
+ }
+
+ /* cut data from one node */
-+ *smallest_removed = *reiser4_min_key();
++ *smallest_removed = *min_key();
+ result = kill_node_content(&left_coord,
+ tap->coord,
+ from_key,
+ smallest_removed,
+ next_node_lock.node,
+ object, truncate);
-+ reiser4_tap_relse(tap);
++#if REISER4_DEBUG
++ /*node_check(node, ~0U); */
++#endif
++ tap_relse(tap);
+
+ if (result)
+ break;
+ if (next_node_lock.node == NULL)
+ break;
+
-+ result = reiser4_tap_move(tap, &next_node_lock);
++ result = tap_move(tap, &next_node_lock);
+ done_lh(&next_node_lock);
+ if (result)
+ break;
+ return result;
+}
+
-+/* 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)
++/* 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)
+{
+ int result = 0;
+ hint_t *hint;
+ lock_handle *lh;
+ loff_t hole_size;
+ int nr_zeroes;
-+ struct reiser4_slide win;
-+ struct cluster_handle clust;
++ reiser4_slide_t win;
++ reiser4_cluster_t clust;
+
+ assert("edward-1133", inode->i_size < new_size);
-+ assert("edward-1134", reiser4_schedulable());
-+ assert("edward-1135", cryptcompress_inode_ok(inode));
++ assert("edward-1134", schedulable());
++ assert("edward-1135", crc_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), reiser4_ctx_gfp_mask_get());
++ hint = kmalloc(sizeof(*hint), GFP_KERNEL);
+ if (hint == NULL)
+ return RETERR(-ENOMEM);
+ hint_init_zero(hint);
+ if (result)
+ goto out;
+ if (off_to_cloff(inode->i_size, inode) == 0)
-+ goto append_fake;
++ goto fake_append;
+ 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;
+ assert("edward-1137",
+ clust.index == off_to_clust(inode->i_size, inode));
+
-+ result = prepare_logical_cluster(inode, 0, 0, &clust, LC_APPOV);
++ result = prepare_cluster(inode, 0, 0, &clust, PCL_APPEND);
+
+ assert("edward-1271", !result || result == -ENOSPC);
+ if (result)
+ if (hole_size == nr_zeroes)
+ /* nothing to append anymore */
+ goto out;
-+ append_fake:
-+ INODE_SET_SIZE(inode, new_size);
-+ out:
++ fake_append:
++ INODE_SET_FIELD(inode, i_size, 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 : reiser4_update_file_size(inode, key, update_sd));
++ ? 0 : update_file_size(inode, key, update_sd));
+}
+
-+/* 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)
++/* 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)
+{
+ int result = 0;
+ unsigned nr_zeroes;
+
+ hint_t *hint;
+ lock_handle *lh;
-+ struct reiser4_slide win;
-+ struct cluster_handle clust;
++ reiser4_slide_t win;
++ reiser4_cluster_t clust;
+
+ assert("edward-1140", inode->i_size >= new_size);
-+ assert("edward-1141", reiser4_schedulable());
-+ assert("edward-1142", cryptcompress_inode_ok(inode));
++ assert("edward-1141", schedulable());
++ assert("edward-1142", crc_inode_ok(inode));
+ assert("edward-1143", current_blocksize == PAGE_CACHE_SIZE);
+
-+ old_size = inode->i_size;
-+
-+ hint = kmalloc(sizeof(*hint), reiser4_ctx_gfp_mask_get());
++ hint = kmalloc(sizeof(*hint), GFP_KERNEL);
+ if (hint == NULL)
+ return RETERR(-ENOMEM);
+ hint_init_zero(hint);
+ cluster_init_read(&clust, &win);
+ clust.hint = hint;
+
-+ /* calculate index of the rightmost logical cluster
-+ that will be completely truncated */
-+ ridx = size_in_lc(new_size, inode);
++ /* rightmost completely truncated cluster */
++ ridx = count_to_nrclust(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 partial truncate is needed */
++ /* no partially truncated clusters */
+ assert("edward-1145", inode->i_size == new_size);
-+ goto truncate_fake;
++ goto finish;
+ }
+ assert("edward-1146", new_size < inode->i_size);
+
+ to_prune = inode->i_size - new_size;
+
-+ /* check if the last logical cluster is fake */
-+ result = lookup_disk_cluster(inode, &aidx, ridx);
++ /* partial truncate of leftmost cluster,
++ first check if it is fake */
++ result = find_real_disk_cluster(inode, &aidx, ridx);
+ if (result)
+ goto out;
+ if (!aidx)
+ /* yup, this is fake one */
-+ goto truncate_fake;
++ goto finish;
+
+ assert("edward-1148", aidx == ridx);
+
-+ /* do partial truncate of the last page cluster,
-+ and try to capture this one */
++ /* do partial truncate of the leftmost page cluster,
++ then try to capture this one */
+ result = alloc_cluster_pgset(&clust, cluster_nrpages(inode));
+ if (result)
+ goto out;
+
+ assert("edward-1149", clust.index == ridx - 1);
+
-+ result = prepare_logical_cluster(inode, 0, 0, &clust, LC_TRUNC);
++ result = prepare_cluster(inode, 0, 0, &clust, PCL_TRUNCATE);
+ if (result)
+ goto out;
+ assert("edward-1151",
+
+ assert("edward-1191", inode->i_size == new_size);
+ assert("edward-1206", body_truncate_ok(inode, ridx));
-+ truncate_fake:
++ finish:
+ /* 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_logical_cluster() */
-+ INODE_SET_SIZE(inode, new_size);
++ released by prepare_cluster() */
+ truncate_inode_pages(inode->i_mapping, new_size);
-+ out:
++ INODE_SET_FIELD(inode, i_size, new_size);
++ out:
+ assert("edward-1334", !result || result == -ENOSPC);
-+ assert("edward-1497",
-+ pages_truncate_ok(inode, size_in_pages(new_size)));
-+
++ assert("edward-1209",
++ pages_truncate_ok(inode, old_size, count_to_nrpages(new_size)));
+ done_lh(lh);
+ kfree(hint);
+ put_cluster_handle(&clust);
+}
+
+/* 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;
+ /* no fake bytes */
+ return 0;
+ bytes = new_size - inode->i_size;
-+ INODE_SET_SIZE(inode, inode->i_size + bytes);
++ INODE_SET_FIELD(inode, i_size, 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(new_size, clust_to_off(aidx, inode));
++ bytes =
++ inode->i_size - max_count(new_size,
++ clust_to_off(aidx, inode));
+ if (!bytes)
+ return 0;
-+ INODE_SET_SIZE(inode, inode->i_size - bytes);
++ INODE_SET_FIELD(inode, i_size, 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
+}
+
+/* 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)
+ if (inode->i_size == new_size)
+ /* nothing to truncate anymore */
+ return 0;
-+ 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;
++ 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);
+}
+
+/* Capture an anonymous pager cluster. (Page cluser is
-+ * anonymous if it contains at least one anonymous page
-+ */
-+static int capture_anon_page_cluster(struct cluster_handle * clust,
-+ struct inode * inode)
++ anonymous if it contains at least one anonymous page */
++static int
++capture_page_cluster(reiser4_cluster_t * clust, struct inode *inode)
+{
+ int result;
+
+ assert("edward-1074", inode != NULL);
+ assert("edward-1075", clust->dstat == INVAL_DISK_CLUSTER);
+
-+ result = prepare_logical_cluster(inode, 0, 0, clust, LC_APPOV);
++ result = prepare_cluster(inode, 0, 0, clust, PCL_APPEND);
+ if (result)
+ return result;
-+ set_cluster_pages_dirty(clust, inode);
-+ result = checkin_logical_cluster(clust, inode);
++ set_cluster_pages_dirty(clust);
++ clear_moved_tag_cluster(inode->i_mapping, clust);
++
++ result = try_capture_cluster(clust, inode);
+ put_hint_cluster(clust, inode, ZNODE_WRITE_LOCK);
-+ if (unlikely(result))
-+ put_page_cluster(clust, inode, WRITE_OP);
++ 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);
++ }
+ return result;
+}
+
-+/* 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;
-+
-+ /* 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)
++#define MAX_CLUSTERS_TO_CAPTURE(inode) (1024 >> cluster_nrpages_shift(inode))
+
-+/* Capture anonymous page clusters */
-+static int capture_anon_pages(struct address_space * mapping, pgoff_t * index,
-+ int to_capture)
++/* read lock should be acquired */
++static int
++capture_anonymous_clusters(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;
-+ struct inode * inode;
-+ struct cluster_handle clust;
-+ struct page * pages[MAX_CLUSTER_NRPAGES];
++ reiser4_cluster_t clust;
+
+ 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);
+
-+ inode = mapping->host;
-+ hint = kmalloc(sizeof(*hint), reiser4_ctx_gfp_mask_get());
++ hint = kmalloc(sizeof(*hint), GFP_KERNEL);
+ if (hint == NULL)
+ return RETERR(-ENOMEM);
+ hint_init_zero(hint);
+ cluster_init_read(&clust, NULL);
+ clust.hint = hint;
+
-+ result = alloc_cluster_pgset(&clust, cluster_nrpages(inode));
++ result = alloc_cluster_pgset(&clust, cluster_nrpages(mapping->host));
+ if (result)
+ goto out;
+
+ while (to_capture > 0) {
-+ found = find_anon_page_cluster(mapping, index, pages);
++ found =
++ find_get_pages_tag(mapping, index,
++ PAGECACHE_TAG_REISER4_MOVED, 1, &page);
+ if (!found) {
+ *index = (pgoff_t) - 1;
+ break;
+ }
-+ move_cluster_forward(&clust, inode, pages[0]->index);
-+ result = capture_anon_page_cluster(&clust, inode);
++ assert("edward-1109", page != NULL);
+
-+ put_found_pages(pages, found); /* find_anon_page_cluster */
++ move_cluster_forward(&clust, mapping->host, page->index,
++ &progress);
++ result = capture_page_cluster(&clust, mapping->host);
++ page_cache_release(page);
+ if (result)
+ break;
-+ to_capture -= clust.nr_pages;
-+ count += clust.nr_pages;
++ to_capture--;
+ }
+ if (result) {
+ warning("edward-1077",
-+ "Capture failed (inode %llu, result=%i, captured=%d)\n",
-+ (unsigned long long)get_inode_oid(inode), result, count);
++ "Cannot capture anon pages: result=%i (captured=%d)\n",
++ result,
++ ((__u32) MAX_CLUSTERS_TO_CAPTURE(mapping->host)) -
++ to_capture);
+ } else {
-+ assert("edward-1078", ergo(found > 0, count > 0));
++ /* something had to be found */
++ assert("edward-1078",
++ to_capture <= MAX_CLUSTERS_TO_CAPTURE(mapping->host));
+ if (to_capture <= 0)
+ /* there may be left more pages */
-+ __mark_inode_dirty(inode, I_DIRTY_PAGES);
-+ result = count;
++ __mark_inode_dirty(mapping->host, I_DIRTY_PAGES);
+ }
+ out:
+ done_lh(lh);
+ return result;
+}
+
-+/* 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)
++/* 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)
+{
-+ 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;
++ return mapping_tagged(inode->i_mapping, PAGECACHE_TAG_REISER4_MOVED);
+}
+
-+/* 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 = 0;
-+ long to_capture;
++ int result;
++ int to_capture;
+ pgoff_t nrpages;
+ pgoff_t index = 0;
++ cryptcompress_info_t *info;
+ struct inode *inode;
-+ struct cryptcompress_info *info;
+
+ inode = mapping->host;
-+ if (!cryptcompress_inode_has_anon_pages(inode))
++ if (!crc_inode_has_anon_pages(inode)) {
++ result = 0;
+ goto end;
++ }
++
+ info = cryptcompress_inode_data(inode);
-+ nrpages = size_in_pages(i_size_read(inode));
++ nrpages = count_to_nrpages(i_size_read(inode));
+
+ if (wbc->sync_mode != WB_SYNC_ALL)
-+ to_capture = min(wbc->nr_to_write, (long)MAX_PAGES_TO_CAPTURE);
++ to_capture =
++ min_count(wbc->nr_to_write, MAX_CLUSTERS_TO_CAPTURE(inode));
+ else
-+ to_capture = MAX_PAGES_TO_CAPTURE;
++ to_capture = MAX_CLUSTERS_TO_CAPTURE(inode);
+ do {
+ reiser4_context *ctx;
+
-+ ctx = reiser4_init_context(inode->i_sb);
++ 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);
+ 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()));
+
-+ reiser4_txn_restart_current();
++ LOCK_CNT_INC(inode_sem_r);
+
-+ 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);
++ result =
++ capture_anonymous_clusters(inode->i_mapping, &index,
++ to_capture);
+
-+ result = capture_anon_pages(inode->i_mapping, &index,
-+ to_capture);
-+ mutex_unlock(&info->checkin_mutex);
++ up_read(&info->lock);
+
-+ if (result < 0) {
-+ reiser4_exit_context(ctx);
-+ break;
-+ }
-+ wbc->nr_to_write -= result;
-+ if (wbc->sync_mode != WB_SYNC_ALL) {
++ LOCK_CNT_DEC(inode_sem_r);
++
++ if (result != 0 || 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 */
-+ reiser4_writeout(inode->i_sb, wbc);
++ /* there are already pages to flush, flush them out, do
++ not delay until end of reiser4_sync_inodes */
++ writeout(inode->i_sb, wbc);
+ get_current_context()->nr_captured = 0;
+ }
+ }
+/* plugin->u.file.mmap */
+int mmap_cryptcompress(struct file *file, struct vm_area_struct *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;
++ //return -ENOSYS;
++ return generic_file_mmap(file, vma);
+}
+
+/* plugin->u.file.release */
+/* plugin->u.file.get_block */
+
+/* this is implementation of delete method of file plugin for
-+ * cryptcompress objects
-+ */
-+int delete_object_cryptcompress(struct inode *inode)
++ cryptcompress objects */
++int delete_cryptcompress(struct inode *inode)
+{
+ int result;
-+ struct cryptcompress_info * info;
+
+ assert("edward-429", inode->i_nlink == 0);
+
-+ 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);
++ 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;
++ }
+ }
-+ truncate_inode_pages(inode->i_mapping, 0);
-+ assert("edward-1487", pages_truncate_ok(inode, 0));
+ /* and remove stat data */
-+ return reiser4_delete_object_common(inode);
++ return delete_object_common(inode);
+}
+
+/* plugin->u.file.setattr method
-+ This implements actual truncate (see comments in reiser4/page_cache.c) */
-+int setattr_cryptcompress(struct dentry *dentry, struct iattr *attr)
++ see plugin.h for description */
++int setattr_cryptcompress(struct dentry *dentry, /* Object to change attributes */
++ struct iattr *attr /* change description */ )
+{
+ int result;
+ struct inode *inode;
-+ struct cryptcompress_info * info;
+
+ inode = dentry->d_inode;
-+ info = cryptcompress_inode_data(inode);
-+
++ result = check_cryptcompress(inode);
++ if (result)
++ return result;
+ if (attr->ia_valid & ATTR_SIZE) {
-+ if (i_size_read(inode) != attr->ia_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:
++ */
++
++ /* truncate does reservation itself and requires exclusive access obtained */
++ if (inode->i_size != attr->ia_size) {
+ reiser4_context *ctx;
+ loff_t old_size;
++ cryptcompress_info_t *info =
++ cryptcompress_inode_data(inode);
+
-+ ctx = reiser4_init_context(dentry->d_inode->i_sb);
++ ctx = init_context(dentry->d_inode->i_sb);
+ if (IS_ERR(ctx))
+ return PTR_ERR(ctx);
+
-+ old_size = i_size_read(inode);
-+ inode_check_scale(inode, old_size, attr->ia_size);
++ down_write(&info->lock);
++ LOCK_CNT_INC(inode_sem_w);
+
-+ mutex_lock(&info->checkin_mutex);
-+ result = cryptcompress_truncate(inode,
-+ attr->ia_size,
-+ 1/* update sd */);
-+ mutex_unlock(&info->checkin_mutex);
++ 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 */ );
+ 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 = reiser4_setattr_common(dentry, attr);
++ result = setattr_common(dentry, attr);
+ return result;
+}
+
+ reiser4_context *ctx;
+ ssize_t result;
+ struct inode *inode;
-+ struct cryptcompress_info *info;
++ cryptcompress_info_t *info;
+
+ inode = file->f_dentry->d_inode;
-+ ctx = reiser4_init_context(inode->i_sb);
++ ctx = init_context(inode->i_sb);
+ if (IS_ERR(ctx))
+ return PTR_ERR(ctx);
+ /*
+ 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;
+ */
+int release_cryptcompress(struct inode *inode, struct file *file)
+{
-+ reiser4_context *ctx = reiser4_init_context(inode->i_sb);
++ reiser4_context *ctx = init_context(inode->i_sb);
+
+ if (IS_ERR(ctx))
+ return PTR_ERR(ctx);
+ return 0;
+}
+
-+#if 0
-+int prepare_write_cryptcompress(struct file *file, struct page *page,
-+ unsigned from, unsigned to)
++static int
++save_len_cryptcompress_plugin(struct inode *inode, reiser4_plugin * plugin)
+{
-+ return prepare_write_common(file, page, from, to);
++ assert("edward-457", inode != NULL);
++ assert("edward-458", plugin != NULL);
++ assert("edward-459", plugin->h.id == CRC_FILE_PLUGIN_ID);
++ return 0;
+}
-+#endif /* 0 */
+
++static int
++load_cryptcompress_plugin(struct inode *inode, reiser4_plugin * plugin,
++ char **area, int *len)
++{
++ 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;
++}
++
++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:
+ scroll-step: 1
+ End:
+*/
-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 @@
+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 @@
+/* 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
+
-+#define MIN_LATTICE_FACTOR 1
-+#define MAX_LATTICE_FACTOR 32
++static inline loff_t min_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))
++static inline loff_t max_count(loff_t a, loff_t b)
++{
++ return (a > b ? a : b);
++}
+
+#if REISER4_DEBUG
+static inline int cluster_shift_ok(int shift)
+}
+#endif
+
-+#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 {
++typedef struct tfm_stream {
+ __u8 *data;
+ size_t size;
-+};
++} tfm_stream_t;
+
+typedef enum {
+ INPUT_STREAM,
+ LAST_STREAM
+} tfm_stream_id;
+
-+typedef struct tfm_stream * tfm_unit[LAST_STREAM];
++typedef tfm_stream_t *tfm_unit[LAST_STREAM];
+
-+static inline __u8 *ts_data(struct tfm_stream * stm)
++static inline __u8 *ts_data(tfm_stream_t * stm)
+{
+ assert("edward-928", stm != NULL);
+ return stm->data;
+}
+
-+static inline size_t ts_size(struct tfm_stream * stm)
++static inline size_t ts_size(tfm_stream_t * stm)
+{
+ assert("edward-929", stm != NULL);
+ return stm->size;
+}
+
-+static inline void set_ts_size(struct tfm_stream * stm, size_t size)
++static inline void set_ts_size(tfm_stream_t * stm, size_t size)
+{
+ assert("edward-930", stm != NULL);
+
+ stm->size = size;
+}
+
-+static inline int alloc_ts(struct tfm_stream ** stm)
++static inline int alloc_ts(tfm_stream_t ** stm)
+{
+ assert("edward-931", stm);
+ assert("edward-932", *stm == NULL);
+
-+ *stm = kmalloc(sizeof **stm, reiser4_ctx_gfp_mask_get());
++ *stm = kmalloc(sizeof **stm, GFP_KERNEL);
+ if (*stm == NULL)
+ return -ENOMEM;
+ memset(*stm, 0, sizeof **stm);
+ return 0;
+}
+
-+static inline void free_ts(struct tfm_stream * stm)
++static inline void free_ts(tfm_stream_t * stm)
+{
+ assert("edward-933", !ts_data(stm));
+ assert("edward-934", !ts_size(stm));
+ kfree(stm);
+}
+
-+static inline int alloc_ts_data(struct tfm_stream * stm, size_t size)
++static inline int alloc_ts_data(tfm_stream_t * stm, size_t size)
+{
+ assert("edward-935", !ts_data(stm));
+ assert("edward-936", !ts_size(stm));
+ assert("edward-937", size != 0);
+
-+ stm->data = reiser4_vmalloc(size);
++ stm->data = vmalloc(size);
+ if (!stm->data)
+ return -ENOMEM;
+ set_ts_size(stm, size);
+ return 0;
+}
+
-+static inline void free_ts_data(struct tfm_stream * stm)
++static inline void free_ts_data(tfm_stream_t * stm)
+{
+ assert("edward-938", equi(ts_data(stm), ts_size(stm)));
+
+ CRC_APPEND_ITEM = 1,
+ CRC_OVERWRITE_ITEM = 2,
+ CRC_CUT_ITEM = 3
-+} cryptcompress_write_mode_t;
++} crc_write_mode_t;
+
+typedef enum {
-+ 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 */
++ 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;
+ tfm_action act;
+ int uptodate;
-+ int lsize; /* number of bytes in logical cluster */
++ int lsize; /* size of the logical cluster */
+ int len; /* length of the transform stream */
-+};
++} tfm_cluster_t;
+
-+static inline coa_t get_coa(struct tfm_cluster * tc, reiser4_compression_id id,
-+ tfm_action act)
++static inline coa_t get_coa(tfm_cluster_t * tc, reiser4_compression_id id, tfm_action act)
+{
+ return tc->coa[id][act];
+}
+
-+static inline void set_coa(struct tfm_cluster * tc, reiser4_compression_id id,
-+ tfm_action act, coa_t coa)
++static inline void
++set_coa(tfm_cluster_t * tc, reiser4_compression_id id, tfm_action act, coa_t coa)
+{
+ tc->coa[id][act] = coa;
+}
+
-+static inline int alloc_coa(struct tfm_cluster * tc, compression_plugin * cplug)
++static inline int
++alloc_coa(tfm_cluster_t * tc, compression_plugin * cplug)
+{
+ coa_t coa;
+
+}
+
+static inline int
-+grab_coa(struct tfm_cluster * tc, compression_plugin * cplug)
++grab_coa(tfm_cluster_t * 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(struct tfm_cluster * tc)
++static inline void free_coa_set(tfm_cluster_t * tc)
+{
+ tfm_action j;
+ reiser4_compression_id i;
+
+ assert("edward-810", tc != NULL);
+
-+ for (j = 0; j < TFMA_LAST; j++)
++ for (j = 0; j < LAST_TFM; j++)
+ for (i = 0; i < LAST_COMPRESSION_ID; i++) {
+ if (!get_coa(tc, i, j))
+ continue;
+ return;
+}
+
-+static inline struct tfm_stream * get_tfm_stream(struct tfm_cluster * tc,
-+ tfm_stream_id id)
++static inline tfm_stream_t *tfm_stream(tfm_cluster_t * tc, tfm_stream_id id)
+{
+ return tc->tun[id];
+}
+
-+static inline void set_tfm_stream(struct tfm_cluster * tc,
-+ tfm_stream_id id, struct tfm_stream * ts)
++static inline void
++set_tfm_stream(tfm_cluster_t * tc, tfm_stream_id id, tfm_stream_t * ts)
+{
+ tc->tun[id] = ts;
+}
+
-+static inline __u8 *tfm_stream_data(struct tfm_cluster * tc, tfm_stream_id id)
++static inline __u8 *tfm_stream_data(tfm_cluster_t * tc, tfm_stream_id id)
+{
-+ return ts_data(get_tfm_stream(tc, id));
++ return ts_data(tfm_stream(tc, id));
+}
+
-+static inline void set_tfm_stream_data(struct tfm_cluster * tc,
-+ tfm_stream_id id, __u8 * data)
++static inline void
++set_tfm_stream_data(tfm_cluster_t * tc, tfm_stream_id id, __u8 * data)
+{
-+ get_tfm_stream(tc, id)->data = data;
++ tfm_stream(tc, id)->data = data;
+}
+
-+static inline size_t tfm_stream_size(struct tfm_cluster * tc, tfm_stream_id id)
++static inline size_t tfm_stream_size(tfm_cluster_t * tc, tfm_stream_id id)
+{
-+ return ts_size(get_tfm_stream(tc, id));
++ return ts_size(tfm_stream(tc, id));
+}
+
+static inline void
-+set_tfm_stream_size(struct tfm_cluster * tc, tfm_stream_id id, size_t size)
++set_tfm_stream_size(tfm_cluster_t * tc, tfm_stream_id id, size_t size)
+{
-+ get_tfm_stream(tc, id)->size = size;
++ tfm_stream(tc, id)->size = size;
+}
+
+static inline int
-+alloc_tfm_stream(struct tfm_cluster * tc, size_t size, tfm_stream_id id)
++alloc_tfm_stream(tfm_cluster_t * tc, size_t size, tfm_stream_id id)
+{
+ assert("edward-939", tc != NULL);
-+ assert("edward-940", !get_tfm_stream(tc, id));
++ assert("edward-940", !tfm_stream(tc, id));
+
-+ tc->tun[id] = kzalloc(sizeof(struct tfm_stream),
-+ reiser4_ctx_gfp_mask_get());
++ tc->tun[id] = kmalloc(sizeof(tfm_stream_t), GFP_KERNEL);
+ if (!tc->tun[id])
+ return -ENOMEM;
-+ return alloc_ts_data(get_tfm_stream(tc, id), size);
++ memset(tfm_stream(tc, id), 0, sizeof(tfm_stream_t));
++ return alloc_ts_data(tfm_stream(tc, id), size);
+}
+
+static inline int
-+realloc_tfm_stream(struct tfm_cluster * tc, size_t size, tfm_stream_id id)
++realloc_tfm_stream(tfm_cluster_t * tc, size_t size, tfm_stream_id id)
+{
+ assert("edward-941", tfm_stream_size(tc, id) < size);
-+ free_ts_data(get_tfm_stream(tc, id));
-+ return alloc_ts_data(get_tfm_stream(tc, id), size);
++ free_ts_data(tfm_stream(tc, id));
++ return alloc_ts_data(tfm_stream(tc, id), size);
+}
+
-+static inline void free_tfm_stream(struct tfm_cluster * tc, tfm_stream_id id)
++static inline void free_tfm_stream(tfm_cluster_t * tc, tfm_stream_id id)
+{
-+ free_ts_data(get_tfm_stream(tc, id));
-+ free_ts(get_tfm_stream(tc, id));
++ free_ts_data(tfm_stream(tc, id));
++ free_ts(tfm_stream(tc, id));
+ set_tfm_stream(tc, id, 0);
+}
+
+ return (cplug->overrun != NULL ? cplug->overrun(ilen) : 0);
+}
+
-+static inline void free_tfm_unit(struct tfm_cluster * tc)
++static inline void free_tfm_unit(tfm_cluster_t * tc)
+{
+ tfm_stream_id id;
+ for (id = 0; id < LAST_STREAM; id++) {
-+ if (!get_tfm_stream(tc, id))
++ if (!tfm_stream(tc, id))
+ continue;
+ free_tfm_stream(tc, id);
+ }
+}
+
-+static inline void put_tfm_cluster(struct tfm_cluster * tc)
++static inline void put_tfm_cluster(tfm_cluster_t * tc)
+{
+ assert("edward-942", tc != NULL);
+ free_coa_set(tc);
+ free_tfm_unit(tc);
+}
+
-+static inline int tfm_cluster_is_uptodate(struct tfm_cluster * tc)
++static inline int tfm_cluster_is_uptodate(tfm_cluster_t * 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(struct tfm_cluster * tc)
++static inline void tfm_cluster_set_uptodate(tfm_cluster_t * tc)
+{
+ assert("edward-945", tc != NULL);
+ assert("edward-946", tc->uptodate == 0 || tc->uptodate == 1);
+ return;
+}
+
-+static inline void tfm_cluster_clr_uptodate(struct tfm_cluster * tc)
++static inline void tfm_cluster_clr_uptodate(tfm_cluster_t * tc)
+{
+ assert("edward-947", tc != NULL);
+ assert("edward-948", tc->uptodate == 0 || tc->uptodate == 1);
+ return;
+}
+
-+static inline int tfm_stream_is_set(struct tfm_cluster * tc, tfm_stream_id id)
++static inline int tfm_stream_is_set(tfm_cluster_t * tc, tfm_stream_id id)
+{
-+ return (get_tfm_stream(tc, id) &&
++ return (tfm_stream(tc, id) &&
+ tfm_stream_data(tc, id) && tfm_stream_size(tc, id));
+}
+
-+static inline int tfm_cluster_is_set(struct tfm_cluster * tc)
++static inline int tfm_cluster_is_set(tfm_cluster_t * tc)
+{
+ int i;
+ for (i = 0; i < LAST_STREAM; i++)
+ return 1;
+}
+
-+static inline void alternate_streams(struct tfm_cluster * tc)
++static inline void alternate_streams(tfm_cluster_t * tc)
+{
-+ struct tfm_stream *tmp = get_tfm_stream(tc, INPUT_STREAM);
++ tfm_stream_t *tmp = tfm_stream(tc, INPUT_STREAM);
+
-+ set_tfm_stream(tc, INPUT_STREAM, get_tfm_stream(tc, OUTPUT_STREAM));
++ set_tfm_stream(tc, INPUT_STREAM, tfm_stream(tc, OUTPUT_STREAM));
+ set_tfm_stream(tc, OUTPUT_STREAM, tmp);
+}
+
-+/* Set of states to indicate a kind of data
-+ * that will be written to the window */
++/* a kind of data that we can write to the window */
+typedef enum {
-+ DATA_WINDOW, /* user's data */
-+ HOLE_WINDOW /* zeroes (such kind of data can be written
-+ * if we start to write from offset > i_size) */
++ DATA_WINDOW, /* the data we copy form user space */
++ HOLE_WINDOW /* zeroes if we write hole */
+} window_stat;
+
-+/* 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 */
++/* 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 */
+ unsigned delta; /* number of bytes to append to the hole */
-+ window_stat stat; /* what kind of data will be written starting
-+ from @off */
-+};
++ window_stat stat; /* a kind of data to write to the window */
++} reiser4_slide_t;
+
-+/* Possible states of a disk cluster */
++/* The following is a set of possible disk cluster states */
+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 */
-+ TRNC_DISK_CLUSTER /* disk cluster is partially truncated */
++ converted by flush */
++ FAKE_DISK_CLUSTER /* disk cluster doesn't exist neither in memory
++ nor on disk */
+} disk_cluster_stat;
+
-+/* 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 */
++/*
++ 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 */
+#if REISER4_DEBUG
+ reiser4_context *ctx;
+ int reserved_prepped;
+ int reserved_unprepped;
+#endif
+
-+};
++} reiser4_cluster_t;
+
-+static inline __u8 * tfm_input_data (struct cluster_handle * clust)
++static inline __u8 * tfm_input_data (reiser4_cluster_t * clust)
+{
+ return tfm_stream_data(&clust->tc, INPUT_STREAM);
+}
+
-+static inline __u8 * tfm_output_data (struct cluster_handle * clust)
++static inline __u8 * tfm_output_data (reiser4_cluster_t * clust)
+{
+ return tfm_stream_data(&clust->tc, OUTPUT_STREAM);
+}
+
-+static inline int reset_cluster_pgset(struct cluster_handle * clust,
-+ int nrpages)
++static inline int reset_cluster_pgset(reiser4_cluster_t * 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(struct cluster_handle * clust,
-+ int nrpages)
++static inline int alloc_cluster_pgset(reiser4_cluster_t * 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 = kzalloc(sizeof(*clust->pages) * nrpages,
-+ reiser4_ctx_gfp_mask_get());
++ clust->pages =
++ kmalloc(sizeof(*clust->pages) * nrpages, GFP_KERNEL);
+ if (!clust->pages)
+ return RETERR(-ENOMEM);
++ reset_cluster_pgset(clust, nrpages);
+ return 0;
+}
+
-+static inline void free_cluster_pgset(struct cluster_handle * clust)
++static inline void free_cluster_pgset(reiser4_cluster_t * clust)
+{
+ assert("edward-951", clust->pages != NULL);
+ kfree(clust->pages);
+ clust->pages = NULL;
+}
+
-+static inline void put_cluster_handle(struct cluster_handle * clust)
++static inline void put_cluster_handle(reiser4_cluster_t * clust)
+{
+ assert("edward-435", clust != NULL);
+
+ memset(clust, 0, sizeof *clust);
+}
+
-+static inline void inc_keyload_count(struct reiser4_crypto_info * data)
++static inline void inc_keyload_count(crypto_stat_t * data)
+{
+ assert("edward-1410", data != NULL);
+ data->keyload_count++;
+}
+
-+static inline void dec_keyload_count(struct reiser4_crypto_info * data)
++static inline void dec_keyload_count(crypto_stat_t * 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 */
-+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
-+ */
++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 */
+#if REISER4_DEBUG
-+ atomic_t pgcount; /* number of grabbed pages */
++ int pgcount; /* number of captured pages */
+#endif
-+};
++} cryptcompress_info_t;
+
-+static inline void set_compression_toggle (struct cryptcompress_info * info, int val)
++
++static inline void toggle_compression (cryptcompress_info_t * info, int val)
+{
+ info->compress_toggle = val;
+}
+
-+static inline int get_compression_toggle (struct cryptcompress_info * info)
++static inline int compression_is_on (cryptcompress_info_t * info)
+{
+ return info->compress_toggle;
+}
+
-+static inline int compression_is_on(struct cryptcompress_info * info)
++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)
+{
-+ return get_compression_toggle(info) == 1;
++ return &info->tfma[id];
+}
+
-+static inline void turn_on_compression(struct cryptcompress_info * info)
++static inline struct crypto_tfm *
++info_get_tfm (crypto_stat_t * info, reiser4_tfm id)
+{
-+ set_compression_toggle(info, 1);
++ return info_get_tfma(info, id)->tfm;
+}
+
-+static inline void turn_off_compression(struct cryptcompress_info * info)
++static inline void
++info_set_tfm (crypto_stat_t * info, reiser4_tfm id, struct crypto_tfm * tfm)
+{
-+ set_compression_toggle(info, 0);
++ info_get_tfma(info, id)->tfm = tfm;
+}
+
-+static inline void set_lattice_factor(struct cryptcompress_info * info, int val)
++static inline struct crypto_tfm *
++info_cipher_tfm (crypto_stat_t * info)
+{
-+ info->lattice_factor = val;
++ return info_get_tfm(info, CIPHER_TFM);
+}
+
-+static inline int get_lattice_factor(struct cryptcompress_info * info)
++static inline struct crypto_tfm *
++info_digest_tfm (crypto_stat_t * info)
+{
-+ return info->lattice_factor;
++ return info_get_tfm(info, DIGEST_TFM);
+}
+
-+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)
++static inline cipher_plugin *
++info_cipher_plugin (crypto_stat_t * info)
+{
-+ return info->cipher;
++ return &info_get_tfma(info, CIPHER_TFM)->plug->cipher;
+}
+
-+static inline void info_set_cipher(struct reiser4_crypto_info * info,
-+ struct crypto_blkcipher * tfm)
++static inline digest_plugin *
++info_digest_plugin (crypto_stat_t * info)
+{
-+ info->cipher = tfm;
++ return &info_get_tfma(info, DIGEST_TFM)->plug->digest;
+}
+
-+static inline struct crypto_hash * info_get_digest(struct reiser4_crypto_info * info)
++static inline void
++info_set_plugin(crypto_stat_t * info, reiser4_tfm id, reiser4_plugin * plugin)
+{
-+ return info->digest;
++ info_get_tfma(info, id)->plug = plugin;
+}
+
-+static inline void info_set_digest(struct reiser4_crypto_info * info,
-+ struct crypto_hash * tfm)
++static inline void
++info_set_cipher_plugin(crypto_stat_t * info, cipher_plugin * cplug)
+{
-+ info->digest = tfm;
++ info_set_plugin(info, CIPHER_TFM, cipher_plugin_to_plugin(cplug));
+}
+
-+static inline void put_cluster_page(struct page * page)
++static inline void
++info_set_digest_plugin(crypto_stat_t * info, digest_plugin * plug)
+{
-+ page_cache_release(page);
++ info_set_plugin(info, DIGEST_TFM, digest_plugin_to_plugin(plug));
+}
+
-+#endif /* __FS_REISER4_CRYPTCOMPRESS_H__ */
++#endif /* __FS_REISER4_CRYPTCOMPRESS_H__ */
+
+/* Make Linus happy.
+ Local variables:
+ scroll-step: 1
+ End:
+*/
-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 @@
+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 @@
+/* Copyright 2001, 2002, 2003, 2004 by Hans Reiser, licensing governed by
+ * reiser4/README */
+
+#include "../../page_cache.h"
+#include "../../ioctl.h"
+#include "../object.h"
-+#include "../cluster.h"
+#include "../../safe_link.h"
+
+#include <linux/writeback.h>
+
+
+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 */
-+struct unix_file_info *unix_file_inode_data(const struct inode *inode)
++unix_file_info_t *unix_file_inode_data(const struct inode *inode)
+{
+ return &reiser4_inode_data(inode)->file_plugin_data.unix_file_info;
+}
+ uf_coord->valid = 0;
+}
+
-+static void validate_extended_coord(uf_coord_t *uf_coord, loff_t offset)
++void validate_extended_coord(uf_coord_t *uf_coord, loff_t offset)
+{
+ assert("vs-1333", uf_coord->valid == 0);
+
+ * 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(struct unix_file_info *uf_info, int cbk_result,
++static void set_file_state(unix_file_info_t *uf_info, int cbk_result,
+ tree_level level)
+{
+ if (cbk_errored(cbk_result))
+ 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)
+ * file state is known, check whether it is set correctly if
+ * file is not being tail converted
+ */
-+ if (!reiser4_inode_get_flag(unix_file_info_to_inode(uf_info),
-+ REISER4_PART_IN_CONV)) {
++ if (!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,
+ const reiser4_key *key, znode_lock_mode lock_mode,
+ struct inode *inode)
+{
-+ 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 */ );
++ 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 */ );
+}
+
+/**
+ coord_t *coord;
+ lock_handle *lh;
+
-+ assert("nikita-3030", reiser4_schedulable());
++ assert("nikita-3030", schedulable());
+ assert("vs-1707", hint != NULL);
+ assert("vs-47", inode != NULL);
+
+
+ set_file_state(unix_file_inode_data(inode), CBK_COORD_FOUND,
+ znode_get_level(coord->node));
-+
++
+ return CBK_COORD_FOUND;
+ }
+
+ hint->ext_coord.lh = &hint->lh;
+}
+
-+static int find_file_state(struct inode *inode, struct unix_file_info *uf_info)
++static int find_file_state(struct inode *inode, unix_file_info_t *uf_info)
+{
+ int result;
+ reiser4_key key;
+ result = 0;
+ assert("vs-1074",
+ ergo(result == 0, uf_info->container != UF_CONTAINER_UNKNOWN));
-+ reiser4_txn_restart_current();
++ txn_restart_current();
+ return result;
+}
+
+ BA_CAN_COMMIT);
+}
+
-+int reiser4_update_file_size(struct inode *inode, reiser4_key * key,
-+ int update_sd)
++int update_file_size(struct inode *inode, reiser4_key * key, int update_sd)
+{
+ int result = 0;
+
-+ INODE_SET_SIZE(inode, get_key_offset(key));
++ INODE_SET_FIELD(inode, i_size, get_key_offset(key));
+ if (update_sd) {
+ inode->i_ctime = inode->i_mtime = CURRENT_TIME;
+ result = reiser4_update_sd(inode);
+
+ assert("vs-1248",
+ fplug == file_plugin_by_id(UNIX_FILE_PLUGIN_ID) ||
-+ fplug == file_plugin_by_id(CRYPTCOMPRESS_FILE_PLUGIN_ID));
++ fplug == file_plugin_by_id(CRC_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(reiser4_max_key()) */ );
++ set_key_offset(&to_key, cur_size - 1 /*get_key_offset(max_key()) */ );
+ /* this loop normally runs just once */
+ while (1) {
-+ result = reserve_cut_iteration(reiser4_tree_by_inode(inode));
++ result = reserve_cut_iteration(tree_by_inode(inode));
+ if (result)
+ break;
+
-+ result = reiser4_cut_tree_object(current_tree, &from_key, &to_key,
-+ &smallest_removed, inode, 1,
-+ &progress);
++ result = 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) {
+ break;
+ }
+
-+ /* the below does up(sbinfo->delete_mutex). Do not get folled */
++ /* the below does up(sbinfo->delete_sema). Do not get folled */
+ reiser4_release_reserved(inode->i_sb);
+
-+ /* reiser4_cut_tree_object() was interrupted probably because
++ /* cut_tree_object() was interrupted probably because
+ * current atom requires commit, we have to release
+ * transaction handle to allow atom commit. */
-+ reiser4_txn_restart_current();
++ txn_restart_current();
+ continue;
+ }
+ if (result
+ break;
+ }
+
-+ /* the below does up(sbinfo->delete_mutex). Do not get folled */
++ /* the below does up(sbinfo->delete_sema). Do not get folled */
+ reiser4_release_reserved(inode->i_sb);
+
+ return result;
+
+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)
+ struct page *page;
+ int padd_from;
+ unsigned long index;
-+ struct unix_file_info *uf_info;
++ char *kaddr;
++ unix_file_info_t *uf_info;
+
+ /*
+ * all items of ordinary reiser4 file are grouped together. That is why
-+ * we can use reiser4_cut_tree. Plan B files (for instance) can not be
++ * we can use 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(reiser4_max_key()),
-+ reiser4_update_file_size);
++ get_key_offset(max_key()), update_file_size);
+ if (result)
+ return result;
+
+ /* file is truncated to page boundary */
+ return 0;
+
-+ result = reserve_partial_page(reiser4_tree_by_inode(inode));
++ result = reserve_partial_page(tree_by_inode(inode));
+ if (result) {
+ reiser4_release_reserved(inode->i_sb);
+ return result;
+
+ /* last page is partially truncated - zero its content */
+ index = (inode->i_size >> PAGE_CACHE_SHIFT);
-+ page = read_mapping_page(inode->i_mapping, index, NULL);
++ page = read_cache_page(inode->i_mapping, index, filler, NULL);
+ if (IS_ERR(page)) {
+ /*
-+ * the below does up(sbinfo->delete_mutex). Do not get
++ * the below does up(sbinfo->delete_sema). Do not get
+ * confused
+ */
+ reiser4_release_reserved(inode->i_sb);
+ if (!PageUptodate(page)) {
+ page_cache_release(page);
+ /*
-+ * the below does up(sbinfo->delete_mutex). Do not get
++ * the below does up(sbinfo->delete_sema). Do not get
+ * confused
+ */
+ reiser4_release_reserved(inode->i_sb);
+ if (result) {
+ page_cache_release(page);
+ /*
-+ * the below does up(sbinfo->delete_mutex). Do not get
++ * the below does up(sbinfo->delete_sema). Do not get
+ * confused
+ */
+ reiser4_release_reserved(inode->i_sb);
+
+ lock_page(page);
+ assert("vs-1066", PageLocked(page));
-+ zero_user_page(page, padd_from, PAGE_CACHE_SIZE - padd_from, KM_USER0);
++ 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);
+ unlock_page(page);
+ page_cache_release(page);
-+ /* the below does up(sbinfo->delete_mutex). Do not get confused */
++ /* the below does up(sbinfo->delete_sema). Do not get confused */
+ reiser4_release_reserved(inode->i_sb);
+ return 0;
+}
+ * 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 struct unix_file_info *uf_info, loff_t new_size)
++static int should_have_notail(const unix_file_info_t *uf_info, loff_t new_size)
+{
+ if (!uf_info->tplug)
+ return 1;
+ /* expanding truncate */
+ struct dentry dentry;
+ struct file file;
-+ struct unix_file_info *uf_info;
++ unix_file_info_t *uf_info;
+
+ dentry.d_inode = inode;
+ file.f_dentry = &dentry;
+ 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
+ * - wait until it completes
+ */
+ while (1) {
-+ if (reiser4_inode_get_flag(inode,
-+ REISER4_PART_IN_CONV)) {
++ if (inode_get_flag(inode, REISER4_PART_IN_CONV)) {
+ drop_exclusive_access(uf_info);
+ schedule();
+ get_exclusive_access(uf_info);
+ }
+ break;
+ }
-+
++
+ if (uf_info->container == UF_CONTAINER_TAILS) {
+ result = tail2extent(uf_info);
+ if (result)
+ return result;
+ }
+ }
-+ result = reiser4_write_extent(&file, NULL, 0,
-+ &new_size);
++ result = 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 = reiser4_write_extent(&file, NULL, 0,
-+ &new_size);
++ result = write_extent(&file, NULL, 0, &new_size);
+ if (result)
+ return result;
+ } else {
-+ result = reiser4_write_tail(&file, NULL, 0,
-+ &new_size);
++ result = write_tail(&file, NULL, 0, &new_size);
+ if (result)
+ return result;
+ uf_info->container = UF_CONTAINER_TAILS;
+ return PTR_ERR(fsdata);
+
+ spin_lock_inode(file->f_dentry->d_inode);
-+ if (reiser4_seal_is_set(&fsdata->reg.hint.seal)) {
++ if (seal_is_set(&fsdata->reg.hint.seal)) {
+ *hint = fsdata->reg.hint;
+ init_lh(&hint->lh);
+ hint->ext_coord.lh = &hint->lh;
+
+ assert("edward-1337", hint != NULL);
+
-+ if (!file || !reiser4_seal_is_set(&hint->seal))
++ if (!file || !seal_is_set(&hint->seal))
+ return;
+ fsdata = reiser4_get_file_fsdata(file);
+ assert("vs-965", !IS_ERR(fsdata));
+ return;
+}
+
-+void reiser4_unset_hint(hint_t * hint)
++void unset_hint(hint_t * hint)
+{
+ assert("vs-1315", hint);
+ hint->ext_coord.valid = 0;
-+ reiser4_seal_done(&hint->seal);
++ seal_done(&hint->seal);
+ done_lh(&hint->lh);
+}
+
-+/* 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)
++/* 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)
+{
+ ON_DEBUG(coord_t * coord = &hint->ext_coord.coord);
+ assert("vs-1207", WITH_DATA(coord->node, check_coord(coord, key)));
+
-+ reiser4_seal_init(&hint->seal, &hint->ext_coord.coord, key);
++ seal_init(&hint->seal, &hint->ext_coord.coord, key);
+ hint->offset = get_key_offset(key);
+ hint->mode = mode;
+ done_lh(&hint->lh);
+
+int hint_is_set(const hint_t * hint)
+{
-+ return reiser4_seal_is_set(&hint->seal);
++ return seal_is_set(&hint->seal);
+}
+
+#if REISER4_DEBUG
+}
+#endif
+
-+static int
++int
+hint_validate(hint_t * hint, const reiser4_key * key, int check_key,
+ znode_lock_mode lock_mode)
+{
+ return RETERR(-E_REPEAT);
+
+ assert("vs-31", hint->ext_coord.lh == &hint->lh);
-+ return reiser4_seal_validate(&hint->seal, &hint->ext_coord.coord, key,
-+ hint->ext_coord.lh, lock_mode,
-+ ZNODE_LOCK_LOPRI);
++ return 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:
+ *
+ *
+ */
+
+ lock_page(page);
+ node = jnode_of_page(page);
-+ if (IS_ERR(node)) {
-+ unlock_page(page);
-+ return PTR_ERR(node);
-+ }
-+ JF_SET(node, JNODE_WRITE_PREPARED);
+ unlock_page(page);
++ if (IS_ERR(node))
++ return PTR_ERR(node);
+
+ if (node->blocknr == 0) {
+ plugged_hole = 0;
-+ result = reiser4_update_extent(inode, node, page_offset(page),
-+ &plugged_hole);
++ result = update_extent(inode, node,
++ (loff_t)page->index << PAGE_CACHE_SHIFT,
++ &plugged_hole);
+ if (result) {
-+ JF_CLR(node, JNODE_WRITE_PREPARED);
+ jput(node);
-+ warning("", "reiser4_update_extent failed: %d", result);
++ warning("", "update_extent failed: %d", result);
+ return result;
+ }
+ if (plugged_hole)
+ reiser4_update_sd(inode);
+ } else {
+ spin_lock_jnode(node);
-+ result = reiser4_try_capture(node, ZNODE_WRITE_LOCK, 0);
++ result = 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) {
+ unix_file_inode_data(inode)->container == UF_CONTAINER_EXTENTS);
+ /* page belongs to file */
+ assert("vs-1393",
-+ inode->i_size > page_offset(page));
++ inode->i_size > ((loff_t) page->index << PAGE_CACHE_SHIFT));
+
+ /* 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
-+ (reiser4_tree_by_inode(inode)),
-+ BA_CAN_COMMIT);
++ result =
++ reiser4_grab_space(2 *
++ estimate_one_insert_into_item(tree_by_inode
++ (inode)),
++ BA_CAN_COMMIT);
+ if (likely(!result))
+ result = find_or_create_extent(page);
+
+ SetPageUptodate(page);
+
+ inode = page->mapping->host;
-+ ctx = reiser4_init_context(page->mapping->host->i_sb);
++ ctx = init_context(page->mapping->host->i_sb);
+ if (IS_ERR(ctx))
+ return PTR_ERR(ctx);
+ page_cache_get(page);
+ for (i = 0; i < pagevec_count(&pvec); i++) {
+ /*
+ * tag PAGECACHE_TAG_REISER4_MOVED will be cleared by
-+ * reiser4_set_page_dirty_internal which is called when jnode is
++ * set_page_dirty_internal which is called when jnode is
+ * captured
+ */
+ result = capture_anonymous_page(pvec.pages[i]);
+ } else
+ atom = NULL;
+ unlock_page(page);
-+ result = reiser4_sync_atom(atom);
++ result = sync_atom(atom);
+ } while (result == -E_REPEAT);
+ /*
+ * ZAM-FIXME-HANS: document the logic of this loop, is it just to
+static int commit_file_atoms(struct inode *inode)
+{
+ int result;
-+ struct unix_file_info *uf_info;
++ unix_file_info_t *uf_info;
+
+ uf_info = unix_file_inode_data(inode);
+
+ switch (uf_info->container) {
+ case UF_CONTAINER_EXTENTS:
+ /* find_file_state might open join an atom */
-+ reiser4_txn_restart_current();
++ txn_restart_current();
+ result =
+ /*
+ * when we are called by
+ * commit current transaction: there can be captured nodes from
+ * find_file_state() and finish_conversion().
+ */
-+ reiser4_txn_restart_current();
++ txn_restart_current();
+ return result;
+}
+
+ struct writeback_control *wbc)
+{
+ int result;
-+ struct unix_file_info *uf_info;
++ unix_file_info_t *uf_info;
+ pgoff_t pindex, jindex, nr_pages;
+ long to_capture;
+ struct inode *inode;
+ result = 0;
+ goto end;
+ }
-+ jindex = pindex = wbc->range_start >> PAGE_CACHE_SHIFT;
++ jindex = pindex = wbc->start >> PAGE_CACHE_SHIFT;
+ result = 0;
-+ nr_pages = size_in_pages(i_size_read(inode));
-+
++ nr_pages =
++ (i_size_read(inode) + PAGE_CACHE_SIZE - 1) >> PAGE_CACHE_SHIFT;
+ uf_info = unix_file_inode_data(inode);
+
+ do {
+ else
+ to_capture = CAPTURE_APAGE_BURST;
+
-+ ctx = reiser4_init_context(inode->i_sb);
++ ctx = init_context(inode->i_sb);
+ if (IS_ERR(ctx)) {
+ result = PTR_ERR(ctx);
+ break;
+ assert("", LOCK_CNT_NIL(inode_sem_w));
+ assert("", LOCK_CNT_NIL(inode_sem_r));
+
-+ reiser4_txn_restart_current();
++ txn_restart_current();
+
+ /* we have to get nonexclusive access to the file */
+ if (get_current_context()->entd) {
+ * there are already pages to flush, flush them out, do
+ * not delay until end of reiser4_sync_inodes
+ */
-+ reiser4_writeout(inode->i_sb, wbc);
++ writeout(inode->i_sb, wbc);
+ get_current_context()->nr_captured = 0;
+ }
+ }
+ txn_atom *atom;
+ reiser4_block_nr reserve;
+
-+ ctx = reiser4_init_context(dentry->d_inode->i_sb);
++ ctx = init_context(dentry->d_inode->i_sb);
+ if (IS_ERR(ctx))
+ return PTR_ERR(ctx);
+
+ * 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(struct file *file, struct page *page)
++int readpage_unix_file_nolock(struct file *file, struct page *page)
+{
+ reiser4_context *ctx;
+ int result;
+ assert("vs-976", !PageUptodate(page));
+ assert("vs-1061", page->mapping && page->mapping->host);
+
-+ if (page->mapping->host->i_size <= page_offset(page)) {
++ if ((page->mapping->host->i_size <=
++ ((loff_t) page->index << PAGE_CACHE_SHIFT))) {
+ /* page is out of file already */
+ unlock_page(page);
+ return -EINVAL;
+ }
+
+ inode = page->mapping->host;
-+ ctx = reiser4_init_context(inode->i_sb);
++ ctx = init_context(inode->i_sb);
+ if (IS_ERR(ctx)) {
+ unlock_page(page);
+ return PTR_ERR(ctx);
+ }
+
-+ hint = kmalloc(sizeof(*hint), reiser4_ctx_gfp_mask_get());
++ hint = kmalloc(sizeof(*hint), get_gfp_mask());
+ if (hint == NULL) {
+ unlock_page(page);
+ reiser4_exit_context(ctx);
+ lh = &hint->lh;
+
+ /* get key of first byte of the page */
-+ key_by_inode_and_offset_common(inode, page_offset(page), &key);
++ key_by_inode_and_offset_common(inode,
++ (loff_t) page->index << PAGE_CACHE_SHIFT,
++ &key);
+
+ /* look for file metadata corresponding to first byte of page */
+ page_cache_get(page);
+ done_lh(lh);
+ kfree(hint);
+ unlock_page(page);
-+ reiser4_txn_restart(ctx);
++ txn_restart(ctx);
+ reiser4_exit_context(ctx);
+ return -EINVAL;
+ }
+ done_lh(lh);
+ kfree(hint);
+ unlock_page(page);
-+ reiser4_txn_restart(ctx);
++ txn_restart(ctx);
+ reiser4_exit_context(ctx);
+ return result;
+ }
+ done_lh(lh);
+ kfree(hint);
+ unlock_page(page);
-+ reiser4_txn_restart(ctx);
++ txn_restart(ctx);
+ reiser4_exit_context(ctx);
+ return 0;
+ }
+ done_lh(lh);
+ kfree(hint);
+ unlock_page(page);
-+ reiser4_txn_restart(ctx);
++ txn_restart(ctx);
+ reiser4_exit_context(ctx);
+ return result;
+ }
+
-+ validate_extended_coord(&hint->ext_coord, page_offset(page));
++ validate_extended_coord(&hint->ext_coord,
++ (loff_t) page->index << PAGE_CACHE_SHIFT);
+
+ if (!coord_is_existing_unit(coord)) {
+ /* this indicates corruption */
+ done_lh(lh);
+ kfree(hint);
+ unlock_page(page);
-+ reiser4_txn_restart(ctx);
++ txn_restart(ctx);
+ reiser4_exit_context(ctx);
+ return RETERR(-EIO);
+ }
+ if (!result) {
+ set_key_offset(&key,
+ (loff_t) (page->index + 1) << PAGE_CACHE_SHIFT);
-+ /* FIXME should call reiser4_set_hint() */
-+ reiser4_unset_hint(hint);
++ /* FIXME should call set_hint() */
++ unset_hint(hint);
+ } else {
+ unlock_page(page);
-+ reiser4_unset_hint(hint);
++ unset_hint(hint);
+ }
+ assert("vs-979",
+ ergo(result == 0, (PageLocked(page) || PageUptodate(page))));
+ * not be done when atom is not NULL because reiser4_writepage can not
+ * kick entd and have to eflush
+ */
-+ reiser4_txn_restart(ctx);
++ txn_restart(ctx);
+ reiser4_exit_context(ctx);
+ return result;
+}
+
-+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).
-+ *
-+ * @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.
-+ */
-+static int uf_readpages_filler(void * data, struct page * 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
++ * readpage_unix_file - readpage of struct address_space_operations
++ * @file: file @page belongs to
++ * @page: page to read
++ *
++ * 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.
+ */
-+int readpages_unix_file(
-+ struct file *file, struct address_space *mapping,
-+ struct list_head *pages, unsigned nr_pages)
++int readpage_unix_file(struct file *file, struct page *page)
+{
-+ 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;
++ return readpage_unix_file_nolock(file, page);
+}
+
+static reiser4_block_nr unix_file_estimate_read(struct inode *inode,
+}
+
+/* this is called with nonexclusive access obtained, file's container can not change */
-+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)
++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)
+{
+ int result;
+ struct inode *inode;
+ 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
+ loff_t *off)
+{
+ reiser4_context *ctx;
-+ ssize_t result;
++ int result;
+ struct inode *inode;
-+ struct unix_file_info *uf_info;
++ hint_t *hint;
++ unix_file_info_t *uf_info;
++ size_t count, read, left;
++ reiser4_block_nr needed;
++ loff_t size;
+
+ if (unlikely(read_amount == 0))
+ return 0;
+ 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));
++ assert("vs-972", !inode_get_flag(inode, REISER4_NO_SD));
+
-+ ctx = reiser4_init_context(inode->i_sb);
++ ctx = 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;
-+}
+
-+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)
++ hint = kmalloc(sizeof(*hint), get_gfp_mask());
++ if (hint == NULL) {
++ context_set_commit_async(ctx);
++ reiser4_exit_context(ctx);
+ return RETERR(-ENOMEM);
++ }
+
+ result = load_file_hint(file, hint);
+ if (result) {
+ kfree(hint);
++ context_set_commit_async(ctx);
++ reiser4_exit_context(ctx);
+ return result;
+ }
+
+ count = 0;
+ uf_info = unix_file_inode_data(inode);
+ while (left > 0) {
-+ reiser4_txn_restart_current();
++ txn_restart_current();
++
++ get_nonexclusive_access(uf_info);
++
+ 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 */
-+ result = fault_in_pages_writeable(buf, left > PAGE_CACHE_SIZE ? PAGE_CACHE_SIZE : left);
-+ if (result)
-+ return RETERR(-EFAULT);
++ if(fault_in_pages_writeable(buf, left > PAGE_CACHE_SIZE ? PAGE_CACHE_SIZE : left)) {
++ drop_nonexclusive_access(uf_info);
++ result = RETERR(-EFAULT);
++ break;
++ }
+
+ 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;
+ /* total number of read bytes */
+ count += read;
+ }
-+ done_lh(&hint->lh);
+ save_file_hint(file, hint);
++ done_lh(&hint->lh);
+ kfree(hint);
-+ if (count)
-+ file_accessed(file);
++
++ 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);
++
+ /* return number of read bytes or error code if nothing is read */
+ return count ? count : result;
+}
+ reiser4_context *ctx;
+ int result;
+ struct inode *inode;
-+ struct unix_file_info *uf_info;
++ unix_file_info_t *uf_info;
+ reiser4_block_nr needed;
+
+ inode = file->f_dentry->d_inode;
-+ ctx = reiser4_init_context(inode->i_sb);
++ ctx = init_context(inode->i_sb);
+ if (IS_ERR(ctx))
+ return PTR_ERR(ctx);
+
+ uf_info = unix_file_inode_data(inode);
+
-+ get_exclusive_access_careful(uf_info, inode);
++ down(&uf_info->write);
++ get_exclusive_access(uf_info);
+
+ if (!IS_RDONLY(inode) && (vma->vm_flags & (VM_MAYWRITE | VM_SHARED))) {
+ /*
+ 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;
+ }
+ result = check_pages_unix_file(file, inode);
+ if (result) {
+ drop_exclusive_access(uf_info);
++ up(&uf_info->write);
+ reiser4_exit_context(ctx);
+ return result;
+ }
+ 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;
+ }
+ result = generic_file_mmap(file, vma);
+ if (result == 0) {
+ /* mark file as having mapping. */
-+ reiser4_inode_set_flag(inode, REISER4_HAS_MMAP);
++ inode_set_flag(inode, REISER4_HAS_MMAP);
+ }
+
+ drop_exclusive_access(uf_info);
++ up(&uf_info->write);
+ reiser4_exit_context(ctx);
+ return result;
+}
+{
+ int result;
+ reiser4_context *ctx;
-+ struct unix_file_info *uf_info;
++ unix_file_info_t *uf_info;
+
+ if (IS_RDONLY(inode))
+ return 0;
+
-+ if (!reiser4_inode_get_flag(inode, REISER4_PART_MIXED))
++ if (!inode_get_flag(inode, REISER4_PART_MIXED))
+ return 0;
+
-+ ctx = reiser4_init_context(inode->i_sb);
++ ctx = 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);
+
-+ get_exclusive_access_careful(uf_info, inode);
++ /*
++ * 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;
++ }
+
-+ if (!reiser4_inode_get_flag(inode, REISER4_PART_MIXED)) {
++ if (!inode_get_flag(inode, REISER4_PART_MIXED)) {
+ /*
+ * other process completed the conversion
+ */
+ result = -EIO;
+
+ assert("vs-1712",
-+ ergo(result == 0,
-+ (!reiser4_inode_get_flag(inode, REISER4_PART_MIXED) &&
-+ !reiser4_inode_get_flag(inode, REISER4_PART_IN_CONV))));
++ ergo(result == 0, (!inode_get_flag(inode, REISER4_PART_MIXED) &&
++ !inode_get_flag(inode, REISER4_PART_IN_CONV))));
+ drop_exclusive_access(uf_info);
+ reiser4_exit_context(ctx);
+ return result;
+#define EA_OBTAINED 1
+#define NEA_OBTAINED 2
+
-+static void drop_access(struct unix_file_info *uf_info)
++static void drop_access(unix_file_info_t *uf_info)
+{
+ if (uf_info->exclusive_use)
+ drop_exclusive_access(uf_info);
+#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
+ int result;
+ reiser4_context *ctx;
+ struct inode *inode;
-+ struct unix_file_info *uf_info;
++ unix_file_info_t *uf_info;
+ ssize_t written;
+ int try_free_space;
+ int to_write = PAGE_CACHE_SIZE * WRITE_GRANULARITY;
+ loff_t new_size;
+
+ inode = file->f_dentry->d_inode;
-+ ctx = reiser4_init_context(inode->i_sb);
++ ctx = init_context(inode->i_sb);
+ if (IS_ERR(ctx))
+ return PTR_ERR(ctx);
+
+ mutex_lock(&inode->i_mutex);
+
-+ assert("vs-947", !reiser4_inode_get_flag(inode, REISER4_NO_SD));
-+ assert("vs-9471", (!reiser4_inode_get_flag(inode, REISER4_PART_MIXED)));
++ assert("vs-947", !inode_get_flag(inode, REISER4_NO_SD));
++ assert("vs-9471", (!inode_get_flag(inode, REISER4_PART_MIXED)));
+
+ /* check amount of bytes to write and writing position */
+ result = generic_write_checks(file, pos, &count, 0);
+ reiser4_exit_context(ctx);
+ return result;
+ }
-+ /* remove_suid might create a transaction */
-+ reiser4_txn_restart(ctx);
+
+ uf_info = unix_file_inode_data(inode);
+
+ /* 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 = reiser4_write_extent;
++ write_op = write_extent;
+ } else if (uf_info->container == UF_CONTAINER_EMPTY) {
+ /* file is empty */
+ if (should_have_notail(uf_info, new_size))
-+ write_op = reiser4_write_extent;
++ write_op = write_extent;
+ else
-+ write_op = reiser4_write_tail;
++ write_op = write_tail;
+ } else {
+ /* file is built of tail items */
+ if (should_have_notail(uf_info, new_size)) {
+ * process - wait until it completes
+ */
+ while (1) {
-+ if (reiser4_inode_get_flag(inode,
-+ REISER4_PART_IN_CONV)) {
++ if (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)
+ ea = NEITHER_OBTAINED;
+ continue;
+ }
-+ write_op = reiser4_write_tail;
++ write_op = write_tail;
+ }
+
+ written = write_op(file, buf, to_write, pos);
+ /* something is written. */
+ if (uf_info->container == UF_CONTAINER_EMPTY) {
+ assert("", ea == EA_OBTAINED);
-+ uf_info->container =
-+ (write_op == reiser4_write_extent) ?
++ uf_info->container = (write_op == write_extent) ?
+ UF_CONTAINER_EXTENTS : UF_CONTAINER_TAILS;
+ } else {
+ assert("", ergo(uf_info->container == UF_CONTAINER_EXTENTS,
-+ write_op == reiser4_write_extent));
++ write_op == write_extent));
+ assert("", ergo(uf_info->container == UF_CONTAINER_TAILS,
-+ write_op == reiser4_write_tail));
++ write_op == write_tail));
+ }
+ if (*pos + written > inode->i_size)
+ INODE_SET_FIELD(inode, i_size, *pos + written);
+ }
+ drop_access(uf_info);
+ ea = NEITHER_OBTAINED;
-+ reiser4_txn_restart(ctx);
++ 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_ratelimited_nr(inode->i_mapping,
-+ (written + PAGE_CACHE_SIZE - 1) / PAGE_CACHE_SIZE);
++ balance_dirty_pages(inode->i_mapping);
+ current->journal_info = ctx;
+
+ left -= written;
+ mutex_unlock(&inode->i_mutex);
+
+ if (result == 0 && ((file->f_flags & O_SYNC) || IS_SYNC(inode))) {
-+ reiser4_txn_restart_current();
++ txn_restart_current();
+ grab_space_enable();
+ result = sync_unix_file(file, file->f_dentry,
+ 0 /* data and stat data */ );
+int release_unix_file(struct inode *inode, struct file *file)
+{
+ reiser4_context *ctx;
-+ struct unix_file_info *uf_info;
++ unix_file_info_t *uf_info;
+ int result;
+ int in_reiser4;
+
+ in_reiser4 = is_in_reiser4_context();
+
-+ ctx = reiser4_init_context(inode->i_sb);
++ ctx = init_context(inode->i_sb);
+ if (IS_ERR(ctx))
+ return PTR_ERR(ctx);
+
+ if (in_reiser4 == 0) {
+ uf_info = unix_file_inode_data(inode);
+
-+ get_exclusive_access_careful(uf_info, inode);
++ down(&uf_info->write);
++ get_exclusive_access(uf_info);
+ if (atomic_read(&file->f_dentry->d_count) == 1 &&
+ uf_info->container == UF_CONTAINER_EXTENTS &&
+ !should_have_notail(uf_info, inode->i_size) &&
+ }
+ }
+ drop_exclusive_access(uf_info);
++ up(&uf_info->write);
+ } else {
+ /*
+ we are within reiser4 context already. How latter is
+ #15 0xc01131e5 in do_page_fault ()
+ #16 0xc0104935 in error_code ()
+ #17 0xc025c0c6 in __copy_to_user_ll ()
-+ #18 0xc01d496f in reiser4_read_tail ()
++ #18 0xc01d496f in read_tail ()
+ #19 0xc01e4def in read_unix_file ()
+ #20 0xc01c3504 in reiser4_read ()
+ #21 0xc014bd4f in vfs_read ()
+
+ state = reiser4_inode_data(inode);
+ tplug = formatting_plugin_by_id(NEVER_TAILS_FORMATTING_ID);
-+ force_plugin_pset(inode, PSET_FORMATTING, (reiser4_plugin *)tplug);
++ plugin_set_formatting(&state->pset, tplug);
++ inode_set_plugin(inode,
++ formatting_plugin_to_plugin(tplug), PSET_FORMATTING);
+}
+
+/* if file is built of tails - convert it to extents */
+static int unpack(struct file *filp, struct inode *inode, int forever)
+{
+ int result = 0;
-+ struct unix_file_info *uf_info;
++ unix_file_info_t *uf_info;
+
+ uf_info = unix_file_inode_data(inode);
+ assert("vs-1628", ea_obtained(uf_info));
+ * completes
+ */
+ while (1) {
-+ if (reiser4_inode_get_flag(inode,
-+ REISER4_PART_IN_CONV)) {
++ if (inode_get_flag(inode, REISER4_PART_IN_CONV)) {
+ drop_exclusive_access(uf_info);
+ schedule();
+ get_exclusive_access(uf_info);
+ 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;
+}
+
+ reiser4_context *ctx;
+ int result;
+
-+ ctx = reiser4_init_context(inode->i_sb);
++ ctx = init_context(inode->i_sb);
+ if (IS_ERR(ctx))
+ return PTR_ERR(ctx);
+
+
+ inode = mapping->host;
+
-+ ctx = reiser4_init_context(inode->i_sb);
++ ctx = init_context(inode->i_sb);
+ if (IS_ERR(ctx))
+ return PTR_ERR(ctx);
+ key_by_inode_and_offset_common(inode,
+ plugin->u.file.create_blank_sd = NULL */
+/* plugin->u.file.delete */
+/*
-+ plugin->u.file.add_link = reiser4_add_link_common
++ plugin->u.file.add_link = add_link_common
+ plugin->u.file.rem_link = NULL */
+
+/* plugin->u.file.owns_item
+ result = owns_item_common(inode, coord);
+ if (!result)
+ return 0;
-+ if (!plugin_of_group(item_plugin_by_coord(coord),
-+ UNIX_FILE_METADATA_ITEM_TYPE))
++ if (item_type_by_coord(coord) != UNIX_FILE_METADATA_ITEM_TYPE)
+ return 0;
+ assert("vs-547",
+ item_id_by_coord(coord) == EXTENT_POINTER_ID ||
+ inode_check_scale(inode, inode->i_size, attr->ia_size);
+
+ old_size = inode->i_size;
-+ tree = reiser4_tree_by_inode(inode);
++ tree = tree_by_inode(inode);
+
+ result = safe_link_grab(tree, BA_CAN_COMMIT);
+ if (result == 0)
+
+ if (attr->ia_valid & ATTR_SIZE) {
+ reiser4_context *ctx;
-+ struct unix_file_info *uf_info;
++ unix_file_info_t *uf_info;
+
+ /* truncate does reservation itself and requires exclusive
+ access obtained */
-+ ctx = reiser4_init_context(dentry->d_inode->i_sb);
++ ctx = init_context(dentry->d_inode->i_sb);
+ if (IS_ERR(ctx))
+ return PTR_ERR(ctx);
+
+ uf_info = unix_file_inode_data(dentry->d_inode);
-+ get_exclusive_access_careful(uf_info, dentry->d_inode);
++ down(&uf_info->write);
++ get_exclusive_access(uf_info);
+ 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 = reiser4_setattr_common(dentry, attr);
++ result = setattr_common(dentry, attr);
+
+ return result;
+}
+init_inode_data_unix_file(struct inode *inode,
+ reiser4_object_create_data * crd, int create)
+{
-+ struct unix_file_info *data;
++ unix_file_info_t *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;
+
+ */
+int delete_object_unix_file(struct inode *inode)
+{
-+ struct unix_file_info *uf_info;
++ unix_file_info_t *uf_info;
+ int result;
+
-+ if (reiser4_inode_get_flag(inode, REISER4_NO_SD))
++ if (inode_get_flag(inode, REISER4_NO_SD))
+ return 0;
+
+ /* truncate file bogy first */
+ get_inode_oid(inode), result);
+
+ /* remove stat data and safe link */
-+ return reiser4_delete_object_common(inode);
++ return delete_object_common(inode);
+}
+
+/**
+ reiser4_context *ctx;
+ ssize_t result;
+ struct inode *inode;
-+ struct unix_file_info *uf_info;
++ unix_file_info_t *uf_info;
+
+ inode = file->f_dentry->d_inode;
-+ ctx = reiser4_init_context(inode->i_sb);
++ ctx = init_context(inode->i_sb);
+ if (IS_ERR(ctx))
+ return PTR_ERR(ctx);
+
+ if (result)
+ goto error;
+ mutex_lock(&inode->i_mutex);
-+ reiser4_inode_set_flag(inode, REISER4_HAS_MMAP);
++ inode_set_flag(inode, REISER4_HAS_MMAP);
+ mutex_unlock(&inode->i_mutex);
+
+ uf_info = unix_file_inode_data(inode);
+ unsigned from, unsigned to)
+{
+ reiser4_context *ctx;
-+ struct unix_file_info *uf_info;
++ unix_file_info_t *uf_info;
+ int ret;
+
-+ ctx = reiser4_init_context(file->f_dentry->d_inode->i_sb);
++ ctx = init_context(file->f_dentry->d_inode->i_sb);
+ if (IS_ERR(ctx))
+ return PTR_ERR(ctx);
+
+ * scroll-step: 1
+ * End:
+ */
-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 @@
+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 @@
+/* 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, CRYPTCOMPRESS_FILE_PLUGIN_ID
-+ and SYMLINK_FILE_PLUGIN_ID) */
++/* this file contains declarations of methods implementing file plugins
++ (UNIX_FILE_PLUGIN_ID, SYMLINK_FILE_PLUGIN_ID and CRC_FILE_PLUGIN_ID) */
+
+#if !defined( __REISER4_FILE_H__ )
+#define __REISER4_FILE_H__
+
+/* address space operations */
+int readpage_unix_file(struct file *, struct page *);
-+int readpages_unix_file(struct file*, struct address_space*, struct list_head*, unsigned);
++int readpage_unix_file_nolock(struct file *, struct page *);
+int writepages_unix_file(struct address_space *, struct writeback_control *);
+int prepare_write_unix_file(struct file *, struct page *, unsigned from,
+ unsigned to);
+struct inode;
+
+/* unix file plugin specific part of reiser4 inode */
-+struct unix_file_info {
++typedef struct unix_file_info {
+ /*
+ * this read-write lock protects file containerization change. Accesses
+ * which do not change file containerization (see file_container_t)
+ * 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;
+ /*
+ 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(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 *);
++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 *);
+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"
+ lock_handle *lh;
+ int valid;
+ union {
-+ struct extent_coord_extension extent;
-+ struct tail_coord_extension tail;
-+ struct ctail_coord_extension ctail;
++ extent_coord_extension_t extent;
++ tail_coord_extension_t tail;
++ ctail_coord_extension_t ctail;
+ } extension;
+};
+
+ lock_handle lh;
+};
+
-+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);
++void set_hint(hint_t *, const reiser4_key *, znode_lock_mode);
+int hint_is_set(const hint_t *);
-+void reiser4_unset_hint(hint_t *);
++void unset_hint(hint_t *);
++int hint_validate(hint_t *, const reiser4_key *, int check_key,
++ znode_lock_mode);
++void hint_init_zero(hint_t *);
+
-+int reiser4_update_file_size(struct inode *, reiser4_key *, int update_sd);
++int 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(struct unix_file_info * uf_info)
++static inline int ea_obtained(unix_file_info_t * uf_info)
+{
+ int ret;
+
+#endif
+
+/* declarations of functions implementing SYMLINK_FILE_PLUGIN_ID file plugin */
-+int reiser4_create_symlink(struct inode *symlink, struct inode *dir,
-+ reiser4_object_create_data *);
++int create_symlink(struct inode *symlink, struct inode *dir,
++ reiser4_object_create_data *);
+void destroy_inode_symlink(struct inode *);
+
-+/* declarations of functions implementing CRYPTCOMPRESS_FILE_PLUGIN_ID
-+ file plugin */
++/* declarations of functions implementing CRC_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, int * conv);
-+ssize_t prot_write_cryptcompress(struct file *, const char __user *buf, size_t write_amount,
-+ loff_t * off);
++ 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_object_cryptcompress(struct inode *);
++int delete_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,
+ 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(struct unix_file_info *);
-+int extent2tail(struct unix_file_info *);
++
++int tail2extent(unix_file_info_t *);
++int extent2tail(unix_file_info_t *);
+
+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);
+
-+static inline int cbk_errored(int cbk_result)
++extern inline int cbk_errored(int cbk_result)
+{
+ return (cbk_result != CBK_COORD_NOTFOUND
+ && cbk_result != CBK_COORD_FOUND);
+ * scroll-step: 1
+ * End:
+*/
-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
+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 */
+
-+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
++/* 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)
++{
++
++}
++
++/* 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
@@ -0,0 +1,87 @@
+/* Copyright 2001, 2002, 2003 by Hans Reiser, licensing governed by reiser4/README */
+
+ sophisticated symfile syntax that we are not planning to write for
+ version 4.0.
+*/
-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 @@
+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 @@
+/* Copyright 2002, 2003, 2005 by Hans Reiser, licensing governed by reiser4/README */
+
+#include "../../inode.h"
+ */
+
+/**
-+ * reiser4_create_symlink - create_object of file plugin for SYMLINK_FILE_PLUGIN_ID
++ * 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 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 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", reiser4_inode_get_flag(symlink, REISER4_NO_SD));
++ assert("nikita-685", 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);
+ */
+ reiser4_inode_data(symlink)->extmask |= (1 << SYMLINK_STAT);
+
-+ assert("vs-838", symlink->i_private == NULL);
-+ symlink->i_private = (void *)data->name;
++ assert("vs-838", symlink->u.generic_ip == NULL);
++ symlink->u.generic_ip = (void *)data->name;
+
+ assert("vs-843", symlink->i_size == 0);
+ INODE_SET_FIELD(symlink, i_size, strlen(data->name));
+ /* 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->i_private is not attached
++ /* FIXME-VS: Make sure that symlink->u.generic_ip is not attached
+ to kmalloced data */
+ INODE_SET_FIELD(symlink, i_size, 0);
+ } else {
-+ assert("vs-849", symlink->i_private
-+ && reiser4_inode_get_flag(symlink,
-+ REISER4_GENERIC_PTR_USED));
++ assert("vs-849", symlink->u.generic_ip
++ && inode_get_flag(symlink, REISER4_GENERIC_PTR_USED));
+ assert("vs-850",
-+ !memcmp((char *)symlink->i_private, data->name,
++ !memcmp((char *)symlink->u.generic_ip, data->name,
+ (size_t) symlink->i_size + 1));
+ }
+ return result;
+ 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", reiser4_inode_get_flag(inode,
-+ REISER4_GENERIC_PTR_USED));
++ assert("edward-801", inode_get_flag(inode, REISER4_GENERIC_PTR_USED));
+ assert("vs-839", S_ISLNK(inode->i_mode));
+
-+ kfree(inode->i_private);
-+ inode->i_private = NULL;
-+ reiser4_inode_clr_flag(inode, REISER4_GENERIC_PTR_USED);
++ kfree(inode->u.generic_ip);
++ inode->u.generic_ip = NULL;
++ 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: 80
-+ scroll-step: 1
-+ End:
++/* 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/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 @@
+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 @@
+/* Copyright 2001, 2002, 2003 by Hans Reiser, licensing governed by reiser4/README */
+
+#include "../../inode.h"
+ tail2extent and extent2tail */
+
+/* exclusive access to a file is acquired when file state changes: tail2extent, empty2tail, extent2tail, etc */
-+void get_exclusive_access(struct unix_file_info * uf_info)
++void get_exclusive_access(unix_file_info_t * uf_info)
+{
-+ assert("nikita-3028", reiser4_schedulable());
++ assert("nikita-3028", schedulable());
+ assert("nikita-3047", LOCK_CNT_NIL(inode_sem_w));
+ assert("nikita-3048", LOCK_CNT_NIL(inode_sem_r));
+ /*
+ * thread that captured some block (hence preventing atom from being
+ * committed) and waits on rw-semaphore.
+ */
-+ reiser4_txn_restart_current();
++ txn_restart_current();
+ LOCK_CNT_INC(inode_sem_w);
+ down_write(&uf_info->latch);
+ uf_info->exclusive_use = 1;
+ ON_DEBUG(uf_info->ea_owner = current);
+}
+
-+void drop_exclusive_access(struct unix_file_info * uf_info)
++void drop_exclusive_access(unix_file_info_t * uf_info)
+{
+ assert("vs-1714", uf_info->ea_owner == current);
+ assert("vs-1715", atomic_read(&uf_info->nr_neas) == 0);
+ assert("nikita-3049", LOCK_CNT_NIL(inode_sem_r));
+ assert("nikita-3049", LOCK_CNT_GTZ(inode_sem_w));
+ LOCK_CNT_DEC(inode_sem_w);
-+ reiser4_txn_restart_current();
++ txn_restart_current();
+}
+
+/**
+ * This is called when nonexclisive access is obtained on file. All it does is
+ * for debugging purposes.
+ */
-+static void nea_grabbed(struct unix_file_info *uf_info)
++static void nea_grabbed(unix_file_info_t *uf_info)
+{
+#if REISER4_DEBUG
+ LOCK_CNT_INC(inode_sem_r);
+ *
+ * Nonexclusive access is obtained on a file before read, write, readpage.
+ */
-+void get_nonexclusive_access(struct unix_file_info *uf_info)
++void get_nonexclusive_access(unix_file_info_t *uf_info)
+{
-+ assert("nikita-3029", reiser4_schedulable());
++ assert("nikita-3029", schedulable());
+ assert("nikita-3361", get_current_context()->trans->atom == NULL);
+
+ down_read(&uf_info->latch);
+ *
+ * Non-blocking version of nonexclusive access obtaining.
+ */
-+int try_to_get_nonexclusive_access(struct unix_file_info *uf_info)
++int try_to_get_nonexclusive_access(unix_file_info_t *uf_info)
+{
+ int result;
+
+ return result;
+}
+
-+void drop_nonexclusive_access(struct unix_file_info * uf_info)
++void drop_nonexclusive_access(unix_file_info_t * uf_info)
+{
+ assert("vs-1718", uf_info->ea_owner == NULL);
+ assert("vs-1719", atomic_read(&uf_info->nr_neas) > 0);
+ up_read(&uf_info->latch);
+
+ LOCK_CNT_DEC(inode_sem_r);
-+ reiser4_txn_restart_current();
++ txn_restart_current();
+}
+
+/* part of tail2extent. Cut all items covering @count bytes starting from
+ set_key_offset(&to, (__u64) (offset + count - 1));
+
+ /* cut everything between those keys */
-+ return reiser4_cut_tree(reiser4_tree_by_inode(inode), &from, &to,
-+ inode, 0);
++ return cut_tree(tree_by_inode(inode), &from, &to, inode, 0);
+}
+
+static void release_all_pages(struct page **pages, unsigned nr_pages)
+ assert("vs-596", pages[0]);
+
+ /* cut copied items */
-+ result = cut_formatting_items(inode, page_offset(pages[0]), count);
++ result =
++ cut_formatting_items(inode,
++ (loff_t) pages[0]->index << PAGE_CACHE_SHIFT,
++ count);
+ if (result)
+ return result;
+
+ reiser4_block_nr unformatted_nodes;
+ reiser4_tree *tree;
+
-+ tree = reiser4_tree_by_inode(inode);
++ tree = tree_by_inode(inode);
+
+ /* number of unformatted nodes which will be created */
+ unformatted_nodes = TAIL2EXTENT_PAGE_NUM;
+ reiser4_grab_space(inode_file_plugin(inode)->estimate.update(inode),
+ BA_CAN_COMMIT);
+ if (result == 0) {
-+ reiser4_inode_clr_flag(inode, REISER4_PART_MIXED);
++ inode_clr_flag(inode, REISER4_PART_MIXED);
+ result = reiser4_update_sd(inode);
+ }
+ if (result)
+ int result;
+ lock_handle lh;
+ coord_t coord;
-+ struct unix_file_info *ufo;
++ unix_file_info_t *ufo;
+ int found;
+ reiser4_key key;
+
+ *
+ *
+ */
-+int tail2extent(struct unix_file_info *uf_info)
++int tail2extent(unix_file_info_t *uf_info)
+{
+ int result;
+ reiser4_key key; /* key of next byte to be moved to page */
+ inode = unix_file_info_to_inode(uf_info);
+ assert("nikita-3412", !IS_RDONLY(inode));
+ assert("vs-1649", uf_info->container != UF_CONTAINER_EXTENTS);
-+ assert("", !reiser4_inode_get_flag(inode, REISER4_PART_IN_CONV));
++ assert("", !inode_get_flag(inode, REISER4_PART_IN_CONV));
+
+ offset = 0;
+ first_iteration = 1;
+ result = 0;
-+ if (reiser4_inode_get_flag(inode, REISER4_PART_MIXED)) {
++ if (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
+ first_iteration = 0;
+ }
+
-+ reiser4_inode_set_flag(inode, REISER4_PART_IN_CONV);
++ 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);
+ if (result != 0)
+ goto out;
+ if (first_iteration) {
-+ reiser4_inode_set_flag(inode, REISER4_PART_MIXED);
++ inode_set_flag(inode, REISER4_PART_MIXED);
+ reiser4_update_sd(inode);
+ first_iteration = 0;
+ }
+ for (i = 0; i < sizeof_array(pages) && done == 0; i++) {
+ assert("vs-598",
+ (get_key_offset(&key) & ~PAGE_CACHE_MASK) == 0);
-+ page = alloc_page(reiser4_ctx_gfp_mask_get());
++ page = alloc_page(get_gfp_mask());
+ if (!page) {
+ result = RETERR(-ENOMEM);
+ goto error;
+ 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,
-+ * 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.
++ * 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
+ */
+ drop_exclusive_access(uf_info);
+ /* throttle the conversion */
+ * nobody is allowed to complete conversion but a
+ * process which started it
+ */
-+ assert("", reiser4_inode_get_flag(inode,
-+ REISER4_PART_MIXED));
++ assert("", inode_get_flag(inode, REISER4_PART_MIXED));
+ }
+ }
+
-+ reiser4_inode_clr_flag(inode, REISER4_PART_IN_CONV);
++ inode_clr_flag(inode, REISER4_PART_IN_CONV);
+
+ if (result == 0) {
+ /* file is converted to extent items */
-+ assert("vs-1697", reiser4_inode_get_flag(inode,
-+ REISER4_PART_MIXED));
++ assert("vs-1697", inode_get_flag(inode, REISER4_PART_MIXED));
+
+ uf_info->container = UF_CONTAINER_EXTENTS;
+ complete_conversion(inode);
+{
+ reiser4_tree *tree;
+
-+ tree = reiser4_tree_by_inode(inode);
++ tree = tree_by_inode(inode);
+ /*
+ * reserve blocks for (in this order):
+ *
+ 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(struct unix_file_info *uf_info)
++int extent2tail(unix_file_info_t *uf_info)
+{
+ int result;
+ struct inode *inode;
+ inode = unix_file_info_to_inode(uf_info);
+ assert("nikita-3412", !IS_RDONLY(inode));
+ assert("vs-1649", uf_info->container != UF_CONTAINER_TAILS);
-+ assert("", !reiser4_inode_get_flag(inode, REISER4_PART_IN_CONV));
++ assert("", !inode_get_flag(inode, REISER4_PART_IN_CONV));
+
+ offset = 0;
-+ if (reiser4_inode_get_flag(inode, REISER4_PART_MIXED)) {
++ if (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
+ return result;
+ }
+
-+ reiser4_inode_set_flag(inode, REISER4_PART_IN_CONV);
++ inode_set_flag(inode, REISER4_PART_IN_CONV);
+
+ /* number of pages in the file */
+ num_pages =
+ if (result != 0)
+ break;
+ if (i == 0 && offset == 0) {
-+ reiser4_inode_set_flag(inode, REISER4_PART_MIXED);
++ inode_set_flag(inode, REISER4_PART_MIXED);
+ reiser4_update_sd(inode);
+ }
+
-+ page = read_mapping_page(inode->i_mapping,
-+ (unsigned)(i + start_page), NULL);
++ page = read_cache_page(inode->i_mapping,
++ (unsigned)(i + start_page), filler, NULL);
+ if (IS_ERR(page)) {
+ result = PTR_ERR(page);
+ break;
+ }
+
+ /* cut part of file we have read */
-+ start_byte = (__u64) ((i + start_page) << PAGE_CACHE_SHIFT);
++ start_byte = (__u64) (i << PAGE_CACHE_SHIFT);
+ set_key_offset(&from, start_byte);
+ set_key_offset(&to, start_byte + PAGE_CACHE_SIZE - 1);
+ /*
-+ * reiser4_cut_tree_object() returns -E_REPEAT to allow atom
++ * 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 = reiser4_cut_tree(reiser4_tree_by_inode(inode), &from,
-+ &to, inode, 0);
++ result = cut_tree(tree_by_inode(inode), &from, &to, inode, 0);
+
+ if (result) {
+ page_cache_release(page);
+ file.f_pos = start_byte;
+ file.private_data = NULL;
+ pos = start_byte;
-+ result = reiser4_write_tail(&file,
-+ (char __user *)kmap(page),
-+ count, &pos);
++ result = write_tail(&file, (char __user *)kmap(page),
++ count, &pos);
+ reiser4_free_file_fsdata(&file);
+ if (result <= 0) {
-+ warning("", "reiser4_write_tail failed");
++ warning("", "write_tail failed");
+ page_cache_release(page);
-+ reiser4_inode_clr_flag(inode, REISER4_PART_IN_CONV);
++ inode_clr_flag(inode, REISER4_PART_IN_CONV);
+ return result;
+ }
+ count -= result;
+ /* waiting for writeback completion with page lock held is
+ * perfectly valid. */
+ wait_on_page_writeback(page);
-+ reiser4_drop_page(page);
++ drop_page(page);
+ /* release reference taken by read_cache_page() above */
+ page_cache_release(page);
+
+ * nobody is allowed to complete conversion but a process which
+ * started it
+ */
-+ assert("", reiser4_inode_get_flag(inode, REISER4_PART_MIXED));
++ assert("", inode_get_flag(inode, REISER4_PART_MIXED));
+ }
+
-+ reiser4_inode_clr_flag(inode, REISER4_PART_IN_CONV);
++ inode_clr_flag(inode, REISER4_PART_IN_CONV);
+
+ if (i == num_pages) {
+ /* file is converted to formatted items */
-+ assert("vs-1698", reiser4_inode_get_flag(inode,
-+ REISER4_PART_MIXED));
++ assert("vs-1698", inode_get_flag(inode, REISER4_PART_MIXED));
+ assert("vs-1260",
+ inode_has_no_jnodes(reiser4_inode_data(inode)));
+
+ * scroll-step: 1
+ * End:
+ */
-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 @@
+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 @@
+/* Copyright 2005 by Hans Reiser, licensing governed by
+ reiser4/README */
+
+/* implementation of vfs's llseek method of struct file_operations for
+ typical directory can be found in readdir_common.c
+*/
-+loff_t reiser4_llseek_dir_common(struct file *, loff_t, int origin);
++loff_t llseek_common_dir(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 reiser4_readdir_common(struct file *, void *dirent, filldir_t);
++int readdir_common(struct file *, void *dirent, filldir_t);
+
+/**
-+ * reiser4_release_dir_common - release of struct file_operations
++ * 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 reiser4_release_dir_common(struct inode *inode, struct file *file)
++int release_dir_common(struct inode *inode, struct file *file)
+{
+ reiser4_context *ctx;
+
-+ ctx = reiser4_init_context(inode->i_sb);
++ ctx = init_context(inode->i_sb);
+ if (IS_ERR(ctx))
+ return PTR_ERR(ctx);
+ reiser4_free_file_fsdata(file);
+/* this is common implementation of vfs's fsync method of struct
+ file_operations
+*/
-+int reiser4_sync_common(struct file *file, struct dentry *dentry, int datasync)
++int sync_common(struct file *file, struct dentry *dentry, int datasync)
+{
+ reiser4_context *ctx;
+ int result;
+
-+ ctx = reiser4_init_context(dentry->d_inode->i_sb);
++ ctx = 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);
+ reiser4_context *ctx;
+ ssize_t result;
+
-+ ctx = reiser4_init_context(file->f_dentry->d_inode->i_sb);
++ ctx = 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);
+ reiser4_context *ctx;
+ int result;
+
-+ ctx = reiser4_init_context(page->mapping->host->i_sb);
++ ctx = init_context(page->mapping->host->i_sb);
+ result = do_prepare_write(file, page, from, to);
+
+ /* don't commit transaction under inode semaphore */
+ * c-basic-offset: 8
+ * tab-width: 8
+ * fill-column: 79
-+ * scroll-step: 1
+ * End:
+ */
-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 @@
+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 @@
+/* Copyright 2005 by Hans Reiser, licensing governed by
+ * reiser4/README */
+
+ * @inode directory. */
+static int is_valid_dir_coord(struct inode *inode, coord_t * coord)
+{
-+ return plugin_of_group(item_plugin_by_coord(coord),
-+ DIR_ENTRY_ITEM_TYPE) &&
-+ inode_file_plugin(inode)->owns_item(inode, coord);
++ return
++ item_type_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 struct dir_pos * p1, const struct dir_pos * p2)
++static cmp_t dir_pos_cmp(const dir_pos * p1, const dir_pos * p2)
+{
+ cmp_t result;
+
+ return result;
+}
+
-+/* see comment before reiser4_readdir_common() for overview of why "adjustment" is
++
++/* see comment before readdir_common() for overview of why "adjustment" is
+ * necessary. */
+static void
-+adjust_dir_pos(struct file *dir, struct readdir_pos * readdir_spot,
-+ const struct dir_pos * mod_point, int adj)
++adjust_dir_pos(struct file *dir,
++ readdir_pos * readdir_spot, const dir_pos * mod_point, int adj)
+{
-+ struct dir_pos *pos;
++ dir_pos *pos;
+
+ /*
+ * new directory entry was added (adj == +1) or removed (adj == -1) at
+ * changes */
+ readdir_spot->entry_no += adj;
+ assert("nikita-2577",
-+ ergo(dir != NULL, reiser4_get_dir_fpos(dir) + adj >= 0));
++ ergo(dir != NULL, 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);
+/* 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 reiser4_adjust_dir_file(struct inode *dir, const struct dentry *de,
-+ int offset, int adj)
++void
++adjust_dir_file(struct inode *dir, const struct dentry *de, int offset, int adj)
+{
+ reiser4_file_fsdata *scan;
-+ struct dir_pos mod_point;
++ dir_pos mod_point;
+
+ assert("nikita-2536", dir != NULL);
+ assert("nikita-2538", de != NULL);
+/*
+ * traverse tree to start/continue readdir from the readdir position @pos.
+ */
-+static int dir_go_to(struct file *dir, struct readdir_pos * pos, tap_t * tap)
++static int dir_go_to(struct file *dir, readdir_pos * pos, tap_t * tap)
+{
+ reiser4_key key;
+ int result;
+ result = inode_dir_plugin(inode)->build_readdir_key(dir, &key);
+ if (result != 0)
+ return result;
-+ result = reiser4_object_lookup(inode,
-+ &key,
-+ tap->coord,
-+ tap->lh,
-+ tap->mode,
-+ FIND_EXACT,
-+ LEAF_LEVEL, LEAF_LEVEL,
-+ 0, &tap->ra_info);
++ result = 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 {
+ * 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, struct readdir_pos * pos, tap_t * tap)
++static int set_pos(struct inode *inode, readdir_pos * pos, tap_t * tap)
+{
+ int result;
+ coord_t coord;
+
+ coord_init_zero(&coord);
+ init_lh(&lh);
-+ reiser4_tap_init(&scan, &coord, &lh, ZNODE_READ_LOCK);
-+ reiser4_tap_copy(&scan, tap);
-+ reiser4_tap_load(&scan);
++ tap_init(&scan, &coord, &lh, ZNODE_READ_LOCK);
++ tap_copy(&scan, tap);
++ tap_load(&scan);
+ pos->position.pos = 0;
+
+ did = &pos->position.dir_entry_key;
+ }
+ } else
+ result = RETERR(-ENOENT);
-+ reiser4_tap_relse(&scan);
-+ reiser4_tap_done(&scan);
++ tap_relse(&scan);
++ tap_done(&scan);
+ return result;
+}
+
+/*
+ * "rewind" directory to @offset, i.e., set @pos and @tap correspondingly.
+ */
-+static int dir_rewind(struct file *dir, struct readdir_pos * pos, tap_t * tap)
++static int dir_rewind(struct file *dir, readdir_pos * pos, tap_t * tap)
+{
+ __u64 destination;
+ __s64 shift;
+ assert("nikita-2551", tap->coord != NULL);
+ assert("nikita-2552", tap->lh != NULL);
+
-+ dirpos = reiser4_get_dir_fpos(dir);
++ dirpos = get_dir_fpos(dir);
+ shift = dirpos - pos->fpos;
+ /* this is logical directory entry within @dir which we are rewinding
+ * to */
+ if (result == 0) {
+ result = rewind_left(tap, shift);
+ if (result == -E_DEADLOCK) {
-+ reiser4_tap_done(tap);
++ tap_done(tap);
+ continue;
+ }
+ }
+ * unlocked.
+ */
+static int
-+feed_entry(struct file *f, struct readdir_pos * pos, tap_t * tap,
-+ filldir_t filldir, void *dirent)
++feed_entry(struct file *f,
++ readdir_pos * pos, tap_t * tap, filldir_t filldir, void *dirent)
+{
+ item_plugin *iplug;
+ char *name;
+ 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,
-+ reiser4_ctx_gfp_mask_get());
++ local_name = kmalloc(strlen(name) + 1, get_gfp_mask());
+ if (local_name == NULL)
+ return RETERR(-ENOMEM);
+ } else
+ file_type = iplug->s.dir.extract_file_type(coord);
+
+ unit_key_by_coord(coord, &entry_key);
-+ reiser4_seal_init(&seal, coord, &entry_key);
++ seal_init(&seal, coord, &entry_key);
+
+ longterm_unlock_znode(tap->lh);
+
+ */
+ 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,
+ /* ->filldir() is satisfied. (no space in buffer, IOW) */
+ result = 1;
+ else
-+ result = reiser4_seal_validate(&seal, coord, &entry_key,
-+ tap->lh, tap->mode,
-+ ZNODE_LOCK_HIPRI);
++ result = seal_validate(&seal, coord, &entry_key,
++ tap->lh, tap->mode, ZNODE_LOCK_HIPRI);
+ return result;
+}
+
-+static void move_entry(struct readdir_pos * pos, coord_t * coord)
++static void move_entry(readdir_pos * pos, coord_t * coord)
+{
+ reiser4_key de_key;
+ de_id *did;
+ *
+ * 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 reiser4_readdir_common() function below. This obviously doesn't
-+ * work when reiser4 is accessed over NFS, because NFS doesn't keep any state
++ * removal), see 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
+ *
+ */
+
++
+/*
+ * prepare for readdir.
+ */
-+static int dir_readdir_init(struct file *f, tap_t * tap,
-+ struct readdir_pos ** pos)
++static int dir_readdir_init(struct file *f, tap_t * tap, readdir_pos ** pos)
+{
+ struct inode *inode;
+ reiser4_file_fsdata *fsdata;
+ return RETERR(-ENOTDIR);
+
+ /* try to find detached readdir state */
-+ result = reiser4_attach_fsdata(f, inode);
++ result = try_to_attach_fsdata(f, inode);
+ if (result != 0)
+ return result;
+
+
+/* this is implementation of vfs's llseek method of struct file_operations for
+ typical directory
-+ See comment before reiser4_readdir_common() for explanation.
++ See comment before readdir_common() for explanation.
+*/
-+loff_t reiser4_llseek_dir_common(struct file * file, loff_t off, int origin)
++loff_t llseek_common_dir(struct file * file, loff_t off, int origin)
+{
+ reiser4_context *ctx;
+ loff_t result;
+
+ inode = file->f_dentry->d_inode;
+
-+ ctx = reiser4_init_context(inode->i_sb);
++ ctx = init_context(inode->i_sb);
+ if (IS_ERR(ctx))
+ return PTR_ERR(ctx);
+
+ coord_t coord;
+ lock_handle lh;
+ tap_t tap;
-+ struct readdir_pos *pos;
++ readdir_pos *pos;
+
+ coord_init_zero(&coord);
+ init_lh(&lh);
-+ reiser4_tap_init(&tap, &coord, &lh, ZNODE_READ_LOCK);
++ tap_init(&tap, &coord, &lh, ZNODE_READ_LOCK);
+
+ ff = dir_readdir_init(file, &tap, &pos);
-+ reiser4_detach_fsdata(file);
++ detach_fsdata(file);
+ if (ff != 0)
+ result = (loff_t) ff;
-+ reiser4_tap_done(&tap);
++ tap_done(&tap);
+ }
-+ reiser4_detach_fsdata(file);
++ detach_fsdata(file);
+ mutex_unlock(&inode->i_mutex);
+
+ reiser4_exit_context(ctx);
+ entry all file descriptors for directory inode are scanned and their
+ readdir_pos are updated accordingly (adjust_dir_pos()).
+*/
-+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 */)
++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 */ )
+{
+ reiser4_context *ctx;
+ int result;
+ coord_t coord;
+ lock_handle lh;
+ tap_t tap;
-+ struct readdir_pos *pos;
++ readdir_pos *pos;
+
+ assert("nikita-1359", f != NULL);
+ inode = f->f_dentry->d_inode;
+ if (!S_ISDIR(inode->i_mode))
+ return RETERR(-ENOTDIR);
+
-+ ctx = reiser4_init_context(inode->i_sb);
++ ctx = init_context(inode->i_sb);
+ if (IS_ERR(ctx))
+ return PTR_ERR(ctx);
+
+ coord_init_zero(&coord);
+ init_lh(&lh);
-+ reiser4_tap_init(&tap, &coord, &lh, ZNODE_READ_LOCK);
++ 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 = reiser4_tap_load(&tap);
++ result = tap_load(&tap);
+ /* scan entries one by one feeding them to @filld */
+ while (result == 0) {
+ coord_t *coord;
+ } else if (result == -E_REPEAT) {
+ /* feed_entry() had to restart. */
+ ++f->f_pos;
-+ reiser4_tap_relse(&tap);
++ tap_relse(&tap);
+ goto repeat;
+ } else
+ warning("vs-1617",
-+ "reiser4_readdir_common: unexpected error %d",
++ "readdir_common: unexpected error %d",
+ result);
+ }
-+ reiser4_tap_relse(&tap);
++ tap_relse(&tap);
+
+ if (result >= 0)
+ f->f_version = inode->i_version;
+ } else if (result == -E_NO_NEIGHBOR || result == -ENOENT)
+ result = 0;
-+ reiser4_tap_done(&tap);
-+ reiser4_detach_fsdata(f);
++ tap_done(&tap);
++ detach_fsdata(f);
+
+ /* try to update directory's atime */
-+ if (reiser4_grab_space_force(inode_file_plugin(inode)->estimate.update(inode),
++ if (reiser4_grab_space(inode_file_plugin(inode)->estimate.update(inode),
+ BA_CAN_COMMIT) != 0)
+ warning("", "failed to update atime on readdir: %llu",
+ get_inode_oid(inode));
+ * fill-column: 79
+ * End:
+ */
-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 @@
+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 @@
+/* Copyright 2005 by Hans Reiser, licensing governed by
+ reiser4/README */
+
+
+ assert("nikita-730", inode != NULL);
+
-+ if (reiser4_inode_get_flag(inode, REISER4_NO_SD))
++ if (inode_get_flag(inode, REISER4_NO_SD))
+ /* object doesn't have stat-data yet */
+ result = insert_new_sd(inode);
+ else
+ object->i_gid = current->fsgid;
+
+ /* this object doesn't have stat-data yet */
-+ reiser4_inode_set_flag(object, REISER4_NO_SD);
++ 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 */
+ setup_inode_ops(object, data);
+#endif
+ object->i_nlink = 0;
-+ reiser4_seal_init(&reiser4_inode_data(object)->sd_seal, NULL, NULL);
++ 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);
+ * inherit missing plugins from parent
+ */
+
-+ 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);
++ grab_plugin(object, parent, PSET_FILE);
++ grab_plugin(object, parent, PSET_SD);
++ grab_plugin(object, parent, PSET_FORMATTING);
++ grab_plugin(object, parent, PSET_PERM);
+ return 0;
+}
+
+ * inherit missing plugins from parent
+ */
+ for (memb = 0; memb < PSET_LAST; ++memb) {
-+ result = grab_plugin_pset(object, parent, memb);
++ result = grab_plugin(object, parent, memb);
+ if (result != 0)
+ break;
+ }
+ return result;
+ assert("edward-1416", parent != NULL);
+
-+ 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);
++ 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);
+
+ return 0;
+}
+
+/* this is common implementation of create_object method of file plugin
+ */
-+int reiser4_create_object_common(struct inode *object, struct inode *parent,
-+ reiser4_object_create_data * data)
++int
++create_object_common(struct inode *object, struct inode *parent UNUSED_ARG,
++ reiser4_object_create_data * data UNUSED_ARG)
+{
+ reiser4_block_nr reserve;
+ assert("nikita-744", object != NULL);
+ assert("nikita-745", parent != NULL);
+ assert("nikita-747", data != NULL);
-+ assert("nikita-748", reiser4_inode_get_flag(object, REISER4_NO_SD));
++ assert("nikita-748", inode_get_flag(object, REISER4_NO_SD));
+
+ reserve = estimate_create_common(object);
+ if (reiser4_grab_space(reserve, BA_CAN_COMMIT))
+static int common_object_delete_no_reserve(struct inode *inode);
+
+/**
-+ * reiser4_delete_object_common - delete_object of file_plugin
++ * 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 reiser4_delete_object_common(struct inode *inode)
++int delete_object_common(struct inode *inode)
+{
+ int result;
+
+ assert("nikita-3420", inode->i_size == 0 || S_ISLNK(inode->i_mode));
+ assert("nikita-3421", inode->i_nlink == 0);
+
-+ if (!reiser4_inode_get_flag(inode, REISER4_NO_SD)) {
++
++ if (!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(reiser4_tree_by_inode(inode));
++ reserve = 2 * estimate_one_item_removal(tree_by_inode(inode));
+ if (reiser4_grab_space_force(reserve,
+ BA_RESERVED | BA_CAN_COMMIT))
+ return RETERR(-ENOSPC);
+}
+
+/**
-+ * reiser4_delete_dir_common - delete_object of file_plugin
++ * delete_directory_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 reiser4_delete_dir_common(struct inode *inode)
++int delete_directory_common(struct inode *inode)
+{
+ int result;
+ dir_plugin *dplug;
+ assert("vs-1101", dplug && dplug->done);
+
+ /* kill cursors which might be attached to inode */
-+ reiser4_kill_cursors(inode);
++ kill_cursors(inode);
+
+ /* grab space enough for removing two items */
+ if (reiser4_grab_space
-+ (2 * estimate_one_item_removal(reiser4_tree_by_inode(inode)),
++ (2 * estimate_one_item_removal(tree_by_inode(inode)),
+ BA_RESERVED | BA_CAN_COMMIT))
+ return RETERR(-ENOSPC);
+
+
+/* this is common implementation of add_link method of file plugin
+ */
-+int reiser4_add_link_common(struct inode *object, struct inode *parent)
++int add_link_common(struct inode *object, struct inode *parent UNUSED_ARG)
+{
+ /*
+ * increment ->i_nlink and update ->i_ctime
+
+/* this is common implementation of rem_link method of file plugin
+ */
-+int reiser4_rem_link_common(struct inode *object, struct inode *parent)
++int rem_link_common(struct inode *object, struct inode *parent UNUSED_ARG)
+{
+ assert("nikita-2021", object != NULL);
+ assert("nikita-2163", object->i_nlink > 0);
+ assert("nikita-1335", inode != NULL);
+ assert("nikita-1334", coord != NULL);
+
-+ if (plugin_of_group(item_plugin_by_coord(coord), DIR_ENTRY_ITEM_TYPE))
++ if (item_type_by_coord(coord) == DIR_ENTRY_ITEM_TYPE)
+ return get_key_locality(item_key_by_coord(coord, &item_key)) ==
+ get_inode_oid(inode);
+ else
+/* this is common implementation of detach method of file plugin for typical
+ directory
+*/
-+int reiser4_detach_common_dir(struct inode *child, struct inode *parent)
++int detach_common_dir(struct inode *child, struct inode *parent)
+{
+ dir_plugin *dplug;
+
+/* this is common implementation of bind method of file plugin for typical
+ directory
+*/
-+int reiser4_bind_common_dir(struct inode *child, struct inode *parent)
++int bind_common_dir(struct inode *child, struct inode *parent)
+{
+ dir_plugin *dplug;
+
+*/
+reiser4_block_nr estimate_create_common(const struct inode * object)
+{
-+ return estimate_one_insert_item(reiser4_tree_by_inode(object));
++ return estimate_one_insert_item(tree_by_inode(object));
+}
+
+/* this is common implementation of estimate.create method of file plugin for
+*/
+reiser4_block_nr estimate_create_common_dir(const struct inode * object)
+{
-+ return 2 * estimate_one_insert_item(reiser4_tree_by_inode(object));
++ return 2 * estimate_one_insert_item(tree_by_inode(object));
+}
+
+/* this is common implementation of estimate.update method of file plugin
+*/
+reiser4_block_nr estimate_update_common(const struct inode * inode)
+{
-+ return estimate_one_insert_into_item(reiser4_tree_by_inode(inode));
++ return estimate_one_insert_into_item(tree_by_inode(inode));
+}
+
+/* this is common implementation of estimate.unlink method of file plugin
+ if (code != -ENOMEM) {
+ warning("nikita-717", "Error for inode %llu (%i)",
+ (unsigned long long)get_key_objectid(key), code);
-+ reiser4_print_key("for key", key);
++ print_key("for key", key);
+ }
+}
+
+ (znode_get_level(coord->node) != LEAF_LEVEL) ||
+ !item_is_statdata(coord)) {
+ warning("nikita-1901", "Conspicuous seal");
-+ reiser4_print_key("key", key);
++ print_key("key", key);
+ print_coord("coord", coord, 1);
+ impossible("nikita-2877", "no way");
+ }
+ oid_t oid;
+
+ assert("nikita-723", inode != NULL);
-+ assert("nikita-3406", reiser4_inode_get_flag(inode, REISER4_NO_SD));
++ assert("nikita-3406", inode_get_flag(inode, REISER4_NO_SD));
+
+ ref = reiser4_inode_data(inode);
+ spin_lock_inode(inode);
+/* 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 > reiser4_tree_by_inode(inode)->nplug->max_item_size()){
++ if (data.length > 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);
+ coord_init_zero(&coord);
+ init_lh(&lh);
+
-+ result = insert_by_key(reiser4_tree_by_inode(inode),
++ result = insert_by_key(tree_by_inode(inode),
+ build_sd_key(inode, &key), &data, &coord, &lh,
+ /* stat data lives on a leaf level */
+ LEAF_LEVEL, CBK_UNIQUE);
+ znode_make_dirty(coord.node);
+ if (result == 0) {
+ /* object has stat-data now */
-+ reiser4_inode_clr_flag(inode, REISER4_NO_SD);
-+ reiser4_inode_set_flag(inode, REISER4_SDLEN_KNOWN);
++ inode_clr_flag(inode, REISER4_NO_SD);
++ inode_set_flag(inode, REISER4_SDLEN_KNOWN);
+ /* initialise stat-data seal */
-+ reiser4_seal_init(&ref->sd_seal, &coord, &key);
++ seal_init(&ref->sd_seal, &coord, &key);
+ ref->sd_coord = coord;
+ check_inode_seal(inode, &coord, &key);
+ } else if (result != -ENOMEM)
+ * it only covers _body_ of the file, and stat data don't belong
+ * there.
+ */
-+ result = coord_by_key(reiser4_tree_by_inode(inode),
++ result = coord_by_key(tree_by_inode(inode),
+ key,
+ coord,
+ lh,
+ spin_unlock_inode(inode);
+
+ build_sd_key(inode, key);
-+ if (reiser4_seal_is_set(&seal)) {
++ if (seal_is_set(&seal)) {
+ /* first, try to use seal */
-+ result = reiser4_seal_validate(&seal,
-+ coord,
-+ key,
-+ lh, ZNODE_WRITE_LOCK,
-+ ZNODE_LOCK_LOPRI);
++ result = seal_validate(&seal,
++ coord,
++ key,
++ lh, ZNODE_WRITE_LOCK, ZNODE_LOCK_LOPRI);
+ if (result == 0)
+ check_sd_coord(coord, key);
+ } else
+ 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,
+
+ /* if inode has non-standard plugins, add appropriate stat data
+ * extension */
-+ if (state->extmask & (1 << PLUGIN_STAT)) {
-+ if (state->plugin_mask == 0)
-+ inode_clr_extension(inode, PLUGIN_STAT);
-+ } else if (state->plugin_mask != 0)
++ 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 (!reiser4_inode_get_flag(inode, REISER4_SDLEN_KNOWN)) {
++ if (!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);
-+ reiser4_inode_set_flag(inode, REISER4_SDLEN_KNOWN);
++ 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 = reiser4_resize_item(coord, &data, key, lh,
-+ COPI_DONT_SHIFT_LEFT);
++ result = 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) {
-+ /* reiser4_resize_item moved coord to another node.
-+ Zload it */
++ /* resize_item moved coord to another node. Zload it */
+ zrelse(loaded);
+ coord_clear_iplug(coord);
+ result = zload(coord->node);
+ 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);
+ * was changed and new extensions were pasted into item.
+ */
+ coord->between = AT_UNIT;
-+ reiser4_seal_init(&state->sd_seal, coord, key);
++ seal_init(&state->sd_seal, coord, key);
+ state->sd_coord = *coord;
+ spin_unlock_inode(inode);
+ check_inode_seal(inode, coord, key);
+ assert("nikita-726", inode != NULL);
+
+ /* no stat-data, nothing to update?! */
-+ assert("nikita-3482", !reiser4_inode_get_flag(inode, REISER4_NO_SD));
++ assert("nikita-3482", !inode_get_flag(inode, REISER4_NO_SD));
+
+ init_lh(&lh);
+
+ return result;
+}
+
-+/* helper for reiser4_delete_object_common and reiser4_delete_dir_common.
-+ Remove object stat data. Space for that must be reserved by caller before
++/* helper for delete_object_common and delete_directory_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 */ )
+
+ assert("nikita-1477", inode != NULL);
+
-+ if (!reiser4_inode_get_flag(inode, REISER4_NO_SD)) {
++ if (!inode_get_flag(inode, REISER4_NO_SD)) {
+ reiser4_key sd_key;
+
+ DQUOT_FREE_INODE(inode);
+
+ build_sd_key(inode, &sd_key);
+ result =
-+ reiser4_cut_tree(reiser4_tree_by_inode(inode),
-+ &sd_key, &sd_key, NULL, 0);
++ cut_tree(tree_by_inode(inode), &sd_key, &sd_key, NULL, 0);
+ if (result == 0) {
-+ reiser4_inode_set_flag(inode, REISER4_NO_SD);
++ 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(reiser4_tree_by_inode(inode),
++ result = safe_link_del(tree_by_inode(inode),
+ get_inode_oid(inode),
+ SAFE_UNLINK);
+ }
+ struct dentry dentry;
+
+ assert("vs-21", is_in_reiser4_context());
-+ ctx = reiser4_init_context(inode->i_sb);
++ ctx = init_context(inode->i_sb);
+ assert("vs-22", !IS_ERR(ctx));
+
+ attr.ia_size = size;
+ return result;
+}
+
-+/*
-+ Local variables:
-+ c-indentation-style: "K&R"
-+ mode-name: "LC"
-+ c-basic-offset: 8
-+ tab-width: 8
-+ fill-column: 80
-+ scroll-step: 1
-+ End:
++/* 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/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 @@
+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 @@
+/* Copyright 2001, 2002, 2003 by Hans Reiser, licensing governed by
+ * reiser4/README */
+
+ return 0xc0c0c0c010101010ull;
+}
+
-+static int change_hash(struct inode *inode,
-+ reiser4_plugin * plugin,
-+ pset_member memb)
++static int change_hash(struct inode *inode, reiser4_plugin * plugin)
+{
+ int result;
+
+ 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 = aset_set_unsafe(&reiser4_inode_data(inode)->pset,
-+ PSET_HASH, plugin);
++ result =
++ plugin_set_hash(&reiser4_inode_data(inode)->pset,
++ &plugin->hash);
+ else
+ result = RETERR(-ENOTEMPTY);
+
+ fill-column: 120
+ End:
+*/
-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 @@
+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 @@
+/*
+ * Copyright 2005 by Hans Reiser, licensing governed by reiser4/README
+ */
+#include <linux/quotaops.h>
+#include <linux/namei.h>
+
++
+static int create_vfs_object(struct inode *parent, struct dentry *dentry,
+ reiser4_object_create_data *data);
+
+/**
-+ * reiser4_create_common - create of inode operations
++ * create_common - create of inode operations
+ * @parent: inode of parent directory
+ * @dentry: dentry of new object to create
+ * @mode: the permissions to use
+ * inode_operations.
+ * Creates regular file using file plugin from parent directory plugin set.
+ */
-+int reiser4_create_common(struct inode *parent, struct dentry *dentry,
-+ int mode, struct nameidata *nameidata)
++int 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;
-+ 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;
++ data.id = inode_regular_plugin(parent)->id;
+ return create_vfs_object(parent, dentry, &data);
+}
+
-+int reiser4_lookup_name(struct inode *dir, struct dentry *, reiser4_key *);
++int lookup_name(struct inode *dir, struct dentry *, reiser4_key *);
+void check_light_weight(struct inode *inode, struct inode *parent);
+
+/**
-+ * reiser4_lookup_common - lookup of inode operations
++ * lookup_common - lookup of inode operations
+ * @parent: inode of directory to lookup into
+ * @dentry: name to look for
+ * @nameidata:
+ * This is common implementation of vfs's lookup method of struct
+ * inode_operations.
+ */
-+struct dentry *reiser4_lookup_common(struct inode *parent,
-+ struct dentry *dentry,
-+ struct nameidata *nameidata)
++struct dentry *lookup_common(struct inode *parent, struct dentry *dentry,
++ struct nameidata *nameidata)
+{
+ reiser4_context *ctx;
+ int result;
+ struct inode *inode;
+ reiser4_dir_entry_desc entry;
+
-+ ctx = reiser4_init_context(parent->i_sb);
++ ctx = 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 = reiser4_lookup_name(parent, dentry, &entry.key);
++ result = lookup_name(parent, dentry, &entry.key);
+ if (result) {
+ context_set_commit_async(ctx);
+ reiser4_exit_context(ctx);
+int reiser4_update_dir(struct inode *);
+
+/**
-+ * reiser4_link_common - link of inode operations
++ * 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
+ * This is common implementation of vfs's link method of struct
+ * inode_operations.
+ */
-+int reiser4_link_common(struct dentry *existing, struct inode *parent,
-+ struct dentry *newname)
++int link_common(struct dentry *existing, struct inode *parent,
++ struct dentry *newname)
+{
+ reiser4_context *ctx;
+ int result;
+ reiser4_object_create_data data;
+ reiser4_block_nr reserve;
+
-+ ctx = reiser4_init_context(parent->i_sb);
++ ctx = init_context(parent->i_sb);
+ if (IS_ERR(ctx))
+ return PTR_ERR(ctx);
+
+ assert("nikita-1434", object != NULL);
+
+ /* check for race with create_object() */
-+ if (reiser4_inode_get_flag(object, REISER4_IMMUTABLE)) {
++ if (inode_get_flag(object, REISER4_IMMUTABLE)) {
+ context_set_commit_async(ctx);
+ reiser4_exit_context(ctx);
+ return RETERR(-E_REPEAT);
+ * reiser4_unlink() viz. creation of safe-link.
+ */
+ if (unlikely(object->i_nlink == 0)) {
-+ result = safe_link_del(reiser4_tree_by_inode(object),
++ result = safe_link_del(tree_by_inode(object),
+ get_inode_oid(object), SAFE_UNLINK);
+ if (result != 0) {
+ context_set_commit_async(ctx);
+static int unlink_check_and_grab(struct inode *parent, struct dentry *victim);
+
+/**
-+ * reiser4_unlink_common - unlink of inode operations
++ * 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 reiser4_unlink_common(struct inode *parent, struct dentry *victim)
++int unlink_common(struct inode *parent, struct dentry *victim)
+{
+ reiser4_context *ctx;
+ int result;
+ struct inode *object;
+ file_plugin *fplug;
+
-+ ctx = reiser4_init_context(parent->i_sb);
++ ctx = init_context(parent->i_sb);
+ if (IS_ERR(ctx))
+ return PTR_ERR(ctx);
+
+}
+
+/**
-+ * reiser4_symlink_common - symlink of inode operations
++ * symlink_common - symlink of inode operations
+ * @parent: inode of parent directory
+ * @dentry: dentry of object to be created
+ * @linkname: string symlink is to contain
+ * inode_operations.
+ * Creates object using file plugin SYMLINK_FILE_PLUGIN_ID.
+ */
-+int reiser4_symlink_common(struct inode *parent, struct dentry *dentry,
-+ const char *linkname)
++int symlink_common(struct inode *parent, struct dentry *dentry,
++ const char *linkname)
+{
+ reiser4_object_create_data data;
+
+}
+
+/**
-+ * reiser4_mkdir_common - mkdir of inode operations
++ * mkdir_common - mkdir of inode operations
+ * @parent: inode of parent directory
+ * @dentry: dentry of object to be created
+ * @mode: the permissions to use
+ * inode_operations.
+ * Creates object using file plugin DIRECTORY_FILE_PLUGIN_ID.
+ */
-+int reiser4_mkdir_common(struct inode *parent, struct dentry *dentry, int mode)
++int mkdir_common(struct inode *parent, struct dentry *dentry, int mode)
+{
+ reiser4_object_create_data data;
+
+}
+
+/**
-+ * reiser4_mknod_common - mknod of inode operations
++ * 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
+ * inode_operations.
+ * Creates object using file plugin SPECIAL_FILE_PLUGIN_ID.
+ */
-+int reiser4_mknod_common(struct inode *parent, struct dentry *dentry,
-+ int mode, dev_t rdev)
++int mknod_common(struct inode *parent, struct dentry *dentry,
++ int mode, dev_t rdev)
+{
+ reiser4_object_create_data data;
+
+ */
+
+/**
-+ * reiser4_follow_link_common - follow_link of inode operations
++ * 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 i_private points to the content of symbolic link.
++ * Assumes that inode's generic_ip points to the content of symbolic link.
+ */
-+void *reiser4_follow_link_common(struct dentry *dentry, struct nameidata *nd)
++void *follow_link_common(struct dentry *dentry, struct nameidata *nd)
+{
+ assert("vs-851", S_ISLNK(dentry->d_inode->i_mode));
+
-+ if (!dentry->d_inode->i_private
-+ || !reiser4_inode_get_flag(dentry->d_inode,
-+ REISER4_GENERIC_PTR_USED))
++ if (!dentry->d_inode->u.generic_ip
++ || !inode_get_flag(dentry->d_inode, REISER4_GENERIC_PTR_USED))
+ return ERR_PTR(RETERR(-EINVAL));
-+ nd_set_link(nd, dentry->d_inode->i_private);
++ nd_set_link(nd, dentry->d_inode->u.generic_ip);
+ return NULL;
+}
+
+/**
-+ * reiser4_permission_common - permission of inode operations
++ * 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 reiser4_permission_common(struct inode *inode, int mask,
-+ struct nameidata *nameidata)
++int permission_common(struct inode *inode, int mask,
++ struct nameidata *nameidata)
+{
+ return generic_permission(inode, mask, NULL);
+}
+/* this is common implementation of vfs's setattr method of struct
+ inode_operations
+*/
-+int reiser4_setattr_common(struct dentry *dentry, struct iattr *attr)
++int setattr_common(struct dentry *dentry, struct iattr *attr)
+{
+ reiser4_context *ctx;
+ struct inode *inode;
+ if (result)
+ return result;
+
-+ ctx = reiser4_init_context(inode->i_sb);
++ ctx = init_context(inode->i_sb);
+ if (IS_ERR(ctx))
+ return PTR_ERR(ctx);
+
+ /*
+ * grab disk space and call standard inode_setattr().
+ */
-+ result = setattr_reserve(reiser4_tree_by_inode(inode));
++ result = setattr_reserve(tree_by_inode(inode));
+ if (!result) {
+ if ((attr->ia_valid & ATTR_UID && attr->ia_uid != inode->i_uid)
+ || (attr->ia_valid & ATTR_GID
+/* this is common implementation of vfs's getattr method of struct
+ inode_operations
+*/
-+int reiser4_getattr_common(struct vfsmount *mnt UNUSED_ARG,
-+ struct dentry *dentry, struct kstat *stat)
++int
++getattr_common(struct vfsmount *mnt UNUSED_ARG, struct dentry *dentry,
++ struct kstat *stat)
+{
+ struct inode *obj;
+
+ memset(&entry, 0, sizeof entry);
+ entry.obj = object;
+
-+ set_plugin(&reiser4_inode_data(object)->pset, PSET_FILE,
-+ file_plugin_to_plugin(obj_plug));
++ plugin_set_file(&reiser4_inode_data(object)->pset, obj_plug);
+ result = obj_plug->set_plug_in_inode(object, parent, data);
+ if (result) {
+ warning("nikita-431", "Cannot install plugin %i on %llx",
+ 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),
+ crash. This all only matters if it's possible to access file
+ without name, for example, by inode number
+ */
-+ reiser4_inode_set_flag(object, REISER4_IMMUTABLE);
++ 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", reiser4_inode_get_flag(object, REISER4_NO_SD));
++ assert("nikita-2265", 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. */
-+ reiser4_inode_set_flag(object, REISER4_LOADED);
++ inode_set_flag(object, REISER4_LOADED);
+
+ result = obj_plug->create_object(object, parent, data);
+ if (result != 0) {
-+ reiser4_inode_clr_flag(object, REISER4_IMMUTABLE);
++ inode_clr_flag(object, REISER4_IMMUTABLE);
+ if (result != -ENAMETOOLONG && result != -ENOMEM)
+ warning("nikita-2219",
+ "Failed to create sd for %llu",
+ if (obj_dir != NULL)
+ result = obj_dir->init(object, parent, data);
+ if (result == 0) {
-+ assert("nikita-434", !reiser4_inode_get_flag(object,
-+ REISER4_NO_SD));
++ assert("nikita-434", !inode_get_flag(object, REISER4_NO_SD));
+ /* insert inode into VFS hash table */
+ insert_inode_hash(object);
+ /* create entry */
+ }
+
+ /* file has name now, clear immutable flag */
-+ reiser4_inode_clr_flag(object, REISER4_IMMUTABLE);
++ 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
+ int result;
+ struct inode *child;
+
-+ ctx = reiser4_init_context(parent->i_sb);
++ ctx = init_context(parent->i_sb);
+ if (IS_ERR(ctx))
+ return PTR_ERR(ctx);
+ context_set_commit_async(ctx);
+ /* update_dir(parent) */
+ res += inode_file_plugin(parent)->estimate.update(parent);
+ /* safe-link */
-+ res += estimate_one_item_removal(reiser4_tree_by_inode(object));
++ res += estimate_one_item_removal(tree_by_inode(object));
+
+ return res;
+}
+ /* fplug->unlink */
+ res += fplug->estimate.unlink(object, parent);
+ /* safe-link */
-+ res += estimate_one_insert_item(reiser4_tree_by_inode(object));
++ res += estimate_one_insert_item(tree_by_inode(object));
+
+ return res;
+}
+
-+/* helper for reiser4_unlink_common. Estimate and grab space for unlink. */
++/* helper for unlink_common. Estimate and grab space for unlink. */
+static int unlink_check_and_grab(struct inode *parent, struct dentry *victim)
+{
+ file_plugin *fplug;
+ fplug = inode_file_plugin(child);
+
+ /* check for race with create_object() */
-+ if (reiser4_inode_get_flag(child, REISER4_IMMUTABLE))
++ if (inode_get_flag(child, REISER4_IMMUTABLE))
+ return RETERR(-E_REPEAT);
+ /* object being deleted should have stat data */
-+ assert("vs-949", !reiser4_inode_get_flag(child, REISER4_NO_SD));
++ assert("vs-949", !inode_get_flag(child, REISER4_NO_SD));
+
+ /* ask object plugin */
+ if (fplug->can_rem_link != NULL && !fplug->can_rem_link(child))
+ return reiser4_grab_reserved(child->i_sb, result, BA_CAN_COMMIT);
+}
+
-+/* helper for reiser4_setattr_common */
++/* helper for setattr_common */
+static int setattr_reserve(reiser4_tree * tree)
+{
+ assert("vs-1096", is_grab_enabled(get_current_context()));
+ dir->i_ctime = dir->i_mtime = CURRENT_TIME;
+ return reiser4_update_sd(dir);
+}
-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 @@
+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 @@
+/* Copyright 2001, 2002, 2003, 2004 by Hans Reiser, licensing governed by
+ * reiser4/README */
+
+ if (result != 0)
+ return result;
+ from_item = item_plugin_by_coord(from_coord);
-+ if (plugin_of_group(item_plugin_by_coord(from_coord),
-+ DIR_ENTRY_ITEM_TYPE))
-+ {
++ if (item_type_by_coord(from_coord) == DIR_ENTRY_ITEM_TYPE) {
+ reiser4_key to_key;
+
+ build_sd_key(to_inode, &to_key);
+ return 0;
+}
+
-+int reiser4_find_entry(struct inode *, struct dentry *, lock_handle *,
++int find_entry(struct inode *, struct dentry *, lock_handle *,
+ znode_lock_mode, reiser4_dir_entry_desc *);
+int reiser4_update_dir(struct inode *);
+
+ entry. This should be re-considered when more than one different
+ directory plugin will be implemented.
+*/
-+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 */ )
++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 */ )
+{
+ /* From `The Open Group Base Specifications Issue 6'
+
+ struct inode *new_inode;
+ coord_t *new_coord;
+
-+ struct reiser4_dentry_fsdata *new_fsdata;
++ 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;
-+ struct reiser4_dentry_fsdata *dataonstack;
++ reiser4_dentry_fsdata *dataonstack;
+
-+ ctx = reiser4_init_context(old_dir->i_sb);
++ ctx = 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),
-+ reiser4_ctx_gfp_mask_get());
++ GFP_KERNEL);
+ if (old_entry == NULL) {
+ context_set_commit_async(ctx);
+ reiser4_exit_context(ctx);
+ new_lh = (lock_handle *)(old_entry + 3);
+ dotdot_lh = new_lh + 1;
+ dotdot_name = (struct dentry *)(new_lh + 2);
-+ dataonstack = (struct reiser4_dentry_fsdata *)(dotdot_name + 1);
++ dataonstack = (reiser4_dentry_fsdata *)(dotdot_name + 1);
+
+ assert("nikita-2318", old_dir != NULL);
+ assert("nikita-2319", new_dir != NULL);
+ init_lh(new_lh);
+
+ /* find entry for @new_name */
-+ result = reiser4_find_entry(new_dir, new_name, new_lh, ZNODE_WRITE_LOCK,
-+ new_entry);
++ result = find_entry(new_dir,
++ new_name, new_lh, ZNODE_WRITE_LOCK, new_entry);
+
+ if (IS_CBKERR(result)) {
+ done_lh(new_lh);
+ return result;
+ }
+
-+ reiser4_seal_done(&new_fsdata->dec.entry_seal);
++ seal_done(&new_fsdata->dec.entry_seal);
+
+ /* add or replace name for @old_inode as @new_name */
+ if (new_inode != NULL) {
+ dotdot_coord = &dataonstack->dec.entry_coord;
+ coord_clear_iplug(dotdot_coord);
+
-+ result = reiser4_find_entry(old_inode, dotdot_name,
-+ dotdot_lh, ZNODE_WRITE_LOCK,
-+ dotdot_entry);
++ result = find_entry(old_inode, dotdot_name, dotdot_lh,
++ ZNODE_WRITE_LOCK, dotdot_entry);
+ if (result == 0) {
+ /* replace_name() decreases i_nlink on
+ * @old_dir */
+}
+
+#if 0
-+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 */ )
++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 */ )
+{
+ /* From `The Open Group Base Specifications Issue 6'
+
+ reiser4_dir_entry_desc old_entry;
+ reiser4_dir_entry_desc new_entry;
+ coord_t *new_coord;
-+ struct reiser4_dentry_fsdata *new_fsdata;
++ reiser4_dentry_fsdata *new_fsdata;
+ lock_handle new_lh;
+ dir_plugin *dplug;
+ file_plugin *fplug;
+
-+ ctx = reiser4_init_context(old_dir->i_sb);
++ ctx = init_context(old_dir->i_sb);
+ if (IS_ERR(ctx))
+ return PTR_ERR(ctx);
+
+ init_lh(&new_lh);
+
+ /* find entry for @new_name */
-+ result = reiser4_find_entry(new_dir, new_name, &new_lh,
-+ ZNODE_WRITE_LOCK, &new_entry);
++ result = find_entry(new_dir,
++ new_name, &new_lh, ZNODE_WRITE_LOCK, &new_entry);
+
+ if (IS_CBKERR(result)) {
+ done_lh(&new_lh);
+ goto exit;
+ }
+
-+ reiser4_seal_done(&new_fsdata->dec.entry_seal);
++ seal_done(&new_fsdata->dec.entry_seal);
+
+ /* add or replace name for @old_inode as @new_name */
+ if (new_inode != NULL) {
+ lock_handle dotdot_lh;
+ struct dentry dotdot_name;
+ reiser4_dir_entry_desc dotdot_entry;
-+ struct reiser4_dentry_fsdata dataonstack;
-+ struct reiser4_dentry_fsdata *fsdata;
++ reiser4_dentry_fsdata dataonstack;
++ reiser4_dentry_fsdata *fsdata;
+
+ memset(&dataonstack, 0, sizeof dataonstack);
+ memset(&dotdot_entry, 0, sizeof dotdot_entry);
+ dotdot_coord = &fsdata->dec.entry_coord;
+ coord_clear_iplug(dotdot_coord);
+
-+ result = reiser4_find_entry(old_inode,
-+ &dotdot_name,
-+ &dotdot_lh,
-+ ZNODE_WRITE_LOCK,
-+ &dotdot_entry);
++ result = find_entry(old_inode, &dotdot_name, &dotdot_lh,
++ ZNODE_WRITE_LOCK, &dotdot_entry);
+ if (result == 0) {
+ /* replace_name() decreases i_nlink on
+ * @old_dir */
+ return result;
+}
+#endif
-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
+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
@@ -0,0 +1,66 @@
+/* Copyright 2001, 2002, 2003 by Hans Reiser, licensing governed by reiser4/README */
+
+ fill-column: 120
+ End:
+*/
-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
+Index: linux-2.6.16/fs/reiser4/plugin/item/blackbox.c
+===================================================================
+--- /dev/null
++++ linux-2.6.16/fs/reiser4/plugin/item/blackbox.c
@@ -0,0 +1,142 @@
+/* Copyright 2003 by Hans Reiser, licensing governed by
+ * reiser4/README */
+
+int kill_black_box(reiser4_tree * tree, const reiser4_key * key)
+{
-+ return reiser4_cut_tree(tree, key, key, NULL, 1);
++ return cut_tree(tree, key, key, NULL, 1);
+}
+
+/* Make Linus happy.
+ fill-column: 120
+ End:
+*/
-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
+Index: linux-2.6.16/fs/reiser4/plugin/item/blackbox.h
+===================================================================
+--- /dev/null
++++ linux-2.6.16/fs/reiser4/plugin/item/blackbox.h
@@ -0,0 +1,33 @@
+/* Copyright 2003 by Hans Reiser, licensing governed by
+ * reiser4/README */
+ fill-column: 120
+ End:
+*/
-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 @@
+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 @@
+/* Copyright 2001, 2002, 2003 by Hans Reiser, licensing governed by reiser4/README */
+
+/* Directory entry implementation */
+
+/* insert new @entry into item */
+static int expand(const coord_t * coord /* coord of item */ ,
-+ struct cde_entry * entry /* entry to insert */ ,
++ 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
+
+/* paste body of @entry into item */
+static int paste_entry(const coord_t * coord /* coord of item */ ,
-+ struct cde_entry * entry /* new entry */ ,
++ cde_entry * entry /* new entry */ ,
+ int pos /* position to insert */ ,
+ reiser4_dir_entry_desc * dir_entry /* parameters for
+ * new entry */ )
+int estimate_cde(const coord_t * coord /* coord of item */ ,
+ const reiser4_item_data * data /* parameters for new item */ )
+{
-+ struct cde_entry_data *e;
++ cde_entry_data *e;
+ int result;
+ int i;
+
-+ e = (struct cde_entry_data *) data->data;
++ e = (cde_entry_data *) data->data;
+
+ assert("nikita-1288", e != NULL);
+ assert("nikita-1289", e->num_of_entries >= 0);
+ assert("nikita-1342", coord != NULL);
+
+ item_key_by_coord(coord, result);
-+ 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()));
++ 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()));
+ return result;
+}
+
+ possible check of the consistency of the item that the inventor can
+ construct
+*/
-+int reiser4_check_cde(const coord_t * coord /* coord of item to check */,
-+ const char **error /* where to store error message */)
++int check_cde(const coord_t * coord /* coord of item to check */ ,
++ const char **error /* where to store error message */ )
+{
+ int i;
+ int result;
+ * inserted */ ,
+ carry_plugin_info * info UNUSED_ARG /* todo carry queue */ )
+{
-+ struct cde_entry_data *e;
++ cde_entry_data *e;
+ int result;
+ int i;
+
+ CHECKME(coord);
-+ e = (struct cde_entry_data *) data->data;
++ e = (cde_entry_data *) data->data;
+
+ result = 0;
+ for (i = 0; i < e->num_of_entries; ++i) {
+ * directory entry */ )
+{
+ reiser4_item_data data;
-+ struct cde_entry entry;
-+ struct cde_entry_data edata;
++ cde_entry entry;
++ cde_entry_data edata;
+ int result;
+
+ assert("nikita-1656", coord->node == lh->node);
+ if (result)
+ result = insert_by_coord(coord, &data, &dir_entry->key, lh, 0);
+ else
-+ result = reiser4_resize_item(coord, &data, &dir_entry->key,
-+ lh, 0);
++ result = resize_item(coord, &data, &dir_entry->key, lh, 0);
+ return result;
+}
+
+int max_name_len_cde(const struct inode *dir /* directory */ )
+{
+ return
-+ reiser4_tree_by_inode(dir)->nplug->max_item_size() -
-+ sizeof(directory_entry_format) - sizeof(cde_item_format) -
-+ sizeof(cde_unit_header) - 2;
++ tree_by_inode(dir)->nplug->max_item_size() -
++ sizeof(directory_entry_format) - sizeof(cde_item_format) -
++ sizeof(cde_unit_header) - 2;
+}
+
+/* Make Linus happy.
+ fill-column: 120
+ End:
+*/
-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
+Index: linux-2.6.16/fs/reiser4/plugin/item/cde.h
+===================================================================
+--- /dev/null
++++ linux-2.6.16/fs/reiser4/plugin/item/cde.h
@@ -0,0 +1,87 @@
+/* Copyright 2001, 2002, 2003 by Hans Reiser, licensing governed by reiser4/README */
+
+ cde_unit_header entry[0];
+} cde_item_format;
+
-+struct cde_entry {
++typedef struct cde_entry {
+ const struct inode *dir;
+ const struct inode *obj;
+ const struct qstr *name;
-+};
++} cde_entry;
+
-+struct cde_entry_data {
++typedef struct cde_entry_data {
+ int num_of_entries;
-+ struct cde_entry *entry;
-+};
++ cde_entry *entry;
++} cde_entry_data;
+
+/* plugin->item.b.* */
+reiser4_key *max_key_inside_cde(const coord_t * coord, reiser4_key * result);
+ struct carry_kill_data *, reiser4_key * smallest_removed,
+ reiser4_key * new_first);
+void print_cde(const char *prefix, coord_t * coord);
-+int reiser4_check_cde(const coord_t * coord, const char **error);
++int 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);
+ fill-column: 120
+ End:
+*/
-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 @@
+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 @@
+/* Copyright 2001, 2002, 2003 by Hans Reiser, licensing governed by reiser4/README */
+
+/* ctails (aka "clustered tails") are items for cryptcompress objects */
+ return item_body_by_coord(coord);
+}
+
-+static int cluster_shift_by_coord(const coord_t * coord)
++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));
+}
+
-+int coord_is_unprepped_ctail(const coord_t * coord)
++static int coord_is_unprepped_ctail(const coord_t * coord)
+{
+ assert("edward-1233", coord != NULL);
+ assert("edward-1234", item_id_by_coord(coord) == CTAIL_ID);
+ return 1;
+}
+
-+/* plugin->u.item.b.mergeable */
++/* plugin->u.item.b.mergeable
++ c-tails of different clusters are not 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", plugin_of_group(item_plugin_by_coord(p1),
-+ UNIX_FILE_METADATA_ITEM_TYPE));
++ assert("edward-61",
++ item_type_by_coord(p1) == UNIX_FILE_METADATA_ITEM_TYPE);
+
+ if (item_id_by_coord(p2) != CTAIL_ID) {
+ /* second item is of another type */
+}
+
+/* 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;
+
+ 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) {
-+ 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));
-+ }
++ 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);
+ }
+ }
+ return 0;
+ /* read only whole ctails */
+ assert("edward-135", nr_units_ctail(coord) <= f->length);
+
-+ assert("edward-136", reiser4_schedulable());
++ assert("edward-136", 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_shift(hint);
++ dclust_set_extension(hint);
+ mark_page_accessed(znode_page(coord->node));
+ move_flow_forward(f, nr_units_ctail(coord));
+
+ return 0;
+}
+
-+/**
-+ * 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)
++/* 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)
+{
+ 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", cryptcompress_inode_ok(inode));
-+ assert("edward-1527", PageLocked(page));
-+
-+ unlock_page(page);
++ assert("edward-672", crc_inode_ok(inode));
+
+ /* set input stream */
+ result = grab_tfm_stream(inode, &clust->tc, INPUT_STREAM);
-+ if (result) {
-+ lock_page(page);
++ if (result)
+ return result;
-+ }
-+ result = find_disk_cluster(clust, inode, 1 /* read items */, mode);
-+ lock_page(page);
++
++ result = find_cluster(clust, inode, 1 /* read */ , write);
++ assert("edward-1340", !result);
+ if (result)
+ return result;
-+ /*
-+ * at this point we have locked position in the tree
-+ */
-+ assert("edward-1528", znode_is_any_locked(clust->hint->lh.node));
++ 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)));
+
-+ 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 == TRNC_DISK_CLUSTER) {
-+ /*
-+ * this information about disk cluster will be valid
-+ * as long as we keep the position in the tree locked
-+ */
++ clust->dstat == UNPR_DISK_CLUSTER) {
+ 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;
-+ /* ..and fill this with plain text */
-+ result = reiser4_inflate_cluster(clust, inode);
++ result = 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;
+}
+
-+/*
-+ * fill one page with plain text.
-+ */
-+int do_readpage_ctail(struct inode * inode, struct cluster_handle * clust,
-+ struct page *page, znode_lock_mode mode)
++/* read one locked page */
++int do_readpage_ctail(struct inode * inode, reiser4_cluster_t * clust,
++ struct page *page)
+{
+ int ret;
+ unsigned cloff;
+ char *data;
-+ size_t to_page;
-+ struct tfm_cluster * tc = &clust->tc;
++ size_t pgcnt;
++ tfm_cluster_t *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);
-+
-+ /* this will unlock/lock the page */
-+ ret = ctail_read_disk_cluster(clust, inode, page, mode);
-+
-+ assert("edward-212", PageLocked(page));
++ unlock_page(page);
++ ret = ctail_read_disk_cluster(clust, inode, 0 /* read */ );
++ lock_page(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))
-+ /* somebody else fill it already */
++ /* races with another read/write */
+ 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:
-+ 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)
-+ */
++ 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
+ case FAKE_DISK_CLUSTER:
+ /* fill the page by zeroes */
-+ zero_user_page(page, 0, PAGE_CACHE_SIZE, KM_USER0);
++ data = kmap_atomic(page, KM_USER0);
++
++ memset(data, 0, PAGE_CACHE_SIZE);
++ flush_dcache_page(page);
++ kunmap_atomic(data, KM_USER0);
+ SetPageUptodate(page);
+ break;
+ case PREP_DISK_CLUSTER:
-+ /* fill page by transformed stream with plain text */
++ /* fill the page by transformed data */
+ assert("edward-1058", !PageUptodate(page));
+ assert("edward-120", tc->len <= inode_cluster_size(inode));
+
-+ /* page index in this logical cluster */
++ /* start page offset in the cluster */
+ cloff = pg_to_off_to_cloff(page->index, inode);
+
+ data = kmap(page);
-+ memcpy(data, tfm_stream_data(tc, OUTPUT_STREAM) + cloff, to_page);
-+ memset(data + to_page, 0, (size_t) PAGE_CACHE_SIZE - to_page);
++ memcpy(data, tfm_stream_data(tc, OUTPUT_STREAM) + cloff, pgcnt);
++ memset(data + pgcnt, 0, (size_t) PAGE_CACHE_SIZE - pgcnt);
+ flush_dcache_page(page);
+ kunmap(page);
+ SetPageUptodate(page);
+int readpage_ctail(void *vp, struct page *page)
+{
+ int result;
-+ hint_t * hint;
-+ struct cluster_handle * clust = vp;
++ hint_t *hint;
++ reiser4_cluster_t *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), reiser4_ctx_gfp_mask_get());
-+ if (hint == NULL) {
-+ unlock_page(page);
++ hint = kmalloc(sizeof(*hint), GFP_KERNEL);
++ if (hint == NULL)
+ 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);
+ return result;
+}
+
-+/* Helper function for ->readpages() */
-+static int ctail_read_page_cluster(struct cluster_handle * clust,
-+ struct inode *inode)
++/* This unconditionally reads a disk cluster.
++ Helper function for ->readpages() */
++static int
++ctail_read_page_cluster(reiser4_cluster_t * clust, struct inode *inode)
+{
+ int i;
+ int result;
+ assert("edward-1059", clust->win == NULL);
+ assert("edward-780", inode != NULL);
+
-+ result = prepare_page_cluster(inode, clust, READ_OP);
++ result = prepare_page_cluster(inode, clust, 0 /* do not capture */ );
+ if (result)
+ return result;
-+
-+ assert("edward-781", !tfm_cluster_is_uptodate(&clust->tc));
++ 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));
+
+ 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);
++ result = do_readpage_ctail(inode, clust, page);
+ unlock_page(page);
+ if (result)
+ break;
+ }
+ tfm_cluster_clr_uptodate(&clust->tc);
-+ put_page_cluster(clust, inode, READ_OP);
++ out:
++ release_cluster_pages(clust);
+ return result;
+}
+
-+/* 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;
++#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))
+
-+ assert("edward-1525", page->mapping == inode->i_mapping);
-+
-+ 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;
-+}
++#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
+
-+/*
-+ * 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)
++/* 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)
+{
+ int ret = 0;
+ hint_t *hint;
-+ struct cluster_handle clust;
++ reiser4_cluster_t clust;
++ struct page *page;
++ struct pagevec lru_pvec;
+ struct inode *inode = mapping->host;
++ int progress = 0;
+
-+ assert("edward-1521", inode == file->f_dentry->d_inode);
-+
++ 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);
+ cluster_init_read(&clust, NULL);
-+ clust.file = file;
-+ hint = kmalloc(sizeof(*hint), reiser4_ctx_gfp_mask_get());
++ clust.file = vp;
++ hint = kmalloc(sizeof(*hint), GFP_KERNEL);
+ 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) {
-+ warning("edward-1522", "failed to load hint");
++ if (ret)
+ goto exit2;
-+ }
-+ assert("vs-26", hint->ext_coord.lh == &hint->lh);
+ ret = alloc_cluster_pgset(&clust, cluster_nrpages(inode));
-+ if (ret) {
-+ warning("edward-1523", "failed to alloc pgset");
++ if (ret)
+ goto exit3;
-+ }
-+ ret = read_cache_pages(mapping, pages, ctail_readpages_filler, &clust);
++ 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);
++ }
+ assert("edward-870", !tfm_cluster_is_uptodate(&clust.tc));
+ exit3:
+ done_lh(&hint->lh);
-+ save_file_hint(file, hint);
++ save_file_hint(clust.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);
-+ return ret;
++ pagevec_lru_add(&lru_pvec);
++ return;
+}
+
+/*
+ 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(struct cluster_handle * clust,
-+ struct inode *inode)
++static int
++insert_unprepped_ctail(reiser4_cluster_t * clust, struct inode *inode)
+{
+ int result;
+ char buf[UCTAIL_NR_UNITS];
+}
+
+static int
-+insert_cryptcompress_flow(coord_t * coord, lock_handle * lh, flow_t * f,
-+ struct inode *inode)
++insert_crc_flow(coord_t * coord, lock_handle * lh, flow_t * f,
++ struct inode *inode)
+{
+ int result;
+ carry_pool *pool;
+ coord->unit_pos = 0;
+ coord->between = AFTER_ITEM;
+ }
-+ op = reiser4_post_carry(lowest_level, COP_INSERT_FLOW, coord->node,
-+ 0 /* operate directly on coord -> node */);
++ op = 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);
+ lowest_level->track_type = CARRY_TRACK_CHANGE;
+ lowest_level->tracked = lh;
+
-+ result = reiser4_carry(lowest_level, NULL);
++ result = carry(lowest_level, NULL);
+ done_carry_pool(pool);
+
+ return result;
+}
+
+/* Implementation of CRC_APPEND_ITEM mode of ctail conversion */
-+static int insert_cryptcompress_flow_in_place(coord_t * coord,
-+ lock_handle * lh, flow_t * f,
-+ struct inode *inode)
++static int
++insert_crc_flow_in_place(coord_t * coord, lock_handle * lh, flow_t * f,
++ struct inode *inode)
+{
+ int ret;
+ coord_t pos;
+ init_lh(&lock);
+ copy_lh(&lock, lh);
+
-+ ret = insert_cryptcompress_flow(&pos, &lock, f, inode);
++ ret = insert_crc_flow(&pos, &lock, f, inode);
+ done_lh(&lock);
+ assert("edward-1347", znode_is_write_locked(lh->node));
+ assert("edward-1228", !ret);
+ 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", reiser4_schedulable());
++ assert("edward-275", schedulable());
+ assert("edward-467", item_id_by_coord(coord) == CTAIL_ID);
+ assert("edward-1243", ctail_ok(coord));
+
+ return cut_node_content(coord, &stop, NULL, NULL, NULL);
+}
+
-+int ctail_insert_unprepped_cluster(struct cluster_handle * clust,
-+ struct inode * inode)
++int
++ctail_insert_unprepped_cluster(reiser4_cluster_t * 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))
+ all_grabbed2free();
+
+ assert("edward-1251", !result);
-+ assert("edward-1252", cryptcompress_inode_ok(inode));
++ assert("edward-1252", crc_inode_ok(inode));
+ assert("edward-1253", znode_is_write_locked(clust->hint->lh.node));
+ assert("edward-1254",
+ reiser4_clustered_blocks(reiser4_get_current_sb()));
+ return result;
+}
+
-+static int do_convert_ctail(flush_pos_t * pos, cryptcompress_write_mode_t mode)
++static int do_convert_ctail(flush_pos_t * pos, crc_write_mode_t mode)
+{
+ int result = 0;
-+ struct convert_item_info * info;
++ convert_item_info_t *info;
+
+ assert("edward-468", pos != NULL);
+ assert("edward-469", pos->sq != NULL);
+ assert("edward-1256",
+ cluster_shift_ok(cluster_shift_by_coord(&pos->coord)));
+ result =
-+ insert_cryptcompress_flow_in_place(&pos->coord,
-+ &pos->lock,
-+ &info->flow,
-+ info->inode);
++ insert_crc_flow_in_place(&pos->coord, &pos->lock,
++ &info->flow, info->inode);
+ break;
+ case CRC_OVERWRITE_ITEM:
+ assert("edward-1230", info->flow.length != 0);
+ page = jnode_page(node);
+ inode = page->mapping->host;
+
-+ if (!reiser4_scanning_left(scan))
++ if (!scanning_left(scan))
+ return result;
+ if (!ZF_ISSET(scan->parent_lock.node, JNODE_DIRTY))
+ znode_make_dirty(scan->parent_lock.node);
+
+/* plugin->init_convert_data() */
+static int
-+init_convert_data_ctail(struct convert_item_info * idata, struct inode *inode)
++init_convert_data_ctail(convert_item_info_t * idata, struct inode *inode)
+{
+ assert("edward-813", idata != NULL);
+ assert("edward-814", inode != NULL);
+ return 0;
+}
+
-+static int alloc_item_convert_data(struct convert_info * sq)
++static int alloc_item_convert_data(convert_info_t * sq)
+{
+ assert("edward-816", sq != NULL);
+ assert("edward-817", sq->itm == NULL);
+
-+ sq->itm = kmalloc(sizeof(*sq->itm), reiser4_ctx_gfp_mask_get());
++ sq->itm = kmalloc(sizeof(*sq->itm), GFP_KERNEL);
+ if (sq->itm == NULL)
+ return RETERR(-ENOMEM);
+ return 0;
+}
+
-+static void free_item_convert_data(struct convert_info * sq)
++static void free_item_convert_data(convert_info_t * sq)
+{
+ assert("edward-818", sq != NULL);
+ assert("edward-819", sq->itm != NULL);
+ assert("edward-821", pos != NULL);
+ assert("edward-822", pos->sq == NULL);
+
-+ pos->sq = kmalloc(sizeof(*pos->sq), reiser4_ctx_gfp_mask_get());
++ pos->sq = kmalloc(sizeof(*pos->sq), GFP_KERNEL);
+ if (!pos->sq)
+ return RETERR(-ENOMEM);
+ memset(pos->sq, 0, sizeof(*pos->sq));
-+ cluster_init_write(&pos->sq->clust, NULL);
++ cluster_init_write(&pos->sq->clust, 0);
+ return 0;
+}
+
+void free_convert_data(flush_pos_t * pos)
+{
-+ struct convert_info *sq;
++ convert_info_t *sq;
+
+ assert("edward-823", pos != NULL);
+ assert("edward-824", pos->sq != NULL);
+
+static int init_item_convert_data(flush_pos_t * pos, struct inode *inode)
+{
-+ struct convert_info *sq;
++ convert_info_t *sq;
+
+ assert("edward-825", pos != NULL);
+ assert("edward-826", pos->sq != NULL);
+static int attach_convert_idata(flush_pos_t * pos, struct inode *inode)
+{
+ int ret = 0;
-+ struct convert_item_info *info;
-+ struct cluster_handle *clust;
++ convert_item_info_t *info;
++ reiser4_cluster_t *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", cryptcompress_inode_ok(inode));
-+ assert("edward-252",
-+ fplug == file_plugin_by_id(CRYPTCOMPRESS_FILE_PLUGIN_ID));
++ assert("edward-682", crc_inode_ok(inode));
++ assert("edward-252", fplug == file_plugin_by_id(CRC_FILE_PLUGIN_ID));
+ assert("edward-473",
+ item_plugin_by_coord(&pos->coord) ==
+ item_plugin_by_id(CTAIL_ID));
+ goto err;
+ info = item_convert_data(pos);
+
-+ ret = checkout_logical_cluster(clust, pos->child, inode);
++ ret = flush_cluster_pages(clust, pos->child, inode);
+ if (ret)
+ goto err;
+
-+ reiser4_deflate_cluster(clust, inode);
++ deflate_cluster(clust, inode);
+ inc_item_convert_count(pos);
+
-+ /* prepare flow for insertion */
++ /* make flow by transformed stream */
+ fplug->flow_by_inode(info->inode,
+ (const char __user *)tfm_stream_data(&clust->tc, OUTPUT_STREAM),
+ 0 /* kernel space */ ,
+ WRITE_OP, &info->flow);
+ jput(pos->child);
+
-+ assert("edward-683", cryptcompress_inode_ok(inode));
++ assert("edward-683", crc_inode_ok(inode));
+ return 0;
+ err:
+ jput(pos->child);
+}
+
+/* clear up disk cluster info */
-+static void detach_convert_idata(struct convert_info * sq)
++static void detach_convert_idata(convert_info_t * sq)
+{
-+ struct convert_item_info *info;
++ convert_item_info_t *info;
+
+ assert("edward-253", sq != NULL);
+ assert("edward-840", sq->itm != NULL);
+ 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;
+ if (pos->coord.item_pos < coord_num_items(&pos->coord) - 1)
+ return ret;
+
-+ /* 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.
-+ */
++ /* check next slum item */
+ init_lh(&right_lock);
+ cur = pos->coord.node;
+
+ znode_make_dirty(lh.node);
+ znode_set_convertible(lh.node);
+ stop = 0;
-+ } else if (same_disk_cluster(&pos->coord, &coord)) {
++ } else if (clustered_ctail(&pos->coord, &coord)) {
+
+ item_convert_data(pos)->d_next = DC_CHAINED_ITEM;
+
+}
+
+static int
-+assign_convert_mode(struct convert_item_info * idata,
-+ cryptcompress_write_mode_t * mode)
++assign_convert_mode(convert_item_info_t * idata, crc_write_mode_t * mode)
+{
+ int result = 0;
+
+{
+ int result;
+ int nr_items;
-+ cryptcompress_write_mode_t mode = CRC_OVERWRITE_ITEM;
++ crc_write_mode_t mode = CRC_OVERWRITE_ITEM;
+
+ assert("edward-1020", pos != NULL);
+ assert("edward-1213", coord_num_items(&pos->coord) != 0);
+ } else {
+ /* use old convert info */
+
-+ struct convert_item_info *idata;
++ convert_item_info_t *idata;
+
+ idata = item_convert_data(pos);
+
+ 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);
+ fill-column: 120
+ End:
+*/
-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 @@
+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 @@
+/* Copyright 2001, 2002, 2003 by Hans Reiser, licensing governed by reiser4/README */
+
-+/* Ctail items are fragments (or bodies) of special tipe to provide
-+ optimal storage of encrypted and(or) compressed files. */
-+
-+
+#if !defined( __FS_REISER4_CTAIL_H__ )
+#define __FS_REISER4_CTAIL_H__
+
-+/* Disk format of ctail item */
++/* cryptcompress object item. See ctail.c for description. */
++
++#define UCTAIL_NR_UNITS 1
++#define UCTAIL_SHIFT 0xff
++
+typedef struct ctail_item_format {
-+ /* packed shift;
-+ if its value is different from UCTAIL_SHIFT (see below), then
-+ size of disk cluster is calculated as (1 << cluster_shift) */
++ /* 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] */
+ DC_AFTER_CLUSTER = 3
+} dc_item_stat;
+
-+/* 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 */
-+};
++typedef struct {
++ int shift; /* we keep here a cpu value of cluster_shift field
++ of ctail_item_format (see above) */
++} ctail_coord_extension_t;
+
+struct cut_list;
+
+/* plugin->u.item.s.* */
+int read_ctail(struct file *, flow_t *, hint_t *);
+int readpage_ctail(void *, struct page *);
-+int readpages_ctail(struct file *, struct address_space *, struct list_head *);
++void readpages_ctail(void *, 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,
+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__ */
+
+ fill-column: 120
+ End:
+*/
-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
+Index: linux-2.6.16/fs/reiser4/plugin/item/extent.c
+===================================================================
+--- /dev/null
++++ linux-2.6.16/fs/reiser4/plugin/item/extent.c
@@ -0,0 +1,197 @@
+/* Copyright 2001, 2002, 2003 by Hans Reiser, licensing governed by reiser4/README */
+
+}
+
+/* how many bytes are addressed by @nr first extents of the extent item */
-+reiser4_block_nr reiser4_extent_size(const coord_t * coord, pos_in_node_t nr)
++reiser4_block_nr extent_size(const coord_t * coord, pos_in_node_t nr)
+{
+ pos_in_node_t i;
+ reiser4_block_nr blocks;
+}
+
+/* set extent's start and width */
-+void reiser4_set_extent(reiser4_extent * ext, reiser4_block_nr start,
-+ reiser4_block_nr width)
++void
++set_extent(reiser4_extent * ext, reiser4_block_nr start, reiser4_block_nr width)
+{
+ extent_set_start(ext, start);
+ extent_set_width(ext, width);
+}
+
++
+/**
-+ * reiser4_replace_extent - replace extent and paste 1 or 2 after it
++ * 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
+ * first of newly inserted units, if it is 0 - @un_extent and @lh are returned
+ * set to extent which was overwritten.
+ */
-+int reiser4_replace_extent(struct replace_handle *h,
-+ int return_inserted_position)
++int replace_extent(struct replace_handle *h, int return_inserted_position)
+{
+ int result;
+ znode *orig_znode;
+ coord_dup(&h->coord_after, h->coord);
+ init_lh(&h->lh_after);
+ copy_lh(&h->lh_after, h->lh);
-+ reiser4_tap_init(&h->watch, &h->coord_after, &h->lh_after, ZNODE_WRITE_LOCK);
-+ reiser4_tap_monitor(&h->watch);
++ tap_init(&h->watch, &h->coord_after, &h->lh_after, ZNODE_WRITE_LOCK);
++ tap_monitor(&h->watch);
+
+ ON_DEBUG(h->orig_ext = *extent_by_coord(h->coord));
+ orig_znode = h->coord->node;
+ }
+ }
+ }
-+ reiser4_tap_done(&h->watch);
++ tap_done(&h->watch);
+
+ return result;
+}
+ * scroll-step: 1
+ * End:
+ */
-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 @@
+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 @@
+/* COPYRIGHT 2001, 2002, 2003 by Hans Reiser, licensing governed by reiser4/README */
+
+#include "item.h"
+
+#include <linux/quotaops.h>
+#include <linux/swap.h>
++#include "../../../../mm/filemap.h"
++
+
+static inline reiser4_extent *ext_by_offset(const znode *node, int offset)
+{
+{
+#if REISER4_DEBUG
+ const coord_t *coord;
-+ const struct extent_coord_extension *ext_coord;
++ const extent_coord_extension_t *ext_coord;
+ reiser4_extent *ext;
+
+ coord = &uf_coord->coord;
+ 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) +
+#endif
+
+/**
-+ * can_append -
++ * can_append -
+ * @key:
+ * @coord:
+ *
+ append_key_extent(coord, &append_key);
+
+ assert("", keyle(&append_key, key));
-+
++
+ /*
+ * extent item has to be appended with hole. Calculate length of that
+ * hole
+ * @hole_width blocks. Note that we do not worry about
+ * overflowing - extent width is 64 bits
+ */
-+ reiser4_set_extent(ext, HOLE_EXTENT_START,
-+ extent_get_width(ext) + hole_width);
++ set_extent(ext, HOLE_EXTENT_START,
++ extent_get_width(ext) + hole_width);
+ znode_make_dirty(coord->node);
+ return 0;
+ }
+ assert("vs-713", (state_of_extent(ext) == ALLOCATED_EXTENT ||
+ state_of_extent(ext) == UNALLOCATED_EXTENT));
+
-+ reiser4_set_extent(&new_ext, HOLE_EXTENT_START, hole_width);
++ 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);
+}
+/**
+ * check_jnodes
+ * @twig: longterm locked twig node
-+ * @key:
++ * @key:
+ *
+ */
+static void check_jnodes(znode *twig, const reiser4_key *key, int count)
+ reiser4_extent new_ext;
+ reiser4_item_data idata;
+ coord_t *coord;
-+ struct extent_coord_extension *ext_coord;
++ extent_coord_extension_t *ext_coord;
+ reiser4_extent *ext;
+ reiser4_block_nr block;
+ jnode *node;
+ * last extent unit of the file is unallocated one. Increase
+ * its width by @count
+ */
-+ reiser4_set_extent(ext, UNALLOCATED_EXTENT_START,
-+ extent_get_width(ext) + count);
++ set_extent(ext, UNALLOCATED_EXTENT_START,
++ extent_get_width(ext) + count);
+ znode_make_dirty(coord->node);
+
+ /* update coord extension */
+ * last extent unit of the file is either hole or allocated
+ * one. Append one unallocated extent of width @count
+ */
-+ reiser4_set_extent(&new_ext, UNALLOCATED_EXTENT_START, count);
++ 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;
+ spin_lock_jnode(node);
+ JF_SET(node, JNODE_CREATED);
+ jnode_set_block(node, &block);
-+ result = reiser4_try_capture(node, ZNODE_WRITE_LOCK, 0);
++ result = 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;
+}
+
+ 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 */
-+ reiser4_set_extent(&new_ext, HOLE_EXTENT_START, hole_width);
++ 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);
+}
+ reiser4_extent new_ext;
+ reiser4_item_data idata;
+ reiser4_block_nr block;
-+ struct unix_file_info *uf_info;
++ unix_file_info_t *uf_info;
+ jnode *node;
+
+ /* first extent insertion starts at leaf level */
+ * file or performing tail conversion
+ */
+ assert("", (uf_info->container == UF_CONTAINER_EMPTY ||
-+ (reiser4_inode_get_flag(inode,
-+ REISER4_PART_MIXED) &&
-+ reiser4_inode_get_flag(inode,
-+ REISER4_PART_IN_CONV))));
++ (inode_get_flag(inode, REISER4_PART_MIXED) &&
++ 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;
+ * prepare for tree modification: compose body of item and item data
+ * structure needed for insertion
+ */
-+ reiser4_set_extent(&new_ext, UNALLOCATED_EXTENT_START, count);
++ set_extent(&new_ext, UNALLOCATED_EXTENT_START, count);
+ init_new_extent(&idata, &new_ext, 1);
+
+ /* insert extent item into the tree */
+ spin_lock_jnode(node);
+ JF_SET(node, JNODE_CREATED);
+ jnode_set_block(node, &block);
-+ result = reiser4_try_capture(node, ZNODE_WRITE_LOCK, 0);
++ result = try_capture(node, ZNODE_WRITE_LOCK, 0);
+ BUG_ON(result != 0);
+ jnode_make_dirty_locked(node);
-+ spin_unlock_jnode(node);
++ spin_unlock_jnode(node);
+ }
+
+ /*
+ reiser4_extent *ext;
+ reiser4_block_nr width, pos_in_unit;
+ coord_t *coord;
-+ struct extent_coord_extension *ext_coord;
++ extent_coord_extension_t *ext_coord;
+ int return_inserted_position;
+
+ check_uf_coord(uf_coord, key);
+
+ *how = 0;
+ if (width == 1) {
-+ reiser4_set_extent(ext, UNALLOCATED_EXTENT_START, 1);
++ set_extent(ext, UNALLOCATED_EXTENT_START, 1);
+ znode_make_dirty(coord->node);
+ /* update uf_coord */
+ ON_DEBUG(ext_coord->extent = *ext);
+ }
+ }
+ /* extent for replace */
-+ reiser4_set_extent(&rh.overwrite, UNALLOCATED_EXTENT_START, 1);
++ set_extent(&rh.overwrite, UNALLOCATED_EXTENT_START, 1);
+ /* extent to be inserted */
-+ reiser4_set_extent(&rh.new_extents[0], HOLE_EXTENT_START,
-+ width - 1);
++ set_extent(&rh.new_extents[0], HOLE_EXTENT_START, width - 1);
+ rh.nr_new_extents = 1;
+
-+ /* have reiser4_replace_extent to return with @coord and
-+ @uf_coord->lh set to unit which was replaced */
++ /* have 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) {
+ }
+ }
+ /* extent for replace */
-+ reiser4_set_extent(&rh.overwrite, HOLE_EXTENT_START, width - 1);
++ set_extent(&rh.overwrite, HOLE_EXTENT_START, width - 1);
+ /* extent to be inserted */
-+ reiser4_set_extent(&rh.new_extents[0], UNALLOCATED_EXTENT_START,
-+ 1);
++ set_extent(&rh.new_extents[0], UNALLOCATED_EXTENT_START, 1);
+ rh.nr_new_extents = 1;
+
-+ /* have reiser4_replace_extent to return with @coord and
-+ @uf_coord->lh set to unit which was inserted */
++ /* have 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 */
-+ reiser4_set_extent(&rh.overwrite, HOLE_EXTENT_START,
-+ pos_in_unit);
++ set_extent(&rh.overwrite, HOLE_EXTENT_START, pos_in_unit);
+ /* extents to be inserted */
-+ 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);
++ set_extent(&rh.new_extents[0], UNALLOCATED_EXTENT_START, 1);
++ set_extent(&rh.new_extents[1], HOLE_EXTENT_START,
++ width - pos_in_unit - 1);
+ rh.nr_new_extents = 2;
+
-+ /* have reiser4_replace_extent to return with @coord and
-+ @uf_coord->lh set to first of units which were inserted */
++ /* have replace_extent to return with @coord and @uf_coord->lh
++ set to first of units which were inserted */
+ return_inserted_position = 1;
+ *how = 6;
+ }
+ extent_get_width(&rh.overwrite) * current_blocksize);
+
+ uf_coord->valid = 0;
-+ return reiser4_replace_extent(&rh, return_inserted_position);
++ return replace_extent(&rh, return_inserted_position);
+}
+
+/**
+ jnode *node, int *hole_plugged)
+{
+ int result;
-+ struct extent_coord_extension *ext_coord;
++ extent_coord_extension_t *ext_coord;
+ reiser4_extent *ext;
+ reiser4_block_nr block;
+ int how;
+ */
+static int move_coord(uf_coord_t *uf_coord)
+{
-+ struct extent_coord_extension *ext_coord;
++ extent_coord_extension_t *ext_coord;
+
+ if (uf_coord->valid == 0)
+ return 1;
+}
+
+/**
-+ * overwrite_extent -
++ * overwrite_extent -
+ * @inode:
+ *
+ * Returns number of handled jnodes.
+ * them dirty
+ */
+ spin_lock_jnode(node);
-+ result = reiser4_try_capture(node, ZNODE_WRITE_LOCK, 0);
++ result = try_capture(node, ZNODE_WRITE_LOCK, 0);
+ BUG_ON(result != 0);
+ jnode_make_dirty_locked(node);
+ spin_unlock_jnode(node);
+ return count;
+}
+
++void init_uf_coord(uf_coord_t *uf_coord, lock_handle *lh);
++
+/**
-+ * reiser4_update_extent
++ * update_extent
+ * @file:
+ * @jnodes:
+ * @count:
+ * @off:
-+ *
++ *
+ */
-+int reiser4_update_extent(struct inode *inode, jnode *node, loff_t pos,
++int update_extent(struct inode *inode, jnode *node, loff_t pos,
+ int *plugged_hole)
+{
+ int result;
+ lock_handle lh;
+ reiser4_key key;
+
-+ assert("", reiser4_lock_counters()->d_refs == 0);
++ assert("", lock_counters()->d_refs == 0);
+
+ key_by_inode_and_offset_common(inode, pos, &key);
+
+ result = find_file_item_nohint(coord, &lh, &key,
+ ZNODE_WRITE_LOCK, inode);
+ if (IS_CBKERR(result)) {
-+ assert("", reiser4_lock_counters()->d_refs == 0);
++ assert("", lock_counters()->d_refs == 0);
+ return result;
+ }
-+
++
+ result = zload(coord->node);
+ BUG_ON(result != 0);
+ loaded = coord->node;
+ assert("", result == 1 || result < 0);
+ zrelse(loaded);
+ done_lh(&lh);
-+ assert("", reiser4_lock_counters()->d_refs == 0);
++ assert("", lock_counters()->d_refs == 0);
+ return (result == 1) ? 0 : result;
+}
+
+ * @jnodes:
+ * @count:
+ * @off:
-+ *
++ *
+ */
+static int update_extents(struct file *file, jnode **jnodes, int count, loff_t pos)
+{
+ 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)
+ /*
+ pos = (loff_t)index_jnode(jnodes[0]) << PAGE_CACHE_SHIFT;
+ key_by_inode_and_offset_common(inode, pos, &key);
+
-+ assert("", reiser4_lock_counters()->d_refs == 0);
-+
++ assert("", lock_counters()->d_refs == 0);
++
+ do {
+ result = find_file_item(&hint, &key, ZNODE_WRITE_LOCK, inode);
+ if (IS_CBKERR(result)) {
-+ assert("", reiser4_lock_counters()->d_refs == 0);
++ assert("", lock_counters()->d_refs == 0);
+ return result;
+ }
+
+
+ /* seal and unlock znode */
+ if (hint.ext_coord.valid)
-+ reiser4_set_hint(&hint, &key, ZNODE_WRITE_LOCK);
++ set_hint(&hint, &key, ZNODE_WRITE_LOCK);
+ else
-+ reiser4_unset_hint(&hint);
++ unset_hint(&hint);
+
+ } while (count > 0);
+
+ save_file_hint(file, &hint);
-+ assert("", reiser4_lock_counters()->d_refs == 0);
++ assert("", lock_counters()->d_refs == 0);
+ return result;
+}
+
+
+ /*
+ * 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
+
+ * 3. stat data update
+ */
-+ tree = reiser4_tree_by_inode(inode);
++ tree = tree_by_inode(inode);
+ count = estimate_one_insert_item(tree) +
+ WRITE_GRANULARITY * (1 + estimate_one_insert_into_item(tree)) +
+ estimate_one_insert_item(tree);
+ 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;
-+}
-+
+/**
-+ * reiser4_write_extent - write method of extent item plugin
++ * write_extent - write method of extent item plugin
+ * @file: file to write to
+ * @buf: address of user-space buffer
-+ * @count: number of bytes to write
-+ * @pos: position in file to write to
++ * @write_amount: number of bytes to write
++ * @off: position in file to write to
+ *
+ */
-+ssize_t reiser4_write_extent(struct file *file, const char __user *buf,
-+ size_t count, loff_t *pos)
++ssize_t write_extent(struct file *file, const char __user *buf, size_t count,
++ loff_t *pos)
+{
+ int have_to_update_extent;
-+ int nr_pages, nr_dirty;
++ int nr_pages;
+ struct page *page;
+ jnode *jnodes[WRITE_GRANULARITY + 1];
+ struct inode *inode;
+ int i;
+ int to_page, page_off;
+ size_t left, written;
-+ int result = 0;
++ int result;
+
+ inode = file->f_dentry->d_inode;
+ if (write_extent_reserve_space(inode))
+
+ 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,
-+ reiser4_ctx_gfp_mask_get());
++ page = find_or_create_page(inode->i_mapping, index + i, get_gfp_mask());
+ if (page == NULL) {
-+ nr_pages = i;
-+ result = RETERR(-ENOMEM);
-+ goto out;
++ while(i --) {
++ unlock_page(jnode_page(jnodes[i]));
++ page_cache_release(jnode_page(jnodes[i]));
++ }
++ return RETERR(-ENOMEM);
+ }
+
+ jnodes[i] = jnode_of_page(page);
+ if (IS_ERR(jnodes[i])) {
+ unlock_page(page);
+ page_cache_release(page);
-+ nr_pages = i;
-+ result = RETERR(-ENOMEM);
-+ goto out;
++ while (i --) {
++ jput(jnodes[i]);
++ page_cache_release(jnode_page(jnodes[i]));
++ }
++ return RETERR(-ENOMEM);
+ }
+ /* prevent jnode and page from disconnecting */
+ JF_SET(jnodes[i], JNODE_WRITE_PREPARED);
+
+ 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 (page_offset(page) < inode->i_size &&
++ if (((loff_t)page->index << PAGE_CACHE_SHIFT) < inode->i_size &&
+ !PageUptodate(page) && to_page != PAGE_CACHE_SIZE) {
+ /*
+ * the above is not optimal for partial write to last
+ /* 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);
+ BUG_ON(get_current_context()->trans->atom != NULL);
+
+ lock_page(page);
-+ if (!PageUptodate(page) && to_page != PAGE_CACHE_SIZE)
-+ simple_prepare_write(file, page, page_off,
-+ page_off + to_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);
++ }
+
+ written = filemap_copy_from_user(page, page_off, buf, to_page);
-+ if (unlikely(written != to_page)) {
++ if (written != to_page) {
+ unlock_page(page);
++ page_cache_release(page);
++ nr_pages = i;
++ jput(jnodes[i]);
+ result = RETERR(-EFAULT);
+ break;
+ }
-+
+ flush_dcache_page(page);
-+ reiser4_set_page_dirty_internal(page);
++ 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 ++;
+ left -= to_page;
+ BUG_ON(get_current_context()->trans->atom != NULL);
+ }
-+
++
+ if (have_to_update_extent) {
-+ update_extents(file, jnodes, nr_dirty, *pos);
++ update_extents(file, jnodes, nr_pages, *pos);
+ } else {
-+ for (i = 0; i < nr_dirty; i ++) {
-+ int ret;
++ for (i = 0; i < nr_pages; i ++) {
+ spin_lock_jnode(jnodes[i]);
-+ ret = reiser4_try_capture(jnodes[i],
-+ ZNODE_WRITE_LOCK, 0);
-+ BUG_ON(ret != 0);
++ result = try_capture(jnodes[i], ZNODE_WRITE_LOCK, 0);
++ BUG_ON(result != 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 errors handled so far is ENOMEM and
-+ EFAULT on copy_from_user */
++ /* the only error handled so far is EFAULT on copy_from_user */
++ return (count - left) ? (count - left) : -EFAULT;
++}
+
-+ return (count - left) ? (count - left) : result;
++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);
+}
+
-+int reiser4_do_readpage_extent(reiser4_extent * ext, reiser4_block_nr pos,
-+ struct page *page)
++static int
++do_readpage_extent(reiser4_extent * ext, reiser4_block_nr pos,
++ struct page *page)
+{
+ jnode *j;
+ struct address_space *mapping;
+ */
+ j = jfind(mapping, index);
+ if (j == NULL) {
-+ zero_user_page(page, 0, PAGE_CACHE_SIZE, KM_USER0);
-+ SetPageUptodate(page);
-+ unlock_page(page);
++ zero_page(page);
+ return 0;
+ }
+ spin_lock_jnode(j);
+ block = *jnode_get_io_block(j);
+ spin_unlock_jnode(j);
+ if (block == 0) {
-+ zero_user_page(page, 0, PAGE_CACHE_SIZE, KM_USER0);
-+ SetPageUptodate(page);
-+ unlock_page(page);
++ zero_page(page);
+ jput(j);
+ return 0;
+ }
+ }
+
+ BUG_ON(j == 0);
-+ reiser4_page_io(page, j, READ, reiser4_ctx_gfp_mask_get());
++ page_io(page, j, READ, get_gfp_mask());
+ 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 reiser4_read_extent(struct file *file, flow_t *flow, hint_t *hint)
++int read_extent(struct file *file, flow_t *flow, hint_t *hint)
+{
+ int result;
+ struct page *page;
+ loff_t file_off;
+ uf_coord_t *uf_coord;
+ coord_t *coord;
-+ struct extent_coord_extension *ext_coord;
-+ unsigned long nr_pages;
++ extent_coord_extension_t *ext_coord;
++ unsigned long nr_pages, prev_page;
++ struct file_ra_state ra;
+ char *kaddr;
+
+ assert("vs-1353", current_blocksize == PAGE_CACHE_SIZE);
+ 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);
+
+ /* 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. */
-+ reiser4_set_hint(hint, &flow->key, ZNODE_READ_LOCK);
++ set_hint(hint, &flow->key, ZNODE_READ_LOCK);
+ /* &hint->lh is done-ed */
+
++ ra = file->f_ra;
++ prev_page = ra.prev_page;
+ do {
-+ 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)) {
++ 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);
++ }
+ unlock_page(page);
-+ page_cache_release(page);
-+ warning("jmacd-97178", "extent_read: page is not up to date");
-+ return RETERR(-EIO);
++ } 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;
+ }
-+ 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
+ if (mapping_writably_mapped(mapping))
+ flush_dcache_page(page);
+
-+ assert("nikita-3034", reiser4_schedulable());
++ assert("nikita-3034", schedulable());
+
+ /* number of bytes which are to be read from the page */
+ if (count > flow->length)
+ 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
+ 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 reiser4_readpage_extent(void *vp, struct page *page)
++int readpage_extent(void *vp, struct page *page)
+{
+ uf_coord_t *uf_coord = vp;
+ ON_DEBUG(coord_t * coord = &uf_coord->coord);
+ get_key_objectid(item_key_by_coord(coord, &key)));
+ check_uf_coord(uf_coord, NULL);
+
-+ return reiser4_do_readpage_extent(
-+ ext_by_ext_coord(uf_coord),
-+ uf_coord->extension.extent.pos_in_unit, page);
++ return do_readpage_extent(ext_by_ext_coord(uf_coord),
++ uf_coord->extension.extent.pos_in_unit, page);
+}
+
+/**
+{
+ item_key_by_coord(coord, key);
+ set_key_offset(key,
-+ get_key_offset(key) + reiser4_extent_size(coord,
-+ nr_units_extent
-+ (coord)));
++ get_key_offset(key) + extent_size(coord,
++ nr_units_extent
++ (coord)));
+
+ assert("vs-610", get_key_offset(key)
+ && (get_key_offset(key) & (current_blocksize - 1)) == 0);
+void init_coord_extension_extent(uf_coord_t * uf_coord, loff_t lookuped)
+{
+ coord_t *coord;
-+ struct extent_coord_extension *ext_coord;
++ extent_coord_extension_t *ext_coord;
+ reiser4_key key;
+ loff_t offset;
+
+ * scroll-step: 1
+ * End:
+ */
-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 @@
+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 @@
+/* Copyright 2001, 2002, 2003 by Hans Reiser, licensing governed by reiser4/README */
+
+#include "item.h"
+ 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 reiser4_scan_extent, handles these terminating conditions,
-+ e.g., by loading the next twig.
++ It returns control to scan_extent, handles these terminating conditions, e.g., by
++ loading the next twig.
+*/
-+int reiser4_scan_extent(flush_scan * scan)
++int scan_extent(flush_scan * scan)
+{
+ coord_t coord;
+ jnode *neighbor;
+
+ coord_dup(&coord, &scan->parent_coord);
+
-+ assert("jmacd-1404", !reiser4_scan_finished(scan));
++ assert("jmacd-1404", !scan_finished(scan));
+ assert("jmacd-1405", jnode_get_level(scan->node) == LEAF_LEVEL);
+ assert("jmacd-1406", jnode_is_unformatted(scan->node));
+
+ (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 (reiser4_scanning_left(scan)) {
++ if (scanning_left(scan)) {
+ scan_max = unit_index;
+ scan_dist = scan_index - unit_index;
+ incr = -1;
+ goto stop_same_parent;
+
+ if (scan->node != neighbor
-+ && !reiser4_scan_goto(scan, neighbor)) {
-+ /* @neighbor was jput() by reiser4_scan_goto */
++ && !scan_goto(scan, neighbor)) {
++ /* @neighbor was jput() by scan_goto(). */
+ goto stop_same_parent;
+ }
+
+ goto exit;
+ }
+
-+ assert("zam-1043",
-+ reiser4_blocknr_is_fake(jnode_get_block(neighbor)));
++ assert("zam-1043", blocknr_is_fake(jnode_get_block(neighbor)));
+
+ ret = scan_set_current(scan, neighbor, scan_dist, &coord);
+ if (ret != 0) {
+
+ scan_index =
+ extent_unit_index(&coord) +
-+ (reiser4_scanning_left(scan) ?
-+ extent_unit_width(&coord) - 1 : 0);
++ (scanning_left(scan) ? extent_unit_width(&coord) - 1 : 0);
+ goto repeat;
+ }
+
+ /* 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 (reiser4_scanning_left(scan) &&
-+ (scan_index - unit_index) != 0) {
++ if (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
+ assert("vs-1410", state_of_extent(ext) == ALLOCATED_EXTENT);
+ assert("vs-1411", extent_get_width(ext) > pos_in_unit);
+
-+ h = kmalloc(sizeof(*h), reiser4_ctx_gfp_mask_get());
++ h = kmalloc(sizeof(*h), get_gfp_mask());
+ if (h == NULL)
+ return RETERR(-ENOMEM);
+ h->coord = coord;
+ set_key_offset(h->pkey,
+ (get_key_offset(h->pkey) +
+ pos_in_unit * current_blocksize));
-+ 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);
++ 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);
+ 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 = reiser4_replace_extent(h, 0 /* leave @coord set to overwritten
-+ extent */);
++ result = replace_extent(h, 0 /* leave @coord set to overwritten
++ extent */);
+ /* restore reserved */
+ free_replace_reserved(grabbed);
+ kfree(h);
+ return 0;
+ }
+
-+ h = kmalloc(sizeof(*h), reiser4_ctx_gfp_mask_get());
++ h = kmalloc(sizeof(*h), get_gfp_mask());
+ if (h == NULL)
+ return RETERR(-ENOMEM);
+ h->coord = coord;
+ h->overwrite = *replace;
+
+ /* replace @ext with @replace and padding extent */
-+ reiser4_set_extent(&h->new_extents[0],
-+ (state == ALLOCATED_EXTENT) ?
-+ (start + new_width) :
-+ UNALLOCATED_EXTENT_START,
-+ width - new_width);
++ 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 = reiser4_replace_extent(h, 0 /* leave @coord set to overwritten
-+ extent */);
++ result = replace_extent(h, 0 /* leave @coord set to overwritten
++ extent */);
+
+ /* restore reserved */
+ free_replace_reserved(grabbed);
+ * @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.
+ */
+
+ tree = current_tree;
+
-+ atom = atom_locked_by_fq(reiser4_pos_fq(flush_pos));
++ atom = atom_locked_by_fq(pos_fq(flush_pos));
+ assert("vs-1478", atom);
+
+ for (i = flush_pos->pos_in_unit; i < width; i++, index++) {
+ txn_atom *atom;
+ int nr;
+
-+ atom = atom_locked_by_fq(reiser4_pos_fq(flush_pos));
++ atom = atom_locked_by_fq(pos_fq(flush_pos));
+ assert("vs-1468", atom);
+
+ nr = 0;
+ * any formatted nodes.
+ */
+ atomic_dec(&node->x_count);
-+ break;
++ break;
+ }
+
+ assert("vs-1476", atomic_read(&node->x_count) > 1);
+ * within the extent. Slum gets to relocate set if flush_pos->leaf_relocate is
+ * set to 1 and to overwrite set otherwise
+ */
-+int reiser4_alloc_extent(flush_pos_t *flush_pos)
++int alloc_extent(flush_pos_t *flush_pos)
+{
+ coord_t *coord;
+ reiser4_extent *ext;
+ */
+ if (coord->unit_pos &&
+ (state_of_extent(ext - 1) == ALLOCATED_EXTENT))
-+ reiser4_pos_hint(flush_pos)->blk =
-+ extent_get_start(ext - 1) +
++ 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(reiser4_pos_hint(flush_pos),
-+ protected,
++ extent_allocate_blocks(pos_hint(flush_pos), protected,
+ &first_allocated, &allocated,
+ block_stage);
+
+ /* assign new block numbers to protected nodes */
+ assign_real_blocknrs(flush_pos, oid, index, allocated, first_allocated);
+
++
+ /* prepare extent which will replace current one */
-+ reiser4_set_extent(&replace_ext, first_allocated, allocated);
++ set_extent(&replace_ext, first_allocated, allocated);
+
+ /* adjust extent item */
+ result = conv_extent(coord, &replace_ext);
+ */
+ if (coord->unit_pos &&
+ (state_of_extent(ext - 1) == ALLOCATED_EXTENT))
-+ reiser4_pos_hint(flush_pos)->blk =
-+ extent_get_start(ext - 1) +
++ 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(reiser4_pos_hint(flush_pos),
-+ protected,
++ extent_allocate_blocks(pos_hint(flush_pos), protected,
+ &first_allocated, &allocated,
+ block_stage);
+
+ /* prepare extent which will be copied to left */
-+ reiser4_set_extent(©_extent, first_allocated, allocated);
++ set_extent(©_extent, first_allocated, allocated);
+
+ result = put_unit_to_end(left, &key, ©_extent);
+ if (result == -E_NODE_FULL) {
+ * overwrite: try to copy unit as it is to left neighbor and
+ * make all first not flushprepped nodes overwrite nodes
+ */
-+ reiser4_set_extent(©_extent, start, width);
++ set_extent(©_extent, start, width);
+ result = put_unit_to_end(left, &key, ©_extent);
+ if (result == -E_NODE_FULL)
+ return SQUEEZE_TARGET_FULL;
+ * scroll-step: 1
+ * End:
+ */
-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 @@
+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 @@
+/* Copyright 2001, 2002, 2003 by Hans Reiser, licensing governed by reiser4/README */
+
+#include "item.h"
+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(reiser4_max_key()));
++ set_key_offset(key, get_key_offset(max_key()));
+ return key;
+}
+
+ get_key_ordering(&key1) != get_key_ordering(&key2) ||
+ get_key_type(&key1) != get_key_type(&key2))
+ return 0;
-+ if (get_key_offset(&key1) +
-+ reiser4_extent_size(p1, nr_units_extent(p1)) !=
++ if (get_key_offset(&key1) + extent_size(p1, nr_units_extent(p1)) !=
+ get_key_offset(&key2))
+ return 0;
+ return 1;
+ ext = extent_item(coord) + from;
+ offset =
+ (get_key_offset(min_item_key) +
-+ reiser4_extent_size(coord, from)) >> PAGE_CACHE_SHIFT;
++ extent_size(coord, from)) >> PAGE_CACHE_SHIFT;
+
+ assert("vs-1551", from_off >= offset);
+ assert("vs-1552", from_off - offset <= extent_get_width(ext));
+ if (result == ITEM_TAIL_KILLED) {
+ assert("vs-1553",
+ get_key_offset(pfrom_key) >=
-+ get_key_offset(&item_key) +
-+ reiser4_extent_size(coord, from));
++ get_key_offset(&item_key) + extent_size(coord, from));
+ off =
-+ get_key_offset(pfrom_key) -
-+ (get_key_offset(&item_key) +
-+ reiser4_extent_size(coord, from));
++ get_key_offset(pfrom_key) - (get_key_offset(&item_key) +
++ extent_size(coord, from));
+ if (off) {
+ /* unit @from is to be cut partially. Its width decreases */
+ ext = extent_item(coord) + from;
+ 1)) == 0);
+ assert("",
+ get_key_offset(pto_key) + 1 >
-+ get_key_offset(&item_key) +
-+ reiser4_extent_size(coord, to));
++ get_key_offset(&item_key) + extent_size(coord, to));
+ max_to_offset =
-+ get_key_offset(&item_key) +
-+ reiser4_extent_size(coord, to + 1) - 1;
++ get_key_offset(&item_key) + extent_size(coord, to + 1) - 1;
+ assert("", get_key_offset(pto_key) <= max_to_offset);
+
+ rest =
+
+ assert("vs-1553",
+ get_key_offset(pfrom_key) >=
-+ get_key_offset(&item_key) + reiser4_extent_size(coord, from));
++ get_key_offset(&item_key) + extent_size(coord, from));
+ off =
+ get_key_offset(pfrom_key) - (get_key_offset(&item_key) +
-+ reiser4_extent_size(coord, from));
++ extent_size(coord, from));
+ if (off) {
+ /* tail of unit @from is to be cut partially. Its width decreases */
+ assert("vs-1582", new_first == NULL);
+
+ assert("vs-1554",
+ get_key_offset(pto_key) <=
-+ get_key_offset(&item_key) +
-+ reiser4_extent_size(coord, to + 1) - 1);
++ get_key_offset(&item_key) + extent_size(coord, to + 1) - 1);
+ off =
-+ (get_key_offset(&item_key) +
-+ reiser4_extent_size(coord, to + 1) - 1) -
-+ get_key_offset(pto_key);
++ (get_key_offset(&item_key) + 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. */
+ item_key_by_coord(coord, key);
+ set_key_offset(key,
+ (get_key_offset(key) +
-+ reiser4_extent_size(coord, coord->unit_pos)));
++ extent_size(coord, coord->unit_pos)));
+
+ return key;
+}
+ item_key_by_coord(coord, key);
+ set_key_offset(key,
+ (get_key_offset(key) +
-+ reiser4_extent_size(coord, coord->unit_pos + 1) - 1));
++ extent_size(coord, coord->unit_pos + 1) - 1));
+ return key;
+}
+
+ possible check of the consistency of the item that the inventor can
+ construct
+*/
-+int reiser4_check_extent(const coord_t * coord /* coord of item to check */,
-+ const char **error /* where to store error message */)
++int 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;
+ scroll-step: 1
+ End:
+*/
-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 @@
+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 @@
+/* Copyright 2001, 2002, 2003 by Hans Reiser, licensing governed by reiser4/README */
+
+/* Implementation of internal-item plugin methods. */
+ return (internal_item_layout *) item_body_by_coord(coord);
+}
+
-+void reiser4_update_internal(const coord_t * coord,
-+ const reiser4_block_nr * blocknr)
++void 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));
+ *block = pointer_at(coord);
+ assert("nikita-2961", reiser4_blocknr_is_sane(block));
+
-+ if (reiser4_blocknr_is_fake(block)) {
++ if (blocknr_is_fake(block)) {
+ *block = 0;
+ }
+
+ return 0;
+}
+
-+#if REISER4_DEBUG
-+
+static void check_link(znode * left, znode * right)
+{
+ znode *scan;
+ 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 */ ,
+ * item to little endian byte order.
+ */
+ child_ptr = get_unaligned((__u64 *)item_body_by_coord(item));
-+ reiser4_update_internal(item, &child_ptr);
++ update_internal(item, &child_ptr);
+
+ child = znode_at(item, item->node);
+ if (child != NULL && !IS_ERR(child)) {
+ . 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 */ ,
+ fill-column: 120
+ End:
+*/
-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
+Index: linux-2.6.16/fs/reiser4/plugin/item/internal.h
+===================================================================
+--- /dev/null
++++ linux-2.6.16/fs/reiser4/plugin/item/internal.h
@@ -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
+ 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 reiser4_print_internal(const char *prefix, coord_t * coord);
++extern void 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 reiser4_update_internal(const coord_t * coord,
-+ const reiser4_block_nr * blocknr);
++extern void 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);
+
+ fill-column: 120
+ End:
+*/
-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 @@
+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 @@
+/* Copyright 2001, 2002, 2003 by Hans Reiser, licensing governed by reiser4/README */
+
+/* definition of item plugins. */
+ 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 */ )
+}
+
+/* ->nr_units() method for items consisting of exactly one unit always */
-+pos_in_node_t
++static pos_in_node_t
+nr_units_single_unit(const coord_t * coord UNUSED_ARG /* coord of item */ )
+{
+ return 1;
+ 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 plugin_of_group(item_plugin_by_coord(item), STAT_DATA_ITEM_TYPE);
++ return item_type_by_coord(item) == STAT_DATA_ITEM_TYPE;
+}
+
+int item_is_ctail(const coord_t * item)
+ return item_id_by_coord(item) == CTAIL_ID;
+}
+
-+#endif /* REISER4_DEBUG */
-+
-+static int change_item(struct inode *inode,
-+ reiser4_plugin * plugin,
-+ pset_member memb)
++static int change_item(struct inode *inode, reiser4_plugin * plugin)
+{
+ /* cannot change constituent item (sd, or dir_item) */
+ return RETERR(-EINVAL);
+ .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,
+ .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,
+ .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,
+ .estimate = estimate_cde,
+ .item_data_by_flow = NULL,
+#if REISER4_DEBUG
-+ .check = reiser4_check_cde
++ .check = check_cde
+#endif
+ },
+ .f = {
+ .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,
+ .utmost_child = utmost_child_internal,
+ .utmost_child_real_block =
+ utmost_child_real_block_internal,
-+ .update = reiser4_update_internal,
++ .update = update_internal,
+ .scan = NULL,
+ .convert = NULL
+ },
+ .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,
+ .estimate = NULL,
+ .item_data_by_flow = NULL,
+#if REISER4_DEBUG
-+ .check = reiser4_check_extent
++ .check = check_extent
+#endif
+ },
+ .f = {
+ .utmost_child_real_block =
+ utmost_child_real_block_extent,
+ .update = NULL,
-+ .scan = reiser4_scan_extent,
++ .scan = scan_extent,
+ .convert = NULL,
+ .key_by_offset = key_by_offset_extent
+ },
+ .s = {
+ .file = {
-+ .write = reiser4_write_extent,
-+ .read = reiser4_read_extent,
-+ .readpage = reiser4_readpage_extent,
++ .write = write_extent,
++ .read = read_extent,
++ .readpage = readpage_extent,
+ .get_block = get_block_address_extent,
++ .readpages = readpages_extent,
+ .append_key = append_key_extent,
+ .init_coord_extension =
+ init_coord_extension_extent
+ .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,
+ },
+ .s = {
+ .file = {
-+ .write = reiser4_write_tail,
-+ .read = reiser4_read_tail,
++ .write = write_tail,
++ .read = read_tail,
+ .readpage = readpage_tail,
-+ .get_block = get_block_address_tail,
++ .get_block = NULL,
++ .readpages = NULL,
+ .append_key = append_key_tail,
+ .init_coord_extension =
+ init_coord_extension_tail
+ .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,
+ .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
+ .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,
+ fill-column: 120
+ End:
+*/
-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 @@
+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 @@
+/* Copyright 2001, 2002, 2003 by Hans Reiser, licensing governed by reiser4/README */
+
+/* first read balance.c comments before reading this */
+/* 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. */
-+struct balance_ops {
++typedef struct {
++ item_type_id item_type;
++
+ /* operations called by balancing
+
+ It is interesting to consider that some of these item
+ 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 reiser4_max_key().
++ return max_key().
+
+ For example extent with the key
+
+ */
+ int (*mergeable) (const coord_t *, 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 *);
++ /* number of atomic things in an item */
++ 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
+ item */
+ int (*init) (coord_t * target, coord_t * from,
+ reiser4_item_data * data);
-+ /* method called (e.g., by reiser4_resize_item()) to place new data
-+ into item when it grows */
++ /* method called (e.g., by 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
+ int (*check) (const coord_t *, const char **error);
+#endif
+
-+};
++} balance_ops;
+
-+struct flush_ops {
++typedef struct {
+ /* return the right or left child of @coord, only if it is in memory */
+ int (*utmost_child) (const coord_t *, sideof side, jnode ** child);
+
+ 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 */
-+struct dir_entry_iops {
++typedef struct {
+ /* extract stat-data key from directory entry at @coord and place it
+ into @key. */
+ int (*extract_key) (const coord_t *, reiser4_key * key);
+ 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 */
-+struct file_iops{
++typedef struct {
+ 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.
+ 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 */
-+struct sd_iops {
++typedef struct {
+ 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 */
-+struct internal_iops{
++typedef struct {
+ /* all tree traversal want to know from internal item is where
+ to go next. */
+ void (*down_link) (const coord_t * coord,
+ /* 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 */
-+ struct balance_ops b; /* balance operations */
-+ struct flush_ops f; /* flush operates with items via this methods */
++ balance_ops b;
++ /* methods used during flush */
++ flush_ops f;
+
+ /* methods specific to particular type of item */
+ union {
-+ struct dir_entry_iops dir;
-+ struct file_iops file;
-+ struct sd_iops sd;
-+ struct internal_iops internal;
++ dir_entry_ops dir;
++ file_ops file;
++ sd_ops sd;
++ internal_item_ops 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)
+{
+extern int item_is_ctail(const coord_t *);
+
+extern pos_in_node_t item_length_by_coord(const coord_t * coord);
-+extern pos_in_node_t nr_units_single_unit(const coord_t * coord);
++extern item_type_id item_type_by_coord(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)
+static inline int item_is_internal(const coord_t * item)
+{
+ assert("vs-483", coord_is_existing_item(item));
-+ return plugin_of_group(item_plugin_by_coord(item), INTERNAL_ITEM_TYPE);
++ return item_type_by_coord(item) == INTERNAL_ITEM_TYPE;
+}
+
+extern void item_body_by_coord_hard(coord_t * coord);
+ scroll-step: 1
+ End:
+*/
-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
+Index: linux-2.6.16/fs/reiser4/plugin/item/sde.c
+===================================================================
+--- /dev/null
++++ linux-2.6.16/fs/reiser4/plugin/item/sde.c
@@ -0,0 +1,190 @@
+/* Copyright 2001, 2002, 2003 by Hans Reiser, licensing governed by reiser4/README */
+
+
+int max_name_len_de(const struct inode *dir)
+{
-+ return reiser4_tree_by_inode(dir)->nplug->max_item_size() -
-+ sizeof(directory_entry_format) - 2;
++ return tree_by_inode(dir)->nplug->max_item_size() -
++ sizeof(directory_entry_format) - 2;
+}
+
+/* Make Linus happy.
+ fill-column: 120
+ End:
+*/
-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
+Index: linux-2.6.16/fs/reiser4/plugin/item/sde.h
+===================================================================
+--- /dev/null
++++ linux-2.6.16/fs/reiser4/plugin/item/sde.h
@@ -0,0 +1,66 @@
+/* Copyright 2001, 2002, 2003 by Hans Reiser, licensing governed by reiser4/README */
+
+ fill-column: 120
+ End:
+*/
-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 @@
+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 @@
+/* Copyright 2001, 2002, 2003 by Hans Reiser, licensing governed by reiser4/README */
+
+/* stat data manipulation. */
+ state = reiser4_inode_data(inode);
+ mask = le16_to_cpu(get_unaligned(&sd_base->extmask));
+ bigmask = mask;
-+ reiser4_inode_set_flag(inode, REISER4_SDLEN_KNOWN);
++ inode_set_flag(inode, REISER4_SDLEN_KNOWN);
+
+ move_on(&len, &sd, sizeof *sd_base);
+ for (bit = 0, chunk = 0;
+ }
+ 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 */
+ if ((inode->i_mode & S_IFMT) == (S_IFREG | S_IFIFO)) {
+ inode->i_mode &= ~S_IFIFO;
+ warning("", "partially converted file is encountered");
-+ reiser4_inode_set_flag(inode, REISER4_PART_MIXED);
++ inode_set_flag(inode, REISER4_PART_MIXED);
+ }
+ move_on(len, area, sizeof *sd_lw);
+ return 0;
+
+ sd = (reiser4_light_weight_stat *) * area;
+
-+ delta = (reiser4_inode_get_flag(inode,
-+ REISER4_PART_MIXED) ? S_IFIFO : 0);
++ delta = (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);
+ 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 (lookup_common) will
++ /* mark inode as lightweight, so that caller (reiser4_lookup) will
+ complete initialisation by copying [ug]id from a parent. */
-+ reiser4_inode_set_flag(inode, REISER4_LIGHT_WEIGHT);
++ inode_set_flag(inode, REISER4_LIGHT_WEIGHT);
+ return 0;
+}
+
+
+/* symlink stat data extension */
+
-+/* allocate memory for symlink target and attach it to inode->i_private */
++/* allocate memory for symlink target and attach it to inode->u.generic_ip */
+static int
+symlink_target_to_inode(struct inode *inode, const char *target, int len)
+{
-+ assert("vs-845", inode->i_private == NULL);
-+ assert("vs-846", !reiser4_inode_get_flag(inode,
-+ REISER4_GENERIC_PTR_USED));
++ assert("vs-845", inode->u.generic_ip == NULL);
++ assert("vs-846", !inode_get_flag(inode, REISER4_GENERIC_PTR_USED));
++
+ /* FIXME-VS: this is prone to deadlock. Not more than other similar
+ places, though */
-+ inode->i_private = kmalloc((size_t) len + 1,
-+ reiser4_ctx_gfp_mask_get());
-+ if (!inode->i_private)
++ inode->u.generic_ip = kmalloc((size_t) len + 1, get_gfp_mask());
++ if (!inode->u.generic_ip)
+ return RETERR(-ENOMEM);
+
-+ memcpy((char *)(inode->i_private), target, (size_t) len);
-+ ((char *)(inode->i_private))[len] = 0;
-+ reiser4_inode_set_flag(inode, REISER4_GENERIC_PTR_USED);
++ 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);
+ return 0;
+}
+
+
+ result = 0;
+ sd = (reiser4_symlink_stat *) * area;
-+ if (!reiser4_inode_get_flag(inode, REISER4_GENERIC_PTR_USED)) {
++ if (!inode_get_flag(inode, REISER4_GENERIC_PTR_USED)) {
+ const char *target;
+
-+ target = (const char *)(inode->i_private);
-+ inode->i_private = NULL;
++ target = (const char *)(inode->u.generic_ip);
++ inode->u.generic_ip = NULL;
+
+ result = symlink_target_to_inode(inode, target, length);
+
+ } else {
+ /* there is nothing to do in update but move area */
+ assert("vs-844",
-+ !memcmp(inode->i_private, sd->body,
++ !memcmp(inode->u.generic_ip, sd->body,
+ (size_t) length + 1));
+ }
+
+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 is_pset /* 1 if plugin set, 0 if heir set. */)
++ int *len /* remaining length */ )
+{
+ reiser4_plugin_stat *sd;
+ reiser4_plugin *plugin;
-+ reiser4_inode *info;
+ int i;
+ __u16 mask;
+ int result;
+ 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));
+ return not_enough_space(inode, "additional plugin");
+
+ memb = le16_to_cpu(get_unaligned(&slot->pset_memb));
-+ type = aset_member_to_type_unsafe(memb);
-+
++ type = pset_member_to_type_unsafe(memb);
+ if (type == REISER4_PLUGIN_TYPES) {
+ warning("nikita-3502",
-+ "wrong %s member (%i) for %llu", is_pset ?
-+ "pset" : "hset", memb,
++ "wrong pset member (%i) for %llu", memb,
+ (unsigned long long)get_inode_oid(inode));
+ return RETERR(-EINVAL);
+ }
-+ plugin = plugin_by_disk_id(reiser4_tree_by_inode(inode),
++ plugin = plugin_by_disk_id(tree_by_inode(inode),
+ type, &slot->id);
+ if (plugin == NULL)
+ return unknown_plugin(le16_to_cpu(get_unaligned(&slot->id)), inode);
+ }
+ 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);
-+ else
-+ result = aset_set_unsafe(is_pset ? &info->pset :
-+ &info->hset, memb, plugin);
-+ if (result)
-+ return result;
++ if (result != 0)
++ return result;
++ } else
++ result = grab_plugin_from(inode, memb, plugin);
+ }
-+ 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;
++ /* 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);
+
++ 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
+ break;
+ }
+ info = reiser4_inode_data(inode);
-+ 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);
++ 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);
+ return 0;
+}
+
+/* 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, int is_pset)
++ pset_member memb, int len)
+{
+ reiser4_inode *info;
+ assert("nikita-661", inode != NULL);
+
-+ if (plugin == NULL)
-+ return len;
-+
+ info = reiser4_inode_data(inode);
-+ if (is_pset ?
-+ info->plugin_mask & (1 << memb) :
-+ info->heir_mask & (1 << memb)) {
++ if (plugin != NULL && (info->plugin_mask & (1 << memb))) {
+ len += sizeof(reiser4_plugin_slot);
+ if (plugin->h.pops && plugin->h.pops->save_len != NULL) {
+ /* non-standard plugin, call method */
+
+/* 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 */,
-+ int is_pset)
++static int save_len_plugin_sd(struct inode *inode /* object being processed */ )
+{
+ 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 (is_pset ? state->plugin_mask == 0 : state->heir_mask == 0)
++ if (state->plugin_mask == 0)
+ return 0;
+ len = sizeof(reiser4_plugin_stat);
-+ 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);
-+ }
++ for (memb = 0; memb < PSET_LAST; ++memb)
++ len = len_for(pset_get(state->pset, memb), inode, memb, len);
+ 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 */ ,
-+ int memb /* what element of pset is saved */ ,
++ pset_member memb /* what element of pset is saved */ ,
+ char **area /* position in stat-data */ ,
-+ int *count /* incremented if plugin were actually saved. */,
-+ int is_pset /* 1 for plugin set, 0 for heir set */)
++ int *count /* incremented if plugin were actually
++ * saved. */ )
+{
+ reiser4_plugin_slot *slot;
+ int fake_len;
+
+ if (plugin == NULL)
+ return 0;
-+
-+ if (is_pset ?
-+ !(reiser4_inode_data(inode)->plugin_mask & (1 << memb)) :
-+ !(reiser4_inode_data(inode)->heir_mask & (1 << memb)))
++ if (!(reiser4_inode_data(inode)->plugin_mask & (1 << memb)))
+ return 0;
+ slot = (reiser4_plugin_slot *) * area;
+ put_unaligned(cpu_to_le16(memb), &slot->pset_memb);
+
+/* 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 */,
-+ int is_pset /* 1 for pset, 0 for hset */)
++ char **area /* position in stat-data */ )
+{
-+ 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);
+ assert("nikita-671", *area != NULL);
+
+ state = reiser4_inode_data(inode);
-+ if (is_pset ? state->plugin_mask == 0 : state->heir_mask == 0)
++ if (state->plugin_mask == 0)
+ return 0;
+ sd = (reiser4_plugin_stat *) * area;
+ fake_len = (int)0xffff;
+
+ num_of_plugins = 0;
+ for (memb = 0; memb < PSET_LAST; ++memb) {
-+ result = save_plug(aset_get(is_pset ? state->pset : state->hset,
-+ memb),
-+ inode, memb, area, &num_of_plugins, is_pset);
++ result = save_plug(pset_get(state->pset, memb),
++ inode, memb, area, &num_of_plugins);
+ if (result != 0)
+ break;
+ }
+ 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.
-+ Extract crypto info from stat-data and attach it to inode */
-+static int extract_crypto_info (struct inode * inode,
++ Allocates memory for crypto stat, keyid and attaches it to the inode */
++static int extract_crypto_stat (struct inode * inode,
+ reiser4_crypto_stat * sd)
+{
-+ struct reiser4_crypto_info * info;
-+ assert("edward-11", !inode_crypto_info(inode));
++ crypto_stat_t * info;
++ assert("edward-11", !inode_crypto_stat(inode));
+ assert("edward-1413",
-+ !reiser4_inode_get_flag(inode, REISER4_CRYPTO_STAT_LOADED));
++ !inode_get_flag(inode, REISER4_CRYPTO_STAT_LOADED));
+ /* create and attach a crypto-stat without secret key loaded */
-+ info = reiser4_alloc_crypto_info(inode);
++ info = alloc_crypto_stat(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);
-+ reiser4_attach_crypto_info(inode, info);
-+ reiser4_inode_set_flag(inode, REISER4_CRYPTO_STAT_LOADED);
++ attach_crypto_stat(inode, info);
++ inode_set_flag(inode, REISER4_CRYPTO_STAT_LOADED);
+ return 0;
+}
+
+ assert("edward-75", sizeof(*sd) + dplug->fipsize <= *len);
+
+ sd = (reiser4_crypto_stat *) * area;
-+ result = extract_crypto_info(inode, sd);
++ result = extract_crypto_stat(inode, sd);
+ move_on(len, area, sizeof(*sd) + dplug->fipsize);
+
+ return result;
+{
+ int result = 0;
+ reiser4_crypto_stat *sd;
-+ struct reiser4_crypto_info * info = inode_crypto_info(inode);
++ crypto_stat_t * info = inode_crypto_stat(inode);
+ digest_plugin *dplug = inode_digest_plugin(inode);
+
+ assert("edward-12", dplug != NULL);
+ assert("edward-1415", info->keysize != 0);
+ assert("edward-76", reiser4_inode_data(inode) != NULL);
+
-+ if (!reiser4_inode_get_flag(inode, REISER4_CRYPTO_STAT_LOADED)) {
++ if (!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);
-+ reiser4_inode_set_flag(inode, REISER4_CRYPTO_STAT_LOADED);
++ inode_set_flag(inode, REISER4_CRYPTO_STAT_LOADED);
+ }
+ *area += (sizeof(*sd) + dplug->fipsize);
+ return result;
+ .desc = "plugin stat-data fields",
+ .linkage = {NULL,NULL}
+ },
-+ .present = present_pset_sd,
++ .present = present_plugin_sd,
+ .absent = absent_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,
++ .save_len = save_len_plugin_sd,
++ .save = save_plugin_sd,
+ .alignment = 8
+ },
+ [FLAGS_STAT] = {
+ fill-column: 120
+ End:
+*/
-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 @@
+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 @@
+/* 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.
+ LARGE_TIMES_STAT,
+ /* stat data has link name included */
+ SYMLINK_STAT,
-+ /* 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. */
++ /* 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. */
+ PLUGIN_STAT,
+ /* this extension contains persistent inode flags. These flags are
+ single bits: immutable, append, only, etc. Layout is in
+ /* 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
+ * ->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. */
+typedef struct reiser4_light_weight_stat {
+ /* 0 */ __le16 mode;
+ /* 2 */ __le32 nlink;
-+ /* 6 */ __le64 size;
++ /* 8 */ __le64 size;
+ /* size in bytes */
-+ /* 14 */
++ /* 16 */
+} PACKED reiser4_light_weight_stat;
+
+typedef struct reiser4_unix_stat {
+
+typedef struct reiser4_large_times_stat {
+ /* access time */
-+ /* 0 */ d32 atime;
++ /* 0 */ d32 atime;
+ /* modification time */
-+ /* 4 */ d32 mtime;
++ /* 8 */ d32 mtime;
+ /* change time */
-+ /* 8 */ d32 ctime;
-+ /* 12 */
++ /* 16 */ d32 ctime;
++ /* 24 */
+} PACKED reiser4_large_times_stat;
+
+/* this structure is filled by sd_item_stat */
+ fill-column: 120
+ End:
+*/
-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 @@
+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 @@
+/* Copyright 2001, 2002, 2003 by Hans Reiser, licensing governed by reiser4/README */
+
+#include "item.h"
+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(reiser4_max_key()));
++ set_key_offset(key, get_key_offset(max_key()));
+ return key;
+}
+
+{
+ reiser4_key key1, key2;
+
-+ assert("vs-535", plugin_of_group(item_plugin_by_coord(p1),
-+ UNIX_FILE_METADATA_ITEM_TYPE));
++ assert("vs-535",
++ item_type_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) {
+ if (data->data) {
+ assert("vs-554", data->user == 0 || data->user == 1);
+ if (data->user) {
-+ assert("nikita-3035", reiser4_schedulable());
++ assert("nikita-3035", schedulable());
+ /* copy from user space */
+ if (__copy_from_user(item + coord->unit_pos,
+ (const char __user *)data->data,
+ inode = page->mapping->host;
+ coord_dup(&coord, &uf_coord->coord);
+
-+ reiser4_tap_init(&tap, &coord, &lh, ZNODE_READ_LOCK);
++ tap_init(&tap, &coord, &lh, ZNODE_READ_LOCK);
+
-+ if ((result = reiser4_tap_load(&tap)))
++ if ((result = tap_load(&tap)))
+ goto out_tap_done;
+
+ /* lookup until page is filled up. */
+ }
+
+ done:
-+ if (mapped != PAGE_CACHE_SIZE)
-+ zero_user_page(page, mapped, PAGE_CACHE_SIZE - mapped,
-+ KM_USER0);
++ 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);
++ }
+ SetPageUptodate(page);
+ out_unlock_page:
+ unlock_page(page);
+ out_tap_relse:
-+ reiser4_tap_relse(&tap);
++ tap_relse(&tap);
+ out_tap_done:
-+ reiser4_tap_done(&tap);
++ tap_done(&tap);
+ return result;
+}
+
+ 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", reiser4_schedulable());
++ assert("nikita-3036", schedulable());
+
+ count = item_length_by_coord(coord) - coord->unit_pos;
+ if (count > flow->length)
+{
+ int result;
+ loff_t to_write;
-+ struct unix_file_info *uf_info;
++ unix_file_info_t *uf_info;
+
+ if (get_key_offset(&flow->key) != 0) {
+ /*
+ */
+ if (DQUOT_ALLOC_SPACE_NODIRTY(inode, flow->length))
+ return RETERR(-EDQUOT);
-+ result = reiser4_insert_flow(coord, lh, flow);
++ result = insert_flow(coord, lh, flow);
+ if (flow->length)
+ DQUOT_FREE_SPACE_NODIRTY(inode, flow->length);
+
+ * file or performing tail conversion
+ */
+ assert("", (uf_info->container == UF_CONTAINER_EMPTY ||
-+ (reiser4_inode_get_flag(inode,
-+ REISER4_PART_MIXED) &&
-+ reiser4_inode_get_flag(inode,
-+ REISER4_PART_IN_CONV))));
++ (inode_get_flag(inode, REISER4_PART_MIXED) &&
++ 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;
+ return RETERR(-EDQUOT);
+
+ to_write = flow->length;
-+ result = reiser4_insert_flow(coord, lh, flow);
++ result = 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;
+ 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);
+ */
+ if (DQUOT_ALLOC_SPACE_NODIRTY(inode, flow->length))
+ return RETERR(-EDQUOT);
-+ result = reiser4_insert_flow(coord, lh, flow);
++ result = insert_flow(coord, lh, flow);
+ if (flow->length)
+ DQUOT_FREE_SPACE_NODIRTY(inode, flow->length);
+ return result;
+ return RETERR(-EDQUOT);
+
+ to_write = flow->length;
-+ result = reiser4_insert_flow(coord, lh, flow);
++ result = 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;
+
+ /*
+ * 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
+ *
+ * 3. stat data update
+ */
-+ tree = reiser4_tree_by_inode(inode);
-+ count = estimate_one_insert_item(tree) +
++ tree = tree_by_inode(inode);
++ count = estimate_one_insert_item(tree) +
+ estimate_insert_flow(tree->height) +
+ estimate_one_insert_item(tree);
+ grab_space_enable();
+
+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)
+}
+
+/**
-+ * reiser4_write_extent - write method of tail item plugin
++ * 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
+ *
+ * Returns number of written bytes or error code.
+ */
-+ssize_t reiser4_write_tail(struct file *file, const char __user *buf,
-+ size_t count, loff_t *pos)
++ssize_t write_tail(struct file *file, const char __user *buf, size_t count,
++ loff_t *pos)
+{
+ struct inode *inode;
+ struct hint hint;
+ 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);
+ done_lh(lh);
+ return result;
+ }
-+
++
+ /* seal and unlock znode */
+ hint.ext_coord.valid = 0;
+ if (hint.ext_coord.valid)
-+ reiser4_set_hint(&hint, &flow.key, ZNODE_WRITE_LOCK);
++ set_hint(&hint, &flow.key, ZNODE_WRITE_LOCK);
+ else
-+ reiser4_unset_hint(&hint);
++ unset_hint(&hint);
+
+ save_file_hint(file, &hint);
+ return result;
+#endif
+
+/* plugin->u.item.s.file.read */
-+int reiser4_read_tail(struct file *file UNUSED_ARG, flow_t *f, hint_t *hint)
++int read_tail(struct file *file UNUSED_ARG, flow_t *f, hint_t *hint)
+{
+ unsigned count;
+ int item_length;
+ assert("vs-1117", znode_is_rlocked(coord->node));
+ assert("vs-1118", znode_is_loaded(coord->node));
+
-+ assert("nikita-3037", reiser4_schedulable());
++ assert("nikita-3037", schedulable());
+ assert("vs-1357", coord_matches_key_tail(coord, &f->key));
+
+ /* calculate number of bytes to read off the item */
+ coord->unit_pos--;
+ coord->between = AFTER_UNIT;
+ }
-+ reiser4_set_hint(hint, &f->key, ZNODE_READ_LOCK);
++
+ return 0;
+}
+
+{
+ assert("nikita-3252", znode_get_level(coord->node) == LEAF_LEVEL);
+
-+ 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);
++ *block = *znode_get_block(coord->node);
+ return 0;
+}
+
+ * scroll-step: 1
+ * End:
+ */
-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
+Index: linux-2.6.16/fs/reiser4/plugin/item/tail.h
+===================================================================
+--- /dev/null
++++ linux-2.6.16/fs/reiser4/plugin/item/tail.h
@@ -0,0 +1,58 @@
+/* Copyright 2002, 2003 by Hans Reiser, licensing governed by reiser4/README */
+
+#if !defined( __REISER4_TAIL_H__ )
+#define __REISER4_TAIL_H__
+
-+struct tail_coord_extension {
++typedef struct {
+ int not_used;
-+};
++} tail_coord_extension_t;
+
+struct cut_list;
+
+reiser4_key *unit_key_tail(const coord_t *, reiser4_key *);
+
+/* plugin->u.item.s.* */
-+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 *);
++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 *);
+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);
+ scroll-step: 1
+ End:
+*/
-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
+Index: linux-2.6.16/fs/reiser4/plugin/node/Makefile
+===================================================================
+--- /dev/null
++++ linux-2.6.16/fs/reiser4/plugin/node/Makefile
@@ -0,0 +1,5 @@
+obj-$(CONFIG_REISER4_FS) += node_plugins.o
+
+node_plugins-objs := \
+ node.o \
+ node40.o
-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
+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
@@ -0,0 +1,2924 @@
+/* Copyright 2001, 2002, 2003 by Hans Reiser, licensing governed by reiser4/README */
+
+#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 */
+
+ /* screw up */
+ warning("nikita-587", "Key less than %i key in a node",
+ left);
-+ reiser4_print_key("key", key);
-+ reiser4_print_key("min", &bstop->key);
++ print_key("key", key);
++ print_key("min", &bstop->key);
+ print_coord_content("coord", coord);
+ return RETERR(-EIO);
+ } else {
+ if (unlikely(iplug == NULL)) {
+ warning("nikita-588", "Unknown plugin %i",
+ le16_to_cpu(get_unaligned(&bstop->plugin_id)));
-+ reiser4_print_key("key", key);
++ print_key("key", key);
+ print_coord_content("coord", coord);
+ return RETERR(-EIO);
+ }
+ if (flags & REISER4_NODE_DKEYS)
+ prev = *znode_get_ld_key((znode *) node);
+ else
-+ prev = *reiser4_min_key();
++ prev = *min_key();
+
+ old_offset = 0;
+ coord_init_zero(&coord);
+ node->nr_items = node40_num_of_items_internal(node);
+ result = 0;
+ }
++ if (unlikely(result != 0))
++ /* print_znode("node", node) */ ;
+ return RETERR(result);
+}
+
+ from userspace was valid and data bytes were
+ available? How will we return -EFAULT of some kind
+ without this check? */
-+ assert("nikita-3038", reiser4_schedulable());
++ assert("nikita-3038", schedulable());
+ /* copy data from user space */
+ __copy_from_user(zdata(target->node) + offset,
+ (const char __user *)data->data,
+ else
+ reference = op->node;
+ assert("nikita-2992", reference != NULL);
-+ cn = reiser4_add_carry(info->todo, POOLO_BEFORE, reference);
++ cn = add_carry(info->todo, POOLO_BEFORE, reference);
+ if (IS_ERR(cn))
+ return PTR_ERR(cn);
+ cn->parent = 1;
+ node40_num_of_items_internal(left) +
+ node40_num_of_items_internal(right) - (mergeable ? 1 : 0);
+ data =
-+ kmalloc(sizeof(struct shift_check) * nr_items,
-+ reiser4_ctx_gfp_mask_get());
++ kmalloc(sizeof(struct shift_check) * nr_items, get_gfp_mask());
+ if (data != NULL) {
+ coord_t coord;
+ pos_in_node_t item_pos;
+ break;
+ case EXTENT_POINTER_ID:
+ data[i].u.bytes =
-+ reiser4_extent_size(&coord,
-+ coord_num_units(&coord));
++ extent_size(&coord,
++ coord_num_units(&coord));
+ break;
+ case COMPOUND_DIR_ID:
+ data[i].u.entries = coord_num_units(&coord);
+ break;
+ case EXTENT_POINTER_ID:
+ data[i - 1].u.bytes +=
-+ reiser4_extent_size(&coord,
++ extent_size(&coord,
+ coord_num_units(&coord));
+ break;
+ case COMPOUND_DIR_ID:
+ break;
+ case EXTENT_POINTER_ID:
+ data[i].u.bytes =
-+ reiser4_extent_size(&coord,
++ extent_size(&coord,
+ coord_num_units(&coord));
+ break;
+ case COMPOUND_DIR_ID:
+ break;
+ case EXTENT_POINTER_ID:
+ assert("vs-1593",
-+ data[i].u.bytes ==
-+ reiser4_extent_size(&coord,
-+ coord_num_units
-+ (&coord)));
++ data[i].u.bytes == extent_size(&coord,
++ coord_num_units
++ (&coord)));
+ break;
+ case COMPOUND_DIR_ID:
+ assert("vs-1594",
+ break;
+ case EXTENT_POINTER_ID:
+ last_bytes =
-+ reiser4_extent_size(&coord,
++ extent_size(&coord,
+ coord_num_units(&coord));
+ break;
+ case COMPOUND_DIR_ID:
+ case EXTENT_POINTER_ID:
+ assert("vs-1597",
+ data[i - 1].u.bytes ==
-+ last_bytes + reiser4_extent_size(&coord,
-+ coord_num_units
-+ (&coord)));
++ last_bytes + extent_size(&coord,
++ coord_num_units
++ (&coord)));
+ break;
+
+ case COMPOUND_DIR_ID:
+ break;
+ case EXTENT_POINTER_ID:
+ assert("vs-1601",
-+ data[i].u.bytes ==
-+ reiser4_extent_size(&coord,
-+ coord_num_units
-+ (&coord)));
++ data[i].u.bytes == extent_size(&coord,
++ coord_num_units
++ (&coord)));
+ break;
+ case COMPOUND_DIR_ID:
+ assert("vs-1602",
+ look for description of this method in plugin/node/node.h */
+int fast_insert_node40(const coord_t * coord UNUSED_ARG /* node to query */ )
+{
-+ return 1;
-+}
-+
-+/* plugin->u.node.fast_paste()
-+ look for description of this method in plugin/node/node.h */
-+int fast_paste_node40(const coord_t * coord UNUSED_ARG /* node to query */ )
-+{
-+ return 1;
-+}
-+
-+/* plugin->u.node.fast_cut()
-+ look for description of this method in plugin/node/node.h */
-+int fast_cut_node40(const coord_t * coord UNUSED_ARG /* node to query */ )
-+{
-+ return 1;
-+}
-+
-+/* 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.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;
-+
-+/* 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;
++ return 1;
++}
+
-+ /* 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);
++/* plugin->u.node.fast_paste()
++ look for description of this method in plugin/node/node.h */
++int fast_paste_node40(const coord_t * coord UNUSED_ARG /* node to query */ )
++{
++ return 1;
++}
+
-+ /* 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);
++/* plugin->u.node.fast_cut()
++ look for description of this method in plugin/node/node.h */
++int fast_cut_node40(const coord_t * coord UNUSED_ARG /* node to query */ )
++{
++ return 1;
++}
+
-+ /* 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);
++/* plugin->u.node.modify - not defined */
+
-+ /* 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);
++/* 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);
++}
+
-+ /* performs every consistency check the node plugin author could
-+ imagine. Optional. */
-+ int (*check) (const znode * node, __u32 flags, const char **error);
++/* plugin->u.node.set_item_plugin */
++int set_item_plugin_node40(coord_t *coord, item_id id)
++{
++ item_header40 *ih;
+
-+ /* 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);
++ ih = node40_ih_at_coord(coord);
++ put_unaligned(cpu_to_le16(id), &ih->plugin_id);
++ coord->iplugid = id;
++ return 0;
++}
+
-+ /* 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);
++/*
++ 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 */
+
-+ /* update key of item. */
-+ void (*update_item_key) (coord_t * target, const reiser4_key * key,
-+ carry_plugin_info * info);
++#if !defined( __REISER4_NODE40_H__ )
++#define __REISER4_NODE40_H__
+
-+ int (*cut_and_kill) (struct carry_kill_data *, carry_plugin_info *);
-+ int (*cut) (struct carry_cut_data *, carry_plugin_info *);
++#include "../../forward.h"
++#include "../../dformat.h"
++#include "node.h"
+
-+ /*
-+ * shrink item pointed to by @coord by @delta bytes.
++#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.
+ */
-+ int (*shrink_item) (coord_t * coord, int delta);
++/* 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. */
+
-+ /* 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.
++ /* 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? */
+
-+ 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.
++ 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;
+
-+ */
-+ 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;
++ /* 1 is leaf level, 2 is twig level, root is the numerically
++ largest level */
++ d8 level;
+
-+typedef enum {
-+ /* standard unified node layout used for both leaf and internal
-+ nodes */
-+ NODE40_ID,
-+ LAST_NODE_ID
-+} reiser4_node_id;
++ d8 pad;
++} PACKED node40_header;
+
-+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);
++/* 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);
+
-+extern void indent_znode(const znode * node);
++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);
+
-+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;
++#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_NODE_H__ */
++/* __REISER4_NODE40_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:
-+ */
-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 @@
++ 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 @@
+/* Copyright 2001, 2002, 2003 by Hans Reiser, licensing governed by
+ * reiser4/README */
+
+
+#define dummyop ((void *)_dummyop)
+
-+static int change_file(struct inode *inode,
-+ reiser4_plugin * plugin,
-+ pset_member memb)
++static int change_file(struct inode *inode, reiser4_plugin * plugin)
+{
+ /* cannot change object plugin of already existing object */
-+ if (memb == PSET_FILE)
-+ return RETERR(-EINVAL);
-+
-+ /* Change PSET_CREATE */
-+ return aset_set_unsafe(&reiser4_inode_data(inode)->pset, memb, plugin);
++ return RETERR(-EINVAL);
+}
+
+static reiser4_plugin_ops file_plugin_ops = {
+ .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 = reiser4_permission_common,
++ .permission = permission_common,
+ .setattr = setattr_unix_file,
-+ .getattr = reiser4_getattr_common
++ .getattr = 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,
+ .sync_page = block_sync_page,
+ .writepages = writepages_unix_file,
+ .set_page_dirty = reiser4_set_page_dirty,
-+ .readpages = readpages_unix_file,
++ .readpages = reiser4_readpages,
+ .prepare_write = prepare_write_unix_file,
+ .commit_write = commit_write_unix_file,
+ .bmap = bmap_unix_file,
+ .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 = reiser4_create_object_common,
++ .create_object = create_object_common, /* this is not inode_operations's create */
+ .delete_object = delete_object_unix_file,
-+ .add_link = reiser4_add_link_common,
-+ .rem_link = reiser4_rem_link_common,
++ .add_link = add_link_common,
++ .rem_link = rem_link_common,
+ .owns_item = owns_item_unix_file,
+ .can_add_link = can_add_link_common,
+ .detach = dummyop,
+ .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 = {.create = NULL},
-+ .file_ops = {.owner = NULL},
-+ .as_ops = {.writepage = NULL},
++ .inode_ops = {NULL,},
++ .file_ops = {NULL,},
++ .as_ops = {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 = reiser4_create_object_common,
-+ .delete_object = reiser4_delete_dir_common,
-+ .add_link = reiser4_add_link_common,
++ .create_object = create_object_common,
++ .delete_object = delete_directory_common,
++ .add_link = 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 = reiser4_detach_common_dir,
-+ .bind = reiser4_bind_common_dir,
++ .detach = detach_common_dir,
++ .bind = bind_common_dir,
+ .safelink = safelink_common,
+ .estimate = {
+ .create = estimate_create_common_dir,
+ .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",
+ },
+ .inode_ops = {
+ .readlink = generic_readlink,
-+ .follow_link = reiser4_follow_link_common,
-+ .permission = reiser4_permission_common,
-+ .setattr = reiser4_setattr_common,
-+ .getattr = reiser4_getattr_common
++ .follow_link = follow_link_common,
++ .permission = permission_common,
++ .setattr = setattr_common,
++ .getattr = getattr_common
+ },
+ /* inode->i_fop of symlink is initialized by NULL in setup_inode_ops */
-+ .file_ops = {.owner = NULL},
-+ .as_ops = {.writepage = NULL},
++ .file_ops = {NULL,},
++ .as_ops = {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 = reiser4_create_symlink,
-+ .delete_object = reiser4_delete_object_common,
-+ .add_link = reiser4_add_link_common,
-+ .rem_link = reiser4_rem_link_common,
++ .create_object = create_symlink,
++ .delete_object = delete_object_common,
++ .add_link = add_link_common,
++ .rem_link = rem_link_common,
+ .can_add_link = can_add_link_common,
+ .detach = dummyop,
+ .bind = dummyop,
+ .h = {
+ .type_id = REISER4_FILE_PLUGIN_TYPE,
+ .id = SPECIAL_FILE_PLUGIN_ID,
-+ .groups = (1 << REISER4_SPECIAL_FILE),
+ .pops = &file_plugin_ops,
+ .label = "special",
+ .desc =
+ .linkage = {NULL, NULL}
+ },
+ .inode_ops = {
-+ .permission = reiser4_permission_common,
-+ .setattr = reiser4_setattr_common,
-+ .getattr = reiser4_getattr_common
++ .permission = permission_common,
++ .setattr = setattr_common,
++ .getattr = getattr_common
+ },
+ /* file_ops of special files (sockets, block, char, fifo) are
+ initialized by init_special_inode. */
-+ .file_ops = {.owner = NULL},
-+ .as_ops = {.writepage = NULL},
++ .file_ops = {NULL,},
++ .as_ops = {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 = reiser4_create_object_common,
-+ .delete_object = reiser4_delete_object_common,
-+ .add_link = reiser4_add_link_common,
-+ .rem_link = reiser4_rem_link_common,
++ .create_object = create_object_common,
++ .delete_object = delete_object_common,
++ .add_link = add_link_common,
++ .rem_link = rem_link_common,
+ .owns_item = owns_item_common,
+ .can_add_link = can_add_link_common,
+ .detach = dummyop,
+ .done = wire_done_common
+ }
+ },
-+ [CRYPTCOMPRESS_FILE_PLUGIN_ID] = {
++ [CRC_FILE_PLUGIN_ID] = {
+ .h = {
+ .type_id = REISER4_FILE_PLUGIN_TYPE,
-+ .id = CRYPTCOMPRESS_FILE_PLUGIN_ID,
-+ .groups = (1 << REISER4_REGULAR_FILE),
-+ .pops = &file_plugin_ops,
++ .id = CRC_FILE_PLUGIN_ID,
++ .pops = &cryptcompress_plugin_ops,
+ .label = "cryptcompress",
+ .desc = "cryptcompress file",
+ .linkage = {NULL, NULL}
+ },
+ .inode_ops = {
-+ .permission = reiser4_permission_common,
-+ .setattr = prot_setattr_cryptcompress,
-+ .getattr = reiser4_getattr_common
++ .permission = permission_common,
++ .setattr = setattr_cryptcompress,
++ .getattr = getattr_common
+ },
+ .file_ops = {
+ .llseek = generic_file_llseek,
-+ .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
++ .read = read_cryptcompress,
++ .write = write_cryptcompress,
++ .mmap = mmap_cryptcompress,
++ .release = release_cryptcompress,
++ .fsync = sync_common,
++ .sendfile = sendfile_cryptcompress
+ },
+ .as_ops = {
+ .writepage = reiser4_writepage,
+ .sync_page = block_sync_page,
+ .writepages = writepages_cryptcompress,
+ .set_page_dirty = reiser4_set_page_dirty,
-+ .readpages = readpages_cryptcompress,
++ .readpages = reiser4_readpages,
+ .prepare_write = prepare_write_common,
+ .invalidatepage = reiser4_invalidatepage,
+ .releasepage = reiser4_releasepage
+ .set_plug_in_inode = set_plug_in_inode_common,
+ .adjust_to_parent = adjust_to_parent_cryptcompress,
+ .create_object = create_cryptcompress,
-+ .open_object = open_object_cryptcompress,
-+ .delete_object = delete_object_cryptcompress,
-+ .add_link = reiser4_add_link_common,
-+ .rem_link = reiser4_rem_link_common,
++ .open_object = open_cryptcompress,
++ .delete_object = delete_cryptcompress,
++ .add_link = add_link_common,
++ .rem_link = rem_link_common,
+ .owns_item = owns_item_common,
+ .can_add_link = can_add_link_common,
+ .detach = dummyop,
+ }
+};
+
-+static int change_dir(struct inode *inode,
-+ reiser4_plugin * plugin,
-+ pset_member memb)
++static int change_dir(struct inode *inode, reiser4_plugin * plugin)
+{
+ /* cannot change dir plugin of already existing object */
+ return RETERR(-EINVAL);
+ .linkage = {NULL, NULL}
+ },
+ .inode_ops = {
-+ .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
++ .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
+ },
+ .file_ops = {
-+ .llseek = reiser4_llseek_dir_common,
++ .llseek = llseek_common_dir,
+ .read = generic_read_dir,
-+ .readdir = reiser4_readdir_common,
-+ .release = reiser4_release_dir_common,
-+ .fsync = reiser4_sync_common
++ .readdir = readdir_common,
++ .release = release_dir_common,
++ .fsync = sync_common
+ },
+ .as_ops = {
+ .writepage = bugop,
+ .is_name_acceptable = is_name_acceptable_common,
+ .build_entry_key = build_entry_key_hashed,
+ .build_readdir_key = build_readdir_key_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,
++ .add_entry = add_entry_common,
++ .rem_entry = rem_entry_common,
++ .init = init_common,
++ .done = done_common,
++ .attach = attach_common,
++ .detach = detach_common,
+ .estimate = {
+ .add_entry = estimate_add_entry_common,
+ .rem_entry = estimate_rem_entry_common,
+ .linkage = {NULL, NULL}
+ },
+ .inode_ops = {
-+ .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
++ .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
+ },
+ .file_ops = {
-+ .llseek = reiser4_llseek_dir_common,
++ .llseek = llseek_common_dir,
+ .read = generic_read_dir,
-+ .readdir = reiser4_readdir_common,
-+ .release = reiser4_release_dir_common,
-+ .fsync = reiser4_sync_common
++ .readdir = readdir_common,
++ .release = release_dir_common,
++ .fsync = sync_common
+ },
+ .as_ops = {
+ .writepage = bugop,
+ .is_name_acceptable = is_name_acceptable_common,
+ .build_entry_key = build_entry_key_seekable,
+ .build_readdir_key = build_readdir_key_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,
++ .add_entry = add_entry_common,
++ .rem_entry = rem_entry_common,
++ .init = init_common,
++ .done = done_common,
++ .attach = attach_common,
++ .detach = detach_common,
+ .estimate = {
+ .add_entry = estimate_add_entry_common,
+ .rem_entry = estimate_rem_entry_common,
+ fill-column: 120
+ End:
+*/
-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
+Index: linux-2.6.16/fs/reiser4/plugin/object.h
+===================================================================
+--- /dev/null
++++ linux-2.6.16/fs/reiser4/plugin/object.h
@@ -0,0 +1,121 @@
+/* Copyright 2002, 2003 by Hans Reiser, licensing governed by
+ * reiser4/README */
+#include "../type_safe_hash.h"
+
+/* common implementations of inode operations */
-+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,
++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,
+ const char *linkname);
-+int reiser4_mknod_common(struct inode *parent, struct dentry *dentry,
++int mknod_common(struct inode *parent, struct dentry *dentry,
+ int mode, dev_t rdev);
-+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 *);
++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 *);
+
+/* common implementations of file operations */
-+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);
++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);
+
+/* common implementations of address space operations */
+int prepare_write_common(struct file *, struct page *, unsigned from,
+ struct inode *root);
+int adjust_to_parent_cryptcompress(struct inode *object, struct inode *parent,
+ struct inode *root);
-+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 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 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 reiser4_detach_common_dir(struct inode *child, struct inode *parent);
-+int reiser4_bind_common_dir(struct inode *child, struct inode *parent);
++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 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 *);
+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 reiser4_add_entry_common(struct inode *object, struct dentry *where,
++int add_entry_common(struct inode *object, struct dentry *where,
+ reiser4_object_create_data *, reiser4_dir_entry_desc *);
-+int reiser4_rem_entry_common(struct inode *object, struct dentry *where,
++int rem_entry_common(struct inode *object, struct dentry *where,
+ reiser4_dir_entry_desc *);
-+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);
++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);
+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 *,
+int lookup_sd(struct inode *, znode_lock_mode, coord_t *, lock_handle *,
+ const reiser4_key *, int silent);
+
++
+/* __FS_REISER4_PLUGIN_OBJECT_H__ */
+#endif
+
+ fill-column: 120
+ End:
+*/
-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 @@
+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 @@
+/* Copyright 2001, 2002, 2003 by Hans Reiser, licensing governed by
+ * reiser4/README */
+
+
+ Plugins are classified into several disjoint "types". Plugins
+ belonging to the particular plugin type are termed "instances" of
-+ this type. Existing types are listed by enum reiser4_plugin_type
-+ (see plugin/plugin_header.h)
++ this type. Currently the following types are present:
++
++ . object plugin
++ . hash plugin
++ . tail plugin
++ . perm plugin
++ . item plugin
++ . node layout plugin
+
+NIKITA-FIXME-HANS: update this list, and review this entire comment for currency
+
+ 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
+ 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).
+
+ 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).
++ 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().
+
+ Interface:
+
+ .desc fields of reiser4_plugin_header respectively. It's possible to
+ locate plugin by the pair of labels.
+
-+ Features (not implemented):
++ Features:
+
+ . user-level plugin manipulations:
+ + reiser4("filename/..file_plugin<='audit'");
+ 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".
+
+ . perm:acl
+
-+ . audi---audit plugin intercepting and possibly logging all
++ d audi---audit plugin intercepting and possibly logging all
+ accesses to object. Requires to put stub functions in file_operations
+ in stead of generic_file_*.
+
+ 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"
+
+#include <linux/fs.h> /* for struct super_block */
+
-+/*
-+ * init_plugins - initialize plugin sub-system.
-+ * Just call this once on reiser4 startup.
++/* 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
+ *
+ * Initializes plugin sub-system. It is part of reiser4 module
+ * initialization. For each plugin of each type init method is called and each
+ reiser4_plugin_type type_id;
+
+ for (type_id = 0; type_id < REISER4_PLUGIN_TYPES; ++type_id) {
-+ struct reiser4_plugin_type_data *ptype;
++ reiser4_plugin_type_data *ptype;
+ int i;
+
+ ptype = &plugins[type_id];
+}
+
+/* true if plugin type id is valid */
-+int is_plugin_type_valid(reiser4_plugin_type type)
++int is_type_id_valid(reiser4_plugin_type type_id /* plugin type id */ )
+{
-+ /* "type" is unsigned, so no comparison with 0 is
++ /* "type_id" is unsigned, so no comparison with 0 is
+ necessary */
-+ return (type < REISER4_PLUGIN_TYPES);
++ return (type_id < REISER4_PLUGIN_TYPES);
+}
+
+/* true if plugin id is valid */
-+int is_plugin_id_valid(reiser4_plugin_type type, reiser4_plugin_id id)
++int is_plugin_id_valid(reiser4_plugin_type type_id /* plugin type id */ ,
++ reiser4_plugin_id id /* plugin id */ )
+{
-+ assert("nikita-1653", is_plugin_type_valid(type));
-+ return id < plugins[type].builtin_num;
++ assert("nikita-1653", is_type_id_valid(type_id));
++ return id < plugins[type_id].builtin_num;
+}
+
-+/* return plugin by its @type and @id.
++/* return plugin by its @type_id and @id.
+
+ Both arguments are checked for validness: this is supposed to be called
+ from user-level.
+comment really confused me on the first reading....
+
+*/
-+reiser4_plugin *plugin_by_unsafe_id(reiser4_plugin_type type /* plugin type
-+ * unchecked */,
++reiser4_plugin *plugin_by_unsafe_id(reiser4_plugin_type type_id /* plugin
++ * type id,
++ * unchecked */ ,
+ reiser4_plugin_id id /* plugin id,
-+ * unchecked */)
++ * unchecked */ )
+{
-+ if (is_plugin_type_valid(type)) {
-+ if (is_plugin_id_valid(type, id))
-+ return plugin_at(&plugins[type], id);
++ if (is_type_id_valid(type_id)) {
++ if (is_plugin_id_valid(type_id, id))
++ return plugin_at(&plugins[type_id], id);
+ else
+ /* id out of bounds */
+ warning("nikita-2913",
-+ "Invalid plugin id: [%i:%i]", type, id);
++ "Invalid plugin id: [%i:%i]", type_id, id);
+ } else
+ /* type_id out of bounds */
-+ warning("nikita-2914", "Invalid type_id: %i", type);
++ warning("nikita-2914", "Invalid type_id: %i", type_id);
+ return NULL;
+}
+
+}
+
+/* list of all plugins of given type */
-+struct list_head *get_plugin_list(reiser4_plugin_type type)
++struct list_head *get_plugin_list(reiser4_plugin_type type_id /* plugin type
++ * id */ )
+{
-+ assert("nikita-1056", is_plugin_type_valid(type));
-+ return &plugins[type].plugins_list;
++ 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);
+}
+
-+static void update_pset_mask(reiser4_inode * info, pset_member memb)
++static void update_plugin_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);
+ * if inode is different from the default one, or we are
+ * changing plugin of root directory, update plugin_mask
+ */
-+ if (aset_get(info->pset, memb) !=
-+ aset_get(root->pset, memb) ||
++ if (pset_get(info->pset, memb) != pset_get(root->pset, memb) ||
+ info == root)
+ info->plugin_mask |= (1 << memb);
-+ else
-+ info->plugin_mask &= ~(1 << memb);
+ }
+}
+
-+/* 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)
++int
++grab_plugin_from(struct inode *self, pset_member memb, reiser4_plugin * plug)
+{
-+ reiser4_plugin *plug;
+ reiser4_inode *info;
+ int result = 0;
+
-+ /* Do not grab if initialised already. */
+ info = reiser4_inode_data(self);
-+ 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));
++ if (pset_get(info->pset, memb) == NULL) {
++ result = pset_set(&info->pset, memb, plug);
++ if (result == 0)
++ update_plugin_mask(info, memb);
+ }
+ return result;
+}
+
-+int force_plugin_pset(struct inode *self, pset_member memb, reiser4_plugin * plug)
++int force_plugin(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, memb);
++ result = plug->h.pops->change(self, plug);
+ else
-+ 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);
-+ }
++ result = pset_set(&info->pset, memb, plug);
++ if (result == 0)
++ update_plugin_mask(info, memb);
+ return result;
+}
+
-+struct reiser4_plugin_type_data plugins[REISER4_PLUGIN_TYPES] = {
++reiser4_plugin_type_data plugins[REISER4_PLUGIN_TYPES] = {
+ /* C90 initializers */
+ [REISER4_FILE_PLUGIN_TYPE] = {
+ .type_id = REISER4_FILE_PLUGIN_TYPE,
+ .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)
+ }
+};
+
+ * fill-column: 120
+ * End:
+ */
-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 @@
+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 @@
+/* Copyright 2001, 2002, 2003 by Hans Reiser, licensing governed by reiser4/README */
+
+/* Basic plugin data-types.
+ * 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 */
+ sockets */
+ SPECIAL_FILE_PLUGIN_ID,
+ /* regular cryptcompress file */
-+ CRYPTCOMPRESS_FILE_PLUGIN_ID,
++ CRC_FILE_PLUGIN_ID,
+ /* number of file plugins. Used as size of arrays to hold
+ file plugins. */
+ LAST_FILE_PLUGIN_ID
+typedef struct cipher_plugin {
+ /* generic fields */
+ plugin_header h;
-+ struct crypto_blkcipher * (*alloc) (void);
-+ void (*free) (struct crypto_blkcipher * tfm);
++ struct crypto_tfm * (*alloc) (void);
++ void (*free) (struct crypto_tfm * 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
+ plugin_header h;
+ /* fingerprint size in bytes */
+ int fipsize;
-+ struct crypto_hash * (*alloc) (void);
-+ void (*free) (struct crypto_hash * tfm);
++ struct crypto_tfm * (*alloc) (void);
++ void (*free) (struct crypto_tfm * tfm);
+} digest_plugin;
+
+typedef struct compression_plugin {
+ 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;
+ 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 {
+ 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;
+ 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,
-+ pset_member memb);
++ int (*change) (struct inode * inode, reiser4_plugin * plugin);
+ /* 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,
+
+/* 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 */
+
+typedef enum {
+ NONE_CIPHER_ID,
++ AES_CIPHER_ID,
+ LAST_CIPHER_ID
+} reiser4_cipher_id;
+
+/* builtin compression mode plugins */
+typedef enum {
+ NONE_COMPRESSION_MODE_ID,
-+ LATTD_COMPRESSION_MODE_ID,
-+ ULTIM_COMPRESSION_MODE_ID,
++ COL_8_COMPRESSION_MODE_ID,
++ COL_16_COMPRESSION_MODE_ID,
++ COL_32_COMPRESSION_MODE_ID,
++ COZ_COMPRESSION_MODE_ID,
+ FORCE_COMPRESSION_MODE_ID,
-+ CONVX_COMPRESSION_MODE_ID,
-+ LAST_COMPRESSION_MODE_ID
++ TEST_COMPRESSION_MODE_ID,
++ LAST_COMPRESSION_MODE_ID
+} reiser4_compression_mode_id;
+
+/* builtin cluster plugins */
+ 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 {
+ 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 {
+ /* add here something for non-standard objects you invent, like
+ query for interpolation file etc. */
+
-+ struct reiser4_crypto_info * crypto;
++ crypto_stat_t * crypto;
++ compression_data_t *compression;
++ cluster_data_t *cluster;
+
+ struct inode *parent;
+ struct dentry *dentry;
+#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 ) \
+{ \
+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);
+
+ plugin = list_entry(plugin->h.linkage.next, reiser4_plugin, h.linkage))
+
+
-+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);
++/* 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);
+
+/* defined in fs/reiser4/plugin/object.c */
+extern file_plugin file_plugins[LAST_FILE_PLUGIN_ID];
+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 */
+ fill-column: 120
+ End:
+*/
-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 @@
+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 @@
+/* Copyright 2002, 2003 by Hans Reiser, licensing governed by reiser4/README */
+
+/* plugin header. Data structures required by all plugin types. */
+#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, /* (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_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_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. */
+ 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. */
+ 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. */
-+struct reiser4_plugin_type_data {
++typedef struct reiser4_plugin_type_data {
+ /* internal plugin type identifier. Should coincide with
+ index of this item in plugins[] array. */
+ reiser4_plugin_type type_id;
+ void *builtin;
+ struct list_head plugins_list;
+ size_t size;
-+};
++} reiser4_plugin_type_data;
+
-+extern struct reiser4_plugin_type_data plugins[REISER4_PLUGIN_TYPES];
++extern reiser4_plugin_type_data plugins[REISER4_PLUGIN_TYPES];
+
-+int is_plugin_type_valid(reiser4_plugin_type type);
-+int is_plugin_id_valid(reiser4_plugin_type type, reiser4_plugin_id id);
++int is_type_id_valid(reiser4_plugin_type type_id);
++int is_plugin_id_valid(reiser4_plugin_type type_id, reiser4_plugin_id id);
+
-+static inline reiser4_plugin *plugin_at(struct reiser4_plugin_type_data * ptype,
-+ int i)
++static inline reiser4_plugin *plugin_at(reiser4_plugin_type_data * ptype, int i)
+{
+ char *builtin;
+
+}
+
+/* return plugin by its @type_id and @id */
-+static inline reiser4_plugin *plugin_by_id(reiser4_plugin_type type,
-+ reiser4_plugin_id id)
++static inline reiser4_plugin *plugin_by_id(reiser4_plugin_type type_id
++ /* plugin type id */ ,
++ reiser4_plugin_id id /* plugin id */
++ )
+{
-+ assert("nikita-1651", is_plugin_type_valid(type));
-+ assert("nikita-1652", is_plugin_id_valid(type, id));
-+ return plugin_at(&plugins[type], 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);
+}
+
+extern reiser4_plugin *plugin_by_unsafe_id(reiser4_plugin_type type_id,
+ * fill-column: 79
+ * End:
+ */
-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 @@
+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 @@
+/* Copyright 2001, 2002, 2003 by Hans Reiser, licensing governed by
+ * reiser4/README */
-+/* 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.
++/* 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.
++ *
+ */
+
+#include "../debug.h"
+#include <linux/stddef.h>
+
+/* slab for plugin sets */
-+static struct kmem_cache *plugin_set_slab;
++static kmem_cache_t *plugin_set_slab;
+
+static spinlock_t plugin_set_lock[8] __cacheline_aligned_in_smp = {
+ [0 ... 7] = SPIN_LOCK_UNLOCKED
+ sizeof set1->digest +
+ sizeof set1->compression +
+ sizeof set1->compression_mode +
-+ sizeof set1->cluster +
-+ sizeof set1->create);
++ sizeof set1->cluster + sizeof set1->regular_entry);
+
+ set1 = cast_to(a1);
+ set2 = cast_to(a2);
+ set1->compression == set2->compression &&
+ set1->compression_mode == set2->compression_mode &&
+ set1->cluster == set2->cluster &&
-+ set1->create == set2->create;
++ set1->regular_entry == set2->regular_entry;
+}
+
+#define HASH_FIELD(hash, set, field) \
+ HASH_FIELD(result, set, compression);
+ HASH_FIELD(result, set, compression_mode);
+ HASH_FIELD(result, set, cluster);
-+ HASH_FIELD(result, set, create);
++ HASH_FIELD(result, set, regular_entry);
+ return result & (PS_TABLE_SIZE - 1);
+}
+
+}
+
+/* The hash table definition */
-+#define KMALLOC(size) kmalloc((size), reiser4_ctx_gfp_mask_get())
++#define KMALLOC(size) kmalloc((size), get_gfp_mask())
+#define KFREE(ptr, size) kfree(ptr)
+TYPE_SAFE_HASH_DEFINE(ps, plugin_set, unsigned long, hashval, link, pshash,
+ pseq);
+ .compression = NULL,
+ .compression_mode = NULL,
+ .cluster = NULL,
-+ .create = NULL,
++ .regular_entry = NULL,
+ .link = {NULL}
+};
+
+ twin = ps_hash_find(&ps_table, &replica.hashval);
+ if (unlikely(twin == NULL)) {
+ rcu_read_unlock();
-+ psal = kmem_cache_alloc(plugin_set_slab,
-+ reiser4_ctx_gfp_mask_get());
++ psal = kmem_cache_alloc(plugin_set_slab, get_gfp_mask());
+ if (psal == NULL)
+ return RETERR(-ENOMEM);
+ *psal = replica;
+
+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,
-+ .groups = 0
++ .type = REISER4_FILE_PLUGIN_TYPE
+ },
+ [PSET_DIR] = {
+ .offset = offsetof(plugin_set, dir),
-+ .type = REISER4_DIR_PLUGIN_TYPE,
-+ .groups = 0
++ .type = REISER4_DIR_PLUGIN_TYPE
+ },
+ [PSET_PERM] = {
+ .offset = offsetof(plugin_set, perm),
-+ .type = REISER4_PERM_PLUGIN_TYPE,
-+ .groups = 0
++ .type = REISER4_PERM_PLUGIN_TYPE
+ },
+ [PSET_FORMATTING] = {
+ .offset = offsetof(plugin_set, formatting),
-+ .type = REISER4_FORMATTING_PLUGIN_TYPE,
-+ .groups = 0
++ .type = REISER4_FORMATTING_PLUGIN_TYPE
+ },
+ [PSET_HASH] = {
+ .offset = offsetof(plugin_set, hash),
-+ .type = REISER4_HASH_PLUGIN_TYPE,
-+ .groups = 0
++ .type = REISER4_HASH_PLUGIN_TYPE
+ },
+ [PSET_FIBRATION] = {
+ .offset = offsetof(plugin_set, fibration),
-+ .type = REISER4_FIBRATION_PLUGIN_TYPE,
-+ .groups = 0
++ .type = REISER4_FIBRATION_PLUGIN_TYPE
+ },
+ [PSET_SD] = {
+ .offset = offsetof(plugin_set, sd),
-+ .type = REISER4_ITEM_PLUGIN_TYPE,
-+ .groups = (1 << STAT_DATA_ITEM_TYPE)
++ .type = REISER4_ITEM_PLUGIN_TYPE
+ },
+ [PSET_DIR_ITEM] = {
+ .offset = offsetof(plugin_set, dir_item),
-+ .type = REISER4_ITEM_PLUGIN_TYPE,
-+ .groups = (1 << DIR_ENTRY_ITEM_TYPE)
++ .type = REISER4_ITEM_PLUGIN_TYPE
+ },
+ [PSET_CIPHER] = {
+ .offset = offsetof(plugin_set, cipher),
-+ .type = REISER4_CIPHER_PLUGIN_TYPE,
-+ .groups = 0
++ .type = REISER4_CIPHER_PLUGIN_TYPE
+ },
+ [PSET_DIGEST] = {
+ .offset = offsetof(plugin_set, digest),
-+ .type = REISER4_DIGEST_PLUGIN_TYPE,
-+ .groups = 0
++ .type = REISER4_DIGEST_PLUGIN_TYPE
+ },
+ [PSET_COMPRESSION] = {
+ .offset = offsetof(plugin_set, compression),
-+ .type = REISER4_COMPRESSION_PLUGIN_TYPE,
-+ .groups = 0
++ .type = REISER4_COMPRESSION_PLUGIN_TYPE
+ },
+ [PSET_COMPRESSION_MODE] = {
+ .offset = offsetof(plugin_set, compression_mode),
-+ .type = REISER4_COMPRESSION_MODE_PLUGIN_TYPE,
-+ .groups = 0
++ .type = REISER4_COMPRESSION_MODE_PLUGIN_TYPE
+ },
+ [PSET_CLUSTER] = {
+ .offset = offsetof(plugin_set, cluster),
-+ .type = REISER4_CLUSTER_PLUGIN_TYPE,
-+ .groups = 0
++ .type = REISER4_CLUSTER_PLUGIN_TYPE
+ },
-+ [PSET_CREATE] = {
-+ .offset = offsetof(plugin_set, create),
-+ .type = REISER4_FILE_PLUGIN_TYPE,
-+ .groups = (1 << REISER4_REGULAR_FILE)
++ [PSET_REGULAR_ENTRY] = {
++ .offset = offsetof(plugin_set, regular_entry),
++ .type = REISER4_REGULAR_PLUGIN_TYPE
+ }
+};
+
-+#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) {
++#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));
++
+ 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 plugin set cache and hash table
++ * init_plugin_set - create pset cache and hash table
+ *
+ * Initializes slab cache of plugin_set-s and their hash table. It is part of
+ * reiser4 module initialization.
+ * fill-column: 120
+ * End:
+ */
-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 @@
+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 @@
+/* Copyright 2001, 2002, 2003 by Hans Reiser, licensing governed by reiser4/README */
+
-+/* Reiser4 plugin set definition.
-+ See fs/reiser4/plugin/plugin_set.c for details */
++/* plugin-sets. see fs/reiser4/plugin/plugin_set.c for details */
+
+#if !defined( __PLUGIN_SET_H__ )
+#define __PLUGIN_SET_H__
+ compression_mode_plugin *compression_mode;
+ /* cluster plugin */
+ cluster_plugin *cluster;
-+ /* this specifies file plugin of regular children.
-+ only meaningful for directories */
-+ file_plugin *create;
++ /* plugin of regular child should be created */
++ regular_plugin *regular_entry;
+ 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 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);
++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);
+
+/* __PLUGIN_SET_H__ */
+#endif
+ fill-column: 120
+ End:
+*/
-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
+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
@@ -0,0 +1,4 @@
+obj-$(CONFIG_REISER4_FS) += security_plugins.o
+
+security_plugins-objs := \
+ perm.o
-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 @@
+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 @@
+/* Copyright 2001, 2002, 2003 by Hans Reiser, licensing governed by reiser4/README */
+
+/*
-+ * This file contains implementation of permission plugins.
-+ * See the comments in perm.h
++ * this file contains implementation of permission plugins. Currently, only
++ * RWX_PERM_ID is implemented
+ */
+
+#include "../plugin.h"
+ .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,
+ }
+};
+
+ * fill-column: 79
+ * End:
+ */
-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 @@
+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 @@
+/* Copyright 2001, 2002, 2003 by Hans Reiser, licensing governed by reiser4/README */
+
+/* Perm (short for "permissions") plugins common stuff. */
+#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
+
-+/* 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. */
++ 2. obtaining acl from the tree and inspecting it
+
-+/* 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 */
++ 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. */
+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;
+ fill-column: 120
+ End:
+*/
-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 @@
+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 @@
+/* Copyright 2001, 2002, 2003 by Hans Reiser, licensing governed by reiser4/README */
+
+#include "../../debug.h"
+
+#include <linux/types.h>
+#include <linux/fs.h> /* for struct super_block */
-+#include <linux/mutex.h>
++#include <asm/semaphore.h>
++#include <linux/vmalloc.h>
+#include <asm/div64.h>
+
+/* Proposed (but discarded) optimization: dynamic loading/unloading of bitmap
+/* Block allocation/deallocation are done through special bitmap objects which
+ are allocated in an array at fs mount. */
+struct bitmap_node {
-+ struct mutex mutex; /* long term lock object */
++ struct semaphore sema; /* long term lock object */
+
+ jnode *wjnode; /* j-nodes for WORKING ... */
+ jnode *cjnode; /* ... and COMMIT bitmap blocks */
+ 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;
+
+ assert("zam-455", start != NULL);
+ assert("zam-437", *start != 0);
-+ assert("zam-541", !reiser4_blocknr_is_fake(start));
++ assert("zam-541", !blocknr_is_fake(start));
+ assert("zam-441", *start < reiser4_block_count(sb));
+
+ if (len != NULL) {
+{
+ memset(bnode, 0, sizeof(struct bitmap_node));
+
-+ mutex_init(&bnode->mutex);
++ sema_init(&bnode->sema, 1);
+ atomic_set(&bnode->loaded, 0);
+}
+
+}
+
+/* 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;
+ jnode *cjnode;
+ jnode *wjnode;
+
-+ assert("nikita-3040", reiser4_schedulable());
++ assert("nikita-3040", 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
+ if (atomic_read(&bnode->loaded)) {
+ /* bitmap is already loaded, nothing to do */
+ check_bnode_loaded(bnode);
-+ mutex_lock(&bnode->mutex);
++ down(&bnode->sema);
+ assert("nikita-2827", atomic_read(&bnode->loaded));
+ return 0;
+ }
+
+ ret = prepare_bnode(bnode, &cjnode, &wjnode);
+ if (ret == 0) {
-+ mutex_lock(&bnode->mutex);
++ down(&bnode->sema);
+
+ if (!atomic_read(&bnode->loaded)) {
+ assert("nikita-2822", cjnode != NULL);
+ atomic_set(&bnode->loaded, 1);
+ /* working bitmap is initialized by on-disk
+ * commit bitmap. This should be performed
-+ * under mutex. */
++ * under semaphore. */
+ memcpy(bnode_working_data(bnode),
+ bnode_commit_data(bnode),
+ bmap_size(current_blocksize));
-+ } else
-+ mutex_unlock(&bnode->mutex);
++ } else {
++ up(&bnode->sema);
++ }
+ } else
+ /* race: someone already loaded bitmap while we were
+ * busy initializing data. */
+static void release_and_unlock_bnode(struct bitmap_node *bnode)
+{
+ check_bnode_loaded(bnode);
-+ mutex_unlock(&bnode->mutex);
++ up(&bnode->sema);
+}
+
+/* This function does all block allocation work but only for one bitmap
+}
+
+/* plugin->u.space_allocator.alloc_blocks() */
-+int reiser4_alloc_blocks_bitmap(reiser4_space_allocator * allocator,
-+ reiser4_blocknr_hint * hint, int needed,
-+ reiser4_block_nr * start, reiser4_block_nr * len)
++int
++alloc_blocks_bitmap(reiser4_space_allocator * allocator UNUSED_ARG,
++ 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);
+ 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 reiser4_dealloc_blocks_bitmap(reiser4_space_allocator * allocator,
-+ reiser4_block_nr start, reiser4_block_nr len)
++void
++dealloc_blocks_bitmap(reiser4_space_allocator * allocator UNUSED_ARG,
++ reiser4_block_nr start, reiser4_block_nr len)
+{
+ struct super_block *super = reiser4_get_current_sb();
+
+}
+
+/* plugin->u.space_allocator.check_blocks(). */
-+void reiser4_check_blocks_bitmap(const reiser4_block_nr * start,
-+ const reiser4_block_nr * len, int desired)
++void
++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();
+ only one transaction can be committed a time, therefore it is safe to access
+ some global variables without any locking */
+
-+int reiser4_pre_commit_hook_bitmap(void)
++int pre_commit_hook_bitmap(void)
+{
+ struct super_block *super = reiser4_get_current_sb();
+ txn_atom *atom;
+
+ assert("zam-559", !JF_ISSET(node, JNODE_OVRWR));
+ assert("zam-460",
-+ !reiser4_blocknr_is_fake(&node->blocknr));
++ !blocknr_is_fake(&node->blocknr));
+
+ parse_blocknr(&node->blocknr, &bmap, &offset);
+ bn = get_bnode(super, bmap);
+
+/* plugin->u.space_allocator.init_allocator
+ constructor of reiser4_space_allocator object. It is called on fs mount */
-+int reiser4_init_allocator_bitmap(reiser4_space_allocator * allocator,
-+ struct super_block *super, void *arg)
++int
++init_allocator_bitmap(reiser4_space_allocator * allocator,
++ struct super_block *super, void *arg UNUSED_ARG)
+{
+ struct bitmap_allocator_data *data = NULL;
+ bmap_nr_t bitmap_blocks_nr;
+ bmap_nr_t i;
+
-+ assert("nikita-3039", reiser4_schedulable());
++ assert("nikita-3039", schedulable());
+
+ /* getting memory for bitmap allocator private data holder */
+ data =
-+ kmalloc(sizeof(struct bitmap_allocator_data),
-+ reiser4_ctx_gfp_mask_get());
++ kmalloc(sizeof(struct bitmap_allocator_data), GFP_KERNEL);
+
+ if (data == NULL)
+ return RETERR(-ENOMEM);
+ 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 = reiser4_vmalloc(sizeof(struct bitmap_node) * bitmap_blocks_nr);
++ data->bitmap = vmalloc(sizeof(struct bitmap_node) * bitmap_blocks_nr);
+ if (data->bitmap == NULL) {
+ kfree(data);
+ return RETERR(-ENOMEM);
+ bnode = data->bitmap + i;
+ ret = load_and_lock_bnode(bnode);
+ if (ret) {
-+ reiser4_destroy_allocator_bitmap(allocator,
-+ super);
++ destroy_allocator_bitmap(allocator, super);
+ return ret;
+ }
+ release_and_unlock_bnode(bnode);
+
+/* plugin->u.space_allocator.destroy_allocator
+ destructor. It is called on fs unmount */
-+int reiser4_destroy_allocator_bitmap(reiser4_space_allocator * allocator,
-+ struct super_block *super)
++int
++destroy_allocator_bitmap(reiser4_space_allocator * allocator,
++ struct super_block *super)
+{
+ bmap_nr_t bitmap_blocks_nr;
+ bmap_nr_t i;
+ for (i = 0; i < bitmap_blocks_nr; i++) {
+ struct bitmap_node *bnode = data->bitmap + i;
+
-+ mutex_lock(&bnode->mutex);
++ down(&bnode->sema);
+
+#if REISER4_DEBUG
+ if (atomic_read(&bnode->loaded)) {
+ }
+#endif
+ done_bnode(bnode);
-+ mutex_unlock(&bnode->mutex);
++ up(&bnode->sema);
+ }
+
+ vfree(data->bitmap);
+}
+
+/*
-+ * 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
++ 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
@@ -0,0 +1,47 @@
+/* Copyright 2002, 2003 by Hans Reiser, licensing governed by reiser4/README */
+
+/* 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 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)
++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)
+
+typedef __u64 bmap_nr_t;
+typedef __u32 bmap_off_t;
+ scroll-step: 1
+ End:
+*/
-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
+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
@@ -0,0 +1,80 @@
+/* Copyright 2002, 2003 by Hans Reiser, licensing governed by reiser4/README */
+
+ \
+static inline int sa_init_allocator (reiser4_space_allocator * al, struct super_block *s, void * opaque) \
+{ \
-+ return reiser4_init_allocator_##allocator (al, s, opaque); \
++ return init_allocator_##allocator (al, s, opaque); \
+} \
+ \
+static inline void sa_destroy_allocator (reiser4_space_allocator *al, struct super_block *s) \
+{ \
-+ reiser4_destroy_allocator_##allocator (al, s); \
++ 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 reiser4_alloc_blocks_##allocator (al, hint, needed, start, len); \
++ return 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) \
+{ \
-+ reiser4_dealloc_blocks_##allocator (al, start, len); \
++ dealloc_blocks_##allocator (al, start, len); \
+} \
+ \
+static inline void sa_check_blocks (const reiser4_block_nr * start, const reiser4_block_nr * end, int desired) \
+{ \
-+ reiser4_check_blocks_##allocator (start, end, desired); \
++ check_blocks_##allocator (start, end, desired); \
+} \
+ \
+static inline void sa_pre_commit_hook (void) \
+{ \
-+ reiser4_pre_commit_hook_##allocator (); \
++ pre_commit_hook_##allocator (); \
+} \
+ \
+static inline void sa_post_commit_hook (void) \
+{ \
-+ reiser4_post_commit_hook_##allocator (); \
++ post_commit_hook_##allocator (); \
+} \
+ \
+static inline void sa_post_write_back_hook (void) \
+{ \
-+ reiser4_post_write_back_hook_##allocator(); \
++ post_write_back_hook_##allocator(); \
+} \
+ \
+static inline void sa_print_info(const char * prefix, reiser4_space_allocator * al) \
+{ \
-+ reiser4_print_info_##allocator (prefix, al); \
++ print_info_##allocator (prefix, al); \
+}
+
+DEF_SPACE_ALLOCATOR(bitmap)
+ scroll-step: 1
+ End:
+*/
-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
+Index: linux-2.6.16/fs/reiser4/plugin/tail_policy.c
+===================================================================
+--- /dev/null
++++ linux-2.6.16/fs/reiser4/plugin/tail_policy.c
@@ -0,0 +1,113 @@
+/* Copyright 2001, 2002, 2003 by Hans Reiser, licensing governed by
+ * reiser4/README */
+ * fill-column: 79
+ * End:
+ */
-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 @@
+Index: linux-2.6.16/fs/reiser4/pool.c
+===================================================================
+--- /dev/null
++++ linux-2.6.16/fs/reiser4/pool.c
+@@ -0,0 +1,236 @@
+/* Copyright 2001, 2002, 2003 by Hans Reiser, licensing governed by
+ * reiser4/README */
+
+ functions in the style of tslist/tshash, i.e., make them unreadable, but
+ type-safe.
+
++
+*/
+
+#include "debug.h"
+#include <linux/types.h>
+#include <linux/err.h>
+
-+/* initialize new pool object @h */
-+static void reiser4_init_pool_obj(struct reiser4_pool_header * h)
++/* initialize new pool object */
++static void reiser4_init_pool_obj(reiser4_pool_header * h /* pool object to
++ * initialize */ )
+{
+ INIT_LIST_HEAD(&h->usage_linkage);
+ INIT_LIST_HEAD(&h->level_linkage);
+}
+
+/* initialize new pool */
-+void reiser4_init_pool(struct reiser4_pool * pool /* pool to initialize */ ,
++void reiser4_init_pool(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 */ )
+{
-+ struct reiser4_pool_header *h;
++ reiser4_pool_header *h;
+ int i;
+
+ assert("nikita-955", pool != NULL);
+ INIT_LIST_HEAD(&pool->extra);
+ memset(data, 0, obj_size * num_of_objs);
+ for (i = 0; i < num_of_objs; ++i) {
-+ h = (struct reiser4_pool_header *) (data + i * obj_size);
++ h = (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);
+ allocated objects.
+
+*/
-+void reiser4_done_pool(struct reiser4_pool * pool UNUSED_ARG)
++void reiser4_done_pool(reiser4_pool * pool UNUSED_ARG /* pool to destroy */ )
+{
+}
+
-+/* 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(struct reiser4_pool * pool)
++static void *reiser4_pool_alloc(reiser4_pool * pool /* pool to allocate object
++ * from */ )
+{
-+ struct reiser4_pool_header *result;
++ reiser4_pool_header *result;
+
+ assert("nikita-959", pool != NULL);
+
+ linkage = pool->free.next;
+ list_del(linkage);
+ INIT_LIST_HEAD(linkage);
-+ result = list_entry(linkage, struct reiser4_pool_header,
-+ usage_linkage);
++ result = list_entry(linkage, 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, reiser4_ctx_gfp_mask_get());
++ result = kmalloc(pool->obj_size, get_gfp_mask());
+ if (result != 0) {
+ reiser4_init_pool_obj(result);
+ list_add(&result->extra_linkage, &pool->extra);
+}
+
+/* return object back to the pool */
-+void reiser4_pool_free(struct reiser4_pool * pool,
-+ struct reiser4_pool_header * h)
++void reiser4_pool_free(reiser4_pool * pool, reiser4_pool_header * h /* pool to return object back
++ * into */ )
+{
+ assert("nikita-961", h != NULL);
+ assert("nikita-962", pool != NULL);
+ 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
+*/
-+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;
++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;
+
+ assert("nikita-972", pool != NULL);
+
+ fill-column: 120
+ End:
+*/
-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 @@
+Index: linux-2.6.16/fs/reiser4/pool.h
+===================================================================
+--- /dev/null
++++ linux-2.6.16/fs/reiser4/pool.h
+@@ -0,0 +1,54 @@
+/* Copyright 2001, 2002, 2003 by Hans Reiser, licensing governed by reiser4/README */
+
+/* Fast pool allocation */
+
+#include <linux/types.h>
+
-+struct reiser4_pool {
++typedef 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;
+
-+struct reiser4_pool_header {
++typedef 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,
+
+/* pool manipulation functions */
+
-+extern void reiser4_init_pool(struct reiser4_pool * pool, size_t obj_size,
++extern void reiser4_init_pool(reiser4_pool * pool, size_t obj_size,
+ int num_of_objs, char *data);
-+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);
++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);
+
+/* __REISER4_POOL_H__ */
+#endif
+ fill-column: 120
+ End:
+*/
-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
+Index: linux-2.6.16/fs/reiser4/readahead.c
+===================================================================
+--- /dev/null
++++ linux-2.6.16/fs/reiser4/readahead.c
@@ -0,0 +1,138 @@
+/* Copyright 2001, 2002, 2003 by Hans Reiser, licensing governed by
+ * reiser4/README */
+
+#include <linux/swap.h> /* for totalram_pages */
+
-+void reiser4_init_ra_info(ra_info_t * rai)
++void init_ra_info(ra_info_t * rai)
+{
-+ rai->key_to_stop = *reiser4_min_key();
++ rai->key_to_stop = *min_key();
+}
+
+/* global formatted node readahead parameter. It can be set by mount option -o readahead:NUM:1 */
+/* start read for @node and for a few of its right neighbors */
+void formatted_readahead(znode * node, ra_info_t * info)
+{
-+ struct formatted_ra_params *ra_params;
++ ra_params_t *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 (reiser4_blocknr_is_fake(znode_get_block(node)))
++ if (blocknr_is_fake(znode_get_block(node)))
+ return;
+
+ ra_params = get_current_super_ra_params();
+ break;
+
+ nextblk = znode_get_block(next_lh.node);
-+ if (reiser4_blocknr_is_fake(nextblk) ||
++ if (blocknr_is_fake(nextblk) ||
+ (ra_adjacent_only(ra_params->flags)
+ && *nextblk != *znode_get_block(cur) + 1)) {
+ break;
+ * 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(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()));
++ 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()));
+}
+
+/*
+ fill-column: 80
+ End:
+*/
-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 @@
+Index: linux-2.6.16/fs/reiser4/readahead.h
+===================================================================
+--- /dev/null
++++ linux-2.6.16/fs/reiser4/readahead.h
+@@ -0,0 +1,48 @@
+/* Copyright 2001, 2002, 2003 by Hans Reiser, licensing governed by reiser4/README */
+
+#ifndef __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 */
-+struct formatted_ra_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 */
++typedef struct formatted_read_ahead_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 reiser4_init_ra_info(ra_info_t * rai);
++void init_ra_info(ra_info_t * rai);
+
+struct reiser4_file_ra_state {
+ loff_t start; /* Current window */
+ fill-column: 120
+ End:
+*/
-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 @@
+Index: linux-2.6.16/fs/reiser4/reiser4.h
+===================================================================
+--- /dev/null
++++ linux-2.6.16/fs/reiser4/reiser4.h
+@@ -0,0 +1,276 @@
+/* Copyright 2001, 2002, 2003 by Hans Reiser, licensing governed by
+ * reiser4/README */
+
+#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 <linux/hardirq.h>
++#include <asm/hardirq.h>
+#include <linux/sched.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
+ fill-column: 120
+ End:
+*/
-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 @@
+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 @@
+/* Copyright 2003, 2004 by Hans Reiser, licensing governed by
+ * reiser4/README */
+
+ int result;
+
+ grab_space_enable();
-+ /* The sbinfo->delete_mutex can be taken here.
++ /* The sbinfo->delete semaphore can be taken here.
+ * safe_link_release() should be called before leaving reiser4
+ * context. */
+ result =
+ length += sizeof(sl.size);
+ put_unaligned(cpu_to_le64(inode->i_size), &sl.size);
+ }
-+ tree = reiser4_tree_by_inode(inode);
++ tree = tree_by_inode(inode);
+ build_link_key(tree, get_inode_oid(inode), link, &key);
+
+ result = store_black_box(tree, &key, &sl, length);
+ * in-memory structure to keep information extracted from safe-link. This is
+ * used to iterate over all safe-links.
+ */
-+struct safe_link_context {
++typedef struct {
+ 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,
-+ struct safe_link_context * ctx)
++static void safe_link_iter_begin(reiser4_tree * tree, 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(reiser4_max_key()));
-+ set_key_offset(&ctx->key, get_key_offset(reiser4_max_key()));
++ set_key_objectid(&ctx->key, get_key_objectid(max_key()));
++ set_key_offset(&ctx->key, get_key_offset(max_key()));
+}
+
+/*
+ * return next safe-link.
+ */
-+static int safe_link_iter_next(struct safe_link_context * ctx)
++static int safe_link_iter_next(safe_link_context * ctx)
+{
+ int result;
+ safelink_t sl;
+/*
+ * check are there any more safe-links left in the tree.
+ */
-+static int safe_link_iter_finished(struct safe_link_context * ctx)
++static int safe_link_iter_finished(safe_link_context * ctx)
+{
+ return get_key_locality(&ctx->key) != safe_link_locality(ctx->tree);
+}
+/*
+ * finish safe-link iteration.
+ */
-+static void safe_link_iter_end(struct safe_link_context * ctx)
++static void safe_link_iter_end(safe_link_context * ctx)
+{
+ /* nothing special */
+}
+ assert("nikita-3428", fplug != NULL);
+ assert("", oid == get_inode_oid(inode));
+ if (fplug->safelink != NULL) {
-+ /* reiser4_txn_restart_current is not necessary because
++ /* txn_restart_current is not necessary because
+ * mounting is signle thread. However, without it
+ * deadlock detection code will complain (see
+ * nikita-3361). */
-+ reiser4_txn_restart_current();
++ txn_restart_current();
+ result = fplug->safelink(inode, link, size);
+ } else {
+ warning("nikita-3430",
+ "Cannot handle safelink for %lli",
+ (unsigned long long)oid);
-+ reiser4_print_key("key", sdkey);
++ print_key("key", sdkey);
+ result = 0;
+ }
+ if (result != 0) {
+ reiser4_iget_complete(inode);
+ iput(inode);
+ if (result == 0) {
-+ result = safe_link_grab(reiser4_get_tree(super), BA_CAN_COMMIT);
++ result = safe_link_grab(get_tree(super), BA_CAN_COMMIT);
+ if (result == 0)
+ result =
-+ safe_link_del(reiser4_get_tree(super), oid, link);
-+ safe_link_release(reiser4_get_tree(super));
++ safe_link_del(get_tree(super), oid, link);
++ safe_link_release(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)
-+ reiser4_txn_restart_current();
++ txn_restart_current();
+ }
+ } else
+ result = PTR_ERR(inode);
+ */
+int process_safelinks(struct super_block *super)
+{
-+ struct safe_link_context ctx;
++ safe_link_context ctx;
+ int result;
+
+ if (rofs_super(super))
+ scroll-step: 1
+ End:
+*/
-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
+Index: linux-2.6.16/fs/reiser4/safe_link.h
+===================================================================
+--- /dev/null
++++ linux-2.6.16/fs/reiser4/safe_link.h
@@ -0,0 +1,29 @@
+/* Copyright 2003 by Hans Reiser, licensing governed by
+ * reiser4/README */
+ fill-column: 120
+ End:
+*/
-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 @@
+Index: linux-2.6.16/fs/reiser4/seal.c
+===================================================================
+--- /dev/null
++++ linux-2.6.16/fs/reiser4/seal.c
+@@ -0,0 +1,217 @@
+/* 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
+ 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
-+ 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.
++ 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
+
+/* initialise seal. This can be called several times on the same seal. @coord
+ and @key can be NULL. */
-+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 */ )
++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 */ )
+{
+ assert("nikita-1886", seal != NULL);
+ memset(seal, 0, sizeof *seal);
+}
+
+/* finish with seal */
-+void reiser4_seal_done(seal_t * seal /* seal to clear */ )
++void seal_done(seal_t * seal /* seal to clear */ )
+{
+ assert("nikita-1887", seal != NULL);
+ seal->version = 0;
+}
+
+/* true if seal was initialised */
-+int reiser4_seal_is_set(const seal_t * seal /* seal to query */ )
++int 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 reiser4_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 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 */ )
+}
+#endif
+
-+/* this is used by reiser4_seal_validate. It accepts return value of
++/* this is used by 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,
-+ * 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. */
++ * 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;
+
+ If seal was burned, or broken irreparably, return -E_REPEAT.
+
-+ NOTE-NIKITA currently reiser4_seal_validate() returns -E_REPEAT if key we are
++ NOTE-NIKITA currently 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 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 */)
++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 */ )
+{
+ znode *node;
+ int result;
+
+ assert("nikita-1889", seal != NULL);
-+ assert("nikita-1881", reiser4_seal_is_set(seal));
++ assert("nikita-1881", seal_is_set(seal));
+ assert("nikita-1882", key != NULL);
+ assert("nikita-1883", coord != NULL);
+ assert("nikita-1884", lh != NULL);
+ scroll-step: 1
+ End:
+*/
-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
+Index: linux-2.6.16/fs/reiser4/seal.h
+===================================================================
+--- /dev/null
++++ linux-2.6.16/fs/reiser4/seal.h
@@ -0,0 +1,49 @@
+/* Copyright 2002, 2003 by Hans Reiser, licensing governed by reiser4/README */
+
+#endif
+} seal_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 *,
++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 *,
+ const reiser4_key *, lock_handle *,
+ znode_lock_mode mode, znode_lock_request request);
+
+ fill-column: 120
+ End:
+*/
-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
+Index: linux-2.6.16/fs/reiser4/search.c
+===================================================================
+--- /dev/null
++++ linux-2.6.16/fs/reiser4/search.c
@@ -0,0 +1,1611 @@
+/* Copyright 2001, 2002, 2003 by Hans Reiser, licensing governed by
+ * reiser4/README */
+ assert("nikita-346", cache != NULL);
+
+ cache->slot =
-+ kmalloc(sizeof(cbk_cache_slot) * cache->nr_slots,
-+ reiser4_ctx_gfp_mask_get());
++ kmalloc(sizeof(cbk_cache_slot) * cache->nr_slots, GFP_KERNEL);
+ if (cache->slot == NULL)
+ return RETERR(-ENOMEM);
+
+ &(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)
+ init_lh(lh);
+ init_lh(&parent_lh);
+
-+ assert("nikita-3023", reiser4_schedulable());
++ assert("nikita-3023", schedulable());
+
+ assert("nikita-353", tree != NULL);
+ assert("nikita-354", key != NULL);
+
+/* like coord_by_key(), but starts traversal from vroot of @object rather than
+ * from tree root. */
-+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)
++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)
+{
+ cbk_handle handle;
+ lock_handle parent_lh;
+ init_lh(lh);
+ init_lh(&parent_lh);
+
-+ assert("nikita-3023", reiser4_schedulable());
++ assert("nikita-3023", schedulable());
+
+ assert("nikita-354", key != NULL);
+ assert("nikita-355", coord != NULL);
+ assert("nikita-2104", lock_stack_isclean(get_current_lock_stack()));
+
+ cbk_pack(&handle,
-+ object != NULL ? reiser4_tree_by_inode(object) : current_tree,
++ object != NULL ? tree_by_inode(object) : current_tree,
+ key,
+ coord,
+ lh,
+ return result;
+}
+
-+/* lookup by cbk_handle. Common part of coord_by_key() and
-+ reiser4_object_lookup(). */
++/* lookup by cbk_handle. Common part of coord_by_key() and object_lookup(). */
+static lookup_result coord_by_handle(cbk_handle * handle)
+{
+ /*
+
+ Error code, or last actor return value is returned.
+
-+ This is used by plugin/dir/hashe_dir.c:reiser4_find_entry() to move through
++ This is used by plugin/dir/hashe_dir.c:find_entry() to move through
+ sequence of entries with identical keys and alikes.
+*/
-+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 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;
+
+ }
+ }
+ }
-+ }
++ } else
++ /* long-term locking failed. Restart. */
++ ;
+
+ zput(vroot);
+
+ /* loop for restarts */
+ restart:
+
-+ assert("nikita-3024", reiser4_schedulable());
++ assert("nikita-3024", schedulable());
+
+ h->result = CBK_COORD_FOUND;
+ /* connect_znode() needs it */
-+ h->ld_key = *reiser4_min_key();
-+ h->rd_key = *reiser4_max_key();
++ h->ld_key = *min_key();
++ h->rd_key = *max_key();
+ h->flags |= CBK_DKSET;
+ h->error = NULL;
+
+ IS_POW(iterations))) {
+ warning("nikita-1481", "Too many iterations: %i",
+ iterations);
-+ reiser4_print_key("key", h->key);
++ print_key("key", h->key);
+ ++iterations;
+ } else if (unlikely(iterations > REISER4_MAX_CBK_ITERATIONS)) {
+ h->error =
+ /* deadlock avoidance is normal case. */
+ if (h->result != -E_DEADLOCK)
+ ++iterations;
-+ reiser4_preempt_point();
++ preempt_point();
+ goto restart;
+ }
+ }
+ 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);
-+ reiser4_print_key("key", h->key);
++ print_key("key", h->key);
+ print_coord_content("coord", h->coord);
+ }
+ /* `unlikely' error case */
+ reiser4_key key;
+ znode *active;
+
-+ assert("nikita-3025", reiser4_schedulable());
++ assert("nikita-3025", schedulable());
+
+ /* acquire reference to @active node */
+ active =
-+ zget(h->tree, &h->block, h->parent_lh->node, h->level,
-+ reiser4_ctx_gfp_mask_get());
++ zget(h->tree, &h->block, h->parent_lh->node, h->level, get_gfp_mask());
+
+ if (IS_ERR(active)) {
+ h->result = PTR_ERR(active);
+ if (ldkeyset && !node_is_empty(active) &&
+ !keyeq(leftmost_key_in_node(active, &key), &ldkey)) {
+ warning("vs-3533", "Keys are inconsistent. Fsck?");
-+ reiser4_print_key("inparent", &ldkey);
-+ reiser4_print_key("inchild", &key);
++ print_key("inparent", &ldkey);
++ print_key("inchild", &key);
+ h->result = RETERR(-EIO);
+ zrelse(active);
+ return LOOKUP_DONE;
+ * are rechecked under dk lock below.
+ */
+ if (znode_get_level(node) == level &&
-+ /* reiser4_min_key < key < reiser4_max_key */
++ /* min_key < key < max_key */
+ znode_contains_key_strict(node, key, isunique)) {
+ zref(node);
+ result = 0;
+ item_body_by_coord(p), item_length_by_coord(p));
+ if (znode_is_loaded(p->node)) {
+ item_key_by_coord(p, &key);
-+ reiser4_print_key(prefix, &key);
++ print_key(prefix, &key);
+ }
+}
+
+
+ if (block == NULL)
+ sprintf(address, "null");
-+ else if (reiser4_blocknr_is_fake(block))
++ else if (blocknr_is_fake(block))
+ sprintf(address, "%llx", (unsigned long long)(*block));
+ else
+ sprintf(address, "%llu", (unsigned long long)(*block));
+ scroll-step: 1
+ End:
+*/
-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 @@
+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 @@
+/* Copyright 2001, 2002, 2003 by Hans Reiser, licensing governed by
+ * reiser4/README */
+
+ struct bio *bio;
+ struct page *page;
+
++
+ get_super_private(sb)->status_page = NULL;
+ get_super_private(sb)->status_bio = NULL;
+
-+ page = alloc_pages(reiser4_ctx_gfp_mask_get(), 0);
++ page = alloc_pages(GFP_KERNEL, 0);
+ if (!page)
+ return -ENOMEM;
+
-+ bio = bio_alloc(reiser4_ctx_gfp_mask_get(), 1);
++ bio = bio_alloc(GFP_KERNEL, 1);
+ if (bio != NULL) {
+ bio->bi_sector = block * (sb->s_blocksize >> 9);
+ bio->bi_bdev = sb->s_bdev;
+ }
+ lock_page(page);
+ submit_bio(READ, bio);
-+ blk_run_address_space(reiser4_get_super_fake(sb)->i_mapping);
++ blk_run_address_space(get_super_fake(sb)->i_mapping);
+ wait_on_page_locked(page);
+ if (!PageUptodate(page)) {
+ warning("green-2007",
+ 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(reiser4_get_super_fake(sb)->i_mapping);
++ blk_run_address_space(get_super_fake(sb)->i_mapping);
+ return 0; // We do not wait for io to finish.
+}
+
+ get_super_private(sb)->status_bio = NULL;
+ return 0;
+}
-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
+Index: linux-2.6.16/fs/reiser4/status_flags.h
+===================================================================
+--- /dev/null
++++ linux-2.6.16/fs/reiser4/status_flags.h
@@ -0,0 +1,43 @@
+/* Copyright 2001, 2002, 2003 by Hans Reiser, licensing governed by
+ * reiser4/README */
+int reiser4_status_finish(void);
+
+#endif
-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 @@
+Index: linux-2.6.16/fs/reiser4/super.c
+===================================================================
+--- /dev/null
++++ linux-2.6.16/fs/reiser4/super.c
+@@ -0,0 +1,313 @@
+/* Copyright 2001, 2002, 2003, 2004 by Hans Reiser, licensing governed by
+ * reiser4/README */
+
+#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);
+}
+
+/* Return reiser4 fstype: value that is returned in ->f_type field by statfs() */
-+long reiser4_statfs_type(const struct super_block *super UNUSED_ARG)
++long statfs_type(const struct super_block *super UNUSED_ARG /* super block
++ * queried */ )
+{
+ assert("nikita-448", super != NULL);
+ assert("nikita-449", is_reiser4_super(super));
+ return get_super_private(super)->block_count;
+}
+
-+#if REISER4_DEBUG
+/*
+ * number of blocks in the current file system
+ */
+{
+ 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)
+ return get_super_private(super)->blocks_grabbed;
+}
+
-+__u64 reiser4_flush_reserved(const struct super_block * super)
++__u64 flush_reserved(const struct super_block * super)
+{
+ assert("vpf-285", super != NULL);
+ assert("vpf-286", is_reiser4_super(super));
+}
+
+/* space allocator used by this file system */
-+reiser4_space_allocator * reiser4_get_space_allocator(const struct super_block
-+ *super)
++reiser4_space_allocator *get_space_allocator(const struct super_block * super)
+{
+ assert("nikita-1965", super != NULL);
+ assert("nikita-1966", is_reiser4_super(super));
+}
+
+/* return fake inode used to bind formatted nodes in the page cache */
-+struct inode *reiser4_get_super_fake(const struct super_block *super /* super block
++struct inode *get_super_fake(const struct super_block *super /* super block
+ queried */ )
+{
+ assert("nikita-1757", super != NULL);
+}
+
+/* return fake inode used to bind copied on capture nodes in the page cache */
-+struct inode *reiser4_get_cc_fake(const struct super_block *super /* super block
++struct inode *get_cc_fake(const struct super_block *super /* super block
+ queried */ )
+{
+ assert("nikita-1757", super != NULL);
+}
+
+/* return fake inode used to bind bitmaps and journlal heads */
-+struct inode *reiser4_get_bitmap_fake(const struct super_block *super)
++struct inode *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 *reiser4_get_tree(const struct super_block * super /* super block
++reiser4_tree *get_tree(const struct super_block * super /* super block
+ * queried */ )
+{
+ assert("nikita-460", super != NULL);
+ assert("nikita-2957", super != NULL);
+ assert("nikita-2958", blk != NULL);
+
-+ if (reiser4_blocknr_is_fake(blk))
++ if (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
+ */
+{
+ return reiser4_blocknr_is_sane_for(reiser4_get_current_sb(), blk);
+}
-+#endif /* REISER4_DEBUG */
+
+/* Make Linus happy.
+ Local variables:
+ fill-column: 120
+ End:
+*/
-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 @@
+Index: linux-2.6.16/fs/reiser4/super.h
+===================================================================
+--- /dev/null
++++ linux-2.6.16/fs/reiser4/super.h
+@@ -0,0 +1,468 @@
+/* Copyright 2001, 2002, 2003, 2004 by Hans Reiser, licensing governed by
+ * reiser4/README */
+
+/*
+ * Flush algorithms parameters.
+ */
-+struct flush_params {
++typedef struct {
+ unsigned relocate_threshold;
+ unsigned relocate_distance;
+ unsigned written_threshold;
+ unsigned scan_maxnodes;
-+};
++} flush_params;
+
+typedef enum {
+ /*
+ 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.
+ */
-+struct object_ops {
++typedef struct object_ops {
+ struct super_operations super;
+ struct dentry_operations dentry;
+ struct export_operations export;
-+};
++} object_ops;
+
+/* reiser4-specific part of super block
+
+
+ ->last_committed_tx
+
-+ is protected by ->tmgr.commit_mutex
++ is protected by ->tmgr.commit_semaphore
+
+ Invariants involving this data-type:
+
+ /* 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;
+
+ unsigned long optimal_io_size;
+
+ /* parameters for the flush algorithm */
-+ struct flush_params flush;
++ flush_params flush;
+
+ /* pointers to jnodes for journal header and footer */
+ jnode *journal_header;
+ /* committed number of files (oid allocator state variable ) */
+ __u64 nr_files_committed;
+
-+ struct formatted_ra_params ra_params;
++ ra_params_t ra_params;
+
+ /*
-+ * A mutex for serializing cut tree operation if out-of-free-space:
++ * A semaphore 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 mutex delete_mutex;
-+ /* task owning ->delete_mutex */
-+ struct task_struct *delete_mutex_owner;
++ struct semaphore delete_sema;
++ /* task owning ->delete_sema */
++ struct task_struct *delete_sema_owner;
++
++ /* serialize semaphore */
++ struct semaphore flush_sema;
+
+ /* Diskmap's blocknumber */
+ __u64 diskmap_block;
+ int onerror;
+
+ /* operations for objects on this file system */
-+ struct object_ops ops;
++ object_ops ops;
+
+ /*
+ * structure to maintain d_cursors. See plugin/file_ops_readdir.c for
+ * more details
+ */
-+ struct d_cursor_info d_info;
++ d_cursor_info d_info;
+
+#ifdef CONFIG_REISER4_BADBLOCKS
+ /* Alternative master superblock offset (in bytes) */
+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)
+ 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)
+ return get_super_private(reiser4_get_current_sb());
+}
+
-+static inline struct formatted_ra_params *get_current_super_ra_params(void)
++static inline ra_params_t *get_current_super_ra_params(void)
+{
+ return &(get_current_super_private()->ra_params);
+}
+
+extern __u64 reiser4_current_block_count(void);
+
-+extern void build_object_ops(struct super_block *super, struct object_ops * ops);
++extern void build_object_ops(struct super_block *super, object_ops * ops);
+
+#define REISER4_SUPER_MAGIC 0x52345362 /* (*(__u32 *)"R4Sb"); */
+
+ spin_unlock(&(sbinfo->guard));
+}
+
-+extern __u64 reiser4_flush_reserved(const struct super_block *);
++extern __u64 flush_reserved(const struct super_block *);
+extern int reiser4_is_set(const struct super_block *super, reiser4_fs_flag f);
-+extern long reiser4_statfs_type(const struct super_block *super);
++extern long 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);
+extern long reiser4_reserved_blocks(const struct super_block *super, uid_t uid,
+ gid_t gid);
+
-+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 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 int is_reiser4_super(const struct super_block *super);
+
+extern int reiser4_blocknr_is_sane(const reiser4_block_nr * blk);
+extern int reiser4_done_super(struct super_block *s);
+
+/* step of fill super */
-+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);
++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 *);
++
+
+/* Maximal possible object id. */
+#define ABSOLUTE_MAX_OID ((oid_t)~0)
+void print_fs_info(const char *prefix, const struct super_block *);
+#endif
+
-+extern void destroy_reiser4_cache(struct kmem_cache **);
++extern void destroy_reiser4_cache(kmem_cache_t **);
+
+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
+ * fill-column: 120
+ * End:
+ */
-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 @@
+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 @@
+/* Copyright 2005 by Hans Reiser, licensing governed by
+ * reiser4/README */
+
+#include <linux/debugfs.h>
+
+/* slab cache for inodes */
-+static struct kmem_cache *inode_cache;
-+
-+static struct dentry *reiser4_debugfs_root = NULL;
++static kmem_cache_t *inode_cache;
+
+/**
+ * init_once - constructor for reiser4 inodes
+ * 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, struct kmem_cache *cache, unsigned long flags)
++static void init_once(void *obj, kmem_cache_t *cache, unsigned long flags)
+{
-+ struct reiser4_inode_object *info;
++ reiser4_inode_object *info;
+
+ info = obj;
+
-+ /* initialize vfs inode */
-+ inode_init_once(&info->vfs_inode);
++ if ((flags & (SLAB_CTOR_VERIFY | SLAB_CTOR_CONSTRUCTOR)) ==
++ SLAB_CTOR_CONSTRUCTOR) {
++ /* 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_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);
++ /*
++ * 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);
+#if REISER4_DEBUG
-+ info->p.nr_jnodes = 0;
++ info->p.nr_jnodes = 0;
+#endif
++ }
+}
+
+/**
+static int init_inodes(void)
+{
+ inode_cache = kmem_cache_create("reiser4_inode",
-+ sizeof(struct reiser4_inode_object),
++ sizeof(reiser4_inode_object),
+ 0,
+ SLAB_HWCACHE_ALIGN |
+ SLAB_RECLAIM_ACCOUNT, init_once, NULL);
+ */
+static struct inode *reiser4_alloc_inode(struct super_block *super)
+{
-+ struct reiser4_inode_object *obj;
++ reiser4_inode_object *obj;
+
+ assert("nikita-1696", super != NULL);
-+ obj = kmem_cache_alloc(inode_cache, reiser4_ctx_gfp_mask_get());
++ obj = kmem_cache_alloc(inode_cache, SLAB_KERNEL);
+ if (obj != NULL) {
+ reiser4_inode *info;
+
+ info = &obj->p;
+
-+ info->pset = plugin_set_get_empty();
-+ info->hset = plugin_set_get_empty();
++ info->hset = info->pset = 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
-+ reiser4_seal_init(&info->sd_seal, NULL, NULL);
++ seal_init(&info->sd_seal, NULL, NULL);
+ coord_init_invalid(&info->sd_coord, NULL);
+ info->flags = 0;
+ spin_lock_init(&info->guard);
+ if (fplug->destroy_inode != NULL)
+ fplug->destroy_inode(inode);
+ }
-+ reiser4_dispose_cursors(inode);
++ 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
+ loading_destroy(info);
+
+ kmem_cache_free(inode_cache,
-+ container_of(info, struct reiser4_inode_object, p));
++ container_of(info, reiser4_inode_object, p));
+}
+
+/**
+ reiser4_context *ctx;
+ file_plugin *fplug;
+
-+ ctx = reiser4_init_context(inode->i_sb);
++ ctx = init_context(inode->i_sb);
+ if (IS_ERR(ctx)) {
+ warning("vs-15", "failed to init context");
+ return;
+ fplug->delete_object(inode);
+ }
+
-+ truncate_inode_pages(&inode->i_data, 0);
+ inode->i_blocks = 0;
+ clear_inode(inode);
+ reiser4_exit_context(ctx);
+ debugfs_remove(sbinfo->tmgr.debugfs_id_count);
+ debugfs_remove(sbinfo->debugfs_root);
+
-+ ctx = reiser4_init_context(super);
++ ctx = 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);
+
-+ reiser4_done_formatted_fake(super);
++ done_formatted_fake(super);
+
+ /* stop daemons: ktxnmgr and entd */
-+ reiser4_done_entd(super);
-+ reiser4_done_ktxnmgrd(super);
-+ reiser4_done_txnmgr(&sbinfo->tmgr);
++ done_entd(super);
++ done_ktxnmgrd(super);
++ done_txnmgr(&sbinfo->tmgr);
+
-+ reiser4_done_fs_info(super);
++ done_fs_info(super);
+ reiser4_exit_context(ctx);
+}
+
+
+ assert("vs-1700", !rofs_super(super));
+
-+ ctx = reiser4_init_context(super);
++ ctx = init_context(super);
+ if (IS_ERR(ctx)) {
+ warning("vs-16", "failed to init context");
+ return;
+ }
+
-+ ret = reiser4_capture_super_block(super);
++ ret = capture_super_block(super);
+ if (ret != 0)
+ warning("vs-1701",
-+ "reiser4_capture_super_block failed in write_super: %d",
-+ ret);
++ "capture_super_block failed in write_super: %d", ret);
+ ret = txnmgr_force_commit_all(super, 0);
+ if (ret != 0)
+ warning("jmacd-77113",
+ *
+ * Returns information about filesystem.
+ */
-+static int reiser4_statfs(struct dentry *dentry, struct kstatfs *statfs)
++static int reiser4_statfs(struct super_block *super, struct kstatfs *statfs)
+{
+ sector_t total;
+ sector_t reserved;
+ 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 = reiser4_init_context(super);
++ ctx = init_context(super);
+ if (IS_ERR(ctx))
+ return PTR_ERR(ctx);
+
-+ statfs->f_type = reiser4_statfs_type(super);
++ statfs->f_type = statfs_type(super);
+ statfs->f_bsize = super->s_blocksize;
+
+ /*
+ to_write = wbc->nr_to_write;
+ assert("vs-49", wbc->older_than_this == NULL);
+
-+ ctx = reiser4_init_context(super);
++ ctx = init_context(super);
+ if (IS_ERR(ctx)) {
+ warning("vs-13", "failed to init context");
+ return;
+
+ /* flush goes here */
+ wbc->nr_to_write = to_write;
-+ reiser4_writeout(super, wbc);
++ writeout(super, wbc);
+
+ /* avoid recursive calls to ->sync_inodes */
+ context_set_commit_async(ctx);
+ init_stack_context(&ctx, super);
+
+ /* allocate reiser4 specific super block */
-+ if ((result = reiser4_init_fs_info(super)) != 0)
++ if ((result = init_fs_info(super)) != 0)
+ goto failed_init_sinfo;
+
+ sbinfo = get_super_private(super);
+ /* initialize various reiser4 parameters, parse mount options */
-+ if ((result = reiser4_init_super_data(super, data)) != 0)
++ if ((result = init_super_data(super, data)) != 0)
+ goto failed_init_super_data;
+
+ /* read reiser4 master super block, initialize disk format plugin */
-+ if ((result = reiser4_init_read_super(super, silent)) != 0)
++ if ((result = init_read_super(super, silent)) != 0)
+ goto failed_init_read_super;
+
+ /* initialize transaction manager */
-+ reiser4_init_txnmgr(&sbinfo->tmgr);
++ init_txnmgr(&sbinfo->tmgr);
+
+ /* initialize ktxnmgrd context and start kernel thread ktxnmrgd */
-+ if ((result = reiser4_init_ktxnmgrd(super)) != 0)
++ if ((result = init_ktxnmgrd(super)) != 0)
+ goto failed_init_ktxnmgrd;
+
+ /* initialize entd context and start kernel thread entd */
-+ if ((result = reiser4_init_entd(super)) != 0)
++ if ((result = init_entd(super)) != 0)
+ goto failed_init_entd;
+
+ /* initialize address spaces for formatted nodes and bitmaps */
-+ if ((result = reiser4_init_formatted_fake(super)) != 0)
++ if ((result = init_formatted_fake(super)) != 0)
+ goto failed_init_formatted_fake;
+
+ /* initialize disk format plugin */
+ sbinfo->nr_files_committed = oids_used(super);
+
+ /* get inode of root directory */
-+ if ((result = reiser4_init_root_inode(super)) != 0)
++ if ((result = 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);
+
+ }
+ return 0;
+
-+ failed_update_format_version:
+ failed_init_root_inode:
+ if (sbinfo->df_plug->release)
+ sbinfo->df_plug->release(super);
+ failed_init_disk_format:
-+ reiser4_done_formatted_fake(super);
++ done_formatted_fake(super);
+ failed_init_formatted_fake:
-+ reiser4_done_entd(super);
++ done_entd(super);
+ failed_init_entd:
-+ reiser4_done_ktxnmgrd(super);
++ done_ktxnmgrd(super);
+ failed_init_ktxnmgrd:
-+ reiser4_done_txnmgr(&sbinfo->tmgr);
++ done_txnmgr(&sbinfo->tmgr);
+ failed_init_read_super:
+ failed_init_super_data:
-+ reiser4_done_fs_info(super);
++ done_fs_info(super);
+ failed_init_sinfo:
+ reiser4_exit_context(&ctx);
+ return result;
+ *
+ * Reiser4 mount entry.
+ */
-+static int reiser4_get_sb(struct file_system_type *fs_type, int flags,
-+ const char *dev_name, void *data, struct vfsmount *mnt)
++static struct super_block *reiser4_get_sb(struct file_system_type *fs_type,
++ int flags,
++ const char *dev_name,
++ void *data)
+{
-+ return get_sb_bdev(fs_type, flags, dev_name, data, fill_super, mnt);
++ return get_sb_bdev(fs_type, flags, dev_name, data, fill_super);
+}
+
+/* structure describing the reiser4 filesystem implementation */
+ .next = NULL
+};
+
-+void destroy_reiser4_cache(struct kmem_cache **cachep)
++void destroy_reiser4_cache(kmem_cache_t **cachep)
+{
++ int result;
++
+ BUG_ON(*cachep == NULL);
-+ kmem_cache_destroy(*cachep);
++ result = kmem_cache_destroy(*cachep);
++ BUG_ON(result != 0);
+ *cachep = NULL;
+}
+
++struct dentry *reiser4_debugfs_root = NULL;
++
+/**
+ * init_reiser4 - reiser4 initialization entry point
+ *
+ goto failed_init_jnodes;
+
+ /* initialize cache of flush queues */
-+ if ((result = reiser4_init_fqs()) != 0)
++ if ((result = init_fqs()) != 0)
+ goto failed_init_fqs;
+
+ /* initialize cache of structures attached to dentry->d_fsdata */
-+ if ((result = reiser4_init_dentry_fsdata()) != 0)
++ if ((result = init_dentry_fsdata()) != 0)
+ goto failed_init_dentry_fsdata;
+
+ /* initialize cache of structures attached to file->private_data */
-+ if ((result = reiser4_init_file_fsdata()) != 0)
++ if ((result = 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 = reiser4_init_d_cursor()) != 0)
++ if ((result = init_d_cursor()) != 0)
+ goto failed_init_d_cursor;
+
+ if ((result = register_filesystem(&reiser4_fs_type)) == 0) {
+ return 0;
+ }
+
-+ reiser4_done_d_cursor();
++ done_d_cursor();
+ failed_init_d_cursor:
-+ reiser4_done_file_fsdata();
++ done_file_fsdata();
+ failed_init_file_fsdata:
-+ reiser4_done_dentry_fsdata();
++ done_dentry_fsdata();
+ failed_init_dentry_fsdata:
-+ reiser4_done_fqs();
++ done_fqs();
+ failed_init_fqs:
+ done_jnodes();
+ failed_init_jnodes:
+ debugfs_remove(reiser4_debugfs_root);
+ result = unregister_filesystem(&reiser4_fs_type);
+ BUG_ON(result != 0);
-+ reiser4_done_d_cursor();
-+ reiser4_done_file_fsdata();
-+ reiser4_done_dentry_fsdata();
-+ reiser4_done_fqs();
++ done_d_cursor();
++ done_file_fsdata();
++ done_dentry_fsdata();
++ done_fqs();
+ done_jnodes();
+ done_txnmgr_static();
+ done_plugin_set();
+ * fill-column: 79
+ * End:
+ */
-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
+Index: linux-2.6.16/fs/reiser4/tap.c
+===================================================================
+--- /dev/null
++++ linux-2.6.16/fs/reiser4/tap.c
@@ -0,0 +1,377 @@
+/* Copyright 2001, 2002, 2003 by Hans Reiser, licensing governed by
+ * reiser4/README */
+#endif
+
+/** load node tap is pointing to, if not loaded already */
-+int reiser4_tap_load(tap_t * tap)
++int tap_load(tap_t * tap)
+{
+ tap_check(tap);
+ if (tap->loaded == 0) {
+}
+
+/** release node tap is pointing to. Dual to tap_load() */
-+void reiser4_tap_relse(tap_t * tap)
++void tap_relse(tap_t * tap)
+{
+ tap_check(tap);
+ if (tap->loaded > 0) {
+ * init tap to consist of @coord and @lh. Locks on nodes will be acquired with
+ * @mode
+ */
-+void reiser4_tap_init(tap_t * tap, coord_t * coord, lock_handle * lh,
-+ znode_lock_mode mode)
++void
++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);
-+ reiser4_init_ra_info(&tap->ra_info);
++ init_ra_info(&tap->ra_info);
+}
+
+/** add @tap to the per-thread list of all taps */
-+void reiser4_tap_monitor(tap_t * tap)
++void tap_monitor(tap_t * tap)
+{
+ assert("nikita-2623", tap != NULL);
+ tap_check(tap);
-+ list_add(&tap->linkage, reiser4_taps_list());
++ list_add(&tap->linkage, taps_list());
+ tap_check(tap);
+}
+
+/* duplicate @src into @dst. Copy lock handle. @dst is not initially
+ * loaded. */
-+void reiser4_tap_copy(tap_t * dst, tap_t * src)
++void tap_copy(tap_t * dst, tap_t * src)
+{
+ assert("nikita-3193", src != NULL);
+ assert("nikita-3194", dst != NULL);
+}
+
+/** finish with @tap */
-+void reiser4_tap_done(tap_t * tap)
++void tap_done(tap_t * tap)
+{
+ assert("nikita-2565", tap != NULL);
+ tap_check(tap);
+ * move @tap to the new node, locked with @target. Load @target, if @tap was
+ * already loaded.
+ */
-+int reiser4_tap_move(tap_t * tap, lock_handle * target)
++int tap_move(tap_t * tap, lock_handle * target)
+{
+ int result = 0;
+
+ result = longterm_lock_znode(&here, target,
+ tap->mode, ZNODE_LOCK_HIPRI);
+ if (result == 0) {
-+ result = reiser4_tap_move(tap, &here);
++ result = tap_move(tap, &here);
+ done_lh(&here);
+ }
+ }
+}
+
+/** return list of all taps */
-+struct list_head *reiser4_taps_list(void)
++struct list_head *taps_list(void)
+{
+ return &get_current_context()->taps;
+}
+ get_dir_neighbor(&dup, coord->node, (int)tap->mode,
+ GN_CAN_USE_UPPER_LEVELS);
+ if (result == 0) {
-+ result = reiser4_tap_move(tap, &dup);
++ result = tap_move(tap, &dup);
+ if (result == 0)
+ coord_init(tap->coord, dup.node);
+ done_lh(&dup);
+ assert("nikita-2562", tap->coord->node == tap->lh->node);
+
+ tap_check(tap);
-+ result = reiser4_tap_load(tap);
++ result = tap_load(tap);
+ if (result != 0)
+ return result;
+
+ if (result != 0)
+ break;
+ }
-+ reiser4_tap_relse(tap);
++ tap_relse(tap);
+ tap_check(tap);
+ return result;
+}
+ scroll-step: 1
+ End:
+*/
-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 @@
+Index: linux-2.6.16/fs/reiser4/tap.h
+===================================================================
+--- /dev/null
++++ linux-2.6.16/fs/reiser4/tap.h
+@@ -0,0 +1,69 @@
+/* Copyright 2002, 2003 by Hans Reiser, licensing governed by reiser4/README */
+
+/* Tree Access Pointers. See tap.c for more details. */
+ lock_handle *lh;
+ /* mode of lock acquired by this tap */
+ znode_lock_mode mode;
-+ /* incremented by reiser4_tap_load().
-+ Decremented by reiser4_tap_relse(). */
++ /* incremented by tap_load(). Decremented by tap_relse(). */
+ int loaded;
+ /* list of taps */
+ struct list_head linkage;
+
+typedef int (*go_actor_t) (tap_t * tap);
+
-+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,
++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,
+ znode_lock_mode mode);
-+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 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 int tap_to_coord(tap_t * tap, coord_t * target);
+
+extern int go_dir_el(tap_t * tap, sideof dir, int units_p);
+extern int rewind_right(tap_t * tap, int shift);
+extern int rewind_left(tap_t * tap, int shift);
+
-+extern struct list_head *reiser4_taps_list(void);
++extern struct list_head *taps_list(void);
+
-+#define for_all_taps(tap) \
-+ for (tap = list_entry(reiser4_taps_list()->next, tap_t, linkage); \
-+ reiser4_taps_list() != &tap->linkage; \
++#define for_all_taps(tap) \
++ for (tap = list_entry(taps_list()->next, tap_t, linkage); \
++ taps_list() != &tap->linkage; \
+ tap = list_entry(tap->linkage.next, tap_t, linkage))
+
+/* __REISER4_TAP_H__ */
+ scroll-step: 1
+ End:
+*/
-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 @@
+Index: linux-2.6.16/fs/reiser4/tree.c
+===================================================================
+--- /dev/null
++++ linux-2.6.16/fs/reiser4/tree.c
+@@ -0,0 +1,1875 @@
+/* Copyright 2001, 2002, 2003 by Hans Reiser, licensing governed by
+ * reiser4/README */
+
+ * ->max_key_inside() can be larger that any key actually located in the item,
+ * intervals
+ *
-+ * [ reiser4_min_key( item ), ->max_key_inside( item ) ]
++ * [ min_key( item ), ->max_key_inside( item ) ]
+ *
+ * are still disjoint for all items within the _same_ node.
+ *
+ lowest_level = (carry_level *) (pool + 1);
+ init_carry_level(lowest_level, pool);
+
-+ op = reiser4_post_carry(lowest_level, cop, coord->node, 0);
++ op = 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);
+ lowest_level->tracked = lh;
+ }
+
-+ result = reiser4_carry(lowest_level, NULL);
++ result = carry(lowest_level, NULL);
+ done_carry_pool(pool);
+
+ return result;
+ lowest_level = (carry_level *) (pool + 1);
+ init_carry_level(lowest_level, pool);
+
-+ op = reiser4_post_carry(lowest_level, COP_PASTE, coord->node, 0);
++ op = 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);
+ lowest_level->tracked = lh;
+ }
+
-+ result = reiser4_carry(lowest_level, NULL);
++ result = carry(lowest_level, NULL);
+ done_carry_pool(pool);
+
+ return result;
+}
+
+/* this either appends or truncates item @coord */
-+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 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;
+}
+
+/* insert flow @f */
-+int reiser4_insert_flow(coord_t * coord, lock_handle * lh, flow_t * f)
++int insert_flow(coord_t * coord, lock_handle * lh, flow_t * f)
+{
+ int result;
+ carry_pool *pool;
+ lowest_level = (carry_level *) (pool + 1);
+ init_carry_level(lowest_level, pool);
+
-+ op = reiser4_post_carry(lowest_level, COP_INSERT_FLOW, coord->node,
++ op = 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);
+ lowest_level->track_type = CARRY_TRACK_CHANGE;
+ lowest_level->tracked = lh;
+
-+ result = reiser4_carry(lowest_level, NULL);
++ result = carry(lowest_level, NULL);
+ done_carry_pool(pool);
+
+ return result;
+ else
+ child =
+ zget(tree, &addr, parent,
-+ znode_get_level(parent) - 1,
-+ reiser4_ctx_gfp_mask_get());
++ znode_get_level(parent) - 1, get_gfp_mask());
+ if ((child != NULL) && !IS_ERR(child) && setup_dkeys_p)
+ set_child_delimiting_keys(parent, parent_coord, child);
+ } else {
+
+ assert("zam-1001", ZF_ISSET(node, JNODE_HEARD_BANSHEE));
+
-+ if (!reiser4_blocknr_is_fake(znode_get_block(node))) {
++ if (!blocknr_is_fake(znode_get_block(node))) {
+ int ret;
+
+ /* An already allocated block goes right to the atom's delete set. */
+ * 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. reiser4_uncapture_page()
-+ * will deal with released page itself.
++ * reference of node->pg under jnode spin lock. uncapture_page() will
++ * deal with released page itself.
+ */
+ spin_lock_znode(node);
+ page = znode_page(node);
+ if (likely(page != NULL)) {
+ /*
-+ * reiser4_uncapture_page() can only be called when we are sure
-+ * that znode is pinned in memory, which we are, because
++ * 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);
-+ reiser4_uncapture_page(page);
++ uncapture_page(page);
+ unlock_page(page);
+ page_cache_release(page);
+ } else {
+ break;
+
+ spin_unlock_znode(node);
-+ reiser4_atom_wait_event(atom);
++ atom_wait_event(atom);
+ spin_lock_znode(node);
+ }
+
-+ reiser4_uncapture_block(ZJNODE(node));
++ uncapture_block(ZJNODE(node));
+ spin_unlock_atom(atom);
+ zput(node);
+ }
+ * 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.*/
-+ reiser4_invalidate_lock(handle);
++ invalidate_lock(handle);
+ uncapture_znode(node);
+}
+
+
+/* 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, reiser4_delete_node */
++/* for try_to_merge_with_left, delete_copied, 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 *
+ lowest_level = (carry_level *) (pool + 1);
+ init_carry_level(lowest_level, pool);
+
-+ op = reiser4_post_carry(lowest_level, COP_CUT, from->node, 0);
++ op = post_carry(lowest_level, COP_CUT, from->node, 0);
+ assert("vs-1509", op != 0);
+ if (IS_ERR(op)) {
+ done_carry_pool(pool);
+ op->u.cut_or_kill.is_cut = 1;
+ op->u.cut_or_kill.u.cut = cut_data;
+
-+ result = reiser4_carry(lowest_level, NULL);
++ result = carry(lowest_level, NULL);
+ done_carry_pool(pool);
+
+ return result;
+ }
+ }
+
-+ op = reiser4_post_carry(lowest_level, COP_CUT, from->node, 0);
++ op = post_carry(lowest_level, COP_CUT, from->node, 0);
+ if (IS_ERR(op) || (op == NULL)) {
+ done_children(kdata);
+ done_carry_pool(pool);
+ op->u.cut_or_kill.is_cut = 0;
+ op->u.cut_or_kill.u.kill = kdata;
+
-+ result = reiser4_carry(lowest_level, NULL);
++ result = carry(lowest_level, NULL);
+
+ done_children(kdata);
+ done_carry_pool(pool);
+void
+fake_kill_hook_tail(struct inode *inode, loff_t start, loff_t end, int truncate)
+{
-+ if (reiser4_inode_get_flag(inode, REISER4_HAS_MMAP)) {
++ if (inode_get_flag(inode, REISER4_HAS_MMAP)) {
+ pgoff_t start_pg, end_pg;
+
+ start_pg = start >> PAGE_CACHE_SHIFT;
+ * cut_worker() iteration. This is needed for proper accounting of
+ * "i_blocks" and "i_bytes" fields of the @object.
+ */
-+int reiser4_delete_node(znode * node, reiser4_key * smallest_removed,
-+ struct inode *object, int truncate)
++int delete_node(znode * node, reiser4_key * smallest_removed,
++ struct inode *object, int truncate)
+{
+ lock_handle parent_lock;
+ coord_t cut_from;
+ * @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
-+ * reiser4_cut_tree operation was interrupted for allowing atom commit.
++ * @return: 0 if success, error code otherwise, -E_REPEAT means that long cut_tree
++ * operation was interrupted for allowing atom commit .
+ */
+int
+cut_tree_worker_common(tap_t * tap, const reiser4_key * from_key,
+ /* Check can we delete the node as a whole. */
+ if (*progress && znode_get_level(node) == LEAF_LEVEL &&
+ can_delete(from_key, node)) {
-+ result = reiser4_delete_node(node, smallest_removed,
-+ object, truncate);
++ result = delete_node(node, smallest_removed, object,
++ truncate);
+ } else {
-+ result = reiser4_tap_load(tap);
++ result = tap_load(tap);
+ if (result)
+ return result;
+
+ }
+
+ /* cut data from one node */
-+ // *smallest_removed = *reiser4_min_key();
++ // *smallest_removed = *min_key();
+ result =
+ kill_node_content(&left_coord, tap->coord, from_key,
+ to_key, smallest_removed,
+ next_node_lock.node, object,
+ truncate);
-+ reiser4_tap_relse(tap);
++ tap_relse(tap);
+ }
+ if (result)
+ break;
+ if (next_node_lock.node == NULL)
+ break;
+
-+ result = reiser4_tap_move(tap, &next_node_lock);
++ result = tap_move(tap, &next_node_lock);
+ done_lh(&next_node_lock);
+ if (result)
+ break;
+
-+ /* Break long reiser4_cut_tree operation (deletion of a large
-+ file) if atom requires commit. */
++ /* Break long 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;
+ }
+ }
+ done_lh(&next_node_lock);
-+ // assert("vs-301", !keyeq(&smallest_removed, reiser4_min_key()));
++ // assert("vs-301", !keyeq(&smallest_removed, min_key()));
+ return result;
+}
+
+ * operation was interrupted for allowing atom commit .
+ */
+
-+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)
++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)
+{
+ lock_handle lock;
+ int result;
+
+ do {
+ /* Find rightmost item to cut away from the tree. */
-+ 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 */);
++ 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 */ );
+ if (result != CBK_COORD_FOUND)
+ break;
+ if (object == NULL
+ else
+ cut_tree_worker =
+ inode_file_plugin(object)->cut_tree_worker;
-+ reiser4_tap_init(&tap, &right_coord, &lock, ZNODE_WRITE_LOCK);
++ tap_init(&tap, &right_coord, &lock, ZNODE_WRITE_LOCK);
+ result =
+ cut_tree_worker(&tap, from_key, to_key, smallest_removed_p,
+ object, truncate, progress);
-+ reiser4_tap_done(&tap);
++ tap_done(&tap);
+
-+ reiser4_preempt_point();
++ preempt_point();
+
+ } while (0);
+
+ return result;
+}
+
-+/* 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)
++/* 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)
+{
+ int result;
+ int progress;
+
+ do {
-+ result = reiser4_cut_tree_object(tree, from, to, NULL,
-+ inode, truncate, &progress);
++ result =
++ cut_tree_object(tree, from, to, NULL, inode, truncate,
++ &progress);
+ } while (result == -E_REPEAT);
+
+ return result;
+}
+
+/* finishing reiser4 initialization */
-+int reiser4_init_tree(reiser4_tree * tree /* pointer to structure being
++int init_tree(reiser4_tree * tree /* pointer to structure being
+ * initialized */ ,
+ const reiser4_block_nr * root_block /* address of a root block
+ * on a disk */ ,
+ if (result == 0)
+ result = jnodes_tree_init(tree);
+ if (result == 0) {
-+ tree->uber = zget(tree, &UBER_TREE_ADDR, NULL, 0,
-+ reiser4_ctx_gfp_mask_get());
++ tree->uber = zget(tree, &UBER_TREE_ADDR, NULL, 0, get_gfp_mask());
+ if (IS_ERR(tree->uber)) {
+ result = PTR_ERR(tree->uber);
+ tree->uber = NULL;
+}
+
+/* release resources associated with @tree */
-+void reiser4_done_tree(reiser4_tree * tree /* tree to release */ )
++void done_tree(reiser4_tree * tree /* tree to release */ )
+{
+ if (tree == NULL)
+ return;
+ scroll-step: 1
+ End:
+*/
-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 @@
+Index: linux-2.6.16/fs/reiser4/tree.h
+===================================================================
+--- /dev/null
++++ linux-2.6.16/fs/reiser4/tree.h
+@@ -0,0 +1,579 @@
+/* Copyright 2001, 2002, 2003 by Hans Reiser, licensing governed by
+ * reiser4/README */
+
+ 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 {
+ } carry;
+};
+
-+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);
++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);
+
+/* cbk flags: options for coord_by_key() */
+typedef enum {
+
+typedef int (*tree_iterate_actor_t) (reiser4_tree * tree, coord_t * coord,
+ lock_handle * lh, void *arg);
-+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 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);
+
+ tree_level lock_level, tree_level stop_level,
+ __u32 flags, ra_info_t *);
+
-+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);
++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);
+
+insert_result insert_by_key(reiser4_tree * tree, const reiser4_key * key,
+ reiser4_item_data * data, coord_t * coord,
+ znode * locked_left_neighbor, struct inode *inode,
+ int truncate);
+
-+int reiser4_resize_item(coord_t * coord, reiser4_item_data * data,
-+ reiser4_key * key, lock_handle * lh, cop_insert_flag);
++int 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 reiser4_insert_flow(coord_t * coord, lock_handle * lh, flow_t * f);
++int 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);
+
+extern int cut_tree_worker_common(tap_t *, const reiser4_key *,
+ const reiser4_key *, reiser4_key *,
+ struct inode *, int, 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 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_delete_node(znode *, reiser4_key *, struct inode *, int);
++extern int delete_node(znode * node, 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);
+ 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 */
+reiser4_block_nr estimate_insert_cluster(struct inode *);
+reiser4_block_nr estimate_update_cluster(struct inode *);
+
++
+/* __REISER4_TREE_H__ */
+#endif
+
+ scroll-step: 1
+ End:
+*/
-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 @@
+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 @@
+/* Copyright 2001, 2002, 2003 by Hans Reiser, licensing governed by
+ * reiser4/README */
+
+ warning( __VA_ARGS__ )
+
+/* allocate new node on the @level and immediately on the right of @brother. */
-+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 *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;
+ if (retcode == 0) {
+ result =
+ zget(znode_get_tree(brother), &blocknr, NULL, level,
-+ reiser4_ctx_gfp_mask_get());
++ get_gfp_mask());
+ if (IS_ERR(result)) {
+ ewarning(PTR_ERR(result), "nikita-929",
+ "Cannot allocate znode for carry: %li",
+ result->nplug = znode_get_tree(brother)->nplug;
+ assert("nikita-933", result->nplug != NULL);
+
-+ retcode = zinit_new(result, reiser4_ctx_gfp_mask_get());
++ retcode = zinit_new(result, get_gfp_mask());
+ if (retcode == 0) {
+ ZF_SET(result, JNODE_CREATED);
+ zrelse(result);
+ This helper function is called by add_new_root().
+
+*/
-+znode *reiser4_add_tree_root(znode * old_root /* existing tree root */ ,
++znode *add_tree_root(znode * old_root /* existing tree root */ ,
+ znode * fake /* "fake" znode */ )
+{
+ reiser4_tree *tree = znode_get_tree(old_root);
+ flush can be going here.
+ */
+ assert("nikita-1448", znode_is_root(old_root));
-+ new_root = reiser4_new_node(fake, tree->height + 1);
++ new_root = new_node(fake, tree->height + 1);
+ if (!IS_ERR(new_root) && (result = zload(new_root)) == 0) {
+ lock_handle rlh;
+
+ WITH_DATA(new_root,
+ node_is_empty(new_root)));
+ write_lock_dk(tree);
-+ znode_set_ld_key(new_root, reiser4_min_key());
-+ znode_set_rd_key(new_root, reiser4_max_key());
++ znode_set_ld_key(new_root, min_key());
++ znode_set_rd_key(new_root, max_key());
+ write_unlock_dk(tree);
+ if (REISER4_DEBUG) {
+ ZF_CLR(old_root, JNODE_LEFT_CONNECTED);
+}
+
+/* actually remove tree 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 */)
++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 */ )
+{
+ znode *uber;
+ int result;
+ 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 reiser4_add_tree_root() for
-+ more on this.
++ protects changes of tree height. See comments in 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
-+ reiser4_kill_tree_root() collects all necessary arguments and calls
-+ reiser4_kill_root() to do the actual job.
++ kill_tree_root() collects all necessary arguments and calls kill_root()
++ to do the actual job.
+
+*/
-+int reiser4_kill_tree_root(znode * old_root /* tree root that we are
-+ removing*/)
++int kill_tree_root(znode * old_root /* tree root that we are removing */ )
+{
+ int result;
+ coord_t down_link;
+ new_root = child_znode(&down_link, old_root, 0, 1);
+ if (!IS_ERR(new_root)) {
+ result =
-+ reiser4_kill_root(tree, old_root, new_root,
-+ znode_get_block(new_root));
++ kill_root(tree, old_root, new_root,
++ znode_get_block(new_root));
+ zput(new_root);
+ } else
+ result = PTR_ERR(new_root);
+ scroll-step: 1
+ End:
+*/
-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
+Index: linux-2.6.16/fs/reiser4/tree_mod.h
+===================================================================
+--- /dev/null
++++ linux-2.6.16/fs/reiser4/tree_mod.h
@@ -0,0 +1,29 @@
+/* Copyright 2001, 2002, 2003 by Hans Reiser, licensing governed by
+ * reiser4/README */
+
+#include "forward.h"
+
-+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);
++znode *new_node(znode * brother, tree_level level);
++znode *add_tree_root(znode * old_root, znode * fake);
++int kill_tree_root(znode * old_root);
+void build_child_ptr_data(znode * child, reiser4_item_data * data);
+
+/* __REISER4_TREE_MOD_H__ */
+ scroll-step: 1
+ End:
+*/
-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 @@
+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 @@
+/* Copyright 2001, 2002, 2003 by Hans Reiser, licensing governed by
+ * reiser4/README */
+
+ neighbor = zlook(tree, &da);
+ } else {
+ neighbor =
-+ zget(tree, &da, side_parent, level,
-+ reiser4_ctx_gfp_mask_get());
++ zget(tree, &da, side_parent, level, get_gfp_mask());
+ }
+
+ if (IS_ERR(neighbor)) {
+ /* there was lock request from hi-pri locker. if
+ it is possible we unlock last parent node and
+ re-lock it again. */
-+ for (; reiser4_check_deadlock(); h--) {
++ for (; check_deadlock(); h--) {
+ done_lh(&path[h]);
+ if (h == 0)
+ goto fail;
+ fill-column: 80
+ End:
+*/
-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
+Index: linux-2.6.16/fs/reiser4/tree_walk.h
+===================================================================
+--- /dev/null
++++ linux-2.6.16/fs/reiser4/tree_walk.h
@@ -0,0 +1,125 @@
+/* Copyright 2001, 2002, 2003 by Hans Reiser, licensing governed by reiser4/README */
+
+ fill-column: 120
+ End:
+*/
-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 @@
+Index: linux-2.6.16/fs/reiser4/txnmgr.c
+===================================================================
+--- /dev/null
++++ linux-2.6.16/fs/reiser4/txnmgr.c
+@@ -0,0 +1,3158 @@
+/* Copyright 2001, 2002, 2003 by Hans Reiser, licensing governed by
+ * reiser4/README */
+
+
+/* Thoughts on the external transaction interface:
+
-+ In the current code, a TRANSCRASH handle is created implicitly by reiser4_init_context() (which
++ In the current code, a TRANSCRASH handle is created implicitly by 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
+ 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
-+ "struct kmem_cache *_txnh_slab" created for that purpose in this file.
++ "kmem_cache_t *_txnh_slab" created for that purpose in this file.
+*/
+
+/* Extending the other system call interfaces for future transaction features:
+ * 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()->reiser4_readpage_extent()):
++ * page fault. After this (in reiser4_readpage()->readpage_extent()):
+ *
+ * 1. if access is made to non-hole page new jnode is created, (if
+ * necessary)
+
+static void capture_fuse_into(txn_atom * small, txn_atom * large);
+
-+void reiser4_invalidate_list(struct list_head *);
++void invalidate_list(struct list_head *);
+
+/* GENERIC STRUCTURES */
+
+
+/* FIXME: In theory, we should be using the slab cache init & destructor
+ methods instead of, e.g., jnode_init, etc. */
-+static struct kmem_cache *_atom_slab = NULL;
++static kmem_cache_t *_atom_slab = NULL;
+/* this is for user-visible, cross system-call transactions. */
-+static struct kmem_cache *_txnh_slab = NULL;
++static kmem_cache_t *_txnh_slab = NULL;
+
+/**
+ * init_txnmgr_static - create transaction manager slab caches
+ *
+ * This is called on mount. Makes necessary initializations.
+ */
-+void reiser4_init_txnmgr(txn_mgr *mgr)
++void init_txnmgr(txn_mgr *mgr)
+{
+ assert("umka-169", mgr != NULL);
+
+ mgr->id_count = 1;
+ INIT_LIST_HEAD(&mgr->atoms_list);
+ spin_lock_init(&mgr->tmgr_lock);
-+ mutex_init(&mgr->commit_mutex);
++ sema_init(&mgr->commit_semaphore, 1);
+}
+
+/**
-+ * reiser4_done_txnmgr - stop transaction manager
++ * done_txnmgr - stop transaction manager
+ * @mgr: pointer to transaction manager embedded in reiser4 super block
+ *
+ * This is called on umount. Does sanity checks.
+ */
-+void reiser4_done_txnmgr(txn_mgr *mgr)
++void done_txnmgr(txn_mgr *mgr)
+{
+ assert("umka-170", mgr != NULL);
+ assert("umka-1701", list_empty_careful(&mgr->atoms_list));
+
+ txnh->mode = mode;
+ txnh->atom = NULL;
-+ reiser4_ctx_gfp_mask_set();
++ set_gfp_mask();
+ txnh->flags = 0;
+ spin_lock_init(&txnh->hlock);
+ INIT_LIST_HEAD(&txnh->txnh_link);
+ 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 */
+ 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 reiser4_txn_begin(reiser4_context * context)
++void txn_begin(reiser4_context * context)
+{
+ assert("jmacd-544", context->trans == NULL);
+
+}
+
+/* Finish a transaction handle context. */
-+int reiser4_txn_end(reiser4_context * context)
++int txn_end(reiser4_context * context)
+{
+ long ret = 0;
+ txn_handle *txnh;
+
+ assert("umka-283", context != NULL);
-+ assert("nikita-3012", reiser4_schedulable());
++ assert("nikita-3012", schedulable());
+ assert("vs-24", context == get_current_context());
+ assert("nikita-2967", lock_stack_isclean(get_current_lock_stack()));
+
+ return ret;
+}
+
-+void reiser4_txn_restart(reiser4_context * context)
++void txn_restart(reiser4_context * context)
+{
-+ reiser4_txn_end(context);
-+ reiser4_preempt_point();
-+ reiser4_txn_begin(context);
++ txn_end(context);
++ preempt_point();
++ txn_begin(context);
+}
+
-+void reiser4_txn_restart_current(void)
++void txn_restart_current(void)
+{
-+ reiser4_txn_restart(get_current_context());
++ txn_restart(get_current_context());
+}
+
+/* TXN_ATOM */
+ }
+
+ if (*atom_alloc == NULL) {
-+ (*atom_alloc) = kmem_cache_alloc(_atom_slab,
-+ reiser4_ctx_gfp_mask_get());
++ (*atom_alloc) = kmem_cache_alloc(_atom_slab, get_gfp_mask());
+
+ if (*atom_alloc == NULL)
+ return RETERR(-ENOMEM);
+ /* 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 reiser4_try_capture() */
++ * atom_alloc here than thread it up to try_capture(). */
+
+ spin_unlock_txnh(txnh);
+ spin_unlock_txnmgr(mgr);
+ assert("jmacd-17", atom_isclean(atom));
+
+ /*
-+ * 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.
++ * 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.
+ */
-+ check_me("", spin_trylock_atom(atom));
++ spin_lock(&(atom->alock));
+
+ /* add atom to the end of transaction manager's list of atoms */
+ list_add_tail(&atom->atom_link, &mgr->atoms_list);
+ atom->super = reiser4_get_current_sb();
+ capture_assign_txnh_nolock(atom, txnh);
+
-+ spin_unlock_atom(atom);
++ spin_unlock(&(atom->alock));
+ spin_unlock_txnh(txnh);
+
+ return -E_REPEAT;
+ dispatch_wb_list(fq->atom, fq);
+ spin_unlock_atom(fq->atom);
+
-+ ret = reiser4_write_fq(fq, NULL, 1);
-+ reiser4_fq_put(fq);
++ ret = write_fq(fq, NULL, 1);
++ fq_put(fq);
+
+ return ret;
+}
+ 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
+ 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_mutex_owner != current);
++ get_current_super_private()->delete_sema_owner != current);
+
+ for (flushiters = 0;; ++flushiters) {
+ ret =
+ /* 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 */
-+ reiser4_preempt_point();
++ preempt_point();
+
+ *atom = get_current_atom_locked();
+ if (flushiters > TOOMANYFLUSHES && IS_POW(flushiters)) {
+ warning("nikita-3176",
+ "Flushing like mad: %i", flushiters);
-+ reiser4_info_atom("atom", *atom);
++ info_atom("atom", *atom);
+ DEBUGON(flushiters > (1 << 20));
+ }
+ }
+ /* 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. */
-+ reiser4_atom_set_stage(*atom, ASTAGE_PRE_COMMIT);
++ atom_set_stage(*atom, ASTAGE_PRE_COMMIT);
+ ON_DEBUG(((*atom)->committer = current));
+ spin_unlock_atom(*atom);
+
+ assert("zam-906", list_empty(ATOM_WB_LIST(*atom)));
+
+ /* isolate critical code path which should be executed by only one
-+ * thread using tmgr mutex */
-+ mutex_lock(&sbinfo->tmgr.commit_mutex);
++ * thread using tmgr semaphore */
++ down(&sbinfo->tmgr.commit_semaphore);
+
+ 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 mutex held
++ /* The atom->ovrwr_nodes list is processed under commit semaphore held
+ because of bitmap nodes which are captured by special way in
-+ reiser4_pre_commit_hook_bitmap(), that way does not include
++ bitmap_pre_commit_hook(), that way does not include
+ capture_fuse_wait() as a capturing of other nodes does -- the commit
-+ mutex is used for transaction isolation instead. */
-+ reiser4_invalidate_list(ATOM_OVRWR_LIST(*atom));
-+ mutex_unlock(&sbinfo->tmgr.commit_mutex);
++ semaphore is used for transaction isolation instead. */
++ invalidate_list(ATOM_OVRWR_LIST(*atom));
++ up(&sbinfo->tmgr.commit_semaphore);
+
-+ reiser4_invalidate_list(ATOM_CLEAN_LIST(*atom));
-+ reiser4_invalidate_list(ATOM_WB_LIST(*atom));
++ invalidate_list(ATOM_CLEAN_LIST(*atom));
++ invalidate_list(ATOM_WB_LIST(*atom));
+ assert("zam-927", list_empty(&(*atom)->inodes));
+
+ spin_lock_atom(*atom);
+ done:
-+ reiser4_atom_set_stage(*atom, ASTAGE_DONE);
++ atom_set_stage(*atom, ASTAGE_DONE);
+ ON_DEBUG((*atom)->committer = NULL);
+
+ /* Atom's state changes, so wake up everybody waiting for this
+ spin_unlock_atom(atom);
+
+ /* commit is here */
-+ reiser4_txn_restart_current();
++ txn_restart_current();
+ return 0;
+}
+
+ reiser4_context *ctx = get_current_context();
+
+ assert("nikita-2965", lock_stack_isclean(get_current_lock_stack()));
-+ assert("nikita-3058", reiser4_commit_check_locks());
++ assert("nikita-3058", commit_check_locks());
+
-+ reiser4_txn_restart_current();
++ txn_restart_current();
+
+ mgr = &get_super_private(super)->tmgr;
+
+ return ret;
+ } else
+ /* wait atom commit */
-+ reiser4_atom_wait_event(atom);
++ atom_wait_event(atom);
+
+ goto again;
+ }
+ has to rescan atoms */
+ mgr->daemon->rescan = 1;
+ spin_unlock(&mgr->daemon->guard);
-+ reiser4_txn_restart_current();
++ txn_restart_current();
+ return 0;
+}
+
+ * makes a progress in flushing or
+ * committing the atom
+ */
-+ reiser4_atom_wait_event(atom);
++ atom_wait_event(atom);
+ goto repeat;
+ }
+ spin_unlock_atom(atom);
+ !(atom->flags & ATOM_CANCEL_FUSION)) {
+ ret = txn_try_to_fuse_small_atom(tmgr, atom);
+ if (ret == -E_REPEAT) {
-+ reiser4_preempt_point();
++ preempt_point();
+ goto repeat;
+ }
+ }
+ if (*nr_submitted == 0) {
+ /* let others who hampers flushing (hold longterm locks,
+ for instance) to free the way for flush */
-+ reiser4_preempt_point();
++ preempt_point();
+ goto repeat;
+ }
+ ret = 0;
+ if (*nr_submitted > wbc->nr_to_write)
+ warning("", "asked for %ld, written %ld\n", wbc->nr_to_write, *nr_submitted);
+*/
-+ reiser4_txn_restart(ctx);
++ txn_restart(ctx);
+
+ return ret;
+}
+
+/* Remove processed nodes from atom's clean list (thereby remove them from transaction). */
-+void reiser4_invalidate_list(struct list_head *head)
++void invalidate_list(struct list_head *head)
+{
+ while (!list_empty(head)) {
+ jnode *node;
+
+ node = list_entry(head->next, jnode, capture_link);
+ spin_lock_jnode(node);
-+ reiser4_uncapture_block(node);
++ uncapture_block(node);
+ jput(node);
+ }
+}
+}
+
+/* Add atom to the atom's waitfor list and wait for somebody to wake us up; */
-+void reiser4_atom_wait_event(txn_atom * atom)
++void atom_wait_event(txn_atom * atom)
+{
+ txn_wait_links _wlinks;
+
+ atomic_inc(&atom->refcount);
+ spin_unlock_atom(atom);
+
-+ reiser4_prepare_to_sleep(_wlinks._lock_stack);
-+ reiser4_go_to_sleep(_wlinks._lock_stack);
++ prepare_to_sleep(_wlinks._lock_stack);
++ go_to_sleep(_wlinks._lock_stack);
+
+ spin_lock_atom(atom);
+ list_del(&_wlinks._fwaitfor_link);
+ atom_dec_and_unlock(atom);
+}
+
-+void reiser4_atom_set_stage(txn_atom * atom, txn_stage stage)
++void atom_set_stage(txn_atom * atom, txn_stage stage)
+{
+ assert("nikita-3535", atom != NULL);
+ assert_spin_locked(&(atom->alock));
-+ assert("nikita-3536", stage <= ASTAGE_INVALID);
++ assert("nikita-3536", ASTAGE_FREE <= stage && stage <= ASTAGE_INVALID);
+ /* Excelsior! */
+ assert("nikita-3537", stage >= atom->stage);
+ if (atom->stage != stage) {
+ atom->stage = stage;
-+ reiser4_atom_send_event(atom);
++ atom_send_event(atom);
+ }
+}
+
+/* wake all threads which wait for an event */
-+void reiser4_atom_send_event(txn_atom * atom)
++void atom_send_event(txn_atom * atom)
+{
+ assert_spin_locked(&(atom->alock));
+ wakeup_atom_waitfor_list(atom);
+ * increase monotonically), hence this check.
+ */
+ if (cd->atom->stage < ASTAGE_CAPTURE_WAIT)
-+ reiser4_atom_set_stage(cd->atom,
-+ ASTAGE_CAPTURE_WAIT);
++ atom_set_stage(cd->atom, ASTAGE_CAPTURE_WAIT);
+ cd->atom->flags |= ATOM_FORCE_COMMIT;
+ }
+ if (cd->txnh->flags & TXNH_DONT_COMMIT) {
+ cd->wake_ktxnmgrd_up =
+ cd->atom->txnh_count == 1 &&
+ cd->atom->nr_waiters == 0;
-+ reiser4_atom_send_event(cd->atom);
++ 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;
-+ reiser4_atom_wait_event(cd->atom);
++ atom_wait_event(cd->atom);
+ result = RETERR(-E_REPEAT);
+ } else {
+ result = 0;
+ /* We change atom state to ASTAGE_CAPTURE_WAIT to
+ prevent atom fusion and count ourself as an active
+ flusher */
-+ reiser4_atom_set_stage(cd->atom, ASTAGE_CAPTURE_WAIT);
++ atom_set_stage(cd->atom, ASTAGE_CAPTURE_WAIT);
+ cd->atom->flags |= ATOM_FORCE_COMMIT;
+
+ result =
+ /* calls try_commit_txnh() until either atom commits, or error
+ * happens */
+ while (try_commit_txnh(&cd) != 0)
-+ reiser4_preempt_point();
++ preempt_point();
+
+ spin_lock_txnh(txnh);
+
+ 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 (reiser4_try_capture) manages re-aquiring the jnode
-+ lock in the failure case.
++ released. The external interface (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,
+ txn_atom *block_atom;
+ txn_atom *txnh_atom;
+
-+ /* Should not call capture for READ_NONCOM requests, handled in reiser4_try_capture. */
++ /* Should not call capture for READ_NONCOM requests, handled in try_capture. */
+ assert("jmacd-567", CAPTURE_TYPE(mode) != TXN_CAPTURE_READ_NONCOM);
+
+ /* FIXME-ZAM-HANS: FIXME_LATER_JMACD Should assert that atom->tree ==
+ assert("umka-194", txnh != NULL);
+ assert("umka-195", node != NULL);
+
-+ /* The jnode is already locked! Being called from reiser4_try_capture(). */
++ /* The jnode is already locked! Being called from try_capture(). */
+ assert_spin_locked(&(node->guard));
+ block_atom = node->atom;
+
+ cannot be processed immediately as it was requested in flags,
+ < 0 - other errors.
+*/
-+int reiser4_try_capture(jnode *node, znode_lock_mode lock_mode,
-+ txn_capture flags)
++int try_capture(jnode *node, znode_lock_mode lock_mode,
++ txn_capture flags)
+{
+ txn_atom *atom_alloc = NULL;
+ txn_capture cap_mode;
+ atomic_inc(&atomf->refcount);
+ spin_unlock_txnh(ctx->trans);
+ if (atomf > atomh) {
-+ spin_lock_atom_nested(atomf);
++ spin_lock_atom(atomf);
+ } else {
+ spin_unlock_atom(atomh);
+ spin_lock_atom(atomf);
-+ spin_lock_atom_nested(atomh);
++ spin_lock_atom(atomh);
+ }
+ if (atomh == atomf || !atom_isopen(atomh) || !atom_isopen(atomf)) {
+ release_two_atoms(atomf, atomh);
+ spin_lock_jnode(node);
+ unlock_page(pg);
+
-+ ret = reiser4_try_capture(node, ZNODE_WRITE_LOCK, 0);
++ ret = try_capture(node, ZNODE_WRITE_LOCK, 0);
+ spin_unlock_jnode(node);
+ jput(node);
+ lock_page(pg);
+
+VS-FIXME-HANS: can this code be at all streamlined? In particular, can you lock and unlock the jnode fewer times?
+ */
-+void reiser4_uncapture_page(struct page *pg)
++void uncapture_page(struct page *pg)
+{
+ jnode *node;
+ txn_atom *atom;
+
+ /* 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 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. */
++ * 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. */
+ 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
-+ * 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.
++ * 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);
-+ reiser4_atom_wait_event(atom);
++ atom_wait_event(atom);
+ lock_page(pg);
+ /*
+ * page may has been detached by ->writepage()->releasepage().
+ return;
+ }
+ }
-+ reiser4_uncapture_block(node);
++ 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 reiser4_uncapture_jnode(jnode * node)
++void uncapture_jnode(jnode * node)
+{
+ txn_atom *atom;
+
+ return;
+ }
+
-+ reiser4_uncapture_block(node);
++ uncapture_block(node);
+ spin_unlock_atom(atom);
+ jput(node);
+}
+
+ atomic_inc(&atom->refcount);
+ txnh->atom = atom;
-+ reiser4_ctx_gfp_mask_set();
++ set_gfp_mask();
+ list_add_tail(&txnh->txnh_link, &atom->txnh_list);
+ atom->txnh_count += 1;
+}
+ 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", !reiser4_blocknr_is_fake(&node->blocknr));
++ assert("vs-1093", !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);
+ spin_unlock_jnode(node);
+ /* reiser4 file write code calls set_page_dirty for
+ * unformatted nodes, for formatted nodes we do it here. */
-+ reiser4_set_page_dirty_internal(page);
++ set_page_dirty_internal(page);
+ page_cache_release(page);
+ /* bump version counter in znode */
+ z->version = znode_build_version(jnode_get_tree(node));
+ assert("jmacd-9777", node->atom != NULL);
+}
+
-+int reiser4_sync_atom(txn_atom * atom)
++int sync_atom(txn_atom * atom)
+{
+ int result;
+ txn_handle *txnh;
+ result = force_commit_atom(txnh);
+ } else if (atom->stage < ASTAGE_POST_COMMIT) {
+ /* wait atom commit */
-+ reiser4_atom_wait_event(atom);
++ atom_wait_event(atom);
+ /* try once more */
+ result = RETERR(-E_REPEAT);
+ } else
+ count = 0;
+
+ /* flush queue list */
-+ /* reiser4_check_fq(atom); */
++ /*check_fq(atom); */
+
+ /* dirty list */
+ count = 0;
+ 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", !reiser4_blocknr_is_fake(jnode_get_block(node)));
++ assert("nikita-3367", !blocknr_is_fake(jnode_get_block(node)));
+
+ atom = node->atom;
+
+ 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", !reiser4_blocknr_is_fake(jnode_get_block(node)));
++ assert("nikita-3367", !blocknr_is_fake(jnode_get_block(node)));
+ jnode_set_reloc(node);
+}
+
+ queue_jnode(fq, node);
+}
+
-+int reiser4_capture_super_block(struct super_block *s)
++int capture_super_block(struct super_block *s)
+{
+ int result;
+ znode *uber;
+ lock_handle lh;
+
+ init_lh(&lh);
-+ result = get_uber_znode(reiser4_get_tree(s),
++ result = get_uber_znode(get_tree(s),
+ ZNODE_WRITE_LOCK, ZNODE_LOCK_LOPRI, &lh);
+ if (result)
+ return result;
+ /* Go to sleep. */
+ spin_unlock_txnh(txnh);
+
-+ ret = reiser4_prepare_to_sleep(wlinks._lock_stack);
++ ret = prepare_to_sleep(wlinks._lock_stack);
+ if (ret == 0) {
-+ reiser4_go_to_sleep(wlinks._lock_stack);
++ go_to_sleep(wlinks._lock_stack);
+ ret = RETERR(-E_REPEAT);
+ }
+
+ /* lock the atom with lesser address first */
+ if (one < two) {
+ spin_lock_atom(one);
-+ spin_lock_atom_nested(two);
++ spin_lock_atom(two);
+ } else {
+ spin_lock_atom(two);
-+ spin_lock_atom_nested(one);
++ spin_lock_atom(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
+ small->nr_waiters = 0;
+
+ /* splice flush queues */
-+ reiser4_fuse_fq(large, small);
++ fuse_fq(large, small);
+
+ /* update counter of jnode on every atom' list */
+ ON_DEBUG(large->dirty += small->dirty;
+
+ if (large->stage < small->stage) {
+ /* Large only needs to notify if it has changed state. */
-+ reiser4_atom_set_stage(large, small->stage);
++ atom_set_stage(large, small->stage);
+ wakeup_atom_waiting_list(large);
+ }
+
-+ reiser4_atom_set_stage(small, ASTAGE_INVALID);
++ 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
+
+ NOTE: this function does not release a (journal) reference to jnode
+ due to locking optimizations, you should call jput() somewhere after
-+ calling reiser4_uncapture_block(). */
-+void reiser4_uncapture_block(jnode * node)
++ calling uncapture_block(). */
++void uncapture_block(jnode * node)
+{
+ txn_atom *atom;
+
+ 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)
+ * fill-column: 79
+ * End:
+ */
-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 @@
+Index: linux-2.6.16/fs/reiser4/txnmgr.h
+===================================================================
+--- /dev/null
++++ linux-2.6.16/fs/reiser4/txnmgr.h
+@@ -0,0 +1,704 @@
+/* Copyright 2001, 2002, 2003 by Hans Reiser, licensing governed by
+ * reiser4/README */
+
+#include <linux/types.h>
+#include <linux/spinlock.h>
+#include <asm/atomic.h>
-+#include <linux/wait.h>
++#include <asm/semaphore.h>
+
+/* TYPE DECLARATIONS */
+
-+/* This enumeration describes the possible types of a capture request (reiser4_try_capture).
++/* This enumeration describes the possible types of a capture request (try_capture).
+ A capture request dynamically assigns a block to the calling thread's transaction
+ handle. */
+typedef enum {
+ indicate modification will occur. */
+ TXN_CAPTURE_WTYPES = (TXN_CAPTURE_READ_MODIFY | TXN_CAPTURE_WRITE),
+
-+ /* An option to reiser4_try_capture, NONBLOCKING indicates that the caller would
++ /* An option to 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 reiser4_try_capture to prevent atom fusion, just simple
-+ capturing is allowed */
++ /* An option to 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
+ 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.
+
+
+ /* The atom's delete set. It collects block numbers of the nodes
+ which were deleted during the transaction. */
-+ struct list_head delete_set;
++ blocknr_set delete_set;
+
+ /* The atom's wandered_block mapping. */
-+ struct list_head wandered_map;
++ blocknr_set wandered_map;
+
+ /* The transaction's list of dirty captured nodes--per level. Index
+ by (level). dirty_nodes[0] is for znode-above-root */
+ /* 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 reiser4_write_fq() routine. */
++ are submitted to disk by the 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 */
+ 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 {
+ /* A counter used to assign atom->atom_id values. */
+ __u32 id_count;
+
-+ /* a mutex object for commit serialization */
-+ struct mutex commit_mutex;
++ /* a semaphore object for commit serialization */
++ struct semaphore commit_semaphore;
+
+ /* a list of all txnmrgs served by particular daemon. */
+ struct list_head linkage;
+extern int init_txnmgr_static(void);
+extern void done_txnmgr_static(void);
+
-+extern void reiser4_init_txnmgr(txn_mgr *);
-+extern void reiser4_done_txnmgr(txn_mgr *);
++extern void init_txnmgr(txn_mgr *);
++extern void done_txnmgr(txn_mgr *);
+
-+extern int reiser4_txn_reserve(int reserved);
++extern int txn_reserve(int reserved);
+
-+extern void reiser4_txn_begin(reiser4_context * context);
-+extern int reiser4_txn_end(reiser4_context * context);
++extern void txn_begin(reiser4_context * context);
++extern int txn_end(reiser4_context * context);
+
-+extern void reiser4_txn_restart(reiser4_context * context);
-+extern void reiser4_txn_restart_current(void);
++extern void txn_restart(reiser4_context * context);
++extern void txn_restart_current(void);
+
+extern int txnmgr_force_commit_all(struct super_block *, int);
+extern int current_atom_should_commit(void);
+
+extern int flush_some_atom(jnode *, long *, const struct writeback_control *, int);
+
-+extern void reiser4_atom_set_stage(txn_atom * atom, txn_stage stage);
++extern void 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 reiser4_try_capture(jnode * node, znode_lock_mode mode, txn_capture flags);
++extern int try_capture(jnode * node, znode_lock_mode mode, txn_capture flags);
+extern int try_capture_page_to_invalidate(struct page *pg);
+
-+extern void reiser4_uncapture_page(struct page *pg);
-+extern void reiser4_uncapture_block(jnode *);
-+extern void reiser4_uncapture_jnode(jnode *);
++extern void uncapture_page(struct page *pg);
++extern void uncapture_block(jnode *);
++extern void uncapture_jnode(jnode *);
+
-+extern int reiser4_capture_inode(struct inode *);
-+extern int reiser4_uncapture_inode(struct inode *);
++extern int capture_inode(struct inode *);
++extern int uncapture_inode(struct inode *);
+
+extern txn_atom *get_current_atom_locked_nocheck(void);
+
+
+extern txn_atom *jnode_get_atom(jnode *);
+
-+extern void reiser4_atom_wait_event(txn_atom *);
-+extern void reiser4_atom_send_event(txn_atom *);
++extern void atom_wait_event(txn_atom *);
++extern void atom_send_event(txn_atom *);
+
+extern void insert_into_atom_ovrwr_list(txn_atom * atom, jnode * node);
-+extern int reiser4_capture_super_block(struct super_block *s);
++extern int 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(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 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 int blocknr_set_add_extent(txn_atom * atom,
-+ struct list_head * bset,
++ blocknr_set * 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, struct list_head * bset,
++extern int blocknr_set_add_pair(txn_atom * atom, blocknr_set * bset,
+ blocknr_set_entry ** new_bsep,
+ const reiser4_block_nr * a,
+ const reiser4_block_nr * b);
+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, struct list_head * bset,
++extern int blocknr_set_iterator(txn_atom * atom, blocknr_set * bset,
+ blocknr_set_actor_f actor, void *data,
+ int delete);
+
+{
+ /* 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) &&
+ 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))) {
+ atomic_t nr_errors;
+ /* An atom this flush queue is attached to */
+ txn_atom *atom;
-+ /* A wait queue head to wait on i/o completion */
-+ wait_queue_head_t wait;
++ /* A semaphore for waiting on i/o completion */
++ struct semaphore io_sem;
+#if REISER4_DEBUG
+ /* A thread which took this fq in exclusive use, NULL if fq is free,
+ * used for debugging. */
+#endif
+};
+
-+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 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 void queue_jnode(flush_queue_t *, jnode *);
++extern void mark_jnode_queued(flush_queue_t *, jnode *);
+
-+extern int reiser4_write_fq(flush_queue_t *, long *, int);
++extern int write_fq(flush_queue_t *, long *, int);
+extern int current_atom_finish_all_fq(void);
+extern void init_atom_fq_parts(txn_atom *);
+
+extern void znode_make_dirty(znode * node);
+extern void jnode_make_dirty_locked(jnode * node);
+
-+extern int reiser4_sync_atom(txn_atom * atom);
++extern int sync_atom(txn_atom * atom);
+
+#if REISER4_DEBUG
+extern int atom_fq_parts_are_clean(txn_atom *);
+extern void add_fq_to_bio(flush_queue_t *, struct bio *);
+extern flush_queue_t *get_fq_for_current_atom(void);
+
-+void reiser4_invalidate_list(struct list_head * head);
++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
+
+# endif /* __REISER4_TXNMGR_H__ */
+
+ fill-column: 120
+ End:
+*/
-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
+Index: linux-2.6.16/fs/reiser4/type_safe_hash.h
+===================================================================
+--- /dev/null
++++ linux-2.6.16/fs/reiser4/type_safe_hash.h
@@ -0,0 +1,320 @@
+/* Copyright 2001, 2002, 2003 by Hans Reiser, licensing governed by
+ * reiser4/README */
+ fill-column: 120
+ End:
+*/
-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 @@
+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 @@
+/* Copyright 2001, 2002, 2003 by Hans Reiser, licensing governed by
+ * reiser4/README */
+
+#include <linux/reboot.h>
+#include <linux/rcupdate.h>
+
++
+/* update inode stat-data by calling plugin */
+int reiser4_update_sd(struct inode *object)
+{
+ return result;
+}
+
++
++
++
+/* Release reiser4 dentry. This is d_op->d_release() method. */
+static void reiser4_d_release(struct dentry *dentry /* dentry released */ )
+{
+ * Called by reiser4_sync_inodes(), during speculative write-back (through
+ * pdflush, or balance_dirty_pages()).
+ */
-+void reiser4_writeout(struct super_block *sb, struct writeback_control *wbc)
++void writeout(struct super_block *sb, struct writeback_control *wbc)
+{
+ long written = 0;
+ int repeats = 0;
+ return;
+ }
+
-+ BUG_ON(reiser4_get_super_fake(sb) == NULL);
-+ mapping = reiser4_get_super_fake(sb)->i_mapping;
++ BUG_ON(get_super_fake(sb) == NULL);
++ mapping = get_super_fake(sb)->i_mapping;
+ do {
+ long nr_submitted = 0;
+ jnode *node = NULL;
+ } while (wbc->nr_to_write > 0);
+}
+
++
+void reiser4_throttle_write(struct inode *inode)
+{
-+ reiser4_txn_restart_current();
++ txn_restart_current();
+ balance_dirty_pages_ratelimited(inode->i_mapping);
+}
+
+const int REISER4_MAGIC_OFFSET = 16 * 4096; /* offset to magic string from the
+ * beginning of device */
+
++
++
+/*
+ * Reiser4 initialization/shutdown.
+ *
+ * during reiser4 module load (when compiled as module).
+ */
+
++
+void reiser4_handle_error(void)
+{
+ struct super_block *sb = reiser4_get_current_sb();
+ fill-column: 120
+ End:
+*/
-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 @@
+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 @@
+/* Copyright 2001, 2002, 2003 by Hans Reiser, licensing governed by
+ * reiser4/README */
+
+/* address space operations */
+int reiser4_writepage(struct page *, struct writeback_control *);
+int reiser4_set_page_dirty(struct page *);
-+void reiser4_invalidatepage(struct page *, unsigned long offset);
++int reiser4_readpages(struct file *, struct address_space *,
++ struct list_head *pages, unsigned nr_pages);
++int 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 reiser4_writeout(struct super_block *, struct writeback_control *);
++void writeout(struct super_block *, struct writeback_control *);
++
+
+extern void reiser4_handle_error(void);
+
++
+/* __FS_REISER4_VFS_OPS_H__ */
+#endif
+
+ scroll-step: 1
+ End:
+*/
-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 @@
+Index: linux-2.6.16/fs/reiser4/wander.c
+===================================================================
+--- /dev/null
++++ linux-2.6.16/fs/reiser4/wander.c
+@@ -0,0 +1,1799 @@
+/* Copyright 2001, 2002, 2003 by Hans Reiser, licensing governed by
+ * reiser4/README */
+
+ 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" mutex). At
++ atom commit a time (there is a per-fs "commit" semaphore). 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.
+ 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)
+{
+ BA_FORMATTED);
+
+ unpin_jnode_data(cur);
-+ reiser4_drop_io_head(cur);
++ drop_io_head(cur);
+ }
+}
+
+
+ assert("zam-499", b != NULL);
+ assert("zam-500", *b != 0);
-+ assert("zam-501", !reiser4_blocknr_is_fake(b));
++ assert("zam-501", !blocknr_is_fake(b));
+
+ reiser4_dealloc_block(b, BLOCK_NOT_COUNTED, BA_FORMATTED);
+ return 0;
+ 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? */
-+ reiser4_blocknr_hint_init(&hint);
++ blocknr_hint_init(&hint);
+ hint.block_stage = BLOCK_GRABBED;
+
+ ret = reiser4_alloc_blocks(&hint, start, &wide_len,
+ jnode *node;
+
+ pg = bio->bi_io_vec[i].bv_page;
-+ end_page_writeback(pg);
++ ClearPageWriteback(pg);
+ node = jprivate(pg);
+ spin_lock_jnode(node);
+ JF_CLR(node, JNODE_WRITEBACK);
+ spin_unlock_jnode(sj);
+
+ /* jload it as the rest of overwrite set */
-+ jload_gfp(sj, reiser4_ctx_gfp_mask_get(), 0);
++ jload_gfp(sj, get_gfp_mask(), 0);
+
+ ch->overwrite_set_size++;
+ }
+ spin_lock_jnode(cur);
-+ reiser4_uncapture_block(cur);
++ uncapture_block(cur);
+ jput(cur);
+
+ } else {
+ int ret;
+ ch->overwrite_set_size++;
-+ ret = jload_gfp(cur, reiser4_ctx_gfp_mask_get(), 0);
++ ret = jload_gfp(cur, get_gfp_mask(), 0);
+ if (ret)
+ reiser4_panic("zam-783",
+ "cannot load e-flushed jnode back (ret = %d)\n",
+ do {
+ atom = get_current_atom_locked();
+ assert("zam-536",
-+ !reiser4_blocknr_is_fake(jnode_get_block(cur)));
++ !blocknr_is_fake(jnode_get_block(cur)));
+ ret =
+ blocknr_set_add_pair(atom, &atom->wandered_map,
+ &new_bsep,
+ while (allocated < (unsigned)ch->tx_size) {
+ len = (ch->tx_size - allocated);
+
-+ reiser4_blocknr_hint_init(&hint);
++ blocknr_hint_init(&hint);
+
+ hint.block_stage = BLOCK_GRABBED;
+
+ ret = reiser4_alloc_blocks(&hint, &first, &len,
+ BA_FORMATTED | BA_RESERVED |
+ BA_USE_DEFAULT_SEARCH_START);
-+ reiser4_blocknr_hint_done(&hint);
++ blocknr_hint_done(&hint);
+
+ if (ret)
+ return ret;
+
+ /* create jnodes for all wander records */
+ while (len--) {
-+ cur = reiser4_alloc_io_head(&first);
++ cur = alloc_io_head(&first);
+
+ if (cur == NULL) {
+ ret = RETERR(-ENOMEM);
+ goto free_not_assigned;
+ }
+
-+ ret = jinit_new(cur, reiser4_ctx_gfp_mask_get());
++ ret = jinit_new(cur, get_gfp_mask());
+
+ if (ret != 0) {
+ jfree(cur);
+ break;
+ } while (0);
+
-+ reiser4_fq_put(fq);
++ fq_put(fq);
+ if (ret)
+ return ret;
+ repeat_wo_barrier:
+ return ret;
+}
+
++
+static int write_tx_back(struct commit_handle * ch)
+{
+ flush_queue_t *fq;
+ int ret;
+ int barrier;
+
-+ reiser4_post_commit_hook();
++ 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);
-+ reiser4_fq_put(fq);
++ fq_put(fq);
+ if (ret)
+ return ret;
+ repeat_wo_barrier:
+ }
+ if (ret)
+ return ret;
-+ reiser4_post_write_back_hook();
++ post_write_back_hook();
+ return 0;
+}
+
+ writeout_mode_enable();
+
+ /* block allocator may add j-nodes to the clean_list */
-+ ret = reiser4_pre_commit_hook();
++ ret = pre_commit_hook();
+ if (ret)
+ return ret;
+
+
+ /* relocate set is on the atom->clean_nodes list after
+ * current_atom_complete_writes() finishes. It can be safely
-+ * uncaptured after commit_mutex is locked, because any atom that
++ * uncaptured after commit_semaphore is taken, because any atom that
+ * captures these nodes is guaranteed to commit after current one.
+ *
-+ * This can only be done after reiser4_pre_commit_hook(), because it is where
++ * This can only be done after pre_commit_hook(), because it is where
+ * early flushed jnodes with CREATED bit are transferred to the
+ * overwrite list. */
-+ reiser4_invalidate_list(ATOM_CLEAN_LIST(atom));
++ 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. */
-+ reiser4_atom_send_event(atom);
++ atom_send_event(atom);
+ spin_unlock_atom(atom);
+
+ if (REISER4_DEBUG) {
+ goto up_and_ret;
+
+ spin_lock_atom(atom);
-+ reiser4_atom_set_stage(atom, ASTAGE_POST_COMMIT);
++ atom_set_stage(atom, ASTAGE_POST_COMMIT);
+ spin_unlock_atom(atom);
+
+ ret = write_tx_back(&ch);
-+ reiser4_post_write_back_hook();
++ post_write_back_hook();
+
+ up_and_ret:
+ if (ret) {
+ goto free_ow_set;
+ }
+
-+ log = reiser4_alloc_io_head(&log_rec_block);
++ log = alloc_io_head(&log_rec_block);
+ if (log == NULL)
+ return RETERR(-ENOMEM);
+
+ ret = jload(log);
+ if (ret < 0) {
-+ reiser4_drop_io_head(log);
++ drop_io_head(log);
+ return ret;
+ }
+
+ ret = check_wander_record(log);
+ if (ret) {
+ jrelse(log);
-+ reiser4_drop_io_head(log);
++ drop_io_head(log);
+ return ret;
+ }
+
+ if (block == 0)
+ break;
+
-+ node = reiser4_alloc_io_head(&block);
++ node = alloc_io_head(&block);
+ if (node == NULL) {
+ ret = RETERR(-ENOMEM);
+ /*
+ * FIXME-VS:???
+ */
+ jrelse(log);
-+ reiser4_drop_io_head(log);
++ drop_io_head(log);
+ goto free_ow_set;
+ }
+
+ ret = jload(node);
+
+ if (ret < 0) {
-+ reiser4_drop_io_head(node);
++ drop_io_head(node);
+ /*
+ * FIXME-VS:???
+ */
+ jrelse(log);
-+ reiser4_drop_io_head(log);
++ drop_io_head(log);
+ goto free_ow_set;
+ }
+
+ }
+
+ jrelse(log);
-+ reiser4_drop_io_head(log);
++ drop_io_head(log);
+
+ --nr_wander_records;
+ }
+ jnode *cur = list_entry(ch.overwrite_set->next, jnode, capture_link);
+ list_del_init(&cur->capture_link);
+ jrelse(cur);
-+ reiser4_drop_io_head(cur);
++ drop_io_head(cur);
+ }
+
+ list_del_init(&tx_head->capture_link);
+
+ /* searching for oldest not flushed transaction */
+ while (1) {
-+ tx_head = reiser4_alloc_io_head(&prev_tx);
++ tx_head = alloc_io_head(&prev_tx);
+ if (!tx_head)
+ return RETERR(-ENOMEM);
+
+ ret = jload(tx_head);
+ if (ret < 0) {
-+ reiser4_drop_io_head(tx_head);
++ drop_io_head(tx_head);
+ return ret;
+ }
+
+ ret = check_tx_head(tx_head);
+ if (ret) {
+ jrelse(tx_head);
-+ reiser4_drop_io_head(tx_head);
++ drop_io_head(tx_head);
+ return ret;
+ }
+
+ break;
+
+ jrelse(tx_head);
-+ reiser4_drop_io_head(tx_head);
++ drop_io_head(tx_head);
+ }
+
+ total = le32_to_cpu(get_unaligned(&T->total));
+ jnode_get_block(tx_head), total - 1);
+
+ unpin_jnode_data(tx_head);
-+ reiser4_drop_io_head(tx_head);
++ drop_io_head(tx_head);
+
+ if (ret)
+ return ret;
+{
+ int ret;
+
-+ *node = reiser4_alloc_io_head(block);
++ *node = alloc_io_head(block);
+ if (!(*node))
+ return RETERR(-ENOMEM);
+
+ ret = jload(*node);
+
+ if (ret) {
-+ reiser4_drop_io_head(*node);
++ drop_io_head(*node);
+ *node = NULL;
+ return ret;
+ }
+{
+ if (*node) {
+ unpin_jnode_data(*node);
-+ reiser4_drop_io_head(*node);
++ drop_io_head(*node);
+ *node = NULL;
+ }
+}
+
+/* release journal control blocks */
-+void reiser4_done_journal_info(struct super_block *s)
++void done_journal_info(struct super_block *s)
+{
+ reiser4_super_info_data *sbinfo = get_super_private(s);
+
+}
+
+/* load journal control blocks */
-+int reiser4_init_journal_info(struct super_block *s)
++int init_journal_info(struct super_block *s)
+{
+ reiser4_super_info_data *sbinfo = get_super_private(s);
+ journal_location *loc;
+ fill-column: 80
+ End:
+*/
-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
+Index: linux-2.6.16/fs/reiser4/wander.h
+===================================================================
+--- /dev/null
++++ linux-2.6.16/fs/reiser4/wander.h
@@ -0,0 +1,135 @@
+/* Copyright 2002, 2003 by Hans Reiser, licensing governed by reiser4/README */
+
+extern int reiser4_journal_replay(struct super_block *);
+extern int reiser4_journal_recover_sb_data(struct super_block *);
+
-+extern int reiser4_init_journal_info(struct super_block *);
-+extern void reiser4_done_journal_info(struct super_block *);
++extern int init_journal_info(struct super_block *);
++extern void done_journal_info(struct super_block *);
+
+extern int write_jnode_list(struct list_head *, flush_queue_t *, long *, int);
+
+ scroll-step: 1
+ End:
+*/
-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
+Index: linux-2.6.16/fs/reiser4/writeout.h
+===================================================================
+--- /dev/null
++++ linux-2.6.16/fs/reiser4/writeout.h
@@ -0,0 +1,21 @@
+/* Copyright 2002, 2003, 2004 by Hans Reiser, licensing governed by reiser4/README */
+
+#define WRITEOUT_FOR_PAGE_RECLAIM (0x2)
+#define WRITEOUT_BARRIER (0x4)
+
-+extern int reiser4_get_writeout_flags(void);
++extern int get_writeout_flags(void);
+
+#endif /* __FS_REISER4_WRITEOUT_H__ */
+
+ fill-column: 80
+ End:
+*/
-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 @@
+Index: linux-2.6.16/fs/reiser4/znode.c
+===================================================================
+--- /dev/null
++++ linux-2.6.16/fs/reiser4/znode.c
+@@ -0,0 +1,1028 @@
+/* Copyright 2001, 2002, 2003 by Hans Reiser, licensing governed by
+ * reiser4/README */
+/* Znode manipulation functions. */
+ 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
-+ reiser4_kill_root() function when tree root is removed.
++ kill_root() function when tree root is removed.
+
+ At this moment znode still has:
+
+ 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 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
++ 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
+ 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.
+}
+
+/* The hash table definition */
-+#define KMALLOC(size) kmalloc((size), reiser4_ctx_gfp_mask_get())
++#define KMALLOC(size) kmalloc((size), GFP_KERNEL)
+#define KFREE(ptr, size) kfree(ptr)
+TYPE_SAFE_HASH_DEFINE(z, znode, reiser4_block_nr, zjnode.key.z, zjnode.link.z,
+ blknrhashfn, blknreq);
+#undef KMALLOC
+
+/* slab for znodes */
-+static struct kmem_cache *znode_cache;
++static kmem_cache_t *znode_cache;
+
+int znode_shift_order;
+
+ write_unlock_tree(tree);
+ }
+#if REISER4_DEBUG
-+ if (!reiser4_blocknr_is_fake(blocknr) && *blocknr != 0)
++ if (!blocknr_is_fake(blocknr) && *blocknr != 0)
+ reiser4_check_block(blocknr, 1);
+#endif
+ /* Check for invalid tree level, return -EIO */
+ 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", reiser4_schedulable());
++ assert("nikita-3016", schedulable());
+
+ if (info)
+ formatted_readahead(node, info);
+ znode_is_any_locked(node) ||
+ znode_get_level(node) != LEAF_LEVEL ||
+ keyge(key, &node->rd_key) ||
-+ keyeq(&node->rd_key, reiser4_min_key()) ||
++ keyeq(&node->rd_key, min_key()) ||
+ ZF_ISSET(node, JNODE_HEARD_BANSHEE));
+
+ node->rd_key = *key;
+ 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,
-+ reiser4_min_key()));
++ znode_is_any_locked(node) || keyeq(&node->ld_key, min_key()));
+
+ node->ld_key = *key;
+ ON_DEBUG(node->ld_key_version = atomic_inc_return(&delim_key_version));
+ fill-column: 120
+ End:
+*/
-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
+Index: linux-2.6.16/fs/reiser4/znode.h
+===================================================================
+--- /dev/null
++++ linux-2.6.16/fs/reiser4/znode.h
@@ -0,0 +1,434 @@
+/* Copyright 2001, 2002, 2003, 2004 by Hans Reiser, licensing governed by
+ * reiser4/README */
+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);
+
+#if REISER4_DEBUG
+#define STORE_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)); \
++ 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)); \
+}) )
+
+#else
+ fill-column: 120
+ End:
+*/
-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 @@
+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 {
void (*clear_inode) (struct inode *);
- void (*umount_begin) (struct vfsmount *, int);
+ void (*umount_begin) (struct super_block *);
+ void (*sync_inodes) (struct super_block *sb,
+ struct writeback_control *wbc);
int (*show_options)(struct seq_file *, struct vfsmount *);
- int (*show_stats)(struct seq_file *, struct vfsmount *);
- #ifdef CONFIG_QUOTA
-@@ -1630,6 +1632,7 @@
+
+ ssize_t (*quota_read)(struct super_block *, int, char *, size_t, loff_t);
+@@ -1449,6 +1451,7 @@ extern int invalidate_inode_pages2(struc
extern int invalidate_inode_pages2_range(struct address_space *mapping,
pgoff_t start, pgoff_t end);
extern int write_inode_now(struct inode *, int);
extern int filemap_fdatawrite(struct address_space *);
extern int filemap_flush(struct address_space *);
extern int filemap_fdatawait(struct address_space *);
-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;
+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]);
}
+EXPORT_SYMBOL(radix_tree_preload);
- 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 @@
+ 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
mapping->nrpages--;
- __dec_zone_page_state(page, NR_FILE_PAGES);
+ pagecache_acct(-1);
}
+EXPORT_SYMBOL(__remove_from_page_cache);
void remove_from_page_cache(struct page *page)
{
-@@ -132,6 +133,7 @@
+@@ -130,6 +131,7 @@ void remove_from_page_cache(struct page
__remove_from_page_cache(page);
write_unlock_irq(&mapping->tree_lock);
}
static int sync_page(void *word)
{
-@@ -719,6 +721,7 @@
- read_unlock_irq(&mapping->tree_lock);
+@@ -272,6 +274,7 @@ static int wait_on_page_writeback_range(
+
return ret;
}
+EXPORT_SYMBOL(add_to_page_cache_lru);
- /**
- * find_get_pages_contig - gang contiguous pagecache lookup
-@@ -838,6 +841,7 @@
+ /*
+ * 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);
- ra->ra_pages /= 4;
+ /**
+@@ -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);
+
+ /*
+ * 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);
+ }
++EXPORT_SYMBOL(balance_dirty_pages);
+
/**
- * 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 @@
+ * 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
ra->flags &= ~RA_FLAG_INCACHE;
ra->cache_hit = 0;
}